@aiquants/spreadsheet 0.11.0 → 0.12.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/dist/index.cjs CHANGED
@@ -1,21 +1,21 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("react/jsx-runtime"),nr=require("@aiquants/virtualscroll"),i=require("react"),ts=1e3,En=1e4,ns=10,ll=(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),rs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/ns):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const 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()-ll(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()+ll(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},os="#000000",wr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Za=20,Ja=256,Cr=new Map,bo=new WeakMap,Xe=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Qa=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},eu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Za}:wr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...wr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...wr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...wr(e.decimals)};default:return null}},tu=e=>{const t=bo.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=Cr.get(n);if(r!==void 0)return bo.set(e,r),r;Cr.size>=Ja&&Cr.clear();const o=eu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Cr.set(n,s),bo.set(e,s),s},nu=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Ri=e=>{const t=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>nu(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},ru=(e,t)=>{const n=Ri(e);if(n===null)return e;const r=(o,s)=>String(o).padStart(s,"0");return t.replace(/yyyy|MM|dd|HH|mm|ss/g,o=>{switch(o){case"yyyy":return r(n.year,4);case"MM":return r(n.month,2);case"dd":return r(n.day,2);case"HH":return r(n.hour,2);case"mm":return r(n.minute,2);default:return r(n.second,2)}})},xn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return ru(e,t.pattern??"yyyy/MM/dd");const n=Xe(e);if(n===null)return e;const r=tu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Qa(n,-2):n)},il=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Ri(n)!==null?"right":"left":Xe(n)!==null?"right":"left",Un=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",ki=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],ou=["bottom","left","right","top"],Si=(e,t,n)=>{e[t]=n},Ei=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},su=e=>{if(e===void 0)return;const t={};for(const n of ou){const r=e[n];r!==void 0&&(t[n]=Ei(r))}return Object.keys(t).length===0?void 0:t},ot=e=>{const t={};for(const n of ki){const r=n==="borders"?su(e.borders):n==="value"?e.value===void 0?void 0:Ei(e.value):e[n];r!==void 0&&r!==!1&&Si(t,n,r)}return Object.keys(t).length===0?void 0:t},ss=(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]||!ss(o[c],s[c]))return!1}return!0},lu=(e,t)=>e===t?!0:ss(e===void 0?void 0:ot(e),t===void 0?void 0:ot(t)),ls=(e,t)=>{const n={};for(const o of ki){const s=t[o];Si(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=ot(n);return ss(r,e===void 0?void 0:ot(e))?e:r},xi="data-aqsp-clip",Ir="application/x-aqsp-clip",_o=512,cl=16*1024,Io=`${xi}=`,iu=16,is=()=>{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(iu));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},rr=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",Be=e=>typeof e=="boolean",_t=e=>typeof e=="number"&&Number.isFinite(e),nt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,al=e=>nt(e)&&e>=1,cu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=En,Rt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},au=e=>t=>Array.isArray(t)&&t.every(e),Ee=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),St=(e,t)=>{if(!rr(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},cs=e=>t=>{if(!rr(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&St(t,n)},uu=["left","center","right"],du=["top","middle","bottom"],fu=["thin","medium","thick","dashed","dotted","double","hair"],vo=["gt","gte","lt","lte","eq","neq","between","notBetween"],pu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],hu=["eq","neq","gt","gte","lt","lte","between","notBetween"],mu=["contains","notContains","startsWith","endsWith"],gu=new Map([["number",Ee({type:le,decimals:_t,grouping:Be,locale:le},["type"])],["percent",Ee({type:le,decimals:_t,scale:Be,locale:le},["type"])],["currency",Ee({type:le,currency:le,decimals:_t,locale:le},["type","currency"])],["scientific",Ee({type:le,decimals:_t,locale:le},["type"])],["date",Ee({type:le,pattern:le},["type"])],["text",Ee({type:le},["type"])]]),wu=Ee({style:Rt(fu),color:le},["style"]),yr=e=>St(e,wu),Cu=Ee({top:yr,right:yr,bottom:yr,left:yr},[]),yu=Ee({value:cs(gu),align:Rt(uu),verticalAlign:Rt(du),wrap:Be,background:le,color:le,bold:Be,italic:Be,underline:Be,strikethrough:Be,fontFamily:le,fontSize:_t,borders:e=>St(e,Cu)},[]),bu=e=>St(e,yu),Zt={strict:Be,inputMessage:le,errorMessage:le},vu=new Map([["list",Ee({...Zt,type:le,values:au(le),showDropdown:Be},["type","values"])],["number",Ee({...Zt,type:le,op:Rt(vo),a:le,b:le},["type","op","a"])],["textLength",Ee({...Zt,type:le,op:Rt(vo),a:_t,b:_t},["type","op","a"])],["date",Ee({...Zt,type:le,op:Rt(vo),a:le,b:le},["type","op","a"])],["text",Ee({...Zt,type:le,op:Rt(pu),value:le},["type","op"])],["checkbox",Ee({...Zt,type:le,checked:le,unchecked:le},["type"])],["custom",Ee({...Zt,type:le,formula:le},["type","formula"])]]),Ru=cs(vu),ku=Ee({startRow:nt,startCol:nt,endRow:nt,endCol:nt},["startRow","startCol","endRow","endCol"]),Su=e=>{if(!St(e,ku))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return nt(t)&&nt(r)&&nt(n)&&nt(o)&&t<=r&&n<=o},Eu=Ee({color:le,value:_t},["color"]),Ro=e=>St(e,Eu),xu=new Map([["cellValue",Ee({type:le,op:Rt(hu),a:le,b:le},["type","op","a"])],["text",Ee({type:le,op:Rt(mu),value:le},["type","op","value"])],["empty",Ee({type:le},["type"])],["notEmpty",Ee({type:le},["type"])],["colorScale",Ee({type:le,min:Ro,mid:Ro,max:Ro},["type","min","max"])],["customFormula",Ee({type:le,formula:le},["type","formula"])]]),Au=Ee({background:le,color:le,bold:Be,italic:Be,underline:Be,strikethrough:Be},[]),Ou=Ee({sourceRuleId:le,ranges:Array.isArray,condition:cs(xu),style:e=>St(e,Au),stopIfTrue:Be},["sourceRuleId","ranges","condition","style"]),Tu=(e,t,n)=>{if(!St(e,Ou))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Su(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Du=Ee({text:le,author:le,createdAt:le},["text","author","createdAt"]),Mu=e=>St(e,Du),$u=(e,t,n)=>{if(!rr(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!nt(o)||o>=t)return!1;break;case"val":if(!nt(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(Mu)))return!1;break;default:return!1}}return!0},ul=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(cu),Fu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Ai=e=>{if(!rr(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Fu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(al(t)&&al(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(bu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Ru)))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(!$u(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!ul(e.colWidths,n)||e.rowHeights!==void 0&&!ul(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Tu(c,t,n))},Qn=e=>Array.isArray(e)?`[${e.map(Qn).join(",")}]`:rr(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Qn(e[n])}`).join(",")}}`:JSON.stringify(e),zu=e=>{const t=ot(e);return t===void 0?"{}":JSON.stringify(t)},Nu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Lu=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(Nu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Oi=e=>{if(!Ai(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(zu).join(","),r=e.validations.map(Qn).join(","),o=e.cells.map(u=>`[${u.map(Lu).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(Qn).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},jo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Ai(t)?t:null},Pu=/&(?:amp|lt|gt|quot|#39|nbsp);/g,qu=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),Ti=e=>e.includes("&")?e.replace(Pu,t=>qu[t]):e,_u=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,dl=e=>{const t=e.length>_o?e.slice(0,_o):e,n=_u.exec(Ti(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Iu=e=>{const t=e.indexOf(Io);if(t===-1)return null;const n=t+Io.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Di=(e,t)=>{if(t==="event"&&e.types.includes(Ir))return{kind:"mime",json:e.getData(Ir)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Iu(n);return r===null?null:{kind:"attribute",html:n,at:r}},ju=(e,t)=>{const n=Di(e,t);return n===null?null:n.kind==="mime"?dl(n.json):dl(n.html.slice(n.at.start,n.at.start+_o))},Hu=(e,t)=>{const n=Di(e,t);if(n===null)return null;if(n.kind==="mime")return jo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:jo(Ti(n.html.slice(n.at.start,r)))},Bu=/<google-sheets-html-origin[\s>]/,Vu='data-sheets-root="1"',Wu=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ku="mso-",Yu=/\.xl\d+\s*\{/,Uu="<table",Xu=e=>e.includes(Io)?"aqsp":Bu.test(e)&&e.includes(Vu)?"sheets":Wu.test(e)||e.includes(Ku)||Yu.test(e)?"excel":null,Mi=(e,t)=>{if(t==="event"&&e.types.includes(Ir))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>cl?n.slice(0,cl):n,o=Xu(r);if(o==="aqsp")return"aqsp";if(n.includes(Uu))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},as=1e3,$i=65534,Gu=9,Zu=10,Ju=12,Qu=13,ed=32,Fi=34,zi=39,td=43,us=47,fl=48,nd=57,rd=61,od=62,sd=97,ld=98,id=100,cd=102,Ni=104,Li=114,Pi=116,ad=["able","body","head","foot"],Xn=e=>e===ed||e===Gu||e===Zu||e===Qu||e===Ju,Ho=e=>e===od||e===us||Xn(e),ud=e=>Xn(e)||e===us||e===Fi||e===zi,dd=(e,t,n,r)=>{if(t===0||!ud(e.charCodeAt(t-1)))return null;let o=t+n;for(;Xn(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==rd)return 1;for(o+=1;Xn(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Fi||s===zi)&&(o+=1);Xn(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===td&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=fl&&u<=nd;u=e.charCodeAt(o))l=l*10+(u-fl),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=dd(e,r,t.length,n);if(l!==null)return l}return 1}},fd=(e,t)=>{if(e.charCodeAt(t+2)!==Pi)return!1;const n=e.charCodeAt(t+3);if(n===Li)return Ho(e.charCodeAt(t+4));if(n!==sd&&n!==ld&&n!==Ni&&n!==cd)return!1;for(const r of ad)if(e.startsWith(r,t+3)&&Ho(e.charCodeAt(t+3+r.length)))return!0;return!1},pd=e=>{const t=e.toLowerCase(),n=pl(t,"colspan",as),r=pl(t,"rowspan",$i);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const y=new Map,q=(_,K)=>{const B=y.get(_);y.set(_,B===void 0?K:B+K)},H=()=>{m&&u+h>c&&(c=u+h),m=!1},z=()=>{H(),l+=1,m=!0,u=0;const _=y.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const K=t.charCodeAt(_+1);if(K===us){fd(t,_)&&H();continue}if(K!==Pi||!Ho(t.charCodeAt(_+3)))continue;const B=t.charCodeAt(_+2);if(B===Li)z();else if(B===id||B===Ni){m||z();const x=_+3,$=s(x),L=n(x,$);u+=L;const S=r(x,$);S>1&&(q(l,L),q(l-1+S,-L))}}return H(),{rows:l,cols:c}},qi=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}},_i=()=>{const e=new WeakMap,t=qi(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=ot(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},hd=()=>{const e=new WeakMap,t=qi(Qn);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}},md=new Set(["http:","https:","mailto:","tel:"]),Bt=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return md.has(n.protocol)?n.href:null},Tn=e=>{if(e===void 0)return;const t=Bt(e);return t===null?void 0:t},Ii=(e,t)=>e.startCol===0&&e.endCol===t-1,ji=(e,t)=>e.startRow===0&&e.endRow===t-1,Bo=13,vt=Object.freeze({style:Object.freeze({}),lineBoxPx:Bo,verticalAlign:"middle"}),gd={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:"#00000000"},wd=new Map(Object.entries(gd)),Cd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,yd=/^rgba?\((.*)\)$/,Hi=/^(\d+(?:\.\d+)?)%$/,br=e=>e.toString(16).padStart(2,"0"),ko=e=>{const t=Hi.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},bd=e=>{const t=Hi.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},vd=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=ko(t[0]),r=ko(t[1]),o=ko(t[2]);if(n===null||r===null||o===null)return null;const s=`#${br(n)}${br(r)}${br(o)}`;if(t.length===3)return s;const l=bd(t[3]);return l===null?null:l===255?s:`${s}${br(l)}`},Ve=e=>{const t=e.trim().toLowerCase(),n=Cd.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=yd.exec(t);if(r!==null)return vd(r[1]);const o=wd.get(t);return o===void 0?null:o},hl={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"}},ml=e=>{if(!Object.hasOwn(hl,e.style))return null;const t=hl[e.style],n=e.color===void 0?os:Ve(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Rd={top:"flex-start",middle:"center",bottom:"flex-end"},kd=e=>e==="left"||e==="center"||e==="right",Bi=e=>e==="top"||e==="middle"||e==="bottom",Vi=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Wi=(e,t)=>{if(typeof e.background=="string"){const s=Ve(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ve(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=Vi(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},vr=(e,t)=>{const n=e===void 0?null:ml(e);return n!==null?n:t===void 0?null:ml(t)},So=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(kd(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=Un(e.align)),Bi(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Rd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Wi(e,s));const c=e?.borders,u=vr(c?.right,t);u!==null&&(s.borderRight=u);const h=vr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=vr(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=vr(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},gl=new WeakMap,Sd=(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:So(void 0,s,l,r,o);if(!c)return So(e,s,l,r,o);const u=gl.get(e);if(u!==void 0)return u;const h=So(e,void 0,void 0,!1,!1);return gl.set(e,h),h},Ed=e=>{if(e===void 0)return vt;const t={};Wi(e,t);const n=Vi(e.fontSize),r=n===null?Bo:Math.round(n),o=Bi(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Bo&&o==="middle"?vt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},xd="#REF!",Ad=11,Od=15,Td=4096,Fr=33,Gn=34,ds=36,Dd=38,Vo=39,Ki=40,Md=42,$d=43,Fd=44,Yi=45,zd=46,Nd=47,vn=58,Ld=59,Pd=60,Ui=61,qd=62,_d=67,Id=82,Kr=91,Xi=93,jd=94,Hd=95,Gi=e=>e>=65&&e<=90||e>=97&&e<=122,Zi=e=>e>=48&&e<=57,fs=e=>Gi(e)||Zi(e)||e===Hd||e===zd||e===ds||e>=128,Bd=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,Vd=e=>e===Ui||e===Ki||e===Fd||e===Ld||e===$d||e===Yi||e===Md||e===Nd||e===jd||e===Dd||e===Pd||e===qd||e===vn,Ji=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(fs(n)||n===Ki||n===Fr||n===Kr)},wl=(e,t)=>{let n=t;for(;n<e.length&&fs(e.charCodeAt(n));)n+=1;return n},Wo=(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},Wd=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Vo){r+=2;continue}if(o===Kr)n+=1;else if(o===Xi&&(n-=1,n===0))return r+1;r+=1}return e.length},Cl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Ji(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Qi=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Gn){o=Wo(e,o,Gn);continue}if(s===Vo){const u=Wo(e,o,Vo);o=e.charCodeAt(u)===Fr?Cl(e,o,u,t,n):u;continue}if(s===Kr){o=Wd(e,o);continue}if(!fs(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Ji(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=wl(e,o);if(e.charCodeAt(c)===vn){const u=wl(e,c+1);u>c+1&&e.charCodeAt(u)===Fr&&(c=u)}o=e.charCodeAt(c)===Fr?Cl(e,o,c,t,n):c}return n},Eo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===ds;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Gi(l))break;if(s+=1,s>Ad)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Ko=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Zi(o))break;if(n-t>=Od)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Rr=(e,t)=>{const n=e.charCodeAt(t)===ds,r=Ko(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Kd=(e,t)=>{const n=Eo(e,t);if(n!==null){const o=Rr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===vn){const s=Eo(e,o.end+1);if(s!==null){const l=Rr(e,s.end);if(l!==null)return{end:l.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:l.index,col:s.col,absRow:l.abs,absCol:s.abs}}}}}return{end:o.end,token:{kind:"cell",row:o.index,col:n.col,absRow:o.abs,absCol:n.abs}}}if(e.charCodeAt(n.end)===vn){const s=Eo(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=Rr(e,t);if(r!==null&&e.charCodeAt(r.end)===vn){const o=Rr(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},or=e=>Qi(e,Kd),ec=(e,t=Td)=>{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}},Yo=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},xo=e=>`${e.absCol?"$":""}${Yo(e.col)}${e.absRow?"$":""}${e.row+1}`,ps=e=>e.sheet===void 0?"":`${e.sheet}!`,It=e=>{const t=ps(e);switch(e.kind){case"cell":return`${t}${xo(e)}`;case"range":return`${t}${xo(e.start)}:${xo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Yo(e.start.col)}:${e.end.abs?"$":""}${Yo(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},gn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Yd=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(gn(n.startRow,"formatRangeReference startRow"),gn(n.startCol,"formatRangeReference startCol"),gn(n.endRow,"formatRangeReference endRow"),gn(n.endCol,"formatRangeReference endCol"),t){case"columns":return It({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return It({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?It({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):It({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},hs=(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?`${ps(s.token)}${xd}`:l),o=s.end}return r+e.slice(o)},Yr=e=>e.charCodeAt(0)===Ui,Ao=(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}},Ud=(e,t,n)=>{switch(e.kind){case"cell":{const r=Ao(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Ao(e.start,t,n),o=Ao(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}}}}},tc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Yr(e)?hs(e,or(e),r=>{const o=Ud(r,t,n);return o===null?null:It(o)}):e},nc=(e,t)=>{gn(e.row,`${t} origin.row`),gn(e.col,`${t} origin.col`)},wn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Oo=(e,t)=>`${wn("R",e.row,e.absRow,t.row)}${wn("C",e.col,e.absCol,t.col)}`,Xd=(e,t)=>{const n=ps(e);switch(e.kind){case"cell":return`${n}${Oo(e,t)}`;case"range":return`${n}${Oo(e.start,t)}:${Oo(e.end,t)}`;case"column":return`${n}${wn("C",e.start.col,e.start.abs,t.col)}:${wn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${wn("R",e.start.row,e.start.abs,t.row)}:${wn("R",e.end.row,e.end.abs,t.row)}`}},Ur=(e,t)=>(nc(t,"toR1C1"),Yr(e)?hs(e,or(e),n=>Xd(n,t)):e),yl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Kr){const l=e.charCodeAt(o+1)===Yi,c=Ko(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Xi?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Ko(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}}},bl=(e,t)=>{const n=yl(e,t,Id),r=yl(e,n===null?t:n.end,_d);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}},Gd=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}}},Zd=(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,Jd=(e,t)=>{const n=bl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===vn){const r=bl(e,n.end+1);if(r!==null){const o=Zd(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Gd(n)}},Qd=e=>Qi(e,Jd),ef=ec(Qd),Cn=(e,t)=>e.rel?t+e.n:e.n-1,vl=(e,t)=>{const n=Cn(e.row,t.row),r=Cn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},tf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=vl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=vl(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=Cn(e.start,t.row),s=Cn(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=Cn(e.start,t.col),s=Cn(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}}}},sr=(e,t)=>(nc(t,"fromR1C1"),Yr(e)?hs(e,ef(e),n=>{const r=tf(n,t);return r===null?null:It(r)}):e),Rl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},nf=e=>{switch(e.kind){case"cell":return{...e,...Rl(e.absCol,e.absRow)};case"range":{const t=Rl(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}}}}},rc=(e,t)=>Yr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,oc=(e,t)=>{if(!rc(e,t))return null;for(const n of or(e))if(n.start<=t&&t<=n.end)return n;return null},rf=(e,t)=>{const n=oc(e,t);if(n===null)return null;const r=It(nf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},kl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Gn){const s=Wo(e,r,Gn);if(s>t)return!1;n=Gn,r=s;continue}Bd(o)||(n=o),r+=1}return Vd(n)},sc=(e,t)=>{if(!rc(e,t))return null;for(const n of or(e))if(n.start<=t&&t<=n.end)return kl(e,n.start)?{replace:[n.start,n.end]}:null;return kl(e,t)?{insertAt:t}:null},An=[{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}],Xr=(e,t)=>`[$${e}-${t}]`,of=new Map(An.map(e=>[Xr(e.symbol,e.lcid),e])),sf=new Map(An.filter((e,t)=>An.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(An.map(e=>[Xr(e.symbol,e.lcid),e.code]));const lf=new Set([...An.map(e=>e.symbol),...An.map(e=>e.code),"¥"]),cf=20,af="yyyy/MM/dd",lc=/yyyy|MM|dd|HH|mm|ss/g,ic=" -+/():!^&'~{}<>=",uf="$¥€£₩₹¥",Uo=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},df=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},ff=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const y=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:y}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(ic.includes(o)||uf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},tt=e=>e===void 0?{}:{locale:e},pf=/^(0|#,##0)(?:\.(0+))?$/,Sl=(e,t,n,r)=>{if(t!==null){const o=of.get(Xr(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!lf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...tt(r.locale)}},hf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const z of e)switch(z.kind){case"locale":break;case"literal":r?u+=z.text:c+=z.text;break;case"digits":if(r)return;n=z.text,r=!0;break;case"currency":if(o!==null)return;o=z;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=pf.exec(n);if(h===null)return;const m=h[1]==="#,##0",y=h[2]===void 0?0:h[2].length,q=c.trim(),H=u.trim();if(s)return l===0&&o===null&&!m&&q===""&&H===""?{type:"scientific",decimals:y,...tt(t.locale)}:void 0;if(l>0)return l===1&&o===null&&q===""&&H===""?{type:"percent",decimals:y,...tt(t.locale)}:void 0;if(H==="%"&&q===""&&o===null)return{type:"percent",decimals:y,scale:!1,...tt(t.locale)};if(o!==null)return q===""&&H===""?Sl(o.symbol,o.lcid,y,t):void 0;if(!(q!==""&&H!==""))return q!==""||H!==""?Sl(q+H,null,y,t):{type:"number",decimals:y,...m?{grouping:!0}:{},...tt(t.locale)}},mf=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),gf=(e,t)=>{const n=[...e.matchAll(lc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},wf=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":mf.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&gf(r,n)?{type:"date",pattern:r}:void 0},Cf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...tt(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...tt(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...tt(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...tt(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...tt(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...tt(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),ms=(e,t)=>{const n=df(e).trim(),r=Cf.get(n);if(r!==void 0)return r(t);const o=ff(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return hf(o,t);if(o.some(s=>s.kind==="date"))return wf(o)}},yf=(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:ms(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Wn=e=>e===0?"":`.${"0".repeat(e)}`,zr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=cf,bf=`${ic}.,`,El=e=>e.includes('"')?null:[...e].every(t=>bf.includes(t))?e:`"${e}"`,vf=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(lc)){const u=El(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=El(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=ms(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Rf=e=>{const t=sf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!zr(n))return null;const r=`#,##0${Wn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Xr(t.symbol,t.lcid)}${r}`},cc=e=>{switch(e.type){case"text":return"@";case"date":return vf(e.pattern===void 0?af:e.pattern);case"number":return zr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Wn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return zr(t)?e.scale===!1?`0${Wn(t)}"%"`:`0${Wn(t)}%`:null}case"scientific":return zr(e.decimals)?`0${Wn(e.decimals)}E+00`:null;case"currency":return Rf(e);default:return null}},xl="-−",kf=(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("")},Sf=(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=kf(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},Ef=(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},xf=(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=L=>L>="0"&&L<="9"||l!==""&&l.includes(L)||n.decimal.includes(L)||c&&(L==="e"||L==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let y=0,q=0,H=0,z="";for(const L of o.slice(0,h))xl.includes(L)?y+=1:L==="("?q+=1:z+=L;for(const L of o.slice(m))xl.includes(L)?y+=1:L===")"?H+=1:z+=L;const _=y+q;if(q!==H||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&z.trim()!==""))return e;const K=Sf(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(K===null)return e;const B=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,x=K.exponent+B;if(x>330||x<-330)return e;const $=Ef(K.integer,K.fraction,x,s);return Number.isFinite(Number($))?$:e},Al="google-sheets-html-origin",ac=Object.freeze({group:",",decimal:"."}),Ol=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"}),uc=["top","right","bottom","left"],Af=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Of=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Tf=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"]),Tl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Df=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Mf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),$f=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"]),Ff=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),zf=3,Nf=1,dc=-25569,Nr=86400,Lf=-693959,Pf=2958465,qf=" ",Gr=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,m)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},jr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},gs=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},_f=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,If=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),y=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const q=Gr(y);for(const H of m.split(",")){const z=H.trim(),_=_f.exec(z);if(_!==null){const K=t.get(_[1]);if(K===void 0)t.set(_[1],new Map(q));else for(const[B,x]of q)K.set(B,x)}else if(z.toLowerCase()==="table"){const K=q.get("mso-displayed-decimal-separator"),B=q.get("mso-displayed-thousand-separator");K!==void 0&&(n=Uo(jr(K))),B!==void 0&&(r=Uo(jr(B)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:ac}},jf="%_-*? ",Hf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||jf.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Bf=(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},fc=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}},hn=(e,t)=>String(e).padStart(t,"0"),pc=e=>{if(e<Lf||e>Pf)return null;let t=Math.floor(e),n=Math.round((e-t)*Nr);n>=Nr&&(t+=1,n-=Nr);const r=fc(t+dc),o=`${hn(r.year,4)}-${hn(r.month,2)}-${hn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${hn(s,2)}:${hn(l,2)}:${hn(n%60,2)}`},Vf=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Wf=e=>{const t=Vf.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=Bf(n,r,o),h=fc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-dc+(s*3600+l*60+c)/Nr},ws=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),Jt=e=>ws(e).replaceAll('"',"&quot;"),hc=e=>ws(e).replaceAll("'","&#39;"),Kf=e=>ws(e).replaceAll(`\r
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("react/jsx-runtime"),lr=require("@aiquants/virtualscroll"),i=require("react"),os=1e3,Dn=1e4,ss=10,ul=(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),ls=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/ss):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),Dn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-ul(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()+ul(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},is="#000000",Rr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},nu=20,ru=256,kr=new Map,ko=new WeakMap,et=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},ou=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},su=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:nu}:Rr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Rr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Rr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Rr(e.decimals)};default:return null}},lu=e=>{const t=ko.get(e);if(t!==void 0)return t;const n=JSON.stringify([e.type,e.locale??null,e.decimals===void 0?null:String(e.decimals),e.type==="number"?e.grouping??!1:null,e.type==="currency"?e.currency:null]),r=kr.get(n);if(r!==void 0)return ko.set(e,r),r;kr.size>=ru&&kr.clear();const o=su(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return kr.set(n,s),ko.set(e,s),s},iu=(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=/^(\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>iu(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},cu=(e,t)=>{const n=Ai(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)}})},Mn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return cu(e,t.pattern??"yyyy/MM/dd");const n=et(e);if(n===null)return e;const r=lu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?ou(n,-2):n)},dl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Ai(n)!==null?"right":"left":et(n)!==null?"right":"left",Zn=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",xi=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],au=["bottom","left","right","top"],Oi=(e,t,n)=>{e[t]=n},Ti=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},uu=e=>{if(e===void 0)return;const t={};for(const n of au){const r=e[n];r!==void 0&&(t[n]=Ti(r))}return Object.keys(t).length===0?void 0:t},dt=e=>{const t={};for(const n of xi){const r=n==="borders"?uu(e.borders):n==="value"?e.value===void 0?void 0:Ti(e.value):e[n];r!==void 0&&r!==!1&&Oi(t,n,r)}return Object.keys(t).length===0?void 0:t},cs=(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]||!cs(o[c],s[c]))return!1}return!0},du=(e,t)=>e===t?!0:cs(e===void 0?void 0:dt(e),t===void 0?void 0:dt(t)),as=(e,t)=>{const n={};for(const o of xi){const s=t[o];Oi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=dt(n);return cs(r,e===void 0?void 0:dt(e))?e:r},Di="data-aqsp-clip",Vr="application/x-aqsp-clip",Ho=512,fl=16*1024,Bo=`${Di}=`,fu=16,us=()=>{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(fu));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},ir=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",We=e=>typeof e=="boolean",_t=e=>typeof e=="number"&&Number.isFinite(e),at=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,pl=e=>at(e)&&e>=1,pu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Dn,Et=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},hu=e=>t=>Array.isArray(t)&&t.every(e),Ee=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),xt=(e,t)=>{if(!ir(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},ds=e=>t=>{if(!ir(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&xt(t,n)},gu=["left","center","right"],mu=["top","middle","bottom"],wu=["thin","medium","thick","dashed","dotted","double","hair"],So=["gt","gte","lt","lte","eq","neq","between","notBetween"],Cu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],yu=["eq","neq","gt","gte","lt","lte","between","notBetween"],bu=["contains","notContains","startsWith","endsWith"],vu=new Map([["number",Ee({type:le,decimals:_t,grouping:We,locale:le},["type"])],["percent",Ee({type:le,decimals:_t,scale:We,locale:le},["type"])],["currency",Ee({type:le,currency:le,decimals:_t,locale:le},["type","currency"])],["scientific",Ee({type:le,decimals:_t,locale:le},["type"])],["date",Ee({type:le,pattern:le},["type"])],["text",Ee({type:le},["type"])]]),Ru=Ee({style:Et(wu),color:le},["style"]),Sr=e=>xt(e,Ru),ku=Ee({top:Sr,right:Sr,bottom:Sr,left:Sr},[]),Su=Ee({value:ds(vu),align:Et(gu),verticalAlign:Et(mu),wrap:We,background:le,color:le,bold:We,italic:We,underline:We,strikethrough:We,fontFamily:le,fontSize:_t,borders:e=>xt(e,ku)},[]),Eu=e=>xt(e,Su),nn={strict:We,inputMessage:le,errorMessage:le},Au=new Map([["list",Ee({...nn,type:le,values:hu(le),showDropdown:We},["type","values"])],["number",Ee({...nn,type:le,op:Et(So),a:le,b:le},["type","op","a"])],["textLength",Ee({...nn,type:le,op:Et(So),a:_t,b:_t},["type","op","a"])],["date",Ee({...nn,type:le,op:Et(So),a:le,b:le},["type","op","a"])],["text",Ee({...nn,type:le,op:Et(Cu),value:le},["type","op"])],["checkbox",Ee({...nn,type:le,checked:le,unchecked:le},["type"])],["custom",Ee({...nn,type:le,formula:le},["type","formula"])]]),xu=ds(Au),Ou=Ee({startRow:at,startCol:at,endRow:at,endCol:at},["startRow","startCol","endRow","endCol"]),Tu=e=>{if(!xt(e,Ou))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return at(t)&&at(r)&&at(n)&&at(o)&&t<=r&&n<=o},Du=Ee({color:le,value:_t},["color"]),Eo=e=>xt(e,Du),Mu=new Map([["cellValue",Ee({type:le,op:Et(yu),a:le,b:le},["type","op","a"])],["text",Ee({type:le,op:Et(bu),value:le},["type","op","value"])],["empty",Ee({type:le},["type"])],["notEmpty",Ee({type:le},["type"])],["colorScale",Ee({type:le,min:Eo,mid:Eo,max:Eo},["type","min","max"])],["customFormula",Ee({type:le,formula:le},["type","formula"])]]),$u=Ee({background:le,color:le,bold:We,italic:We,underline:We,strikethrough:We},[]),Fu=Ee({sourceRuleId:le,ranges:Array.isArray,condition:ds(Mu),style:e=>xt(e,$u),stopIfTrue:We},["sourceRuleId","ranges","condition","style"]),zu=(e,t,n)=>{if(!xt(e,Fu))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Tu(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Nu=Ee({text:le,author:le,createdAt:le},["text","author","createdAt"]),Lu=e=>xt(e,Nu),Pu=(e,t,n)=>{if(!ir(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!at(o)||o>=t)return!1;break;case"val":if(!at(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(Lu)))return!1;break;default:return!1}}return!0},hl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(pu),qu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Mi=e=>{if(!ir(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(!(pl(t)&&pl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Eu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(xu)))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(!Pu(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!hl(e.colWidths,n)||e.rowHeights!==void 0&&!hl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>zu(c,t,n))},rr=e=>Array.isArray(e)?`[${e.map(rr).join(",")}]`:ir(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${rr(e[n])}`).join(",")}}`:JSON.stringify(e),_u=e=>{const t=dt(e);return t===void 0?"{}":JSON.stringify(t)},Iu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,ju=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(Iu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},$i=e=>{if(!Mi(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(_u).join(","),r=e.validations.map(rr).join(","),o=e.cells.map(u=>`[${u.map(ju).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(rr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Vo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Mi(t)?t:null},Hu=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Bu=Object.freeze({"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&nbsp;":" "}),Fi=e=>e.includes("&")?e.replace(Hu,t=>Bu[t]):e,Vu=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,gl=e=>{const t=e.length>Ho?e.slice(0,Ho):e,n=Vu.exec(Fi(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Wu=e=>{const t=e.indexOf(Bo);if(t===-1)return null;const n=t+Bo.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},zi=(e,t)=>{if(t==="event"&&e.types.includes(Vr))return{kind:"mime",json:e.getData(Vr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Wu(n);return r===null?null:{kind:"attribute",html:n,at:r}},Ku=(e,t)=>{const n=zi(e,t);return n===null?null:n.kind==="mime"?gl(n.json):gl(n.html.slice(n.at.start,n.at.start+Ho))},Yu=(e,t)=>{const n=zi(e,t);if(n===null)return null;if(n.kind==="mime")return Vo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Vo(Fi(n.html.slice(n.at.start,r)))},Uu=/<google-sheets-html-origin[\s>]/,Xu='data-sheets-root="1"',Gu=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ju="mso-",Zu=/\.xl\d+\s*\{/,Qu="<table",ed=e=>e.includes(Bo)?"aqsp":Uu.test(e)&&e.includes(Xu)?"sheets":Gu.test(e)||e.includes(Ju)||Zu.test(e)?"excel":null,Ni=(e,t)=>{if(t==="event"&&e.types.includes(Vr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>fl?n.slice(0,fl):n,o=ed(r);if(o==="aqsp")return"aqsp";if(n.includes(Qu))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},fs=1e3,Li=65534,td=9,nd=10,rd=12,od=13,sd=32,Pi=34,qi=39,ld=43,ps=47,ml=48,id=57,cd=61,ad=62,ud=97,dd=98,fd=100,pd=102,_i=104,Ii=114,ji=116,hd=["able","body","head","foot"],Qn=e=>e===sd||e===td||e===nd||e===od||e===rd,Wo=e=>e===ad||e===ps||Qn(e),gd=e=>Qn(e)||e===ps||e===Pi||e===qi,md=(e,t,n,r)=>{if(t===0||!gd(e.charCodeAt(t-1)))return null;let o=t+n;for(;Qn(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==cd)return 1;for(o+=1;Qn(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Pi||s===qi)&&(o+=1);Qn(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===ld&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=ml&&u<=id;u=e.charCodeAt(o))l=l*10+(u-ml),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},wl=(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=md(e,r,t.length,n);if(l!==null)return l}return 1}},wd=(e,t)=>{if(e.charCodeAt(t+2)!==ji)return!1;const n=e.charCodeAt(t+3);if(n===Ii)return Wo(e.charCodeAt(t+4));if(n!==ud&&n!==dd&&n!==_i&&n!==pd)return!1;for(const r of hd)if(e.startsWith(r,t+3)&&Wo(e.charCodeAt(t+3+r.length)))return!0;return!1},Cd=e=>{const t=e.toLowerCase(),n=wl(t,"colspan",fs),r=wl(t,"rowspan",Li);let o=0;const s=I=>(o!==-1&&o<I&&(o=t.indexOf(">",I)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,g=!1;const C=new Map,q=(I,Y)=>{const H=C.get(I);C.set(I,H===void 0?Y:H+Y)},j=()=>{g&&u+h>c&&(c=u+h),g=!1},z=()=>{j(),l+=1,g=!0,u=0;const I=C.get(l-1);I!==void 0&&(h+=I)};for(let I=t.indexOf("<");I!==-1;I=t.indexOf("<",I+1)){const Y=t.charCodeAt(I+1);if(Y===ps){wd(t,I)&&j();continue}if(Y!==ji||!Wo(t.charCodeAt(I+3)))continue;const H=t.charCodeAt(I+2);if(H===Ii)z();else if(H===fd||H===_i){g||z();const $=I+3,T=s($),P=n($,T);u+=P;const S=r($,T);S>1&&(q(l,P),q(l-1+S,-P))}}return j(),{rows:l,cols:c}},Hi=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}},Bi=()=>{const e=new WeakMap,t=Hi(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=dt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},yd=()=>{const e=new WeakMap,t=Hi(rr);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}},bd=new Set(["http:","https:","mailto:","tel:"]),Bt=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return bd.has(n.protocol)?n.href:null},zn=e=>{if(e===void 0)return;const t=Bt(e);return t===null?void 0:t},Vi=(e,t)=>e.startCol===0&&e.endCol===t-1,Wi=(e,t)=>e.startRow===0&&e.endRow===t-1,Ko=13,St=Object.freeze({style:Object.freeze({}),lineBoxPx:Ko,verticalAlign:"middle"}),vd={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"},Rd=new Map(Object.entries(vd)),kd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Sd=/^rgba?\((.*)\)$/,Ki=/^(\d+(?:\.\d+)?)%$/,Er=e=>e.toString(16).padStart(2,"0"),Ao=e=>{const t=Ki.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},Ed=e=>{const t=Ki.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},Ad=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Ao(t[0]),r=Ao(t[1]),o=Ao(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Er(n)}${Er(r)}${Er(o)}`;if(t.length===3)return s;const l=Ed(t[3]);return l===null?null:l===255?s:`${s}${Er(l)}`},Ke=e=>{const t=e.trim().toLowerCase(),n=kd.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=Sd.exec(t);if(r!==null)return Ad(r[1]);const o=Rd.get(t);return o===void 0?null:o},Cl={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"}},yl=e=>{if(!Object.hasOwn(Cl,e.style))return null;const t=Cl[e.style],n=e.color===void 0?is:Ke(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},xd={top:"flex-start",middle:"center",bottom:"flex-end"},Od=e=>e==="left"||e==="center"||e==="right",Yi=e=>e==="top"||e==="middle"||e==="bottom",Ui=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Xi=(e,t)=>{if(typeof e.background=="string"){const s=Ke(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ke(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=Ui(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Ar=(e,t)=>{const n=e===void 0?null:yl(e);return n!==null?n:t===void 0?null:yl(t)},xo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Od(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=Zn(e.align)),Yi(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=xd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Xi(e,s));const c=e?.borders,u=Ar(c?.right,t);u!==null&&(s.borderRight=u);const h=Ar(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const g=Ar(c?.left,void 0);g!==null&&(s.borderLeft=g)}if(o){const g=Ar(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)})},bl=new WeakMap,Td=(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:xo(void 0,s,l,r,o);if(!c)return xo(e,s,l,r,o);const u=bl.get(e);if(u!==void 0)return u;const h=xo(e,void 0,void 0,!1,!1);return bl.set(e,h),h},Dd=e=>{if(e===void 0)return St;const t={};Xi(e,t);const n=Ui(e.fontSize),r=n===null?Ko:Math.round(n),o=Yi(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Ko&&o==="middle"?St:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Md="#REF!",$d=11,Fd=15,zd=4096,Pr=33,er=34,hs=36,Nd=38,Yo=39,Gi=40,Ld=42,Pd=43,qd=44,Ji=45,_d=46,Id=47,An=58,jd=59,Hd=60,Zi=61,Bd=62,Vd=67,Wd=82,Gr=91,Qi=93,Kd=94,Yd=95,ec=e=>e>=65&&e<=90||e>=97&&e<=122,tc=e=>e>=48&&e<=57,gs=e=>ec(e)||tc(e)||e===Yd||e===_d||e===hs||e>=128,Ud=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,Xd=e=>e===Zi||e===Gi||e===qd||e===jd||e===Pd||e===Ji||e===Ld||e===Id||e===Kd||e===Nd||e===Hd||e===Bd||e===An,nc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(gs(n)||n===Gi||n===Pr||n===Gr)},vl=(e,t)=>{let n=t;for(;n<e.length&&gs(e.charCodeAt(n));)n+=1;return n},Uo=(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},Gd=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Yo){r+=2;continue}if(o===Gr)n+=1;else if(o===Qi&&(n-=1,n===0))return r+1;r+=1}return e.length},Rl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&nc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},rc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===er){o=Uo(e,o,er);continue}if(s===Yo){const u=Uo(e,o,Yo);o=e.charCodeAt(u)===Pr?Rl(e,o,u,t,n):u;continue}if(s===Gr){o=Gd(e,o);continue}if(!gs(s)){o+=1;continue}const l=t(e,o);if(l!==null&&nc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=vl(e,o);if(e.charCodeAt(c)===An){const u=vl(e,c+1);u>c+1&&e.charCodeAt(u)===Pr&&(c=u)}o=e.charCodeAt(c)===Pr?Rl(e,o,c,t,n):c}return n},Oo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===hs;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!ec(l))break;if(s+=1,s>$d)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Xo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!tc(o))break;if(n-t>=Fd)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},xr=(e,t)=>{const n=e.charCodeAt(t)===hs,r=Xo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Jd=(e,t)=>{const n=Oo(e,t);if(n!==null){const o=xr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===An){const s=Oo(e,o.end+1);if(s!==null){const l=xr(e,s.end);if(l!==null)return{end:l.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:l.index,col:s.col,absRow:l.abs,absCol:s.abs}}}}}return{end:o.end,token:{kind:"cell",row:o.index,col:n.col,absRow:o.abs,absCol:n.abs}}}if(e.charCodeAt(n.end)===An){const s=Oo(e,n.end+1);if(s!==null)return{end:s.end,token:{kind:"column",start:{col:n.col,abs:n.abs},end:{col:s.col,abs:s.abs}}}}return null}const r=xr(e,t);if(r!==null&&e.charCodeAt(r.end)===An){const o=xr(e,r.end+1);if(o!==null)return{end:o.end,token:{kind:"row",start:{row:r.index,abs:r.abs},end:{row:o.index,abs:o.abs}}}}return null},cr=e=>rc(e,Jd),oc=(e,t=zd)=>{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}},Go=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},To=e=>`${e.absCol?"$":""}${Go(e.col)}${e.absRow?"$":""}${e.row+1}`,ms=e=>e.sheet===void 0?"":`${e.sheet}!`,It=e=>{const t=ms(e);switch(e.kind){case"cell":return`${t}${To(e)}`;case"range":return`${t}${To(e.start)}:${To(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Go(e.start.col)}:${e.end.abs?"$":""}${Go(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},vn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Zd=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(vn(n.startRow,"formatRangeReference startRow"),vn(n.startCol,"formatRangeReference startCol"),vn(n.endRow,"formatRangeReference endRow"),vn(n.endCol,"formatRangeReference endCol"),t){case"columns":return It({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return It({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?It({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):It({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},ws=(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?`${ms(s.token)}${Md}`:l),o=s.end}return r+e.slice(o)},Jr=e=>e.charCodeAt(0)===Zi,Do=(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}},Qd=(e,t,n)=>{switch(e.kind){case"cell":{const r=Do(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Do(e.start,t,n),o=Do(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}}}}},sc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Jr(e)?ws(e,cr(e),r=>{const o=Qd(r,t,n);return o===null?null:It(o)}):e},lc=(e,t)=>{vn(e.row,`${t} origin.row`),vn(e.col,`${t} origin.col`)},Rn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Mo=(e,t)=>`${Rn("R",e.row,e.absRow,t.row)}${Rn("C",e.col,e.absCol,t.col)}`,ef=(e,t)=>{const n=ms(e);switch(e.kind){case"cell":return`${n}${Mo(e,t)}`;case"range":return`${n}${Mo(e.start,t)}:${Mo(e.end,t)}`;case"column":return`${n}${Rn("C",e.start.col,e.start.abs,t.col)}:${Rn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Rn("R",e.start.row,e.start.abs,t.row)}:${Rn("R",e.end.row,e.end.abs,t.row)}`}},Zr=(e,t)=>(lc(t,"toR1C1"),Jr(e)?ws(e,cr(e),n=>ef(n,t)):e),kl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Gr){const l=e.charCodeAt(o+1)===Ji,c=Xo(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Qi?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Xo(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}}},Sl=(e,t)=>{const n=kl(e,t,Wd),r=kl(e,n===null?t:n.end,Vd);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}},tf=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}}},nf=(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,rf=(e,t)=>{const n=Sl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===An){const r=Sl(e,n.end+1);if(r!==null){const o=nf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:tf(n)}},of=e=>rc(e,rf),sf=oc(of),kn=(e,t)=>e.rel?t+e.n:e.n-1,El=(e,t)=>{const n=kn(e.row,t.row),r=kn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},lf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=El(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=El(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=kn(e.start,t.row),s=kn(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=kn(e.start,t.col),s=kn(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}}}},ar=(e,t)=>(lc(t,"fromR1C1"),Jr(e)?ws(e,sf(e),n=>{const r=lf(n,t);return r===null?null:It(r)}):e),Al=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},cf=e=>{switch(e.kind){case"cell":return{...e,...Al(e.absCol,e.absRow)};case"range":{const t=Al(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}}}}},ic=(e,t)=>Jr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,cc=(e,t)=>{if(!ic(e,t))return null;for(const n of cr(e))if(n.start<=t&&t<=n.end)return n;return null},af=(e,t)=>{const n=cc(e,t);if(n===null)return null;const r=It(cf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},xl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===er){const s=Uo(e,r,er);if(s>t)return!1;n=er,r=s;continue}Ud(o)||(n=o),r+=1}return Xd(n)},ac=(e,t)=>{if(!ic(e,t))return null;for(const n of cr(e))if(n.start<=t&&t<=n.end)return xl(e,n.start)?{replace:[n.start,n.end]}:null;return xl(e,t)?{insertAt:t}:null},$n=[{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}],Qr=(e,t)=>`[$${e}-${t}]`,uf=new Map($n.map(e=>[Qr(e.symbol,e.lcid),e])),df=new Map($n.filter((e,t)=>$n.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map($n.map(e=>[Qr(e.symbol,e.lcid),e.code]));const ff=new Set([...$n.map(e=>e.symbol),...$n.map(e=>e.code),"¥"]),pf=20,hf="yyyy/MM/dd",uc=/yyyy|MM|dd|HH|mm|ss/g,dc=" -+/():!^&'~{}<>=",gf="$¥€£₩₹¥",Jo=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},mf=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},wf=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 C=g===null?null:Number.parseInt(g,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:C}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(dc.includes(o)||gf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ct=e=>e===void 0?{}:{locale:e},Cf=/^(0|#,##0)(?:\.(0+))?$/,Ol=(e,t,n,r)=>{if(t!==null){const o=uf.get(Qr(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!ff.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ct(r.locale)}},yf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const z of e)switch(z.kind){case"locale":break;case"literal":r?u+=z.text:c+=z.text;break;case"digits":if(r)return;n=z.text,r=!0;break;case"currency":if(o!==null)return;o=z;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=Cf.exec(n);if(h===null)return;const g=h[1]==="#,##0",C=h[2]===void 0?0:h[2].length,q=c.trim(),j=u.trim();if(s)return l===0&&o===null&&!g&&q===""&&j===""?{type:"scientific",decimals:C,...ct(t.locale)}:void 0;if(l>0)return l===1&&o===null&&q===""&&j===""?{type:"percent",decimals:C,...ct(t.locale)}:void 0;if(j==="%"&&q===""&&o===null)return{type:"percent",decimals:C,scale:!1,...ct(t.locale)};if(o!==null)return q===""&&j===""?Ol(o.symbol,o.lcid,C,t):void 0;if(!(q!==""&&j!==""))return q!==""||j!==""?Ol(q+j,null,C,t):{type:"number",decimals:C,...g?{grouping:!0}:{},...ct(t.locale)}},bf=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),vf=(e,t)=>{const n=[...e.matchAll(uc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Rf=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":bf.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&vf(r,n)?{type:"date",pattern:r}:void 0},kf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ct(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ct(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ct(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ct(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ct(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ct(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Cs=(e,t)=>{const n=mf(e).trim(),r=kf.get(n);if(r!==void 0)return r(t);const o=wf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return yf(o,t);if(o.some(s=>s.kind==="date"))return Rf(o)}},Sf=(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:Cs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Xn=e=>e===0?"":`.${"0".repeat(e)}`,qr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=pf,Ef=`${dc}.,`,Tl=e=>e.includes('"')?null:[...e].every(t=>Ef.includes(t))?e:`"${e}"`,Af=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(uc)){const u=Tl(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=Tl(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Cs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},xf=e=>{const t=df.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!qr(n))return null;const r=`#,##0${Xn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Qr(t.symbol,t.lcid)}${r}`},fc=e=>{switch(e.type){case"text":return"@";case"date":return Af(e.pattern===void 0?hf:e.pattern);case"number":return qr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Xn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return qr(t)?e.scale===!1?`0${Xn(t)}"%"`:`0${Xn(t)}%`:null}case"scientific":return qr(e.decimals)?`0${Xn(e.decimals)}E+00`:null;case"currency":return xf(e);default:return null}},Dl="-−",Of=(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("")},Tf=(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=Of(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},Df=(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},Mf=(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=P=>P>="0"&&P<="9"||l!==""&&l.includes(P)||n.decimal.includes(P)||c&&(P==="e"||P==="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 C=0,q=0,j=0,z="";for(const P of o.slice(0,h))Dl.includes(P)?C+=1:P==="("?q+=1:z+=P;for(const P of o.slice(g))Dl.includes(P)?C+=1:P===")"?j+=1:z+=P;const I=C+q;if(q!==j||I>1||I===1&&s||(s=s||I===1,r!=="currency"&&z.trim()!==""))return e;const Y=Tf(o.slice(h,g).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(Y===null)return e;const H=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,$=Y.exponent+H;if($>330||$<-330)return e;const T=Df(Y.integer,Y.fraction,$,s);return Number.isFinite(Number(T))?T:e},Ml="google-sheets-html-origin",pc=Object.freeze({group:",",decimal:"."}),$l=Object.freeze({thin:".5pt solid",medium:"1.0pt solid",thick:"1.5pt solid",dashed:".5pt dashed",dotted:".5pt dotted",double:"1.5pt double",hair:".5pt hairline"}),hc=["top","right","bottom","left"],$f=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Ff=new Set(["windowtext","currentcolor","inherit","initial","unset"]),zf=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"]),Fl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Nf=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Lf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Pf=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"]),_f=3,If=1,gc=-25569,_r=86400,jf=-693959,Hf=2958465,Bf=" ",eo=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},Wr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},ys=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},Vf=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Wf=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),C=l.slice(u+1,h);if(c=h+1,g.trim().startsWith("@"))continue;const q=eo(C);for(const j of g.split(",")){const z=j.trim(),I=Vf.exec(z);if(I!==null){const Y=t.get(I[1]);if(Y===void 0)t.set(I[1],new Map(q));else for(const[H,$]of q)Y.set(H,$)}else if(z.toLowerCase()==="table"){const Y=q.get("mso-displayed-decimal-separator"),H=q.get("mso-displayed-thousand-separator");Y!==void 0&&(n=Jo(Wr(Y))),H!==void 0&&(r=Jo(Wr(H)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:pc}},Kf="%_-*? ",Yf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Kf.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Uf=(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},mc=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}},Cn=(e,t)=>String(e).padStart(t,"0"),wc=e=>{if(e<jf||e>Hf)return null;let t=Math.floor(e),n=Math.round((e-t)*_r);n>=_r&&(t+=1,n-=_r);const r=mc(t+gc),o=`${Cn(r.year,4)}-${Cn(r.month,2)}-${Cn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Cn(s,2)}:${Cn(l,2)}:${Cn(n%60,2)}`},Xf=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Gf=e=>{const t=Xf.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=Uf(n,r,o),h=mc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-gc+(s*3600+l*60+c)/_r},bs=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),rn=e=>bs(e).replaceAll('"',"&quot;"),Cc=e=>bs(e).replaceAll("'","&#39;"),Jf=e=>bs(e).replaceAll(`\r
2
2
  `,`
3
3
  `).replaceAll("\r",`
4
4
  `).replaceAll(`
5
- `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),Lr=(e,t)=>`${e}="${Jt(JSON.stringify(t))}"`,mc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Yf=e=>{if(Xe(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Uf=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Xf=e=>{if(e.type==="text")return{1:1};const t=cc(e);return t===null?null:{1:e.type==="date"?Uf(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Df[e.type],2:t,3:1}},Gf=/[;"'{}<>&\\]/,gc=e=>e==="left"||e==="center"||e==="right",wc=e=>e==="top"||e==="middle"||e==="bottom",Zf=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"?Ve(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Ve(e.background):null;if(o!==null&&t.push(`background-color:${o}`),gc(e.align)&&t.push(`text-align:${e.align}`),wc(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Gf.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 uc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(Ol,l.style))continue;const c=l.color===void 0?"windowtext":Ve(l.color);c!==null&&t.push(`border-${s}:${Ol[l.style]} ${c}`)}if(e.value!==void 0){const s=cc(e.value);s!==null&&t.push(`mso-number-format:"${Hf(s)}"`)}return t},Jf={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Qf=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=hc([n,...Zf(e)].join(";"));let o=null;if(t!==void 0){const s=Xf(t);s!==null&&(o=Lr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},ep=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:xn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&mc(o)?Yf(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Wf(e.t):null,h=[];if(l?h.push(Lr("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(Lr("data-sheets-value",{1:3,3:c})):u!==null&&h.push(Lr("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${Jt(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${Jt(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${Jt(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${Jt(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const q=sr(e.f,{row:n,col:r});q.includes("#REF!")||h.push(`x:fmla="${Jt(q)}"`)}const m=Kf(s),y=e.link===void 0?m:`<a href="${Jt(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(q=>` ${q}`).join("")}>${y}</td>`},Cc=(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(Qf);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let u=0;u<e.cols;u+=1){const h=e.cells[s][u],m=h.fmt===void 0?void 0:r[h.fmt];c+=ep(h,m===void 0?Jf:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Al}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${xi}='${hc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Al}>`},Xo=(e,t)=>{for(const[n,r]of t)e.set(n,r)},yc=(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&&Xo(n,l)}const o=e.getAttribute("style");return o!==null&&Xo(n,Gr(o)),n},tp=e=>{const t=e.toLowerCase();if(t==="thin")return{pt:.75,unit:"px"};if(t==="medium")return{pt:1.5,unit:"px"};if(t==="thick")return{pt:3,unit:"px"};const n=/^(\d*\.?\d+)(pt|px)$/.exec(t);if(n===null)return null;const r=Number(n[1]);return n[2]==="pt"?{pt:r,unit:"pt"}:{pt:r*.75,unit:"px"}},np=e=>{if(e.unit==="px"){const t=e.pt/.75;return t<=1?"thin":t<3?"medium":"thick"}return e.pt<.75?"thin":e.pt<1.25?"medium":"thick"},rp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),op={pt:1.5,unit:"px"},Dl=e=>{let t=null,n=null;const r=[];for(const u of gs(e)){const h=u.toLowerCase(),m=tp(u);Af.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=rp.get(n),s=o===void 0?np(t===null?op:t):o,l=r.join(" ");if(l===""||Of.has(l.toLowerCase()))return{style:s};const c=Ve(l);return c===null||c.length===9?null:{style:s,color:c}},sp=e=>e.style==="thin"&&e.color==="#cccccc",lp=e=>{const t=Ve(e);if(t!==null)return t;for(const n of gs(e)){const r=Ve(n);if(r!==null)return r}return null},ip=e=>{const t=jr(gs(e.split(",")[0]).join(" ").trim()).trim();return t===""||Tf.has(t.toLowerCase())?null:t},cp=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},ap=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},up=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"},dp=new Set(["normal","pre-wrap","pre-line"]),fp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const E=o.toLowerCase();(E==="bold"||E==="bolder"||Number(E)>=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=ap(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:Ve(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),m=h===void 0?null:lp(h);m!==null&&m.length!==9&&(r.background=m);const y=e.get("text-align"),q=y===void 0?"":y.toLowerCase();gc(q)&&(r.align=q);const H=e.get("vertical-align"),z=H===void 0?"":H.toLowerCase();wc(z)&&(r.verticalAlign=z);const _=e.get("font-family"),K=_===void 0?null:ip(_);K!==null&&(r.fontFamily=K);const B=e.get("font-size"),x=B===void 0?null:cp(B);x!==null&&(r.fontSize=x);const $=e.get("white-space");$!==void 0&&dp.has($.toLowerCase())&&(r.wrap=!0);const L={},S=e.get("border"),v=S===void 0?null:Dl(S);for(const E of uc){const p=e.get(`border-${E}`),g=p===void 0?v:Dl(p);g!==null&&!(n==="sheets"&&sp(g))&&(L[E]=g)}return Object.keys(L).length>0&&(r.borders=L),r},Ml=e=>{e.text!==""&&!e.text.endsWith(`
5
+ `,'<br style="mso-data-placement:same-cell">').replaceAll(" ","&#9;"),Ir=(e,t)=>`${e}="${rn(JSON.stringify(t))}"`,yc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Zf=e=>{if(et(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Qf=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},ep=e=>{if(e.type==="text")return{1:1};const t=fc(e);return t===null?null:{1:e.type==="date"?Qf(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Nf[e.type],2:t,3:1}},tp=/[;"'{}<>&\\]/,bc=e=>e==="left"||e==="center"||e==="right",vc=e=>e==="top"||e==="middle"||e==="bottom",np=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"?Ke(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Ke(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()!==""&&!tp.test(e.fontFamily)&&t.push(`font-family:${e.fontFamily.trim()}`),typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0&&t.push(`font-size:${e.fontSize}pt`),e.borders!==void 0)for(const s of hc){const l=e.borders[s];if(l===void 0||!Object.hasOwn($l,l.style))continue;const c=l.color===void 0?"windowtext":Ke(l.color);c!==null&&t.push(`border-${s}:${$l[l.style]} ${c}`)}if(e.value!==void 0){const s=fc(e.value);s!==null&&t.push(`mso-number-format:"${Yf(s)}"`)}return t},rp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},op=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=Cc([n,...np(e)].join(";"));let o=null;if(t!==void 0){const s=ep(t);s!==null&&(o=Ir("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},sp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Mn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&yc(o)?Zf(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Gf(e.t):null,h=[];if(l?h.push(Ir("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(Ir("data-sheets-value",{1:3,3:c})):u!==null&&h.push(Ir("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${rn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${rn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${rn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${rn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const q=ar(e.f,{row:n,col:r});q.includes("#REF!")||h.push(`x:fmla="${rn(q)}"`)}const g=Jf(s),C=e.link===void 0?g:`<a href="${rn(e.link)}">${g}</a>`;return`<td style='${t.style}'${h.map(q=>` ${q}`).join("")}>${C}</td>`},Rc=(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(op);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+=sp(h,g===void 0?rp:g,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Ml}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Di}='${Cc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Ml}>`},Zo=(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&&Zo(n,l)}const o=e.getAttribute("style");return o!==null&&Zo(n,eo(o)),n},lp=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"}},ip=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"},cp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),ap={pt:1.5,unit:"px"},zl=e=>{let t=null,n=null;const r=[];for(const u of ys(e)){const h=u.toLowerCase(),g=lp(u);$f.has(h)?n=h:g!==null?t=g:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=cp.get(n),s=o===void 0?ip(t===null?ap:t):o,l=r.join(" ");if(l===""||Ff.has(l.toLowerCase()))return{style:s};const c=Ke(l);return c===null||c.length===9?null:{style:s,color:c}},up=e=>e.style==="thin"&&e.color==="#cccccc",dp=e=>{const t=Ke(e);if(t!==null)return t;for(const n of ys(e)){const r=Ke(n);if(r!==null)return r}return null},fp=e=>{const t=Wr(ys(e.split(",")[0]).join(" ").trim()).trim();return t===""||zf.has(t.toLowerCase())?null:t},pp=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},hp=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},gp=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"},mp=new Set(["normal","pre-wrap","pre-line"]),wp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const E=o.toLowerCase();(E==="bold"||E==="bolder"||Number(E)>=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=hp(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:Ke(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:dp(h);g!==null&&g.length!==9&&(r.background=g);const C=e.get("text-align"),q=C===void 0?"":C.toLowerCase();bc(q)&&(r.align=q);const j=e.get("vertical-align"),z=j===void 0?"":j.toLowerCase();vc(z)&&(r.verticalAlign=z);const I=e.get("font-family"),Y=I===void 0?null:fp(I);Y!==null&&(r.fontFamily=Y);const H=e.get("font-size"),$=H===void 0?null:pp(H);$!==null&&(r.fontSize=$);const T=e.get("white-space");T!==void 0&&mp.has(T.toLowerCase())&&(r.wrap=!0);const P={},S=e.get("border"),v=S===void 0?null:zl(S);for(const E of hc){const p=e.get(`border-${E}`),m=p===void 0?v:zl(p);m!==null&&!(n==="sheets"&&up(m))&&(P[E]=m)}return Object.keys(P).length>0&&(r.borders=P),r},Nl=e=>{e.text!==""&&!e.text.endsWith(`
6
6
  `)&&(e.text+=`
7
- `)},pp=e=>{const t=e.getAttribute("style");return t!==null&&Gr(t).get("mso-spacerun")==="yes"},hp=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Ff.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&Ml(t);continue}const o=r.node;if(o.nodeType===zf){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!==Nf)continue;const s=o,l=s.localName;if(Mf.has(l)||pp(s))continue;if(l==="br"){t.text+=`
9
- `;continue}const c=t.mode==="collapse"&&$f.has(l);if(c&&Ml(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})}},mp=(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&&wp(l.element,t,n,r)},gp=(e,t)=>{const n=e.replaceAll(qf," ");if(t==="pre")return n;const r=n.split(`
7
+ `)},Cp=e=>{const t=e.getAttribute("style");return t!==null&&eo(t).get("mso-spacerun")==="yes"},yp=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){qf.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&Nl(t);continue}const o=r.node;if(o.nodeType===_f){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!==If)continue;const s=o,l=s.localName;if(Lf.has(l)||Cp(s))continue;if(l==="br"){t.text+=`
9
+ `;continue}const c=t.mode==="collapse"&&Pf.has(l);if(c&&Nl(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})}},bp=(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&&Rp(l.element,t,n,r)},vp=(e,t)=>{const n=e.replaceAll(Bf," ");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
- `)},wp=(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)}Xo(t,yc(e,r))},Cp=(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"?pc(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<Tl.length?Tl[l]:null}return null},bc=(e,t,n)=>t!==void 0&&mc(t)?xf(e,t,n):e,yp=(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!==""&&Xe(c)!==null)if(n!==void 0&&n.type==="date"){const u=pc(Number(c));if(u!==null)return u}else return c;return bc(t,n,r)},bp=(e,t,n,r)=>{const o=yc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:up(o)};for(const m of Sp(e))hp(m,l);mp(l,o,s,r.rules);const c=gp(l.text,l.mode),u=fp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),y=m===null?void 0:yf(m,r.options);y!==void 0&&(u.value=y);const q=e.getAttribute("data-sheets-value"),H=q===null?null:Cp(q,y);h.t=H===null?bc(c,y,ac):H;const z=e.getAttribute("data-sheets-formula");z?.startsWith("=")&&(h.f=z);const _=e.getAttribute("data-sheets-hyperlink"),K=_!==null?_:l.href,B=K===null?null:Bt(K);B!==null&&(h.link=B);const x=e.getAttribute("data-sheets-note");x!==null&&x!==""&&(h.note=x)}else{const m=o.get("mso-number-format"),y=m===void 0?void 0:ms(Uo(jr(m)),r.options);y!==void 0&&(u.value=y),h.t=yp(e,c,y,r.separators);const q=e.getAttribute("x:fmla");q?.startsWith("=")&&(h.f=Ur(q,{row:t,col:n}));const H=l.href===null?null:Bt(l.href);H!==null&&(h.link=H)}return{cell:h,format:u}},Go=(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},vp=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)},Rp=(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]))},vc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Gr(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:vp(l);if(c!==null)return Math.min(c,En)}const o=Rp(e,t);return o===null?null:Math.min(o,En)},kp=(e,t)=>{const n=[],r=o=>{const s=vc(o,"width");for(let l=Go(o,"span",as);l>0&&n.length<t;l-=1)n.push(s)};for(const o of er(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of er(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*er(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Sp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Ep(e){for(const t of["thead","tbody","tfoot"])for(const n of er(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of er(n))o.localName==="tr"&&(yield o)}}const To=()=>({t:""}),xp=(e,t,n)=>{const r=_i(),o=[],s=[],l=[];let c=0;for(const H of Ep(e)){const z=o.length,_=(z+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const K=[];for(let x=0;x<l.length;x+=1)l[x]>0&&(K[x]=To(),l[x]-=1);let B=0;for(const x of er(H)){const $=x.localName;if($!=="td"&&$!=="th")continue;for(;K[B]!==void 0;)B+=1;const L=Go(x,"colspan",as),S=Go(x,"rowspan",$i),v=(z+1)*Math.max(c,B+L);if(v>n)return{outcome:"limit",cells:v};const E=bp(x,z,B,t),p=r.intern(E.format);p!==void 0&&(E.cell.fmt=p),K[B]=E.cell;for(let g=1;g<L;g+=1)K[B+g]===void 0&&(K[B+g]=To());if(S>1)for(let g=0;g<L;g+=1){const b=S-1,D=B+g;l[D]=l[D]===void 0||l[D]<b?b:l[D]}B+=L}K.length>c&&(c=K.length),o.push(K),s.push(vc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const z=[];for(let _=0;_<c;_+=1){const K=H[_];z.push(K===void 0?To():K)}return z}),h=kp(e,c),m=h.length===c&&h.every(H=>H!==null)?h.map(H=>H===null?0:H):void 0,y=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:is(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...y===void 0?{}:{rowHeights:y},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Rc=(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=If(o);return xp(s,{kind:t,rules:l,options:n,separators:l.separators},r)},pe=(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)}),rn=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,Ge=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),ct=e=>e.reduce((t,n)=>t+Ge(n).rows*Ge(n).cols,0),qt=(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}))}},lr=(e,t,n)=>{if(t<=0||n<=0)throw new RangeError(`[spreadsheet] clampCoord requires a non-empty grid, received ${t} x ${n}`);return{row:Math.min(Math.max(Math.trunc(e.row),0),t-1),col:Math.min(Math.max(Math.trunc(e.col),0),n-1)}},kt=(e,t)=>e.row===t.row&&e.col===t.col,kc=(e,t)=>e===void 0?il(void 0,void 0,t()):il(e.align,e.value,e.align===void 0?t():""),Pr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},On=(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}},qr=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}),Sc=e=>e.isCellReadOnly!==void 0,_e=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Kn=(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},yn=(e,t)=>{for(const n of t)if(Kn(e,n))return!0;return!1},Ap=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=Ge(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Zo=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=Ge(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},y=Math.min(u,r-m.row),q=Math.min(h,o-m.col);return y<=0||q<=0?null:pe(m,{row:m.row+y-1,col:m.col+q-1})},Ec=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=Zo({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,y=u.endCol-u.startCol+1,q=[];for(let H=0;H<m;H+=l){const z=[];for(let K=0;K<y;K+=c){const B={row:h.row+H,col:h.col+K};z.push(B),q.push(B)}const _=Math.min(l,m-H);for(let K=0;K<_;K+=1){const B=h.row+H+K,x=e[K];for(let $=0;$<z.length;$+=1){const L=$*c,S=Math.min(c,y-L);for(let v=0;v<S;v+=1)s(B,h.col+L+v,x[v],z[$])}}}return q},Op=(e,t,n,r,o)=>{const s=[];return Ec(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},$l=(e,t,n,r,o,s)=>{const l=[],c=Ec(e,t,n,r,o,(u,h,m,y)=>{const q=s(m,u,h,y);q!==null&&l.push({...q,row:u,col:h})});return{edits:l,tiles:c}},xc=(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)})`)},Tp=(e,t)=>{xc(e,t);const n=Ge(t),r=Ge(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},Dp=(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(pe({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(pe({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(pe({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(pe({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Mp=(e,t,n,r)=>{xc(t,n);const o=Ge(t).rows,s=Ge(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let y=n.startCol;y<=n.endCol;y+=1){if(m&&y>=t.startCol&&y<=t.endCol)continue;const q=t.startCol+((y-t.startCol)%s+s)%s,H=h*2**21+q;let z=c.get(H);z===void 0&&(z={value:e(h,q),origin:{row:h,col:q}},c.set(H,z)),l.push(r(z.value,z.origin,{row:u,col:y}))}}return l},Ac=(e,t,n)=>{const r=On(e,t,n),o={text:r.text,isFormula:r.isFormula};if(e.getCellFormat!==void 0){const s=e.getCellFormat(t,n);o.format=s===void 0?null:ot(s)}if(e.getCellValidation!==void 0){const s=e.getCellValidation(t,n);o.validation=s===void 0?null:s}if(e.getCellHyperlink!==void 0){const s=Tn(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},Oc=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?tc(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},Tc=e=>`${e.map(t=>t.map($p).join(" ")).join(`\r
12
+ `)},Rp=(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)}Zo(t,kc(e,r))},kp=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?wc(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<Fl.length?Fl[l]:null}return null},Sc=(e,t,n)=>t!==void 0&&yc(t)?Mf(e,t,n):e,Sp=(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!==""&&et(c)!==null)if(n!==void 0&&n.type==="date"){const u=wc(Number(c));if(u!==null)return u}else return c;return Sc(t,n,r)},Ep=(e,t,n,r)=>{const o=kc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:gp(o)};for(const g of Tp(e))yp(g,l);bp(l,o,s,r.rules);const c=vp(l.text,l.mode),u=wp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),C=g===null?void 0:Sf(g,r.options);C!==void 0&&(u.value=C);const q=e.getAttribute("data-sheets-value"),j=q===null?null:kp(q,C);h.t=j===null?Sc(c,C,pc):j;const z=e.getAttribute("data-sheets-formula");z?.startsWith("=")&&(h.f=z);const I=e.getAttribute("data-sheets-hyperlink"),Y=I!==null?I:l.href,H=Y===null?null:Bt(Y);H!==null&&(h.link=H);const $=e.getAttribute("data-sheets-note");$!==null&&$!==""&&(h.note=$)}else{const g=o.get("mso-number-format"),C=g===void 0?void 0:Cs(Jo(Wr(g)),r.options);C!==void 0&&(u.value=C),h.t=Sp(e,c,C,r.separators);const q=e.getAttribute("x:fmla");q?.startsWith("=")&&(h.f=Zr(q,{row:t,col:n}));const j=l.href===null?null:Bt(l.href);j!==null&&(h.link=j)}return{cell:h,format:u}},Qo=(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},Ap=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)},xp=(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]))},Ec=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:eo(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:Ap(l);if(c!==null)return Math.min(c,Dn)}const o=xp(e,t);return o===null?null:Math.min(o,Dn)},Op=(e,t)=>{const n=[],r=o=>{const s=Ec(o,"width");for(let l=Qo(o,"span",fs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of or(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of or(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*or(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Tp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Dp(e){for(const t of["thead","tbody","tfoot"])for(const n of or(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of or(n))o.localName==="tr"&&(yield o)}}const $o=()=>({t:""}),Mp=(e,t,n)=>{const r=Bi(),o=[],s=[],l=[];let c=0;for(const j of Dp(e)){const z=o.length,I=(z+1)*Math.max(c,1);if(I>n)return{outcome:"limit",cells:I};const Y=[];for(let $=0;$<l.length;$+=1)l[$]>0&&(Y[$]=$o(),l[$]-=1);let H=0;for(const $ of or(j)){const T=$.localName;if(T!=="td"&&T!=="th")continue;for(;Y[H]!==void 0;)H+=1;const P=Qo($,"colspan",fs),S=Qo($,"rowspan",Li),v=(z+1)*Math.max(c,H+P);if(v>n)return{outcome:"limit",cells:v};const E=Ep($,z,H,t),p=r.intern(E.format);p!==void 0&&(E.cell.fmt=p),Y[H]=E.cell;for(let m=1;m<P;m+=1)Y[H+m]===void 0&&(Y[H+m]=$o());if(S>1)for(let m=0;m<P;m+=1){const y=S-1,M=H+m;l[M]=l[M]===void 0||l[M]<y?y:l[M]}H+=P}Y.length>c&&(c=Y.length),o.push(Y),s.push(Ec(j,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(j=>{const z=[];for(let I=0;I<c;I+=1){const Y=j[I];z.push(Y===void 0?$o():Y)}return z}),h=Op(e,c),g=h.length===c&&h.every(j=>j!==null)?h.map(j=>j===null?0:j):void 0,C=s.every(j=>j!==null)?s.map(j=>j===null?0:j):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:us(),formats:[...r.entries],validations:[],cells:u,...g===void 0?{}:{colWidths:g},...C===void 0?{}:{rowHeights:C},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Ac=(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=Wf(o);return Mp(s,{kind:t,rules:l,options:n,separators:l.separators},r)},he=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),an=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,tt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),wt=e=>e.reduce((t,n)=>t+tt(n).rows*tt(n).cols,0),qt=(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}))}},Vt=(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)}},At=(e,t)=>e.row===t.row&&e.col===t.col,xc=(e,t)=>e===void 0?dl(void 0,void 0,t()):dl(e.align,e.value,e.align===void 0?t():""),jr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Fn=(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}},Hr=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}),Oc=e=>e.isCellReadOnly!==void 0,Be=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,$p=/^data-[a-z0-9-]+$/,Fp=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},zp=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Fp(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(!$p.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},Gn=(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},Sn=(e,t)=>{for(const n of t)if(Gn(e,n))return!0;return!1},Np=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=tt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},es=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=tt(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},C=Math.min(u,r-g.row),q=Math.min(h,o-g.col);return C<=0||q<=0?null:he(g,{row:g.row+C-1,col:g.col+q-1})},Tc=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=es({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},g=u.endRow-u.startRow+1,C=u.endCol-u.startCol+1,q=[];for(let j=0;j<g;j+=l){const z=[];for(let Y=0;Y<C;Y+=c){const H={row:h.row+j,col:h.col+Y};z.push(H),q.push(H)}const I=Math.min(l,g-j);for(let Y=0;Y<I;Y+=1){const H=h.row+j+Y,$=e[Y];for(let T=0;T<z.length;T+=1){const P=T*c,S=Math.min(c,C-P);for(let v=0;v<S;v+=1)s(H,h.col+P+v,$[v],z[T])}}}return q},Lp=(e,t,n,r,o)=>{const s=[];return Tc(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},Ll=(e,t,n,r,o,s)=>{const l=[],c=Tc(e,t,n,r,o,(u,h,g,C)=>{const q=s(g,u,h,C);q!==null&&l.push({...q,row:u,col:h})});return{edits:l,tiles:c}},Dc=(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)})`)},Pp=(e,t)=>{Dc(e,t);const n=tt(t),r=tt(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},qp=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(he({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(he({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(he({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(he({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},_p=(e,t,n,r)=>{Dc(t,n);const o=tt(t).rows,s=tt(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 C=n.startCol;C<=n.endCol;C+=1){if(g&&C>=t.startCol&&C<=t.endCol)continue;const q=t.startCol+((C-t.startCol)%s+s)%s,j=h*2**21+q;let z=c.get(j);z===void 0&&(z={value:e(h,q),origin:{row:h,col:q}},c.set(j,z)),l.push(r(z.value,z.origin,{row:u,col:C}))}}return l},Mc=(e,t,n)=>{const r=Fn(e,t,n),o={text:r.text,isFormula:r.isFormula};if(e.getCellFormat!==void 0){const s=e.getCellFormat(t,n);o.format=s===void 0?null:dt(s)}if(e.getCellValidation!==void 0){const s=e.getCellValidation(t,n);o.validation=s===void 0?null:s}if(e.getCellHyperlink!==void 0){const s=zn(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},$c=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?sc(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},Fc=e=>`${e.map(t=>t.map(Ip).join(" ")).join(`\r
13
13
  `)}\r
14
- `,$p=e=>/[\t\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e,Dc=e=>e.endsWith(`\r
14
+ `,Ip=e=>/[\t\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e,zc=e=>e.endsWith(`\r
15
15
  `)?e.slice(0,-2):e.endsWith(`
16
- `)||e.endsWith("\r")?e.slice(0,-1):e,Mc=(e,t,n)=>{let r=0;for(;;){let o;if(e[r]==='"'){const s=zp(e,r);if(s!==null)o=s.value,r=s.nextIndex;else{const l=Fl(e,r);o=e.slice(r,l),r=l}}else{const s=Fl(e,r);o=e.slice(r,s),r=s}if(t(o),r>=e.length){n();return}e[r]===" "?r+=1:(r+=e[r]==="\r"&&e[r+1]===`
17
- `?2:1,n())}},$c=e=>{const t=Dc(e);if(t==="")return[[""]];const n=[];let r=[];Mc(t,s=>{r.push(s)},()=>{n.push(r),r=[]});let o=0;for(const s of n)s.length>o&&(o=s.length);return n.map(s=>s.length===o?s:[...s,...Array(o-s.length).fill("")])},Fp=e=>{const t=Dc(e);if(t==="")return{rows:1,cols:1};let n=0,r=0,o=0;return Mc(t,()=>{o+=1},()=>{n+=1,o>r&&(r=o),o=0}),{rows:n,cols:r}},zp=(e,t)=>{let n="",r=t+1;for(;r<e.length;)if(e[r]==='"')if(e[r+1]==='"')n+='"',r+=2;else{const o=r+1;return(o>=e.length||e[o]===" "||e[o]===`
18
- `||e[o]==="\r")&&/[\t\r\n]/.test(n)?{value:n,nextIndex:o}:null}else n+=e[r],r+=1;return null},Fl=(e,t)=>{for(let n=t;n<e.length;n+=1)if(e[n]===" "||e[n]===`
19
- `||e[n]==="\r")return n;return e.length},Zn=e=>{if(!(Number.isInteger(e)&&e>=0))throw new RangeError(`[spreadsheet] columnIndexToName requires a non-negative integer, received ${e}`);let t="",n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.trunc(n/26)-1;return t},Np=e=>{if(!/^[A-Z]+$/.test(e))throw new RangeError(`[spreadsheet] columnNameToIndex requires /^[A-Z]+$/, received "${e}"`);let t=0;for(const n of e)t=t*26+(n.charCodeAt(0)-64);return t-1},Zr=["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","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"],Lp=/^[A-Z]$/,Pp=/^[A-Za-z]$/,qp=/^Key([A-Z])$/,Fc=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"]),_p=e=>Lp.test(e)||Fc.has(e),Qt=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!_p(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}},Ip=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,zc=e=>{if(Pp.test(e.key))return e.key.toUpperCase();const t=qp.exec(e.code);return t!==null?t[1]:Fc.has(e.code)?e.code:null},In=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:zc(t)===e.key,de=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ye=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),jp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(de(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(de(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(de(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(de(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Hp=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(de(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(de(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},ir=[...jp(),de("Home","idle","row start (first visible column)"),de("Ctrl+Home","idle","first visible cell"),de("Shift+Home","idle","extend to row start"),de("Ctrl+Shift+Home","idle","extend to first visible cell"),de("End","idle","row end (last visible column)"),de("Ctrl+End","idle","last visible cell"),de("Shift+End","idle","extend to row end"),de("Ctrl+Shift+End","idle","extend to last visible cell"),de("PageUp","both","page up (idle) / commit + page up (editing)"),de("PageDown","both","page down (idle) / commit + page down (editing)"),de("Shift+PageUp","idle","extend one page up"),de("Shift+PageDown","idle","extend one page down"),de("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),de("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),de("Tab","both","cycle right (idle) / commit + cycle right (editing)"),de("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),de("Enter","both","cycle down (idle) / commit + cycle down (editing)"),de("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),de("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),de("F2","both","start editing (idle) / toggle the pointing arm (editing)"),de("F4","editing","cycle the reference anchor under the caret (formula session)"),de("Delete","idle","clear every selected cell"),de("Backspace","idle","clear every selected cell"),de("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),de("Ctrl+A","idle","select all"),de("Ctrl+Z","idle","undo request"),de("Ctrl+Y","idle","redo request"),de("Ctrl+Shift+Z","idle","redo request"),de("Shift+F10","idle","keyboard context menu"),de("ContextMenu","idle","keyboard context menu"),de("Ctrl+Space","idle","column bands"),de("Shift+Space","idle","row bands"),de("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),de("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),de("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),de("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"},...Hp(),ye("bold","Ctrl+B","both","toggle bold"),ye("italic","Ctrl+I","both","toggle italic"),ye("underline","Ctrl+U","both","toggle underline"),ye("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ye("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ye("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ye("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ye("alignLeft","Ctrl+Shift+L","both","align left"),ye("alignCenter","Ctrl+Shift+E","both","align center"),ye("alignRight","Ctrl+Shift+R","both","align right"),ye("formatNumber","Ctrl+Shift+Digit1","both","number format"),ye("formatTime","Ctrl+Shift+Digit2","both","time format"),ye("formatDate","Ctrl+Shift+Digit3","both","date format"),ye("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ye("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ye("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ye("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ye("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ye("borderTop","Alt+Shift+Digit1","idle","top border"),ye("borderRight","Alt+Shift+Digit2","idle","right border"),ye("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ye("borderLeft","Alt+Shift+Digit4","idle","left border"),ye("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ye("insertNote","Shift+F2","idle","insert / edit note"),ye("insertComment","Ctrl+Alt+M","idle","insert comment"),ye("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ye("openValidationList","Alt+ArrowDown","idle","open the validation list"),ye("fillDown","Ctrl+D","idle","fill down"),ye("fillRight","Ctrl+R","idle","fill right"),ye("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ye("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ye("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ye("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ye("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ye("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],Hr=(e,t)=>e.column==="both"||e.column===t,Bp=Array.from(new Set(ir.filter(e=>!e.rebindable&&Hr(e,"idle")).map(e=>e.chord))),Cs=new Set(ir.filter(e=>e.command!==void 0&&Hr(e,"editing")).map(e=>e.command)),Vp=new Set(ir.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Nc=e=>{const t={};for(const n of Zr)t[n]=e(n);return t},Lc=Nc(e=>ir.filter(t=>t.command===e).map(t=>t.chord)),Wp=e=>{const t=new Map;for(const n of Zr){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},Kp=e=>{const t=new Set(Zr);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(Vp.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`)}}}},Yp=(e,t)=>{const n=Qt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Cs.has(e);for(const o of ir)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Hr(o,"idle")||r&&Hr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Up=e=>{e!==void 0&&Kp(e);const t=Nc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Lc[r]:o===null?[]:o});for(const r of Zr)for(const o of t[r])Yp(r,o);const n=new Map;for(const[r,o]of Wp(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},zl=(e,t)=>{const n=zc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Ip({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},Xp=Object.freeze({ok:!0}),Gp="TRUE",Zp="FALSE",Jp=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Qp=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),eh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,th=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,nh=/^[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])?)+$/,Nl={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},rh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Ll=e=>{const t=e.trim();if(!(eh.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,y=m.search(/[^0]/);return y<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(y).replace(/0+$/,""),point:u.length+l-y}},oh=e=>e===1?-1:e===-1?1:0,sh=(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:oh(n)},lh=(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}},Pl=e=>{const t=th.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>lh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},ih=(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},ch=(e,t)=>e<t?-1:e>t?1:0,ah=e=>e==="between"||e==="notBetween",uh=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!ah(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},dh=(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}},Do=(e,t,n,r,o,s)=>{const l=uh(e,t,n,r);return l===null?!0:o===null?!1:dh(e,s(o,l.a),l.b===null?0:s(o,l.b))},fh=e=>Number.isFinite(e)?e:null,ph=e=>{let t=0;for(const n of e)t+=1;return t},hh=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),mh=(e,t)=>{switch(e.op){case"isEmail":return nh.test(t);case"isUrl":return hh(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)}},gh=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Pc=e=>({checked:e.checked===void 0?Gp:e.checked,unchecked:e.unchecked===void 0?Zp:e.unchecked}),wh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Jp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "${e.type}"`);return;case"text":if(!Qp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type "${String(e.type)}"`)}},Ch=(e,t,n)=>{switch(e.type){case"list":return vh(e).has(t);case"number":return Do(e.op,e.a,e.b,Ll,Ll(t),sh);case"textLength":return Do(e.op,e.a,e.b,fh,ph(t),ch);case"date":return Do(e.op,e.a,e.b,Pl,Pl(t),ih);case"text":return mh(e,t);case"checkbox":{const r=Pc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||gh(n(e.formula))}},qc=(e,t,n)=>(wh(e),t===""||Ch(e,t,n)),Mo=(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}`}},ql=e=>e===void 0?void 0:e.trim(),yh=e=>{switch(e.type){case"list":return"Value must be one of the list items.";case"number":return`Value must be a number ${Mo(e.op,e.a.trim(),ql(e.b),Nl)}.`;case"textLength":return`Text length must be ${Mo(e.op,String(e.a),e.b===void 0?void 0:String(e.b),Nl)}.`;case"date":return`Value must be a date ${Mo(e.op,e.a.trim(),ql(e.b),rh)}.`;case"text":return bh(e);case"checkbox":{const t=Pc(e);return`Value must be "${t.checked}" or "${t.unchecked}".`}default:return`Value does not satisfy the formula ${e.formula}.`}},bh=e=>{switch(e.op){case"contains":return`Value must contain "${e.value}".`;case"notContains":return`Value must not contain "${e.value}".`;case"startsWith":return`Value must start with "${e.value}".`;case"endsWith":return`Value must end with "${e.value}".`;case"isEmail":return"Value must be a valid email address.";default:return"Value must be a valid URL."}},_l=new WeakMap,vh=e=>{const t=_l.get(e);if(t!==void 0)return t;const n=new Set(e.values);return _l.set(e,n),n},_c=(e,t,n)=>qc(e,t,n)?Xp:{ok:!1,message:e.errorMessage===void 0?yh(e):e.errorMessage},Rh=e=>e.type!=="custom",kh=(e,t)=>Rh(e)&&!qc(e,t,void 0),Sh=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","validationRejected","popoverClose","indicatorNote","indicatorComment","indicatorInvalid"],Jo=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",validationRejected:"The value does not satisfy this cell's validation rule",popoverClose:"Close",indicatorNote:"Has a note",indicatorComment:"Has comments",indicatorInvalid:"Invalid value"}),Eh=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 ${JSON.stringify(t)}`)},xh=(e,t,n)=>{e[t]=n},Ah=e=>{if(e===void 0)return Jo;const t={...Jo};for(const n of Sh){const r=e[n];r!==void 0&&xh(t,n,r)}return Eh(t),Object.freeze(t)},De=(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},Ic=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),jc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Hc=(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,Bc=(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),Vc=(e,t)=>Ic(e,t),Wc=(e,t)=>Ic(e,t),Kc=(e,t)=>jc(e,t),Yc=(e,t)=>jc(e,t),tn=(e,t,n)=>Hc(e,t,n),nn=(e,t,n)=>Hc(e,t,n),cr=(e,t,n)=>Bc(e,t,n),ar=(e,t,n)=>Bc(e,t,n),rt=12,Oh=()=>{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)})}},Th=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Pt=1,Yn=3,kr=e=>`${-Math.min(Yn,Math.max(0,Math.floor(e)))}px`,Uc=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Dh=16,Mh=450,$h=e=>e>4?Math.floor(Mh/(5*e)):Dh,jn=(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},Il=()=>({rowLeft:jn("row","left"),rowRight:jn("row","right"),colAbove:jn("column","above"),colBelow:jn("column","below"),cross:jn("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Xc=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Sr=(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},Er=(e,t)=>Math.min(Math.max(e,0),t),jl="inset(100%)",Rn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Fh=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Rn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const q=`${t.height}px`;e.rowLeft.style.height=q,e.rowRight.style.height=q}const m=`translate(${Er(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const y=`translate(${Er(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;y!==s.rowRightTransform&&(s.rowRightTransform=y,e.rowRight.style.transform=y)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Rn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const q=`${t.width}px`;e.colAbove.style.width=q,e.colBelow.style.width=q}const m=`translate(${t.left}px, ${Er(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const y=`translate(${t.left}px, ${Er(t.top+t.height,n.clampHeight)}px)`;y!==s.colBelowTransform&&(s.colBelowTransform=y,e.colBelow.style.transform=y)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Rn([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--aqsp-band-${u})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const m=`translate(${t.left}px, ${t.top}px)`;m!==s.crossTransform&&(s.crossTransform=m,e.cross.style.transform=m)}},Hl=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Rn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Rn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Rn([e.cross],!1))},Bl=e=>{for(const t of Xc(e))t.remove()},zh=(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)},Nh=Object.freeze([]),Vl=e=>e.dividers[0]??e.active,Lh={left:"0px",right:"0px",width:""},Ph={top:"0px",bottom:"0px",height:""},Wl=()=>({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:[]}),Kl=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Yl=6,qh=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:y,fillFrameRef:q,resizeGuideFrameRef:H,fillHandleNodeRef:z,enableFillHandle:_,frozenCols:K,frozenRows:B,trailingCols:x,trailingRows:$,sinkAriaLabel:L,onSinkMouseDown:S,editPaintRef:v,highlightRef:E,highlightColors:p,popoverAnchors:g,interactiveAnchorRef:b,tipAnchorRef:D})=>{const A=i.useRef(null),k=i.useRef(null),w=i.useRef(null),R=i.useRef(new Map(Kl.map(P=>[P,Wl()]))),a=i.useCallback(P=>{const I=R.current.get(P);if(I!==void 0)return I;const G=Wl();return R.current.set(P,G),G},[]),f=i.useCallback((P,I,G)=>{if(P===null)return;const j=P.style;j.left!==I.left&&(j.left=I.left),j.right!==I.right&&(j.right=I.right),j.width!==I.width&&(j.width=I.width),j.top!==G.top&&(j.top=G.top),j.bottom!==G.bottom&&(j.bottom=G.bottom),j.height!==G.height&&(j.height=G.height)},[]),O=i.useCallback((P,I,G)=>{if(!(P.bandClampWidth===I&&P.bandClampHeight===G)){P.bandClampWidth=I,P.bandClampHeight=G;for(const j of P.bandPool)Sr(j,I,G);P.dragBand!==null&&Sr(P.dragBand,I,G)}},[]),d=i.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const F=i.useCallback((P,I,G)=>{const j=P.dividerSlots[I];j===null||P.dividerShown[I]===G||(P.dividerShown[I]=G,j.style.display=G?"":"none")},[]),M=i.useRef({x:0,y:0}),T=i.useRef(null),N=i.useCallback((P,I)=>{const G=n.current,j=G?.getFrozenSize()??Th,U=G?.getViewportSize(),te=U?.width??-1,ce=U?.height??-1,ke=M.current;ke.x=P,ke.y=I;let ge=T.current;if(ge===null||ge.frozenCols!==j.cols||ge.frozenWidth!==j.width||ge.frozenRows!==j.rows||ge.frozenHeight!==j.height||ge.trailingCols!==j.trailingCols||ge.trailingWidth!==j.trailingWidth||ge.trailingVisibleWidth!==j.trailingVisibleWidth||ge.trailingRows!==j.trailingRows||ge.trailingHeight!==j.trailingHeight||ge.trailingVisibleHeight!==j.trailingVisibleHeight||ge.bodyWidth!==te||ge.bodyHeight!==ce){const ne=j.trailingVisibleWidth,ae=j.trailingVisibleHeight,ue=j.cols<=0&&j.trailingCols<=0?[{kind:"m",map:Ce=>Ce-ke.x,clamp:te,style:Lh,seamLead:!1,seamTrail:!1}]:[...j.cols>0?[{kind:"f",map:Ce=>Ce,clamp:j.width,style:{left:"0px",width:`${j.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-ke.x-j.width,clamp:Math.max(0,te-j.width-ne),style:{left:`${j.width}px`,right:`${ne}px`,width:""},seamLead:j.cols>0,seamTrail:j.trailingCols>0},...j.trailingCols>0?[{kind:"t",map:Ce=>Ce-d.current.colAxis.totalSize()+ne,clamp:ne,style:{left:"",right:"0px",width:`${ne}px`},seamLead:!0,seamTrail:!1}]:[]],fe=j.rows<=0&&j.trailingRows<=0?[{kind:"m",map:Ce=>Ce-ke.y,clamp:ce,style:Ph,seamLead:!1,seamTrail:!1}]:[...j.rows>0?[{kind:"f",map:Ce=>Ce,clamp:j.height,style:{top:"0px",height:`${j.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-ke.y-j.height,clamp:Math.max(0,ce-j.height-ae),style:{top:`${j.height}px`,bottom:`${ae}px`,height:""},seamLead:j.rows>0,seamTrail:j.trailingRows>0},...j.trailingRows>0?[{kind:"t",map:Ce=>Ce-d.current.rowAxis.totalSize()+ae,clamp:ae,style:{top:"",bottom:"0px",height:`${ae}px`},seamLead:!0,seamTrail:!1}]:[]],ie=[];for(const Ce of ue)for(const we of fe)ie.push({nodes:a(`${Ce.kind}${we.kind}`),xKind:Ce.kind,yKind:we.kind,mapX:Ce.map,clampWidth:Ce.clamp,xStyle:Ce.style,xSeamLead:Ce.seamLead,xSeamTrail:Ce.seamTrail,mapY:we.map,clampHeight:we.clamp,yStyle:we.style,ySeamLead:we.seamLead,ySeamTrail:we.seamTrail});ge={frozenCols:j.cols,frozenWidth:j.width,frozenRows:j.rows,frozenHeight:j.height,trailingCols:j.trailingCols,trailingWidth:j.trailingWidth,trailingVisibleWidth:j.trailingVisibleWidth,trailingRows:j.trailingRows,trailingHeight:j.trailingHeight,trailingVisibleHeight:j.trailingVisibleHeight,bodyWidth:te,bodyHeight:ce,ctxs:ie},T.current=ge}const qe=j.width>0,Le=j.trailingWidth>0,Pe=j.height>0,Fe=j.trailingHeight>0;for(const ne of ge.ctxs)f(ne.nodes.container,ne.xStyle,ne.yStyle),O(ne.nodes,ne.clampWidth,ne.clampHeight),F(ne.nodes,0,qe),F(ne.nodes,1,Le),F(ne.nodes,2,Pe),F(ne.nodes,3,Fe);return ge.ctxs},[n,a,f,O,F]),V=i.useCallback((P,I,G)=>{P.dividerSlots[I]=G,P.dividerShown[I]=!1,P.dividers.length=0;for(const j of P.dividerSlots)j!==null&&P.dividers.push(j)},[]),X=i.useCallback(P=>{const I=()=>a(P);return{container:G=>{const j=I();j.container=G,G===null&&(j.fillPool.length=0,j.bandPool.length=0,j.dragBand=null,j.bandClampWidth=-1,j.bandClampHeight=-1)},dividerXLeading:G=>V(I(),0,G),dividerXTrailing:G=>V(I(),1,G),dividerYLeading:G=>V(I(),2,G),dividerYTrailing:G=>V(I(),3,G),active:G=>{I().active=G},dragRect:G=>{I().dragRect=G},marquee:G=>{I().marquee=G},fillPreview:G=>{I().fillPreview=G},resizeGuide:G=>{I().resizeGuide=G}}},[a,V]),J=i.useMemo(()=>Object.fromEntries(Kl.map(P=>[P,X(P)])),[X]),Q=Math.min(Math.max(0,K),t.count),Z=Vc(t,Q),se=Math.min(Math.max(0,B),e.count),re=Wc(e,se),ve=x===void 0?0:Math.min(Math.max(0,x),t.count-Q),Me=Kc(t,ve),Te=$===void 0?0:Math.min(Math.max(0,$),e.count-se),Ne=Yc(e,Te),at=i.useRef(null),st=i.useRef("add"),ut=i.useRef(s);ut.current=s;const he=i.useRef(!1),me=nr.useWheelBridge(n,{enableBridge:!s}),Dn=i.useCallback(P=>(r.current=P,me(P)),[r,me]),be=i.useCallback((P,I)=>({top:I.mapY(e.offsetOf(P.startRow)),bottom:I.mapY(e.offsetOf(P.endRow)+e.sizeOf(P.endRow)),left:I.mapX(t.offsetOf(P.startCol)),right:I.mapX(t.offsetOf(P.endCol)+t.sizeOf(P.endCol))}),[e,t]),We=i.useCallback((P,I)=>{if(I.clampHeight<=0||I.clampWidth<=0)return null;const{top:G,bottom:j,left:U,right:te}=be(P,I),ce=-I.clampHeight*Pt,ke=I.clampHeight*(1+Pt),ge=-I.clampWidth*Pt,qe=I.clampWidth*(1+Pt);if(j<ce||G>ke||te<ge||U>qe)return null;const Le=Math.max(G,ce),Pe=Math.max(U,ge);return{top:Le,left:Pe,width:Math.min(te,qe)-Pe,height:Math.min(j,ke)-Le}},[be]),Mn=i.useCallback((P,I)=>{if(I.clampHeight<=0||I.clampWidth<=0)return null;const G=be(P,I),j=-I.clampHeight*Pt,U=I.clampHeight*(1+Pt),te=-I.clampWidth*Pt,ce=I.clampWidth*(1+Pt),ke=Math.min(Math.max(G.top,j),U),ge=Math.min(Math.max(G.left,te),ce);return{top:ke,left:ge,width:Math.min(Math.max(G.right,te),ce)-ge,height:Math.min(Math.max(G.bottom,j),U)-ke}},[be]),on=i.useCallback(()=>{if(E===void 0)return null;const P=E.current;return P.row||P.column||P.intersection?P:null},[E]),sn=i.useCallback((P,I,G)=>{const j=I.fillPool[0]?.node??Vl(I);for(const U of Xc(G))P.insertBefore(U,j)},[]),Vt=i.useCallback((P,I,G,j)=>{const U=Mn(I,G);if(U===null){Hl(P);return}Fh(P,U,G,j,Ii(I,t.count)||ji(I,e.count))},[Mn,e,t]),ur=i.useCallback((P,I,G,j)=>{const U=P.nodes.bandPool;for(;U.length>G.length;){const te=U.pop();te!==void 0&&Bl(te)}if(j===null){P.nodes.dragBand!==null&&(Bl(P.nodes.dragBand),P.nodes.dragBand=null);return}for(let te=0;te<G.length;te+=1){let ce=U[te];ce===void 0&&(ce=Il(),Sr(ce,P.clampWidth,P.clampHeight),sn(I,P.nodes,ce),U.push(ce)),Vt(ce,G[te],P,j)}},[sn,Vt]),$n=i.useCallback((P,I,G)=>{const j=P.nodes.container;if(j===null)return;if(I===null||G===null){P.nodes.dragBand!==null&&Hl(P.nodes.dragBand);return}let U=P.nodes.dragBand;U===null&&(U=Il(),Sr(U,P.clampWidth,P.clampHeight),sn(j,P.nodes,U),P.nodes.dragBand=U),Vt(U,I,P,G)},[sn,Vt]),Et=i.useCallback((P,I)=>{if(P!==null){if(I===null){P.style.display="none";return}P.style.display="block",P.style.transform=`translate(${I.left}px, ${I.top}px)`,P.style.width=`${I.width}px`,P.style.height=`${I.height}px`}},[]),xt=i.useCallback((P,I,G,j)=>{const U=j==="point"?null:on();for(const te of N(G,I))Et(te.nodes.dragRect,We(P,te)),$n(te,P,U)},[We,N,Et,on,$n]),dt=i.useCallback((P,I,G)=>{for(const j of N(G,I))Et(j.nodes.fillPreview,P===null?null:We(P,j))},[We,N,Et]),At=i.useCallback((P,I,G)=>{for(const j of N(G,I)){const U=j.nodes.resizeGuide;if(U===null)continue;if(P===null){U.style.display="none";continue}const te=P.anchor==="trailing";if(P.axis==="col"){if(te&&j.xKind!=="t"){U.style.display="none";continue}U.style.display="block";const ce=j.mapX(P.position);U.style.transform=`translate(${te?Math.max(0,ce):ce}px, 0px)`,U.style.width="1px",U.style.height="100%"}else{if(te&&j.yKind!=="t"){U.style.display="none";continue}U.style.display="block";const ce=j.mapY(P.position);U.style.transform=`translate(0px, ${te?Math.max(0,ce):ce}px)`,U.style.width="100%",U.style.height="1px"}}},[N]),Wt=i.useCallback((P,I,G,j,U,te,ce)=>{if(P===null)return;if(I===null||ce<=0||te<=0){P.style.clipPath=jl;return}const ke=nn(e,I.row,j),ge=tn(t,I.col,G),qe=t.sizeOf(I.col),Le=e.sizeOf(I.row),Pe=ge>=te||ke>=ce,Fe=I.col>=U.cols&&ge<U.width,ne=I.row>=U.rows&&ke<U.height,ae=U.trailingWidth>0&&I.col<t.count-U.trailingCols&&ge+qe>te-U.trailingVisibleWidth,ue=U.trailingHeight>0&&I.row<e.count-U.trailingRows&&ke+Le>ce-U.trailingVisibleHeight;if(Pe||Fe||ne||ae||ue){P.style.clipPath=jl;return}P.style.clipPath="",P.style.transform=`translate(${ge}px, ${ke}px)`;const fe=`${qe} ${Le}`;P.dataset.aqspAnchorSig!==fe&&(P.dataset.aqspAnchorSig=fe,P.style.width=`${qe}px`,P.style.height=`${Le}px`)},[e,t]),ft=i.useCallback((P,I,G)=>{if(g===void 0)return;const j=g.current,{width:U,height:te}=P.getViewportSize(),ce=P.getFrozenSize(),ke={scroll:G,frozenCount:ce.cols,trailingCount:ce.trailingCols,extent:U},ge={scroll:I,frozenCount:ce.rows,trailingCount:ce.trailingRows,extent:te};Wt(b===void 0?null:b.current,j.interactive,ke,ge,ce,U,te),Wt(D===void 0?null:D.current,j.tip,ke,ge,ce,U,te)},[g,b,D,Wt]),Ie=i.useCallback(()=>{const P=A.current,I=n.current;if(P===null||I===null)return;const G=I.getScrollPosition(),j=Math.max(0,G.y),U=Math.max(0,G.x),te=o(),ce=N(U,j),ke=on(),ge=ke===null?Nh:te.ranges.slice(-$h(ce.length));for(const ne of ce){const ae=ne.nodes.container;if(ae===null)continue;const ue=ne.nodes.fillPool;for(let fe=0;fe<Math.max(ue.length,te.ranges.length);fe+=1){let ie=ue[fe];if(ie===void 0){const Re=document.createElement("div");Re.className="aqsp-selection-fill",Re.setAttribute("data-aqsp-fill",""),Re.style.display="none",ae.insertBefore(Re,Vl(ne.nodes)),ie={node:Re,last:{shown:!1,width:-1,height:-1,transform:""}},ue.push(ie)}const Ce=te.ranges[fe],we=Ce===void 0?null:We(Ce,ne);if(we===null)ie.last.shown&&(ie.last.shown=!1,ie.node.style.display="none");else{ie.last.shown||(ie.last.shown=!0,ie.node.style.display="block");const Re=`translate(${we.left}px, ${we.top}px)`;Re!==ie.last.transform&&(ie.last.transform=Re,ie.node.style.transform=Re),we.width!==ie.last.width&&(ie.last.width=we.width,ie.node.style.width=`${we.width}px`),we.height!==ie.last.height&&(ie.last.height=we.height,ie.node.style.height=`${we.height}px`)}}for(;ue.length>te.ranges.length;)ue.pop()?.node.remove();Et(ne.nodes.active,We(pe(te.active,te.active),ne)),ur(ne,ae,ge,ke)}const qe=h(),Le=qe===null||qe.foreign?null:qe;for(const ne of ce){const ae=ne.nodes.marquee;if(ae===null)continue;const ue=Le===null?null:We(Le.range,ne),fe=ue!==null&&(ne.xSeamTrail&&ue.left>=ne.clampWidth&&ue.left<ne.clampWidth+Yn||ne.xSeamLead&&ue.left+ue.width<=0&&ue.left+ue.width>-Yn||ne.ySeamTrail&&ue.top>=ne.clampHeight&&ue.top<ne.clampHeight+Yn||ne.ySeamLead&&ue.top+ue.height<=0&&ue.top+ue.height>-Yn)?null:ue;if(fe===null)ae.style.display="none";else{ae.style.display="block",ae.style.transform=`translate(${fe.left}px, ${fe.top}px)`,ae.style.width=`${fe.width}px`,ae.style.height=`${fe.height}px`;const we=kr(fe.top),Re=kr(fe.left),pt=kr(ne.clampHeight-(fe.top+fe.height)),lt=kr(ne.clampWidth-(fe.left+fe.width)),je=`${we} ${lt} ${pt} ${Re}`;je!==ae.dataset.aqspOutsetSig&&(ae.dataset.aqspOutsetSig=je,ae.style.setProperty("--aqsp-clip-outset-top",we),ae.style.setProperty("--aqsp-clip-outset-right",lt),ae.style.setProperty("--aqsp-clip-outset-bottom",pt),ae.style.setProperty("--aqsp-clip-outset-left",Re))}const ie=fe===null?null:Le?.kind??null,Ce=ae.dataset.aqspClipKindLast??null;ie!==Ce&&(ie===null?(delete ae.dataset.aqspClipKindLast,ae.removeAttribute("data-aqsp-clip-kind")):(ae.dataset.aqspClipKindLast=ie,ae.setAttribute("data-aqsp-clip-kind",ie)))}at.current!==null&&xt(at.current,j,U,st.current),w.current!==null&&At(w.current,j,U),k.current!==null&&dt(k.current,j,U);const Pe=z.current;if(Pe!==null&&!y()){const{width:ne,height:ae}=I.getViewportSize(),ue=te.ranges[te.ranges.length-1];if(!(te.ranges.length===1&&!ut.current&&!m())||ae<=0||ne<=0)Pe.style.display="none";else{const ie=I.getFrozenSize(),Ce={scroll:U,frozenCount:ie.cols,trailingCount:ie.trailingCols,extent:ne},we={scroll:j,frozenCount:ie.rows,trailingCount:ie.trailingRows,extent:ae},Re=ue.endCol<ie.cols,pt=ue.endRow<ie.rows,lt=ue.endCol>=t.count-ie.trailingCols,je=ue.endRow>=e.count-ie.trailingRows,ht=tn(t,ue.endCol,Ce)+t.sizeOf(ue.endCol),Kt=nn(e,ue.endRow,we)+e.sizeOf(ue.endRow),ln=Re||lt?0:ie.width,Dt=pt||je?0:ie.height,eo=lt?ne:ne-ie.trailingVisibleWidth,pr=je?ae:ae-ie.trailingVisibleHeight;Kt<=Dt||Kt>pr||ht<=ln||ht>eo?Pe.style.display="none":(Pe.style.display="block",Pe.style.transform=`translate(${ht-Yl+1}px, ${Kt-Yl+1}px)`)}}const Fe=r.current;if(Fe!==null){const ne=te.active,{width:ae,height:ue}=I.getViewportSize(),fe=I.getFrozenSize(),ie={scroll:U,frozenCount:fe.cols,trailingCount:fe.trailingCols,extent:ae},Ce={scroll:j,frozenCount:fe.rows,trailingCount:fe.trailingRows,extent:ue},we=nn(e,ne.row,Ce),Re=tn(t,ne.col,ie),pt=ue>0?Math.min(Math.max(we,0),Math.max(0,ue-1)):0,lt=ae>0?Math.min(Math.max(Re,0),Math.max(0,ae-1)):0;Fe.style.top=`${pt}px`,Fe.style.left=`${lt}px`,ut.current?(Fe.style.width=`${t.sizeOf(ne.col)}px`,Fe.style.height=`${e.sizeOf(ne.row)}px`,Fe.style.paddingTop=`${zh(e.sizeOf(ne.row),v===void 0?vt:v.current)}px`):(Fe.style.width="1px",Fe.style.height="1px",Fe.style.paddingTop="0px");const je=ne.col>=fe.cols&&Re<fe.width,ht=ne.row>=fe.rows&&we<fe.height,Kt=fe.trailingWidth>0&&ne.col<t.count-fe.trailingCols&&Re+t.sizeOf(ne.col)>ae-fe.trailingVisibleWidth,ln=fe.trailingHeight>0&&ne.row<e.count-fe.trailingRows&&we+e.sizeOf(ne.row)>ue-fe.trailingVisibleHeight,Dt=ut.current&&we===pt&&Re===lt&&!je&&!ht&&!Kt&&!ln;Dt!==he.current&&(he.current=Dt,Dt?Fe.setAttribute("data-aqsp-editing",""):Fe.removeAttribute("data-aqsp-editing"))}ft(I,j,U)},[n,We,N,Et,xt,At,dt,h,o,m,y,z,r,e,t,on,ur,v,ft]),Jr=i.useCallback((P,I)=>{at.current=P,st.current=I;const G=P===null?"add":I;for(const te of N(0,0)){const ce=te.nodes.dragRect;if(ce===null)continue;const ke=ce.dataset.aqspDragModeLast??"add";G!==ke&&(ce.dataset.aqspDragModeLast=G,G==="add"?ce.removeAttribute("data-aqsp-drag-mode"):ce.setAttribute("data-aqsp-drag-mode",G))}const j=n.current;if(P===null||j===null){for(const te of N(0,0))te.nodes.dragRect!==null&&(te.nodes.dragRect.style.display="none"),$n(te,null,null);return}const U=j.getScrollPosition();xt(P,Math.max(0,U.y),Math.max(0,U.x),I)},[n,xt,N,$n]),Qr=i.useCallback(P=>{k.current=P;const I=n.current;if(I===null){for(const j of N(0,0))j.nodes.fillPreview!==null&&(j.nodes.fillPreview.style.display="none");return}const G=I.getScrollPosition();dt(P,Math.max(0,G.y),Math.max(0,G.x))},[n,dt,N]),Ze=i.useCallback(P=>{w.current=P;const I=n.current;if(I===null){for(const j of N(0,0))j.nodes.resizeGuide!==null&&(j.nodes.resizeGuide.style.display="none");return}const G=I.getScrollPosition();At(P,Math.max(0,G.y),Math.max(0,G.x))},[n,At,N]);i.useLayoutEffect(()=>{const P=A.current;if(!(P===null||p===void 0))return P.style.setProperty("--aqsp-band-row",p.row),P.style.setProperty("--aqsp-band-column",p.column),P.style.setProperty("--aqsp-band-intersection",p.intersection),P.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{P.style.removeProperty("--aqsp-band-row"),P.style.removeProperty("--aqsp-band-column"),P.style.removeProperty("--aqsp-band-intersection"),P.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Ie,u.current=Jr,q.current=Qr,H.current=Ze,()=>{c.current=null,u.current=null,q.current=null,H.current=null})),i.useEffect(()=>{Ie()},[Ie,s,Q,se,ve,Te]),i.useEffect(()=>{const P=r.current;if(P===null)return;const I=G=>S(G);return P.addEventListener("mousedown",I),()=>P.removeEventListener("mousedown",I)},[r,S]);const $e=Q>0||ve>0?[...Q>0?[{k:"f",style:{left:0,width:Z}}]:[],{k:"s",style:{left:Z,right:Me}},...ve>0?[{k:"t",style:{right:0,width:Me}}]:[]]:[{k:"m",style:{left:0,right:0}}],Ot=se>0||Te>0?[...se>0?[{k:"f",style:{top:0,height:re}}]:[],{k:"s",style:{top:re,bottom:Ne}},...Te>0?[{k:"t",style:{bottom:0,height:Ne}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Tt=P=>P==="m"?0:P==="s"?1:P==="t"?2:3,dr=$e.flatMap(P=>Ot.map(I=>({xk:P.k,yk:I.k,key:`${P.k}${I.k}`,style:{...P.style,...I.style}}))).sort((P,I)=>Tt(P.key[0])+Tt(P.key[1])-(Tt(I.key[0])+Tt(I.key[1]))),fr=P=>P==="mm"?{"data-aqsp-overlay-main":""}:P==="fm"?{"data-aqsp-overlay-frozen":""}:P==="sm"?{"data-aqsp-overlay-scroll":""}:{};return W.jsxs("div",{ref:A,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:rt,bottom:rt},children:[dr.map(({xk:P,yk:I,key:G,style:j})=>{const U=J[G];return W.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":G,...fr(G),style:j,ref:U.container,children:[P==="s"&&Q>0?W.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:U.dividerXLeading}):null,P==="s"&&ve>0?W.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:U.dividerXTrailing}):null,I==="s"&&se>0?W.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:U.dividerYLeading}):null,I==="s"&&Te>0?W.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:U.dividerYTrailing}):null,W.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:U.active}),W.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:U.dragRect}),W.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:U.marquee}),W.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:U.fillPreview}),W.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:U.resizeGuide})]},G)}),W.jsx("textarea",{ref:Dn,className:"aqsp-sink","aria-label":L,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?W.jsx("div",{ref:z,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Gc=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=y=>{l.current=!0;try{y()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=y=>{if(y.key==="Escape"){y.preventDefault(),c(e.close);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&!y.altKey&&!y.shiftKey&&(y.preventDefault(),u())},m=y=>{l.current||y.relatedTarget instanceof Node&&y.currentTarget.contains(y.relatedTarget)||e.rejected||c(e.close)};return W.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:m,children:[W.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[De(t,"commentTitle"),W.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:De(t,"commentCount",e.current.length)})]}),W.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(y=>W.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":y.id,children:[W.jsx("span",{className:"aqsp-popover-comment-author",children:y.author}),W.jsx("time",{className:"aqsp-popover-comment-time",dateTime:y.createdAt,children:y.createdAt}),W.jsx("p",{className:"aqsp-popover-comment-text",children:y.text})]},y.id))}),W.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":De(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:y=>r(y.currentTarget.value),onKeyDown:h}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:De(t,"commentPost")}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":De(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Zc=({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:Bt(o),m=o.trim()!==""&&h===null,y=_=>{u.current=!0;try{_()}finally{u.current=!1}},q=()=>{l||m||y(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},H=_=>{if(_.key==="Escape"){_.preventDefault(),y(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),q())},z=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||y(e.close)};return W.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:z,children:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:De(t,"linkTitle")}),W.jsxs("label",{className:"aqsp-popover-field",children:[W.jsx("span",{className:"aqsp-popover-field-label",children:De(t,"linkTextField")}),W.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:H})]}),W.jsxs("label",{className:"aqsp-popover-field",children:[W.jsx("span",{className:"aqsp-popover-field-label",children:De(t,"linkUrlField")}),W.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown:H})]}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:q,children:De(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:De(t,"linkOpen")}):null,W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":De(t,"popoverClose"),onClick:()=>y(e.close),children:"×"})]})]})},Ul=500,Jc=({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 B=n.toLowerCase();return e.current.filter(x=>x.toLowerCase().startsWith(B))},[e.current,n]),h=i.useMemo(()=>u.length>Ul?u.slice(0,Ul):u,[u]),m=u.length-h.length,y=h.length===0?-1:Math.min(o,h.length-1),q=B=>{c.current=!0;try{B()}finally{c.current=!1}},H=()=>{y<0||q(()=>e.commit(h[y]))},z=B=>{if(B.key==="Escape"){B.preventDefault(),q(e.close);return}if(B.key==="Enter"){B.preventDefault(),H();return}if(B.key==="ArrowDown"){B.preventDefault(),s(y+1);return}B.key==="ArrowUp"&&(B.preventDefault(),s(Math.max(y-1,0)))},_=B=>{c.current||B.relatedTarget instanceof Node&&B.currentTarget.contains(B.relatedTarget)||q(e.close)},K=B=>`${l}-${B}`;return W.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[W.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":De(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":y<0?void 0:K(y),value:n,onChange:B=>{r(B.currentTarget.value),s(0)},onKeyDown:z}),W.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":De(t,"listTitle"),children:[h.length===0?W.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:De(t,"listEmpty")}):h.map((B,x)=>W.jsx("div",{className:"aqsp-popover-option",id:K(x),role:"option",tabIndex:-1,"aria-selected":x===y,"data-aqsp-list-option":B,onPointerDown:$=>$.preventDefault(),onClick:()=>q(()=>e.commit(B)),children:B},K(x))),m>0?W.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:De(t,"listMore",m)}):null]})]})},Qc=({ctx:e,labels:t})=>W.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),W.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":De(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=z=>{u.current=!0;try{z()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},y=()=>{r!==n&&!s?m():h(e.close)},q=z=>{if(z.key==="Escape"){z.preventDefault(),e.rejected?h(e.close):y();return}z.key==="Enter"&&(z.ctrlKey||z.metaKey)&&!z.altKey&&!z.shiftKey&&(z.preventDefault(),m())},H=z=>{u.current||z.relatedTarget instanceof Node&&z.currentTarget.contains(z.relatedTarget)||e.rejected||y()};return W.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:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:De(t,"noteTitle")}),W.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:z=>o(z.currentTarget.value),onKeyDown:q}),W.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:De(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:De(t,"noteSave")}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":De(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},ta=({ctx:e})=>W.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),yt=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")}),Xl=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],na=Object.freeze({all:yt(Xl),values:yt(["text"]),formats:yt(["format","borders","cf"]),formulas:yt(["text","formula"]),noBorders:yt(Xl.filter(e=>e!=="borders")),columnWidths:yt(["sizes"]),validation:yt(["validation"]),conditionalFormats:yt(["cf"]),commentsAndNotes:yt(["note","comments"])}),Gl=Object.freeze({mode:"all"}),Qo=Object.freeze({t:""}),Zl=Object.freeze({row:1<<30,col:1<<30}),_h=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Ih=e=>e.t===""&&e.f===void 0,jh=e=>e.length>1&&e.startsWith("="),Hh=(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}},Jl=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Bh=(e,t,n,r)=>{const o=jh(e),s=e===""?"0":Xe(e);if(!o&&s===null)return null;const l=_h[n];if(t.f!==void 0){const h=sr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Jl(Number(s));const c=Xe(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Jl(Hh(Number(s),u,n))},Ql=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Vh=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:Ql(e.start),end:Ql(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}}}},Wh=e=>{const t=sr(e,Zl),n=or(t);let r="",o=0,s=!1;for(const l of n){const c=Vh(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${It(c)}`,o=l.end,s=!0)}return s?Ur(`${r}${t.slice(o)}`,Zl):e},Kh=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Qo;const o=r[n];return o===void 0?Qo:o},Yh=e=>{const{rows:t,cols:n}=e,r=ec(Wh);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const u=[];for(let h=0;h<t;h+=1){const m=Kh(e,h,c);let y=m;if(m.f!==void 0){const q=r(m.f);y=q===m.f?m:{...m,f:q}}(y!==m||m===Qo)&&(o=!1),u.push(y)}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}},Uh=(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,Xh=(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},ei=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)Uh(m,t)?(h.push(Xh(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},ti=new WeakMap,ra=e=>{const t=ti.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>ot(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:ot({...s,borders:void 0})),o={canonical:n,borderless:r};return ti.set(e,o),o},Br=(e,t)=>t===void 0?void 0:e[t],Gh=(e,t,n,r)=>{const o=ra(e);if(n){const h=Br(o.canonical,t.fmt);return h===void 0?null:h}const s=Br(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const u=ot(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},Zh=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Bh(n.readText(),o,r,n):o.f===void 0?o.t:sr(o.f,n)},ni=(e,t,n,r,o)=>{const s=na[r.mode];if(r.skipBlanks===!0&&Ih(e))return null;const l={};let c=!1;if(s.text){const u=Zh(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Gh(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Br(ra(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=Br(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},ri=(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}}),Jh=["text/html","text/plain"],Qh=(e,t,n)=>{if(e===0||t===0)return 0;const r=Ge(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,tm=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,nm=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}}},oi=e=>{const t=e.clipboardData;return t??null},rm=(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}},om=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=rm(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},sm=(e,t,n,r,o)=>{const s=On(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Ur(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=Tn(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},oa=(e,t)=>{const n=_i(),r=hd(),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(sm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:om(e.getConditionalFormats(),t)}},si=e=>e.kind==="cut"?{...e.payload,...oa(e.sourceAdapter,e.range)}:e.payload,lm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:is(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),im=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=Bt(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},cm=(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},am=(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 pe({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},um=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(x=>{const $=n.current;if($===null||x==="format"||x==="annotate")return;const L=r.current;L==="own"||L==="foreign"&&$.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const x=n.current;if(x===null)return;if(x.kind==="copy"){o();return}const $=t.current;$.repaintOverlay(),$.onClipChange?.({kind:"cut",range:x.range,foreign:x.sourceAdapter!==$.adapter})},[o]),c=i.useCallback((x,$,L)=>{const S=t.current;n.current={kind:x,range:$,clipId:L.clipId,sourceAdapter:S.adapter,payload:L},S.repaintOverlay(),S.onClipChange?.({kind:x,range:$,foreign:!1})},[]),u=i.useCallback(x=>{const $=t.current,L=$.adapter,S=Ge(x),v={v:1,rows:S.rows,cols:S.cols,clipId:is(),...oa(L,x),wholeRows:Ii(x,L.colCount),wholeCols:ji(x,L.rowCount)};if($.resize!==void 0){if(v.wholeCols){const E=[];for(let p=x.startCol;p<=x.endCol;p+=1)E.push(Math.min($.resize.colAxis.sizeOf(p),En));v.colWidths=E}if(v.wholeRows){const E=[];for(let p=x.startRow;p<=x.endRow;p+=1)E.push(Math.min($.resize.rowAxis.sizeOf(p),En));v.rowHeights=E}}return v},[]),h=i.useCallback((x,$)=>{const L=t.current,S=L.getSelection(),v=S.ranges[S.ranges.length-1],E=ct([v]);if(E>L.maxOperationCells)return x.preventDefault(),L.onOperationRejected?.($,E,"limit"),null;if($==="cut"&&Kn(L.adapter,v))return x.preventDefault(),L.rejectReadOnly({kind:"operation",op:"cut",cellCount:E}),null;S.ranges.length>1&&L.onCopyMultiRange?.();const p=u(v),g=Oi(p),b=oi(x);return b!==null&&(b.setData("text/plain",Tc(p.cells.map(D=>D.map(A=>A.t)))),b.setData("text/html",Cc(p,g)),b.setData(Ir,g)),x.preventDefault(),{payload:p,range:v}},[u]),m=i.useCallback((x,$)=>t.current.commitPaste(x,$)!==null,[]),y=i.useCallback((x,$,L)=>{const S=t.current;if(!L.sizes||S.resize===void 0)return;const{rowAxis:v,colAxis:E,resizeTracks:p}=S.resize,g=(b,D,A)=>{const k=rs(D,A,null,{maxOperationCells:S.maxOperationCells,rowHiddenLimit:ts,axisKind:b});if(!k.ok){S.onOperationRejected?.("resize",k.count,k.reason);return}p(b,k.entries)};if(x.colWidths!==void 0){const b=[];for(let D=$.startCol;D<=$.endCol;D+=1)b.push({index:D,size:x.colWidths[(D-$.startCol)%x.cols]});g("col",E,b)}if(x.rowHeights!==void 0){const b=[];for(let D=$.startRow;D<=$.endRow;D+=1)b.push({index:D,size:x.rowHeights[(D-$.startRow)%x.rows]});g("row",v,b)}},[]),q=i.useCallback((x,$)=>{const L=t.current,S=L.adapter,v=x.payload,E={row:$.startRow,col:$.startCol},p=v.rows*v.cols+ct([x.range]);if(p>L.maxOperationCells)return L.onOperationRejected?.("paste",p,"limit"),"rejected";if(E.row+v.rows>S.rowCount||E.col+v.cols>S.colCount||x.range.endRow>=x.sourceAdapter.rowCount||x.range.endCol>=x.sourceAdapter.colCount)return L.onOperationRejected?.("paste",p,"bounds"),"rejected";const g=Zo({rows:v.rows,cols:v.cols},pe(E,E),E,S.rowCount,S.colCount);if(g!==null&&Kn(S,g))return L.rejectReadOnly({kind:"operation",op:"paste",cellCount:v.rows*v.cols}),"rejected";if(Kn(x.sourceAdapter,x.range))return L.rejectReadOnly({kind:"operation",op:"cut",cellCount:ct([x.range])}),"rejected";const b=si(x),D=qr(S),A=ei(b,D),k={row:0,col:0,readText:()=>On(S,k.row,k.col).text,readFormat:()=>S.getCellFormat===void 0?void 0:S.getCellFormat(k.row,k.col)},{edits:w,tiles:R}=$l(A.cells,pe(E,E),E,S.rowCount,S.colCount,(O,d,F)=>(k.row=x.range.startRow+(d-E.row),k.col=x.range.startCol+(F-E.col),ni(O,A,k,Gl,D))),a=qr(x.sourceAdapter),f=[];if(qt([x.range],O=>{f.push(cm(O.row,O.col,a))}),x.sourceAdapter===S){if(!m([...f,...w],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const O=L.commitPaste(w,{sameSheet:!1,conditionalFormats:ri(A.conditionalFormats,R)});if(O===null)return"rejected";try{x.sourceAdapter.applyEdits(f,{transaction:O,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){L.onEditRejected?.(d,{source:"paste"})}}return L.setSelection({ranges:[pe(E,{row:E.row+b.rows-1,col:E.col+b.cols-1})],anchor:E,active:E}),"applied"},[m]),H=i.useCallback((x,$,L)=>{const S=t.current,v=S.adapter,E=X=>(S.onClipboardUnavailable?.(X),"rejected"),p=Mi(x,$);if(p==="none")return $==="menu"?E("empty"):"empty";const g=S.getSelection(),b=g.ranges[g.ranges.length-1],D=L.transpose===!0,A=(X,J)=>{const Q=Qh(D?J:X,D?X:J,b);return Q>S.maxOperationCells?(S.onOperationRejected?.("paste",Q,"limit"),!0):!1};let k,w=null;if(p==="aqsp"){const X=ju(x,$);if(X===null)return E("unreadable");const J=n.current;if(J!==null&&X.clipId===J.clipId&&(w=J),w!==null&&w.kind==="cut"&&em(L))return q(w,b);if(A(X.rows,X.cols))return"rejected";if(w!==null){if(w.kind==="cut"&&(w.range.endRow>=w.sourceAdapter.rowCount||w.range.endCol>=w.sourceAdapter.colCount))return S.onOperationRejected?.("paste",w.payload.rows*w.payload.cols,"bounds"),"rejected";k=si(w)}else{const Q=Hu(x,$);if(Q===null)return E("unreadable");if(A(Q.rows,Q.cols))return"rejected";k=im(Q)}}else if(p==="tsv"){const X=x.getData("text/plain"),J=Fp(X);if(A(J.rows,J.cols))return"rejected";k=lm($c(X))}else{const X=x.getData("text/html"),J=pd(X);if(J.cols===0&&J.rows>S.maxOperationCells)return S.onOperationRejected?.("paste",J.rows,"limit"),"rejected";if(A(J.rows,J.cols))return"rejected";const Q=Rc(X,p,S.formats===void 0?{}:{currency:S.formats.currency,locale:S.formats.locale},S.maxOperationCells);if(Q.outcome==="none")return E("unreadable");if(Q.outcome==="limit")return S.onOperationRejected?.("paste",Q.cells,"limit"),"rejected";if(A(Q.payload.rows,Q.payload.cols))return"rejected";k=Q.payload}const R=qr(v),a=ei(D?Yh(k):k,R),f=na[L.mode];if(tm(f)){const X=Zo({rows:a.rows,cols:a.cols},b,g.active,v.rowCount,v.colCount);if(X!==null&&Kn(v,X))return S.rejectReadOnly({kind:"operation",op:"paste",cellCount:ct([X])}),"rejected"}const O={row:0,col:0,readText:()=>On(v,O.row,O.col).text,readFormat:()=>v.getCellFormat===void 0?void 0:v.getCellFormat(O.row,O.col)},{edits:d,tiles:F}=$l(a.cells,b,g.active,v.rowCount,v.colCount,(X,J,Q)=>(O.row=J,O.col=Q,ni(X,a,O,L,R))),M=am(F,a.rows,a.cols,v.rowCount,v.colCount);if(M===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let X=0;for(const Q of a.conditionalFormats)X+=Q.ranges.length;const J=F.length*X;if(J>S.maxOperationCells)return S.onOperationRejected?.("paste",J,"limit"),"rejected"}const T=f.cf?ri(a.conditionalFormats,F):[];if(d.length===0&&T.length===0)return y(a,M,f),"empty";r.current=w===null?"foreign":"own";let N=!1;try{N=m(d,{sameSheet:w!==null&&w.sourceAdapter===v,conditionalFormats:T})}finally{r.current="none"}if(!N)return"rejected";y(a,M,f);const V={row:M.startRow,col:M.startCol};return S.setSelection({ranges:[M],anchor:V,active:V}),"applied"},[q,m,y]),z=i.useCallback(async x=>{const $=D=>(t.current.onClipboardUnavailable?.(D),"rejected"),L=navigator;if(L.clipboard===void 0)return $("insecure-origin");let S;try{S=await L.clipboard.read({unsanitized:["text/html"]})}catch{return $("permission-denied")}if(S.length===0)return $("empty");const v=S[0],E=Array.from(v.types),p=new Map;try{for(const D of Jh)E.includes(D)&&p.set(D,await(await v.getType(D)).text())}catch{return $("unreadable")}const g={types:E,getData:D=>{const A=p.get(D);if(A===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${D} was not materialised for the menu path`);return A}},b=t.current;return!b.enabled||b.isDragging()||b.isEditing()?"rejected":H(g,"menu",x)},[H]),_=i.useCallback(async x=>{const $=await z(x);return t.current.onPasteResolved?.($,"menu"),$},[z]),{enabled:K,sinkRef:B}=e;return i.useEffect(()=>{const x=B.current;if(!K||x===null)return;const $=E=>t.current.isDragging()?(E.preventDefault(),!0):!1,L=E=>{const p=t.current;if($(E)||p.isEditing())return;const g=h(E,"copy");g!==null&&c("copy",g.range,g.payload)},S=E=>{const p=t.current;if($(E)||p.isEditing())return;const g=h(E,"cut");g!==null&&c("cut",g.range,g.payload)},v=E=>{const p=t.current;if($(E)||p.isEditing())return;E.preventDefault();let g=Gl;const b=p.pendingPasteOptionsRef;b!==void 0&&b.current!==null&&(g=b.current,b.current=null);const D=oi(E);if(D===null)return;const A=H(nm(D),"event",g);p.onPasteResolved?.(A,"event")};return x.addEventListener("copy",L),x.addEventListener("cut",S),x.addEventListener("paste",v),()=>{x.removeEventListener("copy",L),x.removeEventListener("cut",S),x.removeEventListener("paste",v)}},[K,B,h,c,H]),i.useMemo(()=>({getClip:()=>{const x=n.current;return x===null?null:{kind:x.kind,range:x.range,foreign:x.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},sa=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}},li=(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}`}`},ia=(e,t)=>{let n;if(e.exponent===null)n=li(e.negative,e.digits,e.point+t);else{const r=li(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Xe(n)===null?null:n},dm=(e,t)=>{sa(t);const n=Xe(e);return n===null?null:ia(la(n),t)},fm=e=>{const t=Xe(e);if(t!==null){const r=la(t);return ia({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},ca=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)},pm=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},aa=(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 pm(r)?r:null},hm=(e,t)=>{sa(t);const n=ca(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=aa(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},mm=e=>{const t=ca(e),n=aa(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Hn=(e,t,n,r)=>{const o=ct(t);return o>n?(r?.(e,o,"limit"),!1):!0},xr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Ar={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},ii={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:xr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:xr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:xr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:xr.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:Ar.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Ar.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Ar.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Ar.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},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},gm={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},Jn=e=>e<10?`0${e}`:String(e),wm=e=>{const t=new Date(e);return`${t.getFullYear()}-${Jn(t.getMonth()+1)}-${Jn(t.getDate())}`},Cm=e=>{const t=new Date(e);return`${Jn(t.getHours())}:${Jn(t.getMinutes())}:${Jn(t.getSeconds())}`},ym=(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),bm=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),vm=e=>e===void 0||e.borders===void 0?{}:e.borders,Rm={top:1,right:2,bottom:4,left:8},km={style:"thin",color:os},Sm=(e,t)=>{if(e===void 0)return!1;const n=Ve(e);return n!==null&&n===Ve(t)},Em=(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}}},xm=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const p=t.current;if(p.isEditing()){const g=p.getActive();return[pe(g,g)]}return p.getSelection().ranges},[]),r=i.useCallback(()=>{const p=t.current,g=p.getActive();return p.adapter.getCellFormat===void 0?void 0:p.adapter.getCellFormat(g.row,g.col)},[]),o=i.useCallback(p=>{const g=t.current,b=n();if(!Hn("format",b,g.maxOperationCells,g.onOperationRejected))return!1;if(yn(g.adapter,b))return g.rejectReadOnly({kind:"operation",op:"format",cellCount:ct(b)}),!1;const D=new Map,A=[],k=g.adapter.getCellFormat;for(const w of b)qt([w],R=>{const a=k===void 0?void 0:k(R.row,R.col),{bucket:f,patch:O}=p(R,w,a);let d=D.get(f);d===void 0&&(d=new Map,D.set(f,d));let F;d.has(a)?F=d.get(a):(F=ls(a,O),d.set(a,F)),F!==a&&A.push({row:R.row,col:R.col,format:F===void 0?null:F})});return A.length===0?!0:g.commitEdits(A,{source:"format"})===null?!1:(g.isEditing()&&g.refreshEditPaint(),!0)},[n]),s=i.useCallback(p=>o(()=>({bucket:0,patch:p})),[o]),l=i.useCallback((p,g)=>{const b=t.current;b.formatCommandAnnouncement!==void 0&&b.announce(b.formatCommandAnnouncement({command:p,state:g}))},[]),c=i.useCallback((p,g=km)=>{if(p==="clear")return s({borders:null});if(p==="all")return s({borders:{top:g,right:g,bottom:g,left:g}});const b=p==="outer"?15:Rm[p];return o((D,A,k)=>{const w=ym(D,A)&b;return{bucket:w,patch:{borders:{...vm(k),...bm(w,g)}}}})},[s,o]),u=i.useCallback((p,g,b)=>{const D=Ac(t.current.adapter,p.row,p.col);for(const A of g)b.push(Oc(D,p,A))},[]),h=i.useCallback(p=>{const g=t.current,b=g.getSelection();if(!Hn("fill",b.ranges,g.maxOperationCells,g.onOperationRejected))return!1;const D=[];if(p==="selection"){const k=b.active,w=[];qt(b.ranges,R=>{(R.row!==k.row||R.col!==k.col)&&w.push(R)}),D.push({source:k,targets:w})}else for(const k of b.ranges)if(p==="down"){const w=k.startRow===k.endRow;if(w&&k.startRow===0)continue;const R=w?k.startRow-1:k.startRow;for(let a=k.startCol;a<=k.endCol;a+=1){const f=[];for(let O=w?k.startRow:k.startRow+1;O<=k.endRow;O+=1)f.push({row:O,col:a});D.push({source:{row:R,col:a},targets:f})}}else{const w=k.startCol===k.endCol;if(w&&k.startCol===0)continue;const R=w?k.startCol-1:k.startCol;for(let a=k.startRow;a<=k.endRow;a+=1){const f=[];for(let O=w?k.startCol:k.startCol+1;O<=k.endCol;O+=1)f.push({row:a,col:O});D.push({source:{row:a,col:R},targets:f})}}for(const k of D)for(const w of k.targets)if(_e(g.adapter,w.row,w.col)){let R=0;for(const a of D)R+=a.targets.length;return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:R}),!1}const A=[];for(const k of D)u(k.source,k.targets,A);return A.length===0?!0:g.commitEdits(A,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const p=t.current,g=p.getSessionText();if(g===null)return!1;const b=p.getSelection();if(!Hn("fill",b.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(yn(p.adapter,b.ranges))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:ct(b.ranges)}),!1;const D=[];let A=!1;return qt(b.ranges,k=>{if(!A){if(!p.validateCommit(k,g).ok){A=!0;return}D.push({row:k.row,col:k.col,text:g})}}),A||p.commitEdits(D,{source:"fill"})===null?!1:(p.cancelEdit(),!0)},[]),y=i.useCallback(p=>{const g=t.current,b=g.getSelection();if(!Hn("calc",b.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(yn(g.adapter,b.ranges))return g.rejectReadOnly({kind:"operation",op:"calc",cellCount:ct(b.ranges)}),!1;const D=[],A=g.adapter;return qt(b.ranges,k=>{const w=A.getCellFormula===void 0?void 0:A.getCellFormula(k.row,k.col),R=w===void 0?p.text(A.getCellText(k.row,k.col)):p.formula(w);R!==null&&D.push({row:k.row,col:k.col,text:R})}),D.length===0?!0:g.commitEdits(D,{source:"calc"})!==null},[]),q=i.useCallback((p,g)=>{const b=t.current,D=p==="row"?b.rowAxis:b.colAxis,A=b.getSelection(),k=p==="row"?Math.floor(b.maxOperationCells/ns):b.maxOperationCells;let w=0;for(const d of A.ranges)w+=p==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(w>k)return b.onOperationRejected?.("resize",w,"limit"),!1;const R=new Set,a=[],f=g?0:p==="row"?b.defaultRowHeight:b.defaultColumnWidth;for(const d of A.ranges){const F=p==="row"?d.startRow:d.startCol,M=p==="row"?d.endRow:d.endCol;for(let T=F;T<=M;T+=1){if(R.has(T))continue;R.add(T),D.sizeOf(T)===0!==g&&a.push({index:T,size:f})}}const O=rs(D,a,null,{maxOperationCells:b.maxOperationCells,rowHiddenLimit:ts,axisKind:p});return O.ok?(O.entries.length>0&&b.resizeTracks(p,O.entries),!0):(b.onOperationRejected?.("resize",O.count,O.reason),!1)},[]),H=i.useCallback(()=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)return;const g=p.getActive();return Tn(p.adapter.getCellHyperlink(g.row,g.col))},[]),z=i.useCallback(p=>{const g=t.current,b=g.adapter,D=ii[p],A=b.getCellFormat!==void 0,k=w=>g.popovers===void 0?!0:g.popovers[w]!==!1;switch(D.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return A;case"value":return A&&(D.value!=="currency"||g.formats!==void 0);case"popover":switch(D.popover){case"link":return b.getCellHyperlink!==void 0&&k("link");case"note":return b.getCellNote!==void 0&&k("note");case"comment":return b.getCellComments!==void 0&&k("comment");default:return b.getCellValidation!==void 0&&k("list")}case"openHyperlink":return b.getCellHyperlink!==void 0&&(g.onHyperlinkOpen!==void 0?H()!==void 0:k("link"));case"paste":return D.options.mode==="formats"?A:D.options.mode==="formulas"?b.getCellFormula!==void 0:!0;default:return!0}},[H]),_=i.useCallback(p=>{const g=t.current,b=p.kind==="popover"?p.popover:p.kind==="openHyperlink"&&g.onHyperlinkOpen===void 0?"link":void 0;if(b===void 0)return!0;const D=g.getActive();if(!_e(g.adapter,D.row,D.col))return!0;if(b==="list")return g.rejectReadOnly({kind:"edit",cell:D,editSession:"none"}),!1;let A;if(b==="link")A=H()!==void 0;else if(b==="note"){const k=g.adapter.getCellNote===void 0?void 0:g.adapter.getCellNote(D.row,D.col);A=k!==void 0&&k!==""}else{const k=g.adapter.getCellComments===void 0?void 0:g.adapter.getCellComments(D.row,D.col);A=k!==void 0&&k.length>0}return A?!0:(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[H]),K=i.useCallback(p=>{const g=t.current;if(!z(p))return!1;const b=ii[p];if(!_(b))return!1;const D=g.isEditing();if(D&&!Cs.has(p)&&!g.requestCommit())return!1;switch(b.kind){case"toggle":{const A=r(),k=A!==void 0&&A[b.key]===!0;return s({[b.key]:k?null:!0})?(l(p,!k),!0):!1}case"patch":return s(b.patch)?(l(p,null),!0):!1;case"clear":return s(gm)?(l(p,null),!0):!1;case"value":return s({value:Em(b.value,g.formats)})?(l(p,null),!0):!1;case"borders":return c(b.preset)?(l(p,null),!0):!1;case"color":{const A=b.key==="background"?g.colors.fill:g.colors.font,k=b.preset!==null?b.preset:b.custom!==null&&b.custom<A.length?A[b.custom]:void 0;if(k===void 0)return!1;const w=r(),R=Sm(w===void 0?void 0:w[b.key],k);return s({[b.key]:R?null:k})?(l(p,!R),!0):!1}case"calc":return y({text:A=>dm(A,b.exponent),formula:A=>hm(A,b.exponent)});case"sign":return y({text:fm,formula:mm});case"fill":return D&&b.direction==="selection"?m():h(b.direction);case"popover":return g.openPopover(b.popover),!0;case"openHyperlink":{if(g.onHyperlinkOpen!==void 0){const A=H();return A===void 0?!1:(g.onHyperlinkOpen(A,g.getActive()),!0)}return g.openPopover("link"),!0}case"pasteSpecial":return g.onPasteSpecialRequest!==void 0?(g.onPasteSpecialRequest({kind:"keyboard",cellRect:g.keyboardCellRect()}),!0):(g.paste({mode:"formats"}),!0);case"paste":return g.paste(b.options),!0;case"insertNow":{const A=b.unit==="date"?wm(g.now()):Cm(g.now());if(D)return g.insertAtCaret(A),!0;const k=g.getActive();return _e(g.adapter,k.row,k.col)?(g.rejectReadOnly({kind:"edit",cell:k,editSession:"none"}),!1):g.validateCommit(k,A).ok?g.commitEdits([{row:k.row,col:k.col,text:A}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return q(b.axis,b.hide);default:{const A=g.getHighlight();switch(b.target){case"row":return g.setHighlight({...A,row:!A.row}),!0;case"column":return g.setHighlight({...A,column:!A.column}),!0;case"both":{const k=A.row&&A.column;return g.setHighlight({...A,row:!k,column:!k}),!0}default:return g.setHighlight({...A,intersection:!A.intersection}),!0}}}},[z,_,H,r,s,l,c,y,h,m,q]),B=i.useCallback(()=>{const p=t.current;return!(p.isEditing()&&!p.requestCommit())},[]),x=i.useCallback(p=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const b=p===null?null:Bt(p);if(p!==null&&b===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(p)}`);if(!B())return!1;const D=g.getActive();return _e(g.adapter,D.row,D.col)?(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):g.commitEdits([{row:D.row,col:D.col,hyperlink:b}],{source:"annotate"})!==null},[B]),$=i.useCallback(p=>{const g=t.current;if(g.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!B())return!1;const b=g.getActive();return _e(g.adapter,b.row,b.col)?(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):g.commitEdits([{row:b.row,col:b.col,note:p}],{source:"annotate"})!==null},[B]),L=i.useCallback(p=>{const g=t.current,b=g.adapter.getCellComments;if(b===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!B())return!1;const D=g.getActive();if(_e(g.adapter,D.row,D.col))return g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const A=b(D.row,D.col),k=A===void 0?[p]:[...A,p];return g.commitEdits([{row:D.row,col:D.col,comments:k}],{source:"annotate"})!==null},[B]),S=i.useCallback(p=>{const g=t.current;if(g.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!B())return!1;const b=g.getSelection().ranges;if(!Hn("annotate",b,g.maxOperationCells,g.onOperationRejected))return!1;if(yn(g.adapter,b))return g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:ct(b)}),!1;const D=[];return qt(b,A=>{D.push({row:A.row,col:A.col,validation:p})}),g.commitEdits(D,{source:"annotate"})!==null},[B]),v=i.useCallback(p=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(p)},[s]),E=i.useCallback((p,g)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(p,g)},[c]);return i.useMemo(()=>({executeCommand:K,applyFormat:v,setBorders:E,setHyperlink:x,setNote:$,addComment:L,setValidation:S,isCommandAvailable:z}),[K,v,E,x,$,L,S,z])},Or="data-aqsp-pointing",Am=(e,t)=>{const n=sc(e,t);return n!==null&&"insertAt"in n},Om=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Tm=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(vt),m=i.useCallback(()=>{const w=t.current,R=w.sinkRef.current;if(w.adapter.getCellFormula===void 0||n.current===null||!c.current||R===null)return null;const a=sc(R.value,R.selectionStart);return a===null?null:{sink:R,target:a}},[]),y=i.useCallback(()=>{const w=t.current.sinkRef.current;if(w===null)return;const R=m()!==null;R!==w.hasAttribute(Or)&&(R?w.setAttribute(Or,""):w.removeAttribute(Or))},[m]),q=i.useCallback((w,R)=>{const a=t.current;if(a.resolveEditPaint===void 0)return;const f=a.resolveEditPaint(R),O=f===null?vt:f;O!==vt&&Object.assign(w.style,O.style),h.current=O,a.editPaintRef!==void 0&&(a.editPaintRef.current=O)},[]),H=i.useCallback(w=>{Om(w,Object.keys(h.current.style)),h.current=vt;const R=t.current.editPaintRef;R!==void 0&&(R.current=vt)},[]),z=i.useCallback(w=>{const R=t.current,a=n.current;if(a===null)return!0;const f=()=>{n.current=null,u.current=null;const O=R.sinkRef.current;O!==null&&(O.style.removeProperty("text-align"),H(O),O.removeAttribute(Or)),o(!1)};if(w.commit){const O=R.sinkRef.current,d=O===null?"":O.value,F=On(R.adapter,a.cell.row,a.cell.col).text.replace(/\r\n?/g,`
20
- `),M=d===F;let T;if(M)T=!0;else if(_e(R.adapter,a.cell.row,a.cell.col))R.rejectReadOnly({kind:"edit",cell:a.cell,editSession:w.onReject==="keep"?"kept":"discarded"}),T=!1;else{const N={source:"edit",editSession:w.onReject==="keep"?"kept":"discarded"};T=(R.validateCommit===void 0||R.validateCommit(a.cell,d).ok)&&R.commitEdits([{row:a.cell.row,col:a.cell.col,text:d}],N)!==null}if(!T)return w.onReject==="discard"&&(f(),R.rearmSink()),!1}return f(),w.rearm&&R.rearmSink(),!0},[H]),_=i.useCallback((w,R)=>{const a=t.current;if(a.isDragging()||n.current!==null)return;const f=a.sinkRef.current;if(f===null)return;const O=a.getActive();if(_e(a.adapter,O.row,O.col)){a.rejectReadOnly({kind:"edit",cell:O,editSession:"none"});return}if(a.discardClip(),a.ensureCellVisible(O),w==="edit"){const{text:F,isFormula:M}=On(a.adapter,O.row,O.col);f.value=F;const T=R===void 0||M?F.length:Math.min(R,F.length);f.setSelectionRange(T,T)}else f.value="";const d=a.resolveEditAlign(O);d!==null&&(f.style.textAlign=d),q(f,O),c.current=!1,u.current=null,n.current={cell:O,mode:w},o(!0)},[q]),K=i.useCallback(()=>{z({rearm:!0,commit:!1})},[z]),B=i.useCallback(()=>{const w=t.current;if(n.current===null)return!0;const R=w.sinkRef.current;if(s.current&&R!==null){l.current=!0;try{R.blur()}finally{l.current=!1}return z({rearm:!1,commit:!0,onReject:"keep"})?(w.focusSink(),w.rearmSink(),!0):(w.focusSink(),!1)}return z({rearm:!0,commit:!0,onReject:"keep"})},[z]),x=i.useCallback(()=>m()!==null,[m]),$=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,y(),!0),[y]),L=i.useCallback(()=>{const w=m(),R=n.current;if(w===null||R===null)return null;if("insertAt"in w.target)return u.current=R.cell,{origin:R.cell,cursor:R.cell,axis:"cells"};const a=oc(w.sink.value,w.sink.selectionStart);if(a===null)return null;const f=a.token,O=u.current;switch(f.kind){case"cell":{const d={row:f.row,col:f.col};return u.current=d,{origin:d,cursor:d,axis:"cells"}}case"range":{const d=O!==null&&(O.row===f.start.row||O.row===f.end.row)&&(O.col===f.start.col||O.col===f.end.col)?{row:O.row,col:O.col}:{row:f.start.row,col:f.start.col};return u.current=d,{origin:d,cursor:{row:d.row===f.start.row?f.end.row:f.start.row,col:d.col===f.start.col?f.end.col:f.start.col},axis:"cells"}}case"column":{const d=O!==null&&(O.col===f.start.col||O.col===f.end.col)?O.col:f.start.col,F={row:R.cell.row,col:d};return u.current=F,{origin:F,cursor:{row:R.cell.row,col:d===f.start.col?f.end.col:f.start.col},axis:"columns"}}case"row":{const d=O!==null&&(O.row===f.start.row||O.row===f.end.row)?O.row:f.start.row,F={row:d,col:R.cell.col};return u.current=F,{origin:F,cursor:{row:d===f.start.row?f.end.row:f.start.row,col:R.cell.col},axis:"rows"}}}},[m]),S=i.useCallback((w,R)=>{const a=m();if(a===null)return;const f=Yd(w,R),{sink:O}=a,[d,F]="replace"in a.target?a.target.replace:[a.target.insertAt,a.target.insertAt],M=O.value;O.value=`${M.slice(0,d)}${f}${M.slice(F)}`;const T=d+f.length;O.setSelectionRange(T,T),"row"in w&&(u.current={row:w.row,col:w.col}),y()},[m,y]),v=i.useCallback(()=>{const w=t.current.sinkRef.current;return w===null?null:{value:w.value,selectionStart:w.selectionStart,selectionEnd:w.selectionEnd}},[]),E=i.useCallback(w=>{const R=t.current.sinkRef.current;R!==null&&(R.value=w.value,R.setSelectionRange(w.selectionStart,w.selectionEnd),u.current=null,y())},[y]),p=i.useCallback(()=>{const w=t.current,R=w.sinkRef.current;if(w.adapter.getCellFormula===void 0||n.current===null||R===null)return!1;const a=rf(R.value,R.selectionStart);return a===null?!1:(R.value=a.text,R.setSelectionRange(a.caret,a.caret),y(),!0)},[y]),g=i.useCallback(w=>{const R=t.current.sinkRef.current;if(n.current===null||R===null)return;const a=R.selectionStart,f=R.selectionEnd;R.value=`${R.value.slice(0,a)}${w}${R.value.slice(f)}`;const O=a+w.length;R.setSelectionRange(O,O),u.current=null,y()},[y]),b=i.useCallback(()=>{const w=t.current.sinkRef.current;return n.current===null||w===null?null:w.value},[]),D=i.useCallback(()=>{const w=t.current,R=n.current,a=w.sinkRef.current;R===null||a===null||(H(a),q(a,R.cell),w.repaintOverlay?.())},[H,q]),{enabled:A,sinkRef:k}=e;return i.useEffect(()=>{const w=k.current;if(!A||w===null)return;const R=()=>{s.current=!0},a=()=>{s.current=!1},f=F=>{const M=t.current;if(l.current||n.current===null)return;const T=M.rootRef.current,N=F.relatedTarget;T!==null&&N instanceof Node&&T.contains(N)||z({rearm:!1,commit:!0,onReject:"discard"})},O=()=>{const F=t.current;u.current=null,F.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Am(w.value,w.selectionStart)&&(c.current=!0),y()},d=()=>{n.current!==null&&y()};return w.addEventListener("compositionstart",R),w.addEventListener("compositionend",a),w.addEventListener("focusout",f),w.addEventListener("input",O),document.addEventListener("selectionchange",d),()=>{w.removeEventListener("compositionstart",R),w.removeEventListener("compositionend",a),w.removeEventListener("focusout",f),w.removeEventListener("input",O),document.removeEventListener("selectionchange",d)}},[A,k,z,y]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:B,cancelEdit:K,startEdit:_,getPointing:x,togglePointingArm:$,getReferenceCursor:L,insertReference:S,captureSink:v,restoreSink:E,cycleAnchorAtCaret:p,insertAtCaret:g,getSessionText:b,refreshPaint:D,editing:r}),[B,K,_,x,$,L,S,v,E,p,g,b,D,r])},Dm=(e,t,n)=>{const r=new nr.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}},Mm=(e,t,n)=>{const{tree:r,initialHidden:o}=Dm(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:y}=r.prefixSum(h);return m-y},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),y=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(y+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const y=Math.round(m);r.get(h)===0!=(y===0)&&(s+=y===0?1:-1),r.update(h,y)},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)},kn=(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},ci=(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=Mm(e,t,r)),o.current.model},Sn=256,$o=256,$m=2**32,Fm=4096,ua=Object.freeze([]),da=["background","color","bold","italic","underline","strikethrough"],fa=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Ht=(e,t,n)=>(e.size>=Fm&&e.clear(),e.set(t,n),n),pa=e=>(fa(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),ha=(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},zm=(e,t,n)=>{const r=Math.floor(t/Sn),o=Math.floor(n/$o),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Sn,u=o*$o,h=[];for(const m of e.rules)ha(m.ranges,c,c+Sn-1,u,u+$o-1)&&h.push(m);return Ht(e.buckets,s,h.length===0?ua:h)},Nm=(e,t,n)=>{const r=Math.floor(t/Sn),o=r*$m+n,s=e.columns.get(o);if(s!==void 0)return s;const l=zm(e,t,n),c=r*Sn,u=[];for(const h of l)ha(h.ranges,c,c+Sn-1,n,n)&&u.push(h);return Ht(e.columns,o,u.length===0?ua:u)},Lm=(e,t)=>{for(const n of e)if(rn(n,t))return!0;return!1},ys=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Tr=(e,t)=>e<t?-1:e>t?1:0,ai=(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}},ui=new WeakMap,es=e=>e===null?null:Number(e),Pm=e=>{const t=ui.get(e);if(t!==void 0)return t;const n=e.b,r={a:es(Xe(e.a)),b:n===void 0?null:es(Xe(n))};return ui.set(e,r),r},ma=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Ht(e.numbers,r,es(Xe(n())))},qm=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Pm(e),l=ma(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return ai(e.op,Tr(l,s.a),c===null?null:Tr(l,c));const u=n(),h=e.b;return ai(e.op,Tr(u,e.a),h===void 0?null:Tr(u,h))},_m=(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}},Fo=e=>{const t=Ve(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]},Dr=e=>e.toString(16).padStart(2,"0"),zo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Dr(r(0))}${Dr(r(1))}${Dr(r(2))}`,s=r(3);return s===255?o:`${o}${Dr(s)}`},No=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Im=(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=Fo(t.color),u=Fo(r.color);const h=n===void 0?void 0:Fo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const y=s;s=l,l=y;const q=c;c=u,u=q}if(n!==void 0&&h!==void 0){const y=n.value===void 0?(s+l)/2:n.value;if(s<y&&y<l)return e<=y?zo(c,h,No(e,s,y)):zo(h,u,No(e,y,l))}return zo(c,u,No(e,s,l))},jm=(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 Ht(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return Ht(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return Ht(r.extrema,e.id,{min:c,max:u})},Hm=(e,t,n,r,o,s)=>{const l=ma(s,n,r);if(l===null)return null;const c=jm(e,t,o,s);return c===null?null:Im(l,t.min,t.mid,t.max,c)},Bm=(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:Ht(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Vm=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return qm(s,t,n,o)?e.style:null;case"text":return _m(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Hm(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Bm(e,s,t,r,o)?e.style:null;default:return null}},di=(e,t)=>ls(e,t),Wm=(e,t,n)=>{e[t]=n},Km=(e,t)=>{let n=e;for(const r of da)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Wm(n,r,t[r]));return n},Ym=e=>{let t="";for(const n of da){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},fi=new WeakMap,Um=Object.freeze({}),Xm=e=>{const t=e===void 0?Um:e,n=fi.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return fi.set(t,r),r},Gm=(e,t,n)=>{const r=Xm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=di(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Ym(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=di(e,t);return l!==void 0&&Ht(r.byKey,o,l),l},bs=(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=Nm(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const y of c){if(!Lm(y.ranges,u))continue;const q=Vm(y,u,s,e,n);if(q!==null){if(q!==y.style&&(m=!1),h===null)h=q;else{const H=Km(h,q);H!==h&&(m=!1,h=H)}if(y.stopIfTrue===!0)break}}return h===null?l:Gm(l,h,m)},pi=new WeakMap,Zm=e=>{fa(e,"widthRelevantRules");const t=pi.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 pi.set(e,r),r},Jm=({row:e,col:t,text:n,renderCell:r,__onCellRender:o})=>{const s=i.useRef(!1);return i.useEffect(()=>{const l=s.current?"update":"mount";s.current=!0,o?.(`cell-${e}-${t}`,l,0,0,0,0)}),r?r({row:e,col:t,text:n}):n},Qm=i.memo(Jm),eg=Object.freeze({left:Object.freeze({justifyContent:Un("left")}),center:Object.freeze({justifyContent:Un("center")}),right:Object.freeze({justifyContent:Un("right")})}),tg=4096,hi=new WeakMap,Mr=new Map,ng=(e,t)=>{if(e===null)return eg[t];let n=hi.get(e);n===void 0&&(n={},hi.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:Un(t)},s=JSON.stringify(o);let l=Mr.get(s);return l===void 0&&(Mr.size>=tg&&Mr.clear(),l=Object.freeze(o),Mr.set(s,l)),n[t]=l,l},rg=ys(),og=(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},sg=(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=Pr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=bs(e,r===null?null:r.indexRef.current,r===null?rg:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const y=kc(m,l),q=jt(n,s,1),H=jt(t,o,1),z=Sd(m,q===null?void 0:e.getCellFormat(o,q),H===null?void 0:e.getCellFormat(H,s),n.offsetOf(s)===0,t.offsetOf(o)===0);z!==null&&Object.assign(c,z.attrs),c["data-aqsp-align"]=y,u=ng(z,y)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Tn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&kh(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},lg=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:y,renderCell:q,onScroll:H,onRangeChange:z,focusSink:_,isEditing:K,requestCommit:B,testId:x,__onCellRender:$,cfIndexRef:L,cfMemoRef:S,isPointing:v,tapScrollCircleOptions:E,overscanRows:p,overscanCols:g,background:b})=>{const D=i.useRef(null),A=s??D;if(L===void 0!=(S===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const k=i.useMemo(()=>L===void 0||S===void 0?null:{indexRef:L,memoRef:S},[L,S]),w=i.useCallback(()=>r.get().editVersion,[r]),R=i.useCallback(Z=>r.subscribeCoalesced(Z),[r]),f=i.useSyncExternalStore(R,w,w)+(l??0),O=i.useCallback(Z=>t.sizeOf(Z),[t]),d=i.useCallback(Z=>n.sizeOf(Z),[n]),F=i.useCallback((Z,se)=>e.getCellText(Z,se),[e]),M=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),T=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),N=i.useMemo(()=>({width:rt,tapScrollCircleOptions:E}),[E]),V=i.useRef({row:-1,col:-1,value:void 0}),X=i.useCallback((Z,se)=>{const re={role:"gridcell","aria-rowindex":Z+1,"aria-colindex":se+1,"data-aqsp-cell":"","data-row":Z,"data-col":se,className:"aqsp-cell",..._e(e,Z,se)?{"aria-readonly":"true","data-aqsp-readonly":""}:{}},ve=sg(e,t,n,k,Z,se),Me=V.current;return Me.row=Z,Me.col=se,Me.value=ve===null?void 0:ve.value,ve===null?re:ve.style===null?{...re,...ve.attrs}:{...re,...ve.attrs,style:ve.style}},[e,t,n,k]),J=i.useCallback(Z=>({role:"row","aria-rowindex":Z+1,"data-aqsp-row":Z,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Q=i.useCallback((Z,se,re)=>{let ve=Z;return q===void 0&&e.getCellFormat!==void 0&&(ve=xn(Z,og(V.current,se,re))),W.jsx(Qm,{row:se,col:re,text:ve,renderCell:q,__onCellRender:$})},[f,q,$,e]);return W.jsx("div",{ref:A,className:"aqsp-body","data-aqsp-body":"","data-testid":x?`${x}-body`:void 0,onPointerDownCapture:Z=>{if(!(Z.target instanceof Element&&Z.target.closest("[data-aqsp-cells]")!==null)&&Z.pointerType==="mouse"){if(Z.button!==0){Z.preventDefault();return}if(Z.preventDefault(),v?.()===!0){Z.stopPropagation(),_();return}if(K()&&!B()){Z.stopPropagation(),_();return}_()}},children:W.jsx(nr.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:y,getRowHeight:O,getColWidth:d,getCell:F,getCellProps:X,getRowProps:J,contentProps:M,behaviorOptions:T,scrollBarOptions:N,overscanRows:p,overscanCols:g,background:b,callbackThrottleMs:0,onScroll:H,onRangeChange:z,testId:x,children:Q})})},ig=i.memo(lg),bn=6,Ue=3,Vr=(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:Ue});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-bn,length:Ue}),r.push({kind:"unhide",index:s+1,start:c-Ue,length:Ue})):l>=2*bn?n.push({kind:"resize",index:s,start:c-bn,length:bn}):n.push({kind:"resize",index:s,start:c-Ue,length:Ue})}return[...n,...r]},ga=(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:Ue}),n.push({kind:"resize",index:c,start:h+Ue,length:Ue})):u>=2*bn?n.push({kind:"resize",index:c,start:h,length:bn}):n.push({kind:"resize",index:c,start:h,length:Ue})}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-Ue,length:Ue}),[...n.reverse(),...r]},cg=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:y,dividerTrailingRef:q})=>{const H=nr.useWheelBridge(o),z=i.useCallback(d=>(s.current=d,H(d)),[s,H]),_=i.useCallback(()=>{const{colStart:d,colEnd:F,colVersion:M}=e.get();return`${d}:${F}:${M}`},[e]),K=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(K,_,_);const{colStart:B,colEnd:x}=e.get(),$=t.count===0?0:t.offsetOf(Math.min(B,t.count-1));i.useLayoutEffect(()=>{c.current=$,u()},[$,c,u]);const L=d=>h.some(F=>d>=F.startCol&&d<=F.endCol),S=Math.min(Math.max(0,n),t.count),v=Vc(t,S),E=S>0?kn(t,0,S-1):[],p=Math.min(Math.max(0,r),t.count-S),g=Kc(t,p),b=t.totalSize()-g,D=p>0?kn(t,t.count-p,t.count-1):[],A=kn(t,Math.max(B,S),Math.min(x,Math.max(0,t.count-1)-p)),k=[];for(const d of A)k.push(W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":L(d)?"":void 0,style:{left:t.offsetOf(d)-$,width:t.sizeOf(d)},children:Zn(d)},d));const w=m?Vr(t,A):null,R=w===null?null:w.filter(d=>!(d.kind==="unhide"&&d.index<S&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&g>0)),a=m&&S>0?Vr(t,E):null,f=m&&p>0?ga(t,D):null,O=W.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,R?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-$,width:d.length}},`r${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-$,width:d.length}},`u${d.index}`))]});return W.jsx("div",{ref:z,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:S===0&&p===0?O:W.jsxs(W.Fragment,{children:[E.map(d=>W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":L(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Zn(d)},d)),a?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),W.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:v,right:p>0?`calc(${rt}px + min(${g}px, max(0px, 100% - ${rt+v}px)))`:void 0},children:[O,S>0?W.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,p>0?W.jsx("div",{ref:q,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),p>0?W.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${v}px, calc(100% - ${g+rt}px))`,right:rt},children:W.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[D.map(d=>W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":L(d)?"":void 0,style:{left:t.offsetOf(d)-b,width:t.sizeOf(d)},children:Zn(d)},d)),f?.map(d=>d.kind==="resize"?W.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}`):W.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]})})},ag=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:y,dividerTrailingRef:q})=>{const H=nr.useWheelBridge(n),z=i.useCallback(d=>(r.current=d,H(d)),[r,H]),_=d=>o.some(F=>d>=F.startRow&&d<=F.endRow),K=i.useCallback(()=>{const{rowStart:d,rowEnd:F,rowGeomVersion:M}=e.get();return`${d}:${F}:${M}`},[e]),B=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(B,K,K);const{rowStart:x,rowEnd:$}=e.get(),L=t.count===0?0:t.offsetOf(Math.min(x,t.count-1));i.useLayoutEffect(()=>{l.current=L,c()},[L,l,c]);const S=Math.min(Math.max(0,h),t.count),v=Wc(t,S),E=S>0?kn(t,0,S-1):[],p=Math.min(Math.max(0,m),t.count-S),g=Yc(t,p),b=t.totalSize()-g,D=p>0?kn(t,t.count-p,t.count-1):[],A=kn(t,Math.max(x,S),Math.min($,Math.max(0,t.count-1)-p)),k=[];for(const d of A)k.push(W.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-L,height:t.sizeOf(d)},children:d+1},d));const w=u?Vr(t,A):null,R=w===null?null:w.filter(d=>!(d.kind==="unhide"&&d.index<S&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&g>0)),a=u&&S>0?Vr(t,E):null,f=u&&p>0?ga(t,D):null,O=W.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,R?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-L,height:d.length}},`r${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-L,height:d.length}},`u${d.index}`))]});return W.jsx("div",{ref:z,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:rt},children:S===0&&p===0?O:W.jsxs(W.Fragment,{children:[E.map(d=>W.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"?W.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),W.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:v,bottom:p>0?`calc(min(${g}px, max(0px, 100% - ${v}px)))`:void 0},children:[O,S>0?W.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,p>0?W.jsx("div",{ref:q,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),p>0?W.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${v}px, calc(100% - ${g}px))`},children:W.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[D.map(d=>W.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)-b,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?W.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}`):W.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]})})},ug=9,dg=4,fg=(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},mi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,pg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),y=i.useCallback(S=>s.current!==null?S.pointerId===s.current:S.pointerType==="mouse",[]),q=i.useCallback(()=>{const S=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),S.writeResizeGuide(null);const v=m.current;v!==null&&(window.removeEventListener("pointermove",v.move),window.removeEventListener("pointerup",v.up),m.current=null);const E=c.current;E!==null&&s.current!==null&&E.hasPointerCapture?.(s.current)&&E.releasePointerCapture(s.current),c.current=null,s.current=null,S.repaintOverlay()},[]),H=i.useCallback((S,v)=>{const E=t.current;return S==="col"?v.startRow===0&&v.endRow===E.rowAxis.count-1:v.startCol===0&&v.endCol===E.colAxis.count-1},[]),z=i.useCallback((S,v)=>{const E=t.current,p=E.getSelection().ranges.filter(k=>H(S,k));if(!p.some(k=>S==="col"?v>=k.startCol&&v<=k.endCol:v>=k.startRow&&v<=k.endRow))return[v];const b=p.reduce((k,w)=>k+(S==="col"?w.endCol-w.startCol+1:w.endRow-w.startRow+1),0),D=S==="row"?Math.floor(E.maxOperationCells/ns):E.maxOperationCells;if(b>D)return E.onOperationRejected?.("resize",b,"limit"),null;const A=new Set;for(const k of p){const w=S==="col"?k.startCol:k.startRow,R=S==="col"?k.endCol:k.endRow;for(let a=w;a<=R;a+=1)A.add(a)}return[...A]},[H]),_=i.useCallback((S,v,E)=>{const p=t.current,g=S==="col"?p.colAxis:p.rowAxis,b=rs(g,v,E,{maxOperationCells:p.maxOperationCells,rowHiddenLimit:ts,axisKind:S});if(!b.ok){p.onOperationRejected?.("resize",b.count,b.reason);return}p.resizeTracks(S,b.entries)},[]),K=i.useCallback((S,v)=>{if(v===S.initialSize)return;const E=S.kind==="unhide"?[S.index]:z(S.axis,S.index);E!==null&&_(S.axis,E.map(p=>({index:p,size:v})),S.index)},[z,_]),B=i.useCallback((S,v)=>{const E=t.current,p=z("col",v);if(p===null)return;const g=E.handleRef.current,b=g===null?null:g.getFrozenSize(),D=b===null?0:b.rows,A=b===null?0:b.trailingRows,{rowStart:k,rowEnd:w}=E.viewStore.get(),R=Math.min(w,E.rowAxis.count-1),a=[],f=new Set,O=re=>{!f.has(re)&&E.rowAxis.sizeOf(re)>0&&(f.add(re),a.push(re))};for(let re=0;re<D;re+=1)O(re);for(let re=k;re<=R;re+=1)O(re);for(let re=E.rowAxis.count-A;re<E.rowAxis.count;re+=1)O(re);if(a.length===0)return;const d=p.length*a.length,F=Math.floor(E.maxOperationCells/dg);if(d>F){E.onOperationRejected?.("resize",d,"limit");return}const M=document.createElement("canvas").getContext("2d");if(M===null)return;const T=getComputedStyle(S),N=`${T.fontStyle} ${T.fontWeight} ${T.fontSize} ${T.fontFamily}`,V=E.adapter.getConditionalFormats===void 0?null:Zm(E.adapter.getConditionalFormats()),X=ys(),J=new WeakMap,Q=new Map;for(const re of p){const ve=V===null?null:pa(V.filter(Me=>Me.ranges.some(Te=>re>=Te.startCol&&re<=Te.endCol)));for(const Me of a){const Te=E.adapter.getCellText(Me,re),Ne=E.adapter.getCellFormat===void 0?void 0:bs(E.adapter,ve,X,Me,re,()=>Te),at=Ne===void 0?N:fg(Ne,J,T),st=xn(Te,Ne===void 0?void 0:Ne.value),ut=Q.get(at);ut===void 0?Q.set(at,[{col:re,text:st}]):ut.push({col:re,text:st})}}const Z=new Map;for(const[re,ve]of Q){M.font=re;for(const Me of ve){const Te=M.measureText(Me.text).width,Ne=Z.get(Me.col);(Ne===void 0||Te>Ne)&&Z.set(Me.col,Te)}}const se=[];for(const re of p){const ve=Z.get(re);ve!==void 0&&ve>0&&se.push({index:re,size:Math.ceil(ve)+ug})}se.length!==0&&_("col",se,v)},[z,_]),{enabled:x,colBandRef:$,rowBandRef:L}=e;return i.useEffect(()=>{const S=$.current,v=L.current;if(!x||S===null||v===null)return;const E=F=>F==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",p=(F,M)=>{if(!(M instanceof Element))return null;const T=M.closest(E(F));if(T===null)return null;const N=T.hasAttribute("data-aqsp-unhide"),V=Number(T.getAttribute(N?"data-aqsp-unhide":F==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),X=T.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:N?"unhide":"resize",index:V,anchor:X}},g=F=>{if(!(n.current&&y(F)))return;const M=r.current;if(M===null)return;const T=(M.axis==="col"?F.clientX-M.startClientX:F.clientY-M.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(M.anchor==="trailing"?M.initialSize-T:M.initialSize+T)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const N=r.current;if(!n.current||N===null)return;const V=t.current,X=N.axis==="col"?V.colAxis:V.rowAxis;V.writeResizeGuide({axis:N.axis,position:mi(N,X,o.current),anchor:N.anchor})}))},b=()=>{const F=r.current,M=o.current;q(),F!==null&&K(F,M)},D=F=>{g(F),n.current&&y(F)&&(l.current&1)!==0&&(F.buttons&1)===0&&b()},A=F=>{F.button!==0||!(n.current&&y(F))||b()},k=(F,M)=>T=>{const N=t.current;if(h.current=T.pointerType,T.pointerType!=="mouse")return;if(T.button!==0){T.preventDefault();return}const V=p(F,T.target);if(V===null)return;if(T.stopPropagation(),T.preventDefault(),N.isPointing()){N.focusSink();return}if(N.isEditing()&&!N.requestCommit()){N.focusSink();return}N.focusSink();const X=F==="col"?N.colAxis:N.rowAxis,J={axis:F,kind:V.kind,index:V.index,anchor:V.anchor,initialSize:X.sizeOf(V.index),startClientX:T.clientX,startClientY:T.clientY};r.current=J,o.current=J.initialSize,l.current=T.buttons,n.current=!0,N.repaintOverlay(),s.current=T.pointerId,c.current=M;try{M.setPointerCapture(T.pointerId)}catch{s.current=null}const Q=D,Z=A;m.current={move:Q,up:Z},window.addEventListener("pointermove",Q),window.addEventListener("pointerup",Z),N.writeResizeGuide({axis:F,position:mi(J,X,o.current),anchor:J.anchor})},w=(F,M)=>T=>{const N=t.current;if(h.current!=="mouse")return;const V=M.getRootNode(),X=V instanceof ShadowRoot?V:M.ownerDocument,J=T.target instanceof Element&&T.target.closest(E(F))!==null?T.target:typeof X.elementFromPoint=="function"?X.elementFromPoint(T.clientX,T.clientY):null,Q=p(F,J);if(Q!==null){if(T.stopPropagation(),N.isEditing()){N.focusSink();return}if(Q.kind==="unhide"){_(F,[{index:Q.index,size:F==="col"?N.defaultColumnWidth:N.defaultRowHeight}],null);return}if(N.autofitEnabled){if(F==="row"){const Z=z("row",Q.index);Z!==null&&_("row",Z.map(se=>({index:se,size:N.defaultRowHeight})),Q.index);return}B(M,Q.index)}}},R=F=>{!n.current||s.current===null||F.pointerId!==s.current||q()},a=k("col",S),f=k("row",v),O=w("col",S),d=w("row",v);return S.addEventListener("pointerdown",a,{capture:!0}),v.addEventListener("pointerdown",f,{capture:!0}),S.addEventListener("dblclick",O),v.addEventListener("dblclick",d),S.addEventListener("lostpointercapture",R),v.addEventListener("lostpointercapture",R),()=>{S.removeEventListener("pointerdown",a,{capture:!0}),v.removeEventListener("pointerdown",f,{capture:!0}),S.removeEventListener("dblclick",O),v.removeEventListener("dblclick",d),S.removeEventListener("lostpointercapture",R),v.removeEventListener("lostpointercapture",R),q()}},[x,$,L,y,q,K,_,z,B]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&q()},cancelDrag:q}),[q])},vs=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,hg=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>vs(n,t.ranges[r]))&&kt(e.anchor,t.anchor)&&kt(e.active,t.active),mg=(e,t)=>{const n=e.ranges[e.ranges.length-1];return vs(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},tr=(e,t,n)=>n.extend?en(e,t):n.append?{ranges:[...e.ranges,pe(t,t)],anchor:t,active:t}:e.ranges.length===1&&kt(e.anchor,t)&&kt(e.active,t)&&vs(e.ranges[0],pe(t,t))?e:{ranges:[pe(t,t)],anchor:t,active:t},gg=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),en=(e,t)=>{const n=mg(e,pe(e.anchor,t));return n.ranges.some(r=>rn(r,n.active))?n:{...n,active:gg(n.active,n.ranges[n.ranges.length-1])}},wa=(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(pe({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(pe({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(pe({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(pe({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[pe(n,n)],anchor:n,active:n};const s=o.findIndex(c=>rn(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}},wg=(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}}},Ca=(e,t)=>{const n=e.ranges.findIndex(o=>rn(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=wg(e.ranges,r.rangeIndex,r.cell,t),!kt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},bt=24,gi=32,Wr=4,mn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),y=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),q=i.useCallback(()=>{const z=u.current,_=e.current,K=m.current;if(z===null||_===null||K===null){c.current=null;return}const{clientX:B,clientY:x}=z.getPointerPosition(),$=l.current,L=(B-K.left)/$,S=(x-K.top)/$,v=_.getViewportSize(),E=v.width,p=v.height;if(E<=0||p<=0){c.current=requestAnimationFrame(q);return}const g=R=>Math.min(gi,Math.ceil(R/bt*gi));let b=0,D=0;if(s!=="x"){const R=_.getFrozenSize(),a=R.trailingVisibleHeight;S>p-a-bt?z.anchorRow!==void 0&&R.trailingRows>0&&z.anchorRow>=t.count-R.trailingRows&&a>0&&S>=p-a||(b=g(S-(p-a-bt))):S<R.height+bt&&(z.anchorRow!==void 0&&z.anchorRow<R.rows&&R.height>0&&S<R.height||(b=-g(R.height+bt-S)))}if(s!=="y"){const R=_.getFrozenSize(),a=R.trailingVisibleWidth;L>E-a-bt?z.anchorCol!==void 0&&R.trailingCols>0&&z.anchorCol>=n.count-R.trailingCols&&a>0&&L>=E-a||(D=g(L-(E-a-bt))):L<R.width+bt&&(z.anchorCol!==void 0&&z.anchorCol<R.cols&&R.width>0&&L<R.width||(D=-g(R.width+bt-L)))}const A=D!==0||b!==0?_.scrollBy({x:D!==0?D:void 0,y:b!==0?b:void 0}):_.getScrollPosition(),k=A.y,w=A.x;if(k>=0&&w>=0&&t.totalSize()>0&&n.totalSize()>0){const R=_.getFrozenSize(),a=lr({row:ar(t,S,{scroll:k,frozenSize:R.height,trailingSize:R.trailingHeight,extent:v.height}),col:cr(n,L,{scroll:w,frozenSize:R.width,trailingSize:R.trailingWidth,extent:v.width})},t.count,n.count),f=h.current;(b!==0||D!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(z.buildRange(a)))}c.current=requestAnimationFrame(q)},[e,t,n,s,o]),H=i.useCallback(z=>{y(),u.current=z,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(q)},[y,q,r]);return i.useEffect(()=>{const z=()=>{document.visibilityState==="hidden"&&y()};return document.addEventListener("visibilitychange",z),()=>{document.removeEventListener("visibilitychange",z),y()}},[y]),i.useMemo(()=>({start:H,stop:y}),[H,y])},wi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),y=i.useRef(!1),q=i.useRef(0),H=i.useCallback((v,E)=>{const{axis:p,mainAxis:g,handleRef:b,zoomRef:D}=t.current,A=s.current;if(A===null||g.totalSize()===0)return null;const k=D.current,w=b.current;if(w===null)return null;if(p==="col"){const O=w.getScrollPosition().x;if(O<0)return null;const d=w.getFrozenSize(),F=w.getViewportSize();return Math.min(Math.max(cr(g,(v-A.left)/k,{scroll:O,frozenSize:d.width,trailingSize:d.trailingWidth,extent:F.width}),0),g.count-1)}const R=w.getScrollPosition().y;if(R<0)return null;const a=w.getFrozenSize(),f=w.getViewportSize();return Math.min(Math.max(ar(g,(E-A.top)/k,{scroll:R,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),z=i.useCallback((v,E)=>{const{axis:p,crossCount:g}=t.current;return p==="col"?{press:{row:0,col:v},extend:{row:g-1,col:E}}:{press:{row:v,col:0},extend:{row:E,col:g-1}}},[]),_=i.useCallback((v,E)=>{const{axis:p,crossCount:g}=t.current;return v.ranges.some(b=>p==="col"?b.startRow===0&&b.endRow===g-1&&E>=b.startCol&&E<=b.endCol:b.startCol===0&&b.endCol===g-1&&E>=b.startRow&&E<=b.endRow)},[]),K=i.useRef(!1),B=i.useRef({clientX:0,clientY:0}),x=i.useCallback(()=>{K.current=!1;const{autoScroller:v,headerRef:E,onDragFrame:p}=t.current;n.current=!1,r.current=null,m.current=null,y.current=!1,q.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),v.stop();const g=E.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,p(null),t.current.repaintOverlay()},[]),$=i.useCallback(()=>{if(!n.current)return;const v=r.current;v!==null&&t.current.setSelection(v),x()},[x]),{enabled:L,headerRef:S}=e;return i.useEffect(()=>{const v=S.current;if(!L||v===null)return;const E=w=>{const R=t.current;if(w.pointerType!=="mouse")return;if(w.button!==0){w.preventDefault();return}if(y.current=!1,R.pointing?.getPointing()){s.current=v.getBoundingClientRect();const d=H(w.clientX,w.clientY);if(d===null)return;w.preventDefault(),R.focusSink(),R.pointing.insertReference(R.axis==="col"?{row:0,col:d}:{row:d,col:0},R.axis==="col"?"columns":"rows");return}if(R.isEditing()&&!R.requestCommit()){w.preventDefault(),R.focusSink();return}s.current=v.getBoundingClientRect();const a=H(w.clientX,w.clientY);if(a===null)return;w.preventDefault(),R.focusSink();const f=R.getSelection();r.current=f;const O=w.ctrlKey||w.metaKey;if(w.shiftKey){const d=R.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:F}=z(a,a),M={...f,anchor:d};R.setSelection(en(M,F)),o.current=R.axis==="col"?d.col:d.row}else if(O&&_(f,a))y.current=!0,q.current=a,o.current=a;else{const{press:d,extend:F}=z(a,a),M=tr(f,d,{extend:!1,append:O});R.setSelection(en(M,F)),o.current=a}n.current=!0,R.repaintOverlay(),l.current={clientX:w.clientX,clientY:w.clientY},u.current=w.pointerId,h.current=w.buttons;try{v.setPointerCapture(w.pointerId)}catch{u.current=null}m.current=d=>{const F=t.current.axis==="col"?d.col:d.row,{press:M}=z(o.current,o.current),{extend:T}=z(o.current,F);return pe(M,T)},R.autoScroller.stop(),K.current=!1,B.current={clientX:w.clientX,clientY:w.clientY}},p=w=>u.current!==null?w.pointerId===u.current:w.pointerType==="mouse",g=w=>{if(n.current&&p(w)){if(y.current){const R=w.clientX!==l.current.clientX||w.clientY!==l.current.clientY;if(l.current={clientX:w.clientX,clientY:w.clientY},!R)return;const a=H(w.clientX,w.clientY);if(a===null||a===q.current)return;y.current=!1;const f=t.current,{press:O,extend:d}=z(q.current,q.current),F=tr(f.getSelection(),O,{extend:!1,append:!0});f.setSelection(en(F,d));const M=m.current,T=Math.abs(w.clientX-B.current.clientX),N=Math.abs(w.clientY-B.current.clientY);M!==null&&Math.max(T,N)>=Wr&&(K.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:M,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:w.clientX,clientY:w.clientY},!K.current&&m.current!==null){const R=Math.abs(w.clientX-B.current.clientX),a=Math.abs(w.clientY-B.current.clientY);Math.max(R,a)>=Wr&&(K.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const R=m.current;if(!n.current||R===null)return;const a=H(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(R(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},b=w=>{g(w),n.current&&p(w)&&(h.current&1)!==0&&(w.buttons&1)===0&&A(w)},D=w=>{w.button!==0||!(n.current&&p(w))||A(w)},A=w=>{const R=t.current;if(y.current){const{press:f,extend:O}=z(q.current,q.current);R.setSelection(wa(R.getSelection(),pe(f,O),f)),x();return}const a=H(w.clientX,w.clientY);if(a!==null){const{extend:f}=z(o.current,a);R.setSelection(en(R.getSelection(),f))}x()},k=w=>{!n.current||u.current===null||w.pointerId!==u.current||$()};return v.addEventListener("pointerdown",E),v.addEventListener("pointermove",b),v.addEventListener("pointerup",D),v.addEventListener("lostpointercapture",k),()=>{v.removeEventListener("pointerdown",E),v.removeEventListener("pointermove",b),v.removeEventListener("pointerup",D),v.removeEventListener("lostpointercapture",k),x()}},[L,S,H,z,x,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:$,cancelDrag:x}),[$,x])},Cg=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),y=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):y>l+u-h.trailingVisibleHeight&&o.scrollBy({y:y-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),y=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):y>s+c-h.trailingVisibleWidth&&o.scrollBy({x:y-(s+c-h.trailingVisibleWidth)})}},yg=50,bg=100,ya=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<yg:!1,Bn={selectAll:Qt("Ctrl+A"),undo:Qt("Ctrl+Z"),redo:Qt("Ctrl+Y"),redoShiftZ:Qt("Ctrl+Shift+Z"),pasteValues:Qt("Ctrl+Shift+V")},vg=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Rg={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},kg=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Sg=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,y=u.current;if(!l||m===null||y===null)return;const q=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},H=(a,f,O)=>jt(a,f,O)??f,z=(a,f)=>{const O=s.current;return f==="left"||f==="right"?{row:a.row,col:H(O.colAxis,a.col,f==="right"?1:-1)}:{row:H(O.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),K=a=>a.indexAt(a.totalSize()-1),B=(a,f,O,d)=>{if(a.sizeOf(f)>0)return f;const F=jt(a,f,O);if(F!==null)return F;const M=jt(a,f,O===1?-1:1);return M!==null?M:d},x=()=>{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}},$=a=>z(x(),a),L=(a,f)=>{const O=s.current,d=f==="left"||f==="right",F=f==="right"||f==="down"?1:-1;let M;return O.findDataEdge!==void 0?(M=O.findDataEdge({row:a.row,col:a.col},f),S(M,a,f)):M={row:f==="down"?O.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?O.colAxis.count-1:f==="left"?0:a.col},d?{row:M.row,col:B(O.colAxis,M.col,F,a.col)}:{row:B(O.rowAxis,M.row,F,a.row),col:M.col}},S=(a,f,O)=>{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=O==="left"||O==="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}})`)},v=(a,f,O)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${O} component ${a} (count ${f})`)},E=a=>{const f=s.current,O=f.getSelection();if(Ca(O,a)===O){f.moveActive({mode:"reset",cell:z(O.active,a)});return}f.moveActive({mode:"cycle",direction:a})},p=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,O=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
21
- ${a.value.slice(O)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const O=s.current,d=h.current?.getViewportSize().height??-1;return d<=0?H(O.rowAxis,a,f==="down"?1:-1):O.rowAxis.indexAt(O.rowAxis.offsetOf(a)+(f==="down"?d:-d))},b=a=>{const f=s.current;if(r.current=!1,ya(a,t.current))return;const O=a.ctrlKey||a.metaKey,d=a.altKey,F=Rg[a.key];if(o.current&&!vg.has(a.key)&&!f.isDragging()&&q(),f.isEditing()){const T=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!O&&!a.shiftKey&&!d&&f.abortDrag();return}const N=f.pointing;if(N!==void 0){if(F!==void 0&&!d){const X=N.getReferenceCursor();if(X!==null){a.preventDefault();const J=O?L(X.cursor,F):z(X.cursor,F);if(f.ensureCellVisible(J),N.insertReference(a.shiftKey?pe(X.origin,J):J,X.axis),f.onPointFrame!==void 0){const Q=a.shiftKey?pe(X.origin,J):pe(J,J);f.onPointFrame(X.axis==="columns"?pe({row:0,col:Q.startCol},{row:f.rowAxis.count-1,col:Q.endCol}):X.axis==="rows"?pe({row:Q.startRow,col:0},{row:Q.endRow,col:f.colAxis.count-1}):Q),o.current=!0}return}}if(a.key==="F2"&&!O&&!a.shiftKey&&!d&&N.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!O&&!a.shiftKey&&!d&&N.cycleAnchorAtCaret()){a.preventDefault();return}}const V=f.commands;if(V!==void 0){const X=zl(V.table,a);if(X!==null&&Cs.has(X)&&V.isAvailable(X)){a.preventDefault(),V.execute(X);return}}if(F!==void 0&&!d){if(O&&a.shiftKey){a.preventDefault();return}if(O)return;if(T==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:$(F)}):f.moveActive({mode:"reset",cell:z(f.getSelection().active,F)});return}return}if(a.key==="Enter"&&d&&!O&&!a.shiftKey){a.preventDefault(),p();return}if((a.key==="Enter"||a.key==="Tab")&&!O&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=!a.shiftKey;E(a.key==="Tab"?X?"right":"left":X?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!O&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(X.row,a.key==="PageDown"?"down":"up"),col:X.col}});return}if(a.key==="Escape"&&!O&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const M=f.commands;if(M!==void 0){const T=zl(M.table,a);if(T!==null&&M.isAvailable(T)){a.preventDefault(),M.execute(T);return}}if(F!==void 0&&!d){const T=F==="left"||F==="right",N=F==="right"||F==="down"?1:-1;if(O&&a.shiftKey){a.preventDefault();const V=f.getSelection(),X=x();let J;if(f.findDataEdge!==void 0){const Q=T?{row:V.active.row,col:X.col}:{row:X.row,col:V.active.col},Z=f.findDataEdge(Q,F);J=T?Z.col:Z.row,v(J,T?f.colAxis.count:f.rowAxis.count,T?"col":"row"),J=B(T?f.colAxis:f.rowAxis,J,N,T?X.col:X.row)}else{const Q=T?f.colAxis:f.rowAxis;J=N===1?K(Q):_(Q)}f.moveActive({mode:"extend",cell:T?{row:X.row,col:J}:{row:J,col:X.col}});return}if(O){a.preventDefault(),f.moveActive({mode:"reset",cell:L(f.getSelection().active,F)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:$(F)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,F)});return}if(kg(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!O&&!d){a.preventDefault();const T=!a.shiftKey;E(a.key==="Tab"?T?"right":"left":T?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const N=x();f.moveActive({mode:"extend",cell:{row:O?_(f.rowAxis):N.row,col:_(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:O?_(f.rowAxis):T.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const N=x();f.moveActive({mode:"extend",cell:{row:O?K(f.rowAxis):N.row,col:K(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:O?K(f.rowAxis):T.row,col:K(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!O&&!d){a.preventDefault();const T=a.key==="PageDown"?"down":"up";if(a.shiftKey){const V=x();f.moveActive({mode:"extend",cell:{row:g(V.row,T),col:V.col}});return}const N=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(N.row,T),col:N.col}});return}if(a.key==="F2"&&!O&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!O&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection(),N=ct(T.ranges);if(N>f.maxOperationCells){f.onOperationRejected?.("delete",N,"limit");return}if(f.adapter!==void 0&&yn(f.adapter,T.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:N});return}const V=[],X=f.adapter!==void 0&&qr(f.adapter).hyperlink;qt(T.ranges,J=>{V.push(X?{row:J.row,col:J.col,text:"",hyperlink:null}:{row:J.row,col:J.col,text:""})}),f.commitEdits(V,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(O||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(In(Bn.selectAll,a)){a.preventDefault();const T=f.getSelection(),N=pe({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[N],anchor:T.anchor,active:T.active});return}if(In(Bn.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(In(Bn.redo,a)||In(Bn.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!O&&!d||a.key==="ContextMenu"&&!O&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection().active;f.ensureCellVisible(T);const N=h.current,V=N===null?{x:0,y:0}:N.getScrollPosition(),X=Math.max(0,V.y),J=Math.max(0,V.x),Q=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),Z=N===null?{width:0,height:0}:N.getViewportSize(),se=f.zoomRef.current;f.onCellContextMenu?.(T,{kind:"keyboard",cellRect:{top:nn(f.rowAxis,T.row,{scroll:X,frozenCount:Q.rows,trailingCount:Q.trailingRows,extent:Z.height})*se,left:tn(f.colAxis,T.col,{scroll:J,frozenCount:Q.cols,trailingCount:Q.trailingCols,extent:Z.width})*se,width:f.colAxis.sizeOf(T.col)*se,height:f.rowAxis.sizeOf(T.row)*se}});return}if(a.key===" "&&!d&&O!==a.shiftKey){a.preventDefault();const T=f.getSelection(),N=T.ranges.map(V=>O?pe({row:0,col:V.startCol},{row:f.rowAxis.count-1,col:V.endCol}):pe({row:V.startRow,col:0},{row:V.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:N,anchor:T.anchor,active:T.active});return}if(f.pendingPasteOptionsRef!==void 0&&In(Bn.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}},D=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},A=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},bg)},k=()=>{const a=s.current;if(q(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},w=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},R=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),q()};return m.addEventListener("keydown",b),m.addEventListener("keyup",w),m.addEventListener("blur",R),m.addEventListener("compositionstart",D),m.addEventListener("compositionend",A),m.addEventListener("input",k),()=>{m.removeEventListener("keydown",b),m.removeEventListener("keyup",w),m.removeEventListener("blur",R),m.removeEventListener("compositionstart",D),m.removeEventListener("compositionend",A),m.removeEventListener("input",k),n.current!==null&&window.clearTimeout(n.current),q()}},[l,c,u,h])},Eg=4,xg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Ag=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),y=i.useRef(0),q=i.useRef(null),H=i.useRef(null),z=i.useRef(!1),_=i.useCallback(v=>m.current!==null?v.pointerId===m.current:v.pointerType==="mouse",[]),K=i.useCallback((v,E)=>{const{handleRef:p,rowAxis:g,colAxis:b}=t.current,D=p.current,A=s.current;if(D===null||A===null)return null;const{x:k,y:w}=D.getScrollPosition();if(w<0||k<0||g.totalSize()===0||b.totalSize()===0)return null;const R=t.current.zoomRef.current,a=D.getFrozenSize(),f=D.getViewportSize();return lr({row:ar(g,(E-A.top)/R,{scroll:w,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:cr(b,(v-A.left)/R,{scroll:k,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,b.count)},[]),B=i.useCallback(v=>{const E=r.current;if(E===null)return pe(v,v);const p=pe({row:Math.min(E.startRow,v.row),col:Math.min(E.startCol,v.col)},{row:Math.max(E.endRow,v.row),col:Math.max(E.endCol,v.col)}),g=p.startRow!==E.startRow||p.endRow!==E.endRow||p.startCol!==E.startCol||p.endCol!==E.endCol;return o.current=g?p:null,g?p:E},[]),x=i.useCallback(()=>{const v=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,q.current!==null&&(cancelAnimationFrame(q.current),q.current=null),v.xAutoScroller.stop(),v.yAutoScroller.stop(),z.current=!1,u.current=!1,h.current={dx:0,dy:0},v.writeFillPreview(null);const E=H.current;E!==null&&(window.removeEventListener("pointermove",E.move),window.removeEventListener("pointerup",E.up),H.current=null);const p=t.current.handleNodeRef.current;p!==null&&m.current!==null&&p.hasPointerCapture?.(m.current)&&p.releasePointerCapture(m.current),m.current=null,v.repaintOverlay()},[]),$=i.useCallback(()=>{const v=t.current,E=r.current,p=o.current;if(x(),E===null||p===null)return;const g=Tp(E,p);if(g>v.maxOperationCells){v.onOperationRejected?.("fill",g,"limit");return}if(yn(v.adapter,Dp(E,p))){const A=(p.endRow-p.startRow+1)*(p.endCol-p.startCol+1),k=(E.endRow-E.startRow+1)*(E.endCol-E.startCol+1);v.rejectReadOnly({kind:"operation",op:"fill",cellCount:A-k});return}const b=Mp((A,k)=>Ac(v.adapter,A,k),E,p,Oc);if(v.commitEdits(b,{source:"fill"})===null)return;const D=v.getSelection();v.setSelection({ranges:[p],anchor:D.anchor,active:D.active})},[x]),{enabled:L,handleNodeRef:S}=e;return i.useEffect(()=>{const v=S.current;if(!L||v===null)return;const E=A=>{p(A),n.current&&_(A)&&(y.current&1)!==0&&(A.buttons&1)===0&&$()},p=A=>{if(!(n.current&&_(A)))return;l.current={clientX:A.clientX,clientY:A.clientY};const k=Math.abs(A.clientX-c.current.clientX),w=Math.abs(A.clientY-c.current.clientY);if(!u.current&&Math.max(k,w)>=Eg&&(u.current=!0),!!u.current){if(!z.current){const R=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:B,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};R.xAutoScroller.start(a),R.yAutoScroller.start(a),z.current=!0}q.current===null&&(q.current=requestAnimationFrame(()=>{if(q.current=null,!(n.current&&u.current))return;const R=K(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);R!==null&&t.current.writeFillPreview(B(R))}))}},g=A=>{A.button!==0||!(n.current&&_(A))||$()},b=A=>{const k=t.current;if(A.pointerType!=="mouse")return;if(A.button!==0){A.preventDefault();return}A.preventDefault(),A.stopPropagation(),k.focusSink();const w=k.getSelection(),R=w.ranges[w.ranges.length-1];r.current=R,o.current=null,u.current=!1,k.xAutoScroller.stop(),k.yAutoScroller.stop(),z.current=!1,c.current={clientX:A.clientX,clientY:A.clientY},l.current=c.current,y.current=A.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},O=f.y;if(a!==null&&O>=0&&f.x>=0){const M=f.x,T=k.zoomRef.current,N=k.handleRef.current?.getFrozenSize()??xg,V=k.handleRef.current?.getViewportSize()??{width:0,height:0},X={scroll:M,frozenCount:N.cols,trailingCount:N.trailingCols,extent:V.width},J={scroll:O,frozenCount:N.rows,trailingCount:N.trailingRows,extent:V.height},Q=tn(k.colAxis,R.endCol,X)+k.colAxis.sizeOf(R.endCol),Z=nn(k.rowAxis,R.endRow,J)+k.rowAxis.sizeOf(R.endRow),se=Q-1,re=R.endCol>=N.cols&&N.width>0?Math.max(se,N.width):se,Me=!(R.endCol>=k.colAxis.count-N.trailingCols)&&N.trailingWidth>0?Math.min(re,V.width-N.trailingVisibleWidth-1):re,Te=Z-1,Ne=R.endRow>=N.rows&&N.height>0?Math.max(Te,N.height):Te,st=!(R.endRow>=k.rowAxis.count-N.trailingRows)&&N.trailingHeight>0?Math.min(Ne,V.height-N.trailingVisibleHeight-1):Ne;h.current={dx:A.clientX-(a.left+Me*T),dy:A.clientY-(a.top+st*T)}}else h.current={dx:0,dy:0};m.current=A.pointerId;try{v.setPointerCapture(A.pointerId)}catch{m.current=null}const d=E,F=g;H.current={move:d,up:F},window.addEventListener("pointermove",d),window.addEventListener("pointerup",F),k.writeFillPreview(r.current)},D=A=>{!n.current||m.current===null||A.pointerId!==m.current||x()};return v.addEventListener("pointerdown",b),v.addEventListener("lostpointercapture",D),()=>{v.removeEventListener("pointerdown",b),v.removeEventListener("lostpointercapture",D),x()}},[L,S,_,K,B,x,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&x()},cancelDrag:x}),[x])},Og=320,_r=8,Tg=64,Dg=150,ba=e=>Math.max(0,Math.min(Og,e.width-rt-_r)),Mg=(e,t,n)=>{const r=n.width-rt,o=n.height-rt,s=ba(n),l=Math.max(0,Math.min(t,o-_r)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+s<=r,m=[e.left,c-s],y=[{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 y)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const q=o-u,H=e.top,z=Math.min(l,Math.max(q,H));if(z>=Tg){const _=q>=H?u:e.top-z;for(const K of m)if(h(K))return{left:K,top:_,width:s,height:z}}return{left:_r,top:_r,width:s,height:l}},$g=(e,t,n,r)=>t===null||e!==null&&kt(e,t)||n?!1:r(t),Fg=(e,t)=>{switch(e.kind){case"note":return W.jsx(ea,{ctx:e,labels:t});case"note-tip":return W.jsx(ta,{ctx:e,labels:t});case"comment":return W.jsx(Gc,{ctx:e,labels:t});case"link":return W.jsx(Zc,{ctx:e,labels:t});case"list":return W.jsx(Jc,{ctx:e,labels:t});default:return W.jsx(Qc,{ctx:e,labels:t})}},Lo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,zg=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const y=Lo(s),q=Lo(l),H=i.useRef(null),z=($,L)=>{const S=m.current.getLayerSize();$.style.width=`${ba(S)}px`,$.style.maxHeight="";const v=Mg(L,$.offsetHeight,S);$.style.left=`${v.left-L.left}px`,$.style.top=`${v.top-L.top}px`,$.style.maxHeight=`${v.height}px`};i.useLayoutEffect(()=>{const $=c.current;if($===null||s===null){H.current=null;return}if(z($,s.anchorRect),s.kind==="message")return;const L=Lo(s);if(H.current===L)return;H.current=L;const S=$.querySelector("[data-aqsp-popover-autofocus]");S!==null?S.focus({preventScroll:!0}):$.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const $=u.current,L=h.current;$===null||L===null||z($,L.anchorRect)},[q]);const _=$=>t===void 0?Fg($,n):t($),K=$=>{e.isCompositionKey($.nativeEvent)&&$.stopPropagation()},B=$=>{$.key==="Escape"&&!$.defaultPrevented&&($.preventDefault(),e.close())},x=$=>{e.registerCompositionEnd($.timeStamp)};return W.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:K,onKeyDown:B,onCompositionEnd:x,children:[W.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:W.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},y)}),W.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:W.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:_(l)})})]})},Ng=["note","note-tip","comment","link","list","message"],Lg=(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}},Vn=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Lg(e,n),Pg=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),y=i.useRef(null),q=i.useRef(null),H=i.useRef(null),z=i.useId(),_=i.useCallback(M=>{const T=t.current,N=T.handleRef.current,V=N===null?{x:0,y:0}:N.getScrollPosition(),X=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),J=N===null?{width:0,height:0}:N.getViewportSize();return{top:nn(T.rowAxis,M.row,{scroll:Math.max(0,V.y),frozenCount:X.rows,trailingCount:X.trailingRows,extent:J.height}),left:tn(T.colAxis,M.col,{scroll:Math.max(0,V.x),frozenCount:X.cols,trailingCount:X.trailingCols,extent:J.width}),width:T.colAxis.sizeOf(M.col),height:T.rowAxis.sizeOf(M.row)}},[]),K=i.useCallback(M=>{const T=t.current;T.anchors.current={...T.anchors.current,...M},T.repaintOverlay()},[]),B=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),x=i.useCallback(()=>{const M=t.current.sinkRef.current;if(M===null)return;const T=c.current;T!==null&&kt(T,t.current.getActive())?M.setAttribute("aria-describedby",z):M.getAttribute("aria-describedby")===z&&M.removeAttribute("aria-describedby")},[z]),$=i.useCallback(()=>(B(),h.current=!1,c.current===null?!1:(c.current=null,s(null),K({tip:null}),x(),!0)),[B,K,x]),L=i.useCallback(()=>{B(),m.current=window.setTimeout(()=>{m.current=null,$()},Dg)},[B,$]),S=i.useCallback(M=>{const T=t.current;B();const N=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(M.row,M.col);N===void 0||N===""||(c.current=M,s({kind:"note-tip",cell:M,anchorRect:_(M),current:N,close:$}),K({tip:M}),x())},[_,B,$,K,x]),v=i.useCallback(M=>{const T=t.current;if(M===null&&h.current)return;const N=u.current;u.current=M;const V=c.current;if(V!==null&&M!==null&&kt(V,M)){B();return}const X=J=>{const Q=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(J.row,J.col);return Q!==void 0&&Q!==""};if($g(N,M,T.isDraggingAny(),X)){M!==null&&S(M);return}V!==null&&L()},[S,B,L]),E=i.useCallback((M,T)=>{const N=t.current,V=N.bodyRef.current,X=N.handleRef.current;if(V===null||X===null)return null;const J=V.getBoundingClientRect(),Q=N.zoomRef.current,Z=X.getScrollPosition(),se=X.getFrozenSize(),re=X.getViewportSize();return lr({row:ar(N.rowAxis,(T-J.top)/Q,{scroll:Math.max(0,Z.y),frozenSize:se.height,trailingSize:se.trailingHeight,extent:re.height}),col:cr(N.colAxis,(M-J.left)/Q,{scroll:Math.max(0,Z.x),frozenSize:se.width,trailingSize:se.trailingWidth,extent:re.width})},N.rowAxis.count,N.colAxis.count)},[]),p=i.useCallback(M=>{q.current=M,y.current===null&&(y.current=requestAnimationFrame(()=>{y.current=null;const T=q.current;v(T===null?null:"cell"in T?T.cell:E(T.clientX,T.clientY))}))},[v,E]),g=i.useCallback(M=>p({cell:M}),[p]),b=i.useCallback(()=>$(),[$]),D=i.useCallback(()=>{if(l.current===null)return;const M=t.current;l.current=null,r(null),K({interactive:null}),M.focusSink({preventScroll:!0}),M.isEditing()||M.rearmSink()},[K]),A=i.useCallback(M=>{l.current=M.kind,r(M),K({interactive:M.cell})},[K]),k=i.useCallback(M=>{const T=t.current;return Sc(T.adapter)?{cellReadOnly:_e(T.adapter,M.row,M.col)}:{}},[]),w=i.useCallback((M,T)=>{const N=t.current;if(_e(N.adapter,M.cell.row,M.cell.col)){N.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),A({...M,...k(M.cell)});return}if(N.commitEdits(T,{source:"annotate"})===null){A({...M,rejected:!0});return}D()},[A,D,k]),R=i.useCallback((M,T)=>{const N=t.current;if(!Vn(N.adapter,N.popovers,M))throw new RangeError(`[spreadsheet] openPopover("${M}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const V=N.getActive();if(M==="list"&&_e(N.adapter,V.row,V.col)){N.rejectReadOnly({kind:"edit",cell:V,editSession:"none"});return}if(M==="note-tip"){S(V);return}if(M==="message"){if(l.current!==null&&l.current!=="message")return;const Z=T!==void 0&&T.message!==void 0?T.message:void 0,se=N.adapter.getCellValidation===void 0?void 0:N.adapter.getCellValidation(V.row,V.col),re=Z!==void 0?Z:se===void 0?void 0:se.inputMessage;if(re===void 0)return;const ve=T!==void 0&&T.rejected===!0;A({kind:"message",cell:V,anchorRect:_(V),current:{title:De(N.labels,"messageTitle"),message:re,rejected:ve},close:D});return}if(N.isEditing()&&!N.requestCommit())return;if(M==="list"){const Z=N.adapter.getCellValidation===void 0?void 0:N.adapter.getCellValidation(V.row,V.col);if(Z===void 0||Z.type!=="list")return;const se=T!==void 0&&T.typed!==void 0?T.typed:"";$(),N.focusSink({preventScroll:!0}),A({kind:"list",cell:V,anchorRect:_(V),current:Z.values,typed:se,commit:re=>{if(_e(t.current.adapter,V.row,V.col)){t.current.rejectReadOnly({kind:"edit",cell:V,editSession:"none"}),D();return}t.current.commitEdits([{row:V.row,col:V.col,text:re}],{source:"edit",editSession:"discarded"}),D()},close:D});return}if($(),N.focusSink({preventScroll:!0}),M==="note"){const Z=N.adapter.getCellNote===void 0?void 0:N.adapter.getCellNote(V.row,V.col),se={kind:"note",cell:V,anchorRect:_(V),current:Z,commit:re=>{w(se,[{row:V.row,col:V.col,note:re}])},close:D,rejected:!1,...k(V)};A(se);return}if(M==="comment"){const Z=N.adapter.getCellComments===void 0?void 0:N.adapter.getCellComments(V.row,V.col),se={kind:"comment",cell:V,anchorRect:_(V),current:Z===void 0?[]:Z,commit:re=>{w(se,[{row:V.row,col:V.col,comments:re}])},close:D,rejected:!1,...k(V)};A(se);return}const X=N.adapter.getCellHyperlink===void 0?void 0:Tn(N.adapter.getCellHyperlink(V.row,V.col)),J=N.adapter.getCellText(V.row,V.col),Q={kind:"link",cell:V,anchorRect:_(V),current:{text:J,url:X},commit:Z=>{const se=Z.url===null?null:Bt(Z.url);if(se===null&&Z.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(Z.url)}`);const re=Z.text===J?{row:V.row,col:V.col,hyperlink:se}:{row:V.row,col:V.col,text:Z.text,hyperlink:se};w(Q,[re])},close:D,canOpen:N.onHyperlinkOpen!==void 0,open:()=>{const Z=t.current.onHyperlinkOpen;Z!==void 0&&X!==void 0&&Z(X,V)},rejected:!1,...k(V)};A(Q)},[_,D,w,$,A,S,k]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const M=f.current;if(!a||M===null)return;const T=V=>{const X=t.current;Vn(X.adapter,X.popovers,"note-tip")&&p({clientX:V.clientX,clientY:V.clientY})},N=()=>{Vn(t.current.adapter,t.current.popovers,"note-tip")&&p({cell:null})};return M.addEventListener("pointermove",T),M.addEventListener("pointerleave",N),()=>{M.removeEventListener("pointermove",T),M.removeEventListener("pointerleave",N)}},[a,f,p]),i.useEffect(()=>()=>{y.current!==null&&cancelAnimationFrame(y.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:O,popovers:d}=e,F=i.useMemo(()=>Ng.some(M=>Vn(O,d,M)),[O,d]);return i.useMemo(()=>({layerEnabled:F,isKindEnabled:M=>Vn(t.current.adapter,t.current.popovers,M),open:R,close:D,isOpen:()=>l.current,onCellHover:g,hideTip:b,onTipPointerEnter:()=>{h.current=!0,B()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&L()},syncTipAriaDescribedBy:x,context:n,tipContext:o,registerCompositionEnd:M=>{H.current=M},isCompositionKey:M=>ya(M,H.current),getLayerSize:()=>{const M=t.current.handleRef.current;return M===null?{width:0,height:0}:M.getViewportSize()},tipId:z}),[F,R,D,g,b,B,L,x,n,o,z])},qg=(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},va=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return lr({row:ar(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:cr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},_g=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),y=i.useRef(null),q=i.useRef(""),H=i.useRef(!1),z=i.useRef(!1),_=i.useCallback((p,g)=>{const{handleRef:b,rowAxis:D,colAxis:A,zoomRef:k}=t.current;return va(b.current,o.current,D,A,k.current,p,g)},[]),K=i.useRef(!1),B=i.useRef(null),x=i.useRef(null),$=i.useRef({clientX:0,clientY:0}),L=i.useCallback(()=>{const{autoScroller:p,bodyRef:g,onDragFrame:b}=t.current;n.current=!1,r.current=null,h.current=null,K.current=!1,B.current=null,x.current=null,m.current=!1,y.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.stop();const D=g.current;D!==null&&c.current!==null&&D.hasPointerCapture?.(c.current)&&D.releasePointerCapture(c.current),c.current=null,b(null),t.current.repaintOverlay()},[]),S=i.useCallback(()=>{if(!n.current)return;const p=r.current;p!==null&&t.current.setSelection(p),L()},[L]),{enabled:v,bodyRef:E}=e;return i.useEffect(()=>{const p=E.current;if(!v||p===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,b=d=>{const F=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,y.current=null,z.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(q.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=p.getBoundingClientRect();const T=_(d.clientX,d.clientY);if(T===null)return;if(d.preventDefault(),F.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&F.openHyperlinkAt?.(T)===!0){z.current=!0;return}const N=F.getSelection();r.current=N;const V=d.shiftKey,X=d.ctrlKey||d.metaKey,J=X&&!V&&N.ranges.some(Z=>rn(Z,T));m.current=J,y.current=J?T:null,J||F.setSelection(tr(N,T,{extend:V,append:X})),n.current=!0,F.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{p.setPointerCapture(d.pointerId)}catch{c.current=null}const Q=J?T:F.getSelection().anchor;h.current=Z=>pe(Q,Z),B.current=Q.col,x.current=Q.row,F.autoScroller.stop(),K.current=!1,$.current={clientX:d.clientX,clientY:d.clientY}},D=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",A=d=>{if(n.current&&D(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!K.current&&h.current!==null){const F=Math.abs(d.clientX-$.current.clientX),M=Math.abs(d.clientY-$.current.clientY);Math.max(F,M)>=Wr&&(K.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:B.current??void 0,anchorRow:x.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const F=h.current;if(!n.current||F===null)return;const M=t.current,T=_(s.current.clientX,s.current.clientY);T!==null&&M.onDragFrame(F(T))}))}},k=d=>{A(d),n.current&&D(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&R(d)},w=d=>{d.button!==0||!(n.current&&D(d))||R(d)},R=d=>{const F=t.current,M=_(d.clientX,d.clientY);if(M!==null){const T=y.current;m.current&&T!==null?F.setSelection(wa(F.getSelection(),pe(T,M),T)):F.setSelection(en(F.getSelection(),M))}L()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||S()},f=d=>{const F=t.current;if(!g(d.target)||q.current!=="mouse"||F.isAnyDragging())return;if(F.isEditing()&&!F.requestCommit()){F.focusSink();return}F.focusSink(),o.current=p.getBoundingClientRect();const M=_(d.clientX,d.clientY);if(M===null)return;const T=F.getSelection();T.ranges.some(V=>rn(V,M))||F.setSelection(tr(T,M,{extend:!1,append:!1})),F.onContextMenuSelect(M,d)},O=d=>{const F=t.current;if(!H.current||q.current!=="mouse"||F.getPointing?.()||z.current)return;o.current=p.getBoundingClientRect();const M=_(d.clientX,d.clientY);M!==null&&kt(F.getSelection().active,M)&&F.onRequestEdit(M,F.caretFromPointEnabled(M)?qg(d.clientX,d.clientY,M):void 0)};return p.addEventListener("pointerdown",b),p.addEventListener("pointermove",k),p.addEventListener("pointerup",w),p.addEventListener("lostpointercapture",a),p.addEventListener("contextmenu",f),p.addEventListener("dblclick",O),()=>{p.removeEventListener("pointerdown",b),p.removeEventListener("pointermove",k),p.removeEventListener("pointerup",w),p.removeEventListener("lostpointercapture",a),p.removeEventListener("contextmenu",f),p.removeEventListener("dblclick",O),L()}},[v,E,_,L,S]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:S,cancelDrag:L}),[S,L])},Ig=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),y=i.useRef(null),q=i.useRef(!1),H=i.useCallback(($,L)=>{const{handleRef:S,rowAxis:v,colAxis:E,zoomRef:p}=t.current;return va(S.current,o.current,v,E,p.current,$,L)},[]),z=i.useCallback(()=>{const{autoScroller:$,bodyRef:L,onDragFrame:S}=t.current;n.current=!1,r.current=null,m.current=null,y.current=null,q.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),$.stop();const v=L.current;v!==null&&u.current!==null&&v.hasPointerCapture?.(u.current)&&v.releasePointerCapture(u.current),u.current=null,S(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.restoreSink($),z()},[z]),K=i.useCallback($=>{const L=t.current,S=L.bodyRef.current;if(!L.enabled||S===null||!L.getPointing())return!1;o.current=S.getBoundingClientRect();const v=H($.clientX,$.clientY);if(v===null)return o.current=null,!1;const E=L.captureSink();if(E===null)return o.current=null,!1;$.preventDefault(),L.focusSink(),r.current=E,y.current=v,L.insertReference(v,"cells"),n.current=!0,s.current={clientX:$.clientX,clientY:$.clientY},l.current={clientX:$.clientX,clientY:$.clientY},u.current=$.pointerId,h.current=$.buttons;try{S.setPointerCapture($.pointerId)}catch{u.current=null}return m.current=p=>{const g=pe(v,p);return t.current.insertReference(g,"cells"),g},L.autoScroller.stop(),q.current=!1,L.onDragFrame(pe(v,v)),!0},[H]),{enabled:B,bodyRef:x}=e;return i.useEffect(()=>{const $=x.current;if(!B||$===null)return;const L=p=>u.current!==null?p.pointerId===u.current:p.pointerType==="mouse",S=p=>{if(!(n.current&&L(p)))return;s.current={clientX:p.clientX,clientY:p.clientY};const g=m.current,b=y.current;if(!q.current&&g!==null&&b!==null){const D=Math.abs(p.clientX-l.current.clientX),A=Math.abs(p.clientY-l.current.clientY);Math.max(D,A)>=Wr&&(q.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:b.col,anchorRow:b.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const D=m.current;if(!n.current||D===null)return;const A=H(s.current.clientX,s.current.clientY);A!==null&&t.current.onDragFrame(D(A))})),(h.current&1)!==0&&(p.buttons&1)===0&&z()},v=p=>{p.button!==0||!(n.current&&L(p))||z()},E=p=>{!n.current||u.current===null||p.pointerId!==u.current||z()};return $.addEventListener("pointermove",S),$.addEventListener("pointerup",v),$.addEventListener("lostpointercapture",E),()=>{$.removeEventListener("pointermove",S),$.removeEventListener("pointerup",v),$.removeEventListener("lostpointercapture",E),z()}},[B,x,H,z]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:z,onPointerDown:K}),[_,z,K])},jg=.25,Hg=4,Ci=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${t})`);return t},Po=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(Hg,Math.max(jg,e))},qo=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,Bg=24,Vg=100,Wg=1e5,Kg=200,Ra=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),yi=5,Yg=/^#[0-9A-Fa-f]{6}$/,Ug=Object.freeze({row:!1,column:!1,intersection:!1}),bi=Object.freeze({ok:!0}),vi=(e,t)=>{if(t===void 0)return Ra;if(t.length!==yi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${yi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Yg.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Xg=e=>{for(const t of["row","column","intersection"])if(Ve(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},Gg=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Uc},Zg=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},$r={ranges:[pe({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Jg=i.forwardRef(function({adapter:t,defaultRowHeight:n=Bg,defaultColumnWidth:r=Vg,frozenColumns:o=0,frozenRows:s=0,frozenTrailingColumns:l=0,frozenTrailingRows:c=0,tapScrollCircleOptions:u,overscanRows:h,overscanCols:m,background:y,renderCell:q,onSelectionChange:H,onCellContextMenu:z,onUndoRequest:_,onRedoRequest:K,onCopyMultiRange:B,onOperationRejected:x,onEditRejected:$,onReadOnlyRejected:L,formatReadOnlyAnnouncement:S,dataVersion:v,maxOperationCells:E=Wg,enableFillHandle:p=!0,enableResizeUI:g=!0,formatCellAnnouncement:b,formatSelectionAnnouncement:D,formatCommandAnnouncement:A,labels:k,shortcuts:w,colors:R,formats:a,highlight:f,defaultHighlight:O,onHighlightChange:d,highlightColors:F,popovers:M,renderPopover:T,onClipChange:N,onHyperlinkOpen:V,onValidationRejected:X,onPasteSpecialRequest:J,onClipboardUnavailable:Q,onPasteResolved:Z,now:se=Date.now,zoom:re,defaultZoom:ve,onZoomChange:Me,testId:Te,className:Ne,__onCellRender:at,__onVirtualKeyboardRaise:st},ut){const he=ci(t.rowCount,n),me=ci(t.colCount,r),Dn=i.useRef(null);Dn.current===null&&(Dn.current=Oh());const be=Dn.current,We=i.useMemo(()=>Ah(k),[k]),Mn=i.useMemo(()=>Up(w),[w]),on=i.useMemo(()=>({fill:vi("fill",R===void 0?void 0:R.fill),font:vi("font",R===void 0?void 0:R.font)}),[R]),sn=i.useMemo(()=>F===void 0?void 0:Xg(F),[F]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Vt=i.useCallback(()=>be.get().editVersion,[be]),ur=i.useCallback(C=>be.subscribeCoalesced(C),[be]),Et=i.useSyncExternalStore(ur,Vt,Vt)+(v===void 0?0:v),xt=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),dt=i.useMemo(()=>({index:xt===null?null:pa(xt),memo:ys()}),[t,xt,Et]),At=i.useRef(dt.index);At.current=dt.index;const Wt=i.useRef(dt.memo);Wt.current=dt.memo;const ft=i.useCallback((C,Y,ee)=>bs(t,At.current,Wt.current,C,Y,ee),[t]),Ie=i.useRef(null),[Jr,Qr]=i.useState(()=>Po(ve??1)),Ze=Po(re??Jr),$e=i.useRef(Ze);$e.current=Ze;const Ot=i.useRef(Ze);Ot.current=Ze;const Tt=i.useRef(null),dr=i.useRef(Me);dr.current=Me;const fr=i.useRef(re!==void 0);fr.current=re!==void 0;const P=i.useCallback(C=>{const Y=Po(C);Y!==Ot.current&&(Ot.current=Y,fr.current||Qr(Y),dr.current?.(Y))},[]),I=t.rowCount===0||t.colCount===0,G=!I;i.useEffect(()=>{const C=Ie.current;if(!G||C===null)return;const Y=oe=>{oe.defaultPrevented||!oe.altKey||oe.ctrlKey||oe.metaKey||oe.shiftKey||oe.deltaY!==0&&(oe.preventDefault(),oe.stopPropagation(),!Tt.current?.()&&P(qo(Ot.current,oe.deltaY<0?1:-1)))},ee=oe=>{if(oe.defaultPrevented||!(oe.ctrlKey&&oe.altKey)||oe.metaKey||oe.getModifierState("AltGraph"))return;const Se=oe.key==="="||oe.key==="+"?qo(Ot.current,1):oe.key==="-"?qo(Ot.current,-1):oe.key==="0"?1:null;Se!==null&&(oe.preventDefault(),oe.stopPropagation(),!Tt.current?.()&&P(Se))};return C.addEventListener("wheel",Y,{passive:!1,capture:!0}),C.addEventListener("keydown",ee,!0),()=>{C.removeEventListener("wheel",Y,{capture:!0}),C.removeEventListener("keydown",ee,!0)}},[P,G]);const j=i.useRef(null),U=i.useRef(null),te=i.useRef(null),ce=i.useRef(null),ke=i.useRef(0),ge=i.useRef(null),qe=i.useRef(0),Le=i.useRef(null),Pe=i.useRef(null),Fe=i.useRef(null),ne=i.useRef(null),ae=i.useRef(null),ue=i.useRef(null),fe=i.useRef(null),[ie,Ce]=i.useState($r),we=i.useRef(ie),Re=i.useCallback(()=>we.current,[]),[pt,lt]=i.useState(()=>O===void 0?Ug:O),je=f!==void 0?f:pt,ht=i.useRef(je);ht.current=je;const Kt=Gg(sn,je),ln=i.useRef(f!==void 0);ln.current=f!==void 0;const Dt=i.useRef(d);Dt.current=d;const eo=i.useCallback(C=>{ln.current||lt(C),Dt.current?.(C)},[]),pr=i.useRef(null),to=i.useRef(null),mt=i.useRef(null),no=i.useRef(()=>!1),Rs=i.useRef(()=>{}),ks=i.useRef(()=>null),Ss=i.useRef(()=>{}),Yt=i.useCallback(()=>no.current(),[]),ro=i.useMemo(()=>({getPointing:()=>no.current(),insertReference:(C,Y)=>Rs.current(C,Y)}),[]),Es=i.useRef(vt),xs=i.useRef(null),As=i.useRef({interactive:null,tip:null}),Os=i.useRef(null),Ts=i.useRef(null),hr=i.useRef(()=>{}),Ds=i.useRef(()=>!1),cn=i.useRef(null),Fn=i.useCallback(()=>{const C=cn.current;if(C===null||C.isOpen()!=="message")return!1;const Y=C.context;return Y===null||Y.kind!=="message"||!Y.current.rejected?!1:(C.close(),!0)},[]),oo=i.useRef(()=>!1),Ms=i.useRef(()=>!1),$s=i.useRef(null),so=i.useRef(()=>Promise.resolve("rejected")),xe=i.useCallback(()=>{pr.current?.()},[]),Oe=i.useCallback(C=>{te.current?.focus(C)},[]),lo=i.useRef(!1),ka=i.useCallback(()=>{const C=Ie.current;if(C!==null){lo.current=!0;try{C.focus()}finally{lo.current=!1}}},[]),Ke=i.useCallback(()=>{const C=te.current;C!==null&&(C.value=" ",C.setSelectionRange(0,1))},[]),an=i.useCallback((C,Y)=>{if(C===null)return;const ee=Y?"":"none";C.style.display!==ee&&(C.style.display=ee)},[]),Je=i.useCallback(()=>{const C=ce.current;if(C!==null){const ee=Math.max(0,U.current?.getScrollPosition().y??0),oe=U.current?.getFrozenSize().height??0;C.style.transform=`translateY(${ke.current-ee-oe}px)`}const Y=U.current;if(Y!==null&&(ae.current!==null||ue.current!==null)){const ee=Y.getFrozenSize();an(ae.current,ee.height>0),an(ue.current,ee.trailingHeight>0)}},[an]),Qe=i.useCallback(()=>{const C=ge.current;if(C!==null){const ee=Math.max(0,U.current?.getScrollPosition().x??0),oe=U.current?.getFrozenSize().width??0;C.style.transform=`translateX(${qe.current-ee-oe}px)`}const Y=U.current;if(Y!==null&&(Fe.current!==null||ne.current!==null)){const ee=Y.getFrozenSize();an(Fe.current,ee.width>0),an(ne.current,ee.trailingWidth>0)}},[an]),zn=i.useRef(null),un=i.useCallback(()=>{Fe.current===null&&ne.current===null&&ae.current===null&&ue.current===null||zn.current===null&&(zn.current=requestAnimationFrame(()=>{zn.current=null,Je(),Qe(),xe()}))},[Je,Qe,xe]);i.useEffect(()=>()=>{zn.current!==null&&cancelAnimationFrame(zn.current)},[]);const io=i.useRef(null),co=i.useRef(null);(io.current===null||co.current?.rowAxis!==he||co.current?.colAxis!==me)&&(co.current={rowAxis:he,colAxis:me},io.current=Cg({handleRef:U,rowAxis:he,colAxis:me}));const Mt=i.useCallback(C=>{io.current?.(C)},[]),dn=i.useRef(null),Ut=i.useRef(null),fn=i.useCallback(C=>{dn.current!==null&&window.clearTimeout(dn.current),Ut.current!==null&&(cancelAnimationFrame(Ut.current),Ut.current=null),dn.current=window.setTimeout(()=>{dn.current=null;const Y=fe.current;Y!==null&&(Y.textContent="",Ut.current=requestAnimationFrame(()=>{Ut.current=null,Y.textContent=C}))},Kg)},[]);i.useEffect(()=>()=>{dn.current!==null&&window.clearTimeout(dn.current),Ut.current!==null&&cancelAnimationFrame(Ut.current)},[]);const pn=i.useCallback(C=>{L?.(C),S!==void 0&&fn(S(C))},[L,S,fn]),Fs=i.useCallback((C,Y)=>{if(b===void 0&&D===void 0)return;const ee=Y.ranges[Y.ranges.length-1],oe=Ge(ee),Se=Y.ranges.length===1&&oe.rows===1&&oe.cols===1,Ae=C.ranges[C.ranges.length-1],Co=C.ranges.length!==Y.ranges.length||Ae.startRow!==ee.startRow||Ae.startCol!==ee.startCol||Ae.endRow!==ee.endRow||Ae.endCol!==ee.endCol,ol=()=>{if(b!==void 0){const Ct=Y.active,yo=t.getCellText(Ct.row,Ct.col),sl=t.getCellFormat===void 0?void 0:ft(Ct.row,Ct.col,()=>yo);fn(b({row:Ct.row,col:Ct.col,text:yo,displayText:xn(yo,sl===void 0?void 0:sl.value),columnName:Zn(Ct.col),...Sc(t)?{readOnly:_e(t,Ct.row,Ct.col)}:{}}))}};if(Se){ol();return}if(Co){D!==void 0&&fn(D({range:ee,anchor:Y.anchor,active:Y.active,rangeRowCount:oe.rows,rangeColCount:oe.cols,rangeCount:Y.ranges.length}));return}ol()},[t,b,D,fn,ft]),Ye=i.useCallback(C=>{const Y=we.current;Object.is(C,Y)||hg(C,Y)||(we.current=C,Ce(C),H?.(C),Fs(Y,C),(mt.current?.()??!1)||Ke())},[H,Fs,Ke]),Sa=i.useCallback(C=>{const Y=we.current;if(C.mode==="cycle"){const oe=Ca(Y,C.direction);Ye(oe),Mt(oe.active);return}const ee=lr(C.cell,he.count,me.count);if(C.mode==="extend"){Ye(en(Y,ee)),Mt(ee);return}Ye(tr(Y,ee,{extend:!1,append:!1})),Mt(ee)},[Ye,Mt,he,me]),He=i.useCallback(()=>mt.current?.()??!1,[]),zs=i.useRef(null),et=i.useCallback(()=>zs.current?.()??!0,[]),Ns=i.useRef(null),Nn=i.useCallback((C,Y)=>{const ee=mt.current?.()??!1;Ns.current?.(C,Y),!ee&&(mt.current?.()??!1)&&Fn()},[Fn]),[Ea,ao]=i.useState(!1),Ls=i.useCallback(()=>{st?.(),ao(!0)},[st]),xa=i.useCallback((C,Y)=>{_e(t,C.row,C.col)||Ls(),Nn("edit",Y)},[t,Ls,Nn]),Ps=i.useRef(null),qs=i.useCallback(()=>Ps.current?.()??null,[]),_s=i.useRef(null),$t=i.useCallback(()=>{_s.current?.()},[]),Is=i.useRef(null),js=i.useCallback(C=>{Is.current?.(C)},[]),Hs=i.useRef(()=>{}),mr=i.useRef(0),Xt=i.useCallback((C,Y,ee)=>{let oe;if(Y.source==="paste"){const Se=Zg(ee);if(C.length===0&&Se.conditionalFormats.length===0)return null;mr.current+=1,oe={transaction:mr.current,source:"paste",sameSheet:Se.sameSheet,conditionalFormats:Se.conditionalFormats}}else{if(C.length===0)return null;mr.current+=1,oe={transaction:mr.current,source:Y.source}}try{t.applyEdits(C,oe)}catch(Se){return $?.(Se,Y),null}return be.bumpEdit(),js(Y.source),oe.transaction},[t,be,$,js]),Aa=i.useCallback((C,Y)=>Xt(C,{source:"paste"},Y),[Xt]),Oa=i.useCallback(C=>{be.setVy(C.y),Je(),Qe(),xe()},[be,Je,Qe,xe]),Bs=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Ta=i.useCallback(C=>{be.setRowRange(C.renderingRowStart,C.renderingRowEnd),be.setColRange(C.renderingColStart,C.renderingColEnd);const Y=Bs.current;(Y.rowStart!==C.renderingRowStart||Y.rowEnd!==C.renderingRowEnd||Y.colStart!==C.renderingColStart||Y.colEnd!==C.renderingColEnd)&&(Bs.current={rowStart:C.renderingRowStart,rowEnd:C.renderingRowEnd,colStart:C.renderingColStart,colEnd:C.renderingColEnd},xe())},[be,xe]),Vs=i.useRef(()=>"add"),Ft=i.useCallback(C=>{to.current?.(C,Vs.current())},[]),Da=i.useCallback(C=>{to.current?.(C,"point")},[]),Ws=i.useRef(null),uo=i.useCallback(C=>{Ws.current?.(C)},[]),Ks=i.useRef(null),Ma=i.useCallback(C=>{Ks.current?.(C)},[]),Ys=i.useRef(null),fo=i.useCallback((C,Y)=>{if(Y.length===0)return;const ee=U.current;if(C==="col"){for(const oe of Y){const Se=Math.round(oe.size);me.resize(oe.index,Se),ee?.updateColSize(oe.index,Se)}be.bumpColVersion(),Qe(),xe(),un();return}for(const oe of Y){const Se=Math.round(oe.size);he.resize(oe.index,Se),ee?.updateRowSize(oe.index,Se)}be.bumpRowGeometry(),Je(),xe(),un()},[he,me,be,Qe,Je,xe,un]),$a=i.useCallback((C,Y)=>{z?.(C,{kind:"pointer",event:Y})},[z]),Fa=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:Ft,axis:"both",zoomRef:$e}),za=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:Ft,axis:"x",zoomRef:$e}),Na=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:Ft,axis:"y",zoomRef:$e}),La=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:uo,axis:"x",zoomRef:$e}),Pa=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:uo,axis:"y",zoomRef:$e}),qa=mn({handleRef:U,rowAxis:he,colAxis:me,bodyRef:j,onDragFrame:Ft,axis:"both",zoomRef:$e}),Us=i.useRef(null),Xs=i.useRef(()=>!1),po=i.useCallback(()=>Xs.current(),[]),gt=_g({zoomRef:$e,enabled:!I,rowAxis:he,colAxis:me,handleRef:U,bodyRef:j,isEditing:He,requestCommit:et,getSelection:Re,setSelection:Ye,focusSink:Oe,onDragFrame:Ft,onContextMenuSelect:$a,onRequestEdit:xa,caretFromPointEnabled:C=>{if(q!==void 0||t.getCellFormula!==void 0&&t.getCellFormula(C.row,C.col)!==void 0)return!1;if(t.getCellFormat===void 0)return!0;const Y=t.getCellText(C.row,C.col);return xn(Y,t.getCellFormat(C.row,C.col)?.value)===Y},isAnyDragging:po,autoScroller:Fa,repaintOverlay:xe,pointDragRef:Us,getPointing:Yt,openHyperlinkAt:V===void 0||t.getCellHyperlink===void 0?void 0:C=>{const Y=t.getCellHyperlink===void 0?void 0:Tn(t.getCellHyperlink(C.row,C.col));return Y===void 0?!1:(V(Y,C),!0)}}),zt=wi({zoomRef:$e,enabled:!I,axis:"col",headerRef:Le,mainAxis:me,crossCount:t.rowCount,handleRef:U,isEditing:He,requestCommit:et,getSelection:Re,setSelection:Ye,focusSink:Oe,onDragFrame:Ft,autoScroller:za,repaintOverlay:xe,pointing:ro}),Nt=wi({zoomRef:$e,enabled:!I,axis:"row",headerRef:Pe,mainAxis:he,crossCount:t.colCount,handleRef:U,isEditing:He,requestCommit:et,getSelection:Re,setSelection:Ye,focusSink:Oe,onDragFrame:Ft,autoScroller:Na,repaintOverlay:xe,pointing:ro}),Lt=pg({zoomRef:$e,enabled:!I&&g,colBandRef:Le,rowBandRef:Pe,colAxis:me,rowAxis:he,viewStore:be,handleRef:U,isEditing:He,requestCommit:et,focusSink:Oe,getSelection:Re,adapter:t,autofitEnabled:q===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:E,onOperationRejected:x,resizeTracks:fo,writeResizeGuide:Ma,repaintOverlay:xe,isPointing:Yt}),wt=Ag({zoomRef:$e,enabled:!I&&p,handleNodeRef:Ys,bodyRef:j,rowAxis:he,colAxis:me,handleRef:U,getSelection:Re,setSelection:Ye,focusSink:Oe,adapter:t,commitEdits:Xt,maxOperationCells:E,onOperationRejected:x,rejectReadOnly:pn,writeFillPreview:uo,repaintOverlay:xe,xAutoScroller:La,yAutoScroller:Pa}),it=Ig({zoomRef:$e,enabled:!I,bodyRef:j,handleRef:U,rowAxis:he,colAxis:me,getPointing:Yt,insertReference:ro.insertReference,captureSink:()=>ks.current(),restoreSink:C=>Ss.current(C),focusSink:Oe,autoScroller:qa,onDragFrame:Ft});Us.current=it;const Ln=i.useCallback(()=>gt.isDragging()||zt.isDragging()||Nt.isDragging()||Lt.isDragging()||wt.isDragging()||it.isDragging(),[gt,zt,Nt,Lt,wt,it]);Tt.current=Ln,Xs.current=Ln,Vs.current=()=>it.isDragging()?"point":gt.getDragMode();const _a=i.useCallback(()=>{gt.abortDrag(),zt.abortDrag(),Nt.abortDrag(),Lt.abortDrag(),wt.abortDrag(),it.abortDrag()},[gt,zt,Nt,Lt,wt,it]),ho=i.useCallback(()=>we.current.active,[]),Gs=i.useCallback((C,Y)=>{const ee=t.getCellValidation===void 0?void 0:t.getCellValidation(C.row,C.col);if(ee===void 0)return bi;const oe=t.evaluateFormula,Se=_c(ee,Y,oe===void 0?void 0:Ae=>oe(Ae,C));return Se.ok||ee.strict!==!0?bi:(X?.({cell:C,rule:ee,text:Y,message:Se.message}),cn.current?.isKindEnabled("message")&&hr.current("message",{message:Se.message,rejected:!0}),Se)},[t,X]),ze=Tm({enabled:!I,sinkRef:te,rootRef:Ie,adapter:t,commitEdits:Xt,getActive:ho,ensureCellVisible:Mt,focusSink:Oe,rearmSink:Ke,discardClip:$t,isDragging:po,rejectReadOnly:pn,resolveEditAlign:C=>{if(t.getCellFormat===void 0)return null;const Y=Pr(t,C.row,C.col);return kc(ft(C.row,C.col,Y),Y)},resolveEditPaint:C=>t.getCellFormat===void 0?null:Ed(ft(C.row,C.col,Pr(t,C.row,C.col))),editPaintRef:Es,repaintOverlay:xe,validateCommit:Gs});mt.current=ze.isEditing,zs.current=ze.requestCommit,Ns.current=ze.startEdit,no.current=ze.getPointing,Rs.current=ze.insertReference,ks.current=ze.captureSink,Ss.current=ze.restoreSink;const Zs=i.useCallback(()=>{ze.cancelEdit(),Fn()},[ze.cancelEdit,Fn]),Pn=um({enabled:!I,sinkRef:te,adapter:t,isEditing:He,getSelection:Re,setSelection:Ye,commitPaste:Aa,maxOperationCells:E,onOperationRejected:x,onCopyMultiRange:B,repaintOverlay:xe,isDragging:po,resize:{rowAxis:he,colAxis:me,resizeTracks:fo},pendingPasteOptionsRef:xs,formats:a,onClipChange:N,onClipboardUnavailable:Q,onEditRejected:$,rejectReadOnly:pn,onPasteResolved:Z});Ps.current=Pn.getClip,_s.current=Pn.discardClip,Is.current=Pn.discardClipOnCommit,Hs.current=Pn.onAdapterSwitch,so.current=Pn.paste;const qn=Pg({enabled:!I,adapter:t,popovers:M,sinkRef:te,bodyRef:j,handleRef:U,rowAxis:he,colAxis:me,zoomRef:$e,getActive:ho,isEditing:He,requestCommit:et,focusSink:Oe,rearmSink:Ke,isDraggingAny:Ln,commitEdits:Xt,labels:We,onHyperlinkOpen:V,anchors:As,repaintOverlay:xe,rejectReadOnly:pn});cn.current=qn,hr.current=qn.open,Ds.current=qn.hideTip;const Ia=i.useCallback(()=>{const C=we.current.active;Mt(C);const Y=U.current,ee=Y===null?{x:0,y:0}:Y.getScrollPosition(),oe=Y===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:Y.getFrozenSize(),Se=Y===null?{width:0,height:0}:Y.getViewportSize(),Ae=$e.current;return{top:nn(he,C.row,{scroll:Math.max(0,ee.y),frozenCount:oe.rows,trailingCount:oe.trailingRows,extent:Se.height})*Ae,left:tn(me,C.col,{scroll:Math.max(0,ee.x),frozenCount:oe.cols,trailingCount:oe.trailingCols,extent:Se.width})*Ae,width:me.sizeOf(C.col)*Ae,height:he.sizeOf(C.row)*Ae}},[he,me,Mt]),mo=xm({adapter:t,getSelection:Re,commitEdits:Xt,getActive:ho,isEditing:He,requestCommit:et,cancelEdit:Zs,getSessionText:ze.getSessionText,validateCommit:Gs,insertAtCaret:ze.insertAtCaret,refreshEditPaint:ze.refreshPaint,maxOperationCells:E,onOperationRejected:x,colors:on,formats:a,getHighlight:()=>ht.current,setHighlight:eo,popovers:M,openPopover:C=>hr.current(C),onHyperlinkOpen:V,onPasteSpecialRequest:J,paste:C=>so.current(C),rowAxis:he,colAxis:me,resizeTracks:fo,defaultRowHeight:n,defaultColumnWidth:r,now:se,announce:fn,formatCommandAnnouncement:A,keyboardCellRect:Ia,rejectReadOnly:pn});$s.current=mo,oo.current=mo.executeCommand,Ms.current=mo.isCommandAvailable;const ja=i.useMemo(()=>({table:Mn,execute:C=>oo.current(C),isAvailable:C=>Ms.current(C)}),[Mn]),Ha=i.useCallback(()=>{$t(),_?.()},[$t,_]),Ba=i.useCallback(()=>{$t(),K?.()},[$t,K]);Sg({zoomRef:$e,enabled:!I,sinkRef:te,rootRef:Ie,handOffFocusToRoot:ka,getSelection:Re,setSelection:Ye,moveActive:Sa,ensureCellVisible:Mt,isEditing:He,requestCommit:et,startEdit:Nn,commitEdits:Xt,maxOperationCells:E,onOperationRejected:x,rejectReadOnly:pn,getClip:qs,discardClip:$t,isDragging:Ln,abortDrag:_a,findDataEdge:t.findDataEdge,getEditingMode:ze.getEditingMode,cancelEdit:Zs,onUndoRequest:Ha,onRedoRequest:Ba,onCellContextMenu:z,rowAxis:he,colAxis:me,handleRef:U,rearmSink:Ke,commands:ja,pointing:ze,adapter:t,hideNoteTip:()=>Ds.current(),closeRejectedMessage:Fn,pendingPasteOptionsRef:xs,onPointFrame:Da});const Va=ie.active.row,Wa=ie.active.col;i.useLayoutEffect(()=>{const C=cn.current;C!==null&&(C.syncTipAriaDescribedBy(),C.isKindEnabled("message")&&(C.isOpen()==="message"&&C.close(),C.open("message")))},[Va,Wa]),i.useLayoutEffect(()=>{xe()},[xe,je.row,je.column,je.intersection]);const Ka=i.useCallback(C=>{(mt.current?.()??!1)||(C.preventDefault(),Oe(),Ke())},[Oe,Ke]),Ya=i.useCallback(C=>{const Y=Ie.current,ee=C.relatedTarget;if(Y!==null&&ee instanceof Node&&Y.contains(ee)){C.target===Y&&ee===te.current&&!lo.current&&Oe();return}(mt.current?.()??!1)||(Oe(),Ke())},[Oe,Ke]),Ua=i.useCallback(C=>{const Y=Ie.current,ee=C.relatedTarget;Y!==null&&ee instanceof Node&&Y.contains(ee)||ze.isFocusoutSuppressed()||ao(!1)},[ze]),gr=i.useRef(null),_n=i.useCallback(()=>{const C=gr.current;C!==null&&(gr.current=null,window.removeEventListener("pointerup",C.up,!0),window.removeEventListener("pointercancel",C.cancel,!0))},[]),go=i.useCallback(()=>{if(gr.current!==null)return;const C=ee=>{ee.pointerType==="mouse"&&(_n(),ee.button===1&&ee.preventDefault())},Y=ee=>{ee.pointerType==="mouse"&&_n()};gr.current={up:C,cancel:Y},window.addEventListener("pointerup",C,!0),window.addEventListener("pointercancel",Y,!0)},[_n]);i.useEffect(()=>_n,[_n]),i.useEffect(()=>{const C=Ie.current;if(I||C===null)return;let Y=0;const ee=Ae=>{if(Ae.pointerType!=="mouse"){(mt.current?.()??!1)||ao(!1);return}Y=Ae.buttons,Ae.button===1&&(Ae.target===te.current&&(mt.current?.()??!1)||go())},oe=Ae=>{Ae.pointerType==="mouse"&&(Y=Ae.buttons)},Se=Ae=>{if(Ae.pointerType!=="mouse"||Ae.buttons===Y)return;const Co=Ae.buttons&~Y;Y=Ae.buttons,Ae.preventDefault(),(Co&4)!==0&&go()};return C.addEventListener("pointerdown",ee,!0),C.addEventListener("pointerup",oe,!0),C.addEventListener("pointermove",Se,!0),()=>{C.removeEventListener("pointerdown",ee,!0),C.removeEventListener("pointerup",oe,!0),C.removeEventListener("pointermove",Se,!0)}},[I,go]);const Xa=i.useCallback(C=>{if(!(C.target!==C.currentTarget||C.pointerType!=="mouse")&&(C.preventDefault(),C.button===0)){if(Yt()){Oe();return}if(He()&&!et()){Oe();return}Oe()}},[Oe,He,et,Yt]),wo=i.useRef(!1);i.useLayoutEffect(()=>{if(I){wo.current=!1;return}if(wo.current)return;wo.current=!0,Ke();const C=(Ie.current?.clientHeight??0)/$e.current;C>0&&he.totalSize()>0&&be.setRowRange(0,he.indexAt(Math.min(C-1,he.totalSize()-1)));const Y=(Ie.current?.clientWidth??0)/$e.current;Y>0&&me.totalSize()>0&&be.setColRange(0,me.indexAt(Math.min(Y-1,me.totalSize()-1)))},[I,Ke,be,he,me]);const Js=i.useRef(t);i.useLayoutEffect(()=>{Js.current!==t&&(Js.current=t,gt.cancelDrag(),zt.cancelDrag(),Nt.cancelDrag(),Lt.cancelDrag(),wt.cancelDrag(),it.cancelDrag(),ze.cancelEdit(),cn.current?.hideTip(),cn.current?.close(),I?(we.current=$r,Ce($r)):Ye($r),Hs.current())},[t,I,Ye,gt,zt,Nt,Lt,wt,it,be,ze.cancelEdit]);const Qs=i.useRef(o),el=i.useRef(s),tl=i.useRef(l),nl=i.useRef(c);i.useLayoutEffect(()=>{(Qs.current!==o||el.current!==s||tl.current!==l||nl.current!==c)&&(Qs.current=o,el.current=s,tl.current=l,nl.current=c,gt.cancelDrag(),zt.cancelDrag(),Nt.cancelDrag(),Lt.cancelDrag(),wt.cancelDrag(),it.cancelDrag())},[o,s,l,c,gt,zt,Nt,Lt,wt,it]),i.useLayoutEffect(()=>{Je(),Qe(),xe()},[o,s,l,c,Je,Qe,xe]);const rl=i.useRef(v);i.useLayoutEffect(()=>{rl.current!==v&&(rl.current=v,$t())},[v,$t]),i.useLayoutEffect(()=>{xe()},[xe,ie]);const Gt=i.useCallback(()=>{const C=$s.current;if(C===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return C},[]);if(i.useImperativeHandle(ut,()=>({resizeRow:(C,Y)=>{const ee=Math.round(Y);he.resize(C,ee),U.current?.updateRowSize(C,ee),be.bumpRowGeometry(),Je(),xe(),un()},resizeColumn:(C,Y)=>{const ee=Math.round(Y);me.resize(C,ee),U.current?.updateColSize(C,ee),be.bumpColVersion(),Qe(),xe(),un()},scrollToCell:(C,Y)=>{U.current?.scrollToCell(C.row,C.col,Y)},focus:C=>{Oe(C),He()||Ke()},executeCommand:C=>oo.current(C),applyFormat:C=>Gt().applyFormat(C),setBorders:(C,Y)=>Gt().setBorders(C,Y),setHyperlink:C=>Gt().setHyperlink(C),setNote:C=>Gt().setNote(C),addComment:C=>Gt().addComment(C),setValidation:C=>Gt().setValidation(C),paste:C=>so.current(C),getSelection:()=>we.current,getBaseFormat:C=>t.getCellFormat===void 0?void 0:t.getCellFormat(C.row,C.col),getPaintedFormat:C=>t.getCellFormat===void 0?void 0:ft(C.row,C.col,Pr(t,C.row,C.col)),startEdit:C=>{Nn(C)},openPopover:C=>{hr.current(C)}}),[he,me,be,Qe,Je,xe,un,Oe,He,Ke,t,ft,Nn,Gt]),I)return W.jsx("div",{className:Ne?`aqsp-root ${Ne}`:"aqsp-root","data-aqsp-empty":"","data-testid":Te});const Ga=b!==void 0||D!==void 0||A!==void 0||S!==void 0;return W.jsx("div",{ref:Ie,className:Ne?`aqsp-root ${Ne}`:"aqsp-root",role:"group","aria-label":We.rootAriaLabel,tabIndex:0,onFocus:Ya,onBlur:Ua,"data-aqsp-root":"","data-testid":Te,children:W.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":Ze,onPointerDown:Xa,style:Ze===1?void 0:{width:`${100/Ze}%`,height:`${100/Ze}%`,transform:`scale(${Ze})`},children:[W.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:C=>{if(C.pointerType==="mouse"&&(C.preventDefault(),C.button===0)){if(Yt()){Oe();return}if(He()&&!et()){Oe();return}Oe(),Ye({ranges:[pe({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),W.jsx(cg,{viewStore:be,colAxis:me,frozenCols:o,frozenTrailingCols:l,handleRef:U,bandRef:Le,colTrackRef:ge,windowOriginXRef:qe,repaintColHeaders:Qe,selectionRanges:ie.ranges,enableResizeUI:g,dividerLeadingRef:Fe,dividerTrailingRef:ne}),W.jsx(ag,{viewStore:be,rowAxis:he,handleRef:U,bandRef:Pe,selectionRanges:ie.ranges,rowTrackRef:ce,windowOriginYRef:ke,repaintHeaders:Je,enableResizeUI:g,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:ae,dividerTrailingRef:ue}),W.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[W.jsx(ig,{adapter:t,rowAxis:he,colAxis:me,viewStore:be,handleRef:U,bodyRef:j,dataVersion:v,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:l,frozenTrailingRows:c,tapScrollCircleOptions:u,overscanRows:Ci("overscanRows",h),overscanCols:Ci("overscanCols",m),background:y,renderCell:q,onScroll:Oa,onRangeChange:Ta,focusSink:Oe,isEditing:He,requestCommit:et,testId:Te?`${Te}-vs`:void 0,__onCellRender:at,cfIndexRef:At,cfMemoRef:Wt,isPointing:Yt}),W.jsx(qh,{rowAxis:he,colAxis:me,handleRef:U,sinkRef:te,getSelection:Re,editing:ze.editing,virtualKeyboard:Ea,repaintRef:pr,dragFrameRef:to,getClip:qs,getIsDraggingAny:Ln,getIsFillDragging:wt.isDragging,fillFrameRef:Ws,resizeGuideFrameRef:Ks,fillHandleNodeRef:Ys,enableFillHandle:p,frozenCols:o,frozenRows:s,trailingCols:l,trailingRows:c,sinkAriaLabel:We.sinkAriaLabel,onSinkMouseDown:Ka,editPaintRef:Es,highlightRef:ht,highlightColors:Kt,popoverAnchors:As,interactiveAnchorRef:Os,tipAnchorRef:Ts}),qn.layerEnabled?W.jsx(zg,{controller:qn,labels:We,renderPopover:T,interactiveAnchorRef:Os,tipAnchorRef:Ts}):null]}),Ga?W.jsx("div",{ref:fe,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=os;exports.CommentPopover=Gc;exports.DEFAULT_CUSTOM_COLORS=Ra;exports.DEFAULT_HIGHLIGHT_COLORS=Uc;exports.DEFAULT_LABELS=Jo;exports.DEFAULT_SHORTCUTS=Lc;exports.LinkPopover=Zc;exports.ListPopover=Jc;exports.MessagePopover=Qc;exports.NotePopover=ea;exports.NoteTip=ta;exports.SPREADSHEET_RESERVED_SHORTCUTS=Bp;exports.Spreadsheet=Jg;exports.canonicalizeFormat=ot;exports.columnIndexToName=Zn;exports.columnNameToIndex=Np;exports.detectClipSource=Mi;exports.enumerateRangeCells=qt;exports.estimatePasteCellCount=Ap;exports.expandPaste=Op;exports.formatCellValue=xn;exports.formatEquals=lu;exports.fromR1C1=sr;exports.makeRange=pe;exports.mergeFormat=ls;exports.normalizeHyperlink=Bt;exports.parseChord=Qt;exports.parseClipPayload=jo;exports.parseHtmlTable=Rc;exports.parseTsv=$c;exports.rangeContains=rn;exports.rangeSize=Ge;exports.resolveLabel=De;exports.serializeClipPayload=Oi;exports.serializeHtmlTable=Cc;exports.serializeTsv=Tc;exports.shiftFormula=tc;exports.toR1C1=Ur;exports.validateCellText=_c;
16
+ `)||e.endsWith("\r")?e.slice(0,-1):e,Nc=(e,t,n)=>{let r=0;for(;;){let o;if(e[r]==='"'){const s=Hp(e,r);if(s!==null)o=s.value,r=s.nextIndex;else{const l=Pl(e,r);o=e.slice(r,l),r=l}}else{const s=Pl(e,r);o=e.slice(r,s),r=s}if(t(o),r>=e.length){n();return}e[r]===" "?r+=1:(r+=e[r]==="\r"&&e[r+1]===`
17
+ `?2:1,n())}},Lc=e=>{const t=zc(e);if(t==="")return[[""]];const n=[];let r=[];Nc(t,s=>{r.push(s)},()=>{n.push(r),r=[]});let o=0;for(const s of n)s.length>o&&(o=s.length);return n.map(s=>s.length===o?s:[...s,...Array(o-s.length).fill("")])},jp=e=>{const t=zc(e);if(t==="")return{rows:1,cols:1};let n=0,r=0,o=0;return Nc(t,()=>{o+=1},()=>{n+=1,o>r&&(r=o),o=0}),{rows:n,cols:r}},Hp=(e,t)=>{let n="",r=t+1;for(;r<e.length;)if(e[r]==='"')if(e[r+1]==='"')n+='"',r+=2;else{const o=r+1;return(o>=e.length||e[o]===" "||e[o]===`
18
+ `||e[o]==="\r")&&/[\t\r\n]/.test(n)?{value:n,nextIndex:o}:null}else n+=e[r],r+=1;return null},Pl=(e,t)=>{for(let n=t;n<e.length;n+=1)if(e[n]===" "||e[n]===`
19
+ `||e[n]==="\r")return n;return e.length},tr=e=>{if(!(Number.isInteger(e)&&e>=0))throw new RangeError(`[spreadsheet] columnIndexToName requires a non-negative integer, received ${e}`);let t="",n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.trunc(n/26)-1;return t},Bp=e=>{if(!/^[A-Z]+$/.test(e))throw new RangeError(`[spreadsheet] columnNameToIndex requires /^[A-Z]+$/, received "${e}"`);let t=0;for(const n of e)t=t*26+(n.charCodeAt(0)-64);return t-1},to=["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","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"],Vp=/^[A-Z]$/,Wp=/^[A-Za-z]$/,Kp=/^Key([A-Z])$/,Pc=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"]),Yp=e=>Vp.test(e)||Pc.has(e),on=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||!Yp(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}},Up=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,qc=e=>{if(Wp.test(e.key))return e.key.toUpperCase();const t=Kp.exec(e.code);return t!==null?t[1]:Pc.has(e.code)?e.code:null},Vn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:qc(t)===e.key,pe=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ye=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Xp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(pe(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(pe(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(pe(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(pe(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Gp=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(pe(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(pe(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},ur=[...Xp(),pe("Home","idle","row start (first visible column)"),pe("Ctrl+Home","idle","first visible cell"),pe("Shift+Home","idle","extend to row start"),pe("Ctrl+Shift+Home","idle","extend to first visible cell"),pe("End","idle","row end (last visible column)"),pe("Ctrl+End","idle","last visible cell"),pe("Shift+End","idle","extend to row end"),pe("Ctrl+Shift+End","idle","extend to last visible cell"),pe("PageUp","both","page up (idle) / commit + page up (editing)"),pe("PageDown","both","page down (idle) / commit + page down (editing)"),pe("Shift+PageUp","idle","extend one page up"),pe("Shift+PageDown","idle","extend one page down"),pe("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),pe("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),pe("Tab","both","cycle right (idle) / commit + cycle right (editing)"),pe("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),pe("Enter","both","cycle down (idle) / commit + cycle down (editing)"),pe("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),pe("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),pe("F2","both","start editing (idle) / toggle the pointing arm (editing)"),pe("F4","editing","cycle the reference anchor under the caret (formula session)"),pe("Delete","idle","clear every selected cell"),pe("Backspace","idle","clear every selected cell"),pe("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),pe("Ctrl+A","idle","select all"),pe("Ctrl+Z","idle","undo request"),pe("Ctrl+Y","idle","redo request"),pe("Ctrl+Shift+Z","idle","redo request"),pe("Shift+F10","idle","keyboard context menu"),pe("ContextMenu","idle","keyboard context menu"),pe("Ctrl+Space","idle","column bands"),pe("Shift+Space","idle","row bands"),pe("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),pe("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),pe("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),pe("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"},...Gp(),ye("bold","Ctrl+B","both","toggle bold"),ye("italic","Ctrl+I","both","toggle italic"),ye("underline","Ctrl+U","both","toggle underline"),ye("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ye("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ye("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ye("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ye("alignLeft","Ctrl+Shift+L","both","align left"),ye("alignCenter","Ctrl+Shift+E","both","align center"),ye("alignRight","Ctrl+Shift+R","both","align right"),ye("formatNumber","Ctrl+Shift+Digit1","both","number format"),ye("formatTime","Ctrl+Shift+Digit2","both","time format"),ye("formatDate","Ctrl+Shift+Digit3","both","date format"),ye("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ye("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ye("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ye("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ye("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ye("borderTop","Alt+Shift+Digit1","idle","top border"),ye("borderRight","Alt+Shift+Digit2","idle","right border"),ye("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ye("borderLeft","Alt+Shift+Digit4","idle","left border"),ye("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ye("insertNote","Shift+F2","idle","insert / edit note"),ye("insertComment","Ctrl+Alt+M","idle","insert comment"),ye("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ye("openValidationList","Alt+ArrowDown","idle","open the validation list"),ye("fillDown","Ctrl+D","idle","fill down"),ye("fillRight","Ctrl+R","idle","fill right"),ye("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ye("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ye("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ye("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ye("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ye("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],Kr=(e,t)=>e.column==="both"||e.column===t,Jp=Array.from(new Set(ur.filter(e=>!e.rebindable&&Kr(e,"idle")).map(e=>e.chord))),vs=new Set(ur.filter(e=>e.command!==void 0&&Kr(e,"editing")).map(e=>e.command)),Zp=new Set(ur.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),_c=e=>{const t={};for(const n of to)t[n]=e(n);return t},Ic=_c(e=>ur.filter(t=>t.command===e).map(t=>t.chord)),Qp=e=>{const t=new Map;for(const n of to){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},eh=e=>{const t=new Set(to);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(Zp.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`)}}}},th=(e,t)=>{const n=on(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=vs.has(e);for(const o of ur)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Kr(o,"idle")||r&&Kr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},nh=e=>{e!==void 0&&eh(e);const t=_c(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Ic[r]:o===null?[]:o});for(const r of to)for(const o of t[r])th(r,o);const n=new Map;for(const[r,o]of Qp(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},ql=(e,t)=>{const n=qc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Up({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},rh=Object.freeze({ok:!0}),oh="TRUE",sh="FALSE",lh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),ih=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),ch=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,ah=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,uh=/^[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])?)+$/,_l={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},dh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Il=e=>{const t=e.trim();if(!(ch.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,C=g.search(/[^0]/);return C<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:g.slice(C).replace(/0+$/,""),point:u.length+l-C}},fh=e=>e===1?-1:e===-1?1:0,ph=(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:fh(n)},hh=(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=ah.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>hh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},gh=(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},mh=(e,t)=>e<t?-1:e>t?1:0,wh=e=>e==="between"||e==="notBetween",Ch=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!wh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},yh=(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}},Fo=(e,t,n,r,o,s)=>{const l=Ch(e,t,n,r);return l===null?!0:o===null?!1:yh(e,s(o,l.a),l.b===null?0:s(o,l.b))},bh=e=>Number.isFinite(e)?e:null,vh=e=>{let t=0;for(const n of e)t+=1;return t},Rh=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),kh=(e,t)=>{switch(e.op){case"isEmail":return uh.test(t);case"isUrl":return Rh(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)}},Sh=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,jc=e=>({checked:e.checked===void 0?oh:e.checked,unchecked:e.unchecked===void 0?sh:e.unchecked}),Eh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!lh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "${e.type}"`);return;case"text":if(!ih.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type "${String(e.type)}"`)}},Ah=(e,t,n)=>{switch(e.type){case"list":return Th(e).has(t);case"number":return Fo(e.op,e.a,e.b,Il,Il(t),ph);case"textLength":return Fo(e.op,e.a,e.b,bh,vh(t),mh);case"date":return Fo(e.op,e.a,e.b,jl,jl(t),gh);case"text":return kh(e,t);case"checkbox":{const r=jc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Sh(n(e.formula))}},Hc=(e,t,n)=>(Eh(e),t===""||Ah(e,t,n)),zo=(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}`}},Hl=e=>e===void 0?void 0:e.trim(),xh=e=>{switch(e.type){case"list":return"Value must be one of the list items.";case"number":return`Value must be a number ${zo(e.op,e.a.trim(),Hl(e.b),_l)}.`;case"textLength":return`Text length must be ${zo(e.op,String(e.a),e.b===void 0?void 0:String(e.b),_l)}.`;case"date":return`Value must be a date ${zo(e.op,e.a.trim(),Hl(e.b),dh)}.`;case"text":return Oh(e);case"checkbox":{const t=jc(e);return`Value must be "${t.checked}" or "${t.unchecked}".`}default:return`Value does not satisfy the formula ${e.formula}.`}},Oh=e=>{switch(e.op){case"contains":return`Value must contain "${e.value}".`;case"notContains":return`Value must not contain "${e.value}".`;case"startsWith":return`Value must start with "${e.value}".`;case"endsWith":return`Value must end with "${e.value}".`;case"isEmail":return"Value must be a valid email address.";default:return"Value must be a valid URL."}},Bl=new WeakMap,Th=e=>{const t=Bl.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Bl.set(e,n),n},Bc=(e,t,n)=>Hc(e,t,n)?rh:{ok:!1,message:e.errorMessage===void 0?xh(e):e.errorMessage},Dh=e=>e.type!=="custom",Mh=(e,t)=>Dh(e)&&!Hc(e,t,void 0),$h=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","validationRejected","popoverClose","indicatorNote","indicatorComment","indicatorInvalid"],ts=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",validationRejected:"The value does not satisfy this cell's validation rule",popoverClose:"Close",indicatorNote:"Has a note",indicatorComment:"Has comments",indicatorInvalid:"Invalid value"}),Fh=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 ${JSON.stringify(t)}`)},zh=(e,t,n)=>{e[t]=n},Nh=e=>{if(e===void 0)return ts;const t={...ts};for(const n of $h){const r=e[n];r!==void 0&&zh(t,n,r)}return Fh(t),Object.freeze(t)},$e=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},Vc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Wc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Kc=(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,Yc=(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),Uc=(e,t)=>Vc(e,t),Xc=(e,t)=>Vc(e,t),Gc=(e,t)=>Wc(e,t),Jc=(e,t)=>Wc(e,t),ln=(e,t,n)=>Kc(e,t,n),cn=(e,t,n)=>Kc(e,t,n),dr=(e,t,n)=>Yc(e,t,n),fr=(e,t,n)=>Yc(e,t,n),ut=12,Lh=()=>{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)})}},Ph=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Pt=1,Jn=3,Or=e=>`${-Math.min(Jn,Math.max(0,Math.floor(e)))}px`,Zc=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),qh=16,_h=450,Ih=e=>e>4?Math.floor(_h/(5*e)):qh,Wn=(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},Vl=()=>({rowLeft:Wn("row","left"),rowRight:Wn("row","right"),colAbove:Wn("column","above"),colBelow:Wn("column","below"),cross:Wn("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Qc=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Tr=(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},Dr=(e,t)=>Math.min(Math.max(e,0),t),Wl="inset(100%)",xn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},jh=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,xn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const q=`${t.height}px`;e.rowLeft.style.height=q,e.rowRight.style.height=q}const g=`translate(${Dr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;g!==s.rowLeftTransform&&(s.rowLeftTransform=g,e.rowLeft.style.transform=g);const C=`translate(${Dr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;C!==s.rowRightTransform&&(s.rowRightTransform=C,e.rowRight.style.transform=C)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,xn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const q=`${t.width}px`;e.colAbove.style.width=q,e.colBelow.style.width=q}const g=`translate(${t.left}px, ${Dr(t.top,n.clampHeight)-n.clampHeight}px)`;g!==s.colAboveTransform&&(s.colAboveTransform=g,e.colAbove.style.transform=g);const C=`translate(${t.left}px, ${Dr(t.top+t.height,n.clampHeight)}px)`;C!==s.colBelowTransform&&(s.colBelowTransform=C,e.colBelow.style.transform=C)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,xn([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)}},Kl=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,xn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,xn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,xn([e.cross],!1))},Yl=e=>{for(const t of Qc(e))t.remove()},Hh=(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)},Bh=Object.freeze([]),Ul=e=>e.dividers[0]??e.active,Vh={left:"0px",right:"0px",width:""},Wh={top:"0px",bottom:"0px",height:""},Xl=()=>({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:[]}),Gl=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Jl=6,Kh=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:g,getIsFillDragging:C,fillFrameRef:q,resizeGuideFrameRef:j,fillHandleNodeRef:z,enableFillHandle:I,frozenCols:Y,frozenRows:H,trailingCols:$,trailingRows:T,sinkAriaLabel:P,onSinkMouseDown:S,editPaintRef:v,highlightRef:E,highlightColors:p,popoverAnchors:m,interactiveAnchorRef:y,tipAnchorRef:M})=>{const x=i.useRef(null),R=i.useRef(null),N=i.useRef(null),b=i.useRef(new Map(Gl.map(L=>[L,Xl()]))),a=i.useCallback(L=>{const B=b.current.get(L);if(B!==void 0)return B;const X=Xl();return b.current.set(L,X),X},[]),f=i.useCallback((L,B,X)=>{if(L===null)return;const _=L.style;_.left!==B.left&&(_.left=B.left),_.right!==B.right&&(_.right=B.right),_.width!==B.width&&(_.width=B.width),_.top!==X.top&&(_.top=X.top),_.bottom!==X.bottom&&(_.bottom=X.bottom),_.height!==X.height&&(_.height=X.height)},[]),O=i.useCallback((L,B,X)=>{if(!(L.bandClampWidth===B&&L.bandClampHeight===X)){L.bandClampWidth=B,L.bandClampHeight=X;for(const _ of L.bandPool)Tr(_,B,X);L.dragBand!==null&&Tr(L.dragBand,B,X)}},[]),d=i.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const A=i.useCallback((L,B,X)=>{const _=L.dividerSlots[B];_===null||L.dividerShown[B]===X||(L.dividerShown[B]=X,_.style.display=X?"":"none")},[]),k=i.useRef({x:0,y:0}),D=i.useRef(null),F=i.useCallback((L,B)=>{const X=n.current,_=X?.getFrozenSize()??Ph,J=X?.getViewportSize(),ne=J?.width??-1,Z=J?.height??-1,we=k.current;we.x=L,we.y=B;let me=D.current;if(me===null||me.frozenCols!==_.cols||me.frozenWidth!==_.width||me.frozenRows!==_.rows||me.frozenHeight!==_.height||me.trailingCols!==_.trailingCols||me.trailingWidth!==_.trailingWidth||me.trailingVisibleWidth!==_.trailingVisibleWidth||me.trailingRows!==_.trailingRows||me.trailingHeight!==_.trailingHeight||me.trailingVisibleHeight!==_.trailingVisibleHeight||me.bodyWidth!==ne||me.bodyHeight!==Z){const se=_.trailingVisibleWidth,ae=_.trailingVisibleHeight,ue=_.cols<=0&&_.trailingCols<=0?[{kind:"m",map:Ce=>Ce-we.x,clamp:ne,style:Vh,seamLead:!1,seamTrail:!1}]:[..._.cols>0?[{kind:"f",map:Ce=>Ce,clamp:_.width,style:{left:"0px",width:`${_.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-we.x-_.width,clamp:Math.max(0,ne-_.width-se),style:{left:`${_.width}px`,right:`${se}px`,width:""},seamLead:_.cols>0,seamTrail:_.trailingCols>0},..._.trailingCols>0?[{kind:"t",map:Ce=>Ce-d.current.colAxis.totalSize()+se,clamp:se,style:{left:"",right:"0px",width:`${se}px`},seamLead:!0,seamTrail:!1}]:[]],de=_.rows<=0&&_.trailingRows<=0?[{kind:"m",map:Ce=>Ce-we.y,clamp:Z,style:Wh,seamLead:!1,seamTrail:!1}]:[..._.rows>0?[{kind:"f",map:Ce=>Ce,clamp:_.height,style:{top:"0px",height:`${_.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-we.y-_.height,clamp:Math.max(0,Z-_.height-ae),style:{top:`${_.height}px`,bottom:`${ae}px`,height:""},seamLead:_.rows>0,seamTrail:_.trailingRows>0},..._.trailingRows>0?[{kind:"t",map:Ce=>Ce-d.current.rowAxis.totalSize()+ae,clamp:ae,style:{top:"",bottom:"0px",height:`${ae}px`},seamLead:!0,seamTrail:!1}]:[]],ce=[];for(const Ce of ue)for(const be of de)ce.push({nodes:a(`${Ce.kind}${be.kind}`),xKind:Ce.kind,yKind:be.kind,mapX:Ce.map,clampWidth:Ce.clamp,xStyle:Ce.style,xSeamLead:Ce.seamLead,xSeamTrail:Ce.seamTrail,mapY:be.map,clampHeight:be.clamp,yStyle:be.style,ySeamLead:be.seamLead,ySeamTrail:be.seamTrail});me={frozenCols:_.cols,frozenWidth:_.width,frozenRows:_.rows,frozenHeight:_.height,trailingCols:_.trailingCols,trailingWidth:_.trailingWidth,trailingVisibleWidth:_.trailingVisibleWidth,trailingRows:_.trailingRows,trailingHeight:_.trailingHeight,trailingVisibleHeight:_.trailingVisibleHeight,bodyWidth:ne,bodyHeight:Z,ctxs:ce},D.current=me}const _e=_.width>0,Ie=_.trailingWidth>0,je=_.height>0,Le=_.trailingHeight>0;for(const se of me.ctxs)f(se.nodes.container,se.xStyle,se.yStyle),O(se.nodes,se.clampWidth,se.clampHeight),A(se.nodes,0,_e),A(se.nodes,1,Ie),A(se.nodes,2,je),A(se.nodes,3,Le);return me.ctxs},[n,a,f,O,A]),V=i.useCallback((L,B,X)=>{L.dividerSlots[B]=X,L.dividerShown[B]=!1,L.dividers.length=0;for(const _ of L.dividerSlots)_!==null&&L.dividers.push(_)},[]),U=i.useCallback(L=>{const B=()=>a(L);return{container:X=>{const _=B();_.container=X,X===null&&(_.fillPool.length=0,_.bandPool.length=0,_.dragBand=null,_.bandClampWidth=-1,_.bandClampHeight=-1)},dividerXLeading:X=>V(B(),0,X),dividerXTrailing:X=>V(B(),1,X),dividerYLeading:X=>V(B(),2,X),dividerYTrailing:X=>V(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}}},[a,V]),Q=i.useMemo(()=>Object.fromEntries(Gl.map(L=>[L,U(L)])),[U]),ee=Math.min(Math.max(0,Y),t.count),oe=Uc(t,ee),ie=Math.min(Math.max(0,H),e.count),G=Xc(e,ie),ve=$===void 0?0:Math.min(Math.max(0,$),t.count-ee),Fe=Gc(t,ve),Ae=T===void 0?0:Math.min(Math.max(0,T),e.count-ie),Me=Jc(e,Ae),ze=i.useRef(null),Ye=i.useRef("add"),ft=i.useRef(s);ft.current=s;const pr=i.useRef(!1),hr=lr.useWheelBridge(n,{enableBridge:!s}),ge=i.useCallback(L=>(r.current=L,hr(L)),[r,hr]),fe=i.useCallback((L,B)=>({top:B.mapY(e.offsetOf(L.startRow)),bottom:B.mapY(e.offsetOf(L.endRow)+e.sizeOf(L.endRow)),left:B.mapX(t.offsetOf(L.startCol)),right:B.mapX(t.offsetOf(L.endCol)+t.sizeOf(L.endCol))}),[e,t]),Ge=i.useCallback((L,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const{top:X,bottom:_,left:J,right:ne}=fe(L,B),Z=-B.clampHeight*Pt,we=B.clampHeight*(1+Pt),me=-B.clampWidth*Pt,_e=B.clampWidth*(1+Pt);if(_<Z||X>we||ne<me||J>_e)return null;const Ie=Math.max(X,Z),je=Math.max(J,me);return{top:Ie,left:je,width:Math.min(ne,_e)-je,height:Math.min(_,we)-Ie}},[fe]),Se=i.useCallback((L,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const X=fe(L,B),_=-B.clampHeight*Pt,J=B.clampHeight*(1+Pt),ne=-B.clampWidth*Pt,Z=B.clampWidth*(1+Pt),we=Math.min(Math.max(X.top,_),J),me=Math.min(Math.max(X.left,ne),Z);return{top:we,left:me,width:Math.min(Math.max(X.right,ne),Z)-me,height:Math.min(Math.max(X.bottom,_),J)-we}},[fe]),Ct=i.useCallback(()=>{if(E===void 0)return null;const L=E.current;return L.row||L.column||L.intersection?L:null},[E]),Wt=i.useCallback((L,B,X)=>{const _=B.fillPool[0]?.node??Ul(B);for(const J of Qc(X))L.insertBefore(J,_)},[]),un=i.useCallback((L,B,X,_)=>{const J=Se(B,X);if(J===null){Kl(L);return}jh(L,J,X,_,Vi(B,t.count)||Wi(B,e.count))},[Se,e,t]),gr=i.useCallback((L,B,X,_)=>{const J=L.nodes.bandPool;for(;J.length>X.length;){const ne=J.pop();ne!==void 0&&Yl(ne)}if(_===null){L.nodes.dragBand!==null&&(Yl(L.nodes.dragBand),L.nodes.dragBand=null);return}for(let ne=0;ne<X.length;ne+=1){let Z=J[ne];Z===void 0&&(Z=Vl(),Tr(Z,L.clampWidth,L.clampHeight),Wt(B,L.nodes,Z),J.push(Z)),un(Z,X[ne],L,_)}},[Wt,un]),Kt=i.useCallback((L,B,X)=>{const _=L.nodes.container;if(_===null)return;if(B===null||X===null){L.nodes.dragBand!==null&&Kl(L.nodes.dragBand);return}let J=L.nodes.dragBand;J===null&&(J=Vl(),Tr(J,L.clampWidth,L.clampHeight),Wt(_,L.nodes,J),L.nodes.dragBand=J),un(J,B,L,X)},[Wt,un]),Ot=i.useCallback((L,B)=>{if(L!==null){if(B===null){L.style.display="none";return}L.style.display="block",L.style.transform=`translate(${B.left}px, ${B.top}px)`,L.style.width=`${B.width}px`,L.style.height=`${B.height}px`}},[]),Nn=i.useCallback((L,B,X,_)=>{const J=_==="point"?null:Ct();for(const ne of F(X,B))Ot(ne.nodes.dragRect,Ge(L,ne)),Kt(ne,L,J)},[Ge,F,Ot,Ct,Kt]),dn=i.useCallback((L,B,X)=>{for(const _ of F(X,B))Ot(_.nodes.fillPreview,L===null?null:Ge(L,_))},[Ge,F,Ot]),Tt=i.useCallback((L,B,X)=>{for(const _ of F(X,B)){const J=_.nodes.resizeGuide;if(J===null)continue;if(L===null){J.style.display="none";continue}const ne=L.anchor==="trailing";if(L.axis==="col"){if(ne&&_.xKind!=="t"){J.style.display="none";continue}J.style.display="block";const Z=_.mapX(L.position);J.style.transform=`translate(${ne?Math.max(0,Z):Z}px, 0px)`,J.style.width="1px",J.style.height="100%"}else{if(ne&&_.yKind!=="t"){J.style.display="none";continue}J.style.display="block";const Z=_.mapY(L.position);J.style.transform=`translate(0px, ${ne?Math.max(0,Z):Z}px)`,J.style.width="100%",J.style.height="1px"}}},[F]),Dt=i.useCallback((L,B,X,_,J,ne,Z)=>{if(L===null)return;if(B===null||Z<=0||ne<=0){L.style.clipPath=Wl;return}const we=cn(e,B.row,_),me=ln(t,B.col,X),_e=t.sizeOf(B.col),Ie=e.sizeOf(B.row),je=me>=ne||we>=Z,Le=B.col>=J.cols&&me<J.width,se=B.row>=J.rows&&we<J.height,ae=J.trailingWidth>0&&B.col<t.count-J.trailingCols&&me+_e>ne-J.trailingVisibleWidth,ue=J.trailingHeight>0&&B.row<e.count-J.trailingRows&&we+Ie>Z-J.trailingVisibleHeight;if(je||Le||se||ae||ue){L.style.clipPath=Wl;return}L.style.clipPath="",L.style.transform=`translate(${me}px, ${we}px)`;const de=`${_e} ${Ie}`;L.dataset.aqspAnchorSig!==de&&(L.dataset.aqspAnchorSig=de,L.style.width=`${_e}px`,L.style.height=`${Ie}px`)},[e,t]),fn=i.useCallback((L,B,X)=>{if(m===void 0)return;const _=m.current,{width:J,height:ne}=L.getViewportSize(),Z=L.getFrozenSize(),we={scroll:X,frozenCount:Z.cols,trailingCount:Z.trailingCols,extent:J},me={scroll:B,frozenCount:Z.rows,trailingCount:Z.trailingRows,extent:ne};Dt(y===void 0?null:y.current,_.interactive,we,me,Z,J,ne),Dt(M===void 0?null:M.current,_.tip,we,me,Z,J,ne)},[m,y,M,Dt]),Yt=i.useCallback(()=>{const L=x.current,B=n.current;if(L===null||B===null)return;const X=B.getScrollPosition(),_=Math.max(0,X.y),J=Math.max(0,X.x),ne=o(),Z=F(J,_),we=Ct(),me=we===null?Bh:ne.ranges.slice(-Ih(Z.length));for(const se of Z){const ae=se.nodes.container;if(ae===null)continue;const ue=se.nodes.fillPool;for(let de=0;de<Math.max(ue.length,ne.ranges.length);de+=1){let ce=ue[de];if(ce===void 0){const Te=document.createElement("div");Te.className="aqsp-selection-fill",Te.setAttribute("data-aqsp-fill",""),Te.style.display="none",ae.insertBefore(Te,Ul(se.nodes)),ce={node:Te,last:{shown:!1,width:-1,height:-1,transform:""}},ue.push(ce)}const Ce=ne.ranges[de],be=Ce===void 0?null:Ge(Ce,se);if(be===null)ce.last.shown&&(ce.last.shown=!1,ce.node.style.display="none");else{ce.last.shown||(ce.last.shown=!0,ce.node.style.display="block");const Te=`translate(${be.left}px, ${be.top}px)`;Te!==ce.last.transform&&(ce.last.transform=Te,ce.node.style.transform=Te),be.width!==ce.last.width&&(ce.last.width=be.width,ce.node.style.width=`${be.width}px`),be.height!==ce.last.height&&(ce.last.height=be.height,ce.node.style.height=`${be.height}px`)}}for(;ue.length>ne.ranges.length;)ue.pop()?.node.remove();Ot(se.nodes.active,Ge(he(ne.active,ne.active),se)),gr(se,ae,me,we)}const _e=h(),Ie=_e===null||_e.foreign?null:_e;for(const se of Z){const ae=se.nodes.marquee;if(ae===null)continue;const ue=Ie===null?null:Ge(Ie.range,se),de=ue!==null&&(se.xSeamTrail&&ue.left>=se.clampWidth&&ue.left<se.clampWidth+Jn||se.xSeamLead&&ue.left+ue.width<=0&&ue.left+ue.width>-Jn||se.ySeamTrail&&ue.top>=se.clampHeight&&ue.top<se.clampHeight+Jn||se.ySeamLead&&ue.top+ue.height<=0&&ue.top+ue.height>-Jn)?null:ue;if(de===null)ae.style.display="none";else{ae.style.display="block",ae.style.transform=`translate(${de.left}px, ${de.top}px)`,ae.style.width=`${de.width}px`,ae.style.height=`${de.height}px`;const be=Or(de.top),Te=Or(de.left),Pe=Or(se.clampHeight-(de.top+de.height)),qe=Or(se.clampWidth-(de.left+de.width)),yt=`${be} ${qe} ${Pe} ${Te}`;yt!==ae.dataset.aqspOutsetSig&&(ae.dataset.aqspOutsetSig=yt,ae.style.setProperty("--aqsp-clip-outset-top",be),ae.style.setProperty("--aqsp-clip-outset-right",qe),ae.style.setProperty("--aqsp-clip-outset-bottom",Pe),ae.style.setProperty("--aqsp-clip-outset-left",Te))}const ce=de===null?null:Ie?.kind??null,Ce=ae.dataset.aqspClipKindLast??null;ce!==Ce&&(ce===null?(delete ae.dataset.aqspClipKindLast,ae.removeAttribute("data-aqsp-clip-kind")):(ae.dataset.aqspClipKindLast=ce,ae.setAttribute("data-aqsp-clip-kind",ce)))}ze.current!==null&&Nn(ze.current,_,J,Ye.current),N.current!==null&&Tt(N.current,_,J),R.current!==null&&dn(R.current,_,J);const je=z.current;if(je!==null&&!C()){const{width:se,height:ae}=B.getViewportSize(),ue=ne.ranges[ne.ranges.length-1];if(!(ne.ranges.length===1&&!ft.current&&!g())||ae<=0||se<=0)je.style.display="none";else{const ce=B.getFrozenSize(),Ce={scroll:J,frozenCount:ce.cols,trailingCount:ce.trailingCols,extent:se},be={scroll:_,frozenCount:ce.rows,trailingCount:ce.trailingRows,extent:ae},Te=ue.endCol<ce.cols,Pe=ue.endRow<ce.rows,qe=ue.endCol>=t.count-ce.trailingCols,yt=ue.endRow>=e.count-ce.trailingRows,Ut=ln(t,ue.endCol,Ce)+t.sizeOf(ue.endCol),Je=cn(e,ue.endRow,be)+e.sizeOf(ue.endRow),Xt=Te||qe?0:ce.width,Gt=Pe||yt?0:ce.height,mr=qe?se:se-ce.trailingVisibleWidth,wr=yt?ae:ae-ce.trailingVisibleHeight;Je<=Gt||Je>wr||Ut<=Xt||Ut>mr?je.style.display="none":(je.style.display="block",je.style.transform=`translate(${Ut-Jl+1}px, ${Je-Jl+1}px)`)}}const Le=r.current;if(Le!==null){const se=ne.active,{width:ae,height:ue}=B.getViewportSize(),de=B.getFrozenSize(),ce={scroll:J,frozenCount:de.cols,trailingCount:de.trailingCols,extent:ae},Ce={scroll:_,frozenCount:de.rows,trailingCount:de.trailingRows,extent:ue},be=cn(e,se.row,Ce),Te=ln(t,se.col,ce),Pe=ue>0?Math.min(Math.max(be,0),Math.max(0,ue-1)):0,qe=ae>0?Math.min(Math.max(Te,0),Math.max(0,ae-1)):0;Le.style.top=`${Pe}px`,Le.style.left=`${qe}px`,ft.current?(Le.style.width=`${t.sizeOf(se.col)}px`,Le.style.height=`${e.sizeOf(se.row)}px`,Le.style.paddingTop=`${Hh(e.sizeOf(se.row),v===void 0?St:v.current)}px`):(Le.style.width="1px",Le.style.height="1px",Le.style.paddingTop="0px");const yt=se.col>=de.cols&&Te<de.width,Ut=se.row>=de.rows&&be<de.height,Je=de.trailingWidth>0&&se.col<t.count-de.trailingCols&&Te+t.sizeOf(se.col)>ae-de.trailingVisibleWidth,Xt=de.trailingHeight>0&&se.row<e.count-de.trailingRows&&be+e.sizeOf(se.row)>ue-de.trailingVisibleHeight,Gt=ft.current&&be===Pe&&Te===qe&&!yt&&!Ut&&!Je&&!Xt;Gt!==pr.current&&(pr.current=Gt,Gt?Le.setAttribute("data-aqsp-editing",""):Le.removeAttribute("data-aqsp-editing"))}fn(B,_,J)},[n,Ge,F,Ot,Nn,Tt,dn,h,o,g,C,z,r,e,t,Ct,gr,v,fn]),Mt=i.useCallback((L,B)=>{ze.current=L,Ye.current=B;const X=L===null?"add":B;for(const ne of F(0,0)){const Z=ne.nodes.dragRect;if(Z===null)continue;const we=Z.dataset.aqspDragModeLast??"add";X!==we&&(Z.dataset.aqspDragModeLast=X,X==="add"?Z.removeAttribute("data-aqsp-drag-mode"):Z.setAttribute("data-aqsp-drag-mode",X))}const _=n.current;if(L===null||_===null){for(const ne of F(0,0))ne.nodes.dragRect!==null&&(ne.nodes.dragRect.style.display="none"),Kt(ne,null,null);return}const J=_.getScrollPosition();Nn(L,Math.max(0,J.y),Math.max(0,J.x),B)},[n,Nn,F,Kt]),Ue=i.useCallback(L=>{R.current=L;const B=n.current;if(B===null){for(const _ of F(0,0))_.nodes.fillPreview!==null&&(_.nodes.fillPreview.style.display="none");return}const X=B.getScrollPosition();dn(L,Math.max(0,X.y),Math.max(0,X.x))},[n,dn,F]),no=i.useCallback(L=>{N.current=L;const B=n.current;if(B===null){for(const _ of F(0,0))_.nodes.resizeGuide!==null&&(_.nodes.resizeGuide.style.display="none");return}const X=B.getScrollPosition();Tt(L,Math.max(0,X.y),Math.max(0,X.x))},[n,Tt,F]);i.useLayoutEffect(()=>{const L=x.current;if(!(L===null||p===void 0))return L.style.setProperty("--aqsp-band-row",p.row),L.style.setProperty("--aqsp-band-column",p.column),L.style.setProperty("--aqsp-band-intersection",p.intersection),L.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{L.style.removeProperty("--aqsp-band-row"),L.style.removeProperty("--aqsp-band-column"),L.style.removeProperty("--aqsp-band-intersection"),L.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Yt,u.current=Mt,q.current=Ue,j.current=no,()=>{c.current=null,u.current=null,q.current=null,j.current=null})),i.useEffect(()=>{Yt()},[Yt,s,ee,ie,ve,Ae]),i.useEffect(()=>{const L=r.current;if(L===null)return;const B=X=>S(X);return L.addEventListener("mousedown",B),()=>L.removeEventListener("mousedown",B)},[r,S]);const ro=ee>0||ve>0?[...ee>0?[{k:"f",style:{left:0,width:oe}}]:[],{k:"s",style:{left:oe,right:Fe}},...ve>0?[{k:"t",style:{right:0,width:Fe}}]:[]]:[{k:"m",style:{left:0,right:0}}],nt=ie>0||Ae>0?[...ie>0?[{k:"f",style:{top:0,height:G}}]:[],{k:"s",style:{top:G,bottom:Me}},...Ae>0?[{k:"t",style:{bottom:0,height:Me}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Oe=L=>L==="m"?0:L==="s"?1:L==="t"?2:3,$t=ro.flatMap(L=>nt.map(B=>({xk:L.k,yk:B.k,key:`${L.k}${B.k}`,style:{...L.style,...B.style}}))).sort((L,B)=>Oe(L.key[0])+Oe(L.key[1])-(Oe(B.key[0])+Oe(B.key[1]))),Ln=L=>L==="mm"?{"data-aqsp-overlay-main":""}:L==="fm"?{"data-aqsp-overlay-frozen":""}:L==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:x,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:ut,bottom:ut},children:[$t.map(({xk:L,yk:B,key:X,style:_})=>{const J=Q[X];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Ln(X),style:_,ref:J.container,children:[L==="s"&&ee>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:J.dividerXLeading}):null,L==="s"&&ve>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:J.dividerXTrailing}):null,B==="s"&&ie>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:J.dividerYLeading}):null,B==="s"&&Ae>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:J.dividerYTrailing}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:J.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:J.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:J.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:J.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:J.resizeGuide})]},X)}),K.jsx("textarea",{ref:ge,className:"aqsp-sink","aria-label":P,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),I?K.jsx("div",{ref:z,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},ea=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=C=>{l.current=!0;try{C()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=C=>{if(C.key==="Escape"){C.preventDefault(),c(e.close);return}C.key==="Enter"&&(C.ctrlKey||C.metaKey)&&!C.altKey&&!C.shiftKey&&(C.preventDefault(),u())},g=C=>{l.current||C.relatedTarget instanceof Node&&C.currentTarget.contains(C.relatedTarget)||e.rejected||c(e.close)};return K.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:g,children:[K.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[$e(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:$e(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(C=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":C.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:C.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:C.createdAt,children:C.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:C.text})]},C.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":$e(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:C=>r(C.currentTarget.value),onKeyDown:h}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:$e(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":$e(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},ta=({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:Bt(o),g=o.trim()!==""&&h===null,C=I=>{u.current=!0;try{I()}finally{u.current=!1}},q=()=>{l||g||C(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},j=I=>{if(I.key==="Escape"){I.preventDefault(),C(e.close);return}I.key==="Enter"&&!I.altKey&&!I.shiftKey&&(I.preventDefault(),q())},z=I=>{u.current||I.relatedTarget instanceof Node&&I.currentTarget.contains(I.relatedTarget)||e.rejected||C(e.close)};return K.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":g?"":void 0,role:"dialog","aria-labelledby":c,onBlur:z,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:$e(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:$e(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:I=>r(I.currentTarget.value),onKeyDown:j})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:$e(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":g||e.rejected?!0:void 0,onChange:I=>s(I.currentTarget.value),onKeyDown:j})]}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:g||l,"aria-disabled":l?"true":void 0,onClick:q,children:$e(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:$e(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":$e(t,"popoverClose"),onClick:()=>C(e.close),children:"×"})]})]})},Zl=500,na=({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 H=n.toLowerCase();return e.current.filter($=>$.toLowerCase().startsWith(H))},[e.current,n]),h=i.useMemo(()=>u.length>Zl?u.slice(0,Zl):u,[u]),g=u.length-h.length,C=h.length===0?-1:Math.min(o,h.length-1),q=H=>{c.current=!0;try{H()}finally{c.current=!1}},j=()=>{C<0||q(()=>e.commit(h[C]))},z=H=>{if(H.key==="Escape"){H.preventDefault(),q(e.close);return}if(H.key==="Enter"){H.preventDefault(),j();return}if(H.key==="ArrowDown"){H.preventDefault(),s(C+1);return}H.key==="ArrowUp"&&(H.preventDefault(),s(Math.max(C-1,0)))},I=H=>{c.current||H.relatedTarget instanceof Node&&H.currentTarget.contains(H.relatedTarget)||q(e.close)},Y=H=>`${l}-${H}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:I,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":$e(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":C<0?void 0:Y(C),value:n,onChange:H=>{r(H.currentTarget.value),s(0)},onKeyDown:z}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":$e(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:$e(t,"listEmpty")}):h.map((H,$)=>K.jsx("div",{className:"aqsp-popover-option",id:Y($),role:"option",tabIndex:-1,"aria-selected":$===C,"data-aqsp-list-option":H,onPointerDown:T=>T.preventDefault(),onClick:()=>q(()=>e.commit(H)),children:H},Y($))),g>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:$e(t,"listMore",g)}):null]})]})},ra=({ctx:e,labels:t})=>K.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),K.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":$e(t,"popoverClose"),onClick:e.close,children:"×"})]}),oa=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=z=>{u.current=!0;try{z()}finally{u.current=!1}},g=()=>{s||h(()=>e.commit(r===""?null:r))},C=()=>{r!==n&&!s?g():h(e.close)},q=z=>{if(z.key==="Escape"){z.preventDefault(),e.rejected?h(e.close):C();return}z.key==="Enter"&&(z.ctrlKey||z.metaKey)&&!z.altKey&&!z.shiftKey&&(z.preventDefault(),g())},j=z=>{u.current||z.relatedTarget instanceof Node&&z.currentTarget.contains(z.relatedTarget)||e.rejected||C()};return K.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:j,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:$e(t,"noteTitle")}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:z=>o(z.currentTarget.value),onKeyDown:q}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:$e(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:g,children:$e(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":$e(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},sa=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Rt=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")}),Ql=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],la=Object.freeze({all:Rt(Ql),values:Rt(["text"]),formats:Rt(["format","borders","cf"]),formulas:Rt(["text","formula"]),noBorders:Rt(Ql.filter(e=>e!=="borders")),columnWidths:Rt(["sizes"]),validation:Rt(["validation"]),conditionalFormats:Rt(["cf"]),commentsAndNotes:Rt(["note","comments"])}),ei=Object.freeze({mode:"all"}),ns=Object.freeze({t:""}),ti=Object.freeze({row:1<<30,col:1<<30}),Yh=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Uh=e=>e.t===""&&e.f===void 0,Xh=e=>e.length>1&&e.startsWith("="),Gh=(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}},ni=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Jh=(e,t,n,r)=>{const o=Xh(e),s=e===""?"0":et(e);if(!o&&s===null)return null;const l=Yh[n];if(t.f!==void 0){const h=ar(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:ni(Number(s));const c=et(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:ni(Gh(Number(s),u,n))},ri=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Zh=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:ri(e.start),end:ri(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}}}},Qh=e=>{const t=ar(e,ti),n=cr(t);let r="",o=0,s=!1;for(const l of n){const c=Zh(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${It(c)}`,o=l.end,s=!0)}return s?Zr(`${r}${t.slice(o)}`,ti):e},eg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return ns;const o=r[n];return o===void 0?ns:o},tg=e=>{const{rows:t,cols:n}=e,r=oc(Qh);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=eg(e,h,c);let C=g;if(g.f!==void 0){const q=r(g.f);C=q===g.f?g:{...g,f:q}}(C!==g||g===ns)&&(o=!1),u.push(C)}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}},ng=(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,rg=(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},oi=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const g of c)ng(g,t)?(h.push(rg(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},si=new WeakMap,ia=e=>{const t=si.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>dt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:dt({...s,borders:void 0})),o={canonical:n,borderless:r};return si.set(e,o),o},Yr=(e,t)=>t===void 0?void 0:e[t],og=(e,t,n,r)=>{const o=ia(e);if(n){const h=Yr(o.canonical,t.fmt);return h===void 0?null:h}const s=Yr(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=dt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},sg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Jh(n.readText(),o,r,n):o.f===void 0?o.t:ar(o.f,n)},li=(e,t,n,r,o)=>{const s=la[r.mode];if(r.skipBlanks===!0&&Uh(e))return null;const l={};let c=!1;if(s.text){const u=sg(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=og(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Yr(ia(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=Yr(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},ii=(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}}),lg=["text/html","text/plain"],ig=(e,t,n)=>{if(e===0||t===0)return 0;const r=tt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},cg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,ag=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,ug=e=>{const t=Array.from(e.types),n=new Map;return{types:t,getData:r=>{const o=n.get(r);if(o!==void 0)return o;const s=e.getData(r);return n.set(r,s),s}}},ci=e=>{const t=e.clipboardData;return t??null},dg=(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}},fg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=dg(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},pg=(e,t,n,r,o)=>{const s=Fn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Zr(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=zn(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=Bi(),r=yd(),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(pg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:fg(e.getConditionalFormats(),t)}},ai=e=>e.kind==="cut"?{...e.payload,...ca(e.sourceAdapter,e.range)}:e.payload,hg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:us(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),gg=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=Bt(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},mg=(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},wg=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return he({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Cg=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($=>{const T=n.current;if(T===null||$==="format"||$==="annotate")return;const P=r.current;P==="own"||P==="foreign"&&T.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const $=n.current;if($===null)return;if($.kind==="copy"){o();return}const T=t.current;T.repaintOverlay(),T.onClipChange?.({kind:"cut",range:$.range,foreign:$.sourceAdapter!==T.adapter})},[o]),c=i.useCallback(($,T,P)=>{const S=t.current;n.current={kind:$,range:T,clipId:P.clipId,sourceAdapter:S.adapter,payload:P},S.repaintOverlay(),S.onClipChange?.({kind:$,range:T,foreign:!1})},[]),u=i.useCallback($=>{const T=t.current,P=T.adapter,S=tt($),v={v:1,rows:S.rows,cols:S.cols,clipId:us(),...ca(P,$),wholeRows:Vi($,P.colCount),wholeCols:Wi($,P.rowCount)};if(T.resize!==void 0){if(v.wholeCols){const E=[];for(let p=$.startCol;p<=$.endCol;p+=1)E.push(Math.min(T.resize.colAxis.sizeOf(p),Dn));v.colWidths=E}if(v.wholeRows){const E=[];for(let p=$.startRow;p<=$.endRow;p+=1)E.push(Math.min(T.resize.rowAxis.sizeOf(p),Dn));v.rowHeights=E}}return v},[]),h=i.useCallback(($,T)=>{const P=t.current,S=P.getSelection(),v=S.ranges[S.ranges.length-1],E=wt([v]);if(E>P.maxOperationCells)return $.preventDefault(),P.onOperationRejected?.(T,E,"limit"),null;if(T==="cut"&&Gn(P.adapter,v))return $.preventDefault(),P.rejectReadOnly({kind:"operation",op:"cut",cellCount:E}),null;S.ranges.length>1&&P.onCopyMultiRange?.();const p=u(v),m=$i(p),y=ci($);return y!==null&&(y.setData("text/plain",Fc(p.cells.map(M=>M.map(x=>x.t)))),y.setData("text/html",Rc(p,m)),y.setData(Vr,m)),$.preventDefault(),{payload:p,range:v}},[u]),g=i.useCallback(($,T)=>t.current.commitPaste($,T)!==null,[]),C=i.useCallback(($,T,P)=>{const S=t.current;if(!P.sizes||S.resize===void 0)return;const{rowAxis:v,colAxis:E,resizeTracks:p}=S.resize,m=(y,M,x)=>{const R=ls(M,x,null,{maxOperationCells:S.maxOperationCells,rowHiddenLimit:os,axisKind:y});if(!R.ok){S.onOperationRejected?.("resize",R.count,R.reason);return}p(y,R.entries)};if($.colWidths!==void 0){const y=[];for(let M=T.startCol;M<=T.endCol;M+=1)y.push({index:M,size:$.colWidths[(M-T.startCol)%$.cols]});m("col",E,y)}if($.rowHeights!==void 0){const y=[];for(let M=T.startRow;M<=T.endRow;M+=1)y.push({index:M,size:$.rowHeights[(M-T.startRow)%$.rows]});m("row",v,y)}},[]),q=i.useCallback(($,T)=>{const P=t.current,S=P.adapter,v=$.payload,E={row:T.startRow,col:T.startCol},p=v.rows*v.cols+wt([$.range]);if(p>P.maxOperationCells)return P.onOperationRejected?.("paste",p,"limit"),"rejected";if(E.row+v.rows>S.rowCount||E.col+v.cols>S.colCount||$.range.endRow>=$.sourceAdapter.rowCount||$.range.endCol>=$.sourceAdapter.colCount)return P.onOperationRejected?.("paste",p,"bounds"),"rejected";const m=es({rows:v.rows,cols:v.cols},he(E,E),E,S.rowCount,S.colCount);if(m!==null&&Gn(S,m))return P.rejectReadOnly({kind:"operation",op:"paste",cellCount:v.rows*v.cols}),"rejected";if(Gn($.sourceAdapter,$.range))return P.rejectReadOnly({kind:"operation",op:"cut",cellCount:wt([$.range])}),"rejected";const y=ai($),M=Hr(S),x=oi(y,M),R={row:0,col:0,readText:()=>Fn(S,R.row,R.col).text,readFormat:()=>S.getCellFormat===void 0?void 0:S.getCellFormat(R.row,R.col)},{edits:N,tiles:b}=Ll(x.cells,he(E,E),E,S.rowCount,S.colCount,(O,d,A)=>(R.row=$.range.startRow+(d-E.row),R.col=$.range.startCol+(A-E.col),li(O,x,R,ei,M))),a=Hr($.sourceAdapter),f=[];if(qt([$.range],O=>{f.push(mg(O.row,O.col,a))}),$.sourceAdapter===S){if(!g([...f,...N],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const O=P.commitPaste(N,{sameSheet:!1,conditionalFormats:ii(x.conditionalFormats,b)});if(O===null)return"rejected";try{$.sourceAdapter.applyEdits(f,{transaction:O,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){P.onEditRejected?.(d,{source:"paste"})}}return P.setSelection({ranges:[he(E,{row:E.row+y.rows-1,col:E.col+y.cols-1})],anchor:E,active:E}),"applied"},[g]),j=i.useCallback(($,T,P)=>{const S=t.current,v=S.adapter,E=U=>(S.onClipboardUnavailable?.(U),"rejected"),p=Ni($,T);if(p==="none")return T==="menu"?E("empty"):"empty";const m=S.getSelection(),y=m.ranges[m.ranges.length-1],M=P.transpose===!0,x=(U,Q)=>{const ee=ig(M?Q:U,M?U:Q,y);return ee>S.maxOperationCells?(S.onOperationRejected?.("paste",ee,"limit"),!0):!1};let R,N=null;if(p==="aqsp"){const U=Ku($,T);if(U===null)return E("unreadable");const Q=n.current;if(Q!==null&&U.clipId===Q.clipId&&(N=Q),N!==null&&N.kind==="cut"&&cg(P))return q(N,y);if(x(U.rows,U.cols))return"rejected";if(N!==null){if(N.kind==="cut"&&(N.range.endRow>=N.sourceAdapter.rowCount||N.range.endCol>=N.sourceAdapter.colCount))return S.onOperationRejected?.("paste",N.payload.rows*N.payload.cols,"bounds"),"rejected";R=ai(N)}else{const ee=Yu($,T);if(ee===null)return E("unreadable");if(x(ee.rows,ee.cols))return"rejected";R=gg(ee)}}else if(p==="tsv"){const U=$.getData("text/plain"),Q=jp(U);if(x(Q.rows,Q.cols))return"rejected";R=hg(Lc(U))}else{const U=$.getData("text/html"),Q=Cd(U);if(Q.cols===0&&Q.rows>S.maxOperationCells)return S.onOperationRejected?.("paste",Q.rows,"limit"),"rejected";if(x(Q.rows,Q.cols))return"rejected";const ee=Ac(U,p,S.formats===void 0?{}:{currency:S.formats.currency,locale:S.formats.locale},S.maxOperationCells);if(ee.outcome==="none")return E("unreadable");if(ee.outcome==="limit")return S.onOperationRejected?.("paste",ee.cells,"limit"),"rejected";if(x(ee.payload.rows,ee.payload.cols))return"rejected";R=ee.payload}const b=Hr(v),a=oi(M?tg(R):R,b),f=la[P.mode];if(ag(f)){const U=es({rows:a.rows,cols:a.cols},y,m.active,v.rowCount,v.colCount);if(U!==null&&Gn(v,U))return S.rejectReadOnly({kind:"operation",op:"paste",cellCount:wt([U])}),"rejected"}const O={row:0,col:0,readText:()=>Fn(v,O.row,O.col).text,readFormat:()=>v.getCellFormat===void 0?void 0:v.getCellFormat(O.row,O.col)},{edits:d,tiles:A}=Ll(a.cells,y,m.active,v.rowCount,v.colCount,(U,Q,ee)=>(O.row=Q,O.col=ee,li(U,a,O,P,b))),k=wg(A,a.rows,a.cols,v.rowCount,v.colCount);if(k===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let U=0;for(const ee of a.conditionalFormats)U+=ee.ranges.length;const Q=A.length*U;if(Q>S.maxOperationCells)return S.onOperationRejected?.("paste",Q,"limit"),"rejected"}const D=f.cf?ii(a.conditionalFormats,A):[];if(d.length===0&&D.length===0)return C(a,k,f),"empty";r.current=N===null?"foreign":"own";let F=!1;try{F=g(d,{sameSheet:N!==null&&N.sourceAdapter===v,conditionalFormats:D})}finally{r.current="none"}if(!F)return"rejected";C(a,k,f);const V={row:k.startRow,col:k.startCol};return S.setSelection({ranges:[k],anchor:V,active:V}),"applied"},[q,g,C]),z=i.useCallback(async $=>{const T=M=>(t.current.onClipboardUnavailable?.(M),"rejected"),P=navigator;if(P.clipboard===void 0)return T("insecure-origin");let S;try{S=await P.clipboard.read({unsanitized:["text/html"]})}catch{return T("permission-denied")}if(S.length===0)return T("empty");const v=S[0],E=Array.from(v.types),p=new Map;try{for(const M of lg)E.includes(M)&&p.set(M,await(await v.getType(M)).text())}catch{return T("unreadable")}const m={types:E,getData:M=>{const x=p.get(M);if(x===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${M} was not materialised for the menu path`);return x}},y=t.current;return!y.enabled||y.isDragging()||y.isEditing()?"rejected":j(m,"menu",$)},[j]),I=i.useCallback(async $=>{const T=await z($);return t.current.onPasteResolved?.(T,"menu"),T},[z]),{enabled:Y,sinkRef:H}=e;return i.useEffect(()=>{const $=H.current;if(!Y||$===null)return;const T=E=>t.current.isDragging()?(E.preventDefault(),!0):!1,P=E=>{const p=t.current;if(T(E)||p.isEditing())return;const m=h(E,"copy");m!==null&&c("copy",m.range,m.payload)},S=E=>{const p=t.current;if(T(E)||p.isEditing())return;const m=h(E,"cut");m!==null&&c("cut",m.range,m.payload)},v=E=>{const p=t.current;if(T(E)||p.isEditing())return;E.preventDefault();let m=ei;const y=p.pendingPasteOptionsRef;y!==void 0&&y.current!==null&&(m=y.current,y.current=null);const M=ci(E);if(M===null)return;const x=j(ug(M),"event",m);p.onPasteResolved?.(x,"event")};return $.addEventListener("copy",P),$.addEventListener("cut",S),$.addEventListener("paste",v),()=>{$.removeEventListener("copy",P),$.removeEventListener("cut",S),$.removeEventListener("paste",v)}},[Y,H,h,c,j]),i.useMemo(()=>({getClip:()=>{const $=n.current;return $===null?null:{kind:$.kind,range:$.range,foreign:$.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:I}),[o,s,l,I])},aa=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)}`)},ua=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}},ui=(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=ui(e.negative,e.digits,e.point+t);else{const r=ui(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return et(n)===null?null:n},yg=(e,t)=>{aa(t);const n=et(e);return n===null?null:da(ua(n),t)},bg=e=>{const t=et(e);if(t!==null){const r=ua(t);return da({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},fa=e=>{if(!e.startsWith("=")||e.length===1)throw new RangeError(`[spreadsheet] self-calc expects a formula ("=" followed by a body); got ${JSON.stringify(e)}`);return e.slice(1)},vg=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},pa=(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 vg(r)?r:null},Rg=(e,t)=>{aa(t);const n=fa(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=pa(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},kg=e=>{const t=fa(e),n=pa(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Kn=(e,t,n,r)=>{const o=wt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Mr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},$r={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},di={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:Mr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Mr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Mr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Mr.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:$r.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:$r.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:$r.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:$r.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},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},Sg={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},nr=e=>e<10?`0${e}`:String(e),Eg=e=>{const t=new Date(e);return`${t.getFullYear()}-${nr(t.getMonth()+1)}-${nr(t.getDate())}`},Ag=e=>{const t=new Date(e);return`${nr(t.getHours())}:${nr(t.getMinutes())}:${nr(t.getSeconds())}`},xg=(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),Og=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Tg=e=>e===void 0||e.borders===void 0?{}:e.borders,Dg={top:1,right:2,bottom:4,left:8},Mg={style:"thin",color:is},$g=(e,t)=>{if(e===void 0)return!1;const n=Ke(e);return n!==null&&n===Ke(t)},Fg=(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}}},zg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const p=t.current;if(p.isEditing()){const m=p.getActive();return[he(m,m)]}return p.getSelection().ranges},[]),r=i.useCallback(()=>{const p=t.current,m=p.getActive();return p.adapter.getCellFormat===void 0?void 0:p.adapter.getCellFormat(m.row,m.col)},[]),o=i.useCallback(p=>{const m=t.current,y=n();if(!Kn("format",y,m.maxOperationCells,m.onOperationRejected))return!1;if(Sn(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"format",cellCount:wt(y)}),!1;const M=new Map,x=[],R=m.adapter.getCellFormat;for(const N of y)qt([N],b=>{const a=R===void 0?void 0:R(b.row,b.col),{bucket:f,patch:O}=p(b,N,a);let d=M.get(f);d===void 0&&(d=new Map,M.set(f,d));let A;d.has(a)?A=d.get(a):(A=as(a,O),d.set(a,A)),A!==a&&x.push({row:b.row,col:b.col,format:A===void 0?null:A})});return x.length===0?!0:m.commitEdits(x,{source:"format"})===null?!1:(m.isEditing()&&m.refreshEditPaint(),!0)},[n]),s=i.useCallback(p=>o(()=>({bucket:0,patch:p})),[o]),l=i.useCallback((p,m)=>{const y=t.current;y.formatCommandAnnouncement!==void 0&&y.announce(y.formatCommandAnnouncement({command:p,state:m}))},[]),c=i.useCallback((p,m=Mg)=>{if(p==="clear")return s({borders:null});if(p==="all")return s({borders:{top:m,right:m,bottom:m,left:m}});const y=p==="outer"?15:Dg[p];return o((M,x,R)=>{const N=xg(M,x)&y;return{bucket:N,patch:{borders:{...Tg(R),...Og(N,m)}}}})},[s,o]),u=i.useCallback((p,m,y)=>{const M=Mc(t.current.adapter,p.row,p.col);for(const x of m)y.push($c(M,p,x))},[]),h=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Kn("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;const M=[];if(p==="selection"){const R=y.active,N=[];qt(y.ranges,b=>{(b.row!==R.row||b.col!==R.col)&&N.push(b)}),M.push({source:R,targets:N})}else for(const R of y.ranges)if(p==="down"){const N=R.startRow===R.endRow;if(N&&R.startRow===0)continue;const b=N?R.startRow-1:R.startRow;for(let a=R.startCol;a<=R.endCol;a+=1){const f=[];for(let O=N?R.startRow:R.startRow+1;O<=R.endRow;O+=1)f.push({row:O,col:a});M.push({source:{row:b,col:a},targets:f})}}else{const N=R.startCol===R.endCol;if(N&&R.startCol===0)continue;const b=N?R.startCol-1:R.startCol;for(let a=R.startRow;a<=R.endRow;a+=1){const f=[];for(let O=N?R.startCol:R.startCol+1;O<=R.endCol;O+=1)f.push({row:a,col:O});M.push({source:{row:a,col:b},targets:f})}}for(const R of M)for(const N of R.targets)if(Be(m.adapter,N.row,N.col)){let b=0;for(const a of M)b+=a.targets.length;return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:b}),!1}const x=[];for(const R of M)u(R.source,R.targets,x);return x.length===0?!0:m.commitEdits(x,{source:"fill"})!==null},[u]),g=i.useCallback(()=>{const p=t.current,m=p.getSessionText();if(m===null)return!1;const y=p.getSelection();if(!Kn("fill",y.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Sn(p.adapter,y.ranges))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:wt(y.ranges)}),!1;const M=[];let x=!1;return qt(y.ranges,R=>{if(!x){if(!p.validateCommit(R,m).ok){x=!0;return}M.push({row:R.row,col:R.col,text:m})}}),x||p.commitEdits(M,{source:"fill"})===null?!1:(p.cancelEdit(),!0)},[]),C=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Kn("calc",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(Sn(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"calc",cellCount:wt(y.ranges)}),!1;const M=[],x=m.adapter;return qt(y.ranges,R=>{const N=x.getCellFormula===void 0?void 0:x.getCellFormula(R.row,R.col),b=N===void 0?p.text(x.getCellText(R.row,R.col)):p.formula(N);b!==null&&M.push({row:R.row,col:R.col,text:b})}),M.length===0?!0:m.commitEdits(M,{source:"calc"})!==null},[]),q=i.useCallback((p,m)=>{const y=t.current,M=p==="row"?y.rowAxis:y.colAxis,x=y.getSelection(),R=p==="row"?Math.floor(y.maxOperationCells/ss):y.maxOperationCells;let N=0;for(const d of x.ranges)N+=p==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(N>R)return y.onOperationRejected?.("resize",N,"limit"),!1;const b=new Set,a=[],f=m?0:p==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const d of x.ranges){const A=p==="row"?d.startRow:d.startCol,k=p==="row"?d.endRow:d.endCol;for(let D=A;D<=k;D+=1){if(b.has(D))continue;b.add(D),M.sizeOf(D)===0!==m&&a.push({index:D,size:f})}}const O=ls(M,a,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:os,axisKind:p});return O.ok?(O.entries.length>0&&y.resizeTracks(p,O.entries),!0):(y.onOperationRejected?.("resize",O.count,O.reason),!1)},[]),j=i.useCallback(()=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)return;const m=p.getActive();return zn(p.adapter.getCellHyperlink(m.row,m.col))},[]),z=i.useCallback(p=>{const m=t.current,y=m.adapter,M=di[p],x=y.getCellFormat!==void 0,R=N=>m.popovers===void 0?!0:m.popovers[N]!==!1;switch(M.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return x;case"value":return x&&(M.value!=="currency"||m.formats!==void 0);case"popover":switch(M.popover){case"link":return y.getCellHyperlink!==void 0&&R("link");case"note":return y.getCellNote!==void 0&&R("note");case"comment":return y.getCellComments!==void 0&&R("comment");default:return y.getCellValidation!==void 0&&R("list")}case"openHyperlink":return y.getCellHyperlink!==void 0&&(m.onHyperlinkOpen!==void 0?j()!==void 0:R("link"));case"paste":return M.options.mode==="formats"?x:M.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[j]),I=i.useCallback(p=>{const m=t.current,y=p.kind==="popover"?p.popover:p.kind==="openHyperlink"&&m.onHyperlinkOpen===void 0?"link":void 0;if(y===void 0)return!0;const M=m.getActive();if(!Be(m.adapter,M.row,M.col))return!0;if(y==="list")return m.rejectReadOnly({kind:"edit",cell:M,editSession:"none"}),!1;let x;if(y==="link")x=j()!==void 0;else if(y==="note"){const R=m.adapter.getCellNote===void 0?void 0:m.adapter.getCellNote(M.row,M.col);x=R!==void 0&&R!==""}else{const R=m.adapter.getCellComments===void 0?void 0:m.adapter.getCellComments(M.row,M.col);x=R!==void 0&&R.length>0}return x?!0:(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[j]),Y=i.useCallback(p=>{const m=t.current;if(!z(p))return!1;const y=di[p];if(!I(y))return!1;const M=m.isEditing();if(M&&!vs.has(p)&&!m.requestCommit())return!1;switch(y.kind){case"toggle":{const x=r(),R=x!==void 0&&x[y.key]===!0;return s({[y.key]:R?null:!0})?(l(p,!R),!0):!1}case"patch":return s(y.patch)?(l(p,null),!0):!1;case"clear":return s(Sg)?(l(p,null),!0):!1;case"value":return s({value:Fg(y.value,m.formats)})?(l(p,null),!0):!1;case"borders":return c(y.preset)?(l(p,null),!0):!1;case"color":{const x=y.key==="background"?m.colors.fill:m.colors.font,R=y.preset!==null?y.preset:y.custom!==null&&y.custom<x.length?x[y.custom]:void 0;if(R===void 0)return!1;const N=r(),b=$g(N===void 0?void 0:N[y.key],R);return s({[y.key]:b?null:R})?(l(p,!b),!0):!1}case"calc":return C({text:x=>yg(x,y.exponent),formula:x=>Rg(x,y.exponent)});case"sign":return C({text:bg,formula:kg});case"fill":return M&&y.direction==="selection"?g():h(y.direction);case"popover":return m.openPopover(y.popover),!0;case"openHyperlink":{if(m.onHyperlinkOpen!==void 0){const x=j();return x===void 0?!1:(m.onHyperlinkOpen(x,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 x=y.unit==="date"?Eg(m.now()):Ag(m.now());if(M)return m.insertAtCaret(x),!0;const R=m.getActive();return Be(m.adapter,R.row,R.col)?(m.rejectReadOnly({kind:"edit",cell:R,editSession:"none"}),!1):m.validateCommit(R,x).ok?m.commitEdits([{row:R.row,col:R.col,text:x}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return q(y.axis,y.hide);default:{const x=m.getHighlight();switch(y.target){case"row":return m.setHighlight({...x,row:!x.row}),!0;case"column":return m.setHighlight({...x,column:!x.column}),!0;case"both":{const R=x.row&&x.column;return m.setHighlight({...x,row:!R,column:!R}),!0}default:return m.setHighlight({...x,intersection:!x.intersection}),!0}}}},[z,I,j,r,s,l,c,C,h,g,q]),H=i.useCallback(()=>{const p=t.current;return!(p.isEditing()&&!p.requestCommit())},[]),$=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const y=p===null?null:Bt(p);if(p!==null&&y===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(p)}`);if(!H())return!1;const M=m.getActive();return Be(m.adapter,M.row,M.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:M.row,col:M.col,hyperlink:y}],{source:"annotate"})!==null},[H]),T=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!H())return!1;const y=m.getActive();return Be(m.adapter,y.row,y.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:y.row,col:y.col,note:p}],{source:"annotate"})!==null},[H]),P=i.useCallback(p=>{const m=t.current,y=m.adapter.getCellComments;if(y===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!H())return!1;const M=m.getActive();if(Be(m.adapter,M.row,M.col))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const x=y(M.row,M.col),R=x===void 0?[p]:[...x,p];return m.commitEdits([{row:M.row,col:M.col,comments:R}],{source:"annotate"})!==null},[H]),S=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!H())return!1;const y=m.getSelection().ranges;if(!Kn("annotate",y,m.maxOperationCells,m.onOperationRejected))return!1;if(Sn(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:wt(y)}),!1;const M=[];return qt(y,x=>{M.push({row:x.row,col:x.col,validation:p})}),m.commitEdits(M,{source:"annotate"})!==null},[H]),v=i.useCallback(p=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(p)},[s]),E=i.useCallback((p,m)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(p,m)},[c]);return i.useMemo(()=>({executeCommand:Y,applyFormat:v,setBorders:E,setHyperlink:$,setNote:T,addComment:P,setValidation:S,isCommandAvailable:z}),[Y,v,E,$,T,P,S,z])},Fr="data-aqsp-pointing",Ng=(e,t)=>{const n=ac(e,t);return n!==null&&"insertAt"in n},Lg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Pg=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(St),g=i.useCallback(()=>{const b=t.current,a=b.sinkRef.current;if(b.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=ac(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),C=i.useCallback(()=>{const b=t.current.sinkRef.current;if(b===null)return;const a=g()!==null;a!==b.hasAttribute(Fr)&&(a?b.setAttribute(Fr,""):b.removeAttribute(Fr))},[g]),q=i.useCallback((b,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const O=f.resolveEditPaint(a),d=O===null?St:O;d!==St&&Object.assign(b.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),j=i.useCallback(b=>{Lg(b,Object.keys(h.current.style)),h.current=St;const a=t.current.editPaintRef;a!==void 0&&(a.current=St)},[]),z=i.useCallback(b=>{const a=t.current,f=n.current;if(f===null)return!0;const O=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),j(d),d.removeAttribute(Fr)),o(!1)};if(b.commit){const d=a.sinkRef.current,A=d===null?"":d.value,k=Fn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
20
+ `),D=A===k;let F;if(D)F=!0;else if(Be(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:b.onReject==="keep"?"kept":"discarded"}),F=!1;else{const V={source:"edit",editSession:b.onReject==="keep"?"kept":"discarded"};F=(a.validateCommit===void 0||a.validateCommit(f.cell,A).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:A}],V)!==null}if(!F)return b.onReject==="discard"&&(O(),a.rearmSink()),!1}return O(),b.rearm&&a.rearmSink(),!0},[j]),I=i.useCallback((b,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const O=f.sinkRef.current;if(O===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),b==="edit"){const{text:k,isFormula:D}=Fn(f.adapter,d.row,d.col);O.value=k;const F=a===void 0||D?k.length:Math.min(a,k.length);O.setSelectionRange(F,F)}else O.value="";const A=f.resolveEditAlign(d);A!==null&&(O.style.textAlign=A),q(O,d),c.current=!1,u.current=null,n.current={cell:d,mode:b},o(!0)},[q]),Y=i.useCallback(()=>{z({rearm:!0,commit:!1})},[z]),H=i.useCallback(()=>{const b=t.current;if(n.current===null)return!0;const a=b.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return z({rearm:!1,commit:!0,onReject:"keep"})?(b.focusSink(),b.rearmSink(),!0):(b.focusSink(),!1)}return z({rearm:!0,commit:!0,onReject:"keep"})},[z]),$=i.useCallback(()=>g()!==null,[g]),T=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,C(),!0),[C]),P=i.useCallback(()=>{const b=g(),a=n.current;if(b===null||a===null)return null;if("insertAt"in b.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=cc(b.sink.value,b.sink.selectionStart);if(f===null)return null;const O=f.token,d=u.current;switch(O.kind){case"cell":{const A={row:O.row,col:O.col};return u.current=A,{origin:A,cursor:A,axis:"cells"}}case"range":{const A=d!==null&&(d.row===O.start.row||d.row===O.end.row)&&(d.col===O.start.col||d.col===O.end.col)?{row:d.row,col:d.col}:{row:O.start.row,col:O.start.col};return u.current=A,{origin:A,cursor:{row:A.row===O.start.row?O.end.row:O.start.row,col:A.col===O.start.col?O.end.col:O.start.col},axis:"cells"}}case"column":{const A=d!==null&&(d.col===O.start.col||d.col===O.end.col)?d.col:O.start.col,k={row:a.cell.row,col:A};return u.current=k,{origin:k,cursor:{row:a.cell.row,col:A===O.start.col?O.end.col:O.start.col},axis:"columns"}}case"row":{const A=d!==null&&(d.row===O.start.row||d.row===O.end.row)?d.row:O.start.row,k={row:A,col:a.cell.col};return u.current=k,{origin:k,cursor:{row:A===O.start.row?O.end.row:O.start.row,col:a.cell.col},axis:"rows"}}}},[g]),S=i.useCallback((b,a)=>{const f=g();if(f===null)return;const O=Zd(b,a),{sink:d}=f,[A,k]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],D=d.value;d.value=`${D.slice(0,A)}${O}${D.slice(k)}`;const F=A+O.length;d.setSelectionRange(F,F),"row"in b&&(u.current={row:b.row,col:b.col}),C()},[g,C]),v=i.useCallback(()=>{const b=t.current.sinkRef.current;return b===null?null:{value:b.value,selectionStart:b.selectionStart,selectionEnd:b.selectionEnd}},[]),E=i.useCallback(b=>{const a=t.current.sinkRef.current;a!==null&&(a.value=b.value,a.setSelectionRange(b.selectionStart,b.selectionEnd),u.current=null,C())},[C]),p=i.useCallback(()=>{const b=t.current,a=b.sinkRef.current;if(b.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=af(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),C(),!0)},[C]),m=i.useCallback(b=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,O=a.selectionEnd;a.value=`${a.value.slice(0,f)}${b}${a.value.slice(O)}`;const d=f+b.length;a.setSelectionRange(d,d),u.current=null,C()},[C]),y=i.useCallback(()=>{const b=t.current.sinkRef.current;return n.current===null||b===null?null:b.value},[]),M=i.useCallback(()=>n.current===null?null:n.current.cell,[]),x=i.useCallback(()=>{const b=t.current,a=n.current,f=b.sinkRef.current;a===null||f===null||(j(f),q(f,a.cell),b.repaintOverlay?.())},[j,q]),{enabled:R,sinkRef:N}=e;return i.useEffect(()=>{const b=N.current;if(!R||b===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},O=k=>{const D=t.current;if(l.current||n.current===null)return;const F=D.rootRef.current,V=k.relatedTarget;F!==null&&V instanceof Node&&F.contains(V)||z({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const k=t.current;u.current=null,k.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Ng(b.value,b.selectionStart)&&(c.current=!0),C()},A=()=>{n.current!==null&&C()};return b.addEventListener("compositionstart",a),b.addEventListener("compositionend",f),b.addEventListener("focusout",O),b.addEventListener("input",d),document.addEventListener("selectionchange",A),()=>{b.removeEventListener("compositionstart",a),b.removeEventListener("compositionend",f),b.removeEventListener("focusout",O),b.removeEventListener("input",d),document.removeEventListener("selectionchange",A)}},[R,N,z,C]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:H,cancelEdit:Y,startEdit:I,getPointing:$,togglePointingArm:T,getReferenceCursor:P,insertReference:S,captureSink:v,restoreSink:E,cycleAnchorAtCaret:p,insertAtCaret:m,getSessionText:y,getSessionCell:M,refreshPaint:x,editing:r}),[H,Y,I,$,T,P,S,v,E,p,m,y,M,x,r])},qg=(e,t,n)=>{const r=new lr.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}},_g=(e,t,n)=>{const{tree:r,initialHidden:o}=qg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:g,currentValue:C}=r.prefixSum(h);return g-C},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),C=Math.min(Math.max(g,0),r.getTotal()-1);return r.findIndexAtOrAfter(C+.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 C=Math.round(g);r.get(h)===0!=(C===0)&&(s+=C===0?1:-1),r.update(h,C)},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)},On=(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},fi=(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=_g(e,t,r)),o.current.model},Tn=256,No=256,Ig=2**32,jg=4096,ha=Object.freeze([]),ga=["background","color","bold","italic","underline","strikethrough"],ma=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Ht=(e,t,n)=>(e.size>=jg&&e.clear(),e.set(t,n),n),wa=e=>(ma(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Ca=(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},Hg=(e,t,n)=>{const r=Math.floor(t/Tn),o=Math.floor(n/No),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Tn,u=o*No,h=[];for(const g of e.rules)Ca(g.ranges,c,c+Tn-1,u,u+No-1)&&h.push(g);return Ht(e.buckets,s,h.length===0?ha:h)},Bg=(e,t,n)=>{const r=Math.floor(t/Tn),o=r*Ig+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Hg(e,t,n),c=r*Tn,u=[];for(const h of l)Ca(h.ranges,c,c+Tn-1,n,n)&&u.push(h);return Ht(e.columns,o,u.length===0?ha:u)},Vg=(e,t)=>{for(const n of e)if(an(n,t))return!0;return!1},Rs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),zr=(e,t)=>e<t?-1:e>t?1:0,pi=(e,t,n)=>{switch(e){case"eq":return t===0;case"neq":return t!==0;case"gt":return t>0;case"gte":return t>=0;case"lt":return t<0;case"lte":return t<=0;case"between":return n!==null&&t>=0&&n<=0;case"notBetween":return n!==null&&(t<0||n>0);default:return!1}},hi=new WeakMap,rs=e=>e===null?null:Number(e),Wg=e=>{const t=hi.get(e);if(t!==void 0)return t;const n=e.b,r={a:rs(et(e.a)),b:n===void 0?null:rs(et(n))};return hi.set(e,r),r},ya=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Ht(e.numbers,r,rs(et(n())))},Kg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Wg(e),l=ya(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return pi(e.op,zr(l,s.a),c===null?null:zr(l,c));const u=n(),h=e.b;return pi(e.op,zr(u,e.a),h===void 0?null:zr(u,h))},Yg=(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}},Lo=e=>{const t=Ke(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]},Nr=e=>e.toString(16).padStart(2,"0"),Po=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Nr(r(0))}${Nr(r(1))}${Nr(r(2))}`,s=r(3);return s===255?o:`${o}${Nr(s)}`},qo=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Ug=(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=Lo(t.color),u=Lo(r.color);const h=n===void 0?void 0:Lo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const C=s;s=l,l=C;const q=c;c=u,u=q}if(n!==void 0&&h!==void 0){const C=n.value===void 0?(s+l)/2:n.value;if(s<C&&C<l)return e<=C?Po(c,h,qo(e,s,C)):Po(h,u,qo(e,C,l))}return Po(c,u,qo(e,s,l))},Xg=(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 Ht(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 Ht(r.extrema,e.id,null);c=Math.min(c,g.min),u=Math.max(u,g.max)}return Ht(r.extrema,e.id,{min:c,max:u})},Gg=(e,t,n,r,o,s)=>{const l=ya(s,n,r);if(l===null)return null;const c=Xg(e,t,o,s);return c===null?null:Ug(l,t.min,t.mid,t.max,c)},Jg=(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:Ht(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Zg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Kg(s,t,n,o)?e.style:null;case"text":return Yg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Gg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Jg(e,s,t,r,o)?e.style:null;default:return null}},gi=(e,t)=>as(e,t),Qg=(e,t,n)=>{e[t]=n},em=(e,t)=>{let n=e;for(const r of ga)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Qg(n,r,t[r]));return n},tm=e=>{let t="";for(const n of ga){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},mi=new WeakMap,nm=Object.freeze({}),rm=e=>{const t=e===void 0?nm:e,n=mi.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return mi.set(t,r),r},om=(e,t,n)=>{const r=rm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=gi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=tm(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=gi(e,t);return l!==void 0&&Ht(r.byKey,o,l),l},ks=(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=Bg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,g=!0;for(const C of c){if(!Vg(C.ranges,u))continue;const q=Zg(C,u,s,e,n);if(q!==null){if(q!==C.style&&(g=!1),h===null)h=q;else{const j=em(h,q);j!==h&&(g=!1,h=j)}if(C.stopIfTrue===!0)break}}return h===null?l:om(l,h,g)},wi=new WeakMap,sm=e=>{ma(e,"widthRelevantRules");const t=wi.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 wi.set(e,r),r},lm=({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},im=i.memo(lm),cm=Object.freeze({left:Object.freeze({justifyContent:Zn("left")}),center:Object.freeze({justifyContent:Zn("center")}),right:Object.freeze({justifyContent:Zn("right")})}),am=4096,Ci=new WeakMap,Lr=new Map,um=(e,t)=>{if(e===null)return cm[t];let n=Ci.get(e);n===void 0&&(n={},Ci.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:Zn(t)},s=JSON.stringify(o);let l=Lr.get(s);return l===void 0&&(Lr.size>=am&&Lr.clear(),l=Object.freeze(o),Lr.set(s,l)),n[t]=l,l},dm=Rs(),fm=(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},pm=(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=jr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const g=ks(e,r===null?null:r.indexRef.current,r===null?dm:r.memoRef.current,o,s,l);h=g===void 0?void 0:g.value;const C=xc(g,l),q=jt(n,s,1),j=jt(t,o,1),z=Td(g,q===null?void 0:e.getCellFormat(o,q),j===null?void 0:e.getCellFormat(j,s),n.offsetOf(s)===0,t.offsetOf(o)===0);z!==null&&Object.assign(c,z.attrs),c["data-aqsp-align"]=C,u=um(z,C)}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&&zn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&Mh(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},hm=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:g,frozenTrailingRows:C,renderCell:q,onScroll:j,onRangeChange:z,focusSink:I,isEditing:Y,requestCommit:H,testId:$,__onCellRender:T,__maxRenderedCells:P,cfIndexRef:S,cfMemoRef:v,isPointing:E,tapScrollCircleOptions:p,overscanRows:m,overscanCols:y,background:M,onRenderTruncated:x})=>{const R=i.useRef(null),N=s??R;if(S===void 0!=(v===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const b=i.useMemo(()=>S===void 0||v===void 0?null:{indexRef:S,memoRef:v},[S,v]),a=i.useCallback(()=>r.get().editVersion,[r]),f=i.useCallback(G=>r.subscribeCoalesced(G),[r]),d=i.useSyncExternalStore(f,a,a)+(l??0),A=i.useCallback(G=>t.sizeOf(G),[t]),k=i.useCallback(G=>n.sizeOf(G),[n]),D=i.useCallback((G,ve)=>e.getCellText(G,ve),[e]),F=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),V=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),U=i.useMemo(()=>({width:ut,tapScrollCircleOptions:p}),[p]),Q=i.useRef({row:-1,col:-1,value:void 0}),ee=i.useCallback((G,ve)=>{const Fe={role:"gridcell","aria-rowindex":G+1,"aria-colindex":ve+1,"data-aqsp-cell":"","data-row":G,"data-col":ve,className:"aqsp-cell",...Be(e,G,ve)?{"aria-readonly":"true","data-aqsp-readonly":""}:{}},Ae=zp(e,G,ve),Me=Ae===null?Fe:{...Fe,...Ae},ze=pm(e,t,n,b,G,ve),Ye=Q.current;return Ye.row=G,Ye.col=ve,Ye.value=ze===null?void 0:ze.value,ze===null?Me:ze.style===null?{...Me,...ze.attrs}:{...Me,...ze.attrs,style:ze.style}},[e,t,n,b]),oe=i.useCallback(G=>({role:"row","aria-rowindex":G+1,"data-aqsp-row":G,"data-aqsp-cells":"",className:"aqsp-row"}),[]),ie=i.useCallback((G,ve,Fe)=>{let Ae=G;return e.getCellFormat!==void 0&&(Ae=Mn(G,fm(Q.current,ve,Fe))),K.jsx(im,{row:ve,col:Fe,text:G,display:Ae,renderCell:q,__onCellRender:T})},[d,q,T,e]);return K.jsx("div",{ref:N,className:"aqsp-body","data-aqsp-body":"","data-testid":$?`${$}-body`:void 0,onPointerDownCapture:G=>{if(!(G.target instanceof Element&&G.target.closest("[data-aqsp-cells]")!==null)&&G.pointerType==="mouse"){if(G.button!==0){G.preventDefault();return}if(G.preventDefault(),E?.()===!0){G.stopPropagation(),I();return}if(Y()&&!H()){G.stopPropagation(),I();return}I()}},children:K.jsx(lr.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:g,frozenTrailingRows:C,getRowHeight:A,getColWidth:k,getCell:D,getCellProps:ee,getRowProps:oe,contentProps:F,behaviorOptions:V,scrollBarOptions:U,overscanRows:m,overscanCols:y,background:M,onRenderTruncated:x,__maxRenderedCells:P,callbackThrottleMs:0,onScroll:j,onRangeChange:z,testId:$,children:ie})})},gm=i.memo(hm),En=6,Qe=3,Ur=(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:Qe});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-En,length:Qe}),r.push({kind:"unhide",index:s+1,start:c-Qe,length:Qe})):l>=2*En?n.push({kind:"resize",index:s,start:c-En,length:En}):n.push({kind:"resize",index:s,start:c-Qe,length:Qe})}return[...n,...r]},ba=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:Qe}),n.push({kind:"resize",index:c,start:h+Qe,length:Qe})):u>=2*En?n.push({kind:"resize",index:c,start:h,length:En}):n.push({kind:"resize",index:c,start:h,length:Qe})}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-Qe,length:Qe}),[...n.reverse(),...r]},mm=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:g,dividerLeadingRef:C,dividerTrailingRef:q})=>{const j=lr.useWheelBridge(o),z=i.useCallback(d=>(s.current=d,j(d)),[s,j]),I=i.useCallback(()=>{const{colStart:d,colEnd:A,colVersion:k}=e.get();return`${d}:${A}:${k}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,I,I);const{colStart:H,colEnd:$}=e.get(),T=t.count===0?0:t.offsetOf(Math.min(H,t.count-1));i.useLayoutEffect(()=>{c.current=T,u()},[T,c,u]);const P=d=>h.some(A=>d>=A.startCol&&d<=A.endCol),S=Math.min(Math.max(0,n),t.count),v=Uc(t,S),E=S>0?On(t,0,S-1):[],p=Math.min(Math.max(0,r),t.count-S),m=Gc(t,p),y=t.totalSize()-m,M=p>0?On(t,t.count-p,t.count-1):[],x=On(t,Math.max(H,S),Math.min($,Math.max(0,t.count-1)-p)),R=[];for(const d of x)R.push(K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d)-T,width:t.sizeOf(d)},children:tr(d)},d));const N=g?Ur(t,x):null,b=N===null?null:N.filter(d=>!(d.kind==="unhide"&&d.index<S&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=g&&S>0?Ur(t,E):null,f=g&&p>0?ba(t,M):null,O=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[R,b?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-T,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-T,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:S===0&&p===0?O:K.jsxs(K.Fragment,{children:[E.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:tr(d)},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:v,right:p>0?`calc(${ut}px + min(${m}px, max(0px, 100% - ${ut+v}px)))`:void 0},children:[O,S>0?K.jsx("div",{ref:C,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,p>0?K.jsx("div",{ref:q,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),p>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${v}px, calc(100% - ${m+ut}px))`,right:ut},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[M.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d)-y,width:t.sizeOf(d)},children:tr(d)},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},wm=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:g,dividerLeadingRef:C,dividerTrailingRef:q})=>{const j=lr.useWheelBridge(n),z=i.useCallback(d=>(r.current=d,j(d)),[r,j]),I=d=>o.some(A=>d>=A.startRow&&d<=A.endRow),Y=i.useCallback(()=>{const{rowStart:d,rowEnd:A,rowGeomVersion:k}=e.get();return`${d}:${A}:${k}`},[e]),H=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(H,Y,Y);const{rowStart:$,rowEnd:T}=e.get(),P=t.count===0?0:t.offsetOf(Math.min($,t.count-1));i.useLayoutEffect(()=>{l.current=P,c()},[P,l,c]);const S=Math.min(Math.max(0,h),t.count),v=Xc(t,S),E=S>0?On(t,0,S-1):[],p=Math.min(Math.max(0,g),t.count-S),m=Jc(t,p),y=t.totalSize()-m,M=p>0?On(t,t.count-p,t.count-1):[],x=On(t,Math.max($,S),Math.min(T,Math.max(0,t.count-1)-p)),R=[];for(const d of x)R.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d)-P,height:t.sizeOf(d)},children:d+1},d));const N=u?Ur(t,x):null,b=N===null?null:N.filter(d=>!(d.kind==="unhide"&&d.index<S&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=u&&S>0?Ur(t,E):null,f=u&&p>0?ba(t,M):null,O=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[R,b?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-P,height:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-P,height:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:ut},children:S===0&&p===0?O:K.jsxs(K.Fragment,{children:[E.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:v,bottom:p>0?`calc(min(${m}px, max(0px, 100% - ${v}px)))`:void 0},children:[O,S>0?K.jsx("div",{ref:C,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,p>0?K.jsx("div",{ref:q,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),p>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${v}px, calc(100% - ${m}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[M.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d)-y,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},Cm=9,ym=4,bm=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},yi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,vm=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),C=i.useCallback(S=>s.current!==null?S.pointerId===s.current:S.pointerType==="mouse",[]),q=i.useCallback(()=>{const S=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),S.writeResizeGuide(null);const v=g.current;v!==null&&(window.removeEventListener("pointermove",v.move),window.removeEventListener("pointerup",v.up),g.current=null);const E=c.current;E!==null&&s.current!==null&&E.hasPointerCapture?.(s.current)&&E.releasePointerCapture(s.current),c.current=null,s.current=null,S.repaintOverlay()},[]),j=i.useCallback((S,v)=>{const E=t.current;return S==="col"?v.startRow===0&&v.endRow===E.rowAxis.count-1:v.startCol===0&&v.endCol===E.colAxis.count-1},[]),z=i.useCallback((S,v)=>{const E=t.current,p=E.getSelection().ranges.filter(R=>j(S,R));if(!p.some(R=>S==="col"?v>=R.startCol&&v<=R.endCol:v>=R.startRow&&v<=R.endRow))return[v];const y=p.reduce((R,N)=>R+(S==="col"?N.endCol-N.startCol+1:N.endRow-N.startRow+1),0),M=S==="row"?Math.floor(E.maxOperationCells/ss):E.maxOperationCells;if(y>M)return E.onOperationRejected?.("resize",y,"limit"),null;const x=new Set;for(const R of p){const N=S==="col"?R.startCol:R.startRow,b=S==="col"?R.endCol:R.endRow;for(let a=N;a<=b;a+=1)x.add(a)}return[...x]},[j]),I=i.useCallback((S,v,E)=>{const p=t.current,m=S==="col"?p.colAxis:p.rowAxis,y=ls(m,v,E,{maxOperationCells:p.maxOperationCells,rowHiddenLimit:os,axisKind:S});if(!y.ok){p.onOperationRejected?.("resize",y.count,y.reason);return}p.resizeTracks(S,y.entries)},[]),Y=i.useCallback((S,v)=>{if(v===S.initialSize)return;const E=S.kind==="unhide"?[S.index]:z(S.axis,S.index);E!==null&&I(S.axis,E.map(p=>({index:p,size:v})),S.index)},[z,I]),H=i.useCallback((S,v)=>{const E=t.current,p=z("col",v);if(p===null)return;const m=E.handleRef.current,y=m===null?null:m.getFrozenSize(),M=y===null?0:y.rows,x=y===null?0:y.trailingRows,{rowStart:R,rowEnd:N}=E.viewStore.get(),b=Math.min(N,E.rowAxis.count-1),a=[],f=new Set,O=G=>{!f.has(G)&&E.rowAxis.sizeOf(G)>0&&(f.add(G),a.push(G))};for(let G=0;G<M;G+=1)O(G);for(let G=R;G<=b;G+=1)O(G);for(let G=E.rowAxis.count-x;G<E.rowAxis.count;G+=1)O(G);if(a.length===0)return;const d=p.length*a.length,A=Math.floor(E.maxOperationCells/ym);if(d>A){E.onOperationRejected?.("resize",d,"limit");return}const k=document.createElement("canvas").getContext("2d");if(k===null)return;const D=getComputedStyle(S),F=`${D.fontStyle} ${D.fontWeight} ${D.fontSize} ${D.fontFamily}`,V=E.adapter.getConditionalFormats===void 0?null:sm(E.adapter.getConditionalFormats()),U=Rs(),Q=new WeakMap,ee=new Map;for(const G of p){const ve=V===null?null:wa(V.filter(Fe=>Fe.ranges.some(Ae=>G>=Ae.startCol&&G<=Ae.endCol)));for(const Fe of a){const Ae=E.adapter.getCellText(Fe,G),Me=E.adapter.getCellFormat===void 0?void 0:ks(E.adapter,ve,U,Fe,G,()=>Ae),ze=Me===void 0?F:bm(Me,Q,D),Ye=Mn(Ae,Me===void 0?void 0:Me.value),ft=ee.get(ze);ft===void 0?ee.set(ze,[{col:G,text:Ye}]):ft.push({col:G,text:Ye})}}const oe=new Map;for(const[G,ve]of ee){k.font=G;for(const Fe of ve){const Ae=k.measureText(Fe.text).width,Me=oe.get(Fe.col);(Me===void 0||Ae>Me)&&oe.set(Fe.col,Ae)}}const ie=[];for(const G of p){const ve=oe.get(G);ve!==void 0&&ve>0&&ie.push({index:G,size:Math.ceil(ve)+Cm})}ie.length!==0&&I("col",ie,v)},[z,I]),{enabled:$,colBandRef:T,rowBandRef:P}=e;return i.useEffect(()=>{const S=T.current,v=P.current;if(!$||S===null||v===null)return;const E=A=>A==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",p=(A,k)=>{if(!(k instanceof Element))return null;const D=k.closest(E(A));if(D===null)return null;const F=D.hasAttribute("data-aqsp-unhide"),V=Number(D.getAttribute(F?"data-aqsp-unhide":A==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),U=D.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:F?"unhide":"resize",index:V,anchor:U}},m=A=>{if(!(n.current&&C(A)))return;const k=r.current;if(k===null)return;const D=(k.axis==="col"?A.clientX-k.startClientX:A.clientY-k.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(k.anchor==="trailing"?k.initialSize-D:k.initialSize+D)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const F=r.current;if(!n.current||F===null)return;const V=t.current,U=F.axis==="col"?V.colAxis:V.rowAxis;V.writeResizeGuide({axis:F.axis,position:yi(F,U,o.current),anchor:F.anchor})}))},y=()=>{const A=r.current,k=o.current;q(),A!==null&&Y(A,k)},M=A=>{m(A),n.current&&C(A)&&(l.current&1)!==0&&(A.buttons&1)===0&&y()},x=A=>{A.button!==0||!(n.current&&C(A))||y()},R=(A,k)=>D=>{const F=t.current;if(h.current=D.pointerType,D.pointerType!=="mouse")return;if(D.button!==0){D.preventDefault();return}const V=p(A,D.target);if(V===null)return;if(D.stopPropagation(),D.preventDefault(),F.isPointing()){F.focusSink();return}if(F.isEditing()&&!F.requestCommit()){F.focusSink();return}F.focusSink();const U=A==="col"?F.colAxis:F.rowAxis,Q={axis:A,kind:V.kind,index:V.index,anchor:V.anchor,initialSize:U.sizeOf(V.index),startClientX:D.clientX,startClientY:D.clientY};r.current=Q,o.current=Q.initialSize,l.current=D.buttons,n.current=!0,F.repaintOverlay(),s.current=D.pointerId,c.current=k;try{k.setPointerCapture(D.pointerId)}catch{s.current=null}const ee=M,oe=x;g.current={move:ee,up:oe},window.addEventListener("pointermove",ee),window.addEventListener("pointerup",oe),F.writeResizeGuide({axis:A,position:yi(Q,U,o.current),anchor:Q.anchor})},N=(A,k)=>D=>{const F=t.current;if(h.current!=="mouse")return;const V=k.getRootNode(),U=V instanceof ShadowRoot?V:k.ownerDocument,Q=D.target instanceof Element&&D.target.closest(E(A))!==null?D.target:typeof U.elementFromPoint=="function"?U.elementFromPoint(D.clientX,D.clientY):null,ee=p(A,Q);if(ee!==null){if(D.stopPropagation(),F.isEditing()){F.focusSink();return}if(ee.kind==="unhide"){I(A,[{index:ee.index,size:A==="col"?F.defaultColumnWidth:F.defaultRowHeight}],null);return}if(F.autofitEnabled){if(A==="row"){const oe=z("row",ee.index);oe!==null&&I("row",oe.map(ie=>({index:ie,size:F.defaultRowHeight})),ee.index);return}H(k,ee.index)}}},b=A=>{!n.current||s.current===null||A.pointerId!==s.current||q()},a=R("col",S),f=R("row",v),O=N("col",S),d=N("row",v);return S.addEventListener("pointerdown",a,{capture:!0}),v.addEventListener("pointerdown",f,{capture:!0}),S.addEventListener("dblclick",O),v.addEventListener("dblclick",d),S.addEventListener("lostpointercapture",b),v.addEventListener("lostpointercapture",b),()=>{S.removeEventListener("pointerdown",a,{capture:!0}),v.removeEventListener("pointerdown",f,{capture:!0}),S.removeEventListener("dblclick",O),v.removeEventListener("dblclick",d),S.removeEventListener("lostpointercapture",b),v.removeEventListener("lostpointercapture",b),q()}},[$,T,P,C,q,Y,I,z,H]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&q()},cancelDrag:q}),[q])},Ss=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Rm=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Ss(n,t.ranges[r]))&&At(e.anchor,t.anchor)&&At(e.active,t.active),km=(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=>Vt(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:he(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},Sm=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Ss(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},sr=(e,t,n)=>n.extend?sn(e,t):n.append?{ranges:[...e.ranges,he(t,t)],anchor:t,active:t}:e.ranges.length===1&&At(e.anchor,t)&&At(e.active,t)&&Ss(e.ranges[0],he(t,t))?e:{ranges:[he(t,t)],anchor:t,active:t},Em=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),sn=(e,t)=>{const n=Sm(e,he(e.anchor,t));return n.ranges.some(r=>an(r,n.active))?n:{...n,active:Em(n.active,n.ranges[n.ranges.length-1])}},va=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(he({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(he({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(he({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(he({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[he(n,n)],anchor:n,active:n};const s=o.findIndex(c=>an(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}},Am=(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}}},Ra=(e,t)=>{const n=e.ranges.findIndex(o=>an(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=Am(e.ranges,r.rangeIndex,r.cell,t),!At(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},kt=24,bi=32,Xr=4,yn=({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),C=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,g.current=null,h.current=null},[]),q=i.useCallback(()=>{const z=u.current,I=e.current,Y=g.current;if(z===null||I===null||Y===null){c.current=null;return}const{clientX:H,clientY:$}=z.getPointerPosition(),T=l.current,P=(H-Y.left)/T,S=($-Y.top)/T,v=I.getViewportSize(),E=v.width,p=v.height;if(E<=0||p<=0){c.current=requestAnimationFrame(q);return}const m=b=>Math.min(bi,Math.ceil(b/kt*bi));let y=0,M=0;if(s!=="x"){const b=I.getFrozenSize(),a=b.trailingVisibleHeight;S>p-a-kt?z.anchorRow!==void 0&&b.trailingRows>0&&z.anchorRow>=t.count-b.trailingRows&&a>0&&S>=p-a||(y=m(S-(p-a-kt))):S<b.height+kt&&(z.anchorRow!==void 0&&z.anchorRow<b.rows&&b.height>0&&S<b.height||(y=-m(b.height+kt-S)))}if(s!=="y"){const b=I.getFrozenSize(),a=b.trailingVisibleWidth;P>E-a-kt?z.anchorCol!==void 0&&b.trailingCols>0&&z.anchorCol>=n.count-b.trailingCols&&a>0&&P>=E-a||(M=m(P-(E-a-kt))):P<b.width+kt&&(z.anchorCol!==void 0&&z.anchorCol<b.cols&&b.width>0&&P<b.width||(M=-m(b.width+kt-P)))}const x=M!==0||y!==0?I.scrollBy({x:M!==0?M:void 0,y:y!==0?y:void 0}):I.getScrollPosition(),R=x.y,N=x.x;if(R>=0&&N>=0&&t.totalSize()>0&&n.totalSize()>0){const b=I.getFrozenSize(),a=Vt({row:fr(t,S,{scroll:R,frozenSize:b.height,trailingSize:b.trailingHeight,extent:v.height}),col:dr(n,P,{scroll:N,frozenSize:b.width,trailingSize:b.trailingWidth,extent:v.width})},t.count,n.count),f=h.current;(y!==0||M!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(z.buildRange(a)))}c.current=requestAnimationFrame(q)},[e,t,n,s,o]),j=i.useCallback(z=>{C(),u.current=z,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(q)},[C,q,r]);return i.useEffect(()=>{const z=()=>{document.visibilityState==="hidden"&&C()};return document.addEventListener("visibilitychange",z),()=>{document.removeEventListener("visibilitychange",z),C()}},[C]),i.useMemo(()=>({start:j,stop:C}),[j,C])},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),C=i.useRef(!1),q=i.useRef(0),j=i.useCallback((v,E)=>{const{axis:p,mainAxis:m,handleRef:y,zoomRef:M}=t.current,x=s.current;if(x===null||m.totalSize()===0)return null;const R=M.current,N=y.current;if(N===null)return null;if(p==="col"){const O=N.getScrollPosition().x;if(O<0)return null;const d=N.getFrozenSize(),A=N.getViewportSize();return Math.min(Math.max(dr(m,(v-x.left)/R,{scroll:O,frozenSize:d.width,trailingSize:d.trailingWidth,extent:A.width}),0),m.count-1)}const b=N.getScrollPosition().y;if(b<0)return null;const a=N.getFrozenSize(),f=N.getViewportSize();return Math.min(Math.max(fr(m,(E-x.top)/R,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),m.count-1)},[]),z=i.useCallback((v,E)=>{const{axis:p,crossCount:m}=t.current;return p==="col"?{press:{row:0,col:v},extend:{row:m-1,col:E}}:{press:{row:v,col:0},extend:{row:E,col:m-1}}},[]),I=i.useCallback((v,E)=>{const{axis:p,crossCount:m}=t.current;return v.ranges.some(y=>p==="col"?y.startRow===0&&y.endRow===m-1&&E>=y.startCol&&E<=y.endCol:y.startCol===0&&y.endCol===m-1&&E>=y.startRow&&E<=y.endRow)},[]),Y=i.useRef(!1),H=i.useRef({clientX:0,clientY:0}),$=i.useCallback(()=>{Y.current=!1;const{autoScroller:v,headerRef:E,onDragFrame:p}=t.current;n.current=!1,r.current=null,g.current=null,C.current=!1,q.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),v.stop();const m=E.current;m!==null&&u.current!==null&&m.hasPointerCapture?.(u.current)&&m.releasePointerCapture(u.current),u.current=null,p(null),t.current.repaintOverlay()},[]),T=i.useCallback(()=>{if(!n.current)return;const v=r.current;v!==null&&t.current.setSelection(v),$()},[$]),{enabled:P,headerRef:S}=e;return i.useEffect(()=>{const v=S.current;if(!P||v===null)return;const E=N=>{const b=t.current;if(N.pointerType!=="mouse")return;if(N.button!==0){N.preventDefault();return}if(C.current=!1,b.pointing?.getPointing()){s.current=v.getBoundingClientRect();const d=j(N.clientX,N.clientY);if(d===null)return;N.preventDefault(),b.focusSink(),b.pointing.insertReference(b.axis==="col"?{row:0,col:d}:{row:d,col:0},b.axis==="col"?"columns":"rows");return}if(b.isEditing()&&!b.requestCommit()){N.preventDefault(),b.focusSink();return}s.current=v.getBoundingClientRect();const a=j(N.clientX,N.clientY);if(a===null)return;N.preventDefault(),b.focusSink();const f=b.getSelection();r.current=f;const O=N.ctrlKey||N.metaKey;if(N.shiftKey){const d=b.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:A}=z(a,a),k={...f,anchor:d};b.setSelection(sn(k,A)),o.current=b.axis==="col"?d.col:d.row}else if(O&&I(f,a))C.current=!0,q.current=a,o.current=a;else{const{press:d,extend:A}=z(a,a),k=sr(f,d,{extend:!1,append:O});b.setSelection(sn(k,A)),o.current=a}n.current=!0,b.repaintOverlay(),l.current={clientX:N.clientX,clientY:N.clientY},u.current=N.pointerId,h.current=N.buttons;try{v.setPointerCapture(N.pointerId)}catch{u.current=null}g.current=d=>{const A=t.current.axis==="col"?d.col:d.row,{press:k}=z(o.current,o.current),{extend:D}=z(o.current,A);return he(k,D)},b.autoScroller.stop(),Y.current=!1,H.current={clientX:N.clientX,clientY:N.clientY}},p=N=>u.current!==null?N.pointerId===u.current:N.pointerType==="mouse",m=N=>{if(n.current&&p(N)){if(C.current){const b=N.clientX!==l.current.clientX||N.clientY!==l.current.clientY;if(l.current={clientX:N.clientX,clientY:N.clientY},!b)return;const a=j(N.clientX,N.clientY);if(a===null||a===q.current)return;C.current=!1;const f=t.current,{press:O,extend:d}=z(q.current,q.current),A=sr(f.getSelection(),O,{extend:!1,append:!0});f.setSelection(sn(A,d));const k=g.current,D=Math.abs(N.clientX-H.current.clientX),F=Math.abs(N.clientY-H.current.clientY);k!==null&&Math.max(D,F)>=Xr&&(Y.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:k,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:N.clientX,clientY:N.clientY},!Y.current&&g.current!==null){const b=Math.abs(N.clientX-H.current.clientX),a=Math.abs(N.clientY-H.current.clientY);Math.max(b,a)>=Xr&&(Y.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 b=g.current;if(!n.current||b===null)return;const a=j(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(b(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},y=N=>{m(N),n.current&&p(N)&&(h.current&1)!==0&&(N.buttons&1)===0&&x(N)},M=N=>{N.button!==0||!(n.current&&p(N))||x(N)},x=N=>{const b=t.current;if(C.current){const{press:f,extend:O}=z(q.current,q.current);b.setSelection(va(b.getSelection(),he(f,O),f)),$();return}const a=j(N.clientX,N.clientY);if(a!==null){const{extend:f}=z(o.current,a);b.setSelection(sn(b.getSelection(),f))}$()},R=N=>{!n.current||u.current===null||N.pointerId!==u.current||T()};return v.addEventListener("pointerdown",E),v.addEventListener("pointermove",y),v.addEventListener("pointerup",M),v.addEventListener("lostpointercapture",R),()=>{v.removeEventListener("pointerdown",E),v.removeEventListener("pointermove",y),v.removeEventListener("pointerup",M),v.removeEventListener("lostpointercapture",R),$()}},[P,S,j,z,$,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:T,cancelDrag:$}),[T,$])},xm=({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),C=g+t.sizeOf(r.row);g<h.height+l?o.scrollBy({y:g-(h.height+l)}):C>l+u-h.trailingVisibleHeight&&o.scrollBy({y:C-(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),C=g+n.sizeOf(r.col);g<h.width+s?o.scrollBy({x:g-(h.width+s)}):C>s+c-h.trailingVisibleWidth&&o.scrollBy({x:C-(s+c-h.trailingVisibleWidth)})}},Om=50,Tm=100,ka=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Om:!1,Yn={selectAll:on("Ctrl+A"),undo:on("Ctrl+Z"),redo:on("Ctrl+Y"),redoShiftZ:on("Ctrl+Shift+Z"),pasteValues:on("Ctrl+Shift+V")},Dm=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Mm={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},$m=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Fm=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,C=u.current;if(!l||g===null||C===null)return;const q=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},j=(a,f,O)=>jt(a,f,O)??f,z=(a,f)=>{const O=s.current;return f==="left"||f==="right"?{row:a.row,col:j(O.colAxis,a.col,f==="right"?1:-1)}:{row:j(O.rowAxis,a.row,f==="down"?1:-1),col:a.col}},I=a=>a.indexAt(0),Y=a=>a.indexAt(a.totalSize()-1),H=(a,f,O,d)=>{if(a.sizeOf(f)>0)return f;const A=jt(a,f,O);if(A!==null)return A;const k=jt(a,f,O===1?-1:1);return k!==null?k:d},$=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},T=a=>z($(),a),P=(a,f)=>{const O=s.current,d=f==="left"||f==="right",A=f==="right"||f==="down"?1:-1;let k;return O.findDataEdge!==void 0?(k=O.findDataEdge({row:a.row,col:a.col},f),S(k,a,f)):k={row:f==="down"?O.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?O.colAxis.count-1:f==="left"?0:a.col},d?{row:k.row,col:H(O.colAxis,k.col,A,a.col)}:{row:H(O.rowAxis,k.row,A,a.row),col:k.col}},S=(a,f,O)=>{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 A=O==="left"||O==="right";if(A?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${A?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},v=(a,f,O)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${O} component ${a} (count ${f})`)},E=a=>{const f=s.current,O=f.getSelection();if(Ra(O,a)===O){f.moveActive({mode:"reset",cell:z(O.active,a)});return}f.moveActive({mode:"cycle",direction:a})},p=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,O=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
21
+ ${a.value.slice(O)}`,a.setSelectionRange(f+1,f+1)},m=(a,f)=>{const O=s.current,d=h.current?.getViewportSize().height??-1;return d<=0?j(O.rowAxis,a,f==="down"?1:-1):O.rowAxis.indexAt(O.rowAxis.offsetOf(a)+(f==="down"?d:-d))},y=a=>{const f=s.current;if(r.current=!1,ka(a,t.current))return;const O=a.ctrlKey||a.metaKey,d=a.altKey,A=Mm[a.key];if(o.current&&!Dm.has(a.key)&&!f.isDragging()&&q(),f.isEditing()){const D=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!O&&!a.shiftKey&&!d&&f.abortDrag();return}const F=f.pointing;if(F!==void 0){if(A!==void 0&&!d){const U=F.getReferenceCursor();if(U!==null){a.preventDefault();const Q=Vt(U.cursor,f.rowAxis.count,f.colAxis.count),ee=Vt(U.origin,f.rowAxis.count,f.colAxis.count),oe=O?P(Q,A):z(Q,A);if(f.ensureCellVisible(oe),F.insertReference(a.shiftKey?he(ee,oe):oe,U.axis),f.onPointFrame!==void 0){const ie=a.shiftKey?he(ee,oe):he(oe,oe);f.onPointFrame(U.axis==="columns"?he({row:0,col:ie.startCol},{row:f.rowAxis.count-1,col:ie.endCol}):U.axis==="rows"?he({row:ie.startRow,col:0},{row:ie.endRow,col:f.colAxis.count-1}):ie),o.current=!0}return}}if(a.key==="F2"&&!O&&!a.shiftKey&&!d&&F.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!O&&!a.shiftKey&&!d&&F.cycleAnchorAtCaret()){a.preventDefault();return}}const V=f.commands;if(V!==void 0){const U=ql(V.table,a);if(U!==null&&vs.has(U)&&V.isAvailable(U)){a.preventDefault(),V.execute(U);return}}if(A!==void 0&&!d){if(O&&a.shiftKey){a.preventDefault();return}if(O)return;if(D==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:T(A)}):f.moveActive({mode:"reset",cell:z(f.getSelection().active,A)});return}return}if(a.key==="Enter"&&d&&!O&&!a.shiftKey){a.preventDefault(),p();return}if((a.key==="Enter"||a.key==="Tab")&&!O&&!d){if(a.preventDefault(),!f.requestCommit())return;const U=!a.shiftKey;E(a.key==="Tab"?U?"right":"left":U?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!O&&!d){if(a.preventDefault(),!f.requestCommit())return;const U=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(U.row,a.key==="PageDown"?"down":"up"),col:U.col}});return}if(a.key==="Escape"&&!O&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const k=f.commands;if(k!==void 0){const D=ql(k.table,a);if(D!==null&&k.isAvailable(D)){a.preventDefault(),k.execute(D);return}}if(A!==void 0&&!d){const D=A==="left"||A==="right",F=A==="right"||A==="down"?1:-1;if(O&&a.shiftKey){a.preventDefault();const V=f.getSelection(),U=$();let Q;if(f.findDataEdge!==void 0){const ee=D?{row:V.active.row,col:U.col}:{row:U.row,col:V.active.col},oe=f.findDataEdge(ee,A);Q=D?oe.col:oe.row,v(Q,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),Q=H(D?f.colAxis:f.rowAxis,Q,F,D?U.col:U.row)}else{const ee=D?f.colAxis:f.rowAxis;Q=F===1?Y(ee):I(ee)}f.moveActive({mode:"extend",cell:D?{row:U.row,col:Q}:{row:Q,col:U.col}});return}if(O){a.preventDefault(),f.moveActive({mode:"reset",cell:P(f.getSelection().active,A)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:T(A)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,A)});return}if($m(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!O&&!d){a.preventDefault();const D=!a.shiftKey;E(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const F=$();f.moveActive({mode:"extend",cell:{row:O?I(f.rowAxis):F.row,col:I(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:O?I(f.rowAxis):D.row,col:I(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const F=$();f.moveActive({mode:"extend",cell:{row:O?Y(f.rowAxis):F.row,col:Y(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:O?Y(f.rowAxis):D.row,col:Y(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!O&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const V=$();f.moveActive({mode:"extend",cell:{row:m(V.row,D),col:V.col}});return}const F=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(F.row,D),col:F.col}});return}if(a.key==="F2"&&!O&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!O&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection(),F=wt(D.ranges);if(F>f.maxOperationCells){f.onOperationRejected?.("delete",F,"limit");return}if(f.adapter!==void 0&&Sn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:F});return}const V=[],U=f.adapter!==void 0&&Hr(f.adapter).hyperlink;qt(D.ranges,Q=>{V.push(U?{row:Q.row,col:Q.col,text:"",hyperlink:null}:{row:Q.row,col:Q.col,text:""})}),f.commitEdits(V,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(O||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(Vn(Yn.selectAll,a)){a.preventDefault();const D=f.getSelection(),F=he({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[F],anchor:D.anchor,active:D.active});return}if(Vn(Yn.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(Vn(Yn.redo,a)||Vn(Yn.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!O&&!d||a.key==="ContextMenu"&&!O&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection().active;f.ensureCellVisible(D);const F=h.current,V=F===null?{x:0,y:0}:F.getScrollPosition(),U=Math.max(0,V.y),Q=Math.max(0,V.x),ee=F===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:F.getFrozenSize(),oe=F===null?{width:0,height:0}:F.getViewportSize(),ie=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:cn(f.rowAxis,D.row,{scroll:U,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:oe.height})*ie,left:ln(f.colAxis,D.col,{scroll:Q,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:oe.width})*ie,width:f.colAxis.sizeOf(D.col)*ie,height:f.rowAxis.sizeOf(D.row)*ie}});return}if(a.key===" "&&!d&&O!==a.shiftKey){a.preventDefault();const D=f.getSelection(),F=D.ranges.map(V=>O?he({row:0,col:V.startCol},{row:f.rowAxis.count-1,col:V.endCol}):he({row:V.startRow,col:0},{row:V.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:F,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&Vn(Yn.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}},M=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},x=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Tm)},R=()=>{const a=s.current;if(q(),!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()}},N=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},b=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),q()};return g.addEventListener("keydown",y),g.addEventListener("keyup",N),g.addEventListener("blur",b),g.addEventListener("compositionstart",M),g.addEventListener("compositionend",x),g.addEventListener("input",R),()=>{g.removeEventListener("keydown",y),g.removeEventListener("keyup",N),g.removeEventListener("blur",b),g.removeEventListener("compositionstart",M),g.removeEventListener("compositionend",x),g.removeEventListener("input",R),n.current!==null&&window.clearTimeout(n.current),q()}},[l,c,u,h])},zm=4,Nm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Lm=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),C=i.useRef(0),q=i.useRef(null),j=i.useRef(null),z=i.useRef(!1),I=i.useCallback(v=>g.current!==null?v.pointerId===g.current:v.pointerType==="mouse",[]),Y=i.useCallback((v,E)=>{const{handleRef:p,rowAxis:m,colAxis:y}=t.current,M=p.current,x=s.current;if(M===null||x===null)return null;const{x:R,y:N}=M.getScrollPosition();if(N<0||R<0||m.totalSize()===0||y.totalSize()===0)return null;const b=t.current.zoomRef.current,a=M.getFrozenSize(),f=M.getViewportSize();return Vt({row:fr(m,(E-x.top)/b,{scroll:N,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:dr(y,(v-x.left)/b,{scroll:R,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},m.count,y.count)},[]),H=i.useCallback(v=>{const E=r.current;if(E===null)return he(v,v);const p=he({row:Math.min(E.startRow,v.row),col:Math.min(E.startCol,v.col)},{row:Math.max(E.endRow,v.row),col:Math.max(E.endCol,v.col)}),m=p.startRow!==E.startRow||p.endRow!==E.endRow||p.startCol!==E.startCol||p.endCol!==E.endCol;return o.current=m?p:null,m?p:E},[]),$=i.useCallback(()=>{const v=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,q.current!==null&&(cancelAnimationFrame(q.current),q.current=null),v.xAutoScroller.stop(),v.yAutoScroller.stop(),z.current=!1,u.current=!1,h.current={dx:0,dy:0},v.writeFillPreview(null);const E=j.current;E!==null&&(window.removeEventListener("pointermove",E.move),window.removeEventListener("pointerup",E.up),j.current=null);const p=t.current.handleNodeRef.current;p!==null&&g.current!==null&&p.hasPointerCapture?.(g.current)&&p.releasePointerCapture(g.current),g.current=null,v.repaintOverlay()},[]),T=i.useCallback(()=>{const v=t.current,E=r.current,p=o.current;if($(),E===null||p===null)return;const m=Pp(E,p);if(m>v.maxOperationCells){v.onOperationRejected?.("fill",m,"limit");return}if(Sn(v.adapter,qp(E,p))){const x=(p.endRow-p.startRow+1)*(p.endCol-p.startCol+1),R=(E.endRow-E.startRow+1)*(E.endCol-E.startCol+1);v.rejectReadOnly({kind:"operation",op:"fill",cellCount:x-R});return}const y=_p((x,R)=>Mc(v.adapter,x,R),E,p,$c);if(v.commitEdits(y,{source:"fill"})===null)return;const M=v.getSelection();v.setSelection({ranges:[p],anchor:M.anchor,active:M.active})},[$]),{enabled:P,handleNodeRef:S}=e;return i.useEffect(()=>{const v=S.current;if(!P||v===null)return;const E=x=>{p(x),n.current&&I(x)&&(C.current&1)!==0&&(x.buttons&1)===0&&T()},p=x=>{if(!(n.current&&I(x)))return;l.current={clientX:x.clientX,clientY:x.clientY};const R=Math.abs(x.clientX-c.current.clientX),N=Math.abs(x.clientY-c.current.clientY);if(!u.current&&Math.max(R,N)>=zm&&(u.current=!0),!!u.current){if(!z.current){const b=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:H,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};b.xAutoScroller.start(a),b.yAutoScroller.start(a),z.current=!0}q.current===null&&(q.current=requestAnimationFrame(()=>{if(q.current=null,!(n.current&&u.current))return;const b=Y(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);b!==null&&t.current.writeFillPreview(H(b))}))}},m=x=>{x.button!==0||!(n.current&&I(x))||T()},y=x=>{const R=t.current;if(x.pointerType!=="mouse")return;if(x.button!==0){x.preventDefault();return}x.preventDefault(),x.stopPropagation(),R.focusSink();const N=R.getSelection(),b=N.ranges[N.ranges.length-1];r.current=b,o.current=null,u.current=!1,R.xAutoScroller.stop(),R.yAutoScroller.stop(),z.current=!1,c.current={clientX:x.clientX,clientY:x.clientY},l.current=c.current,C.current=x.buttons,n.current=!0,R.repaintOverlay(),s.current=R.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=R.handleRef.current?.getScrollPosition()??{x:-1,y:-1},O=f.y;if(a!==null&&O>=0&&f.x>=0){const k=f.x,D=R.zoomRef.current,F=R.handleRef.current?.getFrozenSize()??Nm,V=R.handleRef.current?.getViewportSize()??{width:0,height:0},U={scroll:k,frozenCount:F.cols,trailingCount:F.trailingCols,extent:V.width},Q={scroll:O,frozenCount:F.rows,trailingCount:F.trailingRows,extent:V.height},ee=ln(R.colAxis,b.endCol,U)+R.colAxis.sizeOf(b.endCol),oe=cn(R.rowAxis,b.endRow,Q)+R.rowAxis.sizeOf(b.endRow),ie=ee-1,G=b.endCol>=F.cols&&F.width>0?Math.max(ie,F.width):ie,Fe=!(b.endCol>=R.colAxis.count-F.trailingCols)&&F.trailingWidth>0?Math.min(G,V.width-F.trailingVisibleWidth-1):G,Ae=oe-1,Me=b.endRow>=F.rows&&F.height>0?Math.max(Ae,F.height):Ae,Ye=!(b.endRow>=R.rowAxis.count-F.trailingRows)&&F.trailingHeight>0?Math.min(Me,V.height-F.trailingVisibleHeight-1):Me;h.current={dx:x.clientX-(a.left+Fe*D),dy:x.clientY-(a.top+Ye*D)}}else h.current={dx:0,dy:0};g.current=x.pointerId;try{v.setPointerCapture(x.pointerId)}catch{g.current=null}const d=E,A=m;j.current={move:d,up:A},window.addEventListener("pointermove",d),window.addEventListener("pointerup",A),R.writeFillPreview(r.current)},M=x=>{!n.current||g.current===null||x.pointerId!==g.current||$()};return v.addEventListener("pointerdown",y),v.addEventListener("lostpointercapture",M),()=>{v.removeEventListener("pointerdown",y),v.removeEventListener("lostpointercapture",M),$()}},[P,S,I,Y,H,$,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&$()},cancelDrag:$}),[$])},Pm=320,Br=8,qm=64,_m=150,Sa=e=>Math.max(0,Math.min(Pm,e.width-ut-Br)),Im=(e,t,n)=>{const r=n.width-ut,o=n.height-ut,s=Sa(n),l=Math.max(0,Math.min(t,o-Br)),c=e.left+e.width,u=e.top+e.height,h=I=>I>=0&&I+s<=r,g=[e.left,c-s],C=[{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 I of C)if(h(I.left)&&I.top>=0&&I.top+l<=o)return{left:I.left,top:I.top,width:s,height:l};const q=o-u,j=e.top,z=Math.min(l,Math.max(q,j));if(z>=qm){const I=q>=j?u:e.top-z;for(const Y of g)if(h(Y))return{left:Y,top:I,width:s,height:z}}return{left:Br,top:Br,width:s,height:l}},jm=(e,t,n,r)=>t===null||e!==null&&At(e,t)||n?!1:r(t),Hm=(e,t)=>{switch(e.kind){case"note":return K.jsx(oa,{ctx:e,labels:t});case"note-tip":return K.jsx(sa,{ctx:e,labels:t});case"comment":return K.jsx(ea,{ctx:e,labels:t});case"link":return K.jsx(ta,{ctx:e,labels:t});case"list":return K.jsx(na,{ctx:e,labels:t});default:return K.jsx(ra,{ctx:e,labels:t})}},_o=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Bm=({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 C=_o(s),q=_o(l),j=i.useRef(null),z=(T,P)=>{const S=g.current.getLayerSize();T.style.width=`${Sa(S)}px`,T.style.maxHeight="";const v=Im(P,T.offsetHeight,S);T.style.left=`${v.left-P.left}px`,T.style.top=`${v.top-P.top}px`,T.style.maxHeight=`${v.height}px`};i.useLayoutEffect(()=>{const T=c.current;if(T===null||s===null){j.current=null;return}if(z(T,s.anchorRect),s.kind==="message")return;const P=_o(s);if(j.current===P)return;j.current=P;const S=T.querySelector("[data-aqsp-popover-autofocus]");S!==null?S.focus({preventScroll:!0}):T.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const T=u.current,P=h.current;T===null||P===null||z(T,P.anchorRect)},[q]);const I=T=>t===void 0?Hm(T,n):t(T),Y=T=>{e.isCompositionKey(T.nativeEvent)&&T.stopPropagation()},H=T=>{T.key==="Escape"&&!T.defaultPrevented&&(T.preventDefault(),e.close())},$=T=>{e.registerCompositionEnd(T.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:Y,onKeyDown:H,onCompositionEnd:$,children:[K.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:I(s)},C)}),K.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:I(l)})})]})},Vm=["note","note-tip","comment","link","list","message"],Wm=(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}},Un=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Wm(e,n),Km=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),C=i.useRef(null),q=i.useRef(null),j=i.useRef(null),z=i.useId(),I=i.useCallback(k=>{const D=t.current,F=D.handleRef.current,V=F===null?{x:0,y:0}:F.getScrollPosition(),U=F===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:F.getFrozenSize(),Q=F===null?{width:0,height:0}:F.getViewportSize();return{top:cn(D.rowAxis,k.row,{scroll:Math.max(0,V.y),frozenCount:U.rows,trailingCount:U.trailingRows,extent:Q.height}),left:ln(D.colAxis,k.col,{scroll:Math.max(0,V.x),frozenCount:U.cols,trailingCount:U.trailingCols,extent:Q.width}),width:D.colAxis.sizeOf(k.col),height:D.rowAxis.sizeOf(k.row)}},[]),Y=i.useCallback(k=>{const D=t.current;D.anchors.current={...D.anchors.current,...k},D.repaintOverlay()},[]),H=i.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),$=i.useCallback(()=>{const k=t.current.sinkRef.current;if(k===null)return;const D=c.current;D!==null&&At(D,t.current.getActive())?k.setAttribute("aria-describedby",z):k.getAttribute("aria-describedby")===z&&k.removeAttribute("aria-describedby")},[z]),T=i.useCallback(()=>(H(),h.current=!1,c.current===null?!1:(c.current=null,s(null),Y({tip:null}),$(),!0)),[H,Y,$]),P=i.useCallback(()=>{H(),g.current=window.setTimeout(()=>{g.current=null,T()},_m)},[H,T]),S=i.useCallback(k=>{const D=t.current;H();const F=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(k.row,k.col);F===void 0||F===""||(c.current=k,s({kind:"note-tip",cell:k,anchorRect:I(k),current:F,close:T}),Y({tip:k}),$())},[I,H,T,Y,$]),v=i.useCallback(k=>{const D=t.current;if(k===null&&h.current)return;const F=u.current;u.current=k;const V=c.current;if(V!==null&&k!==null&&At(V,k)){H();return}const U=Q=>{const ee=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(Q.row,Q.col);return ee!==void 0&&ee!==""};if(jm(F,k,D.isDraggingAny(),U)){k!==null&&S(k);return}V!==null&&P()},[S,H,P]),E=i.useCallback((k,D)=>{const F=t.current,V=F.bodyRef.current,U=F.handleRef.current;if(V===null||U===null)return null;const Q=V.getBoundingClientRect(),ee=F.zoomRef.current,oe=U.getScrollPosition(),ie=U.getFrozenSize(),G=U.getViewportSize();return Vt({row:fr(F.rowAxis,(D-Q.top)/ee,{scroll:Math.max(0,oe.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:G.height}),col:dr(F.colAxis,(k-Q.left)/ee,{scroll:Math.max(0,oe.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:G.width})},F.rowAxis.count,F.colAxis.count)},[]),p=i.useCallback(k=>{q.current=k,C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null;const D=q.current;v(D===null?null:"cell"in D?D.cell:E(D.clientX,D.clientY))}))},[v,E]),m=i.useCallback(k=>p({cell:k}),[p]),y=i.useCallback(()=>T(),[T]),M=i.useCallback(k=>{if(l.current===null)return;const D=t.current;l.current=null,r(null),Y({interactive:null}),(k===void 0||k.restoreFocus)&&D.focusSink({preventScroll:!0}),D.isEditing()||D.rearmSink()},[Y]),x=i.useCallback(k=>{l.current=k.kind,r(k),Y({interactive:k.cell})},[Y]),R=i.useCallback(k=>{const D=t.current;return Oc(D.adapter)?{cellReadOnly:Be(D.adapter,k.row,k.col)}:{}},[]),N=i.useCallback((k,D)=>{const F=t.current;if(Be(F.adapter,k.cell.row,k.cell.col)){F.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),x({...k,...R(k.cell)});return}if(F.commitEdits(D,{source:"annotate"})===null){x({...k,rejected:!0});return}M()},[x,M,R]),b=i.useCallback((k,D)=>{const F=t.current;if(!Un(F.adapter,F.popovers,k))throw new RangeError(`[spreadsheet] openPopover("${k}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const V=F.getActive();if(k==="list"&&Be(F.adapter,V.row,V.col)){F.rejectReadOnly({kind:"edit",cell:V,editSession:"none"});return}if(k==="note-tip"){S(V);return}if(k==="message"){if(l.current!==null&&l.current!=="message")return;const oe=D!==void 0&&D.message!==void 0?D.message:void 0,ie=F.adapter.getCellValidation===void 0?void 0:F.adapter.getCellValidation(V.row,V.col),G=oe!==void 0?oe:ie===void 0?void 0:ie.inputMessage;if(G===void 0)return;const ve=D!==void 0&&D.rejected===!0;x({kind:"message",cell:V,anchorRect:I(V),current:{title:$e(F.labels,"messageTitle"),message:G,rejected:ve},close:M});return}if(F.isEditing()&&!F.requestCommit())return;if(k==="list"){const oe=F.adapter.getCellValidation===void 0?void 0:F.adapter.getCellValidation(V.row,V.col);if(oe===void 0||oe.type!=="list")return;const ie=D!==void 0&&D.typed!==void 0?D.typed:"";T(),F.focusSink({preventScroll:!0}),x({kind:"list",cell:V,anchorRect:I(V),current:oe.values,typed:ie,commit:G=>{if(Be(t.current.adapter,V.row,V.col)){t.current.rejectReadOnly({kind:"edit",cell:V,editSession:"none"}),M();return}t.current.commitEdits([{row:V.row,col:V.col,text:G}],{source:"edit",editSession:"discarded"}),M()},close:M});return}if(T(),F.focusSink({preventScroll:!0}),k==="note"){const oe=F.adapter.getCellNote===void 0?void 0:F.adapter.getCellNote(V.row,V.col),ie={kind:"note",cell:V,anchorRect:I(V),current:oe,commit:G=>{N(ie,[{row:V.row,col:V.col,note:G}])},close:M,rejected:!1,...R(V)};x(ie);return}if(k==="comment"){const oe=F.adapter.getCellComments===void 0?void 0:F.adapter.getCellComments(V.row,V.col),ie={kind:"comment",cell:V,anchorRect:I(V),current:oe===void 0?[]:oe,commit:G=>{N(ie,[{row:V.row,col:V.col,comments:G}])},close:M,rejected:!1,...R(V)};x(ie);return}const U=F.adapter.getCellHyperlink===void 0?void 0:zn(F.adapter.getCellHyperlink(V.row,V.col)),Q=F.adapter.getCellText(V.row,V.col),ee={kind:"link",cell:V,anchorRect:I(V),current:{text:Q,url:U},commit:oe=>{const ie=oe.url===null?null:Bt(oe.url);if(ie===null&&oe.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(oe.url)}`);const G=oe.text===Q?{row:V.row,col:V.col,hyperlink:ie}:{row:V.row,col:V.col,text:oe.text,hyperlink:ie};N(ee,[G])},close:M,canOpen:F.onHyperlinkOpen!==void 0,open:()=>{const oe=t.current.onHyperlinkOpen;oe!==void 0&&U!==void 0&&oe(U,V)},rejected:!1,...R(V)};x(ee)},[I,M,N,T,x,S,R]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const k=f.current;if(!a||k===null)return;const D=V=>{const U=t.current;Un(U.adapter,U.popovers,"note-tip")&&p({clientX:V.clientX,clientY:V.clientY})},F=()=>{Un(t.current.adapter,t.current.popovers,"note-tip")&&p({cell:null})};return k.addEventListener("pointermove",D),k.addEventListener("pointerleave",F),()=>{k.removeEventListener("pointermove",D),k.removeEventListener("pointerleave",F)}},[a,f,p]),i.useEffect(()=>()=>{C.current!==null&&cancelAnimationFrame(C.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:O,popovers:d}=e,A=i.useMemo(()=>Vm.some(k=>Un(O,d,k)),[O,d]);return i.useMemo(()=>({layerEnabled:A,isKindEnabled:k=>Un(t.current.adapter,t.current.popovers,k),open:b,close:M,isOpen:()=>l.current,onCellHover:m,hideTip:y,onTipPointerEnter:()=>{h.current=!0,H()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&P()},syncTipAriaDescribedBy:$,context:n,tipContext:o,registerCompositionEnd:k=>{j.current=k},isCompositionKey:k=>ka(k,j.current),getLayerSize:()=>{const k=t.current.handleRef.current;return k===null?{width:0,height:0}:k.getViewportSize()},tipId:z}),[A,b,M,m,y,H,P,$,n,o,z])},Ym=(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},Ea=(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 Vt({row:fr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:g.height}),col:dr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:g.width})},n.count,r.count)},Um=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),C=i.useRef(null),q=i.useRef(""),j=i.useRef(!1),z=i.useRef(!1),I=i.useCallback((p,m)=>{const{handleRef:y,rowAxis:M,colAxis:x,zoomRef:R}=t.current;return Ea(y.current,o.current,M,x,R.current,p,m)},[]),Y=i.useRef(!1),H=i.useRef(null),$=i.useRef(null),T=i.useRef({clientX:0,clientY:0}),P=i.useCallback(()=>{const{autoScroller:p,bodyRef:m,onDragFrame:y}=t.current;n.current=!1,r.current=null,h.current=null,Y.current=!1,H.current=null,$.current=null,g.current=!1,C.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.stop();const M=m.current;M!==null&&c.current!==null&&M.hasPointerCapture?.(c.current)&&M.releasePointerCapture(c.current),c.current=null,y(null),t.current.repaintOverlay()},[]),S=i.useCallback(()=>{if(!n.current)return;const p=r.current;p!==null&&t.current.setSelection(p),P()},[P]),{enabled:v,bodyRef:E}=e;return i.useEffect(()=>{const p=E.current;if(!v||p===null)return;const m=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,y=d=>{const A=t.current;if(d.pointerType==="mouse"&&d.button===0&&(g.current=!1,C.current=null,z.current=!1),j.current=m(d.target),!j.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(A.getPointing?.()){A.focusSink();return}if(A.isEditing()&&!A.requestCommit()){d.stopPropagation(),A.focusSink();return}A.focusSink()}return}if(q.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((A.pointDragRef===void 0?null:A.pointDragRef.current)?.onPointerDown(d))return;if(A.isEditing()&&!A.requestCommit()){d.preventDefault(),A.focusSink();return}o.current=p.getBoundingClientRect();const D=I(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),A.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&A.openHyperlinkAt?.(D)===!0){z.current=!0;return}const F=A.getSelection();r.current=F;const V=d.shiftKey,U=d.ctrlKey||d.metaKey,Q=U&&!V&&F.ranges.some(oe=>an(oe,D));g.current=Q,C.current=Q?D:null,Q||A.setSelection(sr(F,D,{extend:V,append:U})),n.current=!0,A.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{p.setPointerCapture(d.pointerId)}catch{c.current=null}const ee=Q?D:A.getSelection().anchor;h.current=oe=>he(ee,oe),H.current=ee.col,$.current=ee.row,A.autoScroller.stop(),Y.current=!1,T.current={clientX:d.clientX,clientY:d.clientY}},M=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",x=d=>{if(n.current&&M(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!Y.current&&h.current!==null){const A=Math.abs(d.clientX-T.current.clientX),k=Math.abs(d.clientY-T.current.clientY);Math.max(A,k)>=Xr&&(Y.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:H.current??void 0,anchorRow:$.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const A=h.current;if(!n.current||A===null)return;const k=t.current,D=I(s.current.clientX,s.current.clientY);D!==null&&k.onDragFrame(A(D))}))}},R=d=>{x(d),n.current&&M(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&b(d)},N=d=>{d.button!==0||!(n.current&&M(d))||b(d)},b=d=>{const A=t.current,k=I(d.clientX,d.clientY);if(k!==null){const D=C.current;g.current&&D!==null?A.setSelection(va(A.getSelection(),he(D,k),D)):A.setSelection(sn(A.getSelection(),k))}P()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||S()},f=d=>{const A=t.current;if(!m(d.target)||q.current!=="mouse"||A.isAnyDragging())return;if(A.isEditing()&&!A.requestCommit()){A.focusSink();return}A.focusSink(),o.current=p.getBoundingClientRect();const k=I(d.clientX,d.clientY);if(k===null)return;const D=A.getSelection();D.ranges.some(V=>an(V,k))||A.setSelection(sr(D,k,{extend:!1,append:!1})),A.onContextMenuSelect(k,d)},O=d=>{const A=t.current;if(!j.current||q.current!=="mouse"||A.getPointing?.()||z.current)return;o.current=p.getBoundingClientRect();const k=I(d.clientX,d.clientY);k!==null&&At(A.getSelection().active,k)&&A.onRequestEdit(k,A.caretFromPointEnabled(k)?Ym(d.clientX,d.clientY,k):void 0)};return p.addEventListener("pointerdown",y),p.addEventListener("pointermove",R),p.addEventListener("pointerup",N),p.addEventListener("lostpointercapture",a),p.addEventListener("contextmenu",f),p.addEventListener("dblclick",O),()=>{p.removeEventListener("pointerdown",y),p.removeEventListener("pointermove",R),p.removeEventListener("pointerup",N),p.removeEventListener("lostpointercapture",a),p.removeEventListener("contextmenu",f),p.removeEventListener("dblclick",O),P()}},[v,E,I,P,S]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:S,cancelDrag:P}),[S,P])},Xm=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),C=i.useRef(null),q=i.useRef(!1),j=i.useCallback((T,P)=>{const{handleRef:S,rowAxis:v,colAxis:E,zoomRef:p}=t.current;return Ea(S.current,o.current,v,E,p.current,T,P)},[]),z=i.useCallback(()=>{const{autoScroller:T,bodyRef:P,onDragFrame:S}=t.current;n.current=!1,r.current=null,g.current=null,C.current=null,q.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const v=P.current;v!==null&&u.current!==null&&v.hasPointerCapture?.(u.current)&&v.releasePointerCapture(u.current),u.current=null,S(null)},[]),I=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.restoreSink(T),z()},[z]),Y=i.useCallback(T=>{const P=t.current,S=P.bodyRef.current;if(!P.enabled||S===null||!P.getPointing())return!1;o.current=S.getBoundingClientRect();const v=j(T.clientX,T.clientY);if(v===null)return o.current=null,!1;const E=P.captureSink();if(E===null)return o.current=null,!1;T.preventDefault(),P.focusSink(),r.current=E,C.current=v,P.insertReference(v,"cells"),n.current=!0,s.current={clientX:T.clientX,clientY:T.clientY},l.current={clientX:T.clientX,clientY:T.clientY},u.current=T.pointerId,h.current=T.buttons;try{S.setPointerCapture(T.pointerId)}catch{u.current=null}return g.current=p=>{const m=he(v,p);return t.current.insertReference(m,"cells"),m},P.autoScroller.stop(),q.current=!1,P.onDragFrame(he(v,v)),!0},[j]),{enabled:H,bodyRef:$}=e;return i.useEffect(()=>{const T=$.current;if(!H||T===null)return;const P=p=>u.current!==null?p.pointerId===u.current:p.pointerType==="mouse",S=p=>{if(!(n.current&&P(p)))return;s.current={clientX:p.clientX,clientY:p.clientY};const m=g.current,y=C.current;if(!q.current&&m!==null&&y!==null){const M=Math.abs(p.clientX-l.current.clientX),x=Math.abs(p.clientY-l.current.clientY);Math.max(M,x)>=Xr&&(q.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m,anchorCol:y.col,anchorRow:y.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const M=g.current;if(!n.current||M===null)return;const x=j(s.current.clientX,s.current.clientY);x!==null&&t.current.onDragFrame(M(x))})),(h.current&1)!==0&&(p.buttons&1)===0&&z()},v=p=>{p.button!==0||!(n.current&&P(p))||z()},E=p=>{!n.current||u.current===null||p.pointerId!==u.current||z()};return T.addEventListener("pointermove",S),T.addEventListener("pointerup",v),T.addEventListener("lostpointercapture",E),()=>{T.removeEventListener("pointermove",S),T.removeEventListener("pointerup",v),T.removeEventListener("lostpointercapture",E),z()}},[H,$,j,z]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:I,cancelDrag:z,onPointerDown:Y}),[I,z,Y])},Gm=.25,Jm=4,Io=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(Jm,Math.max(Gm,e))},jo=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,Ri=(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},Zm=24,Qm=100,e0=1e5,t0=200,Aa=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),ki=5,n0=/^#[0-9A-Fa-f]{6}$/,r0=Object.freeze({row:!1,column:!1,intersection:!1}),Si=Object.freeze({ok:!0}),Ei=(e,t)=>{if(t===void 0)return Aa;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"||!n0.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},o0=e=>{for(const t of["row","column","intersection"])if(Ke(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},s0=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Zc},l0=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},bn={ranges:[he({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},i0=i.forwardRef(function({adapter:t,defaultRowHeight:n=Zm,defaultColumnWidth:r=Qm,frozenColumns:o=0,frozenRows:s=0,frozenTrailingColumns:l=0,frozenTrailingRows:c=0,tapScrollCircleOptions:u,overscanRows:h,overscanCols:g,background:C,onRenderTruncated:q,renderCell:j,onSelectionChange:z,onCellContextMenu:I,onUndoRequest:Y,onRedoRequest:H,onCopyMultiRange:$,onOperationRejected:T,onEditRejected:P,onReadOnlyRejected:S,formatReadOnlyAnnouncement:v,dataVersion:E,maxOperationCells:p=e0,enableFillHandle:m=!0,enableResizeUI:y=!0,formatCellAnnouncement:M,formatSelectionAnnouncement:x,formatCommandAnnouncement:R,labels:N,shortcuts:b,colors:a,formats:f,highlight:O,defaultHighlight:d,onHighlightChange:A,highlightColors:k,popovers:D,renderPopover:F,onClipChange:V,onHyperlinkOpen:U,onValidationRejected:Q,onPasteSpecialRequest:ee,onClipboardUnavailable:oe,onPasteResolved:ie,now:G=Date.now,zoom:ve,defaultZoom:Fe,onZoomChange:Ae,testId:Me,className:ze,__onCellRender:Ye,__onVirtualKeyboardRaise:ft,__maxRenderedCells:pr},hr){const ge=fi(t.rowCount,n),fe=fi(t.colCount,r),Ge=i.useRef(null);Ge.current===null&&(Ge.current=Lh());const Se=Ge.current,Ct=i.useMemo(()=>Nh(N),[N]),Wt=i.useMemo(()=>nh(b),[b]),un=i.useMemo(()=>({fill:Ei("fill",a===void 0?void 0:a.fill),font:Ei("font",a===void 0?void 0:a.font)}),[a]),gr=i.useMemo(()=>k===void 0?void 0:o0(k),[k]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Kt=i.useCallback(()=>Se.get().editVersion,[Se]),Ot=i.useCallback(w=>Se.subscribeCoalesced(w),[Se]),dn=i.useSyncExternalStore(Ot,Kt,Kt)+(E===void 0?0:E),Tt=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),Dt=i.useMemo(()=>({index:Tt===null?null:wa(Tt),memo:Rs()}),[t,Tt,dn]),fn=i.useRef(Dt.index);fn.current=Dt.index;const Yt=i.useRef(Dt.memo);Yt.current=Dt.memo;const Mt=i.useCallback((w,W,te)=>ks(t,fn.current,Yt.current,w,W,te),[t]),Ue=i.useRef(null),[no,ro]=i.useState(()=>Io(Fe??1)),nt=Io(ve??no),Oe=i.useRef(nt);Oe.current=nt;const $t=i.useRef(nt);$t.current=nt;const Ln=i.useRef(null),L=i.useRef(Ae);L.current=Ae;const B=i.useRef(ve!==void 0);B.current=ve!==void 0;const X=i.useCallback(w=>{const W=Io(w);W!==$t.current&&($t.current=W,B.current||ro(W),L.current?.(W))},[]),_=t.rowCount===0||t.colCount===0,J=!_;i.useEffect(()=>{const w=Ue.current;if(!J||w===null)return;const W=re=>{re.defaultPrevented||!re.altKey||re.ctrlKey||re.metaKey||re.shiftKey||re.deltaY!==0&&(re.preventDefault(),re.stopPropagation(),!Ln.current?.()&&X(jo($t.current,re.deltaY<0?1:-1)))},te=re=>{if(re.defaultPrevented||!(re.ctrlKey&&re.altKey)||re.metaKey||re.getModifierState("AltGraph"))return;const Re=re.key==="="||re.key==="+"?jo($t.current,1):re.key==="-"?jo($t.current,-1):re.key==="0"?1:null;Re!==null&&(re.preventDefault(),re.stopPropagation(),!Ln.current?.()&&X(Re))};return w.addEventListener("wheel",W,{passive:!1,capture:!0}),w.addEventListener("keydown",te,!0),()=>{w.removeEventListener("wheel",W,{capture:!0}),w.removeEventListener("keydown",te,!0)}},[X,J]);const ne=i.useRef(null),Z=i.useRef(null),we=i.useRef(null),me=i.useRef(null),_e=i.useRef(0),Ie=i.useRef(null),je=i.useRef(0),Le=i.useRef(null),se=i.useRef(null),ae=i.useRef(null),ue=i.useRef(null),de=i.useRef(null),ce=i.useRef(null),Ce=i.useRef(null),[be,Te]=i.useState(bn),Pe=i.useRef(be),qe=i.useCallback(()=>Pe.current,[]),[yt,Ut]=i.useState(()=>d===void 0?r0:d),Je=O!==void 0?O:yt,Xt=i.useRef(Je);Xt.current=Je;const Gt=s0(gr,Je),mr=i.useRef(O!==void 0);mr.current=O!==void 0;const wr=i.useRef(A);wr.current=A;const xa=i.useCallback(w=>{mr.current||Ut(w),wr.current?.(w)},[]),Es=i.useRef(null),oo=i.useRef(null),bt=i.useRef(null),so=i.useRef(()=>!1),As=i.useRef(()=>{}),xs=i.useRef(()=>null),Os=i.useRef(()=>{}),Jt=i.useCallback(()=>so.current(),[]),lo=i.useMemo(()=>({getPointing:()=>so.current(),insertReference:(w,W)=>As.current(w,W)}),[]),Ts=i.useRef(St),Ds=i.useRef(null),io=i.useRef({interactive:null,tip:null}),Ms=i.useRef(null),$s=i.useRef(null),Cr=i.useRef(()=>{}),Fs=i.useRef(()=>!1),Ft=i.useRef(null),Pn=i.useCallback(()=>{const w=Ft.current;if(w===null||w.isOpen()!=="message")return!1;const W=w.context;return W===null||W.kind!=="message"||!W.current.rejected?!1:(w.close(),!0)},[]),co=i.useRef(()=>!1),zs=i.useRef(()=>!1),Ns=i.useRef(null),ao=i.useRef(()=>Promise.resolve("rejected")),xe=i.useCallback(()=>{Es.current?.()},[]),De=i.useCallback(w=>{we.current?.focus(w)},[]),uo=i.useRef(!1),Oa=i.useCallback(()=>{const w=Ue.current;if(w!==null){uo.current=!0;try{w.focus()}finally{uo.current=!1}}},[]),Xe=i.useCallback(()=>{const w=we.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),pn=i.useCallback((w,W)=>{if(w===null)return;const te=W?"":"none";w.style.display!==te&&(w.style.display=te)},[]),rt=i.useCallback(()=>{const w=me.current;if(w!==null){const te=Math.max(0,Z.current?.getScrollPosition().y??0),re=Z.current?.getFrozenSize().height??0;w.style.transform=`translateY(${_e.current-te-re}px)`}const W=Z.current;if(W!==null&&(de.current!==null||ce.current!==null)){const te=W.getFrozenSize();pn(de.current,te.height>0),pn(ce.current,te.trailingHeight>0)}},[pn]),ot=i.useCallback(()=>{const w=Ie.current;if(w!==null){const te=Math.max(0,Z.current?.getScrollPosition().x??0),re=Z.current?.getFrozenSize().width??0;w.style.transform=`translateX(${je.current-te-re}px)`}const W=Z.current;if(W!==null&&(ae.current!==null||ue.current!==null)){const te=W.getFrozenSize();pn(ae.current,te.width>0),pn(ue.current,te.trailingWidth>0)}},[pn]),qn=i.useRef(null),hn=i.useCallback(()=>{ae.current===null&&ue.current===null&&de.current===null&&ce.current===null||qn.current===null&&(qn.current=requestAnimationFrame(()=>{qn.current=null,rt(),ot(),xe()}))},[rt,ot,xe]);i.useEffect(()=>()=>{qn.current!==null&&cancelAnimationFrame(qn.current)},[]);const fo=i.useRef(null),po=i.useRef(null);(fo.current===null||po.current?.rowAxis!==ge||po.current?.colAxis!==fe)&&(po.current={rowAxis:ge,colAxis:fe},fo.current=xm({handleRef:Z,rowAxis:ge,colAxis:fe}));const zt=i.useCallback(w=>{fo.current?.(w)},[]),gn=i.useRef(null),Zt=i.useRef(null),mn=i.useCallback(w=>{gn.current!==null&&window.clearTimeout(gn.current),Zt.current!==null&&(cancelAnimationFrame(Zt.current),Zt.current=null),gn.current=window.setTimeout(()=>{gn.current=null;const W=Ce.current;W!==null&&(W.textContent="",Zt.current=requestAnimationFrame(()=>{Zt.current=null,W.textContent=w}))},t0)},[]);i.useEffect(()=>()=>{gn.current!==null&&window.clearTimeout(gn.current),Zt.current!==null&&cancelAnimationFrame(Zt.current)},[]);const wn=i.useCallback(w=>{S?.(w),v!==void 0&&mn(v(w))},[S,v,mn]),Ls=i.useCallback((w,W)=>{if(M===void 0&&x===void 0)return;const te=W.ranges[W.ranges.length-1],re=tt(te),Re=W.ranges.length===1&&re.rows===1&&re.cols===1,ke=w.ranges[w.ranges.length-1],Lt=w.ranges.length!==W.ranges.length||ke.startRow!==te.startRow||ke.startCol!==te.startCol||ke.endRow!==te.endRow||ke.endCol!==te.endCol,tn=()=>{if(M!==void 0){const vt=W.active,Ro=t.getCellText(vt.row,vt.col),al=t.getCellFormat===void 0?void 0:Mt(vt.row,vt.col,()=>Ro);mn(M({row:vt.row,col:vt.col,text:Ro,displayText:Mn(Ro,al===void 0?void 0:al.value),columnName:tr(vt.col),...Oc(t)?{readOnly:Be(t,vt.row,vt.col)}:{}}))}};if(Re){tn();return}if(Lt){x!==void 0&&mn(x({range:te,anchor:W.anchor,active:W.active,rangeRowCount:re.rows,rangeColCount:re.cols,rangeCount:W.ranges.length}));return}tn()},[t,M,x,mn,Mt]),He=i.useCallback(w=>{const W=Pe.current;Object.is(w,W)||Rm(w,W)||(Pe.current=w,Te(w),z?.(w),Ls(W,w),(bt.current?.()??!1)||Xe())},[z,Ls,Xe]),Ta=i.useCallback(w=>{const W=Pe.current;if(w.mode==="cycle"){const re=Ra(W,w.direction);He(re),zt(re.active);return}const te=Vt(w.cell,ge.count,fe.count);if(w.mode==="extend"){He(sn(W,te)),zt(te);return}He(sr(W,te,{extend:!1,append:!1})),zt(te)},[He,zt,ge,fe]),Ve=i.useCallback(()=>bt.current?.()??!1,[]),Ps=i.useRef(null),st=i.useCallback(()=>Ps.current?.()??!0,[]),qs=i.useRef(null),_n=i.useCallback((w,W)=>{const te=bt.current?.()??!1;qs.current?.(w,W),!te&&(bt.current?.()??!1)&&Pn()},[Pn]),[Da,ho]=i.useState(!1),_s=i.useCallback(()=>{ft?.(),ho(!0)},[ft]),Ma=i.useCallback((w,W)=>{Be(t,w.row,w.col)||_s(),_n("edit",W)},[t,_s,_n]),Is=i.useRef(null),yr=i.useCallback(()=>Is.current?.()??null,[]),js=i.useRef(null),pt=i.useCallback(()=>{js.current?.()},[]),Hs=i.useRef(null),Bs=i.useCallback(w=>{Hs.current?.(w)},[]),Vs=i.useRef(()=>{}),br=i.useRef(0),Qt=i.useCallback((w,W,te)=>{let re;if(W.source==="paste"){const Re=l0(te);if(w.length===0&&Re.conditionalFormats.length===0)return null;br.current+=1,re={transaction:br.current,source:"paste",sameSheet:Re.sameSheet,conditionalFormats:Re.conditionalFormats}}else{if(w.length===0)return null;br.current+=1,re={transaction:br.current,source:W.source}}try{t.applyEdits(w,re)}catch(Re){return P?.(Re,W),null}return Se.bumpEdit(),Bs(W.source),re.transaction},[t,Se,P,Bs]),$a=i.useCallback((w,W)=>Qt(w,{source:"paste"},W),[Qt]),Fa=i.useCallback(w=>{Se.setVy(w.y),rt(),ot(),xe()},[Se,rt,ot,xe]),Ws=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),za=i.useCallback(w=>{Se.setRowRange(w.renderingRowStart,w.renderingRowEnd),Se.setColRange(w.renderingColStart,w.renderingColEnd);const W=Ws.current;(W.rowStart!==w.renderingRowStart||W.rowEnd!==w.renderingRowEnd||W.colStart!==w.renderingColStart||W.colEnd!==w.renderingColEnd)&&(Ws.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},xe())},[Se,xe]),Ks=i.useRef(()=>"add"),Nt=i.useCallback(w=>{oo.current?.(w,Ks.current())},[]),Na=i.useCallback(w=>{oo.current?.(w,"point")},[]),Ys=i.useRef(null),go=i.useCallback(w=>{Ys.current?.(w)},[]),Us=i.useRef(null),La=i.useCallback(w=>{Us.current?.(w)},[]),Xs=i.useRef(null),mo=i.useCallback((w,W)=>{if(W.length===0)return;const te=Z.current;if(w==="col"){for(const re of W){const Re=Math.round(re.size);fe.resize(re.index,Re),te?.updateColSize(re.index,Re)}Se.bumpColVersion(),ot(),xe(),hn();return}for(const re of W){const Re=Math.round(re.size);ge.resize(re.index,Re),te?.updateRowSize(re.index,Re)}Se.bumpRowGeometry(),rt(),xe(),hn()},[ge,fe,Se,ot,rt,xe,hn]),Pa=i.useCallback((w,W)=>{I?.(w,{kind:"pointer",event:W})},[I]),qa=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:Nt,axis:"both",zoomRef:Oe}),_a=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:Nt,axis:"x",zoomRef:Oe}),Ia=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:Nt,axis:"y",zoomRef:Oe}),ja=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:go,axis:"x",zoomRef:Oe}),Ha=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:go,axis:"y",zoomRef:Oe}),Ba=yn({handleRef:Z,rowAxis:ge,colAxis:fe,bodyRef:ne,onDragFrame:Nt,axis:"both",zoomRef:Oe}),Gs=i.useRef(null),Js=i.useRef(()=>!1),wo=i.useCallback(()=>Js.current(),[]),lt=Um({zoomRef:Oe,enabled:!_,rowAxis:ge,colAxis:fe,handleRef:Z,bodyRef:ne,isEditing:Ve,requestCommit:st,getSelection:qe,setSelection:He,focusSink:De,onDragFrame:Nt,onContextMenuSelect:Pa,onRequestEdit:Ma,caretFromPointEnabled:w=>{if(j!==void 0||t.getCellFormula!==void 0&&t.getCellFormula(w.row,w.col)!==void 0)return!1;if(t.getCellFormat===void 0)return!0;const W=t.getCellText(w.row,w.col);return Mn(W,t.getCellFormat(w.row,w.col)?.value)===W},isAnyDragging:wo,autoScroller:qa,repaintOverlay:xe,pointDragRef:Gs,getPointing:Jt,openHyperlinkAt:U===void 0||t.getCellHyperlink===void 0?void 0:w=>{const W=t.getCellHyperlink===void 0?void 0:zn(t.getCellHyperlink(w.row,w.col));return W===void 0?!1:(U(W,w),!0)}}),ht=vi({zoomRef:Oe,enabled:!_,axis:"col",headerRef:Le,mainAxis:fe,crossCount:t.rowCount,handleRef:Z,isEditing:Ve,requestCommit:st,getSelection:qe,setSelection:He,focusSink:De,onDragFrame:Nt,autoScroller:_a,repaintOverlay:xe,pointing:lo}),gt=vi({zoomRef:Oe,enabled:!_,axis:"row",headerRef:se,mainAxis:ge,crossCount:t.colCount,handleRef:Z,isEditing:Ve,requestCommit:st,getSelection:qe,setSelection:He,focusSink:De,onDragFrame:Nt,autoScroller:Ia,repaintOverlay:xe,pointing:lo}),mt=vm({zoomRef:Oe,enabled:!_&&y,colBandRef:Le,rowBandRef:se,colAxis:fe,rowAxis:ge,viewStore:Se,handleRef:Z,isEditing:Ve,requestCommit:st,focusSink:De,getSelection:qe,adapter:t,autofitEnabled:j===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:p,onOperationRejected:T,resizeTracks:mo,writeResizeGuide:La,repaintOverlay:xe,isPointing:Jt}),it=Lm({zoomRef:Oe,enabled:!_&&m,handleNodeRef:Xs,bodyRef:ne,rowAxis:ge,colAxis:fe,handleRef:Z,getSelection:qe,setSelection:He,focusSink:De,adapter:t,commitEdits:Qt,maxOperationCells:p,onOperationRejected:T,rejectReadOnly:wn,writeFillPreview:go,repaintOverlay:xe,xAutoScroller:ja,yAutoScroller:Ha}),Ze=Xm({zoomRef:Oe,enabled:!_,bodyRef:ne,handleRef:Z,rowAxis:ge,colAxis:fe,getPointing:Jt,insertReference:lo.insertReference,captureSink:()=>xs.current(),restoreSink:w=>Os.current(w),focusSink:De,autoScroller:Ba,onDragFrame:Nt});Gs.current=Ze;const In=i.useCallback(()=>lt.isDragging()||ht.isDragging()||gt.isDragging()||mt.isDragging()||it.isDragging()||Ze.isDragging(),[lt,ht,gt,mt,it,Ze]);Ln.current=In,Js.current=In,Ks.current=()=>Ze.isDragging()?"point":lt.getDragMode();const Va=i.useCallback(()=>{lt.abortDrag(),ht.abortDrag(),gt.abortDrag(),mt.abortDrag(),it.abortDrag(),Ze.abortDrag()},[lt,ht,gt,mt,it,Ze]),Co=i.useCallback(()=>Pe.current.active,[]),Zs=i.useCallback((w,W)=>{const te=t.getCellValidation===void 0?void 0:t.getCellValidation(w.row,w.col);if(te===void 0)return Si;const re=t.evaluateFormula,Re=Bc(te,W,re===void 0?void 0:ke=>re(ke,w));return Re.ok||te.strict!==!0?Si:(Q?.({cell:w,rule:te,text:W,message:Re.message}),Ft.current?.isKindEnabled("message")&&Cr.current("message",{message:Re.message,rejected:!0}),Re)},[t,Q]),Ne=Pg({enabled:!_,sinkRef:we,rootRef:Ue,adapter:t,commitEdits:Qt,getActive:Co,ensureCellVisible:zt,focusSink:De,rearmSink:Xe,discardClip:pt,isDragging:wo,rejectReadOnly:wn,resolveEditAlign:w=>{if(t.getCellFormat===void 0)return null;const W=jr(t,w.row,w.col);return xc(Mt(w.row,w.col,W),W)},resolveEditPaint:w=>t.getCellFormat===void 0?null:Dd(Mt(w.row,w.col,jr(t,w.row,w.col))),editPaintRef:Ts,repaintOverlay:xe,validateCommit:Zs});bt.current=Ne.isEditing,Ps.current=Ne.requestCommit,qs.current=Ne.startEdit,so.current=Ne.getPointing,As.current=Ne.insertReference,xs.current=Ne.captureSink,Os.current=Ne.restoreSink;const Qs=i.useCallback(()=>{Ne.cancelEdit(),Pn()},[Ne.cancelEdit,Pn]),jn=Cg({enabled:!_,sinkRef:we,adapter:t,isEditing:Ve,getSelection:qe,setSelection:He,commitPaste:$a,maxOperationCells:p,onOperationRejected:T,onCopyMultiRange:$,repaintOverlay:xe,isDragging:wo,resize:{rowAxis:ge,colAxis:fe,resizeTracks:mo},pendingPasteOptionsRef:Ds,formats:f,onClipChange:V,onClipboardUnavailable:oe,onEditRejected:P,rejectReadOnly:wn,onPasteResolved:ie});Is.current=jn.getClip,js.current=jn.discardClip,Hs.current=jn.discardClipOnCommit,Vs.current=jn.onAdapterSwitch,ao.current=jn.paste;const Hn=Km({enabled:!_,adapter:t,popovers:D,sinkRef:we,bodyRef:ne,handleRef:Z,rowAxis:ge,colAxis:fe,zoomRef:Oe,getActive:Co,isEditing:Ve,requestCommit:st,focusSink:De,rearmSink:Xe,isDraggingAny:In,commitEdits:Qt,labels:Ct,onHyperlinkOpen:U,anchors:io,repaintOverlay:xe,rejectReadOnly:wn});Ft.current=Hn,Cr.current=Hn.open,Fs.current=Hn.hideTip;const Wa=i.useCallback(()=>{const w=Pe.current.active;zt(w);const W=Z.current,te=W===null?{x:0,y:0}:W.getScrollPosition(),re=W===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:W.getFrozenSize(),Re=W===null?{width:0,height:0}:W.getViewportSize(),ke=Oe.current;return{top:cn(ge,w.row,{scroll:Math.max(0,te.y),frozenCount:re.rows,trailingCount:re.trailingRows,extent:Re.height})*ke,left:ln(fe,w.col,{scroll:Math.max(0,te.x),frozenCount:re.cols,trailingCount:re.trailingCols,extent:Re.width})*ke,width:fe.sizeOf(w.col)*ke,height:ge.sizeOf(w.row)*ke}},[ge,fe,zt]),yo=zg({adapter:t,getSelection:qe,commitEdits:Qt,getActive:Co,isEditing:Ve,requestCommit:st,cancelEdit:Qs,getSessionText:Ne.getSessionText,validateCommit:Zs,insertAtCaret:Ne.insertAtCaret,refreshEditPaint:Ne.refreshPaint,maxOperationCells:p,onOperationRejected:T,colors:un,formats:f,getHighlight:()=>Xt.current,setHighlight:xa,popovers:D,openPopover:w=>Cr.current(w),onHyperlinkOpen:U,onPasteSpecialRequest:ee,paste:w=>ao.current(w),rowAxis:ge,colAxis:fe,resizeTracks:mo,defaultRowHeight:n,defaultColumnWidth:r,now:G,announce:mn,formatCommandAnnouncement:R,keyboardCellRect:Wa,rejectReadOnly:wn});Ns.current=yo,co.current=yo.executeCommand,zs.current=yo.isCommandAvailable;const Ka=i.useMemo(()=>({table:Wt,execute:w=>co.current(w),isAvailable:w=>zs.current(w)}),[Wt]),Ya=i.useCallback(()=>{pt(),Y?.()},[pt,Y]),Ua=i.useCallback(()=>{pt(),H?.()},[pt,H]);Fm({zoomRef:Oe,enabled:!_,sinkRef:we,rootRef:Ue,handOffFocusToRoot:Oa,getSelection:qe,setSelection:He,moveActive:Ta,ensureCellVisible:zt,isEditing:Ve,requestCommit:st,startEdit:_n,commitEdits:Qt,maxOperationCells:p,onOperationRejected:T,rejectReadOnly:wn,getClip:yr,discardClip:pt,isDragging:In,abortDrag:Va,findDataEdge:t.findDataEdge,getEditingMode:Ne.getEditingMode,cancelEdit:Qs,onUndoRequest:Ya,onRedoRequest:Ua,onCellContextMenu:I,rowAxis:ge,colAxis:fe,handleRef:Z,rearmSink:Xe,commands:Ka,pointing:Ne,adapter:t,hideNoteTip:()=>Fs.current(),closeRejectedMessage:Pn,pendingPasteOptionsRef:Ds,onPointFrame:Na});const Xa=be.active.row,Ga=be.active.col;i.useLayoutEffect(()=>{const w=Ft.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[Xa,Ga]),i.useLayoutEffect(()=>{xe()},[xe,Je.row,Je.column,Je.intersection]);const Ja=i.useCallback(w=>{(bt.current?.()??!1)||(w.preventDefault(),De(),Xe())},[De,Xe]),Za=i.useCallback(w=>{const W=Ue.current,te=w.relatedTarget;if(W!==null&&te instanceof Node&&W.contains(te)){w.target===W&&te===we.current&&!uo.current&&De();return}(bt.current?.()??!1)||(De(),Xe())},[De,Xe]),Qa=i.useCallback(w=>{const W=Ue.current,te=w.relatedTarget;W!==null&&te instanceof Node&&W.contains(te)||Ne.isFocusoutSuppressed()||ho(!1)},[Ne]),vr=i.useRef(null),Bn=i.useCallback(()=>{const w=vr.current;w!==null&&(vr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),bo=i.useCallback(()=>{if(vr.current!==null)return;const w=te=>{te.pointerType==="mouse"&&(Bn(),te.button===1&&te.preventDefault())},W=te=>{te.pointerType==="mouse"&&Bn()};vr.current={up:w,cancel:W},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",W,!0)},[Bn]);i.useEffect(()=>Bn,[Bn]),i.useEffect(()=>{const w=Ue.current;if(_||w===null)return;let W=0;const te=ke=>{if(ke.pointerType!=="mouse"){(bt.current?.()??!1)||ho(!1);return}W=ke.buttons,ke.button===1&&(ke.target===we.current&&(bt.current?.()??!1)||bo())},re=ke=>{ke.pointerType==="mouse"&&(W=ke.buttons)},Re=ke=>{if(ke.pointerType!=="mouse"||ke.buttons===W)return;const Lt=ke.buttons&~W;W=ke.buttons,ke.preventDefault(),(Lt&4)!==0&&bo()};return w.addEventListener("pointerdown",te,!0),w.addEventListener("pointerup",re,!0),w.addEventListener("pointermove",Re,!0),()=>{w.removeEventListener("pointerdown",te,!0),w.removeEventListener("pointerup",re,!0),w.removeEventListener("pointermove",Re,!0)}},[_,bo]);const eu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(Jt()){De();return}if(Ve()&&!st()){De();return}De()}},[De,Ve,st,Jt]),vo=i.useRef(!1);i.useLayoutEffect(()=>{if(_){vo.current=!1;return}if(vo.current)return;vo.current=!0,Xe();const w=(Ue.current?.clientHeight??0)/Oe.current;w>0&&ge.totalSize()>0&&Se.setRowRange(0,ge.indexAt(Math.min(w-1,ge.totalSize()-1)));const W=(Ue.current?.clientWidth??0)/Oe.current;W>0&&fe.totalSize()>0&&Se.setColRange(0,fe.indexAt(Math.min(W-1,fe.totalSize()-1)))},[_,Xe,Se,ge,fe]);const el=i.useRef(t);i.useLayoutEffect(()=>{el.current!==t&&(el.current=t,lt.cancelDrag(),ht.cancelDrag(),gt.cancelDrag(),mt.cancelDrag(),it.cancelDrag(),Ze.cancelDrag(),Ne.cancelEdit(),Ft.current?.hideTip(),Ft.current?.close(),_?(Pe.current=bn,Te(bn)):He(bn),Vs.current())},[t,_,He,lt,ht,gt,mt,it,Ze,Se,Ne.cancelEdit]);const tl=i.useRef({adapter:t,rows:ge.count,cols:fe.count}),{getSessionCell:nl,cancelEdit:rl}=Ne;i.useLayoutEffect(()=>{const w=tl.current,W=ge.count,te=fe.count;if(tl.current={adapter:t,rows:W,cols:te},w.adapter!==t||W>=w.rows&&te>=w.cols)return;_?(Pe.current=bn,Te(bn)):He(km(Pe.current,W,te)),lt.cancelDrag(),ht.cancelDrag(),gt.cancelDrag(),mt.cancelDrag(),it.cancelDrag(),Ze.cancelDrag();const re=tn=>_||tn.row>=W||tn.col>=te,Re=nl();Re!==null&&re(Re)&&rl();const ke=io.current;if(ke.tip!==null&&re(ke.tip)&&Ft.current?.hideTip(),ke.interactive!==null&&re(ke.interactive)){const tn=Ue.current?.contains(document.activeElement)===!0;Ft.current?.close({restoreFocus:tn})}const Lt=yr();Lt!==null&&!Lt.foreign&&re({row:Lt.range.endRow,col:Lt.range.endCol})&&pt()},[t,ge.count,fe.count,_,He,lt,ht,gt,mt,it,Ze,nl,rl,yr,pt]);const ol=i.useRef(o),sl=i.useRef(s),ll=i.useRef(l),il=i.useRef(c);i.useLayoutEffect(()=>{(ol.current!==o||sl.current!==s||ll.current!==l||il.current!==c)&&(ol.current=o,sl.current=s,ll.current=l,il.current=c,lt.cancelDrag(),ht.cancelDrag(),gt.cancelDrag(),mt.cancelDrag(),it.cancelDrag(),Ze.cancelDrag())},[o,s,l,c,lt,ht,gt,mt,it,Ze]),i.useLayoutEffect(()=>{rt(),ot(),xe()},[o,s,l,c,rt,ot,xe]);const cl=i.useRef(E);i.useLayoutEffect(()=>{cl.current!==E&&(cl.current=E,pt())},[E,pt]),i.useLayoutEffect(()=>{xe()},[xe,be]);const en=i.useCallback(()=>{const w=Ns.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(hr,()=>({resizeRow:(w,W)=>{const te=Math.round(W);ge.resize(w,te),Z.current?.updateRowSize(w,te),Se.bumpRowGeometry(),rt(),xe(),hn()},resizeColumn:(w,W)=>{const te=Math.round(W);fe.resize(w,te),Z.current?.updateColSize(w,te),Se.bumpColVersion(),ot(),xe(),hn()},scrollToCell:(w,W)=>{Z.current?.scrollToCell(w.row,w.col,W)},focus:w=>{De(w),Ve()||Xe()},executeCommand:w=>co.current(w),applyFormat:w=>en().applyFormat(w),setBorders:(w,W)=>en().setBorders(w,W),setHyperlink:w=>en().setHyperlink(w),setNote:w=>en().setNote(w),addComment:w=>en().addComment(w),setValidation:w=>en().setValidation(w),paste:w=>ao.current(w),getSelection:()=>Pe.current,getBaseFormat:w=>t.getCellFormat===void 0?void 0:t.getCellFormat(w.row,w.col),getPaintedFormat:w=>t.getCellFormat===void 0?void 0:Mt(w.row,w.col,jr(t,w.row,w.col)),startEdit:w=>{_n(w)},openPopover:w=>{Cr.current(w)}}),[ge,fe,Se,ot,rt,xe,hn,De,Ve,Xe,t,Mt,_n,en]),_)return K.jsx("div",{className:ze?`aqsp-root ${ze}`:"aqsp-root","data-aqsp-empty":"","data-testid":Me});const tu=M!==void 0||x!==void 0||R!==void 0||v!==void 0;return K.jsx("div",{ref:Ue,className:ze?`aqsp-root ${ze}`:"aqsp-root",role:"group","aria-label":Ct.rootAriaLabel,tabIndex:0,onFocus:Za,onBlur:Qa,"data-aqsp-root":"","data-testid":Me,children:K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":nt,onPointerDown:eu,style:nt===1?void 0:{width:`${100/nt}%`,height:`${100/nt}%`,transform:`scale(${nt})`},children:[K.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(Jt()){De();return}if(Ve()&&!st()){De();return}De(),He({ranges:[he({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(mm,{viewStore:Se,colAxis:fe,frozenCols:o,frozenTrailingCols:l,handleRef:Z,bandRef:Le,colTrackRef:Ie,windowOriginXRef:je,repaintColHeaders:ot,selectionRanges:be.ranges,enableResizeUI:y,dividerLeadingRef:ae,dividerTrailingRef:ue}),K.jsx(wm,{viewStore:Se,rowAxis:ge,handleRef:Z,bandRef:se,selectionRanges:be.ranges,rowTrackRef:me,windowOriginYRef:_e,repaintHeaders:rt,enableResizeUI:y,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:de,dividerTrailingRef:ce}),K.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(gm,{adapter:t,rowAxis:ge,colAxis:fe,viewStore:Se,handleRef:Z,bodyRef:ne,dataVersion:E,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:l,frozenTrailingRows:c,tapScrollCircleOptions:u,overscanRows:Ri("overscanRows",h),overscanCols:Ri("overscanCols",g),background:C,onRenderTruncated:q,renderCell:j,onScroll:Fa,onRangeChange:za,focusSink:De,isEditing:Ve,requestCommit:st,testId:Me?`${Me}-vs`:void 0,__onCellRender:Ye,__maxRenderedCells:pr,cfIndexRef:fn,cfMemoRef:Yt,isPointing:Jt}),K.jsx(Kh,{rowAxis:ge,colAxis:fe,handleRef:Z,sinkRef:we,getSelection:qe,editing:Ne.editing,virtualKeyboard:Da,repaintRef:Es,dragFrameRef:oo,getClip:yr,getIsDraggingAny:In,getIsFillDragging:it.isDragging,fillFrameRef:Ys,resizeGuideFrameRef:Us,fillHandleNodeRef:Xs,enableFillHandle:m,frozenCols:o,frozenRows:s,trailingCols:l,trailingRows:c,sinkAriaLabel:Ct.sinkAriaLabel,onSinkMouseDown:Ja,editPaintRef:Ts,highlightRef:Xt,highlightColors:Gt,popoverAnchors:io,interactiveAnchorRef:Ms,tipAnchorRef:$s}),Hn.layerEnabled?K.jsx(Bm,{controller:Hn,labels:Ct,renderPopover:F,interactiveAnchorRef:Ms,tipAnchorRef:$s}):null]}),tu?K.jsx("div",{ref:Ce,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=is;exports.CommentPopover=ea;exports.DEFAULT_CUSTOM_COLORS=Aa;exports.DEFAULT_HIGHLIGHT_COLORS=Zc;exports.DEFAULT_LABELS=ts;exports.DEFAULT_SHORTCUTS=Ic;exports.LinkPopover=ta;exports.ListPopover=na;exports.MessagePopover=ra;exports.NotePopover=oa;exports.NoteTip=sa;exports.SPREADSHEET_RESERVED_SHORTCUTS=Jp;exports.Spreadsheet=i0;exports.canonicalizeFormat=dt;exports.columnIndexToName=tr;exports.columnNameToIndex=Bp;exports.detectClipSource=Ni;exports.enumerateRangeCells=qt;exports.estimatePasteCellCount=Np;exports.expandPaste=Lp;exports.formatCellValue=Mn;exports.formatEquals=du;exports.fromR1C1=ar;exports.makeRange=he;exports.mergeFormat=as;exports.normalizeHyperlink=Bt;exports.parseChord=on;exports.parseClipPayload=Vo;exports.parseHtmlTable=Ac;exports.parseTsv=Lc;exports.rangeContains=an;exports.rangeSize=tt;exports.resolveLabel=$e;exports.serializeClipPayload=$i;exports.serializeHtmlTable=Rc;exports.serializeTsv=Fc;exports.shiftFormula=sc;exports.toR1C1=Zr;exports.validateCellText=Bc;