@aiquants/spreadsheet 0.9.0 → 0.10.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 +54 -0
- package/README.md +74 -5
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +129 -7
- package/dist/index.d.ts +129 -7
- package/dist/index.js +4318 -4140
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/package.json +5 -5
- package/src/Spreadsheet.tsx +152 -12
- package/src/clipboard/tiling.ts +106 -16
- package/src/clipboard/useClipboard.ts +120 -7
- package/src/commands/useCommands.ts +226 -42
- package/src/editor/useCellEditor.ts +62 -13
- package/src/grid/GridBody.tsx +29 -3
- package/src/index.ts +5 -1
- package/src/keyboard/useGridKeyboard.ts +24 -3
- package/src/model/dataAdapter.ts +121 -2
- package/src/model/labels.ts +8 -2
- package/src/overlay/useFillHandle.ts +35 -2
- package/src/popover/CommentPopover.tsx +14 -2
- package/src/popover/LinkPopover.tsx +15 -3
- package/src/popover/NotePopover.tsx +24 -6
- package/src/popover/usePopovers.ts +89 -11
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("react/jsx-runtime"),Gn=require("@aiquants/virtualscroll"),l=require("react"),Vo=1e3,bn=1e4,Wo=10,Ys=(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),Yo=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Wo):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),bn))}let i=[...s].map(([a,m])=>({index:a,size:m}));if(e.count-e.hiddenCount()-Ys(e,i)===0){const a=n===null?i[0].index:n;i=i.map(m=>m.index===a?{index:m.index,size:1}:m)}if(r.axisKind==="row"){const a=e.hiddenCount()+Ys(e,i);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:i}},Ko="#000000",fr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Na=20,La=256,pr=new Map,ao=new WeakMap,Ze=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Pa=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},qa=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Na}:fr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...fr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...fr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...fr(e.decimals)};default:return null}},_a=e=>{const t=ao.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=pr.get(n);if(r!==void 0)return ao.set(e,r),r;pr.size>=La&&pr.clear();const o=qa(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return pr.set(n,s),ao.set(e,s),s},Ia=(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}},ll=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]),i=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>Ia(n,r)||s>23||i>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:i,second:c}},Ha=(e,t)=>{const n=ll(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)}})},yn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Ha(e,t.pattern??"yyyy/MM/dd");const n=Ze(e);if(n===null)return e;const r=_a(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Pa(n,-2):n)},Ks=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?ll(n)!==null?"right":"left":Ze(n)!==null?"right":"left",jn=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",cl=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],ja=["bottom","left","right","top"],al=(e,t,n)=>{e[t]=n},ul=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Ba=e=>{if(e===void 0)return;const t={};for(const n of ja){const r=e[n];r!==void 0&&(t[n]=ul(r))}return Object.keys(t).length===0?void 0:t},lt=e=>{const t={};for(const n of cl){const r=n==="borders"?Ba(e.borders):n==="value"?e.value===void 0?void 0:ul(e.value):e[n];r!==void 0&&r!==!1&&al(t,n,r)}return Object.keys(t).length===0?void 0:t},Uo=(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 i=0;i<n.length;i+=1){const c=n[i];if(c!==r[i]||!Uo(o[c],s[c]))return!1}return!0},Va=(e,t)=>e===t?!0:Uo(e===void 0?void 0:lt(e),t===void 0?void 0:lt(t)),Xo=(e,t)=>{const n={};for(const o of cl){const s=t[o];al(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=lt(n);return Uo(r,e===void 0?void 0:lt(e))?e:r},dl="data-aqsp-clip",Nr="application/x-aqsp-clip",To=512,Us=16*1024,Do=`${dl}=`,Wa=16,Go=()=>{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(Wa));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Zn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),oe=e=>typeof e=="string",je=e=>typeof e=="boolean",Lt=e=>typeof e=="number"&&Number.isFinite(e),st=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Xs=e=>st(e)&&e>=1,Ya=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=bn,yt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Ka=e=>t=>Array.isArray(t)&&t.every(e),ke=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),Rt=(e,t)=>{if(!Zn(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},Zo=e=>t=>{if(!Zn(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&Rt(t,n)},Ua=["left","center","right"],Xa=["top","middle","bottom"],Ga=["thin","medium","thick","dashed","dotted","double","hair"],uo=["gt","gte","lt","lte","eq","neq","between","notBetween"],Za=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Ja=["eq","neq","gt","gte","lt","lte","between","notBetween"],Qa=["contains","notContains","startsWith","endsWith"],eu=new Map([["number",ke({type:oe,decimals:Lt,grouping:je,locale:oe},["type"])],["percent",ke({type:oe,decimals:Lt,scale:je,locale:oe},["type"])],["currency",ke({type:oe,currency:oe,decimals:Lt,locale:oe},["type","currency"])],["scientific",ke({type:oe,decimals:Lt,locale:oe},["type"])],["date",ke({type:oe,pattern:oe},["type"])],["text",ke({type:oe},["type"])]]),tu=ke({style:yt(Ga),color:oe},["style"]),hr=e=>Rt(e,tu),nu=ke({top:hr,right:hr,bottom:hr,left:hr},[]),ru=ke({value:Zo(eu),align:yt(Ua),verticalAlign:yt(Xa),wrap:je,background:oe,color:oe,bold:je,italic:je,underline:je,strikethrough:je,fontFamily:oe,fontSize:Lt,borders:e=>Rt(e,nu)},[]),ou=e=>Rt(e,ru),Kt={strict:je,inputMessage:oe,errorMessage:oe},su=new Map([["list",ke({...Kt,type:oe,values:Ka(oe),showDropdown:je},["type","values"])],["number",ke({...Kt,type:oe,op:yt(uo),a:oe,b:oe},["type","op","a"])],["textLength",ke({...Kt,type:oe,op:yt(uo),a:Lt,b:Lt},["type","op","a"])],["date",ke({...Kt,type:oe,op:yt(uo),a:oe,b:oe},["type","op","a"])],["text",ke({...Kt,type:oe,op:yt(Za),value:oe},["type","op"])],["checkbox",ke({...Kt,type:oe,checked:oe,unchecked:oe},["type"])],["custom",ke({...Kt,type:oe,formula:oe},["type","formula"])]]),iu=Zo(su),lu=ke({startRow:st,startCol:st,endRow:st,endCol:st},["startRow","startCol","endRow","endCol"]),cu=e=>{if(!Rt(e,lu))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return st(t)&&st(r)&&st(n)&&st(o)&&t<=r&&n<=o},au=ke({color:oe,value:Lt},["color"]),fo=e=>Rt(e,au),uu=new Map([["cellValue",ke({type:oe,op:yt(Ja),a:oe,b:oe},["type","op","a"])],["text",ke({type:oe,op:yt(Qa),value:oe},["type","op","value"])],["empty",ke({type:oe},["type"])],["notEmpty",ke({type:oe},["type"])],["colorScale",ke({type:oe,min:fo,mid:fo,max:fo},["type","min","max"])],["customFormula",ke({type:oe,formula:oe},["type","formula"])]]),du=ke({background:oe,color:oe,bold:je,italic:je,underline:je,strikethrough:je},[]),fu=ke({sourceRuleId:oe,ranges:Array.isArray,condition:Zo(uu),style:e=>Rt(e,du),stopIfTrue:je},["sourceRuleId","ranges","condition","style"]),pu=(e,t,n)=>{if(!Rt(e,fu))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!cu(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},hu=ke({text:oe,author:oe,createdAt:oe},["text","author","createdAt"]),mu=e=>Rt(e,hu),gu=(e,t,n)=>{if(!Zn(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(!st(o)||o>=t)return!1;break;case"val":if(!st(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(mu)))return!1;break;default:return!1}}return!0},Gs=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Ya),wu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),fl=e=>{if(!Zn(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!wu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Xs(t)&&Xs(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(ou)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(iu)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!gu(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Gs(e.colWidths,n)||e.rowHeights!==void 0&&!Gs(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const i=e.conditionalFormats;return Array.isArray(i)&&i.every(c=>pu(c,t,n))},Kn=e=>Array.isArray(e)?`[${e.map(Kn).join(",")}]`:Zn(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Kn(e[n])}`).join(",")}}`:JSON.stringify(e),Cu=e=>{const t=lt(e);return t===void 0?"{}":JSON.stringify(t)},bu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,yu=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(bu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},pl=e=>{if(!fl(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(Cu).join(","),r=e.validations.map(Kn).join(","),o=e.cells.map(a=>`[${a.map(yu).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,i=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(Kn).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${i},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},Mo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return fl(t)?t:null},vu=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Ru=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),hl=e=>e.includes("&")?e.replace(vu,t=>Ru[t]):e,ku=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Zs=e=>{const t=e.length>To?e.slice(0,To):e,n=ku.exec(hl(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Su=e=>{const t=e.indexOf(Do);if(t===-1)return null;const n=t+Do.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},ml=(e,t)=>{if(t==="event"&&e.types.includes(Nr))return{kind:"mime",json:e.getData(Nr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Su(n);return r===null?null:{kind:"attribute",html:n,at:r}},Eu=(e,t)=>{const n=ml(e,t);return n===null?null:n.kind==="mime"?Zs(n.json):Zs(n.html.slice(n.at.start,n.at.start+To))},xu=(e,t)=>{const n=ml(e,t);if(n===null)return null;if(n.kind==="mime")return Mo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:Mo(hl(n.html.slice(n.at.start,r)))},Au=/<google-sheets-html-origin[\s>]/,Ou='data-sheets-root="1"',Tu=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Du="mso-",Mu=/\.xl\d+\s*\{/,$u="<table",Fu=e=>e.includes(Do)?"aqsp":Au.test(e)&&e.includes(Ou)?"sheets":Tu.test(e)||e.includes(Du)||Mu.test(e)?"excel":null,gl=(e,t)=>{if(t==="event"&&e.types.includes(Nr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Us?n.slice(0,Us):n,o=Fu(r);if(o==="aqsp")return"aqsp";if(n.includes($u))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Jo=1e3,wl=65534,zu=9,Nu=10,Lu=12,Pu=13,qu=32,Cl=34,bl=39,_u=43,Qo=47,Js=48,Iu=57,Hu=61,ju=62,Bu=97,Vu=98,Wu=100,Yu=102,yl=104,vl=114,Rl=116,Ku=["able","body","head","foot"],Bn=e=>e===qu||e===zu||e===Nu||e===Pu||e===Lu,$o=e=>e===ju||e===Qo||Bn(e),Uu=e=>Bn(e)||e===Qo||e===Cl||e===bl,Xu=(e,t,n,r)=>{if(t===0||!Uu(e.charCodeAt(t-1)))return null;let o=t+n;for(;Bn(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Hu)return 1;for(o+=1;Bn(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Cl||s===bl)&&(o+=1);Bn(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===_u&&(o+=1);let i=0,c=0;for(let a=e.charCodeAt(o);a>=Js&&a<=Iu;a=e.charCodeAt(o))i=i*10+(a-Js),c+=1,o+=1;return c===0||i===0?1:i>r?r:i},Qs=(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 i=Xu(e,r,t.length,n);if(i!==null)return i}return 1}},Gu=(e,t)=>{if(e.charCodeAt(t+2)!==Rl)return!1;const n=e.charCodeAt(t+3);if(n===vl)return $o(e.charCodeAt(t+4));if(n!==Bu&&n!==Vu&&n!==yl&&n!==Yu)return!1;for(const r of Ku)if(e.startsWith(r,t+3)&&$o(e.charCodeAt(t+3+r.length)))return!0;return!1},Zu=e=>{const t=e.toLowerCase(),n=Qs(t,"colspan",Jo),r=Qs(t,"rowspan",wl);let o=0;const s=q=>(o!==-1&&o<q&&(o=t.indexOf(">",q)),o===-1?t.length:o);let i=0,c=0,a=0,m=0,p=!1;const S=new Map,N=(q,K)=>{const k=S.get(q);S.set(q,k===void 0?K:k+K)},P=()=>{p&&a+m>c&&(c=a+m),p=!1},T=()=>{P(),i+=1,p=!0,a=0;const q=S.get(i-1);q!==void 0&&(m+=q)};for(let q=t.indexOf("<");q!==-1;q=t.indexOf("<",q+1)){const K=t.charCodeAt(q+1);if(K===Qo){Gu(t,q)&&P();continue}if(K!==Rl||!$o(t.charCodeAt(q+3)))continue;const k=t.charCodeAt(q+2);if(k===vl)T();else if(k===Wu||k===yl){p||T();const L=q+3,D=s(L),x=n(L,D);a+=x;const A=r(L,D);A>1&&(N(i,x),N(i-1+A,-x))}}return P(),{rows:i,cols:c}},kl=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),i=n.get(s);if(i!==void 0)return i;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},Sl=()=>{const e=new WeakMap,t=kl(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=lt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Ju=()=>{const e=new WeakMap,t=kl(Kn);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}},Qu=new Set(["http:","https:","mailto:","tel:"]),It=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Qu.has(n.protocol)?n.href:null},kn=e=>{if(e===void 0)return;const t=It(e);return t===null?void 0:t},El=(e,t)=>e.startCol===0&&e.endCol===t-1,xl=(e,t)=>e.startRow===0&&e.endRow===t-1,Fo=13,bt=Object.freeze({style:Object.freeze({}),lineBoxPx:Fo,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"},td=new Map(Object.entries(ed)),nd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,rd=/^rgba?\((.*)\)$/,Al=/^(\d+(?:\.\d+)?)%$/,mr=e=>e.toString(16).padStart(2,"0"),po=e=>{const t=Al.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},od=e=>{const t=Al.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},sd=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=po(t[0]),r=po(t[1]),o=po(t[2]);if(n===null||r===null||o===null)return null;const s=`#${mr(n)}${mr(r)}${mr(o)}`;if(t.length===3)return s;const i=od(t[3]);return i===null?null:i===255?s:`${s}${mr(i)}`},Be=e=>{const t=e.trim().toLowerCase(),n=nd.exec(t);if(n!==null){const s=n[1],i=s.length<=4?s.replace(/./g,c=>c+c):s;return i.length===8&&i.endsWith("ff")?`#${i.slice(0,6)}`:`#${i}`}const r=rd.exec(t);if(r!==null)return sd(r[1]);const o=td.get(t);return o===void 0?null:o},ei={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"}},ti=e=>{if(!Object.hasOwn(ei,e.style))return null;const t=ei[e.style],n=e.color===void 0?Ko:Be(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},id={top:"flex-start",middle:"center",bottom:"flex-end"},ld=e=>e==="left"||e==="center"||e==="right",Ol=e=>e==="top"||e==="middle"||e==="bottom",Tl=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Dl=(e,t)=>{if(typeof e.background=="string"){const s=Be(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Be(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=Tl(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},gr=(e,t)=>{const n=e===void 0?null:ti(e);return n!==null?n:t===void 0?null:ti(t)},ho=(e,t,n,r,o)=>{const s={},i={};e!==void 0&&(ld(e.align)&&(i["data-aqsp-align"]=e.align,s.justifyContent=jn(e.align)),Ol(e.verticalAlign)&&(i["data-aqsp-valign"]=e.verticalAlign,s.alignItems=id[e.verticalAlign]),e.wrap===!0&&(i["data-aqsp-wrap"]=""),Dl(e,s));const c=e?.borders,a=gr(c?.right,t);a!==null&&(s.borderRight=a);const m=gr(c?.bottom,n);if(m!==null&&(s.borderBottom=m),r){const p=gr(c?.left,void 0);p!==null&&(s.borderLeft=p)}if(o){const p=gr(c?.top,void 0);p!==null&&(s.borderTop=p)}return Object.keys(s).length===0&&Object.keys(i).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(i)})},ni=new WeakMap,cd=(e,t,n,r,o)=>{const s=t?.borders?.left,i=n?.borders?.top,c=!(r||o)&&s===void 0&&i===void 0;if(e===void 0)return c?null:ho(void 0,s,i,r,o);if(!c)return ho(e,s,i,r,o);const a=ni.get(e);if(a!==void 0)return a;const m=ho(e,void 0,void 0,!1,!1);return ni.set(e,m),m},ad=e=>{if(e===void 0)return bt;const t={};Dl(e,t);const n=Tl(e.fontSize),r=n===null?Fo:Math.round(n),o=Ol(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Fo&&o==="middle"?bt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},ud="#REF!",dd=11,fd=15,pd=4096,Or=33,Vn=34,es=36,hd=38,zo=39,Ml=40,md=42,gd=43,wd=44,$l=45,Cd=46,bd=47,mn=58,yd=59,vd=60,Fl=61,Rd=62,kd=67,Sd=82,jr=91,zl=93,Ed=94,xd=95,Nl=e=>e>=65&&e<=90||e>=97&&e<=122,Ll=e=>e>=48&&e<=57,ts=e=>Nl(e)||Ll(e)||e===xd||e===Cd||e===es||e>=128,Ad=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,Od=e=>e===Fl||e===Ml||e===wd||e===yd||e===gd||e===$l||e===md||e===bd||e===Ed||e===hd||e===vd||e===Rd||e===mn,Pl=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(ts(n)||n===Ml||n===Or||n===jr)},ri=(e,t)=>{let n=t;for(;n<e.length&&ts(e.charCodeAt(n));)n+=1;return n},No=(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},Td=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===zo){r+=2;continue}if(o===jr)n+=1;else if(o===zl&&(n-=1,n===0))return r+1;r+=1}return e.length},oi=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Pl(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},ql=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Vn){o=No(e,o,Vn);continue}if(s===zo){const a=No(e,o,zo);o=e.charCodeAt(a)===Or?oi(e,o,a,t,n):a;continue}if(s===jr){o=Td(e,o);continue}if(!ts(s)){o+=1;continue}const i=t(e,o);if(i!==null&&Pl(e,i.end)){n.push({start:o,end:i.end,token:i.token}),o=i.end;continue}let c=ri(e,o);if(e.charCodeAt(c)===mn){const a=ri(e,c+1);a>c+1&&e.charCodeAt(a)===Or&&(c=a)}o=e.charCodeAt(c)===Or?oi(e,o,c,t,n):c}return n},mo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===es;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const i=e.charCodeAt(n);if(!Nl(i))break;if(s+=1,s>dd)return null;o=o*26+(i&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Lo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Ll(o))break;if(n-t>=fd)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},wr=(e,t)=>{const n=e.charCodeAt(t)===es,r=Lo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Dd=(e,t)=>{const n=mo(e,t);if(n!==null){const o=wr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===mn){const s=mo(e,o.end+1);if(s!==null){const i=wr(e,s.end);if(i!==null)return{end:i.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:i.index,col:s.col,absRow:i.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)===mn){const s=mo(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=wr(e,t);if(r!==null&&e.charCodeAt(r.end)===mn){const o=wr(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},Jn=e=>ql(e,Dd),_l=(e,t=pd)=>{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}},Po=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},go=e=>`${e.absCol?"$":""}${Po(e.col)}${e.absRow?"$":""}${e.row+1}`,ns=e=>e.sheet===void 0?"":`${e.sheet}!`,Pt=e=>{const t=ns(e);switch(e.kind){case"cell":return`${t}${go(e)}`;case"range":return`${t}${go(e.start)}:${go(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Po(e.start.col)}:${e.end.abs?"$":""}${Po(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},dn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Md=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(dn(n.startRow,"formatRangeReference startRow"),dn(n.startCol,"formatRangeReference startCol"),dn(n.endRow,"formatRangeReference endRow"),dn(n.endCol,"formatRangeReference endCol"),t){case"columns":return Pt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return Pt({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?Pt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):Pt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},rs=(e,t,n)=>{if(t.length===0)return e;let r="",o=0;for(const s of t){const i=n(s.token);r+=e.slice(o,s.start)+(i===null?`${ns(s.token)}${ud}`:i),o=s.end}return r+e.slice(o)},Br=e=>e.charCodeAt(0)===Fl,wo=(e,t,n)=>{const r=e.absRow?e.row:e.row+t,o=e.absCol?e.col:e.col+n;return r<0||o<0?null:{row:r,col:o,absRow:e.absRow,absCol:e.absCol}},$d=(e,t,n)=>{switch(e.kind){case"cell":{const r=wo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=wo(e.start,t,n),o=wo(e.end,t,n);return r===null||o===null?null:{...e,start:r,end:o}}case"column":{const r=e.start.abs?e.start.col:e.start.col+n,o=e.end.abs?e.end.col:e.end.col+n;return r<0||o<0?null:{...e,start:{col:r,abs:e.start.abs},end:{col:o,abs:e.end.abs}}}case"row":{const r=e.start.abs?e.start.row:e.start.row+t,o=e.end.abs?e.end.row:e.end.row+t;return r<0||o<0?null:{...e,start:{row:r,abs:e.start.abs},end:{row:o,abs:e.end.abs}}}}},Il=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Br(e)?rs(e,Jn(e),r=>{const o=$d(r,t,n);return o===null?null:Pt(o)}):e},Hl=(e,t)=>{dn(e.row,`${t} origin.row`),dn(e.col,`${t} origin.col`)},fn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Co=(e,t)=>`${fn("R",e.row,e.absRow,t.row)}${fn("C",e.col,e.absCol,t.col)}`,Fd=(e,t)=>{const n=ns(e);switch(e.kind){case"cell":return`${n}${Co(e,t)}`;case"range":return`${n}${Co(e.start,t)}:${Co(e.end,t)}`;case"column":return`${n}${fn("C",e.start.col,e.start.abs,t.col)}:${fn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${fn("R",e.start.row,e.start.abs,t.row)}:${fn("R",e.end.row,e.end.abs,t.row)}`}},Vr=(e,t)=>(Hl(t,"toR1C1"),Br(e)?rs(e,Jn(e),n=>Fd(n,t)):e),si=(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 i=e.charCodeAt(o+1)===$l,c=Lo(e,i?o+2:o+1);return c===null||e.charCodeAt(c.end)!==zl?null:{end:c.end+1,axis:{rel:!0,n:i?-c.value:c.value}}}const s=Lo(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}}},ii=(e,t)=>{const n=si(e,t,Sd),r=si(e,n===null?t:n.end,kd);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}},zd=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}}},Nd=(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,Ld=(e,t)=>{const n=ii(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===mn){const r=ii(e,n.end+1);if(r!==null){const o=Nd(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:zd(n)}},Pd=e=>ql(e,Ld),qd=_l(Pd),pn=(e,t)=>e.rel?t+e.n:e.n-1,li=(e,t)=>{const n=pn(e.row,t.row),r=pn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},_d=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=li(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=li(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=pn(e.start,t.row),s=pn(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=pn(e.start,t.col),s=pn(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}}}},Qn=(e,t)=>(Hl(t,"fromR1C1"),Br(e)?rs(e,qd(e),n=>{const r=_d(n,t);return r===null?null:Pt(r)}):e),ci=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Id=e=>{switch(e.kind){case"cell":return{...e,...ci(e.absCol,e.absRow)};case"range":{const t=ci(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}}}}},jl=(e,t)=>Br(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Bl=(e,t)=>{if(!jl(e,t))return null;for(const n of Jn(e))if(n.start<=t&&t<=n.end)return n;return null},Hd=(e,t)=>{const n=Bl(e,t);if(n===null)return null;const r=Pt(Id(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},ai=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Vn){const s=No(e,r,Vn);if(s>t)return!1;n=Vn,r=s;continue}Ad(o)||(n=o),r+=1}return Od(n)},Vl=(e,t)=>{if(!jl(e,t))return null;for(const n of Jn(e))if(n.start<=t&&t<=n.end)return ai(e,n.start)?{replace:[n.start,n.end]}:null;return ai(e,t)?{insertAt:t}:null},vn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],Wr=(e,t)=>`[$${e}-${t}]`,jd=new Map(vn.map(e=>[Wr(e.symbol,e.lcid),e])),Bd=new Map(vn.filter((e,t)=>vn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(vn.map(e=>[Wr(e.symbol,e.lcid),e.code]));const Vd=new Set([...vn.map(e=>e.symbol),...vn.map(e=>e.code),"¥"]),Wd=20,Yd="yyyy/MM/dd",Wl=/yyyy|MM|dd|HH|mm|ss/g,Yl=" -+/():!^&'~{}<>=",Kd="$¥€£₩₹¥",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},Ud=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},Xd=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),i=s<0?"":e.slice(r+1,s);if(s<0||i[0]!=="$")return null;const c=i.slice(1),a=c.lastIndexOf("-"),m=a<0?c:c.slice(0,a),p=a<0?null:c.slice(a+1);if(p!==null&&!/^[0-9a-fA-F]{1,8}$/.test(p)||m===""&&p===null)return null;const S=p===null?null:Number.parseInt(p,16).toString(16);t.push(m===""?{kind:"locale"}:{kind:"currency",symbol:m,lcid:S}),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 i=e.slice(r,s);/[#0?]/.test(i)?t.push({kind:"digits",text:i}):n(i),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(Yl.includes(o)||Kd.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ot=e=>e===void 0?{}:{locale:e},Gd=/^(0|#,##0)(?:\.(0+))?$/,ui=(e,t,n,r)=>{if(t!==null){const o=jd.get(Wr(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Vd.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ot(r.locale)}},Zd=(e,t)=>{let n="",r=!1,o=null,s=!1,i=0,c="",a="";for(const T of e)switch(T.kind){case"locale":break;case"literal":r?a+=T.text:c+=T.text;break;case"digits":if(r)return;n=T.text,r=!0;break;case"currency":if(o!==null)return;o=T;break;case"percent":i+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const m=Gd.exec(n);if(m===null)return;const p=m[1]==="#,##0",S=m[2]===void 0?0:m[2].length,N=c.trim(),P=a.trim();if(s)return i===0&&o===null&&!p&&N===""&&P===""?{type:"scientific",decimals:S,...ot(t.locale)}:void 0;if(i>0)return i===1&&o===null&&N===""&&P===""?{type:"percent",decimals:S,...ot(t.locale)}:void 0;if(P==="%"&&N===""&&o===null)return{type:"percent",decimals:S,scale:!1,...ot(t.locale)};if(o!==null)return N===""&&P===""?ui(o.symbol,o.lcid,S,t):void 0;if(!(N!==""&&P!==""))return N!==""||P!==""?ui(N+P,null,S,t):{type:"number",decimals:S,...p?{grouping:!0}:{},...ot(t.locale)}},Jd=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Qd=(e,t)=>{const n=[...e.matchAll(Wl)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},ef=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 i=s.text==="mm"?t[o-1]==="hh"||t[o+1]==="ss"?"mm":"MM":Jd.get(s.text);if(o+=1,i===void 0)return;n.push({index:r.length,text:i}),r+=i}return n.length>0&&Qd(r,n)?{type:"date",pattern:r}:void 0},tf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ot(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ot(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ot(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ot(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ot(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ot(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),os=(e,t)=>{const n=Ud(e).trim(),r=tf.get(n);if(r!==void 0)return r(t);const o=Xd(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Zd(o,t);if(o.some(s=>s.kind==="date"))return ef(o)}},nf=(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 i=s===void 0?void 0:os(s,t);return o===5?i!==void 0&&i.type==="date"?i:{type:"date"}:i},In=e=>e===0?"":`.${"0".repeat(e)}`,Tr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Wd,rf=`${Yl}.,`,di=e=>e.includes('"')?null:[...e].every(t=>rf.includes(t))?e:`"${e}"`,of=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Wl)){const a=di(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=di(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),i=os(s,{});return i!==void 0&&i.type==="date"&&i.pattern===e?s:null},sf=e=>{const t=Bd.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Tr(n))return null;const r=`#,##0${In(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Wr(t.symbol,t.lcid)}${r}`},Kl=e=>{switch(e.type){case"text":return"@";case"date":return of(e.pattern===void 0?Yd:e.pattern);case"number":return Tr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${In(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Tr(t)?e.scale===!1?`0${In(t)}"%"`:`0${In(t)}%`:null}case"scientific":return Tr(e.decimals)?`0${In(e.decimals)}E+00`:null;case"currency":return sf(e);default:return null}},fi="-−",lf=(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("")},cf=(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],i=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const m=lf(c[0],t);return m===null?null:{integer:m,fraction:a,exponent:i}},af=(e,t,n,r)=>{const o=e+t,s=e.length+n;let i,c;s<=0?(i="0",c="0".repeat(-s)+o):s>=o.length?(i=o+"0".repeat(s-o.length),c=""):(i=o.slice(0,s),c=o.slice(s)),i=i.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const a=c===""?i:`${i}.${c}`;return r&&a!=="0"?`-${a}`:a},uf=(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 i=r==="general"?"":n.group,c=r==="scientific"||r==="general",a=x=>x>="0"&&x<="9"||i!==""&&i.includes(x)||n.decimal.includes(x)||c&&(x==="e"||x==="E");let m=0;for(;m<o.length&&!a(o[m]);)m+=1;let p=o.length;for(;p>m&&!a(o[p-1]);)p-=1;let S=0,N=0,P=0,T="";for(const x of o.slice(0,m))fi.includes(x)?S+=1:x==="("?N+=1:T+=x;for(const x of o.slice(p))fi.includes(x)?S+=1:x===")"?P+=1:T+=x;const q=S+N;if(N!==P||q>1||q===1&&s||(s=s||q===1,r!=="currency"&&T.trim()!==""))return e;const K=cf(o.slice(m,p).trim(),i,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(K===null)return e;const k=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,L=K.exponent+k;if(L>330||L<-330)return e;const D=af(K.integer,K.fraction,L,s);return Number.isFinite(Number(D))?D:e},pi="google-sheets-html-origin",Ul=Object.freeze({group:",",decimal:"."}),hi=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"}),Xl=["top","right","bottom","left"],df=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),ff=new Set(["windowtext","currentcolor","inherit","initial","unset"]),pf=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"]),mi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],hf=Object.freeze({number:2,percent:3,currency:4,scientific:8}),mf=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),gf=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"]),wf=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Cf=3,bf=1,Gl=-25569,Dr=86400,yf=-693959,vf=2958465,Rf=" ",Yr=e=>{const t=new Map;let n=0,r=null,o=0;const s=i=>{const c=e.slice(n,i),a=c.indexOf(":");if(a>0){const m=c.slice(0,a).trim().toLowerCase(),p=c.slice(a+1).trim();m!==""&&p!==""&&t.set(m,p)}n=i+1};for(let i=0;i<e.length;i+=1){const c=e[i];r!==null?c==="\\"?i+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(i)}return s(e.length),t},Lr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},ss=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},kf=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Sf=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const i=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<i.length;){const a=i.indexOf("{",c);if(a===-1)break;const m=i.indexOf("}",a+1);if(m===-1)break;const p=i.slice(c,a),S=i.slice(a+1,m);if(c=m+1,p.trim().startsWith("@"))continue;const N=Yr(S);for(const P of p.split(",")){const T=P.trim(),q=kf.exec(T);if(q!==null){const K=t.get(q[1]);if(K===void 0)t.set(q[1],new Map(N));else for(const[k,L]of N)K.set(k,L)}else if(T.toLowerCase()==="table"){const K=N.get("mso-displayed-decimal-separator"),k=N.get("mso-displayed-thousand-separator");K!==void 0&&(n=qo(Lr(K))),k!==void 0&&(r=qo(Lr(k)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Ul}},Ef="%_-*? ",xf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Ef.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},Af=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,i=t>2?t-3:t+9,c=Math.floor((153*i+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},Zl=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)),i=Math.floor((5*s+2)/153),c=s-Math.floor((153*i+2)/5)+1,a=i<10?i+3:i-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},an=(e,t)=>String(e).padStart(t,"0"),Jl=e=>{if(e<yf||e>vf)return null;let t=Math.floor(e),n=Math.round((e-t)*Dr);n>=Dr&&(t+=1,n-=Dr);const r=Zl(t+Gl),o=`${an(r.year,4)}-${an(r.month,2)}-${an(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),i=Math.floor(n%3600/60);return`${o} ${an(s,2)}:${an(i,2)}:${an(n%60,2)}`},Of=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Tf=e=>{const t=Of.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]),i=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||i>59||c>59)return null;const a=Af(n,r,o),m=Zl(a);return m.year!==n||m.month!==r||m.day!==o?null:a-Gl+(s*3600+i*60+c)/Dr},is=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),Ut=e=>is(e).replaceAll('"',"""),Ql=e=>is(e).replaceAll("'","'"),Df=e=>is(e).replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("react/jsx-runtime"),rr=require("@aiquants/virtualscroll"),i=require("react"),Jo=1e3,Sn=1e4,Qo=10,rl=(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),es=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Qo):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),Sn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-rl(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()+rl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},ts="#000000",yr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Ya=20,Ua=256,br=new Map,wo=new WeakMap,Xe=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Xa=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},Ga=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Ya}:yr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...yr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...yr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...yr(e.decimals)};default:return null}},Za=e=>{const t=wo.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=br.get(n);if(r!==void 0)return wo.set(e,r),r;br.size>=Ua&&br.clear();const o=Ga(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return br.set(n,s),wo.set(e,s),s},Ja=(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}},Ci=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>Ja(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Qa=(e,t)=>{const n=Ci(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)}})},En=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Qa(e,t.pattern??"yyyy/MM/dd");const n=Xe(e);if(n===null)return e;const r=Za(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Xa(n,-2):n)},ol=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Ci(n)!==null?"right":"left":Xe(n)!==null?"right":"left",Xn=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",yi=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],eu=["bottom","left","right","top"],bi=(e,t,n)=>{e[t]=n},vi=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},tu=e=>{if(e===void 0)return;const t={};for(const n of eu){const r=e[n];r!==void 0&&(t[n]=vi(r))}return Object.keys(t).length===0?void 0:t},it=e=>{const t={};for(const n of yi){const r=n==="borders"?tu(e.borders):n==="value"?e.value===void 0?void 0:vi(e.value):e[n];r!==void 0&&r!==!1&&bi(t,n,r)}return Object.keys(t).length===0?void 0:t},ns=(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]||!ns(o[c],s[c]))return!1}return!0},nu=(e,t)=>e===t?!0:ns(e===void 0?void 0:it(e),t===void 0?void 0:it(t)),rs=(e,t)=>{const n={};for(const o of yi){const s=t[o];bi(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=it(n);return ns(r,e===void 0?void 0:it(e))?e:r},Ri="data-aqsp-clip",Hr="application/x-aqsp-clip",Lo=512,sl=16*1024,Po=`${Ri}=`,ru=16,os=()=>{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},or=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),le=e=>typeof e=="string",Be=e=>typeof e=="boolean",Pt=e=>typeof e=="number"&&Number.isFinite(e),st=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,ll=e=>st(e)&&e>=1,ou=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=Sn,Rt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},su=e=>t=>Array.isArray(t)&&t.every(e),ke=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),St=(e,t)=>{if(!or(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},ss=e=>t=>{if(!or(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&St(t,n)},lu=["left","center","right"],iu=["top","middle","bottom"],cu=["thin","medium","thick","dashed","dotted","double","hair"],Co=["gt","gte","lt","lte","eq","neq","between","notBetween"],au=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],uu=["eq","neq","gt","gte","lt","lte","between","notBetween"],du=["contains","notContains","startsWith","endsWith"],fu=new Map([["number",ke({type:le,decimals:Pt,grouping:Be,locale:le},["type"])],["percent",ke({type:le,decimals:Pt,scale:Be,locale:le},["type"])],["currency",ke({type:le,currency:le,decimals:Pt,locale:le},["type","currency"])],["scientific",ke({type:le,decimals:Pt,locale:le},["type"])],["date",ke({type:le,pattern:le},["type"])],["text",ke({type:le},["type"])]]),pu=ke({style:Rt(cu),color:le},["style"]),vr=e=>St(e,pu),hu=ke({top:vr,right:vr,bottom:vr,left:vr},[]),mu=ke({value:ss(fu),align:Rt(lu),verticalAlign:Rt(iu),wrap:Be,background:le,color:le,bold:Be,italic:Be,underline:Be,strikethrough:Be,fontFamily:le,fontSize:Pt,borders:e=>St(e,hu)},[]),gu=e=>St(e,mu),Ut={strict:Be,inputMessage:le,errorMessage:le},wu=new Map([["list",ke({...Ut,type:le,values:su(le),showDropdown:Be},["type","values"])],["number",ke({...Ut,type:le,op:Rt(Co),a:le,b:le},["type","op","a"])],["textLength",ke({...Ut,type:le,op:Rt(Co),a:Pt,b:Pt},["type","op","a"])],["date",ke({...Ut,type:le,op:Rt(Co),a:le,b:le},["type","op","a"])],["text",ke({...Ut,type:le,op:Rt(au),value:le},["type","op"])],["checkbox",ke({...Ut,type:le,checked:le,unchecked:le},["type"])],["custom",ke({...Ut,type:le,formula:le},["type","formula"])]]),Cu=ss(wu),yu=ke({startRow:st,startCol:st,endRow:st,endCol:st},["startRow","startCol","endRow","endCol"]),bu=e=>{if(!St(e,yu))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return st(t)&&st(r)&&st(n)&&st(o)&&t<=r&&n<=o},vu=ke({color:le,value:Pt},["color"]),yo=e=>St(e,vu),Ru=new Map([["cellValue",ke({type:le,op:Rt(uu),a:le,b:le},["type","op","a"])],["text",ke({type:le,op:Rt(du),value:le},["type","op","value"])],["empty",ke({type:le},["type"])],["notEmpty",ke({type:le},["type"])],["colorScale",ke({type:le,min:yo,mid:yo,max:yo},["type","min","max"])],["customFormula",ke({type:le,formula:le},["type","formula"])]]),ku=ke({background:le,color:le,bold:Be,italic:Be,underline:Be,strikethrough:Be},[]),Su=ke({sourceRuleId:le,ranges:Array.isArray,condition:ss(Ru),style:e=>St(e,ku),stopIfTrue:Be},["sourceRuleId","ranges","condition","style"]),Eu=(e,t,n)=>{if(!St(e,Su))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!bu(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},xu=ke({text:le,author:le,createdAt:le},["text","author","createdAt"]),Au=e=>St(e,xu),Ou=(e,t,n)=>{if(!or(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(!st(o)||o>=t)return!1;break;case"val":if(!st(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(Au)))return!1;break;default:return!1}}return!0},il=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(ou),Tu=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),ki=e=>{if(!or(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Tu.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(ll(t)&&ll(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(gu)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(Cu)))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(!Ou(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!il(e.colWidths,n)||e.rowHeights!==void 0&&!il(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Eu(c,t,n))},er=e=>Array.isArray(e)?`[${e.map(er).join(",")}]`:or(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${er(e[n])}`).join(",")}}`:JSON.stringify(e),Du=e=>{const t=it(e);return t===void 0?"{}":JSON.stringify(t)},Mu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,$u=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(Mu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Si=e=>{if(!ki(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(Du).join(","),r=e.validations.map(er).join(","),o=e.cells.map(u=>`[${u.map($u).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(er).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},qo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return ki(t)?t:null},Fu=/&(?:amp|lt|gt|quot|#39|nbsp);/g,zu=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),Ei=e=>e.includes("&")?e.replace(Fu,t=>zu[t]):e,Nu=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,cl=e=>{const t=e.length>Lo?e.slice(0,Lo):e,n=Nu.exec(Ei(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Lu=e=>{const t=e.indexOf(Po);if(t===-1)return null;const n=t+Po.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},xi=(e,t)=>{if(t==="event"&&e.types.includes(Hr))return{kind:"mime",json:e.getData(Hr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Lu(n);return r===null?null:{kind:"attribute",html:n,at:r}},Pu=(e,t)=>{const n=xi(e,t);return n===null?null:n.kind==="mime"?cl(n.json):cl(n.html.slice(n.at.start,n.at.start+Lo))},qu=(e,t)=>{const n=xi(e,t);if(n===null)return null;if(n.kind==="mime")return qo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:qo(Ei(n.html.slice(n.at.start,r)))},_u=/<google-sheets-html-origin[\s>]/,Iu='data-sheets-root="1"',ju=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Hu="mso-",Bu=/\.xl\d+\s*\{/,Vu="<table",Wu=e=>e.includes(Po)?"aqsp":_u.test(e)&&e.includes(Iu)?"sheets":ju.test(e)||e.includes(Hu)||Bu.test(e)?"excel":null,Ai=(e,t)=>{if(t==="event"&&e.types.includes(Hr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>sl?n.slice(0,sl):n,o=Wu(r);if(o==="aqsp")return"aqsp";if(n.includes(Vu))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},ls=1e3,Oi=65534,Ku=9,Yu=10,Uu=12,Xu=13,Gu=32,Ti=34,Di=39,Zu=43,is=47,al=48,Ju=57,Qu=61,ed=62,td=97,nd=98,rd=100,od=102,Mi=104,$i=114,Fi=116,sd=["able","body","head","foot"],Gn=e=>e===Gu||e===Ku||e===Yu||e===Xu||e===Uu,_o=e=>e===ed||e===is||Gn(e),ld=e=>Gn(e)||e===is||e===Ti||e===Di,id=(e,t,n,r)=>{if(t===0||!ld(e.charCodeAt(t-1)))return null;let o=t+n;for(;Gn(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Qu)return 1;for(o+=1;Gn(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===Ti||s===Di)&&(o+=1);Gn(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Zu&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=al&&u<=Ju;u=e.charCodeAt(o))l=l*10+(u-al),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},ul=(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=id(e,r,t.length,n);if(l!==null)return l}return 1}},cd=(e,t)=>{if(e.charCodeAt(t+2)!==Fi)return!1;const n=e.charCodeAt(t+3);if(n===$i)return _o(e.charCodeAt(t+4));if(n!==td&&n!==nd&&n!==Mi&&n!==od)return!1;for(const r of sd)if(e.startsWith(r,t+3)&&_o(e.charCodeAt(t+3+r.length)))return!0;return!1},ad=e=>{const t=e.toLowerCase(),n=ul(t,"colspan",ls),r=ul(t,"rowspan",Oi);let o=0;const s=I=>(o!==-1&&o<I&&(o=t.indexOf(">",I)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const y=new Map,_=(I,Y)=>{const B=y.get(I);y.set(I,B===void 0?Y:B+Y)},j=()=>{m&&u+h>c&&(c=u+h),m=!1},L=()=>{j(),l+=1,m=!0,u=0;const I=y.get(l-1);I!==void 0&&(h+=I)};for(let I=t.indexOf("<");I!==-1;I=t.indexOf("<",I+1)){const Y=t.charCodeAt(I+1);if(Y===is){cd(t,I)&&j();continue}if(Y!==Fi||!_o(t.charCodeAt(I+3)))continue;const B=t.charCodeAt(I+2);if(B===$i)L();else if(B===rd||B===Mi){m||L();const T=I+3,A=s(T),P=n(T,A);u+=P;const S=r(T,A);S>1&&(_(l,P),_(l-1+S,-P))}}return j(),{rows:l,cols:c}},zi=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}},Ni=()=>{const e=new WeakMap,t=zi(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=it(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},ud=()=>{const e=new WeakMap,t=zi(er);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}},dd=new Set(["http:","https:","mailto:","tel:"]),jt=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return dd.has(n.protocol)?n.href:null},On=e=>{if(e===void 0)return;const t=jt(e);return t===null?void 0:t},Li=(e,t)=>e.startCol===0&&e.endCol===t-1,Pi=(e,t)=>e.startRow===0&&e.endRow===t-1,Io=13,vt=Object.freeze({style:Object.freeze({}),lineBoxPx:Io,verticalAlign:"middle"}),fd={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:"#00000000"},pd=new Map(Object.entries(fd)),hd=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,md=/^rgba?\((.*)\)$/,qi=/^(\d+(?:\.\d+)?)%$/,Rr=e=>e.toString(16).padStart(2,"0"),bo=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},gd=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},wd=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=bo(t[0]),r=bo(t[1]),o=bo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Rr(n)}${Rr(r)}${Rr(o)}`;if(t.length===3)return s;const l=gd(t[3]);return l===null?null:l===255?s:`${s}${Rr(l)}`},Ve=e=>{const t=e.trim().toLowerCase(),n=hd.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=md.exec(t);if(r!==null)return wd(r[1]);const o=pd.get(t);return o===void 0?null:o},dl={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"}},fl=e=>{if(!Object.hasOwn(dl,e.style))return null;const t=dl[e.style],n=e.color===void 0?ts:Ve(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Cd={top:"flex-start",middle:"center",bottom:"flex-end"},yd=e=>e==="left"||e==="center"||e==="right",_i=e=>e==="top"||e==="middle"||e==="bottom",Ii=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,ji=(e,t)=>{if(typeof e.background=="string"){const s=Ve(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ve(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=Ii(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},kr=(e,t)=>{const n=e===void 0?null:fl(e);return n!==null?n:t===void 0?null:fl(t)},vo=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(yd(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=Xn(e.align)),_i(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Cd[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),ji(e,s));const c=e?.borders,u=kr(c?.right,t);u!==null&&(s.borderRight=u);const h=kr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=kr(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=kr(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},pl=new WeakMap,bd=(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:vo(void 0,s,l,r,o);if(!c)return vo(e,s,l,r,o);const u=pl.get(e);if(u!==void 0)return u;const h=vo(e,void 0,void 0,!1,!1);return pl.set(e,h),h},vd=e=>{if(e===void 0)return vt;const t={};ji(e,t);const n=Ii(e.fontSize),r=n===null?Io:Math.round(n),o=_i(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===Io&&o==="middle"?vt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Rd="#REF!",kd=11,Sd=15,Ed=4096,Nr=33,Zn=34,cs=36,xd=38,jo=39,Hi=40,Ad=42,Od=43,Td=44,Bi=45,Dd=46,Md=47,bn=58,$d=59,Fd=60,Vi=61,zd=62,Nd=67,Ld=82,Ur=91,Wi=93,Pd=94,qd=95,Ki=e=>e>=65&&e<=90||e>=97&&e<=122,Yi=e=>e>=48&&e<=57,as=e=>Ki(e)||Yi(e)||e===qd||e===Dd||e===cs||e>=128,_d=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,Id=e=>e===Vi||e===Hi||e===Td||e===$d||e===Od||e===Bi||e===Ad||e===Md||e===Pd||e===xd||e===Fd||e===zd||e===bn,Ui=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(as(n)||n===Hi||n===Nr||n===Ur)},hl=(e,t)=>{let n=t;for(;n<e.length&&as(e.charCodeAt(n));)n+=1;return n},Ho=(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},jd=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===jo){r+=2;continue}if(o===Ur)n+=1;else if(o===Wi&&(n-=1,n===0))return r+1;r+=1}return e.length},ml=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Ui(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Xi=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===Zn){o=Ho(e,o,Zn);continue}if(s===jo){const u=Ho(e,o,jo);o=e.charCodeAt(u)===Nr?ml(e,o,u,t,n):u;continue}if(s===Ur){o=jd(e,o);continue}if(!as(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Ui(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=hl(e,o);if(e.charCodeAt(c)===bn){const u=hl(e,c+1);u>c+1&&e.charCodeAt(u)===Nr&&(c=u)}o=e.charCodeAt(c)===Nr?ml(e,o,c,t,n):c}return n},Ro=(e,t)=>{let n=t;const r=e.charCodeAt(n)===cs;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Ki(l))break;if(s+=1,s>kd)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Bo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Yi(o))break;if(n-t>=Sd)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Sr=(e,t)=>{const n=e.charCodeAt(t)===cs,r=Bo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Hd=(e,t)=>{const n=Ro(e,t);if(n!==null){const o=Sr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===bn){const s=Ro(e,o.end+1);if(s!==null){const l=Sr(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)===bn){const s=Ro(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=Sr(e,t);if(r!==null&&e.charCodeAt(r.end)===bn){const o=Sr(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},sr=e=>Xi(e,Hd),Gi=(e,t=Ed)=>{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}},Vo=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},ko=e=>`${e.absCol?"$":""}${Vo(e.col)}${e.absRow?"$":""}${e.row+1}`,us=e=>e.sheet===void 0?"":`${e.sheet}!`,qt=e=>{const t=us(e);switch(e.kind){case"cell":return`${t}${ko(e)}`;case"range":return`${t}${ko(e.start)}:${ko(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${Vo(e.start.col)}:${e.end.abs?"$":""}${Vo(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},mn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Bd=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(mn(n.startRow,"formatRangeReference startRow"),mn(n.startCol,"formatRangeReference startCol"),mn(n.endRow,"formatRangeReference endRow"),mn(n.endCol,"formatRangeReference endCol"),t){case"columns":return qt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return qt({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?qt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):qt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},ds=(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?`${us(s.token)}${Rd}`:l),o=s.end}return r+e.slice(o)},Xr=e=>e.charCodeAt(0)===Vi,So=(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}},Vd=(e,t,n)=>{switch(e.kind){case"cell":{const r=So(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=So(e.start,t,n),o=So(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}}}}},Zi=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Xr(e)?ds(e,sr(e),r=>{const o=Vd(r,t,n);return o===null?null:qt(o)}):e},Ji=(e,t)=>{mn(e.row,`${t} origin.row`),mn(e.col,`${t} origin.col`)},gn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Eo=(e,t)=>`${gn("R",e.row,e.absRow,t.row)}${gn("C",e.col,e.absCol,t.col)}`,Wd=(e,t)=>{const n=us(e);switch(e.kind){case"cell":return`${n}${Eo(e,t)}`;case"range":return`${n}${Eo(e.start,t)}:${Eo(e.end,t)}`;case"column":return`${n}${gn("C",e.start.col,e.start.abs,t.col)}:${gn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${gn("R",e.start.row,e.start.abs,t.row)}:${gn("R",e.end.row,e.end.abs,t.row)}`}},Gr=(e,t)=>(Ji(t,"toR1C1"),Xr(e)?ds(e,sr(e),n=>Wd(n,t)):e),gl=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Ur){const l=e.charCodeAt(o+1)===Bi,c=Bo(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Wi?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Bo(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}}},wl=(e,t)=>{const n=gl(e,t,Ld),r=gl(e,n===null?t:n.end,Nd);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}},Kd=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}}},Yd=(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,Ud=(e,t)=>{const n=wl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===bn){const r=wl(e,n.end+1);if(r!==null){const o=Yd(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Kd(n)}},Xd=e=>Xi(e,Ud),Gd=Gi(Xd),wn=(e,t)=>e.rel?t+e.n:e.n-1,Cl=(e,t)=>{const n=wn(e.row,t.row),r=wn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},Zd=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Cl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Cl(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=wn(e.start,t.row),s=wn(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=wn(e.start,t.col),s=wn(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}}}},lr=(e,t)=>(Ji(t,"fromR1C1"),Xr(e)?ds(e,Gd(e),n=>{const r=Zd(n,t);return r===null?null:qt(r)}):e),yl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Jd=e=>{switch(e.kind){case"cell":return{...e,...yl(e.absCol,e.absRow)};case"range":{const t=yl(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}}}}},Qi=(e,t)=>Xr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,ec=(e,t)=>{if(!Qi(e,t))return null;for(const n of sr(e))if(n.start<=t&&t<=n.end)return n;return null},Qd=(e,t)=>{const n=ec(e,t);if(n===null)return null;const r=qt(Jd(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},bl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===Zn){const s=Ho(e,r,Zn);if(s>t)return!1;n=Zn,r=s;continue}_d(o)||(n=o),r+=1}return Id(n)},tc=(e,t)=>{if(!Qi(e,t))return null;for(const n of sr(e))if(n.start<=t&&t<=n.end)return bl(e,n.start)?{replace:[n.start,n.end]}:null;return bl(e,t)?{insertAt:t}:null},xn=[{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}],Zr=(e,t)=>`[$${e}-${t}]`,ef=new Map(xn.map(e=>[Zr(e.symbol,e.lcid),e])),tf=new Map(xn.filter((e,t)=>xn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(xn.map(e=>[Zr(e.symbol,e.lcid),e.code]));const nf=new Set([...xn.map(e=>e.symbol),...xn.map(e=>e.code),"¥"]),rf=20,of="yyyy/MM/dd",nc=/yyyy|MM|dd|HH|mm|ss/g,rc=" -+/():!^&'~{}<>=",sf="$¥€£₩₹¥",Wo=e=>{let t="",n=0;for(;n<e.length;){const r=e[n];if(r!=="\\"){t+=r,n+=1;continue}const o=e.slice(n+1,n+5);if(/^[0-9a-fA-F]{4}$/.test(o)){t+=String.fromCharCode(Number.parseInt(o,16)),n+=5;continue}if(n+1<e.length){t+=e[n+1],n+=2;continue}t+=r,n+=1}return t},lf=e=>{let t=0;for(;t<e.length;){const n=e[t];if(n==='"'){const r=e.indexOf('"',t+1);t=r<0?e.length:r+1}else if(n==="["){const r=e.indexOf("]",t+1);t=r<0?e.length:r+1}else if(n==="\\"||n==="_"||n==="*")t+=2;else{if(n===";")return e.slice(0,t);t+=1}}return e},cf=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const y=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:y}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(rc.includes(o)||sf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ot=e=>e===void 0?{}:{locale:e},af=/^(0|#,##0)(?:\.(0+))?$/,vl=(e,t,n,r)=>{if(t!==null){const o=ef.get(Zr(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!nf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ot(r.locale)}},uf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const L of e)switch(L.kind){case"locale":break;case"literal":r?u+=L.text:c+=L.text;break;case"digits":if(r)return;n=L.text,r=!0;break;case"currency":if(o!==null)return;o=L;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=af.exec(n);if(h===null)return;const m=h[1]==="#,##0",y=h[2]===void 0?0:h[2].length,_=c.trim(),j=u.trim();if(s)return l===0&&o===null&&!m&&_===""&&j===""?{type:"scientific",decimals:y,...ot(t.locale)}:void 0;if(l>0)return l===1&&o===null&&_===""&&j===""?{type:"percent",decimals:y,...ot(t.locale)}:void 0;if(j==="%"&&_===""&&o===null)return{type:"percent",decimals:y,scale:!1,...ot(t.locale)};if(o!==null)return _===""&&j===""?vl(o.symbol,o.lcid,y,t):void 0;if(!(_!==""&&j!==""))return _!==""||j!==""?vl(_+j,null,y,t):{type:"number",decimals:y,...m?{grouping:!0}:{},...ot(t.locale)}},df=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),ff=(e,t)=>{const n=[...e.matchAll(nc)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},pf=e=>{const t=e.flatMap(s=>s.kind==="date"?[s.text]:[]),n=[];let r="",o=0;for(const s of e){if(s.kind==="locale")continue;if(s.kind==="literal"){r+=s.text;continue}if(s.kind!=="date")return;const l=s.text==="mm"?t[o-1]==="hh"||t[o+1]==="ss"?"mm":"MM":df.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&ff(r,n)?{type:"date",pattern:r}:void 0},hf=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ot(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ot(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ot(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ot(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ot(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ot(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),fs=(e,t)=>{const n=lf(e).trim(),r=hf.get(n);if(r!==void 0)return r(t);const o=cf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return uf(o,t);if(o.some(s=>s.kind==="date"))return pf(o)}},mf=(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:fs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},Kn=e=>e===0?"":`.${"0".repeat(e)}`,Lr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=rf,gf=`${rc}.,`,Rl=e=>e.includes('"')?null:[...e].every(t=>gf.includes(t))?e:`"${e}"`,wf=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(nc)){const u=Rl(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=Rl(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=fs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Cf=e=>{const t=tf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Lr(n))return null;const r=`#,##0${Kn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Zr(t.symbol,t.lcid)}${r}`},oc=e=>{switch(e.type){case"text":return"@";case"date":return wf(e.pattern===void 0?of:e.pattern);case"number":return Lr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${Kn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Lr(t)?e.scale===!1?`0${Kn(t)}"%"`:`0${Kn(t)}%`:null}case"scientific":return Lr(e.decimals)?`0${Kn(e.decimals)}E+00`:null;case"currency":return Cf(e);default:return null}},kl="-−",yf=(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("")},bf=(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=yf(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},vf=(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},Rf=(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 m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let y=0,_=0,j=0,L="";for(const P of o.slice(0,h))kl.includes(P)?y+=1:P==="("?_+=1:L+=P;for(const P of o.slice(m))kl.includes(P)?y+=1:P===")"?j+=1:L+=P;const I=y+_;if(_!==j||I>1||I===1&&s||(s=s||I===1,r!=="currency"&&L.trim()!==""))return e;const Y=bf(o.slice(h,m).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,T=Y.exponent+B;if(T>330||T<-330)return e;const A=vf(Y.integer,Y.fraction,T,s);return Number.isFinite(Number(A))?A:e},Sl="google-sheets-html-origin",sc=Object.freeze({group:",",decimal:"."}),El=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"}),lc=["top","right","bottom","left"],kf=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Sf=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Ef=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"]),xl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],xf=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Af=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Of=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"]),Tf=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Df=3,Mf=1,ic=-25569,Pr=86400,$f=-693959,Ff=2958465,zf=" ",Jr=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,m)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},Br=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},ps=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},Nf=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Lf=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),y=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const _=Jr(y);for(const j of m.split(",")){const L=j.trim(),I=Nf.exec(L);if(I!==null){const Y=t.get(I[1]);if(Y===void 0)t.set(I[1],new Map(_));else for(const[B,T]of _)Y.set(B,T)}else if(L.toLowerCase()==="table"){const Y=_.get("mso-displayed-decimal-separator"),B=_.get("mso-displayed-thousand-separator");Y!==void 0&&(n=Wo(Br(Y))),B!==void 0&&(r=Wo(Br(B)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:sc}},Pf="%_-*? ",qf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Pf.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},_f=(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},cc=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}},pn=(e,t)=>String(e).padStart(t,"0"),ac=e=>{if(e<$f||e>Ff)return null;let t=Math.floor(e),n=Math.round((e-t)*Pr);n>=Pr&&(t+=1,n-=Pr);const r=cc(t+ic),o=`${pn(r.year,4)}-${pn(r.month,2)}-${pn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${pn(s,2)}:${pn(l,2)}:${pn(n%60,2)}`},If=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,jf=e=>{const t=If.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=_f(n,r,o),h=cc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-ic+(s*3600+l*60+c)/Pr},hs=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),Xt=e=>hs(e).replaceAll('"',"""),uc=e=>hs(e).replaceAll("'","'"),Hf=e=>hs(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(" ","	"),qr=(e,t)=>`${e}="${Xt(JSON.stringify(t))}"`,dc=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Bf=e=>{if(Xe(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Vf=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Wf=e=>{if(e.type==="text")return{1:1};const t=oc(e);return t===null?null:{1:e.type==="date"?Vf(e.pattern===void 0?"yyyy/MM/dd":e.pattern):xf[e.type],2:t,3:1}},Kf=/[;"'{}<>&\\]/,fc=e=>e==="left"||e==="center"||e==="right",pc=e=>e==="top"||e==="middle"||e==="bottom",Yf=e=>{const t=[];e.bold===!0&&t.push("font-weight:bold"),e.italic===!0&&t.push("font-style:italic");const n=[...e.underline===!0?["underline"]:[],...e.strikethrough===!0?["line-through"]:[]];n.length>0&&t.push(`text-decoration:${n.join(" ")}`);const r=typeof e.color=="string"?Ve(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Ve(e.background):null;if(o!==null&&t.push(`background-color:${o}`),fc(e.align)&&t.push(`text-align:${e.align}`),pc(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Kf.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 lc){const l=e.borders[s];if(l===void 0||!Object.hasOwn(El,l.style))continue;const c=l.color===void 0?"windowtext":Ve(l.color);c!==null&&t.push(`border-${s}:${El[l.style]} ${c}`)}if(e.value!==void 0){const s=oc(e.value);s!==null&&t.push(`mso-number-format:"${qf(s)}"`)}return t},Uf={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Xf=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=uc([n,...Yf(e)].join(";"));let o=null;if(t!==void 0){const s=Wf(t);s!==null&&(o=qr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},Gf=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:En(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&dc(o)?Bf(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?jf(e.t):null,h=[];if(l?h.push(qr("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(qr("data-sheets-value",{1:3,3:c})):u!==null&&h.push(qr("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${Xt(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${Xt(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${Xt(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${Xt(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const _=lr(e.f,{row:n,col:r});_.includes("#REF!")||h.push(`x:fmla="${Xt(_)}"`)}const m=Hf(s),y=e.link===void 0?m:`<a href="${Xt(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(_=>` ${_}`).join("")}>${y}</td>`},hc=(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(Xf);let o="";for(let s=0;s<e.rows;s+=1){const l=e.rowHeights===void 0?"":` height="${e.rowHeights[s]}" style="height:${e.rowHeights[s]}px;"`;let c="";for(let u=0;u<e.cols;u+=1){const h=e.cells[s][u],m=h.fmt===void 0?void 0:r[h.fmt];c+=Gf(h,m===void 0?Uf:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${Sl}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Ri}='${uc(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${Sl}>`},Ko=(e,t)=>{for(const[n,r]of t)e.set(n,r)},mc=(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&&Ko(n,l)}const o=e.getAttribute("style");return o!==null&&Ko(n,Jr(o)),n},Zf=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"}},Jf=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"},Qf=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),ep={pt:1.5,unit:"px"},Al=e=>{let t=null,n=null;const r=[];for(const u of ps(e)){const h=u.toLowerCase(),m=Zf(u);kf.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=Qf.get(n),s=o===void 0?Jf(t===null?ep:t):o,l=r.join(" ");if(l===""||Sf.has(l.toLowerCase()))return{style:s};const c=Ve(l);return c===null||c.length===9?null:{style:s,color:c}},tp=e=>e.style==="thin"&&e.color==="#cccccc",np=e=>{const t=Ve(e);if(t!==null)return t;for(const n of ps(e)){const r=Ve(n);if(r!==null)return r}return null},rp=e=>{const t=Br(ps(e.split(",")[0]).join(" ").trim()).trim();return t===""||Ef.has(t.toLowerCase())?null:t},op=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},sp=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},lp=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"},ip=new Set(["normal","pre-wrap","pre-line"]),cp=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const E=o.toLowerCase();(E==="bold"||E==="bolder"||Number(E)>=600)&&(r.bold=!0)}const s=e.get("font-style");s!==void 0&&(s.toLowerCase()==="italic"||s.toLowerCase().startsWith("oblique"))&&(r.italic=!0);const l=sp(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),u=c===void 0?null:Ve(c);u!==null&&u.length!==9&&(r.color=u);const h=e.has("background-color")?e.get("background-color"):e.get("background"),m=h===void 0?null:np(h);m!==null&&m.length!==9&&(r.background=m);const y=e.get("text-align"),_=y===void 0?"":y.toLowerCase();fc(_)&&(r.align=_);const j=e.get("vertical-align"),L=j===void 0?"":j.toLowerCase();pc(L)&&(r.verticalAlign=L);const I=e.get("font-family"),Y=I===void 0?null:rp(I);Y!==null&&(r.fontFamily=Y);const B=e.get("font-size"),T=B===void 0?null:op(B);T!==null&&(r.fontSize=T);const A=e.get("white-space");A!==void 0&&ip.has(A.toLowerCase())&&(r.wrap=!0);const P={},S=e.get("border"),R=S===void 0?null:Al(S);for(const E of lc){const f=e.get(`border-${E}`),g=f===void 0?R:Al(f);g!==null&&!(n==="sheets"&&tp(g))&&(P[E]=g)}return Object.keys(P).length>0&&(r.borders=P),r},Ol=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
6
|
`)&&(e.text+=`
|
|
7
|
-
`)},
|
|
8
|
-
`);continue}if(o.nodeType!==
|
|
9
|
-
`;continue}const c=t.mode==="collapse"&&
|
|
10
|
-
`).map(
|
|
7
|
+
`)},ap=e=>{const t=e.getAttribute("style");return t!==null&&Jr(t).get("mso-spacerun")==="yes"},up=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Tf.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&Ol(t);continue}const o=r.node;if(o.nodeType===Df){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!==Mf)continue;const s=o,l=s.localName;if(Af.has(l)||ap(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&Of.has(l);if(c&&Ol(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})}},dp=(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&&pp(l.element,t,n,r)},fp=(e,t)=>{const n=e.replaceAll(zf," ");if(t==="pre")return n;const r=n.split(`
|
|
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
|
-
`)},tp=(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"),i=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),i!==null&&i.trim()!==""&&t.set("font-family",i)}_o(t,oc(e,r))},np=(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"?Jl(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 i=s[1];return typeof i=="number"&&i>=1&&i<mi.length?mi[i]:null}return null},sc=(e,t,n)=>t!==void 0&&ec(t)?uf(e,t,n):e,rp=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const i=e.getAttribute("x:err");if(i!==null)return i===""?t:i;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&Ze(c)!==null)if(n!==void 0&&n.type==="date"){const a=Jl(Number(c));if(a!==null)return a}else return c;return sc(t,n,r)},op=(e,t,n,r)=>{const o=oc(e,r.rules),s={underline:!1,strikethrough:!1},i={text:"",runs:[],href:null,mode:Uf(o)};for(const p of cp(e))Jf(p,i);Qf(i,o,s,r.rules);const c=ep(i.text,i.mode),a=Gf(o,s,r.kind),m={t:""};if(r.kind==="sheets"){const p=e.getAttribute("data-sheets-numberformat"),S=p===null?void 0:nf(p,r.options);S!==void 0&&(a.value=S);const N=e.getAttribute("data-sheets-value"),P=N===null?null:np(N,S);m.t=P===null?sc(c,S,Ul):P;const T=e.getAttribute("data-sheets-formula");T?.startsWith("=")&&(m.f=T);const q=e.getAttribute("data-sheets-hyperlink"),K=q!==null?q:i.href,k=K===null?null:It(K);k!==null&&(m.link=k);const L=e.getAttribute("data-sheets-note");L!==null&&L!==""&&(m.note=L)}else{const p=o.get("mso-number-format"),S=p===void 0?void 0:os(qo(Lr(p)),r.options);S!==void 0&&(a.value=S),m.t=rp(e,c,S,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(m.f=Vr(N,{row:t,col:n}));const P=i.href===null?null:It(i.href);P!==null&&(m.link=P)}return{cell:m,format:a}},Io=(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},sp=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)},ip=(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]))},ic=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Yr(n);if(r!==null){const s=r.get("display");if(s!==void 0&&s.toLowerCase()==="none")return 0;const i=r.get(t),c=i===void 0?null:sp(i);if(c!==null)return Math.min(c,bn)}const o=ip(e,t);return o===null?null:Math.min(o,bn)},lp=(e,t)=>{const n=[],r=o=>{const s=ic(o,"width");for(let i=Io(o,"span",Jo);i>0&&n.length<t;i-=1)n.push(s)};for(const o of Un(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Un(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Un(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*cp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*ap(e){for(const t of["thead","tbody","tfoot"])for(const n of Un(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Un(n))o.localName==="tr"&&(yield o)}}const bo=()=>({t:""}),up=(e,t,n)=>{const r=Sl(),o=[],s=[],i=[];let c=0;for(const P of ap(e)){const T=o.length,q=(T+1)*Math.max(c,1);if(q>n)return{outcome:"limit",cells:q};const K=[];for(let L=0;L<i.length;L+=1)i[L]>0&&(K[L]=bo(),i[L]-=1);let k=0;for(const L of Un(P)){const D=L.localName;if(D!=="td"&&D!=="th")continue;for(;K[k]!==void 0;)k+=1;const x=Io(L,"colspan",Jo),A=Io(L,"rowspan",wl),h=(T+1)*Math.max(c,k+x);if(h>n)return{outcome:"limit",cells:h};const g=op(L,T,k,t),w=r.intern(g.format);w!==void 0&&(g.cell.fmt=w),K[k]=g.cell;for(let E=1;E<x;E+=1)K[k+E]===void 0&&(K[k+E]=bo());if(A>1)for(let E=0;E<x;E+=1){const y=A-1,z=k+E;i[z]=i[z]===void 0||i[z]<y?y:i[z]}k+=x}K.length>c&&(c=K.length),o.push(K),s.push(ic(P,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map(P=>{const T=[];for(let q=0;q<c;q+=1){const K=P[q];T.push(K===void 0?bo():K)}return T}),m=lp(e,c),p=m.length===c&&m.every(P=>P!==null)?m.map(P=>P===null?0:P):void 0,S=s.every(P=>P!==null)?s.map(P=>P===null?0:P):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:Go(),formats:[...r.entries],validations:[],cells:a,...p===void 0?{}:{colWidths:p},...S===void 0?{}:{rowHeights:S},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 i=Sf(o);return up(s,{kind:t,rules:i,options:n,separators:i.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)}),Qt=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,Je=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),Pr=e=>e.reduce((t,n)=>t+Je(n).rows*Je(n).cols,0),Nt=(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 i=`${o}:${s}`;n.has(i)||(n.add(i),t({row:o,col:s}))}},er=(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)}},vt=(e,t)=>e.row===t.row&&e.col===t.col,cc=(e,t)=>e===void 0?Ks(void 0,void 0,t()):Ks(e.align,e.value,e.align===void 0?t():""),$r=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Rn=(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}},Fr=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}),dp=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=Je(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},ac=(e,t,n,r,o,s)=>{const i=e.length,c=e[0]?.length??0;if(i===0||c===0)return[];const a=Je(t),m=a.rows===1&&a.cols===1,p=!m&&a.rows%i===0&&a.cols%c===0,S=p?a.rows:i,N=p?a.cols:c,P=m?n:{row:t.startRow,col:t.startCol},T=Math.min(S,r-P.row),q=Math.min(N,o-P.col),K=[];for(let k=0;k<T;k+=i){const L=[];for(let x=0;x<q;x+=c){const A={row:P.row+k,col:P.col+x};L.push(A),K.push(A)}const D=Math.min(i,T-k);for(let x=0;x<D;x+=1){const A=P.row+k+x,h=e[x];for(let g=0;g<L.length;g+=1){const w=g*c,E=Math.min(c,q-w);for(let y=0;y<E;y+=1)s(A,P.col+w+y,h[y],L[g])}}}return K},fp=(e,t,n,r,o)=>{const s=[];return ac(e,t,n,r,o,(i,c,a)=>{s.push({row:i,col:c,text:a})}),s},Ci=(e,t,n,r,o,s)=>{const i=[],c=ac(e,t,n,r,o,(a,m,p,S)=>{const N=s(p,a,m,S);N!==null&&i.push({...N,row:a,col:m})});return{edits:i,tiles:c}},uc=(e,t)=>{const n=t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol,r=t.startRow!==e.startRow||t.endRow!==e.endRow||t.startCol!==e.startCol||t.endCol!==e.endCol;if(!(n&&r))throw new RangeError(`[spreadsheet] expandFill requires a box strictly containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`)},pp=(e,t)=>{uc(e,t);const n=Je(t),r=Je(e),o=n.rows-r.rows,s=n.cols-r.cols,i=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+i*c},hp=(e,t,n,r)=>{uc(t,n);const o=Je(t).rows,s=Je(t).cols,i=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const m=t.startRow+((a-t.startRow)%o+o)%o,p=a>=t.startRow&&a<=t.endRow;for(let S=n.startCol;S<=n.endCol;S+=1){if(p&&S>=t.startCol&&S<=t.endCol)continue;const N=t.startCol+((S-t.startCol)%s+s)%s,P=m*2**21+N;let T=c.get(P);T===void 0&&(T={value:e(m,N),origin:{row:m,col:N}},c.set(P,T)),i.push(r(T.value,T.origin,{row:a,col:S}))}}return i},dc=(e,t,n)=>{const r=Rn(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:lt(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=kn(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},fc=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Il(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},pc=e=>`${e.map(t=>t.map(mp).join(" ")).join(`\r
|
|
12
|
+
`)},pp=(e,t,n,r)=>{const o=e.localName;if(o==="b"||o==="strong")t.set("font-weight","bold");else if(o==="i"||o==="em")t.set("font-style","italic");else if(o==="u")n.underline=!0;else if(o==="s"||o==="strike"||o==="del")n.strikethrough=!0;else if(o==="font"){const s=e.getAttribute("color"),l=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),l!==null&&l.trim()!==""&&t.set("font-family",l)}Ko(t,mc(e,r))},hp=(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"?ac(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<xl.length?xl[l]:null}return null},gc=(e,t,n)=>t!==void 0&&dc(t)?Rf(e,t,n):e,mp=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&Xe(c)!==null)if(n!==void 0&&n.type==="date"){const u=ac(Number(c));if(u!==null)return u}else return c;return gc(t,n,r)},gp=(e,t,n,r)=>{const o=mc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:lp(o)};for(const m of bp(e))up(m,l);dp(l,o,s,r.rules);const c=fp(l.text,l.mode),u=cp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),y=m===null?void 0:mf(m,r.options);y!==void 0&&(u.value=y);const _=e.getAttribute("data-sheets-value"),j=_===null?null:hp(_,y);h.t=j===null?gc(c,y,sc):j;const L=e.getAttribute("data-sheets-formula");L?.startsWith("=")&&(h.f=L);const I=e.getAttribute("data-sheets-hyperlink"),Y=I!==null?I:l.href,B=Y===null?null:jt(Y);B!==null&&(h.link=B);const T=e.getAttribute("data-sheets-note");T!==null&&T!==""&&(h.note=T)}else{const m=o.get("mso-number-format"),y=m===void 0?void 0:fs(Wo(Br(m)),r.options);y!==void 0&&(u.value=y),h.t=mp(e,c,y,r.separators);const _=e.getAttribute("x:fmla");_?.startsWith("=")&&(h.f=Gr(_,{row:t,col:n}));const j=l.href===null?null:jt(l.href);j!==null&&(h.link=j)}return{cell:h,format:u}},Yo=(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},wp=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)},Cp=(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]))},wc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Jr(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:wp(l);if(c!==null)return Math.min(c,Sn)}const o=Cp(e,t);return o===null?null:Math.min(o,Sn)},yp=(e,t)=>{const n=[],r=o=>{const s=wc(o,"width");for(let l=Yo(o,"span",ls);l>0&&n.length<t;l-=1)n.push(s)};for(const o of tr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of tr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*tr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*bp(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*vp(e){for(const t of["thead","tbody","tfoot"])for(const n of tr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of tr(n))o.localName==="tr"&&(yield o)}}const xo=()=>({t:""}),Rp=(e,t,n)=>{const r=Ni(),o=[],s=[],l=[];let c=0;for(const j of vp(e)){const L=o.length,I=(L+1)*Math.max(c,1);if(I>n)return{outcome:"limit",cells:I};const Y=[];for(let T=0;T<l.length;T+=1)l[T]>0&&(Y[T]=xo(),l[T]-=1);let B=0;for(const T of tr(j)){const A=T.localName;if(A!=="td"&&A!=="th")continue;for(;Y[B]!==void 0;)B+=1;const P=Yo(T,"colspan",ls),S=Yo(T,"rowspan",Oi),R=(L+1)*Math.max(c,B+P);if(R>n)return{outcome:"limit",cells:R};const E=gp(T,L,B,t),f=r.intern(E.format);f!==void 0&&(E.cell.fmt=f),Y[B]=E.cell;for(let g=1;g<P;g+=1)Y[B+g]===void 0&&(Y[B+g]=xo());if(S>1)for(let g=0;g<P;g+=1){const b=S-1,$=B+g;l[$]=l[$]===void 0||l[$]<b?b:l[$]}B+=P}Y.length>c&&(c=Y.length),o.push(Y),s.push(wc(j,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(j=>{const L=[];for(let I=0;I<c;I+=1){const Y=j[I];L.push(Y===void 0?xo():Y)}return L}),h=yp(e,c),m=h.length===c&&h.every(j=>j!==null)?h.map(j=>j===null?0:j):void 0,y=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:os(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...y===void 0?{}:{rowHeights:y},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Cc=(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=Lf(o);return Rp(s,{kind:t,rules:l,options:n,separators:l.separators},r)},me=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),en=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,Ge=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),pt=e=>e.reduce((t,n)=>t+Ge(n).rows*Ge(n).cols,0),Lt=(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}))}},ir=(e,t,n)=>{if(t<=0||n<=0)throw new RangeError(`[spreadsheet] clampCoord requires a non-empty grid, received ${t} x ${n}`);return{row:Math.min(Math.max(Math.trunc(e.row),0),t-1),col:Math.min(Math.max(Math.trunc(e.col),0),n-1)}},kt=(e,t)=>e.row===t.row&&e.col===t.col,yc=(e,t)=>e===void 0?ol(void 0,void 0,t()):ol(e.align,e.value,e.align===void 0?t():""),_r=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},An=(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}},Ir=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}),bc=e=>e.isCellReadOnly!==void 0,je=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Yn=(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},Cn=(e,t)=>{for(const n of t)if(Yn(e,n))return!0;return!1},kp=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=Ge(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Uo=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=Ge(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},y=Math.min(u,r-m.row),_=Math.min(h,o-m.col);return y<=0||_<=0?null:me(m,{row:m.row+y-1,col:m.col+_-1})},vc=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=Uo({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,y=u.endCol-u.startCol+1,_=[];for(let j=0;j<m;j+=l){const L=[];for(let Y=0;Y<y;Y+=c){const B={row:h.row+j,col:h.col+Y};L.push(B),_.push(B)}const I=Math.min(l,m-j);for(let Y=0;Y<I;Y+=1){const B=h.row+j+Y,T=e[Y];for(let A=0;A<L.length;A+=1){const P=A*c,S=Math.min(c,y-P);for(let R=0;R<S;R+=1)s(B,h.col+P+R,T[R],L[A])}}}return _},Sp=(e,t,n,r,o)=>{const s=[];return vc(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},Tl=(e,t,n,r,o,s)=>{const l=[],c=vc(e,t,n,r,o,(u,h,m,y)=>{const _=s(m,u,h,y);_!==null&&l.push({..._,row:u,col:h})});return{edits:l,tiles:c}},Rc=(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)})`)},Ep=(e,t)=>{Rc(e,t);const n=Ge(t),r=Ge(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},xp=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(me({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(me({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(me({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(me({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Ap=(e,t,n,r)=>{Rc(t,n);const o=Ge(t).rows,s=Ge(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let y=n.startCol;y<=n.endCol;y+=1){if(m&&y>=t.startCol&&y<=t.endCol)continue;const _=t.startCol+((y-t.startCol)%s+s)%s,j=h*2**21+_;let L=c.get(j);L===void 0&&(L={value:e(h,_),origin:{row:h,col:_}},c.set(j,L)),l.push(r(L.value,L.origin,{row:u,col:y}))}}return l},kc=(e,t,n)=>{const r=An(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:it(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=On(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},Sc=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Zi(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},Ec=e=>`${e.map(t=>t.map(Op).join(" ")).join(`\r
|
|
13
13
|
`)}\r
|
|
14
|
-
`,
|
|
14
|
+
`,Op=e=>/[\t\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e,xc=e=>e.endsWith(`\r
|
|
15
15
|
`)?e.slice(0,-2):e.endsWith(`
|
|
16
|
-
`)||e.endsWith("\r")?e.slice(0,-1):e,
|
|
17
|
-
`?2:1,n())}},
|
|
18
|
-
`||e[o]==="\r")&&/[\t\r\n]/.test(n)?{value:n,nextIndex:o}:null}else n+=e[r],r+=1;return null},
|
|
19
|
-
`||e[n]==="\r")return n;return e.length},Wn=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},Cp=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},Kr=["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"],bp=/^[A-Z]$/,yp=/^[A-Za-z]$/,vp=/^Key([A-Z])$/,wc=new Set([...Array.from({length:10},(e,t)=>`Digit${t}`),...Array.from({length:10},(e,t)=>`Numpad${t}`),"NumpadAdd","NumpadSubtract","NumpadMultiply","NumpadDivide","NumpadDecimal","NumpadEnter",...Array.from({length:12},(e,t)=>`F${t+1}`),"Semicolon","Quote","Comma","Period","Slash","Backslash","BracketLeft","BracketRight","Backquote","Minus","Equal","IntlYen","IntlRo","IntlBackslash","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Rp=e=>bp.test(e)||wc.has(e),Xt=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const i=t[n];if(n!==t.length-1||i===void 0||!Rp(i))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:i}},kp=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Cc=e=>{if(yp.test(e.key))return e.key.toUpperCase();const t=vp.exec(e.code);return t!==null?t[1]:wc.has(e.code)?e.code:null},Nn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Cc(t)===e.key,fe=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),we=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Sp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(fe(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(fe(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(fe(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(fe(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Ep=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(fe(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(fe(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},tr=[...Sp(),fe("Home","idle","row start (first visible column)"),fe("Ctrl+Home","idle","first visible cell"),fe("Shift+Home","idle","extend to row start"),fe("Ctrl+Shift+Home","idle","extend to first visible cell"),fe("End","idle","row end (last visible column)"),fe("Ctrl+End","idle","last visible cell"),fe("Shift+End","idle","extend to row end"),fe("Ctrl+Shift+End","idle","extend to last visible cell"),fe("PageUp","both","page up (idle) / commit + page up (editing)"),fe("PageDown","both","page down (idle) / commit + page down (editing)"),fe("Shift+PageUp","idle","extend one page up"),fe("Shift+PageDown","idle","extend one page down"),fe("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),fe("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),fe("Tab","both","cycle right (idle) / commit + cycle right (editing)"),fe("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),fe("Enter","both","cycle down (idle) / commit + cycle down (editing)"),fe("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),fe("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),fe("F2","both","start editing (idle) / toggle the pointing arm (editing)"),fe("F4","editing","cycle the reference anchor under the caret (formula session)"),fe("Delete","idle","clear every selected cell"),fe("Backspace","idle","clear every selected cell"),fe("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),fe("Ctrl+A","idle","select all"),fe("Ctrl+Z","idle","undo request"),fe("Ctrl+Y","idle","redo request"),fe("Ctrl+Shift+Z","idle","redo request"),fe("Shift+F10","idle","keyboard context menu"),fe("ContextMenu","idle","keyboard context menu"),fe("Ctrl+Space","idle","column bands"),fe("Shift+Space","idle","row bands"),fe("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),fe("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),fe("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),fe("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"},...Ep(),we("bold","Ctrl+B","both","toggle bold"),we("italic","Ctrl+I","both","toggle italic"),we("underline","Ctrl+U","both","toggle underline"),we("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),we("clearFormatting","Ctrl+Backslash","idle","clear formatting"),we("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),we("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),we("alignLeft","Ctrl+Shift+L","both","align left"),we("alignCenter","Ctrl+Shift+E","both","align center"),we("alignRight","Ctrl+Shift+R","both","align right"),we("formatNumber","Ctrl+Shift+Digit1","both","number format"),we("formatTime","Ctrl+Shift+Digit2","both","time format"),we("formatDate","Ctrl+Shift+Digit3","both","date format"),we("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),we("formatPercent","Ctrl+Shift+Digit5","both","percent format"),we("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),we("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),we("bordersClear","Alt+Shift+Digit6","idle","clear borders"),we("borderTop","Alt+Shift+Digit1","idle","top border"),we("borderRight","Alt+Shift+Digit2","idle","right border"),we("borderBottom","Alt+Shift+Digit3","idle","bottom border"),we("borderLeft","Alt+Shift+Digit4","idle","left border"),we("insertLink","Ctrl+K","idle","insert / edit hyperlink"),we("insertNote","Shift+F2","idle","insert / edit note"),we("insertComment","Ctrl+Alt+M","idle","insert comment"),we("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),we("openValidationList","Alt+ArrowDown","idle","open the validation list"),we("fillDown","Ctrl+D","idle","fill down"),we("fillRight","Ctrl+R","idle","fill right"),we("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),we("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),we("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),we("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),we("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),we("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],qr=(e,t)=>e.column==="both"||e.column===t,xp=Array.from(new Set(tr.filter(e=>!e.rebindable&&qr(e,"idle")).map(e=>e.chord))),ls=new Set(tr.filter(e=>e.command!==void 0&&qr(e,"editing")).map(e=>e.command)),Ap=new Set(tr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),bc=e=>{const t={};for(const n of Kr)t[n]=e(n);return t},yc=bc(e=>tr.filter(t=>t.command===e).map(t=>t.chord)),Op=e=>{const t=new Map;for(const n of Kr){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},Tp=e=>{const t=new Set(Kr);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(Ap.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`)}}}},Dp=(e,t)=>{const n=Xt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=ls.has(e);for(const o of tr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(qr(o,"idle")||r&&qr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Mp=e=>{e!==void 0&&Tp(e);const t=bc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?yc[r]:o===null?[]:o});for(const r of Kr)for(const o of t[r])Dp(r,o);const n=new Map;for(const[r,o]of Op(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},yi=(e,t)=>{const n=Cc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(kp({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},$p=Object.freeze({ok:!0}),Fp="TRUE",zp="FALSE",Np=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Lp=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Pp=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,qp=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,_p=/^[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])?)+$/,vi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Ip={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Ri=e=>{const t=e.trim();if(!(Pp.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),i=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),a=c<0?s:s.slice(0,c),m=c<0?"":s.slice(c+1),p=a+m,S=p.search(/[^0]/);return S<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:p.slice(S).replace(/0+$/,""),point:a.length+i-S}},Hp=e=>e===1?-1:e===-1?1:0,jp=(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:Hp(n)},Bp=(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}},ki=e=>{const t=qp.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]),i=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>Bp(n,r)||s>23||i>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:i,second:c}},Vp=(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},Wp=(e,t)=>e<t?-1:e>t?1:0,Yp=e=>e==="between"||e==="notBetween",Kp=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Yp(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Up=(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}},yo=(e,t,n,r,o,s)=>{const i=Kp(e,t,n,r);return i===null?!0:o===null?!1:Up(e,s(o,i.a),i.b===null?0:s(o,i.b))},Xp=e=>Number.isFinite(e)?e:null,Gp=e=>{let t=0;for(const n of e)t+=1;return t},Zp=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Jp=(e,t)=>{switch(e.op){case"isEmail":return _p.test(t);case"isUrl":return Zp(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)}},Qp=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,vc=e=>({checked:e.checked===void 0?Fp:e.checked,unchecked:e.unchecked===void 0?zp:e.unchecked}),eh=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Np.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "${e.type}"`);return;case"text":if(!Lp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type "${String(e.type)}"`)}},th=(e,t,n)=>{switch(e.type){case"list":return oh(e).has(t);case"number":return yo(e.op,e.a,e.b,Ri,Ri(t),jp);case"textLength":return yo(e.op,e.a,e.b,Xp,Gp(t),Wp);case"date":return yo(e.op,e.a,e.b,ki,ki(t),Vp);case"text":return Jp(e,t);case"checkbox":{const r=vc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Qp(n(e.formula))}},Rc=(e,t,n)=>(eh(e),t===""||th(e,t,n)),vo=(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}`}},Si=e=>e===void 0?void 0:e.trim(),nh=e=>{switch(e.type){case"list":return"Value must be one of the list items.";case"number":return`Value must be a number ${vo(e.op,e.a.trim(),Si(e.b),vi)}.`;case"textLength":return`Text length must be ${vo(e.op,String(e.a),e.b===void 0?void 0:String(e.b),vi)}.`;case"date":return`Value must be a date ${vo(e.op,e.a.trim(),Si(e.b),Ip)}.`;case"text":return rh(e);case"checkbox":{const t=vc(e);return`Value must be "${t.checked}" or "${t.unchecked}".`}default:return`Value does not satisfy the formula ${e.formula}.`}},rh=e=>{switch(e.op){case"contains":return`Value must contain "${e.value}".`;case"notContains":return`Value must not contain "${e.value}".`;case"startsWith":return`Value must start with "${e.value}".`;case"endsWith":return`Value must end with "${e.value}".`;case"isEmail":return"Value must be a valid email address.";default:return"Value must be a valid URL."}},Ei=new WeakMap,oh=e=>{const t=Ei.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Ei.set(e,n),n},kc=(e,t,n)=>Rc(e,t,n)?$p:{ok:!1,message:e.errorMessage===void 0?nh(e):e.errorMessage},sh=e=>e.type!=="custom",ih=(e,t)=>sh(e)&&!Rc(e,t,void 0),lh=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","validationRejected","popoverClose","indicatorNote","indicatorComment","indicatorInvalid"],Ho=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",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",validationRejected:"The value does not satisfy this cell's validation rule",popoverClose:"Close",indicatorNote:"Has a note",indicatorComment:"Has comments",indicatorInvalid:"Invalid value"}),ch=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${JSON.stringify(t)}`)},ah=(e,t,n)=>{e[t]=n},uh=e=>{if(e===void 0)return Ho;const t={...Ho};for(const n of lh){const r=e[n];r!==void 0&&ah(t,n,r)}return ch(t),Object.freeze(t)},Te=(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},Sc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Ec=(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,Ac=(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),Oc=(e,t)=>Sc(e,t),Tc=(e,t)=>Sc(e,t),Dc=(e,t)=>Ec(e,t),Mc=(e,t)=>Ec(e,t),Zt=(e,t,n)=>xc(e,t,n),Jt=(e,t,n)=>xc(e,t,n),nr=(e,t,n)=>Ac(e,t,n),rr=(e,t,n)=>Ac(e,t,n),it=12,dh=()=>{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 i of[...t])i()},o=()=>{t.size!==0&&n===null&&(n=requestAnimationFrame(r))},s=i=>{e={...e,...i},o()};return{get:()=>e,setVy:i=>{i!==e.vy&&s({vy:i})},setRowRange:(i,c)=>{(i!==e.rowStart||c!==e.rowEnd)&&s({rowStart:i,rowEnd:c})},setColRange:(i,c)=>{(i!==e.colStart||c!==e.colEnd)&&s({colStart:i,colEnd:c})},bumpColVersion:()=>s({colVersion:e.colVersion+1}),bumpRowGeometry:()=>s({rowGeomVersion:e.rowGeomVersion+1}),bumpEdit:()=>s({editVersion:e.editVersion+1}),subscribeCoalesced:i=>(t.add(i),()=>{t.delete(i),t.size===0&&n!==null&&(cancelAnimationFrame(n),n=null)})}},fh=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),zt=1,Hn=3,Cr=e=>`${-Math.min(Hn,Math.max(0,Math.floor(e)))}px`,$c=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),ph=16,hh=450,mh=e=>e>4?Math.floor(hh/(5*e)):ph,Ln=(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},xi=()=>({rowLeft:Ln("row","left"),rowRight:Ln("row","right"),colAbove:Ln("column","above"),colBelow:Ln("column","below"),cross:Ln("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Fc=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],br=(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},yr=(e,t)=>Math.min(Math.max(e,0),t),Ai="inset(100%)",gn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},gh=(e,t,n,r,o)=>{const s=e.last,i=r.row&&!o;if(i!==s.rowShown&&(s.rowShown=i,gn([e.rowLeft,e.rowRight],i)),i){if(t.height!==s.rowHeight){s.rowHeight=t.height;const N=`${t.height}px`;e.rowLeft.style.height=N,e.rowRight.style.height=N}const p=`translate(${yr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;p!==s.rowLeftTransform&&(s.rowLeftTransform=p,e.rowLeft.style.transform=p);const S=`translate(${yr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;S!==s.rowRightTransform&&(s.rowRightTransform=S,e.rowRight.style.transform=S)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,gn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const N=`${t.width}px`;e.colAbove.style.width=N,e.colBelow.style.width=N}const p=`translate(${t.left}px, ${yr(t.top,n.clampHeight)-n.clampHeight}px)`;p!==s.colAboveTransform&&(s.colAboveTransform=p,e.colAbove.style.transform=p);const S=`translate(${t.left}px, ${yr(t.top+t.height,n.clampHeight)}px)`;S!==s.colBelowTransform&&(s.colBelowTransform=S,e.colBelow.style.transform=S)}const a=r.intersection?"intersection":i!==c?i?"row":"column":null,m=a!==null;if(m!==s.crossShown&&(s.crossShown=m,gn([e.cross],m)),a!==null){a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const p=`translate(${t.left}px, ${t.top}px)`;p!==s.crossTransform&&(s.crossTransform=p,e.cross.style.transform=p)}},Oi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,gn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,gn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,gn([e.cross],!1))},Ti=e=>{for(const t of Fc(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)},Ch=Object.freeze([]),Di=e=>e.dividers[0]??e.active,bh={left:"0px",right:"0px",width:""},yh={top:"0px",bottom:"0px",height:""},Mi=()=>({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:[]}),$i=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Fi=6,vh=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:i,repaintRef:c,dragFrameRef:a,getClip:m,getIsDraggingAny:p,getIsFillDragging:S,fillFrameRef:N,resizeGuideFrameRef:P,fillHandleNodeRef:T,enableFillHandle:q,frozenCols:K,frozenRows:k,trailingCols:L,trailingRows:D,sinkAriaLabel:x,onSinkMouseDown:A,editPaintRef:h,highlightRef:g,highlightColors:w,popoverAnchors:E,interactiveAnchorRef:y,tipAnchorRef:z})=>{const I=l.useRef(null),H=l.useRef(null),v=l.useRef(null),R=l.useRef(new Map($i.map(F=>[F,Mi()]))),u=l.useCallback(F=>{const V=R.current.get(F);if(V!==void 0)return V;const U=Mi();return R.current.set(F,U),U},[]),f=l.useCallback((F,V,U)=>{if(F===null)return;const j=F.style;j.left!==V.left&&(j.left=V.left),j.right!==V.right&&(j.right=V.right),j.width!==V.width&&(j.width=V.width),j.top!==U.top&&(j.top=U.top),j.bottom!==U.bottom&&(j.bottom=U.bottom),j.height!==U.height&&(j.height=U.height)},[]),$=l.useCallback((F,V,U)=>{if(!(F.bandClampWidth===V&&F.bandClampHeight===U)){F.bandClampWidth=V,F.bandClampHeight=U;for(const j of F.bandPool)br(j,V,U);F.dragBand!==null&&br(F.dragBand,V,U)}},[]),d=l.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const C=l.useCallback((F,V,U)=>{const j=F.dividerSlots[V];j===null||F.dividerShown[V]===U||(F.dividerShown[V]=U,j.style.display=U?"":"none")},[]),_=l.useRef({x:0,y:0}),O=l.useRef(null),M=l.useCallback((F,V)=>{const U=n.current,j=U?.getFrozenSize()??fh,Z=U?.getViewportSize(),ne=Z?.width??-1,le=Z?.height??-1,ye=_.current;ye.x=F,ye.y=V;let me=O.current;if(me===null||me.frozenCols!==j.cols||me.frozenWidth!==j.width||me.frozenRows!==j.rows||me.frozenHeight!==j.height||me.trailingCols!==j.trailingCols||me.trailingWidth!==j.trailingWidth||me.trailingVisibleWidth!==j.trailingVisibleWidth||me.trailingRows!==j.trailingRows||me.trailingHeight!==j.trailingHeight||me.trailingVisibleHeight!==j.trailingVisibleHeight||me.bodyWidth!==ne||me.bodyHeight!==le){const te=j.trailingVisibleWidth,pe=j.trailingVisibleHeight,ce=j.cols<=0&&j.trailingCols<=0?[{kind:"m",map:ge=>ge-ye.x,clamp:ne,style:bh,seamLead:!1,seamTrail:!1}]:[...j.cols>0?[{kind:"f",map:ge=>ge,clamp:j.width,style:{left:"0px",width:`${j.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ge=>ge-ye.x-j.width,clamp:Math.max(0,ne-j.width-te),style:{left:`${j.width}px`,right:`${te}px`,width:""},seamLead:j.cols>0,seamTrail:j.trailingCols>0},...j.trailingCols>0?[{kind:"t",map:ge=>ge-d.current.colAxis.totalSize()+te,clamp:te,style:{left:"",right:"0px",width:`${te}px`},seamLead:!0,seamTrail:!1}]:[]],de=j.rows<=0&&j.trailingRows<=0?[{kind:"m",map:ge=>ge-ye.y,clamp:le,style:yh,seamLead:!1,seamTrail:!1}]:[...j.rows>0?[{kind:"f",map:ge=>ge,clamp:j.height,style:{top:"0px",height:`${j.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ge=>ge-ye.y-j.height,clamp:Math.max(0,le-j.height-pe),style:{top:`${j.height}px`,bottom:`${pe}px`,height:""},seamLead:j.rows>0,seamTrail:j.trailingRows>0},...j.trailingRows>0?[{kind:"t",map:ge=>ge-d.current.rowAxis.totalSize()+pe,clamp:pe,style:{top:"",bottom:"0px",height:`${pe}px`},seamLead:!0,seamTrail:!1}]:[]],ue=[];for(const ge of ce)for(const ve of de)ue.push({nodes:u(`${ge.kind}${ve.kind}`),xKind:ge.kind,yKind:ve.kind,mapX:ge.map,clampWidth:ge.clamp,xStyle:ge.style,xSeamLead:ge.seamLead,xSeamTrail:ge.seamTrail,mapY:ve.map,clampHeight:ve.clamp,yStyle:ve.style,ySeamLead:ve.seamLead,ySeamTrail:ve.seamTrail});me={frozenCols:j.cols,frozenWidth:j.width,frozenRows:j.rows,frozenHeight:j.height,trailingCols:j.trailingCols,trailingWidth:j.trailingWidth,trailingVisibleWidth:j.trailingVisibleWidth,trailingRows:j.trailingRows,trailingHeight:j.trailingHeight,trailingVisibleHeight:j.trailingVisibleHeight,bodyWidth:ne,bodyHeight:le,ctxs:ue},O.current=me}const Fe=j.width>0,qe=j.trailingWidth>0,De=j.height>0,Ee=j.trailingHeight>0;for(const te of me.ctxs)f(te.nodes.container,te.xStyle,te.yStyle),$(te.nodes,te.clampWidth,te.clampHeight),C(te.nodes,0,Fe),C(te.nodes,1,qe),C(te.nodes,2,De),C(te.nodes,3,Ee);return me.ctxs},[n,u,f,$,C]),B=l.useCallback((F,V,U)=>{F.dividerSlots[V]=U,F.dividerShown[V]=!1,F.dividers.length=0;for(const j of F.dividerSlots)j!==null&&F.dividers.push(j)},[]),X=l.useCallback(F=>{const V=()=>u(F);return{container:U=>{const j=V();j.container=U,U===null&&(j.fillPool.length=0,j.bandPool.length=0,j.dragBand=null,j.bandClampWidth=-1,j.bandClampHeight=-1)},dividerXLeading:U=>B(V(),0,U),dividerXTrailing:U=>B(V(),1,U),dividerYLeading:U=>B(V(),2,U),dividerYTrailing:U=>B(V(),3,U),active:U=>{V().active=U},dragRect:U=>{V().dragRect=U},marquee:U=>{V().marquee=U},fillPreview:U=>{V().fillPreview=U},resizeGuide:U=>{V().resizeGuide=U}}},[u,B]),J=l.useMemo(()=>Object.fromEntries($i.map(F=>[F,X(F)])),[X]),G=Math.min(Math.max(0,K),t.count),se=Oc(t,G),he=Math.min(Math.max(0,k),e.count),Q=Tc(e,he),ie=L===void 0?0:Math.min(Math.max(0,L),t.count-G),Le=Dc(t,ie),ae=D===void 0?0:Math.min(Math.max(0,D),e.count-he),Ne=Mc(e,ae),ct=l.useRef(null),dt=l.useRef("add"),ft=l.useRef(s);ft.current=s;const Sn=l.useRef(!1),or=Gn.useWheelBridge(n,{enableBridge:!s}),ds=l.useCallback(F=>(r.current=F,or(F)),[r,or]),en=l.useCallback((F,V)=>({top:V.mapY(e.offsetOf(F.startRow)),bottom:V.mapY(e.offsetOf(F.endRow)+e.sizeOf(F.endRow)),left:V.mapX(t.offsetOf(F.startCol)),right:V.mapX(t.offsetOf(F.endCol)+t.sizeOf(F.endCol))}),[e,t]),Ue=l.useCallback((F,V)=>{if(V.clampHeight<=0||V.clampWidth<=0)return null;const{top:U,bottom:j,left:Z,right:ne}=en(F,V),le=-V.clampHeight*zt,ye=V.clampHeight*(1+zt),me=-V.clampWidth*zt,Fe=V.clampWidth*(1+zt);if(j<le||U>ye||ne<me||Z>Fe)return null;const qe=Math.max(U,le),De=Math.max(Z,me);return{top:qe,left:De,width:Math.min(ne,Fe)-De,height:Math.min(j,ye)-qe}},[en]),Ht=l.useCallback((F,V)=>{if(V.clampHeight<=0||V.clampWidth<=0)return null;const U=en(F,V),j=-V.clampHeight*zt,Z=V.clampHeight*(1+zt),ne=-V.clampWidth*zt,le=V.clampWidth*(1+zt),ye=Math.min(Math.max(U.top,j),Z),me=Math.min(Math.max(U.left,ne),le);return{top:ye,left:me,width:Math.min(Math.max(U.right,ne),le)-me,height:Math.min(Math.max(U.bottom,j),Z)-ye}},[en]),kt=l.useCallback(()=>{if(g===void 0)return null;const F=g.current;return F.row||F.column||F.intersection?F:null},[g]),St=l.useCallback((F,V,U)=>{const j=V.fillPool[0]?.node??Di(V);for(const Z of Fc(U))F.insertBefore(Z,j)},[]),Qe=l.useCallback((F,V,U,j)=>{const Z=Ht(V,U);if(Z===null){Oi(F);return}gh(F,Z,U,j,El(V,t.count)||xl(V,e.count))},[Ht,e,t]),Ve=l.useCallback((F,V,U,j)=>{const Z=F.nodes.bandPool;for(;Z.length>U.length;){const ne=Z.pop();ne!==void 0&&Ti(ne)}if(j===null){F.nodes.dragBand!==null&&(Ti(F.nodes.dragBand),F.nodes.dragBand=null);return}for(let ne=0;ne<U.length;ne+=1){let le=Z[ne];le===void 0&&(le=xi(),br(le,F.clampWidth,F.clampHeight),St(V,F.nodes,le),Z.push(le)),Qe(le,U[ne],F,j)}},[St,Qe]),tn=l.useCallback((F,V,U)=>{const j=F.nodes.container;if(j===null)return;if(V===null||U===null){F.nodes.dragBand!==null&&Oi(F.nodes.dragBand);return}let Z=F.nodes.dragBand;Z===null&&(Z=xi(),br(Z,F.clampWidth,F.clampHeight),St(j,F.nodes,Z),F.nodes.dragBand=Z),Qe(Z,V,F,U)},[St,Qe]),Et=l.useCallback((F,V)=>{if(F!==null){if(V===null){F.style.display="none";return}F.style.display="block",F.style.transform=`translate(${V.left}px, ${V.top}px)`,F.style.width=`${V.width}px`,F.style.height=`${V.height}px`}},[]),_e=l.useCallback((F,V,U,j)=>{const Z=j==="point"?null:kt();for(const ne of M(U,V))Et(ne.nodes.dragRect,Ue(F,ne)),tn(ne,F,Z)},[Ue,M,Et,kt,tn]),Ae=l.useCallback((F,V,U)=>{for(const j of M(U,V))Et(j.nodes.fillPreview,F===null?null:Ue(F,j))},[Ue,M,Et]),et=l.useCallback((F,V,U)=>{for(const j of M(U,V)){const Z=j.nodes.resizeGuide;if(Z===null)continue;if(F===null){Z.style.display="none";continue}const ne=F.anchor==="trailing";if(F.axis==="col"){if(ne&&j.xKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const le=j.mapX(F.position);Z.style.transform=`translate(${ne?Math.max(0,le):le}px, 0px)`,Z.style.width="1px",Z.style.height="100%"}else{if(ne&&j.yKind!=="t"){Z.style.display="none";continue}Z.style.display="block";const le=j.mapY(F.position);Z.style.transform=`translate(0px, ${ne?Math.max(0,le):le}px)`,Z.style.width="100%",Z.style.height="1px"}}},[M]),jt=l.useCallback((F,V,U,j,Z,ne,le)=>{if(F===null)return;if(V===null||le<=0||ne<=0){F.style.clipPath=Ai;return}const ye=Jt(e,V.row,j),me=Zt(t,V.col,U),Fe=t.sizeOf(V.col),qe=e.sizeOf(V.row),De=me>=ne||ye>=le,Ee=V.col>=Z.cols&&me<Z.width,te=V.row>=Z.rows&&ye<Z.height,pe=Z.trailingWidth>0&&V.col<t.count-Z.trailingCols&&me+Fe>ne-Z.trailingVisibleWidth,ce=Z.trailingHeight>0&&V.row<e.count-Z.trailingRows&&ye+qe>le-Z.trailingVisibleHeight;if(De||Ee||te||pe||ce){F.style.clipPath=Ai;return}F.style.clipPath="",F.style.transform=`translate(${me}px, ${ye}px)`;const de=`${Fe} ${qe}`;F.dataset.aqspAnchorSig!==de&&(F.dataset.aqspAnchorSig=de,F.style.width=`${Fe}px`,F.style.height=`${qe}px`)},[e,t]),En=l.useCallback((F,V,U)=>{if(E===void 0)return;const j=E.current,{width:Z,height:ne}=F.getViewportSize(),le=F.getFrozenSize(),ye={scroll:U,frozenCount:le.cols,trailingCount:le.trailingCols,extent:Z},me={scroll:V,frozenCount:le.rows,trailingCount:le.trailingRows,extent:ne};jt(y===void 0?null:y.current,j.interactive,ye,me,le,Z,ne),jt(z===void 0?null:z.current,j.tip,ye,me,le,Z,ne)},[E,y,z,jt]),nn=l.useCallback(()=>{const F=I.current,V=n.current;if(F===null||V===null)return;const U=V.getScrollPosition(),j=Math.max(0,U.y),Z=Math.max(0,U.x),ne=o(),le=M(Z,j),ye=kt(),me=ye===null?Ch:ne.ranges.slice(-mh(le.length));for(const te of le){const pe=te.nodes.container;if(pe===null)continue;const ce=te.nodes.fillPool;for(let de=0;de<Math.max(ce.length,ne.ranges.length);de+=1){let ue=ce[de];if(ue===void 0){const Me=document.createElement("div");Me.className="aqsp-selection-fill",Me.setAttribute("data-aqsp-fill",""),Me.style.display="none",pe.insertBefore(Me,Di(te.nodes)),ue={node:Me,last:{shown:!1,width:-1,height:-1,transform:""}},ce.push(ue)}const ge=ne.ranges[de],ve=ge===void 0?null:Ue(ge,te);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 Me=`translate(${ve.left}px, ${ve.top}px)`;Me!==ue.last.transform&&(ue.last.transform=Me,ue.node.style.transform=Me),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(;ce.length>ne.ranges.length;)ce.pop()?.node.remove();Et(te.nodes.active,Ue(Ce(ne.active,ne.active),te)),Ve(te,pe,me,ye)}const Fe=m(),qe=Fe===null||Fe.foreign?null:Fe;for(const te of le){const pe=te.nodes.marquee;if(pe===null)continue;const ce=qe===null?null:Ue(qe.range,te),de=ce!==null&&(te.xSeamTrail&&ce.left>=te.clampWidth&&ce.left<te.clampWidth+Hn||te.xSeamLead&&ce.left+ce.width<=0&&ce.left+ce.width>-Hn||te.ySeamTrail&&ce.top>=te.clampHeight&&ce.top<te.clampHeight+Hn||te.ySeamLead&&ce.top+ce.height<=0&&ce.top+ce.height>-Hn)?null:ce;if(de===null)pe.style.display="none";else{pe.style.display="block",pe.style.transform=`translate(${de.left}px, ${de.top}px)`,pe.style.width=`${de.width}px`,pe.style.height=`${de.height}px`;const ve=Cr(de.top),Me=Cr(de.left),at=Cr(te.clampHeight-(de.top+de.height)),Xe=Cr(te.clampWidth-(de.left+de.width)),Pe=`${ve} ${Xe} ${at} ${Me}`;Pe!==pe.dataset.aqspOutsetSig&&(pe.dataset.aqspOutsetSig=Pe,pe.style.setProperty("--aqsp-clip-outset-top",ve),pe.style.setProperty("--aqsp-clip-outset-right",Xe),pe.style.setProperty("--aqsp-clip-outset-bottom",at),pe.style.setProperty("--aqsp-clip-outset-left",Me))}const ue=de===null?null:qe?.kind??null,ge=pe.dataset.aqspClipKindLast??null;ue!==ge&&(ue===null?(delete pe.dataset.aqspClipKindLast,pe.removeAttribute("data-aqsp-clip-kind")):(pe.dataset.aqspClipKindLast=ue,pe.setAttribute("data-aqsp-clip-kind",ue)))}ct.current!==null&&_e(ct.current,j,Z,dt.current),v.current!==null&&et(v.current,j,Z),H.current!==null&&Ae(H.current,j,Z);const De=T.current;if(De!==null&&!S()){const{width:te,height:pe}=V.getViewportSize(),ce=ne.ranges[ne.ranges.length-1];if(!(ne.ranges.length===1&&!ft.current&&!p())||pe<=0||te<=0)De.style.display="none";else{const ue=V.getFrozenSize(),ge={scroll:Z,frozenCount:ue.cols,trailingCount:ue.trailingCols,extent:te},ve={scroll:j,frozenCount:ue.rows,trailingCount:ue.trailingRows,extent:pe},Me=ce.endCol<ue.cols,at=ce.endRow<ue.rows,Xe=ce.endCol>=t.count-ue.trailingCols,Pe=ce.endRow>=e.count-ue.trailingRows,pt=Zt(t,ce.endCol,ge)+t.sizeOf(ce.endCol),xt=Jt(e,ce.endRow,ve)+e.sizeOf(ce.endRow),rn=Me||Xe?0:ue.width,At=at||Pe?0:ue.height,ht=Xe?te:te-ue.trailingVisibleWidth,An=Pe?pe:pe-ue.trailingVisibleHeight;xt<=At||xt>An||pt<=rn||pt>ht?De.style.display="none":(De.style.display="block",De.style.transform=`translate(${pt-Fi+1}px, ${xt-Fi+1}px)`)}}const Ee=r.current;if(Ee!==null){const te=ne.active,{width:pe,height:ce}=V.getViewportSize(),de=V.getFrozenSize(),ue={scroll:Z,frozenCount:de.cols,trailingCount:de.trailingCols,extent:pe},ge={scroll:j,frozenCount:de.rows,trailingCount:de.trailingRows,extent:ce},ve=Jt(e,te.row,ge),Me=Zt(t,te.col,ue),at=ce>0?Math.min(Math.max(ve,0),Math.max(0,ce-1)):0,Xe=pe>0?Math.min(Math.max(Me,0),Math.max(0,pe-1)):0;Ee.style.top=`${at}px`,Ee.style.left=`${Xe}px`,ft.current?(Ee.style.width=`${t.sizeOf(te.col)}px`,Ee.style.height=`${e.sizeOf(te.row)}px`,Ee.style.paddingTop=`${wh(e.sizeOf(te.row),h===void 0?bt:h.current)}px`):(Ee.style.width="1px",Ee.style.height="1px",Ee.style.paddingTop="0px");const Pe=te.col>=de.cols&&Me<de.width,pt=te.row>=de.rows&&ve<de.height,xt=de.trailingWidth>0&&te.col<t.count-de.trailingCols&&Me+t.sizeOf(te.col)>pe-de.trailingVisibleWidth,rn=de.trailingHeight>0&&te.row<e.count-de.trailingRows&&ve+e.sizeOf(te.row)>ce-de.trailingVisibleHeight,At=ft.current&&ve===at&&Me===Xe&&!Pe&&!pt&&!xt&&!rn;At!==Sn.current&&(Sn.current=At,At?Ee.setAttribute("data-aqsp-editing",""):Ee.removeAttribute("data-aqsp-editing"))}En(V,j,Z)},[n,Ue,M,Et,_e,et,Ae,m,o,p,S,T,r,e,t,kt,Ve,h,En]),xn=l.useCallback((F,V)=>{ct.current=F,dt.current=V;const U=F===null?"add":V;for(const ne of M(0,0)){const le=ne.nodes.dragRect;if(le===null)continue;const ye=le.dataset.aqspDragModeLast??"add";U!==ye&&(le.dataset.aqspDragModeLast=U,U==="add"?le.removeAttribute("data-aqsp-drag-mode"):le.setAttribute("data-aqsp-drag-mode",U))}const j=n.current;if(F===null||j===null){for(const ne of M(0,0))ne.nodes.dragRect!==null&&(ne.nodes.dragRect.style.display="none"),tn(ne,null,null);return}const Z=j.getScrollPosition();_e(F,Math.max(0,Z.y),Math.max(0,Z.x),V)},[n,_e,M,tn]),$e=l.useCallback(F=>{H.current=F;const V=n.current;if(V===null){for(const j of M(0,0))j.nodes.fillPreview!==null&&(j.nodes.fillPreview.style.display="none");return}const U=V.getScrollPosition();Ae(F,Math.max(0,U.y),Math.max(0,U.x))},[n,Ae,M]),sr=l.useCallback(F=>{v.current=F;const V=n.current;if(V===null){for(const j of M(0,0))j.nodes.resizeGuide!==null&&(j.nodes.resizeGuide.style.display="none");return}const U=V.getScrollPosition();et(F,Math.max(0,U.y),Math.max(0,U.x))},[n,et,M]);l.useLayoutEffect(()=>{const F=I.current;if(!(F===null||w===void 0))return F.style.setProperty("--aqsp-band-row",w.row),F.style.setProperty("--aqsp-band-column",w.column),F.style.setProperty("--aqsp-band-intersection",w.intersection),F.style.setProperty("--aqsp-band-opacity",String(w.opacity)),()=>{F.style.removeProperty("--aqsp-band-row"),F.style.removeProperty("--aqsp-band-column"),F.style.removeProperty("--aqsp-band-intersection"),F.style.removeProperty("--aqsp-band-opacity")}},[w]),l.useEffect(()=>(c.current=nn,a.current=xn,N.current=$e,P.current=sr,()=>{c.current=null,a.current=null,N.current=null,P.current=null})),l.useEffect(()=>{nn()},[nn,s,G,he,ie,ae]),l.useEffect(()=>{const F=r.current;if(F===null)return;const V=U=>A(U);return F.addEventListener("mousedown",V),()=>F.removeEventListener("mousedown",V)},[r,A]);const We=G>0||ie>0?[...G>0?[{k:"f",style:{left:0,width:se}}]:[],{k:"s",style:{left:se,right:Le}},...ie>0?[{k:"t",style:{right:0,width:Le}}]:[]]:[{k:"m",style:{left:0,right:0}}],be=he>0||ae>0?[...he>0?[{k:"f",style:{top:0,height:Q}}]:[],{k:"s",style:{top:Q,bottom:Ne}},...ae>0?[{k:"t",style:{bottom:0,height:Ne}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Ie=F=>F==="m"?0:F==="s"?1:F==="t"?2:3,ir=We.flatMap(F=>be.map(V=>({xk:F.k,yk:V.k,key:`${F.k}${V.k}`,style:{...F.style,...V.style}}))).sort((F,V)=>Ie(F.key[0])+Ie(F.key[1])-(Ie(V.key[0])+Ie(V.key[1]))),lr=F=>F==="mm"?{"data-aqsp-overlay-main":""}:F==="fm"?{"data-aqsp-overlay-frozen":""}:F==="sm"?{"data-aqsp-overlay-scroll":""}:{};return W.jsxs("div",{ref:I,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:it,bottom:it},children:[ir.map(({xk:F,yk:V,key:U,style:j})=>{const Z=J[U];return W.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":U,...lr(U),style:j,ref:Z.container,children:[F==="s"&&G>0?W.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:Z.dividerXLeading}):null,F==="s"&&ie>0?W.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:Z.dividerXTrailing}):null,V==="s"&&he>0?W.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:Z.dividerYLeading}):null,V==="s"&&ae>0?W.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:Z.dividerYTrailing}):null,W.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:Z.active}),W.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:Z.dragRect}),W.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:Z.marquee}),W.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:Z.fillPreview}),W.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:Z.resizeGuide})]},U)}),W.jsx("textarea",{ref:ds,className:"aqsp-sink","aria-label":x,tabIndex:-1,defaultValue:" ",inputMode:i?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),q?W.jsx("div",{ref:T,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},zc=({ctx:e,labels:t})=>{const[n,r]=l.useState(""),o=l.useId(),s=l.useRef(!1),i=p=>{s.current=!0;try{p()}finally{s.current=!1}},c=()=>{n.trim()!==""&&i(()=>e.commit([...e.current,{text:n}]))},a=p=>{if(p.key==="Escape"){p.preventDefault(),i(e.close);return}p.key==="Enter"&&(p.ctrlKey||p.metaKey)&&!p.altKey&&!p.shiftKey&&(p.preventDefault(),c())},m=p=>{s.current||p.relatedTarget instanceof Node&&p.currentTarget.contains(p.relatedTarget)||e.rejected||i(e.close)};return W.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":o,onBlur:m,children:[W.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:o,children:[Te(t,"commentTitle"),W.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Te(t,"commentCount",e.current.length)})]}),W.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(p=>W.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":p.id,children:[W.jsx("span",{className:"aqsp-popover-comment-author",children:p.author}),W.jsx("time",{className:"aqsp-popover-comment-time",dateTime:p.createdAt,children:p.createdAt}),W.jsx("p",{className:"aqsp-popover-comment-text",children:p.text})]},p.id))}),W.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Te(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:p=>r(p.currentTarget.value),onKeyDown:a}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",onClick:c,children:Te(t,"commentPost")}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Te(t,"popoverClose"),onClick:()=>i(e.close),children:"×"})]})]})},Nc=({ctx:e,labels:t})=>{const[n,r]=l.useState(e.current.text),[o,s]=l.useState(e.current.url===void 0?"":e.current.url),i=l.useId(),c=l.useRef(!1),a=o.trim()===""?null:It(o),m=o.trim()!==""&&a===null,p=T=>{c.current=!0;try{T()}finally{c.current=!1}},S=()=>{m||p(()=>e.commit({text:n===""&&a!==null?a:n,url:a}))},N=T=>{if(T.key==="Escape"){T.preventDefault(),p(e.close);return}T.key==="Enter"&&!T.altKey&&!T.shiftKey&&(T.preventDefault(),S())},P=T=>{c.current||T.relatedTarget instanceof Node&&T.currentTarget.contains(T.relatedTarget)||e.rejected||p(e.close)};return W.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":i,onBlur:P,children:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:i,children:Te(t,"linkTitle")}),W.jsxs("label",{className:"aqsp-popover-field",children:[W.jsx("span",{className:"aqsp-popover-field-label",children:Te(t,"linkTextField")}),W.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:T=>r(T.currentTarget.value),onKeyDown:N})]}),W.jsxs("label",{className:"aqsp-popover-field",children:[W.jsx("span",{className:"aqsp-popover-field-label",children:Te(t,"linkUrlField")}),W.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:T=>s(T.currentTarget.value),onKeyDown:N})]}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m,onClick:S,children:Te(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:Te(t,"linkOpen")}):null,W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Te(t,"popoverClose"),onClick:()=>p(e.close),children:"×"})]})]})},zi=500,Lc=({ctx:e,labels:t})=>{const[n,r]=l.useState(e.typed),[o,s]=l.useState(0),i=l.useId(),c=l.useRef(!1),a=l.useMemo(()=>{const k=n.toLowerCase();return e.current.filter(L=>L.toLowerCase().startsWith(k))},[e.current,n]),m=l.useMemo(()=>a.length>zi?a.slice(0,zi):a,[a]),p=a.length-m.length,S=m.length===0?-1:Math.min(o,m.length-1),N=k=>{c.current=!0;try{k()}finally{c.current=!1}},P=()=>{S<0||N(()=>e.commit(m[S]))},T=k=>{if(k.key==="Escape"){k.preventDefault(),N(e.close);return}if(k.key==="Enter"){k.preventDefault(),P();return}if(k.key==="ArrowDown"){k.preventDefault(),s(S+1);return}k.key==="ArrowUp"&&(k.preventDefault(),s(Math.max(S-1,0)))},q=k=>{c.current||k.relatedTarget instanceof Node&&k.currentTarget.contains(k.relatedTarget)||N(e.close)},K=k=>`${i}-${k}`;return W.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:q,children:[W.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Te(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":i,"aria-activedescendant":S<0?void 0:K(S),value:n,onChange:k=>{r(k.currentTarget.value),s(0)},onKeyDown:T}),W.jsxs("div",{className:"aqsp-popover-options",id:i,role:"listbox","aria-label":Te(t,"listTitle"),children:[m.length===0?W.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Te(t,"listEmpty")}):m.map((k,L)=>W.jsx("div",{className:"aqsp-popover-option",id:K(L),role:"option",tabIndex:-1,"aria-selected":L===S,"data-aqsp-list-option":k,onPointerDown:D=>D.preventDefault(),onClick:()=>N(()=>e.commit(k)),children:k},K(L))),p>0?W.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Te(t,"listMore",p)}):null]})]})},Pc=({ctx:e,labels:t})=>W.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),W.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Te(t,"popoverClose"),onClick:e.close,children:"×"})]}),qc=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=l.useState(n),s=l.useId(),i=l.useId(),c=l.useRef(!1),a=P=>{c.current=!0;try{P()}finally{c.current=!1}},m=()=>{a(()=>e.commit(r===""?null:r))},p=()=>{r!==n?m():a(e.close)},S=P=>{if(P.key==="Escape"){P.preventDefault(),e.rejected?a(e.close):p();return}P.key==="Enter"&&(P.ctrlKey||P.metaKey)&&!P.altKey&&!P.shiftKey&&(P.preventDefault(),m())},N=P=>{c.current||P.relatedTarget instanceof Node&&P.currentTarget.contains(P.relatedTarget)||e.rejected||p()};return W.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:N,children:[W.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:Te(t,"noteTitle")}),W.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":i,"aria-invalid":e.rejected?!0:void 0,onChange:P=>o(P.currentTarget.value),onKeyDown:S}),W.jsx("p",{className:"aqsp-popover-hint",id:i,"data-aqsp-popover-hint":"",children:Te(t,e.rejected?"noteRejectedHint":"noteEscapeHint")}),W.jsxs("div",{className:"aqsp-popover-actions",children:[W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",onClick:m,children:Te(t,"noteSave")}),W.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Te(t,"popoverClose"),onClick:()=>a(e.close),children:"×"})]})]})},_c=({ctx:e})=>W.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),wt=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")}),Ni=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Ic=Object.freeze({all:wt(Ni),values:wt(["text"]),formats:wt(["format","borders","cf"]),formulas:wt(["text","formula"]),noBorders:wt(Ni.filter(e=>e!=="borders")),columnWidths:wt(["sizes"]),validation:wt(["validation"]),conditionalFormats:wt(["cf"]),commentsAndNotes:wt(["note","comments"])}),Li=Object.freeze({mode:"all"}),jo=Object.freeze({t:""}),Pi=Object.freeze({row:1<<30,col:1<<30}),Rh=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),kh=e=>e.t===""&&e.f===void 0,Sh=e=>e.length>1&&e.startsWith("="),Eh=(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}},qi=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,xh=(e,t,n,r)=>{const o=Sh(e),s=e===""?"0":Ze(e);if(!o&&s===null)return null;const i=Rh[n];if(t.f!==void 0){const m=Qn(t.f,r),p=m.startsWith("=")?m.slice(1):m;return`=(${o?e.slice(1):s})${i}(${p})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:qi(Number(s));const c=Ze(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${i}(${c})`:qi(Eh(Number(s),a,n))},_i=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Ah=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:_i(e.start),end:_i(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},Oh=e=>{const t=Qn(e,Pi),n=Jn(t);let r="",o=0,s=!1;for(const i of n){const c=Ah(i.token);c!==i.token&&(r+=`${t.slice(o,i.start)}${Pt(c)}`,o=i.end,s=!0)}return s?Vr(`${r}${t.slice(o)}`,Pi):e},Th=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return jo;const o=r[n];return o===void 0?jo:o},Dh=e=>{const{rows:t,cols:n}=e,r=_l(Oh);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let m=0;m<t;m+=1){const p=Th(e,m,c);let S=p;if(p.f!==void 0){const N=r(p.f);S=N===p.f?p:{...p,f:N}}(S!==p||p===jo)&&(o=!1),a.push(S)}s.push(a)}if(o)return e;const i=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:i}},Mh=(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,$h=(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},Ii=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const m=[];for(const p of c)Mh(p,t)?(m.push($h(p,t)),a=!0):m.push(p);a&&(n=!0),r.push(a?m:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,i=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||i!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:i,cells:r}:e},Hi=new WeakMap,Hc=e=>{const t=Hi.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>lt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:lt({...s,borders:void 0})),o={canonical:n,borderless:r};return Hi.set(e,o),o},_r=(e,t)=>t===void 0?void 0:e[t],Fh=(e,t,n,r)=>{const o=Hc(e);if(n){const m=_r(o.canonical,t.fmt);return m===void 0?null:m}const s=_r(o.borderless,t.fmt),i=r.readFormat(),c=i===void 0?void 0:i.borders;if(c===void 0)return s===void 0?null:s;const a=lt(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},zh=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?xh(n.readText(),o,r,n):o.f===void 0?o.t:Qn(o.f,n)},ji=(e,t,n,r,o)=>{const s=Ic[r.mode];if(r.skipBlanks===!0&&kh(e))return null;const i={};let c=!1;if(s.text){const a=zh(e,s.formula&&o.formula,n,r.operation);a!==null&&(i.text=a,c=!0)}if(o.format){if(s.format)i.format=Fh(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=_r(Hc(t).canonical,e.fmt);a!==void 0&&(i.format=a,c=!0)}}if(s.note&&o.note&&(i.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(i.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(i.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const a=_r(t.validations,e.val);i.validation=a===void 0?null:a,c=!0}return c?i:null},Bi=(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}}),Nh=["text/html","text/plain"],Lh=(e,t,n)=>{if(e===0||t===0)return 0;const r=Je(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Ph=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,qh=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}}},Vi=e=>{const t=e.clipboardData;return t??null},_h=(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}},Ih=(e,t)=>{const n=[];for(const r of e){const o=[];for(const i of r.ranges){const c=_h(i,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},Hh=(e,t,n,r,o)=>{const s=Rn(e,r,o),i={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(i.f=Vr(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(i.fmt=a)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(i.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(i.comments=c.map(({text:a,author:m,createdAt:p})=>({text:a,author:m,createdAt:p})))}if(e.getCellHyperlink!==void 0){const c=kn(e.getCellHyperlink(r,o));c!==void 0&&(i.link=c)}if(e.getCellValidation!==void 0){const c=e.getCellValidation(r,o);c!==void 0&&(i.val=n.intern(c))}return i},jc=(e,t)=>{const n=Sl(),r=Ju(),o=[];for(let s=t.startRow;s<=t.endRow;s+=1){const i=[];for(let c=t.startCol;c<=t.endCol;c+=1)i.push(Hh(e,n,r,s,c));o.push(i)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Ih(e.getConditionalFormats(),t)}},Wi=e=>e.kind==="cut"?{...e.payload,...jc(e.sourceAdapter,e.range)}:e.payload,jh=e=>({v:1,rows:e.length,cols:e[0].length,clipId:Go(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Bh=e=>{let t=!1;const n=[];for(const r of e.cells){let o=!1;const s=[];for(const i of r){if(i.link===void 0){s.push(i);continue}const c=It(i.link);if(c===i.link){s.push(i);continue}if(o=!0,c===null){const{link:a,...m}=i;s.push(m)}else s.push({...i,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Vh=(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},Wh=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,i=0;for(const c of e)s=Math.max(s,c.row+t-1),i=Math.max(i,c.col+n-1);return Ce({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(i,o-1)})},Yh=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(null),r=l.useRef("none"),o=l.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=l.useCallback(k=>{const L=n.current;if(L===null||k==="format"||k==="annotate")return;const D=r.current;D==="own"||D==="foreign"&&L.kind==="copy"||o()},[o]),i=l.useCallback(()=>{const k=n.current;if(k===null)return;if(k.kind==="copy"){o();return}const L=t.current;L.repaintOverlay(),L.onClipChange?.({kind:"cut",range:k.range,foreign:k.sourceAdapter!==L.adapter})},[o]),c=l.useCallback((k,L,D)=>{const x=t.current;n.current={kind:k,range:L,clipId:D.clipId,sourceAdapter:x.adapter,payload:D},x.repaintOverlay(),x.onClipChange?.({kind:k,range:L,foreign:!1})},[]),a=l.useCallback(k=>{const L=t.current,D=L.adapter,x=Je(k),A={v:1,rows:x.rows,cols:x.cols,clipId:Go(),...jc(D,k),wholeRows:El(k,D.colCount),wholeCols:xl(k,D.rowCount)};if(L.resize!==void 0){if(A.wholeCols){const h=[];for(let g=k.startCol;g<=k.endCol;g+=1)h.push(Math.min(L.resize.colAxis.sizeOf(g),bn));A.colWidths=h}if(A.wholeRows){const h=[];for(let g=k.startRow;g<=k.endRow;g+=1)h.push(Math.min(L.resize.rowAxis.sizeOf(g),bn));A.rowHeights=h}}return A},[]),m=l.useCallback((k,L)=>{const D=t.current,x=D.getSelection(),A=x.ranges[x.ranges.length-1],h=Pr([A]);if(h>D.maxOperationCells)return k.preventDefault(),D.onOperationRejected?.(L,h,"limit"),null;x.ranges.length>1&&D.onCopyMultiRange?.();const g=a(A),w=pl(g),E=Vi(k);return E!==null&&(E.setData("text/plain",pc(g.cells.map(y=>y.map(z=>z.t)))),E.setData("text/html",rc(g,w)),E.setData(Nr,w)),k.preventDefault(),{payload:g,range:A}},[a]),p=l.useCallback((k,L)=>t.current.commitPaste(k,L)!==null,[]),S=l.useCallback((k,L,D)=>{const x=t.current;if(!D.sizes||x.resize===void 0)return;const{rowAxis:A,colAxis:h,resizeTracks:g}=x.resize,w=(E,y,z)=>{const I=Yo(y,z,null,{maxOperationCells:x.maxOperationCells,rowHiddenLimit:Vo,axisKind:E});if(!I.ok){x.onOperationRejected?.("resize",I.count,I.reason);return}g(E,I.entries)};if(k.colWidths!==void 0){const E=[];for(let y=L.startCol;y<=L.endCol;y+=1)E.push({index:y,size:k.colWidths[(y-L.startCol)%k.cols]});w("col",h,E)}if(k.rowHeights!==void 0){const E=[];for(let y=L.startRow;y<=L.endRow;y+=1)E.push({index:y,size:k.rowHeights[(y-L.startRow)%k.rows]});w("row",A,E)}},[]),N=l.useCallback((k,L)=>{const D=t.current,x=D.adapter,A=k.payload,h={row:L.startRow,col:L.startCol},g=A.rows*A.cols+Pr([k.range]);if(g>D.maxOperationCells)return D.onOperationRejected?.("paste",g,"limit"),"rejected";if(h.row+A.rows>x.rowCount||h.col+A.cols>x.colCount||k.range.endRow>=k.sourceAdapter.rowCount||k.range.endCol>=k.sourceAdapter.colCount)return D.onOperationRejected?.("paste",g,"bounds"),"rejected";const w=Wi(k),E=Fr(x),y=Ii(w,E),z={row:0,col:0,readText:()=>Rn(x,z.row,z.col).text,readFormat:()=>x.getCellFormat===void 0?void 0:x.getCellFormat(z.row,z.col)},{edits:I,tiles:H}=Ci(y.cells,Ce(h,h),h,x.rowCount,x.colCount,(u,f,$)=>(z.row=k.range.startRow+(f-h.row),z.col=k.range.startCol+($-h.col),ji(u,y,z,Li,E))),v=Fr(k.sourceAdapter),R=[];if(Nt([k.range],u=>{R.push(Vh(u.row,u.col,v))}),k.sourceAdapter===x){if(!p([...R,...I],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const u=D.commitPaste(I,{sameSheet:!1,conditionalFormats:Bi(y.conditionalFormats,H)});if(u===null)return"rejected";try{k.sourceAdapter.applyEdits(R,{transaction:u,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(f){D.onEditRejected?.(f,{source:"paste"})}}return D.setSelection({ranges:[Ce(h,{row:h.row+w.rows-1,col:h.col+w.cols-1})],anchor:h,active:h}),"applied"},[p]),P=l.useCallback((k,L,D)=>{const x=t.current,A=x.adapter,h=B=>(x.onClipboardUnavailable?.(B),"rejected"),g=gl(k,L);if(g==="none")return L==="menu"?h("empty"):"empty";const w=x.getSelection(),E=w.ranges[w.ranges.length-1],y=D.transpose===!0,z=(B,X)=>{const J=Lh(y?X:B,y?B:X,E);return J>x.maxOperationCells?(x.onOperationRejected?.("paste",J,"limit"),!0):!1};let I,H=null;if(g==="aqsp"){const B=Eu(k,L);if(B===null)return h("unreadable");const X=n.current;if(X!==null&&B.clipId===X.clipId&&(H=X),H!==null&&H.kind==="cut"&&Ph(D))return N(H,E);if(z(B.rows,B.cols))return"rejected";if(H!==null){if(H.kind==="cut"&&(H.range.endRow>=H.sourceAdapter.rowCount||H.range.endCol>=H.sourceAdapter.colCount))return x.onOperationRejected?.("paste",H.payload.rows*H.payload.cols,"bounds"),"rejected";I=Wi(H)}else{const J=xu(k,L);if(J===null)return h("unreadable");if(z(J.rows,J.cols))return"rejected";I=Bh(J)}}else if(g==="tsv"){const B=k.getData("text/plain"),X=gp(B);if(z(X.rows,X.cols))return"rejected";I=jh(gc(B))}else{const B=k.getData("text/html"),X=Zu(B);if(X.cols===0&&X.rows>x.maxOperationCells)return x.onOperationRejected?.("paste",X.rows,"limit"),"rejected";if(z(X.rows,X.cols))return"rejected";const J=lc(B,g,x.formats===void 0?{}:{currency:x.formats.currency,locale:x.formats.locale},x.maxOperationCells);if(J.outcome==="none")return h("unreadable");if(J.outcome==="limit")return x.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(z(J.payload.rows,J.payload.cols))return"rejected";I=J.payload}const v=Fr(A),R=Ii(y?Dh(I):I,v),u=Ic[D.mode],f={row:0,col:0,readText:()=>Rn(A,f.row,f.col).text,readFormat:()=>A.getCellFormat===void 0?void 0:A.getCellFormat(f.row,f.col)},{edits:$,tiles:d}=Ci(R.cells,E,w.active,A.rowCount,A.colCount,(B,X,J)=>(f.row=X,f.col=J,ji(B,R,f,D,v))),C=Wh(d,R.rows,R.cols,A.rowCount,A.colCount);if(C===null)return"empty";if(u.cf&&R.conditionalFormats.length>0){let B=0;for(const J of R.conditionalFormats)B+=J.ranges.length;const X=d.length*B;if(X>x.maxOperationCells)return x.onOperationRejected?.("paste",X,"limit"),"rejected"}const _=u.cf?Bi(R.conditionalFormats,d):[];if($.length===0&&_.length===0)return S(R,C,u),"empty";r.current=H===null?"foreign":"own";let O=!1;try{O=p($,{sameSheet:H!==null&&H.sourceAdapter===A,conditionalFormats:_})}finally{r.current="none"}if(!O)return"rejected";S(R,C,u);const M={row:C.startRow,col:C.startCol};return x.setSelection({ranges:[C],anchor:M,active:M}),"applied"},[N,p,S]),T=l.useCallback(async k=>{const L=y=>(t.current.onClipboardUnavailable?.(y),"rejected"),D=navigator;if(D.clipboard===void 0)return L("insecure-origin");let x;try{x=await D.clipboard.read({unsanitized:["text/html"]})}catch{return L("permission-denied")}if(x.length===0)return L("empty");const A=x[0],h=Array.from(A.types),g=new Map;try{for(const y of Nh)h.includes(y)&&g.set(y,await(await A.getType(y)).text())}catch{return L("unreadable")}const w={types:h,getData:y=>{const z=g.get(y);if(z===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${y} was not materialised for the menu path`);return z}},E=t.current;return!E.enabled||E.isDragging()||E.isEditing()?"rejected":P(w,"menu",k)},[P]),{enabled:q,sinkRef:K}=e;return l.useEffect(()=>{const k=K.current;if(!q||k===null)return;const L=h=>t.current.isDragging()?(h.preventDefault(),!0):!1,D=h=>{const g=t.current;if(L(h)||g.isEditing())return;const w=m(h,"copy");w!==null&&c("copy",w.range,w.payload)},x=h=>{const g=t.current;if(L(h)||g.isEditing())return;const w=m(h,"cut");w!==null&&c("cut",w.range,w.payload)},A=h=>{const g=t.current;if(L(h)||g.isEditing())return;h.preventDefault();let w=Li;const E=g.pendingPasteOptionsRef;E!==void 0&&E.current!==null&&(w=E.current,E.current=null);const y=Vi(h);y!==null&&P(qh(y),"event",w)};return k.addEventListener("copy",D),k.addEventListener("cut",x),k.addEventListener("paste",A),()=>{k.removeEventListener("copy",D),k.removeEventListener("cut",x),k.removeEventListener("paste",A)}},[q,K,m,c,P]),l.useMemo(()=>({getClip:()=>{const k=n.current;return k===null?null:{kind:k.kind,range:k.range,foreign:k.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:i,paste:T}),[o,s,i,T])},Bc=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)}`)},Vc=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("."),i=s<0?t:t.slice(0,s),c=s<0?"":t.slice(s+1);return{negative:n,digits:i+c,point:i.length,exponent:o}},Yi=(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}`}`},Wc=(e,t)=>{let n;if(e.exponent===null)n=Yi(e.negative,e.digits,e.point+t);else{const r=Yi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Ze(n)===null?null:n},Kh=(e,t)=>{Bc(t);const n=Ze(e);return n===null?null:Wc(Vc(n),t)},Uh=e=>{const t=Ze(e);if(t!==null){const r=Vc(t);return Wc({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},Yc=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)},Xh=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},Kc=(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 Xh(r)?r:null},Gh=(e,t)=>{Bc(t);const n=Yc(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",i=Kc(n,"(",`)${s}${r}`);return i===null?`=(${n})${o}${r}`:`=${i}`},Zh=e=>{const t=Yc(e),n=Kc(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Pn=(e,t,n,r)=>{const o=Pr(t);return o>n?(r?.(e,o,"limit"),!1):!0},vr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Rr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Ki={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:vr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:vr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:vr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:vr.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:Rr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Rr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Rr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Rr.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"}},Jh={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},Yn=e=>e<10?`0${e}`:String(e),Qh=e=>{const t=new Date(e);return`${t.getFullYear()}-${Yn(t.getMonth()+1)}-${Yn(t.getDate())}`},em=e=>{const t=new Date(e);return`${Yn(t.getHours())}:${Yn(t.getMinutes())}:${Yn(t.getSeconds())}`},tm=(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),nm=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),rm=e=>e===void 0||e.borders===void 0?{}:e.borders,om={top:1,right:2,bottom:4,left:8},sm={style:"thin",color:Ko},im=(e,t)=>{if(e===void 0)return!1;const n=Be(e);return n!==null&&n===Be(t)},lm=(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}}},cm=e=>{const t=l.useRef(e);t.current=e;const n=l.useCallback(()=>{const h=t.current;if(h.isEditing()){const g=h.getActive();return[Ce(g,g)]}return h.getSelection().ranges},[]),r=l.useCallback(()=>{const h=t.current,g=h.getActive();return h.adapter.getCellFormat===void 0?void 0:h.adapter.getCellFormat(g.row,g.col)},[]),o=l.useCallback(h=>{const g=t.current,w=n();if(!Pn("format",w,g.maxOperationCells,g.onOperationRejected))return!1;const E=new Map,y=[],z=g.adapter.getCellFormat;for(const I of w)Nt([I],H=>{const v=z===void 0?void 0:z(H.row,H.col),{bucket:R,patch:u}=h(H,I,v);let f=E.get(R);f===void 0&&(f=new Map,E.set(R,f));let $;f.has(v)?$=f.get(v):($=Xo(v,u),f.set(v,$)),$!==v&&y.push({row:H.row,col:H.col,format:$===void 0?null:$})});return y.length===0?!0:g.commitEdits(y,{source:"format"})===null?!1:(g.isEditing()&&g.refreshEditPaint(),!0)},[n]),s=l.useCallback(h=>o(()=>({bucket:0,patch:h})),[o]),i=l.useCallback((h,g)=>{const w=t.current;w.formatCommandAnnouncement!==void 0&&w.announce(w.formatCommandAnnouncement({command:h,state:g}))},[]),c=l.useCallback((h,g=sm)=>{if(h==="clear")return s({borders:null});if(h==="all")return s({borders:{top:g,right:g,bottom:g,left:g}});const w=h==="outer"?15:om[h];return o((E,y,z)=>{const I=tm(E,y)&w;return{bucket:I,patch:{borders:{...rm(z),...nm(I,g)}}}})},[s,o]),a=l.useCallback((h,g,w)=>{const E=dc(t.current.adapter,h.row,h.col);for(const y of g)w.push(fc(E,h,y))},[]),m=l.useCallback(h=>{const g=t.current,w=g.getSelection();if(!Pn("fill",w.ranges,g.maxOperationCells,g.onOperationRejected))return!1;const E=[];if(h==="selection"){const y=w.active,z=[];Nt(w.ranges,I=>{(I.row!==y.row||I.col!==y.col)&&z.push(I)}),a(y,z,E)}else for(const y of w.ranges)if(h==="down"){const z=y.startRow===y.endRow;if(z&&y.startRow===0)continue;const I=z?y.startRow-1:y.startRow;for(let H=y.startCol;H<=y.endCol;H+=1){const v=[];for(let R=z?y.startRow:y.startRow+1;R<=y.endRow;R+=1)v.push({row:R,col:H});a({row:I,col:H},v,E)}}else{const z=y.startCol===y.endCol;if(z&&y.startCol===0)continue;const I=z?y.startCol-1:y.startCol;for(let H=y.startRow;H<=y.endRow;H+=1){const v=[];for(let R=z?y.startCol:y.startCol+1;R<=y.endCol;R+=1)v.push({row:H,col:R});a({row:H,col:I},v,E)}}return E.length===0?!0:g.commitEdits(E,{source:"fill"})!==null},[a]),p=l.useCallback(h=>{const g=t.current,w=g.getSelection();if(!Pn("calc",w.ranges,g.maxOperationCells,g.onOperationRejected))return!1;const E=[],y=g.adapter;return Nt(w.ranges,z=>{const I=y.getCellFormula===void 0?void 0:y.getCellFormula(z.row,z.col),H=I===void 0?h.text(y.getCellText(z.row,z.col)):h.formula(I);H!==null&&E.push({row:z.row,col:z.col,text:H})}),E.length===0?!0:g.commitEdits(E,{source:"calc"})!==null},[]),S=l.useCallback((h,g)=>{const w=t.current,E=h==="row"?w.rowAxis:w.colAxis,y=w.getSelection(),z=h==="row"?Math.floor(w.maxOperationCells/Wo):w.maxOperationCells;let I=0;for(const f of y.ranges)I+=h==="row"?f.endRow-f.startRow+1:f.endCol-f.startCol+1;if(I>z)return w.onOperationRejected?.("resize",I,"limit"),!1;const H=new Set,v=[],R=g?0:h==="row"?w.defaultRowHeight:w.defaultColumnWidth;for(const f of y.ranges){const $=h==="row"?f.startRow:f.startCol,d=h==="row"?f.endRow:f.endCol;for(let C=$;C<=d;C+=1){if(H.has(C))continue;H.add(C),E.sizeOf(C)===0!==g&&v.push({index:C,size:R})}}const u=Yo(E,v,null,{maxOperationCells:w.maxOperationCells,rowHiddenLimit:Vo,axisKind:h});return u.ok?(u.entries.length>0&&w.resizeTracks(h,u.entries),!0):(w.onOperationRejected?.("resize",u.count,u.reason),!1)},[]),N=l.useCallback(()=>{const h=t.current;if(h.adapter.getCellHyperlink===void 0)return;const g=h.getActive();return kn(h.adapter.getCellHyperlink(g.row,g.col))},[]),P=l.useCallback(h=>{const g=t.current,w=g.adapter,E=Ki[h],y=w.getCellFormat!==void 0,z=I=>g.popovers===void 0?!0:g.popovers[I]!==!1;switch(E.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return y;case"value":return y&&(E.value!=="currency"||g.formats!==void 0);case"popover":switch(E.popover){case"link":return w.getCellHyperlink!==void 0&&z("link");case"note":return w.getCellNote!==void 0&&z("note");case"comment":return w.getCellComments!==void 0&&z("comment");default:return w.getCellValidation!==void 0&&z("list")}case"openHyperlink":return w.getCellHyperlink!==void 0&&(g.onHyperlinkOpen!==void 0?N()!==void 0:z("link"));case"paste":return E.options.mode==="formats"?y:E.options.mode==="formulas"?w.getCellFormula!==void 0:!0;default:return!0}},[N]),T=l.useCallback(h=>{const g=t.current;if(!P(h))return!1;const w=Ki[h],E=g.isEditing();if(E&&!ls.has(h)&&!g.requestCommit())return!1;switch(w.kind){case"toggle":{const y=r(),z=y!==void 0&&y[w.key]===!0;return s({[w.key]:z?null:!0})?(i(h,!z),!0):!1}case"patch":return s(w.patch)?(i(h,null),!0):!1;case"clear":return s(Jh)?(i(h,null),!0):!1;case"value":return s({value:lm(w.value,g.formats)})?(i(h,null),!0):!1;case"borders":return c(w.preset)?(i(h,null),!0):!1;case"color":{const y=w.key==="background"?g.colors.fill:g.colors.font,z=w.preset!==null?w.preset:w.custom!==null&&w.custom<y.length?y[w.custom]:void 0;if(z===void 0)return!1;const I=r(),H=im(I===void 0?void 0:I[w.key],z);return s({[w.key]:H?null:z})?(i(h,!H),!0):!1}case"calc":return p({text:y=>Kh(y,w.exponent),formula:y=>Gh(y,w.exponent)});case"sign":return p({text:Uh,formula:Zh});case"fill":{if(E&&w.direction==="selection"){const y=g.getSessionText();if(y===null)return!1;const z=g.getSelection();if(!Pn("fill",z.ranges,g.maxOperationCells,g.onOperationRejected))return!1;const I=[];let H=!1;return Nt(z.ranges,v=>{if(!H){if(!g.validateCommit(v,y).ok){H=!0;return}I.push({row:v.row,col:v.col,text:y})}}),H||g.commitEdits(I,{source:"fill"})===null?!1:(g.cancelEdit(),!0)}return m(w.direction)}case"popover":return g.openPopover(w.popover),!0;case"openHyperlink":{if(g.onHyperlinkOpen!==void 0){const y=N();return y===void 0?!1:(g.onHyperlinkOpen(y,g.getActive()),!0)}return g.openPopover("link"),!0}case"pasteSpecial":return g.onPasteSpecialRequest!==void 0?(g.onPasteSpecialRequest({kind:"keyboard",cellRect:g.keyboardCellRect()}),!0):(g.paste({mode:"formats"}),!0);case"paste":return g.paste(w.options),!0;case"insertNow":{const y=w.unit==="date"?Qh(g.now()):em(g.now());if(E)return g.insertAtCaret(y),!0;const z=g.getActive();return g.validateCommit(z,y).ok?g.commitEdits([{row:z.row,col:z.col,text:y}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return S(w.axis,w.hide);default:{const y=g.getHighlight();switch(w.target){case"row":return g.setHighlight({...y,row:!y.row}),!0;case"column":return g.setHighlight({...y,column:!y.column}),!0;case"both":{const z=y.row&&y.column;return g.setHighlight({...y,row:!z,column:!z}),!0}default:return g.setHighlight({...y,intersection:!y.intersection}),!0}}}},[P,N,r,s,i,c,p,m,S]),q=l.useCallback(()=>{const h=t.current;return!(h.isEditing()&&!h.requestCommit())},[]),K=l.useCallback(h=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const w=h===null?null:It(h);if(h!==null&&w===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(h)}`);if(!q())return!1;const E=g.getActive();return g.commitEdits([{row:E.row,col:E.col,hyperlink:w}],{source:"annotate"})!==null},[q]),k=l.useCallback(h=>{const g=t.current;if(g.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!q())return!1;const w=g.getActive();return g.commitEdits([{row:w.row,col:w.col,note:h}],{source:"annotate"})!==null},[q]),L=l.useCallback(h=>{const g=t.current,w=g.adapter.getCellComments;if(w===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!q())return!1;const E=g.getActive(),y=w(E.row,E.col),z=y===void 0?[h]:[...y,h];return g.commitEdits([{row:E.row,col:E.col,comments:z}],{source:"annotate"})!==null},[q]),D=l.useCallback(h=>{const g=t.current;if(g.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!q())return!1;const w=g.getSelection().ranges;if(!Pn("annotate",w,g.maxOperationCells,g.onOperationRejected))return!1;const E=[];return Nt(w,y=>{E.push({row:y.row,col:y.col,validation:h})}),g.commitEdits(E,{source:"annotate"})!==null},[q]),x=l.useCallback(h=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(h)},[s]),A=l.useCallback((h,g)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(h,g)},[c]);return l.useMemo(()=>({executeCommand:T,applyFormat:x,setBorders:A,setHyperlink:K,setNote:k,addComment:L,setValidation:D,isCommandAvailable:P}),[T,x,A,K,k,L,D,P])},kr="data-aqsp-pointing",am=(e,t)=>{const n=Vl(e,t);return n!==null&&"insertAt"in n},um=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},dm=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(null),[r,o]=l.useState(!1),s=l.useRef(!1),i=l.useRef(!1),c=l.useRef(!1),a=l.useRef(null),m=l.useRef(bt),p=l.useCallback(()=>{const v=t.current,R=v.sinkRef.current;if(v.adapter.getCellFormula===void 0||n.current===null||!c.current||R===null)return null;const u=Vl(R.value,R.selectionStart);return u===null?null:{sink:R,target:u}},[]),S=l.useCallback(()=>{const v=t.current.sinkRef.current;if(v===null)return;const R=p()!==null;R!==v.hasAttribute(kr)&&(R?v.setAttribute(kr,""):v.removeAttribute(kr))},[p]),N=l.useCallback((v,R)=>{const u=t.current;if(u.resolveEditPaint===void 0)return;const f=u.resolveEditPaint(R),$=f===null?bt:f;$!==bt&&Object.assign(v.style,$.style),m.current=$,u.editPaintRef!==void 0&&(u.editPaintRef.current=$)},[]),P=l.useCallback(v=>{um(v,Object.keys(m.current.style)),m.current=bt;const R=t.current.editPaintRef;R!==void 0&&(R.current=bt)},[]),T=l.useCallback(v=>{const R=t.current,u=n.current;if(u===null)return!0;const f=()=>{n.current=null,a.current=null;const $=R.sinkRef.current;$!==null&&($.style.removeProperty("text-align"),P($),$.removeAttribute(kr)),o(!1)};if(v.commit){const $=R.sinkRef.current,d=$===null?"":$.value,C=Rn(R.adapter,u.cell.row,u.cell.col).text.replace(/\r\n?/g,`
|
|
20
|
-
`),_=d===C,O={source:"edit",editSession:v.onReject==="keep"?"kept":"discarded"};if(!(_||(R.validateCommit===void 0||R.validateCommit(u.cell,d).ok)&&R.commitEdits([{row:u.cell.row,col:u.cell.col,text:d}],O)!==null))return v.onReject==="discard"&&(f(),R.rearmSink()),!1}return f(),v.rearm&&R.rearmSink(),!0},[P]),q=l.useCallback((v,R)=>{const u=t.current;if(u.isDragging()||n.current!==null)return;const f=u.sinkRef.current;if(f===null)return;u.discardClip();const $=u.getActive();if(u.ensureCellVisible($),v==="edit"){const{text:C,isFormula:_}=Rn(u.adapter,$.row,$.col);f.value=C;const O=R===void 0||_?C.length:Math.min(R,C.length);f.setSelectionRange(O,O)}else f.value="";const d=u.resolveEditAlign($);d!==null&&(f.style.textAlign=d),N(f,$),c.current=!1,a.current=null,n.current={cell:$,mode:v},o(!0)},[N]),K=l.useCallback(()=>{T({rearm:!0,commit:!1})},[T]),k=l.useCallback(()=>{const v=t.current;if(n.current===null)return!0;const R=v.sinkRef.current;if(s.current&&R!==null){i.current=!0;try{R.blur()}finally{i.current=!1}return T({rearm:!1,commit:!0,onReject:"keep"})?(v.focusSink(),v.rearmSink(),!0):(v.focusSink(),!1)}return T({rearm:!0,commit:!0,onReject:"keep"})},[T]),L=l.useCallback(()=>p()!==null,[p]),D=l.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,S(),!0),[S]),x=l.useCallback(()=>{const v=p(),R=n.current;if(v===null||R===null)return null;if("insertAt"in v.target)return a.current=R.cell,{origin:R.cell,cursor:R.cell,axis:"cells"};const u=Bl(v.sink.value,v.sink.selectionStart);if(u===null)return null;const f=u.token,$=a.current;switch(f.kind){case"cell":{const d={row:f.row,col:f.col};return a.current=d,{origin:d,cursor:d,axis:"cells"}}case"range":{const d=$!==null&&($.row===f.start.row||$.row===f.end.row)&&($.col===f.start.col||$.col===f.end.col)?{row:$.row,col:$.col}:{row:f.start.row,col:f.start.col};return a.current=d,{origin:d,cursor:{row:d.row===f.start.row?f.end.row:f.start.row,col:d.col===f.start.col?f.end.col:f.start.col},axis:"cells"}}case"column":{const d=$!==null&&($.col===f.start.col||$.col===f.end.col)?$.col:f.start.col,C={row:R.cell.row,col:d};return a.current=C,{origin:C,cursor:{row:R.cell.row,col:d===f.start.col?f.end.col:f.start.col},axis:"columns"}}case"row":{const d=$!==null&&($.row===f.start.row||$.row===f.end.row)?$.row:f.start.row,C={row:d,col:R.cell.col};return a.current=C,{origin:C,cursor:{row:d===f.start.row?f.end.row:f.start.row,col:R.cell.col},axis:"rows"}}}},[p]),A=l.useCallback((v,R)=>{const u=p();if(u===null)return;const f=Md(v,R),{sink:$}=u,[d,C]="replace"in u.target?u.target.replace:[u.target.insertAt,u.target.insertAt],_=$.value;$.value=`${_.slice(0,d)}${f}${_.slice(C)}`;const O=d+f.length;$.setSelectionRange(O,O),"row"in v&&(a.current={row:v.row,col:v.col}),S()},[p,S]),h=l.useCallback(()=>{const v=t.current.sinkRef.current;return v===null?null:{value:v.value,selectionStart:v.selectionStart,selectionEnd:v.selectionEnd}},[]),g=l.useCallback(v=>{const R=t.current.sinkRef.current;R!==null&&(R.value=v.value,R.setSelectionRange(v.selectionStart,v.selectionEnd),a.current=null,S())},[S]),w=l.useCallback(()=>{const v=t.current,R=v.sinkRef.current;if(v.adapter.getCellFormula===void 0||n.current===null||R===null)return!1;const u=Hd(R.value,R.selectionStart);return u===null?!1:(R.value=u.text,R.setSelectionRange(u.caret,u.caret),S(),!0)},[S]),E=l.useCallback(v=>{const R=t.current.sinkRef.current;if(n.current===null||R===null)return;const u=R.selectionStart,f=R.selectionEnd;R.value=`${R.value.slice(0,u)}${v}${R.value.slice(f)}`;const $=u+v.length;R.setSelectionRange($,$),a.current=null,S()},[S]),y=l.useCallback(()=>{const v=t.current.sinkRef.current;return n.current===null||v===null?null:v.value},[]),z=l.useCallback(()=>{const v=t.current,R=n.current,u=v.sinkRef.current;R===null||u===null||(P(u),N(u,R.cell),v.repaintOverlay?.())},[P,N]),{enabled:I,sinkRef:H}=e;return l.useEffect(()=>{const v=H.current;if(!I||v===null)return;const R=()=>{s.current=!0},u=()=>{s.current=!1},f=C=>{const _=t.current;if(i.current||n.current===null)return;const O=_.rootRef.current,M=C.relatedTarget;O!==null&&M instanceof Node&&O.contains(M)||T({rearm:!1,commit:!0,onReject:"discard"})},$=()=>{const C=t.current;a.current=null,C.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&am(v.value,v.selectionStart)&&(c.current=!0),S()},d=()=>{n.current!==null&&S()};return v.addEventListener("compositionstart",R),v.addEventListener("compositionend",u),v.addEventListener("focusout",f),v.addEventListener("input",$),document.addEventListener("selectionchange",d),()=>{v.removeEventListener("compositionstart",R),v.removeEventListener("compositionend",u),v.removeEventListener("focusout",f),v.removeEventListener("input",$),document.removeEventListener("selectionchange",d)}},[I,H,T,S]),l.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>i.current,requestCommit:k,cancelEdit:K,startEdit:q,getPointing:L,togglePointingArm:D,getReferenceCursor:x,insertReference:A,captureSink:h,restoreSink:g,cycleAnchorAtCaret:w,insertAtCaret:E,getSessionText:y,refreshPaint:z,editing:r}),[k,K,q,L,D,x,A,h,g,w,E,y,z,r])},fm=(e,t,n)=>{const r=new Gn.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const i=Math.round(n(s));i!==t&&r.update(s,i),i===0&&(o+=1)}return{tree:r,initialHidden:o}},pm=(e,t,n)=>{const{tree:r,initialHidden:o}=fm(e,t,n);let s=o;const a={count:e,sizeOf:m=>r.get(m),offsetOf:m=>{const{cumulative:p,currentValue:S}=r.prefixSum(m);return p-S},indexAt:m=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const p=Math.floor(m),S=Math.min(Math.max(p,0),r.getTotal()-1);return r.findIndexAtOrAfter(S+.5).index},totalSize:()=>r.getTotal(),resize:(m,p)=>{if(!(Number.isFinite(p)&&p>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${p}`);const S=Math.round(p);r.get(m)===0!=(S===0)&&(s+=S===0?1:-1),r.update(m,S)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},qt=(e,t,n)=>{if(n>0){const o=e.offsetOf(t)+e.sizeOf(t);return o>=e.totalSize()?null:e.indexAt(o)}const r=e.offsetOf(t)-1;return r<0?null:e.indexAt(r)},wn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:qt(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=qt(e,o,1);return r},Ui=(e,t,n)=>{if(!(Number.isInteger(t)&&t>0))throw new TypeError(`[spreadsheet] useAxisModel requires a positive integer defaultSize, received ${t}`);const r=l.useRef(n).current,o=l.useRef(null),s=`${e}:${t}`;return(o.current===null||o.current.key!==s)&&(o.current=pm(e,t,r)),o.current.model},Cn=256,Ro=256,hm=2**32,mm=4096,Uc=Object.freeze([]),Xc=["background","color","bold","italic","underline","strikethrough"],Gc=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},_t=(e,t,n)=>(e.size>=mm&&e.clear(),e.set(t,n),n),Zc=e=>(Gc(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Jc=(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},gm=(e,t,n)=>{const r=Math.floor(t/Cn),o=Math.floor(n/Ro),s=r*65536+o,i=e.buckets.get(s);if(i!==void 0)return i;const c=r*Cn,a=o*Ro,m=[];for(const p of e.rules)Jc(p.ranges,c,c+Cn-1,a,a+Ro-1)&&m.push(p);return _t(e.buckets,s,m.length===0?Uc:m)},wm=(e,t,n)=>{const r=Math.floor(t/Cn),o=r*hm+n,s=e.columns.get(o);if(s!==void 0)return s;const i=gm(e,t,n),c=r*Cn,a=[];for(const m of i)Jc(m.ranges,c,c+Cn-1,n,n)&&a.push(m);return _t(e.columns,o,a.length===0?Uc:a)},Cm=(e,t)=>{for(const n of e)if(Qt(n,t))return!0;return!1},cs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Sr=(e,t)=>e<t?-1:e>t?1:0,Xi=(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}},Gi=new WeakMap,Bo=e=>e===null?null:Number(e),bm=e=>{const t=Gi.get(e);if(t!==void 0)return t;const n=e.b,r={a:Bo(Ze(e.a)),b:n===void 0?null:Bo(Ze(n))};return Gi.set(e,r),r},Qc=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:_t(e.numbers,r,Bo(Ze(n())))},ym=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=bm(e),i=Qc(r,t,n),c=o?s.b:null;if(i!==null&&s.a!==null&&(!o||c!==null))return Xi(e.op,Sr(i,s.a),c===null?null:Sr(i,c));const a=n(),m=e.b;return Xi(e.op,Sr(a,e.a),m===void 0?null:Sr(a,m))},vm=(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}},ko=e=>{const t=Be(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]},Er=e=>e.toString(16).padStart(2,"0"),So=(e,t,n)=>{const r=i=>Math.round(e[i]+(t[i]-e[i])*n),o=`#${Er(r(0))}${Er(r(1))}${Er(r(2))}`,s=r(3);return s===255?o:`${o}${Er(s)}`},Eo=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Rm=(e,t,n,r,o)=>{let s=t.value===void 0?o.min:t.value,i=r.value===void 0?o.max:r.value,c=ko(t.color),a=ko(r.color);const m=n===void 0?void 0:ko(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(i))||c===null||a===null||m===null)return null;if(s>i){const S=s;s=i,i=S;const N=c;c=a,a=N}if(n!==void 0&&m!==void 0){const S=n.value===void 0?(s+i)/2:n.value;if(s<S&&S<i)return e<=S?So(c,m,Eo(e,s,S)):So(m,a,Eo(e,S,i))}return So(c,a,Eo(e,s,i))},km=(e,t,n,r)=>{const o=r.extrema.get(e.id);if(o!==void 0)return o;const{min:s,max:i}=t;if(s.value!==void 0&&i.value!==void 0)return _t(r.extrema,e.id,{min:s.value,max:i.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const m of e.ranges){const p=n.getRangeExtrema(m);if(p===null)return _t(r.extrema,e.id,null);c=Math.min(c,p.min),a=Math.max(a,p.max)}return _t(r.extrema,e.id,{min:c,max:a})},Sm=(e,t,n,r,o,s)=>{const i=Qc(s,n,r);if(i===null)return null;const c=km(e,t,o,s);return c===null?null:Rm(i,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}`,i=o.formulas.get(s),c=i!==void 0?i:_t(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},xm=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return ym(s,t,n,o)?e.style:null;case"text":return vm(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const i=Sm(e,s,t,n,r,o);return i===null?null:{...e.style,background:i}}case"customFormula":return Em(e,s,t,r,o)?e.style:null;default:return null}},Zi=(e,t)=>Xo(e,t),Am=(e,t,n)=>{e[t]=n},Om=(e,t)=>{let n=e;for(const r of Xc)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Am(n,r,t[r]));return n},Tm=e=>{let t="";for(const n of Xc){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Ji=new WeakMap,Dm=Object.freeze({}),Mm=e=>{const t=e===void 0?Dm:e,n=Ji.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Ji.set(t,r),r},$m=(e,t,n)=>{const r=Mm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=Zi(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=Tm(t),s=r.byKey.get(o);if(s!==void 0)return s;const i=Zi(e,t);return i!==void 0&&_t(r.byKey,o,i),i},as=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const i=e.getCellFormat(r,o);if(t===null)return i;const c=wm(t,r,o);if(c.length===0)return i;const a={row:r,col:o};let m=null,p=!0;for(const S of c){if(!Cm(S.ranges,a))continue;const N=xm(S,a,s,e,n);if(N!==null){if(N!==S.style&&(p=!1),m===null)m=N;else{const P=Om(m,N);P!==m&&(p=!1,m=P)}if(S.stopIfTrue===!0)break}}return m===null?i:$m(i,m,p)},Qi=new WeakMap,Fm=e=>{Gc(e,"widthRelevantRules");const t=Qi.get(e);if(t!==void 0)return t;const n=e.filter(o=>o.style.bold!==void 0||o.style.italic!==void 0||o.stopIfTrue===!0),r=n.length===e.length?e:n;return Qi.set(e,r),r},zm=({row:e,col:t,text:n,renderCell:r,__onCellRender:o})=>{const s=l.useRef(!1);return l.useEffect(()=>{const i=s.current?"update":"mount";s.current=!0,o?.(`cell-${e}-${t}`,i,0,0,0,0)}),r?r({row:e,col:t,text:n}):n},Nm=l.memo(zm),Lm=Object.freeze({left:Object.freeze({justifyContent:jn("left")}),center:Object.freeze({justifyContent:jn("center")}),right:Object.freeze({justifyContent:jn("right")})}),Pm=4096,el=new WeakMap,xr=new Map,qm=(e,t)=>{if(e===null)return Lm[t];let n=el.get(e);n===void 0&&(n={},el.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:jn(t)},s=JSON.stringify(o);let i=xr.get(s);return i===void 0&&(xr.size>=Pm&&xr.clear(),i=Object.freeze(o),xr.set(s,i)),n[t]=i,i},_m=cs(),Im=(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},Hm=(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 i=$r(e,o,s),c={};let a=null,m;if(e.getCellFormat!==void 0){const p=as(e,r===null?null:r.indexRef.current,r===null?_m:r.memoRef.current,o,s,i);m=p===void 0?void 0:p.value;const S=cc(p,i),N=qt(n,s,1),P=qt(t,o,1),T=cd(p,N===null?void 0:e.getCellFormat(o,N),P===null?void 0:e.getCellFormat(P,s),n.offsetOf(s)===0,t.offsetOf(o)===0);T!==null&&Object.assign(c,T.attrs),c["data-aqsp-align"]=S,a=qm(T,S)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const p=e.getCellComments(o,s);p!==void 0&&p.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&kn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const p=e.getCellValidation(o,s);p!==void 0&&ih(p,i())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:m}},jm=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:i,defaultColumnWidth:c,frozenColumns:a,frozenRows:m,frozenTrailingColumns:p,frozenTrailingRows:S,renderCell:N,onScroll:P,onRangeChange:T,focusSink:q,isEditing:K,requestCommit:k,testId:L,__onCellRender:D,cfIndexRef:x,cfMemoRef:A,isPointing:h})=>{const g=l.useRef(null),w=s??g;if(x===void 0!=(A===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const E=l.useMemo(()=>x===void 0||A===void 0?null:{indexRef:x,memoRef:A},[x,A]),y=l.useCallback(()=>r.get().editVersion,[r]),z=l.useCallback(B=>r.subscribeCoalesced(B),[r]),H=l.useSyncExternalStore(z,y,y)+(i??0),v=l.useCallback(B=>t.sizeOf(B),[t]),R=l.useCallback(B=>n.sizeOf(B),[n]),u=l.useCallback((B,X)=>e.getCellText(B,X),[e]),f=l.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),$=l.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),d=l.useMemo(()=>({width:it}),[]),C=l.useRef({row:-1,col:-1,value:void 0}),_=l.useCallback((B,X)=>{const J={role:"gridcell","aria-rowindex":B+1,"aria-colindex":X+1,"data-aqsp-cell":"","data-row":B,"data-col":X,className:"aqsp-cell"},G=Hm(e,t,n,E,B,X),se=C.current;return se.row=B,se.col=X,se.value=G===null?void 0:G.value,G===null?J:G.style===null?{...J,...G.attrs}:{...J,...G.attrs,style:G.style}},[e,t,n,E]),O=l.useCallback(B=>({role:"row","aria-rowindex":B+1,"data-aqsp-row":B,"data-aqsp-cells":"",className:"aqsp-row"}),[]),M=l.useCallback((B,X,J)=>{let G=B;return N===void 0&&e.getCellFormat!==void 0&&(G=yn(B,Im(C.current,X,J))),W.jsx(Nm,{row:X,col:J,text:G,renderCell:N,__onCellRender:D})},[H,N,D,e]);return W.jsx("div",{ref:w,className:"aqsp-body","data-aqsp-body":"","data-testid":L?`${L}-body`:void 0,onPointerDownCapture:B=>{if(!(B.target instanceof Element&&B.target.closest("[data-aqsp-cells]")!==null)&&B.pointerType==="mouse"){if(B.button!==0){B.preventDefault();return}if(B.preventDefault(),h?.()===!0){B.stopPropagation(),q();return}if(K()&&!k()){B.stopPropagation(),q();return}q()}},children:W.jsx(Gn.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:m,frozenTrailingCols:p,frozenTrailingRows:S,getRowHeight:v,getColWidth:R,getCell:u,getCellProps:_,getRowProps:O,contentProps:f,behaviorOptions:$,scrollBarOptions:d,callbackThrottleMs:0,onScroll:P,onRangeChange:T,testId:L,children:M})})},Bm=l.memo(jm),hn=6,Ge=3,Ir=(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:Ge});for(const s of t){const i=e.sizeOf(s),c=e.offsetOf(s)+i,a=qt(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-hn,length:Ge}),r.push({kind:"unhide",index:s+1,start:c-Ge,length:Ge})):i>=2*hn?n.push({kind:"resize",index:s,start:c-hn,length:hn}):n.push({kind:"resize",index:s,start:c-Ge,length:Ge})}return[...n,...r]},ea=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const a=e.sizeOf(c),m=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:m,length:Ge}),n.push({kind:"resize",index:c,start:m+Ge,length:Ge})):a>=2*hn?n.push({kind:"resize",index:c,start:m,length:hn}):n.push({kind:"resize",index:c,start:m,length:Ge})}const i=t[t.length-1];return i<e.count-1&&e.sizeOf(i+1)===0&&r.push({kind:"unhide",index:i+1,start:s-Ge,length:Ge}),[...n.reverse(),...r]},Vm=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:i,windowOriginXRef:c,repaintColHeaders:a,selectionRanges:m,enableResizeUI:p,dividerLeadingRef:S,dividerTrailingRef:N})=>{const P=Gn.useWheelBridge(o),T=l.useCallback(d=>(s.current=d,P(d)),[s,P]),q=l.useCallback(()=>{const{colStart:d,colEnd:C,colVersion:_}=e.get();return`${d}:${C}:${_}`},[e]),K=l.useCallback(d=>e.subscribeCoalesced(d),[e]);l.useSyncExternalStore(K,q,q);const{colStart:k,colEnd:L}=e.get(),D=t.count===0?0:t.offsetOf(Math.min(k,t.count-1));l.useLayoutEffect(()=>{c.current=D,a()},[D,c,a]);const x=d=>m.some(C=>d>=C.startCol&&d<=C.endCol),A=Math.min(Math.max(0,n),t.count),h=Oc(t,A),g=A>0?wn(t,0,A-1):[],w=Math.min(Math.max(0,r),t.count-A),E=Dc(t,w),y=t.totalSize()-E,z=w>0?wn(t,t.count-w,t.count-1):[],I=wn(t,Math.max(k,A),Math.min(L,Math.max(0,t.count-1)-w)),H=[];for(const d of I)H.push(W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":x(d)?"":void 0,style:{left:t.offsetOf(d)-D,width:t.sizeOf(d)},children:Wn(d)},d));const v=p?Ir(t,I):null,R=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<A&&h>0||d.kind==="unhide"&&d.index>=t.count-w&&E>0)),u=p&&A>0?Ir(t,g):null,f=p&&w>0?ea(t,z):null,$=W.jsxs("div",{ref:i,className:"aqsp-col-header-track",children:[H,R?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-D,width:d.length}},`r${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-D,width:d.length}},`u${d.index}`))]});return W.jsx("div",{ref:T,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:A===0&&w===0?$:W.jsxs(W.Fragment,{children:[g.map(d=>W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":x(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Wn(d)},d)),u?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),W.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:h,right:w>0?`calc(${it}px + min(${E}px, max(0px, 100% - ${it+h}px)))`:void 0},children:[$,A>0?W.jsx("div",{ref:S,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,w>0?W.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),w>0?W.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${h}px, calc(100% - ${E+it}px))`,right:it},children:W.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:E},children:[z.map(d=>W.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":x(d)?"":void 0,style:{left:t.offsetOf(d)-y,width:t.sizeOf(d)},children:Wn(d)},d)),f?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},Wm=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:i,repaintHeaders:c,enableResizeUI:a,frozenRows:m,frozenTrailingRows:p,dividerLeadingRef:S,dividerTrailingRef:N})=>{const P=Gn.useWheelBridge(n),T=l.useCallback(d=>(r.current=d,P(d)),[r,P]),q=d=>o.some(C=>d>=C.startRow&&d<=C.endRow),K=l.useCallback(()=>{const{rowStart:d,rowEnd:C,rowGeomVersion:_}=e.get();return`${d}:${C}:${_}`},[e]),k=l.useCallback(d=>e.subscribeCoalesced(d),[e]);l.useSyncExternalStore(k,K,K);const{rowStart:L,rowEnd:D}=e.get(),x=t.count===0?0:t.offsetOf(Math.min(L,t.count-1));l.useLayoutEffect(()=>{i.current=x,c()},[x,i,c]);const A=Math.min(Math.max(0,m),t.count),h=Tc(t,A),g=A>0?wn(t,0,A-1):[],w=Math.min(Math.max(0,p),t.count-A),E=Mc(t,w),y=t.totalSize()-E,z=w>0?wn(t,t.count-w,t.count-1):[],I=wn(t,Math.max(L,A),Math.min(D,Math.max(0,t.count-1)-w)),H=[];for(const d of I)H.push(W.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d)-x,height:t.sizeOf(d)},children:d+1},d));const v=a?Ir(t,I):null,R=v===null?null:v.filter(d=>!(d.kind==="unhide"&&d.index<A&&h>0||d.kind==="unhide"&&d.index>=t.count-w&&E>0)),u=a&&A>0?Ir(t,g):null,f=a&&w>0?ea(t,z):null,$=W.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[H,R?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-x,height:d.length}},`r${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-x,height:d.length}},`u${d.index}`))]});return W.jsx("div",{ref:T,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:it},children:A===0&&w===0?$:W.jsxs(W.Fragment,{children:[g.map(d=>W.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),u?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),W.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:h,bottom:w>0?`calc(min(${E}px, max(0px, 100% - ${h}px)))`:void 0},children:[$,A>0?W.jsx("div",{ref:S,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,w>0?W.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),w>0?W.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${h}px, calc(100% - ${E}px))`},children:W.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:E},children:[z.map(d=>W.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":q(d)?"":void 0,style:{top:t.offsetOf(d)-y,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?W.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):W.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},Ym=9,Km=4,Um=(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,i=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,a=`${o} ${s} ${i} ${c}`;return t.set(e,a),a},tl=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,Xm=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(!1),r=l.useRef(null),o=l.useRef(0),s=l.useRef(null),i=l.useRef(0),c=l.useRef(null),a=l.useRef(null),m=l.useRef(""),p=l.useRef(null),S=l.useCallback(A=>s.current!==null?A.pointerId===s.current:A.pointerType==="mouse",[]),N=l.useCallback(()=>{const A=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),A.writeResizeGuide(null);const h=p.current;h!==null&&(window.removeEventListener("pointermove",h.move),window.removeEventListener("pointerup",h.up),p.current=null);const g=c.current;g!==null&&s.current!==null&&g.hasPointerCapture?.(s.current)&&g.releasePointerCapture(s.current),c.current=null,s.current=null,A.repaintOverlay()},[]),P=l.useCallback((A,h)=>{const g=t.current;return A==="col"?h.startRow===0&&h.endRow===g.rowAxis.count-1:h.startCol===0&&h.endCol===g.colAxis.count-1},[]),T=l.useCallback((A,h)=>{const g=t.current,w=g.getSelection().ranges.filter(H=>P(A,H));if(!w.some(H=>A==="col"?h>=H.startCol&&h<=H.endCol:h>=H.startRow&&h<=H.endRow))return[h];const y=w.reduce((H,v)=>H+(A==="col"?v.endCol-v.startCol+1:v.endRow-v.startRow+1),0),z=A==="row"?Math.floor(g.maxOperationCells/Wo):g.maxOperationCells;if(y>z)return g.onOperationRejected?.("resize",y,"limit"),null;const I=new Set;for(const H of w){const v=A==="col"?H.startCol:H.startRow,R=A==="col"?H.endCol:H.endRow;for(let u=v;u<=R;u+=1)I.add(u)}return[...I]},[P]),q=l.useCallback((A,h,g)=>{const w=t.current,E=A==="col"?w.colAxis:w.rowAxis,y=Yo(E,h,g,{maxOperationCells:w.maxOperationCells,rowHiddenLimit:Vo,axisKind:A});if(!y.ok){w.onOperationRejected?.("resize",y.count,y.reason);return}w.resizeTracks(A,y.entries)},[]),K=l.useCallback((A,h)=>{if(h===A.initialSize)return;const g=A.kind==="unhide"?[A.index]:T(A.axis,A.index);g!==null&&q(A.axis,g.map(w=>({index:w,size:h})),A.index)},[T,q]),k=l.useCallback((A,h)=>{const g=t.current,w=T("col",h);if(w===null)return;const E=g.handleRef.current,y=E===null?null:E.getFrozenSize(),z=y===null?0:y.rows,I=y===null?0:y.trailingRows,{rowStart:H,rowEnd:v}=g.viewStore.get(),R=Math.min(v,g.rowAxis.count-1),u=[],f=new Set,$=Q=>{!f.has(Q)&&g.rowAxis.sizeOf(Q)>0&&(f.add(Q),u.push(Q))};for(let Q=0;Q<z;Q+=1)$(Q);for(let Q=H;Q<=R;Q+=1)$(Q);for(let Q=g.rowAxis.count-I;Q<g.rowAxis.count;Q+=1)$(Q);if(u.length===0)return;const d=w.length*u.length,C=Math.floor(g.maxOperationCells/Km);if(d>C){g.onOperationRejected?.("resize",d,"limit");return}const _=document.createElement("canvas").getContext("2d");if(_===null)return;const O=getComputedStyle(A),M=`${O.fontStyle} ${O.fontWeight} ${O.fontSize} ${O.fontFamily}`,B=g.adapter.getConditionalFormats===void 0?null:Fm(g.adapter.getConditionalFormats()),X=cs(),J=new WeakMap,G=new Map;for(const Q of w){const ie=B===null?null:Zc(B.filter(Le=>Le.ranges.some(ae=>Q>=ae.startCol&&Q<=ae.endCol)));for(const Le of u){const ae=g.adapter.getCellText(Le,Q),Ne=g.adapter.getCellFormat===void 0?void 0:as(g.adapter,ie,X,Le,Q,()=>ae),ct=Ne===void 0?M:Um(Ne,J,O),dt=yn(ae,Ne===void 0?void 0:Ne.value),ft=G.get(ct);ft===void 0?G.set(ct,[{col:Q,text:dt}]):ft.push({col:Q,text:dt})}}const se=new Map;for(const[Q,ie]of G){_.font=Q;for(const Le of ie){const ae=_.measureText(Le.text).width,Ne=se.get(Le.col);(Ne===void 0||ae>Ne)&&se.set(Le.col,ae)}}const he=[];for(const Q of w){const ie=se.get(Q);ie!==void 0&&ie>0&&he.push({index:Q,size:Math.ceil(ie)+Ym})}he.length!==0&&q("col",he,h)},[T,q]),{enabled:L,colBandRef:D,rowBandRef:x}=e;return l.useEffect(()=>{const A=D.current,h=x.current;if(!L||A===null||h===null)return;const g=C=>C==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",w=(C,_)=>{if(!(_ instanceof Element))return null;const O=_.closest(g(C));if(O===null)return null;const M=O.hasAttribute("data-aqsp-unhide"),B=Number(O.getAttribute(M?"data-aqsp-unhide":C==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),X=O.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:M?"unhide":"resize",index:B,anchor:X}},E=C=>{if(!(n.current&&S(C)))return;const _=r.current;if(_===null)return;const O=(_.axis==="col"?C.clientX-_.startClientX:C.clientY-_.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(_.anchor==="trailing"?_.initialSize-O:_.initialSize+O)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const M=r.current;if(!n.current||M===null)return;const B=t.current,X=M.axis==="col"?B.colAxis:B.rowAxis;B.writeResizeGuide({axis:M.axis,position:tl(M,X,o.current),anchor:M.anchor})}))},y=()=>{const C=r.current,_=o.current;N(),C!==null&&K(C,_)},z=C=>{E(C),n.current&&S(C)&&(i.current&1)!==0&&(C.buttons&1)===0&&y()},I=C=>{C.button!==0||!(n.current&&S(C))||y()},H=(C,_)=>O=>{const M=t.current;if(m.current=O.pointerType,O.pointerType!=="mouse")return;if(O.button!==0){O.preventDefault();return}const B=w(C,O.target);if(B===null)return;if(O.stopPropagation(),O.preventDefault(),M.isPointing()){M.focusSink();return}if(M.isEditing()&&!M.requestCommit()){M.focusSink();return}M.focusSink();const X=C==="col"?M.colAxis:M.rowAxis,J={axis:C,kind:B.kind,index:B.index,anchor:B.anchor,initialSize:X.sizeOf(B.index),startClientX:O.clientX,startClientY:O.clientY};r.current=J,o.current=J.initialSize,i.current=O.buttons,n.current=!0,M.repaintOverlay(),s.current=O.pointerId,c.current=_;try{_.setPointerCapture(O.pointerId)}catch{s.current=null}const G=z,se=I;p.current={move:G,up:se},window.addEventListener("pointermove",G),window.addEventListener("pointerup",se),M.writeResizeGuide({axis:C,position:tl(J,X,o.current),anchor:J.anchor})},v=(C,_)=>O=>{const M=t.current;if(m.current!=="mouse")return;const B=_.getRootNode(),X=B instanceof ShadowRoot?B:_.ownerDocument,J=O.target instanceof Element&&O.target.closest(g(C))!==null?O.target:typeof X.elementFromPoint=="function"?X.elementFromPoint(O.clientX,O.clientY):null,G=w(C,J);if(G!==null){if(O.stopPropagation(),M.isEditing()){M.focusSink();return}if(G.kind==="unhide"){q(C,[{index:G.index,size:C==="col"?M.defaultColumnWidth:M.defaultRowHeight}],null);return}if(M.autofitEnabled){if(C==="row"){const se=T("row",G.index);se!==null&&q("row",se.map(he=>({index:he,size:M.defaultRowHeight})),G.index);return}k(_,G.index)}}},R=C=>{!n.current||s.current===null||C.pointerId!==s.current||N()},u=H("col",A),f=H("row",h),$=v("col",A),d=v("row",h);return A.addEventListener("pointerdown",u,{capture:!0}),h.addEventListener("pointerdown",f,{capture:!0}),A.addEventListener("dblclick",$),h.addEventListener("dblclick",d),A.addEventListener("lostpointercapture",R),h.addEventListener("lostpointercapture",R),()=>{A.removeEventListener("pointerdown",u,{capture:!0}),h.removeEventListener("pointerdown",f,{capture:!0}),A.removeEventListener("dblclick",$),h.removeEventListener("dblclick",d),A.removeEventListener("lostpointercapture",R),h.removeEventListener("lostpointercapture",R),N()}},[L,D,x,S,N,K,q,T,k]),l.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N])},us=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Gm=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>us(n,t.ranges[r]))&&vt(e.anchor,t.anchor)&&vt(e.active,t.active),Zm=(e,t)=>{const n=e.ranges[e.ranges.length-1];return us(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Xn=(e,t,n)=>n.extend?Gt(e,t):n.append?{ranges:[...e.ranges,Ce(t,t)],anchor:t,active:t}:e.ranges.length===1&&vt(e.anchor,t)&&vt(e.active,t)&&us(e.ranges[0],Ce(t,t))?e:{ranges:[Ce(t,t)],anchor:t,active:t},Jm=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Gt=(e,t)=>{const n=Zm(e,Ce(e.anchor,t));return n.ranges.some(r=>Qt(r,n.active))?n:{...n,active:Jm(n.active,n.ranges[n.ranges.length-1])}},ta=(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 a=Math.max(c.startRow,t.startRow),m=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Ce({row:a,col:c.startCol},{row:m,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Ce({row:a,col:t.endCol+1},{row:m,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=>Qt(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 i={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:i,active:i}},Qm=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,i=e[s];return{rangeIndex:s,cell:{row:i.endRow,col:i.endCol}}},na=(e,t)=>{const n=e.ranges.findIndex(o=>Qt(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=Qm(e.ranges,r.rangeIndex,r.cell,t),!vt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Ct=24,nl=32,Hr=4,un=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:i})=>{const c=l.useRef(null),a=l.useRef(null),m=l.useRef(null),p=l.useRef(null),S=l.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,p.current=null,m.current=null},[]),N=l.useCallback(()=>{const T=a.current,q=e.current,K=p.current;if(T===null||q===null||K===null){c.current=null;return}const{clientX:k,clientY:L}=T.getPointerPosition(),D=i.current,x=(k-K.left)/D,A=(L-K.top)/D,h=q.getViewportSize(),g=h.width,w=h.height;if(g<=0||w<=0){c.current=requestAnimationFrame(N);return}const E=R=>Math.min(nl,Math.ceil(R/Ct*nl));let y=0,z=0;if(s!=="x"){const R=q.getFrozenSize(),u=R.trailingVisibleHeight;A>w-u-Ct?T.anchorRow!==void 0&&R.trailingRows>0&&T.anchorRow>=t.count-R.trailingRows&&u>0&&A>=w-u||(y=E(A-(w-u-Ct))):A<R.height+Ct&&(T.anchorRow!==void 0&&T.anchorRow<R.rows&&R.height>0&&A<R.height||(y=-E(R.height+Ct-A)))}if(s!=="y"){const R=q.getFrozenSize(),u=R.trailingVisibleWidth;x>g-u-Ct?T.anchorCol!==void 0&&R.trailingCols>0&&T.anchorCol>=n.count-R.trailingCols&&u>0&&x>=g-u||(z=E(x-(g-u-Ct))):x<R.width+Ct&&(T.anchorCol!==void 0&&T.anchorCol<R.cols&&R.width>0&&x<R.width||(z=-E(R.width+Ct-x)))}const I=z!==0||y!==0?q.scrollBy({x:z!==0?z:void 0,y:y!==0?y:void 0}):q.getScrollPosition(),H=I.y,v=I.x;if(H>=0&&v>=0&&t.totalSize()>0&&n.totalSize()>0){const R=q.getFrozenSize(),u=er({row:rr(t,A,{scroll:H,frozenSize:R.height,trailingSize:R.trailingHeight,extent:h.height}),col:nr(n,x,{scroll:v,frozenSize:R.width,trailingSize:R.trailingWidth,extent:h.width})},t.count,n.count),f=m.current;(y!==0||z!==0||f===null||f.row!==u.row||f.col!==u.col)&&(m.current=u,o(T.buildRange(u)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),P=l.useCallback(T=>{S(),a.current=T,p.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[S,N,r]);return l.useEffect(()=>{const T=()=>{document.visibilityState==="hidden"&&S()};return document.addEventListener("visibilitychange",T),()=>{document.removeEventListener("visibilitychange",T),S()}},[S]),l.useMemo(()=>({start:P,stop:S}),[P,S])},rl=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(!1),r=l.useRef(null),o=l.useRef(0),s=l.useRef(null),i=l.useRef({clientX:0,clientY:0}),c=l.useRef(null),a=l.useRef(null),m=l.useRef(0),p=l.useRef(null),S=l.useRef(!1),N=l.useRef(0),P=l.useCallback((h,g)=>{const{axis:w,mainAxis:E,handleRef:y,zoomRef:z}=t.current,I=s.current;if(I===null||E.totalSize()===0)return null;const H=z.current,v=y.current;if(v===null)return null;if(w==="col"){const $=v.getScrollPosition().x;if($<0)return null;const d=v.getFrozenSize(),C=v.getViewportSize();return Math.min(Math.max(nr(E,(h-I.left)/H,{scroll:$,frozenSize:d.width,trailingSize:d.trailingWidth,extent:C.width}),0),E.count-1)}const R=v.getScrollPosition().y;if(R<0)return null;const u=v.getFrozenSize(),f=v.getViewportSize();return Math.min(Math.max(rr(E,(g-I.top)/H,{scroll:R,frozenSize:u.height,trailingSize:u.trailingHeight,extent:f.height}),0),E.count-1)},[]),T=l.useCallback((h,g)=>{const{axis:w,crossCount:E}=t.current;return w==="col"?{press:{row:0,col:h},extend:{row:E-1,col:g}}:{press:{row:h,col:0},extend:{row:g,col:E-1}}},[]),q=l.useCallback((h,g)=>{const{axis:w,crossCount:E}=t.current;return h.ranges.some(y=>w==="col"?y.startRow===0&&y.endRow===E-1&&g>=y.startCol&&g<=y.endCol:y.startCol===0&&y.endCol===E-1&&g>=y.startRow&&g<=y.endRow)},[]),K=l.useRef(!1),k=l.useRef({clientX:0,clientY:0}),L=l.useCallback(()=>{K.current=!1;const{autoScroller:h,headerRef:g,onDragFrame:w}=t.current;n.current=!1,r.current=null,p.current=null,S.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),h.stop();const E=g.current;E!==null&&a.current!==null&&E.hasPointerCapture?.(a.current)&&E.releasePointerCapture(a.current),a.current=null,w(null),t.current.repaintOverlay()},[]),D=l.useCallback(()=>{if(!n.current)return;const h=r.current;h!==null&&t.current.setSelection(h),L()},[L]),{enabled:x,headerRef:A}=e;return l.useEffect(()=>{const h=A.current;if(!x||h===null)return;const g=v=>{const R=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}if(S.current=!1,R.pointing?.getPointing()){s.current=h.getBoundingClientRect();const d=P(v.clientX,v.clientY);if(d===null)return;v.preventDefault(),R.focusSink(),R.pointing.insertReference(R.axis==="col"?{row:0,col:d}:{row:d,col:0},R.axis==="col"?"columns":"rows");return}if(R.isEditing()&&!R.requestCommit()){v.preventDefault(),R.focusSink();return}s.current=h.getBoundingClientRect();const u=P(v.clientX,v.clientY);if(u===null)return;v.preventDefault(),R.focusSink();const f=R.getSelection();r.current=f;const $=v.ctrlKey||v.metaKey;if(v.shiftKey){const d=R.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:C}=T(u,u),_={...f,anchor:d};R.setSelection(Gt(_,C)),o.current=R.axis==="col"?d.col:d.row}else if($&&q(f,u))S.current=!0,N.current=u,o.current=u;else{const{press:d,extend:C}=T(u,u),_=Xn(f,d,{extend:!1,append:$});R.setSelection(Gt(_,C)),o.current=u}n.current=!0,R.repaintOverlay(),i.current={clientX:v.clientX,clientY:v.clientY},a.current=v.pointerId,m.current=v.buttons;try{h.setPointerCapture(v.pointerId)}catch{a.current=null}p.current=d=>{const C=t.current.axis==="col"?d.col:d.row,{press:_}=T(o.current,o.current),{extend:O}=T(o.current,C);return Ce(_,O)},R.autoScroller.stop(),K.current=!1,k.current={clientX:v.clientX,clientY:v.clientY}},w=v=>a.current!==null?v.pointerId===a.current:v.pointerType==="mouse",E=v=>{if(n.current&&w(v)){if(S.current){const R=v.clientX!==i.current.clientX||v.clientY!==i.current.clientY;if(i.current={clientX:v.clientX,clientY:v.clientY},!R)return;const u=P(v.clientX,v.clientY);if(u===null||u===N.current)return;S.current=!1;const f=t.current,{press:$,extend:d}=T(N.current,N.current),C=Xn(f.getSelection(),$,{extend:!1,append:!0});f.setSelection(Gt(C,d));const _=p.current,O=Math.abs(v.clientX-k.current.clientX),M=Math.abs(v.clientY-k.current.clientY);_!==null&&Math.max(O,M)>=Hr&&(K.current=!0,f.autoScroller.start({getPointerPosition:()=>i.current,buildRange:_,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(i.current={clientX:v.clientX,clientY:v.clientY},!K.current&&p.current!==null){const R=Math.abs(v.clientX-k.current.clientX),u=Math.abs(v.clientY-k.current.clientY);Math.max(R,u)>=Hr&&(K.current=!0,t.current.autoScroller.start({getPointerPosition:()=>i.current,buildRange:p.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const R=p.current;if(!n.current||R===null)return;const u=P(i.current.clientX,i.current.clientY);u!==null&&t.current.onDragFrame(R(t.current.axis==="col"?{row:0,col:u}:{row:u,col:0}))}))}},y=v=>{E(v),n.current&&w(v)&&(m.current&1)!==0&&(v.buttons&1)===0&&I(v)},z=v=>{v.button!==0||!(n.current&&w(v))||I(v)},I=v=>{const R=t.current;if(S.current){const{press:f,extend:$}=T(N.current,N.current);R.setSelection(ta(R.getSelection(),Ce(f,$),f)),L();return}const u=P(v.clientX,v.clientY);if(u!==null){const{extend:f}=T(o.current,u);R.setSelection(Gt(R.getSelection(),f))}L()},H=v=>{!n.current||a.current===null||v.pointerId!==a.current||D()};return h.addEventListener("pointerdown",g),h.addEventListener("pointermove",y),h.addEventListener("pointerup",z),h.addEventListener("lostpointercapture",H),()=>{h.removeEventListener("pointerdown",g),h.removeEventListener("pointermove",y),h.removeEventListener("pointerup",z),h.removeEventListener("lostpointercapture",H),L()}},[x,A,P,T,L,D]),l.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:D,cancelDrag:L}),[D,L])},eg=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:i}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(i<0||s<0)return;const m=o.getFrozenSize();if(a>0&&r.row>=m.rows&&r.row<t.count-m.trailingRows){const p=t.offsetOf(r.row),S=p+t.sizeOf(r.row);p<m.height+i?o.scrollBy({y:p-(m.height+i)}):S>i+a-m.trailingVisibleHeight&&o.scrollBy({y:S-(i+a-m.trailingVisibleHeight)})}if(c>0){if(r.col<m.cols||r.col>=n.count-m.trailingCols)return;const p=n.offsetOf(r.col),S=p+n.sizeOf(r.col);p<m.width+s?o.scrollBy({x:p-(m.width+s)}):S>s+c-m.trailingVisibleWidth&&o.scrollBy({x:S-(s+c-m.trailingVisibleWidth)})}},tg=50,ng=100,ra=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<tg:!1,qn={selectAll:Xt("Ctrl+A"),undo:Xt("Ctrl+Z"),redo:Xt("Ctrl+Y"),redoShiftZ:Xt("Ctrl+Shift+Z"),pasteValues:Xt("Ctrl+Shift+V")},rg=new Set(["Shift","Control","Alt","Meta","AltGraph"]),og={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},sg=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",ig=e=>{const t=l.useRef(null),n=l.useRef(null),r=l.useRef(!1),o=l.useRef(!1),s=l.useRef(e);s.current=e;const{enabled:i,sinkRef:c,rootRef:a,handleRef:m}=e;l.useEffect(()=>{const p=c.current,S=a.current;if(!i||p===null||S===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},P=(u,f,$)=>qt(u,f,$)??f,T=(u,f)=>{const $=s.current;return f==="left"||f==="right"?{row:u.row,col:P($.colAxis,u.col,f==="right"?1:-1)}:{row:P($.rowAxis,u.row,f==="down"?1:-1),col:u.col}},q=u=>u.indexAt(0),K=u=>u.indexAt(u.totalSize()-1),k=(u,f,$,d)=>{if(u.sizeOf(f)>0)return f;const C=qt(u,f,$);if(C!==null)return C;const _=qt(u,f,$===1?-1:1);return _!==null?_:d},L=()=>{const u=s.current.getSelection(),f=u.ranges[u.ranges.length-1];return{row:u.anchor.row===f.startRow?f.endRow:f.startRow,col:u.anchor.col===f.startCol?f.endCol:f.startCol}},D=u=>T(L(),u),x=(u,f)=>{const $=s.current,d=f==="left"||f==="right",C=f==="right"||f==="down"?1:-1;let _;return $.findDataEdge!==void 0?(_=$.findDataEdge({row:u.row,col:u.col},f),A(_,u,f)):_={row:f==="down"?$.rowAxis.count-1:f==="up"?0:u.row,col:f==="right"?$.colAxis.count-1:f==="left"?0:u.col},d?{row:_.row,col:k($.colAxis,_.col,C,u.col)}:{row:k($.rowAxis,_.row,C,u.row),col:_.col}},A=(u,f,$)=>{const d=s.current;if(!(Number.isInteger(u.row)&&Number.isInteger(u.col)&&u.row>=0&&u.row<d.rowAxis.count&&u.col>=0&&u.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${u.row}, col: ${u.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const C=$==="left"||$==="right";if(C?u.row!==f.row:u.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${C?"row":"column"} (received {row: ${u.row}, col: ${u.col}} from {row: ${f.row}, col: ${f.col}})`)},h=(u,f,$)=>{if(!(Number.isInteger(u)&&u>=0&&u<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${$} component ${u} (count ${f})`)},g=u=>{const f=s.current,$=f.getSelection();if(na($,u)===$){f.moveActive({mode:"reset",cell:T($.active,u)});return}f.moveActive({mode:"cycle",direction:u})},w=()=>{const u=c.current;if(u===null)return;const f=u.selectionStart??u.value.length,$=u.selectionEnd??f;u.value=`${u.value.slice(0,f)}
|
|
21
|
-
${u.value.slice($)}`,u.setSelectionRange(f+1,f+1)},E=(u,f)=>{const $=s.current,d=m.current?.getViewportSize().height??-1;return d<=0?P($.rowAxis,u,f==="down"?1:-1):$.rowAxis.indexAt($.rowAxis.offsetOf(u)+(f==="down"?d:-d))},y=u=>{const f=s.current;if(r.current=!1,ra(u,t.current))return;const $=u.ctrlKey||u.metaKey,d=u.altKey,C=og[u.key];if(o.current&&!rg.has(u.key)&&!f.isDragging()&&N(),f.isEditing()){const O=f.getEditingMode();if(f.isDragging()){u.preventDefault(),u.key==="Escape"&&!$&&!u.shiftKey&&!d&&f.abortDrag();return}const M=f.pointing;if(M!==void 0){if(C!==void 0&&!d){const X=M.getReferenceCursor();if(X!==null){u.preventDefault();const J=$?x(X.cursor,C):T(X.cursor,C);if(f.ensureCellVisible(J),M.insertReference(u.shiftKey?Ce(X.origin,J):J,X.axis),f.onPointFrame!==void 0){const G=u.shiftKey?Ce(X.origin,J):Ce(J,J);f.onPointFrame(X.axis==="columns"?Ce({row:0,col:G.startCol},{row:f.rowAxis.count-1,col:G.endCol}):X.axis==="rows"?Ce({row:G.startRow,col:0},{row:G.endRow,col:f.colAxis.count-1}):G),o.current=!0}return}}if(u.key==="F2"&&!$&&!u.shiftKey&&!d&&M.togglePointingArm()){u.preventDefault();return}if(u.key==="F4"&&!$&&!u.shiftKey&&!d&&M.cycleAnchorAtCaret()){u.preventDefault();return}}const B=f.commands;if(B!==void 0){const X=yi(B.table,u);if(X!==null&&ls.has(X)&&B.isAvailable(X)){u.preventDefault(),B.execute(X);return}}if(C!==void 0&&!d){if($&&u.shiftKey){u.preventDefault();return}if($)return;if(O==="replace"){if(u.preventDefault(),!f.requestCommit())return;u.shiftKey?f.moveActive({mode:"extend",cell:D(C)}):f.moveActive({mode:"reset",cell:T(f.getSelection().active,C)});return}return}if(u.key==="Enter"&&d&&!$&&!u.shiftKey){u.preventDefault(),w();return}if((u.key==="Enter"||u.key==="Tab")&&!$&&!d){if(u.preventDefault(),!f.requestCommit())return;const X=!u.shiftKey;g(u.key==="Tab"?X?"right":"left":X?"down":"up");return}if((u.key==="PageUp"||u.key==="PageDown")&&!u.shiftKey&&!$&&!d){if(u.preventDefault(),!f.requestCommit())return;const X=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E(X.row,u.key==="PageDown"?"down":"up"),col:X.col}});return}if(u.key==="Escape"&&!$&&!u.shiftKey&&!d){u.preventDefault(),f.cancelEdit();return}return}if(u.defaultPrevented)return;if(f.isDragging()&&u.key!=="Escape"){u.preventDefault();return}const _=f.commands;if(_!==void 0){const O=yi(_.table,u);if(O!==null&&_.isAvailable(O)){u.preventDefault(),_.execute(O);return}}if(C!==void 0&&!d){const O=C==="left"||C==="right",M=C==="right"||C==="down"?1:-1;if($&&u.shiftKey){u.preventDefault();const B=f.getSelection(),X=L();let J;if(f.findDataEdge!==void 0){const G=O?{row:B.active.row,col:X.col}:{row:X.row,col:B.active.col},se=f.findDataEdge(G,C);J=O?se.col:se.row,h(J,O?f.colAxis.count:f.rowAxis.count,O?"col":"row"),J=k(O?f.colAxis:f.rowAxis,J,M,O?X.col:X.row)}else{const G=O?f.colAxis:f.rowAxis;J=M===1?K(G):q(G)}f.moveActive({mode:"extend",cell:O?{row:X.row,col:J}:{row:J,col:X.col}});return}if($){u.preventDefault(),f.moveActive({mode:"reset",cell:x(f.getSelection().active,C)});return}if(u.shiftKey){u.preventDefault(),f.moveActive({mode:"extend",cell:D(C)});return}u.preventDefault(),f.moveActive({mode:"reset",cell:T(f.getSelection().active,C)});return}if(sg(u)){u.preventDefault();return}if((u.key==="Tab"||u.key==="Enter")&&!$&&!d){u.preventDefault();const O=!u.shiftKey;g(u.key==="Tab"?O?"right":"left":O?"down":"up");return}if(u.key==="Home"&&!d){if(u.preventDefault(),u.shiftKey){const M=L();f.moveActive({mode:"extend",cell:{row:$?q(f.rowAxis):M.row,col:q(f.colAxis)}});return}const O=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:$?q(f.rowAxis):O.row,col:q(f.colAxis)}});return}if(u.key==="End"&&!d){if(u.preventDefault(),u.shiftKey){const M=L();f.moveActive({mode:"extend",cell:{row:$?K(f.rowAxis):M.row,col:K(f.colAxis)}});return}const O=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:$?K(f.rowAxis):O.row,col:K(f.colAxis)}});return}if((u.key==="PageUp"||u.key==="PageDown")&&!$&&!d){u.preventDefault();const O=u.key==="PageDown"?"down":"up";if(u.shiftKey){const B=L();f.moveActive({mode:"extend",cell:{row:E(B.row,O),col:B.col}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E(M.row,O),col:M.col}});return}if(u.key==="F2"&&!$&&!u.shiftKey&&!d){u.preventDefault(),f.startEdit("edit");return}if((u.key==="Delete"||u.key==="Backspace")&&!$&&!u.shiftKey&&!d){u.preventDefault();const O=f.getSelection(),M=Pr(O.ranges);if(M>f.maxOperationCells){f.onOperationRejected?.("delete",M,"limit");return}const B=[],X=f.adapter!==void 0&&Fr(f.adapter).hyperlink;Nt(O.ranges,J=>{B.push(X?{row:J.row,col:J.col,text:"",hyperlink:null}:{row:J.row,col:J.col,text:""})}),f.commitEdits(B,{source:"delete"});return}if(u.key==="Escape"){if(f.isDragging()){u.preventDefault(),f.abortDrag();return}if($||u.shiftKey||d||(u.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(Nn(qn.selectAll,u)){u.preventDefault();const O=f.getSelection(),M=Ce({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[M],anchor:O.anchor,active:O.active});return}if(Nn(qn.undo,u)){u.preventDefault(),f.onUndoRequest?.();return}if(Nn(qn.redo,u)||Nn(qn.redoShiftZ,u)){u.preventDefault(),f.onRedoRequest?.();return}if(u.key==="F10"&&u.shiftKey&&!$&&!d||u.key==="ContextMenu"&&!$&&!u.shiftKey&&!d){u.preventDefault();const O=f.getSelection().active;f.ensureCellVisible(O);const M=m.current,B=M===null?{x:0,y:0}:M.getScrollPosition(),X=Math.max(0,B.y),J=Math.max(0,B.x),G=M===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:M.getFrozenSize(),se=M===null?{width:0,height:0}:M.getViewportSize(),he=f.zoomRef.current;f.onCellContextMenu?.(O,{kind:"keyboard",cellRect:{top:Jt(f.rowAxis,O.row,{scroll:X,frozenCount:G.rows,trailingCount:G.trailingRows,extent:se.height})*he,left:Zt(f.colAxis,O.col,{scroll:J,frozenCount:G.cols,trailingCount:G.trailingCols,extent:se.width})*he,width:f.colAxis.sizeOf(O.col)*he,height:f.rowAxis.sizeOf(O.row)*he}});return}if(u.key===" "&&!d&&$!==u.shiftKey){u.preventDefault();const O=f.getSelection(),M=O.ranges.map(B=>$?Ce({row:0,col:B.startCol},{row:f.rowAxis.count-1,col:B.endCol}):Ce({row:B.startRow,col:0},{row:B.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:M,anchor:O.anchor,active:O.active});return}if(f.pendingPasteOptionsRef!==void 0&&Nn(qn.pasteValues,u)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(u.key.length===1&&!u.metaKey&&u.ctrlKey===u.altKey){if(u.ctrlKey&&u.altKey){r.current=!0;return}f.startEdit("replace");return}},z=()=>{const u=s.current;u.isEditing()||u.startEdit("replace")},I=u=>{t.current=u.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},ng)},H=()=>{const u=s.current;if(N(),!u.isEditing()){if(r.current){r.current=!1;const f=p.value;if(f!==""&&(u.startEdit("replace"),u.isEditing())){p.value=f,p.setSelectionRange(f.length,f.length);return}}u.rearmSink()}},v=()=>{r.current=!1;const u=s.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null)},R=()=>{r.current=!1;const u=s.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null),N()};return p.addEventListener("keydown",y),p.addEventListener("keyup",v),p.addEventListener("blur",R),p.addEventListener("compositionstart",z),p.addEventListener("compositionend",I),p.addEventListener("input",H),()=>{p.removeEventListener("keydown",y),p.removeEventListener("keyup",v),p.removeEventListener("blur",R),p.removeEventListener("compositionstart",z),p.removeEventListener("compositionend",I),p.removeEventListener("input",H),n.current!==null&&window.clearTimeout(n.current),N()}},[i,c,a,m])},lg=4,cg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),ag=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(!1),r=l.useRef(null),o=l.useRef(null),s=l.useRef(null),i=l.useRef({clientX:0,clientY:0}),c=l.useRef({clientX:0,clientY:0}),a=l.useRef(!1),m=l.useRef({dx:0,dy:0}),p=l.useRef(null),S=l.useRef(0),N=l.useRef(null),P=l.useRef(null),T=l.useRef(!1),q=l.useCallback(h=>p.current!==null?h.pointerId===p.current:h.pointerType==="mouse",[]),K=l.useCallback((h,g)=>{const{handleRef:w,rowAxis:E,colAxis:y}=t.current,z=w.current,I=s.current;if(z===null||I===null)return null;const{x:H,y:v}=z.getScrollPosition();if(v<0||H<0||E.totalSize()===0||y.totalSize()===0)return null;const R=t.current.zoomRef.current,u=z.getFrozenSize(),f=z.getViewportSize();return er({row:rr(E,(g-I.top)/R,{scroll:v,frozenSize:u.height,trailingSize:u.trailingHeight,extent:f.height}),col:nr(y,(h-I.left)/R,{scroll:H,frozenSize:u.width,trailingSize:u.trailingWidth,extent:f.width})},E.count,y.count)},[]),k=l.useCallback(h=>{const g=r.current;if(g===null)return Ce(h,h);const w=Ce({row:Math.min(g.startRow,h.row),col:Math.min(g.startCol,h.col)},{row:Math.max(g.endRow,h.row),col:Math.max(g.endCol,h.col)}),E=w.startRow!==g.startRow||w.endRow!==g.endRow||w.startCol!==g.startCol||w.endCol!==g.endCol;return o.current=E?w:null,E?w:g},[]),L=l.useCallback(()=>{const h=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),h.xAutoScroller.stop(),h.yAutoScroller.stop(),T.current=!1,a.current=!1,m.current={dx:0,dy:0},h.writeFillPreview(null);const g=P.current;g!==null&&(window.removeEventListener("pointermove",g.move),window.removeEventListener("pointerup",g.up),P.current=null);const w=t.current.handleNodeRef.current;w!==null&&p.current!==null&&w.hasPointerCapture?.(p.current)&&w.releasePointerCapture(p.current),p.current=null,h.repaintOverlay()},[]),D=l.useCallback(()=>{const h=t.current,g=r.current,w=o.current;if(L(),g===null||w===null)return;const E=pp(g,w);if(E>h.maxOperationCells){h.onOperationRejected?.("fill",E,"limit");return}const y=hp((I,H)=>dc(h.adapter,I,H),g,w,fc);if(h.commitEdits(y,{source:"fill"})===null)return;const z=h.getSelection();h.setSelection({ranges:[w],anchor:z.anchor,active:z.active})},[L]),{enabled:x,handleNodeRef:A}=e;return l.useEffect(()=>{const h=A.current;if(!x||h===null)return;const g=I=>{w(I),n.current&&q(I)&&(S.current&1)!==0&&(I.buttons&1)===0&&D()},w=I=>{if(!(n.current&&q(I)))return;i.current={clientX:I.clientX,clientY:I.clientY};const H=Math.abs(I.clientX-c.current.clientX),v=Math.abs(I.clientY-c.current.clientY);if(!a.current&&Math.max(H,v)>=lg&&(a.current=!0),!!a.current){if(!T.current){const R=t.current,u={getPointerPosition:()=>({clientX:i.current.clientX-m.current.dx,clientY:i.current.clientY-m.current.dy}),buildRange:k,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};R.xAutoScroller.start(u),R.yAutoScroller.start(u),T.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&a.current))return;const R=K(i.current.clientX-m.current.dx,i.current.clientY-m.current.dy);R!==null&&t.current.writeFillPreview(k(R))}))}},E=I=>{I.button!==0||!(n.current&&q(I))||D()},y=I=>{const H=t.current;if(I.pointerType!=="mouse")return;if(I.button!==0){I.preventDefault();return}I.preventDefault(),I.stopPropagation(),H.focusSink();const v=H.getSelection(),R=v.ranges[v.ranges.length-1];r.current=R,o.current=null,a.current=!1,H.xAutoScroller.stop(),H.yAutoScroller.stop(),T.current=!1,c.current={clientX:I.clientX,clientY:I.clientY},i.current=c.current,S.current=I.buttons,n.current=!0,H.repaintOverlay(),s.current=H.bodyRef.current?.getBoundingClientRect()??null;const u=s.current,f=H.handleRef.current?.getScrollPosition()??{x:-1,y:-1},$=f.y;if(u!==null&&$>=0&&f.x>=0){const _=f.x,O=H.zoomRef.current,M=H.handleRef.current?.getFrozenSize()??cg,B=H.handleRef.current?.getViewportSize()??{width:0,height:0},X={scroll:_,frozenCount:M.cols,trailingCount:M.trailingCols,extent:B.width},J={scroll:$,frozenCount:M.rows,trailingCount:M.trailingRows,extent:B.height},G=Zt(H.colAxis,R.endCol,X)+H.colAxis.sizeOf(R.endCol),se=Jt(H.rowAxis,R.endRow,J)+H.rowAxis.sizeOf(R.endRow),he=G-1,Q=R.endCol>=M.cols&&M.width>0?Math.max(he,M.width):he,Le=!(R.endCol>=H.colAxis.count-M.trailingCols)&&M.trailingWidth>0?Math.min(Q,B.width-M.trailingVisibleWidth-1):Q,ae=se-1,Ne=R.endRow>=M.rows&&M.height>0?Math.max(ae,M.height):ae,dt=!(R.endRow>=H.rowAxis.count-M.trailingRows)&&M.trailingHeight>0?Math.min(Ne,B.height-M.trailingVisibleHeight-1):Ne;m.current={dx:I.clientX-(u.left+Le*O),dy:I.clientY-(u.top+dt*O)}}else m.current={dx:0,dy:0};p.current=I.pointerId;try{h.setPointerCapture(I.pointerId)}catch{p.current=null}const d=g,C=E;P.current={move:d,up:C},window.addEventListener("pointermove",d),window.addEventListener("pointerup",C),H.writeFillPreview(r.current)},z=I=>{!n.current||p.current===null||I.pointerId!==p.current||L()};return h.addEventListener("pointerdown",y),h.addEventListener("lostpointercapture",z),()=>{h.removeEventListener("pointerdown",y),h.removeEventListener("lostpointercapture",z),L()}},[x,A,q,K,k,L,D]),l.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L])},ug=320,zr=8,dg=64,fg=150,oa=e=>Math.max(0,Math.min(ug,e.width-it-zr)),pg=(e,t,n)=>{const r=n.width-it,o=n.height-it,s=oa(n),i=Math.max(0,Math.min(t,o-zr)),c=e.left+e.width,a=e.top+e.height,m=q=>q>=0&&q+s<=r,p=[e.left,c-s],S=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-i},{left:c-s,top:e.top-i}];for(const q of S)if(m(q.left)&&q.top>=0&&q.top+i<=o)return{left:q.left,top:q.top,width:s,height:i};const N=o-a,P=e.top,T=Math.min(i,Math.max(N,P));if(T>=dg){const q=N>=P?a:e.top-T;for(const K of p)if(m(K))return{left:K,top:q,width:s,height:T}}return{left:zr,top:zr,width:s,height:i}},hg=(e,t,n,r)=>t===null||e!==null&&vt(e,t)||n?!1:r(t),mg=(e,t)=>{switch(e.kind){case"note":return W.jsx(qc,{ctx:e,labels:t});case"note-tip":return W.jsx(_c,{ctx:e,labels:t});case"comment":return W.jsx(zc,{ctx:e,labels:t});case"link":return W.jsx(Nc,{ctx:e,labels:t});case"list":return W.jsx(Lc,{ctx:e,labels:t});default:return W.jsx(Pc,{ctx:e,labels:t})}},xo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,gg=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:i}=e,c=l.useRef(null),a=l.useRef(null),m=l.useRef(i);m.current=i;const p=l.useRef(e);p.current=e;const S=xo(s),N=xo(i),P=l.useRef(null),T=(D,x)=>{const A=p.current.getLayerSize();D.style.width=`${oa(A)}px`,D.style.maxHeight="";const h=pg(x,D.offsetHeight,A);D.style.left=`${h.left-x.left}px`,D.style.top=`${h.top-x.top}px`,D.style.maxHeight=`${h.height}px`};l.useLayoutEffect(()=>{const D=c.current;if(D===null||s===null){P.current=null;return}if(T(D,s.anchorRect),s.kind==="message")return;const x=xo(s);if(P.current===x)return;P.current=x;const A=D.querySelector("[data-aqsp-popover-autofocus]");A!==null?A.focus({preventScroll:!0}):D.focus({preventScroll:!0})},[s]),l.useLayoutEffect(()=>{const D=a.current,x=m.current;D===null||x===null||T(D,x.anchorRect)},[N]);const q=D=>t===void 0?mg(D,n):t(D),K=D=>{e.isCompositionKey(D.nativeEvent)&&D.stopPropagation()},k=D=>{D.key==="Escape"&&!D.defaultPrevented&&(D.preventDefault(),e.close())},L=D=>{e.registerCompositionEnd(D.timeStamp)};return W.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:K,onKeyDown:k,onCompositionEnd:L,children:[W.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:W.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:q(s)},S)}),W.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":i===null?void 0:"",inert:i===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:i===null?null:W.jsx("div",{ref:a,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:q(i)})})]})},wg=["note","note-tip","comment","link","list","message"],Cg=(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}},_n=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Cg(e,n),bg=e=>{const t=l.useRef(e);t.current=e;const[n,r]=l.useState(null),[o,s]=l.useState(null),i=l.useRef(null),c=l.useRef(null),a=l.useRef(null),m=l.useRef(!1),p=l.useRef(null),S=l.useRef(null),N=l.useRef(null),P=l.useRef(null),T=l.useId(),q=l.useCallback(C=>{const _=t.current,O=_.handleRef.current,M=O===null?{x:0,y:0}:O.getScrollPosition(),B=O===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:O.getFrozenSize(),X=O===null?{width:0,height:0}:O.getViewportSize();return{top:Jt(_.rowAxis,C.row,{scroll:Math.max(0,M.y),frozenCount:B.rows,trailingCount:B.trailingRows,extent:X.height}),left:Zt(_.colAxis,C.col,{scroll:Math.max(0,M.x),frozenCount:B.cols,trailingCount:B.trailingCols,extent:X.width}),width:_.colAxis.sizeOf(C.col),height:_.rowAxis.sizeOf(C.row)}},[]),K=l.useCallback(C=>{const _=t.current;_.anchors.current={..._.anchors.current,...C},_.repaintOverlay()},[]),k=l.useCallback(()=>{p.current!==null&&(window.clearTimeout(p.current),p.current=null)},[]),L=l.useCallback(()=>{const C=t.current.sinkRef.current;if(C===null)return;const _=c.current;_!==null&&vt(_,t.current.getActive())?C.setAttribute("aria-describedby",T):C.getAttribute("aria-describedby")===T&&C.removeAttribute("aria-describedby")},[T]),D=l.useCallback(()=>(k(),m.current=!1,c.current===null?!1:(c.current=null,s(null),K({tip:null}),L(),!0)),[k,K,L]),x=l.useCallback(()=>{k(),p.current=window.setTimeout(()=>{p.current=null,D()},fg)},[k,D]),A=l.useCallback(C=>{const _=t.current;k();const O=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(C.row,C.col);O===void 0||O===""||(c.current=C,s({kind:"note-tip",cell:C,anchorRect:q(C),current:O,close:D}),K({tip:C}),L())},[q,k,D,K,L]),h=l.useCallback(C=>{const _=t.current;if(C===null&&m.current)return;const O=a.current;a.current=C;const M=c.current;if(M!==null&&C!==null&&vt(M,C)){k();return}const B=X=>{const J=_.adapter.getCellNote===void 0?void 0:_.adapter.getCellNote(X.row,X.col);return J!==void 0&&J!==""};if(hg(O,C,_.isDraggingAny(),B)){C!==null&&A(C);return}M!==null&&x()},[A,k,x]),g=l.useCallback((C,_)=>{const O=t.current,M=O.bodyRef.current,B=O.handleRef.current;if(M===null||B===null)return null;const X=M.getBoundingClientRect(),J=O.zoomRef.current,G=B.getScrollPosition(),se=B.getFrozenSize(),he=B.getViewportSize();return er({row:rr(O.rowAxis,(_-X.top)/J,{scroll:Math.max(0,G.y),frozenSize:se.height,trailingSize:se.trailingHeight,extent:he.height}),col:nr(O.colAxis,(C-X.left)/J,{scroll:Math.max(0,G.x),frozenSize:se.width,trailingSize:se.trailingWidth,extent:he.width})},O.rowAxis.count,O.colAxis.count)},[]),w=l.useCallback(C=>{N.current=C,S.current===null&&(S.current=requestAnimationFrame(()=>{S.current=null;const _=N.current;h(_===null?null:"cell"in _?_.cell:g(_.clientX,_.clientY))}))},[h,g]),E=l.useCallback(C=>w({cell:C}),[w]),y=l.useCallback(()=>D(),[D]),z=l.useCallback(()=>{if(i.current===null)return;const C=t.current;i.current=null,r(null),K({interactive:null}),C.focusSink({preventScroll:!0}),C.isEditing()||C.rearmSink()},[K]),I=l.useCallback(C=>{i.current=C.kind,r(C),K({interactive:C.cell})},[K]),H=l.useCallback((C,_)=>{if(t.current.commitEdits(_,{source:"annotate"})===null){I({...C,rejected:!0});return}z()},[I,z]),v=l.useCallback((C,_)=>{const O=t.current;if(!_n(O.adapter,O.popovers,C))throw new RangeError(`[spreadsheet] openPopover("${C}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const M=O.getActive();if(C==="note-tip"){A(M);return}if(C==="message"){if(i.current!==null&&i.current!=="message")return;const G=_!==void 0&&_.message!==void 0?_.message:void 0,se=O.adapter.getCellValidation===void 0?void 0:O.adapter.getCellValidation(M.row,M.col),he=G!==void 0?G:se===void 0?void 0:se.inputMessage;if(he===void 0)return;const Q=_!==void 0&&_.rejected===!0;I({kind:"message",cell:M,anchorRect:q(M),current:{title:Te(O.labels,"messageTitle"),message:he,rejected:Q},close:z});return}if(O.isEditing()&&!O.requestCommit())return;if(C==="list"){const G=O.adapter.getCellValidation===void 0?void 0:O.adapter.getCellValidation(M.row,M.col);if(G===void 0||G.type!=="list")return;const se=_!==void 0&&_.typed!==void 0?_.typed:"";D(),O.focusSink({preventScroll:!0}),I({kind:"list",cell:M,anchorRect:q(M),current:G.values,typed:se,commit:he=>{t.current.commitEdits([{row:M.row,col:M.col,text:he}],{source:"edit",editSession:"discarded"}),z()},close:z});return}if(D(),O.focusSink({preventScroll:!0}),C==="note"){const G=O.adapter.getCellNote===void 0?void 0:O.adapter.getCellNote(M.row,M.col),se={kind:"note",cell:M,anchorRect:q(M),current:G,commit:he=>{H(se,[{row:M.row,col:M.col,note:he}])},close:z,rejected:!1};I(se);return}if(C==="comment"){const G=O.adapter.getCellComments===void 0?void 0:O.adapter.getCellComments(M.row,M.col),se={kind:"comment",cell:M,anchorRect:q(M),current:G===void 0?[]:G,commit:he=>{H(se,[{row:M.row,col:M.col,comments:he}])},close:z,rejected:!1};I(se);return}const B=O.adapter.getCellHyperlink===void 0?void 0:kn(O.adapter.getCellHyperlink(M.row,M.col)),X=O.adapter.getCellText(M.row,M.col),J={kind:"link",cell:M,anchorRect:q(M),current:{text:X,url:B},commit:G=>{const se=G.url===null?null:It(G.url);if(se===null&&G.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(G.url)}`);const he=G.text===X?{row:M.row,col:M.col,hyperlink:se}:{row:M.row,col:M.col,text:G.text,hyperlink:se};H(J,[he])},close:z,canOpen:O.onHyperlinkOpen!==void 0,open:()=>{const G=t.current.onHyperlinkOpen;G!==void 0&&B!==void 0&&G(B,M)},rejected:!1};I(J)},[q,z,H,D,I,A]),{enabled:R,bodyRef:u}=e;l.useEffect(()=>{const C=u.current;if(!R||C===null)return;const _=M=>{const B=t.current;_n(B.adapter,B.popovers,"note-tip")&&w({clientX:M.clientX,clientY:M.clientY})},O=()=>{_n(t.current.adapter,t.current.popovers,"note-tip")&&w({cell:null})};return C.addEventListener("pointermove",_),C.addEventListener("pointerleave",O),()=>{C.removeEventListener("pointermove",_),C.removeEventListener("pointerleave",O)}},[R,u,w]),l.useEffect(()=>()=>{S.current!==null&&cancelAnimationFrame(S.current),p.current!==null&&window.clearTimeout(p.current)},[]);const{adapter:f,popovers:$}=e,d=l.useMemo(()=>wg.some(C=>_n(f,$,C)),[f,$]);return l.useMemo(()=>({layerEnabled:d,isKindEnabled:C=>_n(t.current.adapter,t.current.popovers,C),open:v,close:z,isOpen:()=>i.current,onCellHover:E,hideTip:y,onTipPointerEnter:()=>{m.current=!0,k()},onTipPointerLeave:()=>{m.current=!1,c.current!==null&&x()},syncTipAriaDescribedBy:L,context:n,tipContext:o,registerCompositionEnd:C=>{P.current=C},isCompositionKey:C=>ra(C,P.current),getLayerSize:()=>{const C=t.current.handleRef.current;return C===null?{width:0,height:0}:C.getViewportSize()},tipId:T}),[d,v,z,E,y,k,x,L,n,o,T])},yg=(e,t,n)=>{let r=null,o=0;if(typeof document.caretPositionFromPoint=="function"){const i=document.caretPositionFromPoint(e,t);if(i===null)return;r=i.offsetNode,o=i.offset}else if(typeof document.caretRangeFromPoint=="function"){const i=document.caretRangeFromPoint(e,t);if(i===null)return;r=i.startContainer,o=i.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},sa=(e,t,n,r,o,s,i)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const m=e.getFrozenSize(),p=e.getViewportSize();return er({row:rr(n,(i-t.top)/o,{scroll:a,frozenSize:m.height,trailingSize:m.trailingHeight,extent:p.height}),col:nr(r,(s-t.left)/o,{scroll:c,frozenSize:m.width,trailingSize:m.trailingWidth,extent:p.width})},n.count,r.count)},vg=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(!1),r=l.useRef(null),o=l.useRef(null),s=l.useRef({clientX:0,clientY:0}),i=l.useRef(null),c=l.useRef(null),a=l.useRef(0),m=l.useRef(null),p=l.useRef(!1),S=l.useRef(null),N=l.useRef(""),P=l.useRef(!1),T=l.useRef(!1),q=l.useCallback((w,E)=>{const{handleRef:y,rowAxis:z,colAxis:I,zoomRef:H}=t.current;return sa(y.current,o.current,z,I,H.current,w,E)},[]),K=l.useRef(!1),k=l.useRef(null),L=l.useRef(null),D=l.useRef({clientX:0,clientY:0}),x=l.useCallback(()=>{const{autoScroller:w,bodyRef:E,onDragFrame:y}=t.current;n.current=!1,r.current=null,m.current=null,K.current=!1,k.current=null,L.current=null,p.current=!1,S.current=null,i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),w.stop();const z=E.current;z!==null&&c.current!==null&&z.hasPointerCapture?.(c.current)&&z.releasePointerCapture(c.current),c.current=null,y(null),t.current.repaintOverlay()},[]),A=l.useCallback(()=>{if(!n.current)return;const w=r.current;w!==null&&t.current.setSelection(w),x()},[x]),{enabled:h,bodyRef:g}=e;return l.useEffect(()=>{const w=g.current;if(!h||w===null)return;const E=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,y=d=>{const C=t.current;if(d.pointerType==="mouse"&&d.button===0&&(p.current=!1,S.current=null,T.current=!1),P.current=E(d.target),!P.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(C.getPointing?.()){C.focusSink();return}if(C.isEditing()&&!C.requestCommit()){d.stopPropagation(),C.focusSink();return}C.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((C.pointDragRef===void 0?null:C.pointDragRef.current)?.onPointerDown(d))return;if(C.isEditing()&&!C.requestCommit()){d.preventDefault(),C.focusSink();return}o.current=w.getBoundingClientRect();const O=q(d.clientX,d.clientY);if(O===null)return;if(d.preventDefault(),C.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&C.openHyperlinkAt?.(O)===!0){T.current=!0;return}const M=C.getSelection();r.current=M;const B=d.shiftKey,X=d.ctrlKey||d.metaKey,J=X&&!B&&M.ranges.some(se=>Qt(se,O));p.current=J,S.current=J?O:null,J||C.setSelection(Xn(M,O,{extend:B,append:X})),n.current=!0,C.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,a.current=d.buttons;try{w.setPointerCapture(d.pointerId)}catch{c.current=null}const G=J?O:C.getSelection().anchor;m.current=se=>Ce(G,se),k.current=G.col,L.current=G.row,C.autoScroller.stop(),K.current=!1,D.current={clientX:d.clientX,clientY:d.clientY}},z=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",I=d=>{if(n.current&&z(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!K.current&&m.current!==null){const C=Math.abs(d.clientX-D.current.clientX),_=Math.abs(d.clientY-D.current.clientY);Math.max(C,_)>=Hr&&(K.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m.current,anchorCol:k.current??void 0,anchorRow:L.current??void 0}))}i.current===null&&(i.current=requestAnimationFrame(()=>{i.current=null;const C=m.current;if(!n.current||C===null)return;const _=t.current,O=q(s.current.clientX,s.current.clientY);O!==null&&_.onDragFrame(C(O))}))}},H=d=>{I(d),n.current&&z(d)&&(a.current&1)!==0&&(d.buttons&1)===0&&R(d)},v=d=>{d.button!==0||!(n.current&&z(d))||R(d)},R=d=>{const C=t.current,_=q(d.clientX,d.clientY);if(_!==null){const O=S.current;p.current&&O!==null?C.setSelection(ta(C.getSelection(),Ce(O,_),O)):C.setSelection(Gt(C.getSelection(),_))}x()},u=d=>{!n.current||c.current===null||d.pointerId!==c.current||A()},f=d=>{const C=t.current;if(!E(d.target)||N.current!=="mouse"||C.isAnyDragging())return;if(C.isEditing()&&!C.requestCommit()){C.focusSink();return}C.focusSink(),o.current=w.getBoundingClientRect();const _=q(d.clientX,d.clientY);if(_===null)return;const O=C.getSelection();O.ranges.some(B=>Qt(B,_))||C.setSelection(Xn(O,_,{extend:!1,append:!1})),C.onContextMenuSelect(_,d)},$=d=>{const C=t.current;if(!P.current||N.current!=="mouse"||C.getPointing?.()||T.current)return;o.current=w.getBoundingClientRect();const _=q(d.clientX,d.clientY);_!==null&&vt(C.getSelection().active,_)&&C.onRequestEdit(_,C.caretFromPointEnabled(_)?yg(d.clientX,d.clientY,_):void 0)};return w.addEventListener("pointerdown",y),w.addEventListener("pointermove",H),w.addEventListener("pointerup",v),w.addEventListener("lostpointercapture",u),w.addEventListener("contextmenu",f),w.addEventListener("dblclick",$),()=>{w.removeEventListener("pointerdown",y),w.removeEventListener("pointermove",H),w.removeEventListener("pointerup",v),w.removeEventListener("lostpointercapture",u),w.removeEventListener("contextmenu",f),w.removeEventListener("dblclick",$),x()}},[h,g,q,x,A]),l.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>p.current?"subtract":"add",abortDrag:A,cancelDrag:x}),[A,x])},Rg=e=>{const t=l.useRef(e);t.current=e;const n=l.useRef(!1),r=l.useRef(null),o=l.useRef(null),s=l.useRef({clientX:0,clientY:0}),i=l.useRef({clientX:0,clientY:0}),c=l.useRef(null),a=l.useRef(null),m=l.useRef(0),p=l.useRef(null),S=l.useRef(null),N=l.useRef(!1),P=l.useCallback((D,x)=>{const{handleRef:A,rowAxis:h,colAxis:g,zoomRef:w}=t.current;return sa(A.current,o.current,h,g,w.current,D,x)},[]),T=l.useCallback(()=>{const{autoScroller:D,bodyRef:x,onDragFrame:A}=t.current;n.current=!1,r.current=null,p.current=null,S.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),D.stop();const h=x.current;h!==null&&a.current!==null&&h.hasPointerCapture?.(a.current)&&h.releasePointerCapture(a.current),a.current=null,A(null)},[]),q=l.useCallback(()=>{if(!n.current)return;const D=r.current;D!==null&&t.current.restoreSink(D),T()},[T]),K=l.useCallback(D=>{const x=t.current,A=x.bodyRef.current;if(!x.enabled||A===null||!x.getPointing())return!1;o.current=A.getBoundingClientRect();const h=P(D.clientX,D.clientY);if(h===null)return o.current=null,!1;const g=x.captureSink();if(g===null)return o.current=null,!1;D.preventDefault(),x.focusSink(),r.current=g,S.current=h,x.insertReference(h,"cells"),n.current=!0,s.current={clientX:D.clientX,clientY:D.clientY},i.current={clientX:D.clientX,clientY:D.clientY},a.current=D.pointerId,m.current=D.buttons;try{A.setPointerCapture(D.pointerId)}catch{a.current=null}return p.current=w=>{const E=Ce(h,w);return t.current.insertReference(E,"cells"),E},x.autoScroller.stop(),N.current=!1,x.onDragFrame(Ce(h,h)),!0},[P]),{enabled:k,bodyRef:L}=e;return l.useEffect(()=>{const D=L.current;if(!k||D===null)return;const x=w=>a.current!==null?w.pointerId===a.current:w.pointerType==="mouse",A=w=>{if(!(n.current&&x(w)))return;s.current={clientX:w.clientX,clientY:w.clientY};const E=p.current,y=S.current;if(!N.current&&E!==null&&y!==null){const z=Math.abs(w.clientX-i.current.clientX),I=Math.abs(w.clientY-i.current.clientY);Math.max(z,I)>=Hr&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:E,anchorCol:y.col,anchorRow:y.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const z=p.current;if(!n.current||z===null)return;const I=P(s.current.clientX,s.current.clientY);I!==null&&t.current.onDragFrame(z(I))})),(m.current&1)!==0&&(w.buttons&1)===0&&T()},h=w=>{w.button!==0||!(n.current&&x(w))||T()},g=w=>{!n.current||a.current===null||w.pointerId!==a.current||T()};return D.addEventListener("pointermove",A),D.addEventListener("pointerup",h),D.addEventListener("lostpointercapture",g),()=>{D.removeEventListener("pointermove",A),D.removeEventListener("pointerup",h),D.removeEventListener("lostpointercapture",g),T()}},[k,L,P,T]),l.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:q,cancelDrag:T,onPointerDown:K}),[q,T,K])},kg=.25,Sg=4,Ao=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(Sg,Math.max(kg,e))},Oo=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,Eg=24,xg=100,Ag=1e5,Og=200,ia=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),ol=5,Tg=/^#[0-9A-Fa-f]{6}$/,Dg=Object.freeze({row:!1,column:!1,intersection:!1}),sl=Object.freeze({ok:!0}),il=(e,t)=>{if(t===void 0)return ia;if(t.length!==ol)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${ol} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Tg.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Mg=e=>{for(const t of["row","column","intersection"])if(Be(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},$g=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return $c},Fg=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},Ar={ranges:[Ce({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},zg=l.forwardRef(function({adapter:t,defaultRowHeight:n=Eg,defaultColumnWidth:r=xg,frozenColumns:o=0,frozenRows:s=0,frozenTrailingColumns:i=0,frozenTrailingRows:c=0,renderCell:a,onSelectionChange:m,onCellContextMenu:p,onUndoRequest:S,onRedoRequest:N,onCopyMultiRange:P,onOperationRejected:T,onEditRejected:q,dataVersion:K,maxOperationCells:k=Ag,enableFillHandle:L=!0,enableResizeUI:D=!0,formatCellAnnouncement:x,formatSelectionAnnouncement:A,formatCommandAnnouncement:h,labels:g,shortcuts:w,colors:E,formats:y,highlight:z,defaultHighlight:I,onHighlightChange:H,highlightColors:v,popovers:R,renderPopover:u,onClipChange:f,onHyperlinkOpen:$,onValidationRejected:d,onPasteSpecialRequest:C,onClipboardUnavailable:_,now:O=Date.now,zoom:M,defaultZoom:B,onZoomChange:X,testId:J,className:G,__onCellRender:se},he){const Q=Ui(t.rowCount,n),ie=Ui(t.colCount,r),Le=l.useRef(null);Le.current===null&&(Le.current=dh());const ae=Le.current,Ne=l.useMemo(()=>uh(g),[g]),ct=l.useMemo(()=>Mp(w),[w]),dt=l.useMemo(()=>({fill:il("fill",E===void 0?void 0:E.fill),font:il("font",E===void 0?void 0:E.font)}),[E]),ft=l.useMemo(()=>v===void 0?void 0:Mg(v),[v]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Sn=l.useCallback(()=>ae.get().editVersion,[ae]),or=l.useCallback(b=>ae.subscribeCoalesced(b),[ae]),en=l.useSyncExternalStore(or,Sn,Sn)+(K===void 0?0:K),Ue=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),Ht=l.useMemo(()=>({index:Ue===null?null:Zc(Ue),memo:cs()}),[t,Ue,en]),kt=l.useRef(Ht.index);kt.current=Ht.index;const St=l.useRef(Ht.memo);St.current=Ht.memo;const Qe=l.useCallback((b,Y,ee)=>as(t,kt.current,St.current,b,Y,ee),[t]),Ve=l.useRef(null),[tn,Et]=l.useState(()=>Ao(B??1)),_e=Ao(M??tn),Ae=l.useRef(_e);Ae.current=_e;const et=l.useRef(_e);et.current=_e;const jt=l.useRef(null),En=l.useRef(X);En.current=X;const nn=l.useRef(M!==void 0);nn.current=M!==void 0;const xn=l.useCallback(b=>{const Y=Ao(b);Y!==et.current&&(et.current=Y,nn.current||Et(Y),En.current?.(Y))},[]),$e=t.rowCount===0||t.colCount===0,sr=!$e;l.useEffect(()=>{const b=Ve.current;if(!sr||b===null)return;const Y=re=>{re.defaultPrevented||!re.altKey||re.ctrlKey||re.metaKey||re.shiftKey||re.deltaY!==0&&(re.preventDefault(),re.stopPropagation(),!jt.current?.()&&xn(Oo(et.current,re.deltaY<0?1:-1)))},ee=re=>{if(re.defaultPrevented||!(re.ctrlKey&&re.altKey)||re.metaKey||re.getModifierState("AltGraph"))return;const Re=re.key==="="||re.key==="+"?Oo(et.current,1):re.key==="-"?Oo(et.current,-1):re.key==="0"?1:null;Re!==null&&(re.preventDefault(),re.stopPropagation(),!jt.current?.()&&xn(Re))};return b.addEventListener("wheel",Y,{passive:!1,capture:!0}),b.addEventListener("keydown",ee,!0),()=>{b.removeEventListener("wheel",Y,{capture:!0}),b.removeEventListener("keydown",ee,!0)}},[xn,sr]);const We=l.useRef(null),be=l.useRef(null),Ie=l.useRef(null),ir=l.useRef(null),lr=l.useRef(0),F=l.useRef(null),V=l.useRef(0),U=l.useRef(null),j=l.useRef(null),Z=l.useRef(null),ne=l.useRef(null),le=l.useRef(null),ye=l.useRef(null),me=l.useRef(null),[Fe,qe]=l.useState(Ar),De=l.useRef(Fe),Ee=l.useCallback(()=>De.current,[]),[te,pe]=l.useState(()=>I===void 0?Dg:I),ce=z!==void 0?z:te,de=l.useRef(ce);de.current=ce;const ue=$g(ft,ce),ge=l.useRef(z!==void 0);ge.current=z!==void 0;const ve=l.useRef(H);ve.current=H;const Me=l.useCallback(b=>{ge.current||pe(b),ve.current?.(b)},[]),at=l.useRef(null),Xe=l.useRef(null),Pe=l.useRef(null),pt=l.useRef(()=>!1),xt=l.useRef(()=>{}),rn=l.useRef(()=>null),At=l.useRef(()=>{}),ht=l.useCallback(()=>pt.current(),[]),An=l.useMemo(()=>({getPointing:()=>pt.current(),insertReference:(b,Y)=>xt.current(b,Y)}),[]),fs=l.useRef(bt),ps=l.useRef(null),hs=l.useRef({interactive:null,tip:null}),ms=l.useRef(null),gs=l.useRef(null),cr=l.useRef(()=>{}),ws=l.useRef(()=>!1),on=l.useRef(null),On=l.useCallback(()=>{const b=on.current;if(b===null||b.isOpen()!=="message")return!1;const Y=b.context;return Y===null||Y.kind!=="message"||!Y.current.rejected?!1:(b.close(),!0)},[]),Ur=l.useRef(()=>!1),Cs=l.useRef(()=>!1),bs=l.useRef(null),Xr=l.useRef(()=>Promise.resolve("rejected")),Se=l.useCallback(()=>{at.current?.()},[]),Oe=l.useCallback(b=>{Ie.current?.focus(b)},[]),Gr=l.useRef(!1),la=l.useCallback(()=>{const b=Ve.current;if(b!==null){Gr.current=!0;try{b.focus()}finally{Gr.current=!1}}},[]),Ye=l.useCallback(()=>{const b=Ie.current;b!==null&&(b.value=" ",b.setSelectionRange(0,1))},[]),sn=l.useCallback((b,Y)=>{if(b===null)return;const ee=Y?"":"none";b.style.display!==ee&&(b.style.display=ee)},[]),tt=l.useCallback(()=>{const b=ir.current;if(b!==null){const ee=Math.max(0,be.current?.getScrollPosition().y??0),re=be.current?.getFrozenSize().height??0;b.style.transform=`translateY(${lr.current-ee-re}px)`}const Y=be.current;if(Y!==null&&(le.current!==null||ye.current!==null)){const ee=Y.getFrozenSize();sn(le.current,ee.height>0),sn(ye.current,ee.trailingHeight>0)}},[sn]),nt=l.useCallback(()=>{const b=F.current;if(b!==null){const ee=Math.max(0,be.current?.getScrollPosition().x??0),re=be.current?.getFrozenSize().width??0;b.style.transform=`translateX(${V.current-ee-re}px)`}const Y=be.current;if(Y!==null&&(Z.current!==null||ne.current!==null)){const ee=Y.getFrozenSize();sn(Z.current,ee.width>0),sn(ne.current,ee.trailingWidth>0)}},[sn]),Tn=l.useRef(null),ln=l.useCallback(()=>{Z.current===null&&ne.current===null&&le.current===null&&ye.current===null||Tn.current===null&&(Tn.current=requestAnimationFrame(()=>{Tn.current=null,tt(),nt(),Se()}))},[tt,nt,Se]);l.useEffect(()=>()=>{Tn.current!==null&&cancelAnimationFrame(Tn.current)},[]);const Zr=l.useRef(null),Jr=l.useRef(null);(Zr.current===null||Jr.current?.rowAxis!==Q||Jr.current?.colAxis!==ie)&&(Jr.current={rowAxis:Q,colAxis:ie},Zr.current=eg({handleRef:be,rowAxis:Q,colAxis:ie}));const Ot=l.useCallback(b=>{Zr.current?.(b)},[]),cn=l.useRef(null),Bt=l.useRef(null),ar=l.useCallback(b=>{cn.current!==null&&window.clearTimeout(cn.current),Bt.current!==null&&(cancelAnimationFrame(Bt.current),Bt.current=null),cn.current=window.setTimeout(()=>{cn.current=null;const Y=me.current;Y!==null&&(Y.textContent="",Bt.current=requestAnimationFrame(()=>{Bt.current=null,Y.textContent=b}))},Og)},[]);l.useEffect(()=>()=>{cn.current!==null&&window.clearTimeout(cn.current),Bt.current!==null&&cancelAnimationFrame(Bt.current)},[]);const ys=l.useCallback((b,Y)=>{if(x===void 0&&A===void 0)return;const ee=Y.ranges[Y.ranges.length-1],re=Je(ee),Re=Y.ranges.length===1&&re.rows===1&&re.cols===1,xe=b.ranges[b.ranges.length-1],lo=b.ranges.length!==Y.ranges.length||xe.startRow!==ee.startRow||xe.startCol!==ee.startCol||xe.endRow!==ee.endRow||xe.endCol!==ee.endCol,Vs=()=>{if(x!==void 0){const Yt=Y.active,co=t.getCellText(Yt.row,Yt.col),Ws=t.getCellFormat===void 0?void 0:Qe(Yt.row,Yt.col,()=>co);ar(x({row:Yt.row,col:Yt.col,text:co,displayText:yn(co,Ws===void 0?void 0:Ws.value),columnName:Wn(Yt.col)}))}};if(Re){Vs();return}if(lo){A!==void 0&&ar(A({range:ee,anchor:Y.anchor,active:Y.active,rangeRowCount:re.rows,rangeColCount:re.cols,rangeCount:Y.ranges.length}));return}Vs()},[t,x,A,ar,Qe]),Ke=l.useCallback(b=>{const Y=De.current;Object.is(b,Y)||Gm(b,Y)||(De.current=b,qe(b),m?.(b),ys(Y,b),(Pe.current?.()??!1)||Ye())},[m,ys,Ye]),ca=l.useCallback(b=>{const Y=De.current;if(b.mode==="cycle"){const re=na(Y,b.direction);Ke(re),Ot(re.active);return}const ee=er(b.cell,Q.count,ie.count);if(b.mode==="extend"){Ke(Gt(Y,ee)),Ot(ee);return}Ke(Xn(Y,ee,{extend:!1,append:!1})),Ot(ee)},[Ke,Ot,Q,ie]),He=l.useCallback(()=>Pe.current?.()??!1,[]),vs=l.useRef(null),rt=l.useCallback(()=>vs.current?.()??!0,[]),Rs=l.useRef(null),Dn=l.useCallback((b,Y)=>{const ee=Pe.current?.()??!1;Rs.current?.(b,Y),!ee&&(Pe.current?.()??!1)&&On()},[On]),[aa,Qr]=l.useState(!1),ua=l.useCallback((b,Y)=>{Qr(!0),Dn("edit",Y)},[Dn]),ks=l.useRef(null),Ss=l.useCallback(()=>ks.current?.()??null,[]),Es=l.useRef(null),Tt=l.useCallback(()=>{Es.current?.()},[]),xs=l.useRef(null),As=l.useCallback(b=>{xs.current?.(b)},[]),Os=l.useRef(()=>{}),ur=l.useRef(0),Vt=l.useCallback((b,Y,ee)=>{let re;if(Y.source==="paste"){const Re=Fg(ee);if(b.length===0&&Re.conditionalFormats.length===0)return null;ur.current+=1,re={transaction:ur.current,source:"paste",sameSheet:Re.sameSheet,conditionalFormats:Re.conditionalFormats}}else{if(b.length===0)return null;ur.current+=1,re={transaction:ur.current,source:Y.source}}try{t.applyEdits(b,re)}catch(Re){return q?.(Re,Y),null}return ae.bumpEdit(),As(Y.source),re.transaction},[t,ae,q,As]),da=l.useCallback((b,Y)=>Vt(b,{source:"paste"},Y),[Vt]),fa=l.useCallback(b=>{ae.setVy(b.y),tt(),nt(),Se()},[ae,tt,nt,Se]),Ts=l.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),pa=l.useCallback(b=>{ae.setRowRange(b.renderingRowStart,b.renderingRowEnd),ae.setColRange(b.renderingColStart,b.renderingColEnd);const Y=Ts.current;(Y.rowStart!==b.renderingRowStart||Y.rowEnd!==b.renderingRowEnd||Y.colStart!==b.renderingColStart||Y.colEnd!==b.renderingColEnd)&&(Ts.current={rowStart:b.renderingRowStart,rowEnd:b.renderingRowEnd,colStart:b.renderingColStart,colEnd:b.renderingColEnd},Se())},[ae,Se]),Ds=l.useRef(()=>"add"),Dt=l.useCallback(b=>{Xe.current?.(b,Ds.current())},[]),ha=l.useCallback(b=>{Xe.current?.(b,"point")},[]),Ms=l.useRef(null),eo=l.useCallback(b=>{Ms.current?.(b)},[]),$s=l.useRef(null),ma=l.useCallback(b=>{$s.current?.(b)},[]),Fs=l.useRef(null),to=l.useCallback((b,Y)=>{if(Y.length===0)return;const ee=be.current;if(b==="col"){for(const re of Y){const Re=Math.round(re.size);ie.resize(re.index,Re),ee?.updateColSize(re.index,Re)}ae.bumpColVersion(),nt(),Se(),ln();return}for(const re of Y){const Re=Math.round(re.size);Q.resize(re.index,Re),ee?.updateRowSize(re.index,Re)}ae.bumpRowGeometry(),tt(),Se(),ln()},[Q,ie,ae,nt,tt,Se,ln]),ga=l.useCallback((b,Y)=>{p?.(b,{kind:"pointer",event:Y})},[p]),wa=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:Dt,axis:"both",zoomRef:Ae}),Ca=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:Dt,axis:"x",zoomRef:Ae}),ba=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:Dt,axis:"y",zoomRef:Ae}),ya=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:eo,axis:"x",zoomRef:Ae}),va=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:eo,axis:"y",zoomRef:Ae}),Ra=un({handleRef:be,rowAxis:Q,colAxis:ie,bodyRef:We,onDragFrame:Dt,axis:"both",zoomRef:Ae}),zs=l.useRef(null),Ns=l.useRef(()=>!1),no=l.useCallback(()=>Ns.current(),[]),mt=vg({zoomRef:Ae,enabled:!$e,rowAxis:Q,colAxis:ie,handleRef:be,bodyRef:We,isEditing:He,requestCommit:rt,getSelection:Ee,setSelection:Ke,focusSink:Oe,onDragFrame:Dt,onContextMenuSelect:ga,onRequestEdit:ua,caretFromPointEnabled:b=>{if(a!==void 0||t.getCellFormula!==void 0&&t.getCellFormula(b.row,b.col)!==void 0)return!1;if(t.getCellFormat===void 0)return!0;const Y=t.getCellText(b.row,b.col);return yn(Y,t.getCellFormat(b.row,b.col)?.value)===Y},isAnyDragging:no,autoScroller:wa,repaintOverlay:Se,pointDragRef:zs,getPointing:ht,openHyperlinkAt:$===void 0||t.getCellHyperlink===void 0?void 0:b=>{const Y=t.getCellHyperlink===void 0?void 0:kn(t.getCellHyperlink(b.row,b.col));return Y===void 0?!1:($(Y,b),!0)}}),Mt=rl({zoomRef:Ae,enabled:!$e,axis:"col",headerRef:U,mainAxis:ie,crossCount:t.rowCount,handleRef:be,isEditing:He,requestCommit:rt,getSelection:Ee,setSelection:Ke,focusSink:Oe,onDragFrame:Dt,autoScroller:Ca,repaintOverlay:Se,pointing:An}),$t=rl({zoomRef:Ae,enabled:!$e,axis:"row",headerRef:j,mainAxis:Q,crossCount:t.colCount,handleRef:be,isEditing:He,requestCommit:rt,getSelection:Ee,setSelection:Ke,focusSink:Oe,onDragFrame:Dt,autoScroller:ba,repaintOverlay:Se,pointing:An}),Ft=Xm({zoomRef:Ae,enabled:!$e&&D,colBandRef:U,rowBandRef:j,colAxis:ie,rowAxis:Q,viewStore:ae,handleRef:be,isEditing:He,requestCommit:rt,focusSink:Oe,getSelection:Ee,adapter:t,autofitEnabled:a===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:k,onOperationRejected:T,resizeTracks:to,writeResizeGuide:ma,repaintOverlay:Se,isPointing:ht}),gt=ag({zoomRef:Ae,enabled:!$e&&L,handleNodeRef:Fs,bodyRef:We,rowAxis:Q,colAxis:ie,handleRef:be,getSelection:Ee,setSelection:Ke,focusSink:Oe,adapter:t,commitEdits:Vt,maxOperationCells:k,onOperationRejected:T,writeFillPreview:eo,repaintOverlay:Se,xAutoScroller:ya,yAutoScroller:va}),ut=Rg({zoomRef:Ae,enabled:!$e,bodyRef:We,handleRef:be,rowAxis:Q,colAxis:ie,getPointing:ht,insertReference:An.insertReference,captureSink:()=>rn.current(),restoreSink:b=>At.current(b),focusSink:Oe,autoScroller:Ra,onDragFrame:Dt});zs.current=ut;const Mn=l.useCallback(()=>mt.isDragging()||Mt.isDragging()||$t.isDragging()||Ft.isDragging()||gt.isDragging()||ut.isDragging(),[mt,Mt,$t,Ft,gt,ut]);jt.current=Mn,Ns.current=Mn,Ds.current=()=>ut.isDragging()?"point":mt.getDragMode();const ka=l.useCallback(()=>{mt.abortDrag(),Mt.abortDrag(),$t.abortDrag(),Ft.abortDrag(),gt.abortDrag(),ut.abortDrag()},[mt,Mt,$t,Ft,gt,ut]),ro=l.useCallback(()=>De.current.active,[]),Ls=l.useCallback((b,Y)=>{const ee=t.getCellValidation===void 0?void 0:t.getCellValidation(b.row,b.col);if(ee===void 0)return sl;const re=t.evaluateFormula,Re=kc(ee,Y,re===void 0?void 0:xe=>re(xe,b));return Re.ok||ee.strict!==!0?sl:(d?.({cell:b,rule:ee,text:Y,message:Re.message}),on.current?.isKindEnabled("message")&&cr.current("message",{message:Re.message,rejected:!0}),Re)},[t,d]),ze=dm({enabled:!$e,sinkRef:Ie,rootRef:Ve,adapter:t,commitEdits:Vt,getActive:ro,ensureCellVisible:Ot,focusSink:Oe,rearmSink:Ye,discardClip:Tt,isDragging:no,resolveEditAlign:b=>{if(t.getCellFormat===void 0)return null;const Y=$r(t,b.row,b.col);return cc(Qe(b.row,b.col,Y),Y)},resolveEditPaint:b=>t.getCellFormat===void 0?null:ad(Qe(b.row,b.col,$r(t,b.row,b.col))),editPaintRef:fs,repaintOverlay:Se,validateCommit:Ls});Pe.current=ze.isEditing,vs.current=ze.requestCommit,Rs.current=ze.startEdit,pt.current=ze.getPointing,xt.current=ze.insertReference,rn.current=ze.captureSink,At.current=ze.restoreSink;const Ps=l.useCallback(()=>{ze.cancelEdit(),On()},[ze.cancelEdit,On]),$n=Yh({enabled:!$e,sinkRef:Ie,adapter:t,isEditing:He,getSelection:Ee,setSelection:Ke,commitPaste:da,maxOperationCells:k,onOperationRejected:T,onCopyMultiRange:P,repaintOverlay:Se,isDragging:no,resize:{rowAxis:Q,colAxis:ie,resizeTracks:to},pendingPasteOptionsRef:ps,formats:y,onClipChange:f,onClipboardUnavailable:_,onEditRejected:q});ks.current=$n.getClip,Es.current=$n.discardClip,xs.current=$n.discardClipOnCommit,Os.current=$n.onAdapterSwitch,Xr.current=$n.paste;const Fn=bg({enabled:!$e,adapter:t,popovers:R,sinkRef:Ie,bodyRef:We,handleRef:be,rowAxis:Q,colAxis:ie,zoomRef:Ae,getActive:ro,isEditing:He,requestCommit:rt,focusSink:Oe,rearmSink:Ye,isDraggingAny:Mn,commitEdits:Vt,labels:Ne,onHyperlinkOpen:$,anchors:hs,repaintOverlay:Se});on.current=Fn,cr.current=Fn.open,ws.current=Fn.hideTip;const Sa=l.useCallback(()=>{const b=De.current.active;Ot(b);const Y=be.current,ee=Y===null?{x:0,y:0}:Y.getScrollPosition(),re=Y===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:Y.getFrozenSize(),Re=Y===null?{width:0,height:0}:Y.getViewportSize(),xe=Ae.current;return{top:Jt(Q,b.row,{scroll:Math.max(0,ee.y),frozenCount:re.rows,trailingCount:re.trailingRows,extent:Re.height})*xe,left:Zt(ie,b.col,{scroll:Math.max(0,ee.x),frozenCount:re.cols,trailingCount:re.trailingCols,extent:Re.width})*xe,width:ie.sizeOf(b.col)*xe,height:Q.sizeOf(b.row)*xe}},[Q,ie,Ot]),oo=cm({adapter:t,getSelection:Ee,commitEdits:Vt,getActive:ro,isEditing:He,requestCommit:rt,cancelEdit:Ps,getSessionText:ze.getSessionText,validateCommit:Ls,insertAtCaret:ze.insertAtCaret,refreshEditPaint:ze.refreshPaint,maxOperationCells:k,onOperationRejected:T,colors:dt,formats:y,getHighlight:()=>de.current,setHighlight:Me,popovers:R,openPopover:b=>cr.current(b),onHyperlinkOpen:$,onPasteSpecialRequest:C,paste:b=>Xr.current(b),rowAxis:Q,colAxis:ie,resizeTracks:to,defaultRowHeight:n,defaultColumnWidth:r,now:O,announce:ar,formatCommandAnnouncement:h,keyboardCellRect:Sa});bs.current=oo,Ur.current=oo.executeCommand,Cs.current=oo.isCommandAvailable;const Ea=l.useMemo(()=>({table:ct,execute:b=>Ur.current(b),isAvailable:b=>Cs.current(b)}),[ct]),xa=l.useCallback(()=>{Tt(),S?.()},[Tt,S]),Aa=l.useCallback(()=>{Tt(),N?.()},[Tt,N]);ig({zoomRef:Ae,enabled:!$e,sinkRef:Ie,rootRef:Ve,handOffFocusToRoot:la,getSelection:Ee,setSelection:Ke,moveActive:ca,ensureCellVisible:Ot,isEditing:He,requestCommit:rt,startEdit:Dn,commitEdits:Vt,maxOperationCells:k,onOperationRejected:T,getClip:Ss,discardClip:Tt,isDragging:Mn,abortDrag:ka,findDataEdge:t.findDataEdge,getEditingMode:ze.getEditingMode,cancelEdit:Ps,onUndoRequest:xa,onRedoRequest:Aa,onCellContextMenu:p,rowAxis:Q,colAxis:ie,handleRef:be,rearmSink:Ye,commands:Ea,pointing:ze,adapter:t,hideNoteTip:()=>ws.current(),closeRejectedMessage:On,pendingPasteOptionsRef:ps,onPointFrame:ha});const Oa=Fe.active.row,Ta=Fe.active.col;l.useLayoutEffect(()=>{const b=on.current;b!==null&&(b.syncTipAriaDescribedBy(),b.isKindEnabled("message")&&(b.isOpen()==="message"&&b.close(),b.open("message")))},[Oa,Ta]),l.useLayoutEffect(()=>{Se()},[Se,ce.row,ce.column,ce.intersection]);const Da=l.useCallback(b=>{(Pe.current?.()??!1)||(b.preventDefault(),Oe(),Ye())},[Oe,Ye]),Ma=l.useCallback(b=>{const Y=Ve.current,ee=b.relatedTarget;if(Y!==null&&ee instanceof Node&&Y.contains(ee)){b.target===Y&&ee===Ie.current&&!Gr.current&&Oe();return}(Pe.current?.()??!1)||(Oe(),Ye())},[Oe,Ye]),$a=l.useCallback(b=>{const Y=Ve.current,ee=b.relatedTarget;Y!==null&&ee instanceof Node&&Y.contains(ee)||ze.isFocusoutSuppressed()||Qr(!1)},[ze]),dr=l.useRef(null),zn=l.useCallback(()=>{const b=dr.current;b!==null&&(dr.current=null,window.removeEventListener("pointerup",b.up,!0),window.removeEventListener("pointercancel",b.cancel,!0))},[]),so=l.useCallback(()=>{if(dr.current!==null)return;const b=ee=>{ee.pointerType==="mouse"&&(zn(),ee.button===1&&ee.preventDefault())},Y=ee=>{ee.pointerType==="mouse"&&zn()};dr.current={up:b,cancel:Y},window.addEventListener("pointerup",b,!0),window.addEventListener("pointercancel",Y,!0)},[zn]);l.useEffect(()=>zn,[zn]),l.useEffect(()=>{const b=Ve.current;if($e||b===null)return;let Y=0;const ee=xe=>{if(xe.pointerType!=="mouse"){(Pe.current?.()??!1)||Qr(!1);return}Y=xe.buttons,xe.button===1&&(xe.target===Ie.current&&(Pe.current?.()??!1)||so())},re=xe=>{xe.pointerType==="mouse"&&(Y=xe.buttons)},Re=xe=>{if(xe.pointerType!=="mouse"||xe.buttons===Y)return;const lo=xe.buttons&~Y;Y=xe.buttons,xe.preventDefault(),(lo&4)!==0&&so()};return b.addEventListener("pointerdown",ee,!0),b.addEventListener("pointerup",re,!0),b.addEventListener("pointermove",Re,!0),()=>{b.removeEventListener("pointerdown",ee,!0),b.removeEventListener("pointerup",re,!0),b.removeEventListener("pointermove",Re,!0)}},[$e,so]);const Fa=l.useCallback(b=>{if(!(b.target!==b.currentTarget||b.pointerType!=="mouse")&&(b.preventDefault(),b.button===0)){if(ht()){Oe();return}if(He()&&!rt()){Oe();return}Oe()}},[Oe,He,rt,ht]),io=l.useRef(!1);l.useLayoutEffect(()=>{if($e){io.current=!1;return}if(io.current)return;io.current=!0,Ye();const b=(Ve.current?.clientHeight??0)/Ae.current;b>0&&Q.totalSize()>0&&ae.setRowRange(0,Q.indexAt(Math.min(b-1,Q.totalSize()-1)));const Y=(Ve.current?.clientWidth??0)/Ae.current;Y>0&&ie.totalSize()>0&&ae.setColRange(0,ie.indexAt(Math.min(Y-1,ie.totalSize()-1)))},[$e,Ye,ae,Q,ie]);const qs=l.useRef(t);l.useLayoutEffect(()=>{qs.current!==t&&(qs.current=t,mt.cancelDrag(),Mt.cancelDrag(),$t.cancelDrag(),Ft.cancelDrag(),gt.cancelDrag(),ut.cancelDrag(),ze.cancelEdit(),on.current?.hideTip(),on.current?.close(),$e?(De.current=Ar,qe(Ar)):Ke(Ar),Os.current())},[t,$e,Ke,mt,Mt,$t,Ft,gt,ut,ae,ze.cancelEdit]);const _s=l.useRef(o),Is=l.useRef(s),Hs=l.useRef(i),js=l.useRef(c);l.useLayoutEffect(()=>{(_s.current!==o||Is.current!==s||Hs.current!==i||js.current!==c)&&(_s.current=o,Is.current=s,Hs.current=i,js.current=c,mt.cancelDrag(),Mt.cancelDrag(),$t.cancelDrag(),Ft.cancelDrag(),gt.cancelDrag(),ut.cancelDrag())},[o,s,i,c,mt,Mt,$t,Ft,gt,ut]),l.useLayoutEffect(()=>{tt(),nt(),Se()},[o,s,i,c,tt,nt,Se]);const Bs=l.useRef(K);l.useLayoutEffect(()=>{Bs.current!==K&&(Bs.current=K,Tt())},[K,Tt]),l.useLayoutEffect(()=>{Se()},[Se,Fe]);const Wt=l.useCallback(()=>{const b=bs.current;if(b===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return b},[]);if(l.useImperativeHandle(he,()=>({resizeRow:(b,Y)=>{const ee=Math.round(Y);Q.resize(b,ee),be.current?.updateRowSize(b,ee),ae.bumpRowGeometry(),tt(),Se(),ln()},resizeColumn:(b,Y)=>{const ee=Math.round(Y);ie.resize(b,ee),be.current?.updateColSize(b,ee),ae.bumpColVersion(),nt(),Se(),ln()},scrollToCell:(b,Y)=>{be.current?.scrollToCell(b.row,b.col,Y)},focus:b=>{Oe(b),He()||Ye()},executeCommand:b=>Ur.current(b),applyFormat:b=>Wt().applyFormat(b),setBorders:(b,Y)=>Wt().setBorders(b,Y),setHyperlink:b=>Wt().setHyperlink(b),setNote:b=>Wt().setNote(b),addComment:b=>Wt().addComment(b),setValidation:b=>Wt().setValidation(b),paste:b=>Xr.current(b),getSelection:()=>De.current,getBaseFormat:b=>t.getCellFormat===void 0?void 0:t.getCellFormat(b.row,b.col),getPaintedFormat:b=>t.getCellFormat===void 0?void 0:Qe(b.row,b.col,$r(t,b.row,b.col)),startEdit:b=>{Dn(b)},openPopover:b=>{cr.current(b)}}),[Q,ie,ae,nt,tt,Se,ln,Oe,He,Ye,t,Qe,Dn,Wt]),$e)return W.jsx("div",{className:G?`aqsp-root ${G}`:"aqsp-root","data-aqsp-empty":"","data-testid":J});const za=x!==void 0||A!==void 0||h!==void 0;return W.jsx("div",{ref:Ve,className:G?`aqsp-root ${G}`:"aqsp-root",role:"group","aria-label":Ne.rootAriaLabel,tabIndex:0,onFocus:Ma,onBlur:$a,"data-aqsp-root":"","data-testid":J,children:W.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":_e,onPointerDown:Fa,style:_e===1?void 0:{width:`${100/_e}%`,height:`${100/_e}%`,transform:`scale(${_e})`},children:[W.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:b=>{if(b.pointerType==="mouse"&&(b.preventDefault(),b.button===0)){if(ht()){Oe();return}if(He()&&!rt()){Oe();return}Oe(),Ke({ranges:[Ce({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),W.jsx(Vm,{viewStore:ae,colAxis:ie,frozenCols:o,frozenTrailingCols:i,handleRef:be,bandRef:U,colTrackRef:F,windowOriginXRef:V,repaintColHeaders:nt,selectionRanges:Fe.ranges,enableResizeUI:D,dividerLeadingRef:Z,dividerTrailingRef:ne}),W.jsx(Wm,{viewStore:ae,rowAxis:Q,handleRef:be,bandRef:j,selectionRanges:Fe.ranges,rowTrackRef:ir,windowOriginYRef:lr,repaintHeaders:tt,enableResizeUI:D,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:le,dividerTrailingRef:ye}),W.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[W.jsx(Bm,{adapter:t,rowAxis:Q,colAxis:ie,viewStore:ae,handleRef:be,bodyRef:We,dataVersion:K,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:i,frozenTrailingRows:c,renderCell:a,onScroll:fa,onRangeChange:pa,focusSink:Oe,isEditing:He,requestCommit:rt,testId:J?`${J}-vs`:void 0,__onCellRender:se,cfIndexRef:kt,cfMemoRef:St,isPointing:ht}),W.jsx(vh,{rowAxis:Q,colAxis:ie,handleRef:be,sinkRef:Ie,getSelection:Ee,editing:ze.editing,virtualKeyboard:aa,repaintRef:at,dragFrameRef:Xe,getClip:Ss,getIsDraggingAny:Mn,getIsFillDragging:gt.isDragging,fillFrameRef:Ms,resizeGuideFrameRef:$s,fillHandleNodeRef:Fs,enableFillHandle:L,frozenCols:o,frozenRows:s,trailingCols:i,trailingRows:c,sinkAriaLabel:Ne.sinkAriaLabel,onSinkMouseDown:Da,editPaintRef:fs,highlightRef:de,highlightColors:ue,popoverAnchors:hs,interactiveAnchorRef:ms,tipAnchorRef:gs}),Fn.layerEnabled?W.jsx(gg,{controller:Fn,labels:Ne,renderPopover:u,interactiveAnchorRef:ms,tipAnchorRef:gs}):null]}),za?W.jsx("div",{ref:me,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=Ko;exports.CommentPopover=zc;exports.DEFAULT_CUSTOM_COLORS=ia;exports.DEFAULT_HIGHLIGHT_COLORS=$c;exports.DEFAULT_LABELS=Ho;exports.DEFAULT_SHORTCUTS=yc;exports.LinkPopover=Nc;exports.ListPopover=Lc;exports.MessagePopover=Pc;exports.NotePopover=qc;exports.NoteTip=_c;exports.SPREADSHEET_RESERVED_SHORTCUTS=xp;exports.Spreadsheet=zg;exports.canonicalizeFormat=lt;exports.columnIndexToName=Wn;exports.columnNameToIndex=Cp;exports.detectClipSource=gl;exports.enumerateRangeCells=Nt;exports.estimatePasteCellCount=dp;exports.expandPaste=fp;exports.formatCellValue=yn;exports.formatEquals=Va;exports.fromR1C1=Qn;exports.makeRange=Ce;exports.mergeFormat=Xo;exports.normalizeHyperlink=It;exports.parseChord=Xt;exports.parseClipPayload=Mo;exports.parseHtmlTable=lc;exports.parseTsv=gc;exports.rangeContains=Qt;exports.rangeSize=Je;exports.resolveLabel=Te;exports.serializeClipPayload=pl;exports.serializeHtmlTable=rc;exports.serializeTsv=pc;exports.shiftFormula=Il;exports.toR1C1=Vr;exports.validateCellText=kc;
|
|
16
|
+
`)||e.endsWith("\r")?e.slice(0,-1):e,Ac=(e,t,n)=>{let r=0;for(;;){let o;if(e[r]==='"'){const s=Dp(e,r);if(s!==null)o=s.value,r=s.nextIndex;else{const l=Dl(e,r);o=e.slice(r,l),r=l}}else{const s=Dl(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())}},Oc=e=>{const t=xc(e);if(t==="")return[[""]];const n=[];let r=[];Ac(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("")])},Tp=e=>{const t=xc(e);if(t==="")return{rows:1,cols:1};let n=0,r=0,o=0;return Ac(t,()=>{o+=1},()=>{n+=1,o>r&&(r=o),o=0}),{rows:n,cols:r}},Dp=(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},Dl=(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},Jn=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},Mp=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},Qr=["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"],$p=/^[A-Z]$/,Fp=/^[A-Za-z]$/,zp=/^Key([A-Z])$/,Tc=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"]),Np=e=>$p.test(e)||Tc.has(e),Gt=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!Np(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}},Lp=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Dc=e=>{if(Fp.test(e.key))return e.key.toUpperCase();const t=zp.exec(e.code);return t!==null?t[1]:Tc.has(e.code)?e.code:null},jn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Dc(t)===e.key,pe=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),we=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),Pp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(pe(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(pe(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(pe(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(pe(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},qp=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(pe(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(pe(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},cr=[...Pp(),pe("Home","idle","row start (first visible column)"),pe("Ctrl+Home","idle","first visible cell"),pe("Shift+Home","idle","extend to row start"),pe("Ctrl+Shift+Home","idle","extend to first visible cell"),pe("End","idle","row end (last visible column)"),pe("Ctrl+End","idle","last visible cell"),pe("Shift+End","idle","extend to row end"),pe("Ctrl+Shift+End","idle","extend to last visible cell"),pe("PageUp","both","page up (idle) / commit + page up (editing)"),pe("PageDown","both","page down (idle) / commit + page down (editing)"),pe("Shift+PageUp","idle","extend one page up"),pe("Shift+PageDown","idle","extend one page down"),pe("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),pe("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),pe("Tab","both","cycle right (idle) / commit + cycle right (editing)"),pe("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),pe("Enter","both","cycle down (idle) / commit + cycle down (editing)"),pe("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),pe("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),pe("F2","both","start editing (idle) / toggle the pointing arm (editing)"),pe("F4","editing","cycle the reference anchor under the caret (formula session)"),pe("Delete","idle","clear every selected cell"),pe("Backspace","idle","clear every selected cell"),pe("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),pe("Ctrl+A","idle","select all"),pe("Ctrl+Z","idle","undo request"),pe("Ctrl+Y","idle","redo request"),pe("Ctrl+Shift+Z","idle","redo request"),pe("Shift+F10","idle","keyboard context menu"),pe("ContextMenu","idle","keyboard context menu"),pe("Ctrl+Space","idle","column bands"),pe("Shift+Space","idle","row bands"),pe("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),pe("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),pe("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),pe("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...qp(),we("bold","Ctrl+B","both","toggle bold"),we("italic","Ctrl+I","both","toggle italic"),we("underline","Ctrl+U","both","toggle underline"),we("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),we("clearFormatting","Ctrl+Backslash","idle","clear formatting"),we("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),we("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),we("alignLeft","Ctrl+Shift+L","both","align left"),we("alignCenter","Ctrl+Shift+E","both","align center"),we("alignRight","Ctrl+Shift+R","both","align right"),we("formatNumber","Ctrl+Shift+Digit1","both","number format"),we("formatTime","Ctrl+Shift+Digit2","both","time format"),we("formatDate","Ctrl+Shift+Digit3","both","date format"),we("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),we("formatPercent","Ctrl+Shift+Digit5","both","percent format"),we("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),we("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),we("bordersClear","Alt+Shift+Digit6","idle","clear borders"),we("borderTop","Alt+Shift+Digit1","idle","top border"),we("borderRight","Alt+Shift+Digit2","idle","right border"),we("borderBottom","Alt+Shift+Digit3","idle","bottom border"),we("borderLeft","Alt+Shift+Digit4","idle","left border"),we("insertLink","Ctrl+K","idle","insert / edit hyperlink"),we("insertNote","Shift+F2","idle","insert / edit note"),we("insertComment","Ctrl+Alt+M","idle","insert comment"),we("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),we("openValidationList","Alt+ArrowDown","idle","open the validation list"),we("fillDown","Ctrl+D","idle","fill down"),we("fillRight","Ctrl+R","idle","fill right"),we("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),we("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),we("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),we("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),we("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),we("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],Vr=(e,t)=>e.column==="both"||e.column===t,_p=Array.from(new Set(cr.filter(e=>!e.rebindable&&Vr(e,"idle")).map(e=>e.chord))),ms=new Set(cr.filter(e=>e.command!==void 0&&Vr(e,"editing")).map(e=>e.command)),Ip=new Set(cr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Mc=e=>{const t={};for(const n of Qr)t[n]=e(n);return t},$c=Mc(e=>cr.filter(t=>t.command===e).map(t=>t.chord)),jp=e=>{const t=new Map;for(const n of Qr){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},Hp=e=>{const t=new Set(Qr);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(Ip.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`)}}}},Bp=(e,t)=>{const n=Gt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=ms.has(e);for(const o of cr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(Vr(o,"idle")||r&&Vr(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Vp=e=>{e!==void 0&&Hp(e);const t=Mc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?$c[r]:o===null?[]:o});for(const r of Qr)for(const o of t[r])Bp(r,o);const n=new Map;for(const[r,o]of jp(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},Ml=(e,t)=>{const n=Dc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Lp({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},Wp=Object.freeze({ok:!0}),Kp="TRUE",Yp="FALSE",Up=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Xp=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Gp=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Zp=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Jp=/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/,$l={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Qp={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Fl=e=>{const t=e.trim();if(!(Gp.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,y=m.search(/[^0]/);return y<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(y).replace(/0+$/,""),point:u.length+l-y}},eh=e=>e===1?-1:e===-1?1:0,th=(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:eh(n)},nh=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},zl=e=>{const t=Zp.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>nh(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},rh=(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},oh=(e,t)=>e<t?-1:e>t?1:0,sh=e=>e==="between"||e==="notBetween",lh=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!sh(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},ih=(e,t,n)=>{switch(e){case"gt":return t===1;case"gte":return t!==-1;case"lt":return t===-1;case"lte":return t!==1;case"eq":return t===0;case"neq":return t!==0;case"between":return t!==-1&&n!==1;default:return t===-1||n===1}},Ao=(e,t,n,r,o,s)=>{const l=lh(e,t,n,r);return l===null?!0:o===null?!1:ih(e,s(o,l.a),l.b===null?0:s(o,l.b))},ch=e=>Number.isFinite(e)?e:null,ah=e=>{let t=0;for(const n of e)t+=1;return t},uh=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),dh=(e,t)=>{switch(e.op){case"isEmail":return Jp.test(t);case"isUrl":return uh(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)}},fh=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,Fc=e=>({checked:e.checked===void 0?Kp:e.checked,unchecked:e.unchecked===void 0?Yp:e.unchecked}),ph=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Up.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "${e.type}"`);return;case"text":if(!Xp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type "${String(e.type)}"`)}},hh=(e,t,n)=>{switch(e.type){case"list":return wh(e).has(t);case"number":return Ao(e.op,e.a,e.b,Fl,Fl(t),th);case"textLength":return Ao(e.op,e.a,e.b,ch,ah(t),oh);case"date":return Ao(e.op,e.a,e.b,zl,zl(t),rh);case"text":return dh(e,t);case"checkbox":{const r=Fc(e);return t===r.checked||t===r.unchecked}default:return n===void 0||fh(n(e.formula))}},zc=(e,t,n)=>(ph(e),t===""||hh(e,t,n)),Oo=(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}`}},Nl=e=>e===void 0?void 0:e.trim(),mh=e=>{switch(e.type){case"list":return"Value must be one of the list items.";case"number":return`Value must be a number ${Oo(e.op,e.a.trim(),Nl(e.b),$l)}.`;case"textLength":return`Text length must be ${Oo(e.op,String(e.a),e.b===void 0?void 0:String(e.b),$l)}.`;case"date":return`Value must be a date ${Oo(e.op,e.a.trim(),Nl(e.b),Qp)}.`;case"text":return gh(e);case"checkbox":{const t=Fc(e);return`Value must be "${t.checked}" or "${t.unchecked}".`}default:return`Value does not satisfy the formula ${e.formula}.`}},gh=e=>{switch(e.op){case"contains":return`Value must contain "${e.value}".`;case"notContains":return`Value must not contain "${e.value}".`;case"startsWith":return`Value must start with "${e.value}".`;case"endsWith":return`Value must end with "${e.value}".`;case"isEmail":return"Value must be a valid email address.";default:return"Value must be a valid URL."}},Ll=new WeakMap,wh=e=>{const t=Ll.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Ll.set(e,n),n},Nc=(e,t,n)=>zc(e,t,n)?Wp:{ok:!1,message:e.errorMessage===void 0?mh(e):e.errorMessage},Ch=e=>e.type!=="custom",yh=(e,t)=>Ch(e)&&!zc(e,t,void 0),bh=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","validationRejected","popoverClose","indicatorNote","indicatorComment","indicatorInvalid"],Xo=Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",validationRejected:"The value does not satisfy this cell's validation rule",popoverClose:"Close",indicatorNote:"Has a note",indicatorComment:"Has comments",indicatorInvalid:"Invalid value"}),vh=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${JSON.stringify(t)}`)},Rh=(e,t,n)=>{e[t]=n},kh=e=>{if(e===void 0)return Xo;const t={...Xo};for(const n of bh){const r=e[n];r!==void 0&&Rh(t,n,r)}return vh(t),Object.freeze(t)},Oe=(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},Lc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Pc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),qc=(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,_c=(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),Ic=(e,t)=>Lc(e,t),jc=(e,t)=>Lc(e,t),Hc=(e,t)=>Pc(e,t),Bc=(e,t)=>Pc(e,t),Jt=(e,t,n)=>qc(e,t,n),Qt=(e,t,n)=>qc(e,t,n),ar=(e,t,n)=>_c(e,t,n),ur=(e,t,n)=>_c(e,t,n),lt=12,Sh=()=>{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)})}},Eh=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Nt=1,Un=3,Er=e=>`${-Math.min(Un,Math.max(0,Math.floor(e)))}px`,Vc=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),xh=16,Ah=450,Oh=e=>e>4?Math.floor(Ah/(5*e)):xh,Hn=(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},Pl=()=>({rowLeft:Hn("row","left"),rowRight:Hn("row","right"),colAbove:Hn("column","above"),colBelow:Hn("column","below"),cross:Hn("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Wc=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],xr=(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},Ar=(e,t)=>Math.min(Math.max(e,0),t),ql="inset(100%)",vn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Th=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,vn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const _=`${t.height}px`;e.rowLeft.style.height=_,e.rowRight.style.height=_}const m=`translate(${Ar(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const y=`translate(${Ar(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;y!==s.rowRightTransform&&(s.rowRightTransform=y,e.rowRight.style.transform=y)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,vn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const _=`${t.width}px`;e.colAbove.style.width=_,e.colBelow.style.width=_}const m=`translate(${t.left}px, ${Ar(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const y=`translate(${t.left}px, ${Ar(t.top+t.height,n.clampHeight)}px)`;y!==s.colBelowTransform&&(s.colBelowTransform=y,e.colBelow.style.transform=y)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,vn([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--aqsp-band-${u})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const m=`translate(${t.left}px, ${t.top}px)`;m!==s.crossTransform&&(s.crossTransform=m,e.cross.style.transform=m)}},_l=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,vn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,vn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,vn([e.cross],!1))},Il=e=>{for(const t of Wc(e))t.remove()},Dh=(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)},Mh=Object.freeze([]),jl=e=>e.dividers[0]??e.active,$h={left:"0px",right:"0px",width:""},Fh={top:"0px",bottom:"0px",height:""},Hl=()=>({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:[]}),Bl=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],Vl=6,zh=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:y,fillFrameRef:_,resizeGuideFrameRef:j,fillHandleNodeRef:L,enableFillHandle:I,frozenCols:Y,frozenRows:B,trailingCols:T,trailingRows:A,sinkAriaLabel:P,onSinkMouseDown:S,editPaintRef:R,highlightRef:E,highlightColors:f,popoverAnchors:g,interactiveAnchorRef:b,tipAnchorRef:$})=>{const x=i.useRef(null),k=i.useRef(null),w=i.useRef(null),v=i.useRef(new Map(Bl.map(z=>[z,Hl()]))),a=i.useCallback(z=>{const q=v.current.get(z);if(q!==void 0)return q;const X=Hl();return v.current.set(z,X),X},[]),p=i.useCallback((z,q,X)=>{if(z===null)return;const H=z.style;H.left!==q.left&&(H.left=q.left),H.right!==q.right&&(H.right=q.right),H.width!==q.width&&(H.width=q.width),H.top!==X.top&&(H.top=X.top),H.bottom!==X.bottom&&(H.bottom=X.bottom),H.height!==X.height&&(H.height=X.height)},[]),M=i.useCallback((z,q,X)=>{if(!(z.bandClampWidth===q&&z.bandClampHeight===X)){z.bandClampWidth=q,z.bandClampHeight=X;for(const H of z.bandPool)xr(H,q,X);z.dragBand!==null&&xr(z.dragBand,q,X)}},[]),d=i.useRef({rowAxis:e,colAxis:t});d.current={rowAxis:e,colAxis:t};const F=i.useCallback((z,q,X)=>{const H=z.dividerSlots[q];H===null||z.dividerShown[q]===X||(z.dividerShown[q]=X,H.style.display=X?"":"none")},[]),O=i.useRef({x:0,y:0}),D=i.useRef(null),N=i.useCallback((z,q)=>{const X=n.current,H=X?.getFrozenSize()??Eh,J=X?.getViewportSize(),re=J?.width??-1,ce=J?.height??-1,ye=O.current;ye.x=z,ye.y=q;let ge=D.current;if(ge===null||ge.frozenCols!==H.cols||ge.frozenWidth!==H.width||ge.frozenRows!==H.rows||ge.frozenHeight!==H.height||ge.trailingCols!==H.trailingCols||ge.trailingWidth!==H.trailingWidth||ge.trailingVisibleWidth!==H.trailingVisibleWidth||ge.trailingRows!==H.trailingRows||ge.trailingHeight!==H.trailingHeight||ge.trailingVisibleHeight!==H.trailingVisibleHeight||ge.bodyWidth!==re||ge.bodyHeight!==ce){const te=H.trailingVisibleWidth,ue=H.trailingVisibleHeight,he=H.cols<=0&&H.trailingCols<=0?[{kind:"m",map:Ce=>Ce-ye.x,clamp:re,style:$h,seamLead:!1,seamTrail:!1}]:[...H.cols>0?[{kind:"f",map:Ce=>Ce,clamp:H.width,style:{left:"0px",width:`${H.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-ye.x-H.width,clamp:Math.max(0,re-H.width-te),style:{left:`${H.width}px`,right:`${te}px`,width:""},seamLead:H.cols>0,seamTrail:H.trailingCols>0},...H.trailingCols>0?[{kind:"t",map:Ce=>Ce-d.current.colAxis.totalSize()+te,clamp:te,style:{left:"",right:"0px",width:`${te}px`},seamLead:!0,seamTrail:!1}]:[]],ae=H.rows<=0&&H.trailingRows<=0?[{kind:"m",map:Ce=>Ce-ye.y,clamp:ce,style:Fh,seamLead:!1,seamTrail:!1}]:[...H.rows>0?[{kind:"f",map:Ce=>Ce,clamp:H.height,style:{top:"0px",height:`${H.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:Ce=>Ce-ye.y-H.height,clamp:Math.max(0,ce-H.height-ue),style:{top:`${H.height}px`,bottom:`${ue}px`,height:""},seamLead:H.rows>0,seamTrail:H.trailingRows>0},...H.trailingRows>0?[{kind:"t",map:Ce=>Ce-d.current.rowAxis.totalSize()+ue,clamp:ue,style:{top:"",bottom:"0px",height:`${ue}px`},seamLead:!0,seamTrail:!1}]:[]],se=[];for(const Ce of he)for(const be of ae)se.push({nodes:a(`${Ce.kind}${be.kind}`),xKind:Ce.kind,yKind:be.kind,mapX:Ce.map,clampWidth:Ce.clamp,xStyle:Ce.style,xSeamLead:Ce.seamLead,xSeamTrail:Ce.seamTrail,mapY:be.map,clampHeight:be.clamp,yStyle:be.style,ySeamLead:be.seamLead,ySeamTrail:be.seamTrail});ge={frozenCols:H.cols,frozenWidth:H.width,frozenRows:H.rows,frozenHeight:H.height,trailingCols:H.trailingCols,trailingWidth:H.trailingWidth,trailingVisibleWidth:H.trailingVisibleWidth,trailingRows:H.trailingRows,trailingHeight:H.trailingHeight,trailingVisibleHeight:H.trailingVisibleHeight,bodyWidth:re,bodyHeight:ce,ctxs:se},D.current=ge}const Ne=H.width>0,Le=H.trailingWidth>0,Pe=H.height>0,Fe=H.trailingHeight>0;for(const te of ge.ctxs)p(te.nodes.container,te.xStyle,te.yStyle),M(te.nodes,te.clampWidth,te.clampHeight),F(te.nodes,0,Ne),F(te.nodes,1,Le),F(te.nodes,2,Pe),F(te.nodes,3,Fe);return ge.ctxs},[n,a,p,M,F]),W=i.useCallback((z,q,X)=>{z.dividerSlots[q]=X,z.dividerShown[q]=!1,z.dividers.length=0;for(const H of z.dividerSlots)H!==null&&z.dividers.push(H)},[]),V=i.useCallback(z=>{const q=()=>a(z);return{container:X=>{const H=q();H.container=X,X===null&&(H.fillPool.length=0,H.bandPool.length=0,H.dragBand=null,H.bandClampWidth=-1,H.bandClampHeight=-1)},dividerXLeading:X=>W(q(),0,X),dividerXTrailing:X=>W(q(),1,X),dividerYLeading:X=>W(q(),2,X),dividerYTrailing:X=>W(q(),3,X),active:X=>{q().active=X},dragRect:X=>{q().dragRect=X},marquee:X=>{q().marquee=X},fillPreview:X=>{q().fillPreview=X},resizeGuide:X=>{q().resizeGuide=X}}},[a,W]),G=i.useMemo(()=>Object.fromEntries(Bl.map(z=>[z,V(z)])),[V]),Z=Math.min(Math.max(0,Y),t.count),ee=Ic(t,Z),ie=Math.min(Math.max(0,B),e.count),oe=jc(e,ie),Te=T===void 0?0:Math.min(Math.max(0,T),t.count-Z),qe=Hc(t,Te),De=A===void 0?0:Math.min(Math.max(0,A),e.count-ie),_e=Bc(e,De),de=i.useRef(null),fe=i.useRef("add"),Ze=i.useRef(s);Ze.current=s;const ve=i.useRef(!1),Ht=rr.useWheelBridge(n,{enableBridge:!s}),dr=i.useCallback(z=>(r.current=z,Ht(z)),[r,Ht]),tn=i.useCallback((z,q)=>({top:q.mapY(e.offsetOf(z.startRow)),bottom:q.mapY(e.offsetOf(z.endRow)+e.sizeOf(z.endRow)),left:q.mapX(t.offsetOf(z.startCol)),right:q.mapX(t.offsetOf(z.endCol)+t.sizeOf(z.endCol))}),[e,t]),ct=i.useCallback((z,q)=>{if(q.clampHeight<=0||q.clampWidth<=0)return null;const{top:X,bottom:H,left:J,right:re}=tn(z,q),ce=-q.clampHeight*Nt,ye=q.clampHeight*(1+Nt),ge=-q.clampWidth*Nt,Ne=q.clampWidth*(1+Nt);if(H<ce||X>ye||re<ge||J>Ne)return null;const Le=Math.max(X,ce),Pe=Math.max(J,ge);return{top:Le,left:Pe,width:Math.min(re,Ne)-Pe,height:Math.min(H,ye)-Le}},[tn]),Tn=i.useCallback((z,q)=>{if(q.clampHeight<=0||q.clampWidth<=0)return null;const X=tn(z,q),H=-q.clampHeight*Nt,J=q.clampHeight*(1+Nt),re=-q.clampWidth*Nt,ce=q.clampWidth*(1+Nt),ye=Math.min(Math.max(X.top,H),J),ge=Math.min(Math.max(X.left,re),ce);return{top:ye,left:ge,width:Math.min(Math.max(X.right,re),ce)-ge,height:Math.min(Math.max(X.bottom,H),J)-ye}},[tn]),nn=i.useCallback(()=>{if(E===void 0)return null;const z=E.current;return z.row||z.column||z.intersection?z:null},[E]),Dn=i.useCallback((z,q,X)=>{const H=q.fillPool[0]?.node??jl(q);for(const J of Wc(X))z.insertBefore(J,H)},[]),rn=i.useCallback((z,q,X,H)=>{const J=Tn(q,X);if(J===null){_l(z);return}Th(z,J,X,H,Li(q,t.count)||Pi(q,e.count))},[Tn,e,t]),on=i.useCallback((z,q,X,H)=>{const J=z.nodes.bandPool;for(;J.length>X.length;){const re=J.pop();re!==void 0&&Il(re)}if(H===null){z.nodes.dragBand!==null&&(Il(z.nodes.dragBand),z.nodes.dragBand=null);return}for(let re=0;re<X.length;re+=1){let ce=J[re];ce===void 0&&(ce=Pl(),xr(ce,z.clampWidth,z.clampHeight),Dn(q,z.nodes,ce),J.push(ce)),rn(ce,X[re],z,H)}},[Dn,rn]),ht=i.useCallback((z,q,X)=>{const H=z.nodes.container;if(H===null)return;if(q===null||X===null){z.nodes.dragBand!==null&&_l(z.nodes.dragBand);return}let J=z.nodes.dragBand;J===null&&(J=Pl(),xr(J,z.clampWidth,z.clampHeight),Dn(H,z.nodes,J),z.nodes.dragBand=J),rn(J,q,z,X)},[Dn,rn]),at=i.useCallback((z,q)=>{if(z!==null){if(q===null){z.style.display="none";return}z.style.display="block",z.style.transform=`translate(${q.left}px, ${q.top}px)`,z.style.width=`${q.width}px`,z.style.height=`${q.height}px`}},[]),Et=i.useCallback((z,q,X,H)=>{const J=H==="point"?null:nn();for(const re of N(X,q))at(re.nodes.dragRect,ct(z,re)),ht(re,z,J)},[ct,N,at,nn,ht]),Je=i.useCallback((z,q,X)=>{for(const H of N(X,q))at(H.nodes.fillPreview,z===null?null:ct(z,H))},[ct,N,at]),Ie=i.useCallback((z,q,X)=>{for(const H of N(X,q)){const J=H.nodes.resizeGuide;if(J===null)continue;if(z===null){J.style.display="none";continue}const re=z.anchor==="trailing";if(z.axis==="col"){if(re&&H.xKind!=="t"){J.style.display="none";continue}J.style.display="block";const ce=H.mapX(z.position);J.style.transform=`translate(${re?Math.max(0,ce):ce}px, 0px)`,J.style.width="1px",J.style.height="100%"}else{if(re&&H.yKind!=="t"){J.style.display="none";continue}J.style.display="block";const ce=H.mapY(z.position);J.style.transform=`translate(0px, ${re?Math.max(0,ce):ce}px)`,J.style.width="100%",J.style.height="1px"}}},[N]),Mn=i.useCallback((z,q,X,H,J,re,ce)=>{if(z===null)return;if(q===null||ce<=0||re<=0){z.style.clipPath=ql;return}const ye=Qt(e,q.row,H),ge=Jt(t,q.col,X),Ne=t.sizeOf(q.col),Le=e.sizeOf(q.row),Pe=ge>=re||ye>=ce,Fe=q.col>=J.cols&&ge<J.width,te=q.row>=J.rows&&ye<J.height,ue=J.trailingWidth>0&&q.col<t.count-J.trailingCols&&ge+Ne>re-J.trailingVisibleWidth,he=J.trailingHeight>0&&q.row<e.count-J.trailingRows&&ye+Le>ce-J.trailingVisibleHeight;if(Pe||Fe||te||ue||he){z.style.clipPath=ql;return}z.style.clipPath="",z.style.transform=`translate(${ge}px, ${ye}px)`;const ae=`${Ne} ${Le}`;z.dataset.aqspAnchorSig!==ae&&(z.dataset.aqspAnchorSig=ae,z.style.width=`${Ne}px`,z.style.height=`${Le}px`)},[e,t]),fr=i.useCallback((z,q,X)=>{if(g===void 0)return;const H=g.current,{width:J,height:re}=z.getViewportSize(),ce=z.getFrozenSize(),ye={scroll:X,frozenCount:ce.cols,trailingCount:ce.trailingCols,extent:J},ge={scroll:q,frozenCount:ce.rows,trailingCount:ce.trailingRows,extent:re};Mn(b===void 0?null:b.current,H.interactive,ye,ge,ce,J,re),Mn($===void 0?null:$.current,H.tip,ye,ge,ce,J,re)},[g,b,$,Mn]),We=i.useCallback(()=>{const z=x.current,q=n.current;if(z===null||q===null)return;const X=q.getScrollPosition(),H=Math.max(0,X.y),J=Math.max(0,X.x),re=o(),ce=N(J,H),ye=nn(),ge=ye===null?Mh:re.ranges.slice(-Oh(ce.length));for(const te of ce){const ue=te.nodes.container;if(ue===null)continue;const he=te.nodes.fillPool;for(let ae=0;ae<Math.max(he.length,re.ranges.length);ae+=1){let se=he[ae];if(se===void 0){const Se=document.createElement("div");Se.className="aqsp-selection-fill",Se.setAttribute("data-aqsp-fill",""),Se.style.display="none",ue.insertBefore(Se,jl(te.nodes)),se={node:Se,last:{shown:!1,width:-1,height:-1,transform:""}},he.push(se)}const Ce=re.ranges[ae],be=Ce===void 0?null:ct(Ce,te);if(be===null)se.last.shown&&(se.last.shown=!1,se.node.style.display="none");else{se.last.shown||(se.last.shown=!0,se.node.style.display="block");const Se=`translate(${be.left}px, ${be.top}px)`;Se!==se.last.transform&&(se.last.transform=Se,se.node.style.transform=Se),be.width!==se.last.width&&(se.last.width=be.width,se.node.style.width=`${be.width}px`),be.height!==se.last.height&&(se.last.height=be.height,se.node.style.height=`${be.height}px`)}}for(;he.length>re.ranges.length;)he.pop()?.node.remove();at(te.nodes.active,ct(me(re.active,re.active),te)),on(te,ue,ge,ye)}const Ne=h(),Le=Ne===null||Ne.foreign?null:Ne;for(const te of ce){const ue=te.nodes.marquee;if(ue===null)continue;const he=Le===null?null:ct(Le.range,te),ae=he!==null&&(te.xSeamTrail&&he.left>=te.clampWidth&&he.left<te.clampWidth+Un||te.xSeamLead&&he.left+he.width<=0&&he.left+he.width>-Un||te.ySeamTrail&&he.top>=te.clampHeight&&he.top<te.clampHeight+Un||te.ySeamLead&&he.top+he.height<=0&&he.top+he.height>-Un)?null:he;if(ae===null)ue.style.display="none";else{ue.style.display="block",ue.style.transform=`translate(${ae.left}px, ${ae.top}px)`,ue.style.width=`${ae.width}px`,ue.style.height=`${ae.height}px`;const be=Er(ae.top),Se=Er(ae.left),Qe=Er(te.clampHeight-(ae.top+ae.height)),ut=Er(te.clampWidth-(ae.left+ae.width)),dt=`${be} ${ut} ${Qe} ${Se}`;dt!==ue.dataset.aqspOutsetSig&&(ue.dataset.aqspOutsetSig=dt,ue.style.setProperty("--aqsp-clip-outset-top",be),ue.style.setProperty("--aqsp-clip-outset-right",ut),ue.style.setProperty("--aqsp-clip-outset-bottom",Qe),ue.style.setProperty("--aqsp-clip-outset-left",Se))}const se=ae===null?null:Le?.kind??null,Ce=ue.dataset.aqspClipKindLast??null;se!==Ce&&(se===null?(delete ue.dataset.aqspClipKindLast,ue.removeAttribute("data-aqsp-clip-kind")):(ue.dataset.aqspClipKindLast=se,ue.setAttribute("data-aqsp-clip-kind",se)))}de.current!==null&&Et(de.current,H,J,fe.current),w.current!==null&&Ie(w.current,H,J),k.current!==null&&Je(k.current,H,J);const Pe=L.current;if(Pe!==null&&!y()){const{width:te,height:ue}=q.getViewportSize(),he=re.ranges[re.ranges.length-1];if(!(re.ranges.length===1&&!Ze.current&&!m())||ue<=0||te<=0)Pe.style.display="none";else{const se=q.getFrozenSize(),Ce={scroll:J,frozenCount:se.cols,trailingCount:se.trailingCols,extent:te},be={scroll:H,frozenCount:se.rows,trailingCount:se.trailingRows,extent:ue},Se=he.endCol<se.cols,Qe=he.endRow<se.rows,ut=he.endCol>=t.count-se.trailingCols,dt=he.endRow>=e.count-se.trailingRows,Ot=Jt(t,he.endCol,Ce)+t.sizeOf(he.endCol),Bt=Qt(e,he.endRow,be)+e.sizeOf(he.endRow),sn=Se||ut?0:se.width,mt=Qe||dt?0:se.height,et=ut?te:te-se.trailingVisibleWidth,Fn=dt?ue:ue-se.trailingVisibleHeight;Bt<=mt||Bt>Fn||Ot<=sn||Ot>et?Pe.style.display="none":(Pe.style.display="block",Pe.style.transform=`translate(${Ot-Vl+1}px, ${Bt-Vl+1}px)`)}}const Fe=r.current;if(Fe!==null){const te=re.active,{width:ue,height:he}=q.getViewportSize(),ae=q.getFrozenSize(),se={scroll:J,frozenCount:ae.cols,trailingCount:ae.trailingCols,extent:ue},Ce={scroll:H,frozenCount:ae.rows,trailingCount:ae.trailingRows,extent:he},be=Qt(e,te.row,Ce),Se=Jt(t,te.col,se),Qe=he>0?Math.min(Math.max(be,0),Math.max(0,he-1)):0,ut=ue>0?Math.min(Math.max(Se,0),Math.max(0,ue-1)):0;Fe.style.top=`${Qe}px`,Fe.style.left=`${ut}px`,Ze.current?(Fe.style.width=`${t.sizeOf(te.col)}px`,Fe.style.height=`${e.sizeOf(te.row)}px`,Fe.style.paddingTop=`${Dh(e.sizeOf(te.row),R===void 0?vt:R.current)}px`):(Fe.style.width="1px",Fe.style.height="1px",Fe.style.paddingTop="0px");const dt=te.col>=ae.cols&&Se<ae.width,Ot=te.row>=ae.rows&&be<ae.height,Bt=ae.trailingWidth>0&&te.col<t.count-ae.trailingCols&&Se+t.sizeOf(te.col)>ue-ae.trailingVisibleWidth,sn=ae.trailingHeight>0&&te.row<e.count-ae.trailingRows&&be+e.sizeOf(te.row)>he-ae.trailingVisibleHeight,mt=Ze.current&&be===Qe&&Se===ut&&!dt&&!Ot&&!Bt&&!sn;mt!==ve.current&&(ve.current=mt,mt?Fe.setAttribute("data-aqsp-editing",""):Fe.removeAttribute("data-aqsp-editing"))}fr(q,H,J)},[n,ct,N,at,Et,Ie,Je,h,o,m,y,L,r,e,t,nn,on,R,fr]),Me=i.useCallback((z,q)=>{de.current=z,fe.current=q;const X=z===null?"add":q;for(const re of N(0,0)){const ce=re.nodes.dragRect;if(ce===null)continue;const ye=ce.dataset.aqspDragModeLast??"add";X!==ye&&(ce.dataset.aqspDragModeLast=X,X==="add"?ce.removeAttribute("data-aqsp-drag-mode"):ce.setAttribute("data-aqsp-drag-mode",X))}const H=n.current;if(z===null||H===null){for(const re of N(0,0))re.nodes.dragRect!==null&&(re.nodes.dragRect.style.display="none"),ht(re,null,null);return}const J=H.getScrollPosition();Et(z,Math.max(0,J.y),Math.max(0,J.x),q)},[n,Et,N,ht]),xt=i.useCallback(z=>{k.current=z;const q=n.current;if(q===null){for(const H of N(0,0))H.nodes.fillPreview!==null&&(H.nodes.fillPreview.style.display="none");return}const X=q.getScrollPosition();Je(z,Math.max(0,X.y),Math.max(0,X.x))},[n,Je,N]),$n=i.useCallback(z=>{w.current=z;const q=n.current;if(q===null){for(const H of N(0,0))H.nodes.resizeGuide!==null&&(H.nodes.resizeGuide.style.display="none");return}const X=q.getScrollPosition();Ie(z,Math.max(0,X.y),Math.max(0,X.x))},[n,Ie,N]);i.useLayoutEffect(()=>{const z=x.current;if(!(z===null||f===void 0))return z.style.setProperty("--aqsp-band-row",f.row),z.style.setProperty("--aqsp-band-column",f.column),z.style.setProperty("--aqsp-band-intersection",f.intersection),z.style.setProperty("--aqsp-band-opacity",String(f.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")}},[f]),i.useEffect(()=>(c.current=We,u.current=Me,_.current=xt,j.current=$n,()=>{c.current=null,u.current=null,_.current=null,j.current=null})),i.useEffect(()=>{We()},[We,s,Z,ie,Te,De]),i.useEffect(()=>{const z=r.current;if(z===null)return;const q=X=>S(X);return z.addEventListener("mousedown",q),()=>z.removeEventListener("mousedown",q)},[r,S]);const pr=Z>0||Te>0?[...Z>0?[{k:"f",style:{left:0,width:ee}}]:[],{k:"s",style:{left:ee,right:qe}},...Te>0?[{k:"t",style:{right:0,width:qe}}]:[]]:[{k:"m",style:{left:0,right:0}}],hr=ie>0||De>0?[...ie>0?[{k:"f",style:{top:0,height:oe}}]:[],{k:"s",style:{top:oe,bottom:_e}},...De>0?[{k:"t",style:{bottom:0,height:_e}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],At=z=>z==="m"?0:z==="s"?1:z==="t"?2:3,$e=pr.flatMap(z=>hr.map(q=>({xk:z.k,yk:q.k,key:`${z.k}${q.k}`,style:{...z.style,...q.style}}))).sort((z,q)=>At(z.key[0])+At(z.key[1])-(At(q.key[0])+At(q.key[1]))),mr=z=>z==="mm"?{"data-aqsp-overlay-main":""}:z==="fm"?{"data-aqsp-overlay-frozen":""}:z==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:x,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:lt,bottom:lt},children:[$e.map(({xk:z,yk:q,key:X,style:H})=>{const J=G[X];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...mr(X),style:H,ref:J.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:J.dividerXLeading}):null,z==="s"&&Te>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:J.dividerXTrailing}):null,q==="s"&&ie>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:J.dividerYLeading}):null,q==="s"&&De>0?K.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:J.dividerYTrailing}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:J.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:J.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:J.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:J.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:J.resizeGuide})]},X)}),K.jsx("textarea",{ref:dr,className:"aqsp-sink","aria-label":P,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),I?K.jsx("div",{ref:L,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Kc=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=y=>{l.current=!0;try{y()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=y=>{if(y.key==="Escape"){y.preventDefault(),c(e.close);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&!y.altKey&&!y.shiftKey&&(y.preventDefault(),u())},m=y=>{l.current||y.relatedTarget instanceof Node&&y.currentTarget.contains(y.relatedTarget)||e.rejected||c(e.close)};return 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:m,children:[K.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[Oe(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Oe(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(y=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":y.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:y.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:y.createdAt,children:y.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:y.text})]},y.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Oe(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:y=>r(y.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:Oe(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Oe(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Yc=({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:jt(o),m=o.trim()!==""&&h===null,y=I=>{u.current=!0;try{I()}finally{u.current=!1}},_=()=>{l||m||y(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},j=I=>{if(I.key==="Escape"){I.preventDefault(),y(e.close);return}I.key==="Enter"&&!I.altKey&&!I.shiftKey&&(I.preventDefault(),_())},L=I=>{u.current||I.relatedTarget instanceof Node&&I.currentTarget.contains(I.relatedTarget)||e.rejected||y(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":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:L,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:Oe(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Oe(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:I=>r(I.currentTarget.value),onKeyDown:j})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:Oe(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:I=>s(I.currentTarget.value),onKeyDown:j})]}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:_,children:Oe(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:Oe(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Oe(t,"popoverClose"),onClick:()=>y(e.close),children:"×"})]})]})},Wl=500,Uc=({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(T=>T.toLowerCase().startsWith(B))},[e.current,n]),h=i.useMemo(()=>u.length>Wl?u.slice(0,Wl):u,[u]),m=u.length-h.length,y=h.length===0?-1:Math.min(o,h.length-1),_=B=>{c.current=!0;try{B()}finally{c.current=!1}},j=()=>{y<0||_(()=>e.commit(h[y]))},L=B=>{if(B.key==="Escape"){B.preventDefault(),_(e.close);return}if(B.key==="Enter"){B.preventDefault(),j();return}if(B.key==="ArrowDown"){B.preventDefault(),s(y+1);return}B.key==="ArrowUp"&&(B.preventDefault(),s(Math.max(y-1,0)))},I=B=>{c.current||B.relatedTarget instanceof Node&&B.currentTarget.contains(B.relatedTarget)||_(e.close)},Y=B=>`${l}-${B}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:I,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":Oe(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":y<0?void 0:Y(y),value:n,onChange:B=>{r(B.currentTarget.value),s(0)},onKeyDown:L}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Oe(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Oe(t,"listEmpty")}):h.map((B,T)=>K.jsx("div",{className:"aqsp-popover-option",id:Y(T),role:"option",tabIndex:-1,"aria-selected":T===y,"data-aqsp-list-option":B,onPointerDown:A=>A.preventDefault(),onClick:()=>_(()=>e.commit(B)),children:B},Y(T))),m>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Oe(t,"listMore",m)}):null]})]})},Xc=({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":Oe(t,"popoverClose"),onClick:e.close,children:"×"})]}),Gc=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=L=>{u.current=!0;try{L()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},y=()=>{r!==n&&!s?m():h(e.close)},_=L=>{if(L.key==="Escape"){L.preventDefault(),e.rejected?h(e.close):y();return}L.key==="Enter"&&(L.ctrlKey||L.metaKey)&&!L.altKey&&!L.shiftKey&&(L.preventDefault(),m())},j=L=>{u.current||L.relatedTarget instanceof Node&&L.currentTarget.contains(L.relatedTarget)||e.rejected||y()};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:Oe(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:L=>o(L.currentTarget.value),onKeyDown:_}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:Oe(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:m,children:Oe(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Oe(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},Zc=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),yt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),Kl=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Jc=Object.freeze({all:yt(Kl),values:yt(["text"]),formats:yt(["format","borders","cf"]),formulas:yt(["text","formula"]),noBorders:yt(Kl.filter(e=>e!=="borders")),columnWidths:yt(["sizes"]),validation:yt(["validation"]),conditionalFormats:yt(["cf"]),commentsAndNotes:yt(["note","comments"])}),Yl=Object.freeze({mode:"all"}),Go=Object.freeze({t:""}),Ul=Object.freeze({row:1<<30,col:1<<30}),Nh=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Lh=e=>e.t===""&&e.f===void 0,Ph=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}},Xl=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,_h=(e,t,n,r)=>{const o=Ph(e),s=e===""?"0":Xe(e);if(!o&&s===null)return null;const l=Nh[n];if(t.f!==void 0){const h=lr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Xl(Number(s));const c=Xe(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Xl(qh(Number(s),u,n))},Gl=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Ih=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:Gl(e.start),end:Gl(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}}}},jh=e=>{const t=lr(e,Ul),n=sr(t);let r="",o=0,s=!1;for(const l of n){const c=Ih(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${qt(c)}`,o=l.end,s=!0)}return s?Gr(`${r}${t.slice(o)}`,Ul):e},Hh=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Go;const o=r[n];return o===void 0?Go:o},Bh=e=>{const{rows:t,cols:n}=e,r=Gi(jh);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const u=[];for(let h=0;h<t;h+=1){const m=Hh(e,h,c);let y=m;if(m.f!==void 0){const _=r(m.f);y=_===m.f?m:{...m,f:_}}(y!==m||m===Go)&&(o=!1),u.push(y)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},Vh=(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,Wh=(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},Zl=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)Vh(m,t)?(h.push(Wh(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},Jl=new WeakMap,Qc=e=>{const t=Jl.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>it(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:it({...s,borders:void 0})),o={canonical:n,borderless:r};return Jl.set(e,o),o},Wr=(e,t)=>t===void 0?void 0:e[t],Kh=(e,t,n,r)=>{const o=Qc(e);if(n){const h=Wr(o.canonical,t.fmt);return h===void 0?null:h}const s=Wr(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=it(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},Yh=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?_h(n.readText(),o,r,n):o.f===void 0?o.t:lr(o.f,n)},Ql=(e,t,n,r,o)=>{const s=Jc[r.mode];if(r.skipBlanks===!0&&Lh(e))return null;const l={};let c=!1;if(s.text){const u=Yh(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Kh(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=Wr(Qc(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=Wr(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},ei=(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}}),Uh=["text/html","text/plain"],Xh=(e,t,n)=>{if(e===0||t===0)return 0;const r=Ge(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Gh=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Zh=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Jh=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}}},ti=e=>{const t=e.clipboardData;return t??null},Qh=(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}},em=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Qh(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},tm=(e,t,n,r,o)=>{const s=An(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Gr(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=On(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},ea=(e,t)=>{const n=Ni(),r=ud(),o=[];for(let s=t.startRow;s<=t.endRow;s+=1){const l=[];for(let c=t.startCol;c<=t.endCol;c+=1)l.push(tm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:em(e.getConditionalFormats(),t)}},ni=e=>e.kind==="cut"?{...e.payload,...ea(e.sourceAdapter,e.range)}:e.payload,nm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:os(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),rm=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=jt(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},om=(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},sm=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return me({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},lm=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(T=>{const A=n.current;if(A===null||T==="format"||T==="annotate")return;const P=r.current;P==="own"||P==="foreign"&&A.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const T=n.current;if(T===null)return;if(T.kind==="copy"){o();return}const A=t.current;A.repaintOverlay(),A.onClipChange?.({kind:"cut",range:T.range,foreign:T.sourceAdapter!==A.adapter})},[o]),c=i.useCallback((T,A,P)=>{const S=t.current;n.current={kind:T,range:A,clipId:P.clipId,sourceAdapter:S.adapter,payload:P},S.repaintOverlay(),S.onClipChange?.({kind:T,range:A,foreign:!1})},[]),u=i.useCallback(T=>{const A=t.current,P=A.adapter,S=Ge(T),R={v:1,rows:S.rows,cols:S.cols,clipId:os(),...ea(P,T),wholeRows:Li(T,P.colCount),wholeCols:Pi(T,P.rowCount)};if(A.resize!==void 0){if(R.wholeCols){const E=[];for(let f=T.startCol;f<=T.endCol;f+=1)E.push(Math.min(A.resize.colAxis.sizeOf(f),Sn));R.colWidths=E}if(R.wholeRows){const E=[];for(let f=T.startRow;f<=T.endRow;f+=1)E.push(Math.min(A.resize.rowAxis.sizeOf(f),Sn));R.rowHeights=E}}return R},[]),h=i.useCallback((T,A)=>{const P=t.current,S=P.getSelection(),R=S.ranges[S.ranges.length-1],E=pt([R]);if(E>P.maxOperationCells)return T.preventDefault(),P.onOperationRejected?.(A,E,"limit"),null;if(A==="cut"&&Yn(P.adapter,R))return T.preventDefault(),P.rejectReadOnly({kind:"operation",op:"cut",cellCount:E}),null;S.ranges.length>1&&P.onCopyMultiRange?.();const f=u(R),g=Si(f),b=ti(T);return b!==null&&(b.setData("text/plain",Ec(f.cells.map($=>$.map(x=>x.t)))),b.setData("text/html",hc(f,g)),b.setData(Hr,g)),T.preventDefault(),{payload:f,range:R}},[u]),m=i.useCallback((T,A)=>t.current.commitPaste(T,A)!==null,[]),y=i.useCallback((T,A,P)=>{const S=t.current;if(!P.sizes||S.resize===void 0)return;const{rowAxis:R,colAxis:E,resizeTracks:f}=S.resize,g=(b,$,x)=>{const k=es($,x,null,{maxOperationCells:S.maxOperationCells,rowHiddenLimit:Jo,axisKind:b});if(!k.ok){S.onOperationRejected?.("resize",k.count,k.reason);return}f(b,k.entries)};if(T.colWidths!==void 0){const b=[];for(let $=A.startCol;$<=A.endCol;$+=1)b.push({index:$,size:T.colWidths[($-A.startCol)%T.cols]});g("col",E,b)}if(T.rowHeights!==void 0){const b=[];for(let $=A.startRow;$<=A.endRow;$+=1)b.push({index:$,size:T.rowHeights[($-A.startRow)%T.rows]});g("row",R,b)}},[]),_=i.useCallback((T,A)=>{const P=t.current,S=P.adapter,R=T.payload,E={row:A.startRow,col:A.startCol},f=R.rows*R.cols+pt([T.range]);if(f>P.maxOperationCells)return P.onOperationRejected?.("paste",f,"limit"),"rejected";if(E.row+R.rows>S.rowCount||E.col+R.cols>S.colCount||T.range.endRow>=T.sourceAdapter.rowCount||T.range.endCol>=T.sourceAdapter.colCount)return P.onOperationRejected?.("paste",f,"bounds"),"rejected";const g=Uo({rows:R.rows,cols:R.cols},me(E,E),E,S.rowCount,S.colCount);if(g!==null&&Yn(S,g))return P.rejectReadOnly({kind:"operation",op:"paste",cellCount:R.rows*R.cols}),"rejected";if(Yn(T.sourceAdapter,T.range))return P.rejectReadOnly({kind:"operation",op:"cut",cellCount:pt([T.range])}),"rejected";const b=ni(T),$=Ir(S),x=Zl(b,$),k={row:0,col:0,readText:()=>An(S,k.row,k.col).text,readFormat:()=>S.getCellFormat===void 0?void 0:S.getCellFormat(k.row,k.col)},{edits:w,tiles:v}=Tl(x.cells,me(E,E),E,S.rowCount,S.colCount,(M,d,F)=>(k.row=T.range.startRow+(d-E.row),k.col=T.range.startCol+(F-E.col),Ql(M,x,k,Yl,$))),a=Ir(T.sourceAdapter),p=[];if(Lt([T.range],M=>{p.push(om(M.row,M.col,a))}),T.sourceAdapter===S){if(!m([...p,...w],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const M=P.commitPaste(w,{sameSheet:!1,conditionalFormats:ei(x.conditionalFormats,v)});if(M===null)return"rejected";try{T.sourceAdapter.applyEdits(p,{transaction:M,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){P.onEditRejected?.(d,{source:"paste"})}}return P.setSelection({ranges:[me(E,{row:E.row+b.rows-1,col:E.col+b.cols-1})],anchor:E,active:E}),"applied"},[m]),j=i.useCallback((T,A,P)=>{const S=t.current,R=S.adapter,E=V=>(S.onClipboardUnavailable?.(V),"rejected"),f=Ai(T,A);if(f==="none")return A==="menu"?E("empty"):"empty";const g=S.getSelection(),b=g.ranges[g.ranges.length-1],$=P.transpose===!0,x=(V,G)=>{const Z=Xh($?G:V,$?V:G,b);return Z>S.maxOperationCells?(S.onOperationRejected?.("paste",Z,"limit"),!0):!1};let k,w=null;if(f==="aqsp"){const V=Pu(T,A);if(V===null)return E("unreadable");const G=n.current;if(G!==null&&V.clipId===G.clipId&&(w=G),w!==null&&w.kind==="cut"&&Gh(P))return _(w,b);if(x(V.rows,V.cols))return"rejected";if(w!==null){if(w.kind==="cut"&&(w.range.endRow>=w.sourceAdapter.rowCount||w.range.endCol>=w.sourceAdapter.colCount))return S.onOperationRejected?.("paste",w.payload.rows*w.payload.cols,"bounds"),"rejected";k=ni(w)}else{const Z=qu(T,A);if(Z===null)return E("unreadable");if(x(Z.rows,Z.cols))return"rejected";k=rm(Z)}}else if(f==="tsv"){const V=T.getData("text/plain"),G=Tp(V);if(x(G.rows,G.cols))return"rejected";k=nm(Oc(V))}else{const V=T.getData("text/html"),G=ad(V);if(G.cols===0&&G.rows>S.maxOperationCells)return S.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(x(G.rows,G.cols))return"rejected";const Z=Cc(V,f,S.formats===void 0?{}:{currency:S.formats.currency,locale:S.formats.locale},S.maxOperationCells);if(Z.outcome==="none")return E("unreadable");if(Z.outcome==="limit")return S.onOperationRejected?.("paste",Z.cells,"limit"),"rejected";if(x(Z.payload.rows,Z.payload.cols))return"rejected";k=Z.payload}const v=Ir(R),a=Zl($?Bh(k):k,v),p=Jc[P.mode];if(Zh(p)){const V=Uo({rows:a.rows,cols:a.cols},b,g.active,R.rowCount,R.colCount);if(V!==null&&Yn(R,V))return S.rejectReadOnly({kind:"operation",op:"paste",cellCount:pt([V])}),"rejected"}const M={row:0,col:0,readText:()=>An(R,M.row,M.col).text,readFormat:()=>R.getCellFormat===void 0?void 0:R.getCellFormat(M.row,M.col)},{edits:d,tiles:F}=Tl(a.cells,b,g.active,R.rowCount,R.colCount,(V,G,Z)=>(M.row=G,M.col=Z,Ql(V,a,M,P,v))),O=sm(F,a.rows,a.cols,R.rowCount,R.colCount);if(O===null)return"empty";if(p.cf&&a.conditionalFormats.length>0){let V=0;for(const Z of a.conditionalFormats)V+=Z.ranges.length;const G=F.length*V;if(G>S.maxOperationCells)return S.onOperationRejected?.("paste",G,"limit"),"rejected"}const D=p.cf?ei(a.conditionalFormats,F):[];if(d.length===0&&D.length===0)return y(a,O,p),"empty";r.current=w===null?"foreign":"own";let N=!1;try{N=m(d,{sameSheet:w!==null&&w.sourceAdapter===R,conditionalFormats:D})}finally{r.current="none"}if(!N)return"rejected";y(a,O,p);const W={row:O.startRow,col:O.startCol};return S.setSelection({ranges:[O],anchor:W,active:W}),"applied"},[_,m,y]),L=i.useCallback(async T=>{const A=$=>(t.current.onClipboardUnavailable?.($),"rejected"),P=navigator;if(P.clipboard===void 0)return A("insecure-origin");let S;try{S=await P.clipboard.read({unsanitized:["text/html"]})}catch{return A("permission-denied")}if(S.length===0)return A("empty");const R=S[0],E=Array.from(R.types),f=new Map;try{for(const $ of Uh)E.includes($)&&f.set($,await(await R.getType($)).text())}catch{return A("unreadable")}const g={types:E,getData:$=>{const x=f.get($);if(x===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${$} was not materialised for the menu path`);return x}},b=t.current;return!b.enabled||b.isDragging()||b.isEditing()?"rejected":j(g,"menu",T)},[j]),I=i.useCallback(async T=>{const A=await L(T);return t.current.onPasteResolved?.(A,"menu"),A},[L]),{enabled:Y,sinkRef:B}=e;return i.useEffect(()=>{const T=B.current;if(!Y||T===null)return;const A=E=>t.current.isDragging()?(E.preventDefault(),!0):!1,P=E=>{const f=t.current;if(A(E)||f.isEditing())return;const g=h(E,"copy");g!==null&&c("copy",g.range,g.payload)},S=E=>{const f=t.current;if(A(E)||f.isEditing())return;const g=h(E,"cut");g!==null&&c("cut",g.range,g.payload)},R=E=>{const f=t.current;if(A(E)||f.isEditing())return;E.preventDefault();let g=Yl;const b=f.pendingPasteOptionsRef;b!==void 0&&b.current!==null&&(g=b.current,b.current=null);const $=ti(E);if($===null)return;const x=j(Jh($),"event",g);f.onPasteResolved?.(x,"event")};return T.addEventListener("copy",P),T.addEventListener("cut",S),T.addEventListener("paste",R),()=>{T.removeEventListener("copy",P),T.removeEventListener("cut",S),T.removeEventListener("paste",R)}},[Y,B,h,c,j]),i.useMemo(()=>({getClip:()=>{const T=n.current;return T===null?null:{kind:T.kind,range:T.range,foreign:T.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:I}),[o,s,l,I])},ta=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)}`)},na=e=>{let t=e,n=!1;t.startsWith("-")?(n=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));const r=t.search(/[eE]/);let o=null;r>=0&&(o=Number(t.slice(r+1)),t=t.slice(0,r));const s=t.indexOf("."),l=s<0?t:t.slice(0,s),c=s<0?"":t.slice(s+1);return{negative:n,digits:l+c,point:l.length,exponent:o}},ri=(e,t,n)=>{let r,o;return n<=0?(r="0",o="0".repeat(-n)+t):n>=t.length?(r=t+"0".repeat(n-t.length),o=""):(r=t.slice(0,n),o=t.slice(n)),r=r.replace(/^0+(?=\d)/,""),o=o.replace(/0+$/,""),r==="0"&&o===""?"0":`${e?"-":""}${r}${o===""?"":`.${o}`}`},ra=(e,t)=>{let n;if(e.exponent===null)n=ri(e.negative,e.digits,e.point+t);else{const r=ri(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return Xe(n)===null?null:n},im=(e,t)=>{ta(t);const n=Xe(e);return n===null?null:ra(na(n),t)},cm=e=>{const t=Xe(e);if(t!==null){const r=na(t);return ra({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},oa=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)},am=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},sa=(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 am(r)?r:null},um=(e,t)=>{ta(t);const n=oa(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=sa(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},dm=e=>{const t=oa(e),n=sa(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},Bn=(e,t,n,r)=>{const o=pt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Or={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Tr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},oi={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:Or.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Or.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Or.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Or.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:Tr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Tr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Tr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Tr.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"}},fm={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},Qn=e=>e<10?`0${e}`:String(e),pm=e=>{const t=new Date(e);return`${t.getFullYear()}-${Qn(t.getMonth()+1)}-${Qn(t.getDate())}`},hm=e=>{const t=new Date(e);return`${Qn(t.getHours())}:${Qn(t.getMinutes())}:${Qn(t.getSeconds())}`},mm=(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),gm=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),wm=e=>e===void 0||e.borders===void 0?{}:e.borders,Cm={top:1,right:2,bottom:4,left:8},ym={style:"thin",color:ts},bm=(e,t)=>{if(e===void 0)return!1;const n=Ve(e);return n!==null&&n===Ve(t)},vm=(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}}},Rm=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const f=t.current;if(f.isEditing()){const g=f.getActive();return[me(g,g)]}return f.getSelection().ranges},[]),r=i.useCallback(()=>{const f=t.current,g=f.getActive();return f.adapter.getCellFormat===void 0?void 0:f.adapter.getCellFormat(g.row,g.col)},[]),o=i.useCallback(f=>{const g=t.current,b=n();if(!Bn("format",b,g.maxOperationCells,g.onOperationRejected))return!1;if(Cn(g.adapter,b))return g.rejectReadOnly({kind:"operation",op:"format",cellCount:pt(b)}),!1;const $=new Map,x=[],k=g.adapter.getCellFormat;for(const w of b)Lt([w],v=>{const a=k===void 0?void 0:k(v.row,v.col),{bucket:p,patch:M}=f(v,w,a);let d=$.get(p);d===void 0&&(d=new Map,$.set(p,d));let F;d.has(a)?F=d.get(a):(F=rs(a,M),d.set(a,F)),F!==a&&x.push({row:v.row,col:v.col,format:F===void 0?null:F})});return x.length===0?!0:g.commitEdits(x,{source:"format"})===null?!1:(g.isEditing()&&g.refreshEditPaint(),!0)},[n]),s=i.useCallback(f=>o(()=>({bucket:0,patch:f})),[o]),l=i.useCallback((f,g)=>{const b=t.current;b.formatCommandAnnouncement!==void 0&&b.announce(b.formatCommandAnnouncement({command:f,state:g}))},[]),c=i.useCallback((f,g=ym)=>{if(f==="clear")return s({borders:null});if(f==="all")return s({borders:{top:g,right:g,bottom:g,left:g}});const b=f==="outer"?15:Cm[f];return o(($,x,k)=>{const w=mm($,x)&b;return{bucket:w,patch:{borders:{...wm(k),...gm(w,g)}}}})},[s,o]),u=i.useCallback((f,g,b)=>{const $=kc(t.current.adapter,f.row,f.col);for(const x of g)b.push(Sc($,f,x))},[]),h=i.useCallback(f=>{const g=t.current,b=g.getSelection();if(!Bn("fill",b.ranges,g.maxOperationCells,g.onOperationRejected))return!1;const $=[];if(f==="selection"){const k=b.active,w=[];Lt(b.ranges,v=>{(v.row!==k.row||v.col!==k.col)&&w.push(v)}),$.push({source:k,targets:w})}else for(const k of b.ranges)if(f==="down"){const w=k.startRow===k.endRow;if(w&&k.startRow===0)continue;const v=w?k.startRow-1:k.startRow;for(let a=k.startCol;a<=k.endCol;a+=1){const p=[];for(let M=w?k.startRow:k.startRow+1;M<=k.endRow;M+=1)p.push({row:M,col:a});$.push({source:{row:v,col:a},targets:p})}}else{const w=k.startCol===k.endCol;if(w&&k.startCol===0)continue;const v=w?k.startCol-1:k.startCol;for(let a=k.startRow;a<=k.endRow;a+=1){const p=[];for(let M=w?k.startCol:k.startCol+1;M<=k.endCol;M+=1)p.push({row:a,col:M});$.push({source:{row:a,col:v},targets:p})}}for(const k of $)for(const w of k.targets)if(je(g.adapter,w.row,w.col)){let v=0;for(const a of $)v+=a.targets.length;return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:v}),!1}const x=[];for(const k of $)u(k.source,k.targets,x);return x.length===0?!0:g.commitEdits(x,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const f=t.current,g=f.getSessionText();if(g===null)return!1;const b=f.getSelection();if(!Bn("fill",b.ranges,f.maxOperationCells,f.onOperationRejected))return!1;if(Cn(f.adapter,b.ranges))return f.rejectReadOnly({kind:"operation",op:"fill",cellCount:pt(b.ranges)}),!1;const $=[];let x=!1;return Lt(b.ranges,k=>{if(!x){if(!f.validateCommit(k,g).ok){x=!0;return}$.push({row:k.row,col:k.col,text:g})}}),x||f.commitEdits($,{source:"fill"})===null?!1:(f.cancelEdit(),!0)},[]),y=i.useCallback(f=>{const g=t.current,b=g.getSelection();if(!Bn("calc",b.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(Cn(g.adapter,b.ranges))return g.rejectReadOnly({kind:"operation",op:"calc",cellCount:pt(b.ranges)}),!1;const $=[],x=g.adapter;return Lt(b.ranges,k=>{const w=x.getCellFormula===void 0?void 0:x.getCellFormula(k.row,k.col),v=w===void 0?f.text(x.getCellText(k.row,k.col)):f.formula(w);v!==null&&$.push({row:k.row,col:k.col,text:v})}),$.length===0?!0:g.commitEdits($,{source:"calc"})!==null},[]),_=i.useCallback((f,g)=>{const b=t.current,$=f==="row"?b.rowAxis:b.colAxis,x=b.getSelection(),k=f==="row"?Math.floor(b.maxOperationCells/Qo):b.maxOperationCells;let w=0;for(const d of x.ranges)w+=f==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(w>k)return b.onOperationRejected?.("resize",w,"limit"),!1;const v=new Set,a=[],p=g?0:f==="row"?b.defaultRowHeight:b.defaultColumnWidth;for(const d of x.ranges){const F=f==="row"?d.startRow:d.startCol,O=f==="row"?d.endRow:d.endCol;for(let D=F;D<=O;D+=1){if(v.has(D))continue;v.add(D),$.sizeOf(D)===0!==g&&a.push({index:D,size:p})}}const M=es($,a,null,{maxOperationCells:b.maxOperationCells,rowHiddenLimit:Jo,axisKind:f});return M.ok?(M.entries.length>0&&b.resizeTracks(f,M.entries),!0):(b.onOperationRejected?.("resize",M.count,M.reason),!1)},[]),j=i.useCallback(()=>{const f=t.current;if(f.adapter.getCellHyperlink===void 0)return;const g=f.getActive();return On(f.adapter.getCellHyperlink(g.row,g.col))},[]),L=i.useCallback(f=>{const g=t.current,b=g.adapter,$=oi[f],x=b.getCellFormat!==void 0,k=w=>g.popovers===void 0?!0:g.popovers[w]!==!1;switch($.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return x;case"value":return x&&($.value!=="currency"||g.formats!==void 0);case"popover":switch($.popover){case"link":return b.getCellHyperlink!==void 0&&k("link");case"note":return b.getCellNote!==void 0&&k("note");case"comment":return b.getCellComments!==void 0&&k("comment");default:return b.getCellValidation!==void 0&&k("list")}case"openHyperlink":return b.getCellHyperlink!==void 0&&(g.onHyperlinkOpen!==void 0?j()!==void 0:k("link"));case"paste":return $.options.mode==="formats"?x:$.options.mode==="formulas"?b.getCellFormula!==void 0:!0;default:return!0}},[j]),I=i.useCallback(f=>{const g=t.current,b=f.kind==="popover"?f.popover:f.kind==="openHyperlink"&&g.onHyperlinkOpen===void 0?"link":void 0;if(b===void 0)return!0;const $=g.getActive();if(!je(g.adapter,$.row,$.col))return!0;if(b==="list")return g.rejectReadOnly({kind:"edit",cell:$,editSession:"none"}),!1;let x;if(b==="link")x=j()!==void 0;else if(b==="note"){const k=g.adapter.getCellNote===void 0?void 0:g.adapter.getCellNote($.row,$.col);x=k!==void 0&&k!==""}else{const k=g.adapter.getCellComments===void 0?void 0:g.adapter.getCellComments($.row,$.col);x=k!==void 0&&k.length>0}return x?!0:(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[j]),Y=i.useCallback(f=>{const g=t.current;if(!L(f))return!1;const b=oi[f];if(!I(b))return!1;const $=g.isEditing();if($&&!ms.has(f)&&!g.requestCommit())return!1;switch(b.kind){case"toggle":{const x=r(),k=x!==void 0&&x[b.key]===!0;return s({[b.key]:k?null:!0})?(l(f,!k),!0):!1}case"patch":return s(b.patch)?(l(f,null),!0):!1;case"clear":return s(fm)?(l(f,null),!0):!1;case"value":return s({value:vm(b.value,g.formats)})?(l(f,null),!0):!1;case"borders":return c(b.preset)?(l(f,null),!0):!1;case"color":{const x=b.key==="background"?g.colors.fill:g.colors.font,k=b.preset!==null?b.preset:b.custom!==null&&b.custom<x.length?x[b.custom]:void 0;if(k===void 0)return!1;const w=r(),v=bm(w===void 0?void 0:w[b.key],k);return s({[b.key]:v?null:k})?(l(f,!v),!0):!1}case"calc":return y({text:x=>im(x,b.exponent),formula:x=>um(x,b.exponent)});case"sign":return y({text:cm,formula:dm});case"fill":return $&&b.direction==="selection"?m():h(b.direction);case"popover":return g.openPopover(b.popover),!0;case"openHyperlink":{if(g.onHyperlinkOpen!==void 0){const x=j();return x===void 0?!1:(g.onHyperlinkOpen(x,g.getActive()),!0)}return g.openPopover("link"),!0}case"pasteSpecial":return g.onPasteSpecialRequest!==void 0?(g.onPasteSpecialRequest({kind:"keyboard",cellRect:g.keyboardCellRect()}),!0):(g.paste({mode:"formats"}),!0);case"paste":return g.paste(b.options),!0;case"insertNow":{const x=b.unit==="date"?pm(g.now()):hm(g.now());if($)return g.insertAtCaret(x),!0;const k=g.getActive();return je(g.adapter,k.row,k.col)?(g.rejectReadOnly({kind:"edit",cell:k,editSession:"none"}),!1):g.validateCommit(k,x).ok?g.commitEdits([{row:k.row,col:k.col,text:x}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return _(b.axis,b.hide);default:{const x=g.getHighlight();switch(b.target){case"row":return g.setHighlight({...x,row:!x.row}),!0;case"column":return g.setHighlight({...x,column:!x.column}),!0;case"both":{const k=x.row&&x.column;return g.setHighlight({...x,row:!k,column:!k}),!0}default:return g.setHighlight({...x,intersection:!x.intersection}),!0}}}},[L,I,j,r,s,l,c,y,h,m,_]),B=i.useCallback(()=>{const f=t.current;return!(f.isEditing()&&!f.requestCommit())},[]),T=i.useCallback(f=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const b=f===null?null:jt(f);if(f!==null&&b===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(f)}`);if(!B())return!1;const $=g.getActive();return je(g.adapter,$.row,$.col)?(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):g.commitEdits([{row:$.row,col:$.col,hyperlink:b}],{source:"annotate"})!==null},[B]),A=i.useCallback(f=>{const g=t.current;if(g.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!B())return!1;const b=g.getActive();return je(g.adapter,b.row,b.col)?(g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):g.commitEdits([{row:b.row,col:b.col,note:f}],{source:"annotate"})!==null},[B]),P=i.useCallback(f=>{const g=t.current,b=g.adapter.getCellComments;if(b===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!B())return!1;const $=g.getActive();if(je(g.adapter,$.row,$.col))return g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const x=b($.row,$.col),k=x===void 0?[f]:[...x,f];return g.commitEdits([{row:$.row,col:$.col,comments:k}],{source:"annotate"})!==null},[B]),S=i.useCallback(f=>{const g=t.current;if(g.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!B())return!1;const b=g.getSelection().ranges;if(!Bn("annotate",b,g.maxOperationCells,g.onOperationRejected))return!1;if(Cn(g.adapter,b))return g.rejectReadOnly({kind:"operation",op:"annotate",cellCount:pt(b)}),!1;const $=[];return Lt(b,x=>{$.push({row:x.row,col:x.col,validation:f})}),g.commitEdits($,{source:"annotate"})!==null},[B]),R=i.useCallback(f=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(f)},[s]),E=i.useCallback((f,g)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(f,g)},[c]);return i.useMemo(()=>({executeCommand:Y,applyFormat:R,setBorders:E,setHyperlink:T,setNote:A,addComment:P,setValidation:S,isCommandAvailable:L}),[Y,R,E,T,A,P,S,L])},Dr="data-aqsp-pointing",km=(e,t)=>{const n=tc(e,t);return n!==null&&"insertAt"in n},Sm=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Em=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),u=i.useRef(null),h=i.useRef(vt),m=i.useCallback(()=>{const w=t.current,v=w.sinkRef.current;if(w.adapter.getCellFormula===void 0||n.current===null||!c.current||v===null)return null;const a=tc(v.value,v.selectionStart);return a===null?null:{sink:v,target:a}},[]),y=i.useCallback(()=>{const w=t.current.sinkRef.current;if(w===null)return;const v=m()!==null;v!==w.hasAttribute(Dr)&&(v?w.setAttribute(Dr,""):w.removeAttribute(Dr))},[m]),_=i.useCallback((w,v)=>{const a=t.current;if(a.resolveEditPaint===void 0)return;const p=a.resolveEditPaint(v),M=p===null?vt:p;M!==vt&&Object.assign(w.style,M.style),h.current=M,a.editPaintRef!==void 0&&(a.editPaintRef.current=M)},[]),j=i.useCallback(w=>{Sm(w,Object.keys(h.current.style)),h.current=vt;const v=t.current.editPaintRef;v!==void 0&&(v.current=vt)},[]),L=i.useCallback(w=>{const v=t.current,a=n.current;if(a===null)return!0;const p=()=>{n.current=null,u.current=null;const M=v.sinkRef.current;M!==null&&(M.style.removeProperty("text-align"),j(M),M.removeAttribute(Dr)),o(!1)};if(w.commit){const M=v.sinkRef.current,d=M===null?"":M.value,F=An(v.adapter,a.cell.row,a.cell.col).text.replace(/\r\n?/g,`
|
|
20
|
+
`),O=d===F;let D;if(O)D=!0;else if(je(v.adapter,a.cell.row,a.cell.col))v.rejectReadOnly({kind:"edit",cell:a.cell,editSession:w.onReject==="keep"?"kept":"discarded"}),D=!1;else{const N={source:"edit",editSession:w.onReject==="keep"?"kept":"discarded"};D=(v.validateCommit===void 0||v.validateCommit(a.cell,d).ok)&&v.commitEdits([{row:a.cell.row,col:a.cell.col,text:d}],N)!==null}if(!D)return w.onReject==="discard"&&(p(),v.rearmSink()),!1}return p(),w.rearm&&v.rearmSink(),!0},[j]),I=i.useCallback((w,v)=>{const a=t.current;if(a.isDragging()||n.current!==null)return;const p=a.sinkRef.current;if(p===null)return;const M=a.getActive();if(je(a.adapter,M.row,M.col)){a.rejectReadOnly({kind:"edit",cell:M,editSession:"none"});return}if(a.discardClip(),a.ensureCellVisible(M),w==="edit"){const{text:F,isFormula:O}=An(a.adapter,M.row,M.col);p.value=F;const D=v===void 0||O?F.length:Math.min(v,F.length);p.setSelectionRange(D,D)}else p.value="";const d=a.resolveEditAlign(M);d!==null&&(p.style.textAlign=d),_(p,M),c.current=!1,u.current=null,n.current={cell:M,mode:w},o(!0)},[_]),Y=i.useCallback(()=>{L({rearm:!0,commit:!1})},[L]),B=i.useCallback(()=>{const w=t.current;if(n.current===null)return!0;const v=w.sinkRef.current;if(s.current&&v!==null){l.current=!0;try{v.blur()}finally{l.current=!1}return L({rearm:!1,commit:!0,onReject:"keep"})?(w.focusSink(),w.rearmSink(),!0):(w.focusSink(),!1)}return L({rearm:!0,commit:!0,onReject:"keep"})},[L]),T=i.useCallback(()=>m()!==null,[m]),A=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,y(),!0),[y]),P=i.useCallback(()=>{const w=m(),v=n.current;if(w===null||v===null)return null;if("insertAt"in w.target)return u.current=v.cell,{origin:v.cell,cursor:v.cell,axis:"cells"};const a=ec(w.sink.value,w.sink.selectionStart);if(a===null)return null;const p=a.token,M=u.current;switch(p.kind){case"cell":{const d={row:p.row,col:p.col};return u.current=d,{origin:d,cursor:d,axis:"cells"}}case"range":{const d=M!==null&&(M.row===p.start.row||M.row===p.end.row)&&(M.col===p.start.col||M.col===p.end.col)?{row:M.row,col:M.col}:{row:p.start.row,col:p.start.col};return u.current=d,{origin:d,cursor:{row:d.row===p.start.row?p.end.row:p.start.row,col:d.col===p.start.col?p.end.col:p.start.col},axis:"cells"}}case"column":{const d=M!==null&&(M.col===p.start.col||M.col===p.end.col)?M.col:p.start.col,F={row:v.cell.row,col:d};return u.current=F,{origin:F,cursor:{row:v.cell.row,col:d===p.start.col?p.end.col:p.start.col},axis:"columns"}}case"row":{const d=M!==null&&(M.row===p.start.row||M.row===p.end.row)?M.row:p.start.row,F={row:d,col:v.cell.col};return u.current=F,{origin:F,cursor:{row:d===p.start.row?p.end.row:p.start.row,col:v.cell.col},axis:"rows"}}}},[m]),S=i.useCallback((w,v)=>{const a=m();if(a===null)return;const p=Bd(w,v),{sink:M}=a,[d,F]="replace"in a.target?a.target.replace:[a.target.insertAt,a.target.insertAt],O=M.value;M.value=`${O.slice(0,d)}${p}${O.slice(F)}`;const D=d+p.length;M.setSelectionRange(D,D),"row"in w&&(u.current={row:w.row,col:w.col}),y()},[m,y]),R=i.useCallback(()=>{const w=t.current.sinkRef.current;return w===null?null:{value:w.value,selectionStart:w.selectionStart,selectionEnd:w.selectionEnd}},[]),E=i.useCallback(w=>{const v=t.current.sinkRef.current;v!==null&&(v.value=w.value,v.setSelectionRange(w.selectionStart,w.selectionEnd),u.current=null,y())},[y]),f=i.useCallback(()=>{const w=t.current,v=w.sinkRef.current;if(w.adapter.getCellFormula===void 0||n.current===null||v===null)return!1;const a=Qd(v.value,v.selectionStart);return a===null?!1:(v.value=a.text,v.setSelectionRange(a.caret,a.caret),y(),!0)},[y]),g=i.useCallback(w=>{const v=t.current.sinkRef.current;if(n.current===null||v===null)return;const a=v.selectionStart,p=v.selectionEnd;v.value=`${v.value.slice(0,a)}${w}${v.value.slice(p)}`;const M=a+w.length;v.setSelectionRange(M,M),u.current=null,y()},[y]),b=i.useCallback(()=>{const w=t.current.sinkRef.current;return n.current===null||w===null?null:w.value},[]),$=i.useCallback(()=>{const w=t.current,v=n.current,a=w.sinkRef.current;v===null||a===null||(j(a),_(a,v.cell),w.repaintOverlay?.())},[j,_]),{enabled:x,sinkRef:k}=e;return i.useEffect(()=>{const w=k.current;if(!x||w===null)return;const v=()=>{s.current=!0},a=()=>{s.current=!1},p=F=>{const O=t.current;if(l.current||n.current===null)return;const D=O.rootRef.current,N=F.relatedTarget;D!==null&&N instanceof Node&&D.contains(N)||L({rearm:!1,commit:!0,onReject:"discard"})},M=()=>{const F=t.current;u.current=null,F.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&km(w.value,w.selectionStart)&&(c.current=!0),y()},d=()=>{n.current!==null&&y()};return w.addEventListener("compositionstart",v),w.addEventListener("compositionend",a),w.addEventListener("focusout",p),w.addEventListener("input",M),document.addEventListener("selectionchange",d),()=>{w.removeEventListener("compositionstart",v),w.removeEventListener("compositionend",a),w.removeEventListener("focusout",p),w.removeEventListener("input",M),document.removeEventListener("selectionchange",d)}},[x,k,L,y]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:B,cancelEdit:Y,startEdit:I,getPointing:T,togglePointingArm:A,getReferenceCursor:P,insertReference:S,captureSink:R,restoreSink:E,cycleAnchorAtCaret:f,insertAtCaret:g,getSessionText:b,refreshPaint:$,editing:r}),[B,Y,I,T,A,P,S,R,E,f,g,b,$,r])},xm=(e,t,n)=>{const r=new rr.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}},Am=(e,t,n)=>{const{tree:r,initialHidden:o}=xm(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:y}=r.prefixSum(h);return m-y},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),y=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(y+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const y=Math.round(m);r.get(h)===0!=(y===0)&&(s+=y===0?1:-1),r.update(h,y)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},_t=(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)},Rn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:_t(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=_t(e,o,1);return r},si=(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=Am(e,t,r)),o.current.model},kn=256,To=256,Om=2**32,Tm=4096,la=Object.freeze([]),ia=["background","color","bold","italic","underline","strikethrough"],ca=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},It=(e,t,n)=>(e.size>=Tm&&e.clear(),e.set(t,n),n),aa=e=>(ca(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),ua=(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},Dm=(e,t,n)=>{const r=Math.floor(t/kn),o=Math.floor(n/To),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*kn,u=o*To,h=[];for(const m of e.rules)ua(m.ranges,c,c+kn-1,u,u+To-1)&&h.push(m);return It(e.buckets,s,h.length===0?la:h)},Mm=(e,t,n)=>{const r=Math.floor(t/kn),o=r*Om+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Dm(e,t,n),c=r*kn,u=[];for(const h of l)ua(h.ranges,c,c+kn-1,n,n)&&u.push(h);return It(e.columns,o,u.length===0?la:u)},$m=(e,t)=>{for(const n of e)if(en(n,t))return!0;return!1},gs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Mr=(e,t)=>e<t?-1:e>t?1:0,li=(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}},ii=new WeakMap,Zo=e=>e===null?null:Number(e),Fm=e=>{const t=ii.get(e);if(t!==void 0)return t;const n=e.b,r={a:Zo(Xe(e.a)),b:n===void 0?null:Zo(Xe(n))};return ii.set(e,r),r},da=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:It(e.numbers,r,Zo(Xe(n())))},zm=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Fm(e),l=da(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return li(e.op,Mr(l,s.a),c===null?null:Mr(l,c));const u=n(),h=e.b;return li(e.op,Mr(u,e.a),h===void 0?null:Mr(u,h))},Nm=(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}},Do=e=>{const t=Ve(e);if(t===null)return null;const n=r=>Number.parseInt(t.slice(r,r+2),16);return[n(1),n(3),n(5),t.length===9?n(7):255]},$r=e=>e.toString(16).padStart(2,"0"),Mo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${$r(r(0))}${$r(r(1))}${$r(r(2))}`,s=r(3);return s===255?o:`${o}${$r(s)}`},$o=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Lm=(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=Do(t.color),u=Do(r.color);const h=n===void 0?void 0:Do(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const y=s;s=l,l=y;const _=c;c=u,u=_}if(n!==void 0&&h!==void 0){const y=n.value===void 0?(s+l)/2:n.value;if(s<y&&y<l)return e<=y?Mo(c,h,$o(e,s,y)):Mo(h,u,$o(e,y,l))}return Mo(c,u,$o(e,s,l))},Pm=(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 It(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return It(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return It(r.extrema,e.id,{min:c,max:u})},qm=(e,t,n,r,o,s)=>{const l=da(s,n,r);if(l===null)return null;const c=Pm(e,t,o,s);return c===null?null:Lm(l,t.min,t.mid,t.max,c)},_m=(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:It(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Im=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return zm(s,t,n,o)?e.style:null;case"text":return Nm(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=qm(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return _m(e,s,t,r,o)?e.style:null;default:return null}},ci=(e,t)=>rs(e,t),jm=(e,t,n)=>{e[t]=n},Hm=(e,t)=>{let n=e;for(const r of ia)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),jm(n,r,t[r]));return n},Bm=e=>{let t="";for(const n of ia){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},ai=new WeakMap,Vm=Object.freeze({}),Wm=e=>{const t=e===void 0?Vm:e,n=ai.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return ai.set(t,r),r},Km=(e,t,n)=>{const r=Wm(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=ci(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Bm(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=ci(e,t);return l!==void 0&&It(r.byKey,o,l),l},ws=(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=Mm(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const y of c){if(!$m(y.ranges,u))continue;const _=Im(y,u,s,e,n);if(_!==null){if(_!==y.style&&(m=!1),h===null)h=_;else{const j=Hm(h,_);j!==h&&(m=!1,h=j)}if(y.stopIfTrue===!0)break}}return h===null?l:Km(l,h,m)},ui=new WeakMap,Ym=e=>{ca(e,"widthRelevantRules");const t=ui.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 ui.set(e,r),r},Um=({row:e,col:t,text:n,renderCell:r,__onCellRender:o})=>{const s=i.useRef(!1);return i.useEffect(()=>{const l=s.current?"update":"mount";s.current=!0,o?.(`cell-${e}-${t}`,l,0,0,0,0)}),r?r({row:e,col:t,text:n}):n},Xm=i.memo(Um),Gm=Object.freeze({left:Object.freeze({justifyContent:Xn("left")}),center:Object.freeze({justifyContent:Xn("center")}),right:Object.freeze({justifyContent:Xn("right")})}),Zm=4096,di=new WeakMap,Fr=new Map,Jm=(e,t)=>{if(e===null)return Gm[t];let n=di.get(e);n===void 0&&(n={},di.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:Xn(t)},s=JSON.stringify(o);let l=Fr.get(s);return l===void 0&&(Fr.size>=Zm&&Fr.clear(),l=Object.freeze(o),Fr.set(s,l)),n[t]=l,l},Qm=gs(),eg=(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},tg=(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=_r(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=ws(e,r===null?null:r.indexRef.current,r===null?Qm:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const y=yc(m,l),_=_t(n,s,1),j=_t(t,o,1),L=bd(m,_===null?void 0:e.getCellFormat(o,_),j===null?void 0:e.getCellFormat(j,s),n.offsetOf(s)===0,t.offsetOf(o)===0);L!==null&&Object.assign(c,L.attrs),c["data-aqsp-align"]=y,u=Jm(L,y)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&On(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&yh(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},ng=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:y,renderCell:_,onScroll:j,onRangeChange:L,focusSink:I,isEditing:Y,requestCommit:B,testId:T,__onCellRender:A,cfIndexRef:P,cfMemoRef:S,isPointing:R,tapScrollCircleOptions:E})=>{const f=i.useRef(null),g=s??f;if(P===void 0!=(S===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const b=i.useMemo(()=>P===void 0||S===void 0?null:{indexRef:P,memoRef:S},[P,S]),$=i.useCallback(()=>r.get().editVersion,[r]),x=i.useCallback(V=>r.subscribeCoalesced(V),[r]),w=i.useSyncExternalStore(x,$,$)+(l??0),v=i.useCallback(V=>t.sizeOf(V),[t]),a=i.useCallback(V=>n.sizeOf(V),[n]),p=i.useCallback((V,G)=>e.getCellText(V,G),[e]),M=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),d=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),F=i.useMemo(()=>({width:lt,tapScrollCircleOptions:E}),[E]),O=i.useRef({row:-1,col:-1,value:void 0}),D=i.useCallback((V,G)=>{const Z={role:"gridcell","aria-rowindex":V+1,"aria-colindex":G+1,"data-aqsp-cell":"","data-row":V,"data-col":G,className:"aqsp-cell",...je(e,V,G)?{"aria-readonly":"true","data-aqsp-readonly":""}:{}},ee=tg(e,t,n,b,V,G),ie=O.current;return ie.row=V,ie.col=G,ie.value=ee===null?void 0:ee.value,ee===null?Z:ee.style===null?{...Z,...ee.attrs}:{...Z,...ee.attrs,style:ee.style}},[e,t,n,b]),N=i.useCallback(V=>({role:"row","aria-rowindex":V+1,"data-aqsp-row":V,"data-aqsp-cells":"",className:"aqsp-row"}),[]),W=i.useCallback((V,G,Z)=>{let ee=V;return _===void 0&&e.getCellFormat!==void 0&&(ee=En(V,eg(O.current,G,Z))),K.jsx(Xm,{row:G,col:Z,text:ee,renderCell:_,__onCellRender:A})},[w,_,A,e]);return K.jsx("div",{ref:g,className:"aqsp-body","data-aqsp-body":"","data-testid":T?`${T}-body`:void 0,onPointerDownCapture:V=>{if(!(V.target instanceof Element&&V.target.closest("[data-aqsp-cells]")!==null)&&V.pointerType==="mouse"){if(V.button!==0){V.preventDefault();return}if(V.preventDefault(),R?.()===!0){V.stopPropagation(),I();return}if(Y()&&!B()){V.stopPropagation(),I();return}I()}},children:K.jsx(rr.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:y,getRowHeight:v,getColWidth:a,getCell:p,getCellProps:D,getRowProps:N,contentProps:M,behaviorOptions:d,scrollBarOptions:F,callbackThrottleMs:0,onScroll:j,onRangeChange:L,testId:T,children:W})})},rg=i.memo(ng),yn=6,Ue=3,Kr=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=t[0];o>0&&e.sizeOf(o-1)===0&&r.push({kind:"unhide",index:o-1,start:e.offsetOf(o),length:Ue});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=_t(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-yn,length:Ue}),r.push({kind:"unhide",index:s+1,start:c-Ue,length:Ue})):l>=2*yn?n.push({kind:"resize",index:s,start:c-yn,length:yn}):n.push({kind:"resize",index:s,start:c-Ue,length:Ue})}return[...n,...r]},fa=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:Ue}),n.push({kind:"resize",index:c,start:h+Ue,length:Ue})):u>=2*yn?n.push({kind:"resize",index:c,start:h,length:yn}):n.push({kind:"resize",index:c,start:h,length:Ue})}const l=t[t.length-1];return l<e.count-1&&e.sizeOf(l+1)===0&&r.push({kind:"unhide",index:l+1,start:s-Ue,length:Ue}),[...n.reverse(),...r]},og=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:y,dividerTrailingRef:_})=>{const j=rr.useWheelBridge(o),L=i.useCallback(d=>(s.current=d,j(d)),[s,j]),I=i.useCallback(()=>{const{colStart:d,colEnd:F,colVersion:O}=e.get();return`${d}:${F}:${O}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,I,I);const{colStart:B,colEnd:T}=e.get(),A=t.count===0?0:t.offsetOf(Math.min(B,t.count-1));i.useLayoutEffect(()=>{c.current=A,u()},[A,c,u]);const P=d=>h.some(F=>d>=F.startCol&&d<=F.endCol),S=Math.min(Math.max(0,n),t.count),R=Ic(t,S),E=S>0?Rn(t,0,S-1):[],f=Math.min(Math.max(0,r),t.count-S),g=Hc(t,f),b=t.totalSize()-g,$=f>0?Rn(t,t.count-f,t.count-1):[],x=Rn(t,Math.max(B,S),Math.min(T,Math.max(0,t.count-1)-f)),k=[];for(const d of x)k.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)-A,width:t.sizeOf(d)},children:Jn(d)},d));const w=m?Kr(t,x):null,v=w===null?null:w.filter(d=>!(d.kind==="unhide"&&d.index<S&&R>0||d.kind==="unhide"&&d.index>=t.count-f&&g>0)),a=m&&S>0?Kr(t,E):null,p=m&&f>0?fa(t,$):null,M=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,v?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-A,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-A,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:L,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:S===0&&f===0?M:K.jsxs(K.Fragment,{children:[E.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":P(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Jn(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:f>0?`calc(${lt}px + min(${g}px, max(0px, 100% - ${lt+R}px)))`:void 0},children:[M,S>0?K.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,f>0?K.jsx("div",{ref:_,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),f>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${R}px, calc(100% - ${g+lt}px))`,right:lt},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[$.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)-b,width:t.sizeOf(d)},children:Jn(d)},d)),p?.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]})})},sg=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:y,dividerTrailingRef:_})=>{const j=rr.useWheelBridge(n),L=i.useCallback(d=>(r.current=d,j(d)),[r,j]),I=d=>o.some(F=>d>=F.startRow&&d<=F.endRow),Y=i.useCallback(()=>{const{rowStart:d,rowEnd:F,rowGeomVersion:O}=e.get();return`${d}:${F}:${O}`},[e]),B=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(B,Y,Y);const{rowStart:T,rowEnd:A}=e.get(),P=t.count===0?0:t.offsetOf(Math.min(T,t.count-1));i.useLayoutEffect(()=>{l.current=P,c()},[P,l,c]);const S=Math.min(Math.max(0,h),t.count),R=jc(t,S),E=S>0?Rn(t,0,S-1):[],f=Math.min(Math.max(0,m),t.count-S),g=Bc(t,f),b=t.totalSize()-g,$=f>0?Rn(t,t.count-f,t.count-1):[],x=Rn(t,Math.max(T,S),Math.min(A,Math.max(0,t.count-1)-f)),k=[];for(const d of x)k.push(K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d)-P,height:t.sizeOf(d)},children:d+1},d));const w=u?Kr(t,x):null,v=w===null?null:w.filter(d=>!(d.kind==="unhide"&&d.index<S&&R>0||d.kind==="unhide"&&d.index>=t.count-f&&g>0)),a=u&&S>0?Kr(t,E):null,p=u&&f>0?fa(t,$):null,M=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,v?.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:L,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:lt},children:S===0&&f===0?M:K.jsxs(K.Fragment,{children:[E.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:R,bottom:f>0?`calc(min(${g}px, max(0px, 100% - ${R}px)))`:void 0},children:[M,S>0?K.jsx("div",{ref:y,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,f>0?K.jsx("div",{ref:_,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),f>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${R}px, calc(100% - ${g}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[$.map(d=>K.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":I(d)?"":void 0,style:{top:t.offsetOf(d)-b,height:t.sizeOf(d)},children:d+1},d)),p?.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]})})},lg=9,ig=4,cg=(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},fi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,ag=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),y=i.useCallback(S=>s.current!==null?S.pointerId===s.current:S.pointerType==="mouse",[]),_=i.useCallback(()=>{const S=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),S.writeResizeGuide(null);const R=m.current;R!==null&&(window.removeEventListener("pointermove",R.move),window.removeEventListener("pointerup",R.up),m.current=null);const E=c.current;E!==null&&s.current!==null&&E.hasPointerCapture?.(s.current)&&E.releasePointerCapture(s.current),c.current=null,s.current=null,S.repaintOverlay()},[]),j=i.useCallback((S,R)=>{const E=t.current;return S==="col"?R.startRow===0&&R.endRow===E.rowAxis.count-1:R.startCol===0&&R.endCol===E.colAxis.count-1},[]),L=i.useCallback((S,R)=>{const E=t.current,f=E.getSelection().ranges.filter(k=>j(S,k));if(!f.some(k=>S==="col"?R>=k.startCol&&R<=k.endCol:R>=k.startRow&&R<=k.endRow))return[R];const b=f.reduce((k,w)=>k+(S==="col"?w.endCol-w.startCol+1:w.endRow-w.startRow+1),0),$=S==="row"?Math.floor(E.maxOperationCells/Qo):E.maxOperationCells;if(b>$)return E.onOperationRejected?.("resize",b,"limit"),null;const x=new Set;for(const k of f){const w=S==="col"?k.startCol:k.startRow,v=S==="col"?k.endCol:k.endRow;for(let a=w;a<=v;a+=1)x.add(a)}return[...x]},[j]),I=i.useCallback((S,R,E)=>{const f=t.current,g=S==="col"?f.colAxis:f.rowAxis,b=es(g,R,E,{maxOperationCells:f.maxOperationCells,rowHiddenLimit:Jo,axisKind:S});if(!b.ok){f.onOperationRejected?.("resize",b.count,b.reason);return}f.resizeTracks(S,b.entries)},[]),Y=i.useCallback((S,R)=>{if(R===S.initialSize)return;const E=S.kind==="unhide"?[S.index]:L(S.axis,S.index);E!==null&&I(S.axis,E.map(f=>({index:f,size:R})),S.index)},[L,I]),B=i.useCallback((S,R)=>{const E=t.current,f=L("col",R);if(f===null)return;const g=E.handleRef.current,b=g===null?null:g.getFrozenSize(),$=b===null?0:b.rows,x=b===null?0:b.trailingRows,{rowStart:k,rowEnd:w}=E.viewStore.get(),v=Math.min(w,E.rowAxis.count-1),a=[],p=new Set,M=oe=>{!p.has(oe)&&E.rowAxis.sizeOf(oe)>0&&(p.add(oe),a.push(oe))};for(let oe=0;oe<$;oe+=1)M(oe);for(let oe=k;oe<=v;oe+=1)M(oe);for(let oe=E.rowAxis.count-x;oe<E.rowAxis.count;oe+=1)M(oe);if(a.length===0)return;const d=f.length*a.length,F=Math.floor(E.maxOperationCells/ig);if(d>F){E.onOperationRejected?.("resize",d,"limit");return}const O=document.createElement("canvas").getContext("2d");if(O===null)return;const D=getComputedStyle(S),N=`${D.fontStyle} ${D.fontWeight} ${D.fontSize} ${D.fontFamily}`,W=E.adapter.getConditionalFormats===void 0?null:Ym(E.adapter.getConditionalFormats()),V=gs(),G=new WeakMap,Z=new Map;for(const oe of f){const Te=W===null?null:aa(W.filter(qe=>qe.ranges.some(De=>oe>=De.startCol&&oe<=De.endCol)));for(const qe of a){const De=E.adapter.getCellText(qe,oe),_e=E.adapter.getCellFormat===void 0?void 0:ws(E.adapter,Te,V,qe,oe,()=>De),de=_e===void 0?N:cg(_e,G,D),fe=En(De,_e===void 0?void 0:_e.value),Ze=Z.get(de);Ze===void 0?Z.set(de,[{col:oe,text:fe}]):Ze.push({col:oe,text:fe})}}const ee=new Map;for(const[oe,Te]of Z){O.font=oe;for(const qe of Te){const De=O.measureText(qe.text).width,_e=ee.get(qe.col);(_e===void 0||De>_e)&&ee.set(qe.col,De)}}const ie=[];for(const oe of f){const Te=ee.get(oe);Te!==void 0&&Te>0&&ie.push({index:oe,size:Math.ceil(Te)+lg})}ie.length!==0&&I("col",ie,R)},[L,I]),{enabled:T,colBandRef:A,rowBandRef:P}=e;return i.useEffect(()=>{const S=A.current,R=P.current;if(!T||S===null||R===null)return;const E=F=>F==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",f=(F,O)=>{if(!(O instanceof Element))return null;const D=O.closest(E(F));if(D===null)return null;const N=D.hasAttribute("data-aqsp-unhide"),W=Number(D.getAttribute(N?"data-aqsp-unhide":F==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),V=D.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:N?"unhide":"resize",index:W,anchor:V}},g=F=>{if(!(n.current&&y(F)))return;const O=r.current;if(O===null)return;const D=(O.axis==="col"?F.clientX-O.startClientX:F.clientY-O.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(O.anchor==="trailing"?O.initialSize-D:O.initialSize+D)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const N=r.current;if(!n.current||N===null)return;const W=t.current,V=N.axis==="col"?W.colAxis:W.rowAxis;W.writeResizeGuide({axis:N.axis,position:fi(N,V,o.current),anchor:N.anchor})}))},b=()=>{const F=r.current,O=o.current;_(),F!==null&&Y(F,O)},$=F=>{g(F),n.current&&y(F)&&(l.current&1)!==0&&(F.buttons&1)===0&&b()},x=F=>{F.button!==0||!(n.current&&y(F))||b()},k=(F,O)=>D=>{const N=t.current;if(h.current=D.pointerType,D.pointerType!=="mouse")return;if(D.button!==0){D.preventDefault();return}const W=f(F,D.target);if(W===null)return;if(D.stopPropagation(),D.preventDefault(),N.isPointing()){N.focusSink();return}if(N.isEditing()&&!N.requestCommit()){N.focusSink();return}N.focusSink();const V=F==="col"?N.colAxis:N.rowAxis,G={axis:F,kind:W.kind,index:W.index,anchor:W.anchor,initialSize:V.sizeOf(W.index),startClientX:D.clientX,startClientY:D.clientY};r.current=G,o.current=G.initialSize,l.current=D.buttons,n.current=!0,N.repaintOverlay(),s.current=D.pointerId,c.current=O;try{O.setPointerCapture(D.pointerId)}catch{s.current=null}const Z=$,ee=x;m.current={move:Z,up:ee},window.addEventListener("pointermove",Z),window.addEventListener("pointerup",ee),N.writeResizeGuide({axis:F,position:fi(G,V,o.current),anchor:G.anchor})},w=(F,O)=>D=>{const N=t.current;if(h.current!=="mouse")return;const W=O.getRootNode(),V=W instanceof ShadowRoot?W:O.ownerDocument,G=D.target instanceof Element&&D.target.closest(E(F))!==null?D.target:typeof V.elementFromPoint=="function"?V.elementFromPoint(D.clientX,D.clientY):null,Z=f(F,G);if(Z!==null){if(D.stopPropagation(),N.isEditing()){N.focusSink();return}if(Z.kind==="unhide"){I(F,[{index:Z.index,size:F==="col"?N.defaultColumnWidth:N.defaultRowHeight}],null);return}if(N.autofitEnabled){if(F==="row"){const ee=L("row",Z.index);ee!==null&&I("row",ee.map(ie=>({index:ie,size:N.defaultRowHeight})),Z.index);return}B(O,Z.index)}}},v=F=>{!n.current||s.current===null||F.pointerId!==s.current||_()},a=k("col",S),p=k("row",R),M=w("col",S),d=w("row",R);return S.addEventListener("pointerdown",a,{capture:!0}),R.addEventListener("pointerdown",p,{capture:!0}),S.addEventListener("dblclick",M),R.addEventListener("dblclick",d),S.addEventListener("lostpointercapture",v),R.addEventListener("lostpointercapture",v),()=>{S.removeEventListener("pointerdown",a,{capture:!0}),R.removeEventListener("pointerdown",p,{capture:!0}),S.removeEventListener("dblclick",M),R.removeEventListener("dblclick",d),S.removeEventListener("lostpointercapture",v),R.removeEventListener("lostpointercapture",v),_()}},[T,A,P,y,_,Y,I,L,B]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&_()},cancelDrag:_}),[_])},Cs=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,ug=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Cs(n,t.ranges[r]))&&kt(e.anchor,t.anchor)&&kt(e.active,t.active),dg=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Cs(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},nr=(e,t,n)=>n.extend?Zt(e,t):n.append?{ranges:[...e.ranges,me(t,t)],anchor:t,active:t}:e.ranges.length===1&&kt(e.anchor,t)&&kt(e.active,t)&&Cs(e.ranges[0],me(t,t))?e:{ranges:[me(t,t)],anchor:t,active:t},fg=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),Zt=(e,t)=>{const n=dg(e,me(e.anchor,t));return n.ranges.some(r=>en(r,n.active))?n:{...n,active:fg(n.active,n.ranges[n.ranges.length-1])}},pa=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(me({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(me({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(me({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(me({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[me(n,n)],anchor:n,active:n};const s=o.findIndex(c=>en(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}},pg=(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}}},ha=(e,t)=>{const n=e.ranges.findIndex(o=>en(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=pg(e.ranges,r.rangeIndex,r.cell,t),!kt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},bt=24,pi=32,Yr=4,hn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),y=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),_=i.useCallback(()=>{const L=u.current,I=e.current,Y=m.current;if(L===null||I===null||Y===null){c.current=null;return}const{clientX:B,clientY:T}=L.getPointerPosition(),A=l.current,P=(B-Y.left)/A,S=(T-Y.top)/A,R=I.getViewportSize(),E=R.width,f=R.height;if(E<=0||f<=0){c.current=requestAnimationFrame(_);return}const g=v=>Math.min(pi,Math.ceil(v/bt*pi));let b=0,$=0;if(s!=="x"){const v=I.getFrozenSize(),a=v.trailingVisibleHeight;S>f-a-bt?L.anchorRow!==void 0&&v.trailingRows>0&&L.anchorRow>=t.count-v.trailingRows&&a>0&&S>=f-a||(b=g(S-(f-a-bt))):S<v.height+bt&&(L.anchorRow!==void 0&&L.anchorRow<v.rows&&v.height>0&&S<v.height||(b=-g(v.height+bt-S)))}if(s!=="y"){const v=I.getFrozenSize(),a=v.trailingVisibleWidth;P>E-a-bt?L.anchorCol!==void 0&&v.trailingCols>0&&L.anchorCol>=n.count-v.trailingCols&&a>0&&P>=E-a||($=g(P-(E-a-bt))):P<v.width+bt&&(L.anchorCol!==void 0&&L.anchorCol<v.cols&&v.width>0&&P<v.width||($=-g(v.width+bt-P)))}const x=$!==0||b!==0?I.scrollBy({x:$!==0?$:void 0,y:b!==0?b:void 0}):I.getScrollPosition(),k=x.y,w=x.x;if(k>=0&&w>=0&&t.totalSize()>0&&n.totalSize()>0){const v=I.getFrozenSize(),a=ir({row:ur(t,S,{scroll:k,frozenSize:v.height,trailingSize:v.trailingHeight,extent:R.height}),col:ar(n,P,{scroll:w,frozenSize:v.width,trailingSize:v.trailingWidth,extent:R.width})},t.count,n.count),p=h.current;(b!==0||$!==0||p===null||p.row!==a.row||p.col!==a.col)&&(h.current=a,o(L.buildRange(a)))}c.current=requestAnimationFrame(_)},[e,t,n,s,o]),j=i.useCallback(L=>{y(),u.current=L,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(_)},[y,_,r]);return i.useEffect(()=>{const L=()=>{document.visibilityState==="hidden"&&y()};return document.addEventListener("visibilitychange",L),()=>{document.removeEventListener("visibilitychange",L),y()}},[y]),i.useMemo(()=>({start:j,stop:y}),[j,y])},hi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),y=i.useRef(!1),_=i.useRef(0),j=i.useCallback((R,E)=>{const{axis:f,mainAxis:g,handleRef:b,zoomRef:$}=t.current,x=s.current;if(x===null||g.totalSize()===0)return null;const k=$.current,w=b.current;if(w===null)return null;if(f==="col"){const M=w.getScrollPosition().x;if(M<0)return null;const d=w.getFrozenSize(),F=w.getViewportSize();return Math.min(Math.max(ar(g,(R-x.left)/k,{scroll:M,frozenSize:d.width,trailingSize:d.trailingWidth,extent:F.width}),0),g.count-1)}const v=w.getScrollPosition().y;if(v<0)return null;const a=w.getFrozenSize(),p=w.getViewportSize();return Math.min(Math.max(ur(g,(E-x.top)/k,{scroll:v,frozenSize:a.height,trailingSize:a.trailingHeight,extent:p.height}),0),g.count-1)},[]),L=i.useCallback((R,E)=>{const{axis:f,crossCount:g}=t.current;return f==="col"?{press:{row:0,col:R},extend:{row:g-1,col:E}}:{press:{row:R,col:0},extend:{row:E,col:g-1}}},[]),I=i.useCallback((R,E)=>{const{axis:f,crossCount:g}=t.current;return R.ranges.some(b=>f==="col"?b.startRow===0&&b.endRow===g-1&&E>=b.startCol&&E<=b.endCol:b.startCol===0&&b.endCol===g-1&&E>=b.startRow&&E<=b.endRow)},[]),Y=i.useRef(!1),B=i.useRef({clientX:0,clientY:0}),T=i.useCallback(()=>{Y.current=!1;const{autoScroller:R,headerRef:E,onDragFrame:f}=t.current;n.current=!1,r.current=null,m.current=null,y.current=!1,_.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),R.stop();const g=E.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,f(null),t.current.repaintOverlay()},[]),A=i.useCallback(()=>{if(!n.current)return;const R=r.current;R!==null&&t.current.setSelection(R),T()},[T]),{enabled:P,headerRef:S}=e;return i.useEffect(()=>{const R=S.current;if(!P||R===null)return;const E=w=>{const v=t.current;if(w.pointerType!=="mouse")return;if(w.button!==0){w.preventDefault();return}if(y.current=!1,v.pointing?.getPointing()){s.current=R.getBoundingClientRect();const d=j(w.clientX,w.clientY);if(d===null)return;w.preventDefault(),v.focusSink(),v.pointing.insertReference(v.axis==="col"?{row:0,col:d}:{row:d,col:0},v.axis==="col"?"columns":"rows");return}if(v.isEditing()&&!v.requestCommit()){w.preventDefault(),v.focusSink();return}s.current=R.getBoundingClientRect();const a=j(w.clientX,w.clientY);if(a===null)return;w.preventDefault(),v.focusSink();const p=v.getSelection();r.current=p;const M=w.ctrlKey||w.metaKey;if(w.shiftKey){const d=v.axis==="col"?{row:0,col:p.anchor.col}:{row:p.anchor.row,col:0},{extend:F}=L(a,a),O={...p,anchor:d};v.setSelection(Zt(O,F)),o.current=v.axis==="col"?d.col:d.row}else if(M&&I(p,a))y.current=!0,_.current=a,o.current=a;else{const{press:d,extend:F}=L(a,a),O=nr(p,d,{extend:!1,append:M});v.setSelection(Zt(O,F)),o.current=a}n.current=!0,v.repaintOverlay(),l.current={clientX:w.clientX,clientY:w.clientY},u.current=w.pointerId,h.current=w.buttons;try{R.setPointerCapture(w.pointerId)}catch{u.current=null}m.current=d=>{const F=t.current.axis==="col"?d.col:d.row,{press:O}=L(o.current,o.current),{extend:D}=L(o.current,F);return me(O,D)},v.autoScroller.stop(),Y.current=!1,B.current={clientX:w.clientX,clientY:w.clientY}},f=w=>u.current!==null?w.pointerId===u.current:w.pointerType==="mouse",g=w=>{if(n.current&&f(w)){if(y.current){const v=w.clientX!==l.current.clientX||w.clientY!==l.current.clientY;if(l.current={clientX:w.clientX,clientY:w.clientY},!v)return;const a=j(w.clientX,w.clientY);if(a===null||a===_.current)return;y.current=!1;const p=t.current,{press:M,extend:d}=L(_.current,_.current),F=nr(p.getSelection(),M,{extend:!1,append:!0});p.setSelection(Zt(F,d));const O=m.current,D=Math.abs(w.clientX-B.current.clientX),N=Math.abs(w.clientY-B.current.clientY);O!==null&&Math.max(D,N)>=Yr&&(Y.current=!0,p.autoScroller.start({getPointerPosition:()=>l.current,buildRange:O,anchorCol:p.axis==="col"?o.current:void 0,anchorRow:p.axis==="row"?o.current:void 0}))}else if(l.current={clientX:w.clientX,clientY:w.clientY},!Y.current&&m.current!==null){const v=Math.abs(w.clientX-B.current.clientX),a=Math.abs(w.clientY-B.current.clientY);Math.max(v,a)>=Yr&&(Y.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const v=m.current;if(!n.current||v===null)return;const a=j(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(v(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},b=w=>{g(w),n.current&&f(w)&&(h.current&1)!==0&&(w.buttons&1)===0&&x(w)},$=w=>{w.button!==0||!(n.current&&f(w))||x(w)},x=w=>{const v=t.current;if(y.current){const{press:p,extend:M}=L(_.current,_.current);v.setSelection(pa(v.getSelection(),me(p,M),p)),T();return}const a=j(w.clientX,w.clientY);if(a!==null){const{extend:p}=L(o.current,a);v.setSelection(Zt(v.getSelection(),p))}T()},k=w=>{!n.current||u.current===null||w.pointerId!==u.current||A()};return R.addEventListener("pointerdown",E),R.addEventListener("pointermove",b),R.addEventListener("pointerup",$),R.addEventListener("lostpointercapture",k),()=>{R.removeEventListener("pointerdown",E),R.removeEventListener("pointermove",b),R.removeEventListener("pointerup",$),R.removeEventListener("lostpointercapture",k),T()}},[P,S,j,L,T,A]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:A,cancelDrag:T}),[A,T])},hg=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),y=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):y>l+u-h.trailingVisibleHeight&&o.scrollBy({y:y-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),y=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):y>s+c-h.trailingVisibleWidth&&o.scrollBy({x:y-(s+c-h.trailingVisibleWidth)})}},mg=50,gg=100,ma=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<mg:!1,Vn={selectAll:Gt("Ctrl+A"),undo:Gt("Ctrl+Z"),redo:Gt("Ctrl+Y"),redoShiftZ:Gt("Ctrl+Shift+Z"),pasteValues:Gt("Ctrl+Shift+V")},wg=new Set(["Shift","Control","Alt","Meta","AltGraph"]),Cg={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},yg=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",bg=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,y=u.current;if(!l||m===null||y===null)return;const _=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},j=(a,p,M)=>_t(a,p,M)??p,L=(a,p)=>{const M=s.current;return p==="left"||p==="right"?{row:a.row,col:j(M.colAxis,a.col,p==="right"?1:-1)}:{row:j(M.rowAxis,a.row,p==="down"?1:-1),col:a.col}},I=a=>a.indexAt(0),Y=a=>a.indexAt(a.totalSize()-1),B=(a,p,M,d)=>{if(a.sizeOf(p)>0)return p;const F=_t(a,p,M);if(F!==null)return F;const O=_t(a,p,M===1?-1:1);return O!==null?O:d},T=()=>{const a=s.current.getSelection(),p=a.ranges[a.ranges.length-1];return{row:a.anchor.row===p.startRow?p.endRow:p.startRow,col:a.anchor.col===p.startCol?p.endCol:p.startCol}},A=a=>L(T(),a),P=(a,p)=>{const M=s.current,d=p==="left"||p==="right",F=p==="right"||p==="down"?1:-1;let O;return M.findDataEdge!==void 0?(O=M.findDataEdge({row:a.row,col:a.col},p),S(O,a,p)):O={row:p==="down"?M.rowAxis.count-1:p==="up"?0:a.row,col:p==="right"?M.colAxis.count-1:p==="left"?0:a.col},d?{row:O.row,col:B(M.colAxis,O.col,F,a.col)}:{row:B(M.rowAxis,O.row,F,a.row),col:O.col}},S=(a,p,M)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const F=M==="left"||M==="right";if(F?a.row!==p.row:a.col!==p.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${F?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${p.row}, col: ${p.col}})`)},R=(a,p,M)=>{if(!(Number.isInteger(a)&&a>=0&&a<p))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${M} component ${a} (count ${p})`)},E=a=>{const p=s.current,M=p.getSelection();if(ha(M,a)===M){p.moveActive({mode:"reset",cell:L(M.active,a)});return}p.moveActive({mode:"cycle",direction:a})},f=()=>{const a=c.current;if(a===null)return;const p=a.selectionStart??a.value.length,M=a.selectionEnd??p;a.value=`${a.value.slice(0,p)}
|
|
21
|
+
${a.value.slice(M)}`,a.setSelectionRange(p+1,p+1)},g=(a,p)=>{const M=s.current,d=h.current?.getViewportSize().height??-1;return d<=0?j(M.rowAxis,a,p==="down"?1:-1):M.rowAxis.indexAt(M.rowAxis.offsetOf(a)+(p==="down"?d:-d))},b=a=>{const p=s.current;if(r.current=!1,ma(a,t.current))return;const M=a.ctrlKey||a.metaKey,d=a.altKey,F=Cg[a.key];if(o.current&&!wg.has(a.key)&&!p.isDragging()&&_(),p.isEditing()){const D=p.getEditingMode();if(p.isDragging()){a.preventDefault(),a.key==="Escape"&&!M&&!a.shiftKey&&!d&&p.abortDrag();return}const N=p.pointing;if(N!==void 0){if(F!==void 0&&!d){const V=N.getReferenceCursor();if(V!==null){a.preventDefault();const G=M?P(V.cursor,F):L(V.cursor,F);if(p.ensureCellVisible(G),N.insertReference(a.shiftKey?me(V.origin,G):G,V.axis),p.onPointFrame!==void 0){const Z=a.shiftKey?me(V.origin,G):me(G,G);p.onPointFrame(V.axis==="columns"?me({row:0,col:Z.startCol},{row:p.rowAxis.count-1,col:Z.endCol}):V.axis==="rows"?me({row:Z.startRow,col:0},{row:Z.endRow,col:p.colAxis.count-1}):Z),o.current=!0}return}}if(a.key==="F2"&&!M&&!a.shiftKey&&!d&&N.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!M&&!a.shiftKey&&!d&&N.cycleAnchorAtCaret()){a.preventDefault();return}}const W=p.commands;if(W!==void 0){const V=Ml(W.table,a);if(V!==null&&ms.has(V)&&W.isAvailable(V)){a.preventDefault(),W.execute(V);return}}if(F!==void 0&&!d){if(M&&a.shiftKey){a.preventDefault();return}if(M)return;if(D==="replace"){if(a.preventDefault(),!p.requestCommit())return;a.shiftKey?p.moveActive({mode:"extend",cell:A(F)}):p.moveActive({mode:"reset",cell:L(p.getSelection().active,F)});return}return}if(a.key==="Enter"&&d&&!M&&!a.shiftKey){a.preventDefault(),f();return}if((a.key==="Enter"||a.key==="Tab")&&!M&&!d){if(a.preventDefault(),!p.requestCommit())return;const V=!a.shiftKey;E(a.key==="Tab"?V?"right":"left":V?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!M&&!d){if(a.preventDefault(),!p.requestCommit())return;const V=p.getSelection().active;p.moveActive({mode:"reset",cell:{row:g(V.row,a.key==="PageDown"?"down":"up"),col:V.col}});return}if(a.key==="Escape"&&!M&&!a.shiftKey&&!d){a.preventDefault(),p.cancelEdit();return}return}if(a.defaultPrevented)return;if(p.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const O=p.commands;if(O!==void 0){const D=Ml(O.table,a);if(D!==null&&O.isAvailable(D)){a.preventDefault(),O.execute(D);return}}if(F!==void 0&&!d){const D=F==="left"||F==="right",N=F==="right"||F==="down"?1:-1;if(M&&a.shiftKey){a.preventDefault();const W=p.getSelection(),V=T();let G;if(p.findDataEdge!==void 0){const Z=D?{row:W.active.row,col:V.col}:{row:V.row,col:W.active.col},ee=p.findDataEdge(Z,F);G=D?ee.col:ee.row,R(G,D?p.colAxis.count:p.rowAxis.count,D?"col":"row"),G=B(D?p.colAxis:p.rowAxis,G,N,D?V.col:V.row)}else{const Z=D?p.colAxis:p.rowAxis;G=N===1?Y(Z):I(Z)}p.moveActive({mode:"extend",cell:D?{row:V.row,col:G}:{row:G,col:V.col}});return}if(M){a.preventDefault(),p.moveActive({mode:"reset",cell:P(p.getSelection().active,F)});return}if(a.shiftKey){a.preventDefault(),p.moveActive({mode:"extend",cell:A(F)});return}a.preventDefault(),p.moveActive({mode:"reset",cell:L(p.getSelection().active,F)});return}if(yg(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!M&&!d){a.preventDefault();const D=!a.shiftKey;E(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const N=T();p.moveActive({mode:"extend",cell:{row:M?I(p.rowAxis):N.row,col:I(p.colAxis)}});return}const D=p.getSelection().active;p.moveActive({mode:"reset",cell:{row:M?I(p.rowAxis):D.row,col:I(p.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const N=T();p.moveActive({mode:"extend",cell:{row:M?Y(p.rowAxis):N.row,col:Y(p.colAxis)}});return}const D=p.getSelection().active;p.moveActive({mode:"reset",cell:{row:M?Y(p.rowAxis):D.row,col:Y(p.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!M&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const W=T();p.moveActive({mode:"extend",cell:{row:g(W.row,D),col:W.col}});return}const N=p.getSelection().active;p.moveActive({mode:"reset",cell:{row:g(N.row,D),col:N.col}});return}if(a.key==="F2"&&!M&&!a.shiftKey&&!d){a.preventDefault(),p.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!M&&!a.shiftKey&&!d){a.preventDefault();const D=p.getSelection(),N=pt(D.ranges);if(N>p.maxOperationCells){p.onOperationRejected?.("delete",N,"limit");return}if(p.adapter!==void 0&&Cn(p.adapter,D.ranges)){p.rejectReadOnly({kind:"operation",op:"delete",cellCount:N});return}const W=[],V=p.adapter!==void 0&&Ir(p.adapter).hyperlink;Lt(D.ranges,G=>{W.push(V?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),p.commitEdits(W,{source:"delete"});return}if(a.key==="Escape"){if(p.isDragging()){a.preventDefault(),p.abortDrag();return}if(M||a.shiftKey||d||(a.preventDefault(),p.hideNoteTip?.())||p.closeRejectedMessage?.())return;if(p.getClip()!==null){p.discardClip();return}p.handOffFocusToRoot();return}if(jn(Vn.selectAll,a)){a.preventDefault();const D=p.getSelection(),N=me({row:0,col:0},{row:p.rowAxis.count-1,col:p.colAxis.count-1});p.setSelection({ranges:[N],anchor:D.anchor,active:D.active});return}if(jn(Vn.undo,a)){a.preventDefault(),p.onUndoRequest?.();return}if(jn(Vn.redo,a)||jn(Vn.redoShiftZ,a)){a.preventDefault(),p.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!M&&!d||a.key==="ContextMenu"&&!M&&!a.shiftKey&&!d){a.preventDefault();const D=p.getSelection().active;p.ensureCellVisible(D);const N=h.current,W=N===null?{x:0,y:0}:N.getScrollPosition(),V=Math.max(0,W.y),G=Math.max(0,W.x),Z=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),ee=N===null?{width:0,height:0}:N.getViewportSize(),ie=p.zoomRef.current;p.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:Qt(p.rowAxis,D.row,{scroll:V,frozenCount:Z.rows,trailingCount:Z.trailingRows,extent:ee.height})*ie,left:Jt(p.colAxis,D.col,{scroll:G,frozenCount:Z.cols,trailingCount:Z.trailingCols,extent:ee.width})*ie,width:p.colAxis.sizeOf(D.col)*ie,height:p.rowAxis.sizeOf(D.row)*ie}});return}if(a.key===" "&&!d&&M!==a.shiftKey){a.preventDefault();const D=p.getSelection(),N=D.ranges.map(W=>M?me({row:0,col:W.startCol},{row:p.rowAxis.count-1,col:W.endCol}):me({row:W.startRow,col:0},{row:W.endRow,col:p.colAxis.count-1}));p.setSelection({ranges:N,anchor:D.anchor,active:D.active});return}if(p.pendingPasteOptionsRef!==void 0&&jn(Vn.pasteValues,a)){p.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}p.startEdit("replace");return}},$=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},x=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},gg)},k=()=>{const a=s.current;if(_(),!a.isEditing()){if(r.current){r.current=!1;const p=m.value;if(p!==""&&(a.startEdit("replace"),a.isEditing())){m.value=p,m.setSelectionRange(p.length,p.length);return}}a.rearmSink()}},w=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},v=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),_()};return m.addEventListener("keydown",b),m.addEventListener("keyup",w),m.addEventListener("blur",v),m.addEventListener("compositionstart",$),m.addEventListener("compositionend",x),m.addEventListener("input",k),()=>{m.removeEventListener("keydown",b),m.removeEventListener("keyup",w),m.removeEventListener("blur",v),m.removeEventListener("compositionstart",$),m.removeEventListener("compositionend",x),m.removeEventListener("input",k),n.current!==null&&window.clearTimeout(n.current),_()}},[l,c,u,h])},vg=4,Rg=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),kg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),y=i.useRef(0),_=i.useRef(null),j=i.useRef(null),L=i.useRef(!1),I=i.useCallback(R=>m.current!==null?R.pointerId===m.current:R.pointerType==="mouse",[]),Y=i.useCallback((R,E)=>{const{handleRef:f,rowAxis:g,colAxis:b}=t.current,$=f.current,x=s.current;if($===null||x===null)return null;const{x:k,y:w}=$.getScrollPosition();if(w<0||k<0||g.totalSize()===0||b.totalSize()===0)return null;const v=t.current.zoomRef.current,a=$.getFrozenSize(),p=$.getViewportSize();return ir({row:ur(g,(E-x.top)/v,{scroll:w,frozenSize:a.height,trailingSize:a.trailingHeight,extent:p.height}),col:ar(b,(R-x.left)/v,{scroll:k,frozenSize:a.width,trailingSize:a.trailingWidth,extent:p.width})},g.count,b.count)},[]),B=i.useCallback(R=>{const E=r.current;if(E===null)return me(R,R);const f=me({row:Math.min(E.startRow,R.row),col:Math.min(E.startCol,R.col)},{row:Math.max(E.endRow,R.row),col:Math.max(E.endCol,R.col)}),g=f.startRow!==E.startRow||f.endRow!==E.endRow||f.startCol!==E.startCol||f.endCol!==E.endCol;return o.current=g?f:null,g?f:E},[]),T=i.useCallback(()=>{const R=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,_.current!==null&&(cancelAnimationFrame(_.current),_.current=null),R.xAutoScroller.stop(),R.yAutoScroller.stop(),L.current=!1,u.current=!1,h.current={dx:0,dy:0},R.writeFillPreview(null);const E=j.current;E!==null&&(window.removeEventListener("pointermove",E.move),window.removeEventListener("pointerup",E.up),j.current=null);const f=t.current.handleNodeRef.current;f!==null&&m.current!==null&&f.hasPointerCapture?.(m.current)&&f.releasePointerCapture(m.current),m.current=null,R.repaintOverlay()},[]),A=i.useCallback(()=>{const R=t.current,E=r.current,f=o.current;if(T(),E===null||f===null)return;const g=Ep(E,f);if(g>R.maxOperationCells){R.onOperationRejected?.("fill",g,"limit");return}if(Cn(R.adapter,xp(E,f))){const x=(f.endRow-f.startRow+1)*(f.endCol-f.startCol+1),k=(E.endRow-E.startRow+1)*(E.endCol-E.startCol+1);R.rejectReadOnly({kind:"operation",op:"fill",cellCount:x-k});return}const b=Ap((x,k)=>kc(R.adapter,x,k),E,f,Sc);if(R.commitEdits(b,{source:"fill"})===null)return;const $=R.getSelection();R.setSelection({ranges:[f],anchor:$.anchor,active:$.active})},[T]),{enabled:P,handleNodeRef:S}=e;return i.useEffect(()=>{const R=S.current;if(!P||R===null)return;const E=x=>{f(x),n.current&&I(x)&&(y.current&1)!==0&&(x.buttons&1)===0&&A()},f=x=>{if(!(n.current&&I(x)))return;l.current={clientX:x.clientX,clientY:x.clientY};const k=Math.abs(x.clientX-c.current.clientX),w=Math.abs(x.clientY-c.current.clientY);if(!u.current&&Math.max(k,w)>=vg&&(u.current=!0),!!u.current){if(!L.current){const v=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};v.xAutoScroller.start(a),v.yAutoScroller.start(a),L.current=!0}_.current===null&&(_.current=requestAnimationFrame(()=>{if(_.current=null,!(n.current&&u.current))return;const v=Y(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);v!==null&&t.current.writeFillPreview(B(v))}))}},g=x=>{x.button!==0||!(n.current&&I(x))||A()},b=x=>{const k=t.current;if(x.pointerType!=="mouse")return;if(x.button!==0){x.preventDefault();return}x.preventDefault(),x.stopPropagation(),k.focusSink();const w=k.getSelection(),v=w.ranges[w.ranges.length-1];r.current=v,o.current=null,u.current=!1,k.xAutoScroller.stop(),k.yAutoScroller.stop(),L.current=!1,c.current={clientX:x.clientX,clientY:x.clientY},l.current=c.current,y.current=x.buttons,n.current=!0,k.repaintOverlay(),s.current=k.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,p=k.handleRef.current?.getScrollPosition()??{x:-1,y:-1},M=p.y;if(a!==null&&M>=0&&p.x>=0){const O=p.x,D=k.zoomRef.current,N=k.handleRef.current?.getFrozenSize()??Rg,W=k.handleRef.current?.getViewportSize()??{width:0,height:0},V={scroll:O,frozenCount:N.cols,trailingCount:N.trailingCols,extent:W.width},G={scroll:M,frozenCount:N.rows,trailingCount:N.trailingRows,extent:W.height},Z=Jt(k.colAxis,v.endCol,V)+k.colAxis.sizeOf(v.endCol),ee=Qt(k.rowAxis,v.endRow,G)+k.rowAxis.sizeOf(v.endRow),ie=Z-1,oe=v.endCol>=N.cols&&N.width>0?Math.max(ie,N.width):ie,qe=!(v.endCol>=k.colAxis.count-N.trailingCols)&&N.trailingWidth>0?Math.min(oe,W.width-N.trailingVisibleWidth-1):oe,De=ee-1,_e=v.endRow>=N.rows&&N.height>0?Math.max(De,N.height):De,fe=!(v.endRow>=k.rowAxis.count-N.trailingRows)&&N.trailingHeight>0?Math.min(_e,W.height-N.trailingVisibleHeight-1):_e;h.current={dx:x.clientX-(a.left+qe*D),dy:x.clientY-(a.top+fe*D)}}else h.current={dx:0,dy:0};m.current=x.pointerId;try{R.setPointerCapture(x.pointerId)}catch{m.current=null}const d=E,F=g;j.current={move:d,up:F},window.addEventListener("pointermove",d),window.addEventListener("pointerup",F),k.writeFillPreview(r.current)},$=x=>{!n.current||m.current===null||x.pointerId!==m.current||T()};return R.addEventListener("pointerdown",b),R.addEventListener("lostpointercapture",$),()=>{R.removeEventListener("pointerdown",b),R.removeEventListener("lostpointercapture",$),T()}},[P,S,I,Y,B,T,A]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&T()},cancelDrag:T}),[T])},Sg=320,jr=8,Eg=64,xg=150,ga=e=>Math.max(0,Math.min(Sg,e.width-lt-jr)),Ag=(e,t,n)=>{const r=n.width-lt,o=n.height-lt,s=ga(n),l=Math.max(0,Math.min(t,o-jr)),c=e.left+e.width,u=e.top+e.height,h=I=>I>=0&&I+s<=r,m=[e.left,c-s],y=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const I of y)if(h(I.left)&&I.top>=0&&I.top+l<=o)return{left:I.left,top:I.top,width:s,height:l};const _=o-u,j=e.top,L=Math.min(l,Math.max(_,j));if(L>=Eg){const I=_>=j?u:e.top-L;for(const Y of m)if(h(Y))return{left:Y,top:I,width:s,height:L}}return{left:jr,top:jr,width:s,height:l}},Og=(e,t,n,r)=>t===null||e!==null&&kt(e,t)||n?!1:r(t),Tg=(e,t)=>{switch(e.kind){case"note":return K.jsx(Gc,{ctx:e,labels:t});case"note-tip":return K.jsx(Zc,{ctx:e,labels:t});case"comment":return K.jsx(Kc,{ctx:e,labels:t});case"link":return K.jsx(Yc,{ctx:e,labels:t});case"list":return K.jsx(Uc,{ctx:e,labels:t});default:return K.jsx(Xc,{ctx:e,labels:t})}},Fo=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Dg=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const y=Fo(s),_=Fo(l),j=i.useRef(null),L=(A,P)=>{const S=m.current.getLayerSize();A.style.width=`${ga(S)}px`,A.style.maxHeight="";const R=Ag(P,A.offsetHeight,S);A.style.left=`${R.left-P.left}px`,A.style.top=`${R.top-P.top}px`,A.style.maxHeight=`${R.height}px`};i.useLayoutEffect(()=>{const A=c.current;if(A===null||s===null){j.current=null;return}if(L(A,s.anchorRect),s.kind==="message")return;const P=Fo(s);if(j.current===P)return;j.current=P;const S=A.querySelector("[data-aqsp-popover-autofocus]");S!==null?S.focus({preventScroll:!0}):A.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const A=u.current,P=h.current;A===null||P===null||L(A,P.anchorRect)},[_]);const I=A=>t===void 0?Tg(A,n):t(A),Y=A=>{e.isCompositionKey(A.nativeEvent)&&A.stopPropagation()},B=A=>{A.key==="Escape"&&!A.defaultPrevented&&(A.preventDefault(),e.close())},T=A=>{e.registerCompositionEnd(A.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:Y,onKeyDown:B,onCompositionEnd:T,children:[K.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:K.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:I(s)},y)}),K.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:I(l)})})]})},Mg=["note","note-tip","comment","link","list","message"],$g=(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}},Wn=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&$g(e,n),Fg=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),y=i.useRef(null),_=i.useRef(null),j=i.useRef(null),L=i.useId(),I=i.useCallback(O=>{const D=t.current,N=D.handleRef.current,W=N===null?{x:0,y:0}:N.getScrollPosition(),V=N===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:N.getFrozenSize(),G=N===null?{width:0,height:0}:N.getViewportSize();return{top:Qt(D.rowAxis,O.row,{scroll:Math.max(0,W.y),frozenCount:V.rows,trailingCount:V.trailingRows,extent:G.height}),left:Jt(D.colAxis,O.col,{scroll:Math.max(0,W.x),frozenCount:V.cols,trailingCount:V.trailingCols,extent:G.width}),width:D.colAxis.sizeOf(O.col),height:D.rowAxis.sizeOf(O.row)}},[]),Y=i.useCallback(O=>{const D=t.current;D.anchors.current={...D.anchors.current,...O},D.repaintOverlay()},[]),B=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),T=i.useCallback(()=>{const O=t.current.sinkRef.current;if(O===null)return;const D=c.current;D!==null&&kt(D,t.current.getActive())?O.setAttribute("aria-describedby",L):O.getAttribute("aria-describedby")===L&&O.removeAttribute("aria-describedby")},[L]),A=i.useCallback(()=>(B(),h.current=!1,c.current===null?!1:(c.current=null,s(null),Y({tip:null}),T(),!0)),[B,Y,T]),P=i.useCallback(()=>{B(),m.current=window.setTimeout(()=>{m.current=null,A()},xg)},[B,A]),S=i.useCallback(O=>{const D=t.current;B();const N=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(O.row,O.col);N===void 0||N===""||(c.current=O,s({kind:"note-tip",cell:O,anchorRect:I(O),current:N,close:A}),Y({tip:O}),T())},[I,B,A,Y,T]),R=i.useCallback(O=>{const D=t.current;if(O===null&&h.current)return;const N=u.current;u.current=O;const W=c.current;if(W!==null&&O!==null&&kt(W,O)){B();return}const V=G=>{const Z=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(G.row,G.col);return Z!==void 0&&Z!==""};if(Og(N,O,D.isDraggingAny(),V)){O!==null&&S(O);return}W!==null&&P()},[S,B,P]),E=i.useCallback((O,D)=>{const N=t.current,W=N.bodyRef.current,V=N.handleRef.current;if(W===null||V===null)return null;const G=W.getBoundingClientRect(),Z=N.zoomRef.current,ee=V.getScrollPosition(),ie=V.getFrozenSize(),oe=V.getViewportSize();return ir({row:ur(N.rowAxis,(D-G.top)/Z,{scroll:Math.max(0,ee.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:oe.height}),col:ar(N.colAxis,(O-G.left)/Z,{scroll:Math.max(0,ee.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:oe.width})},N.rowAxis.count,N.colAxis.count)},[]),f=i.useCallback(O=>{_.current=O,y.current===null&&(y.current=requestAnimationFrame(()=>{y.current=null;const D=_.current;R(D===null?null:"cell"in D?D.cell:E(D.clientX,D.clientY))}))},[R,E]),g=i.useCallback(O=>f({cell:O}),[f]),b=i.useCallback(()=>A(),[A]),$=i.useCallback(()=>{if(l.current===null)return;const O=t.current;l.current=null,r(null),Y({interactive:null}),O.focusSink({preventScroll:!0}),O.isEditing()||O.rearmSink()},[Y]),x=i.useCallback(O=>{l.current=O.kind,r(O),Y({interactive:O.cell})},[Y]),k=i.useCallback(O=>{const D=t.current;return bc(D.adapter)?{cellReadOnly:je(D.adapter,O.row,O.col)}:{}},[]),w=i.useCallback((O,D)=>{const N=t.current;if(je(N.adapter,O.cell.row,O.cell.col)){N.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),x({...O,...k(O.cell)});return}if(N.commitEdits(D,{source:"annotate"})===null){x({...O,rejected:!0});return}$()},[x,$,k]),v=i.useCallback((O,D)=>{const N=t.current;if(!Wn(N.adapter,N.popovers,O))throw new RangeError(`[spreadsheet] openPopover("${O}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const W=N.getActive();if(O==="list"&&je(N.adapter,W.row,W.col)){N.rejectReadOnly({kind:"edit",cell:W,editSession:"none"});return}if(O==="note-tip"){S(W);return}if(O==="message"){if(l.current!==null&&l.current!=="message")return;const ee=D!==void 0&&D.message!==void 0?D.message:void 0,ie=N.adapter.getCellValidation===void 0?void 0:N.adapter.getCellValidation(W.row,W.col),oe=ee!==void 0?ee:ie===void 0?void 0:ie.inputMessage;if(oe===void 0)return;const Te=D!==void 0&&D.rejected===!0;x({kind:"message",cell:W,anchorRect:I(W),current:{title:Oe(N.labels,"messageTitle"),message:oe,rejected:Te},close:$});return}if(N.isEditing()&&!N.requestCommit())return;if(O==="list"){const ee=N.adapter.getCellValidation===void 0?void 0:N.adapter.getCellValidation(W.row,W.col);if(ee===void 0||ee.type!=="list")return;const ie=D!==void 0&&D.typed!==void 0?D.typed:"";A(),N.focusSink({preventScroll:!0}),x({kind:"list",cell:W,anchorRect:I(W),current:ee.values,typed:ie,commit:oe=>{if(je(t.current.adapter,W.row,W.col)){t.current.rejectReadOnly({kind:"edit",cell:W,editSession:"none"}),$();return}t.current.commitEdits([{row:W.row,col:W.col,text:oe}],{source:"edit",editSession:"discarded"}),$()},close:$});return}if(A(),N.focusSink({preventScroll:!0}),O==="note"){const ee=N.adapter.getCellNote===void 0?void 0:N.adapter.getCellNote(W.row,W.col),ie={kind:"note",cell:W,anchorRect:I(W),current:ee,commit:oe=>{w(ie,[{row:W.row,col:W.col,note:oe}])},close:$,rejected:!1,...k(W)};x(ie);return}if(O==="comment"){const ee=N.adapter.getCellComments===void 0?void 0:N.adapter.getCellComments(W.row,W.col),ie={kind:"comment",cell:W,anchorRect:I(W),current:ee===void 0?[]:ee,commit:oe=>{w(ie,[{row:W.row,col:W.col,comments:oe}])},close:$,rejected:!1,...k(W)};x(ie);return}const V=N.adapter.getCellHyperlink===void 0?void 0:On(N.adapter.getCellHyperlink(W.row,W.col)),G=N.adapter.getCellText(W.row,W.col),Z={kind:"link",cell:W,anchorRect:I(W),current:{text:G,url:V},commit:ee=>{const ie=ee.url===null?null:jt(ee.url);if(ie===null&&ee.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ee.url)}`);const oe=ee.text===G?{row:W.row,col:W.col,hyperlink:ie}:{row:W.row,col:W.col,text:ee.text,hyperlink:ie};w(Z,[oe])},close:$,canOpen:N.onHyperlinkOpen!==void 0,open:()=>{const ee=t.current.onHyperlinkOpen;ee!==void 0&&V!==void 0&&ee(V,W)},rejected:!1,...k(W)};x(Z)},[I,$,w,A,x,S,k]),{enabled:a,bodyRef:p}=e;i.useEffect(()=>{const O=p.current;if(!a||O===null)return;const D=W=>{const V=t.current;Wn(V.adapter,V.popovers,"note-tip")&&f({clientX:W.clientX,clientY:W.clientY})},N=()=>{Wn(t.current.adapter,t.current.popovers,"note-tip")&&f({cell:null})};return O.addEventListener("pointermove",D),O.addEventListener("pointerleave",N),()=>{O.removeEventListener("pointermove",D),O.removeEventListener("pointerleave",N)}},[a,p,f]),i.useEffect(()=>()=>{y.current!==null&&cancelAnimationFrame(y.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:M,popovers:d}=e,F=i.useMemo(()=>Mg.some(O=>Wn(M,d,O)),[M,d]);return i.useMemo(()=>({layerEnabled:F,isKindEnabled:O=>Wn(t.current.adapter,t.current.popovers,O),open:v,close:$,isOpen:()=>l.current,onCellHover:g,hideTip:b,onTipPointerEnter:()=>{h.current=!0,B()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&P()},syncTipAriaDescribedBy:T,context:n,tipContext:o,registerCompositionEnd:O=>{j.current=O},isCompositionKey:O=>ma(O,j.current),getLayerSize:()=>{const O=t.current.handleRef.current;return O===null?{width:0,height:0}:O.getViewportSize()},tipId:L}),[F,v,$,g,b,B,P,T,n,o,L])},zg=(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},wa=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return ir({row:ur(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:ar(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},Ng=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),y=i.useRef(null),_=i.useRef(""),j=i.useRef(!1),L=i.useRef(!1),I=i.useCallback((f,g)=>{const{handleRef:b,rowAxis:$,colAxis:x,zoomRef:k}=t.current;return wa(b.current,o.current,$,x,k.current,f,g)},[]),Y=i.useRef(!1),B=i.useRef(null),T=i.useRef(null),A=i.useRef({clientX:0,clientY:0}),P=i.useCallback(()=>{const{autoScroller:f,bodyRef:g,onDragFrame:b}=t.current;n.current=!1,r.current=null,h.current=null,Y.current=!1,B.current=null,T.current=null,m.current=!1,y.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),f.stop();const $=g.current;$!==null&&c.current!==null&&$.hasPointerCapture?.(c.current)&&$.releasePointerCapture(c.current),c.current=null,b(null),t.current.repaintOverlay()},[]),S=i.useCallback(()=>{if(!n.current)return;const f=r.current;f!==null&&t.current.setSelection(f),P()},[P]),{enabled:R,bodyRef:E}=e;return i.useEffect(()=>{const f=E.current;if(!R||f===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,b=d=>{const F=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,y.current=null,L.current=!1),j.current=g(d.target),!j.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(F.getPointing?.()){F.focusSink();return}if(F.isEditing()&&!F.requestCommit()){d.stopPropagation(),F.focusSink();return}F.focusSink()}return}if(_.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((F.pointDragRef===void 0?null:F.pointDragRef.current)?.onPointerDown(d))return;if(F.isEditing()&&!F.requestCommit()){d.preventDefault(),F.focusSink();return}o.current=f.getBoundingClientRect();const D=I(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),F.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&F.openHyperlinkAt?.(D)===!0){L.current=!0;return}const N=F.getSelection();r.current=N;const W=d.shiftKey,V=d.ctrlKey||d.metaKey,G=V&&!W&&N.ranges.some(ee=>en(ee,D));m.current=G,y.current=G?D:null,G||F.setSelection(nr(N,D,{extend:W,append:V})),n.current=!0,F.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{f.setPointerCapture(d.pointerId)}catch{c.current=null}const Z=G?D:F.getSelection().anchor;h.current=ee=>me(Z,ee),B.current=Z.col,T.current=Z.row,F.autoScroller.stop(),Y.current=!1,A.current={clientX:d.clientX,clientY:d.clientY}},$=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",x=d=>{if(n.current&&$(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!Y.current&&h.current!==null){const F=Math.abs(d.clientX-A.current.clientX),O=Math.abs(d.clientY-A.current.clientY);Math.max(F,O)>=Yr&&(Y.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:B.current??void 0,anchorRow:T.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const F=h.current;if(!n.current||F===null)return;const O=t.current,D=I(s.current.clientX,s.current.clientY);D!==null&&O.onDragFrame(F(D))}))}},k=d=>{x(d),n.current&&$(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&v(d)},w=d=>{d.button!==0||!(n.current&&$(d))||v(d)},v=d=>{const F=t.current,O=I(d.clientX,d.clientY);if(O!==null){const D=y.current;m.current&&D!==null?F.setSelection(pa(F.getSelection(),me(D,O),D)):F.setSelection(Zt(F.getSelection(),O))}P()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||S()},p=d=>{const F=t.current;if(!g(d.target)||_.current!=="mouse"||F.isAnyDragging())return;if(F.isEditing()&&!F.requestCommit()){F.focusSink();return}F.focusSink(),o.current=f.getBoundingClientRect();const O=I(d.clientX,d.clientY);if(O===null)return;const D=F.getSelection();D.ranges.some(W=>en(W,O))||F.setSelection(nr(D,O,{extend:!1,append:!1})),F.onContextMenuSelect(O,d)},M=d=>{const F=t.current;if(!j.current||_.current!=="mouse"||F.getPointing?.()||L.current)return;o.current=f.getBoundingClientRect();const O=I(d.clientX,d.clientY);O!==null&&kt(F.getSelection().active,O)&&F.onRequestEdit(O,F.caretFromPointEnabled(O)?zg(d.clientX,d.clientY,O):void 0)};return f.addEventListener("pointerdown",b),f.addEventListener("pointermove",k),f.addEventListener("pointerup",w),f.addEventListener("lostpointercapture",a),f.addEventListener("contextmenu",p),f.addEventListener("dblclick",M),()=>{f.removeEventListener("pointerdown",b),f.removeEventListener("pointermove",k),f.removeEventListener("pointerup",w),f.removeEventListener("lostpointercapture",a),f.removeEventListener("contextmenu",p),f.removeEventListener("dblclick",M),P()}},[R,E,I,P,S]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:S,cancelDrag:P}),[S,P])},Lg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),y=i.useRef(null),_=i.useRef(!1),j=i.useCallback((A,P)=>{const{handleRef:S,rowAxis:R,colAxis:E,zoomRef:f}=t.current;return wa(S.current,o.current,R,E,f.current,A,P)},[]),L=i.useCallback(()=>{const{autoScroller:A,bodyRef:P,onDragFrame:S}=t.current;n.current=!1,r.current=null,m.current=null,y.current=null,_.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),A.stop();const R=P.current;R!==null&&u.current!==null&&R.hasPointerCapture?.(u.current)&&R.releasePointerCapture(u.current),u.current=null,S(null)},[]),I=i.useCallback(()=>{if(!n.current)return;const A=r.current;A!==null&&t.current.restoreSink(A),L()},[L]),Y=i.useCallback(A=>{const P=t.current,S=P.bodyRef.current;if(!P.enabled||S===null||!P.getPointing())return!1;o.current=S.getBoundingClientRect();const R=j(A.clientX,A.clientY);if(R===null)return o.current=null,!1;const E=P.captureSink();if(E===null)return o.current=null,!1;A.preventDefault(),P.focusSink(),r.current=E,y.current=R,P.insertReference(R,"cells"),n.current=!0,s.current={clientX:A.clientX,clientY:A.clientY},l.current={clientX:A.clientX,clientY:A.clientY},u.current=A.pointerId,h.current=A.buttons;try{S.setPointerCapture(A.pointerId)}catch{u.current=null}return m.current=f=>{const g=me(R,f);return t.current.insertReference(g,"cells"),g},P.autoScroller.stop(),_.current=!1,P.onDragFrame(me(R,R)),!0},[j]),{enabled:B,bodyRef:T}=e;return i.useEffect(()=>{const A=T.current;if(!B||A===null)return;const P=f=>u.current!==null?f.pointerId===u.current:f.pointerType==="mouse",S=f=>{if(!(n.current&&P(f)))return;s.current={clientX:f.clientX,clientY:f.clientY};const g=m.current,b=y.current;if(!_.current&&g!==null&&b!==null){const $=Math.abs(f.clientX-l.current.clientX),x=Math.abs(f.clientY-l.current.clientY);Math.max($,x)>=Yr&&(_.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:b.col,anchorRow:b.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const $=m.current;if(!n.current||$===null)return;const x=j(s.current.clientX,s.current.clientY);x!==null&&t.current.onDragFrame($(x))})),(h.current&1)!==0&&(f.buttons&1)===0&&L()},R=f=>{f.button!==0||!(n.current&&P(f))||L()},E=f=>{!n.current||u.current===null||f.pointerId!==u.current||L()};return A.addEventListener("pointermove",S),A.addEventListener("pointerup",R),A.addEventListener("lostpointercapture",E),()=>{A.removeEventListener("pointermove",S),A.removeEventListener("pointerup",R),A.removeEventListener("lostpointercapture",E),L()}},[B,T,j,L]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:I,cancelDrag:L,onPointerDown:Y}),[I,L,Y])},Pg=.25,qg=4,zo=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(qg,Math.max(Pg,e))},No=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,_g=24,Ig=100,jg=1e5,Hg=200,Ca=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),mi=5,Bg=/^#[0-9A-Fa-f]{6}$/,Vg=Object.freeze({row:!1,column:!1,intersection:!1}),gi=Object.freeze({ok:!0}),wi=(e,t)=>{if(t===void 0)return Ca;if(t.length!==mi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${mi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Bg.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Wg=e=>{for(const t of["row","column","intersection"])if(Ve(e[t])===null)throw new RangeError(`[spreadsheet] highlightColors.${t} is not a colour (got ${JSON.stringify(e[t])})`);if(!(Number.isFinite(e.opacity)&&e.opacity>=0&&e.opacity<=1))throw new RangeError(`[spreadsheet] highlightColors.opacity must be a number in [0, 1] (got ${e.opacity})`);return e},Kg=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return Vc},Yg=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},zr={ranges:[me({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Ug=i.forwardRef(function({adapter:t,defaultRowHeight:n=_g,defaultColumnWidth:r=Ig,frozenColumns:o=0,frozenRows:s=0,frozenTrailingColumns:l=0,frozenTrailingRows:c=0,tapScrollCircleOptions:u,renderCell:h,onSelectionChange:m,onCellContextMenu:y,onUndoRequest:_,onRedoRequest:j,onCopyMultiRange:L,onOperationRejected:I,onEditRejected:Y,onReadOnlyRejected:B,formatReadOnlyAnnouncement:T,dataVersion:A,maxOperationCells:P=jg,enableFillHandle:S=!0,enableResizeUI:R=!0,formatCellAnnouncement:E,formatSelectionAnnouncement:f,formatCommandAnnouncement:g,labels:b,shortcuts:$,colors:x,formats:k,highlight:w,defaultHighlight:v,onHighlightChange:a,highlightColors:p,popovers:M,renderPopover:d,onClipChange:F,onHyperlinkOpen:O,onValidationRejected:D,onPasteSpecialRequest:N,onClipboardUnavailable:W,onPasteResolved:V,now:G=Date.now,zoom:Z,defaultZoom:ee,onZoomChange:ie,testId:oe,className:Te,__onCellRender:qe,__onVirtualKeyboardRaise:De},_e){const de=si(t.rowCount,n),fe=si(t.colCount,r),Ze=i.useRef(null);Ze.current===null&&(Ze.current=Sh());const ve=Ze.current,Ht=i.useMemo(()=>kh(b),[b]),dr=i.useMemo(()=>Vp($),[$]),tn=i.useMemo(()=>({fill:wi("fill",x===void 0?void 0:x.fill),font:wi("font",x===void 0?void 0:x.font)}),[x]),ct=i.useMemo(()=>p===void 0?void 0:Wg(p),[p]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const Tn=i.useCallback(()=>ve.get().editVersion,[ve]),nn=i.useCallback(C=>ve.subscribeCoalesced(C),[ve]),rn=i.useSyncExternalStore(nn,Tn,Tn)+(A===void 0?0:A),on=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),ht=i.useMemo(()=>({index:on===null?null:aa(on),memo:gs()}),[t,on,rn]),at=i.useRef(ht.index);at.current=ht.index;const Et=i.useRef(ht.memo);Et.current=ht.memo;const Je=i.useCallback((C,U,Q)=>ws(t,at.current,Et.current,C,U,Q),[t]),Ie=i.useRef(null),[Mn,fr]=i.useState(()=>zo(ee??1)),We=zo(Z??Mn),Me=i.useRef(We);Me.current=We;const xt=i.useRef(We);xt.current=We;const $n=i.useRef(null),pr=i.useRef(ie);pr.current=ie;const hr=i.useRef(Z!==void 0);hr.current=Z!==void 0;const At=i.useCallback(C=>{const U=zo(C);U!==xt.current&&(xt.current=U,hr.current||fr(U),pr.current?.(U))},[]),$e=t.rowCount===0||t.colCount===0,mr=!$e;i.useEffect(()=>{const C=Ie.current;if(!mr||C===null)return;const U=ne=>{ne.defaultPrevented||!ne.altKey||ne.ctrlKey||ne.metaKey||ne.shiftKey||ne.deltaY!==0&&(ne.preventDefault(),ne.stopPropagation(),!$n.current?.()&&At(No(xt.current,ne.deltaY<0?1:-1)))},Q=ne=>{if(ne.defaultPrevented||!(ne.ctrlKey&&ne.altKey)||ne.metaKey||ne.getModifierState("AltGraph"))return;const Re=ne.key==="="||ne.key==="+"?No(xt.current,1):ne.key==="-"?No(xt.current,-1):ne.key==="0"?1:null;Re!==null&&(ne.preventDefault(),ne.stopPropagation(),!$n.current?.()&&At(Re))};return C.addEventListener("wheel",U,{passive:!1,capture:!0}),C.addEventListener("keydown",Q,!0),()=>{C.removeEventListener("wheel",U,{capture:!0}),C.removeEventListener("keydown",Q,!0)}},[At,mr]);const z=i.useRef(null),q=i.useRef(null),X=i.useRef(null),H=i.useRef(null),J=i.useRef(0),re=i.useRef(null),ce=i.useRef(0),ye=i.useRef(null),ge=i.useRef(null),Ne=i.useRef(null),Le=i.useRef(null),Pe=i.useRef(null),Fe=i.useRef(null),te=i.useRef(null),[ue,he]=i.useState(zr),ae=i.useRef(ue),se=i.useCallback(()=>ae.current,[]),[Ce,be]=i.useState(()=>v===void 0?Vg:v),Se=w!==void 0?w:Ce,Qe=i.useRef(Se);Qe.current=Se;const ut=Kg(ct,Se),dt=i.useRef(w!==void 0);dt.current=w!==void 0;const Ot=i.useRef(a);Ot.current=a;const Bt=i.useCallback(C=>{dt.current||be(C),Ot.current?.(C)},[]),sn=i.useRef(null),mt=i.useRef(null),et=i.useRef(null),Fn=i.useRef(()=>!1),ys=i.useRef(()=>{}),bs=i.useRef(()=>null),vs=i.useRef(()=>{}),Vt=i.useCallback(()=>Fn.current(),[]),eo=i.useMemo(()=>({getPointing:()=>Fn.current(),insertReference:(C,U)=>ys.current(C,U)}),[]),Rs=i.useRef(vt),ks=i.useRef(null),Ss=i.useRef({interactive:null,tip:null}),Es=i.useRef(null),xs=i.useRef(null),gr=i.useRef(()=>{}),As=i.useRef(()=>!1),ln=i.useRef(null),zn=i.useCallback(()=>{const C=ln.current;if(C===null||C.isOpen()!=="message")return!1;const U=C.context;return U===null||U.kind!=="message"||!U.current.rejected?!1:(C.close(),!0)},[]),to=i.useRef(()=>!1),Os=i.useRef(()=>!1),Ts=i.useRef(null),no=i.useRef(()=>Promise.resolve("rejected")),Ee=i.useCallback(()=>{sn.current?.()},[]),Ae=i.useCallback(C=>{X.current?.focus(C)},[]),ro=i.useRef(!1),ya=i.useCallback(()=>{const C=Ie.current;if(C!==null){ro.current=!0;try{C.focus()}finally{ro.current=!1}}},[]),Ke=i.useCallback(()=>{const C=X.current;C!==null&&(C.value=" ",C.setSelectionRange(0,1))},[]),cn=i.useCallback((C,U)=>{if(C===null)return;const Q=U?"":"none";C.style.display!==Q&&(C.style.display=Q)},[]),tt=i.useCallback(()=>{const C=H.current;if(C!==null){const Q=Math.max(0,q.current?.getScrollPosition().y??0),ne=q.current?.getFrozenSize().height??0;C.style.transform=`translateY(${J.current-Q-ne}px)`}const U=q.current;if(U!==null&&(Pe.current!==null||Fe.current!==null)){const Q=U.getFrozenSize();cn(Pe.current,Q.height>0),cn(Fe.current,Q.trailingHeight>0)}},[cn]),nt=i.useCallback(()=>{const C=re.current;if(C!==null){const Q=Math.max(0,q.current?.getScrollPosition().x??0),ne=q.current?.getFrozenSize().width??0;C.style.transform=`translateX(${ce.current-Q-ne}px)`}const U=q.current;if(U!==null&&(Ne.current!==null||Le.current!==null)){const Q=U.getFrozenSize();cn(Ne.current,Q.width>0),cn(Le.current,Q.trailingWidth>0)}},[cn]),Nn=i.useRef(null),an=i.useCallback(()=>{Ne.current===null&&Le.current===null&&Pe.current===null&&Fe.current===null||Nn.current===null&&(Nn.current=requestAnimationFrame(()=>{Nn.current=null,tt(),nt(),Ee()}))},[tt,nt,Ee]);i.useEffect(()=>()=>{Nn.current!==null&&cancelAnimationFrame(Nn.current)},[]);const oo=i.useRef(null),so=i.useRef(null);(oo.current===null||so.current?.rowAxis!==de||so.current?.colAxis!==fe)&&(so.current={rowAxis:de,colAxis:fe},oo.current=hg({handleRef:q,rowAxis:de,colAxis:fe}));const Tt=i.useCallback(C=>{oo.current?.(C)},[]),un=i.useRef(null),Wt=i.useRef(null),dn=i.useCallback(C=>{un.current!==null&&window.clearTimeout(un.current),Wt.current!==null&&(cancelAnimationFrame(Wt.current),Wt.current=null),un.current=window.setTimeout(()=>{un.current=null;const U=te.current;U!==null&&(U.textContent="",Wt.current=requestAnimationFrame(()=>{Wt.current=null,U.textContent=C}))},Hg)},[]);i.useEffect(()=>()=>{un.current!==null&&window.clearTimeout(un.current),Wt.current!==null&&cancelAnimationFrame(Wt.current)},[]);const fn=i.useCallback(C=>{B?.(C),T!==void 0&&dn(T(C))},[B,T,dn]),Ds=i.useCallback((C,U)=>{if(E===void 0&&f===void 0)return;const Q=U.ranges[U.ranges.length-1],ne=Ge(Q),Re=U.ranges.length===1&&ne.rows===1&&ne.cols===1,xe=C.ranges[C.ranges.length-1],mo=C.ranges.length!==U.ranges.length||xe.startRow!==Q.startRow||xe.startCol!==Q.startCol||xe.endRow!==Q.endRow||xe.endCol!==Q.endCol,tl=()=>{if(E!==void 0){const Ct=U.active,go=t.getCellText(Ct.row,Ct.col),nl=t.getCellFormat===void 0?void 0:Je(Ct.row,Ct.col,()=>go);dn(E({row:Ct.row,col:Ct.col,text:go,displayText:En(go,nl===void 0?void 0:nl.value),columnName:Jn(Ct.col),...bc(t)?{readOnly:je(t,Ct.row,Ct.col)}:{}}))}};if(Re){tl();return}if(mo){f!==void 0&&dn(f({range:Q,anchor:U.anchor,active:U.active,rangeRowCount:ne.rows,rangeColCount:ne.cols,rangeCount:U.ranges.length}));return}tl()},[t,E,f,dn,Je]),Ye=i.useCallback(C=>{const U=ae.current;Object.is(C,U)||ug(C,U)||(ae.current=C,he(C),m?.(C),Ds(U,C),(et.current?.()??!1)||Ke())},[m,Ds,Ke]),ba=i.useCallback(C=>{const U=ae.current;if(C.mode==="cycle"){const ne=ha(U,C.direction);Ye(ne),Tt(ne.active);return}const Q=ir(C.cell,de.count,fe.count);if(C.mode==="extend"){Ye(Zt(U,Q)),Tt(Q);return}Ye(nr(U,Q,{extend:!1,append:!1})),Tt(Q)},[Ye,Tt,de,fe]),He=i.useCallback(()=>et.current?.()??!1,[]),Ms=i.useRef(null),rt=i.useCallback(()=>Ms.current?.()??!0,[]),$s=i.useRef(null),Ln=i.useCallback((C,U)=>{const Q=et.current?.()??!1;$s.current?.(C,U),!Q&&(et.current?.()??!1)&&zn()},[zn]),[va,lo]=i.useState(!1),Fs=i.useCallback(()=>{De?.(),lo(!0)},[De]),Ra=i.useCallback((C,U)=>{je(t,C.row,C.col)||Fs(),Ln("edit",U)},[t,Fs,Ln]),zs=i.useRef(null),Ns=i.useCallback(()=>zs.current?.()??null,[]),Ls=i.useRef(null),Dt=i.useCallback(()=>{Ls.current?.()},[]),Ps=i.useRef(null),qs=i.useCallback(C=>{Ps.current?.(C)},[]),_s=i.useRef(()=>{}),wr=i.useRef(0),Kt=i.useCallback((C,U,Q)=>{let ne;if(U.source==="paste"){const Re=Yg(Q);if(C.length===0&&Re.conditionalFormats.length===0)return null;wr.current+=1,ne={transaction:wr.current,source:"paste",sameSheet:Re.sameSheet,conditionalFormats:Re.conditionalFormats}}else{if(C.length===0)return null;wr.current+=1,ne={transaction:wr.current,source:U.source}}try{t.applyEdits(C,ne)}catch(Re){return Y?.(Re,U),null}return ve.bumpEdit(),qs(U.source),ne.transaction},[t,ve,Y,qs]),ka=i.useCallback((C,U)=>Kt(C,{source:"paste"},U),[Kt]),Sa=i.useCallback(C=>{ve.setVy(C.y),tt(),nt(),Ee()},[ve,tt,nt,Ee]),Is=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Ea=i.useCallback(C=>{ve.setRowRange(C.renderingRowStart,C.renderingRowEnd),ve.setColRange(C.renderingColStart,C.renderingColEnd);const U=Is.current;(U.rowStart!==C.renderingRowStart||U.rowEnd!==C.renderingRowEnd||U.colStart!==C.renderingColStart||U.colEnd!==C.renderingColEnd)&&(Is.current={rowStart:C.renderingRowStart,rowEnd:C.renderingRowEnd,colStart:C.renderingColStart,colEnd:C.renderingColEnd},Ee())},[ve,Ee]),js=i.useRef(()=>"add"),Mt=i.useCallback(C=>{mt.current?.(C,js.current())},[]),xa=i.useCallback(C=>{mt.current?.(C,"point")},[]),Hs=i.useRef(null),io=i.useCallback(C=>{Hs.current?.(C)},[]),Bs=i.useRef(null),Aa=i.useCallback(C=>{Bs.current?.(C)},[]),Vs=i.useRef(null),co=i.useCallback((C,U)=>{if(U.length===0)return;const Q=q.current;if(C==="col"){for(const ne of U){const Re=Math.round(ne.size);fe.resize(ne.index,Re),Q?.updateColSize(ne.index,Re)}ve.bumpColVersion(),nt(),Ee(),an();return}for(const ne of U){const Re=Math.round(ne.size);de.resize(ne.index,Re),Q?.updateRowSize(ne.index,Re)}ve.bumpRowGeometry(),tt(),Ee(),an()},[de,fe,ve,nt,tt,Ee,an]),Oa=i.useCallback((C,U)=>{y?.(C,{kind:"pointer",event:U})},[y]),Ta=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:Mt,axis:"both",zoomRef:Me}),Da=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:Mt,axis:"x",zoomRef:Me}),Ma=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:Mt,axis:"y",zoomRef:Me}),$a=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:io,axis:"x",zoomRef:Me}),Fa=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:io,axis:"y",zoomRef:Me}),za=hn({handleRef:q,rowAxis:de,colAxis:fe,bodyRef:z,onDragFrame:Mt,axis:"both",zoomRef:Me}),Ws=i.useRef(null),Ks=i.useRef(()=>!1),ao=i.useCallback(()=>Ks.current(),[]),gt=Ng({zoomRef:Me,enabled:!$e,rowAxis:de,colAxis:fe,handleRef:q,bodyRef:z,isEditing:He,requestCommit:rt,getSelection:se,setSelection:Ye,focusSink:Ae,onDragFrame:Mt,onContextMenuSelect:Oa,onRequestEdit:Ra,caretFromPointEnabled:C=>{if(h!==void 0||t.getCellFormula!==void 0&&t.getCellFormula(C.row,C.col)!==void 0)return!1;if(t.getCellFormat===void 0)return!0;const U=t.getCellText(C.row,C.col);return En(U,t.getCellFormat(C.row,C.col)?.value)===U},isAnyDragging:ao,autoScroller:Ta,repaintOverlay:Ee,pointDragRef:Ws,getPointing:Vt,openHyperlinkAt:O===void 0||t.getCellHyperlink===void 0?void 0:C=>{const U=t.getCellHyperlink===void 0?void 0:On(t.getCellHyperlink(C.row,C.col));return U===void 0?!1:(O(U,C),!0)}}),$t=hi({zoomRef:Me,enabled:!$e,axis:"col",headerRef:ye,mainAxis:fe,crossCount:t.rowCount,handleRef:q,isEditing:He,requestCommit:rt,getSelection:se,setSelection:Ye,focusSink:Ae,onDragFrame:Mt,autoScroller:Da,repaintOverlay:Ee,pointing:eo}),Ft=hi({zoomRef:Me,enabled:!$e,axis:"row",headerRef:ge,mainAxis:de,crossCount:t.colCount,handleRef:q,isEditing:He,requestCommit:rt,getSelection:se,setSelection:Ye,focusSink:Ae,onDragFrame:Mt,autoScroller:Ma,repaintOverlay:Ee,pointing:eo}),zt=ag({zoomRef:Me,enabled:!$e&&R,colBandRef:ye,rowBandRef:ge,colAxis:fe,rowAxis:de,viewStore:ve,handleRef:q,isEditing:He,requestCommit:rt,focusSink:Ae,getSelection:se,adapter:t,autofitEnabled:h===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:P,onOperationRejected:I,resizeTracks:co,writeResizeGuide:Aa,repaintOverlay:Ee,isPointing:Vt}),wt=kg({zoomRef:Me,enabled:!$e&&S,handleNodeRef:Vs,bodyRef:z,rowAxis:de,colAxis:fe,handleRef:q,getSelection:se,setSelection:Ye,focusSink:Ae,adapter:t,commitEdits:Kt,maxOperationCells:P,onOperationRejected:I,rejectReadOnly:fn,writeFillPreview:io,repaintOverlay:Ee,xAutoScroller:$a,yAutoScroller:Fa}),ft=Lg({zoomRef:Me,enabled:!$e,bodyRef:z,handleRef:q,rowAxis:de,colAxis:fe,getPointing:Vt,insertReference:eo.insertReference,captureSink:()=>bs.current(),restoreSink:C=>vs.current(C),focusSink:Ae,autoScroller:za,onDragFrame:Mt});Ws.current=ft;const Pn=i.useCallback(()=>gt.isDragging()||$t.isDragging()||Ft.isDragging()||zt.isDragging()||wt.isDragging()||ft.isDragging(),[gt,$t,Ft,zt,wt,ft]);$n.current=Pn,Ks.current=Pn,js.current=()=>ft.isDragging()?"point":gt.getDragMode();const Na=i.useCallback(()=>{gt.abortDrag(),$t.abortDrag(),Ft.abortDrag(),zt.abortDrag(),wt.abortDrag(),ft.abortDrag()},[gt,$t,Ft,zt,wt,ft]),uo=i.useCallback(()=>ae.current.active,[]),Ys=i.useCallback((C,U)=>{const Q=t.getCellValidation===void 0?void 0:t.getCellValidation(C.row,C.col);if(Q===void 0)return gi;const ne=t.evaluateFormula,Re=Nc(Q,U,ne===void 0?void 0:xe=>ne(xe,C));return Re.ok||Q.strict!==!0?gi:(D?.({cell:C,rule:Q,text:U,message:Re.message}),ln.current?.isKindEnabled("message")&&gr.current("message",{message:Re.message,rejected:!0}),Re)},[t,D]),ze=Em({enabled:!$e,sinkRef:X,rootRef:Ie,adapter:t,commitEdits:Kt,getActive:uo,ensureCellVisible:Tt,focusSink:Ae,rearmSink:Ke,discardClip:Dt,isDragging:ao,rejectReadOnly:fn,resolveEditAlign:C=>{if(t.getCellFormat===void 0)return null;const U=_r(t,C.row,C.col);return yc(Je(C.row,C.col,U),U)},resolveEditPaint:C=>t.getCellFormat===void 0?null:vd(Je(C.row,C.col,_r(t,C.row,C.col))),editPaintRef:Rs,repaintOverlay:Ee,validateCommit:Ys});et.current=ze.isEditing,Ms.current=ze.requestCommit,$s.current=ze.startEdit,Fn.current=ze.getPointing,ys.current=ze.insertReference,bs.current=ze.captureSink,vs.current=ze.restoreSink;const Us=i.useCallback(()=>{ze.cancelEdit(),zn()},[ze.cancelEdit,zn]),qn=lm({enabled:!$e,sinkRef:X,adapter:t,isEditing:He,getSelection:se,setSelection:Ye,commitPaste:ka,maxOperationCells:P,onOperationRejected:I,onCopyMultiRange:L,repaintOverlay:Ee,isDragging:ao,resize:{rowAxis:de,colAxis:fe,resizeTracks:co},pendingPasteOptionsRef:ks,formats:k,onClipChange:F,onClipboardUnavailable:W,onEditRejected:Y,rejectReadOnly:fn,onPasteResolved:V});zs.current=qn.getClip,Ls.current=qn.discardClip,Ps.current=qn.discardClipOnCommit,_s.current=qn.onAdapterSwitch,no.current=qn.paste;const _n=Fg({enabled:!$e,adapter:t,popovers:M,sinkRef:X,bodyRef:z,handleRef:q,rowAxis:de,colAxis:fe,zoomRef:Me,getActive:uo,isEditing:He,requestCommit:rt,focusSink:Ae,rearmSink:Ke,isDraggingAny:Pn,commitEdits:Kt,labels:Ht,onHyperlinkOpen:O,anchors:Ss,repaintOverlay:Ee,rejectReadOnly:fn});ln.current=_n,gr.current=_n.open,As.current=_n.hideTip;const La=i.useCallback(()=>{const C=ae.current.active;Tt(C);const U=q.current,Q=U===null?{x:0,y:0}:U.getScrollPosition(),ne=U===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:U.getFrozenSize(),Re=U===null?{width:0,height:0}:U.getViewportSize(),xe=Me.current;return{top:Qt(de,C.row,{scroll:Math.max(0,Q.y),frozenCount:ne.rows,trailingCount:ne.trailingRows,extent:Re.height})*xe,left:Jt(fe,C.col,{scroll:Math.max(0,Q.x),frozenCount:ne.cols,trailingCount:ne.trailingCols,extent:Re.width})*xe,width:fe.sizeOf(C.col)*xe,height:de.sizeOf(C.row)*xe}},[de,fe,Tt]),fo=Rm({adapter:t,getSelection:se,commitEdits:Kt,getActive:uo,isEditing:He,requestCommit:rt,cancelEdit:Us,getSessionText:ze.getSessionText,validateCommit:Ys,insertAtCaret:ze.insertAtCaret,refreshEditPaint:ze.refreshPaint,maxOperationCells:P,onOperationRejected:I,colors:tn,formats:k,getHighlight:()=>Qe.current,setHighlight:Bt,popovers:M,openPopover:C=>gr.current(C),onHyperlinkOpen:O,onPasteSpecialRequest:N,paste:C=>no.current(C),rowAxis:de,colAxis:fe,resizeTracks:co,defaultRowHeight:n,defaultColumnWidth:r,now:G,announce:dn,formatCommandAnnouncement:g,keyboardCellRect:La,rejectReadOnly:fn});Ts.current=fo,to.current=fo.executeCommand,Os.current=fo.isCommandAvailable;const Pa=i.useMemo(()=>({table:dr,execute:C=>to.current(C),isAvailable:C=>Os.current(C)}),[dr]),qa=i.useCallback(()=>{Dt(),_?.()},[Dt,_]),_a=i.useCallback(()=>{Dt(),j?.()},[Dt,j]);bg({zoomRef:Me,enabled:!$e,sinkRef:X,rootRef:Ie,handOffFocusToRoot:ya,getSelection:se,setSelection:Ye,moveActive:ba,ensureCellVisible:Tt,isEditing:He,requestCommit:rt,startEdit:Ln,commitEdits:Kt,maxOperationCells:P,onOperationRejected:I,rejectReadOnly:fn,getClip:Ns,discardClip:Dt,isDragging:Pn,abortDrag:Na,findDataEdge:t.findDataEdge,getEditingMode:ze.getEditingMode,cancelEdit:Us,onUndoRequest:qa,onRedoRequest:_a,onCellContextMenu:y,rowAxis:de,colAxis:fe,handleRef:q,rearmSink:Ke,commands:Pa,pointing:ze,adapter:t,hideNoteTip:()=>As.current(),closeRejectedMessage:zn,pendingPasteOptionsRef:ks,onPointFrame:xa});const Ia=ue.active.row,ja=ue.active.col;i.useLayoutEffect(()=>{const C=ln.current;C!==null&&(C.syncTipAriaDescribedBy(),C.isKindEnabled("message")&&(C.isOpen()==="message"&&C.close(),C.open("message")))},[Ia,ja]),i.useLayoutEffect(()=>{Ee()},[Ee,Se.row,Se.column,Se.intersection]);const Ha=i.useCallback(C=>{(et.current?.()??!1)||(C.preventDefault(),Ae(),Ke())},[Ae,Ke]),Ba=i.useCallback(C=>{const U=Ie.current,Q=C.relatedTarget;if(U!==null&&Q instanceof Node&&U.contains(Q)){C.target===U&&Q===X.current&&!ro.current&&Ae();return}(et.current?.()??!1)||(Ae(),Ke())},[Ae,Ke]),Va=i.useCallback(C=>{const U=Ie.current,Q=C.relatedTarget;U!==null&&Q instanceof Node&&U.contains(Q)||ze.isFocusoutSuppressed()||lo(!1)},[ze]),Cr=i.useRef(null),In=i.useCallback(()=>{const C=Cr.current;C!==null&&(Cr.current=null,window.removeEventListener("pointerup",C.up,!0),window.removeEventListener("pointercancel",C.cancel,!0))},[]),po=i.useCallback(()=>{if(Cr.current!==null)return;const C=Q=>{Q.pointerType==="mouse"&&(In(),Q.button===1&&Q.preventDefault())},U=Q=>{Q.pointerType==="mouse"&&In()};Cr.current={up:C,cancel:U},window.addEventListener("pointerup",C,!0),window.addEventListener("pointercancel",U,!0)},[In]);i.useEffect(()=>In,[In]),i.useEffect(()=>{const C=Ie.current;if($e||C===null)return;let U=0;const Q=xe=>{if(xe.pointerType!=="mouse"){(et.current?.()??!1)||lo(!1);return}U=xe.buttons,xe.button===1&&(xe.target===X.current&&(et.current?.()??!1)||po())},ne=xe=>{xe.pointerType==="mouse"&&(U=xe.buttons)},Re=xe=>{if(xe.pointerType!=="mouse"||xe.buttons===U)return;const mo=xe.buttons&~U;U=xe.buttons,xe.preventDefault(),(mo&4)!==0&&po()};return C.addEventListener("pointerdown",Q,!0),C.addEventListener("pointerup",ne,!0),C.addEventListener("pointermove",Re,!0),()=>{C.removeEventListener("pointerdown",Q,!0),C.removeEventListener("pointerup",ne,!0),C.removeEventListener("pointermove",Re,!0)}},[$e,po]);const Wa=i.useCallback(C=>{if(!(C.target!==C.currentTarget||C.pointerType!=="mouse")&&(C.preventDefault(),C.button===0)){if(Vt()){Ae();return}if(He()&&!rt()){Ae();return}Ae()}},[Ae,He,rt,Vt]),ho=i.useRef(!1);i.useLayoutEffect(()=>{if($e){ho.current=!1;return}if(ho.current)return;ho.current=!0,Ke();const C=(Ie.current?.clientHeight??0)/Me.current;C>0&&de.totalSize()>0&&ve.setRowRange(0,de.indexAt(Math.min(C-1,de.totalSize()-1)));const U=(Ie.current?.clientWidth??0)/Me.current;U>0&&fe.totalSize()>0&&ve.setColRange(0,fe.indexAt(Math.min(U-1,fe.totalSize()-1)))},[$e,Ke,ve,de,fe]);const Xs=i.useRef(t);i.useLayoutEffect(()=>{Xs.current!==t&&(Xs.current=t,gt.cancelDrag(),$t.cancelDrag(),Ft.cancelDrag(),zt.cancelDrag(),wt.cancelDrag(),ft.cancelDrag(),ze.cancelEdit(),ln.current?.hideTip(),ln.current?.close(),$e?(ae.current=zr,he(zr)):Ye(zr),_s.current())},[t,$e,Ye,gt,$t,Ft,zt,wt,ft,ve,ze.cancelEdit]);const Gs=i.useRef(o),Zs=i.useRef(s),Js=i.useRef(l),Qs=i.useRef(c);i.useLayoutEffect(()=>{(Gs.current!==o||Zs.current!==s||Js.current!==l||Qs.current!==c)&&(Gs.current=o,Zs.current=s,Js.current=l,Qs.current=c,gt.cancelDrag(),$t.cancelDrag(),Ft.cancelDrag(),zt.cancelDrag(),wt.cancelDrag(),ft.cancelDrag())},[o,s,l,c,gt,$t,Ft,zt,wt,ft]),i.useLayoutEffect(()=>{tt(),nt(),Ee()},[o,s,l,c,tt,nt,Ee]);const el=i.useRef(A);i.useLayoutEffect(()=>{el.current!==A&&(el.current=A,Dt())},[A,Dt]),i.useLayoutEffect(()=>{Ee()},[Ee,ue]);const Yt=i.useCallback(()=>{const C=Ts.current;if(C===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return C},[]);if(i.useImperativeHandle(_e,()=>({resizeRow:(C,U)=>{const Q=Math.round(U);de.resize(C,Q),q.current?.updateRowSize(C,Q),ve.bumpRowGeometry(),tt(),Ee(),an()},resizeColumn:(C,U)=>{const Q=Math.round(U);fe.resize(C,Q),q.current?.updateColSize(C,Q),ve.bumpColVersion(),nt(),Ee(),an()},scrollToCell:(C,U)=>{q.current?.scrollToCell(C.row,C.col,U)},focus:C=>{Ae(C),He()||Ke()},executeCommand:C=>to.current(C),applyFormat:C=>Yt().applyFormat(C),setBorders:(C,U)=>Yt().setBorders(C,U),setHyperlink:C=>Yt().setHyperlink(C),setNote:C=>Yt().setNote(C),addComment:C=>Yt().addComment(C),setValidation:C=>Yt().setValidation(C),paste:C=>no.current(C),getSelection:()=>ae.current,getBaseFormat:C=>t.getCellFormat===void 0?void 0:t.getCellFormat(C.row,C.col),getPaintedFormat:C=>t.getCellFormat===void 0?void 0:Je(C.row,C.col,_r(t,C.row,C.col)),startEdit:C=>{Ln(C)},openPopover:C=>{gr.current(C)}}),[de,fe,ve,nt,tt,Ee,an,Ae,He,Ke,t,Je,Ln,Yt]),$e)return K.jsx("div",{className:Te?`aqsp-root ${Te}`:"aqsp-root","data-aqsp-empty":"","data-testid":oe});const Ka=E!==void 0||f!==void 0||g!==void 0||T!==void 0;return K.jsx("div",{ref:Ie,className:Te?`aqsp-root ${Te}`:"aqsp-root",role:"group","aria-label":Ht.rootAriaLabel,tabIndex:0,onFocus:Ba,onBlur:Va,"data-aqsp-root":"","data-testid":oe,children:K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":We,onPointerDown:Wa,style:We===1?void 0:{width:`${100/We}%`,height:`${100/We}%`,transform:`scale(${We})`},children:[K.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:C=>{if(C.pointerType==="mouse"&&(C.preventDefault(),C.button===0)){if(Vt()){Ae();return}if(He()&&!rt()){Ae();return}Ae(),Ye({ranges:[me({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(og,{viewStore:ve,colAxis:fe,frozenCols:o,frozenTrailingCols:l,handleRef:q,bandRef:ye,colTrackRef:re,windowOriginXRef:ce,repaintColHeaders:nt,selectionRanges:ue.ranges,enableResizeUI:R,dividerLeadingRef:Ne,dividerTrailingRef:Le}),K.jsx(sg,{viewStore:ve,rowAxis:de,handleRef:q,bandRef:ge,selectionRanges:ue.ranges,rowTrackRef:H,windowOriginYRef:J,repaintHeaders:tt,enableResizeUI:R,frozenRows:s,frozenTrailingRows:c,dividerLeadingRef:Pe,dividerTrailingRef:Fe}),K.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(rg,{adapter:t,rowAxis:de,colAxis:fe,viewStore:ve,handleRef:q,bodyRef:z,dataVersion:A,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,frozenTrailingColumns:l,frozenTrailingRows:c,tapScrollCircleOptions:u,renderCell:h,onScroll:Sa,onRangeChange:Ea,focusSink:Ae,isEditing:He,requestCommit:rt,testId:oe?`${oe}-vs`:void 0,__onCellRender:qe,cfIndexRef:at,cfMemoRef:Et,isPointing:Vt}),K.jsx(zh,{rowAxis:de,colAxis:fe,handleRef:q,sinkRef:X,getSelection:se,editing:ze.editing,virtualKeyboard:va,repaintRef:sn,dragFrameRef:mt,getClip:Ns,getIsDraggingAny:Pn,getIsFillDragging:wt.isDragging,fillFrameRef:Hs,resizeGuideFrameRef:Bs,fillHandleNodeRef:Vs,enableFillHandle:S,frozenCols:o,frozenRows:s,trailingCols:l,trailingRows:c,sinkAriaLabel:Ht.sinkAriaLabel,onSinkMouseDown:Ha,editPaintRef:Rs,highlightRef:Qe,highlightColors:ut,popoverAnchors:Ss,interactiveAnchorRef:Es,tipAnchorRef:xs}),_n.layerEnabled?K.jsx(Dg,{controller:_n,labels:Ht,renderPopover:d,interactiveAnchorRef:Es,tipAnchorRef:xs}):null]}),Ka?K.jsx("div",{ref:te,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=ts;exports.CommentPopover=Kc;exports.DEFAULT_CUSTOM_COLORS=Ca;exports.DEFAULT_HIGHLIGHT_COLORS=Vc;exports.DEFAULT_LABELS=Xo;exports.DEFAULT_SHORTCUTS=$c;exports.LinkPopover=Yc;exports.ListPopover=Uc;exports.MessagePopover=Xc;exports.NotePopover=Gc;exports.NoteTip=Zc;exports.SPREADSHEET_RESERVED_SHORTCUTS=_p;exports.Spreadsheet=Ug;exports.canonicalizeFormat=it;exports.columnIndexToName=Jn;exports.columnNameToIndex=Mp;exports.detectClipSource=Ai;exports.enumerateRangeCells=Lt;exports.estimatePasteCellCount=kp;exports.expandPaste=Sp;exports.formatCellValue=En;exports.formatEquals=nu;exports.fromR1C1=lr;exports.makeRange=me;exports.mergeFormat=rs;exports.normalizeHyperlink=jt;exports.parseChord=Gt;exports.parseClipPayload=qo;exports.parseHtmlTable=Cc;exports.parseTsv=Oc;exports.rangeContains=en;exports.rangeSize=Ge;exports.resolveLabel=Oe;exports.serializeClipPayload=Si;exports.serializeHtmlTable=hc;exports.serializeTsv=Ec;exports.shiftFormula=Zi;exports.toR1C1=Gr;exports.validateCellText=Nc;
|