@aiquants/spreadsheet 0.13.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +53 -7
- package/dist/index.cjs +8 -15
- package/dist/index.d.cts +12 -11
- package/dist/index.d.ts +12 -11
- package/dist/index.js +1176 -1255
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/dist/tsv-B6TDExlk.js +91 -0
- package/dist/tsv-BHXbWK5W.cjs +8 -0
- package/dist/tsv.cjs +1 -0
- package/dist/tsv.d.cts +13 -0
- package/dist/tsv.d.ts +13 -0
- package/dist/tsv.js +5 -0
- package/dist/view.cjs +1 -0
- package/dist/view.d.cts +49 -0
- package/dist/view.d.ts +49 -0
- package/dist/view.js +14 -0
- package/package.json +31 -7
- package/src/Spreadsheet.tsx +20 -50
- package/src/grid/GridBody.tsx +7 -6
- package/src/header/ColumnHeader.tsx +10 -6
- package/src/header/RowHeader.tsx +4 -3
- package/src/model/labels.ts +23 -22
- package/src/model/viewStore.ts +1 -4
- package/src/overlay/SelectionOverlay.tsx +3 -3
- package/src/popover/placement.ts +4 -4
- package/src/styles/spreadsheet.css +1 -1
- package/src/tsv.ts +13 -0
- package/src/view.ts +62 -0
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Xe=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),ls=1e3,Dn=1e4,is=10,gl=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),cs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/is):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()-gl(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()+gl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},as="#000000",kr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},fu=20,pu=256,Sr=new Map,So=new WeakMap,et=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},hu=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},gu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:fu}:kr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...kr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...kr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...kr(e.decimals)};default:return null}},mu=e=>{const t=So.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=Sr.get(n);if(r!==void 0)return So.set(e,r),r;Sr.size>=pu&&Sr.clear();const o=gu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Sr.set(n,s),So.set(e,s),s},wu=(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}},Mi=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>wu(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=Mi(e);if(n===null)return e;const r=(o,s)=>String(o).padStart(s,"0");return t.replace(/yyyy|MM|dd|HH|mm|ss/g,o=>{switch(o){case"yyyy":return r(n.year,4);case"MM":return r(n.month,2);case"dd":return r(n.day,2);case"HH":return r(n.hour,2);case"mm":return r(n.minute,2);default:return r(n.second,2)}})},Ln=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Cu(e,t.pattern??"yyyy/MM/dd");const n=et(e);if(n===null)return e;const r=mu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?hu(n,-2):n)},ml=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Mi(n)!==null?"right":"left":et(n)!==null?"right":"left",tr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",zi=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],yu=["bottom","left","right","top"],Fi=(e,t,n)=>{e[t]=n},Ni=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},bu=e=>{if(e===void 0)return;const t={};for(const n of yu){const r=e[n];r!==void 0&&(t[n]=Ni(r))}return Object.keys(t).length===0?void 0:t},ft=e=>{const t={};for(const n of zi){const r=n==="borders"?bu(e.borders):n==="value"?e.value===void 0?void 0:Ni(e.value):e[n];r!==void 0&&r!==!1&&Fi(t,n,r)}return Object.keys(t).length===0?void 0:t},us=(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]||!us(o[c],s[c]))return!1}return!0},vu=(e,t)=>e===t?!0:us(e===void 0?void 0:ft(e),t===void 0?void 0:ft(t)),ds=(e,t)=>{const n={};for(const o of zi){const s=t[o];Fi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=ft(n);return us(r,e===void 0?void 0:ft(e))?e:r},Pi="data-aqsp-clip",Wr="application/x-aqsp-clip",Vo=512,wl=16*1024,Wo=`${Pi}=`,Ru=16,fs=()=>{const e=globalThis.crypto;if(e===void 0||typeof e.getRandomValues!="function")throw new RangeError("[spreadsheet] newClipId requires crypto.getRandomValues — there is no counter or randomUUID substitute by design");const t=e.getRandomValues(new Uint8Array(Ru));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",Ye=e=>typeof e=="boolean",_t=e=>typeof e=="number"&&Number.isFinite(e),ut=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Cl=e=>ut(e)&&e>=1,ku=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Dn,At=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Su=e=>t=>Array.isArray(t)&&t.every(e),Oe=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),xt=(e,t)=>{if(!ar(e))return!1;for(const n of Object.keys(e)){const r=e[n];if(r===void 0)continue;const o=t.fields.get(n);if(o===void 0||!o(r))return!1}for(const n of t.required)if(e[n]===void 0)return!1;return!0},ps=e=>t=>{if(!ar(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&xt(t,n)},Eu=["left","center","right"],Au=["top","middle","bottom"],Ou=["thin","medium","thick","dashed","dotted","double","hair"],Eo=["gt","gte","lt","lte","eq","neq","between","notBetween"],xu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Tu=["eq","neq","gt","gte","lt","lte","between","notBetween"],$u=["contains","notContains","startsWith","endsWith"],Du=new Map([["number",Oe({type:le,decimals:_t,grouping:Ye,locale:le},["type"])],["percent",Oe({type:le,decimals:_t,scale:Ye,locale:le},["type"])],["currency",Oe({type:le,currency:le,decimals:_t,locale:le},["type","currency"])],["scientific",Oe({type:le,decimals:_t,locale:le},["type"])],["date",Oe({type:le,pattern:le},["type"])],["text",Oe({type:le},["type"])]]),Lu=Oe({style:At(Ou),color:le},["style"]),Er=e=>xt(e,Lu),Mu=Oe({top:Er,right:Er,bottom:Er,left:Er},[]),zu=Oe({value:ps(Du),align:At(Eu),verticalAlign:At(Au),wrap:Ye,background:le,color:le,bold:Ye,italic:Ye,underline:Ye,strikethrough:Ye,fontFamily:le,fontSize:_t,borders:e=>xt(e,Mu)},[]),Fu=e=>xt(e,zu),en={strict:Ye,inputMessage:le,errorMessage:le},Nu=new Map([["list",Oe({...en,type:le,values:Su(le),showDropdown:Ye},["type","values"])],["number",Oe({...en,type:le,op:At(Eo),a:le,b:le},["type","op","a"])],["textLength",Oe({...en,type:le,op:At(Eo),a:_t,b:_t},["type","op","a"])],["date",Oe({...en,type:le,op:At(Eo),a:le,b:le},["type","op","a"])],["text",Oe({...en,type:le,op:At(xu),value:le},["type","op"])],["checkbox",Oe({...en,type:le,checked:le,unchecked:le},["type"])],["custom",Oe({...en,type:le,formula:le},["type","formula"])]]),Pu=ps(Nu),qu=Oe({startRow:ut,startCol:ut,endRow:ut,endCol:ut},["startRow","startCol","endRow","endCol"]),_u=e=>{if(!xt(e,qu))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return ut(t)&&ut(r)&&ut(n)&&ut(o)&&t<=r&&n<=o},ju=Oe({color:le,value:_t},["color"]),Ao=e=>xt(e,ju),Iu=new Map([["cellValue",Oe({type:le,op:At(Tu),a:le,b:le},["type","op","a"])],["text",Oe({type:le,op:At($u),value:le},["type","op","value"])],["empty",Oe({type:le},["type"])],["notEmpty",Oe({type:le},["type"])],["colorScale",Oe({type:le,min:Ao,mid:Ao,max:Ao},["type","min","max"])],["customFormula",Oe({type:le,formula:le},["type","formula"])]]),Hu=Oe({background:le,color:le,bold:Ye,italic:Ye,underline:Ye,strikethrough:Ye},[]),Bu=Oe({sourceRuleId:le,ranges:Array.isArray,condition:ps(Iu),style:e=>xt(e,Hu),stopIfTrue:Ye},["sourceRuleId","ranges","condition","style"]),Vu=(e,t,n)=>{if(!xt(e,Bu))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!_u(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Wu=Oe({text:le,author:le,createdAt:le},["text","author","createdAt"]),Ku=e=>xt(e,Wu),Yu=(e,t,n)=>{if(!ar(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!ut(o)||o>=t)return!1;break;case"val":if(!ut(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(Ku)))return!1;break;default:return!1}}return!0},yl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(ku),Uu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),qi=e=>{if(!ar(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Uu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Cl(t)&&Cl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Fu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Pu)))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(!Yu(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!yl(e.colWidths,n)||e.rowHeights!==void 0&&!yl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Vu(c,t,n))},lr=e=>Array.isArray(e)?`[${e.map(lr).join(",")}]`:ar(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${lr(e[n])}`).join(",")}}`:JSON.stringify(e),Xu=e=>{const t=ft(e);return t===void 0?"{}":JSON.stringify(t)},Gu=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(Gu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},_i=e=>{if(!qi(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(Xu).join(","),r=e.validations.map(lr).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(lr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Ko=e=>{let t;try{t=JSON.parse(e)}catch{return null}return qi(t)?t:null},Zu=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Qu=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),ji=e=>e.includes("&")?e.replace(Zu,t=>Qu[t]):e,ed=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,bl=e=>{const t=e.length>Vo?e.slice(0,Vo):e,n=ed.exec(ji(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},td=e=>{const t=e.indexOf(Wo);if(t===-1)return null;const n=t+Wo.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Ii=(e,t)=>{if(t==="event"&&e.types.includes(Wr))return{kind:"mime",json:e.getData(Wr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=td(n);return r===null?null:{kind:"attribute",html:n,at:r}},nd=(e,t)=>{const n=Ii(e,t);return n===null?null:n.kind==="mime"?bl(n.json):bl(n.html.slice(n.at.start,n.at.start+Vo))},rd=(e,t)=>{const n=Ii(e,t);if(n===null)return null;if(n.kind==="mime")return Ko(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Ko(ji(n.html.slice(n.at.start,r)))},od=/<google-sheets-html-origin[\s>]/,sd='data-sheets-root="1"',ld=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,id="mso-",cd=/\.xl\d+\s*\{/,ad="<table",ud=e=>e.includes(Wo)?"aqsp":od.test(e)&&e.includes(sd)?"sheets":ld.test(e)||e.includes(id)||cd.test(e)?"excel":null,Hi=(e,t)=>{if(t==="event"&&e.types.includes(Wr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>wl?n.slice(0,wl):n,o=ud(r);if(o==="aqsp")return"aqsp";if(n.includes(ad))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},hs=1e3,Bi=65534,dd=9,fd=10,pd=12,hd=13,gd=32,Vi=34,Wi=39,md=43,gs=47,vl=48,wd=57,Cd=61,yd=62,bd=97,vd=98,Rd=100,kd=102,Ki=104,Yi=114,Ui=116,Sd=["able","body","head","foot"],nr=e=>e===gd||e===dd||e===fd||e===hd||e===pd,Yo=e=>e===yd||e===gs||nr(e),Ed=e=>nr(e)||e===gs||e===Vi||e===Wi,Ad=(e,t,n,r)=>{if(t===0||!Ed(e.charCodeAt(t-1)))return null;let o=t+n;for(;nr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Cd)return 1;for(o+=1;nr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Vi||s===Wi)&&(o+=1);nr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===md&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=vl&&u<=wd;u=e.charCodeAt(o))l=l*10+(u-vl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Rl=(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=Ad(e,r,t.length,n);if(l!==null)return l}return 1}},Od=(e,t)=>{if(e.charCodeAt(t+2)!==Ui)return!1;const n=e.charCodeAt(t+3);if(n===Yi)return Yo(e.charCodeAt(t+4));if(n!==bd&&n!==vd&&n!==Ki&&n!==kd)return!1;for(const r of Sd)if(e.startsWith(r,t+3)&&Yo(e.charCodeAt(t+3+r.length)))return!0;return!1},xd=e=>{const t=e.toLowerCase(),n=Rl(t,"colspan",hs),r=Rl(t,"rowspan",Bi);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,g=!1;const C=new Map,q=(_,Y)=>{const B=C.get(_);C.set(_,B===void 0?Y:B+Y)},j=()=>{g&&u+h>c&&(c=u+h),g=!1},N=()=>{j(),l+=1,g=!0,u=0;const _=C.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const Y=t.charCodeAt(_+1);if(Y===gs){Od(t,_)&&j();continue}if(Y!==Ui||!Yo(t.charCodeAt(_+3)))continue;const B=t.charCodeAt(_+2);if(B===Yi)N();else if(B===Rd||B===Ki){g||N();const L=_+3,$=s(L),P=n(L,$);u+=P;const k=r(L,$);k>1&&(q(l,P),q(l-1+k,-P))}}return j(),{rows:l,cols:c}},Xi=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}},Gi=()=>{const e=new WeakMap,t=Xi(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=ft(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Td=()=>{const e=new WeakMap,t=Xi(lr);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}},$d=new Set(["http:","https:","mailto:","tel:"]),Bt=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return $d.has(n.protocol)?n.href:null},Fn=e=>{if(e===void 0)return;const t=Bt(e);return t===null?void 0:t},Ji=(e,t)=>e.startCol===0&&e.endCol===t-1,Zi=(e,t)=>e.startRow===0&&e.endRow===t-1,Uo=13,Et=Object.freeze({style:Object.freeze({}),lineBoxPx:Uo,verticalAlign:"middle"}),Dd={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"},Ld=new Map(Object.entries(Dd)),Md=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,zd=/^rgba?\((.*)\)$/,Qi=/^(\d+(?:\.\d+)?)%$/,Ar=e=>e.toString(16).padStart(2,"0"),Oo=e=>{const t=Qi.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},Fd=e=>{const t=Qi.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},Nd=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Oo(t[0]),r=Oo(t[1]),o=Oo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Ar(n)}${Ar(r)}${Ar(o)}`;if(t.length===3)return s;const l=Fd(t[3]);return l===null?null:l===255?s:`${s}${Ar(l)}`},Ue=e=>{const t=e.trim().toLowerCase(),n=Md.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=zd.exec(t);if(r!==null)return Nd(r[1]);const o=Ld.get(t);return o===void 0?null:o},kl={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"}},Sl=e=>{if(!Object.hasOwn(kl,e.style))return null;const t=kl[e.style],n=e.color===void 0?as:Ue(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Pd={top:"flex-start",middle:"center",bottom:"flex-end"},qd=e=>e==="left"||e==="center"||e==="right",ec=e=>e==="top"||e==="middle"||e==="bottom",tc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,nc=(e,t)=>{if(typeof e.background=="string"){const s=Ue(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ue(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=tc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Or=(e,t)=>{const n=e===void 0?null:Sl(e);return n!==null?n:t===void 0?null:Sl(t)},xo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(qd(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=tr(e.align)),ec(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Pd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),nc(e,s));const c=e?.borders,u=Or(c?.right,t);u!==null&&(s.borderRight=u);const h=Or(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const g=Or(c?.left,void 0);g!==null&&(s.borderLeft=g)}if(o){const g=Or(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)})},El=new WeakMap,_d=(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=El.get(e);if(u!==void 0)return u;const h=xo(e,void 0,void 0,!1,!1);return El.set(e,h),h},jd=e=>{if(e===void 0)return Et;const t={};nc(e,t);const n=tc(e.fontSize),r=n===null?Uo:Math.round(n),o=ec(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Uo&&o==="middle"?Et:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Id="#REF!",Hd=11,Bd=15,Vd=4096,qr=33,rr=34,ms=36,Wd=38,Xo=39,rc=40,Kd=42,Yd=43,Ud=44,oc=45,Xd=46,Gd=47,On=58,Jd=59,Zd=60,sc=61,Qd=62,ef=67,tf=82,Jr=91,lc=93,nf=94,rf=95,ic=e=>e>=65&&e<=90||e>=97&&e<=122,cc=e=>e>=48&&e<=57,ws=e=>ic(e)||cc(e)||e===rf||e===Xd||e===ms||e>=128,of=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,sf=e=>e===sc||e===rc||e===Ud||e===Jd||e===Yd||e===oc||e===Kd||e===Gd||e===nf||e===Wd||e===Zd||e===Qd||e===On,ac=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(ws(n)||n===rc||n===qr||n===Jr)},Al=(e,t)=>{let n=t;for(;n<e.length&&ws(e.charCodeAt(n));)n+=1;return n},Go=(e,t,n)=>{let r=t+1;for(;r<e.length;){if(e.charCodeAt(r)===n){if(e.charCodeAt(r+1)===n){r+=2;continue}return r+1}r+=1}return e.length},lf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Xo){r+=2;continue}if(o===Jr)n+=1;else if(o===lc&&(n-=1,n===0))return r+1;r+=1}return e.length},Ol=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&ac(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},uc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===rr){o=Go(e,o,rr);continue}if(s===Xo){const u=Go(e,o,Xo);o=e.charCodeAt(u)===qr?Ol(e,o,u,t,n):u;continue}if(s===Jr){o=lf(e,o);continue}if(!ws(s)){o+=1;continue}const l=t(e,o);if(l!==null&&ac(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Al(e,o);if(e.charCodeAt(c)===On){const u=Al(e,c+1);u>c+1&&e.charCodeAt(u)===qr&&(c=u)}o=e.charCodeAt(c)===qr?Ol(e,o,c,t,n):c}return n},To=(e,t)=>{let n=t;const r=e.charCodeAt(n)===ms;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!ic(l))break;if(s+=1,s>Hd)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Jo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!cc(o))break;if(n-t>=Bd)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)===ms,r=Jo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},cf=(e,t)=>{const n=To(e,t);if(n!==null){const o=xr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===On){const s=To(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)===On){const s=To(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)===On){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},ur=e=>uc(e,cf),dc=(e,t=Vd)=>{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}},Zo=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},$o=e=>`${e.absCol?"$":""}${Zo(e.col)}${e.absRow?"$":""}${e.row+1}`,Cs=e=>e.sheet===void 0?"":`${e.sheet}!`,jt=e=>{const t=Cs(e);switch(e.kind){case"cell":return`${t}${$o(e)}`;case"range":return`${t}${$o(e.start)}:${$o(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Zo(e.start.col)}:${e.end.abs?"$":""}${Zo(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Rn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},af=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Rn(n.startRow,"formatRangeReference startRow"),Rn(n.startCol,"formatRangeReference startCol"),Rn(n.endRow,"formatRangeReference endRow"),Rn(n.endCol,"formatRangeReference endCol"),t){case"columns":return jt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return jt({kind:"row",start:{row:n.startRow,abs:!1},end:{row:n.endRow,abs:!1}});case"cells":return n.startRow===n.endRow&&n.startCol===n.endCol?jt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):jt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},ys=(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?`${Cs(s.token)}${Id}`:l),o=s.end}return r+e.slice(o)},Zr=e=>e.charCodeAt(0)===sc,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}},uf=(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}}}}},fc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Zr(e)?ys(e,ur(e),r=>{const o=uf(r,t,n);return o===null?null:jt(o)}):e},pc=(e,t)=>{Rn(e.row,`${t} origin.row`),Rn(e.col,`${t} origin.col`)},kn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Lo=(e,t)=>`${kn("R",e.row,e.absRow,t.row)}${kn("C",e.col,e.absCol,t.col)}`,df=(e,t)=>{const n=Cs(e);switch(e.kind){case"cell":return`${n}${Lo(e,t)}`;case"range":return`${n}${Lo(e.start,t)}:${Lo(e.end,t)}`;case"column":return`${n}${kn("C",e.start.col,e.start.abs,t.col)}:${kn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${kn("R",e.start.row,e.start.abs,t.row)}:${kn("R",e.end.row,e.end.abs,t.row)}`}},Qr=(e,t)=>(pc(t,"toR1C1"),Zr(e)?ys(e,ur(e),n=>df(n,t)):e),xl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Jr){const l=e.charCodeAt(o+1)===oc,c=Jo(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==lc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Jo(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}}},Tl=(e,t)=>{const n=xl(e,t,tf),r=xl(e,n===null?t:n.end,ef);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},ff=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},pf=(e,t)=>e.shape==="cell"&&t.shape==="cell"?{shape:"cell",start:e.cell,end:t.cell}:e.shape==="row"&&t.shape==="row"?{shape:"row",start:e.row,end:t.row}:e.shape==="column"&&t.shape==="column"?{shape:"column",start:e.col,end:t.col}:null,hf=(e,t)=>{const n=Tl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===On){const r=Tl(e,n.end+1);if(r!==null){const o=pf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:ff(n)}},gf=e=>uc(e,hf),mf=dc(gf),Sn=(e,t)=>e.rel?t+e.n:e.n-1,$l=(e,t)=>{const n=Sn(e.row,t.row),r=Sn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},wf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=$l(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=$l(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=Sn(e.start,t.row),s=Sn(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=Sn(e.start,t.col),s=Sn(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}}}},dr=(e,t)=>(pc(t,"fromR1C1"),Zr(e)?ys(e,mf(e),n=>{const r=wf(n,t);return r===null?null:jt(r)}):e),Dl=(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,...Dl(e.absCol,e.absRow)};case"range":{const t=Dl(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}}}}},hc=(e,t)=>Zr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,gc=(e,t)=>{if(!hc(e,t))return null;for(const n of ur(e))if(n.start<=t&&t<=n.end)return n;return null},yf=(e,t)=>{const n=gc(e,t);if(n===null)return null;const r=jt(Cf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Ll=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===rr){const s=Go(e,r,rr);if(s>t)return!1;n=rr,r=s;continue}of(o)||(n=o),r+=1}return sf(n)},mc=(e,t)=>{if(!hc(e,t))return null;for(const n of ur(e))if(n.start<=t&&t<=n.end)return Ll(e,n.start)?{replace:[n.start,n.end]}:null;return Ll(e,t)?{insertAt:t}:null},Mn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],eo=(e,t)=>`[$${e}-${t}]`,bf=new Map(Mn.map(e=>[eo(e.symbol,e.lcid),e])),vf=new Map(Mn.filter((e,t)=>Mn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Mn.map(e=>[eo(e.symbol,e.lcid),e.code]));const Rf=new Set([...Mn.map(e=>e.symbol),...Mn.map(e=>e.code),"¥"]),kf=20,Sf="yyyy/MM/dd",wc=/yyyy|MM|dd|HH|mm|ss/g,Cc=" -+/():!^&'~{}<>=",Ef="$¥€£₩₹¥",Qo=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},Af=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},Of=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(Cc.includes(o)||Ef.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},at=e=>e===void 0?{}:{locale:e},xf=/^(0|#,##0)(?:\.(0+))?$/,Ml=(e,t,n,r)=>{if(t!==null){const o=bf.get(eo(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Rf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...at(r.locale)}},Tf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const N of e)switch(N.kind){case"locale":break;case"literal":r?u+=N.text:c+=N.text;break;case"digits":if(r)return;n=N.text,r=!0;break;case"currency":if(o!==null)return;o=N;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=xf.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,...at(t.locale)}:void 0;if(l>0)return l===1&&o===null&&q===""&&j===""?{type:"percent",decimals:C,...at(t.locale)}:void 0;if(j==="%"&&q===""&&o===null)return{type:"percent",decimals:C,scale:!1,...at(t.locale)};if(o!==null)return q===""&&j===""?Ml(o.symbol,o.lcid,C,t):void 0;if(!(q!==""&&j!==""))return q!==""||j!==""?Ml(q+j,null,C,t):{type:"number",decimals:C,...g?{grouping:!0}:{},...at(t.locale)}},$f=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Df=(e,t)=>{const n=[...e.matchAll(wc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Lf=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":$f.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Df(r,n)?{type:"date",pattern:r}:void 0},Mf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...at(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...at(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...at(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...at(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...at(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...at(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),bs=(e,t)=>{const n=Af(e).trim(),r=Mf.get(n);if(r!==void 0)return r(t);const o=Of(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Tf(o,t);if(o.some(s=>s.kind==="date"))return Lf(o)}},zf=(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:bs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Zn=e=>e===0?"":`.${"0".repeat(e)}`,_r=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=kf,Ff=`${Cc}.,`,zl=e=>e.includes('"')?null:[...e].every(t=>Ff.includes(t))?e:`"${e}"`,Nf=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(wc)){const u=zl(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=zl(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=bs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Pf=e=>{const t=vf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!_r(n))return null;const r=`#,##0${Zn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${eo(t.symbol,t.lcid)}${r}`},yc=e=>{switch(e.type){case"text":return"@";case"date":return Nf(e.pattern===void 0?Sf:e.pattern);case"number":return _r(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Zn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return _r(t)?e.scale===!1?`0${Zn(t)}"%"`:`0${Zn(t)}%`:null}case"scientific":return _r(e.decimals)?`0${Zn(e.decimals)}E+00`:null;case"currency":return Pf(e);default:return null}},Fl="-−",qf=(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("")},_f=(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=qf(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},jf=(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},If=(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,N="";for(const P of o.slice(0,h))Fl.includes(P)?C+=1:P==="("?q+=1:N+=P;for(const P of o.slice(g))Fl.includes(P)?C+=1:P===")"?j+=1:N+=P;const _=C+q;if(q!==j||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&N.trim()!==""))return e;const Y=_f(o.slice(h,g).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(Y===null)return e;const B=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,L=Y.exponent+B;if(L>330||L<-330)return e;const $=jf(Y.integer,Y.fraction,L,s);return Number.isFinite(Number($))?$:e},Nl="google-sheets-html-origin",bc=Object.freeze({group:",",decimal:"."}),Pl=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"}),vc=["top","right","bottom","left"],Hf=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Bf=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Vf=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),ql=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Wf=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Kf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Yf=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"]),Uf=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Xf=3,Gf=1,Rc=-25569,jr=86400,Jf=-693959,Zf=2958465,Qf=" ",to=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},Kr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},vs=e=>{const t=[];let n="",r=0;for(const o of e)o==="("?r+=1:o===")"&&(r=r>0?r-1:0),r===0&&/\s/.test(o)?n!==""&&(t.push(n),n=""):n+=o;return n!==""&&t.push(n),t},ep=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,tp=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=to(C);for(const j of g.split(",")){const N=j.trim(),_=ep.exec(N);if(_!==null){const Y=t.get(_[1]);if(Y===void 0)t.set(_[1],new Map(q));else for(const[B,L]of q)Y.set(B,L)}else if(N.toLowerCase()==="table"){const Y=q.get("mso-displayed-decimal-separator"),B=q.get("mso-displayed-thousand-separator");Y!==void 0&&(n=Qo(Kr(Y))),B!==void 0&&(r=Qo(Kr(B)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:bc}},np="%_-*? ",rp=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||np.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},op=(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},kc=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}},yn=(e,t)=>String(e).padStart(t,"0"),Sc=e=>{if(e<Jf||e>Zf)return null;let t=Math.floor(e),n=Math.round((e-t)*jr);n>=jr&&(t+=1,n-=jr);const r=kc(t+Rc),o=`${yn(r.year,4)}-${yn(r.month,2)}-${yn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${yn(s,2)}:${yn(l,2)}:${yn(n%60,2)}`},sp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,lp=e=>{const t=sp.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const u=op(n,r,o),h=kc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-Rc+(s*3600+l*60+c)/jr},Rs=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),tn=e=>Rs(e).replaceAll('"',"""),Ec=e=>Rs(e).replaceAll("'","'"),ip=e=>Rs(e).replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const tr=require("./tsv-BHXbWK5W.cjs"),Ge=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),_e=require("./view.cjs"),ss=1e3,Ln=1e4,ls=10,hl=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),is=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/ls):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),Ln))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-hl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+hl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},cs="#000000",Sr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},lu=20,iu=256,Er=new Map,Eo=new WeakMap,tt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},cu=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},au=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:lu}:Sr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Sr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Sr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Sr(e.decimals)};default:return null}},uu=e=>{const t=Eo.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=Er.get(n);if(r!==void 0)return Eo.set(e,r),r;Er.size>=iu&&Er.clear();const o=au(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Er.set(n,s),Eo.set(e,s),s},du=(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}},Li=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>du(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},fu=(e,t)=>{const n=Li(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)}})},Dn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return fu(e,t.pattern??"yyyy/MM/dd");const n=tt(e);if(n===null)return e;const r=uu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?cu(n,-2):n)},gl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Li(n)!==null?"right":"left":tt(n)!==null?"right":"left",nr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Di=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],pu=["bottom","left","right","top"],Mi=(e,t,n)=>{e[t]=n},zi=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},hu=e=>{if(e===void 0)return;const t={};for(const n of pu){const r=e[n];r!==void 0&&(t[n]=zi(r))}return Object.keys(t).length===0?void 0:t},ft=e=>{const t={};for(const n of Di){const r=n==="borders"?hu(e.borders):n==="value"?e.value===void 0?void 0:zi(e.value):e[n];r!==void 0&&r!==!1&&Mi(t,n,r)}return Object.keys(t).length===0?void 0:t},as=(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]||!as(o[c],s[c]))return!1}return!0},gu=(e,t)=>e===t?!0:as(e===void 0?void 0:ft(e),t===void 0?void 0:ft(t)),us=(e,t)=>{const n={};for(const o of Di){const s=t[o];Mi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=ft(n);return as(r,e===void 0?void 0:ft(e))?e:r},Fi="data-aqsp-clip",Kr="application/x-aqsp-clip",Bo=512,ml=16*1024,Vo=`${Fi}=`,mu=16,ds=()=>{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(mu));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},ur=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",Ue=e=>typeof e=="boolean",_t=e=>typeof e=="number"&&Number.isFinite(e),dt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,wl=e=>dt(e)&&e>=1,wu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Ln,At=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Cu=e=>t=>Array.isArray(t)&&t.every(e),Oe=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),xt=(e,t)=>{if(!ur(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},fs=e=>t=>{if(!ur(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&xt(t,n)},yu=["left","center","right"],bu=["top","middle","bottom"],Ru=["thin","medium","thick","dashed","dotted","double","hair"],Ao=["gt","gte","lt","lte","eq","neq","between","notBetween"],vu=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],ku=["eq","neq","gt","gte","lt","lte","between","notBetween"],Su=["contains","notContains","startsWith","endsWith"],Eu=new Map([["number",Oe({type:le,decimals:_t,grouping:Ue,locale:le},["type"])],["percent",Oe({type:le,decimals:_t,scale:Ue,locale:le},["type"])],["currency",Oe({type:le,currency:le,decimals:_t,locale:le},["type","currency"])],["scientific",Oe({type:le,decimals:_t,locale:le},["type"])],["date",Oe({type:le,pattern:le},["type"])],["text",Oe({type:le},["type"])]]),Au=Oe({style:At(Ru),color:le},["style"]),Ar=e=>xt(e,Au),Ou=Oe({top:Ar,right:Ar,bottom:Ar,left:Ar},[]),xu=Oe({value:fs(Eu),align:At(yu),verticalAlign:At(bu),wrap:Ue,background:le,color:le,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue,fontFamily:le,fontSize:_t,borders:e=>xt(e,Ou)},[]),Tu=e=>xt(e,xu),en={strict:Ue,inputMessage:le,errorMessage:le},$u=new Map([["list",Oe({...en,type:le,values:Cu(le),showDropdown:Ue},["type","values"])],["number",Oe({...en,type:le,op:At(Ao),a:le,b:le},["type","op","a"])],["textLength",Oe({...en,type:le,op:At(Ao),a:_t,b:_t},["type","op","a"])],["date",Oe({...en,type:le,op:At(Ao),a:le,b:le},["type","op","a"])],["text",Oe({...en,type:le,op:At(vu),value:le},["type","op"])],["checkbox",Oe({...en,type:le,checked:le,unchecked:le},["type"])],["custom",Oe({...en,type:le,formula:le},["type","formula"])]]),Lu=fs($u),Du=Oe({startRow:dt,startCol:dt,endRow:dt,endCol:dt},["startRow","startCol","endRow","endCol"]),Mu=e=>{if(!xt(e,Du))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return dt(t)&&dt(r)&&dt(n)&&dt(o)&&t<=r&&n<=o},zu=Oe({color:le,value:_t},["color"]),Oo=e=>xt(e,zu),Fu=new Map([["cellValue",Oe({type:le,op:At(ku),a:le,b:le},["type","op","a"])],["text",Oe({type:le,op:At(Su),value:le},["type","op","value"])],["empty",Oe({type:le},["type"])],["notEmpty",Oe({type:le},["type"])],["colorScale",Oe({type:le,min:Oo,mid:Oo,max:Oo},["type","min","max"])],["customFormula",Oe({type:le,formula:le},["type","formula"])]]),Nu=Oe({background:le,color:le,bold:Ue,italic:Ue,underline:Ue,strikethrough:Ue},[]),Pu=Oe({sourceRuleId:le,ranges:Array.isArray,condition:fs(Fu),style:e=>xt(e,Nu),stopIfTrue:Ue},["sourceRuleId","ranges","condition","style"]),qu=(e,t,n)=>{if(!xt(e,Pu))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Mu(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},_u=Oe({text:le,author:le,createdAt:le},["text","author","createdAt"]),ju=e=>xt(e,_u),Iu=(e,t,n)=>{if(!ur(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(!dt(o)||o>=t)return!1;break;case"val":if(!dt(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(ju)))return!1;break;default:return!1}}return!0},Cl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(wu),Hu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Ni=e=>{if(!ur(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Hu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(wl(t)&&wl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Tu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Lu)))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(!Iu(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Cl(e.colWidths,n)||e.rowHeights!==void 0&&!Cl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>qu(c,t,n))},ir=e=>Array.isArray(e)?`[${e.map(ir).join(",")}]`:ur(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${ir(e[n])}`).join(",")}}`:JSON.stringify(e),Bu=e=>{const t=ft(e);return t===void 0?"{}":JSON.stringify(t)},Vu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Wu=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(Vu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Pi=e=>{if(!Ni(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(Bu).join(","),r=e.validations.map(ir).join(","),o=e.cells.map(u=>`[${u.map(Wu).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(ir).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Wo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Ni(t)?t:null},Ku=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Yu=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),qi=e=>e.includes("&")?e.replace(Ku,t=>Yu[t]):e,Uu=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,yl=e=>{const t=e.length>Bo?e.slice(0,Bo):e,n=Uu.exec(qi(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Xu=e=>{const t=e.indexOf(Vo);if(t===-1)return null;const n=t+Vo.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},_i=(e,t)=>{if(t==="event"&&e.types.includes(Kr))return{kind:"mime",json:e.getData(Kr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Xu(n);return r===null?null:{kind:"attribute",html:n,at:r}},Gu=(e,t)=>{const n=_i(e,t);return n===null?null:n.kind==="mime"?yl(n.json):yl(n.html.slice(n.at.start,n.at.start+Bo))},Zu=(e,t)=>{const n=_i(e,t);if(n===null)return null;if(n.kind==="mime")return Wo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Wo(qi(n.html.slice(n.at.start,r)))},Ju=/<google-sheets-html-origin[\s>]/,Qu='data-sheets-root="1"',ed=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,td="mso-",nd=/\.xl\d+\s*\{/,rd="<table",od=e=>e.includes(Vo)?"aqsp":Ju.test(e)&&e.includes(Qu)?"sheets":ed.test(e)||e.includes(td)||nd.test(e)?"excel":null,ji=(e,t)=>{if(t==="event"&&e.types.includes(Kr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>ml?n.slice(0,ml):n,o=od(r);if(o==="aqsp")return"aqsp";if(n.includes(rd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},ps=1e3,Ii=65534,sd=9,ld=10,id=12,cd=13,ad=32,Hi=34,Bi=39,ud=43,hs=47,bl=48,dd=57,fd=61,pd=62,hd=97,gd=98,md=100,wd=102,Vi=104,Wi=114,Ki=116,Cd=["able","body","head","foot"],rr=e=>e===ad||e===sd||e===ld||e===cd||e===id,Ko=e=>e===pd||e===hs||rr(e),yd=e=>rr(e)||e===hs||e===Hi||e===Bi,bd=(e,t,n,r)=>{if(t===0||!yd(e.charCodeAt(t-1)))return null;let o=t+n;for(;rr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==fd)return 1;for(o+=1;rr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Hi||s===Bi)&&(o+=1);rr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===ud&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=bl&&u<=dd;u=e.charCodeAt(o))l=l*10+(u-bl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Rl=(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=bd(e,r,t.length,n);if(l!==null)return l}return 1}},Rd=(e,t)=>{if(e.charCodeAt(t+2)!==Ki)return!1;const n=e.charCodeAt(t+3);if(n===Wi)return Ko(e.charCodeAt(t+4));if(n!==hd&&n!==gd&&n!==Vi&&n!==wd)return!1;for(const r of Cd)if(e.startsWith(r,t+3)&&Ko(e.charCodeAt(t+3+r.length)))return!0;return!1},vd=e=>{const t=e.toLowerCase(),n=Rl(t,"colspan",ps),r=Rl(t,"rowspan",Ii);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,g=!1;const C=new Map,q=(_,Y)=>{const B=C.get(_);C.set(_,B===void 0?Y:B+Y)},j=()=>{g&&u+h>c&&(c=u+h),g=!1},N=()=>{j(),l+=1,g=!0,u=0;const _=C.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const Y=t.charCodeAt(_+1);if(Y===hs){Rd(t,_)&&j();continue}if(Y!==Ki||!Ko(t.charCodeAt(_+3)))continue;const B=t.charCodeAt(_+2);if(B===Wi)N();else if(B===md||B===Vi){g||N();const D=_+3,$=s(D),P=n(D,$);u+=P;const k=r(D,$);k>1&&(q(l,P),q(l-1+k,-P))}}return j(),{rows:l,cols:c}},Yi=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}},Ui=()=>{const e=new WeakMap,t=Yi(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=ft(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},kd=()=>{const e=new WeakMap,t=Yi(ir);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}},Sd=new Set(["http:","https:","mailto:","tel:"]),Bt=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Sd.has(n.protocol)?n.href:null},Fn=e=>{if(e===void 0)return;const t=Bt(e);return t===null?void 0:t},Xi=(e,t)=>e.startCol===0&&e.endCol===t-1,Gi=(e,t)=>e.startRow===0&&e.endRow===t-1,Yo=13,Et=Object.freeze({style:Object.freeze({}),lineBoxPx:Yo,verticalAlign:"middle"}),Ed={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"},Ad=new Map(Object.entries(Ed)),Od=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,xd=/^rgba?\((.*)\)$/,Zi=/^(\d+(?:\.\d+)?)%$/,Or=e=>e.toString(16).padStart(2,"0"),xo=e=>{const t=Zi.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},Td=e=>{const t=Zi.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},$d=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=xo(t[0]),r=xo(t[1]),o=xo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Or(n)}${Or(r)}${Or(o)}`;if(t.length===3)return s;const l=Td(t[3]);return l===null?null:l===255?s:`${s}${Or(l)}`},Xe=e=>{const t=e.trim().toLowerCase(),n=Od.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=xd.exec(t);if(r!==null)return $d(r[1]);const o=Ad.get(t);return o===void 0?null:o},vl={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"}},kl=e=>{if(!Object.hasOwn(vl,e.style))return null;const t=vl[e.style],n=e.color===void 0?cs:Xe(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Ld={top:"flex-start",middle:"center",bottom:"flex-end"},Dd=e=>e==="left"||e==="center"||e==="right",Ji=e=>e==="top"||e==="middle"||e==="bottom",Qi=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,ec=(e,t)=>{if(typeof e.background=="string"){const s=Xe(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Xe(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=Qi(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},xr=(e,t)=>{const n=e===void 0?null:kl(e);return n!==null?n:t===void 0?null:kl(t)},To=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Dd(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=nr(e.align)),Ji(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Ld[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),ec(e,s));const c=e?.borders,u=xr(c?.right,t);u!==null&&(s.borderRight=u);const h=xr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const g=xr(c?.left,void 0);g!==null&&(s.borderLeft=g)}if(o){const g=xr(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)})},Sl=new WeakMap,Md=(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:To(void 0,s,l,r,o);if(!c)return To(e,s,l,r,o);const u=Sl.get(e);if(u!==void 0)return u;const h=To(e,void 0,void 0,!1,!1);return Sl.set(e,h),h},zd=e=>{if(e===void 0)return Et;const t={};ec(e,t);const n=Qi(e.fontSize),r=n===null?Yo:Math.round(n),o=Ji(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Yo&&o==="middle"?Et:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Fd="#REF!",Nd=11,Pd=15,qd=4096,_r=33,or=34,gs=36,_d=38,Uo=39,tc=40,jd=42,Id=43,Hd=44,nc=45,Bd=46,Vd=47,On=58,Wd=59,Kd=60,rc=61,Yd=62,Ud=67,Xd=82,Jr=91,oc=93,Gd=94,Zd=95,sc=e=>e>=65&&e<=90||e>=97&&e<=122,lc=e=>e>=48&&e<=57,ms=e=>sc(e)||lc(e)||e===Zd||e===Bd||e===gs||e>=128,Jd=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,Qd=e=>e===rc||e===tc||e===Hd||e===Wd||e===Id||e===nc||e===jd||e===Vd||e===Gd||e===_d||e===Kd||e===Yd||e===On,ic=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(ms(n)||n===tc||n===_r||n===Jr)},El=(e,t)=>{let n=t;for(;n<e.length&&ms(e.charCodeAt(n));)n+=1;return n},Xo=(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},ef=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Uo){r+=2;continue}if(o===Jr)n+=1;else if(o===oc&&(n-=1,n===0))return r+1;r+=1}return e.length},Al=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&ic(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},cc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===or){o=Xo(e,o,or);continue}if(s===Uo){const u=Xo(e,o,Uo);o=e.charCodeAt(u)===_r?Al(e,o,u,t,n):u;continue}if(s===Jr){o=ef(e,o);continue}if(!ms(s)){o+=1;continue}const l=t(e,o);if(l!==null&&ic(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=El(e,o);if(e.charCodeAt(c)===On){const u=El(e,c+1);u>c+1&&e.charCodeAt(u)===_r&&(c=u)}o=e.charCodeAt(c)===_r?Al(e,o,c,t,n):c}return n},$o=(e,t)=>{let n=t;const r=e.charCodeAt(n)===gs;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!sc(l))break;if(s+=1,s>Nd)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Go=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!lc(o))break;if(n-t>=Pd)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Tr=(e,t)=>{const n=e.charCodeAt(t)===gs,r=Go(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},tf=(e,t)=>{const n=$o(e,t);if(n!==null){const o=Tr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===On){const s=$o(e,o.end+1);if(s!==null){const l=Tr(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)===On){const s=$o(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=Tr(e,t);if(r!==null&&e.charCodeAt(r.end)===On){const o=Tr(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},dr=e=>cc(e,tf),ac=(e,t=qd)=>{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}},Zo=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},Lo=e=>`${e.absCol?"$":""}${Zo(e.col)}${e.absRow?"$":""}${e.row+1}`,ws=e=>e.sheet===void 0?"":`${e.sheet}!`,jt=e=>{const t=ws(e);switch(e.kind){case"cell":return`${t}${Lo(e)}`;case"range":return`${t}${Lo(e.start)}:${Lo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Zo(e.start.col)}:${e.end.abs?"$":""}${Zo(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}`)},nf=(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 jt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return jt({kind:"row",start:{row:n.startRow,abs:!1},end:{row:n.endRow,abs:!1}});case"cells":return n.startRow===n.endRow&&n.startCol===n.endCol?jt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):jt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Cs=(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?`${ws(s.token)}${Fd}`:l),o=s.end}return r+e.slice(o)},Qr=e=>e.charCodeAt(0)===rc,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}},rf=(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}}}}},uc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Qr(e)?Cs(e,dr(e),r=>{const o=rf(r,t,n);return o===null?null:jt(o)}):e},dc=(e,t)=>{vn(e.row,`${t} origin.row`),vn(e.col,`${t} origin.col`)},kn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Mo=(e,t)=>`${kn("R",e.row,e.absRow,t.row)}${kn("C",e.col,e.absCol,t.col)}`,of=(e,t)=>{const n=ws(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}${kn("C",e.start.col,e.start.abs,t.col)}:${kn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${kn("R",e.start.row,e.start.abs,t.row)}:${kn("R",e.end.row,e.end.abs,t.row)}`}},eo=(e,t)=>(dc(t,"toR1C1"),Qr(e)?Cs(e,dr(e),n=>of(n,t)):e),Ol=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Jr){const l=e.charCodeAt(o+1)===nc,c=Go(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==oc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Go(e,o);return s===null?{end:o,axis:{rel:!0,n:0}}:s.value===0?null:{end:s.end,axis:{rel:!1,n:s.value}}},xl=(e,t)=>{const n=Ol(e,t,Xd),r=Ol(e,n===null?t:n.end,Ud);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}},sf=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}}},lf=(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,cf=(e,t)=>{const n=xl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===On){const r=xl(e,n.end+1);if(r!==null){const o=lf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:sf(n)}},af=e=>cc(e,cf),uf=ac(af),Sn=(e,t)=>e.rel?t+e.n:e.n-1,Tl=(e,t)=>{const n=Sn(e.row,t.row),r=Sn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},df=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Tl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Tl(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=Sn(e.start,t.row),s=Sn(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=Sn(e.start,t.col),s=Sn(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}}}},fr=(e,t)=>(dc(t,"fromR1C1"),Qr(e)?Cs(e,uf(e),n=>{const r=df(n,t);return r===null?null:jt(r)}):e),$l=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},ff=e=>{switch(e.kind){case"cell":return{...e,...$l(e.absCol,e.absRow)};case"range":{const t=$l(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}}}}},fc=(e,t)=>Qr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,pc=(e,t)=>{if(!fc(e,t))return null;for(const n of dr(e))if(n.start<=t&&t<=n.end)return n;return null},pf=(e,t)=>{const n=pc(e,t);if(n===null)return null;const r=jt(ff(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Ll=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===or){const s=Xo(e,r,or);if(s>t)return!1;n=or,r=s;continue}Jd(o)||(n=o),r+=1}return Qd(n)},hc=(e,t)=>{if(!fc(e,t))return null;for(const n of dr(e))if(n.start<=t&&t<=n.end)return Ll(e,n.start)?{replace:[n.start,n.end]}:null;return Ll(e,t)?{insertAt:t}:null},Mn=[{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}],to=(e,t)=>`[$${e}-${t}]`,hf=new Map(Mn.map(e=>[to(e.symbol,e.lcid),e])),gf=new Map(Mn.filter((e,t)=>Mn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Mn.map(e=>[to(e.symbol,e.lcid),e.code]));const mf=new Set([...Mn.map(e=>e.symbol),...Mn.map(e=>e.code),"¥"]),wf=20,Cf="yyyy/MM/dd",gc=/yyyy|MM|dd|HH|mm|ss/g,mc=" -+/():!^&'~{}<>=",yf="$¥€£₩₹¥",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},bf=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},Rf=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(mc.includes(o)||yf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ut=e=>e===void 0?{}:{locale:e},vf=/^(0|#,##0)(?:\.(0+))?$/,Dl=(e,t,n,r)=>{if(t!==null){const o=hf.get(to(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!mf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ut(r.locale)}},kf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const N of e)switch(N.kind){case"locale":break;case"literal":r?u+=N.text:c+=N.text;break;case"digits":if(r)return;n=N.text,r=!0;break;case"currency":if(o!==null)return;o=N;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=vf.exec(n);if(h===null)return;const g=h[1]==="#,##0",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,...ut(t.locale)}:void 0;if(l>0)return l===1&&o===null&&q===""&&j===""?{type:"percent",decimals:C,...ut(t.locale)}:void 0;if(j==="%"&&q===""&&o===null)return{type:"percent",decimals:C,scale:!1,...ut(t.locale)};if(o!==null)return q===""&&j===""?Dl(o.symbol,o.lcid,C,t):void 0;if(!(q!==""&&j!==""))return q!==""||j!==""?Dl(q+j,null,C,t):{type:"number",decimals:C,...g?{grouping:!0}:{},...ut(t.locale)}},Sf=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Ef=(e,t)=>{const n=[...e.matchAll(gc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Af=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":Sf.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Ef(r,n)?{type:"date",pattern:r}:void 0},Of=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ut(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ut(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ut(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ut(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ut(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ut(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),ys=(e,t)=>{const n=bf(e).trim(),r=Of.get(n);if(r!==void 0)return r(t);const o=Rf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return kf(o,t);if(o.some(s=>s.kind==="date"))return Af(o)}},xf=(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:ys(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Jn=e=>e===0?"":`.${"0".repeat(e)}`,jr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=wf,Tf=`${mc}.,`,Ml=e=>e.includes('"')?null:[...e].every(t=>Tf.includes(t))?e:`"${e}"`,$f=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(gc)){const u=Ml(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=Ml(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=ys(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Lf=e=>{const t=gf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!jr(n))return null;const r=`#,##0${Jn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${to(t.symbol,t.lcid)}${r}`},wc=e=>{switch(e.type){case"text":return"@";case"date":return $f(e.pattern===void 0?Cf:e.pattern);case"number":return jr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Jn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return jr(t)?e.scale===!1?`0${Jn(t)}"%"`:`0${Jn(t)}%`:null}case"scientific":return jr(e.decimals)?`0${Jn(e.decimals)}E+00`:null;case"currency":return Lf(e);default:return null}},zl="-−",Df=(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("")},Mf=(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=Df(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},zf=(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},Ff=(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,N="";for(const P of o.slice(0,h))zl.includes(P)?C+=1:P==="("?q+=1:N+=P;for(const P of o.slice(g))zl.includes(P)?C+=1:P===")"?j+=1:N+=P;const _=C+q;if(q!==j||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&N.trim()!==""))return e;const Y=Mf(o.slice(h,g).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(Y===null)return e;const B=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,D=Y.exponent+B;if(D>330||D<-330)return e;const $=zf(Y.integer,Y.fraction,D,s);return Number.isFinite(Number($))?$:e},Fl="google-sheets-html-origin",Cc=Object.freeze({group:",",decimal:"."}),Nl=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"}),yc=["top","right","bottom","left"],Nf=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Pf=new Set(["windowtext","currentcolor","inherit","initial","unset"]),qf=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"]),Pl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],_f=Object.freeze({number:2,percent:3,currency:4,scientific:8}),jf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),If=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"]),Hf=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Bf=3,Vf=1,bc=-25569,Ir=86400,Wf=-693959,Kf=2958465,Yf=" ",no=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},Yr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},bs=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},Uf=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Xf=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=no(C);for(const j of g.split(",")){const N=j.trim(),_=Uf.exec(N);if(_!==null){const Y=t.get(_[1]);if(Y===void 0)t.set(_[1],new Map(q));else for(const[B,D]of q)Y.set(B,D)}else if(N.toLowerCase()==="table"){const Y=q.get("mso-displayed-decimal-separator"),B=q.get("mso-displayed-thousand-separator");Y!==void 0&&(n=Jo(Yr(Y))),B!==void 0&&(r=Jo(Yr(B)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Cc}},Gf="%_-*? ",Zf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Gf.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Jf=(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},Rc=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}},yn=(e,t)=>String(e).padStart(t,"0"),vc=e=>{if(e<Wf||e>Kf)return null;let t=Math.floor(e),n=Math.round((e-t)*Ir);n>=Ir&&(t+=1,n-=Ir);const r=Rc(t+bc),o=`${yn(r.year,4)}-${yn(r.month,2)}-${yn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${yn(s,2)}:${yn(l,2)}:${yn(n%60,2)}`},Qf=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,ep=e=>{const t=Qf.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=Jf(n,r,o),h=Rc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-bc+(s*3600+l*60+c)/Ir},Rs=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),tn=e=>Rs(e).replaceAll('"',"""),kc=e=>Rs(e).replaceAll("'","'"),tp=e=>Rs(e).replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).replaceAll("\r",`
|
|
4
4
|
`).replaceAll(`
|
|
5
|
-
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),
|
|
5
|
+
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),Hr=(e,t)=>`${e}="${tn(JSON.stringify(t))}"`,Sc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",np=e=>{if(tt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},rp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},op=e=>{if(e.type==="text")return{1:1};const t=wc(e);return t===null?null:{1:e.type==="date"?rp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):_f[e.type],2:t,3:1}},sp=/[;"'{}<>&\\]/,Ec=e=>e==="left"||e==="center"||e==="right",Ac=e=>e==="top"||e==="middle"||e==="bottom",lp=e=>{const t=[];e.bold===!0&&t.push("font-weight:bold"),e.italic===!0&&t.push("font-style:italic");const n=[...e.underline===!0?["underline"]:[],...e.strikethrough===!0?["line-through"]:[]];n.length>0&&t.push(`text-decoration:${n.join(" ")}`);const r=typeof e.color=="string"?Xe(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Xe(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Ec(e.align)&&t.push(`text-align:${e.align}`),Ac(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!sp.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 yc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(Nl,l.style))continue;const c=l.color===void 0?"windowtext":Xe(l.color);c!==null&&t.push(`border-${s}:${Nl[l.style]} ${c}`)}if(e.value!==void 0){const s=wc(e.value);s!==null&&t.push(`mso-number-format:"${Zf(s)}"`)}return t},ip={value:void 0,style:"white-space:pre",numberFormatAttribute:null},cp=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=kc([n,...lp(e)].join(";"));let o=null;if(t!==void 0){const s=op(t);s!==null&&(o=Hr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},ap=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Dn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Sc(o)?np(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?ep(e.t):null,h=[];if(l?h.push(Hr("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(Hr("data-sheets-value",{1:3,3:c})):u!==null&&h.push(Hr("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${tn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${tn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${tn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${tn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const q=fr(e.f,{row:n,col:r});q.includes("#REF!")||h.push(`x:fmla="${tn(q)}"`)}const g=tp(s),C=e.link===void 0?g:`<a href="${tn(e.link)}">${g}</a>`;return`<td style='${t.style}'${h.map(q=>` ${q}`).join("")}>${C}</td>`},Oc=(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(cp);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+=ap(h,g===void 0?ip:g,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Fl}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Fi}='${kc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Fl}>`},Qo=(e,t)=>{for(const[n,r]of t)e.set(n,r)},xc=(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&&Qo(n,l)}const o=e.getAttribute("style");return o!==null&&Qo(n,no(o)),n},up=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"}},dp=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"},fp=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),pp={pt:1.5,unit:"px"},ql=e=>{let t=null,n=null;const r=[];for(const u of bs(e)){const h=u.toLowerCase(),g=up(u);Nf.has(h)?n=h:g!==null?t=g:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=fp.get(n),s=o===void 0?dp(t===null?pp:t):o,l=r.join(" ");if(l===""||Pf.has(l.toLowerCase()))return{style:s};const c=Xe(l);return c===null||c.length===9?null:{style:s,color:c}},hp=e=>e.style==="thin"&&e.color==="#cccccc",gp=e=>{const t=Xe(e);if(t!==null)return t;for(const n of bs(e)){const r=Xe(n);if(r!==null)return r}return null},mp=e=>{const t=Yr(bs(e.split(",")[0]).join(" ").trim()).trim();return t===""||qf.has(t.toLowerCase())?null:t},wp=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},Cp=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},yp=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"},bp=new Set(["normal","pre-wrap","pre-line"]),Rp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const S=o.toLowerCase();(S==="bold"||S==="bolder"||Number(S)>=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=Cp(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:Xe(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),g=h===void 0?null:gp(h);g!==null&&g.length!==9&&(r.background=g);const C=e.get("text-align"),q=C===void 0?"":C.toLowerCase();Ec(q)&&(r.align=q);const j=e.get("vertical-align"),N=j===void 0?"":j.toLowerCase();Ac(N)&&(r.verticalAlign=N);const _=e.get("font-family"),Y=_===void 0?null:mp(_);Y!==null&&(r.fontFamily=Y);const B=e.get("font-size"),D=B===void 0?null:wp(B);D!==null&&(r.fontSize=D);const $=e.get("white-space");$!==void 0&&bp.has($.toLowerCase())&&(r.wrap=!0);const P={},k=e.get("border"),R=k===void 0?null:ql(k);for(const S of yc){const p=e.get(`border-${S}`),m=p===void 0?R:ql(p);m!==null&&!(n==="sheets"&&hp(m))&&(P[S]=m)}return Object.keys(P).length>0&&(r.borders=P),r},_l=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
6
|
`)&&(e.text+=`
|
|
7
|
-
`)},
|
|
8
|
-
`);continue}if(o.nodeType!==
|
|
9
|
-
`;continue}const c=t.mode==="collapse"&&
|
|
7
|
+
`)},vp=e=>{const t=e.getAttribute("style");return t!==null&&no(t).get("mso-spacerun")==="yes"},kp=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Hf.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&_l(t);continue}const o=r.node;if(o.nodeType===Bf){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!==Vf)continue;const s=o,l=s.localName;if(jf.has(l)||vp(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&If.has(l);if(c&&_l(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})}},Sp=(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&&Ap(l.element,t,n,r)},Ep=(e,t)=>{const n=e.replaceAll(Yf," ");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
|
-
`)},Lp=(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)}es(t,$c(e,r))},Mp=(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"?Sc(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<ql.length?ql[l]:null}return null},Dc=(e,t,n)=>t!==void 0&&Ac(t)?If(e,t,n):e,zp=(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=Sc(Number(c));if(u!==null)return u}else return c;return Dc(t,n,r)},Fp=(e,t,n,r)=>{const o=$c(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Ep(o)};for(const g of _p(e))Tp(g,l);$p(l,o,s,r.rules);const c=Dp(l.text,l.mode),u=Op(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),C=g===null?void 0:zf(g,r.options);C!==void 0&&(u.value=C);const q=e.getAttribute("data-sheets-value"),j=q===null?null:Mp(q,C);h.t=j===null?Dc(c,C,bc):j;const N=e.getAttribute("data-sheets-formula");N?.startsWith("=")&&(h.f=N);const _=e.getAttribute("data-sheets-hyperlink"),Y=_!==null?_:l.href,B=Y===null?null:Bt(Y);B!==null&&(h.link=B);const L=e.getAttribute("data-sheets-note");L!==null&&L!==""&&(h.note=L)}else{const g=o.get("mso-number-format"),C=g===void 0?void 0:bs(Qo(Kr(g)),r.options);C!==void 0&&(u.value=C),h.t=zp(e,c,C,r.separators);const q=e.getAttribute("x:fmla");q?.startsWith("=")&&(h.f=Qr(q,{row:t,col:n}));const j=l.href===null?null:Bt(l.href);j!==null&&(h.link=j)}return{cell:h,format:u}},ts=(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},Np=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)},Pp=(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]))},Lc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:to(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:Np(l);if(c!==null)return Math.min(c,Dn)}const o=Pp(e,t);return o===null?null:Math.min(o,Dn)},qp=(e,t)=>{const n=[],r=o=>{const s=Lc(o,"width");for(let l=ts(o,"span",hs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of ir(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of ir(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*ir(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*_p(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*jp(e){for(const t of["thead","tbody","tfoot"])for(const n of ir(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of ir(n))o.localName==="tr"&&(yield o)}}const Mo=()=>({t:""}),Ip=(e,t,n)=>{const r=Gi(),o=[],s=[],l=[];let c=0;for(const j of jp(e)){const N=o.length,_=(N+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const Y=[];for(let L=0;L<l.length;L+=1)l[L]>0&&(Y[L]=Mo(),l[L]-=1);let B=0;for(const L of ir(j)){const $=L.localName;if($!=="td"&&$!=="th")continue;for(;Y[B]!==void 0;)B+=1;const P=ts(L,"colspan",hs),k=ts(L,"rowspan",Bi),v=(N+1)*Math.max(c,B+P);if(v>n)return{outcome:"limit",cells:v};const S=Fp(L,N,B,t),p=r.intern(S.format);p!==void 0&&(S.cell.fmt=p),Y[B]=S.cell;for(let m=1;m<P;m+=1)Y[B+m]===void 0&&(Y[B+m]=Mo());if(k>1)for(let m=0;m<P;m+=1){const y=k-1,D=B+m;l[D]=l[D]===void 0||l[D]<y?y:l[D]}B+=P}Y.length>c&&(c=Y.length),o.push(Y),s.push(Lc(j,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(j=>{const N=[];for(let _=0;_<c;_+=1){const Y=j[_];N.push(Y===void 0?Mo():Y)}return N}),h=qp(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:fs(),formats:[...r.entries],validations:[],cells:u,...g===void 0?{}:{colWidths:g},...C===void 0?{}:{rowHeights:C},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Mc=(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=tp(o);return Ip(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Ce=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),cn=(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}),yt=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)}},Ot=(e,t)=>e.row===t.row&&e.col===t.col,zc=(e,t)=>e===void 0?ml(void 0,void 0,t()):ml(e.align,e.value,e.align===void 0?t():""),Hr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},zn=(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}},Br=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}),Fc=e=>e.isCellReadOnly!==void 0,We=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Hp=/^data-[a-z0-9-]+$/,Bp=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Vp=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Bp(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(!Hp.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},Qn=(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},En=(e,t)=>{for(const n of t)if(Qn(e,n))return!0;return!1},Wp=(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},ns=(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:Ce(g,{row:g.row+C-1,col:g.col+q-1})},Nc=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=ns({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 N=[];for(let Y=0;Y<C;Y+=c){const B={row:h.row+j,col:h.col+Y};N.push(B),q.push(B)}const _=Math.min(l,g-j);for(let Y=0;Y<_;Y+=1){const B=h.row+j+Y,L=e[Y];for(let $=0;$<N.length;$+=1){const P=$*c,k=Math.min(c,C-P);for(let v=0;v<k;v+=1)s(B,h.col+P+v,L[v],N[$])}}}return q},Kp=(e,t,n,r,o)=>{const s=[];return Nc(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},Il=(e,t,n,r,o,s)=>{const l=[],c=Nc(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}},Pc=(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)})`)},Yp=(e,t)=>{Pc(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},Up=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(Ce({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Ce({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Ce({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Ce({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Xp=(e,t,n,r)=>{Pc(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 N=c.get(j);N===void 0&&(N={value:e(h,q),origin:{row:h,col:q}},c.set(j,N)),l.push(r(N.value,N.origin,{row:u,col:C}))}}return l},qc=(e,t,n)=>{const r=zn(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:ft(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=Fn(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?fc(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},jc=e=>`${e.map(t=>t.map(Gp).join(" ")).join(`\r
|
|
13
|
-
`)}\r
|
|
14
|
-
`,Gp=e=>/[\t\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e,Ic=e=>e.endsWith(`\r
|
|
15
|
-
`)?e.slice(0,-2):e.endsWith(`
|
|
16
|
-
`)||e.endsWith("\r")?e.slice(0,-1):e,Hc=(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=Hl(e,r);o=e.slice(r,l),r=l}}else{const s=Hl(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())}},Bc=e=>{const t=Ic(e);if(t==="")return[[""]];const n=[];let r=[];Hc(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=Ic(e);if(t==="")return{rows:1,cols:1};let n=0,r=0,o=0;return Hc(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},Hl=(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},or=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},Qp=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},no=["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"],eh=/^[A-Z]$/,th=/^[A-Za-z]$/,nh=/^Key([A-Z])$/,Vc=new Set([...Array.from({length:10},(e,t)=>`Digit${t}`),...Array.from({length:10},(e,t)=>`Numpad${t}`),"NumpadAdd","NumpadSubtract","NumpadMultiply","NumpadDivide","NumpadDecimal","NumpadEnter",...Array.from({length:12},(e,t)=>`F${t+1}`),"Semicolon","Quote","Comma","Period","Slash","Backslash","BracketLeft","BracketRight","Backquote","Minus","Equal","IntlYen","IntlRo","IntlBackslash","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),rh=e=>eh.test(e)||Vc.has(e),nn=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!rh(l))throw new RangeError(`[spreadsheet] shortcut ${JSON.stringify(e)} is not canonical (expected Ctrl+Alt+Shift+KEY with used modifiers only, KEY = A-Z or a code name such as Digit1 / Semicolon / F2)`);return{ctrl:r,alt:o,shift:s,key:l}},oh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Wc=e=>{if(th.test(e.key))return e.key.toUpperCase();const t=nh.exec(e.code);return t!==null?t[1]:Vc.has(e.code)?e.code:null},Yn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Wc(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),be=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),sh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},lh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},fr=[...sh(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...lh(),be("bold","Ctrl+B","both","toggle bold"),be("italic","Ctrl+I","both","toggle italic"),be("underline","Ctrl+U","both","toggle underline"),be("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),be("clearFormatting","Ctrl+Backslash","idle","clear formatting"),be("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),be("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),be("alignLeft","Ctrl+Shift+L","both","align left"),be("alignCenter","Ctrl+Shift+E","both","align center"),be("alignRight","Ctrl+Shift+R","both","align right"),be("formatNumber","Ctrl+Shift+Digit1","both","number format"),be("formatTime","Ctrl+Shift+Digit2","both","time format"),be("formatDate","Ctrl+Shift+Digit3","both","date format"),be("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),be("formatPercent","Ctrl+Shift+Digit5","both","percent format"),be("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),be("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),be("bordersClear","Alt+Shift+Digit6","idle","clear borders"),be("borderTop","Alt+Shift+Digit1","idle","top border"),be("borderRight","Alt+Shift+Digit2","idle","right border"),be("borderBottom","Alt+Shift+Digit3","idle","bottom border"),be("borderLeft","Alt+Shift+Digit4","idle","left border"),be("insertLink","Ctrl+K","idle","insert / edit hyperlink"),be("insertNote","Shift+F2","idle","insert / edit note"),be("insertComment","Ctrl+Alt+M","idle","insert comment"),be("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),be("openValidationList","Alt+ArrowDown","idle","open the validation list"),be("fillDown","Ctrl+D","idle","fill down"),be("fillRight","Ctrl+R","idle","fill right"),be("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),be("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),be("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),be("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),be("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),be("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],Yr=(e,t)=>e.column==="both"||e.column===t,ih=Array.from(new Set(fr.filter(e=>!e.rebindable&&Yr(e,"idle")).map(e=>e.chord))),ks=new Set(fr.filter(e=>e.command!==void 0&&Yr(e,"editing")).map(e=>e.command)),ch=new Set(fr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Kc=e=>{const t={};for(const n of no)t[n]=e(n);return t},Yc=Kc(e=>fr.filter(t=>t.command===e).map(t=>t.chord)),ah=e=>{const t=new Map;for(const n of no){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},uh=e=>{const t=new Set(no);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(ch.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`)}}}},dh=(e,t)=>{const n=nn(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=ks.has(e);for(const o of fr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Yr(o,"idle")||r&&Yr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},fh=e=>{e!==void 0&&uh(e);const t=Kc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Yc[r]:o===null?[]:o});for(const r of no)for(const o of t[r])dh(r,o);const n=new Map;for(const[r,o]of ah(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},Bl=(e,t)=>{const n=Wc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(oh({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},Ss=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],Vl=[...Xe.VIRTUAL_SCROLL_LABEL_KEYS,...Ss],rs=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),Uc=Object.freeze({en:Object.freeze({...Xe.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...rs.en}),ja:Object.freeze({...Xe.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...rs.ja})}),on=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Wl=e=>e==="commentCount"||e==="listMore",ph=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${on(t)}`);for(const n of Ss){const r=e[n];if(!(Wl(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Wl(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${on(r)}`)}}},hh=e=>{const t={};let n=!1;for(const r of Xe.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},gh=(e,t,n)=>{e[t]=n},Xc=(e,t)=>{const n=Xe.resolveVirtualScrollLocale(e);if(t===void 0)return Uc[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${on(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!Vl.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Vl.join(", ")}`);const s={...Xe.resolveVirtualScrollLabels(n,hh(t)),...rs[n]};for(const l of Ss){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&gh(s,l,c)}return ph(s),Object.freeze(s)},mh=e=>{const t={};for(const n of Xe.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Me=(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},Kl={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},wh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Ch=(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}`}},zo=(e,t)=>{const n=r=>(o,s)=>`${e} ${Ch(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},yh=Object.freeze({list:"Value must be one of the list items.",number:zo("Value must be a number",Kl),textLength:zo("Text length must be",Kl),date:zo("Value must be a date",wh),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),bh=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),Fo=Object.freeze({en:yh,ja:bh}),vh=Object.freeze({ok:!0}),Rh="TRUE",kh="FALSE",Sh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Eh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Ah=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Oh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,xh=/^[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])?)+$/,Yl=e=>{const t=e.trim();if(!(Ah.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}},Th=e=>e===1?-1:e===-1?1:0,$h=(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:Th(n)},Dh=(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}},Ul=e=>{const t=Oh.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>Dh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Lh=(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,zh=e=>e==="between"||e==="notBetween",Fh=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!zh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Nh=(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}},No=(e,t,n,r,o,s)=>{const l=Fh(e,t,n,r);return l===null?!0:o===null?!1:Nh(e,s(o,l.a),l.b===null?0:s(o,l.b))},Ph=e=>Number.isFinite(e)?e:null,qh=e=>{let t=0;for(const n of e)t+=1;return t},_h=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),jh=(e,t)=>{switch(e.op){case"isEmail":return xh.test(t);case"isUrl":return _h(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)}},Ih=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Gc=e=>({checked:e.checked===void 0?Rh:e.checked,unchecked:e.unchecked===void 0?kh:e.unchecked}),Hh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Sh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${on(e.op)} for type "${e.type}"`);return;case"text":if(!Eh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${on(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${on(e.type)}`)}},Bh=(e,t,n)=>{switch(e.type){case"list":return Kh(e).has(t);case"number":return No(e.op,e.a,e.b,Yl,Yl(t),$h);case"textLength":return No(e.op,e.a,e.b,Ph,qh(t),Mh);case"date":return No(e.op,e.a,e.b,Ul,Ul(t),Lh);case"text":return jh(e,t);case"checkbox":{const r=Gc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Ih(n(e.formula))}},Jc=(e,t,n)=>(Hh(e),t===""||Bh(e,t,n)),Xl=e=>e===void 0?void 0:e.trim(),Vh=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Xl(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),Xl(e.b));case"text":return Wh(e,t.text);case"checkbox":{const n=Gc(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},Wh=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},Gl=new WeakMap,Kh=e=>{const t=Gl.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Gl.set(e,n),n},Zc=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Fo,n)){const o=Object.keys(Fo).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${on(n)}`)}return Jc(e,t,r)?vh:{ok:!1,message:e.errorMessage===void 0?Vh(e,Fo[n]):e.errorMessage}},Yh=e=>e.type!=="custom",Uh=(e,t)=>Yh(e)&&!Jc(e,t,void 0),Qc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),ea=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),ta=(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,na=(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),ra=(e,t)=>Qc(e,t),oa=(e,t)=>Qc(e,t),sa=(e,t)=>ea(e,t),la=(e,t)=>ea(e,t),sn=(e,t,n)=>ta(e,t,n),ln=(e,t,n)=>ta(e,t,n),pr=(e,t,n)=>na(e,t,n),hr=(e,t,n)=>na(e,t,n),dt=12,Xh=()=>{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)})}},Gh=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Pt=1,er=3,Tr=e=>`${-Math.min(er,Math.max(0,Math.floor(e)))}px`,ia=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Jh=16,Zh=450,Qh=e=>e>4?Math.floor(Zh/(5*e)):Jh,Un=(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},Jl=()=>({rowLeft:Un("row","left"),rowRight:Un("row","right"),colAbove:Un("column","above"),colBelow:Un("column","below"),cross:Un("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),ca=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],$r=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},Dr=(e,t)=>Math.min(Math.max(e,0),t),Zl="inset(100%)",xn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},eg=(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)}},Ql=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))},ei=e=>{for(const t of ca(e))t.remove()},tg=(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)},ng=Object.freeze([]),ti=e=>e.dividers[0]??e.active,rg={left:"0px",right:"0px",width:""},og={top:"0px",bottom:"0px",height:""},ni=()=>({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:[]}),ri=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],oi=6,sg=({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:N,enableFillHandle:_,frozenCols:Y,frozenRows:B,trailingCols:L,trailingRows:$,sinkAriaLabel:P,onSinkMouseDown:k,editPaintRef:v,highlightRef:S,highlightColors:p,popoverAnchors:m,interactiveAnchorRef:y,tipAnchorRef:D})=>{const O=i.useRef(null),R=i.useRef(null),F=i.useRef(null),b=i.useRef(new Map(ri.map(z=>[z,ni()]))),a=i.useCallback(z=>{const H=b.current.get(z);if(H!==void 0)return H;const U=ni();return b.current.set(z,U),U},[]),f=i.useCallback((z,H,U)=>{if(z===null)return;const I=z.style;I.left!==H.left&&(I.left=H.left),I.right!==H.right&&(I.right=H.right),I.width!==H.width&&(I.width=H.width),I.top!==U.top&&(I.top=U.top),I.bottom!==U.bottom&&(I.bottom=U.bottom),I.height!==U.height&&(I.height=U.height)},[]),x=i.useCallback((z,H,U)=>{if(!(z.bandClampWidth===H&&z.bandClampHeight===U)){z.bandClampWidth=H,z.bandClampHeight=U;for(const I of z.bandPool)$r(I,H,U);z.dragBand!==null&&$r(z.dragBand,H,U)}},[]),d=i.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const A=i.useCallback((z,H,U)=>{const I=z.dividerSlots[H];I===null||z.dividerShown[H]===U||(z.dividerShown[H]=U,I.style.display=U?"":"none")},[]),E=i.useRef({x:0,y:0}),T=i.useRef(null),M=i.useCallback((z,H)=>{const U=n.current,I=U?.getFrozenSize()??Gh,G=U?.getViewportSize(),oe=G?.width??-1,ee=G?.height??-1,Ae=E.current;Ae.x=z,Ae.y=H;let de=T.current;if(de===null||de.frozenCols!==I.cols||de.frozenWidth!==I.width||de.frozenRows!==I.rows||de.frozenHeight!==I.height||de.trailingCols!==I.trailingCols||de.trailingWidth!==I.trailingWidth||de.trailingVisibleWidth!==I.trailingVisibleWidth||de.trailingRows!==I.trailingRows||de.trailingHeight!==I.trailingHeight||de.trailingVisibleHeight!==I.trailingVisibleHeight||de.bodyWidth!==oe||de.bodyHeight!==ee){const re=I.trailingVisibleWidth,he=I.trailingVisibleHeight,ge=I.cols<=0&&I.trailingCols<=0?[{kind:"m",map:ye=>ye-Ae.x,clamp:oe,style:rg,seamLead:!1,seamTrail:!1}]:[...I.cols>0?[{kind:"f",map:ye=>ye,clamp:I.width,style:{left:"0px",width:`${I.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ye=>ye-Ae.x-I.width,clamp:Math.max(0,oe-I.width-re),style:{left:`${I.width}px`,right:`${re}px`,width:""},seamLead:I.cols>0,seamTrail:I.trailingCols>0},...I.trailingCols>0?[{kind:"t",map:ye=>ye-d.current.colAxis.totalSize()+re,clamp:re,style:{left:"",right:"0px",width:`${re}px`},seamLead:!0,seamTrail:!1}]:[]],me=I.rows<=0&&I.trailingRows<=0?[{kind:"m",map:ye=>ye-Ae.y,clamp:ee,style:og,seamLead:!1,seamTrail:!1}]:[...I.rows>0?[{kind:"f",map:ye=>ye,clamp:I.height,style:{top:"0px",height:`${I.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ye=>ye-Ae.y-I.height,clamp:Math.max(0,ee-I.height-he),style:{top:`${I.height}px`,bottom:`${he}px`,height:""},seamLead:I.rows>0,seamTrail:I.trailingRows>0},...I.trailingRows>0?[{kind:"t",map:ye=>ye-d.current.rowAxis.totalSize()+he,clamp:he,style:{top:"",bottom:"0px",height:`${he}px`},seamLead:!0,seamTrail:!1}]:[]],ue=[];for(const ye of ge)for(const ve of me)ue.push({nodes:a(`${ye.kind}${ve.kind}`),xKind:ye.kind,yKind:ve.kind,mapX:ye.map,clampWidth:ye.clamp,xStyle:ye.style,xSeamLead:ye.seamLead,xSeamTrail:ye.seamTrail,mapY:ve.map,clampHeight:ve.clamp,yStyle:ve.style,ySeamLead:ve.seamLead,ySeamTrail:ve.seamTrail});de={frozenCols:I.cols,frozenWidth:I.width,frozenRows:I.rows,frozenHeight:I.height,trailingCols:I.trailingCols,trailingWidth:I.trailingWidth,trailingVisibleWidth:I.trailingVisibleWidth,trailingRows:I.trailingRows,trailingHeight:I.trailingHeight,trailingVisibleHeight:I.trailingVisibleHeight,bodyWidth:oe,bodyHeight:ee,ctxs:ue},T.current=de}const fe=I.width>0,Le=I.trailingWidth>0,Ie=I.height>0,Pe=I.trailingHeight>0;for(const re of de.ctxs)f(re.nodes.container,re.xStyle,re.yStyle),x(re.nodes,re.clampWidth,re.clampHeight),A(re.nodes,0,fe),A(re.nodes,1,Le),A(re.nodes,2,Ie),A(re.nodes,3,Pe);return de.ctxs},[n,a,f,x,A]),V=i.useCallback((z,H,U)=>{z.dividerSlots[H]=U,z.dividerShown[H]=!1,z.dividers.length=0;for(const I of z.dividerSlots)I!==null&&z.dividers.push(I)},[]),X=i.useCallback(z=>{const H=()=>a(z);return{container:U=>{const I=H();I.container=U,U===null&&(I.fillPool.length=0,I.bandPool.length=0,I.dragBand=null,I.bandClampWidth=-1,I.bandClampHeight=-1)},dividerXLeading:U=>V(H(),0,U),dividerXTrailing:U=>V(H(),1,U),dividerYLeading:U=>V(H(),2,U),dividerYTrailing:U=>V(H(),3,U),active:U=>{H().active=U},dragRect:U=>{H().dragRect=U},marquee:U=>{H().marquee=U},fillPreview:U=>{H().fillPreview=U},resizeGuide:U=>{H().resizeGuide=U}}},[a,V]),J=i.useMemo(()=>Object.fromEntries(ri.map(z=>[z,X(z)])),[X]),Z=Math.min(Math.max(0,Y),t.count),ne=ra(t,Z),ie=Math.min(Math.max(0,B),e.count),se=oa(e,ie),ze=L===void 0?0:Math.min(Math.max(0,L),t.count-Z),ce=sa(t,ze),Re=$===void 0?0:Math.min(Math.max(0,$),e.count-ie),De=la(e,Re),Ne=i.useRef(null),_e=i.useRef("add"),qe=i.useRef(s);qe.current=s;const bt=i.useRef(!1),gr=Xe.useWheelBridge(n,{enableBridge:!s}),ro=i.useCallback(z=>(r.current=z,gr(z)),[r,gr]),pe=i.useCallback((z,H)=>({top:H.mapY(e.offsetOf(z.startRow)),bottom:H.mapY(e.offsetOf(z.endRow)+e.sizeOf(z.endRow)),left:H.mapX(t.offsetOf(z.startCol)),right:H.mapX(t.offsetOf(z.endCol)+t.sizeOf(z.endCol))}),[e,t]),ae=i.useCallback((z,H)=>{if(H.clampHeight<=0||H.clampWidth<=0)return null;const{top:U,bottom:I,left:G,right:oe}=pe(z,H),ee=-H.clampHeight*Pt,Ae=H.clampHeight*(1+Pt),de=-H.clampWidth*Pt,fe=H.clampWidth*(1+Pt);if(I<ee||U>Ae||oe<de||G>fe)return null;const Le=Math.max(U,ee),Ie=Math.max(G,de);return{top:Le,left:Ie,width:Math.min(oe,fe)-Ie,height:Math.min(I,Ae)-Le}},[pe]),an=i.useCallback((z,H)=>{if(H.clampHeight<=0||H.clampWidth<=0)return null;const U=pe(z,H),I=-H.clampHeight*Pt,G=H.clampHeight*(1+Pt),oe=-H.clampWidth*Pt,ee=H.clampWidth*(1+Pt),Ae=Math.min(Math.max(U.top,I),G),de=Math.min(Math.max(U.left,oe),ee);return{top:Ae,left:de,width:Math.min(Math.max(U.right,oe),ee)-de,height:Math.min(Math.max(U.bottom,I),G)-Ae}},[pe]),ke=i.useCallback(()=>{if(S===void 0)return null;const z=S.current;return z.row||z.column||z.intersection?z:null},[S]),Tt=i.useCallback((z,H,U)=>{const I=H.fillPool[0]?.node??ti(H);for(const G of ca(U))z.insertBefore(G,I)},[]),pt=i.useCallback((z,H,U,I)=>{const G=an(H,U);if(G===null){Ql(z);return}eg(z,G,U,I,Ji(H,t.count)||Zi(H,e.count))},[an,e,t]),mr=i.useCallback((z,H,U,I)=>{const G=z.nodes.bandPool;for(;G.length>U.length;){const oe=G.pop();oe!==void 0&&ei(oe)}if(I===null){z.nodes.dragBand!==null&&(ei(z.nodes.dragBand),z.nodes.dragBand=null);return}for(let oe=0;oe<U.length;oe+=1){let ee=G[oe];ee===void 0&&(ee=Jl(),$r(ee,z.clampWidth,z.clampHeight),Tt(H,z.nodes,ee),G.push(ee)),pt(ee,U[oe],z,I)}},[Tt,pt]),Wt=i.useCallback((z,H,U)=>{const I=z.nodes.container;if(I===null)return;if(H===null||U===null){z.nodes.dragBand!==null&&Ql(z.nodes.dragBand);return}let G=z.nodes.dragBand;G===null&&(G=Jl(),$r(G,z.clampWidth,z.clampHeight),Tt(I,z.nodes,G),z.nodes.dragBand=G),pt(G,H,z,U)},[Tt,pt]),$t=i.useCallback((z,H)=>{if(z!==null){if(H===null){z.style.display="none";return}z.style.display="block",z.style.transform=`translate(${H.left}px, ${H.top}px)`,z.style.width=`${H.width}px`,z.style.height=`${H.height}px`}},[]),un=i.useCallback((z,H,U,I)=>{const G=I==="point"?null:ke();for(const oe of M(U,H))$t(oe.nodes.dragRect,ae(z,oe)),Wt(oe,z,G)},[ae,M,$t,ke,Wt]),Kt=i.useCallback((z,H,U)=>{for(const I of M(U,H))$t(I.nodes.fillPreview,z===null?null:ae(z,I))},[ae,M,$t]),dn=i.useCallback((z,H,U)=>{for(const I of M(U,H)){const G=I.nodes.resizeGuide;if(G===null)continue;if(z===null){G.style.display="none";continue}const oe=z.anchor==="trailing";if(z.axis==="col"){if(oe&&I.xKind!=="t"){G.style.display="none";continue}G.style.display="block";const ee=I.mapX(z.position);G.style.transform=`translate(${oe?Math.max(0,ee):ee}px, 0px)`,G.style.width="1px",G.style.height="100%"}else{if(oe&&I.yKind!=="t"){G.style.display="none";continue}G.style.display="block";const ee=I.mapY(z.position);G.style.transform=`translate(0px, ${oe?Math.max(0,ee):ee}px)`,G.style.width="100%",G.style.height="1px"}}},[M]),wr=i.useCallback((z,H,U,I,G,oe,ee)=>{if(z===null)return;if(H===null||ee<=0||oe<=0){z.style.clipPath=Zl;return}const Ae=ln(e,H.row,I),de=sn(t,H.col,U),fe=t.sizeOf(H.col),Le=e.sizeOf(H.row),Ie=de>=oe||Ae>=ee,Pe=H.col>=G.cols&&de<G.width,re=H.row>=G.rows&&Ae<G.height,he=G.trailingWidth>0&&H.col<t.count-G.trailingCols&&de+fe>oe-G.trailingVisibleWidth,ge=G.trailingHeight>0&&H.row<e.count-G.trailingRows&&Ae+Le>ee-G.trailingVisibleHeight;if(Ie||Pe||re||he||ge){z.style.clipPath=Zl;return}z.style.clipPath="",z.style.transform=`translate(${de}px, ${Ae}px)`;const me=`${fe} ${Le}`;z.dataset.aqspAnchorSig!==me&&(z.dataset.aqspAnchorSig=me,z.style.width=`${fe}px`,z.style.height=`${Le}px`)},[e,t]),Cr=i.useCallback((z,H,U)=>{if(m===void 0)return;const I=m.current,{width:G,height:oe}=z.getViewportSize(),ee=z.getFrozenSize(),Ae={scroll:U,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:G},de={scroll:H,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:oe};wr(y===void 0?null:y.current,I.interactive,Ae,de,ee,G,oe),wr(D===void 0?null:D.current,I.tip,Ae,de,ee,G,oe)},[m,y,D,wr]),Yt=i.useCallback(()=>{const z=O.current,H=n.current;if(z===null||H===null)return;const U=H.getScrollPosition(),I=Math.max(0,U.y),G=Math.max(0,U.x),oe=o(),ee=M(G,I),Ae=ke(),de=Ae===null?ng:oe.ranges.slice(-Qh(ee.length));for(const re of ee){const he=re.nodes.container;if(he===null)continue;const ge=re.nodes.fillPool;for(let me=0;me<Math.max(ge.length,oe.ranges.length);me+=1){let ue=ge[me];if(ue===void 0){const Te=document.createElement("div");Te.className="aqsp-selection-fill",Te.setAttribute("data-aqsp-fill",""),Te.style.display="none",he.insertBefore(Te,ti(re.nodes)),ue={node:Te,last:{shown:!1,width:-1,height:-1,transform:""}},ge.push(ue)}const ye=oe.ranges[me],ve=ye===void 0?null:ae(ye,re);if(ve===null)ue.last.shown&&(ue.last.shown=!1,ue.node.style.display="none");else{ue.last.shown||(ue.last.shown=!0,ue.node.style.display="block");const Te=`translate(${ve.left}px, ${ve.top}px)`;Te!==ue.last.transform&&(ue.last.transform=Te,ue.node.style.transform=Te),ve.width!==ue.last.width&&(ue.last.width=ve.width,ue.node.style.width=`${ve.width}px`),ve.height!==ue.last.height&&(ue.last.height=ve.height,ue.node.style.height=`${ve.height}px`)}}for(;ge.length>oe.ranges.length;)ge.pop()?.node.remove();$t(re.nodes.active,ae(Ce(oe.active,oe.active),re)),mr(re,he,de,Ae)}const fe=h(),Le=fe===null||fe.foreign?null:fe;for(const re of ee){const he=re.nodes.marquee;if(he===null)continue;const ge=Le===null?null:ae(Le.range,re),me=ge!==null&&(re.xSeamTrail&&ge.left>=re.clampWidth&&ge.left<re.clampWidth+er||re.xSeamLead&&ge.left+ge.width<=0&&ge.left+ge.width>-er||re.ySeamTrail&&ge.top>=re.clampHeight&&ge.top<re.clampHeight+er||re.ySeamLead&&ge.top+ge.height<=0&&ge.top+ge.height>-er)?null:ge;if(me===null)he.style.display="none";else{he.style.display="block",he.style.transform=`translate(${me.left}px, ${me.top}px)`,he.style.width=`${me.width}px`,he.style.height=`${me.height}px`;const ve=Tr(me.top),Te=Tr(me.left),ht=Tr(re.clampHeight-(me.top+me.height)),He=Tr(re.clampWidth-(me.left+me.width)),rt=`${ve} ${He} ${ht} ${Te}`;rt!==he.dataset.aqspOutsetSig&&(he.dataset.aqspOutsetSig=rt,he.style.setProperty("--aqsp-clip-outset-top",ve),he.style.setProperty("--aqsp-clip-outset-right",He),he.style.setProperty("--aqsp-clip-outset-bottom",ht),he.style.setProperty("--aqsp-clip-outset-left",Te))}const ue=me===null?null:Le?.kind??null,ye=he.dataset.aqspClipKindLast??null;ue!==ye&&(ue===null?(delete he.dataset.aqspClipKindLast,he.removeAttribute("data-aqsp-clip-kind")):(he.dataset.aqspClipKindLast=ue,he.setAttribute("data-aqsp-clip-kind",ue)))}Ne.current!==null&&un(Ne.current,I,G,_e.current),F.current!==null&&dn(F.current,I,G),R.current!==null&&Kt(R.current,I,G);const Ie=N.current;if(Ie!==null&&!C()){const{width:re,height:he}=H.getViewportSize(),ge=oe.ranges[oe.ranges.length-1];if(!(oe.ranges.length===1&&!qe.current&&!g())||he<=0||re<=0)Ie.style.display="none";else{const ue=H.getFrozenSize(),ye={scroll:G,frozenCount:ue.cols,trailingCount:ue.trailingCols,extent:re},ve={scroll:I,frozenCount:ue.rows,trailingCount:ue.trailingRows,extent:he},Te=ge.endCol<ue.cols,ht=ge.endRow<ue.rows,He=ge.endCol>=t.count-ue.trailingCols,rt=ge.endRow>=e.count-ue.trailingRows,je=sn(t,ge.endCol,ye)+t.sizeOf(ge.endCol),Be=ln(e,ge.endRow,ve)+e.sizeOf(ge.endRow),qn=Te||He?0:ue.width,Ut=ht||rt?0:ue.height,Lt=He?re:re-ue.trailingVisibleWidth,_n=rt?he:he-ue.trailingVisibleHeight;Be<=Ut||Be>_n||je<=qn||je>Lt?Ie.style.display="none":(Ie.style.display="block",Ie.style.transform=`translate(${je-oi+1}px, ${Be-oi+1}px)`)}}const Pe=r.current;if(Pe!==null){const re=oe.active,{width:he,height:ge}=H.getViewportSize(),me=H.getFrozenSize(),ue={scroll:G,frozenCount:me.cols,trailingCount:me.trailingCols,extent:he},ye={scroll:I,frozenCount:me.rows,trailingCount:me.trailingRows,extent:ge},ve=ln(e,re.row,ye),Te=sn(t,re.col,ue),ht=ge>0?Math.min(Math.max(ve,0),Math.max(0,ge-1)):0,He=he>0?Math.min(Math.max(Te,0),Math.max(0,he-1)):0;Pe.style.top=`${ht}px`,Pe.style.left=`${He}px`,qe.current?(Pe.style.width=`${t.sizeOf(re.col)}px`,Pe.style.height=`${e.sizeOf(re.row)}px`,Pe.style.paddingTop=`${tg(e.sizeOf(re.row),v===void 0?Et:v.current)}px`):(Pe.style.width="1px",Pe.style.height="1px",Pe.style.paddingTop="0px");const rt=re.col>=me.cols&&Te<me.width,je=re.row>=me.rows&&ve<me.height,Be=me.trailingWidth>0&&re.col<t.count-me.trailingCols&&Te+t.sizeOf(re.col)>he-me.trailingVisibleWidth,qn=me.trailingHeight>0&&re.row<e.count-me.trailingRows&&ve+e.sizeOf(re.row)>ge-me.trailingVisibleHeight,Ut=qe.current&&ve===ht&&Te===He&&!rt&&!je&&!Be&&!qn;Ut!==bt.current&&(bt.current=Ut,Ut?Pe.setAttribute("data-aqsp-editing",""):Pe.removeAttribute("data-aqsp-editing"))}Cr(H,I,G)},[n,ae,M,$t,un,dn,Kt,h,o,g,C,N,r,e,t,ke,mr,v,Cr]),fn=i.useCallback((z,H)=>{Ne.current=z,_e.current=H;const U=z===null?"add":H;for(const oe of M(0,0)){const ee=oe.nodes.dragRect;if(ee===null)continue;const Ae=ee.dataset.aqspDragModeLast??"add";U!==Ae&&(ee.dataset.aqspDragModeLast=U,U==="add"?ee.removeAttribute("data-aqsp-drag-mode"):ee.setAttribute("data-aqsp-drag-mode",U))}const I=n.current;if(z===null||I===null){for(const oe of M(0,0))oe.nodes.dragRect!==null&&(oe.nodes.dragRect.style.display="none"),Wt(oe,null,null);return}const G=I.getScrollPosition();un(z,Math.max(0,G.y),Math.max(0,G.x),H)},[n,un,M,Wt]),Nn=i.useCallback(z=>{R.current=z;const H=n.current;if(H===null){for(const I of M(0,0))I.nodes.fillPreview!==null&&(I.nodes.fillPreview.style.display="none");return}const U=H.getScrollPosition();Kt(z,Math.max(0,U.y),Math.max(0,U.x))},[n,Kt,M]),Pn=i.useCallback(z=>{F.current=z;const H=n.current;if(H===null){for(const I of M(0,0))I.nodes.resizeGuide!==null&&(I.nodes.resizeGuide.style.display="none");return}const U=H.getScrollPosition();dn(z,Math.max(0,U.y),Math.max(0,U.x))},[n,dn,M]);i.useLayoutEffect(()=>{const z=O.current;if(!(z===null||p===void 0))return z.style.setProperty("--aqsp-band-row",p.row),z.style.setProperty("--aqsp-band-column",p.column),z.style.setProperty("--aqsp-band-intersection",p.intersection),z.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{z.style.removeProperty("--aqsp-band-row"),z.style.removeProperty("--aqsp-band-column"),z.style.removeProperty("--aqsp-band-intersection"),z.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Yt,u.current=fn,q.current=Nn,j.current=Pn,()=>{c.current=null,u.current=null,q.current=null,j.current=null})),i.useEffect(()=>{Yt()},[Yt,s,Z,ie,ze,Re]),i.useEffect(()=>{const z=r.current;if(z===null)return;const H=U=>k(U);return z.addEventListener("mousedown",H),()=>z.removeEventListener("mousedown",H)},[r,k]);const Dt=Z>0||ze>0?[...Z>0?[{k:"f",style:{left:0,width:ne}}]:[],{k:"s",style:{left:ne,right:ce}},...ze>0?[{k:"t",style:{right:0,width:ce}}]:[]]:[{k:"m",style:{left:0,right:0}}],Ge=ie>0||Re>0?[...ie>0?[{k:"f",style:{top:0,height:se}}]:[],{k:"s",style:{top:se,bottom:De}},...Re>0?[{k:"t",style:{bottom:0,height:De}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],pn=z=>z==="m"?0:z==="s"?1:z==="t"?2:3,oo=Dt.flatMap(z=>Ge.map(H=>({xk:z.k,yk:H.k,key:`${z.k}${H.k}`,style:{...z.style,...H.style}}))).sort((z,H)=>pn(z.key[0])+pn(z.key[1])-(pn(H.key[0])+pn(H.key[1]))),nt=z=>z==="mm"?{"data-aqsp-overlay-main":""}:z==="fm"?{"data-aqsp-overlay-frozen":""}:z==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:O,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:dt,bottom:dt},children:[oo.map(({xk:z,yk:H,key:U,style:I})=>{const G=J[U];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":U,...nt(U),style:I,ref:G.container,children:[z==="s"&&Z>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:G.dividerXLeading}):null,z==="s"&&ze>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:G.dividerXTrailing}):null,H==="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:G.dividerYLeading}):null,H==="s"&&Re>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:G.dividerYTrailing}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:G.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:G.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:G.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:G.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:G.resizeGuide})]},U)}),K.jsx("textarea",{ref:ro,className:"aqsp-sink","aria-label":P,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?K.jsx("div",{ref:N,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},aa=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=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:[Me(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Me(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":Me(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:Me(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},ua=({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=_=>{u.current=!0;try{_()}finally{u.current=!1}},q=()=>{l||g||C(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},j=_=>{if(_.key==="Escape"){_.preventDefault(),C(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),q())},N=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.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:N,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Me(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Me(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:j})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Me(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":g||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown: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:Me(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:Me(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>C(e.close),children:"×"})]})]})},si=500,da=({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(L=>L.toLowerCase().startsWith(B))},[e.current,n]),h=i.useMemo(()=>u.length>si?u.slice(0,si):u,[u]),g=u.length-h.length,C=h.length===0?-1:Math.min(o,h.length-1),q=B=>{c.current=!0;try{B()}finally{c.current=!1}},j=()=>{C<0||q(()=>e.commit(h[C]))},N=B=>{if(B.key==="Escape"){B.preventDefault(),q(e.close);return}if(B.key==="Enter"){B.preventDefault(),j();return}if(B.key==="ArrowDown"){B.preventDefault(),s(C+1);return}B.key==="ArrowUp"&&(B.preventDefault(),s(Math.max(C-1,0)))},_=B=>{c.current||B.relatedTarget instanceof Node&&B.currentTarget.contains(B.relatedTarget)||q(e.close)},Y=B=>`${l}-${B}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Me(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":C<0?void 0:Y(C),value:n,onChange:B=>{r(B.currentTarget.value),s(0)},onKeyDown:N}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Me(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Me(t,"listEmpty")}):h.map((B,L)=>K.jsx("div",{className:"aqsp-popover-option",id:Y(L),role:"option",tabIndex:-1,"aria-selected":L===C,"data-aqsp-list-option":B,onPointerDown:$=>$.preventDefault(),onClick:()=>q(()=>e.commit(B)),children:B},Y(L))),g>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Me(t,"listMore",g)}):null]})]})},fa=({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":Me(t,"popoverClose"),onClick:e.close,children:"×"})]}),pa=({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=N=>{u.current=!0;try{N()}finally{u.current=!1}},g=()=>{s||h(()=>e.commit(r===""?null:r))},C=()=>{r!==n&&!s?g():h(e.close)},q=N=>{if(N.key==="Escape"){N.preventDefault(),e.rejected?h(e.close):C();return}N.key==="Enter"&&(N.ctrlKey||N.metaKey)&&!N.altKey&&!N.shiftKey&&(N.preventDefault(),g())},j=N=>{u.current||N.relatedTarget instanceof Node&&N.currentTarget.contains(N.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:Me(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:N=>o(N.currentTarget.value),onKeyDown:q}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Me(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:Me(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},ha=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),kt=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")}),li=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],ga=Object.freeze({all:kt(li),values:kt(["text"]),formats:kt(["format","borders","cf"]),formulas:kt(["text","formula"]),noBorders:kt(li.filter(e=>e!=="borders")),columnWidths:kt(["sizes"]),validation:kt(["validation"]),conditionalFormats:kt(["cf"]),commentsAndNotes:kt(["note","comments"])}),ii=Object.freeze({mode:"all"}),os=Object.freeze({t:""}),ci=Object.freeze({row:1<<30,col:1<<30}),lg=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),ig=e=>e.t===""&&e.f===void 0,cg=e=>e.length>1&&e.startsWith("="),ag=(e,t,n)=>{switch(n){case"add":return e+t;case"subtract":return e-t;case"multiply":return e*t;case"divide":return e/t}},ai=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,ug=(e,t,n,r)=>{const o=cg(e),s=e===""?"0":et(e);if(!o&&s===null)return null;const l=lg[n];if(t.f!==void 0){const h=dr(t.f,r),g=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${g})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:ai(Number(s));const c=et(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:ai(ag(Number(s),u,n))},ui=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),dg=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:ui(e.start),end:ui(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},fg=e=>{const t=dr(e,ci),n=ur(t);let r="",o=0,s=!1;for(const l of n){const c=dg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${jt(c)}`,o=l.end,s=!0)}return s?Qr(`${r}${t.slice(o)}`,ci):e},pg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return os;const o=r[n];return o===void 0?os:o},hg=e=>{const{rows:t,cols:n}=e,r=dc(fg);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=pg(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===os)&&(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}},gg=(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,mg=(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},di=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const g of c)gg(g,t)?(h.push(mg(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},fi=new WeakMap,ma=e=>{const t=fi.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>ft(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:ft({...s,borders:void 0})),o={canonical:n,borderless:r};return fi.set(e,o),o},Ur=(e,t)=>t===void 0?void 0:e[t],wg=(e,t,n,r)=>{const o=ma(e);if(n){const h=Ur(o.canonical,t.fmt);return h===void 0?null:h}const s=Ur(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=ft(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},Cg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?ug(n.readText(),o,r,n):o.f===void 0?o.t:dr(o.f,n)},pi=(e,t,n,r,o)=>{const s=ga[r.mode];if(r.skipBlanks===!0&&ig(e))return null;const l={};let c=!1;if(s.text){const u=Cg(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=wg(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Ur(ma(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=Ur(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},hi=(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}}),yg=["text/html","text/plain"],bg=(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},vg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Rg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,kg=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}}},gi=e=>{const t=e.clipboardData;return t??null},Sg=(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}},Eg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Sg(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},Ag=(e,t,n,r,o)=>{const s=zn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Qr(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=Fn(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},wa=(e,t)=>{const n=Gi(),r=Td(),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(Ag(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Eg(e.getConditionalFormats(),t)}},mi=e=>e.kind==="cut"?{...e.payload,...wa(e.sourceAdapter,e.range)}:e.payload,Og=e=>({v:1,rows:e.length,cols:e[0].length,clipId:fs(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),xg=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},Tg=(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},$g=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return Ce({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Dg=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(L=>{const $=n.current;if($===null||L==="format"||L==="annotate")return;const P=r.current;P==="own"||P==="foreign"&&$.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const L=n.current;if(L===null)return;if(L.kind==="copy"){o();return}const $=t.current;$.repaintOverlay(),$.onClipChange?.({kind:"cut",range:L.range,foreign:L.sourceAdapter!==$.adapter})},[o]),c=i.useCallback((L,$,P)=>{const k=t.current;n.current={kind:L,range:$,clipId:P.clipId,sourceAdapter:k.adapter,payload:P},k.repaintOverlay(),k.onClipChange?.({kind:L,range:$,foreign:!1})},[]),u=i.useCallback(L=>{const $=t.current,P=$.adapter,k=tt(L),v={v:1,rows:k.rows,cols:k.cols,clipId:fs(),...wa(P,L),wholeRows:Ji(L,P.colCount),wholeCols:Zi(L,P.rowCount)};if($.resize!==void 0){if(v.wholeCols){const S=[];for(let p=L.startCol;p<=L.endCol;p+=1)S.push(Math.min($.resize.colAxis.sizeOf(p),Dn));v.colWidths=S}if(v.wholeRows){const S=[];for(let p=L.startRow;p<=L.endRow;p+=1)S.push(Math.min($.resize.rowAxis.sizeOf(p),Dn));v.rowHeights=S}}return v},[]),h=i.useCallback((L,$)=>{const P=t.current,k=P.getSelection(),v=k.ranges[k.ranges.length-1],S=yt([v]);if(S>P.maxOperationCells)return L.preventDefault(),P.onOperationRejected?.($,S,"limit"),null;if($==="cut"&&Qn(P.adapter,v))return L.preventDefault(),P.rejectReadOnly({kind:"operation",op:"cut",cellCount:S}),null;k.ranges.length>1&&P.onCopyMultiRange?.();const p=u(v),m=_i(p),y=gi(L);return y!==null&&(y.setData("text/plain",jc(p.cells.map(D=>D.map(O=>O.t)))),y.setData("text/html",Tc(p,m)),y.setData(Wr,m)),L.preventDefault(),{payload:p,range:v}},[u]),g=i.useCallback((L,$)=>t.current.commitPaste(L,$)!==null,[]),C=i.useCallback((L,$,P)=>{const k=t.current;if(!P.sizes||k.resize===void 0)return;const{rowAxis:v,colAxis:S,resizeTracks:p}=k.resize,m=(y,D,O)=>{const R=cs(D,O,null,{maxOperationCells:k.maxOperationCells,rowHiddenLimit:ls,axisKind:y});if(!R.ok){k.onOperationRejected?.("resize",R.count,R.reason);return}p(y,R.entries)};if(L.colWidths!==void 0){const y=[];for(let D=$.startCol;D<=$.endCol;D+=1)y.push({index:D,size:L.colWidths[(D-$.startCol)%L.cols]});m("col",S,y)}if(L.rowHeights!==void 0){const y=[];for(let D=$.startRow;D<=$.endRow;D+=1)y.push({index:D,size:L.rowHeights[(D-$.startRow)%L.rows]});m("row",v,y)}},[]),q=i.useCallback((L,$)=>{const P=t.current,k=P.adapter,v=L.payload,S={row:$.startRow,col:$.startCol},p=v.rows*v.cols+yt([L.range]);if(p>P.maxOperationCells)return P.onOperationRejected?.("paste",p,"limit"),"rejected";if(S.row+v.rows>k.rowCount||S.col+v.cols>k.colCount||L.range.endRow>=L.sourceAdapter.rowCount||L.range.endCol>=L.sourceAdapter.colCount)return P.onOperationRejected?.("paste",p,"bounds"),"rejected";const m=ns({rows:v.rows,cols:v.cols},Ce(S,S),S,k.rowCount,k.colCount);if(m!==null&&Qn(k,m))return P.rejectReadOnly({kind:"operation",op:"paste",cellCount:v.rows*v.cols}),"rejected";if(Qn(L.sourceAdapter,L.range))return P.rejectReadOnly({kind:"operation",op:"cut",cellCount:yt([L.range])}),"rejected";const y=mi(L),D=Br(k),O=di(y,D),R={row:0,col:0,readText:()=>zn(k,R.row,R.col).text,readFormat:()=>k.getCellFormat===void 0?void 0:k.getCellFormat(R.row,R.col)},{edits:F,tiles:b}=Il(O.cells,Ce(S,S),S,k.rowCount,k.colCount,(x,d,A)=>(R.row=L.range.startRow+(d-S.row),R.col=L.range.startCol+(A-S.col),pi(x,O,R,ii,D))),a=Br(L.sourceAdapter),f=[];if(qt([L.range],x=>{f.push(Tg(x.row,x.col,a))}),L.sourceAdapter===k){if(!g([...f,...F],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const x=P.commitPaste(F,{sameSheet:!1,conditionalFormats:hi(O.conditionalFormats,b)});if(x===null)return"rejected";try{L.sourceAdapter.applyEdits(f,{transaction:x,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){P.onEditRejected?.(d,{source:"paste"})}}return P.setSelection({ranges:[Ce(S,{row:S.row+y.rows-1,col:S.col+y.cols-1})],anchor:S,active:S}),"applied"},[g]),j=i.useCallback((L,$,P)=>{const k=t.current,v=k.adapter,S=X=>(k.onClipboardUnavailable?.(X),"rejected"),p=Hi(L,$);if(p==="none")return $==="menu"?S("empty"):"empty";const m=k.getSelection(),y=m.ranges[m.ranges.length-1],D=P.transpose===!0,O=(X,J)=>{const Z=bg(D?J:X,D?X:J,y);return Z>k.maxOperationCells?(k.onOperationRejected?.("paste",Z,"limit"),!0):!1};let R,F=null;if(p==="aqsp"){const X=nd(L,$);if(X===null)return S("unreadable");const J=n.current;if(J!==null&&X.clipId===J.clipId&&(F=J),F!==null&&F.kind==="cut"&&vg(P))return q(F,y);if(O(X.rows,X.cols))return"rejected";if(F!==null){if(F.kind==="cut"&&(F.range.endRow>=F.sourceAdapter.rowCount||F.range.endCol>=F.sourceAdapter.colCount))return k.onOperationRejected?.("paste",F.payload.rows*F.payload.cols,"bounds"),"rejected";R=mi(F)}else{const Z=rd(L,$);if(Z===null)return S("unreadable");if(O(Z.rows,Z.cols))return"rejected";R=xg(Z)}}else if(p==="tsv"){const X=L.getData("text/plain"),J=Jp(X);if(O(J.rows,J.cols))return"rejected";R=Og(Bc(X))}else{const X=L.getData("text/html"),J=xd(X);if(J.cols===0&&J.rows>k.maxOperationCells)return k.onOperationRejected?.("paste",J.rows,"limit"),"rejected";if(O(J.rows,J.cols))return"rejected";const Z=Mc(X,p,k.formats===void 0?{}:{currency:k.formats.currency,locale:k.formats.locale},k.maxOperationCells);if(Z.outcome==="none")return S("unreadable");if(Z.outcome==="limit")return k.onOperationRejected?.("paste",Z.cells,"limit"),"rejected";if(O(Z.payload.rows,Z.payload.cols))return"rejected";R=Z.payload}const b=Br(v),a=di(D?hg(R):R,b),f=ga[P.mode];if(Rg(f)){const X=ns({rows:a.rows,cols:a.cols},y,m.active,v.rowCount,v.colCount);if(X!==null&&Qn(v,X))return k.rejectReadOnly({kind:"operation",op:"paste",cellCount:yt([X])}),"rejected"}const x={row:0,col:0,readText:()=>zn(v,x.row,x.col).text,readFormat:()=>v.getCellFormat===void 0?void 0:v.getCellFormat(x.row,x.col)},{edits:d,tiles:A}=Il(a.cells,y,m.active,v.rowCount,v.colCount,(X,J,Z)=>(x.row=J,x.col=Z,pi(X,a,x,P,b))),E=$g(A,a.rows,a.cols,v.rowCount,v.colCount);if(E===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let X=0;for(const Z of a.conditionalFormats)X+=Z.ranges.length;const J=A.length*X;if(J>k.maxOperationCells)return k.onOperationRejected?.("paste",J,"limit"),"rejected"}const T=f.cf?hi(a.conditionalFormats,A):[];if(d.length===0&&T.length===0)return C(a,E,f),"empty";r.current=F===null?"foreign":"own";let M=!1;try{M=g(d,{sameSheet:F!==null&&F.sourceAdapter===v,conditionalFormats:T})}finally{r.current="none"}if(!M)return"rejected";C(a,E,f);const V={row:E.startRow,col:E.startCol};return k.setSelection({ranges:[E],anchor:V,active:V}),"applied"},[q,g,C]),N=i.useCallback(async L=>{const $=D=>(t.current.onClipboardUnavailable?.(D),"rejected"),P=navigator;if(P.clipboard===void 0)return $("insecure-origin");let k;try{k=await P.clipboard.read({unsanitized:["text/html"]})}catch{return $("permission-denied")}if(k.length===0)return $("empty");const v=k[0],S=Array.from(v.types),p=new Map;try{for(const D of yg)S.includes(D)&&p.set(D,await(await v.getType(D)).text())}catch{return $("unreadable")}const m={types:S,getData:D=>{const O=p.get(D);if(O===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${D} was not materialised for the menu path`);return O}},y=t.current;return!y.enabled||y.isDragging()||y.isEditing()?"rejected":j(m,"menu",L)},[j]),_=i.useCallback(async L=>{const $=await N(L);return t.current.onPasteResolved?.($,"menu"),$},[N]),{enabled:Y,sinkRef:B}=e;return i.useEffect(()=>{const L=B.current;if(!Y||L===null)return;const $=S=>t.current.isDragging()?(S.preventDefault(),!0):!1,P=S=>{const p=t.current;if($(S)||p.isEditing())return;const m=h(S,"copy");m!==null&&c("copy",m.range,m.payload)},k=S=>{const p=t.current;if($(S)||p.isEditing())return;const m=h(S,"cut");m!==null&&c("cut",m.range,m.payload)},v=S=>{const p=t.current;if($(S)||p.isEditing())return;S.preventDefault();let m=ii;const y=p.pendingPasteOptionsRef;y!==void 0&&y.current!==null&&(m=y.current,y.current=null);const D=gi(S);if(D===null)return;const O=j(kg(D),"event",m);p.onPasteResolved?.(O,"event")};return L.addEventListener("copy",P),L.addEventListener("cut",k),L.addEventListener("paste",v),()=>{L.removeEventListener("copy",P),L.removeEventListener("cut",k),L.removeEventListener("paste",v)}},[Y,B,h,c,j]),i.useMemo(()=>({getClip:()=>{const L=n.current;return L===null?null:{kind:L.kind,range:L.range,foreign:L.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},Ca=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)}`)},ya=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}},wi=(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}`}`},ba=(e,t)=>{let n;if(e.exponent===null)n=wi(e.negative,e.digits,e.point+t);else{const r=wi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return et(n)===null?null:n},Lg=(e,t)=>{Ca(t);const n=et(e);return n===null?null:ba(ya(n),t)},Mg=e=>{const t=et(e);if(t!==null){const r=ya(t);return ba({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},va=e=>{if(!e.startsWith("=")||e.length===1)throw new RangeError(`[spreadsheet] self-calc expects a formula ("=" followed by a body); got ${JSON.stringify(e)}`);return e.slice(1)},zg=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},Ra=(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 zg(r)?r:null},Fg=(e,t)=>{Ca(t);const n=va(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Ra(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},Ng=e=>{const t=va(e),n=Ra(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Xn=(e,t,n,r)=>{const o=yt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Lr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Mr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Ci={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:Lr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Lr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Lr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Lr.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:Mr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Mr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Mr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Mr.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"}},Pg={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},sr=e=>e<10?`0${e}`:String(e),qg=e=>{const t=new Date(e);return`${t.getFullYear()}-${sr(t.getMonth()+1)}-${sr(t.getDate())}`},_g=e=>{const t=new Date(e);return`${sr(t.getHours())}:${sr(t.getMinutes())}:${sr(t.getSeconds())}`},jg=(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),Ig=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Hg=e=>e===void 0||e.borders===void 0?{}:e.borders,Bg={top:1,right:2,bottom:4,left:8},Vg={style:"thin",color:as},Wg=(e,t)=>{if(e===void 0)return!1;const n=Ue(e);return n!==null&&n===Ue(t)},Kg=(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}}},Yg=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[Ce(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(!Xn("format",y,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"format",cellCount:yt(y)}),!1;const D=new Map,O=[],R=m.adapter.getCellFormat;for(const F of y)qt([F],b=>{const a=R===void 0?void 0:R(b.row,b.col),{bucket:f,patch:x}=p(b,F,a);let d=D.get(f);d===void 0&&(d=new Map,D.set(f,d));let A;d.has(a)?A=d.get(a):(A=ds(a,x),d.set(a,A)),A!==a&&O.push({row:b.row,col:b.col,format:A===void 0?null:A})});return O.length===0?!0:m.commitEdits(O,{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=Vg)=>{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:Bg[p];return o((D,O,R)=>{const F=jg(D,O)&y;return{bucket:F,patch:{borders:{...Hg(R),...Ig(F,m)}}}})},[s,o]),u=i.useCallback((p,m,y)=>{const D=qc(t.current.adapter,p.row,p.col);for(const O of m)y.push(_c(D,p,O))},[]),h=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Xn("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;const D=[];if(p==="selection"){const R=y.active,F=[];qt(y.ranges,b=>{(b.row!==R.row||b.col!==R.col)&&F.push(b)}),D.push({source:R,targets:F})}else for(const R of y.ranges)if(p==="down"){const F=R.startRow===R.endRow;if(F&&R.startRow===0)continue;const b=F?R.startRow-1:R.startRow;for(let a=R.startCol;a<=R.endCol;a+=1){const f=[];for(let x=F?R.startRow:R.startRow+1;x<=R.endRow;x+=1)f.push({row:x,col:a});D.push({source:{row:b,col:a},targets:f})}}else{const F=R.startCol===R.endCol;if(F&&R.startCol===0)continue;const b=F?R.startCol-1:R.startCol;for(let a=R.startRow;a<=R.endRow;a+=1){const f=[];for(let x=F?R.startCol:R.startCol+1;x<=R.endCol;x+=1)f.push({row:a,col:x});D.push({source:{row:a,col:b},targets:f})}}for(const R of D)for(const F of R.targets)if(We(m.adapter,F.row,F.col)){let b=0;for(const a of D)b+=a.targets.length;return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:b}),!1}const O=[];for(const R of D)u(R.source,R.targets,O);return O.length===0?!0:m.commitEdits(O,{source:"fill"})!==null},[u]),g=i.useCallback(()=>{const p=t.current,m=p.getSessionText();if(m===null)return!1;const y=p.getSelection();if(!Xn("fill",y.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(En(p.adapter,y.ranges))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:yt(y.ranges)}),!1;const D=[];let O=!1;return qt(y.ranges,R=>{if(!O){if(!p.validateCommit(R,m).ok){O=!0;return}D.push({row:R.row,col:R.col,text:m})}}),O||p.commitEdits(D,{source:"fill"})===null?!1:(p.cancelEdit(),!0)},[]),C=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Xn("calc",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"calc",cellCount:yt(y.ranges)}),!1;const D=[],O=m.adapter;return qt(y.ranges,R=>{const F=O.getCellFormula===void 0?void 0:O.getCellFormula(R.row,R.col),b=F===void 0?p.text(O.getCellText(R.row,R.col)):p.formula(F);b!==null&&D.push({row:R.row,col:R.col,text:b})}),D.length===0?!0:m.commitEdits(D,{source:"calc"})!==null},[]),q=i.useCallback((p,m)=>{const y=t.current,D=p==="row"?y.rowAxis:y.colAxis,O=y.getSelection(),R=p==="row"?Math.floor(y.maxOperationCells/is):y.maxOperationCells;let F=0;for(const d of O.ranges)F+=p==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(F>R)return y.onOperationRejected?.("resize",F,"limit"),!1;const b=new Set,a=[],f=m?0:p==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const d of O.ranges){const A=p==="row"?d.startRow:d.startCol,E=p==="row"?d.endRow:d.endCol;for(let T=A;T<=E;T+=1){if(b.has(T))continue;b.add(T),D.sizeOf(T)===0!==m&&a.push({index:T,size:f})}}const x=cs(D,a,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:ls,axisKind:p});return x.ok?(x.entries.length>0&&y.resizeTracks(p,x.entries),!0):(y.onOperationRejected?.("resize",x.count,x.reason),!1)},[]),j=i.useCallback(()=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)return;const m=p.getActive();return Fn(p.adapter.getCellHyperlink(m.row,m.col))},[]),N=i.useCallback(p=>{const m=t.current,y=m.adapter,D=Ci[p],O=y.getCellFormat!==void 0,R=F=>m.popovers===void 0?!0:m.popovers[F]!==!1;switch(D.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return O;case"value":return O&&(D.value!=="currency"||m.formats!==void 0);case"popover":switch(D.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 D.options.mode==="formats"?O:D.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[j]),_=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 D=m.getActive();if(!We(m.adapter,D.row,D.col))return!0;if(y==="list")return m.rejectReadOnly({kind:"edit",cell:D,editSession:"none"}),!1;let O;if(y==="link")O=j()!==void 0;else if(y==="note"){const R=m.adapter.getCellNote===void 0?void 0:m.adapter.getCellNote(D.row,D.col);O=R!==void 0&&R!==""}else{const R=m.adapter.getCellComments===void 0?void 0:m.adapter.getCellComments(D.row,D.col);O=R!==void 0&&R.length>0}return O?!0:(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[j]),Y=i.useCallback(p=>{const m=t.current;if(!N(p))return!1;const y=Ci[p];if(!_(y))return!1;const D=m.isEditing();if(D&&!ks.has(p)&&!m.requestCommit())return!1;switch(y.kind){case"toggle":{const O=r(),R=O!==void 0&&O[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(Pg)?(l(p,null),!0):!1;case"value":return s({value:Kg(y.value,m.formats)})?(l(p,null),!0):!1;case"borders":return c(y.preset)?(l(p,null),!0):!1;case"color":{const O=y.key==="background"?m.colors.fill:m.colors.font,R=y.preset!==null?y.preset:y.custom!==null&&y.custom<O.length?O[y.custom]:void 0;if(R===void 0)return!1;const F=r(),b=Wg(F===void 0?void 0:F[y.key],R);return s({[y.key]:b?null:R})?(l(p,!b),!0):!1}case"calc":return C({text:O=>Lg(O,y.exponent),formula:O=>Fg(O,y.exponent)});case"sign":return C({text:Mg,formula:Ng});case"fill":return D&&y.direction==="selection"?g():h(y.direction);case"popover":return m.openPopover(y.popover),!0;case"openHyperlink":{if(m.onHyperlinkOpen!==void 0){const O=j();return O===void 0?!1:(m.onHyperlinkOpen(O,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 O=y.unit==="date"?qg(m.now()):_g(m.now());if(D)return m.insertAtCaret(O),!0;const R=m.getActive();return We(m.adapter,R.row,R.col)?(m.rejectReadOnly({kind:"edit",cell:R,editSession:"none"}),!1):m.validateCommit(R,O).ok?m.commitEdits([{row:R.row,col:R.col,text:O}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return q(y.axis,y.hide);default:{const O=m.getHighlight();switch(y.target){case"row":return m.setHighlight({...O,row:!O.row}),!0;case"column":return m.setHighlight({...O,column:!O.column}),!0;case"both":{const R=O.row&&O.column;return m.setHighlight({...O,row:!R,column:!R}),!0}default:return m.setHighlight({...O,intersection:!O.intersection}),!0}}}},[N,_,j,r,s,l,c,C,h,g,q]),B=i.useCallback(()=>{const p=t.current;return!(p.isEditing()&&!p.requestCommit())},[]),L=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(!B())return!1;const D=m.getActive();return We(m.adapter,D.row,D.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:D.row,col:D.col,hyperlink:y}],{source:"annotate"})!==null},[B]),$=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!B())return!1;const y=m.getActive();return We(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},[B]),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(!B())return!1;const D=m.getActive();if(We(m.adapter,D.row,D.col))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const O=y(D.row,D.col),R=O===void 0?[p]:[...O,p];return m.commitEdits([{row:D.row,col:D.col,comments:R}],{source:"annotate"})!==null},[B]),k=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!B())return!1;const y=m.getSelection().ranges;if(!Xn("annotate",y,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:yt(y)}),!1;const D=[];return qt(y,O=>{D.push({row:O.row,col:O.col,validation:p})}),m.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]),S=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:S,setHyperlink:L,setNote:$,addComment:P,setValidation:k,isCommandAvailable:N}),[Y,v,S,L,$,P,k,N])},zr="data-aqsp-pointing",Ug=(e,t)=>{const n=mc(e,t);return n!==null&&"insertAt"in n},Xg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Gg=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(Et),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=mc(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(zr)&&(a?b.setAttribute(zr,""):b.removeAttribute(zr))},[g]),q=i.useCallback((b,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const x=f.resolveEditPaint(a),d=x===null?Et:x;d!==Et&&Object.assign(b.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),j=i.useCallback(b=>{Xg(b,Object.keys(h.current.style)),h.current=Et;const a=t.current.editPaintRef;a!==void 0&&(a.current=Et)},[]),N=i.useCallback(b=>{const a=t.current,f=n.current;if(f===null)return!0;const x=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),j(d),d.removeAttribute(zr)),o(!1)};if(b.commit){const d=a.sinkRef.current,A=d===null?"":d.value,E=zn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
20
|
-
`),T=A===E;let M;if(T)M=!0;else if(We(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:b.onReject==="keep"?"kept":"discarded"}),M=!1;else{const V={source:"edit",editSession:b.onReject==="keep"?"kept":"discarded"};M=(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(!M)return b.onReject==="discard"&&(x(),a.rearmSink()),!1}return x(),b.rearm&&a.rearmSink(),!0},[j]),_=i.useCallback((b,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const x=f.sinkRef.current;if(x===null)return;const d=f.getActive();if(We(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),b==="edit"){const{text:E,isFormula:T}=zn(f.adapter,d.row,d.col);x.value=E;const M=a===void 0||T?E.length:Math.min(a,E.length);x.setSelectionRange(M,M)}else x.value="";const A=f.resolveEditAlign(d);A!==null&&(x.style.textAlign=A),q(x,d),c.current=!1,u.current=null,n.current={cell:d,mode:b},o(!0)},[q]),Y=i.useCallback(()=>{N({rearm:!0,commit:!1})},[N]),B=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 N({rearm:!1,commit:!0,onReject:"keep"})?(b.focusSink(),b.rearmSink(),!0):(b.focusSink(),!1)}return N({rearm:!0,commit:!0,onReject:"keep"})},[N]),L=i.useCallback(()=>g()!==null,[g]),$=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=gc(b.sink.value,b.sink.selectionStart);if(f===null)return null;const x=f.token,d=u.current;switch(x.kind){case"cell":{const A={row:x.row,col:x.col};return u.current=A,{origin:A,cursor:A,axis:"cells"}}case"range":{const A=d!==null&&(d.row===x.start.row||d.row===x.end.row)&&(d.col===x.start.col||d.col===x.end.col)?{row:d.row,col:d.col}:{row:x.start.row,col:x.start.col};return u.current=A,{origin:A,cursor:{row:A.row===x.start.row?x.end.row:x.start.row,col:A.col===x.start.col?x.end.col:x.start.col},axis:"cells"}}case"column":{const A=d!==null&&(d.col===x.start.col||d.col===x.end.col)?d.col:x.start.col,E={row:a.cell.row,col:A};return u.current=E,{origin:E,cursor:{row:a.cell.row,col:A===x.start.col?x.end.col:x.start.col},axis:"columns"}}case"row":{const A=d!==null&&(d.row===x.start.row||d.row===x.end.row)?d.row:x.start.row,E={row:A,col:a.cell.col};return u.current=E,{origin:E,cursor:{row:A===x.start.row?x.end.row:x.start.row,col:a.cell.col},axis:"rows"}}}},[g]),k=i.useCallback((b,a)=>{const f=g();if(f===null)return;const x=af(b,a),{sink:d}=f,[A,E]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],T=d.value;d.value=`${T.slice(0,A)}${x}${T.slice(E)}`;const M=A+x.length;d.setSelectionRange(M,M),"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}},[]),S=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=yf(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,x=a.selectionEnd;a.value=`${a.value.slice(0,f)}${b}${a.value.slice(x)}`;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},[]),D=i.useCallback(()=>n.current===null?null:n.current.cell,[]),O=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:F}=e;return i.useEffect(()=>{const b=F.current;if(!R||b===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},x=E=>{const T=t.current;if(l.current||n.current===null)return;const M=T.rootRef.current,V=E.relatedTarget;M!==null&&V instanceof Node&&M.contains(V)||N({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const E=t.current;u.current=null,E.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Ug(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",x),b.addEventListener("input",d),document.addEventListener("selectionchange",A),()=>{b.removeEventListener("compositionstart",a),b.removeEventListener("compositionend",f),b.removeEventListener("focusout",x),b.removeEventListener("input",d),document.removeEventListener("selectionchange",A)}},[R,F,N,C]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:B,cancelEdit:Y,startEdit:_,getPointing:L,togglePointingArm:$,getReferenceCursor:P,insertReference:k,captureSink:v,restoreSink:S,cycleAnchorAtCaret:p,insertAtCaret:m,getSessionText:y,getSessionCell:D,refreshPaint:O,editing:r}),[B,Y,_,L,$,P,k,v,S,p,m,y,D,O,r])},Jg=(e,t,n)=>{const r=new Xe.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}},Zg=(e,t,n)=>{const{tree:r,initialHidden:o}=Jg(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}},It=(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)},Tn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:It(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=It(e,o,1);return r},yi=(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=Zg(e,t,r)),o.current.model},$n=256,Po=256,Qg=2**32,em=4096,ka=Object.freeze([]),Sa=["background","color","bold","italic","underline","strikethrough"],Ea=(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>=em&&e.clear(),e.set(t,n),n),Aa=e=>(Ea(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Oa=(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},tm=(e,t,n)=>{const r=Math.floor(t/$n),o=Math.floor(n/Po),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*$n,u=o*Po,h=[];for(const g of e.rules)Oa(g.ranges,c,c+$n-1,u,u+Po-1)&&h.push(g);return Ht(e.buckets,s,h.length===0?ka:h)},nm=(e,t,n)=>{const r=Math.floor(t/$n),o=r*Qg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=tm(e,t,n),c=r*$n,u=[];for(const h of l)Oa(h.ranges,c,c+$n-1,n,n)&&u.push(h);return Ht(e.columns,o,u.length===0?ka:u)},rm=(e,t)=>{for(const n of e)if(cn(n,t))return!0;return!1},Es=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Fr=(e,t)=>e<t?-1:e>t?1:0,bi=(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}},vi=new WeakMap,ss=e=>e===null?null:Number(e),om=e=>{const t=vi.get(e);if(t!==void 0)return t;const n=e.b,r={a:ss(et(e.a)),b:n===void 0?null:ss(et(n))};return vi.set(e,r),r},xa=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Ht(e.numbers,r,ss(et(n())))},sm=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=om(e),l=xa(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return bi(e.op,Fr(l,s.a),c===null?null:Fr(l,c));const u=n(),h=e.b;return bi(e.op,Fr(u,e.a),h===void 0?null:Fr(u,h))},lm=(e,t)=>{switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);case"endsWith":return t.endsWith(e.value);default:return!1}},qo=e=>{const t=Ue(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"),_o=(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)}`},jo=(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=qo(t.color),u=qo(r.color);const h=n===void 0?void 0:qo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const 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?_o(c,h,jo(e,s,C)):_o(h,u,jo(e,C,l))}return _o(c,u,jo(e,s,l))},cm=(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})},am=(e,t,n,r,o,s)=>{const l=xa(s,n,r);if(l===null)return null;const c=cm(e,t,o,s);return c===null?null:im(l,t.min,t.mid,t.max,c)},um=(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},dm=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return sm(s,t,n,o)?e.style:null;case"text":return lm(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=am(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return um(e,s,t,r,o)?e.style:null;default:return null}},Ri=(e,t)=>ds(e,t),fm=(e,t,n)=>{e[t]=n},pm=(e,t)=>{let n=e;for(const r of Sa)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),fm(n,r,t[r]));return n},hm=e=>{let t="";for(const n of Sa){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},ki=new WeakMap,gm=Object.freeze({}),mm=e=>{const t=e===void 0?gm:e,n=ki.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return ki.set(t,r),r},wm=(e,t,n)=>{const r=mm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=Ri(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=hm(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Ri(e,t);return l!==void 0&&Ht(r.byKey,o,l),l},As=(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,g=!0;for(const C of c){if(!rm(C.ranges,u))continue;const q=dm(C,u,s,e,n);if(q!==null){if(q!==C.style&&(g=!1),h===null)h=q;else{const j=pm(h,q);j!==h&&(g=!1,h=j)}if(C.stopIfTrue===!0)break}}return h===null?l:wm(l,h,g)},Si=new WeakMap,Cm=e=>{Ea(e,"widthRelevantRules");const t=Si.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 Si.set(e,r),r},ym=({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},bm=i.memo(ym),vm=Object.freeze({left:Object.freeze({justifyContent:tr("left")}),center:Object.freeze({justifyContent:tr("center")}),right:Object.freeze({justifyContent:tr("right")})}),Rm=4096,Ei=new WeakMap,Pr=new Map,km=(e,t)=>{if(e===null)return vm[t];let n=Ei.get(e);n===void 0&&(n={},Ei.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:tr(t)},s=JSON.stringify(o);let l=Pr.get(s);return l===void 0&&(Pr.size>=Rm&&Pr.clear(),l=Object.freeze(o),Pr.set(s,l)),n[t]=l,l},Sm=Es(),Em=(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},Am=(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=Hr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const g=As(e,r===null?null:r.indexRef.current,r===null?Sm:r.memoRef.current,o,s,l);h=g===void 0?void 0:g.value;const C=zc(g,l),q=It(n,s,1),j=It(t,o,1),N=_d(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);N!==null&&Object.assign(c,N.attrs),c["data-aqsp-align"]=C,u=km(N,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&&Fn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&Uh(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Om=({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:N,focusSink:_,isEditing:Y,requestCommit:B,testId:L,__onCellRender:$,__maxRenderedCells:P,cfIndexRef:k,cfMemoRef:v,isPointing:S,tapScrollCircleOptions:p,overscanRows:m,overscanCols:y,background:D,onRenderTruncated:O,locale:R,scrollLabels:F})=>{const b=i.useRef(null),a=s??b;if(k===void 0!=(v===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const f=i.useMemo(()=>k===void 0||v===void 0?null:{indexRef:k,memoRef:v},[k,v]),x=i.useCallback(()=>r.get().editVersion,[r]),d=i.useCallback(ce=>r.subscribeCoalesced(ce),[r]),E=i.useSyncExternalStore(d,x,x)+(l??0),T=i.useCallback(ce=>t.sizeOf(ce),[t]),M=i.useCallback(ce=>n.sizeOf(ce),[n]),V=i.useCallback((ce,Re)=>e.getCellText(ce,Re),[e]),X=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),J=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),Z=i.useMemo(()=>({width:dt,tapScrollCircleOptions:p}),[p]),ne=i.useRef({row:-1,col:-1,value:void 0}),ie=i.useCallback((ce,Re)=>{const De={role:"gridcell","aria-rowindex":ce+1,"aria-colindex":Re+1,"data-aqsp-cell":"","data-row":ce,"data-col":Re,className:"aqsp-cell",...We(e,ce,Re)?{"aria-readonly":"true","data-aqsp-readonly":""}:{}},Ne=Vp(e,ce,Re),_e=Ne===null?De:{...De,...Ne},qe=Am(e,t,n,f,ce,Re),bt=ne.current;return bt.row=ce,bt.col=Re,bt.value=qe===null?void 0:qe.value,qe===null?_e:qe.style===null?{..._e,...qe.attrs}:{..._e,...qe.attrs,style:qe.style}},[e,t,n,f]),se=i.useCallback(ce=>({role:"row","aria-rowindex":ce+1,"data-aqsp-row":ce,"data-aqsp-cells":"",className:"aqsp-row"}),[]),ze=i.useCallback((ce,Re,De)=>{let Ne=ce;return e.getCellFormat!==void 0&&(Ne=Ln(ce,Em(ne.current,Re,De))),K.jsx(bm,{row:Re,col:De,text:ce,display:Ne,renderCell:q,__onCellRender:$})},[E,q,$,e]);return K.jsx("div",{ref:a,className:"aqsp-body","data-aqsp-body":"","data-testid":L?`${L}-body`:void 0,onPointerDownCapture:ce=>{if(!(ce.target instanceof Element&&ce.target.closest("[data-aqsp-cells]")!==null)&&ce.pointerType==="mouse"){if(ce.button!==0){ce.preventDefault();return}if(ce.preventDefault(),S?.()===!0){ce.stopPropagation(),_();return}if(Y()&&!B()){ce.stopPropagation(),_();return}_()}},children:K.jsx(Xe.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:g,frozenTrailingRows:C,getRowHeight:T,getColWidth:M,getCell:V,getCellProps:ie,getRowProps:se,contentProps:X,behaviorOptions:J,scrollBarOptions:Z,overscanRows:m,overscanCols:y,background:D,onRenderTruncated:O,__maxRenderedCells:P,locale:R,labels:F,callbackThrottleMs:0,onScroll:j,onRangeChange:N,testId:L,children:ze})})},xm=i.memo(Om),An=6,Qe=3,Xr=(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=It(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-An,length:Qe}),r.push({kind:"unhide",index:s+1,start:c-Qe,length:Qe})):l>=2*An?n.push({kind:"resize",index:s,start:c-An,length:An}):n.push({kind:"resize",index:s,start:c-Qe,length:Qe})}return[...n,...r]},Ta=(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*An?n.push({kind:"resize",index:c,start:h,length:An}):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]},Tm=({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=Xe.useWheelBridge(o),N=i.useCallback(d=>(s.current=d,j(d)),[s,j]),_=i.useCallback(()=>{const{colStart:d,colEnd:A,colVersion:E}=e.get();return`${d}:${A}:${E}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,_,_);const{colStart:B,colEnd:L}=e.get(),$=t.count===0?0:t.offsetOf(Math.min(B,t.count-1));i.useLayoutEffect(()=>{c.current=$,u()},[$,c,u]);const P=d=>h.some(A=>d>=A.startCol&&d<=A.endCol),k=Math.min(Math.max(0,n),t.count),v=ra(t,k),S=k>0?Tn(t,0,k-1):[],p=Math.min(Math.max(0,r),t.count-k),m=sa(t,p),y=t.totalSize()-m,D=p>0?Tn(t,t.count-p,t.count-1):[],O=Tn(t,Math.max(B,k),Math.min(L,Math.max(0,t.count-1)-p)),R=[];for(const d of O)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)-$,width:t.sizeOf(d)},children:or(d)},d));const F=g?Xr(t,O):null,b=F===null?null:F.filter(d=>!(d.kind==="unhide"&&d.index<k&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=g&&k>0?Xr(t,S):null,f=g&&p>0?Ta(t,D):null,x=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-$,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-$,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:N,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:k===0&&p===0?x:K.jsxs(K.Fragment,{children:[S.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:or(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(${dt}px + min(${m}px, max(0px, 100% - ${dt+v}px)))`:void 0},children:[x,k>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+dt}px))`,right:dt},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[D.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:or(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]})})},$m=({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=Xe.useWheelBridge(n),N=i.useCallback(d=>(r.current=d,j(d)),[r,j]),_=d=>o.some(A=>d>=A.startRow&&d<=A.endRow),Y=i.useCallback(()=>{const{rowStart:d,rowEnd:A,rowGeomVersion:E}=e.get();return`${d}:${A}:${E}`},[e]),B=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(B,Y,Y);const{rowStart:L,rowEnd:$}=e.get(),P=t.count===0?0:t.offsetOf(Math.min(L,t.count-1));i.useLayoutEffect(()=>{l.current=P,c()},[P,l,c]);const k=Math.min(Math.max(0,h),t.count),v=oa(t,k),S=k>0?Tn(t,0,k-1):[],p=Math.min(Math.max(0,g),t.count-k),m=la(t,p),y=t.totalSize()-m,D=p>0?Tn(t,t.count-p,t.count-1):[],O=Tn(t,Math.max(L,k),Math.min($,Math.max(0,t.count-1)-p)),R=[];for(const d of O)R.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-P,height:t.sizeOf(d)},children:d+1},d));const F=u?Xr(t,O):null,b=F===null?null:F.filter(d=>!(d.kind==="unhide"&&d.index<k&&v>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=u&&k>0?Xr(t,S):null,f=u&&p>0?Ta(t,D):null,x=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:N,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:dt},children:k===0&&p===0?x:K.jsxs(K.Fragment,{children:[S.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:v,bottom:p>0?`calc(min(${m}px, max(0px, 100% - ${v}px)))`:void 0},children:[x,k>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:[D.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-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]})})},Dm=9,Lm=4,Mm=(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},Ai=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,zm=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(k=>s.current!==null?k.pointerId===s.current:k.pointerType==="mouse",[]),q=i.useCallback(()=>{const k=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),k.writeResizeGuide(null);const v=g.current;v!==null&&(window.removeEventListener("pointermove",v.move),window.removeEventListener("pointerup",v.up),g.current=null);const S=c.current;S!==null&&s.current!==null&&S.hasPointerCapture?.(s.current)&&S.releasePointerCapture(s.current),c.current=null,s.current=null,k.repaintOverlay()},[]),j=i.useCallback((k,v)=>{const S=t.current;return k==="col"?v.startRow===0&&v.endRow===S.rowAxis.count-1:v.startCol===0&&v.endCol===S.colAxis.count-1},[]),N=i.useCallback((k,v)=>{const S=t.current,p=S.getSelection().ranges.filter(R=>j(k,R));if(!p.some(R=>k==="col"?v>=R.startCol&&v<=R.endCol:v>=R.startRow&&v<=R.endRow))return[v];const y=p.reduce((R,F)=>R+(k==="col"?F.endCol-F.startCol+1:F.endRow-F.startRow+1),0),D=k==="row"?Math.floor(S.maxOperationCells/is):S.maxOperationCells;if(y>D)return S.onOperationRejected?.("resize",y,"limit"),null;const O=new Set;for(const R of p){const F=k==="col"?R.startCol:R.startRow,b=k==="col"?R.endCol:R.endRow;for(let a=F;a<=b;a+=1)O.add(a)}return[...O]},[j]),_=i.useCallback((k,v,S)=>{const p=t.current,m=k==="col"?p.colAxis:p.rowAxis,y=cs(m,v,S,{maxOperationCells:p.maxOperationCells,rowHiddenLimit:ls,axisKind:k});if(!y.ok){p.onOperationRejected?.("resize",y.count,y.reason);return}p.resizeTracks(k,y.entries)},[]),Y=i.useCallback((k,v)=>{if(v===k.initialSize)return;const S=k.kind==="unhide"?[k.index]:N(k.axis,k.index);S!==null&&_(k.axis,S.map(p=>({index:p,size:v})),k.index)},[N,_]),B=i.useCallback((k,v)=>{const S=t.current,p=N("col",v);if(p===null)return;const m=S.handleRef.current,y=m===null?null:m.getFrozenSize(),D=y===null?0:y.rows,O=y===null?0:y.trailingRows,{rowStart:R,rowEnd:F}=S.viewStore.get(),b=Math.min(F,S.rowAxis.count-1),a=[],f=new Set,x=se=>{!f.has(se)&&S.rowAxis.sizeOf(se)>0&&(f.add(se),a.push(se))};for(let se=0;se<D;se+=1)x(se);for(let se=R;se<=b;se+=1)x(se);for(let se=S.rowAxis.count-O;se<S.rowAxis.count;se+=1)x(se);if(a.length===0)return;const d=p.length*a.length,A=Math.floor(S.maxOperationCells/Lm);if(d>A){S.onOperationRejected?.("resize",d,"limit");return}const E=document.createElement("canvas").getContext("2d");if(E===null)return;const T=getComputedStyle(k),M=`${T.fontStyle} ${T.fontWeight} ${T.fontSize} ${T.fontFamily}`,V=S.adapter.getConditionalFormats===void 0?null:Cm(S.adapter.getConditionalFormats()),X=Es(),J=new WeakMap,Z=new Map;for(const se of p){const ze=V===null?null:Aa(V.filter(ce=>ce.ranges.some(Re=>se>=Re.startCol&&se<=Re.endCol)));for(const ce of a){const Re=S.adapter.getCellText(ce,se),De=S.adapter.getCellFormat===void 0?void 0:As(S.adapter,ze,X,ce,se,()=>Re),Ne=De===void 0?M:Mm(De,J,T),_e=Ln(Re,De===void 0?void 0:De.value),qe=Z.get(Ne);qe===void 0?Z.set(Ne,[{col:se,text:_e}]):qe.push({col:se,text:_e})}}const ne=new Map;for(const[se,ze]of Z){E.font=se;for(const ce of ze){const Re=E.measureText(ce.text).width,De=ne.get(ce.col);(De===void 0||Re>De)&&ne.set(ce.col,Re)}}const ie=[];for(const se of p){const ze=ne.get(se);ze!==void 0&&ze>0&&ie.push({index:se,size:Math.ceil(ze)+Dm})}ie.length!==0&&_("col",ie,v)},[N,_]),{enabled:L,colBandRef:$,rowBandRef:P}=e;return i.useEffect(()=>{const k=$.current,v=P.current;if(!L||k===null||v===null)return;const S=A=>A==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",p=(A,E)=>{if(!(E instanceof Element))return null;const T=E.closest(S(A));if(T===null)return null;const M=T.hasAttribute("data-aqsp-unhide"),V=Number(T.getAttribute(M?"data-aqsp-unhide":A==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),X=T.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:M?"unhide":"resize",index:V,anchor:X}},m=A=>{if(!(n.current&&C(A)))return;const E=r.current;if(E===null)return;const T=(E.axis==="col"?A.clientX-E.startClientX:A.clientY-E.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(E.anchor==="trailing"?E.initialSize-T:E.initialSize+T)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const M=r.current;if(!n.current||M===null)return;const V=t.current,X=M.axis==="col"?V.colAxis:V.rowAxis;V.writeResizeGuide({axis:M.axis,position:Ai(M,X,o.current),anchor:M.anchor})}))},y=()=>{const A=r.current,E=o.current;q(),A!==null&&Y(A,E)},D=A=>{m(A),n.current&&C(A)&&(l.current&1)!==0&&(A.buttons&1)===0&&y()},O=A=>{A.button!==0||!(n.current&&C(A))||y()},R=(A,E)=>T=>{const M=t.current;if(h.current=T.pointerType,T.pointerType!=="mouse")return;if(T.button!==0){T.preventDefault();return}const V=p(A,T.target);if(V===null)return;if(T.stopPropagation(),T.preventDefault(),M.isPointing()){M.focusSink();return}if(M.isEditing()&&!M.requestCommit()){M.focusSink();return}M.focusSink();const X=A==="col"?M.colAxis:M.rowAxis,J={axis:A,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,M.repaintOverlay(),s.current=T.pointerId,c.current=E;try{E.setPointerCapture(T.pointerId)}catch{s.current=null}const Z=D,ne=O;g.current={move:Z,up:ne},window.addEventListener("pointermove",Z),window.addEventListener("pointerup",ne),M.writeResizeGuide({axis:A,position:Ai(J,X,o.current),anchor:J.anchor})},F=(A,E)=>T=>{const M=t.current;if(h.current!=="mouse")return;const V=E.getRootNode(),X=V instanceof ShadowRoot?V:E.ownerDocument,J=T.target instanceof Element&&T.target.closest(S(A))!==null?T.target:typeof X.elementFromPoint=="function"?X.elementFromPoint(T.clientX,T.clientY):null,Z=p(A,J);if(Z!==null){if(T.stopPropagation(),M.isEditing()){M.focusSink();return}if(Z.kind==="unhide"){_(A,[{index:Z.index,size:A==="col"?M.defaultColumnWidth:M.defaultRowHeight}],null);return}if(M.autofitEnabled){if(A==="row"){const ne=N("row",Z.index);ne!==null&&_("row",ne.map(ie=>({index:ie,size:M.defaultRowHeight})),Z.index);return}B(E,Z.index)}}},b=A=>{!n.current||s.current===null||A.pointerId!==s.current||q()},a=R("col",k),f=R("row",v),x=F("col",k),d=F("row",v);return k.addEventListener("pointerdown",a,{capture:!0}),v.addEventListener("pointerdown",f,{capture:!0}),k.addEventListener("dblclick",x),v.addEventListener("dblclick",d),k.addEventListener("lostpointercapture",b),v.addEventListener("lostpointercapture",b),()=>{k.removeEventListener("pointerdown",a,{capture:!0}),v.removeEventListener("pointerdown",f,{capture:!0}),k.removeEventListener("dblclick",x),v.removeEventListener("dblclick",d),k.removeEventListener("lostpointercapture",b),v.removeEventListener("lostpointercapture",b),q()}},[L,$,P,C,q,Y,_,N,B]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&q()},cancelDrag:q}),[q])},Os=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Fm=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Os(n,t.ranges[r]))&&Ot(e.anchor,t.anchor)&&Ot(e.active,t.active),Nm=(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:Ce(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},Pm=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Os(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},cr=(e,t,n)=>n.extend?rn(e,t):n.append?{ranges:[...e.ranges,Ce(t,t)],anchor:t,active:t}:e.ranges.length===1&&Ot(e.anchor,t)&&Ot(e.active,t)&&Os(e.ranges[0],Ce(t,t))?e:{ranges:[Ce(t,t)],anchor:t,active:t},qm=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),rn=(e,t)=>{const n=Pm(e,Ce(e.anchor,t));return n.ranges.some(r=>cn(r,n.active))?n:{...n,active:qm(n.active,n.ranges[n.ranges.length-1])}},$a=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(Ce({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Ce({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Ce({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Ce({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Ce(n,n)],anchor:n,active:n};const s=o.findIndex(c=>cn(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},_m=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Da=(e,t)=>{const n=e.ranges.findIndex(o=>cn(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=_m(e.ranges,r.rangeIndex,r.cell,t),!Ot(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},St=24,Oi=32,Gr=4,bn=({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 N=u.current,_=e.current,Y=g.current;if(N===null||_===null||Y===null){c.current=null;return}const{clientX:B,clientY:L}=N.getPointerPosition(),$=l.current,P=(B-Y.left)/$,k=(L-Y.top)/$,v=_.getViewportSize(),S=v.width,p=v.height;if(S<=0||p<=0){c.current=requestAnimationFrame(q);return}const m=b=>Math.min(Oi,Math.ceil(b/St*Oi));let y=0,D=0;if(s!=="x"){const b=_.getFrozenSize(),a=b.trailingVisibleHeight;k>p-a-St?N.anchorRow!==void 0&&b.trailingRows>0&&N.anchorRow>=t.count-b.trailingRows&&a>0&&k>=p-a||(y=m(k-(p-a-St))):k<b.height+St&&(N.anchorRow!==void 0&&N.anchorRow<b.rows&&b.height>0&&k<b.height||(y=-m(b.height+St-k)))}if(s!=="y"){const b=_.getFrozenSize(),a=b.trailingVisibleWidth;P>S-a-St?N.anchorCol!==void 0&&b.trailingCols>0&&N.anchorCol>=n.count-b.trailingCols&&a>0&&P>=S-a||(D=m(P-(S-a-St))):P<b.width+St&&(N.anchorCol!==void 0&&N.anchorCol<b.cols&&b.width>0&&P<b.width||(D=-m(b.width+St-P)))}const O=D!==0||y!==0?_.scrollBy({x:D!==0?D:void 0,y:y!==0?y:void 0}):_.getScrollPosition(),R=O.y,F=O.x;if(R>=0&&F>=0&&t.totalSize()>0&&n.totalSize()>0){const b=_.getFrozenSize(),a=Vt({row:hr(t,k,{scroll:R,frozenSize:b.height,trailingSize:b.trailingHeight,extent:v.height}),col:pr(n,P,{scroll:F,frozenSize:b.width,trailingSize:b.trailingWidth,extent:v.width})},t.count,n.count),f=h.current;(y!==0||D!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(N.buildRange(a)))}c.current=requestAnimationFrame(q)},[e,t,n,s,o]),j=i.useCallback(N=>{C(),u.current=N,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(q)},[C,q,r]);return i.useEffect(()=>{const N=()=>{document.visibilityState==="hidden"&&C()};return document.addEventListener("visibilitychange",N),()=>{document.removeEventListener("visibilitychange",N),C()}},[C]),i.useMemo(()=>({start:j,stop:C}),[j,C])},xi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),g=i.useRef(null),C=i.useRef(!1),q=i.useRef(0),j=i.useCallback((v,S)=>{const{axis:p,mainAxis:m,handleRef:y,zoomRef:D}=t.current,O=s.current;if(O===null||m.totalSize()===0)return null;const R=D.current,F=y.current;if(F===null)return null;if(p==="col"){const x=F.getScrollPosition().x;if(x<0)return null;const d=F.getFrozenSize(),A=F.getViewportSize();return Math.min(Math.max(pr(m,(v-O.left)/R,{scroll:x,frozenSize:d.width,trailingSize:d.trailingWidth,extent:A.width}),0),m.count-1)}const b=F.getScrollPosition().y;if(b<0)return null;const a=F.getFrozenSize(),f=F.getViewportSize();return Math.min(Math.max(hr(m,(S-O.top)/R,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),m.count-1)},[]),N=i.useCallback((v,S)=>{const{axis:p,crossCount:m}=t.current;return p==="col"?{press:{row:0,col:v},extend:{row:m-1,col:S}}:{press:{row:v,col:0},extend:{row:S,col:m-1}}},[]),_=i.useCallback((v,S)=>{const{axis:p,crossCount:m}=t.current;return v.ranges.some(y=>p==="col"?y.startRow===0&&y.endRow===m-1&&S>=y.startCol&&S<=y.endCol:y.startCol===0&&y.endCol===m-1&&S>=y.startRow&&S<=y.endRow)},[]),Y=i.useRef(!1),B=i.useRef({clientX:0,clientY:0}),L=i.useCallback(()=>{Y.current=!1;const{autoScroller:v,headerRef:S,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=S.current;m!==null&&u.current!==null&&m.hasPointerCapture?.(u.current)&&m.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),L()},[L]),{enabled:P,headerRef:k}=e;return i.useEffect(()=>{const v=k.current;if(!P||v===null)return;const S=F=>{const b=t.current;if(F.pointerType!=="mouse")return;if(F.button!==0){F.preventDefault();return}if(C.current=!1,b.pointing?.getPointing()){s.current=v.getBoundingClientRect();const d=j(F.clientX,F.clientY);if(d===null)return;F.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()){F.preventDefault(),b.focusSink();return}s.current=v.getBoundingClientRect();const a=j(F.clientX,F.clientY);if(a===null)return;F.preventDefault(),b.focusSink();const f=b.getSelection();r.current=f;const x=F.ctrlKey||F.metaKey;if(F.shiftKey){const d=b.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:A}=N(a,a),E={...f,anchor:d};b.setSelection(rn(E,A)),o.current=b.axis==="col"?d.col:d.row}else if(x&&_(f,a))C.current=!0,q.current=a,o.current=a;else{const{press:d,extend:A}=N(a,a),E=cr(f,d,{extend:!1,append:x});b.setSelection(rn(E,A)),o.current=a}n.current=!0,b.repaintOverlay(),l.current={clientX:F.clientX,clientY:F.clientY},u.current=F.pointerId,h.current=F.buttons;try{v.setPointerCapture(F.pointerId)}catch{u.current=null}g.current=d=>{const A=t.current.axis==="col"?d.col:d.row,{press:E}=N(o.current,o.current),{extend:T}=N(o.current,A);return Ce(E,T)},b.autoScroller.stop(),Y.current=!1,B.current={clientX:F.clientX,clientY:F.clientY}},p=F=>u.current!==null?F.pointerId===u.current:F.pointerType==="mouse",m=F=>{if(n.current&&p(F)){if(C.current){const b=F.clientX!==l.current.clientX||F.clientY!==l.current.clientY;if(l.current={clientX:F.clientX,clientY:F.clientY},!b)return;const a=j(F.clientX,F.clientY);if(a===null||a===q.current)return;C.current=!1;const f=t.current,{press:x,extend:d}=N(q.current,q.current),A=cr(f.getSelection(),x,{extend:!1,append:!0});f.setSelection(rn(A,d));const E=g.current,T=Math.abs(F.clientX-B.current.clientX),M=Math.abs(F.clientY-B.current.clientY);E!==null&&Math.max(T,M)>=Gr&&(Y.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:E,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:F.clientX,clientY:F.clientY},!Y.current&&g.current!==null){const b=Math.abs(F.clientX-B.current.clientX),a=Math.abs(F.clientY-B.current.clientY);Math.max(b,a)>=Gr&&(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=F=>{m(F),n.current&&p(F)&&(h.current&1)!==0&&(F.buttons&1)===0&&O(F)},D=F=>{F.button!==0||!(n.current&&p(F))||O(F)},O=F=>{const b=t.current;if(C.current){const{press:f,extend:x}=N(q.current,q.current);b.setSelection($a(b.getSelection(),Ce(f,x),f)),L();return}const a=j(F.clientX,F.clientY);if(a!==null){const{extend:f}=N(o.current,a);b.setSelection(rn(b.getSelection(),f))}L()},R=F=>{!n.current||u.current===null||F.pointerId!==u.current||$()};return v.addEventListener("pointerdown",S),v.addEventListener("pointermove",y),v.addEventListener("pointerup",D),v.addEventListener("lostpointercapture",R),()=>{v.removeEventListener("pointerdown",S),v.removeEventListener("pointermove",y),v.removeEventListener("pointerup",D),v.removeEventListener("lostpointercapture",R),L()}},[P,k,j,N,L,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:$,cancelDrag:L}),[$,L])},jm=({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)})}},Im=50,Hm=100,La=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Im:!1,Gn={selectAll:nn("Ctrl+A"),undo:nn("Ctrl+Z"),redo:nn("Ctrl+Y"),redoShiftZ:nn("Ctrl+Shift+Z"),pasteValues:nn("Ctrl+Shift+V")},Bm=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Vm={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Wm=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Km=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,x)=>It(a,f,x)??f,N=(a,f)=>{const x=s.current;return f==="left"||f==="right"?{row:a.row,col:j(x.colAxis,a.col,f==="right"?1:-1)}:{row:j(x.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),Y=a=>a.indexAt(a.totalSize()-1),B=(a,f,x,d)=>{if(a.sizeOf(f)>0)return f;const A=It(a,f,x);if(A!==null)return A;const E=It(a,f,x===1?-1:1);return E!==null?E:d},L=()=>{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=>N(L(),a),P=(a,f)=>{const x=s.current,d=f==="left"||f==="right",A=f==="right"||f==="down"?1:-1;let E;return x.findDataEdge!==void 0?(E=x.findDataEdge({row:a.row,col:a.col},f),k(E,a,f)):E={row:f==="down"?x.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?x.colAxis.count-1:f==="left"?0:a.col},d?{row:E.row,col:B(x.colAxis,E.col,A,a.col)}:{row:B(x.rowAxis,E.row,A,a.row),col:E.col}},k=(a,f,x)=>{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=x==="left"||x==="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,x)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${x} component ${a} (count ${f})`)},S=a=>{const f=s.current,x=f.getSelection();if(Da(x,a)===x){f.moveActive({mode:"reset",cell:N(x.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,x=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
|
|
21
|
-
${a.value.slice(x)}`,a.setSelectionRange(f+1,f+1)},m=(a,f)=>{const x=s.current,d=h.current?.getViewportSize().height??-1;return d<=0?j(x.rowAxis,a,f==="down"?1:-1):x.rowAxis.indexAt(x.rowAxis.offsetOf(a)+(f==="down"?d:-d))},y=a=>{const f=s.current;if(r.current=!1,La(a,t.current))return;const x=a.ctrlKey||a.metaKey,d=a.altKey,A=Vm[a.key];if(o.current&&!Bm.has(a.key)&&!f.isDragging()&&q(),f.isEditing()){const T=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!x&&!a.shiftKey&&!d&&f.abortDrag();return}const M=f.pointing;if(M!==void 0){if(A!==void 0&&!d){const X=M.getReferenceCursor();if(X!==null){a.preventDefault();const J=Vt(X.cursor,f.rowAxis.count,f.colAxis.count),Z=Vt(X.origin,f.rowAxis.count,f.colAxis.count),ne=x?P(J,A):N(J,A);if(f.ensureCellVisible(ne),M.insertReference(a.shiftKey?Ce(Z,ne):ne,X.axis),f.onPointFrame!==void 0){const ie=a.shiftKey?Ce(Z,ne):Ce(ne,ne);f.onPointFrame(X.axis==="columns"?Ce({row:0,col:ie.startCol},{row:f.rowAxis.count-1,col:ie.endCol}):X.axis==="rows"?Ce({row:ie.startRow,col:0},{row:ie.endRow,col:f.colAxis.count-1}):ie),o.current=!0}return}}if(a.key==="F2"&&!x&&!a.shiftKey&&!d&&M.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!x&&!a.shiftKey&&!d&&M.cycleAnchorAtCaret()){a.preventDefault();return}}const V=f.commands;if(V!==void 0){const X=Bl(V.table,a);if(X!==null&&ks.has(X)&&V.isAvailable(X)){a.preventDefault(),V.execute(X);return}}if(A!==void 0&&!d){if(x&&a.shiftKey){a.preventDefault();return}if(x)return;if(T==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:$(A)}):f.moveActive({mode:"reset",cell:N(f.getSelection().active,A)});return}return}if(a.key==="Enter"&&d&&!x&&!a.shiftKey){a.preventDefault(),p();return}if((a.key==="Enter"||a.key==="Tab")&&!x&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=!a.shiftKey;S(a.key==="Tab"?X?"right":"left":X?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!x&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(X.row,a.key==="PageDown"?"down":"up"),col:X.col}});return}if(a.key==="Escape"&&!x&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const E=f.commands;if(E!==void 0){const T=Bl(E.table,a);if(T!==null&&E.isAvailable(T)){a.preventDefault(),E.execute(T);return}}if(A!==void 0&&!d){const T=A==="left"||A==="right",M=A==="right"||A==="down"?1:-1;if(x&&a.shiftKey){a.preventDefault();const V=f.getSelection(),X=L();let J;if(f.findDataEdge!==void 0){const Z=T?{row:V.active.row,col:X.col}:{row:X.row,col:V.active.col},ne=f.findDataEdge(Z,A);J=T?ne.col:ne.row,v(J,T?f.colAxis.count:f.rowAxis.count,T?"col":"row"),J=B(T?f.colAxis:f.rowAxis,J,M,T?X.col:X.row)}else{const Z=T?f.colAxis:f.rowAxis;J=M===1?Y(Z):_(Z)}f.moveActive({mode:"extend",cell:T?{row:X.row,col:J}:{row:J,col:X.col}});return}if(x){a.preventDefault(),f.moveActive({mode:"reset",cell:P(f.getSelection().active,A)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:$(A)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:N(f.getSelection().active,A)});return}if(Wm(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!x&&!d){a.preventDefault();const T=!a.shiftKey;S(a.key==="Tab"?T?"right":"left":T?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const M=L();f.moveActive({mode:"extend",cell:{row:x?_(f.rowAxis):M.row,col:_(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:x?_(f.rowAxis):T.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const M=L();f.moveActive({mode:"extend",cell:{row:x?Y(f.rowAxis):M.row,col:Y(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:x?Y(f.rowAxis):T.row,col:Y(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!x&&!d){a.preventDefault();const T=a.key==="PageDown"?"down":"up";if(a.shiftKey){const V=L();f.moveActive({mode:"extend",cell:{row:m(V.row,T),col:V.col}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(M.row,T),col:M.col}});return}if(a.key==="F2"&&!x&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!x&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection(),M=yt(T.ranges);if(M>f.maxOperationCells){f.onOperationRejected?.("delete",M,"limit");return}if(f.adapter!==void 0&&En(f.adapter,T.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:M});return}const V=[],X=f.adapter!==void 0&&Br(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(x||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(Yn(Gn.selectAll,a)){a.preventDefault();const T=f.getSelection(),M=Ce({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[M],anchor:T.anchor,active:T.active});return}if(Yn(Gn.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(Yn(Gn.redo,a)||Yn(Gn.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!x&&!d||a.key==="ContextMenu"&&!x&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection().active;f.ensureCellVisible(T);const M=h.current,V=M===null?{x:0,y:0}:M.getScrollPosition(),X=Math.max(0,V.y),J=Math.max(0,V.x),Z=M===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:M.getFrozenSize(),ne=M===null?{width:0,height:0}:M.getViewportSize(),ie=f.zoomRef.current;f.onCellContextMenu?.(T,{kind:"keyboard",cellRect:{top:ln(f.rowAxis,T.row,{scroll:X,frozenCount:Z.rows,trailingCount:Z.trailingRows,extent:ne.height})*ie,left:sn(f.colAxis,T.col,{scroll:J,frozenCount:Z.cols,trailingCount:Z.trailingCols,extent:ne.width})*ie,width:f.colAxis.sizeOf(T.col)*ie,height:f.rowAxis.sizeOf(T.row)*ie}});return}if(a.key===" "&&!d&&x!==a.shiftKey){a.preventDefault();const T=f.getSelection(),M=T.ranges.map(V=>x?Ce({row:0,col:V.startCol},{row:f.rowAxis.count-1,col:V.endCol}):Ce({row:V.startRow,col:0},{row:V.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:M,anchor:T.anchor,active:T.active});return}if(f.pendingPasteOptionsRef!==void 0&&Yn(Gn.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")},O=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Hm)},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()}},F=()=>{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",F),g.addEventListener("blur",b),g.addEventListener("compositionstart",D),g.addEventListener("compositionend",O),g.addEventListener("input",R),()=>{g.removeEventListener("keydown",y),g.removeEventListener("keyup",F),g.removeEventListener("blur",b),g.removeEventListener("compositionstart",D),g.removeEventListener("compositionend",O),g.removeEventListener("input",R),n.current!==null&&window.clearTimeout(n.current),q()}},[l,c,u,h])},Ym=4,Um=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),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(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),N=i.useRef(!1),_=i.useCallback(v=>g.current!==null?v.pointerId===g.current:v.pointerType==="mouse",[]),Y=i.useCallback((v,S)=>{const{handleRef:p,rowAxis:m,colAxis:y}=t.current,D=p.current,O=s.current;if(D===null||O===null)return null;const{x:R,y:F}=D.getScrollPosition();if(F<0||R<0||m.totalSize()===0||y.totalSize()===0)return null;const b=t.current.zoomRef.current,a=D.getFrozenSize(),f=D.getViewportSize();return Vt({row:hr(m,(S-O.top)/b,{scroll:F,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:pr(y,(v-O.left)/b,{scroll:R,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},m.count,y.count)},[]),B=i.useCallback(v=>{const S=r.current;if(S===null)return Ce(v,v);const p=Ce({row:Math.min(S.startRow,v.row),col:Math.min(S.startCol,v.col)},{row:Math.max(S.endRow,v.row),col:Math.max(S.endCol,v.col)}),m=p.startRow!==S.startRow||p.endRow!==S.endRow||p.startCol!==S.startCol||p.endCol!==S.endCol;return o.current=m?p:null,m?p:S},[]),L=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(),N.current=!1,u.current=!1,h.current={dx:0,dy:0},v.writeFillPreview(null);const S=j.current;S!==null&&(window.removeEventListener("pointermove",S.move),window.removeEventListener("pointerup",S.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()},[]),$=i.useCallback(()=>{const v=t.current,S=r.current,p=o.current;if(L(),S===null||p===null)return;const m=Yp(S,p);if(m>v.maxOperationCells){v.onOperationRejected?.("fill",m,"limit");return}if(En(v.adapter,Up(S,p))){const O=(p.endRow-p.startRow+1)*(p.endCol-p.startCol+1),R=(S.endRow-S.startRow+1)*(S.endCol-S.startCol+1);v.rejectReadOnly({kind:"operation",op:"fill",cellCount:O-R});return}const y=Xp((O,R)=>qc(v.adapter,O,R),S,p,_c);if(v.commitEdits(y,{source:"fill"})===null)return;const D=v.getSelection();v.setSelection({ranges:[p],anchor:D.anchor,active:D.active})},[L]),{enabled:P,handleNodeRef:k}=e;return i.useEffect(()=>{const v=k.current;if(!P||v===null)return;const S=O=>{p(O),n.current&&_(O)&&(C.current&1)!==0&&(O.buttons&1)===0&&$()},p=O=>{if(!(n.current&&_(O)))return;l.current={clientX:O.clientX,clientY:O.clientY};const R=Math.abs(O.clientX-c.current.clientX),F=Math.abs(O.clientY-c.current.clientY);if(!u.current&&Math.max(R,F)>=Ym&&(u.current=!0),!!u.current){if(!N.current){const b=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};b.xAutoScroller.start(a),b.yAutoScroller.start(a),N.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(B(b))}))}},m=O=>{O.button!==0||!(n.current&&_(O))||$()},y=O=>{const R=t.current;if(O.pointerType!=="mouse")return;if(O.button!==0){O.preventDefault();return}O.preventDefault(),O.stopPropagation(),R.focusSink();const F=R.getSelection(),b=F.ranges[F.ranges.length-1];r.current=b,o.current=null,u.current=!1,R.xAutoScroller.stop(),R.yAutoScroller.stop(),N.current=!1,c.current={clientX:O.clientX,clientY:O.clientY},l.current=c.current,C.current=O.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},x=f.y;if(a!==null&&x>=0&&f.x>=0){const E=f.x,T=R.zoomRef.current,M=R.handleRef.current?.getFrozenSize()??Um,V=R.handleRef.current?.getViewportSize()??{width:0,height:0},X={scroll:E,frozenCount:M.cols,trailingCount:M.trailingCols,extent:V.width},J={scroll:x,frozenCount:M.rows,trailingCount:M.trailingRows,extent:V.height},Z=sn(R.colAxis,b.endCol,X)+R.colAxis.sizeOf(b.endCol),ne=ln(R.rowAxis,b.endRow,J)+R.rowAxis.sizeOf(b.endRow),ie=Z-1,se=b.endCol>=M.cols&&M.width>0?Math.max(ie,M.width):ie,ce=!(b.endCol>=R.colAxis.count-M.trailingCols)&&M.trailingWidth>0?Math.min(se,V.width-M.trailingVisibleWidth-1):se,Re=ne-1,De=b.endRow>=M.rows&&M.height>0?Math.max(Re,M.height):Re,_e=!(b.endRow>=R.rowAxis.count-M.trailingRows)&&M.trailingHeight>0?Math.min(De,V.height-M.trailingVisibleHeight-1):De;h.current={dx:O.clientX-(a.left+ce*T),dy:O.clientY-(a.top+_e*T)}}else h.current={dx:0,dy:0};g.current=O.pointerId;try{v.setPointerCapture(O.pointerId)}catch{g.current=null}const d=S,A=m;j.current={move:d,up:A},window.addEventListener("pointermove",d),window.addEventListener("pointerup",A),R.writeFillPreview(r.current)},D=O=>{!n.current||g.current===null||O.pointerId!==g.current||L()};return v.addEventListener("pointerdown",y),v.addEventListener("lostpointercapture",D),()=>{v.removeEventListener("pointerdown",y),v.removeEventListener("lostpointercapture",D),L()}},[P,k,_,Y,B,L,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L])},Gm=320,Vr=8,Jm=64,Zm=150,Ma=e=>Math.max(0,Math.min(Gm,e.width-dt-Vr)),Qm=(e,t,n)=>{const r=n.width-dt,o=n.height-dt,s=Ma(n),l=Math.max(0,Math.min(t,o-Vr)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+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 _ of C)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const q=o-u,j=e.top,N=Math.min(l,Math.max(q,j));if(N>=Jm){const _=q>=j?u:e.top-N;for(const Y of g)if(h(Y))return{left:Y,top:_,width:s,height:N}}return{left:Vr,top:Vr,width:s,height:l}},ew=(e,t,n,r)=>t===null||e!==null&&Ot(e,t)||n?!1:r(t),tw=(e,t)=>{switch(e.kind){case"note":return K.jsx(pa,{ctx:e,labels:t});case"note-tip":return K.jsx(ha,{ctx:e,labels:t});case"comment":return K.jsx(aa,{ctx:e,labels:t});case"link":return K.jsx(ua,{ctx:e,labels:t});case"list":return K.jsx(da,{ctx:e,labels:t});default:return K.jsx(fa,{ctx:e,labels:t})}},Io=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,nw=({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=Io(s),q=Io(l),j=i.useRef(null),N=($,P)=>{const k=g.current.getLayerSize();$.style.width=`${Ma(k)}px`,$.style.maxHeight="";const v=Qm(P,$.offsetHeight,k);$.style.left=`${v.left-P.left}px`,$.style.top=`${v.top-P.top}px`,$.style.maxHeight=`${v.height}px`};i.useLayoutEffect(()=>{const $=c.current;if($===null||s===null){j.current=null;return}if(N($,s.anchorRect),s.kind==="message")return;const P=Io(s);if(j.current===P)return;j.current=P;const k=$.querySelector("[data-aqsp-popover-autofocus]");k!==null?k.focus({preventScroll:!0}):$.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const $=u.current,P=h.current;$===null||P===null||N($,P.anchorRect)},[q]);const _=$=>t===void 0?tw($,n):t($),Y=$=>{e.isCompositionKey($.nativeEvent)&&$.stopPropagation()},B=$=>{$.key==="Escape"&&!$.defaultPrevented&&($.preventDefault(),e.close())},L=$=>{e.registerCompositionEnd($.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:Y,onKeyDown:B,onCompositionEnd:L,children:[K.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},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:_(l)})})]})},rw=["note","note-tip","comment","link","list","message"],ow=(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}},Jn=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&ow(e,n),sw=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),g=i.useRef(null),C=i.useRef(null),q=i.useRef(null),j=i.useRef(null),N=i.useId(),_=i.useCallback(E=>{const T=t.current,M=T.handleRef.current,V=M===null?{x:0,y:0}:M.getScrollPosition(),X=M===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:M.getFrozenSize(),J=M===null?{width:0,height:0}:M.getViewportSize();return{top:ln(T.rowAxis,E.row,{scroll:Math.max(0,V.y),frozenCount:X.rows,trailingCount:X.trailingRows,extent:J.height}),left:sn(T.colAxis,E.col,{scroll:Math.max(0,V.x),frozenCount:X.cols,trailingCount:X.trailingCols,extent:J.width}),width:T.colAxis.sizeOf(E.col),height:T.rowAxis.sizeOf(E.row)}},[]),Y=i.useCallback(E=>{const T=t.current;T.anchors.current={...T.anchors.current,...E},T.repaintOverlay()},[]),B=i.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),L=i.useCallback(()=>{const E=t.current.sinkRef.current;if(E===null)return;const T=c.current;T!==null&&Ot(T,t.current.getActive())?E.setAttribute("aria-describedby",N):E.getAttribute("aria-describedby")===N&&E.removeAttribute("aria-describedby")},[N]),$=i.useCallback(()=>(B(),h.current=!1,c.current===null?!1:(c.current=null,s(null),Y({tip:null}),L(),!0)),[B,Y,L]),P=i.useCallback(()=>{B(),g.current=window.setTimeout(()=>{g.current=null,$()},Zm)},[B,$]),k=i.useCallback(E=>{const T=t.current;B();const M=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(E.row,E.col);M===void 0||M===""||(c.current=E,s({kind:"note-tip",cell:E,anchorRect:_(E),current:M,close:$}),Y({tip:E}),L())},[_,B,$,Y,L]),v=i.useCallback(E=>{const T=t.current;if(E===null&&h.current)return;const M=u.current;u.current=E;const V=c.current;if(V!==null&&E!==null&&Ot(V,E)){B();return}const X=J=>{const Z=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(J.row,J.col);return Z!==void 0&&Z!==""};if(ew(M,E,T.isDraggingAny(),X)){E!==null&&k(E);return}V!==null&&P()},[k,B,P]),S=i.useCallback((E,T)=>{const M=t.current,V=M.bodyRef.current,X=M.handleRef.current;if(V===null||X===null)return null;const J=V.getBoundingClientRect(),Z=M.zoomRef.current,ne=X.getScrollPosition(),ie=X.getFrozenSize(),se=X.getViewportSize();return Vt({row:hr(M.rowAxis,(T-J.top)/Z,{scroll:Math.max(0,ne.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:se.height}),col:pr(M.colAxis,(E-J.left)/Z,{scroll:Math.max(0,ne.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:se.width})},M.rowAxis.count,M.colAxis.count)},[]),p=i.useCallback(E=>{q.current=E,C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null;const T=q.current;v(T===null?null:"cell"in T?T.cell:S(T.clientX,T.clientY))}))},[v,S]),m=i.useCallback(E=>p({cell:E}),[p]),y=i.useCallback(()=>$(),[$]),D=i.useCallback(E=>{if(l.current===null)return;const T=t.current;l.current=null,r(null),Y({interactive:null}),(E===void 0||E.restoreFocus)&&T.focusSink({preventScroll:!0}),T.isEditing()||T.rearmSink()},[Y]),O=i.useCallback(E=>{l.current=E.kind,r(E),Y({interactive:E.cell})},[Y]),R=i.useCallback(E=>{const T=t.current;return Fc(T.adapter)?{cellReadOnly:We(T.adapter,E.row,E.col)}:{}},[]),F=i.useCallback((E,T)=>{const M=t.current;if(We(M.adapter,E.cell.row,E.cell.col)){M.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),O({...E,...R(E.cell)});return}if(M.commitEdits(T,{source:"annotate"})===null){O({...E,rejected:!0});return}D()},[O,D,R]),b=i.useCallback((E,T)=>{const M=t.current;if(!Jn(M.adapter,M.popovers,E))throw new RangeError(`[spreadsheet] openPopover("${E}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const V=M.getActive();if(E==="list"&&We(M.adapter,V.row,V.col)){M.rejectReadOnly({kind:"edit",cell:V,editSession:"none"});return}if(E==="note-tip"){k(V);return}if(E==="message"){if(l.current!==null&&l.current!=="message")return;const ne=T!==void 0&&T.message!==void 0?T.message:void 0,ie=M.adapter.getCellValidation===void 0?void 0:M.adapter.getCellValidation(V.row,V.col),se=ne!==void 0?ne:ie===void 0?void 0:ie.inputMessage;if(se===void 0)return;const ze=T!==void 0&&T.rejected===!0;O({kind:"message",cell:V,anchorRect:_(V),current:{title:Me(M.labels,"messageTitle"),message:se,rejected:ze},close:D});return}if(M.isEditing()&&!M.requestCommit())return;if(E==="list"){const ne=M.adapter.getCellValidation===void 0?void 0:M.adapter.getCellValidation(V.row,V.col);if(ne===void 0||ne.type!=="list")return;const ie=T!==void 0&&T.typed!==void 0?T.typed:"";$(),M.focusSink({preventScroll:!0}),O({kind:"list",cell:V,anchorRect:_(V),current:ne.values,typed:ie,commit:se=>{if(We(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:se}],{source:"edit",editSession:"discarded"}),D()},close:D});return}if($(),M.focusSink({preventScroll:!0}),E==="note"){const ne=M.adapter.getCellNote===void 0?void 0:M.adapter.getCellNote(V.row,V.col),ie={kind:"note",cell:V,anchorRect:_(V),current:ne,commit:se=>{F(ie,[{row:V.row,col:V.col,note:se}])},close:D,rejected:!1,...R(V)};O(ie);return}if(E==="comment"){const ne=M.adapter.getCellComments===void 0?void 0:M.adapter.getCellComments(V.row,V.col),ie={kind:"comment",cell:V,anchorRect:_(V),current:ne===void 0?[]:ne,commit:se=>{F(ie,[{row:V.row,col:V.col,comments:se}])},close:D,rejected:!1,...R(V)};O(ie);return}const X=M.adapter.getCellHyperlink===void 0?void 0:Fn(M.adapter.getCellHyperlink(V.row,V.col)),J=M.adapter.getCellText(V.row,V.col),Z={kind:"link",cell:V,anchorRect:_(V),current:{text:J,url:X},commit:ne=>{const ie=ne.url===null?null:Bt(ne.url);if(ie===null&&ne.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ne.url)}`);const se=ne.text===J?{row:V.row,col:V.col,hyperlink:ie}:{row:V.row,col:V.col,text:ne.text,hyperlink:ie};F(Z,[se])},close:D,canOpen:M.onHyperlinkOpen!==void 0,open:()=>{const ne=t.current.onHyperlinkOpen;ne!==void 0&&X!==void 0&&ne(X,V)},rejected:!1,...R(V)};O(Z)},[_,D,F,$,O,k,R]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const E=f.current;if(!a||E===null)return;const T=V=>{const X=t.current;Jn(X.adapter,X.popovers,"note-tip")&&p({clientX:V.clientX,clientY:V.clientY})},M=()=>{Jn(t.current.adapter,t.current.popovers,"note-tip")&&p({cell:null})};return E.addEventListener("pointermove",T),E.addEventListener("pointerleave",M),()=>{E.removeEventListener("pointermove",T),E.removeEventListener("pointerleave",M)}},[a,f,p]),i.useEffect(()=>()=>{C.current!==null&&cancelAnimationFrame(C.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:x,popovers:d}=e,A=i.useMemo(()=>rw.some(E=>Jn(x,d,E)),[x,d]);return i.useMemo(()=>({layerEnabled:A,isKindEnabled:E=>Jn(t.current.adapter,t.current.popovers,E),open:b,close:D,isOpen:()=>l.current,onCellHover:m,hideTip:y,onTipPointerEnter:()=>{h.current=!0,B()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&P()},syncTipAriaDescribedBy:L,context:n,tipContext:o,registerCompositionEnd:E=>{j.current=E},isCompositionKey:E=>La(E,j.current),getLayerSize:()=>{const E=t.current.handleRef.current;return E===null?{width:0,height:0}:E.getViewportSize()},tipId:N}),[A,b,D,m,y,B,P,L,n,o,N])},lw=(e,t,n)=>{let r=null,o=0;if(typeof document.caretPositionFromPoint=="function"){const l=document.caretPositionFromPoint(e,t);if(l===null)return;r=l.offsetNode,o=l.offset}else if(typeof document.caretRangeFromPoint=="function"){const l=document.caretRangeFromPoint(e,t);if(l===null)return;r=l.startContainer,o=l.startOffset}else return;if(r===null||r.nodeType!==Node.TEXT_NODE)return;const s=r.parentElement?.closest("[data-aqsp-cell]")??null;if(!(s===null||Number(s.getAttribute("data-row"))!==n.row||Number(s.getAttribute("data-col"))!==n.col))return o},za=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),g=e.getViewportSize();return Vt({row:hr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:g.height}),col:pr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:g.width})},n.count,r.count)},iw=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),N=i.useRef(!1),_=i.useCallback((p,m)=>{const{handleRef:y,rowAxis:D,colAxis:O,zoomRef:R}=t.current;return za(y.current,o.current,D,O,R.current,p,m)},[]),Y=i.useRef(!1),B=i.useRef(null),L=i.useRef(null),$=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,B.current=null,L.current=null,g.current=!1,C.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.stop();const D=m.current;D!==null&&c.current!==null&&D.hasPointerCapture?.(c.current)&&D.releasePointerCapture(c.current),c.current=null,y(null),t.current.repaintOverlay()},[]),k=i.useCallback(()=>{if(!n.current)return;const p=r.current;p!==null&&t.current.setSelection(p),P()},[P]),{enabled:v,bodyRef:S}=e;return i.useEffect(()=>{const p=S.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,N.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 T=_(d.clientX,d.clientY);if(T===null)return;if(d.preventDefault(),A.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&A.openHyperlinkAt?.(T)===!0){N.current=!0;return}const M=A.getSelection();r.current=M;const V=d.shiftKey,X=d.ctrlKey||d.metaKey,J=X&&!V&&M.ranges.some(ne=>cn(ne,T));g.current=J,C.current=J?T:null,J||A.setSelection(cr(M,T,{extend:V,append:X})),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 Z=J?T:A.getSelection().anchor;h.current=ne=>Ce(Z,ne),B.current=Z.col,L.current=Z.row,A.autoScroller.stop(),Y.current=!1,$.current={clientX:d.clientX,clientY:d.clientY}},D=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",O=d=>{if(n.current&&D(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!Y.current&&h.current!==null){const A=Math.abs(d.clientX-$.current.clientX),E=Math.abs(d.clientY-$.current.clientY);Math.max(A,E)>=Gr&&(Y.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:B.current??void 0,anchorRow:L.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const A=h.current;if(!n.current||A===null)return;const E=t.current,T=_(s.current.clientX,s.current.clientY);T!==null&&E.onDragFrame(A(T))}))}},R=d=>{O(d),n.current&&D(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&b(d)},F=d=>{d.button!==0||!(n.current&&D(d))||b(d)},b=d=>{const A=t.current,E=_(d.clientX,d.clientY);if(E!==null){const T=C.current;g.current&&T!==null?A.setSelection($a(A.getSelection(),Ce(T,E),T)):A.setSelection(rn(A.getSelection(),E))}P()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||k()},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 E=_(d.clientX,d.clientY);if(E===null)return;const T=A.getSelection();T.ranges.some(V=>cn(V,E))||A.setSelection(cr(T,E,{extend:!1,append:!1})),A.onContextMenuSelect(E,d)},x=d=>{const A=t.current;if(!j.current||q.current!=="mouse"||A.getPointing?.()||N.current)return;o.current=p.getBoundingClientRect();const E=_(d.clientX,d.clientY);E!==null&&Ot(A.getSelection().active,E)&&A.onRequestEdit(E,A.caretFromPointEnabled(E)?lw(d.clientX,d.clientY,E):void 0)};return p.addEventListener("pointerdown",y),p.addEventListener("pointermove",R),p.addEventListener("pointerup",F),p.addEventListener("lostpointercapture",a),p.addEventListener("contextmenu",f),p.addEventListener("dblclick",x),()=>{p.removeEventListener("pointerdown",y),p.removeEventListener("pointermove",R),p.removeEventListener("pointerup",F),p.removeEventListener("lostpointercapture",a),p.removeEventListener("contextmenu",f),p.removeEventListener("dblclick",x),P()}},[v,S,_,P,k]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:k,cancelDrag:P}),[k,P])},cw=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(($,P)=>{const{handleRef:k,rowAxis:v,colAxis:S,zoomRef:p}=t.current;return za(k.current,o.current,v,S,p.current,$,P)},[]),N=i.useCallback(()=>{const{autoScroller:$,bodyRef:P,onDragFrame:k}=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),$.stop();const v=P.current;v!==null&&u.current!==null&&v.hasPointerCapture?.(u.current)&&v.releasePointerCapture(u.current),u.current=null,k(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.restoreSink($),N()},[N]),Y=i.useCallback($=>{const P=t.current,k=P.bodyRef.current;if(!P.enabled||k===null||!P.getPointing())return!1;o.current=k.getBoundingClientRect();const v=j($.clientX,$.clientY);if(v===null)return o.current=null,!1;const S=P.captureSink();if(S===null)return o.current=null,!1;$.preventDefault(),P.focusSink(),r.current=S,C.current=v,P.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{k.setPointerCapture($.pointerId)}catch{u.current=null}return g.current=p=>{const m=Ce(v,p);return t.current.insertReference(m,"cells"),m},P.autoScroller.stop(),q.current=!1,P.onDragFrame(Ce(v,v)),!0},[j]),{enabled:B,bodyRef:L}=e;return i.useEffect(()=>{const $=L.current;if(!B||$===null)return;const P=p=>u.current!==null?p.pointerId===u.current:p.pointerType==="mouse",k=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 D=Math.abs(p.clientX-l.current.clientX),O=Math.abs(p.clientY-l.current.clientY);Math.max(D,O)>=Gr&&(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 D=g.current;if(!n.current||D===null)return;const O=j(s.current.clientX,s.current.clientY);O!==null&&t.current.onDragFrame(D(O))})),(h.current&1)!==0&&(p.buttons&1)===0&&N()},v=p=>{p.button!==0||!(n.current&&P(p))||N()},S=p=>{!n.current||u.current===null||p.pointerId!==u.current||N()};return $.addEventListener("pointermove",k),$.addEventListener("pointerup",v),$.addEventListener("lostpointercapture",S),()=>{$.removeEventListener("pointermove",k),$.removeEventListener("pointerup",v),$.removeEventListener("lostpointercapture",S),N()}},[B,L,j,N]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:N,onPointerDown:Y}),[_,N,Y])},aw=.25,uw=4,Ho=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(uw,Math.max(aw,e))},Bo=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,Ti=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${typeof t=="string"?JSON.stringify(t):String(t)})`);return t},dw=24,fw=100,pw=1e5,hw=200,Fa=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),$i=5,gw=/^#[0-9A-Fa-f]{6}$/,mw=Object.freeze({row:!1,column:!1,intersection:!1}),Di=Object.freeze({ok:!0}),Li=(e,t)=>{if(t===void 0)return Fa;if(t.length!==$i)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${$i} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!gw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},ww=e=>{for(const t of["row","column","intersection"])if(Ue(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},Cw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ia},yw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},bw=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Xe.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},vn={ranges:[Ce({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},vw=i.forwardRef(function({adapter:t,defaultRowHeight:n=dw,defaultColumnWidth:r=fw,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:N,onCellContextMenu:_,onUndoRequest:Y,onRedoRequest:B,onCopyMultiRange:L,onOperationRejected:$,onEditRejected:P,onReadOnlyRejected:k,formatReadOnlyAnnouncement:v,dataVersion:S,maxOperationCells:p=pw,enableFillHandle:m=!0,enableResizeUI:y=!0,formatCellAnnouncement:D,formatSelectionAnnouncement:O,formatCommandAnnouncement:R,locale:F,labels:b,shortcuts:a,colors:f,formats:x,highlight:d,defaultHighlight:A,onHighlightChange:E,highlightColors:T,popovers:M,renderPopover:V,onClipChange:X,onHyperlinkOpen:J,onValidationRejected:Z,onPasteSpecialRequest:ne,onClipboardUnavailable:ie,onPasteResolved:se,now:ze=Date.now,zoom:ce,defaultZoom:Re,onZoomChange:De,testId:Ne,className:_e,__onCellRender:qe,__onVirtualKeyboardRaise:bt,__maxRenderedCells:gr},ro){const pe=yi(t.rowCount,n),ae=yi(t.colCount,r),an=i.useRef(null);an.current===null&&(an.current=Xh());const ke=an.current,Tt=Xe.resolveVirtualScrollLocale(F),pt=i.useMemo(()=>Xc(F,b),[F,b]),mr=bw(mh(pt)),Wt=i.useMemo(()=>fh(a),[a]),$t=i.useMemo(()=>({fill:Li("fill",f===void 0?void 0:f.fill),font:Li("font",f===void 0?void 0:f.font)}),[f]),un=i.useMemo(()=>T===void 0?void 0:ww(T),[T]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Kt=i.useCallback(()=>ke.get().editVersion,[ke]),dn=i.useCallback(w=>ke.subscribeCoalesced(w),[ke]),Cr=i.useSyncExternalStore(dn,Kt,Kt)+(S===void 0?0:S),Yt=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),fn=i.useMemo(()=>({index:Yt===null?null:Aa(Yt),memo:Es()}),[t,Yt,Cr]),Nn=i.useRef(fn.index);Nn.current=fn.index;const Pn=i.useRef(fn.memo);Pn.current=fn.memo;const Dt=i.useCallback((w,W,Q)=>As(t,Nn.current,Pn.current,w,W,Q),[t]),Ge=i.useRef(null),[pn,oo]=i.useState(()=>Ho(Re??1)),nt=Ho(ce??pn),z=i.useRef(nt);z.current=nt;const H=i.useRef(nt);H.current=nt;const U=i.useRef(null),I=i.useRef(De);I.current=De;const G=i.useRef(ce!==void 0);G.current=ce!==void 0;const oe=i.useCallback(w=>{const W=Ho(w);W!==H.current&&(H.current=W,G.current||oo(W),I.current?.(W))},[]),ee=t.rowCount===0||t.colCount===0,Ae=!ee;i.useEffect(()=>{const w=Ge.current;if(!Ae||w===null)return;const W=te=>{te.defaultPrevented||!te.altKey||te.ctrlKey||te.metaKey||te.shiftKey||te.deltaY!==0&&(te.preventDefault(),te.stopPropagation(),!U.current?.()&&oe(Bo(H.current,te.deltaY<0?1:-1)))},Q=te=>{if(te.defaultPrevented||!(te.ctrlKey&&te.altKey)||te.metaKey||te.getModifierState("AltGraph"))return;const Se=te.key==="="||te.key==="+"?Bo(H.current,1):te.key==="-"?Bo(H.current,-1):te.key==="0"?1:null;Se!==null&&(te.preventDefault(),te.stopPropagation(),!U.current?.()&&oe(Se))};return w.addEventListener("wheel",W,{passive:!1,capture:!0}),w.addEventListener("keydown",Q,!0),()=>{w.removeEventListener("wheel",W,{capture:!0}),w.removeEventListener("keydown",Q,!0)}},[oe,Ae]);const de=i.useRef(null),fe=i.useRef(null),Le=i.useRef(null),Ie=i.useRef(null),Pe=i.useRef(0),re=i.useRef(null),he=i.useRef(0),ge=i.useRef(null),me=i.useRef(null),ue=i.useRef(null),ye=i.useRef(null),ve=i.useRef(null),Te=i.useRef(null),ht=i.useRef(null),[He,rt]=i.useState(vn),je=i.useRef(He),Be=i.useCallback(()=>je.current,[]),[qn,Ut]=i.useState(()=>A===void 0?mw:A),Lt=d!==void 0?d:qn,_n=i.useRef(Lt);_n.current=Lt;const Na=Cw(un,Lt),xs=i.useRef(d!==void 0);xs.current=d!==void 0;const Ts=i.useRef(E);Ts.current=E;const Pa=i.useCallback(w=>{xs.current||Ut(w),Ts.current?.(w)},[]),$s=i.useRef(null),so=i.useRef(null),vt=i.useRef(null),lo=i.useRef(()=>!1),Ds=i.useRef(()=>{}),Ls=i.useRef(()=>null),Ms=i.useRef(()=>{}),Xt=i.useCallback(()=>lo.current(),[]),io=i.useMemo(()=>({getPointing:()=>lo.current(),insertReference:(w,W)=>Ds.current(w,W)}),[]),zs=i.useRef(Et),Fs=i.useRef(null),co=i.useRef({interactive:null,tip:null}),Ns=i.useRef(null),Ps=i.useRef(null),yr=i.useRef(()=>{}),qs=i.useRef(()=>!1),Mt=i.useRef(null),jn=i.useCallback(()=>{const w=Mt.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)},[]),ao=i.useRef(()=>!1),_s=i.useRef(()=>!1),js=i.useRef(null),uo=i.useRef(()=>Promise.resolve("rejected")),xe=i.useCallback(()=>{$s.current?.()},[]),$e=i.useCallback(w=>{Le.current?.focus(w)},[]),fo=i.useRef(!1),qa=i.useCallback(()=>{const w=Ge.current;if(w!==null){fo.current=!0;try{w.focus()}finally{fo.current=!1}}},[]),Je=i.useCallback(()=>{const w=Le.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),hn=i.useCallback((w,W)=>{if(w===null)return;const Q=W?"":"none";w.style.display!==Q&&(w.style.display=Q)},[]),ot=i.useCallback(()=>{const w=Ie.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().y??0),te=fe.current?.getFrozenSize().height??0;w.style.transform=`translateY(${Pe.current-Q-te}px)`}const W=fe.current;if(W!==null&&(ve.current!==null||Te.current!==null)){const Q=W.getFrozenSize();hn(ve.current,Q.height>0),hn(Te.current,Q.trailingHeight>0)}},[hn]),st=i.useCallback(()=>{const w=re.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().x??0),te=fe.current?.getFrozenSize().width??0;w.style.transform=`translateX(${he.current-Q-te}px)`}const W=fe.current;if(W!==null&&(ue.current!==null||ye.current!==null)){const Q=W.getFrozenSize();hn(ue.current,Q.width>0),hn(ye.current,Q.trailingWidth>0)}},[hn]),In=i.useRef(null),gn=i.useCallback(()=>{ue.current===null&&ye.current===null&&ve.current===null&&Te.current===null||In.current===null&&(In.current=requestAnimationFrame(()=>{In.current=null,ot(),st(),xe()}))},[ot,st,xe]);i.useEffect(()=>()=>{In.current!==null&&cancelAnimationFrame(In.current)},[]);const po=i.useRef(null),ho=i.useRef(null);(po.current===null||ho.current?.rowAxis!==pe||ho.current?.colAxis!==ae)&&(ho.current={rowAxis:pe,colAxis:ae},po.current=jm({handleRef:fe,rowAxis:pe,colAxis:ae}));const zt=i.useCallback(w=>{po.current?.(w)},[]),mn=i.useRef(null),Gt=i.useRef(null),wn=i.useCallback(w=>{mn.current!==null&&window.clearTimeout(mn.current),Gt.current!==null&&(cancelAnimationFrame(Gt.current),Gt.current=null),mn.current=window.setTimeout(()=>{mn.current=null;const W=ht.current;W!==null&&(W.textContent="",Gt.current=requestAnimationFrame(()=>{Gt.current=null,W.textContent=w}))},hw)},[]);i.useEffect(()=>()=>{mn.current!==null&&window.clearTimeout(mn.current),Gt.current!==null&&cancelAnimationFrame(Gt.current)},[]);const Cn=i.useCallback(w=>{k?.(w),v!==void 0&&wn(v(w))},[k,v,wn]),Is=i.useCallback((w,W)=>{if(D===void 0&&O===void 0)return;const Q=W.ranges[W.ranges.length-1],te=tt(Q),Se=W.ranges.length===1&&te.rows===1&&te.cols===1,Ee=w.ranges[w.ranges.length-1],Nt=w.ranges.length!==W.ranges.length||Ee.startRow!==Q.startRow||Ee.startCol!==Q.startCol||Ee.endRow!==Q.endRow||Ee.endCol!==Q.endCol,Qt=()=>{if(D!==void 0){const Rt=W.active,ko=t.getCellText(Rt.row,Rt.col),hl=t.getCellFormat===void 0?void 0:Dt(Rt.row,Rt.col,()=>ko);wn(D({row:Rt.row,col:Rt.col,text:ko,displayText:Ln(ko,hl===void 0?void 0:hl.value),columnName:or(Rt.col),...Fc(t)?{readOnly:We(t,Rt.row,Rt.col)}:{}}))}};if(Se){Qt();return}if(Nt){O!==void 0&&wn(O({range:Q,anchor:W.anchor,active:W.active,rangeRowCount:te.rows,rangeColCount:te.cols,rangeCount:W.ranges.length}));return}Qt()},[t,D,O,wn,Dt]),Ve=i.useCallback(w=>{const W=je.current;Object.is(w,W)||Fm(w,W)||(je.current=w,rt(w),N?.(w),Is(W,w),(vt.current?.()??!1)||Je())},[N,Is,Je]),_a=i.useCallback(w=>{const W=je.current;if(w.mode==="cycle"){const te=Da(W,w.direction);Ve(te),zt(te.active);return}const Q=Vt(w.cell,pe.count,ae.count);if(w.mode==="extend"){Ve(rn(W,Q)),zt(Q);return}Ve(cr(W,Q,{extend:!1,append:!1})),zt(Q)},[Ve,zt,pe,ae]),Ke=i.useCallback(()=>vt.current?.()??!1,[]),Hs=i.useRef(null),lt=i.useCallback(()=>Hs.current?.()??!0,[]),Bs=i.useRef(null),Hn=i.useCallback((w,W)=>{const Q=vt.current?.()??!1;Bs.current?.(w,W),!Q&&(vt.current?.()??!1)&&jn()},[jn]),[ja,go]=i.useState(!1),Vs=i.useCallback(()=>{bt?.(),go(!0)},[bt]),Ia=i.useCallback((w,W)=>{We(t,w.row,w.col)||Vs(),Hn("edit",W)},[t,Vs,Hn]),Ws=i.useRef(null),br=i.useCallback(()=>Ws.current?.()??null,[]),Ks=i.useRef(null),gt=i.useCallback(()=>{Ks.current?.()},[]),Ys=i.useRef(null),Us=i.useCallback(w=>{Ys.current?.(w)},[]),Xs=i.useRef(()=>{}),vr=i.useRef(0),Jt=i.useCallback((w,W,Q)=>{let te;if(W.source==="paste"){const Se=yw(Q);if(w.length===0&&Se.conditionalFormats.length===0)return null;vr.current+=1,te={transaction:vr.current,source:"paste",sameSheet:Se.sameSheet,conditionalFormats:Se.conditionalFormats}}else{if(w.length===0)return null;vr.current+=1,te={transaction:vr.current,source:W.source}}try{t.applyEdits(w,te)}catch(Se){return P?.(Se,W),null}return ke.bumpEdit(),Us(W.source),te.transaction},[t,ke,P,Us]),Ha=i.useCallback((w,W)=>Jt(w,{source:"paste"},W),[Jt]),Ba=i.useCallback(w=>{ke.setVy(w.y),ot(),st(),xe()},[ke,ot,st,xe]),Gs=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Va=i.useCallback(w=>{ke.setRowRange(w.renderingRowStart,w.renderingRowEnd),ke.setColRange(w.renderingColStart,w.renderingColEnd);const W=Gs.current;(W.rowStart!==w.renderingRowStart||W.rowEnd!==w.renderingRowEnd||W.colStart!==w.renderingColStart||W.colEnd!==w.renderingColEnd)&&(Gs.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},xe())},[ke,xe]),Js=i.useRef(()=>"add"),Ft=i.useCallback(w=>{so.current?.(w,Js.current())},[]),Wa=i.useCallback(w=>{so.current?.(w,"point")},[]),Zs=i.useRef(null),mo=i.useCallback(w=>{Zs.current?.(w)},[]),Qs=i.useRef(null),Ka=i.useCallback(w=>{Qs.current?.(w)},[]),el=i.useRef(null),wo=i.useCallback((w,W)=>{if(W.length===0)return;const Q=fe.current;if(w==="col"){for(const te of W){const Se=Math.round(te.size);ae.resize(te.index,Se),Q?.updateColSize(te.index,Se)}ke.bumpColVersion(),st(),xe(),gn();return}for(const te of W){const Se=Math.round(te.size);pe.resize(te.index,Se),Q?.updateRowSize(te.index,Se)}ke.bumpRowGeometry(),ot(),xe(),gn()},[pe,ae,ke,st,ot,xe,gn]),Ya=i.useCallback((w,W)=>{_?.(w,{kind:"pointer",event:W})},[_]),Ua=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"both",zoomRef:z}),Xa=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"x",zoomRef:z}),Ga=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"y",zoomRef:z}),Ja=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:mo,axis:"x",zoomRef:z}),Za=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:mo,axis:"y",zoomRef:z}),Qa=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"both",zoomRef:z}),tl=i.useRef(null),nl=i.useRef(()=>!1),Co=i.useCallback(()=>nl.current(),[]),it=iw({zoomRef:z,enabled:!ee,rowAxis:pe,colAxis:ae,handleRef:fe,bodyRef:de,isEditing:Ke,requestCommit:lt,getSelection:Be,setSelection:Ve,focusSink:$e,onDragFrame:Ft,onContextMenuSelect:Ya,onRequestEdit:Ia,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 Ln(W,t.getCellFormat(w.row,w.col)?.value)===W},isAnyDragging:Co,autoScroller:Ua,repaintOverlay:xe,pointDragRef:tl,getPointing:Xt,openHyperlinkAt:J===void 0||t.getCellHyperlink===void 0?void 0:w=>{const W=t.getCellHyperlink===void 0?void 0:Fn(t.getCellHyperlink(w.row,w.col));return W===void 0?!1:(J(W,w),!0)}}),mt=xi({zoomRef:z,enabled:!ee,axis:"col",headerRef:ge,mainAxis:ae,crossCount:t.rowCount,handleRef:fe,isEditing:Ke,requestCommit:lt,getSelection:Be,setSelection:Ve,focusSink:$e,onDragFrame:Ft,autoScroller:Xa,repaintOverlay:xe,pointing:io}),wt=xi({zoomRef:z,enabled:!ee,axis:"row",headerRef:me,mainAxis:pe,crossCount:t.colCount,handleRef:fe,isEditing:Ke,requestCommit:lt,getSelection:Be,setSelection:Ve,focusSink:$e,onDragFrame:Ft,autoScroller:Ga,repaintOverlay:xe,pointing:io}),Ct=zm({zoomRef:z,enabled:!ee&&y,colBandRef:ge,rowBandRef:me,colAxis:ae,rowAxis:pe,viewStore:ke,handleRef:fe,isEditing:Ke,requestCommit:lt,focusSink:$e,getSelection:Be,adapter:t,autofitEnabled:j===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:p,onOperationRejected:$,resizeTracks:wo,writeResizeGuide:Ka,repaintOverlay:xe,isPointing:Xt}),ct=Xm({zoomRef:z,enabled:!ee&&m,handleNodeRef:el,bodyRef:de,rowAxis:pe,colAxis:ae,handleRef:fe,getSelection:Be,setSelection:Ve,focusSink:$e,adapter:t,commitEdits:Jt,maxOperationCells:p,onOperationRejected:$,rejectReadOnly:Cn,writeFillPreview:mo,repaintOverlay:xe,xAutoScroller:Ja,yAutoScroller:Za}),Ze=cw({zoomRef:z,enabled:!ee,bodyRef:de,handleRef:fe,rowAxis:pe,colAxis:ae,getPointing:Xt,insertReference:io.insertReference,captureSink:()=>Ls.current(),restoreSink:w=>Ms.current(w),focusSink:$e,autoScroller:Qa,onDragFrame:Ft});tl.current=Ze;const Bn=i.useCallback(()=>it.isDragging()||mt.isDragging()||wt.isDragging()||Ct.isDragging()||ct.isDragging()||Ze.isDragging(),[it,mt,wt,Ct,ct,Ze]);U.current=Bn,nl.current=Bn,Js.current=()=>Ze.isDragging()?"point":it.getDragMode();const eu=i.useCallback(()=>{it.abortDrag(),mt.abortDrag(),wt.abortDrag(),Ct.abortDrag(),ct.abortDrag(),Ze.abortDrag()},[it,mt,wt,Ct,ct,Ze]),yo=i.useCallback(()=>je.current.active,[]),rl=i.useCallback((w,W)=>{const Q=t.getCellValidation===void 0?void 0:t.getCellValidation(w.row,w.col);if(Q===void 0)return Di;const te=t.evaluateFormula,Se=Zc(Q,W,Tt,te===void 0?void 0:Ee=>te(Ee,w));return Se.ok||Q.strict!==!0?Di:(Z?.({cell:w,rule:Q,text:W,message:Se.message}),Mt.current?.isKindEnabled("message")&&yr.current("message",{message:Se.message,rejected:!0}),Se)},[t,Z,Tt]),Fe=Gg({enabled:!ee,sinkRef:Le,rootRef:Ge,adapter:t,commitEdits:Jt,getActive:yo,ensureCellVisible:zt,focusSink:$e,rearmSink:Je,discardClip:gt,isDragging:Co,rejectReadOnly:Cn,resolveEditAlign:w=>{if(t.getCellFormat===void 0)return null;const W=Hr(t,w.row,w.col);return zc(Dt(w.row,w.col,W),W)},resolveEditPaint:w=>t.getCellFormat===void 0?null:jd(Dt(w.row,w.col,Hr(t,w.row,w.col))),editPaintRef:zs,repaintOverlay:xe,validateCommit:rl});vt.current=Fe.isEditing,Hs.current=Fe.requestCommit,Bs.current=Fe.startEdit,lo.current=Fe.getPointing,Ds.current=Fe.insertReference,Ls.current=Fe.captureSink,Ms.current=Fe.restoreSink;const ol=i.useCallback(()=>{Fe.cancelEdit(),jn()},[Fe.cancelEdit,jn]),Vn=Dg({enabled:!ee,sinkRef:Le,adapter:t,isEditing:Ke,getSelection:Be,setSelection:Ve,commitPaste:Ha,maxOperationCells:p,onOperationRejected:$,onCopyMultiRange:L,repaintOverlay:xe,isDragging:Co,resize:{rowAxis:pe,colAxis:ae,resizeTracks:wo},pendingPasteOptionsRef:Fs,formats:x,onClipChange:X,onClipboardUnavailable:ie,onEditRejected:P,rejectReadOnly:Cn,onPasteResolved:se});Ws.current=Vn.getClip,Ks.current=Vn.discardClip,Ys.current=Vn.discardClipOnCommit,Xs.current=Vn.onAdapterSwitch,uo.current=Vn.paste;const Wn=sw({enabled:!ee,adapter:t,popovers:M,sinkRef:Le,bodyRef:de,handleRef:fe,rowAxis:pe,colAxis:ae,zoomRef:z,getActive:yo,isEditing:Ke,requestCommit:lt,focusSink:$e,rearmSink:Je,isDraggingAny:Bn,commitEdits:Jt,labels:pt,onHyperlinkOpen:J,anchors:co,repaintOverlay:xe,rejectReadOnly:Cn});Mt.current=Wn,yr.current=Wn.open,qs.current=Wn.hideTip;const tu=i.useCallback(()=>{const w=je.current.active;zt(w);const W=fe.current,Q=W===null?{x:0,y:0}:W.getScrollPosition(),te=W===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:W.getFrozenSize(),Se=W===null?{width:0,height:0}:W.getViewportSize(),Ee=z.current;return{top:ln(pe,w.row,{scroll:Math.max(0,Q.y),frozenCount:te.rows,trailingCount:te.trailingRows,extent:Se.height})*Ee,left:sn(ae,w.col,{scroll:Math.max(0,Q.x),frozenCount:te.cols,trailingCount:te.trailingCols,extent:Se.width})*Ee,width:ae.sizeOf(w.col)*Ee,height:pe.sizeOf(w.row)*Ee}},[pe,ae,zt]),bo=Yg({adapter:t,getSelection:Be,commitEdits:Jt,getActive:yo,isEditing:Ke,requestCommit:lt,cancelEdit:ol,getSessionText:Fe.getSessionText,validateCommit:rl,insertAtCaret:Fe.insertAtCaret,refreshEditPaint:Fe.refreshPaint,maxOperationCells:p,onOperationRejected:$,colors:$t,formats:x,getHighlight:()=>_n.current,setHighlight:Pa,popovers:M,openPopover:w=>yr.current(w),onHyperlinkOpen:J,onPasteSpecialRequest:ne,paste:w=>uo.current(w),rowAxis:pe,colAxis:ae,resizeTracks:wo,defaultRowHeight:n,defaultColumnWidth:r,now:ze,announce:wn,formatCommandAnnouncement:R,keyboardCellRect:tu,rejectReadOnly:Cn});js.current=bo,ao.current=bo.executeCommand,_s.current=bo.isCommandAvailable;const nu=i.useMemo(()=>({table:Wt,execute:w=>ao.current(w),isAvailable:w=>_s.current(w)}),[Wt]),ru=i.useCallback(()=>{gt(),Y?.()},[gt,Y]),ou=i.useCallback(()=>{gt(),B?.()},[gt,B]);Km({zoomRef:z,enabled:!ee,sinkRef:Le,rootRef:Ge,handOffFocusToRoot:qa,getSelection:Be,setSelection:Ve,moveActive:_a,ensureCellVisible:zt,isEditing:Ke,requestCommit:lt,startEdit:Hn,commitEdits:Jt,maxOperationCells:p,onOperationRejected:$,rejectReadOnly:Cn,getClip:br,discardClip:gt,isDragging:Bn,abortDrag:eu,findDataEdge:t.findDataEdge,getEditingMode:Fe.getEditingMode,cancelEdit:ol,onUndoRequest:ru,onRedoRequest:ou,onCellContextMenu:_,rowAxis:pe,colAxis:ae,handleRef:fe,rearmSink:Je,commands:nu,pointing:Fe,adapter:t,hideNoteTip:()=>qs.current(),closeRejectedMessage:jn,pendingPasteOptionsRef:Fs,onPointFrame:Wa});const su=He.active.row,lu=He.active.col;i.useLayoutEffect(()=>{const w=Mt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[su,lu]),i.useLayoutEffect(()=>{xe()},[xe,Lt.row,Lt.column,Lt.intersection]);const iu=i.useCallback(w=>{(vt.current?.()??!1)||(w.preventDefault(),$e(),Je())},[$e,Je]),cu=i.useCallback(w=>{const W=Ge.current,Q=w.relatedTarget;if(W!==null&&Q instanceof Node&&W.contains(Q)){w.target===W&&Q===Le.current&&!fo.current&&$e();return}(vt.current?.()??!1)||($e(),Je())},[$e,Je]),au=i.useCallback(w=>{const W=Ge.current,Q=w.relatedTarget;W!==null&&Q instanceof Node&&W.contains(Q)||Fe.isFocusoutSuppressed()||go(!1)},[Fe]),Rr=i.useRef(null),Kn=i.useCallback(()=>{const w=Rr.current;w!==null&&(Rr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),vo=i.useCallback(()=>{if(Rr.current!==null)return;const w=Q=>{Q.pointerType==="mouse"&&(Kn(),Q.button===1&&Q.preventDefault())},W=Q=>{Q.pointerType==="mouse"&&Kn()};Rr.current={up:w,cancel:W},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",W,!0)},[Kn]);i.useEffect(()=>Kn,[Kn]),i.useEffect(()=>{const w=Ge.current;if(ee||w===null)return;let W=0;const Q=Ee=>{if(Ee.pointerType!=="mouse"){(vt.current?.()??!1)||go(!1);return}W=Ee.buttons,Ee.button===1&&(Ee.target===Le.current&&(vt.current?.()??!1)||vo())},te=Ee=>{Ee.pointerType==="mouse"&&(W=Ee.buttons)},Se=Ee=>{if(Ee.pointerType!=="mouse"||Ee.buttons===W)return;const Nt=Ee.buttons&~W;W=Ee.buttons,Ee.preventDefault(),(Nt&4)!==0&&vo()};return w.addEventListener("pointerdown",Q,!0),w.addEventListener("pointerup",te,!0),w.addEventListener("pointermove",Se,!0),()=>{w.removeEventListener("pointerdown",Q,!0),w.removeEventListener("pointerup",te,!0),w.removeEventListener("pointermove",Se,!0)}},[ee,vo]);const uu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(Xt()){$e();return}if(Ke()&&!lt()){$e();return}$e()}},[$e,Ke,lt,Xt]),Ro=i.useRef(!1);i.useLayoutEffect(()=>{if(ee){Ro.current=!1;return}if(Ro.current)return;Ro.current=!0,Je();const w=(Ge.current?.clientHeight??0)/z.current;w>0&&pe.totalSize()>0&&ke.setRowRange(0,pe.indexAt(Math.min(w-1,pe.totalSize()-1)));const W=(Ge.current?.clientWidth??0)/z.current;W>0&&ae.totalSize()>0&&ke.setColRange(0,ae.indexAt(Math.min(W-1,ae.totalSize()-1)))},[ee,Je,ke,pe,ae]);const sl=i.useRef(t);i.useLayoutEffect(()=>{sl.current!==t&&(sl.current=t,it.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),ct.cancelDrag(),Ze.cancelDrag(),Fe.cancelEdit(),Mt.current?.hideTip(),Mt.current?.close(),ee?(je.current=vn,rt(vn)):Ve(vn),Xs.current())},[t,ee,Ve,it,mt,wt,Ct,ct,Ze,ke,Fe.cancelEdit]);const ll=i.useRef({adapter:t,rows:pe.count,cols:ae.count}),{getSessionCell:il,cancelEdit:cl}=Fe;i.useLayoutEffect(()=>{const w=ll.current,W=pe.count,Q=ae.count;if(ll.current={adapter:t,rows:W,cols:Q},w.adapter!==t||W>=w.rows&&Q>=w.cols)return;ee?(je.current=vn,rt(vn)):Ve(Nm(je.current,W,Q)),it.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),ct.cancelDrag(),Ze.cancelDrag();const te=Qt=>ee||Qt.row>=W||Qt.col>=Q,Se=il();Se!==null&&te(Se)&&cl();const Ee=co.current;if(Ee.tip!==null&&te(Ee.tip)&&Mt.current?.hideTip(),Ee.interactive!==null&&te(Ee.interactive)){const Qt=Ge.current?.contains(document.activeElement)===!0;Mt.current?.close({restoreFocus:Qt})}const Nt=br();Nt!==null&&!Nt.foreign&&te({row:Nt.range.endRow,col:Nt.range.endCol})&>()},[t,pe.count,ae.count,ee,Ve,it,mt,wt,Ct,ct,Ze,il,cl,br,gt]);const al=i.useRef(o),ul=i.useRef(s),dl=i.useRef(l),fl=i.useRef(c);i.useLayoutEffect(()=>{(al.current!==o||ul.current!==s||dl.current!==l||fl.current!==c)&&(al.current=o,ul.current=s,dl.current=l,fl.current=c,it.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),ct.cancelDrag(),Ze.cancelDrag())},[o,s,l,c,it,mt,wt,Ct,ct,Ze]),i.useLayoutEffect(()=>{ot(),st(),xe()},[o,s,l,c,ot,st,xe]);const pl=i.useRef(S);i.useLayoutEffect(()=>{pl.current!==S&&(pl.current=S,gt())},[S,gt]),i.useLayoutEffect(()=>{xe()},[xe,He]);const Zt=i.useCallback(()=>{const w=js.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(ro,()=>({resizeRow:(w,W)=>{const Q=Math.round(W);pe.resize(w,Q),fe.current?.updateRowSize(w,Q),ke.bumpRowGeometry(),ot(),xe(),gn()},resizeColumn:(w,W)=>{const Q=Math.round(W);ae.resize(w,Q),fe.current?.updateColSize(w,Q),ke.bumpColVersion(),st(),xe(),gn()},scrollToCell:(w,W)=>{fe.current?.scrollToCell(w.row,w.col,W)},focus:w=>{$e(w),Ke()||Je()},executeCommand:w=>ao.current(w),applyFormat:w=>Zt().applyFormat(w),setBorders:(w,W)=>Zt().setBorders(w,W),setHyperlink:w=>Zt().setHyperlink(w),setNote:w=>Zt().setNote(w),addComment:w=>Zt().addComment(w),setValidation:w=>Zt().setValidation(w),paste:w=>uo.current(w),getSelection:()=>je.current,getBaseFormat:w=>t.getCellFormat===void 0?void 0:t.getCellFormat(w.row,w.col),getPaintedFormat:w=>t.getCellFormat===void 0?void 0:Dt(w.row,w.col,Hr(t,w.row,w.col)),startEdit:w=>{Hn(w)},openPopover:w=>{yr.current(w)}}),[pe,ae,ke,st,ot,xe,gn,$e,Ke,Je,t,Dt,Hn,Zt]),ee)return K.jsx("div",{className:_e?`aqsp-root ${_e}`:"aqsp-root","data-aqsp-empty":"","data-testid":Ne});const du=D!==void 0||O!==void 0||R!==void 0||v!==void 0;return K.jsx("div",{ref:Ge,className:_e?`aqsp-root ${_e}`:"aqsp-root",role:"group","aria-label":pt.rootAriaLabel,tabIndex:0,onFocus:cu,onBlur:au,"data-aqsp-root":"","data-testid":Ne,children:K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":nt,onPointerDown:uu,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(Xt()){$e();return}if(Ke()&&!lt()){$e();return}$e(),Ve({ranges:[Ce({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(Tm,{viewStore:ke,colAxis:ae,frozenCols:o,frozenTrailingCols:l,handleRef:fe,bandRef:ge,colTrackRef:re,windowOriginXRef:he,repaintColHeaders:st,selectionRanges:He.ranges,enableResizeUI:y,dividerLeadingRef:ue,dividerTrailingRef:ye}),K.jsx($m,{viewStore:ke,rowAxis:pe,handleRef:fe,bandRef:me,selectionRanges:He.ranges,rowTrackRef:Ie,windowOriginYRef:Pe,repaintHeaders:ot,enableResizeUI:y,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:ve,dividerTrailingRef:Te}),K.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(xm,{adapter:t,rowAxis:pe,colAxis:ae,viewStore:ke,handleRef:fe,bodyRef:de,dataVersion:S,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:l,frozenTrailingRows:c,tapScrollCircleOptions:u,overscanRows:Ti("overscanRows",h),overscanCols:Ti("overscanCols",g),background:C,onRenderTruncated:q,renderCell:j,onScroll:Ba,onRangeChange:Va,focusSink:$e,isEditing:Ke,requestCommit:lt,testId:Ne?`${Ne}-vs`:void 0,__onCellRender:qe,__maxRenderedCells:gr,cfIndexRef:Nn,cfMemoRef:Pn,isPointing:Xt,locale:Tt,scrollLabels:mr}),K.jsx(sg,{rowAxis:pe,colAxis:ae,handleRef:fe,sinkRef:Le,getSelection:Be,editing:Fe.editing,virtualKeyboard:ja,repaintRef:$s,dragFrameRef:so,getClip:br,getIsDraggingAny:Bn,getIsFillDragging:ct.isDragging,fillFrameRef:Zs,resizeGuideFrameRef:Qs,fillHandleNodeRef:el,enableFillHandle:m,frozenCols:o,frozenRows:s,trailingCols:l,trailingRows:c,sinkAriaLabel:pt.sinkAriaLabel,onSinkMouseDown:iu,editPaintRef:zs,highlightRef:_n,highlightColors:Na,popoverAnchors:co,interactiveAnchorRef:Ns,tipAnchorRef:Ps}),Wn.layerEnabled?K.jsx(nw,{controller:Wn,labels:pt,renderPopover:V,interactiveAnchorRef:Ns,tipAnchorRef:Ps}):null]}),du?K.jsx("div",{ref:ht,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=as;exports.CommentPopover=aa;exports.DEFAULT_CUSTOM_COLORS=Fa;exports.DEFAULT_HIGHLIGHT_COLORS=ia;exports.DEFAULT_SHORTCUTS=Yc;exports.LinkPopover=ua;exports.ListPopover=da;exports.MessagePopover=fa;exports.NotePopover=pa;exports.NoteTip=ha;exports.SPREADSHEET_LABEL_CATALOGS=Uc;exports.SPREADSHEET_RESERVED_SHORTCUTS=ih;exports.Spreadsheet=vw;exports.canonicalizeFormat=ft;exports.columnIndexToName=or;exports.columnNameToIndex=Qp;exports.detectClipSource=Hi;exports.enumerateRangeCells=qt;exports.estimatePasteCellCount=Wp;exports.expandPaste=Kp;exports.formatCellValue=Ln;exports.formatEquals=vu;exports.fromR1C1=dr;exports.makeRange=Ce;exports.mergeFormat=ds;exports.normalizeHyperlink=Bt;exports.parseChord=nn;exports.parseClipPayload=Ko;exports.parseHtmlTable=Mc;exports.parseTsv=Bc;exports.rangeContains=cn;exports.rangeSize=tt;exports.resolveLabel=Me;exports.resolveLabels=Xc;exports.serializeClipPayload=_i;exports.serializeHtmlTable=Tc;exports.serializeTsv=jc;exports.shiftFormula=fc;exports.toR1C1=Qr;exports.validateCellText=Zc;
|
|
12
|
+
`)},Ap=(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)}Qo(t,xc(e,r))},Op=(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"?vc(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<Pl.length?Pl[l]:null}return null},Tc=(e,t,n)=>t!==void 0&&Sc(t)?Ff(e,t,n):e,xp=(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!==""&&tt(c)!==null)if(n!==void 0&&n.type==="date"){const u=vc(Number(c));if(u!==null)return u}else return c;return Tc(t,n,r)},Tp=(e,t,n,r)=>{const o=xc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:yp(o)};for(const g of Mp(e))kp(g,l);Sp(l,o,s,r.rules);const c=Ep(l.text,l.mode),u=Rp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const g=e.getAttribute("data-sheets-numberformat"),C=g===null?void 0:xf(g,r.options);C!==void 0&&(u.value=C);const q=e.getAttribute("data-sheets-value"),j=q===null?null:Op(q,C);h.t=j===null?Tc(c,C,Cc):j;const N=e.getAttribute("data-sheets-formula");N?.startsWith("=")&&(h.f=N);const _=e.getAttribute("data-sheets-hyperlink"),Y=_!==null?_:l.href,B=Y===null?null:Bt(Y);B!==null&&(h.link=B);const D=e.getAttribute("data-sheets-note");D!==null&&D!==""&&(h.note=D)}else{const g=o.get("mso-number-format"),C=g===void 0?void 0:ys(Jo(Yr(g)),r.options);C!==void 0&&(u.value=C),h.t=xp(e,c,C,r.separators);const q=e.getAttribute("x:fmla");q?.startsWith("=")&&(h.f=eo(q,{row:t,col:n}));const j=l.href===null?null:Bt(l.href);j!==null&&(h.link=j)}return{cell:h,format:u}},es=(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},$p=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)},Lp=(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]))},$c=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:no(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:$p(l);if(c!==null)return Math.min(c,Ln)}const o=Lp(e,t);return o===null?null:Math.min(o,Ln)},Dp=(e,t)=>{const n=[],r=o=>{const s=$c(o,"width");for(let l=es(o,"span",ps);l>0&&n.length<t;l-=1)n.push(s)};for(const o of cr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of cr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*cr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Mp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*zp(e){for(const t of["thead","tbody","tfoot"])for(const n of cr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of cr(n))o.localName==="tr"&&(yield o)}}const zo=()=>({t:""}),Fp=(e,t,n)=>{const r=Ui(),o=[],s=[],l=[];let c=0;for(const j of zp(e)){const N=o.length,_=(N+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const Y=[];for(let D=0;D<l.length;D+=1)l[D]>0&&(Y[D]=zo(),l[D]-=1);let B=0;for(const D of cr(j)){const $=D.localName;if($!=="td"&&$!=="th")continue;for(;Y[B]!==void 0;)B+=1;const P=es(D,"colspan",ps),k=es(D,"rowspan",Ii),R=(N+1)*Math.max(c,B+P);if(R>n)return{outcome:"limit",cells:R};const S=Tp(D,N,B,t),p=r.intern(S.format);p!==void 0&&(S.cell.fmt=p),Y[B]=S.cell;for(let m=1;m<P;m+=1)Y[B+m]===void 0&&(Y[B+m]=zo());if(k>1)for(let m=0;m<P;m+=1){const y=k-1,L=B+m;l[L]=l[L]===void 0||l[L]<y?y:l[L]}B+=P}Y.length>c&&(c=Y.length),o.push(Y),s.push($c(j,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(j=>{const N=[];for(let _=0;_<c;_+=1){const Y=j[_];N.push(Y===void 0?zo():Y)}return N}),h=Dp(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:ds(),formats:[...r.entries],validations:[],cells:u,...g===void 0?{}:{colWidths:g},...C===void 0?{}:{rowHeights:C},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Lc=(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=Xf(o);return Fp(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Ce=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),cn=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,nt=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),yt=e=>e.reduce((t,n)=>t+nt(n).rows*nt(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)}},Ot=(e,t)=>e.row===t.row&&e.col===t.col,Dc=(e,t)=>e===void 0?gl(void 0,void 0,t()):gl(e.align,e.value,e.align===void 0?t():""),Br=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},zn=(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}},Vr=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}),Mc=e=>e.isCellReadOnly!==void 0,Ke=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Np=/^data-[a-z0-9-]+$/,Pp=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},qp=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Pp(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(!Np.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},Qn=(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},En=(e,t)=>{for(const n of t)if(Qn(e,n))return!0;return!1},_p=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=nt(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},ts=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=nt(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:Ce(g,{row:g.row+C-1,col:g.col+q-1})},zc=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=ts({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 N=[];for(let Y=0;Y<C;Y+=c){const B={row:h.row+j,col:h.col+Y};N.push(B),q.push(B)}const _=Math.min(l,g-j);for(let Y=0;Y<_;Y+=1){const B=h.row+j+Y,D=e[Y];for(let $=0;$<N.length;$+=1){const P=$*c,k=Math.min(c,C-P);for(let R=0;R<k;R+=1)s(B,h.col+P+R,D[R],N[$])}}}return q},jp=(e,t,n,r,o)=>{const s=[];return zc(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},jl=(e,t,n,r,o,s)=>{const l=[],c=zc(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}},Fc=(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)})`)},Ip=(e,t)=>{Fc(e,t);const n=nt(t),r=nt(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},Hp=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(Ce({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Ce({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Ce({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Ce({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Bp=(e,t,n,r)=>{Fc(t,n);const o=nt(t).rows,s=nt(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 N=c.get(j);N===void 0&&(N={value:e(h,q),origin:{row:h,col:q}},c.set(j,N)),l.push(r(N.value,N.origin,{row:u,col:C}))}}return l},Nc=(e,t,n)=>{const r=zn(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:ft(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=Fn(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},Pc=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?uc(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},sr=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},Vp=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},ro=["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"],Wp=/^[A-Z]$/,Kp=/^[A-Za-z]$/,Yp=/^Key([A-Z])$/,qc=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"]),Up=e=>Wp.test(e)||qc.has(e),nn=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||!Up(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}},Xp=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,_c=e=>{if(Kp.test(e.key))return e.key.toUpperCase();const t=Yp.exec(e.code);return t!==null?t[1]:qc.has(e.code)?e.code:null},Yn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:_c(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),be=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Gp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Zp=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},pr=[...Gp(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...Zp(),be("bold","Ctrl+B","both","toggle bold"),be("italic","Ctrl+I","both","toggle italic"),be("underline","Ctrl+U","both","toggle underline"),be("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),be("clearFormatting","Ctrl+Backslash","idle","clear formatting"),be("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),be("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),be("alignLeft","Ctrl+Shift+L","both","align left"),be("alignCenter","Ctrl+Shift+E","both","align center"),be("alignRight","Ctrl+Shift+R","both","align right"),be("formatNumber","Ctrl+Shift+Digit1","both","number format"),be("formatTime","Ctrl+Shift+Digit2","both","time format"),be("formatDate","Ctrl+Shift+Digit3","both","date format"),be("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),be("formatPercent","Ctrl+Shift+Digit5","both","percent format"),be("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),be("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),be("bordersClear","Alt+Shift+Digit6","idle","clear borders"),be("borderTop","Alt+Shift+Digit1","idle","top border"),be("borderRight","Alt+Shift+Digit2","idle","right border"),be("borderBottom","Alt+Shift+Digit3","idle","bottom border"),be("borderLeft","Alt+Shift+Digit4","idle","left border"),be("insertLink","Ctrl+K","idle","insert / edit hyperlink"),be("insertNote","Shift+F2","idle","insert / edit note"),be("insertComment","Ctrl+Alt+M","idle","insert comment"),be("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),be("openValidationList","Alt+ArrowDown","idle","open the validation list"),be("fillDown","Ctrl+D","idle","fill down"),be("fillRight","Ctrl+R","idle","fill right"),be("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),be("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),be("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),be("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),be("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),be("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],Ur=(e,t)=>e.column==="both"||e.column===t,Jp=Array.from(new Set(pr.filter(e=>!e.rebindable&&Ur(e,"idle")).map(e=>e.chord))),vs=new Set(pr.filter(e=>e.command!==void 0&&Ur(e,"editing")).map(e=>e.command)),Qp=new Set(pr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),jc=e=>{const t={};for(const n of ro)t[n]=e(n);return t},Ic=jc(e=>pr.filter(t=>t.command===e).map(t=>t.chord)),eh=e=>{const t=new Map;for(const n of ro){const r=e[n];if(r!=null)for(const o of r){const s=t.get(o);s===void 0?t.set(o,[n]):s.includes(n)||s.push(n)}}return t},th=e=>{const t=new Set(ro);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(Qp.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},nh=(e,t)=>{const n=nn(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 pr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Ur(o,"idle")||r&&Ur(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},rh=e=>{e!==void 0&&th(e);const t=jc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Ic[r]:o===null?[]:o});for(const r of ro)for(const o of t[r])nh(r,o);const n=new Map;for(const[r,o]of eh(t)){if(o.length>1)throw new RangeError(`[spreadsheet] shortcut ${r} bound to ${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`);n.set(r,o[0])}return n},Il=(e,t)=>{const n=_c(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Xp({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},ks=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],Hl=[...Ge.VIRTUAL_SCROLL_LABEL_KEYS,...ks],ns=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),Hc=Object.freeze({en:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ns.en}),ja:Object.freeze({...Ge.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ns.ja})}),on=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Bl=e=>e==="commentCount"||e==="listMore",oh=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 ${on(t)}`);for(const n of ks){const r=e[n];if(!(Bl(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Bl(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${on(r)}`)}}},sh=e=>{const t={};let n=!1;for(const r of Ge.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},lh=(e,t,n)=>{e[t]=n},Bc=(e,t)=>{const n=Ge.resolveVirtualScrollLocale(e);if(t===void 0)return Hc[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${on(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!Hl.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${Hl.join(", ")}`);const s={...Ge.resolveVirtualScrollLabels(n,sh(t)),...ns[n]};for(const l of ks){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&lh(s,l,c)}return oh(s),Object.freeze(s)},ih=e=>{const t={};for(const n of Ge.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},Me=(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},Vl={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},ch={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},ah=(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}`}},Fo=(e,t)=>{const n=r=>(o,s)=>`${e} ${ah(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},uh=Object.freeze({list:"Value must be one of the list items.",number:Fo("Value must be a number",Vl),textLength:Fo("Text length must be",Vl),date:Fo("Value must be a date",ch),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),dh=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),No=Object.freeze({en:uh,ja:dh}),fh=Object.freeze({ok:!0}),ph="TRUE",hh="FALSE",gh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),mh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),wh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Ch=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,yh=/^[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])?)+$/,Wl=e=>{const t=e.trim();if(!(wh.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),g=u+h,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}},bh=e=>e===1?-1:e===-1?1:0,Rh=(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:bh(n)},vh=(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}},Kl=e=>{const t=Ch.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>vh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},kh=(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},Sh=(e,t)=>e<t?-1:e>t?1:0,Eh=e=>e==="between"||e==="notBetween",Ah=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Eh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Oh=(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}},Po=(e,t,n,r,o,s)=>{const l=Ah(e,t,n,r);return l===null?!0:o===null?!1:Oh(e,s(o,l.a),l.b===null?0:s(o,l.b))},xh=e=>Number.isFinite(e)?e:null,Th=e=>{let t=0;for(const n of e)t+=1;return t},$h=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Lh=(e,t)=>{switch(e.op){case"isEmail":return yh.test(t);case"isUrl":return $h(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)}},Dh=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Vc=e=>({checked:e.checked===void 0?ph:e.checked,unchecked:e.unchecked===void 0?hh:e.unchecked}),Mh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!gh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${on(e.op)} for type "${e.type}"`);return;case"text":if(!mh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${on(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${on(e.type)}`)}},zh=(e,t,n)=>{switch(e.type){case"list":return Ph(e).has(t);case"number":return Po(e.op,e.a,e.b,Wl,Wl(t),Rh);case"textLength":return Po(e.op,e.a,e.b,xh,Th(t),Sh);case"date":return Po(e.op,e.a,e.b,Kl,Kl(t),kh);case"text":return Lh(e,t);case"checkbox":{const r=Vc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Dh(n(e.formula))}},Wc=(e,t,n)=>(Mh(e),t===""||zh(e,t,n)),Yl=e=>e===void 0?void 0:e.trim(),Fh=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),Yl(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),Yl(e.b));case"text":return Nh(e,t.text);case"checkbox":{const n=Vc(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},Nh=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},Ul=new WeakMap,Ph=e=>{const t=Ul.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Ul.set(e,n),n},Kc=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(No,n)){const o=Object.keys(No).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${on(n)}`)}return Wc(e,t,r)?fh:{ok:!1,message:e.errorMessage===void 0?Fh(e,No[n]):e.errorMessage}},qh=e=>e.type!=="custom",_h=(e,t)=>qh(e)&&!Wc(e,t,void 0),Yc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Uc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Xc=(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,Gc=(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),Zc=(e,t)=>Yc(e,t),Jc=(e,t)=>Yc(e,t),Qc=(e,t)=>Uc(e,t),ea=(e,t)=>Uc(e,t),sn=(e,t,n)=>Xc(e,t,n),ln=(e,t,n)=>Xc(e,t,n),hr=(e,t,n)=>Gc(e,t,n),gr=(e,t,n)=>Gc(e,t,n),jh=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Pt=1,er=3,$r=e=>`${-Math.min(er,Math.max(0,Math.floor(e)))}px`,ta=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Ih=16,Hh=450,Bh=e=>e>4?Math.floor(Hh/(5*e)):Ih,Un=(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},Xl=()=>({rowLeft:Un("row","left"),rowRight:Un("row","right"),colAbove:Un("column","above"),colBelow:Un("column","below"),cross:Un("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),na=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Lr=(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),Gl="inset(100%)",xn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Vh=(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)}},Zl=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))},Jl=e=>{for(const t of na(e))t.remove()},Wh=(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)},Kh=Object.freeze([]),Ql=e=>e.dividers[0]??e.active,Yh={left:"0px",right:"0px",width:""},Uh={top:"0px",bottom:"0px",height:""},ei=()=>({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:[]}),ti=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],ni=6,Xh=({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:N,enableFillHandle:_,frozenCols:Y,frozenRows:B,trailingCols:D,trailingRows:$,sinkAriaLabel:P,onSinkMouseDown:k,editPaintRef:R,highlightRef:S,highlightColors:p,popoverAnchors:m,interactiveAnchorRef:y,tipAnchorRef:L})=>{const O=i.useRef(null),v=i.useRef(null),F=i.useRef(null),b=i.useRef(new Map(ti.map(z=>[z,ei()]))),a=i.useCallback(z=>{const H=b.current.get(z);if(H!==void 0)return H;const U=ei();return b.current.set(z,U),U},[]),f=i.useCallback((z,H,U)=>{if(z===null)return;const I=z.style;I.left!==H.left&&(I.left=H.left),I.right!==H.right&&(I.right=H.right),I.width!==H.width&&(I.width=H.width),I.top!==U.top&&(I.top=U.top),I.bottom!==U.bottom&&(I.bottom=U.bottom),I.height!==U.height&&(I.height=U.height)},[]),x=i.useCallback((z,H,U)=>{if(!(z.bandClampWidth===H&&z.bandClampHeight===U)){z.bandClampWidth=H,z.bandClampHeight=U;for(const I of z.bandPool)Lr(I,H,U);z.dragBand!==null&&Lr(z.dragBand,H,U)}},[]),d=i.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const A=i.useCallback((z,H,U)=>{const I=z.dividerSlots[H];I===null||z.dividerShown[H]===U||(z.dividerShown[H]=U,I.style.display=U?"":"none")},[]),E=i.useRef({x:0,y:0}),T=i.useRef(null),M=i.useCallback((z,H)=>{const U=n.current,I=U?.getFrozenSize()??jh,G=U?.getViewportSize(),oe=G?.width??-1,ee=G?.height??-1,Ae=E.current;Ae.x=z,Ae.y=H;let de=T.current;if(de===null||de.frozenCols!==I.cols||de.frozenWidth!==I.width||de.frozenRows!==I.rows||de.frozenHeight!==I.height||de.trailingCols!==I.trailingCols||de.trailingWidth!==I.trailingWidth||de.trailingVisibleWidth!==I.trailingVisibleWidth||de.trailingRows!==I.trailingRows||de.trailingHeight!==I.trailingHeight||de.trailingVisibleHeight!==I.trailingVisibleHeight||de.bodyWidth!==oe||de.bodyHeight!==ee){const re=I.trailingVisibleWidth,he=I.trailingVisibleHeight,ge=I.cols<=0&&I.trailingCols<=0?[{kind:"m",map:ye=>ye-Ae.x,clamp:oe,style:Yh,seamLead:!1,seamTrail:!1}]:[...I.cols>0?[{kind:"f",map:ye=>ye,clamp:I.width,style:{left:"0px",width:`${I.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ye=>ye-Ae.x-I.width,clamp:Math.max(0,oe-I.width-re),style:{left:`${I.width}px`,right:`${re}px`,width:""},seamLead:I.cols>0,seamTrail:I.trailingCols>0},...I.trailingCols>0?[{kind:"t",map:ye=>ye-d.current.colAxis.totalSize()+re,clamp:re,style:{left:"",right:"0px",width:`${re}px`},seamLead:!0,seamTrail:!1}]:[]],me=I.rows<=0&&I.trailingRows<=0?[{kind:"m",map:ye=>ye-Ae.y,clamp:ee,style:Uh,seamLead:!1,seamTrail:!1}]:[...I.rows>0?[{kind:"f",map:ye=>ye,clamp:I.height,style:{top:"0px",height:`${I.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ye=>ye-Ae.y-I.height,clamp:Math.max(0,ee-I.height-he),style:{top:`${I.height}px`,bottom:`${he}px`,height:""},seamLead:I.rows>0,seamTrail:I.trailingRows>0},...I.trailingRows>0?[{kind:"t",map:ye=>ye-d.current.rowAxis.totalSize()+he,clamp:he,style:{top:"",bottom:"0px",height:`${he}px`},seamLead:!0,seamTrail:!1}]:[]],ue=[];for(const ye of ge)for(const Re of me)ue.push({nodes:a(`${ye.kind}${Re.kind}`),xKind:ye.kind,yKind:Re.kind,mapX:ye.map,clampWidth:ye.clamp,xStyle:ye.style,xSeamLead:ye.seamLead,xSeamTrail:ye.seamTrail,mapY:Re.map,clampHeight:Re.clamp,yStyle:Re.style,ySeamLead:Re.seamLead,ySeamTrail:Re.seamTrail});de={frozenCols:I.cols,frozenWidth:I.width,frozenRows:I.rows,frozenHeight:I.height,trailingCols:I.trailingCols,trailingWidth:I.trailingWidth,trailingVisibleWidth:I.trailingVisibleWidth,trailingRows:I.trailingRows,trailingHeight:I.trailingHeight,trailingVisibleHeight:I.trailingVisibleHeight,bodyWidth:oe,bodyHeight:ee,ctxs:ue},T.current=de}const fe=I.width>0,De=I.trailingWidth>0,He=I.height>0,Pe=I.trailingHeight>0;for(const re of de.ctxs)f(re.nodes.container,re.xStyle,re.yStyle),x(re.nodes,re.clampWidth,re.clampHeight),A(re.nodes,0,fe),A(re.nodes,1,De),A(re.nodes,2,He),A(re.nodes,3,Pe);return de.ctxs},[n,a,f,x,A]),V=i.useCallback((z,H,U)=>{z.dividerSlots[H]=U,z.dividerShown[H]=!1,z.dividers.length=0;for(const I of z.dividerSlots)I!==null&&z.dividers.push(I)},[]),X=i.useCallback(z=>{const H=()=>a(z);return{container:U=>{const I=H();I.container=U,U===null&&(I.fillPool.length=0,I.bandPool.length=0,I.dragBand=null,I.bandClampWidth=-1,I.bandClampHeight=-1)},dividerXLeading:U=>V(H(),0,U),dividerXTrailing:U=>V(H(),1,U),dividerYLeading:U=>V(H(),2,U),dividerYTrailing:U=>V(H(),3,U),active:U=>{H().active=U},dragRect:U=>{H().dragRect=U},marquee:U=>{H().marquee=U},fillPreview:U=>{H().fillPreview=U},resizeGuide:U=>{H().resizeGuide=U}}},[a,V]),Z=i.useMemo(()=>Object.fromEntries(ti.map(z=>[z,X(z)])),[X]),J=Math.min(Math.max(0,Y),t.count),ne=Zc(t,J),ie=Math.min(Math.max(0,B),e.count),se=Jc(e,ie),ze=D===void 0?0:Math.min(Math.max(0,D),t.count-J),ce=Qc(t,ze),ve=$===void 0?0:Math.min(Math.max(0,$),e.count-ie),Le=ea(e,ve),Ne=i.useRef(null),je=i.useRef("add"),qe=i.useRef(s);qe.current=s;const bt=i.useRef(!1),mr=Ge.useWheelBridge(n,{enableBridge:!s}),oo=i.useCallback(z=>(r.current=z,mr(z)),[r,mr]),pe=i.useCallback((z,H)=>({top:H.mapY(e.offsetOf(z.startRow)),bottom:H.mapY(e.offsetOf(z.endRow)+e.sizeOf(z.endRow)),left:H.mapX(t.offsetOf(z.startCol)),right:H.mapX(t.offsetOf(z.endCol)+t.sizeOf(z.endCol))}),[e,t]),ae=i.useCallback((z,H)=>{if(H.clampHeight<=0||H.clampWidth<=0)return null;const{top:U,bottom:I,left:G,right:oe}=pe(z,H),ee=-H.clampHeight*Pt,Ae=H.clampHeight*(1+Pt),de=-H.clampWidth*Pt,fe=H.clampWidth*(1+Pt);if(I<ee||U>Ae||oe<de||G>fe)return null;const De=Math.max(U,ee),He=Math.max(G,de);return{top:De,left:He,width:Math.min(oe,fe)-He,height:Math.min(I,Ae)-De}},[pe]),an=i.useCallback((z,H)=>{if(H.clampHeight<=0||H.clampWidth<=0)return null;const U=pe(z,H),I=-H.clampHeight*Pt,G=H.clampHeight*(1+Pt),oe=-H.clampWidth*Pt,ee=H.clampWidth*(1+Pt),Ae=Math.min(Math.max(U.top,I),G),de=Math.min(Math.max(U.left,oe),ee);return{top:Ae,left:de,width:Math.min(Math.max(U.right,oe),ee)-de,height:Math.min(Math.max(U.bottom,I),G)-Ae}},[pe]),ke=i.useCallback(()=>{if(S===void 0)return null;const z=S.current;return z.row||z.column||z.intersection?z:null},[S]),Tt=i.useCallback((z,H,U)=>{const I=H.fillPool[0]?.node??Ql(H);for(const G of na(U))z.insertBefore(G,I)},[]),pt=i.useCallback((z,H,U,I)=>{const G=an(H,U);if(G===null){Zl(z);return}Vh(z,G,U,I,Xi(H,t.count)||Gi(H,e.count))},[an,e,t]),wr=i.useCallback((z,H,U,I)=>{const G=z.nodes.bandPool;for(;G.length>U.length;){const oe=G.pop();oe!==void 0&&Jl(oe)}if(I===null){z.nodes.dragBand!==null&&(Jl(z.nodes.dragBand),z.nodes.dragBand=null);return}for(let oe=0;oe<U.length;oe+=1){let ee=G[oe];ee===void 0&&(ee=Xl(),Lr(ee,z.clampWidth,z.clampHeight),Tt(H,z.nodes,ee),G.push(ee)),pt(ee,U[oe],z,I)}},[Tt,pt]),Wt=i.useCallback((z,H,U)=>{const I=z.nodes.container;if(I===null)return;if(H===null||U===null){z.nodes.dragBand!==null&&Zl(z.nodes.dragBand);return}let G=z.nodes.dragBand;G===null&&(G=Xl(),Lr(G,z.clampWidth,z.clampHeight),Tt(I,z.nodes,G),z.nodes.dragBand=G),pt(G,H,z,U)},[Tt,pt]),$t=i.useCallback((z,H)=>{if(z!==null){if(H===null){z.style.display="none";return}z.style.display="block",z.style.transform=`translate(${H.left}px, ${H.top}px)`,z.style.width=`${H.width}px`,z.style.height=`${H.height}px`}},[]),un=i.useCallback((z,H,U,I)=>{const G=I==="point"?null:ke();for(const oe of M(U,H))$t(oe.nodes.dragRect,ae(z,oe)),Wt(oe,z,G)},[ae,M,$t,ke,Wt]),Kt=i.useCallback((z,H,U)=>{for(const I of M(U,H))$t(I.nodes.fillPreview,z===null?null:ae(z,I))},[ae,M,$t]),dn=i.useCallback((z,H,U)=>{for(const I of M(U,H)){const G=I.nodes.resizeGuide;if(G===null)continue;if(z===null){G.style.display="none";continue}const oe=z.anchor==="trailing";if(z.axis==="col"){if(oe&&I.xKind!=="t"){G.style.display="none";continue}G.style.display="block";const ee=I.mapX(z.position);G.style.transform=`translate(${oe?Math.max(0,ee):ee}px, 0px)`,G.style.width="1px",G.style.height="100%"}else{if(oe&&I.yKind!=="t"){G.style.display="none";continue}G.style.display="block";const ee=I.mapY(z.position);G.style.transform=`translate(0px, ${oe?Math.max(0,ee):ee}px)`,G.style.width="100%",G.style.height="1px"}}},[M]),Cr=i.useCallback((z,H,U,I,G,oe,ee)=>{if(z===null)return;if(H===null||ee<=0||oe<=0){z.style.clipPath=Gl;return}const Ae=ln(e,H.row,I),de=sn(t,H.col,U),fe=t.sizeOf(H.col),De=e.sizeOf(H.row),He=de>=oe||Ae>=ee,Pe=H.col>=G.cols&&de<G.width,re=H.row>=G.rows&&Ae<G.height,he=G.trailingWidth>0&&H.col<t.count-G.trailingCols&&de+fe>oe-G.trailingVisibleWidth,ge=G.trailingHeight>0&&H.row<e.count-G.trailingRows&&Ae+De>ee-G.trailingVisibleHeight;if(He||Pe||re||he||ge){z.style.clipPath=Gl;return}z.style.clipPath="",z.style.transform=`translate(${de}px, ${Ae}px)`;const me=`${fe} ${De}`;z.dataset.aqspAnchorSig!==me&&(z.dataset.aqspAnchorSig=me,z.style.width=`${fe}px`,z.style.height=`${De}px`)},[e,t]),yr=i.useCallback((z,H,U)=>{if(m===void 0)return;const I=m.current,{width:G,height:oe}=z.getViewportSize(),ee=z.getFrozenSize(),Ae={scroll:U,frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:G},de={scroll:H,frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:oe};Cr(y===void 0?null:y.current,I.interactive,Ae,de,ee,G,oe),Cr(L===void 0?null:L.current,I.tip,Ae,de,ee,G,oe)},[m,y,L,Cr]),Yt=i.useCallback(()=>{const z=O.current,H=n.current;if(z===null||H===null)return;const U=H.getScrollPosition(),I=Math.max(0,U.y),G=Math.max(0,U.x),oe=o(),ee=M(G,I),Ae=ke(),de=Ae===null?Kh:oe.ranges.slice(-Bh(ee.length));for(const re of ee){const he=re.nodes.container;if(he===null)continue;const ge=re.nodes.fillPool;for(let me=0;me<Math.max(ge.length,oe.ranges.length);me+=1){let ue=ge[me];if(ue===void 0){const Te=document.createElement("div");Te.className="aqsp-selection-fill",Te.setAttribute("data-aqsp-fill",""),Te.style.display="none",he.insertBefore(Te,Ql(re.nodes)),ue={node:Te,last:{shown:!1,width:-1,height:-1,transform:""}},ge.push(ue)}const ye=oe.ranges[me],Re=ye===void 0?null:ae(ye,re);if(Re===null)ue.last.shown&&(ue.last.shown=!1,ue.node.style.display="none");else{ue.last.shown||(ue.last.shown=!0,ue.node.style.display="block");const Te=`translate(${Re.left}px, ${Re.top}px)`;Te!==ue.last.transform&&(ue.last.transform=Te,ue.node.style.transform=Te),Re.width!==ue.last.width&&(ue.last.width=Re.width,ue.node.style.width=`${Re.width}px`),Re.height!==ue.last.height&&(ue.last.height=Re.height,ue.node.style.height=`${Re.height}px`)}}for(;ge.length>oe.ranges.length;)ge.pop()?.node.remove();$t(re.nodes.active,ae(Ce(oe.active,oe.active),re)),wr(re,he,de,Ae)}const fe=h(),De=fe===null||fe.foreign?null:fe;for(const re of ee){const he=re.nodes.marquee;if(he===null)continue;const ge=De===null?null:ae(De.range,re),me=ge!==null&&(re.xSeamTrail&&ge.left>=re.clampWidth&&ge.left<re.clampWidth+er||re.xSeamLead&&ge.left+ge.width<=0&&ge.left+ge.width>-er||re.ySeamTrail&&ge.top>=re.clampHeight&&ge.top<re.clampHeight+er||re.ySeamLead&&ge.top+ge.height<=0&&ge.top+ge.height>-er)?null:ge;if(me===null)he.style.display="none";else{he.style.display="block",he.style.transform=`translate(${me.left}px, ${me.top}px)`,he.style.width=`${me.width}px`,he.style.height=`${me.height}px`;const Re=$r(me.top),Te=$r(me.left),ht=$r(re.clampHeight-(me.top+me.height)),Be=$r(re.clampWidth-(me.left+me.width)),ot=`${Re} ${Be} ${ht} ${Te}`;ot!==he.dataset.aqspOutsetSig&&(he.dataset.aqspOutsetSig=ot,he.style.setProperty("--aqsp-clip-outset-top",Re),he.style.setProperty("--aqsp-clip-outset-right",Be),he.style.setProperty("--aqsp-clip-outset-bottom",ht),he.style.setProperty("--aqsp-clip-outset-left",Te))}const ue=me===null?null:De?.kind??null,ye=he.dataset.aqspClipKindLast??null;ue!==ye&&(ue===null?(delete he.dataset.aqspClipKindLast,he.removeAttribute("data-aqsp-clip-kind")):(he.dataset.aqspClipKindLast=ue,he.setAttribute("data-aqsp-clip-kind",ue)))}Ne.current!==null&&un(Ne.current,I,G,je.current),F.current!==null&&dn(F.current,I,G),v.current!==null&&Kt(v.current,I,G);const He=N.current;if(He!==null&&!C()){const{width:re,height:he}=H.getViewportSize(),ge=oe.ranges[oe.ranges.length-1];if(!(oe.ranges.length===1&&!qe.current&&!g())||he<=0||re<=0)He.style.display="none";else{const ue=H.getFrozenSize(),ye={scroll:G,frozenCount:ue.cols,trailingCount:ue.trailingCols,extent:re},Re={scroll:I,frozenCount:ue.rows,trailingCount:ue.trailingRows,extent:he},Te=ge.endCol<ue.cols,ht=ge.endRow<ue.rows,Be=ge.endCol>=t.count-ue.trailingCols,ot=ge.endRow>=e.count-ue.trailingRows,Ie=sn(t,ge.endCol,ye)+t.sizeOf(ge.endCol),Ve=ln(e,ge.endRow,Re)+e.sizeOf(ge.endRow),qn=Te||Be?0:ue.width,Ut=ht||ot?0:ue.height,Dt=Be?re:re-ue.trailingVisibleWidth,_n=ot?he:he-ue.trailingVisibleHeight;Ve<=Ut||Ve>_n||Ie<=qn||Ie>Dt?He.style.display="none":(He.style.display="block",He.style.transform=`translate(${Ie-ni+1}px, ${Ve-ni+1}px)`)}}const Pe=r.current;if(Pe!==null){const re=oe.active,{width:he,height:ge}=H.getViewportSize(),me=H.getFrozenSize(),ue={scroll:G,frozenCount:me.cols,trailingCount:me.trailingCols,extent:he},ye={scroll:I,frozenCount:me.rows,trailingCount:me.trailingRows,extent:ge},Re=ln(e,re.row,ye),Te=sn(t,re.col,ue),ht=ge>0?Math.min(Math.max(Re,0),Math.max(0,ge-1)):0,Be=he>0?Math.min(Math.max(Te,0),Math.max(0,he-1)):0;Pe.style.top=`${ht}px`,Pe.style.left=`${Be}px`,qe.current?(Pe.style.width=`${t.sizeOf(re.col)}px`,Pe.style.height=`${e.sizeOf(re.row)}px`,Pe.style.paddingTop=`${Wh(e.sizeOf(re.row),R===void 0?Et:R.current)}px`):(Pe.style.width="1px",Pe.style.height="1px",Pe.style.paddingTop="0px");const ot=re.col>=me.cols&&Te<me.width,Ie=re.row>=me.rows&&Re<me.height,Ve=me.trailingWidth>0&&re.col<t.count-me.trailingCols&&Te+t.sizeOf(re.col)>he-me.trailingVisibleWidth,qn=me.trailingHeight>0&&re.row<e.count-me.trailingRows&&Re+e.sizeOf(re.row)>ge-me.trailingVisibleHeight,Ut=qe.current&&Re===ht&&Te===Be&&!ot&&!Ie&&!Ve&&!qn;Ut!==bt.current&&(bt.current=Ut,Ut?Pe.setAttribute("data-aqsp-editing",""):Pe.removeAttribute("data-aqsp-editing"))}yr(H,I,G)},[n,ae,M,$t,un,dn,Kt,h,o,g,C,N,r,e,t,ke,wr,R,yr]),fn=i.useCallback((z,H)=>{Ne.current=z,je.current=H;const U=z===null?"add":H;for(const oe of M(0,0)){const ee=oe.nodes.dragRect;if(ee===null)continue;const Ae=ee.dataset.aqspDragModeLast??"add";U!==Ae&&(ee.dataset.aqspDragModeLast=U,U==="add"?ee.removeAttribute("data-aqsp-drag-mode"):ee.setAttribute("data-aqsp-drag-mode",U))}const I=n.current;if(z===null||I===null){for(const oe of M(0,0))oe.nodes.dragRect!==null&&(oe.nodes.dragRect.style.display="none"),Wt(oe,null,null);return}const G=I.getScrollPosition();un(z,Math.max(0,G.y),Math.max(0,G.x),H)},[n,un,M,Wt]),Nn=i.useCallback(z=>{v.current=z;const H=n.current;if(H===null){for(const I of M(0,0))I.nodes.fillPreview!==null&&(I.nodes.fillPreview.style.display="none");return}const U=H.getScrollPosition();Kt(z,Math.max(0,U.y),Math.max(0,U.x))},[n,Kt,M]),Pn=i.useCallback(z=>{F.current=z;const H=n.current;if(H===null){for(const I of M(0,0))I.nodes.resizeGuide!==null&&(I.nodes.resizeGuide.style.display="none");return}const U=H.getScrollPosition();dn(z,Math.max(0,U.y),Math.max(0,U.x))},[n,dn,M]);i.useLayoutEffect(()=>{const z=O.current;if(!(z===null||p===void 0))return z.style.setProperty("--aqsp-band-row",p.row),z.style.setProperty("--aqsp-band-column",p.column),z.style.setProperty("--aqsp-band-intersection",p.intersection),z.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{z.style.removeProperty("--aqsp-band-row"),z.style.removeProperty("--aqsp-band-column"),z.style.removeProperty("--aqsp-band-intersection"),z.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Yt,u.current=fn,q.current=Nn,j.current=Pn,()=>{c.current=null,u.current=null,q.current=null,j.current=null})),i.useEffect(()=>{Yt()},[Yt,s,J,ie,ze,ve]),i.useEffect(()=>{const z=r.current;if(z===null)return;const H=U=>k(U);return z.addEventListener("mousedown",H),()=>z.removeEventListener("mousedown",H)},[r,k]);const Lt=J>0||ze>0?[...J>0?[{k:"f",style:{left:0,width:ne}}]:[],{k:"s",style:{left:ne,right:ce}},...ze>0?[{k:"t",style:{right:0,width:ce}}]:[]]:[{k:"m",style:{left:0,right:0}}],Ze=ie>0||ve>0?[...ie>0?[{k:"f",style:{top:0,height:se}}]:[],{k:"s",style:{top:se,bottom:Le}},...ve>0?[{k:"t",style:{bottom:0,height:Le}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],pn=z=>z==="m"?0:z==="s"?1:z==="t"?2:3,so=Lt.flatMap(z=>Ze.map(H=>({xk:z.k,yk:H.k,key:`${z.k}${H.k}`,style:{...z.style,...H.style}}))).sort((z,H)=>pn(z.key[0])+pn(z.key[1])-(pn(H.key[0])+pn(H.key[1]))),rt=z=>z==="mm"?{"data-aqsp-overlay-main":""}:z==="fm"?{"data-aqsp-overlay-frozen":""}:z==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:O,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:_e.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:_e.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[so.map(({xk:z,yk:H,key:U,style:I})=>{const G=Z[U];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":U,...rt(U),style:I,ref:G.container,children:[z==="s"&&J>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:G.dividerXLeading}):null,z==="s"&&ze>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:G.dividerXTrailing}):null,H==="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:G.dividerYLeading}):null,H==="s"&&ve>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:G.dividerYTrailing}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:G.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:G.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:G.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:G.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:G.resizeGuide})]},U)}),K.jsx("textarea",{ref:oo,className:"aqsp-sink","aria-label":P,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?K.jsx("div",{ref:N,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},ra=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=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:[Me(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Me(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":Me(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:Me(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},oa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),u=i.useRef(!1),h=o.trim()===""?null:Bt(o),g=o.trim()!==""&&h===null,C=_=>{u.current=!0;try{_()}finally{u.current=!1}},q=()=>{l||g||C(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},j=_=>{if(_.key==="Escape"){_.preventDefault(),C(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),q())},N=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.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:N,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Me(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Me(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:j})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Me(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":g||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown: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:Me(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:Me(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>C(e.close),children:"×"})]})]})},ri=500,sa=({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(D=>D.toLowerCase().startsWith(B))},[e.current,n]),h=i.useMemo(()=>u.length>ri?u.slice(0,ri):u,[u]),g=u.length-h.length,C=h.length===0?-1:Math.min(o,h.length-1),q=B=>{c.current=!0;try{B()}finally{c.current=!1}},j=()=>{C<0||q(()=>e.commit(h[C]))},N=B=>{if(B.key==="Escape"){B.preventDefault(),q(e.close);return}if(B.key==="Enter"){B.preventDefault(),j();return}if(B.key==="ArrowDown"){B.preventDefault(),s(C+1);return}B.key==="ArrowUp"&&(B.preventDefault(),s(Math.max(C-1,0)))},_=B=>{c.current||B.relatedTarget instanceof Node&&B.currentTarget.contains(B.relatedTarget)||q(e.close)},Y=B=>`${l}-${B}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Me(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":C<0?void 0:Y(C),value:n,onChange:B=>{r(B.currentTarget.value),s(0)},onKeyDown:N}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Me(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Me(t,"listEmpty")}):h.map((B,D)=>K.jsx("div",{className:"aqsp-popover-option",id:Y(D),role:"option",tabIndex:-1,"aria-selected":D===C,"data-aqsp-list-option":B,onPointerDown:$=>$.preventDefault(),onClick:()=>q(()=>e.commit(B)),children:B},Y(D))),g>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Me(t,"listMore",g)}):null]})]})},la=({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":Me(t,"popoverClose"),onClick:e.close,children:"×"})]}),ia=({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=N=>{u.current=!0;try{N()}finally{u.current=!1}},g=()=>{s||h(()=>e.commit(r===""?null:r))},C=()=>{r!==n&&!s?g():h(e.close)},q=N=>{if(N.key==="Escape"){N.preventDefault(),e.rejected?h(e.close):C();return}N.key==="Enter"&&(N.ctrlKey||N.metaKey)&&!N.altKey&&!N.shiftKey&&(N.preventDefault(),g())},j=N=>{u.current||N.relatedTarget instanceof Node&&N.currentTarget.contains(N.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:Me(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:N=>o(N.currentTarget.value),onKeyDown:q}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Me(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:Me(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Me(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},ca=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),kt=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")}),oi=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],aa=Object.freeze({all:kt(oi),values:kt(["text"]),formats:kt(["format","borders","cf"]),formulas:kt(["text","formula"]),noBorders:kt(oi.filter(e=>e!=="borders")),columnWidths:kt(["sizes"]),validation:kt(["validation"]),conditionalFormats:kt(["cf"]),commentsAndNotes:kt(["note","comments"])}),si=Object.freeze({mode:"all"}),rs=Object.freeze({t:""}),li=Object.freeze({row:1<<30,col:1<<30}),Gh=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Zh=e=>e.t===""&&e.f===void 0,Jh=e=>e.length>1&&e.startsWith("="),Qh=(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}},ii=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,eg=(e,t,n,r)=>{const o=Jh(e),s=e===""?"0":tt(e);if(!o&&s===null)return null;const l=Gh[n];if(t.f!==void 0){const h=fr(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:ii(Number(s));const c=tt(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:ii(Qh(Number(s),u,n))},ci=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),tg=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:ci(e.start),end:ci(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}}}},ng=e=>{const t=fr(e,li),n=dr(t);let r="",o=0,s=!1;for(const l of n){const c=tg(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${jt(c)}`,o=l.end,s=!0)}return s?eo(`${r}${t.slice(o)}`,li):e},rg=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return rs;const o=r[n];return o===void 0?rs:o},og=e=>{const{rows:t,cols:n}=e,r=ac(ng);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=rg(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===rs)&&(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}},sg=(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,lg=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},ai=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const g of c)sg(g,t)?(h.push(lg(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},ui=new WeakMap,ua=e=>{const t=ui.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>ft(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:ft({...s,borders:void 0})),o={canonical:n,borderless:r};return ui.set(e,o),o},Xr=(e,t)=>t===void 0?void 0:e[t],ig=(e,t,n,r)=>{const o=ua(e);if(n){const h=Xr(o.canonical,t.fmt);return h===void 0?null:h}const s=Xr(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=ft(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},cg=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?eg(n.readText(),o,r,n):o.f===void 0?o.t:fr(o.f,n)},di=(e,t,n,r,o)=>{const s=aa[r.mode];if(r.skipBlanks===!0&&Zh(e))return null;const l={};let c=!1;if(s.text){const u=cg(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=ig(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Xr(ua(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=Xr(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},fi=(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}}),ag=["text/html","text/plain"],ug=(e,t,n)=>{if(e===0||t===0)return 0;const r=nt(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},dg=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,fg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,pg=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}}},pi=e=>{const t=e.clipboardData;return t??null},hg=(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}},gg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=hg(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},mg=(e,t,n,r,o)=>{const s=zn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=eo(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=Fn(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},da=(e,t)=>{const n=Ui(),r=kd(),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(mg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:gg(e.getConditionalFormats(),t)}},hi=e=>e.kind==="cut"?{...e.payload,...da(e.sourceAdapter,e.range)}:e.payload,wg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:ds(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Cg=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},yg=(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},bg=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return Ce({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Rg=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(D=>{const $=n.current;if($===null||D==="format"||D==="annotate")return;const P=r.current;P==="own"||P==="foreign"&&$.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const D=n.current;if(D===null)return;if(D.kind==="copy"){o();return}const $=t.current;$.repaintOverlay(),$.onClipChange?.({kind:"cut",range:D.range,foreign:D.sourceAdapter!==$.adapter})},[o]),c=i.useCallback((D,$,P)=>{const k=t.current;n.current={kind:D,range:$,clipId:P.clipId,sourceAdapter:k.adapter,payload:P},k.repaintOverlay(),k.onClipChange?.({kind:D,range:$,foreign:!1})},[]),u=i.useCallback(D=>{const $=t.current,P=$.adapter,k=nt(D),R={v:1,rows:k.rows,cols:k.cols,clipId:ds(),...da(P,D),wholeRows:Xi(D,P.colCount),wholeCols:Gi(D,P.rowCount)};if($.resize!==void 0){if(R.wholeCols){const S=[];for(let p=D.startCol;p<=D.endCol;p+=1)S.push(Math.min($.resize.colAxis.sizeOf(p),Ln));R.colWidths=S}if(R.wholeRows){const S=[];for(let p=D.startRow;p<=D.endRow;p+=1)S.push(Math.min($.resize.rowAxis.sizeOf(p),Ln));R.rowHeights=S}}return R},[]),h=i.useCallback((D,$)=>{const P=t.current,k=P.getSelection(),R=k.ranges[k.ranges.length-1],S=yt([R]);if(S>P.maxOperationCells)return D.preventDefault(),P.onOperationRejected?.($,S,"limit"),null;if($==="cut"&&Qn(P.adapter,R))return D.preventDefault(),P.rejectReadOnly({kind:"operation",op:"cut",cellCount:S}),null;k.ranges.length>1&&P.onCopyMultiRange?.();const p=u(R),m=Pi(p),y=pi(D);return y!==null&&(y.setData("text/plain",tr.serializeTsv(p.cells.map(L=>L.map(O=>O.t)))),y.setData("text/html",Oc(p,m)),y.setData(Kr,m)),D.preventDefault(),{payload:p,range:R}},[u]),g=i.useCallback((D,$)=>t.current.commitPaste(D,$)!==null,[]),C=i.useCallback((D,$,P)=>{const k=t.current;if(!P.sizes||k.resize===void 0)return;const{rowAxis:R,colAxis:S,resizeTracks:p}=k.resize,m=(y,L,O)=>{const v=is(L,O,null,{maxOperationCells:k.maxOperationCells,rowHiddenLimit:ss,axisKind:y});if(!v.ok){k.onOperationRejected?.("resize",v.count,v.reason);return}p(y,v.entries)};if(D.colWidths!==void 0){const y=[];for(let L=$.startCol;L<=$.endCol;L+=1)y.push({index:L,size:D.colWidths[(L-$.startCol)%D.cols]});m("col",S,y)}if(D.rowHeights!==void 0){const y=[];for(let L=$.startRow;L<=$.endRow;L+=1)y.push({index:L,size:D.rowHeights[(L-$.startRow)%D.rows]});m("row",R,y)}},[]),q=i.useCallback((D,$)=>{const P=t.current,k=P.adapter,R=D.payload,S={row:$.startRow,col:$.startCol},p=R.rows*R.cols+yt([D.range]);if(p>P.maxOperationCells)return P.onOperationRejected?.("paste",p,"limit"),"rejected";if(S.row+R.rows>k.rowCount||S.col+R.cols>k.colCount||D.range.endRow>=D.sourceAdapter.rowCount||D.range.endCol>=D.sourceAdapter.colCount)return P.onOperationRejected?.("paste",p,"bounds"),"rejected";const m=ts({rows:R.rows,cols:R.cols},Ce(S,S),S,k.rowCount,k.colCount);if(m!==null&&Qn(k,m))return P.rejectReadOnly({kind:"operation",op:"paste",cellCount:R.rows*R.cols}),"rejected";if(Qn(D.sourceAdapter,D.range))return P.rejectReadOnly({kind:"operation",op:"cut",cellCount:yt([D.range])}),"rejected";const y=hi(D),L=Vr(k),O=ai(y,L),v={row:0,col:0,readText:()=>zn(k,v.row,v.col).text,readFormat:()=>k.getCellFormat===void 0?void 0:k.getCellFormat(v.row,v.col)},{edits:F,tiles:b}=jl(O.cells,Ce(S,S),S,k.rowCount,k.colCount,(x,d,A)=>(v.row=D.range.startRow+(d-S.row),v.col=D.range.startCol+(A-S.col),di(x,O,v,si,L))),a=Vr(D.sourceAdapter),f=[];if(qt([D.range],x=>{f.push(yg(x.row,x.col,a))}),D.sourceAdapter===k){if(!g([...f,...F],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const x=P.commitPaste(F,{sameSheet:!1,conditionalFormats:fi(O.conditionalFormats,b)});if(x===null)return"rejected";try{D.sourceAdapter.applyEdits(f,{transaction:x,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){P.onEditRejected?.(d,{source:"paste"})}}return P.setSelection({ranges:[Ce(S,{row:S.row+y.rows-1,col:S.col+y.cols-1})],anchor:S,active:S}),"applied"},[g]),j=i.useCallback((D,$,P)=>{const k=t.current,R=k.adapter,S=X=>(k.onClipboardUnavailable?.(X),"rejected"),p=ji(D,$);if(p==="none")return $==="menu"?S("empty"):"empty";const m=k.getSelection(),y=m.ranges[m.ranges.length-1],L=P.transpose===!0,O=(X,Z)=>{const J=ug(L?Z:X,L?X:Z,y);return J>k.maxOperationCells?(k.onOperationRejected?.("paste",J,"limit"),!0):!1};let v,F=null;if(p==="aqsp"){const X=Gu(D,$);if(X===null)return S("unreadable");const Z=n.current;if(Z!==null&&X.clipId===Z.clipId&&(F=Z),F!==null&&F.kind==="cut"&&dg(P))return q(F,y);if(O(X.rows,X.cols))return"rejected";if(F!==null){if(F.kind==="cut"&&(F.range.endRow>=F.sourceAdapter.rowCount||F.range.endCol>=F.sourceAdapter.colCount))return k.onOperationRejected?.("paste",F.payload.rows*F.payload.cols,"bounds"),"rejected";v=hi(F)}else{const J=Zu(D,$);if(J===null)return S("unreadable");if(O(J.rows,J.cols))return"rejected";v=Cg(J)}}else if(p==="tsv"){const X=D.getData("text/plain"),Z=tr.measureTsv(X);if(O(Z.rows,Z.cols))return"rejected";v=wg(tr.parseTsv(X))}else{const X=D.getData("text/html"),Z=vd(X);if(Z.cols===0&&Z.rows>k.maxOperationCells)return k.onOperationRejected?.("paste",Z.rows,"limit"),"rejected";if(O(Z.rows,Z.cols))return"rejected";const J=Lc(X,p,k.formats===void 0?{}:{currency:k.formats.currency,locale:k.formats.locale},k.maxOperationCells);if(J.outcome==="none")return S("unreadable");if(J.outcome==="limit")return k.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(O(J.payload.rows,J.payload.cols))return"rejected";v=J.payload}const b=Vr(R),a=ai(L?og(v):v,b),f=aa[P.mode];if(fg(f)){const X=ts({rows:a.rows,cols:a.cols},y,m.active,R.rowCount,R.colCount);if(X!==null&&Qn(R,X))return k.rejectReadOnly({kind:"operation",op:"paste",cellCount:yt([X])}),"rejected"}const x={row:0,col:0,readText:()=>zn(R,x.row,x.col).text,readFormat:()=>R.getCellFormat===void 0?void 0:R.getCellFormat(x.row,x.col)},{edits:d,tiles:A}=jl(a.cells,y,m.active,R.rowCount,R.colCount,(X,Z,J)=>(x.row=Z,x.col=J,di(X,a,x,P,b))),E=bg(A,a.rows,a.cols,R.rowCount,R.colCount);if(E===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let X=0;for(const J of a.conditionalFormats)X+=J.ranges.length;const Z=A.length*X;if(Z>k.maxOperationCells)return k.onOperationRejected?.("paste",Z,"limit"),"rejected"}const T=f.cf?fi(a.conditionalFormats,A):[];if(d.length===0&&T.length===0)return C(a,E,f),"empty";r.current=F===null?"foreign":"own";let M=!1;try{M=g(d,{sameSheet:F!==null&&F.sourceAdapter===R,conditionalFormats:T})}finally{r.current="none"}if(!M)return"rejected";C(a,E,f);const V={row:E.startRow,col:E.startCol};return k.setSelection({ranges:[E],anchor:V,active:V}),"applied"},[q,g,C]),N=i.useCallback(async D=>{const $=L=>(t.current.onClipboardUnavailable?.(L),"rejected"),P=navigator;if(P.clipboard===void 0)return $("insecure-origin");let k;try{k=await P.clipboard.read({unsanitized:["text/html"]})}catch{return $("permission-denied")}if(k.length===0)return $("empty");const R=k[0],S=Array.from(R.types),p=new Map;try{for(const L of ag)S.includes(L)&&p.set(L,await(await R.getType(L)).text())}catch{return $("unreadable")}const m={types:S,getData:L=>{const O=p.get(L);if(O===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${L} was not materialised for the menu path`);return O}},y=t.current;return!y.enabled||y.isDragging()||y.isEditing()?"rejected":j(m,"menu",D)},[j]),_=i.useCallback(async D=>{const $=await N(D);return t.current.onPasteResolved?.($,"menu"),$},[N]),{enabled:Y,sinkRef:B}=e;return i.useEffect(()=>{const D=B.current;if(!Y||D===null)return;const $=S=>t.current.isDragging()?(S.preventDefault(),!0):!1,P=S=>{const p=t.current;if($(S)||p.isEditing())return;const m=h(S,"copy");m!==null&&c("copy",m.range,m.payload)},k=S=>{const p=t.current;if($(S)||p.isEditing())return;const m=h(S,"cut");m!==null&&c("cut",m.range,m.payload)},R=S=>{const p=t.current;if($(S)||p.isEditing())return;S.preventDefault();let m=si;const y=p.pendingPasteOptionsRef;y!==void 0&&y.current!==null&&(m=y.current,y.current=null);const L=pi(S);if(L===null)return;const O=j(pg(L),"event",m);p.onPasteResolved?.(O,"event")};return D.addEventListener("copy",P),D.addEventListener("cut",k),D.addEventListener("paste",R),()=>{D.removeEventListener("copy",P),D.removeEventListener("cut",k),D.removeEventListener("paste",R)}},[Y,B,h,c,j]),i.useMemo(()=>({getClip:()=>{const D=n.current;return D===null?null:{kind:D.kind,range:D.range,foreign:D.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},fa=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)}`)},pa=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}},gi=(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}`}`},ha=(e,t)=>{let n;if(e.exponent===null)n=gi(e.negative,e.digits,e.point+t);else{const r=gi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return tt(n)===null?null:n},vg=(e,t)=>{fa(t);const n=tt(e);return n===null?null:ha(pa(n),t)},kg=e=>{const t=tt(e);if(t!==null){const r=pa(t);return ha({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},ga=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)},Sg=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},ma=(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 Sg(r)?r:null},Eg=(e,t)=>{fa(t);const n=ga(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=ma(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},Ag=e=>{const t=ga(e),n=ma(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Xn=(e,t,n,r)=>{const o=yt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Mr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},zr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},mi={bold:{kind:"toggle",key:"bold"},italic:{kind:"toggle",key:"italic"},underline:{kind:"toggle",key:"underline"},strikethrough:{kind:"toggle",key:"strikethrough"},clearFormatting:{kind:"clear"},alignLeft:{kind:"patch",patch:{align:"left"}},alignCenter:{kind:"patch",patch:{align:"center"}},alignRight:{kind:"patch",patch:{align:"right"}},formatNumber:{kind:"value",value:"number"},formatTime:{kind:"value",value:"time"},formatDate:{kind:"value",value:"date"},formatCurrency:{kind:"value",value:"currency"},formatPercent:{kind:"value",value:"percent"},formatScientific:{kind:"value",value:"scientific"},bordersOuter:{kind:"borders",preset:"outer"},bordersClear:{kind:"borders",preset:"clear"},borderTop:{kind:"borders",preset:"top"},borderRight:{kind:"borders",preset:"right"},borderBottom:{kind:"borders",preset:"bottom"},borderLeft:{kind:"borders",preset:"left"},insertLink:{kind:"popover",popover:"link"},insertNote:{kind:"popover",popover:"note"},insertComment:{kind:"popover",popover:"comment"},openHyperlink:{kind:"openHyperlink"},openValidationList:{kind:"popover",popover:"list"},pasteSpecial:{kind:"pasteSpecial"},fillDown:{kind:"fill",direction:"down"},fillRight:{kind:"fill",direction:"right"},fillSelection:{kind:"fill",direction:"selection"},insertDate:{kind:"insertNow",unit:"date"},insertTime:{kind:"insertNow",unit:"time"},hideRows:{kind:"hide",axis:"row",hide:!0},hideColumns:{kind:"hide",axis:"col",hide:!0},unhideRows:{kind:"hide",axis:"row",hide:!1},unhideColumns:{kind:"hide",axis:"col",hide:!1},formatGeneral:{kind:"patch",patch:{value:null}},bordersAll:{kind:"borders",preset:"all"},pasteFormats:{kind:"paste",options:{mode:"formats"}},pasteFormulas:{kind:"paste",options:{mode:"formulas"}},pasteAdd:{kind:"paste",options:{mode:"all",operation:"add"}},pasteSubtract:{kind:"paste",options:{mode:"all",operation:"subtract"}},pasteMultiply:{kind:"paste",options:{mode:"all",operation:"multiply"}},pasteDivide:{kind:"paste",options:{mode:"all",operation:"divide"}},multiplyBy100:{kind:"calc",exponent:2},multiplyBy1000:{kind:"calc",exponent:3},divideBy100:{kind:"calc",exponent:-2},divideBy1000:{kind:"calc",exponent:-3},signReversal:{kind:"sign"},fillColorYellow:{kind:"color",key:"background",preset: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:zr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:zr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:zr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:zr.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"}},Og={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},lr=e=>e<10?`0${e}`:String(e),xg=e=>{const t=new Date(e);return`${t.getFullYear()}-${lr(t.getMonth()+1)}-${lr(t.getDate())}`},Tg=e=>{const t=new Date(e);return`${lr(t.getHours())}:${lr(t.getMinutes())}:${lr(t.getSeconds())}`},$g=(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),Lg=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Dg=e=>e===void 0||e.borders===void 0?{}:e.borders,Mg={top:1,right:2,bottom:4,left:8},zg={style:"thin",color:cs},Fg=(e,t)=>{if(e===void 0)return!1;const n=Xe(e);return n!==null&&n===Xe(t)},Ng=(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}}},Pg=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[Ce(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(!Xn("format",y,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"format",cellCount:yt(y)}),!1;const L=new Map,O=[],v=m.adapter.getCellFormat;for(const F of y)qt([F],b=>{const a=v===void 0?void 0:v(b.row,b.col),{bucket:f,patch:x}=p(b,F,a);let d=L.get(f);d===void 0&&(d=new Map,L.set(f,d));let A;d.has(a)?A=d.get(a):(A=us(a,x),d.set(a,A)),A!==a&&O.push({row:b.row,col:b.col,format:A===void 0?null:A})});return O.length===0?!0:m.commitEdits(O,{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=zg)=>{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:Mg[p];return o((L,O,v)=>{const F=$g(L,O)&y;return{bucket:F,patch:{borders:{...Dg(v),...Lg(F,m)}}}})},[s,o]),u=i.useCallback((p,m,y)=>{const L=Nc(t.current.adapter,p.row,p.col);for(const O of m)y.push(Pc(L,p,O))},[]),h=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Xn("fill",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;const L=[];if(p==="selection"){const v=y.active,F=[];qt(y.ranges,b=>{(b.row!==v.row||b.col!==v.col)&&F.push(b)}),L.push({source:v,targets:F})}else for(const v of y.ranges)if(p==="down"){const F=v.startRow===v.endRow;if(F&&v.startRow===0)continue;const b=F?v.startRow-1:v.startRow;for(let a=v.startCol;a<=v.endCol;a+=1){const f=[];for(let x=F?v.startRow:v.startRow+1;x<=v.endRow;x+=1)f.push({row:x,col:a});L.push({source:{row:b,col:a},targets:f})}}else{const F=v.startCol===v.endCol;if(F&&v.startCol===0)continue;const b=F?v.startCol-1:v.startCol;for(let a=v.startRow;a<=v.endRow;a+=1){const f=[];for(let x=F?v.startCol:v.startCol+1;x<=v.endCol;x+=1)f.push({row:a,col:x});L.push({source:{row:a,col:b},targets:f})}}for(const v of L)for(const F of v.targets)if(Ke(m.adapter,F.row,F.col)){let b=0;for(const a of L)b+=a.targets.length;return m.rejectReadOnly({kind:"operation",op:"fill",cellCount:b}),!1}const O=[];for(const v of L)u(v.source,v.targets,O);return O.length===0?!0:m.commitEdits(O,{source:"fill"})!==null},[u]),g=i.useCallback(()=>{const p=t.current,m=p.getSessionText();if(m===null)return!1;const y=p.getSelection();if(!Xn("fill",y.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(En(p.adapter,y.ranges))return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:yt(y.ranges)}),!1;const L=[];let O=!1;return qt(y.ranges,v=>{if(!O){if(!p.validateCommit(v,m).ok){O=!0;return}L.push({row:v.row,col:v.col,text:m})}}),O||p.commitEdits(L,{source:"fill"})===null?!1:(p.cancelEdit(),!0)},[]),C=i.useCallback(p=>{const m=t.current,y=m.getSelection();if(!Xn("calc",y.ranges,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y.ranges))return m.rejectReadOnly({kind:"operation",op:"calc",cellCount:yt(y.ranges)}),!1;const L=[],O=m.adapter;return qt(y.ranges,v=>{const F=O.getCellFormula===void 0?void 0:O.getCellFormula(v.row,v.col),b=F===void 0?p.text(O.getCellText(v.row,v.col)):p.formula(F);b!==null&&L.push({row:v.row,col:v.col,text:b})}),L.length===0?!0:m.commitEdits(L,{source:"calc"})!==null},[]),q=i.useCallback((p,m)=>{const y=t.current,L=p==="row"?y.rowAxis:y.colAxis,O=y.getSelection(),v=p==="row"?Math.floor(y.maxOperationCells/ls):y.maxOperationCells;let F=0;for(const d of O.ranges)F+=p==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(F>v)return y.onOperationRejected?.("resize",F,"limit"),!1;const b=new Set,a=[],f=m?0:p==="row"?y.defaultRowHeight:y.defaultColumnWidth;for(const d of O.ranges){const A=p==="row"?d.startRow:d.startCol,E=p==="row"?d.endRow:d.endCol;for(let T=A;T<=E;T+=1){if(b.has(T))continue;b.add(T),L.sizeOf(T)===0!==m&&a.push({index:T,size:f})}}const x=is(L,a,null,{maxOperationCells:y.maxOperationCells,rowHiddenLimit:ss,axisKind:p});return x.ok?(x.entries.length>0&&y.resizeTracks(p,x.entries),!0):(y.onOperationRejected?.("resize",x.count,x.reason),!1)},[]),j=i.useCallback(()=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)return;const m=p.getActive();return Fn(p.adapter.getCellHyperlink(m.row,m.col))},[]),N=i.useCallback(p=>{const m=t.current,y=m.adapter,L=mi[p],O=y.getCellFormat!==void 0,v=F=>m.popovers===void 0?!0:m.popovers[F]!==!1;switch(L.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return O;case"value":return O&&(L.value!=="currency"||m.formats!==void 0);case"popover":switch(L.popover){case"link":return y.getCellHyperlink!==void 0&&v("link");case"note":return y.getCellNote!==void 0&&v("note");case"comment":return y.getCellComments!==void 0&&v("comment");default:return y.getCellValidation!==void 0&&v("list")}case"openHyperlink":return y.getCellHyperlink!==void 0&&(m.onHyperlinkOpen!==void 0?j()!==void 0:v("link"));case"paste":return L.options.mode==="formats"?O:L.options.mode==="formulas"?y.getCellFormula!==void 0:!0;default:return!0}},[j]),_=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 L=m.getActive();if(!Ke(m.adapter,L.row,L.col))return!0;if(y==="list")return m.rejectReadOnly({kind:"edit",cell:L,editSession:"none"}),!1;let O;if(y==="link")O=j()!==void 0;else if(y==="note"){const v=m.adapter.getCellNote===void 0?void 0:m.adapter.getCellNote(L.row,L.col);O=v!==void 0&&v!==""}else{const v=m.adapter.getCellComments===void 0?void 0:m.adapter.getCellComments(L.row,L.col);O=v!==void 0&&v.length>0}return O?!0:(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[j]),Y=i.useCallback(p=>{const m=t.current;if(!N(p))return!1;const y=mi[p];if(!_(y))return!1;const L=m.isEditing();if(L&&!vs.has(p)&&!m.requestCommit())return!1;switch(y.kind){case"toggle":{const O=r(),v=O!==void 0&&O[y.key]===!0;return s({[y.key]:v?null:!0})?(l(p,!v),!0):!1}case"patch":return s(y.patch)?(l(p,null),!0):!1;case"clear":return s(Og)?(l(p,null),!0):!1;case"value":return s({value:Ng(y.value,m.formats)})?(l(p,null),!0):!1;case"borders":return c(y.preset)?(l(p,null),!0):!1;case"color":{const O=y.key==="background"?m.colors.fill:m.colors.font,v=y.preset!==null?y.preset:y.custom!==null&&y.custom<O.length?O[y.custom]:void 0;if(v===void 0)return!1;const F=r(),b=Fg(F===void 0?void 0:F[y.key],v);return s({[y.key]:b?null:v})?(l(p,!b),!0):!1}case"calc":return C({text:O=>vg(O,y.exponent),formula:O=>Eg(O,y.exponent)});case"sign":return C({text:kg,formula:Ag});case"fill":return L&&y.direction==="selection"?g():h(y.direction);case"popover":return m.openPopover(y.popover),!0;case"openHyperlink":{if(m.onHyperlinkOpen!==void 0){const O=j();return O===void 0?!1:(m.onHyperlinkOpen(O,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 O=y.unit==="date"?xg(m.now()):Tg(m.now());if(L)return m.insertAtCaret(O),!0;const v=m.getActive();return Ke(m.adapter,v.row,v.col)?(m.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1):m.validateCommit(v,O).ok?m.commitEdits([{row:v.row,col:v.col,text:O}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return q(y.axis,y.hide);default:{const O=m.getHighlight();switch(y.target){case"row":return m.setHighlight({...O,row:!O.row}),!0;case"column":return m.setHighlight({...O,column:!O.column}),!0;case"both":{const v=O.row&&O.column;return m.setHighlight({...O,row:!v,column:!v}),!0}default:return m.setHighlight({...O,intersection:!O.intersection}),!0}}}},[N,_,j,r,s,l,c,C,h,g,q]),B=i.useCallback(()=>{const p=t.current;return!(p.isEditing()&&!p.requestCommit())},[]),D=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(!B())return!1;const L=m.getActive();return Ke(m.adapter,L.row,L.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:L.row,col:L.col,hyperlink:y}],{source:"annotate"})!==null},[B]),$=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!B())return!1;const y=m.getActive();return Ke(m.adapter,y.row,y.col)?(m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):m.commitEdits([{row:y.row,col:y.col,note:p}],{source:"annotate"})!==null},[B]),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(!B())return!1;const L=m.getActive();if(Ke(m.adapter,L.row,L.col))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const O=y(L.row,L.col),v=O===void 0?[p]:[...O,p];return m.commitEdits([{row:L.row,col:L.col,comments:v}],{source:"annotate"})!==null},[B]),k=i.useCallback(p=>{const m=t.current;if(m.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!B())return!1;const y=m.getSelection().ranges;if(!Xn("annotate",y,m.maxOperationCells,m.onOperationRejected))return!1;if(En(m.adapter,y))return m.rejectReadOnly({kind:"operation",op:"annotate",cellCount:yt(y)}),!1;const L=[];return qt(y,O=>{L.push({row:O.row,col:O.col,validation:p})}),m.commitEdits(L,{source:"annotate"})!==null},[B]),R=i.useCallback(p=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(p)},[s]),S=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:R,setBorders:S,setHyperlink:D,setNote:$,addComment:P,setValidation:k,isCommandAvailable:N}),[Y,R,S,D,$,P,k,N])},Fr="data-aqsp-pointing",qg=(e,t)=>{const n=hc(e,t);return n!==null&&"insertAt"in n},_g=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},jg=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(Et),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=hc(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 x=f.resolveEditPaint(a),d=x===null?Et:x;d!==Et&&Object.assign(b.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),j=i.useCallback(b=>{_g(b,Object.keys(h.current.style)),h.current=Et;const a=t.current.editPaintRef;a!==void 0&&(a.current=Et)},[]),N=i.useCallback(b=>{const a=t.current,f=n.current;if(f===null)return!0;const x=()=>{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,E=zn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
+
`),T=A===E;let M;if(T)M=!0;else if(Ke(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:b.onReject==="keep"?"kept":"discarded"}),M=!1;else{const V={source:"edit",editSession:b.onReject==="keep"?"kept":"discarded"};M=(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(!M)return b.onReject==="discard"&&(x(),a.rearmSink()),!1}return x(),b.rearm&&a.rearmSink(),!0},[j]),_=i.useCallback((b,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const x=f.sinkRef.current;if(x===null)return;const d=f.getActive();if(Ke(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),b==="edit"){const{text:E,isFormula:T}=zn(f.adapter,d.row,d.col);x.value=E;const M=a===void 0||T?E.length:Math.min(a,E.length);x.setSelectionRange(M,M)}else x.value="";const A=f.resolveEditAlign(d);A!==null&&(x.style.textAlign=A),q(x,d),c.current=!1,u.current=null,n.current={cell:d,mode:b},o(!0)},[q]),Y=i.useCallback(()=>{N({rearm:!0,commit:!1})},[N]),B=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 N({rearm:!1,commit:!0,onReject:"keep"})?(b.focusSink(),b.rearmSink(),!0):(b.focusSink(),!1)}return N({rearm:!0,commit:!0,onReject:"keep"})},[N]),D=i.useCallback(()=>g()!==null,[g]),$=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=pc(b.sink.value,b.sink.selectionStart);if(f===null)return null;const x=f.token,d=u.current;switch(x.kind){case"cell":{const A={row:x.row,col:x.col};return u.current=A,{origin:A,cursor:A,axis:"cells"}}case"range":{const A=d!==null&&(d.row===x.start.row||d.row===x.end.row)&&(d.col===x.start.col||d.col===x.end.col)?{row:d.row,col:d.col}:{row:x.start.row,col:x.start.col};return u.current=A,{origin:A,cursor:{row:A.row===x.start.row?x.end.row:x.start.row,col:A.col===x.start.col?x.end.col:x.start.col},axis:"cells"}}case"column":{const A=d!==null&&(d.col===x.start.col||d.col===x.end.col)?d.col:x.start.col,E={row:a.cell.row,col:A};return u.current=E,{origin:E,cursor:{row:a.cell.row,col:A===x.start.col?x.end.col:x.start.col},axis:"columns"}}case"row":{const A=d!==null&&(d.row===x.start.row||d.row===x.end.row)?d.row:x.start.row,E={row:A,col:a.cell.col};return u.current=E,{origin:E,cursor:{row:A===x.start.row?x.end.row:x.start.row,col:a.cell.col},axis:"rows"}}}},[g]),k=i.useCallback((b,a)=>{const f=g();if(f===null)return;const x=nf(b,a),{sink:d}=f,[A,E]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],T=d.value;d.value=`${T.slice(0,A)}${x}${T.slice(E)}`;const M=A+x.length;d.setSelectionRange(M,M),"row"in b&&(u.current={row:b.row,col:b.col}),C()},[g,C]),R=i.useCallback(()=>{const b=t.current.sinkRef.current;return b===null?null:{value:b.value,selectionStart:b.selectionStart,selectionEnd:b.selectionEnd}},[]),S=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=pf(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,x=a.selectionEnd;a.value=`${a.value.slice(0,f)}${b}${a.value.slice(x)}`;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},[]),L=i.useCallback(()=>n.current===null?null:n.current.cell,[]),O=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:v,sinkRef:F}=e;return i.useEffect(()=>{const b=F.current;if(!v||b===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},x=E=>{const T=t.current;if(l.current||n.current===null)return;const M=T.rootRef.current,V=E.relatedTarget;M!==null&&V instanceof Node&&M.contains(V)||N({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const E=t.current;u.current=null,E.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&qg(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",x),b.addEventListener("input",d),document.addEventListener("selectionchange",A),()=>{b.removeEventListener("compositionstart",a),b.removeEventListener("compositionend",f),b.removeEventListener("focusout",x),b.removeEventListener("input",d),document.removeEventListener("selectionchange",A)}},[v,F,N,C]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:B,cancelEdit:Y,startEdit:_,getPointing:D,togglePointingArm:$,getReferenceCursor:P,insertReference:k,captureSink:R,restoreSink:S,cycleAnchorAtCaret:p,insertAtCaret:m,getSessionText:y,getSessionCell:L,refreshPaint:O,editing:r}),[B,Y,_,D,$,P,k,R,S,p,m,y,L,O,r])},Ig=(e,t,n)=>{const r=new Ge.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},Hg=(e,t,n)=>{const{tree:r,initialHidden:o}=Ig(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}},It=(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)},Tn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:It(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=It(e,o,1);return r},wi=(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=Hg(e,t,r)),o.current.model},$n=256,qo=256,Bg=2**32,Vg=4096,wa=Object.freeze([]),Ca=["background","color","bold","italic","underline","strikethrough"],ya=(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>=Vg&&e.clear(),e.set(t,n),n),ba=e=>(ya(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Ra=(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},Wg=(e,t,n)=>{const r=Math.floor(t/$n),o=Math.floor(n/qo),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*$n,u=o*qo,h=[];for(const g of e.rules)Ra(g.ranges,c,c+$n-1,u,u+qo-1)&&h.push(g);return Ht(e.buckets,s,h.length===0?wa:h)},Kg=(e,t,n)=>{const r=Math.floor(t/$n),o=r*Bg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Wg(e,t,n),c=r*$n,u=[];for(const h of l)Ra(h.ranges,c,c+$n-1,n,n)&&u.push(h);return Ht(e.columns,o,u.length===0?wa:u)},Yg=(e,t)=>{for(const n of e)if(cn(n,t))return!0;return!1},Ss=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Nr=(e,t)=>e<t?-1:e>t?1:0,Ci=(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}},yi=new WeakMap,os=e=>e===null?null:Number(e),Ug=e=>{const t=yi.get(e);if(t!==void 0)return t;const n=e.b,r={a:os(tt(e.a)),b:n===void 0?null:os(tt(n))};return yi.set(e,r),r},va=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Ht(e.numbers,r,os(tt(n())))},Xg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Ug(e),l=va(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Ci(e.op,Nr(l,s.a),c===null?null:Nr(l,c));const u=n(),h=e.b;return Ci(e.op,Nr(u,e.a),h===void 0?null:Nr(u,h))},Gg=(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}},_o=e=>{const t=Xe(e);if(t===null)return null;const n=r=>Number.parseInt(t.slice(r,r+2),16);return[n(1),n(3),n(5),t.length===9?n(7):255]},Pr=e=>e.toString(16).padStart(2,"0"),jo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Pr(r(0))}${Pr(r(1))}${Pr(r(2))}`,s=r(3);return s===255?o:`${o}${Pr(s)}`},Io=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Zg=(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=_o(t.color),u=_o(r.color);const h=n===void 0?void 0:_o(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?jo(c,h,Io(e,s,C)):jo(h,u,Io(e,C,l))}return jo(c,u,Io(e,s,l))},Jg=(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})},Qg=(e,t,n,r,o,s)=>{const l=va(s,n,r);if(l===null)return null;const c=Jg(e,t,o,s);return c===null?null:Zg(l,t.min,t.mid,t.max,c)},em=(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},tm=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Xg(s,t,n,o)?e.style:null;case"text":return Gg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Qg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return em(e,s,t,r,o)?e.style:null;default:return null}},bi=(e,t)=>us(e,t),nm=(e,t,n)=>{e[t]=n},rm=(e,t)=>{let n=e;for(const r of Ca)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),nm(n,r,t[r]));return n},om=e=>{let t="";for(const n of Ca){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Ri=new WeakMap,sm=Object.freeze({}),lm=e=>{const t=e===void 0?sm:e,n=Ri.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Ri.set(t,r),r},im=(e,t,n)=>{const r=lm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=bi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=om(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=bi(e,t);return l!==void 0&&Ht(r.byKey,o,l),l},Es=(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=Kg(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(!Yg(C.ranges,u))continue;const q=tm(C,u,s,e,n);if(q!==null){if(q!==C.style&&(g=!1),h===null)h=q;else{const j=rm(h,q);j!==h&&(g=!1,h=j)}if(C.stopIfTrue===!0)break}}return h===null?l:im(l,h,g)},vi=new WeakMap,cm=e=>{ya(e,"widthRelevantRules");const t=vi.get(e);if(t!==void 0)return t;const n=e.filter(o=>o.style.bold!==void 0||o.style.italic!==void 0||o.stopIfTrue===!0),r=n.length===e.length?e:n;return vi.set(e,r),r},am=({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},um=i.memo(am),dm=Object.freeze({left:Object.freeze({justifyContent:nr("left")}),center:Object.freeze({justifyContent:nr("center")}),right:Object.freeze({justifyContent:nr("right")})}),fm=4096,ki=new WeakMap,qr=new Map,pm=(e,t)=>{if(e===null)return dm[t];let n=ki.get(e);n===void 0&&(n={},ki.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:nr(t)},s=JSON.stringify(o);let l=qr.get(s);return l===void 0&&(qr.size>=fm&&qr.clear(),l=Object.freeze(o),qr.set(s,l)),n[t]=l,l},hm=Ss(),gm=(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},mm=(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=Br(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const g=Es(e,r===null?null:r.indexRef.current,r===null?hm:r.memoRef.current,o,s,l);h=g===void 0?void 0:g.value;const C=Dc(g,l),q=It(n,s,1),j=It(t,o,1),N=Md(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);N!==null&&Object.assign(c,N.attrs),c["data-aqsp-align"]=C,u=pm(N,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&&Fn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const g=e.getCellValidation(o,s);g!==void 0&&_h(g,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},wm=({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:N,focusSink:_,isEditing:Y,requestCommit:B,testId:D,__onCellRender:$,__maxRenderedCells:P,cfIndexRef:k,cfMemoRef:R,isPointing:S,tapScrollCircleOptions:p,overscanRows:m,overscanCols:y,background:L,onRenderTruncated:O,locale:v,scrollLabels:F})=>{const b=i.useRef(null),a=s??b;if(k===void 0!=(R===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const f=i.useMemo(()=>k===void 0||R===void 0?null:{indexRef:k,memoRef:R},[k,R]),x=i.useCallback(()=>r.get().editVersion,[r]),d=i.useCallback(ce=>r.subscribeCoalesced(ce),[r]),E=i.useSyncExternalStore(d,x,x)+(l??0),T=i.useCallback(ce=>t.sizeOf(ce),[t]),M=i.useCallback(ce=>n.sizeOf(ce),[n]),V=i.useCallback((ce,ve)=>e.getCellText(ce,ve),[e]),X=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),Z=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),J=i.useMemo(()=>({width:_e.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:p}),[p]),ne=i.useRef({row:-1,col:-1,value:void 0}),ie=i.useCallback((ce,ve)=>{const Le={role:"gridcell","aria-rowindex":ce+1,"aria-colindex":ve+1,"data-aqsp-cell":"","data-row":ce,"data-col":ve,className:"aqsp-cell",...Ke(e,ce,ve)?{"aria-readonly":"true","data-aqsp-readonly":""}:{}},Ne=qp(e,ce,ve),je=Ne===null?Le:{...Le,...Ne},qe=mm(e,t,n,f,ce,ve),bt=ne.current;return bt.row=ce,bt.col=ve,bt.value=qe===null?void 0:qe.value,qe===null?je:qe.style===null?{...je,...qe.attrs}:{...je,...qe.attrs,style:qe.style}},[e,t,n,f]),se=i.useCallback(ce=>({role:"row","aria-rowindex":ce+1,"data-aqsp-row":ce,"data-aqsp-cells":"",className:"aqsp-row"}),[]),ze=i.useCallback((ce,ve,Le)=>{let Ne=ce;return e.getCellFormat!==void 0&&(Ne=Dn(ce,gm(ne.current,ve,Le))),K.jsx(um,{row:ve,col:Le,text:ce,display:Ne,renderCell:q,__onCellRender:$})},[E,q,$,e]);return K.jsx("div",{ref:a,className:"aqsp-body","data-aqsp-body":"","data-testid":D?`${D}-body`:void 0,onPointerDownCapture:ce=>{if(!(ce.target instanceof Element&&ce.target.closest("[data-aqsp-cells]")!==null)&&ce.pointerType==="mouse"){if(ce.button!==0){ce.preventDefault();return}if(ce.preventDefault(),S?.()===!0){ce.stopPropagation(),_();return}if(Y()&&!B()){ce.stopPropagation(),_();return}_()}},children:K.jsx(Ge.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:g,frozenTrailingRows:C,getRowHeight:T,getColWidth:M,getCell:V,getCellProps:ie,getRowProps:se,contentProps:X,behaviorOptions:Z,scrollBarOptions:J,overscanRows:m,overscanCols:y,background:L,onRenderTruncated:O,__maxRenderedCells:P,locale:v,labels:F,callbackThrottleMs:0,onScroll:j,onRangeChange:N,testId:D,children:ze})})},Cm=i.memo(wm),An=6,et=3,Gr=(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:et});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=It(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-An,length:et}),r.push({kind:"unhide",index:s+1,start:c-et,length:et})):l>=2*An?n.push({kind:"resize",index:s,start:c-An,length:An}):n.push({kind:"resize",index:s,start:c-et,length:et})}return[...n,...r]},ka=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:et}),n.push({kind:"resize",index:c,start:h+et,length:et})):u>=2*An?n.push({kind:"resize",index:c,start:h,length:An}):n.push({kind:"resize",index:c,start:h,length:et})}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-et,length:et}),[...n.reverse(),...r]},ym=({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=Ge.useWheelBridge(o),N=i.useCallback(d=>(s.current=d,j(d)),[s,j]),_=i.useCallback(()=>{const{colStart:d,colEnd:A,colVersion:E}=e.get();return`${d}:${A}:${E}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,_,_);const{colStart:B,colEnd:D}=e.get(),$=t.count===0?0:t.offsetOf(Math.min(B,t.count-1));i.useLayoutEffect(()=>{c.current=$,u()},[$,c,u]);const P=d=>h.some(A=>d>=A.startCol&&d<=A.endCol),k=Math.min(Math.max(0,n),t.count),R=Zc(t,k),S=k>0?Tn(t,0,k-1):[],p=Math.min(Math.max(0,r),t.count-k),m=Qc(t,p),y=t.totalSize()-m,L=p>0?Tn(t,t.count-p,t.count-1):[],O=Tn(t,Math.max(B,k),Math.min(D,Math.max(0,t.count-1)-p)),v=[];for(const d of O)v.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)-$,width:t.sizeOf(d)},children:sr(d)},d));const F=g?Gr(t,O):null,b=F===null?null:F.filter(d=>!(d.kind==="unhide"&&d.index<k&&R>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=g&&k>0?Gr(t,S):null,f=g&&p>0?ka(t,L):null,x=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[v,b?.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}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-$,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:N,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:k===0&&p===0?x:K.jsxs(K.Fragment,{children:[S.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:sr(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:R,right:p>0?`calc(${_e.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${m}px, max(0px, 100% - ${_e.SPREADSHEET_SCROLLBAR_SIZE_PX+R}px)))`:void 0},children:[x,k>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(${R}px, calc(100% - ${m+_e.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:_e.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:m},children:[L.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:sr(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]})})},bm=({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=Ge.useWheelBridge(n),N=i.useCallback(d=>(r.current=d,j(d)),[r,j]),_=d=>o.some(A=>d>=A.startRow&&d<=A.endRow),Y=i.useCallback(()=>{const{rowStart:d,rowEnd:A,rowGeomVersion:E}=e.get();return`${d}:${A}:${E}`},[e]),B=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(B,Y,Y);const{rowStart:D,rowEnd:$}=e.get(),P=t.count===0?0:t.offsetOf(Math.min(D,t.count-1));i.useLayoutEffect(()=>{l.current=P,c()},[P,l,c]);const k=Math.min(Math.max(0,h),t.count),R=Jc(t,k),S=k>0?Tn(t,0,k-1):[],p=Math.min(Math.max(0,g),t.count-k),m=ea(t,p),y=t.totalSize()-m,L=p>0?Tn(t,t.count-p,t.count-1):[],O=Tn(t,Math.max(D,k),Math.min($,Math.max(0,t.count-1)-p)),v=[];for(const d of O)v.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-P,height:t.sizeOf(d)},children:d+1},d));const F=u?Gr(t,O):null,b=F===null?null:F.filter(d=>!(d.kind==="unhide"&&d.index<k&&R>0||d.kind==="unhide"&&d.index>=t.count-p&&m>0)),a=u&&k>0?Gr(t,S):null,f=u&&p>0?ka(t,L):null,x=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[v,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:N,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:_e.SPREADSHEET_SCROLLBAR_SIZE_PX},children:k===0&&p===0?x:K.jsxs(K.Fragment,{children:[S.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:R,bottom:p>0?`calc(min(${m}px, max(0px, 100% - ${R}px)))`:void 0},children:[x,k>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(${R}px, calc(100% - ${m}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:m},children:[L.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-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]})})},Rm=9,vm=4,km=(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},Si=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Sm=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(k=>s.current!==null?k.pointerId===s.current:k.pointerType==="mouse",[]),q=i.useCallback(()=>{const k=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),k.writeResizeGuide(null);const R=g.current;R!==null&&(window.removeEventListener("pointermove",R.move),window.removeEventListener("pointerup",R.up),g.current=null);const S=c.current;S!==null&&s.current!==null&&S.hasPointerCapture?.(s.current)&&S.releasePointerCapture(s.current),c.current=null,s.current=null,k.repaintOverlay()},[]),j=i.useCallback((k,R)=>{const S=t.current;return k==="col"?R.startRow===0&&R.endRow===S.rowAxis.count-1:R.startCol===0&&R.endCol===S.colAxis.count-1},[]),N=i.useCallback((k,R)=>{const S=t.current,p=S.getSelection().ranges.filter(v=>j(k,v));if(!p.some(v=>k==="col"?R>=v.startCol&&R<=v.endCol:R>=v.startRow&&R<=v.endRow))return[R];const y=p.reduce((v,F)=>v+(k==="col"?F.endCol-F.startCol+1:F.endRow-F.startRow+1),0),L=k==="row"?Math.floor(S.maxOperationCells/ls):S.maxOperationCells;if(y>L)return S.onOperationRejected?.("resize",y,"limit"),null;const O=new Set;for(const v of p){const F=k==="col"?v.startCol:v.startRow,b=k==="col"?v.endCol:v.endRow;for(let a=F;a<=b;a+=1)O.add(a)}return[...O]},[j]),_=i.useCallback((k,R,S)=>{const p=t.current,m=k==="col"?p.colAxis:p.rowAxis,y=is(m,R,S,{maxOperationCells:p.maxOperationCells,rowHiddenLimit:ss,axisKind:k});if(!y.ok){p.onOperationRejected?.("resize",y.count,y.reason);return}p.resizeTracks(k,y.entries)},[]),Y=i.useCallback((k,R)=>{if(R===k.initialSize)return;const S=k.kind==="unhide"?[k.index]:N(k.axis,k.index);S!==null&&_(k.axis,S.map(p=>({index:p,size:R})),k.index)},[N,_]),B=i.useCallback((k,R)=>{const S=t.current,p=N("col",R);if(p===null)return;const m=S.handleRef.current,y=m===null?null:m.getFrozenSize(),L=y===null?0:y.rows,O=y===null?0:y.trailingRows,{rowStart:v,rowEnd:F}=S.viewStore.get(),b=Math.min(F,S.rowAxis.count-1),a=[],f=new Set,x=se=>{!f.has(se)&&S.rowAxis.sizeOf(se)>0&&(f.add(se),a.push(se))};for(let se=0;se<L;se+=1)x(se);for(let se=v;se<=b;se+=1)x(se);for(let se=S.rowAxis.count-O;se<S.rowAxis.count;se+=1)x(se);if(a.length===0)return;const d=p.length*a.length,A=Math.floor(S.maxOperationCells/vm);if(d>A){S.onOperationRejected?.("resize",d,"limit");return}const E=document.createElement("canvas").getContext("2d");if(E===null)return;const T=getComputedStyle(k),M=`${T.fontStyle} ${T.fontWeight} ${T.fontSize} ${T.fontFamily}`,V=S.adapter.getConditionalFormats===void 0?null:cm(S.adapter.getConditionalFormats()),X=Ss(),Z=new WeakMap,J=new Map;for(const se of p){const ze=V===null?null:ba(V.filter(ce=>ce.ranges.some(ve=>se>=ve.startCol&&se<=ve.endCol)));for(const ce of a){const ve=S.adapter.getCellText(ce,se),Le=S.adapter.getCellFormat===void 0?void 0:Es(S.adapter,ze,X,ce,se,()=>ve),Ne=Le===void 0?M:km(Le,Z,T),je=Dn(ve,Le===void 0?void 0:Le.value),qe=J.get(Ne);qe===void 0?J.set(Ne,[{col:se,text:je}]):qe.push({col:se,text:je})}}const ne=new Map;for(const[se,ze]of J){E.font=se;for(const ce of ze){const ve=E.measureText(ce.text).width,Le=ne.get(ce.col);(Le===void 0||ve>Le)&&ne.set(ce.col,ve)}}const ie=[];for(const se of p){const ze=ne.get(se);ze!==void 0&&ze>0&&ie.push({index:se,size:Math.ceil(ze)+Rm})}ie.length!==0&&_("col",ie,R)},[N,_]),{enabled:D,colBandRef:$,rowBandRef:P}=e;return i.useEffect(()=>{const k=$.current,R=P.current;if(!D||k===null||R===null)return;const S=A=>A==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",p=(A,E)=>{if(!(E instanceof Element))return null;const T=E.closest(S(A));if(T===null)return null;const M=T.hasAttribute("data-aqsp-unhide"),V=Number(T.getAttribute(M?"data-aqsp-unhide":A==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),X=T.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:M?"unhide":"resize",index:V,anchor:X}},m=A=>{if(!(n.current&&C(A)))return;const E=r.current;if(E===null)return;const T=(E.axis==="col"?A.clientX-E.startClientX:A.clientY-E.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(E.anchor==="trailing"?E.initialSize-T:E.initialSize+T)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const M=r.current;if(!n.current||M===null)return;const V=t.current,X=M.axis==="col"?V.colAxis:V.rowAxis;V.writeResizeGuide({axis:M.axis,position:Si(M,X,o.current),anchor:M.anchor})}))},y=()=>{const A=r.current,E=o.current;q(),A!==null&&Y(A,E)},L=A=>{m(A),n.current&&C(A)&&(l.current&1)!==0&&(A.buttons&1)===0&&y()},O=A=>{A.button!==0||!(n.current&&C(A))||y()},v=(A,E)=>T=>{const M=t.current;if(h.current=T.pointerType,T.pointerType!=="mouse")return;if(T.button!==0){T.preventDefault();return}const V=p(A,T.target);if(V===null)return;if(T.stopPropagation(),T.preventDefault(),M.isPointing()){M.focusSink();return}if(M.isEditing()&&!M.requestCommit()){M.focusSink();return}M.focusSink();const X=A==="col"?M.colAxis:M.rowAxis,Z={axis:A,kind:V.kind,index:V.index,anchor:V.anchor,initialSize:X.sizeOf(V.index),startClientX:T.clientX,startClientY:T.clientY};r.current=Z,o.current=Z.initialSize,l.current=T.buttons,n.current=!0,M.repaintOverlay(),s.current=T.pointerId,c.current=E;try{E.setPointerCapture(T.pointerId)}catch{s.current=null}const J=L,ne=O;g.current={move:J,up:ne},window.addEventListener("pointermove",J),window.addEventListener("pointerup",ne),M.writeResizeGuide({axis:A,position:Si(Z,X,o.current),anchor:Z.anchor})},F=(A,E)=>T=>{const M=t.current;if(h.current!=="mouse")return;const V=E.getRootNode(),X=V instanceof ShadowRoot?V:E.ownerDocument,Z=T.target instanceof Element&&T.target.closest(S(A))!==null?T.target:typeof X.elementFromPoint=="function"?X.elementFromPoint(T.clientX,T.clientY):null,J=p(A,Z);if(J!==null){if(T.stopPropagation(),M.isEditing()){M.focusSink();return}if(J.kind==="unhide"){_(A,[{index:J.index,size:A==="col"?M.defaultColumnWidth:M.defaultRowHeight}],null);return}if(M.autofitEnabled){if(A==="row"){const ne=N("row",J.index);ne!==null&&_("row",ne.map(ie=>({index:ie,size:M.defaultRowHeight})),J.index);return}B(E,J.index)}}},b=A=>{!n.current||s.current===null||A.pointerId!==s.current||q()},a=v("col",k),f=v("row",R),x=F("col",k),d=F("row",R);return k.addEventListener("pointerdown",a,{capture:!0}),R.addEventListener("pointerdown",f,{capture:!0}),k.addEventListener("dblclick",x),R.addEventListener("dblclick",d),k.addEventListener("lostpointercapture",b),R.addEventListener("lostpointercapture",b),()=>{k.removeEventListener("pointerdown",a,{capture:!0}),R.removeEventListener("pointerdown",f,{capture:!0}),k.removeEventListener("dblclick",x),R.removeEventListener("dblclick",d),k.removeEventListener("lostpointercapture",b),R.removeEventListener("lostpointercapture",b),q()}},[D,$,P,C,q,Y,_,N,B]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&q()},cancelDrag:q}),[q])},As=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Em=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>As(n,t.ranges[r]))&&Ot(e.anchor,t.anchor)&&Ot(e.active,t.active),Am=(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:Ce(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},Om=(e,t)=>{const n=e.ranges[e.ranges.length-1];return As(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},ar=(e,t,n)=>n.extend?rn(e,t):n.append?{ranges:[...e.ranges,Ce(t,t)],anchor:t,active:t}:e.ranges.length===1&&Ot(e.anchor,t)&&Ot(e.active,t)&&As(e.ranges[0],Ce(t,t))?e:{ranges:[Ce(t,t)],anchor:t,active:t},xm=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),rn=(e,t)=>{const n=Om(e,Ce(e.anchor,t));return n.ranges.some(r=>cn(r,n.active))?n:{...n,active:xm(n.active,n.ranges[n.ranges.length-1])}},Sa=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(Ce({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Ce({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Ce({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Ce({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Ce(n,n)],anchor:n,active:n};const s=o.findIndex(c=>cn(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},Tm=(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}}},Ea=(e,t)=>{const n=e.ranges.findIndex(o=>cn(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=Tm(e.ranges,r.rangeIndex,r.cell,t),!Ot(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},St=24,Ei=32,Zr=4,bn=({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 N=u.current,_=e.current,Y=g.current;if(N===null||_===null||Y===null){c.current=null;return}const{clientX:B,clientY:D}=N.getPointerPosition(),$=l.current,P=(B-Y.left)/$,k=(D-Y.top)/$,R=_.getViewportSize(),S=R.width,p=R.height;if(S<=0||p<=0){c.current=requestAnimationFrame(q);return}const m=b=>Math.min(Ei,Math.ceil(b/St*Ei));let y=0,L=0;if(s!=="x"){const b=_.getFrozenSize(),a=b.trailingVisibleHeight;k>p-a-St?N.anchorRow!==void 0&&b.trailingRows>0&&N.anchorRow>=t.count-b.trailingRows&&a>0&&k>=p-a||(y=m(k-(p-a-St))):k<b.height+St&&(N.anchorRow!==void 0&&N.anchorRow<b.rows&&b.height>0&&k<b.height||(y=-m(b.height+St-k)))}if(s!=="y"){const b=_.getFrozenSize(),a=b.trailingVisibleWidth;P>S-a-St?N.anchorCol!==void 0&&b.trailingCols>0&&N.anchorCol>=n.count-b.trailingCols&&a>0&&P>=S-a||(L=m(P-(S-a-St))):P<b.width+St&&(N.anchorCol!==void 0&&N.anchorCol<b.cols&&b.width>0&&P<b.width||(L=-m(b.width+St-P)))}const O=L!==0||y!==0?_.scrollBy({x:L!==0?L:void 0,y:y!==0?y:void 0}):_.getScrollPosition(),v=O.y,F=O.x;if(v>=0&&F>=0&&t.totalSize()>0&&n.totalSize()>0){const b=_.getFrozenSize(),a=Vt({row:gr(t,k,{scroll:v,frozenSize:b.height,trailingSize:b.trailingHeight,extent:R.height}),col:hr(n,P,{scroll:F,frozenSize:b.width,trailingSize:b.trailingWidth,extent:R.width})},t.count,n.count),f=h.current;(y!==0||L!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(N.buildRange(a)))}c.current=requestAnimationFrame(q)},[e,t,n,s,o]),j=i.useCallback(N=>{C(),u.current=N,g.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(q)},[C,q,r]);return i.useEffect(()=>{const N=()=>{document.visibilityState==="hidden"&&C()};return document.addEventListener("visibilitychange",N),()=>{document.removeEventListener("visibilitychange",N),C()}},[C]),i.useMemo(()=>({start:j,stop:C}),[j,C])},Ai=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((R,S)=>{const{axis:p,mainAxis:m,handleRef:y,zoomRef:L}=t.current,O=s.current;if(O===null||m.totalSize()===0)return null;const v=L.current,F=y.current;if(F===null)return null;if(p==="col"){const x=F.getScrollPosition().x;if(x<0)return null;const d=F.getFrozenSize(),A=F.getViewportSize();return Math.min(Math.max(hr(m,(R-O.left)/v,{scroll:x,frozenSize:d.width,trailingSize:d.trailingWidth,extent:A.width}),0),m.count-1)}const b=F.getScrollPosition().y;if(b<0)return null;const a=F.getFrozenSize(),f=F.getViewportSize();return Math.min(Math.max(gr(m,(S-O.top)/v,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),m.count-1)},[]),N=i.useCallback((R,S)=>{const{axis:p,crossCount:m}=t.current;return p==="col"?{press:{row:0,col:R},extend:{row:m-1,col:S}}:{press:{row:R,col:0},extend:{row:S,col:m-1}}},[]),_=i.useCallback((R,S)=>{const{axis:p,crossCount:m}=t.current;return R.ranges.some(y=>p==="col"?y.startRow===0&&y.endRow===m-1&&S>=y.startCol&&S<=y.endCol:y.startCol===0&&y.endCol===m-1&&S>=y.startRow&&S<=y.endRow)},[]),Y=i.useRef(!1),B=i.useRef({clientX:0,clientY:0}),D=i.useCallback(()=>{Y.current=!1;const{autoScroller:R,headerRef:S,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),R.stop();const m=S.current;m!==null&&u.current!==null&&m.hasPointerCapture?.(u.current)&&m.releasePointerCapture(u.current),u.current=null,p(null),t.current.repaintOverlay()},[]),$=i.useCallback(()=>{if(!n.current)return;const R=r.current;R!==null&&t.current.setSelection(R),D()},[D]),{enabled:P,headerRef:k}=e;return i.useEffect(()=>{const R=k.current;if(!P||R===null)return;const S=F=>{const b=t.current;if(F.pointerType!=="mouse")return;if(F.button!==0){F.preventDefault();return}if(C.current=!1,b.pointing?.getPointing()){s.current=R.getBoundingClientRect();const d=j(F.clientX,F.clientY);if(d===null)return;F.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()){F.preventDefault(),b.focusSink();return}s.current=R.getBoundingClientRect();const a=j(F.clientX,F.clientY);if(a===null)return;F.preventDefault(),b.focusSink();const f=b.getSelection();r.current=f;const x=F.ctrlKey||F.metaKey;if(F.shiftKey){const d=b.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:A}=N(a,a),E={...f,anchor:d};b.setSelection(rn(E,A)),o.current=b.axis==="col"?d.col:d.row}else if(x&&_(f,a))C.current=!0,q.current=a,o.current=a;else{const{press:d,extend:A}=N(a,a),E=ar(f,d,{extend:!1,append:x});b.setSelection(rn(E,A)),o.current=a}n.current=!0,b.repaintOverlay(),l.current={clientX:F.clientX,clientY:F.clientY},u.current=F.pointerId,h.current=F.buttons;try{R.setPointerCapture(F.pointerId)}catch{u.current=null}g.current=d=>{const A=t.current.axis==="col"?d.col:d.row,{press:E}=N(o.current,o.current),{extend:T}=N(o.current,A);return Ce(E,T)},b.autoScroller.stop(),Y.current=!1,B.current={clientX:F.clientX,clientY:F.clientY}},p=F=>u.current!==null?F.pointerId===u.current:F.pointerType==="mouse",m=F=>{if(n.current&&p(F)){if(C.current){const b=F.clientX!==l.current.clientX||F.clientY!==l.current.clientY;if(l.current={clientX:F.clientX,clientY:F.clientY},!b)return;const a=j(F.clientX,F.clientY);if(a===null||a===q.current)return;C.current=!1;const f=t.current,{press:x,extend:d}=N(q.current,q.current),A=ar(f.getSelection(),x,{extend:!1,append:!0});f.setSelection(rn(A,d));const E=g.current,T=Math.abs(F.clientX-B.current.clientX),M=Math.abs(F.clientY-B.current.clientY);E!==null&&Math.max(T,M)>=Zr&&(Y.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:E,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:F.clientX,clientY:F.clientY},!Y.current&&g.current!==null){const b=Math.abs(F.clientX-B.current.clientX),a=Math.abs(F.clientY-B.current.clientY);Math.max(b,a)>=Zr&&(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=F=>{m(F),n.current&&p(F)&&(h.current&1)!==0&&(F.buttons&1)===0&&O(F)},L=F=>{F.button!==0||!(n.current&&p(F))||O(F)},O=F=>{const b=t.current;if(C.current){const{press:f,extend:x}=N(q.current,q.current);b.setSelection(Sa(b.getSelection(),Ce(f,x),f)),D();return}const a=j(F.clientX,F.clientY);if(a!==null){const{extend:f}=N(o.current,a);b.setSelection(rn(b.getSelection(),f))}D()},v=F=>{!n.current||u.current===null||F.pointerId!==u.current||$()};return R.addEventListener("pointerdown",S),R.addEventListener("pointermove",y),R.addEventListener("pointerup",L),R.addEventListener("lostpointercapture",v),()=>{R.removeEventListener("pointerdown",S),R.removeEventListener("pointermove",y),R.removeEventListener("pointerup",L),R.removeEventListener("lostpointercapture",v),D()}},[P,k,j,N,D,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:$,cancelDrag:D}),[$,D])},$m=({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)})}},Lm=50,Dm=100,Aa=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Lm:!1,Gn={selectAll:nn("Ctrl+A"),undo:nn("Ctrl+Z"),redo:nn("Ctrl+Y"),redoShiftZ:nn("Ctrl+Shift+Z"),pasteValues:nn("Ctrl+Shift+V")},Mm=new Set(["Shift","Control","Alt","Meta","AltGraph"]),zm={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Fm=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Nm=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,x)=>It(a,f,x)??f,N=(a,f)=>{const x=s.current;return f==="left"||f==="right"?{row:a.row,col:j(x.colAxis,a.col,f==="right"?1:-1)}:{row:j(x.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),Y=a=>a.indexAt(a.totalSize()-1),B=(a,f,x,d)=>{if(a.sizeOf(f)>0)return f;const A=It(a,f,x);if(A!==null)return A;const E=It(a,f,x===1?-1:1);return E!==null?E:d},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}},$=a=>N(D(),a),P=(a,f)=>{const x=s.current,d=f==="left"||f==="right",A=f==="right"||f==="down"?1:-1;let E;return x.findDataEdge!==void 0?(E=x.findDataEdge({row:a.row,col:a.col},f),k(E,a,f)):E={row:f==="down"?x.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?x.colAxis.count-1:f==="left"?0:a.col},d?{row:E.row,col:B(x.colAxis,E.col,A,a.col)}:{row:B(x.rowAxis,E.row,A,a.row),col:E.col}},k=(a,f,x)=>{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=x==="left"||x==="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}})`)},R=(a,f,x)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${x} component ${a} (count ${f})`)},S=a=>{const f=s.current,x=f.getSelection();if(Ea(x,a)===x){f.moveActive({mode:"reset",cell:N(x.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,x=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
|
|
14
|
+
${a.value.slice(x)}`,a.setSelectionRange(f+1,f+1)},m=(a,f)=>{const x=s.current,d=h.current?.getViewportSize().height??-1;return d<=0?j(x.rowAxis,a,f==="down"?1:-1):x.rowAxis.indexAt(x.rowAxis.offsetOf(a)+(f==="down"?d:-d))},y=a=>{const f=s.current;if(r.current=!1,Aa(a,t.current))return;const x=a.ctrlKey||a.metaKey,d=a.altKey,A=zm[a.key];if(o.current&&!Mm.has(a.key)&&!f.isDragging()&&q(),f.isEditing()){const T=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!x&&!a.shiftKey&&!d&&f.abortDrag();return}const M=f.pointing;if(M!==void 0){if(A!==void 0&&!d){const X=M.getReferenceCursor();if(X!==null){a.preventDefault();const Z=Vt(X.cursor,f.rowAxis.count,f.colAxis.count),J=Vt(X.origin,f.rowAxis.count,f.colAxis.count),ne=x?P(Z,A):N(Z,A);if(f.ensureCellVisible(ne),M.insertReference(a.shiftKey?Ce(J,ne):ne,X.axis),f.onPointFrame!==void 0){const ie=a.shiftKey?Ce(J,ne):Ce(ne,ne);f.onPointFrame(X.axis==="columns"?Ce({row:0,col:ie.startCol},{row:f.rowAxis.count-1,col:ie.endCol}):X.axis==="rows"?Ce({row:ie.startRow,col:0},{row:ie.endRow,col:f.colAxis.count-1}):ie),o.current=!0}return}}if(a.key==="F2"&&!x&&!a.shiftKey&&!d&&M.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!x&&!a.shiftKey&&!d&&M.cycleAnchorAtCaret()){a.preventDefault();return}}const V=f.commands;if(V!==void 0){const X=Il(V.table,a);if(X!==null&&vs.has(X)&&V.isAvailable(X)){a.preventDefault(),V.execute(X);return}}if(A!==void 0&&!d){if(x&&a.shiftKey){a.preventDefault();return}if(x)return;if(T==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:$(A)}):f.moveActive({mode:"reset",cell:N(f.getSelection().active,A)});return}return}if(a.key==="Enter"&&d&&!x&&!a.shiftKey){a.preventDefault(),p();return}if((a.key==="Enter"||a.key==="Tab")&&!x&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=!a.shiftKey;S(a.key==="Tab"?X?"right":"left":X?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!x&&!d){if(a.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(X.row,a.key==="PageDown"?"down":"up"),col:X.col}});return}if(a.key==="Escape"&&!x&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const E=f.commands;if(E!==void 0){const T=Il(E.table,a);if(T!==null&&E.isAvailable(T)){a.preventDefault(),E.execute(T);return}}if(A!==void 0&&!d){const T=A==="left"||A==="right",M=A==="right"||A==="down"?1:-1;if(x&&a.shiftKey){a.preventDefault();const V=f.getSelection(),X=D();let Z;if(f.findDataEdge!==void 0){const J=T?{row:V.active.row,col:X.col}:{row:X.row,col:V.active.col},ne=f.findDataEdge(J,A);Z=T?ne.col:ne.row,R(Z,T?f.colAxis.count:f.rowAxis.count,T?"col":"row"),Z=B(T?f.colAxis:f.rowAxis,Z,M,T?X.col:X.row)}else{const J=T?f.colAxis:f.rowAxis;Z=M===1?Y(J):_(J)}f.moveActive({mode:"extend",cell:T?{row:X.row,col:Z}:{row:Z,col:X.col}});return}if(x){a.preventDefault(),f.moveActive({mode:"reset",cell:P(f.getSelection().active,A)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:$(A)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:N(f.getSelection().active,A)});return}if(Fm(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!x&&!d){a.preventDefault();const T=!a.shiftKey;S(a.key==="Tab"?T?"right":"left":T?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const M=D();f.moveActive({mode:"extend",cell:{row:x?_(f.rowAxis):M.row,col:_(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:x?_(f.rowAxis):T.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const M=D();f.moveActive({mode:"extend",cell:{row:x?Y(f.rowAxis):M.row,col:Y(f.colAxis)}});return}const T=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:x?Y(f.rowAxis):T.row,col:Y(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!x&&!d){a.preventDefault();const T=a.key==="PageDown"?"down":"up";if(a.shiftKey){const V=D();f.moveActive({mode:"extend",cell:{row:m(V.row,T),col:V.col}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:m(M.row,T),col:M.col}});return}if(a.key==="F2"&&!x&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!x&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection(),M=yt(T.ranges);if(M>f.maxOperationCells){f.onOperationRejected?.("delete",M,"limit");return}if(f.adapter!==void 0&&En(f.adapter,T.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:M});return}const V=[],X=f.adapter!==void 0&&Vr(f.adapter).hyperlink;qt(T.ranges,Z=>{V.push(X?{row:Z.row,col:Z.col,text:"",hyperlink:null}:{row:Z.row,col:Z.col,text:""})}),f.commitEdits(V,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(x||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(Yn(Gn.selectAll,a)){a.preventDefault();const T=f.getSelection(),M=Ce({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[M],anchor:T.anchor,active:T.active});return}if(Yn(Gn.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(Yn(Gn.redo,a)||Yn(Gn.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!x&&!d||a.key==="ContextMenu"&&!x&&!a.shiftKey&&!d){a.preventDefault();const T=f.getSelection().active;f.ensureCellVisible(T);const M=h.current,V=M===null?{x:0,y:0}:M.getScrollPosition(),X=Math.max(0,V.y),Z=Math.max(0,V.x),J=M===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:M.getFrozenSize(),ne=M===null?{width:0,height:0}:M.getViewportSize(),ie=f.zoomRef.current;f.onCellContextMenu?.(T,{kind:"keyboard",cellRect:{top:ln(f.rowAxis,T.row,{scroll:X,frozenCount:J.rows,trailingCount:J.trailingRows,extent:ne.height})*ie,left:sn(f.colAxis,T.col,{scroll:Z,frozenCount:J.cols,trailingCount:J.trailingCols,extent:ne.width})*ie,width:f.colAxis.sizeOf(T.col)*ie,height:f.rowAxis.sizeOf(T.row)*ie}});return}if(a.key===" "&&!d&&x!==a.shiftKey){a.preventDefault();const T=f.getSelection(),M=T.ranges.map(V=>x?Ce({row:0,col:V.startCol},{row:f.rowAxis.count-1,col:V.endCol}):Ce({row:V.startRow,col:0},{row:V.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:M,anchor:T.anchor,active:T.active});return}if(f.pendingPasteOptionsRef!==void 0&&Yn(Gn.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}},L=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},O=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Dm)},v=()=>{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()}},F=()=>{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",F),g.addEventListener("blur",b),g.addEventListener("compositionstart",L),g.addEventListener("compositionend",O),g.addEventListener("input",v),()=>{g.removeEventListener("keydown",y),g.removeEventListener("keyup",F),g.removeEventListener("blur",b),g.removeEventListener("compositionstart",L),g.removeEventListener("compositionend",O),g.removeEventListener("input",v),n.current!==null&&window.clearTimeout(n.current),q()}},[l,c,u,h])},Pm=()=>{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)})}},qm=4,_m=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),jm=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),N=i.useRef(!1),_=i.useCallback(R=>g.current!==null?R.pointerId===g.current:R.pointerType==="mouse",[]),Y=i.useCallback((R,S)=>{const{handleRef:p,rowAxis:m,colAxis:y}=t.current,L=p.current,O=s.current;if(L===null||O===null)return null;const{x:v,y:F}=L.getScrollPosition();if(F<0||v<0||m.totalSize()===0||y.totalSize()===0)return null;const b=t.current.zoomRef.current,a=L.getFrozenSize(),f=L.getViewportSize();return Vt({row:gr(m,(S-O.top)/b,{scroll:F,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:hr(y,(R-O.left)/b,{scroll:v,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},m.count,y.count)},[]),B=i.useCallback(R=>{const S=r.current;if(S===null)return Ce(R,R);const p=Ce({row:Math.min(S.startRow,R.row),col:Math.min(S.startCol,R.col)},{row:Math.max(S.endRow,R.row),col:Math.max(S.endCol,R.col)}),m=p.startRow!==S.startRow||p.endRow!==S.endRow||p.startCol!==S.startCol||p.endCol!==S.endCol;return o.current=m?p:null,m?p:S},[]),D=i.useCallback(()=>{const R=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,q.current!==null&&(cancelAnimationFrame(q.current),q.current=null),R.xAutoScroller.stop(),R.yAutoScroller.stop(),N.current=!1,u.current=!1,h.current={dx:0,dy:0},R.writeFillPreview(null);const S=j.current;S!==null&&(window.removeEventListener("pointermove",S.move),window.removeEventListener("pointerup",S.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,R.repaintOverlay()},[]),$=i.useCallback(()=>{const R=t.current,S=r.current,p=o.current;if(D(),S===null||p===null)return;const m=Ip(S,p);if(m>R.maxOperationCells){R.onOperationRejected?.("fill",m,"limit");return}if(En(R.adapter,Hp(S,p))){const O=(p.endRow-p.startRow+1)*(p.endCol-p.startCol+1),v=(S.endRow-S.startRow+1)*(S.endCol-S.startCol+1);R.rejectReadOnly({kind:"operation",op:"fill",cellCount:O-v});return}const y=Bp((O,v)=>Nc(R.adapter,O,v),S,p,Pc);if(R.commitEdits(y,{source:"fill"})===null)return;const L=R.getSelection();R.setSelection({ranges:[p],anchor:L.anchor,active:L.active})},[D]),{enabled:P,handleNodeRef:k}=e;return i.useEffect(()=>{const R=k.current;if(!P||R===null)return;const S=O=>{p(O),n.current&&_(O)&&(C.current&1)!==0&&(O.buttons&1)===0&&$()},p=O=>{if(!(n.current&&_(O)))return;l.current={clientX:O.clientX,clientY:O.clientY};const v=Math.abs(O.clientX-c.current.clientX),F=Math.abs(O.clientY-c.current.clientY);if(!u.current&&Math.max(v,F)>=qm&&(u.current=!0),!!u.current){if(!N.current){const b=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};b.xAutoScroller.start(a),b.yAutoScroller.start(a),N.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(B(b))}))}},m=O=>{O.button!==0||!(n.current&&_(O))||$()},y=O=>{const v=t.current;if(O.pointerType!=="mouse")return;if(O.button!==0){O.preventDefault();return}O.preventDefault(),O.stopPropagation(),v.focusSink();const F=v.getSelection(),b=F.ranges[F.ranges.length-1];r.current=b,o.current=null,u.current=!1,v.xAutoScroller.stop(),v.yAutoScroller.stop(),N.current=!1,c.current={clientX:O.clientX,clientY:O.clientY},l.current=c.current,C.current=O.buttons,n.current=!0,v.repaintOverlay(),s.current=v.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=v.handleRef.current?.getScrollPosition()??{x:-1,y:-1},x=f.y;if(a!==null&&x>=0&&f.x>=0){const E=f.x,T=v.zoomRef.current,M=v.handleRef.current?.getFrozenSize()??_m,V=v.handleRef.current?.getViewportSize()??{width:0,height:0},X={scroll:E,frozenCount:M.cols,trailingCount:M.trailingCols,extent:V.width},Z={scroll:x,frozenCount:M.rows,trailingCount:M.trailingRows,extent:V.height},J=sn(v.colAxis,b.endCol,X)+v.colAxis.sizeOf(b.endCol),ne=ln(v.rowAxis,b.endRow,Z)+v.rowAxis.sizeOf(b.endRow),ie=J-1,se=b.endCol>=M.cols&&M.width>0?Math.max(ie,M.width):ie,ce=!(b.endCol>=v.colAxis.count-M.trailingCols)&&M.trailingWidth>0?Math.min(se,V.width-M.trailingVisibleWidth-1):se,ve=ne-1,Le=b.endRow>=M.rows&&M.height>0?Math.max(ve,M.height):ve,je=!(b.endRow>=v.rowAxis.count-M.trailingRows)&&M.trailingHeight>0?Math.min(Le,V.height-M.trailingVisibleHeight-1):Le;h.current={dx:O.clientX-(a.left+ce*T),dy:O.clientY-(a.top+je*T)}}else h.current={dx:0,dy:0};g.current=O.pointerId;try{R.setPointerCapture(O.pointerId)}catch{g.current=null}const d=S,A=m;j.current={move:d,up:A},window.addEventListener("pointermove",d),window.addEventListener("pointerup",A),v.writeFillPreview(r.current)},L=O=>{!n.current||g.current===null||O.pointerId!==g.current||D()};return R.addEventListener("pointerdown",y),R.addEventListener("lostpointercapture",L),()=>{R.removeEventListener("pointerdown",y),R.removeEventListener("lostpointercapture",L),D()}},[P,k,_,Y,B,D,$]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&D()},cancelDrag:D}),[D])},Im=320,Wr=8,Hm=64,Bm=150,Oa=e=>Math.max(0,Math.min(Im,e.width-_e.SPREADSHEET_SCROLLBAR_SIZE_PX-Wr)),Vm=(e,t,n)=>{const r=n.width-_e.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-_e.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Oa(n),l=Math.max(0,Math.min(t,o-Wr)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+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 _ of C)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const q=o-u,j=e.top,N=Math.min(l,Math.max(q,j));if(N>=Hm){const _=q>=j?u:e.top-N;for(const Y of g)if(h(Y))return{left:Y,top:_,width:s,height:N}}return{left:Wr,top:Wr,width:s,height:l}},Wm=(e,t,n,r)=>t===null||e!==null&&Ot(e,t)||n?!1:r(t),Km=(e,t)=>{switch(e.kind){case"note":return K.jsx(ia,{ctx:e,labels:t});case"note-tip":return K.jsx(ca,{ctx:e,labels:t});case"comment":return K.jsx(ra,{ctx:e,labels:t});case"link":return K.jsx(oa,{ctx:e,labels:t});case"list":return K.jsx(sa,{ctx:e,labels:t});default:return K.jsx(la,{ctx:e,labels:t})}},Ho=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Ym=({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=Ho(s),q=Ho(l),j=i.useRef(null),N=($,P)=>{const k=g.current.getLayerSize();$.style.width=`${Oa(k)}px`,$.style.maxHeight="";const R=Vm(P,$.offsetHeight,k);$.style.left=`${R.left-P.left}px`,$.style.top=`${R.top-P.top}px`,$.style.maxHeight=`${R.height}px`};i.useLayoutEffect(()=>{const $=c.current;if($===null||s===null){j.current=null;return}if(N($,s.anchorRect),s.kind==="message")return;const P=Ho(s);if(j.current===P)return;j.current=P;const k=$.querySelector("[data-aqsp-popover-autofocus]");k!==null?k.focus({preventScroll:!0}):$.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const $=u.current,P=h.current;$===null||P===null||N($,P.anchorRect)},[q]);const _=$=>t===void 0?Km($,n):t($),Y=$=>{e.isCompositionKey($.nativeEvent)&&$.stopPropagation()},B=$=>{$.key==="Escape"&&!$.defaultPrevented&&($.preventDefault(),e.close())},D=$=>{e.registerCompositionEnd($.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:Y,onKeyDown:B,onCompositionEnd:D,children:[K.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},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:_(l)})})]})},Um=["note","note-tip","comment","link","list","message"],Xm=(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}},Zn=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Xm(e,n),Gm=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),N=i.useId(),_=i.useCallback(E=>{const T=t.current,M=T.handleRef.current,V=M===null?{x:0,y:0}:M.getScrollPosition(),X=M===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:M.getFrozenSize(),Z=M===null?{width:0,height:0}:M.getViewportSize();return{top:ln(T.rowAxis,E.row,{scroll:Math.max(0,V.y),frozenCount:X.rows,trailingCount:X.trailingRows,extent:Z.height}),left:sn(T.colAxis,E.col,{scroll:Math.max(0,V.x),frozenCount:X.cols,trailingCount:X.trailingCols,extent:Z.width}),width:T.colAxis.sizeOf(E.col),height:T.rowAxis.sizeOf(E.row)}},[]),Y=i.useCallback(E=>{const T=t.current;T.anchors.current={...T.anchors.current,...E},T.repaintOverlay()},[]),B=i.useCallback(()=>{g.current!==null&&(window.clearTimeout(g.current),g.current=null)},[]),D=i.useCallback(()=>{const E=t.current.sinkRef.current;if(E===null)return;const T=c.current;T!==null&&Ot(T,t.current.getActive())?E.setAttribute("aria-describedby",N):E.getAttribute("aria-describedby")===N&&E.removeAttribute("aria-describedby")},[N]),$=i.useCallback(()=>(B(),h.current=!1,c.current===null?!1:(c.current=null,s(null),Y({tip:null}),D(),!0)),[B,Y,D]),P=i.useCallback(()=>{B(),g.current=window.setTimeout(()=>{g.current=null,$()},Bm)},[B,$]),k=i.useCallback(E=>{const T=t.current;B();const M=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(E.row,E.col);M===void 0||M===""||(c.current=E,s({kind:"note-tip",cell:E,anchorRect:_(E),current:M,close:$}),Y({tip:E}),D())},[_,B,$,Y,D]),R=i.useCallback(E=>{const T=t.current;if(E===null&&h.current)return;const M=u.current;u.current=E;const V=c.current;if(V!==null&&E!==null&&Ot(V,E)){B();return}const X=Z=>{const J=T.adapter.getCellNote===void 0?void 0:T.adapter.getCellNote(Z.row,Z.col);return J!==void 0&&J!==""};if(Wm(M,E,T.isDraggingAny(),X)){E!==null&&k(E);return}V!==null&&P()},[k,B,P]),S=i.useCallback((E,T)=>{const M=t.current,V=M.bodyRef.current,X=M.handleRef.current;if(V===null||X===null)return null;const Z=V.getBoundingClientRect(),J=M.zoomRef.current,ne=X.getScrollPosition(),ie=X.getFrozenSize(),se=X.getViewportSize();return Vt({row:gr(M.rowAxis,(T-Z.top)/J,{scroll:Math.max(0,ne.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:se.height}),col:hr(M.colAxis,(E-Z.left)/J,{scroll:Math.max(0,ne.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:se.width})},M.rowAxis.count,M.colAxis.count)},[]),p=i.useCallback(E=>{q.current=E,C.current===null&&(C.current=requestAnimationFrame(()=>{C.current=null;const T=q.current;R(T===null?null:"cell"in T?T.cell:S(T.clientX,T.clientY))}))},[R,S]),m=i.useCallback(E=>p({cell:E}),[p]),y=i.useCallback(()=>$(),[$]),L=i.useCallback(E=>{if(l.current===null)return;const T=t.current;l.current=null,r(null),Y({interactive:null}),(E===void 0||E.restoreFocus)&&T.focusSink({preventScroll:!0}),T.isEditing()||T.rearmSink()},[Y]),O=i.useCallback(E=>{l.current=E.kind,r(E),Y({interactive:E.cell})},[Y]),v=i.useCallback(E=>{const T=t.current;return Mc(T.adapter)?{cellReadOnly:Ke(T.adapter,E.row,E.col)}:{}},[]),F=i.useCallback((E,T)=>{const M=t.current;if(Ke(M.adapter,E.cell.row,E.cell.col)){M.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),O({...E,...v(E.cell)});return}if(M.commitEdits(T,{source:"annotate"})===null){O({...E,rejected:!0});return}L()},[O,L,v]),b=i.useCallback((E,T)=>{const M=t.current;if(!Zn(M.adapter,M.popovers,E))throw new RangeError(`[spreadsheet] openPopover("${E}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const V=M.getActive();if(E==="list"&&Ke(M.adapter,V.row,V.col)){M.rejectReadOnly({kind:"edit",cell:V,editSession:"none"});return}if(E==="note-tip"){k(V);return}if(E==="message"){if(l.current!==null&&l.current!=="message")return;const ne=T!==void 0&&T.message!==void 0?T.message:void 0,ie=M.adapter.getCellValidation===void 0?void 0:M.adapter.getCellValidation(V.row,V.col),se=ne!==void 0?ne:ie===void 0?void 0:ie.inputMessage;if(se===void 0)return;const ze=T!==void 0&&T.rejected===!0;O({kind:"message",cell:V,anchorRect:_(V),current:{title:Me(M.labels,"messageTitle"),message:se,rejected:ze},close:L});return}if(M.isEditing()&&!M.requestCommit())return;if(E==="list"){const ne=M.adapter.getCellValidation===void 0?void 0:M.adapter.getCellValidation(V.row,V.col);if(ne===void 0||ne.type!=="list")return;const ie=T!==void 0&&T.typed!==void 0?T.typed:"";$(),M.focusSink({preventScroll:!0}),O({kind:"list",cell:V,anchorRect:_(V),current:ne.values,typed:ie,commit:se=>{if(Ke(t.current.adapter,V.row,V.col)){t.current.rejectReadOnly({kind:"edit",cell:V,editSession:"none"}),L();return}t.current.commitEdits([{row:V.row,col:V.col,text:se}],{source:"edit",editSession:"discarded"}),L()},close:L});return}if($(),M.focusSink({preventScroll:!0}),E==="note"){const ne=M.adapter.getCellNote===void 0?void 0:M.adapter.getCellNote(V.row,V.col),ie={kind:"note",cell:V,anchorRect:_(V),current:ne,commit:se=>{F(ie,[{row:V.row,col:V.col,note:se}])},close:L,rejected:!1,...v(V)};O(ie);return}if(E==="comment"){const ne=M.adapter.getCellComments===void 0?void 0:M.adapter.getCellComments(V.row,V.col),ie={kind:"comment",cell:V,anchorRect:_(V),current:ne===void 0?[]:ne,commit:se=>{F(ie,[{row:V.row,col:V.col,comments:se}])},close:L,rejected:!1,...v(V)};O(ie);return}const X=M.adapter.getCellHyperlink===void 0?void 0:Fn(M.adapter.getCellHyperlink(V.row,V.col)),Z=M.adapter.getCellText(V.row,V.col),J={kind:"link",cell:V,anchorRect:_(V),current:{text:Z,url:X},commit:ne=>{const ie=ne.url===null?null:Bt(ne.url);if(ie===null&&ne.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ne.url)}`);const se=ne.text===Z?{row:V.row,col:V.col,hyperlink:ie}:{row:V.row,col:V.col,text:ne.text,hyperlink:ie};F(J,[se])},close:L,canOpen:M.onHyperlinkOpen!==void 0,open:()=>{const ne=t.current.onHyperlinkOpen;ne!==void 0&&X!==void 0&&ne(X,V)},rejected:!1,...v(V)};O(J)},[_,L,F,$,O,k,v]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const E=f.current;if(!a||E===null)return;const T=V=>{const X=t.current;Zn(X.adapter,X.popovers,"note-tip")&&p({clientX:V.clientX,clientY:V.clientY})},M=()=>{Zn(t.current.adapter,t.current.popovers,"note-tip")&&p({cell:null})};return E.addEventListener("pointermove",T),E.addEventListener("pointerleave",M),()=>{E.removeEventListener("pointermove",T),E.removeEventListener("pointerleave",M)}},[a,f,p]),i.useEffect(()=>()=>{C.current!==null&&cancelAnimationFrame(C.current),g.current!==null&&window.clearTimeout(g.current)},[]);const{adapter:x,popovers:d}=e,A=i.useMemo(()=>Um.some(E=>Zn(x,d,E)),[x,d]);return i.useMemo(()=>({layerEnabled:A,isKindEnabled:E=>Zn(t.current.adapter,t.current.popovers,E),open:b,close:L,isOpen:()=>l.current,onCellHover:m,hideTip:y,onTipPointerEnter:()=>{h.current=!0,B()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&P()},syncTipAriaDescribedBy:D,context:n,tipContext:o,registerCompositionEnd:E=>{j.current=E},isCompositionKey:E=>Aa(E,j.current),getLayerSize:()=>{const E=t.current.handleRef.current;return E===null?{width:0,height:0}:E.getViewportSize()},tipId:N}),[A,b,L,m,y,B,P,D,n,o,N])},Zm=(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},xa=(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:gr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:g.height}),col:hr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:g.width})},n.count,r.count)},Jm=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),N=i.useRef(!1),_=i.useCallback((p,m)=>{const{handleRef:y,rowAxis:L,colAxis:O,zoomRef:v}=t.current;return xa(y.current,o.current,L,O,v.current,p,m)},[]),Y=i.useRef(!1),B=i.useRef(null),D=i.useRef(null),$=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,B.current=null,D.current=null,g.current=!1,C.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),p.stop();const L=m.current;L!==null&&c.current!==null&&L.hasPointerCapture?.(c.current)&&L.releasePointerCapture(c.current),c.current=null,y(null),t.current.repaintOverlay()},[]),k=i.useCallback(()=>{if(!n.current)return;const p=r.current;p!==null&&t.current.setSelection(p),P()},[P]),{enabled:R,bodyRef:S}=e;return i.useEffect(()=>{const p=S.current;if(!R||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,N.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 T=_(d.clientX,d.clientY);if(T===null)return;if(d.preventDefault(),A.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&A.openHyperlinkAt?.(T)===!0){N.current=!0;return}const M=A.getSelection();r.current=M;const V=d.shiftKey,X=d.ctrlKey||d.metaKey,Z=X&&!V&&M.ranges.some(ne=>cn(ne,T));g.current=Z,C.current=Z?T:null,Z||A.setSelection(ar(M,T,{extend:V,append:X})),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 J=Z?T:A.getSelection().anchor;h.current=ne=>Ce(J,ne),B.current=J.col,D.current=J.row,A.autoScroller.stop(),Y.current=!1,$.current={clientX:d.clientX,clientY:d.clientY}},L=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",O=d=>{if(n.current&&L(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!Y.current&&h.current!==null){const A=Math.abs(d.clientX-$.current.clientX),E=Math.abs(d.clientY-$.current.clientY);Math.max(A,E)>=Zr&&(Y.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:B.current??void 0,anchorRow:D.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const A=h.current;if(!n.current||A===null)return;const E=t.current,T=_(s.current.clientX,s.current.clientY);T!==null&&E.onDragFrame(A(T))}))}},v=d=>{O(d),n.current&&L(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&b(d)},F=d=>{d.button!==0||!(n.current&&L(d))||b(d)},b=d=>{const A=t.current,E=_(d.clientX,d.clientY);if(E!==null){const T=C.current;g.current&&T!==null?A.setSelection(Sa(A.getSelection(),Ce(T,E),T)):A.setSelection(rn(A.getSelection(),E))}P()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||k()},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 E=_(d.clientX,d.clientY);if(E===null)return;const T=A.getSelection();T.ranges.some(V=>cn(V,E))||A.setSelection(ar(T,E,{extend:!1,append:!1})),A.onContextMenuSelect(E,d)},x=d=>{const A=t.current;if(!j.current||q.current!=="mouse"||A.getPointing?.()||N.current)return;o.current=p.getBoundingClientRect();const E=_(d.clientX,d.clientY);E!==null&&Ot(A.getSelection().active,E)&&A.onRequestEdit(E,A.caretFromPointEnabled(E)?Zm(d.clientX,d.clientY,E):void 0)};return p.addEventListener("pointerdown",y),p.addEventListener("pointermove",v),p.addEventListener("pointerup",F),p.addEventListener("lostpointercapture",a),p.addEventListener("contextmenu",f),p.addEventListener("dblclick",x),()=>{p.removeEventListener("pointerdown",y),p.removeEventListener("pointermove",v),p.removeEventListener("pointerup",F),p.removeEventListener("lostpointercapture",a),p.removeEventListener("contextmenu",f),p.removeEventListener("dblclick",x),P()}},[R,S,_,P,k]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>g.current?"subtract":"add",abortDrag:k,cancelDrag:P}),[k,P])},Qm=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(($,P)=>{const{handleRef:k,rowAxis:R,colAxis:S,zoomRef:p}=t.current;return xa(k.current,o.current,R,S,p.current,$,P)},[]),N=i.useCallback(()=>{const{autoScroller:$,bodyRef:P,onDragFrame:k}=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),$.stop();const R=P.current;R!==null&&u.current!==null&&R.hasPointerCapture?.(u.current)&&R.releasePointerCapture(u.current),u.current=null,k(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.restoreSink($),N()},[N]),Y=i.useCallback($=>{const P=t.current,k=P.bodyRef.current;if(!P.enabled||k===null||!P.getPointing())return!1;o.current=k.getBoundingClientRect();const R=j($.clientX,$.clientY);if(R===null)return o.current=null,!1;const S=P.captureSink();if(S===null)return o.current=null,!1;$.preventDefault(),P.focusSink(),r.current=S,C.current=R,P.insertReference(R,"cells"),n.current=!0,s.current={clientX:$.clientX,clientY:$.clientY},l.current={clientX:$.clientX,clientY:$.clientY},u.current=$.pointerId,h.current=$.buttons;try{k.setPointerCapture($.pointerId)}catch{u.current=null}return g.current=p=>{const m=Ce(R,p);return t.current.insertReference(m,"cells"),m},P.autoScroller.stop(),q.current=!1,P.onDragFrame(Ce(R,R)),!0},[j]),{enabled:B,bodyRef:D}=e;return i.useEffect(()=>{const $=D.current;if(!B||$===null)return;const P=p=>u.current!==null?p.pointerId===u.current:p.pointerType==="mouse",k=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 L=Math.abs(p.clientX-l.current.clientX),O=Math.abs(p.clientY-l.current.clientY);Math.max(L,O)>=Zr&&(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 L=g.current;if(!n.current||L===null)return;const O=j(s.current.clientX,s.current.clientY);O!==null&&t.current.onDragFrame(L(O))})),(h.current&1)!==0&&(p.buttons&1)===0&&N()},R=p=>{p.button!==0||!(n.current&&P(p))||N()},S=p=>{!n.current||u.current===null||p.pointerId!==u.current||N()};return $.addEventListener("pointermove",k),$.addEventListener("pointerup",R),$.addEventListener("lostpointercapture",S),()=>{$.removeEventListener("pointermove",k),$.removeEventListener("pointerup",R),$.removeEventListener("lostpointercapture",S),N()}},[B,D,j,N]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:N,onPointerDown:Y}),[_,N,Y])},Oi=(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},ew=24,tw=100,nw=1e5,rw=200,Ta=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),xi=5,ow=/^#[0-9A-Fa-f]{6}$/,sw=Object.freeze({row:!1,column:!1,intersection:!1}),Ti=Object.freeze({ok:!0}),$i=(e,t)=>{if(t===void 0)return Ta;if(t.length!==xi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${xi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!ow.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},lw=e=>{for(const t of["row","column","intersection"])if(Xe(e[t])===null)throw new RangeError(`[spreadsheet] highlightColors.${t} is not a colour (got ${JSON.stringify(e[t])})`);if(!(Number.isFinite(e.opacity)&&e.opacity>=0&&e.opacity<=1))throw new RangeError(`[spreadsheet] highlightColors.opacity must be a number in [0, 1] (got ${e.opacity})`);return e},iw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ta},cw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},aw=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Ge.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Rn={ranges:[Ce({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},uw=i.forwardRef(function({adapter:t,defaultRowHeight:n=ew,defaultColumnWidth:r=tw,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:N,onCellContextMenu:_,onUndoRequest:Y,onRedoRequest:B,onCopyMultiRange:D,onOperationRejected:$,onEditRejected:P,onReadOnlyRejected:k,formatReadOnlyAnnouncement:R,dataVersion:S,maxOperationCells:p=nw,enableFillHandle:m=!0,enableResizeUI:y=!0,formatCellAnnouncement:L,formatSelectionAnnouncement:O,formatCommandAnnouncement:v,locale:F,labels:b,shortcuts:a,colors:f,formats:x,highlight:d,defaultHighlight:A,onHighlightChange:E,highlightColors:T,popovers:M,renderPopover:V,onClipChange:X,onHyperlinkOpen:Z,onValidationRejected:J,onPasteSpecialRequest:ne,onClipboardUnavailable:ie,onPasteResolved:se,now:ze=Date.now,zoom:ce,defaultZoom:ve,onZoomChange:Le,testId:Ne,className:je,__onCellRender:qe,__onVirtualKeyboardRaise:bt,__maxRenderedCells:mr},oo){const pe=wi(t.rowCount,n),ae=wi(t.colCount,r),an=i.useRef(null);an.current===null&&(an.current=Pm());const ke=an.current,Tt=Ge.resolveVirtualScrollLocale(F),pt=i.useMemo(()=>Bc(F,b),[F,b]),wr=aw(ih(pt)),Wt=i.useMemo(()=>rh(a),[a]),$t=i.useMemo(()=>({fill:$i("fill",f===void 0?void 0:f.fill),font:$i("font",f===void 0?void 0:f.font)}),[f]),un=i.useMemo(()=>T===void 0?void 0:lw(T),[T]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Kt=i.useCallback(()=>ke.get().editVersion,[ke]),dn=i.useCallback(w=>ke.subscribeCoalesced(w),[ke]),yr=i.useSyncExternalStore(dn,Kt,Kt)+(S===void 0?0:S),Yt=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),fn=i.useMemo(()=>({index:Yt===null?null:ba(Yt),memo:Ss()}),[t,Yt,yr]),Nn=i.useRef(fn.index);Nn.current=fn.index;const Pn=i.useRef(fn.memo);Pn.current=fn.memo;const Lt=i.useCallback((w,W,Q)=>Es(t,Nn.current,Pn.current,w,W,Q),[t]),Ze=i.useRef(null),[pn,so]=i.useState(()=>_e.clampSpreadsheetZoom(ve??1)),rt=_e.clampSpreadsheetZoom(ce??pn),z=i.useRef(rt);z.current=rt;const H=i.useRef(rt);H.current=rt;const U=i.useRef(null),I=i.useRef(Le);I.current=Le;const G=i.useRef(ce!==void 0);G.current=ce!==void 0;const oe=i.useCallback(w=>{const W=_e.clampSpreadsheetZoom(w);W!==H.current&&(H.current=W,G.current||so(W),I.current?.(W))},[]),ee=t.rowCount===0||t.colCount===0,Ae=!ee;i.useEffect(()=>{const w=Ze.current;if(!Ae||w===null)return;const W=te=>{te.defaultPrevented||!te.altKey||te.ctrlKey||te.metaKey||te.shiftKey||te.deltaY!==0&&(te.preventDefault(),te.stopPropagation(),!U.current?.()&&oe(_e.stepSpreadsheetZoom(H.current,te.deltaY<0?1:-1)))},Q=te=>{if(te.defaultPrevented||!(te.ctrlKey&&te.altKey)||te.metaKey||te.getModifierState("AltGraph"))return;const Se=te.key==="="||te.key==="+"?_e.stepSpreadsheetZoom(H.current,1):te.key==="-"?_e.stepSpreadsheetZoom(H.current,-1):te.key==="0"?1:null;Se!==null&&(te.preventDefault(),te.stopPropagation(),!U.current?.()&&oe(Se))};return w.addEventListener("wheel",W,{passive:!1,capture:!0}),w.addEventListener("keydown",Q,!0),()=>{w.removeEventListener("wheel",W,{capture:!0}),w.removeEventListener("keydown",Q,!0)}},[oe,Ae]);const de=i.useRef(null),fe=i.useRef(null),De=i.useRef(null),He=i.useRef(null),Pe=i.useRef(0),re=i.useRef(null),he=i.useRef(0),ge=i.useRef(null),me=i.useRef(null),ue=i.useRef(null),ye=i.useRef(null),Re=i.useRef(null),Te=i.useRef(null),ht=i.useRef(null),[Be,ot]=i.useState(Rn),Ie=i.useRef(Be),Ve=i.useCallback(()=>Ie.current,[]),[qn,Ut]=i.useState(()=>A===void 0?sw:A),Dt=d!==void 0?d:qn,_n=i.useRef(Dt);_n.current=Dt;const $a=iw(un,Dt),Os=i.useRef(d!==void 0);Os.current=d!==void 0;const xs=i.useRef(E);xs.current=E;const La=i.useCallback(w=>{Os.current||Ut(w),xs.current?.(w)},[]),Ts=i.useRef(null),lo=i.useRef(null),Rt=i.useRef(null),io=i.useRef(()=>!1),$s=i.useRef(()=>{}),Ls=i.useRef(()=>null),Ds=i.useRef(()=>{}),Xt=i.useCallback(()=>io.current(),[]),co=i.useMemo(()=>({getPointing:()=>io.current(),insertReference:(w,W)=>$s.current(w,W)}),[]),Ms=i.useRef(Et),zs=i.useRef(null),ao=i.useRef({interactive:null,tip:null}),Fs=i.useRef(null),Ns=i.useRef(null),br=i.useRef(()=>{}),Ps=i.useRef(()=>!1),Mt=i.useRef(null),jn=i.useCallback(()=>{const w=Mt.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)},[]),uo=i.useRef(()=>!1),qs=i.useRef(()=>!1),_s=i.useRef(null),fo=i.useRef(()=>Promise.resolve("rejected")),xe=i.useCallback(()=>{Ts.current?.()},[]),$e=i.useCallback(w=>{De.current?.focus(w)},[]),po=i.useRef(!1),Da=i.useCallback(()=>{const w=Ze.current;if(w!==null){po.current=!0;try{w.focus()}finally{po.current=!1}}},[]),Je=i.useCallback(()=>{const w=De.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),hn=i.useCallback((w,W)=>{if(w===null)return;const Q=W?"":"none";w.style.display!==Q&&(w.style.display=Q)},[]),st=i.useCallback(()=>{const w=He.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().y??0),te=fe.current?.getFrozenSize().height??0;w.style.transform=`translateY(${Pe.current-Q-te}px)`}const W=fe.current;if(W!==null&&(Re.current!==null||Te.current!==null)){const Q=W.getFrozenSize();hn(Re.current,Q.height>0),hn(Te.current,Q.trailingHeight>0)}},[hn]),lt=i.useCallback(()=>{const w=re.current;if(w!==null){const Q=Math.max(0,fe.current?.getScrollPosition().x??0),te=fe.current?.getFrozenSize().width??0;w.style.transform=`translateX(${he.current-Q-te}px)`}const W=fe.current;if(W!==null&&(ue.current!==null||ye.current!==null)){const Q=W.getFrozenSize();hn(ue.current,Q.width>0),hn(ye.current,Q.trailingWidth>0)}},[hn]),In=i.useRef(null),gn=i.useCallback(()=>{ue.current===null&&ye.current===null&&Re.current===null&&Te.current===null||In.current===null&&(In.current=requestAnimationFrame(()=>{In.current=null,st(),lt(),xe()}))},[st,lt,xe]);i.useEffect(()=>()=>{In.current!==null&&cancelAnimationFrame(In.current)},[]);const ho=i.useRef(null),go=i.useRef(null);(ho.current===null||go.current?.rowAxis!==pe||go.current?.colAxis!==ae)&&(go.current={rowAxis:pe,colAxis:ae},ho.current=$m({handleRef:fe,rowAxis:pe,colAxis:ae}));const zt=i.useCallback(w=>{ho.current?.(w)},[]),mn=i.useRef(null),Gt=i.useRef(null),wn=i.useCallback(w=>{mn.current!==null&&window.clearTimeout(mn.current),Gt.current!==null&&(cancelAnimationFrame(Gt.current),Gt.current=null),mn.current=window.setTimeout(()=>{mn.current=null;const W=ht.current;W!==null&&(W.textContent="",Gt.current=requestAnimationFrame(()=>{Gt.current=null,W.textContent=w}))},rw)},[]);i.useEffect(()=>()=>{mn.current!==null&&window.clearTimeout(mn.current),Gt.current!==null&&cancelAnimationFrame(Gt.current)},[]);const Cn=i.useCallback(w=>{k?.(w),R!==void 0&&wn(R(w))},[k,R,wn]),js=i.useCallback((w,W)=>{if(L===void 0&&O===void 0)return;const Q=W.ranges[W.ranges.length-1],te=nt(Q),Se=W.ranges.length===1&&te.rows===1&&te.cols===1,Ee=w.ranges[w.ranges.length-1],Nt=w.ranges.length!==W.ranges.length||Ee.startRow!==Q.startRow||Ee.startCol!==Q.startCol||Ee.endRow!==Q.endRow||Ee.endCol!==Q.endCol,Qt=()=>{if(L!==void 0){const vt=W.active,So=t.getCellText(vt.row,vt.col),pl=t.getCellFormat===void 0?void 0:Lt(vt.row,vt.col,()=>So);wn(L({row:vt.row,col:vt.col,text:So,displayText:Dn(So,pl===void 0?void 0:pl.value),columnName:sr(vt.col),...Mc(t)?{readOnly:Ke(t,vt.row,vt.col)}:{}}))}};if(Se){Qt();return}if(Nt){O!==void 0&&wn(O({range:Q,anchor:W.anchor,active:W.active,rangeRowCount:te.rows,rangeColCount:te.cols,rangeCount:W.ranges.length}));return}Qt()},[t,L,O,wn,Lt]),We=i.useCallback(w=>{const W=Ie.current;Object.is(w,W)||Em(w,W)||(Ie.current=w,ot(w),N?.(w),js(W,w),(Rt.current?.()??!1)||Je())},[N,js,Je]),Ma=i.useCallback(w=>{const W=Ie.current;if(w.mode==="cycle"){const te=Ea(W,w.direction);We(te),zt(te.active);return}const Q=Vt(w.cell,pe.count,ae.count);if(w.mode==="extend"){We(rn(W,Q)),zt(Q);return}We(ar(W,Q,{extend:!1,append:!1})),zt(Q)},[We,zt,pe,ae]),Ye=i.useCallback(()=>Rt.current?.()??!1,[]),Is=i.useRef(null),it=i.useCallback(()=>Is.current?.()??!0,[]),Hs=i.useRef(null),Hn=i.useCallback((w,W)=>{const Q=Rt.current?.()??!1;Hs.current?.(w,W),!Q&&(Rt.current?.()??!1)&&jn()},[jn]),[za,mo]=i.useState(!1),Bs=i.useCallback(()=>{bt?.(),mo(!0)},[bt]),Fa=i.useCallback((w,W)=>{Ke(t,w.row,w.col)||Bs(),Hn("edit",W)},[t,Bs,Hn]),Vs=i.useRef(null),Rr=i.useCallback(()=>Vs.current?.()??null,[]),Ws=i.useRef(null),gt=i.useCallback(()=>{Ws.current?.()},[]),Ks=i.useRef(null),Ys=i.useCallback(w=>{Ks.current?.(w)},[]),Us=i.useRef(()=>{}),vr=i.useRef(0),Zt=i.useCallback((w,W,Q)=>{let te;if(W.source==="paste"){const Se=cw(Q);if(w.length===0&&Se.conditionalFormats.length===0)return null;vr.current+=1,te={transaction:vr.current,source:"paste",sameSheet:Se.sameSheet,conditionalFormats:Se.conditionalFormats}}else{if(w.length===0)return null;vr.current+=1,te={transaction:vr.current,source:W.source}}try{t.applyEdits(w,te)}catch(Se){return P?.(Se,W),null}return ke.bumpEdit(),Ys(W.source),te.transaction},[t,ke,P,Ys]),Na=i.useCallback((w,W)=>Zt(w,{source:"paste"},W),[Zt]),Pa=i.useCallback(w=>{ke.setVy(w.y),st(),lt(),xe()},[ke,st,lt,xe]),Xs=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),qa=i.useCallback(w=>{ke.setRowRange(w.renderingRowStart,w.renderingRowEnd),ke.setColRange(w.renderingColStart,w.renderingColEnd);const W=Xs.current;(W.rowStart!==w.renderingRowStart||W.rowEnd!==w.renderingRowEnd||W.colStart!==w.renderingColStart||W.colEnd!==w.renderingColEnd)&&(Xs.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},xe())},[ke,xe]),Gs=i.useRef(()=>"add"),Ft=i.useCallback(w=>{lo.current?.(w,Gs.current())},[]),_a=i.useCallback(w=>{lo.current?.(w,"point")},[]),Zs=i.useRef(null),wo=i.useCallback(w=>{Zs.current?.(w)},[]),Js=i.useRef(null),ja=i.useCallback(w=>{Js.current?.(w)},[]),Qs=i.useRef(null),Co=i.useCallback((w,W)=>{if(W.length===0)return;const Q=fe.current;if(w==="col"){for(const te of W){const Se=Math.round(te.size);ae.resize(te.index,Se),Q?.updateColSize(te.index,Se)}ke.bumpColVersion(),lt(),xe(),gn();return}for(const te of W){const Se=Math.round(te.size);pe.resize(te.index,Se),Q?.updateRowSize(te.index,Se)}ke.bumpRowGeometry(),st(),xe(),gn()},[pe,ae,ke,lt,st,xe,gn]),Ia=i.useCallback((w,W)=>{_?.(w,{kind:"pointer",event:W})},[_]),Ha=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"both",zoomRef:z}),Ba=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"x",zoomRef:z}),Va=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"y",zoomRef:z}),Wa=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:wo,axis:"x",zoomRef:z}),Ka=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:wo,axis:"y",zoomRef:z}),Ya=bn({handleRef:fe,rowAxis:pe,colAxis:ae,bodyRef:de,onDragFrame:Ft,axis:"both",zoomRef:z}),el=i.useRef(null),tl=i.useRef(()=>!1),yo=i.useCallback(()=>tl.current(),[]),ct=Jm({zoomRef:z,enabled:!ee,rowAxis:pe,colAxis:ae,handleRef:fe,bodyRef:de,isEditing:Ye,requestCommit:it,getSelection:Ve,setSelection:We,focusSink:$e,onDragFrame:Ft,onContextMenuSelect:Ia,onRequestEdit:Fa,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 Dn(W,t.getCellFormat(w.row,w.col)?.value)===W},isAnyDragging:yo,autoScroller:Ha,repaintOverlay:xe,pointDragRef:el,getPointing:Xt,openHyperlinkAt:Z===void 0||t.getCellHyperlink===void 0?void 0:w=>{const W=t.getCellHyperlink===void 0?void 0:Fn(t.getCellHyperlink(w.row,w.col));return W===void 0?!1:(Z(W,w),!0)}}),mt=Ai({zoomRef:z,enabled:!ee,axis:"col",headerRef:ge,mainAxis:ae,crossCount:t.rowCount,handleRef:fe,isEditing:Ye,requestCommit:it,getSelection:Ve,setSelection:We,focusSink:$e,onDragFrame:Ft,autoScroller:Ba,repaintOverlay:xe,pointing:co}),wt=Ai({zoomRef:z,enabled:!ee,axis:"row",headerRef:me,mainAxis:pe,crossCount:t.colCount,handleRef:fe,isEditing:Ye,requestCommit:it,getSelection:Ve,setSelection:We,focusSink:$e,onDragFrame:Ft,autoScroller:Va,repaintOverlay:xe,pointing:co}),Ct=Sm({zoomRef:z,enabled:!ee&&y,colBandRef:ge,rowBandRef:me,colAxis:ae,rowAxis:pe,viewStore:ke,handleRef:fe,isEditing:Ye,requestCommit:it,focusSink:$e,getSelection:Ve,adapter:t,autofitEnabled:j===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:p,onOperationRejected:$,resizeTracks:Co,writeResizeGuide:ja,repaintOverlay:xe,isPointing:Xt}),at=jm({zoomRef:z,enabled:!ee&&m,handleNodeRef:Qs,bodyRef:de,rowAxis:pe,colAxis:ae,handleRef:fe,getSelection:Ve,setSelection:We,focusSink:$e,adapter:t,commitEdits:Zt,maxOperationCells:p,onOperationRejected:$,rejectReadOnly:Cn,writeFillPreview:wo,repaintOverlay:xe,xAutoScroller:Wa,yAutoScroller:Ka}),Qe=Qm({zoomRef:z,enabled:!ee,bodyRef:de,handleRef:fe,rowAxis:pe,colAxis:ae,getPointing:Xt,insertReference:co.insertReference,captureSink:()=>Ls.current(),restoreSink:w=>Ds.current(w),focusSink:$e,autoScroller:Ya,onDragFrame:Ft});el.current=Qe;const Bn=i.useCallback(()=>ct.isDragging()||mt.isDragging()||wt.isDragging()||Ct.isDragging()||at.isDragging()||Qe.isDragging(),[ct,mt,wt,Ct,at,Qe]);U.current=Bn,tl.current=Bn,Gs.current=()=>Qe.isDragging()?"point":ct.getDragMode();const Ua=i.useCallback(()=>{ct.abortDrag(),mt.abortDrag(),wt.abortDrag(),Ct.abortDrag(),at.abortDrag(),Qe.abortDrag()},[ct,mt,wt,Ct,at,Qe]),bo=i.useCallback(()=>Ie.current.active,[]),nl=i.useCallback((w,W)=>{const Q=t.getCellValidation===void 0?void 0:t.getCellValidation(w.row,w.col);if(Q===void 0)return Ti;const te=t.evaluateFormula,Se=Kc(Q,W,Tt,te===void 0?void 0:Ee=>te(Ee,w));return Se.ok||Q.strict!==!0?Ti:(J?.({cell:w,rule:Q,text:W,message:Se.message}),Mt.current?.isKindEnabled("message")&&br.current("message",{message:Se.message,rejected:!0}),Se)},[t,J,Tt]),Fe=jg({enabled:!ee,sinkRef:De,rootRef:Ze,adapter:t,commitEdits:Zt,getActive:bo,ensureCellVisible:zt,focusSink:$e,rearmSink:Je,discardClip:gt,isDragging:yo,rejectReadOnly:Cn,resolveEditAlign:w=>{if(t.getCellFormat===void 0)return null;const W=Br(t,w.row,w.col);return Dc(Lt(w.row,w.col,W),W)},resolveEditPaint:w=>t.getCellFormat===void 0?null:zd(Lt(w.row,w.col,Br(t,w.row,w.col))),editPaintRef:Ms,repaintOverlay:xe,validateCommit:nl});Rt.current=Fe.isEditing,Is.current=Fe.requestCommit,Hs.current=Fe.startEdit,io.current=Fe.getPointing,$s.current=Fe.insertReference,Ls.current=Fe.captureSink,Ds.current=Fe.restoreSink;const rl=i.useCallback(()=>{Fe.cancelEdit(),jn()},[Fe.cancelEdit,jn]),Vn=Rg({enabled:!ee,sinkRef:De,adapter:t,isEditing:Ye,getSelection:Ve,setSelection:We,commitPaste:Na,maxOperationCells:p,onOperationRejected:$,onCopyMultiRange:D,repaintOverlay:xe,isDragging:yo,resize:{rowAxis:pe,colAxis:ae,resizeTracks:Co},pendingPasteOptionsRef:zs,formats:x,onClipChange:X,onClipboardUnavailable:ie,onEditRejected:P,rejectReadOnly:Cn,onPasteResolved:se});Vs.current=Vn.getClip,Ws.current=Vn.discardClip,Ks.current=Vn.discardClipOnCommit,Us.current=Vn.onAdapterSwitch,fo.current=Vn.paste;const Wn=Gm({enabled:!ee,adapter:t,popovers:M,sinkRef:De,bodyRef:de,handleRef:fe,rowAxis:pe,colAxis:ae,zoomRef:z,getActive:bo,isEditing:Ye,requestCommit:it,focusSink:$e,rearmSink:Je,isDraggingAny:Bn,commitEdits:Zt,labels:pt,onHyperlinkOpen:Z,anchors:ao,repaintOverlay:xe,rejectReadOnly:Cn});Mt.current=Wn,br.current=Wn.open,Ps.current=Wn.hideTip;const Xa=i.useCallback(()=>{const w=Ie.current.active;zt(w);const W=fe.current,Q=W===null?{x:0,y:0}:W.getScrollPosition(),te=W===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:W.getFrozenSize(),Se=W===null?{width:0,height:0}:W.getViewportSize(),Ee=z.current;return{top:ln(pe,w.row,{scroll:Math.max(0,Q.y),frozenCount:te.rows,trailingCount:te.trailingRows,extent:Se.height})*Ee,left:sn(ae,w.col,{scroll:Math.max(0,Q.x),frozenCount:te.cols,trailingCount:te.trailingCols,extent:Se.width})*Ee,width:ae.sizeOf(w.col)*Ee,height:pe.sizeOf(w.row)*Ee}},[pe,ae,zt]),Ro=Pg({adapter:t,getSelection:Ve,commitEdits:Zt,getActive:bo,isEditing:Ye,requestCommit:it,cancelEdit:rl,getSessionText:Fe.getSessionText,validateCommit:nl,insertAtCaret:Fe.insertAtCaret,refreshEditPaint:Fe.refreshPaint,maxOperationCells:p,onOperationRejected:$,colors:$t,formats:x,getHighlight:()=>_n.current,setHighlight:La,popovers:M,openPopover:w=>br.current(w),onHyperlinkOpen:Z,onPasteSpecialRequest:ne,paste:w=>fo.current(w),rowAxis:pe,colAxis:ae,resizeTracks:Co,defaultRowHeight:n,defaultColumnWidth:r,now:ze,announce:wn,formatCommandAnnouncement:v,keyboardCellRect:Xa,rejectReadOnly:Cn});_s.current=Ro,uo.current=Ro.executeCommand,qs.current=Ro.isCommandAvailable;const Ga=i.useMemo(()=>({table:Wt,execute:w=>uo.current(w),isAvailable:w=>qs.current(w)}),[Wt]),Za=i.useCallback(()=>{gt(),Y?.()},[gt,Y]),Ja=i.useCallback(()=>{gt(),B?.()},[gt,B]);Nm({zoomRef:z,enabled:!ee,sinkRef:De,rootRef:Ze,handOffFocusToRoot:Da,getSelection:Ve,setSelection:We,moveActive:Ma,ensureCellVisible:zt,isEditing:Ye,requestCommit:it,startEdit:Hn,commitEdits:Zt,maxOperationCells:p,onOperationRejected:$,rejectReadOnly:Cn,getClip:Rr,discardClip:gt,isDragging:Bn,abortDrag:Ua,findDataEdge:t.findDataEdge,getEditingMode:Fe.getEditingMode,cancelEdit:rl,onUndoRequest:Za,onRedoRequest:Ja,onCellContextMenu:_,rowAxis:pe,colAxis:ae,handleRef:fe,rearmSink:Je,commands:Ga,pointing:Fe,adapter:t,hideNoteTip:()=>Ps.current(),closeRejectedMessage:jn,pendingPasteOptionsRef:zs,onPointFrame:_a});const Qa=Be.active.row,eu=Be.active.col;i.useLayoutEffect(()=>{const w=Mt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[Qa,eu]),i.useLayoutEffect(()=>{xe()},[xe,Dt.row,Dt.column,Dt.intersection]);const tu=i.useCallback(w=>{(Rt.current?.()??!1)||(w.preventDefault(),$e(),Je())},[$e,Je]),nu=i.useCallback(w=>{const W=Ze.current,Q=w.relatedTarget;if(W!==null&&Q instanceof Node&&W.contains(Q)){w.target===W&&Q===De.current&&!po.current&&$e();return}(Rt.current?.()??!1)||($e(),Je())},[$e,Je]),ru=i.useCallback(w=>{const W=Ze.current,Q=w.relatedTarget;W!==null&&Q instanceof Node&&W.contains(Q)||Fe.isFocusoutSuppressed()||mo(!1)},[Fe]),kr=i.useRef(null),Kn=i.useCallback(()=>{const w=kr.current;w!==null&&(kr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),vo=i.useCallback(()=>{if(kr.current!==null)return;const w=Q=>{Q.pointerType==="mouse"&&(Kn(),Q.button===1&&Q.preventDefault())},W=Q=>{Q.pointerType==="mouse"&&Kn()};kr.current={up:w,cancel:W},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",W,!0)},[Kn]);i.useEffect(()=>Kn,[Kn]),i.useEffect(()=>{const w=Ze.current;if(ee||w===null)return;let W=0;const Q=Ee=>{if(Ee.pointerType!=="mouse"){(Rt.current?.()??!1)||mo(!1);return}W=Ee.buttons,Ee.button===1&&(Ee.target===De.current&&(Rt.current?.()??!1)||vo())},te=Ee=>{Ee.pointerType==="mouse"&&(W=Ee.buttons)},Se=Ee=>{if(Ee.pointerType!=="mouse"||Ee.buttons===W)return;const Nt=Ee.buttons&~W;W=Ee.buttons,Ee.preventDefault(),(Nt&4)!==0&&vo()};return w.addEventListener("pointerdown",Q,!0),w.addEventListener("pointerup",te,!0),w.addEventListener("pointermove",Se,!0),()=>{w.removeEventListener("pointerdown",Q,!0),w.removeEventListener("pointerup",te,!0),w.removeEventListener("pointermove",Se,!0)}},[ee,vo]);const ou=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(Xt()){$e();return}if(Ye()&&!it()){$e();return}$e()}},[$e,Ye,it,Xt]),ko=i.useRef(!1);i.useLayoutEffect(()=>{if(ee){ko.current=!1;return}if(ko.current)return;ko.current=!0,Je();const w=(Ze.current?.clientHeight??0)/z.current;w>0&&pe.totalSize()>0&&ke.setRowRange(0,pe.indexAt(Math.min(w-1,pe.totalSize()-1)));const W=(Ze.current?.clientWidth??0)/z.current;W>0&&ae.totalSize()>0&&ke.setColRange(0,ae.indexAt(Math.min(W-1,ae.totalSize()-1)))},[ee,Je,ke,pe,ae]);const ol=i.useRef(t);i.useLayoutEffect(()=>{ol.current!==t&&(ol.current=t,ct.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),at.cancelDrag(),Qe.cancelDrag(),Fe.cancelEdit(),Mt.current?.hideTip(),Mt.current?.close(),ee?(Ie.current=Rn,ot(Rn)):We(Rn),Us.current())},[t,ee,We,ct,mt,wt,Ct,at,Qe,ke,Fe.cancelEdit]);const sl=i.useRef({adapter:t,rows:pe.count,cols:ae.count}),{getSessionCell:ll,cancelEdit:il}=Fe;i.useLayoutEffect(()=>{const w=sl.current,W=pe.count,Q=ae.count;if(sl.current={adapter:t,rows:W,cols:Q},w.adapter!==t||W>=w.rows&&Q>=w.cols)return;ee?(Ie.current=Rn,ot(Rn)):We(Am(Ie.current,W,Q)),ct.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),at.cancelDrag(),Qe.cancelDrag();const te=Qt=>ee||Qt.row>=W||Qt.col>=Q,Se=ll();Se!==null&&te(Se)&&il();const Ee=ao.current;if(Ee.tip!==null&&te(Ee.tip)&&Mt.current?.hideTip(),Ee.interactive!==null&&te(Ee.interactive)){const Qt=Ze.current?.contains(document.activeElement)===!0;Mt.current?.close({restoreFocus:Qt})}const Nt=Rr();Nt!==null&&!Nt.foreign&&te({row:Nt.range.endRow,col:Nt.range.endCol})&>()},[t,pe.count,ae.count,ee,We,ct,mt,wt,Ct,at,Qe,ll,il,Rr,gt]);const cl=i.useRef(o),al=i.useRef(s),ul=i.useRef(l),dl=i.useRef(c);i.useLayoutEffect(()=>{(cl.current!==o||al.current!==s||ul.current!==l||dl.current!==c)&&(cl.current=o,al.current=s,ul.current=l,dl.current=c,ct.cancelDrag(),mt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),at.cancelDrag(),Qe.cancelDrag())},[o,s,l,c,ct,mt,wt,Ct,at,Qe]),i.useLayoutEffect(()=>{st(),lt(),xe()},[o,s,l,c,st,lt,xe]);const fl=i.useRef(S);i.useLayoutEffect(()=>{fl.current!==S&&(fl.current=S,gt())},[S,gt]),i.useLayoutEffect(()=>{xe()},[xe,Be]);const Jt=i.useCallback(()=>{const w=_s.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(oo,()=>({resizeRow:(w,W)=>{const Q=Math.round(W);pe.resize(w,Q),fe.current?.updateRowSize(w,Q),ke.bumpRowGeometry(),st(),xe(),gn()},resizeColumn:(w,W)=>{const Q=Math.round(W);ae.resize(w,Q),fe.current?.updateColSize(w,Q),ke.bumpColVersion(),lt(),xe(),gn()},scrollToCell:(w,W)=>{fe.current?.scrollToCell(w.row,w.col,W)},focus:w=>{$e(w),Ye()||Je()},executeCommand:w=>uo.current(w),applyFormat:w=>Jt().applyFormat(w),setBorders:(w,W)=>Jt().setBorders(w,W),setHyperlink:w=>Jt().setHyperlink(w),setNote:w=>Jt().setNote(w),addComment:w=>Jt().addComment(w),setValidation:w=>Jt().setValidation(w),paste:w=>fo.current(w),getSelection:()=>Ie.current,getBaseFormat:w=>t.getCellFormat===void 0?void 0:t.getCellFormat(w.row,w.col),getPaintedFormat:w=>t.getCellFormat===void 0?void 0:Lt(w.row,w.col,Br(t,w.row,w.col)),startEdit:w=>{Hn(w)},openPopover:w=>{br.current(w)}}),[pe,ae,ke,lt,st,xe,gn,$e,Ye,Je,t,Lt,Hn,Jt]),ee)return K.jsx("div",{className:je?`aqsp-root ${je}`:"aqsp-root","data-aqsp-empty":"","data-testid":Ne});const su=L!==void 0||O!==void 0||v!==void 0||R!==void 0;return K.jsx("div",{ref:Ze,className:je?`aqsp-root ${je}`:"aqsp-root",role:"group","aria-label":pt.rootAriaLabel,tabIndex:0,onFocus:nu,onBlur:ru,"data-aqsp-root":"","data-testid":Ne,children:K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":rt,onPointerDown:ou,style:rt===1?void 0:{width:`${100/rt}%`,height:`${100/rt}%`,transform:`scale(${rt})`},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(Xt()){$e();return}if(Ye()&&!it()){$e();return}$e(),We({ranges:[Ce({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(ym,{viewStore:ke,colAxis:ae,frozenCols:o,frozenTrailingCols:l,handleRef:fe,bandRef:ge,colTrackRef:re,windowOriginXRef:he,repaintColHeaders:lt,selectionRanges:Be.ranges,enableResizeUI:y,dividerLeadingRef:ue,dividerTrailingRef:ye}),K.jsx(bm,{viewStore:ke,rowAxis:pe,handleRef:fe,bandRef:me,selectionRanges:Be.ranges,rowTrackRef:He,windowOriginYRef:Pe,repaintHeaders:st,enableResizeUI:y,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:Re,dividerTrailingRef:Te}),K.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(Cm,{adapter:t,rowAxis:pe,colAxis:ae,viewStore:ke,handleRef:fe,bodyRef:de,dataVersion:S,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:l,frozenTrailingRows:c,tapScrollCircleOptions:u,overscanRows:Oi("overscanRows",h),overscanCols:Oi("overscanCols",g),background:C,onRenderTruncated:q,renderCell:j,onScroll:Pa,onRangeChange:qa,focusSink:$e,isEditing:Ye,requestCommit:it,testId:Ne?`${Ne}-vs`:void 0,__onCellRender:qe,__maxRenderedCells:mr,cfIndexRef:Nn,cfMemoRef:Pn,isPointing:Xt,locale:Tt,scrollLabels:wr}),K.jsx(Xh,{rowAxis:pe,colAxis:ae,handleRef:fe,sinkRef:De,getSelection:Ve,editing:Fe.editing,virtualKeyboard:za,repaintRef:Ts,dragFrameRef:lo,getClip:Rr,getIsDraggingAny:Bn,getIsFillDragging:at.isDragging,fillFrameRef:Zs,resizeGuideFrameRef:Js,fillHandleNodeRef:Qs,enableFillHandle:m,frozenCols:o,frozenRows:s,trailingCols:l,trailingRows:c,sinkAriaLabel:pt.sinkAriaLabel,onSinkMouseDown:tu,editPaintRef:Ms,highlightRef:_n,highlightColors:$a,popoverAnchors:ao,interactiveAnchorRef:Fs,tipAnchorRef:Ns}),Wn.layerEnabled?K.jsx(Ym,{controller:Wn,labels:pt,renderPopover:V,interactiveAnchorRef:Fs,tipAnchorRef:Ns}):null]}),su?K.jsx("div",{ref:ht,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.parseTsv=tr.parseTsv;exports.serializeTsv=tr.serializeTsv;exports.BORDER_DEFAULT_COLOR=cs;exports.CommentPopover=ra;exports.DEFAULT_CUSTOM_COLORS=Ta;exports.DEFAULT_HIGHLIGHT_COLORS=ta;exports.DEFAULT_SHORTCUTS=Ic;exports.LinkPopover=oa;exports.ListPopover=sa;exports.MessagePopover=la;exports.NotePopover=ia;exports.NoteTip=ca;exports.SPREADSHEET_LABEL_CATALOGS=Hc;exports.SPREADSHEET_RESERVED_SHORTCUTS=Jp;exports.Spreadsheet=uw;exports.canonicalizeFormat=ft;exports.columnIndexToName=sr;exports.columnNameToIndex=Vp;exports.detectClipSource=ji;exports.enumerateRangeCells=qt;exports.estimatePasteCellCount=_p;exports.expandPaste=jp;exports.formatCellValue=Dn;exports.formatEquals=gu;exports.fromR1C1=fr;exports.makeRange=Ce;exports.mergeFormat=us;exports.normalizeHyperlink=Bt;exports.parseChord=nn;exports.parseClipPayload=Wo;exports.parseHtmlTable=Lc;exports.rangeContains=cn;exports.rangeSize=nt;exports.resolveLabel=Me;exports.resolveLabels=Bc;exports.serializeClipPayload=Pi;exports.serializeHtmlTable=Oc;exports.shiftFormula=uc;exports.toR1C1=eo;exports.validateCellText=Kc;
|