@aiquants/spreadsheet 0.17.3 → 0.18.1
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 +82 -0
- package/README.md +48 -4
- package/dist/index.cjs +8 -8
- package/dist/index.d.cts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +4130 -4004
- package/dist/styles/spreadsheet.css +1 -1
- package/dist/styles/spreadsheet.standalone.css +1 -1
- package/package.json +1 -1
- package/src/Spreadsheet.tsx +57 -2
- package/src/overlay/SelectionOverlay.tsx +627 -24
- package/src/styles/spreadsheet.css +48 -0
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const qt=require("./tsv.cjs"),Te=require("./view-BkwCUzTl.cjs"),Je=require("@aiquants/virtualscroll"),Y=require("react/jsx-runtime"),i=require("react"),ys=1e3,on=1e4,Rs=10,zl=2**(1/4),Nu=(e,t)=>e<=0?e:t>0?e>=on?e:Math.min(on,Math.max(e+1,Math.round(e*zl))):Math.max(1,Math.min(e-1,Math.round(e/zl))),Nl=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),vs=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/Rs):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const u of t){if(!(Number.isFinite(u.size)&&u.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${u.size} at index ${u.index}`);s.set(u.index,Math.min(Math.round(u.size),on))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Nl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Nl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},Ss="#000000",zr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Fu=20,Pu=256,Nr=new Map,_o=new WeakMap,ot=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},_u=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},qu=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Fu}:zr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...zr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...zr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...zr(e.decimals)};default:return null}},Iu=e=>{const t=_o.get(e);if(t!==void 0)return t;const n=JSON.stringify([e.type,e.locale??null,e.decimals===void 0?null:String(e.decimals),e.type==="number"?e.grouping??!1:null,e.type==="currency"?e.currency:null]),r=Nr.get(n);if(r!==void 0)return _o.set(e,r),r;Nr.size>=Pu&&Nr.clear();const o=qu(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Nr.set(n,s),_o.set(e,s),s},ju=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},ec=e=>{const t=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>ju(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Hu=(e,t)=>{const n=ec(e);if(n===null)return e;const r=(o,s)=>String(o).padStart(s,"0");return t.replace(/yyyy|MM|dd|HH|mm|ss/g,o=>{switch(o){case"yyyy":return r(n.year,4);case"MM":return r(n.month,2);case"dd":return r(n.day,2);case"HH":return r(n.hour,2);case"mm":return r(n.minute,2);default:return r(n.second,2)}})},Wn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return Hu(e,t.pattern??"yyyy/MM/dd");const n=ot(e);if(n===null)return e;const r=Iu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?_u(n,-2):n)},Fl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?ec(n)!==null?"right":"left":ot(n)!==null?"right":"left",fr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",tc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Bu=["bottom","left","right","top"],nc=(e,t,n)=>{e[t]=n},rc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Vu=e=>{if(e===void 0)return;const t={};for(const n of Bu){const r=e[n];r!==void 0&&(t[n]=rc(r))}return Object.keys(t).length===0?void 0:t},gt=e=>{const t={};for(const n of tc){const r=n==="borders"?Vu(e.borders):n==="value"?e.value===void 0?void 0:rc(e.value):e[n];r!==void 0&&r!==!1&&nc(t,n,r)}return Object.keys(t).length===0?void 0:t},ks=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;const o=e,s=t;for(let l=0;l<n.length;l+=1){const c=n[l];if(c!==r[l]||!ks(o[c],s[c]))return!1}return!0},Wu=(e,t)=>e===t?!0:ks(e===void 0?void 0:gt(e),t===void 0?void 0:gt(t)),Es=(e,t)=>{const n={};for(const o of tc){const s=t[o];nc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=gt(n);return ks(r,e===void 0?void 0:gt(e))?e:r},oc="data-aqsp-clip",no="application/x-aqsp-clip",os=512,Pl=16*1024,ss=`${oc}=`,Ku=16,As=()=>{const e=globalThis.crypto;if(e===void 0||typeof e.getRandomValues!="function")throw new RangeError("[spreadsheet] newClipId requires crypto.getRandomValues — there is no counter or randomUUID substitute by design");const t=e.getRandomValues(new Uint8Array(Ku));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},br=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",Ge=e=>typeof e=="boolean",en=e=>typeof e=="number"&&Number.isFinite(e),mt=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,_l=e=>mt(e)&&e>=1,Yu=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=on,_t=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Uu=e=>t=>Array.isArray(t)&&t.every(e),$e=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),jt=(e,t)=>{if(!br(e))return!1;for(const n of Object.keys(e)){const r=e[n];if(r===void 0)continue;const o=t.fields.get(n);if(o===void 0||!o(r))return!1}for(const n of t.required)if(e[n]===void 0)return!1;return!0},Os=e=>t=>{if(!br(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&jt(t,n)},Xu=["left","center","right"],Gu=["top","middle","bottom"],Zu=["thin","medium","thick","dashed","dotted","double","hair"],qo=["gt","gte","lt","lte","eq","neq","between","notBetween"],Ju=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Qu=["eq","neq","gt","gte","lt","lte","between","notBetween"],ed=["contains","notContains","startsWith","endsWith"],td=new Map([["number",$e({type:ae,decimals:en,grouping:Ge,locale:ae},["type"])],["percent",$e({type:ae,decimals:en,scale:Ge,locale:ae},["type"])],["currency",$e({type:ae,currency:ae,decimals:en,locale:ae},["type","currency"])],["scientific",$e({type:ae,decimals:en,locale:ae},["type"])],["date",$e({type:ae,pattern:ae},["type"])],["text",$e({type:ae},["type"])]]),nd=$e({style:_t(Zu),color:ae},["style"]),Fr=e=>jt(e,nd),rd=$e({top:Fr,right:Fr,bottom:Fr,left:Fr},[]),od=$e({value:Os(td),align:_t(Xu),verticalAlign:_t(Gu),wrap:Ge,background:ae,color:ae,bold:Ge,italic:Ge,underline:Ge,strikethrough:Ge,fontFamily:ae,fontSize:en,borders:e=>jt(e,rd)},[]),sd=e=>jt(e,od),fn={strict:Ge,inputMessage:ae,errorMessage:ae},ld=new Map([["list",$e({...fn,type:ae,values:Uu(ae),showDropdown:Ge},["type","values"])],["number",$e({...fn,type:ae,op:_t(qo),a:ae,b:ae},["type","op","a"])],["textLength",$e({...fn,type:ae,op:_t(qo),a:en,b:en},["type","op","a"])],["date",$e({...fn,type:ae,op:_t(qo),a:ae,b:ae},["type","op","a"])],["text",$e({...fn,type:ae,op:_t(Ju),value:ae},["type","op"])],["checkbox",$e({...fn,type:ae,checked:ae,unchecked:ae},["type"])],["custom",$e({...fn,type:ae,formula:ae},["type","formula"])]]),id=Os(ld),cd=$e({startRow:mt,startCol:mt,endRow:mt,endCol:mt},["startRow","startCol","endRow","endCol"]),ad=e=>{if(!jt(e,cd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return mt(t)&&mt(r)&&mt(n)&&mt(o)&&t<=r&&n<=o},ud=$e({color:ae,value:en},["color"]),Io=e=>jt(e,ud),dd=new Map([["cellValue",$e({type:ae,op:_t(Qu),a:ae,b:ae},["type","op","a"])],["text",$e({type:ae,op:_t(ed),value:ae},["type","op","value"])],["empty",$e({type:ae},["type"])],["notEmpty",$e({type:ae},["type"])],["colorScale",$e({type:ae,min:Io,mid:Io,max:Io},["type","min","max"])],["customFormula",$e({type:ae,formula:ae},["type","formula"])]]),fd=$e({background:ae,color:ae,bold:Ge,italic:Ge,underline:Ge,strikethrough:Ge},[]),pd=$e({sourceRuleId:ae,ranges:Array.isArray,condition:Os(dd),style:e=>jt(e,fd),stopIfTrue:Ge},["sourceRuleId","ranges","condition","style"]),hd=(e,t,n)=>{if(!jt(e,pd))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!ad(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},md=$e({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),gd=e=>jt(e,md),wd=(e,t,n)=>{if(!br(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!mt(o)||o>=t)return!1;break;case"val":if(!mt(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(gd)))return!1;break;default:return!1}}return!0},ql=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Yu),Cd=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),sc=e=>{if(!br(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Cd.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(_l(t)&&_l(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(sd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(id)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const u of c)if(!wd(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!ql(e.colWidths,n)||e.rowHeights!==void 0&&!ql(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>hd(c,t,n))},gr=e=>Array.isArray(e)?`[${e.map(gr).join(",")}]`:br(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${gr(e[n])}`).join(",")}}`:JSON.stringify(e),bd=e=>{const t=gt(e);return t===void 0?"{}":JSON.stringify(t)},yd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Rd=e=>{let t=`{"t":${JSON.stringify(e.t)}`;return e.f!==void 0&&(t+=`,"f":${JSON.stringify(e.f)}`),e.fmt!==void 0&&(t+=`,"fmt":${e.fmt}`),e.val!==void 0&&(t+=`,"val":${e.val}`),e.note!==void 0&&(t+=`,"note":${JSON.stringify(e.note)}`),e.comments!==void 0&&(t+=`,"comments":[${e.comments.map(yd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},lc=e=>{if(!sc(e))throw new RangeError("[spreadsheet] serializeClipPayload received a payload outside the wire format v1 vocabulary");const t=`{"v":1,"rows":${e.rows},"cols":${e.cols},"clipId":${JSON.stringify(e.clipId)}`,n=e.formats.map(bd).join(","),r=e.validations.map(gr).join(","),o=e.cells.map(u=>`[${u.map(Rd).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(gr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},ls=e=>{let t;try{t=JSON.parse(e)}catch{return null}return sc(t)?t:null},vd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Sd=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),ic=e=>e.includes("&")?e.replace(vd,t=>Sd[t]):e,kd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Il=e=>{const t=e.length>os?e.slice(0,os):e,n=kd.exec(ic(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},Ed=e=>{const t=e.indexOf(ss);if(t===-1)return null;const n=t+ss.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},cc=(e,t)=>{if(t==="event"&&e.types.includes(no))return{kind:"mime",json:e.getData(no)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=Ed(n);return r===null?null:{kind:"attribute",html:n,at:r}},Ad=(e,t)=>{const n=cc(e,t);return n===null?null:n.kind==="mime"?Il(n.json):Il(n.html.slice(n.at.start,n.at.start+os))},Od=(e,t)=>{const n=cc(e,t);if(n===null)return null;if(n.kind==="mime")return ls(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:ls(ic(n.html.slice(n.at.start,r)))},xd=/<google-sheets-html-origin[\s>]/,Td='data-sheets-root="1"',$d=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Ld="mso-",Dd=/\.xl\d+\s*\{/,Md="<table",zd=e=>e.includes(ss)?"aqsp":xd.test(e)&&e.includes(Td)?"sheets":$d.test(e)||e.includes(Ld)||Dd.test(e)?"excel":null,ac=(e,t)=>{if(t==="event"&&e.types.includes(no))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Pl?n.slice(0,Pl):n,o=zd(r);if(o==="aqsp")return"aqsp";if(n.includes(Md))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},xs=1e3,uc=65534,Nd=9,Fd=10,Pd=12,_d=13,qd=32,dc=34,fc=39,Id=43,Ts=47,jl=48,jd=57,Hd=61,Bd=62,Vd=97,Wd=98,Kd=100,Yd=102,pc=104,hc=114,mc=116,Ud=["able","body","head","foot"],pr=e=>e===qd||e===Nd||e===Fd||e===_d||e===Pd,is=e=>e===Bd||e===Ts||pr(e),Xd=e=>pr(e)||e===Ts||e===dc||e===fc,Gd=(e,t,n,r)=>{if(t===0||!Xd(e.charCodeAt(t-1)))return null;let o=t+n;for(;pr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==Hd)return 1;for(o+=1;pr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===dc||s===fc)&&(o+=1);pr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Id&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=jl&&u<=jd;u=e.charCodeAt(o))l=l*10+(u-jl),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Hl=(e,t,n)=>{let r=e.indexOf(t);return(o,s)=>{for(;r!==-1&&r<o;)r=e.indexOf(t,r+t.length);for(;r!==-1&&r<s;r=e.indexOf(t,r+t.length)){const l=Gd(e,r,t.length,n);if(l!==null)return l}return 1}},Zd=(e,t)=>{if(e.charCodeAt(t+2)!==mc)return!1;const n=e.charCodeAt(t+3);if(n===hc)return is(e.charCodeAt(t+4));if(n!==Vd&&n!==Wd&&n!==pc&&n!==Yd)return!1;for(const r of Ud)if(e.startsWith(r,t+3)&&is(e.charCodeAt(t+3+r.length)))return!0;return!1},Jd=e=>{const t=e.toLowerCase(),n=Hl(t,"colspan",xs),r=Hl(t,"rowspan",uc);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,u=0,h=0,m=!1;const R=new Map,N=(_,U)=>{const W=R.get(_);R.set(_,W===void 0?U:W+U)},H=()=>{m&&u+h>c&&(c=u+h),m=!1},L=()=>{H(),l+=1,m=!0,u=0;const _=R.get(l-1);_!==void 0&&(h+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const U=t.charCodeAt(_+1);if(U===Ts){Zd(t,_)&&H();continue}if(U!==mc||!is(t.charCodeAt(_+3)))continue;const W=t.charCodeAt(_+2);if(W===hc)L();else if(W===Kd||W===pc){m||L();const k=_+3,x=s(k),z=n(k,x);u+=z;const I=r(k,x);I>1&&(N(l,z),N(l-1+I,-z))}}return H(),{rows:l,cols:c}},gc=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),l=n.get(s);if(l!==void 0)return l;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},wc=()=>{const e=new WeakMap,t=gc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=gt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Qd=()=>{const e=new WeakMap,t=gc(gr);return{intern:r=>{const o=e.get(r);if(o!==void 0)return o;const s=t.intern(r);return e.set(r,s),s},entries:t.entries}},ef=new Set(["http:","https:","mailto:","tel:"]),sn=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return ef.has(n.protocol)?n.href:null},Un=e=>{if(e===void 0)return;const t=sn(e);return t===null?void 0:t},Cc=(e,t)=>e.startCol===0&&e.endCol===t-1,bc=(e,t)=>e.startRow===0&&e.endRow===t-1,cs=13,Pt=Object.freeze({style:Object.freeze({}),lineBoxPx:cs,verticalAlign:"middle"}),tf={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:"#00000000"},nf=new Map(Object.entries(tf)),rf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,of=/^rgba?\((.*)\)$/,yc=/^(\d+(?:\.\d+)?)%$/,Pr=e=>e.toString(16).padStart(2,"0"),jo=e=>{const t=yc.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^\d+$/.test(e))return null;const n=Number(e);return n<=255?n:null},sf=e=>{const t=yc.exec(e);if(t!==null){const r=Number(t[1]);return r<=100?Math.round(r*255/100):null}if(!/^(?:\d+(?:\.\d+)?|\.\d+)$/.test(e))return null;const n=Number(e);return n<=1?Math.round(n*255):null},lf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=jo(t[0]),r=jo(t[1]),o=jo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Pr(n)}${Pr(r)}${Pr(o)}`;if(t.length===3)return s;const l=sf(t[3]);return l===null?null:l===255?s:`${s}${Pr(l)}`},Ze=e=>{const t=e.trim().toLowerCase(),n=rf.exec(t);if(n!==null){const s=n[1],l=s.length<=4?s.replace(/./g,c=>c+c):s;return l.length===8&&l.endsWith("ff")?`#${l.slice(0,6)}`:`#${l}`}const r=of.exec(t);if(r!==null)return lf(r[1]);const o=nf.get(t);return o===void 0?null:o},Bl={thin:{width:1,line:"solid"},medium:{width:2,line:"solid"},thick:{width:3,line:"solid"},dashed:{width:1,line:"dashed"},dotted:{width:1,line:"dotted"},double:{width:3,line:"double"},hair:{width:1,line:"dotted"}},Vl=e=>{if(!Object.hasOwn(Bl,e.style))return null;const t=Bl[e.style],n=e.color===void 0?Ss:Ze(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},cf={top:"flex-start",middle:"center",bottom:"flex-end"},af=e=>e==="left"||e==="center"||e==="right",Rc=e=>e==="top"||e==="middle"||e==="bottom",vc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Sc=(e,t)=>{if(typeof e.background=="string"){const s=Ze(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Ze(e.color);s!==null&&(t.color=s)}e.bold===!0&&(t.fontWeight="bold"),e.italic===!0&&(t.fontStyle="italic");const n=e.underline===!0,r=e.strikethrough===!0;(n||r)&&(t.textDecoration=n&&r?"underline line-through":n?"underline":"line-through"),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&(t.fontFamily=e.fontFamily);const o=vc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},_r=(e,t)=>{const n=e===void 0?null:Vl(e);return n!==null?n:t===void 0?null:Vl(t)},Ho=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(af(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=fr(e.align)),Rc(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=cf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Sc(e,s));const c=e?.borders,u=_r(c?.right,t);u!==null&&(s.borderRight=u);const h=_r(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=_r(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=_r(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Wl=new WeakMap,uf=(e,t,n,r,o)=>{const s=t?.borders?.left,l=n?.borders?.top,c=!(r||o)&&s===void 0&&l===void 0;if(e===void 0)return c?null:Ho(void 0,s,l,r,o);if(!c)return Ho(e,s,l,r,o);const u=Wl.get(e);if(u!==void 0)return u;const h=Ho(e,void 0,void 0,!1,!1);return Wl.set(e,h),h},df=e=>{if(e===void 0)return Pt;const t={};Sc(e,t);const n=vc(e.fontSize),r=n===null?cs:Math.round(n),o=Rc(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===cs&&o==="middle"?Pt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},ff="#REF!",pf=11,hf=15,mf=4096,Xr=33,hr=34,$s=36,gf=38,as=39,kc=40,wf=42,Cf=43,bf=44,Ec=45,yf=46,Rf=47,jn=58,vf=59,Sf=60,Ac=61,kf=62,Ef=67,Af=82,co=91,Oc=93,Of=94,xf=95,xc=e=>e>=65&&e<=90||e>=97&&e<=122,Tc=e=>e>=48&&e<=57,Ls=e=>xc(e)||Tc(e)||e===xf||e===yf||e===$s||e>=128,Tf=e=>e===32||e>=9&&e<=13||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279,$f=e=>e===Ac||e===kc||e===bf||e===vf||e===Cf||e===Ec||e===wf||e===Rf||e===Of||e===gf||e===Sf||e===kf||e===jn,$c=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Ls(n)||n===kc||n===Xr||n===co)},Kl=(e,t)=>{let n=t;for(;n<e.length&&Ls(e.charCodeAt(n));)n+=1;return n},us=(e,t,n)=>{let r=t+1;for(;r<e.length;){if(e.charCodeAt(r)===n){if(e.charCodeAt(r+1)===n){r+=2;continue}return r+1}r+=1}return e.length},Lf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===as){r+=2;continue}if(o===co)n+=1;else if(o===Oc&&(n-=1,n===0))return r+1;r+=1}return e.length},Yl=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&$c(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Lc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===hr){o=us(e,o,hr);continue}if(s===as){const u=us(e,o,as);o=e.charCodeAt(u)===Xr?Yl(e,o,u,t,n):u;continue}if(s===co){o=Lf(e,o);continue}if(!Ls(s)){o+=1;continue}const l=t(e,o);if(l!==null&&$c(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Kl(e,o);if(e.charCodeAt(c)===jn){const u=Kl(e,c+1);u>c+1&&e.charCodeAt(u)===Xr&&(c=u)}o=e.charCodeAt(c)===Xr?Yl(e,o,c,t,n):c}return n},Bo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===$s;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!xc(l))break;if(s+=1,s>pf)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},ds=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Tc(o))break;if(n-t>=hf)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},qr=(e,t)=>{const n=e.charCodeAt(t)===$s,r=ds(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Df=(e,t)=>{const n=Bo(e,t);if(n!==null){const o=qr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===jn){const s=Bo(e,o.end+1);if(s!==null){const l=qr(e,s.end);if(l!==null)return{end:l.end,token:{kind:"range",start:{row:o.index,col:n.col,absRow:o.abs,absCol:n.abs},end:{row:l.index,col:s.col,absRow:l.abs,absCol:s.abs}}}}}return{end:o.end,token:{kind:"cell",row:o.index,col:n.col,absRow:o.abs,absCol:n.abs}}}if(e.charCodeAt(n.end)===jn){const s=Bo(e,n.end+1);if(s!==null)return{end:s.end,token:{kind:"column",start:{col:n.col,abs:n.abs},end:{col:s.col,abs:s.abs}}}}return null}const r=qr(e,t);if(r!==null&&e.charCodeAt(r.end)===jn){const o=qr(e,r.end+1);if(o!==null)return{end:o.end,token:{kind:"row",start:{row:r.index,abs:r.abs},end:{row:o.index,abs:o.abs}}}}return null},yr=e=>Lc(e,Df),Dc=(e,t=mf)=>{if(!Number.isInteger(t)||t<=0)throw new RangeError(`[spreadsheet] createFormulaMemo requires a positive integer limit, received ${t}`);const n=new Map;return r=>{const o=n.get(r);if(o!==void 0)return o;n.size>=t&&n.clear();const s=e(r);return n.set(r,s),s}},fs=e=>{let t=e+1,n="";for(;t>0;){const r=(t-1)%26;n=String.fromCharCode(65+r)+n,t=Math.floor((t-1)/26)}return n},Vo=e=>`${e.absCol?"$":""}${fs(e.col)}${e.absRow?"$":""}${e.row+1}`,Ds=e=>e.sheet===void 0?"":`${e.sheet}!`,tn=e=>{const t=Ds(e);switch(e.kind){case"cell":return`${t}${Vo(e)}`;case"range":return`${t}${Vo(e.start)}:${Vo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${fs(e.start.col)}:${e.end.abs?"$":""}${fs(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Fn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Mf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Fn(n.startRow,"formatRangeReference startRow"),Fn(n.startCol,"formatRangeReference startCol"),Fn(n.endRow,"formatRangeReference endRow"),Fn(n.endCol,"formatRangeReference endCol"),t){case"columns":return tn({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return tn({kind:"row",start:{row:n.startRow,abs:!1},end:{row:n.endRow,abs:!1}});case"cells":return n.startRow===n.endRow&&n.startCol===n.endCol?tn({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):tn({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Ms=(e,t,n)=>{if(t.length===0)return e;let r="",o=0;for(const s of t){const l=n(s.token);r+=e.slice(o,s.start)+(l===null?`${Ds(s.token)}${ff}`:l),o=s.end}return r+e.slice(o)},ao=e=>e.charCodeAt(0)===Ac,Wo=(e,t,n)=>{const r=e.absRow?e.row:e.row+t,o=e.absCol?e.col:e.col+n;return r<0||o<0?null:{row:r,col:o,absRow:e.absRow,absCol:e.absCol}},zf=(e,t,n)=>{switch(e.kind){case"cell":{const r=Wo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Wo(e.start,t,n),o=Wo(e.end,t,n);return r===null||o===null?null:{...e,start:r,end:o}}case"column":{const r=e.start.abs?e.start.col:e.start.col+n,o=e.end.abs?e.end.col:e.end.col+n;return r<0||o<0?null:{...e,start:{col:r,abs:e.start.abs},end:{col:o,abs:e.end.abs}}}case"row":{const r=e.start.abs?e.start.row:e.start.row+t,o=e.end.abs?e.end.row:e.end.row+t;return r<0||o<0?null:{...e,start:{row:r,abs:e.start.abs},end:{row:o,abs:e.end.abs}}}}},Mc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return ao(e)?Ms(e,yr(e),r=>{const o=zf(r,t,n);return o===null?null:tn(o)}):e},zc=(e,t)=>{Fn(e.row,`${t} origin.row`),Fn(e.col,`${t} origin.col`)},Pn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,Ko=(e,t)=>`${Pn("R",e.row,e.absRow,t.row)}${Pn("C",e.col,e.absCol,t.col)}`,Nf=(e,t)=>{const n=Ds(e);switch(e.kind){case"cell":return`${n}${Ko(e,t)}`;case"range":return`${n}${Ko(e.start,t)}:${Ko(e.end,t)}`;case"column":return`${n}${Pn("C",e.start.col,e.start.abs,t.col)}:${Pn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Pn("R",e.start.row,e.start.abs,t.row)}:${Pn("R",e.end.row,e.end.abs,t.row)}`}},uo=(e,t)=>(zc(t,"toR1C1"),ao(e)?Ms(e,yr(e),n=>Nf(n,t)):e),Ul=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===co){const l=e.charCodeAt(o+1)===Ec,c=ds(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Oc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=ds(e,o);return s===null?{end:o,axis:{rel:!0,n:0}}:s.value===0?null:{end:s.end,axis:{rel:!1,n:s.value}}},Xl=(e,t)=>{const n=Ul(e,t,Af),r=Ul(e,n===null?t:n.end,Ef);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},Ff=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},Pf=(e,t)=>e.shape==="cell"&&t.shape==="cell"?{shape:"cell",start:e.cell,end:t.cell}:e.shape==="row"&&t.shape==="row"?{shape:"row",start:e.row,end:t.row}:e.shape==="column"&&t.shape==="column"?{shape:"column",start:e.col,end:t.col}:null,_f=(e,t)=>{const n=Xl(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===jn){const r=Xl(e,n.end+1);if(r!==null){const o=Pf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Ff(n)}},qf=e=>Lc(e,_f),If=Dc(qf),_n=(e,t)=>e.rel?t+e.n:e.n-1,Gl=(e,t)=>{const n=_n(e.row,t.row),r=_n(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},jf=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Gl(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Gl(e.end,t);return o===null?null:{kind:"range",start:r,end:o,...n}}case"row":{const r=e.end===null?e.start:e.end,o=_n(e.start,t.row),s=_n(r,t.row);return o<0||s<0?null:{kind:"row",start:{row:o,abs:!e.start.rel},end:{row:s,abs:!r.rel},...n}}case"column":{const r=e.end===null?e.start:e.end,o=_n(e.start,t.col),s=_n(r,t.col);return o<0||s<0?null:{kind:"column",start:{col:o,abs:!e.start.rel},end:{col:s,abs:!r.rel},...n}}}},Rr=(e,t)=>(zc(t,"fromR1C1"),ao(e)?Ms(e,If(e),n=>{const r=jf(n,t);return r===null?null:tn(r)}):e),Zl=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Hf=e=>{switch(e.kind){case"cell":return{...e,...Zl(e.absCol,e.absRow)};case"range":{const t=Zl(e.start.absCol,e.start.absRow);return{...e,start:{...e.start,...t},end:{...e.end,...t}}}case"column":{const t=!e.start.abs;return{...e,start:{col:e.start.col,abs:t},end:{col:e.end.col,abs:t}}}case"row":{const t=!e.start.abs;return{...e,start:{row:e.start.row,abs:t},end:{row:e.end.row,abs:t}}}}},Nc=(e,t)=>ao(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Fc=(e,t)=>{if(!Nc(e,t))return null;for(const n of yr(e))if(n.start<=t&&t<=n.end)return n;return null},Bf=(e,t)=>{const n=Fc(e,t);if(n===null)return null;const r=tn(Hf(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Jl=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===hr){const s=us(e,r,hr);if(s>t)return!1;n=hr,r=s;continue}Tf(o)||(n=o),r+=1}return $f(n)},Pc=(e,t)=>{if(!Nc(e,t))return null;for(const n of yr(e))if(n.start<=t&&t<=n.end)return Jl(e,n.start)?{replace:[n.start,n.end]}:null;return Jl(e,t)?{insertAt:t}:null},Kn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],fo=(e,t)=>`[$${e}-${t}]`,Vf=new Map(Kn.map(e=>[fo(e.symbol,e.lcid),e])),Wf=new Map(Kn.filter((e,t)=>Kn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Kn.map(e=>[fo(e.symbol,e.lcid),e.code]));const Kf=new Set([...Kn.map(e=>e.symbol),...Kn.map(e=>e.code),"¥"]),Yf=20,Uf="yyyy/MM/dd",_c=/yyyy|MM|dd|HH|mm|ss/g,qc=" -+/():!^&'~{}<>=",Xf="$¥€£₩₹¥",ps=e=>{let t="",n=0;for(;n<e.length;){const r=e[n];if(r!=="\\"){t+=r,n+=1;continue}const o=e.slice(n+1,n+5);if(/^[0-9a-fA-F]{4}$/.test(o)){t+=String.fromCharCode(Number.parseInt(o,16)),n+=5;continue}if(n+1<e.length){t+=e[n+1],n+=2;continue}t+=r,n+=1}return t},Gf=e=>{let t=0;for(;t<e.length;){const n=e[t];if(n==='"'){const r=e.indexOf('"',t+1);t=r<0?e.length:r+1}else if(n==="["){const r=e.indexOf("]",t+1);t=r<0?e.length:r+1}else if(n==="\\"||n==="_"||n==="*")t+=2;else{if(n===";")return e.slice(0,t);t+=1}}return e},Zf=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const R=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:R}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(qc.includes(o)||Xf.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},ht=e=>e===void 0?{}:{locale:e},Jf=/^(0|#,##0)(?:\.(0+))?$/,Ql=(e,t,n,r)=>{if(t!==null){const o=Vf.get(fo(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Kf.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...ht(r.locale)}},Qf=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const L of e)switch(L.kind){case"locale":break;case"literal":r?u+=L.text:c+=L.text;break;case"digits":if(r)return;n=L.text,r=!0;break;case"currency":if(o!==null)return;o=L;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=Jf.exec(n);if(h===null)return;const m=h[1]==="#,##0",R=h[2]===void 0?0:h[2].length,N=c.trim(),H=u.trim();if(s)return l===0&&o===null&&!m&&N===""&&H===""?{type:"scientific",decimals:R,...ht(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&H===""?{type:"percent",decimals:R,...ht(t.locale)}:void 0;if(H==="%"&&N===""&&o===null)return{type:"percent",decimals:R,scale:!1,...ht(t.locale)};if(o!==null)return N===""&&H===""?Ql(o.symbol,o.lcid,R,t):void 0;if(!(N!==""&&H!==""))return N!==""||H!==""?Ql(N+H,null,R,t):{type:"number",decimals:R,...m?{grouping:!0}:{},...ht(t.locale)}},ep=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),tp=(e,t)=>{const n=[...e.matchAll(_c)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},np=e=>{const t=e.flatMap(s=>s.kind==="date"?[s.text]:[]),n=[];let r="",o=0;for(const s of e){if(s.kind==="locale")continue;if(s.kind==="literal"){r+=s.text;continue}if(s.kind!=="date")return;const l=s.text==="mm"?t[o-1]==="hh"||t[o+1]==="ss"?"mm":"MM":ep.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&tp(r,n)?{type:"date",pattern:r}:void 0},rp=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...ht(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...ht(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...ht(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...ht(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...ht(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...ht(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),zs=(e,t)=>{const n=Gf(e).trim(),r=rp.get(n);if(r!==void 0)return r(t);const o=Zf(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return Qf(o,t);if(o.some(s=>s.kind==="date"))return np(o)}},op=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return}if(typeof n!="object"||n===null||Array.isArray(n))return;const r=n,o=r[1],s=r[2];if(typeof o!="number"||!Number.isInteger(o)||o<0||o>8||s!==void 0&&typeof s!="string"||o===0)return;if(o===1)return{type:"text"};const l=s===void 0?void 0:zs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},ar=e=>e===0?"":`.${"0".repeat(e)}`,Gr=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=Yf,sp=`${qc}.,`,ei=e=>e.includes('"')?null:[...e].every(t=>sp.includes(t))?e:`"${e}"`,lp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(_c)){const u=ei(e.slice(r,c.index));if(u===null)return null;t.push(u,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=ei(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=zs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},ip=e=>{const t=Wf.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!Gr(n))return null;const r=`#,##0${ar(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${fo(t.symbol,t.lcid)}${r}`},Ic=e=>{switch(e.type){case"text":return"@";case"date":return lp(e.pattern===void 0?Uf:e.pattern);case"number":return Gr(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${ar(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return Gr(t)?e.scale===!1?`0${ar(t)}"%"`:`0${ar(t)}%`:null}case"scientific":return Gr(e.decimals)?`0${ar(e.decimals)}E+00`:null;case"currency":return ip(e);default:return null}},ti="-−",cp=(e,t)=>{if(t===""||!e.includes(t))return/^\d+$/.test(e)?e:null;const n=e.split(t);return!/^\d{1,3}$/.test(n[0])||n.slice(1).some(r=>!/^\d{3}$/.test(r))?null:n.join("")},ap=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=cp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},up=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},dp=(e,t,n)=>{if(n.decimal===""||n.group===n.decimal)throw new RangeError(`numberDisplayToCanonical: separators must declare a non-empty decimal separator distinct from the group separator (got group="${n.group}", decimal="${n.decimal}")`);if(t!==void 0&&(t.type==="date"||t.type==="text"))return e;const r=t===void 0?"general":t.type;let o=e.trim(),s=!1;if(o.startsWith("(")&&o.endsWith(")")&&(s=!0,o=o.slice(1,-1).trim()),r==="percent"){if(!o.endsWith("%"))return e;o=o.slice(0,-1).trim()}else if(o.includes("%"))return e;const l=r==="general"?"":n.group,c=r==="scientific"||r==="general",u=z=>z>="0"&&z<="9"||l!==""&&l.includes(z)||n.decimal.includes(z)||c&&(z==="e"||z==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let R=0,N=0,H=0,L="";for(const z of o.slice(0,h))ti.includes(z)?R+=1:z==="("?N+=1:L+=z;for(const z of o.slice(m))ti.includes(z)?R+=1:z===")"?H+=1:L+=z;const _=R+N;if(N!==H||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&L.trim()!==""))return e;const U=ap(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(U===null)return e;const W=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,k=U.exponent+W;if(k>330||k<-330)return e;const x=up(U.integer,U.fraction,k,s);return Number.isFinite(Number(x))?x:e},ni="google-sheets-html-origin",jc=Object.freeze({group:",",decimal:"."}),ri=Object.freeze({thin:".5pt solid",medium:"1.0pt solid",thick:"1.5pt solid",dashed:".5pt dashed",dotted:".5pt dotted",double:"1.5pt double",hair:".5pt hairline"}),Hc=["top","right","bottom","left"],fp=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),pp=new Set(["windowtext","currentcolor","inherit","initial","unset"]),hp=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),oi=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],mp=Object.freeze({number:2,percent:3,currency:4,scientific:8}),gp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),wp=new Set(["div","p","li","ul","ol","dl","dt","dd","h1","h2","h3","h4","h5","h6","blockquote","pre","section","article","header","footer","table","tr","hr"]),Cp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),bp=3,yp=1,Bc=-25569,Zr=86400,Rp=-693959,vp=2958465,Sp=" ",po=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),u=c.indexOf(":");if(u>0){const h=c.slice(0,u).trim().toLowerCase(),m=c.slice(u+1).trim();h!==""&&m!==""&&t.set(h,m)}n=l+1};for(let l=0;l<e.length;l+=1){const c=e[l];r!==null?c==="\\"?l+=1:c===r&&(r=null):c==='"'||c==="'"?r=c:c==="("?o+=1:c===")"?o=o>0?o-1:0:c===";"&&o===0&&s(l)}return s(e.length),t},ro=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Ns=e=>{const t=[];let n="",r=0;for(const o of e)o==="("?r+=1:o===")"&&(r=r>0?r-1:0),r===0&&/\s/.test(o)?n!==""&&(t.push(n),n=""):n+=o;return n!==""&&t.push(n),t},kp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,Ep=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),R=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const N=po(R);for(const H of m.split(",")){const L=H.trim(),_=kp.exec(L);if(_!==null){const U=t.get(_[1]);if(U===void 0)t.set(_[1],new Map(N));else for(const[W,k]of N)U.set(W,k)}else if(L.toLowerCase()==="table"){const U=N.get("mso-displayed-decimal-separator"),W=N.get("mso-displayed-thousand-separator");U!==void 0&&(n=ps(ro(U))),W!==void 0&&(r=ps(ro(W)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:jc}},Ap="%_-*? ",Op=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||Ap.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},xp=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,u=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+u-719468},Vc=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},Mn=(e,t)=>String(e).padStart(t,"0"),Wc=e=>{if(e<Rp||e>vp)return null;let t=Math.floor(e),n=Math.round((e-t)*Zr);n>=Zr&&(t+=1,n-=Zr);const r=Vc(t+Bc),o=`${Mn(r.year,4)}-${Mn(r.month,2)}-${Mn(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Mn(s,2)}:${Mn(l,2)}:${Mn(n%60,2)}`},Tp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,$p=e=>{const t=Tp.exec(e);if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);if(r<1||r>12||o<1||s>23||l>59||c>59)return null;const u=xp(n,r,o),h=Vc(u);return h.year!==n||h.month!==r||h.day!==o?null:u-Bc+(s*3600+l*60+c)/Zr},Fs=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),pn=e=>Fs(e).replaceAll('"',"""),Kc=e=>Fs(e).replaceAll("'","'"),Lp=e=>Fs(e).replaceAll(`\r
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Vt=require("./tsv.cjs"),Le=require("./view-BkwCUzTl.cjs"),lt=require("@aiquants/virtualscroll"),K=require("react/jsx-runtime"),i=require("react"),Ts=1e3,cn=1e4,$s=10,jl=2**(1/4),Uu=(e,t)=>e<=0?e:t>0?e>=cn?e:Math.min(cn,Math.max(e+1,Math.round(e*jl))):Math.max(1,Math.min(e-1,Math.round(e/jl))),Hl=(e,t)=>t.reduce((n,r)=>{const o=e.sizeOf(r.index)===0,s=r.size===0;return n+(s&&!o?1:0)-(!s&&o?1:0)},0),Ls=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/$s):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),cn))}let l=[...s].map(([u,h])=>({index:u,size:h}));if(e.count-e.hiddenCount()-Hl(e,l)===0){const u=n===null?l[0].index:n;l=l.map(h=>h.index===u?{index:h.index,size:1}:h)}if(r.axisKind==="row"){const u=e.hiddenCount()+Hl(e,l);if(u>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:u}}return{ok:!0,entries:l}},Ds="#000000",jr=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},Xu=20,Gu=256,Hr=new Map,Yo=new WeakMap,wt=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},Zu=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},Ju=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:Xu}:jr(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...jr(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...jr(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...jr(e.decimals)};default:return null}},Qu=e=>{const t=Yo.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=Hr.get(n);if(r!==void 0)return Yo.set(e,r),r;Hr.size>=Gu&&Hr.clear();const o=Ju(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Hr.set(n,s),Yo.set(e,s),s},ed=(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}},wc=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>ed(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},td=(e,t)=>{const n=wc(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)}})},Gn=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return td(e,t.pattern??"yyyy/MM/dd");const n=wt(e);if(n===null)return e;const r=Qu(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?Zu(n,-2):n)},Bl=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?wc(n)!==null?"right":"left":wt(n)!==null?"right":"left",yr=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Cc=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],nd=["bottom","left","right","top"],bc=(e,t,n)=>{e[t]=n},yc=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},rd=e=>{if(e===void 0)return;const t={};for(const n of nd){const r=e[n];r!==void 0&&(t[n]=yc(r))}return Object.keys(t).length===0?void 0:t},xt=e=>{const t={};for(const n of Cc){const r=n==="borders"?rd(e.borders):n==="value"?e.value===void 0?void 0:yc(e.value):e[n];r!==void 0&&r!==!1&&bc(t,n,r)}return Object.keys(t).length===0?void 0:t},zs=(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]||!zs(o[c],s[c]))return!1}return!0},od=(e,t)=>e===t?!0:zs(e===void 0?void 0:xt(e),t===void 0?void 0:xt(t)),Ms=(e,t)=>{const n={};for(const o of Cc){const s=t[o];bc(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=xt(n);return zs(r,e===void 0?void 0:xt(e))?e:r},Rc="data-aqsp-clip",fo="application/x-aqsp-clip",fs=512,Wl=16*1024,ps=`${Rc}=`,sd=16,Ns=()=>{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(sd));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Ar=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ae=e=>typeof e=="string",ot=e=>typeof e=="boolean",rn=e=>typeof e=="number"&&Number.isFinite(e),At=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,Vl=e=>At(e)&&e>=1,ld=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=cn,Wt=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},id=e=>t=>Array.isArray(t)&&t.every(e),De=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),Kt=(e,t)=>{if(!Ar(e))return!1;for(const n of Object.keys(e)){const r=e[n];if(r===void 0)continue;const o=t.fields.get(n);if(o===void 0||!o(r))return!1}for(const n of t.required)if(e[n]===void 0)return!1;return!0},Fs=e=>t=>{if(!Ar(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&Kt(t,n)},cd=["left","center","right"],ad=["top","middle","bottom"],ud=["thin","medium","thick","dashed","dotted","double","hair"],Ko=["gt","gte","lt","lte","eq","neq","between","notBetween"],dd=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],fd=["eq","neq","gt","gte","lt","lte","between","notBetween"],pd=["contains","notContains","startsWith","endsWith"],hd=new Map([["number",De({type:ae,decimals:rn,grouping:ot,locale:ae},["type"])],["percent",De({type:ae,decimals:rn,scale:ot,locale:ae},["type"])],["currency",De({type:ae,currency:ae,decimals:rn,locale:ae},["type","currency"])],["scientific",De({type:ae,decimals:rn,locale:ae},["type"])],["date",De({type:ae,pattern:ae},["type"])],["text",De({type:ae},["type"])]]),md=De({style:Wt(ud),color:ae},["style"]),Br=e=>Kt(e,md),gd=De({top:Br,right:Br,bottom:Br,left:Br},[]),wd=De({value:Fs(hd),align:Wt(cd),verticalAlign:Wt(ad),wrap:ot,background:ae,color:ae,bold:ot,italic:ot,underline:ot,strikethrough:ot,fontFamily:ae,fontSize:rn,borders:e=>Kt(e,gd)},[]),Cd=e=>Kt(e,wd),yn={strict:ot,inputMessage:ae,errorMessage:ae},bd=new Map([["list",De({...yn,type:ae,values:id(ae),showDropdown:ot},["type","values"])],["number",De({...yn,type:ae,op:Wt(Ko),a:ae,b:ae},["type","op","a"])],["textLength",De({...yn,type:ae,op:Wt(Ko),a:rn,b:rn},["type","op","a"])],["date",De({...yn,type:ae,op:Wt(Ko),a:ae,b:ae},["type","op","a"])],["text",De({...yn,type:ae,op:Wt(dd),value:ae},["type","op"])],["checkbox",De({...yn,type:ae,checked:ae,unchecked:ae},["type"])],["custom",De({...yn,type:ae,formula:ae},["type","formula"])]]),yd=Fs(bd),Rd=De({startRow:At,startCol:At,endRow:At,endCol:At},["startRow","startCol","endRow","endCol"]),vd=e=>{if(!Kt(e,Rd))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return At(t)&&At(r)&&At(n)&&At(o)&&t<=r&&n<=o},Sd=De({color:ae,value:rn},["color"]),Uo=e=>Kt(e,Sd),kd=new Map([["cellValue",De({type:ae,op:Wt(fd),a:ae,b:ae},["type","op","a"])],["text",De({type:ae,op:Wt(pd),value:ae},["type","op","value"])],["empty",De({type:ae},["type"])],["notEmpty",De({type:ae},["type"])],["colorScale",De({type:ae,min:Uo,mid:Uo,max:Uo},["type","min","max"])],["customFormula",De({type:ae,formula:ae},["type","formula"])]]),Ed=De({background:ae,color:ae,bold:ot,italic:ot,underline:ot,strikethrough:ot},[]),Od=De({sourceRuleId:ae,ranges:Array.isArray,condition:Fs(kd),style:e=>Kt(e,Ed),stopIfTrue:ot},["sourceRuleId","ranges","condition","style"]),Ad=(e,t,n)=>{if(!Kt(e,Od))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!vd(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},xd=De({text:ae,author:ae,createdAt:ae},["text","author","createdAt"]),Td=e=>Kt(e,xd),$d=(e,t,n)=>{if(!Ar(e)||typeof e.t!="string")return!1;for(const r of Object.keys(e)){const o=e[r];if(o!==void 0)switch(r){case"t":break;case"f":if(typeof o!="string"||!o.startsWith("="))return!1;break;case"fmt":if(!At(o)||o>=t)return!1;break;case"val":if(!At(o)||o>=n)return!1;break;case"note":case"link":if(typeof o!="string")return!1;break;case"comments":if(!(Array.isArray(o)&&o.every(Td)))return!1;break;default:return!1}}return!0},Yl=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(ld),Ld=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),vc=e=>{if(!Ar(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Ld.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(Vl(t)&&Vl(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Cd)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(yd)))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(!$d(u,r.length,o.length))return!1}if(e.colWidths!==void 0&&!Yl(e.colWidths,n)||e.rowHeights!==void 0&&!Yl(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Ad(c,t,n))},kr=e=>Array.isArray(e)?`[${e.map(kr).join(",")}]`:Ar(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${kr(e[n])}`).join(",")}}`:JSON.stringify(e),Dd=e=>{const t=xt(e);return t===void 0?"{}":JSON.stringify(t)},zd=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,Md=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(zd).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Sc=e=>{if(!vc(e))throw new RangeError("[spreadsheet] serializeClipPayload received a payload outside the wire format v1 vocabulary");const t=`{"v":1,"rows":${e.rows},"cols":${e.cols},"clipId":${JSON.stringify(e.clipId)}`,n=e.formats.map(Dd).join(","),r=e.validations.map(kr).join(","),o=e.cells.map(u=>`[${u.map(Md).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(kr).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},hs=e=>{let t;try{t=JSON.parse(e)}catch{return null}return vc(t)?t:null},Nd=/&(?:amp|lt|gt|quot|#39|nbsp);/g,Fd=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),kc=e=>e.includes("&")?e.replace(Nd,t=>Fd[t]):e,Pd=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,Kl=e=>{const t=e.length>fs?e.slice(0,fs):e,n=Pd.exec(kc(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},_d=e=>{const t=e.indexOf(ps);if(t===-1)return null;const n=t+ps.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},Ec=(e,t)=>{if(t==="event"&&e.types.includes(fo))return{kind:"mime",json:e.getData(fo)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=_d(n);return r===null?null:{kind:"attribute",html:n,at:r}},qd=(e,t)=>{const n=Ec(e,t);return n===null?null:n.kind==="mime"?Kl(n.json):Kl(n.html.slice(n.at.start,n.at.start+fs))},Id=(e,t)=>{const n=Ec(e,t);if(n===null)return null;if(n.kind==="mime")return hs(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:hs(kc(n.html.slice(n.at.start,r)))},jd=/<google-sheets-html-origin[\s>]/,Hd='data-sheets-root="1"',Bd=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,Wd="mso-",Vd=/\.xl\d+\s*\{/,Yd="<table",Kd=e=>e.includes(ps)?"aqsp":jd.test(e)&&e.includes(Hd)?"sheets":Bd.test(e)||e.includes(Wd)||Vd.test(e)?"excel":null,Oc=(e,t)=>{if(t==="event"&&e.types.includes(fo))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Wl?n.slice(0,Wl):n,o=Kd(r);if(o==="aqsp")return"aqsp";if(n.includes(Yd))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Ps=1e3,Ac=65534,Ud=9,Xd=10,Gd=12,Zd=13,Jd=32,xc=34,Tc=39,Qd=43,_s=47,Ul=48,ef=57,tf=61,nf=62,rf=97,of=98,sf=100,lf=102,$c=104,Lc=114,Dc=116,cf=["able","body","head","foot"],Rr=e=>e===Jd||e===Ud||e===Xd||e===Zd||e===Gd,ms=e=>e===nf||e===_s||Rr(e),af=e=>Rr(e)||e===_s||e===xc||e===Tc,uf=(e,t,n,r)=>{if(t===0||!af(e.charCodeAt(t-1)))return null;let o=t+n;for(;Rr(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==tf)return 1;for(o+=1;Rr(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===xc||s===Tc)&&(o+=1);Rr(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===Qd&&(o+=1);let l=0,c=0;for(let u=e.charCodeAt(o);u>=Ul&&u<=ef;u=e.charCodeAt(o))l=l*10+(u-Ul),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Xl=(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=uf(e,r,t.length,n);if(l!==null)return l}return 1}},df=(e,t)=>{if(e.charCodeAt(t+2)!==Dc)return!1;const n=e.charCodeAt(t+3);if(n===Lc)return ms(e.charCodeAt(t+4));if(n!==rf&&n!==of&&n!==$c&&n!==lf)return!1;for(const r of cf)if(e.startsWith(r,t+3)&&ms(e.charCodeAt(t+3+r.length)))return!0;return!1},ff=e=>{const t=e.toLowerCase(),n=Xl(t,"colspan",Ps),r=Xl(t,"rowspan",Ac);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 R=new Map,N=(I,X)=>{const Y=R.get(I);R.set(I,Y===void 0?X:Y+X)},W=()=>{m&&u+h>c&&(c=u+h),m=!1},z=()=>{W(),l+=1,m=!0,u=0;const I=R.get(l-1);I!==void 0&&(h+=I)};for(let I=t.indexOf("<");I!==-1;I=t.indexOf("<",I+1)){const X=t.charCodeAt(I+1);if(X===_s){df(t,I)&&W();continue}if(X!==Dc||!ms(t.charCodeAt(I+3)))continue;const Y=t.charCodeAt(I+2);if(Y===Lc)z();else if(Y===sf||Y===$c){m||z();const O=I+3,T=s(O),F=n(O,T);u+=F;const H=r(O,T);H>1&&(N(l,F),N(l-1+H,-F))}}return W(),{rows:l,cols:c}},zc=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}},Mc=()=>{const e=new WeakMap,t=zc(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=xt(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},pf=()=>{const e=new WeakMap,t=zc(kr);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}},hf=new Set(["http:","https:","mailto:","tel:"]),an=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return hf.has(n.protocol)?n.href:null},Qn=e=>{if(e===void 0)return;const t=an(e);return t===null?void 0:t},Nc=(e,t)=>e.startCol===0&&e.endCol===t-1,Fc=(e,t)=>e.startRow===0&&e.endRow===t-1,gs=13,Bt=Object.freeze({style:Object.freeze({}),lineBoxPx:gs,verticalAlign:"middle"}),mf={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"},gf=new Map(Object.entries(mf)),wf=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,Cf=/^rgba?\((.*)\)$/,Pc=/^(\d+(?:\.\d+)?)%$/,Wr=e=>e.toString(16).padStart(2,"0"),Xo=e=>{const t=Pc.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},bf=e=>{const t=Pc.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},yf=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=Xo(t[0]),r=Xo(t[1]),o=Xo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Wr(n)}${Wr(r)}${Wr(o)}`;if(t.length===3)return s;const l=bf(t[3]);return l===null?null:l===255?s:`${s}${Wr(l)}`},st=e=>{const t=e.trim().toLowerCase(),n=wf.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=Cf.exec(t);if(r!==null)return yf(r[1]);const o=gf.get(t);return o===void 0?null:o},Gl={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"}},Zl=e=>{if(!Object.hasOwn(Gl,e.style))return null;const t=Gl[e.style],n=e.color===void 0?Ds:st(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},Rf={top:"flex-start",middle:"center",bottom:"flex-end"},vf=e=>e==="left"||e==="center"||e==="right",_c=e=>e==="top"||e==="middle"||e==="bottom",qc=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,Ic=(e,t)=>{if(typeof e.background=="string"){const s=st(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=st(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=qc(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Vr=(e,t)=>{const n=e===void 0?null:Zl(e);return n!==null?n:t===void 0?null:Zl(t)},Go=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(vf(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=yr(e.align)),_c(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=Rf[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),Ic(e,s));const c=e?.borders,u=Vr(c?.right,t);u!==null&&(s.borderRight=u);const h=Vr(c?.bottom,n);if(h!==null&&(s.borderBottom=h),r){const m=Vr(c?.left,void 0);m!==null&&(s.borderLeft=m)}if(o){const m=Vr(c?.top,void 0);m!==null&&(s.borderTop=m)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Jl=new WeakMap,Sf=(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:Go(void 0,s,l,r,o);if(!c)return Go(e,s,l,r,o);const u=Jl.get(e);if(u!==void 0)return u;const h=Go(e,void 0,void 0,!1,!1);return Jl.set(e,h),h},kf=e=>{if(e===void 0)return Bt;const t={};Ic(e,t);const n=qc(e.fontSize),r=n===null?gs:Math.round(n),o=_c(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===gs&&o==="middle"?Bt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Ef="#REF!",Of=11,Af=15,xf=4096,oo=33,vr=34,qs=36,Tf=38,ws=39,jc=40,$f=42,Lf=43,Df=44,Hc=45,zf=46,Mf=47,Yn=58,Nf=59,Ff=60,Bc=61,Pf=62,_f=67,qf=82,Co=91,Wc=93,If=94,jf=95,Vc=e=>e>=65&&e<=90||e>=97&&e<=122,Yc=e=>e>=48&&e<=57,Is=e=>Vc(e)||Yc(e)||e===jf||e===zf||e===qs||e>=128,Hf=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,Bf=e=>e===Bc||e===jc||e===Df||e===Nf||e===Lf||e===Hc||e===$f||e===Mf||e===If||e===Tf||e===Ff||e===Pf||e===Yn,Kc=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Is(n)||n===jc||n===oo||n===Co)},Ql=(e,t)=>{let n=t;for(;n<e.length&&Is(e.charCodeAt(n));)n+=1;return n},Cs=(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},Wf=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===ws){r+=2;continue}if(o===Co)n+=1;else if(o===Wc&&(n-=1,n===0))return r+1;r+=1}return e.length},ei=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&Kc(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Uc=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===vr){o=Cs(e,o,vr);continue}if(s===ws){const u=Cs(e,o,ws);o=e.charCodeAt(u)===oo?ei(e,o,u,t,n):u;continue}if(s===Co){o=Wf(e,o);continue}if(!Is(s)){o+=1;continue}const l=t(e,o);if(l!==null&&Kc(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Ql(e,o);if(e.charCodeAt(c)===Yn){const u=Ql(e,c+1);u>c+1&&e.charCodeAt(u)===oo&&(c=u)}o=e.charCodeAt(c)===oo?ei(e,o,c,t,n):c}return n},Zo=(e,t)=>{let n=t;const r=e.charCodeAt(n)===qs;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!Vc(l))break;if(s+=1,s>Of)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},bs=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Yc(o))break;if(n-t>=Af)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Yr=(e,t)=>{const n=e.charCodeAt(t)===qs,r=bs(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},Vf=(e,t)=>{const n=Zo(e,t);if(n!==null){const o=Yr(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===Yn){const s=Zo(e,o.end+1);if(s!==null){const l=Yr(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)===Yn){const s=Zo(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=Yr(e,t);if(r!==null&&e.charCodeAt(r.end)===Yn){const o=Yr(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},xr=e=>Uc(e,Vf),Xc=(e,t=xf)=>{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}},ys=e=>{let t=e+1,n="";for(;t>0;){const r=(t-1)%26;n=String.fromCharCode(65+r)+n,t=Math.floor((t-1)/26)}return n},Jo=e=>`${e.absCol?"$":""}${ys(e.col)}${e.absRow?"$":""}${e.row+1}`,js=e=>e.sheet===void 0?"":`${e.sheet}!`,on=e=>{const t=js(e);switch(e.kind){case"cell":return`${t}${Jo(e)}`;case"range":return`${t}${Jo(e.start)}:${Jo(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${ys(e.start.col)}:${e.end.abs?"$":""}${ys(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},jn=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},Yf=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(jn(n.startRow,"formatRangeReference startRow"),jn(n.startCol,"formatRangeReference startCol"),jn(n.endRow,"formatRangeReference endRow"),jn(n.endCol,"formatRangeReference endCol"),t){case"columns":return on({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return on({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?on({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):on({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Hs=(e,t,n)=>{if(t.length===0)return e;let r="",o=0;for(const s of t){const l=n(s.token);r+=e.slice(o,s.start)+(l===null?`${js(s.token)}${Ef}`:l),o=s.end}return r+e.slice(o)},bo=e=>e.charCodeAt(0)===Bc,Qo=(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}},Kf=(e,t,n)=>{switch(e.kind){case"cell":{const r=Qo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=Qo(e.start,t,n),o=Qo(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}}}}},Gc=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return bo(e)?Hs(e,xr(e),r=>{const o=Kf(r,t,n);return o===null?null:on(o)}):e},Zc=(e,t)=>{jn(e.row,`${t} origin.row`),jn(e.col,`${t} origin.col`)},Hn=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,es=(e,t)=>`${Hn("R",e.row,e.absRow,t.row)}${Hn("C",e.col,e.absCol,t.col)}`,Uf=(e,t)=>{const n=js(e);switch(e.kind){case"cell":return`${n}${es(e,t)}`;case"range":return`${n}${es(e.start,t)}:${es(e.end,t)}`;case"column":return`${n}${Hn("C",e.start.col,e.start.abs,t.col)}:${Hn("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Hn("R",e.start.row,e.start.abs,t.row)}:${Hn("R",e.end.row,e.end.abs,t.row)}`}},yo=(e,t)=>(Zc(t,"toR1C1"),bo(e)?Hs(e,xr(e),n=>Uf(n,t)):e),ti=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Co){const l=e.charCodeAt(o+1)===Hc,c=bs(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==Wc?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=bs(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}}},ni=(e,t)=>{const n=ti(e,t,qf),r=ti(e,n===null?t:n.end,_f);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},Xf=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},Gf=(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,Zf=(e,t)=>{const n=ni(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===Yn){const r=ni(e,n.end+1);if(r!==null){const o=Gf(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:Xf(n)}},Jf=e=>Uc(e,Zf),Qf=Xc(Jf),Bn=(e,t)=>e.rel?t+e.n:e.n-1,ri=(e,t)=>{const n=Bn(e.row,t.row),r=Bn(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},ep=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=ri(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=ri(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=Bn(e.start,t.row),s=Bn(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=Bn(e.start,t.col),s=Bn(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}}}},Tr=(e,t)=>(Zc(t,"fromR1C1"),bo(e)?Hs(e,Qf(e),n=>{const r=ep(n,t);return r===null?null:on(r)}):e),oi=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},tp=e=>{switch(e.kind){case"cell":return{...e,...oi(e.absCol,e.absRow)};case"range":{const t=oi(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}}}}},Jc=(e,t)=>bo(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Qc=(e,t)=>{if(!Jc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return n;return null},np=(e,t)=>{const n=Qc(e,t);if(n===null)return null;const r=on(tp(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},si=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===vr){const s=Cs(e,r,vr);if(s>t)return!1;n=vr,r=s;continue}Hf(o)||(n=o),r+=1}return Bf(n)},ea=(e,t)=>{if(!Jc(e,t))return null;for(const n of xr(e))if(n.start<=t&&t<=n.end)return si(e,n.start)?{replace:[n.start,n.end]}:null;return si(e,t)?{insertAt:t}:null},Zn=[{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}],Ro=(e,t)=>`[$${e}-${t}]`,rp=new Map(Zn.map(e=>[Ro(e.symbol,e.lcid),e])),op=new Map(Zn.filter((e,t)=>Zn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(Zn.map(e=>[Ro(e.symbol,e.lcid),e.code]));const sp=new Set([...Zn.map(e=>e.symbol),...Zn.map(e=>e.code),"¥"]),lp=20,ip="yyyy/MM/dd",ta=/yyyy|MM|dd|HH|mm|ss/g,na=" -+/():!^&'~{}<>=",cp="$¥€£₩₹¥",Rs=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},ap=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},up=e=>{const t=[],n=o=>{const s=t[t.length-1];s!==void 0&&s.kind==="literal"?t[t.length-1]={kind:"literal",text:s.text+o}:t.push({kind:"literal",text:o})};let r=0;for(;r<e.length;){const o=e[r];if(o==='"'){const s=e.indexOf('"',r+1);if(s<0)return null;n(e.slice(r+1,s)),r=s+1}else if(o==="\\"){if(r+1>=e.length)return null;n(e[r+1]),r+=2}else if(o==="_"||o==="*"){if(r+1>=e.length)return null;r+=2}else if(o==="["){const s=e.indexOf("]",r+1),l=s<0?"":e.slice(r+1,s);if(s<0||l[0]!=="$")return null;const c=l.slice(1),u=c.lastIndexOf("-"),h=u<0?c:c.slice(0,u),m=u<0?null:c.slice(u+1);if(m!==null&&!/^[0-9a-fA-F]{1,8}$/.test(m)||h===""&&m===null)return null;const R=m===null?null:Number.parseInt(m,16).toString(16);t.push(h===""?{kind:"locale"}:{kind:"currency",symbol:h,lcid:R}),r=s+1}else if(o==="%")t.push({kind:"percent"}),r+=1;else if("#0?,.".includes(o)){let s=r;for(;s<e.length&&"#0?,.".includes(e[s]);)s+=1;const l=e.slice(r,s);/[#0?]/.test(l)?t.push({kind:"digits",text:l}):n(l),r=s}else if(/[A-Za-z]/.test(o))if((o==="E"||o==="e")&&(e[r+1]==="+"||e[r+1]==="-")){let s=r+2;for(;e[s]==="0";)s+=1;if(s===r+2)return null;t.push({kind:"exponent"}),r=s}else{let s=r;for(;s<e.length&&e[s].toLowerCase()===o.toLowerCase();)s+=1;t.push({kind:"date",text:e.slice(r,s).toLowerCase()}),r=s}else if(na.includes(o)||cp.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},Ot=e=>e===void 0?{}:{locale:e},dp=/^(0|#,##0)(?:\.(0+))?$/,li=(e,t,n,r)=>{if(t!==null){const o=rp.get(Ro(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!sp.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...Ot(r.locale)}},fp=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",u="";for(const z of e)switch(z.kind){case"locale":break;case"literal":r?u+=z.text:c+=z.text;break;case"digits":if(r)return;n=z.text,r=!0;break;case"currency":if(o!==null)return;o=z;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const h=dp.exec(n);if(h===null)return;const m=h[1]==="#,##0",R=h[2]===void 0?0:h[2].length,N=c.trim(),W=u.trim();if(s)return l===0&&o===null&&!m&&N===""&&W===""?{type:"scientific",decimals:R,...Ot(t.locale)}:void 0;if(l>0)return l===1&&o===null&&N===""&&W===""?{type:"percent",decimals:R,...Ot(t.locale)}:void 0;if(W==="%"&&N===""&&o===null)return{type:"percent",decimals:R,scale:!1,...Ot(t.locale)};if(o!==null)return N===""&&W===""?li(o.symbol,o.lcid,R,t):void 0;if(!(N!==""&&W!==""))return N!==""||W!==""?li(N+W,null,R,t):{type:"number",decimals:R,...m?{grouping:!0}:{},...Ot(t.locale)}},pp=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),hp=(e,t)=>{const n=[...e.matchAll(ta)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},mp=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":pp.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&hp(r,n)?{type:"date",pattern:r}:void 0},gp=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"})]]),Bs=(e,t)=>{const n=ap(e).trim(),r=gp.get(n);if(r!==void 0)return r(t);const o=up(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return fp(o,t);if(o.some(s=>s.kind==="date"))return mp(o)}},wp=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return}if(typeof n!="object"||n===null||Array.isArray(n))return;const r=n,o=r[1],s=r[2];if(typeof o!="number"||!Number.isInteger(o)||o<0||o>8||s!==void 0&&typeof s!="string"||o===0)return;if(o===1)return{type:"text"};const l=s===void 0?void 0:Bs(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},wr=e=>e===0?"":`.${"0".repeat(e)}`,so=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=lp,Cp=`${na}.,`,ii=e=>e.includes('"')?null:[...e].every(t=>Cp.includes(t))?e:`"${e}"`,bp=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(ta)){const u=ii(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=ii(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Bs(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},yp=e=>{const t=op.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!so(n))return null;const r=`#,##0${wr(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${Ro(t.symbol,t.lcid)}${r}`},ra=e=>{switch(e.type){case"text":return"@";case"date":return bp(e.pattern===void 0?ip:e.pattern);case"number":return so(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${wr(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return so(t)?e.scale===!1?`0${wr(t)}"%"`:`0${wr(t)}%`:null}case"scientific":return so(e.decimals)?`0${wr(e.decimals)}E+00`:null;case"currency":return yp(e);default:return null}},ci="-−",Rp=(e,t)=>{if(t===""||!e.includes(t))return/^\d+$/.test(e)?e:null;const n=e.split(t);return!/^\d{1,3}$/.test(n[0])||n.slice(1).some(r=>!/^\d{3}$/.test(r))?null:n.join("")},vp=(e,t,n,r)=>{const o=/^(.*?)[eE]([+-]?\d{1,4})$/.exec(e);if(o!==null&&r==="none"||o===null&&r==="required")return null;const s=o===null?e:o[1],l=o===null?0:Number(o[2]),c=s.split(n);if(c.length>2)return null;const u=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(u))return null;const h=Rp(c[0],t);return h===null?null:{integer:h,fraction:u,exponent:l}},Sp=(e,t,n,r)=>{const o=e+t,s=e.length+n;let l,c;s<=0?(l="0",c="0".repeat(-s)+o):s>=o.length?(l=o+"0".repeat(s-o.length),c=""):(l=o.slice(0,s),c=o.slice(s)),l=l.replace(/^0+(?=\d)/,""),c=c.replace(/0+$/,"");const u=c===""?l:`${l}.${c}`;return r&&u!=="0"?`-${u}`:u},kp=(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=F=>F>="0"&&F<="9"||l!==""&&l.includes(F)||n.decimal.includes(F)||c&&(F==="e"||F==="E");let h=0;for(;h<o.length&&!u(o[h]);)h+=1;let m=o.length;for(;m>h&&!u(o[m-1]);)m-=1;let R=0,N=0,W=0,z="";for(const F of o.slice(0,h))ci.includes(F)?R+=1:F==="("?N+=1:z+=F;for(const F of o.slice(m))ci.includes(F)?R+=1:F===")"?W+=1:z+=F;const I=R+N;if(N!==W||I>1||I===1&&s||(s=s||I===1,r!=="currency"&&z.trim()!==""))return e;const X=vp(o.slice(h,m).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(X===null)return e;const Y=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,O=X.exponent+Y;if(O>330||O<-330)return e;const T=Sp(X.integer,X.fraction,O,s);return Number.isFinite(Number(T))?T:e},ai="google-sheets-html-origin",oa=Object.freeze({group:",",decimal:"."}),ui=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"}),sa=["top","right","bottom","left"],Ep=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Op=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Ap=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong","inherit","initial","unset"]),di=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],xp=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Tp=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),$p=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"]),Lp=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Dp=3,zp=1,la=-25569,lo=86400,Mp=-693959,Np=2958465,Fp=" ",vo=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},po=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Ws=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},Pp=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,_p=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const u=l.indexOf("{",c);if(u===-1)break;const h=l.indexOf("}",u+1);if(h===-1)break;const m=l.slice(c,u),R=l.slice(u+1,h);if(c=h+1,m.trim().startsWith("@"))continue;const N=vo(R);for(const W of m.split(",")){const z=W.trim(),I=Pp.exec(z);if(I!==null){const X=t.get(I[1]);if(X===void 0)t.set(I[1],new Map(N));else for(const[Y,O]of N)X.set(Y,O)}else if(z.toLowerCase()==="table"){const X=N.get("mso-displayed-decimal-separator"),Y=N.get("mso-displayed-thousand-separator");X!==void 0&&(n=Rs(po(X))),Y!==void 0&&(r=Rs(po(Y)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:oa}},qp="%_-*? ",Ip=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||qp.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},jp=(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},ia=e=>{const t=e+719468,n=Math.floor(t/146097),r=t-n*146097,o=Math.floor((r-Math.floor(r/1460)+Math.floor(r/36524)-Math.floor(r/146096))/365),s=r-(365*o+Math.floor(o/4)-Math.floor(o/100)),l=Math.floor((5*s+2)/153),c=s-Math.floor((153*l+2)/5)+1,u=l<10?l+3:l-9;return{year:o+n*400+(u<=2?1:0),month:u,day:c}},_n=(e,t)=>String(e).padStart(t,"0"),ca=e=>{if(e<Mp||e>Np)return null;let t=Math.floor(e),n=Math.round((e-t)*lo);n>=lo&&(t+=1,n-=lo);const r=ia(t+la),o=`${_n(r.year,4)}-${_n(r.month,2)}-${_n(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${_n(s,2)}:${_n(l,2)}:${_n(n%60,2)}`},Hp=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,Bp=e=>{const t=Hp.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=jp(n,r,o),h=ia(u);return h.year!==n||h.month!==r||h.day!==o?null:u-la+(s*3600+l*60+c)/lo},Vs=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),Rn=e=>Vs(e).replaceAll('"',"""),aa=e=>Vs(e).replaceAll("'","'"),Wp=e=>Vs(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(" ","	"),io=(e,t)=>`${e}="${Rn(JSON.stringify(t))}"`,ua=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",Vp=e=>{if(wt(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},Yp=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},Kp=e=>{if(e.type==="text")return{1:1};const t=ra(e);return t===null?null:{1:e.type==="date"?Yp(e.pattern===void 0?"yyyy/MM/dd":e.pattern):xp[e.type],2:t,3:1}},Up=/[;"'{}<>&\\]/,da=e=>e==="left"||e==="center"||e==="right",fa=e=>e==="top"||e==="middle"||e==="bottom",Xp=e=>{const t=[];e.bold===!0&&t.push("font-weight:bold"),e.italic===!0&&t.push("font-style:italic");const n=[...e.underline===!0?["underline"]:[],...e.strikethrough===!0?["line-through"]:[]];n.length>0&&t.push(`text-decoration:${n.join(" ")}`);const r=typeof e.color=="string"?st(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?st(e.background):null;if(o!==null&&t.push(`background-color:${o}`),da(e.align)&&t.push(`text-align:${e.align}`),fa(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!Up.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 sa){const l=e.borders[s];if(l===void 0||!Object.hasOwn(ui,l.style))continue;const c=l.color===void 0?"windowtext":st(l.color);c!==null&&t.push(`border-${s}:${ui[l.style]} ${c}`)}if(e.value!==void 0){const s=ra(e.value);s!==null&&t.push(`mso-number-format:"${Ip(s)}"`)}return t},Gp={value:void 0,style:"white-space:pre",numberFormatAttribute:null},Zp=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=aa([n,...Xp(e)].join(";"));let o=null;if(t!==void 0){const s=Kp(t);s!==null&&(o=io("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},Jp=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:Gn(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&ua(o)?Vp(e.t):null,u=!l&&c===null&&o!==void 0&&o.type==="date"?Bp(e.t):null,h=[];if(l?h.push(io("data-sheets-value",{1:2,2:e.t})):c!==null?h.push(io("data-sheets-value",{1:3,3:c})):u!==null&&h.push(io("data-sheets-value",{1:3,3:u})),e.f!==void 0&&h.push(`data-sheets-formula="${Rn(e.f)}"`),t.numberFormatAttribute!==null&&h.push(t.numberFormatAttribute),e.link!==void 0&&h.push(`data-sheets-hyperlink="${Rn(e.link)}"`),e.note!==void 0&&h.push(`data-sheets-note="${Rn(e.note)}"`),l?h.push("x:str"):c!==null?h.push(`x:num="${Rn(e.t)}"`):u!==null&&h.push(`x:num="${u}"`),e.f!==void 0){const N=Tr(e.f,{row:n,col:r});N.includes("#REF!")||h.push(`x:fmla="${Rn(N)}"`)}const m=Wp(s),R=e.link===void 0?m:`<a href="${Rn(e.link)}">${m}</a>`;return`<td style='${t.style}'${h.map(N=>` ${N}`).join("")}>${R}</td>`},pa=(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(Zp);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+=Jp(h,m===void 0?Gp:m,s,u)}o+=`<tr${l}>${c}</tr>`}return`<${ai}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Rc}='${aa(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${ai}>`},vs=(e,t)=>{for(const[n,r]of t)e.set(n,r)},ha=(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&&vs(n,l)}const o=e.getAttribute("style");return o!==null&&vs(n,vo(o)),n},Qp=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"}},eh=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"},th=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),nh={pt:1.5,unit:"px"},fi=e=>{let t=null,n=null;const r=[];for(const u of Ws(e)){const h=u.toLowerCase(),m=Qp(u);Ep.has(h)?n=h:m!==null?t=m:r.push(u)}if(n===null||n==="none"||n==="hidden")return null;const o=th.get(n),s=o===void 0?eh(t===null?nh:t):o,l=r.join(" ");if(l===""||Op.has(l.toLowerCase()))return{style:s};const c=st(l);return c===null||c.length===9?null:{style:s,color:c}},rh=e=>e.style==="thin"&&e.color==="#cccccc",oh=e=>{const t=st(e);if(t!==null)return t;for(const n of Ws(e)){const r=st(n);if(r!==null)return r}return null},sh=e=>{const t=po(Ws(e.split(",")[0]).join(" ").trim()).trim();return t===""||Ap.has(t.toLowerCase())?null:t},lh=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},ih=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},ch=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"},ah=new Set(["normal","pre-wrap","pre-line"]),uh=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const _=o.toLowerCase();(_==="bold"||_==="bolder"||Number(_)>=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=ih(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:st(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:oh(h);m!==null&&m.length!==9&&(r.background=m);const R=e.get("text-align"),N=R===void 0?"":R.toLowerCase();da(N)&&(r.align=N);const W=e.get("vertical-align"),z=W===void 0?"":W.toLowerCase();fa(z)&&(r.verticalAlign=z);const I=e.get("font-family"),X=I===void 0?null:sh(I);X!==null&&(r.fontFamily=X);const Y=e.get("font-size"),O=Y===void 0?null:lh(Y);O!==null&&(r.fontSize=O);const T=e.get("white-space");T!==void 0&&ah.has(T.toLowerCase())&&(r.wrap=!0);const F={},H=e.get("border"),$=H===void 0?null:fi(H);for(const _ of sa){const x=e.get(`border-${_}`),g=x===void 0?$:fi(x);g!==null&&!(n==="sheets"&&rh(g))&&(F[_]=g)}return Object.keys(F).length>0&&(r.borders=F),r},pi=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
6
|
`)&&(e.text+=`
|
|
7
|
-
`)},
|
|
8
|
-
`);continue}if(o.nodeType!==
|
|
9
|
-
`;continue}const c=t.mode==="collapse"
|
|
7
|
+
`)},dh=e=>{const t=e.getAttribute("style");return t!==null&&vo(t).get("mso-spacerun")==="yes"},fh=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Lp.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&pi(t);continue}const o=r.node;if(o.nodeType===Dp){const u=o.data;t.text+=t.mode==="collapse"?u.replace(/[\r\n\t\f]/g," "):u.replace(/\r\n?/g,`
|
|
8
|
+
`);continue}if(o.nodeType!==zp)continue;const s=o,l=s.localName;if(Tp.has(l)||dh(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&$p.has(l);if(c&&pi(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})}},ph=(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&&mh(l.element,t,n,r)},hh=(e,t)=>{const n=e.replaceAll(Fp," ");if(t==="pre")return n;const r=n.split(`
|
|
10
10
|
`).map(l=>l.replace(/[ \t\f\r]+/g," ").trim());if(t==="pre-line")return r.join(`
|
|
11
11
|
`);let o=0;for(;o<r.length&&r[o]==="";)o+=1;let s=r.length;for(;s>o&&r[s-1]==="";)s-=1;return r.slice(o,s).join(`
|
|
12
|
-
`)},nh=(e,t,n,r)=>{const o=e.localName;if(o==="b"||o==="strong")t.set("font-weight","bold");else if(o==="i"||o==="em")t.set("font-style","italic");else if(o==="u")n.underline=!0;else if(o==="s"||o==="strike"||o==="del")n.strikethrough=!0;else if(o==="font"){const s=e.getAttribute("color"),l=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),l!==null&&l.trim()!==""&&t.set("font-family",l)}hs(t,Zc(e,r))},rh=(e,t)=>{let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null)return null;const r=n,o=r[1];if(typeof o!="number")return null;const s=r[String(o)];if(o===2)return typeof s=="string"?s:null;if(o===3)return typeof s!="number"||!Number.isFinite(s)?null:t!==void 0&&t.type==="date"?Wc(s):String(s);if(o===4)return s===1||s===!0?"TRUE":s===0||s===!1?"FALSE":null;if(o===5&&typeof s=="object"&&s!==null){const l=s[1];return typeof l=="number"&&l>=1&&l<oi.length?oi[l]:null}return null},Jc=(e,t,n)=>t!==void 0&&Yc(t)?dp(e,t,n):e,oh=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const u=s.toUpperCase();return u==="TRUE"||u==="FALSE"?u:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&ot(c)!==null)if(n!==void 0&&n.type==="date"){const u=Wc(Number(c));if(u!==null)return u}else return c;return Jc(t,n,r)},sh=(e,t,n,r)=>{const o=Zc(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Xp(o)};for(const m of ah(e))Qp(m,l);eh(l,o,s,r.rules);const c=th(l.text,l.mode),u=Zp(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),R=m===null?void 0:op(m,r.options);R!==void 0&&(u.value=R);const N=e.getAttribute("data-sheets-value"),H=N===null?null:rh(N,R);h.t=H===null?Jc(c,R,jc):H;const L=e.getAttribute("data-sheets-formula");L?.startsWith("=")&&(h.f=L);const _=e.getAttribute("data-sheets-hyperlink"),U=_!==null?_:l.href,W=U===null?null:sn(U);W!==null&&(h.link=W);const k=e.getAttribute("data-sheets-note");k!==null&&k!==""&&(h.note=k)}else{const m=o.get("mso-number-format"),R=m===void 0?void 0:zs(ps(ro(m)),r.options);R!==void 0&&(u.value=R),h.t=oh(e,c,R,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(h.f=uo(N,{row:t,col:n}));const H=l.href===null?null:sn(l.href);H!==null&&(h.link=H)}return{cell:h,format:u}},ms=(e,t,n)=>{const r=e.getAttribute(t);if(r===null)return 1;const o=/^\s*\+?(\d+)/.exec(r);if(o===null)return 1;const s=Number(o[1]);return s<1?1:s>n?n:s},lh=e=>{const t=/^(\d*\.?\d+)(px|pt)$/i.exec(e.trim());if(t===null)return null;const n=Number(t[1]);return t[2].toLowerCase()==="pt"?Math.round(n*4/3):Math.round(n)},ih=(e,t)=>{const n=e.getAttribute(t);if(n===null)return null;const r=/^\s*\+?(\d*\.?\d+)/.exec(n);return r===null?null:Math.round(Number(r[1]))},Qc=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:po(n);if(r!==null){const s=r.get("display");if(s!==void 0&&s.toLowerCase()==="none")return 0;const l=r.get(t),c=l===void 0?null:lh(l);if(c!==null)return Math.min(c,on)}const o=ih(e,t);return o===null?null:Math.min(o,on)},ch=(e,t)=>{const n=[],r=o=>{const s=Qc(o,"width");for(let l=ms(o,"span",xs);l>0&&n.length<t;l-=1)n.push(s)};for(const o of wr(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of wr(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*wr(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*ah(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*uh(e){for(const t of["thead","tbody","tfoot"])for(const n of wr(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of wr(n))o.localName==="tr"&&(yield o)}}const Yo=()=>({t:""}),dh=(e,t,n)=>{const r=wc(),o=[],s=[],l=[];let c=0;for(const H of uh(e)){const L=o.length,_=(L+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const U=[];for(let k=0;k<l.length;k+=1)l[k]>0&&(U[k]=Yo(),l[k]-=1);let W=0;for(const k of wr(H)){const x=k.localName;if(x!=="td"&&x!=="th")continue;for(;U[W]!==void 0;)W+=1;const z=ms(k,"colspan",xs),I=ms(k,"rowspan",uc),T=(L+1)*Math.max(c,W+z);if(T>n)return{outcome:"limit",cells:T};const F=sh(k,L,W,t),O=r.intern(F.format);O!==void 0&&(F.cell.fmt=O),U[W]=F.cell;for(let g=1;g<z;g+=1)U[W+g]===void 0&&(U[W+g]=Yo());if(I>1)for(let g=0;g<z;g+=1){const p=I-1,C=W+g;l[C]=l[C]===void 0||l[C]<p?p:l[C]}W+=z}U.length>c&&(c=U.length),o.push(U),s.push(Qc(H,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(H=>{const L=[];for(let _=0;_<c;_+=1){const U=H[_];L.push(U===void 0?Yo():U)}return L}),h=ch(e,c),m=h.length===c&&h.every(H=>H!==null)?h.map(H=>H===null?0:H):void 0,R=s.every(H=>H!==null)?s.map(H=>H===null?0:H):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:As(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...R===void 0?{}:{rowHeights:R},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},ea=(e,t,n,r)=>{if(!Number.isInteger(r)||r<=0)throw new RangeError(`[spreadsheet] parseHtmlTable requires a positive integer maxCells, received ${r}`);let o;try{o=new DOMParser().parseFromString(e,"text/html")}catch{return{outcome:"none"}}const s=o.querySelector("table");if(s===null)return{outcome:"none"};const l=Ep(o);return dh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},Re=(e,t)=>({startRow:Math.min(e.row,t.row),endRow:Math.max(e.row,t.row),startCol:Math.min(e.col,t.col),endCol:Math.max(e.col,t.col)}),Cn=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,st=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),At=e=>e.reduce((t,n)=>t+st(n).rows*st(n).cols,0),Jt=(e,t)=>{if(e.length===1){const r=e[0];for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1)t({row:o,col:s});return}const n=new Set;for(const r of e)for(let o=r.startRow;o<=r.endRow;o+=1)for(let s=r.startCol;s<=r.endCol;s+=1){const l=`${o}:${s}`;n.has(l)||(n.add(l),t({row:o,col:s}))}},ln=(e,t,n)=>{if(t<=0||n<=0)throw new RangeError(`[spreadsheet] clampCoord requires a non-empty grid, received ${t} x ${n}`);return{row:Math.min(Math.max(Math.trunc(e.row),0),t-1),col:Math.min(Math.max(Math.trunc(e.col),0),n-1)}},It=(e,t)=>e.row===t.row&&e.col===t.col,ta=(e,t)=>e===void 0?Fl(void 0,void 0,t()):Fl(e.align,e.value,e.align===void 0?t():""),Qr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Yn=(e,t,n)=>{if(e.getCellFormula!==void 0){const r=e.getCellFormula(t,n);if(r!==void 0){if(typeof r!="string"||!r.startsWith("="))throw new RangeError(`[spreadsheet] getCellFormula(${t}, ${n}) must return a string starting with "=", received ${JSON.stringify(r)}`);return{text:r,isFormula:!0}}}return{text:e.getCellText(t,n),isFormula:!1}},eo=e=>({format:e.getCellFormat!==void 0,note:e.getCellNote!==void 0,comments:e.getCellComments!==void 0,hyperlink:e.getCellHyperlink!==void 0,validation:e.getCellValidation!==void 0,cf:e.getConditionalFormats!==void 0,formula:e.getCellFormula!==void 0}),na=e=>e.isCellReadOnly!==void 0,Ye=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,fh=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],ph=()=>!0,hh=e=>{const t=new WeakMap,n={};for(const r of fh)r!=="isCellReadOnly"&&Object.defineProperty(n,r,{enumerable:!0,get:()=>{const o=Reflect.get(e,r,e);if(typeof o!="function")return o;const s=t.get(o);if(s!==void 0)return s;const l=o.bind(e);return t.set(o,l),l}});return Object.defineProperty(n,"isCellReadOnly",{enumerable:!0,value:ph}),n},mh=/^data-[a-z0-9-]+$/,gh=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},wh=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!gh(r))throw new RangeError(`[spreadsheet] getCellAttributes must return a plain data-* record or null (got ${Object.prototype.toString.call(r)})`);for(const[o,s]of Object.entries(r)){if(!mh.test(o))throw new RangeError(`[spreadsheet] getCellAttributes key must be a lowercase data-* name (got ${JSON.stringify(o)})`);if(o.startsWith("data-aqsp")||o.startsWith("data-aqvs")||o==="data-row"||o==="data-col")throw new RangeError(`[spreadsheet] getCellAttributes key ${JSON.stringify(o)} shadows a package- or engine-emitted cell attribute`);if(typeof s!="string")throw new RangeError(`[spreadsheet] getCellAttributes value for ${JSON.stringify(o)} must be a string (got ${typeof s})`)}return r},ur=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},qn=(e,t)=>{for(const n of t)if(ur(e,n))return!0;return!1},Ch=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=st(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},gs=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=st(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},R=Math.min(u,r-m.row),N=Math.min(h,o-m.col);return R<=0||N<=0?null:Re(m,{row:m.row+R-1,col:m.col+N-1})},ra=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=gs({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,R=u.endCol-u.startCol+1,N=[];for(let H=0;H<m;H+=l){const L=[];for(let U=0;U<R;U+=c){const W={row:h.row+H,col:h.col+U};L.push(W),N.push(W)}const _=Math.min(l,m-H);for(let U=0;U<_;U+=1){const W=h.row+H+U,k=e[U];for(let x=0;x<L.length;x+=1){const z=x*c,I=Math.min(c,R-z);for(let T=0;T<I;T+=1)s(W,h.col+z+T,k[T],L[x])}}}return N},bh=(e,t,n,r,o)=>{const s=[];return ra(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},ii=(e,t,n,r,o,s)=>{const l=[],c=ra(e,t,n,r,o,(u,h,m,R)=>{const N=s(m,u,h,R);N!==null&&l.push({...N,row:u,col:h})});return{edits:l,tiles:c}},oa=(e,t)=>{const n=t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol,r=t.startRow!==e.startRow||t.endRow!==e.endRow||t.startCol!==e.startCol||t.endCol!==e.endCol;if(!(n&&r))throw new RangeError(`[spreadsheet] expandFill requires a box strictly containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`)},yh=(e,t)=>{oa(e,t);const n=st(t),r=st(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},Rh=(e,t)=>{if(!(t.startRow<=e.startRow&&t.endRow>=e.endRow&&t.startCol<=e.startCol&&t.endCol>=e.endCol))throw new RangeError(`[spreadsheet] fillExtensionRects requires a box containing the source (source ${JSON.stringify(e)}, box ${JSON.stringify(t)})`);const r=[];return t.startRow<e.startRow&&r.push(Re({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(Re({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(Re({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(Re({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},vh=(e,t,n,r)=>{oa(t,n);const o=st(t).rows,s=st(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let R=n.startCol;R<=n.endCol;R+=1){if(m&&R>=t.startCol&&R<=t.endCol)continue;const N=t.startCol+((R-t.startCol)%s+s)%s,H=h*2**21+N;let L=c.get(H);L===void 0&&(L={value:e(h,N),origin:{row:h,col:N}},c.set(H,L)),l.push(r(L.value,L.origin,{row:u,col:R}))}}return l},sa=(e,t,n)=>{const r=Yn(e,t,n),o={text:r.text,isFormula:r.isFormula};if(e.getCellFormat!==void 0){const s=e.getCellFormat(t,n);o.format=s===void 0?null:gt(s)}if(e.getCellValidation!==void 0){const s=e.getCellValidation(t,n);o.validation=s===void 0?null:s}if(e.getCellHyperlink!==void 0){const s=Un(e.getCellHyperlink(t,n));o.hyperlink=s===void 0?null:s}if(e.getCellNote!==void 0){const s=e.getCellNote(t,n);o.note=s===void 0?null:s}return o},la=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Mc(e.text,n.row-t.row,n.col-t.col):e.text};return e.format!==void 0&&(r.format=e.format),e.validation!==void 0&&(r.validation=e.validation),e.hyperlink!==void 0&&(r.hyperlink=e.hyperlink),e.note!==void 0&&(r.note=e.note),r},ho=["bold","italic","underline","strikethrough","clearFormatting","alignLeft","alignCenter","alignRight","formatNumber","formatTime","formatDate","formatCurrency","formatPercent","formatScientific","bordersOuter","bordersClear","borderTop","borderRight","borderBottom","borderLeft","insertLink","insertNote","insertComment","openHyperlink","openValidationList","pasteSpecial","fillDown","fillRight","fillSelection","insertDate","insertTime","hideRows","hideColumns","unhideRows","unhideColumns","increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth","formatGeneral","bordersAll","pasteFormats","pasteFormulas","pasteAdd","pasteSubtract","pasteMultiply","pasteDivide","multiplyBy100","multiplyBy1000","divideBy100","divideBy1000","signReversal","fillColorYellow","fillColorBlue","fillColorGreen","fillColorRed","fillColorCustom1","fillColorCustom2","fillColorCustom3","fillColorCustom4","fillColorCustom5","fontColorYellow","fontColorBlue","fontColorGreen","fontColorRed","fontColorCustom1","fontColorCustom2","fontColorCustom3","fontColorCustom4","fontColorCustom5","toggleRowHighlight","toggleColumnHighlight","toggleBothHighlight","toggleIntersectionHighlight"],Sh=/^[A-Z]$/,kh=/^[A-Za-z]$/,Eh=/^Key([A-Z])$/,ia=new Set([...Array.from({length:10},(e,t)=>`Digit${t}`),...Array.from({length:10},(e,t)=>`Numpad${t}`),"NumpadAdd","NumpadSubtract","NumpadMultiply","NumpadDivide","NumpadDecimal","NumpadEnter",...Array.from({length:12},(e,t)=>`F${t+1}`),"Semicolon","Quote","Comma","Period","Slash","Backslash","BracketLeft","BracketRight","Backquote","Minus","Equal","IntlYen","IntlRo","IntlBackslash","ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown","Enter","Escape","Space","Tab","Delete","Backspace","Insert","ContextMenu"]),Ah=e=>Sh.test(e)||ia.has(e),Qt=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!Ah(l))throw new RangeError(`[spreadsheet] shortcut ${JSON.stringify(e)} is not canonical (expected Ctrl+Alt+Shift+KEY with used modifiers only, KEY = A-Z or a code name such as Digit1 / Semicolon / F2)`);return{ctrl:r,alt:o,shift:s,key:l}},Oh=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,ca=e=>{if(kh.test(e.key))return e.key.toUpperCase();const t=Eh.exec(e.code);return t!==null?t[1]:ia.has(e.code)?e.code:null},or=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:ca(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ye=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),xh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Th=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},vr=[...xh(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...Th(),ye("bold","Ctrl+B","both","toggle bold"),ye("italic","Ctrl+I","both","toggle italic"),ye("underline","Ctrl+U","both","toggle underline"),ye("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ye("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ye("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ye("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ye("alignLeft","Ctrl+Shift+L","both","align left"),ye("alignCenter","Ctrl+Shift+E","both","align center"),ye("alignRight","Ctrl+Shift+R","both","align right"),ye("formatNumber","Ctrl+Shift+Digit1","both","number format"),ye("formatTime","Ctrl+Shift+Digit2","both","time format"),ye("formatDate","Ctrl+Shift+Digit3","both","date format"),ye("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ye("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ye("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ye("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ye("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ye("borderTop","Alt+Shift+Digit1","idle","top border"),ye("borderRight","Alt+Shift+Digit2","idle","right border"),ye("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ye("borderLeft","Alt+Shift+Digit4","idle","left border"),ye("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ye("insertNote","Shift+F2","idle","insert / edit note"),ye("insertComment","Ctrl+Alt+M","idle","insert comment"),ye("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ye("openValidationList","Alt+ArrowDown","idle","open the validation list"),ye("fillDown","Ctrl+D","idle","fill down"),ye("fillRight","Ctrl+R","idle","fill right"),ye("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ye("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ye("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ye("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ye("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ye("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),ye("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),ye("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),ye("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),ye("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),ye("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],Uo=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),ci=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),$h=e=>{const t=Qt(e);if(t.key==="IntlYen"||t.key==="IntlRo"||t.key==="IntlBackslash")return null;const n=/^(?:Digit|Numpad)(\d)$/u.exec(t.key),r=n!==null?n[1]:t.key in ci?ci[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},oo=(e,t)=>e.column==="both"||e.column===t,Lh=Array.from(new Set(vr.filter(e=>!e.rebindable&&oo(e,"idle")).map(e=>e.chord))),Ps=new Set(vr.filter(e=>e.command!==void 0&&oo(e,"editing")).map(e=>e.command)),Dh=new Set(vr.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),aa=e=>{const t={};for(const n of ho)t[n]=e(n);return t},ua=aa(e=>vr.filter(t=>t.command===e).map(t=>t.chord)),Mh=e=>{const t=new Map;for(const n of ho){const r=e[n];if(r!=null)for(const o of r){const s=t.get(o);s===void 0?t.set(o,[n]):s.includes(n)||s.push(n)}}return t},zh=e=>{const t=new Set(ho);for(const n of Object.keys(e)){if(!t.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not a SpreadsheetCommand`);const r=e[n];if(r!==void 0){if(Dh.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},Nh=(e,t)=>{const n=Qt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Ps.has(e);for(const o of vr)if(!(o.rebindable||o.command===e||o.chord!==t)&&(oo(o,"idle")||r&&oo(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Fh=e=>{e!==void 0&&zh(e);const t=aa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?ua[r]:o===null?[]:o});for(const r of ho)for(const o of t[r])Nh(r,o);const n=new Map;for(const[r,o]of Mh(t)){if(o.length>1)throw new RangeError(`[spreadsheet] shortcut ${r} bound to ${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`);n.set(r,o[0])}return n},ai=(e,t)=>{const n=ca(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Oh({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},_s=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],ui=[...Je.VIRTUAL_SCROLL_LABEL_KEYS,..._s],ws=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),da=Object.freeze({en:Object.freeze({...Je.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...ws.en}),ja:Object.freeze({...Je.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...ws.ja})}),mn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,di=e=>e==="commentCount"||e==="listMore",Ph=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${mn(t)}`);for(const n of _s){const r=e[n];if(!(di(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=di(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${mn(r)}`)}}},_h=e=>{const t={};let n=!1;for(const r of Je.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},qh=(e,t,n)=>{e[t]=n},fa=(e,t)=>{const n=Je.resolveVirtualScrollLocale(e);if(t===void 0)return da[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${mn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!ui.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${ui.join(", ")}`);const s={...Je.resolveVirtualScrollLabels(n,_h(t)),...ws[n]};for(const l of _s){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&qh(s,l,c)}return Ph(s),Object.freeze(s)},Ih=e=>{const t={};for(const n of Je.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},ze=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},fi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},jh={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},Hh=(e,t,n,r)=>{switch(e){case"gt":case"gte":case"lt":case"lte":return`${r[e]} ${t}`;case"eq":return`equal to ${t}`;case"neq":return`not equal to ${t}`;case"between":return`between ${t} and ${n}`;default:return`not between ${t} and ${n}`}},Xo=(e,t)=>{const n=r=>(o,s)=>`${e} ${Hh(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},Bh=Object.freeze({list:"Value must be one of the list items.",number:Xo("Value must be a number",fi),textLength:Xo("Text length must be",fi),date:Xo("Value must be a date",jh),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),Vh=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),Go=Object.freeze({en:Bh,ja:Vh}),Wh=Object.freeze({ok:!0}),Kh="TRUE",Yh="FALSE",Uh=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Xh=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),Gh=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,Zh=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,Jh=/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/,pi=e=>{const t=e.trim();if(!(Gh.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,R=m.search(/[^0]/);return R<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(R).replace(/0+$/,""),point:u.length+l-R}},Qh=e=>e===1?-1:e===-1?1:0,em=(e,t)=>{if(e.sign!==t.sign)return e.sign<t.sign?-1:1;if(e.sign===0)return 0;const n=e.point!==t.point?e.point<t.point?-1:1:e.digits===t.digits?0:e.digits<t.digits?-1:1;return e.sign===1?n:Qh(n)},tm=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},hi=e=>{const t=Zh.exec(e.trim());if(t===null)return null;const n=Number(t[1]),r=Number(t[3]),o=Number(t[4]),s=t[5]===void 0?0:Number(t[5]),l=t[6]===void 0?0:Number(t[6]),c=t[7]===void 0?0:Number(t[7]);return r<1||r>12||o<1||o>tm(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},nm=(e,t)=>{const n=[e.year,e.month,e.day,e.hour,e.minute,e.second],r=[t.year,t.month,t.day,t.hour,t.minute,t.second];for(let o=0;o<n.length;o+=1)if(n[o]!==r[o])return n[o]<r[o]?-1:1;return 0},rm=(e,t)=>e<t?-1:e>t?1:0,om=e=>e==="between"||e==="notBetween",sm=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!om(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},lm=(e,t,n)=>{switch(e){case"gt":return t===1;case"gte":return t!==-1;case"lt":return t===-1;case"lte":return t!==1;case"eq":return t===0;case"neq":return t!==0;case"between":return t!==-1&&n!==1;default:return t===-1||n===1}},Zo=(e,t,n,r,o,s)=>{const l=sm(e,t,n,r);return l===null?!0:o===null?!1:lm(e,s(o,l.a),l.b===null?0:s(o,l.b))},im=e=>Number.isFinite(e)?e:null,cm=e=>{let t=0;for(const n of e)t+=1;return t},am=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),um=(e,t)=>{switch(e.op){case"isEmail":return Jh.test(t);case"isUrl":return am(t)}if(e.value===void 0)return!0;switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);default:return t.endsWith(e.value)}},dm=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,pa=e=>({checked:e.checked===void 0?Kh:e.checked,unchecked:e.unchecked===void 0?Yh:e.unchecked}),fm=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!Uh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${mn(e.op)} for type "${e.type}"`);return;case"text":if(!Xh.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${mn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${mn(e.type)}`)}},pm=(e,t,n)=>{switch(e.type){case"list":return gm(e).has(t);case"number":return Zo(e.op,e.a,e.b,pi,pi(t),em);case"textLength":return Zo(e.op,e.a,e.b,im,cm(t),rm);case"date":return Zo(e.op,e.a,e.b,hi,hi(t),nm);case"text":return um(e,t);case"checkbox":{const r=pa(e);return t===r.checked||t===r.unchecked}default:return n===void 0||dm(n(e.formula))}},ha=(e,t,n)=>(fm(e),t===""||pm(e,t,n)),mi=e=>e===void 0?void 0:e.trim(),hm=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),mi(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),mi(e.b));case"text":return mm(e,t.text);case"checkbox":{const n=pa(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},mm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},gi=new WeakMap,gm=e=>{const t=gi.get(e);if(t!==void 0)return t;const n=new Set(e.values);return gi.set(e,n),n},ma=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(Go,n)){const o=Object.keys(Go).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${mn(n)}`)}return ha(e,t,r)?Wh:{ok:!1,message:e.errorMessage===void 0?hm(e,Go[n]):e.errorMessage}},wm=e=>e.type!=="custom",Cm=(e,t)=>wm(e)&&!ha(e,t,void 0),ga=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),wa=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Ca=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,ba=(e,t,{scroll:n,frozenSize:r,trailingSize:o,extent:s})=>r>0&&t<r?e.indexAt(t):o>0&&s>0&&t>=s-o?e.indexAt(e.totalSize()-(s-t)):e.indexAt(t+n),ya=(e,t)=>ga(e,t),Ra=(e,t)=>ga(e,t),va=(e,t)=>wa(e,t),Sa=(e,t)=>wa(e,t),gn=(e,t,n)=>Ca(e,t,n),wn=(e,t,n)=>Ca(e,t,n),Sr=(e,t,n)=>ba(e,t,n),kr=(e,t,n)=>ba(e,t,n),bm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Zt=1,dr=3,Ir=e=>`${-Math.min(dr,Math.max(0,Math.floor(e)))}px`,ka=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),ym=16,Rm=450,vm=e=>e>4?Math.floor(Rm/(5*e)):ym,sr=(e,t)=>{const n=document.createElement("div");return n.className="aqsp-band",n.setAttribute("data-aqsp-band",e),t!==null&&n.setAttribute("data-aqsp-band-edge",t),n.style.display="none",n},wi=()=>({rowLeft:sr("row","left"),rowRight:sr("row","right"),colAbove:sr("column","above"),colBelow:sr("column","below"),cross:sr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Ea=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],jr=(e,t,n)=>{const r=`${t}px`,o=`${n}px`;e.rowLeft.style.width=r,e.rowRight.style.width=r,e.colAbove.style.height=o,e.colBelow.style.height=o},Hr=(e,t)=>Math.min(Math.max(e,0),t),Ci="inset(100%)",Hn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Sm=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Hn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const N=`${t.height}px`;e.rowLeft.style.height=N,e.rowRight.style.height=N}const m=`translate(${Hr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const R=`translate(${Hr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;R!==s.rowRightTransform&&(s.rowRightTransform=R,e.rowRight.style.transform=R)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Hn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const N=`${t.width}px`;e.colAbove.style.width=N,e.colBelow.style.width=N}const m=`translate(${t.left}px, ${Hr(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const R=`translate(${t.left}px, ${Hr(t.top+t.height,n.clampHeight)}px)`;R!==s.colBelowTransform&&(s.colBelowTransform=R,e.colBelow.style.transform=R)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Hn([e.cross],h)),u!==null){u!==s.crossTint&&(s.crossTint=u,e.cross.style.background=u==="intersection"?"":`var(--_aqsp-band-${u})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`);const m=`translate(${t.left}px, ${t.top}px)`;m!==s.crossTransform&&(s.crossTransform=m,e.cross.style.transform=m)}},bi=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Hn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Hn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Hn([e.cross],!1))},yi=e=>{for(const t of Ea(e))t.remove()},km=(e,t)=>{const n=e-1-t.lineBoxPx;return t.verticalAlign==="top"?0:t.verticalAlign==="bottom"?Math.max(0,n):Math.max(0,n/2)},Em=Object.freeze([]),Ri=e=>e.dividers[0]??e.active,Am={left:"0px",right:"0px",width:""},Om={top:"0px",bottom:"0px",height:""},vi=()=>({container:null,active:null,dragRect:null,marquee:null,fillPreview:null,resizeGuide:null,fillPool:[],bandPool:[],dragBand:null,bandClampWidth:-1,bandClampHeight:-1,dividerSlots:[null,null,null,null],dividerShown:[!1,!1,!1,!1],dividers:[]}),Si=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],ki=6,xm=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:R,fillFrameRef:N,resizeGuideFrameRef:H,fillHandleNodeRef:L,enableFillHandle:_,frozenCols:U,frozenRows:W,trailingCols:k,trailingRows:x,sinkAriaLabel:z,sinkReadOnly:I,sinkKeyShortcuts:T,onSinkMouseDown:F,editPaintRef:O,highlightRef:g,highlightColors:p,popoverAnchors:C,interactiveAnchorRef:v,tipAnchorRef:S})=>{const b=i.useRef(null),y=i.useRef(null),a=i.useRef(null),f=i.useRef(new Map(Si.map(M=>[M,vi()]))),E=i.useCallback(M=>{const B=f.current.get(M);if(B!==void 0)return B;const X=vi();return f.current.set(M,X),X},[]),d=i.useCallback((M,B,X)=>{if(M===null)return;const V=M.style;V.left!==B.left&&(V.left=B.left),V.right!==B.right&&(V.right=B.right),V.width!==B.width&&(V.width=B.width),V.top!==X.top&&(V.top=X.top),V.bottom!==X.bottom&&(V.bottom=X.bottom),V.height!==X.height&&(V.height=X.height)},[]),$=i.useCallback((M,B,X)=>{if(!(M.bandClampWidth===B&&M.bandClampHeight===X)){M.bandClampWidth=B,M.bandClampHeight=X;for(const V of M.bandPool)jr(V,B,X);M.dragBand!==null&&jr(M.dragBand,B,X)}},[]),A=i.useRef({rowAxis:e,colAxis:t});A.current={rowAxis:e,colAxis:t};const D=i.useCallback((M,B,X)=>{const V=M.dividerSlots[B];V===null||M.dividerShown[B]===X||(M.dividerShown[B]=X,V.style.display=X?"":"none")},[]),q=i.useRef({x:0,y:0}),j=i.useRef(null),K=i.useCallback((M,B)=>{const X=n.current,V=X?.getFrozenSize()??bm,ee=X?.getViewportSize(),se=ee?.width??-1,ne=ee?.height??-1,Oe=q.current;Oe.x=M,Oe.y=B;let Se=j.current;if(Se===null||Se.frozenCols!==V.cols||Se.frozenWidth!==V.width||Se.frozenRows!==V.rows||Se.frozenHeight!==V.height||Se.trailingCols!==V.trailingCols||Se.trailingWidth!==V.trailingWidth||Se.trailingVisibleWidth!==V.trailingVisibleWidth||Se.trailingRows!==V.trailingRows||Se.trailingHeight!==V.trailingHeight||Se.trailingVisibleHeight!==V.trailingVisibleHeight||Se.bodyWidth!==se||Se.bodyHeight!==ne){const ie=V.trailingVisibleWidth,ce=V.trailingVisibleHeight,ge=V.cols<=0&&V.trailingCols<=0?[{kind:"m",map:re=>re-Oe.x,clamp:se,style:Am,seamLead:!1,seamTrail:!1}]:[...V.cols>0?[{kind:"f",map:re=>re,clamp:V.width,style:{left:"0px",width:`${V.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:re=>re-Oe.x-V.width,clamp:Math.max(0,se-V.width-ie),style:{left:`${V.width}px`,right:`${ie}px`,width:""},seamLead:V.cols>0,seamTrail:V.trailingCols>0},...V.trailingCols>0?[{kind:"t",map:re=>re-A.current.colAxis.totalSize()+ie,clamp:ie,style:{left:"",right:"0px",width:`${ie}px`},seamLead:!0,seamTrail:!1}]:[]],Ce=V.rows<=0&&V.trailingRows<=0?[{kind:"m",map:re=>re-Oe.y,clamp:ne,style:Om,seamLead:!1,seamTrail:!1}]:[...V.rows>0?[{kind:"f",map:re=>re,clamp:V.height,style:{top:"0px",height:`${V.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:re=>re-Oe.y-V.height,clamp:Math.max(0,ne-V.height-ce),style:{top:`${V.height}px`,bottom:`${ce}px`,height:""},seamLead:V.rows>0,seamTrail:V.trailingRows>0},...V.trailingRows>0?[{kind:"t",map:re=>re-A.current.rowAxis.totalSize()+ce,clamp:ce,style:{top:"",bottom:"0px",height:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],he=[];for(const re of ge)for(const ke of Ce)he.push({nodes:E(`${re.kind}${ke.kind}`),xKind:re.kind,yKind:ke.kind,mapX:re.map,clampWidth:re.clamp,xStyle:re.style,xSeamLead:re.seamLead,xSeamTrail:re.seamTrail,mapY:ke.map,clampHeight:ke.clamp,yStyle:ke.style,ySeamLead:ke.seamLead,ySeamTrail:ke.seamTrail});Se={frozenCols:V.cols,frozenWidth:V.width,frozenRows:V.rows,frozenHeight:V.height,trailingCols:V.trailingCols,trailingWidth:V.trailingWidth,trailingVisibleWidth:V.trailingVisibleWidth,trailingRows:V.trailingRows,trailingHeight:V.trailingHeight,trailingVisibleHeight:V.trailingVisibleHeight,bodyWidth:se,bodyHeight:ne,ctxs:he},j.current=Se}const Be=V.width>0,Ve=V.trailingWidth>0,_e=V.height>0,ve=V.trailingHeight>0;for(const ie of Se.ctxs)d(ie.nodes.container,ie.xStyle,ie.yStyle),$(ie.nodes,ie.clampWidth,ie.clampHeight),D(ie.nodes,0,Be),D(ie.nodes,1,Ve),D(ie.nodes,2,_e),D(ie.nodes,3,ve);return Se.ctxs},[n,E,d,$,D]),G=i.useCallback((M,B,X)=>{M.dividerSlots[B]=X,M.dividerShown[B]=!1,M.dividers.length=0;for(const V of M.dividerSlots)V!==null&&M.dividers.push(V)},[]),J=i.useCallback(M=>{const B=()=>E(M);return{container:X=>{const V=B();V.container=X,X===null&&(V.fillPool.length=0,V.bandPool.length=0,V.dragBand=null,V.bandClampWidth=-1,V.bandClampHeight=-1)},dividerXLeading:X=>G(B(),0,X),dividerXTrailing:X=>G(B(),1,X),dividerYLeading:X=>G(B(),2,X),dividerYTrailing:X=>G(B(),3,X),active:X=>{B().active=X},dragRect:X=>{B().dragRect=X},marquee:X=>{B().marquee=X},fillPreview:X=>{B().fillPreview=X},resizeGuide:X=>{B().resizeGuide=X}}},[E,G]),te=i.useMemo(()=>Object.fromEntries(Si.map(M=>[M,J(M)])),[J]),le=Math.min(Math.max(0,U),t.count),me=ya(t,le),Ee=Math.min(Math.max(0,W),e.count),xe=Ra(e,Ee),De=k===void 0?0:Math.min(Math.max(0,k),t.count-le),Pe=va(t,De),ue=x===void 0?0:Math.min(Math.max(0,x),e.count-Ee),Ne=Sa(e,ue),Ue=i.useRef(null),je=i.useRef("add"),Ot=i.useRef(s);Ot.current=s;const xt=i.useRef(!1),He=Je.useWheelBridge(n,{enableBridge:!s}),wt=i.useCallback(M=>(r.current=M,He(M)),[r,He]),bn=i.useCallback((M,B)=>({top:B.mapY(e.offsetOf(M.startRow)),bottom:B.mapY(e.offsetOf(M.endRow)+e.sizeOf(M.endRow)),left:B.mapX(t.offsetOf(M.startCol)),right:B.mapX(t.offsetOf(M.endCol)+t.sizeOf(M.endCol))}),[e,t]),lt=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const{top:X,bottom:V,left:ee,right:se}=bn(M,B),ne=-B.clampHeight*Zt,Oe=B.clampHeight*(1+Zt),Se=-B.clampWidth*Zt,Be=B.clampWidth*(1+Zt);if(V<ne||X>Oe||se<Se||ee>Be)return null;const Ve=Math.max(X,ne),_e=Math.max(ee,Se);return{top:Ve,left:_e,width:Math.min(se,Be)-_e,height:Math.min(V,Oe)-Ve}},[bn]),Er=i.useCallback((M,B)=>{if(B.clampHeight<=0||B.clampWidth<=0)return null;const X=bn(M,B),V=-B.clampHeight*Zt,ee=B.clampHeight*(1+Zt),se=-B.clampWidth*Zt,ne=B.clampWidth*(1+Zt),Oe=Math.min(Math.max(X.top,V),ee),Se=Math.min(Math.max(X.left,se),ne);return{top:Oe,left:Se,width:Math.min(Math.max(X.right,se),ne)-Se,height:Math.min(Math.max(X.bottom,V),ee)-Oe}},[bn]),yn=i.useCallback(()=>{if(g===void 0)return null;const M=g.current;return M.row||M.column||M.intersection?M:null},[g]),oe=i.useCallback((M,B,X)=>{const V=B.fillPool[0]?.node??Ri(B);for(const ee of Ea(X))M.insertBefore(ee,V)},[]),fe=i.useCallback((M,B,X,V)=>{const ee=Er(B,X);if(ee===null){bi(M);return}Sm(M,ee,X,V,Cc(B,t.count)||bc(B,e.count))},[Er,e,t]),pe=i.useCallback((M,B,X,V)=>{const ee=M.nodes.bandPool;for(;ee.length>X.length;){const se=ee.pop();se!==void 0&&yi(se)}if(V===null){M.nodes.dragBand!==null&&(yi(M.nodes.dragBand),M.nodes.dragBand=null);return}for(let se=0;se<X.length;se+=1){let ne=ee[se];ne===void 0&&(ne=wi(),jr(ne,M.clampWidth,M.clampHeight),oe(B,M.nodes,ne),ee.push(ne)),fe(ne,X[se],M,V)}},[oe,fe]),Ht=i.useCallback((M,B,X)=>{const V=M.nodes.container;if(V===null)return;if(B===null||X===null){M.nodes.dragBand!==null&&bi(M.nodes.dragBand);return}let ee=M.nodes.dragBand;ee===null&&(ee=wi(),jr(ee,M.clampWidth,M.clampHeight),oe(V,M.nodes,ee),M.nodes.dragBand=ee),fe(ee,B,M,X)},[oe,fe]),Ae=i.useCallback((M,B)=>{if(M!==null){if(B===null){M.style.display="none";return}M.style.display="block",M.style.transform=`translate(${B.left}px, ${B.top}px)`,M.style.width=`${B.width}px`,M.style.height=`${B.height}px`}},[]),Bt=i.useCallback((M,B,X,V)=>{const ee=V==="point"?null:yn();for(const se of K(X,B))Ae(se.nodes.dragRect,lt(M,se)),Ht(se,M,ee)},[lt,K,Ae,yn,Ht]),it=i.useCallback((M,B,X)=>{for(const V of K(X,B))Ae(V.nodes.fillPreview,M===null?null:lt(M,V))},[lt,K,Ae]),Rn=i.useCallback((M,B,X)=>{for(const V of K(X,B)){const ee=V.nodes.resizeGuide;if(ee===null)continue;if(M===null){ee.style.display="none";continue}const se=M.anchor==="trailing";if(M.axis==="col"){if(se&&V.xKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ne=V.mapX(M.position);ee.style.transform=`translate(${se?Math.max(0,ne):ne}px, 0px)`,ee.style.width="1px",ee.style.height="100%"}else{if(se&&V.yKind!=="t"){ee.style.display="none";continue}ee.style.display="block";const ne=V.mapY(M.position);ee.style.transform=`translate(0px, ${se?Math.max(0,ne):ne}px)`,ee.style.width="100%",ee.style.height="1px"}}},[K]),Vt=i.useCallback((M,B,X,V,ee,se,ne)=>{if(M===null)return;if(B===null||ne<=0||se<=0){M.style.clipPath=Ci;return}const Oe=wn(e,B.row,V),Se=gn(t,B.col,X),Be=t.sizeOf(B.col),Ve=e.sizeOf(B.row),_e=Se>=se||Oe>=ne,ve=B.col>=ee.cols&&Se<ee.width,ie=B.row>=ee.rows&&Oe<ee.height,ce=ee.trailingWidth>0&&B.col<t.count-ee.trailingCols&&Se+Be>se-ee.trailingVisibleWidth,ge=ee.trailingHeight>0&&B.row<e.count-ee.trailingRows&&Oe+Ve>ne-ee.trailingVisibleHeight;if(_e||ve||ie||ce||ge){M.style.clipPath=Ci;return}M.style.clipPath="",M.style.transform=`translate(${Se}px, ${Oe}px)`;const Ce=`${Be} ${Ve}`;M.dataset.aqspAnchorSig!==Ce&&(M.dataset.aqspAnchorSig=Ce,M.style.width=`${Be}px`,M.style.height=`${Ve}px`)},[e,t]),Ar=i.useCallback((M,B,X)=>{if(C===void 0)return;const V=C.current,{width:ee,height:se}=M.getViewportSize(),ne=M.getFrozenSize(),Oe={scroll:X,frozenCount:ne.cols,trailingCount:ne.trailingCols,extent:ee},Se={scroll:B,frozenCount:ne.rows,trailingCount:ne.trailingRows,extent:se};Vt(v===void 0?null:v.current,V.interactive,Oe,Se,ne,ee,se),Vt(S===void 0?null:S.current,V.tip,Oe,Se,ne,ee,se)},[C,v,S,Vt]),Xn=i.useCallback(()=>{const M=b.current,B=n.current;if(M===null||B===null)return;const X=B.getScrollPosition(),V=Math.max(0,X.y),ee=Math.max(0,X.x),se=o(),ne=K(ee,V),Oe=yn(),Se=Oe===null?Em:se.ranges.slice(-vm(ne.length));for(const ie of ne){const ce=ie.nodes.container;if(ce===null)continue;const ge=ie.nodes.fillPool;for(let Ce=0;Ce<Math.max(ge.length,se.ranges.length);Ce+=1){let he=ge[Ce];if(he===void 0){const Me=document.createElement("div");Me.className="aqsp-selection-fill",Me.setAttribute("data-aqsp-fill",""),Me.style.display="none",ce.insertBefore(Me,Ri(ie.nodes)),he={node:Me,last:{shown:!1,width:-1,height:-1,transform:""}},ge.push(he)}const re=se.ranges[Ce],ke=re===void 0?null:lt(re,ie);if(ke===null)he.last.shown&&(he.last.shown=!1,he.node.style.display="none");else{he.last.shown||(he.last.shown=!0,he.node.style.display="block");const Me=`translate(${ke.left}px, ${ke.top}px)`;Me!==he.last.transform&&(he.last.transform=Me,he.node.style.transform=Me),ke.width!==he.last.width&&(he.last.width=ke.width,he.node.style.width=`${ke.width}px`),ke.height!==he.last.height&&(he.last.height=ke.height,he.node.style.height=`${ke.height}px`)}}for(;ge.length>se.ranges.length;)ge.pop()?.node.remove();Ae(ie.nodes.active,lt(Re(se.active,se.active),ie)),pe(ie,ce,Se,Oe)}const Be=h(),Ve=Be===null||Be.foreign?null:Be;for(const ie of ne){const ce=ie.nodes.marquee;if(ce===null)continue;const ge=Ve===null?null:lt(Ve.range,ie),Ce=ge!==null&&(ie.xSeamTrail&&ge.left>=ie.clampWidth&&ge.left<ie.clampWidth+dr||ie.xSeamLead&&ge.left+ge.width<=0&&ge.left+ge.width>-dr||ie.ySeamTrail&&ge.top>=ie.clampHeight&&ge.top<ie.clampHeight+dr||ie.ySeamLead&&ge.top+ge.height<=0&&ge.top+ge.height>-dr)?null:ge;if(Ce===null)ce.style.display="none";else{ce.style.display="block",ce.style.transform=`translate(${Ce.left}px, ${Ce.top}px)`,ce.style.width=`${Ce.width}px`,ce.style.height=`${Ce.height}px`;const ke=Ir(Ce.top),Me=Ir(Ce.left),Ct=Ir(ie.clampHeight-(Ce.top+Ce.height)),ct=Ir(ie.clampWidth-(Ce.left+Ce.width)),bt=`${ke} ${ct} ${Ct} ${Me}`;bt!==ce.dataset.aqspOutsetSig&&(ce.dataset.aqspOutsetSig=bt,ce.style.setProperty("--aqsp-clip-outset-top",ke),ce.style.setProperty("--aqsp-clip-outset-right",ct),ce.style.setProperty("--aqsp-clip-outset-bottom",Ct),ce.style.setProperty("--aqsp-clip-outset-left",Me))}const he=Ce===null?null:Ve?.kind??null,re=ce.dataset.aqspClipKindLast??null;he!==re&&(he===null?(delete ce.dataset.aqspClipKindLast,ce.removeAttribute("data-aqsp-clip-kind")):(ce.dataset.aqspClipKindLast=he,ce.setAttribute("data-aqsp-clip-kind",he)))}Ue.current!==null&&Bt(Ue.current,V,ee,je.current),a.current!==null&&Rn(a.current,V,ee),y.current!==null&&it(y.current,V,ee);const _e=L.current;if(_e!==null&&!R()){const{width:ie,height:ce}=B.getViewportSize(),ge=se.ranges[se.ranges.length-1];if(!(se.ranges.length===1&&!Ot.current&&!m())||ce<=0||ie<=0)_e.style.display="none";else{const he=B.getFrozenSize(),re={scroll:ee,frozenCount:he.cols,trailingCount:he.trailingCols,extent:ie},ke={scroll:V,frozenCount:he.rows,trailingCount:he.trailingRows,extent:ce},Me=ge.endCol<he.cols,Ct=ge.endRow<he.rows,ct=ge.endCol>=t.count-he.trailingCols,bt=ge.endRow>=e.count-he.trailingRows,Tt=gn(t,ge.endCol,re)+t.sizeOf(ge.endCol),$t=wn(e,ge.endRow,ke)+e.sizeOf(ge.endRow),Kt=Me||ct?0:he.width,yt=Ct||bt?0:he.height,Sn=ct?ie:ie-he.trailingVisibleWidth,kn=bt?ce:ce-he.trailingVisibleHeight;$t<=yt||$t>kn||Tt<=Kt||Tt>Sn?_e.style.display="none":(_e.style.display="block",_e.style.transform=`translate(${Tt-ki+1}px, ${$t-ki+1}px)`)}}const ve=r.current;if(ve!==null){const ie=se.active,{width:ce,height:ge}=B.getViewportSize(),Ce=B.getFrozenSize(),he={scroll:ee,frozenCount:Ce.cols,trailingCount:Ce.trailingCols,extent:ce},re={scroll:V,frozenCount:Ce.rows,trailingCount:Ce.trailingRows,extent:ge},ke=wn(e,ie.row,re),Me=gn(t,ie.col,he),Ct=ge>0?Math.min(Math.max(ke,0),Math.max(0,ge-1)):0,ct=ce>0?Math.min(Math.max(Me,0),Math.max(0,ce-1)):0;ve.style.top=`${Ct}px`,ve.style.left=`${ct}px`,Ot.current?(ve.style.width=`${t.sizeOf(ie.col)}px`,ve.style.height=`${e.sizeOf(ie.row)}px`,ve.style.paddingTop=`${km(e.sizeOf(ie.row),O===void 0?Pt:O.current)}px`):(ve.style.width="1px",ve.style.height="1px",ve.style.paddingTop="0px");const bt=ie.col>=Ce.cols&&Me<Ce.width,Tt=ie.row>=Ce.rows&&ke<Ce.height,$t=Ce.trailingWidth>0&&ie.col<t.count-Ce.trailingCols&&Me+t.sizeOf(ie.col)>ce-Ce.trailingVisibleWidth,Kt=Ce.trailingHeight>0&&ie.row<e.count-Ce.trailingRows&&ke+e.sizeOf(ie.row)>ge-Ce.trailingVisibleHeight,yt=Ot.current&&ke===Ct&&Me===ct&&!bt&&!Tt&&!$t&&!Kt;yt!==xt.current&&(xt.current=yt,yt?ve.setAttribute("data-aqsp-editing",""):ve.removeAttribute("data-aqsp-editing"))}Ar(B,V,ee)},[n,lt,K,Ae,Bt,Rn,it,h,o,m,R,L,r,e,t,yn,pe,O,Ar]),mo=i.useCallback((M,B)=>{Ue.current=M,je.current=B;const X=M===null?"add":B;for(const se of K(0,0)){const ne=se.nodes.dragRect;if(ne===null)continue;const Oe=ne.dataset.aqspDragModeLast??"add";X!==Oe&&(ne.dataset.aqspDragModeLast=X,X==="add"?ne.removeAttribute("data-aqsp-drag-mode"):ne.setAttribute("data-aqsp-drag-mode",X))}const V=n.current;if(M===null||V===null){for(const se of K(0,0))se.nodes.dragRect!==null&&(se.nodes.dragRect.style.display="none"),Ht(se,null,null);return}const ee=V.getScrollPosition();Bt(M,Math.max(0,ee.y),Math.max(0,ee.x),B)},[n,Bt,K,Ht]),Or=i.useCallback(M=>{y.current=M;const B=n.current;if(B===null){for(const V of K(0,0))V.nodes.fillPreview!==null&&(V.nodes.fillPreview.style.display="none");return}const X=B.getScrollPosition();it(M,Math.max(0,X.y),Math.max(0,X.x))},[n,it,K]),go=i.useCallback(M=>{a.current=M;const B=n.current;if(B===null){for(const V of K(0,0))V.nodes.resizeGuide!==null&&(V.nodes.resizeGuide.style.display="none");return}const X=B.getScrollPosition();Rn(M,Math.max(0,X.y),Math.max(0,X.x))},[n,Rn,K]);i.useLayoutEffect(()=>{const M=b.current;if(!(M===null||p===void 0))return M.style.setProperty("--aqsp-band-row",p.row),M.style.setProperty("--aqsp-band-column",p.column),M.style.setProperty("--aqsp-band-intersection",p.intersection),M.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{M.style.removeProperty("--aqsp-band-row"),M.style.removeProperty("--aqsp-band-column"),M.style.removeProperty("--aqsp-band-intersection"),M.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=Xn,u.current=mo,N.current=Or,H.current=go,()=>{c.current=null,u.current=null,N.current=null,H.current=null})),i.useEffect(()=>{Xn()},[Xn,s,le,Ee,De,ue]),i.useEffect(()=>{const M=r.current;if(M===null)return;const B=X=>F(X);return M.addEventListener("mousedown",B),()=>M.removeEventListener("mousedown",B)},[r,F]);const Hs=le>0||De>0?[...le>0?[{k:"f",style:{left:0,width:me}}]:[],{k:"s",style:{left:me,right:Pe}},...De>0?[{k:"t",style:{right:0,width:Pe}}]:[]]:[{k:"m",style:{left:0,right:0}}],wo=Ee>0||ue>0?[...Ee>0?[{k:"f",style:{top:0,height:xe}}]:[],{k:"s",style:{top:xe,bottom:Ne}},...ue>0?[{k:"t",style:{bottom:0,height:Ne}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Wt=M=>M==="m"?0:M==="s"?1:M==="t"?2:3,vn=Hs.flatMap(M=>wo.map(B=>({xk:M.k,yk:B.k,key:`${M.k}${B.k}`,style:{...M.style,...B.style}}))).sort((M,B)=>Wt(M.key[0])+Wt(M.key[1])-(Wt(B.key[0])+Wt(B.key[1]))),Gn=M=>M==="mm"?{"data-aqsp-overlay-main":""}:M==="fm"?{"data-aqsp-overlay-frozen":""}:M==="sm"?{"data-aqsp-overlay-scroll":""}:{};return Y.jsxs("div",{ref:b,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Te.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[vn.map(({xk:M,yk:B,key:X,style:V})=>{const ee=te[X];return Y.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":X,...Gn(X),style:V,ref:ee.container,children:[M==="s"&&le>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0,display:"none"},ref:ee.dividerXLeading}):null,M==="s"&&De>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0,display:"none"},ref:ee.dividerXTrailing}):null,B==="s"&&Ee>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0,display:"none"},ref:ee.dividerYLeading}):null,B==="s"&&ue>0?Y.jsx("div",{className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0,display:"none"},ref:ee.dividerYTrailing}):null,Y.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:ee.active}),Y.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:ee.dragRect}),Y.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:ee.marquee}),Y.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:ee.fillPreview}),Y.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:ee.resizeGuide})]},X)}),Y.jsx("textarea",{ref:wt,className:"aqsp-sink","aria-label":z,"aria-readonly":I?"true":void 0,"aria-keyshortcuts":T,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?Y.jsx("div",{ref:L,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Aa=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=R=>{l.current=!0;try{R()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=R=>{if(R.key==="Escape"){R.preventDefault(),c(e.close);return}R.key==="Enter"&&(R.ctrlKey||R.metaKey)&&!R.altKey&&!R.shiftKey&&(R.preventDefault(),u())},m=R=>{l.current||R.relatedTarget instanceof Node&&R.currentTarget.contains(R.relatedTarget)||e.rejected||c(e.close)};return Y.jsxs("div",{className:"aqsp-popover-comment","data-aqsp-popover":"comment","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:m,children:[Y.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:[ze(t,"commentTitle"),Y.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:ze(t,"commentCount",e.current.length)})]}),Y.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(R=>Y.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":R.id,children:[Y.jsx("span",{className:"aqsp-popover-comment-author",children:R.author}),Y.jsx("time",{className:"aqsp-popover-comment-time",dateTime:R.createdAt,children:R.createdAt}),Y.jsx("p",{className:"aqsp-popover-comment-text",children:R.text})]},R.id))}),Y.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":ze(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:R=>r(R.currentTarget.value),onKeyDown:h}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:ze(t,"commentPost")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Oa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.current.text),[o,s]=i.useState(e.current.url===void 0?"":e.current.url),l=e.cellReadOnly===!0,c=i.useId(),u=i.useRef(!1),h=o.trim()===""?null:sn(o),m=o.trim()!==""&&h===null,R=_=>{u.current=!0;try{_()}finally{u.current=!1}},N=()=>{l||m||R(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},H=_=>{if(_.key==="Escape"){_.preventDefault(),R(e.close);return}_.key==="Enter"&&!_.altKey&&!_.shiftKey&&(_.preventDefault(),N())},L=_=>{u.current||_.relatedTarget instanceof Node&&_.currentTarget.contains(_.relatedTarget)||e.rejected||R(e.close)};return Y.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:L,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:ze(t,"linkTitle")}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:ze(t,"linkTextField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:_=>r(_.currentTarget.value),onKeyDown:H})]}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:ze(t,"linkUrlField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:_=>s(_.currentTarget.value),onKeyDown:H})]}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m||l,"aria-disabled":l?"true":void 0,onClick:N,children:ze(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:ze(t,"linkOpen")}):null,Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>R(e.close),children:"×"})]})]})},Ei=500,xa=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),u=i.useMemo(()=>{const W=n.toLowerCase();return e.current.filter(k=>k.toLowerCase().startsWith(W))},[e.current,n]),h=i.useMemo(()=>u.length>Ei?u.slice(0,Ei):u,[u]),m=u.length-h.length,R=h.length===0?-1:Math.min(o,h.length-1),N=W=>{c.current=!0;try{W()}finally{c.current=!1}},H=()=>{R<0||N(()=>e.commit(h[R]))},L=W=>{if(W.key==="Escape"){W.preventDefault(),N(e.close);return}if(W.key==="Enter"){W.preventDefault(),H();return}if(W.key==="ArrowDown"){W.preventDefault(),s(R+1);return}W.key==="ArrowUp"&&(W.preventDefault(),s(Math.max(R-1,0)))},_=W=>{c.current||W.relatedTarget instanceof Node&&W.currentTarget.contains(W.relatedTarget)||N(e.close)},U=W=>`${l}-${W}`;return Y.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:_,children:[Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":ze(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":R<0?void 0:U(R),value:n,onChange:W=>{r(W.currentTarget.value),s(0)},onKeyDown:L}),Y.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":ze(t,"listTitle"),children:[h.length===0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:ze(t,"listEmpty")}):h.map((W,k)=>Y.jsx("div",{className:"aqsp-popover-option",id:U(k),role:"option",tabIndex:-1,"aria-selected":k===R,"data-aqsp-list-option":W,onPointerDown:x=>x.preventDefault(),onClick:()=>N(()=>e.commit(W)),children:W},U(k))),m>0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:ze(t,"listMore",m)}):null]})]})},Ta=({ctx:e,labels:t})=>Y.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),Y.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:e.close,children:"×"})]}),$a=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=L=>{u.current=!0;try{L()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},R=()=>{r!==n&&!s?m():h(e.close)},N=L=>{if(L.key==="Escape"){L.preventDefault(),e.rejected?h(e.close):R();return}L.key==="Enter"&&(L.ctrlKey||L.metaKey)&&!L.altKey&&!L.shiftKey&&(L.preventDefault(),m())},H=L=>{u.current||L.relatedTarget instanceof Node&&L.currentTarget.contains(L.relatedTarget)||e.rejected||R()};return Y.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:H,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:ze(t,"noteTitle")}),Y.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:L=>o(L.currentTarget.value),onKeyDown:N}),Y.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:ze(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:ze(t,"noteSave")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":ze(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},La=({ctx:e})=>Y.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),Nt=e=>Object.freeze({text:e.includes("text"),formula:e.includes("formula"),format:e.includes("format"),borders:e.includes("borders"),cf:e.includes("cf"),note:e.includes("note"),comments:e.includes("comments"),hyperlink:e.includes("hyperlink"),validation:e.includes("validation"),sizes:e.includes("sizes")}),Ai=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Da=Object.freeze({all:Nt(Ai),values:Nt(["text"]),formats:Nt(["format","borders","cf"]),formulas:Nt(["text","formula"]),noBorders:Nt(Ai.filter(e=>e!=="borders")),columnWidths:Nt(["sizes"]),validation:Nt(["validation"]),conditionalFormats:Nt(["cf"]),commentsAndNotes:Nt(["note","comments"])}),Oi=Object.freeze({mode:"all"}),Cs=Object.freeze({t:""}),xi=Object.freeze({row:1<<30,col:1<<30}),Tm=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),$m=e=>e.t===""&&e.f===void 0,Lm=e=>e.length>1&&e.startsWith("="),Dm=(e,t,n)=>{switch(n){case"add":return e+t;case"subtract":return e-t;case"multiply":return e*t;case"divide":return e/t}},Ti=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Mm=(e,t,n,r)=>{const o=Lm(e),s=e===""?"0":ot(e);if(!o&&s===null)return null;const l=Tm[n];if(t.f!==void 0){const h=Rr(t.f,r),m=h.startsWith("=")?h.slice(1):h;return`=(${o?e.slice(1):s})${l}(${m})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Ti(Number(s));const c=ot(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Ti(Dm(Number(s),u,n))},$i=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),zm=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:$i(e.start),end:$i(e.end)};case"column":return e.start.abs||e.end.abs?e:{...e,kind:"row",start:{row:e.start.col,abs:!1},end:{row:e.end.col,abs:!1}};case"row":return e.start.abs||e.end.abs?e:{...e,kind:"column",start:{col:e.start.row,abs:!1},end:{col:e.end.row,abs:!1}}}},Nm=e=>{const t=Rr(e,xi),n=yr(t);let r="",o=0,s=!1;for(const l of n){const c=zm(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${tn(c)}`,o=l.end,s=!0)}return s?uo(`${r}${t.slice(o)}`,xi):e},Fm=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return Cs;const o=r[n];return o===void 0?Cs:o},Pm=e=>{const{rows:t,cols:n}=e,r=Dc(Nm);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const u=[];for(let h=0;h<t;h+=1){const m=Fm(e,h,c);let R=m;if(m.f!==void 0){const N=r(m.f);R=N===m.f?m:{...m,f:N}}(R!==m||m===Cs)&&(o=!1),u.push(R)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},_m=(e,t)=>!t.formula&&e.f!==void 0||!t.format&&e.fmt!==void 0||!t.validation&&e.val!==void 0||!t.note&&e.note!==void 0||!t.comments&&e.comments!==void 0||!t.hyperlink&&e.link!==void 0,qm=(e,t)=>{const n={t:e.t};return t.formula&&e.f!==void 0&&(n.f=e.f),t.format&&e.fmt!==void 0&&(n.fmt=e.fmt),t.validation&&e.val!==void 0&&(n.val=e.val),t.note&&e.note!==void 0&&(n.note=e.note),t.comments&&e.comments!==void 0&&(n.comments=e.comments),t.hyperlink&&e.link!==void 0&&(n.link=e.link),n},Li=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)_m(m,t)?(h.push(qm(m,t)),u=!0):h.push(m);u&&(n=!0),r.push(u?h:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,l=!t.cf&&e.conditionalFormats.length>0?[]:e.conditionalFormats;return(o!==e.formats||s!==e.validations||l!==e.conditionalFormats)&&(n=!0),n?{...e,formats:o,validations:s,conditionalFormats:l,cells:r}:e},Di=new WeakMap,Ma=e=>{const t=Di.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>gt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:gt({...s,borders:void 0})),o={canonical:n,borderless:r};return Di.set(e,o),o},so=(e,t)=>t===void 0?void 0:e[t],Im=(e,t,n,r)=>{const o=Ma(e);if(n){const h=so(o.canonical,t.fmt);return h===void 0?null:h}const s=so(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const u=gt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},jm=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Mm(n.readText(),o,r,n):o.f===void 0?o.t:Rr(o.f,n)},Mi=(e,t,n,r,o)=>{const s=Da[r.mode];if(r.skipBlanks===!0&&$m(e))return null;const l={};let c=!1;if(s.text){const u=jm(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=Im(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=so(Ma(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=so(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},zi=(e,t)=>e.length===0?e:t.length===0?[]:e.map(n=>{const r=[];for(const o of t)for(const s of n.ranges)r.push({startRow:o.row+s.startRow,startCol:o.col+s.startCol,endRow:o.row+s.endRow,endCol:o.col+s.endCol});return{...n,ranges:r}}),Hm=["text/html","text/plain"],Bm=(e,t,n)=>{if(e===0||t===0)return 0;const r=st(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},Vm=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,Wm=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,Km=e=>{const t=Array.from(e.types),n=new Map;return{types:t,getData:r=>{const o=n.get(r);if(o!==void 0)return o;const s=e.getData(r);return n.set(r,s),s}}},Ni=e=>{const t=e.clipboardData;return t??null},Ym=(e,t)=>{const n=Math.max(e.startRow,t.startRow),r=Math.min(e.endRow,t.endRow),o=Math.max(e.startCol,t.startCol),s=Math.min(e.endCol,t.endCol);return n>r||o>s?null:{startRow:n,startCol:o,endRow:r,endCol:s}},Um=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Ym(l,t);c!==null&&o.push({startRow:c.startRow-t.startRow,startCol:c.startCol-t.startCol,endRow:c.endRow-t.startRow,endCol:c.endCol-t.startCol})}if(o.length===0)continue;const s={sourceRuleId:r.id,ranges:o,condition:r.condition,style:r.style};r.stopIfTrue!==void 0&&(s.stopIfTrue=r.stopIfTrue),n.push(s)}return n},Xm=(e,t,n,r,o)=>{const s=Yn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=uo(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const u=t.intern(c);u!==void 0&&(l.fmt=u)}}if(e.getCellNote!==void 0){const c=e.getCellNote(r,o);c!==void 0&&(l.note=c)}if(e.getCellComments!==void 0){const c=e.getCellComments(r,o);c!==void 0&&c.length>0&&(l.comments=c.map(({text:u,author:h,createdAt:m})=>({text:u,author:h,createdAt:m})))}if(e.getCellHyperlink!==void 0){const c=Un(e.getCellHyperlink(r,o));c!==void 0&&(l.link=c)}if(e.getCellValidation!==void 0){const c=e.getCellValidation(r,o);c!==void 0&&(l.val=n.intern(c))}return l},za=(e,t)=>{const n=wc(),r=Qd(),o=[];for(let s=t.startRow;s<=t.endRow;s+=1){const l=[];for(let c=t.startCol;c<=t.endCol;c+=1)l.push(Xm(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:Um(e.getConditionalFormats(),t)}},Fi=e=>e.kind==="cut"?{...e.payload,...za(e.sourceAdapter,e.range)}:e.payload,Gm=e=>({v:1,rows:e.length,cols:e[0].length,clipId:As(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Zm=e=>{let t=!1;const n=[];for(const r of e.cells){let o=!1;const s=[];for(const l of r){if(l.link===void 0){s.push(l);continue}const c=sn(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},Jm=(e,t,n)=>{const r={row:e,col:t,text:""};return n.format&&(r.format=null),n.note&&(r.note=null),n.comments&&(r.comments=null),n.hyperlink&&(r.hyperlink=null),n.validation&&(r.validation=null),r},Qm=(e,t,n,r,o)=>{if(e.length===0)return null;let s=0,l=0;for(const c of e)s=Math.max(s,c.row+t-1),l=Math.max(l,c.col+n-1);return Re({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},eg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),r=i.useRef("none"),o=i.useCallback(()=>{n.current!==null&&(n.current=null,t.current.repaintOverlay(),t.current.onClipChange?.(null))},[]),s=i.useCallback(k=>{const x=n.current;if(x===null||k==="format"||k==="annotate")return;const z=r.current;z==="own"||z==="foreign"&&x.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const k=n.current;if(k===null)return;if(k.kind==="copy"){o();return}const x=t.current;x.repaintOverlay(),x.onClipChange?.({kind:"cut",range:k.range,foreign:k.sourceAdapter!==x.adapter})},[o]),c=i.useCallback((k,x,z)=>{const I=t.current;n.current={kind:k,range:x,clipId:z.clipId,sourceAdapter:I.adapter,payload:z},I.repaintOverlay(),I.onClipChange?.({kind:k,range:x,foreign:!1})},[]),u=i.useCallback(k=>{const x=t.current,z=x.adapter,I=st(k),T={v:1,rows:I.rows,cols:I.cols,clipId:As(),...za(z,k),wholeRows:Cc(k,z.colCount),wholeCols:bc(k,z.rowCount)};if(x.resize!==void 0){if(T.wholeCols){const F=[];for(let O=k.startCol;O<=k.endCol;O+=1)F.push(Math.min(x.resize.colAxis.sizeOf(O),on));T.colWidths=F}if(T.wholeRows){const F=[];for(let O=k.startRow;O<=k.endRow;O+=1)F.push(Math.min(x.resize.rowAxis.sizeOf(O),on));T.rowHeights=F}}return T},[]),h=i.useCallback((k,x)=>{const z=t.current,I=z.getSelection(),T=I.ranges[I.ranges.length-1],F=At([T]);if(F>z.maxOperationCells)return k.preventDefault(),z.onOperationRejected?.(x,F,"limit"),null;if(x==="cut"&&ur(z.adapter,T))return k.preventDefault(),z.rejectReadOnly({kind:"operation",op:"cut",cellCount:F}),null;I.ranges.length>1&&z.onCopyMultiRange?.();const O=u(T),g=lc(O),p=Ni(k);return p!==null&&(p.setData("text/plain",qt.serializeClipboardTsv(O.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",Gc(O,g)),p.setData(no,g)),k.preventDefault(),{payload:O,range:T}},[u]),m=i.useCallback((k,x)=>t.current.commitPaste(k,x)!==null,[]),R=i.useCallback((k,x,z)=>{const I=t.current;if(!z.sizes||I.resize===void 0)return;const{rowAxis:T,colAxis:F,resizeTracks:O}=I.resize,g=(p,C,v)=>{const S=vs(C,v,null,{maxOperationCells:I.maxOperationCells,rowHiddenLimit:ys,axisKind:p});if(!S.ok){I.onOperationRejected?.("resize",S.count,S.reason);return}O(p,S.entries)};if(k.colWidths!==void 0){const p=[];for(let C=x.startCol;C<=x.endCol;C+=1)p.push({index:C,size:k.colWidths[(C-x.startCol)%k.cols]});g("col",F,p)}if(k.rowHeights!==void 0){const p=[];for(let C=x.startRow;C<=x.endRow;C+=1)p.push({index:C,size:k.rowHeights[(C-x.startRow)%k.rows]});g("row",T,p)}},[]),N=i.useCallback((k,x)=>{const z=t.current,I=z.adapter,T=k.payload,F={row:x.startRow,col:x.startCol},O=T.rows*T.cols+At([k.range]);if(O>z.maxOperationCells)return z.onOperationRejected?.("paste",O,"limit"),"rejected";if(F.row+T.rows>I.rowCount||F.col+T.cols>I.colCount||k.range.endRow>=k.sourceAdapter.rowCount||k.range.endCol>=k.sourceAdapter.colCount)return z.onOperationRejected?.("paste",O,"bounds"),"rejected";const g=gs({rows:T.rows,cols:T.cols},Re(F,F),F,I.rowCount,I.colCount);if(g!==null&&ur(I,g))return z.rejectReadOnly({kind:"operation",op:"paste",cellCount:T.rows*T.cols}),"rejected";if(ur(k.sourceAdapter,k.range))return z.rejectReadOnly({kind:"operation",op:"cut",cellCount:At([k.range])}),"rejected";const p=Fi(k),C=eo(I),v=Li(p,C),S={row:0,col:0,readText:()=>Yn(I,S.row,S.col).text,readFormat:()=>I.getCellFormat===void 0?void 0:I.getCellFormat(S.row,S.col)},{edits:b,tiles:y}=ii(v.cells,Re(F,F),F,I.rowCount,I.colCount,(E,d,$)=>(S.row=k.range.startRow+(d-F.row),S.col=k.range.startCol+($-F.col),Mi(E,v,S,Oi,C))),a=eo(k.sourceAdapter),f=[];if(Jt([k.range],E=>{f.push(Jm(E.row,E.col,a))}),k.sourceAdapter===I){if(!m([...f,...b],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const E=z.commitPaste(b,{sameSheet:!1,conditionalFormats:zi(v.conditionalFormats,y)});if(E===null)return"rejected";try{k.sourceAdapter.applyEdits(f,{transaction:E,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){z.onEditRejected?.(d,{source:"paste"})}}return z.setSelection({ranges:[Re(F,{row:F.row+p.rows-1,col:F.col+p.cols-1})],anchor:F,active:F}),"applied"},[m]),H=i.useCallback((k,x,z)=>{const I=t.current,T=I.adapter,F=K=>(I.onClipboardUnavailable?.(K),"rejected"),O=ac(k,x);if(O==="none")return x==="menu"?F("empty"):"empty";const g=I.getSelection(),p=g.ranges[g.ranges.length-1],C=z.transpose===!0,v=(K,G)=>{const J=Bm(C?G:K,C?K:G,p);return J>I.maxOperationCells?(I.onOperationRejected?.("paste",J,"limit"),!0):!1};let S,b=null;if(O==="aqsp"){const K=Ad(k,x);if(K===null)return F("unreadable");const G=n.current;if(G!==null&&K.clipId===G.clipId&&(b=G),b!==null&&b.kind==="cut"&&Vm(z))return N(b,p);if(v(K.rows,K.cols))return"rejected";if(b!==null){if(b.kind==="cut"&&(b.range.endRow>=b.sourceAdapter.rowCount||b.range.endCol>=b.sourceAdapter.colCount))return I.onOperationRejected?.("paste",b.payload.rows*b.payload.cols,"bounds"),"rejected";S=Fi(b)}else{const J=Od(k,x);if(J===null)return F("unreadable");if(v(J.rows,J.cols))return"rejected";S=Zm(J)}}else if(O==="tsv"){const K=k.getData("text/plain"),G=qt.measureTsv(K);if(v(G.rows,G.cols))return"rejected";S=Gm(qt.parseTsv(K))}else{const K=k.getData("text/html"),G=Jd(K);if(G.cols===0&&G.rows>I.maxOperationCells)return I.onOperationRejected?.("paste",G.rows,"limit"),"rejected";if(v(G.rows,G.cols))return"rejected";const J=ea(K,O,I.formats===void 0?{}:{currency:I.formats.currency,locale:I.formats.locale},I.maxOperationCells);if(J.outcome==="none")return F("unreadable");if(J.outcome==="limit")return I.onOperationRejected?.("paste",J.cells,"limit"),"rejected";if(v(J.payload.rows,J.payload.cols))return"rejected";S=J.payload}const y=eo(T),a=Li(C?Pm(S):S,y),f=Da[z.mode];if(Wm(f)){const K=gs({rows:a.rows,cols:a.cols},p,g.active,T.rowCount,T.colCount);if(K!==null&&ur(T,K))return I.rejectReadOnly({kind:"operation",op:"paste",cellCount:At([K])}),"rejected"}const E={row:0,col:0,readText:()=>Yn(T,E.row,E.col).text,readFormat:()=>T.getCellFormat===void 0?void 0:T.getCellFormat(E.row,E.col)},{edits:d,tiles:$}=ii(a.cells,p,g.active,T.rowCount,T.colCount,(K,G,J)=>(E.row=G,E.col=J,Mi(K,a,E,z,y))),A=Qm($,a.rows,a.cols,T.rowCount,T.colCount);if(A===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let K=0;for(const J of a.conditionalFormats)K+=J.ranges.length;const G=$.length*K;if(G>I.maxOperationCells)return I.onOperationRejected?.("paste",G,"limit"),"rejected"}const D=f.cf?zi(a.conditionalFormats,$):[];if(d.length===0&&D.length===0)return R(a,A,f),"empty";r.current=b===null?"foreign":"own";let q=!1;try{q=m(d,{sameSheet:b!==null&&b.sourceAdapter===T,conditionalFormats:D})}finally{r.current="none"}if(!q)return"rejected";R(a,A,f);const j={row:A.startRow,col:A.startCol};return I.setSelection({ranges:[A],anchor:j,active:j}),"applied"},[N,m,R]),L=i.useCallback(async k=>{const x=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),z=navigator;if(z.clipboard===void 0)return x("insecure-origin");let I;try{I=await z.clipboard.read({unsanitized:["text/html"]})}catch{return x("permission-denied")}if(I.length===0)return x("empty");const T=I[0],F=Array.from(T.types),O=new Map;try{for(const C of Hm)F.includes(C)&&O.set(C,await(await T.getType(C)).text())}catch{return x("unreadable")}const g={types:F,getData:C=>{const v=O.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":H(g,"menu",k)},[H]),_=i.useCallback(async k=>{const x=await L(k);return t.current.onPasteResolved?.(x,"menu"),x},[L]),{enabled:U,sinkRef:W}=e;return i.useEffect(()=>{const k=W.current;if(!U||k===null)return;const x=F=>t.current.isDragging()?(F.preventDefault(),!0):!1,z=F=>{const O=t.current;if(x(F)||O.isEditing())return;const g=h(F,"copy");g!==null&&c("copy",g.range,g.payload)},I=F=>{const O=t.current;if(x(F)||O.isEditing())return;const g=h(F,"cut");g!==null&&c("cut",g.range,g.payload)},T=F=>{const O=t.current;if(x(F)||O.isEditing())return;F.preventDefault();let g=Oi;const p=O.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(g=p.current,p.current=null);const C=Ni(F);if(C===null)return;const v=H(Km(C),"event",g);O.onPasteResolved?.(v,"event")};return k.addEventListener("copy",z),k.addEventListener("cut",I),k.addEventListener("paste",T),()=>{k.removeEventListener("copy",z),k.removeEventListener("cut",I),k.removeEventListener("paste",T)}},[U,W,h,c,H]),i.useMemo(()=>({getClip:()=>{const k=n.current;return k===null?null:{kind:k.kind,range:k.range,foreign:k.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:_}),[o,s,l,_])},Na=e=>{if(e!==2&&e!==3&&e!==-2&&e!==-3)throw new RangeError(`[spreadsheet] self-calc exponent must be 2, 3, -2 or -3; got ${String(e)}`)},Fa=e=>{let t=e,n=!1;t.startsWith("-")?(n=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));const r=t.search(/[eE]/);let o=null;r>=0&&(o=Number(t.slice(r+1)),t=t.slice(0,r));const s=t.indexOf("."),l=s<0?t:t.slice(0,s),c=s<0?"":t.slice(s+1);return{negative:n,digits:l+c,point:l.length,exponent:o}},Pi=(e,t,n)=>{let r,o;return n<=0?(r="0",o="0".repeat(-n)+t):n>=t.length?(r=t+"0".repeat(n-t.length),o=""):(r=t.slice(0,n),o=t.slice(n)),r=r.replace(/^0+(?=\d)/,""),o=o.replace(/0+$/,""),r==="0"&&o===""?"0":`${e?"-":""}${r}${o===""?"":`.${o}`}`},Pa=(e,t)=>{let n;if(e.exponent===null)n=Pi(e.negative,e.digits,e.point+t);else{const r=Pi(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return ot(n)===null?null:n},tg=(e,t)=>{Na(t);const n=ot(e);return n===null?null:Pa(Fa(n),t)},ng=e=>{const t=ot(e);if(t!==null){const r=Fa(t);return Pa({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},_a=e=>{if(!e.startsWith("=")||e.length===1)throw new RangeError(`[spreadsheet] self-calc expects a formula ("=" followed by a body); got ${JSON.stringify(e)}`);return e.slice(1)},rg=e=>{let t=0,n=null;for(let r=0;r<e.length;r++){const o=e[r];if(n!==null){o===n&&(n=null);continue}if(o==='"'||o==="'")n=o;else if(o==="(")t++;else if(o===")"&&(t--,t<0))return!1}return n===null&&t===0},qa=(e,t,n)=>{if(e.length<=t.length+n.length||!e.startsWith(t)||!e.endsWith(n))return null;const r=e.slice(t.length,e.length-n.length);return rg(r)?r:null},og=(e,t)=>{Na(t);const n=_a(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=qa(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},sg=e=>{const t=_a(e),n=qa(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},lr=(e,t,n,r)=>{const o=At(t);return o>n?(r?.(e,o,"limit"),!1):!0},Br={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Vr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},_i={bold:{kind:"toggle",key:"bold"},italic:{kind:"toggle",key:"italic"},underline:{kind:"toggle",key:"underline"},strikethrough:{kind:"toggle",key:"strikethrough"},clearFormatting:{kind:"clear"},alignLeft:{kind:"patch",patch:{align:"left"}},alignCenter:{kind:"patch",patch:{align:"center"}},alignRight:{kind:"patch",patch:{align:"right"}},formatNumber:{kind:"value",value:"number"},formatTime:{kind:"value",value:"time"},formatDate:{kind:"value",value:"date"},formatCurrency:{kind:"value",value:"currency"},formatPercent:{kind:"value",value:"percent"},formatScientific:{kind:"value",value:"scientific"},bordersOuter:{kind:"borders",preset:"outer"},bordersClear:{kind:"borders",preset:"clear"},borderTop:{kind:"borders",preset:"top"},borderRight:{kind:"borders",preset:"right"},borderBottom:{kind:"borders",preset:"bottom"},borderLeft:{kind:"borders",preset:"left"},insertLink:{kind:"popover",popover:"link"},insertNote:{kind:"popover",popover:"note"},insertComment:{kind:"popover",popover:"comment"},openHyperlink:{kind:"openHyperlink"},openValidationList:{kind:"popover",popover:"list"},pasteSpecial:{kind:"pasteSpecial"},fillDown:{kind:"fill",direction:"down"},fillRight:{kind:"fill",direction:"right"},fillSelection:{kind:"fill",direction:"selection"},insertDate:{kind:"insertNow",unit:"date"},insertTime:{kind:"insertNow",unit:"time"},hideRows:{kind:"hide",axis:"row",hide:!0},hideColumns:{kind:"hide",axis:"col",hide:!0},unhideRows:{kind:"hide",axis:"row",hide:!1},unhideColumns:{kind:"hide",axis:"col",hide:!1},formatGeneral:{kind:"patch",patch:{value:null}},bordersAll:{kind:"borders",preset:"all"},pasteFormats:{kind:"paste",options:{mode:"formats"}},pasteFormulas:{kind:"paste",options:{mode:"formulas"}},pasteAdd:{kind:"paste",options:{mode:"all",operation:"add"}},pasteSubtract:{kind:"paste",options:{mode:"all",operation:"subtract"}},pasteMultiply:{kind:"paste",options:{mode:"all",operation:"multiply"}},pasteDivide:{kind:"paste",options:{mode:"all",operation:"divide"}},multiplyBy100:{kind:"calc",exponent:2},multiplyBy1000:{kind:"calc",exponent:3},divideBy100:{kind:"calc",exponent:-2},divideBy1000:{kind:"calc",exponent:-3},signReversal:{kind:"sign"},fillColorYellow:{kind:"color",key:"background",preset:Br.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Br.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Br.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Br.Red,custom:null},fillColorCustom1:{kind:"color",key:"background",preset:null,custom:0},fillColorCustom2:{kind:"color",key:"background",preset:null,custom:1},fillColorCustom3:{kind:"color",key:"background",preset:null,custom:2},fillColorCustom4:{kind:"color",key:"background",preset:null,custom:3},fillColorCustom5:{kind:"color",key:"background",preset:null,custom:4},fontColorYellow:{kind:"color",key:"color",preset:Vr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Vr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Vr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Vr.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},lg={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},mr=e=>e<10?`0${e}`:String(e),ig=e=>{const t=new Date(e);return`${t.getFullYear()}-${mr(t.getMonth()+1)}-${mr(t.getDate())}`},cg=e=>{const t=new Date(e);return`${mr(t.getHours())}:${mr(t.getMinutes())}:${mr(t.getSeconds())}`},ag=(e,t)=>(e.row===t.startRow?1:0)|(e.col===t.endCol?2:0)|(e.row===t.endRow?4:0)|(e.col===t.startCol?8:0),ug=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),dg=e=>e===void 0||e.borders===void 0?{}:e.borders,fg={top:1,right:2,bottom:4,left:8},pg={style:"thin",color:Ss},hg=(e,t)=>{if(e===void 0)return!1;const n=Ze(e);return n!==null&&n===Ze(t)},mg=(e,t)=>{const n=t===void 0||t.locale===void 0?{}:{locale:t.locale};switch(e){case"number":return{type:"number",decimals:2,grouping:!0,...n};case"time":return{type:"date",pattern:"HH:mm:ss"};case"date":return{type:"date"};case"currency":if(t===void 0)throw new RangeError("[spreadsheet] formatCurrency requires the formats prop (currency)");return{type:"currency",currency:t.currency,decimals:2,...n};case"percent":return{type:"percent",decimals:2,...n};default:return{type:"scientific",decimals:2,...n}}},gg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const p=g.getActive();return[Re(p,p)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,p=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(g=>{const p=t.current,C=n();if(!lr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:At(C)}),!1;const v=new Map,S=[],b=p.adapter.getCellFormat;for(const y of C)Jt([y],a=>{const f=b===void 0?void 0:b(a.row,a.col),{bucket:E,patch:d}=g(a,y,f);let $=v.get(E);$===void 0&&($=new Map,v.set(E,$));let A;$.has(f)?A=$.get(f):(A=Es(f,d),$.set(f,A)),A!==f&&S.push({row:a.row,col:a.col,format:A===void 0?null:A})});return S.length===0?!0:p.commitEdits(S,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:g,state:p}))},[]),c=i.useCallback((g,p=pg)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=g==="outer"?15:fg[g];return o((v,S,b)=>{const y=ag(v,S)&C;return{bucket:y,patch:{borders:{...dg(b),...ug(y,p)}}}})},[s,o]),u=i.useCallback((g,p,C)=>{const v=sa(t.current.adapter,g.row,g.col);for(const S of p)C.push(la(v,g,S))},[]),h=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!lr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[];if(g==="selection"){const b=C.active,y=[];Jt(C.ranges,a=>{(a.row!==b.row||a.col!==b.col)&&y.push(a)}),v.push({source:b,targets:y})}else for(const b of C.ranges)if(g==="down"){const y=b.startRow===b.endRow;if(y&&b.startRow===0)continue;const a=y?b.startRow-1:b.startRow;for(let f=b.startCol;f<=b.endCol;f+=1){const E=[];for(let d=y?b.startRow:b.startRow+1;d<=b.endRow;d+=1)E.push({row:d,col:f});v.push({source:{row:a,col:f},targets:E})}}else{const y=b.startCol===b.endCol;if(y&&b.startCol===0)continue;const a=y?b.startCol-1:b.startCol;for(let f=b.startRow;f<=b.endRow;f+=1){const E=[];for(let d=y?b.startCol:b.startCol+1;d<=b.endCol;d+=1)E.push({row:f,col:d});v.push({source:{row:f,col:a},targets:E})}}for(const b of v)for(const y of b.targets)if(Ye(p.adapter,y.row,y.col)){let a=0;for(const f of v)a+=f.targets.length;return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:a}),!1}const S=[];for(const b of v)u(b.source,b.targets,S);return S.length===0?!0:p.commitEdits(S,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const g=t.current,p=g.getSessionText();if(p===null)return!1;const C=g.getSelection();if(!lr("fill",C.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(qn(g.adapter,C.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:At(C.ranges)}),!1;const v=[];let S=!1;return Jt(C.ranges,b=>{if(!S){if(!g.validateCommit(b,p).ok){S=!0;return}v.push({row:b.row,col:b.col,text:p})}}),S||g.commitEdits(v,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),R=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!lr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:At(C.ranges)}),!1;const v=[],S=p.adapter;return Jt(C.ranges,b=>{const y=S.getCellFormula===void 0?void 0:S.getCellFormula(b.row,b.col),a=y===void 0?g.text(S.getCellText(b.row,b.col)):g.formula(y);a!==null&&v.push({row:b.row,col:b.col,text:a})}),v.length===0?!0:p.commitEdits(v,{source:"calc"})!==null},[]),N=i.useCallback((g,p)=>{const C=t.current,v=g==="row"?C.rowAxis:C.colAxis,S=C.getSelection(),b=g==="row"?Math.floor(C.maxOperationCells/Rs):C.maxOperationCells;let y=0;for(const $ of S.ranges)y+=g==="row"?$.endRow-$.startRow+1:$.endCol-$.startCol+1;if(y>b)return C.onOperationRejected?.("resize",y,"limit"),!1;const a=new Set,f=[],E=p?0:g==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const $ of S.ranges){const A=g==="row"?$.startRow:$.startCol,D=g==="row"?$.endRow:$.endCol;for(let q=A;q<=D;q+=1){if(a.has(q))continue;a.add(q),v.sizeOf(q)===0!==p&&f.push({index:q,size:E})}}const d=vs(v,f,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:ys,axisKind:g});return d.ok?(d.entries.length>0&&C.resizeTracks(g,d.entries),!0):(C.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),H=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const p=g.getActive();return Un(g.adapter.getCellHyperlink(p.row,p.col))},[]),L=i.useCallback(g=>{const p=t.current,C=p.adapter,v=_i[g],S=C.getCellFormat!==void 0,b=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(v.kind){case"resize":return p.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return S;case"value":return S&&(v.value!=="currency"||p.formats!==void 0);case"popover":switch(v.popover){case"link":return C.getCellHyperlink!==void 0&&b("link");case"note":return C.getCellNote!==void 0&&b("note");case"comment":return C.getCellComments!==void 0&&b("comment");default:return C.getCellValidation!==void 0&&b("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(p.onHyperlinkOpen!==void 0?H()!==void 0:b("link"));case"paste":return v.options.mode==="formats"?S:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[H]),_=i.useCallback(g=>{const p=t.current,C=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=p.getActive();if(!Ye(p.adapter,v.row,v.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let S;if(C==="link")S=H()!==void 0;else if(C==="note"){const b=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(v.row,v.col);S=b!==void 0&&b!==""}else{const b=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(v.row,v.col);S=b!==void 0&&b.length>0}return S?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[H]),U=i.useCallback((g,p,C)=>{const v=t.current,S=v.trackResize;if(S===void 0)return!1;const b=v.getActive(),y=p==="col"?b.col:b.row,a=C==="fit"?S.autofitColumn(y):S.stepTrack(p,y,C),f=(p==="col"?v.colAxis:v.rowAxis).sizeOf(y);return a&&f>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:g,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),W=i.useCallback(g=>{const p=t.current;if(!L(g))return!1;const C=_i[g];if(!_(C))return!1;const v=p.isEditing();if(v&&!Ps.has(g)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const S=r(),b=S!==void 0&&S[C.key]===!0;return s({[C.key]:b?null:!0})?(l(g,!b),!0):!1}case"patch":return s(C.patch)?(l(g,null),!0):!1;case"clear":return s(lg)?(l(g,null),!0):!1;case"value":return s({value:mg(C.value,p.formats)})?(l(g,null),!0):!1;case"borders":return c(C.preset)?(l(g,null),!0):!1;case"color":{const S=C.key==="background"?p.colors.fill:p.colors.font,b=C.preset!==null?C.preset:C.custom!==null&&C.custom<S.length?S[C.custom]:void 0;if(b===void 0)return!1;const y=r(),a=hg(y===void 0?void 0:y[C.key],b);return s({[C.key]:a?null:b})?(l(g,!a),!0):!1}case"calc":return R({text:S=>tg(S,C.exponent),formula:S=>og(S,C.exponent)});case"sign":return R({text:ng,formula:sg});case"fill":return v&&C.direction==="selection"?m():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const S=H();return S===void 0?!1:(p.onHyperlinkOpen(S,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const S=C.unit==="date"?ig(p.now()):cg(p.now());if(v)return p.insertAtCaret(S),!0;const b=p.getActive();return Ye(p.adapter,b.row,b.col)?(p.rejectReadOnly({kind:"edit",cell:b,editSession:"none"}),!1):p.validateCommit(b,S).ok?p.commitEdits([{row:b.row,col:b.col,text:S}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return U(g,C.axis,C.step);default:{const S=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...S,row:!S.row}),!0;case"column":return p.setHighlight({...S,column:!S.column}),!0;case"both":{const b=S.row&&S.column;return p.setHighlight({...S,row:!b,column:!b}),!0}default:return p.setHighlight({...S,intersection:!S.intersection}),!0}}}},[L,_,H,r,s,l,c,R,h,m,N,U]),k=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),x=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=g===null?null:sn(g);if(g!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!k())return!1;const v=p.getActive();return Ye(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[k]),z=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!k())return!1;const C=p.getActive();return Ye(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:g}],{source:"annotate"})!==null},[k]),I=i.useCallback(g=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!k())return!1;const v=p.getActive();if(Ye(p.adapter,v.row,v.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const S=C(v.row,v.col),b=S===void 0?[g]:[...S,g];return p.commitEdits([{row:v.row,col:v.col,comments:b}],{source:"annotate"})!==null},[k]),T=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!k())return!1;const C=p.getSelection().ranges;if(!lr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(qn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:At(C)}),!1;const v=[];return Jt(C,S=>{v.push({row:S.row,col:S.col,validation:g})}),p.commitEdits(v,{source:"annotate"})!==null},[k]),F=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),O=i.useCallback((g,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,p)},[c]);return i.useMemo(()=>({executeCommand:W,applyFormat:F,setBorders:O,setHyperlink:x,setNote:z,addComment:I,setValidation:T,isCommandAvailable:L}),[W,F,O,x,z,I,T,L])},Wr="data-aqsp-pointing",wg=(e,t)=>{const n=Pc(e,t);return n!==null&&"insertAt"in n},Cg=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},bg=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(null),[r,o]=i.useState(!1),s=i.useRef(!1),l=i.useRef(!1),c=i.useRef(!1),u=i.useRef(null),h=i.useRef(Pt),m=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=Pc(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),R=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=m()!==null;a!==y.hasAttribute(Wr)&&(a?y.setAttribute(Wr,""):y.removeAttribute(Wr))},[m]),N=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const E=f.resolveEditPaint(a),d=E===null?Pt:E;d!==Pt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),H=i.useCallback(y=>{Cg(y,Object.keys(h.current.style)),h.current=Pt;const a=t.current.editPaintRef;a!==void 0&&(a.current=Pt)},[]),L=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const E=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),H(d),d.removeAttribute(Wr)),o(!1)};if(y.commit){const d=a.sinkRef.current,$=d===null?"":d.value,A=Yn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
-
`),D=$===A;let q;if(D)q=!0;else if(Ye(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),q=!1;else{const j={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};q=(a.validateCommit===void 0||a.validateCommit(f.cell,$).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:$}],j)!==null}if(!q)return y.onReject==="discard"&&(E(),a.rearmSink()),!1}return E(),y.rearm&&a.rearmSink(),!0},[H]),_=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const E=f.sinkRef.current;if(E===null)return;const d=f.getActive();if(Ye(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:A,isFormula:D}=Yn(f.adapter,d.row,d.col);E.value=A;const q=a===void 0||D?A.length:Math.min(a,A.length);E.setSelectionRange(q,q)}else E.value="";const $=f.resolveEditAlign(d);$!==null&&(E.style.textAlign=$),N(E,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[N]),U=i.useCallback(()=>{L({rearm:!0,commit:!1})},[L]),W=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return L({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return L({rearm:!0,commit:!0,onReject:"keep"})},[L]),k=i.useCallback(()=>m()!==null,[m]),x=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,R(),!0),[R]),z=i.useCallback(()=>{const y=m(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=Fc(y.sink.value,y.sink.selectionStart);if(f===null)return null;const E=f.token,d=u.current;switch(E.kind){case"cell":{const $={row:E.row,col:E.col};return u.current=$,{origin:$,cursor:$,axis:"cells"}}case"range":{const $=d!==null&&(d.row===E.start.row||d.row===E.end.row)&&(d.col===E.start.col||d.col===E.end.col)?{row:d.row,col:d.col}:{row:E.start.row,col:E.start.col};return u.current=$,{origin:$,cursor:{row:$.row===E.start.row?E.end.row:E.start.row,col:$.col===E.start.col?E.end.col:E.start.col},axis:"cells"}}case"column":{const $=d!==null&&(d.col===E.start.col||d.col===E.end.col)?d.col:E.start.col,A={row:a.cell.row,col:$};return u.current=A,{origin:A,cursor:{row:a.cell.row,col:$===E.start.col?E.end.col:E.start.col},axis:"columns"}}case"row":{const $=d!==null&&(d.row===E.start.row||d.row===E.end.row)?d.row:E.start.row,A={row:$,col:a.cell.col};return u.current=A,{origin:A,cursor:{row:$===E.start.row?E.end.row:E.start.row,col:a.cell.col},axis:"rows"}}}},[m]),I=i.useCallback((y,a)=>{const f=m();if(f===null)return;const E=Mf(y,a),{sink:d}=f,[$,A]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],D=d.value;d.value=`${D.slice(0,$)}${E}${D.slice(A)}`;const q=$+E.length;d.setSelectionRange(q,q),"row"in y&&(u.current={row:y.row,col:y.col}),R()},[m,R]),T=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),F=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,R())},[R]),O=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=Bf(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),R(),!0)},[R]),g=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,E=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(E)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,R()},[R]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(H(f),N(f,a.cell),y.repaintOverlay?.())},[H,N]),{enabled:S,sinkRef:b}=e;return i.useEffect(()=>{const y=b.current;if(!S||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},E=A=>{const D=t.current;if(l.current||n.current===null)return;const q=D.rootRef.current,j=A.relatedTarget;q!==null&&j instanceof Node&&q.contains(j)||L({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const A=t.current;u.current=null,A.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&wg(y.value,y.selectionStart)&&(c.current=!0),R()},$=()=>{n.current!==null&&R()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",E),y.addEventListener("input",d),document.addEventListener("selectionchange",$),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",E),y.removeEventListener("input",d),document.removeEventListener("selectionchange",$)}},[S,b,L,R]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:W,cancelEdit:U,startEdit:_,getPointing:k,togglePointingArm:x,getReferenceCursor:z,insertReference:I,captureSink:T,restoreSink:F,cycleAnchorAtCaret:O,insertAtCaret:g,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[W,U,_,k,x,z,I,T,F,O,g,p,C,v,r])},yg=(e,t,n)=>{const r=new Je.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},Rg=(e,t,n)=>{const{tree:r,initialHidden:o}=yg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:R}=r.prefixSum(h);return m-R},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),R=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(R+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const R=Math.round(m);r.get(h)===0!=(R===0)&&(s+=R===0?1:-1),r.update(h,R)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},nn=(e,t,n)=>{if(n>0){const o=e.offsetOf(t)+e.sizeOf(t);return o>=e.totalSize()?null:e.indexAt(o)}const r=e.offsetOf(t)-1;return r<0?null:e.indexAt(r)},Bn=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:nn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=nn(e,o,1);return r},qi=(e,t,n)=>{if(!(Number.isInteger(t)&&t>0))throw new TypeError(`[spreadsheet] useAxisModel requires a positive integer defaultSize, received ${t}`);const r=i.useRef(n).current,o=i.useRef(null),s=`${e}:${t}`;return(o.current===null||o.current.key!==s)&&(o.current=Rg(e,t,r)),o.current.model},Vn=256,Jo=256,vg=2**32,Sg=4096,Ia=Object.freeze([]),ja=["background","color","bold","italic","underline","strikethrough"],Ha=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},rn=(e,t,n)=>(e.size>=Sg&&e.clear(),e.set(t,n),n),Ba=e=>(Ha(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Va=(e,t,n,r,o)=>{for(const s of e)if(s.startRow<=n&&s.endRow>=t&&s.startCol<=o&&s.endCol>=r)return!0;return!1},kg=(e,t,n)=>{const r=Math.floor(t/Vn),o=Math.floor(n/Jo),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Vn,u=o*Jo,h=[];for(const m of e.rules)Va(m.ranges,c,c+Vn-1,u,u+Jo-1)&&h.push(m);return rn(e.buckets,s,h.length===0?Ia:h)},Eg=(e,t,n)=>{const r=Math.floor(t/Vn),o=r*vg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=kg(e,t,n),c=r*Vn,u=[];for(const h of l)Va(h.ranges,c,c+Vn-1,n,n)&&u.push(h);return rn(e.columns,o,u.length===0?Ia:u)},Ag=(e,t)=>{for(const n of e)if(Cn(n,t))return!0;return!1},qs=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),Kr=(e,t)=>e<t?-1:e>t?1:0,Ii=(e,t,n)=>{switch(e){case"eq":return t===0;case"neq":return t!==0;case"gt":return t>0;case"gte":return t>=0;case"lt":return t<0;case"lte":return t<=0;case"between":return n!==null&&t>=0&&n<=0;case"notBetween":return n!==null&&(t<0||n>0);default:return!1}},ji=new WeakMap,bs=e=>e===null?null:Number(e),Og=e=>{const t=ji.get(e);if(t!==void 0)return t;const n=e.b,r={a:bs(ot(e.a)),b:n===void 0?null:bs(ot(n))};return ji.set(e,r),r},Wa=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:rn(e.numbers,r,bs(ot(n())))},xg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Og(e),l=Wa(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Ii(e.op,Kr(l,s.a),c===null?null:Kr(l,c));const u=n(),h=e.b;return Ii(e.op,Kr(u,e.a),h===void 0?null:Kr(u,h))},Tg=(e,t)=>{switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);case"endsWith":return t.endsWith(e.value);default:return!1}},Qo=e=>{const t=Ze(e);if(t===null)return null;const n=r=>Number.parseInt(t.slice(r,r+2),16);return[n(1),n(3),n(5),t.length===9?n(7):255]},Yr=e=>e.toString(16).padStart(2,"0"),es=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${Yr(r(0))}${Yr(r(1))}${Yr(r(2))}`,s=r(3);return s===255?o:`${o}${Yr(s)}`},ts=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),$g=(e,t,n,r,o)=>{let s=t.value===void 0?o.min:t.value,l=r.value===void 0?o.max:r.value,c=Qo(t.color),u=Qo(r.color);const h=n===void 0?void 0:Qo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const R=s;s=l,l=R;const N=c;c=u,u=N}if(n!==void 0&&h!==void 0){const R=n.value===void 0?(s+l)/2:n.value;if(s<R&&R<l)return e<=R?es(c,h,ts(e,s,R)):es(h,u,ts(e,R,l))}return es(c,u,ts(e,s,l))},Lg=(e,t,n,r)=>{const o=r.extrema.get(e.id);if(o!==void 0)return o;const{min:s,max:l}=t;if(s.value!==void 0&&l.value!==void 0)return rn(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const h of e.ranges){const m=n.getRangeExtrema(h);if(m===null)return rn(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return rn(r.extrema,e.id,{min:c,max:u})},Dg=(e,t,n,r,o,s)=>{const l=Wa(s,n,r);if(l===null)return null;const c=Lg(e,t,o,s);return c===null?null:$g(l,t.min,t.mid,t.max,c)},Mg=(e,t,n,r,o)=>{if(r.evaluateFormula===void 0)return!1;const s=`${e.id}\0${n.row}\0${n.col}`,l=o.formulas.get(s),c=l!==void 0?l:rn(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},zg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return xg(s,t,n,o)?e.style:null;case"text":return Tg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Dg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Mg(e,s,t,r,o)?e.style:null;default:return null}},Hi=(e,t)=>Es(e,t),Ng=(e,t,n)=>{e[t]=n},Fg=(e,t)=>{let n=e;for(const r of ja)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Ng(n,r,t[r]));return n},Pg=e=>{let t="";for(const n of ja){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},Bi=new WeakMap,_g=Object.freeze({}),qg=e=>{const t=e===void 0?_g:e,n=Bi.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return Bi.set(t,r),r},Ig=(e,t,n)=>{const r=qg(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=Hi(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=Pg(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=Hi(e,t);return l!==void 0&&rn(r.byKey,o,l),l},Is=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const l=e.getCellFormat(r,o);if(t===null)return l;const c=Eg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const R of c){if(!Ag(R.ranges,u))continue;const N=zg(R,u,s,e,n);if(N!==null){if(N!==R.style&&(m=!1),h===null)h=N;else{const H=Fg(h,N);H!==h&&(m=!1,h=H)}if(R.stopIfTrue===!0)break}}return h===null?l:Ig(l,h,m)},Vi=new WeakMap,jg=e=>{Ha(e,"widthRelevantRules");const t=Vi.get(e);if(t!==void 0)return t;const n=e.filter(o=>o.style.bold!==void 0||o.style.italic!==void 0||o.stopIfTrue===!0),r=n.length===e.length?e:n;return Vi.set(e,r),r},Hg=({row:e,col:t,text:n,display:r,renderCell:o,__onCellRender:s})=>{const l=i.useRef(!1);if(i.useEffect(()=>{const c=l.current?"update":"mount";l.current=!0,s?.(`cell-${e}-${t}`,c,0,0,0,0)}),o!==void 0){const c=o({row:e,col:t,text:n,displayText:r});return c===void 0?r:c}return r},Bg=i.memo(Hg),Vg=Object.freeze({left:Object.freeze({justifyContent:fr("left")}),center:Object.freeze({justifyContent:fr("center")}),right:Object.freeze({justifyContent:fr("right")})}),Wg=Object.freeze({role:"rowgroup"}),Kg=4096,Wi=new WeakMap,Ur=new Map,Yg=(e,t)=>{if(e===null)return Vg[t];let n=Wi.get(e);n===void 0&&(n={},Wi.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:fr(t)},s=JSON.stringify(o);let l=Ur.get(s);return l===void 0&&(Ur.size>=Kg&&Ur.clear(),l=Object.freeze(o),Ur.set(s,l)),n[t]=l,l},Ug=qs(),Xg=(e,t,n)=>{if(e.row!==t||e.col!==n)throw new RangeError(`[spreadsheet] cell renderer (${t}, ${n}) ran without its getCellProps (latched ${e.row}, ${e.col})`);return e.value},Gg=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0&&e.getCellNote===void 0&&e.getCellComments===void 0&&e.getCellHyperlink===void 0&&e.getCellValidation===void 0)return null;const l=Qr(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=Is(e,r===null?null:r.indexRef.current,r===null?Ug:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const R=ta(m,l),N=nn(n,s,1),H=nn(t,o,1),L=uf(m,N===null?void 0:e.getCellFormat(o,N),H===null?void 0:e.getCellFormat(H,s),n.offsetOf(s)===0,t.offsetOf(o)===0);L!==null&&Object.assign(c,L.attrs),c["data-aqsp-align"]=R,u=Yg(L,R)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Un(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&Cm(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},Zg=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:R,headerRows:N,labelledBy:H,gridLabel:L,readOnly:_,renderCell:U,onScroll:W,onRangeChange:k,focusSink:x,isEditing:z,requestCommit:I,testId:T,__onCellRender:F,__maxRenderedCells:O,cfIndexRef:g,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:v,overscanRows:S,overscanCols:b,background:y,onRenderTruncated:a,locale:f,scrollLabels:E})=>{const d=i.useRef(null),$=s??d;if(g===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const A=i.useMemo(()=>g===void 0||p===void 0?null:{indexRef:g,memoRef:p},[g,p]),D=i.useCallback(()=>r.get().editVersion,[r]),q=i.useCallback(ue=>r.subscribeCoalesced(ue),[r]),K=i.useSyncExternalStore(q,D,D)+(l??0),G=i.useCallback(ue=>t.sizeOf(ue),[t]),J=i.useCallback(ue=>n.sizeOf(ue),[n]),te=i.useCallback((ue,Ne)=>e.getCellText(ue,Ne),[e]),le=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),me=i.useMemo(()=>({width:Te.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Ee=i.useRef({row:-1,col:-1,value:void 0}),xe=i.useCallback((ue,Ne)=>{const Ue=ue<N,je={role:Ue?"columnheader":"gridcell","aria-rowindex":ue+1,"aria-colindex":Ne+1,"data-aqsp-cell":"","data-row":ue,"data-col":Ne,className:"aqsp-cell",...Ye(e,ue,Ne)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...Ue?{"data-aqsp-header-row":""}:{}},Ot=wh(e,ue,Ne),xt=Ot===null?je:{...je,...Ot},He=Gg(e,t,n,A,ue,Ne),wt=Ee.current;return wt.row=ue,wt.col=Ne,wt.value=He===null?void 0:He.value,He===null?xt:He.style===null?{...xt,...He.attrs}:{...xt,...He.attrs,style:He.style}},[e,t,n,A,N]),De=i.useCallback(ue=>({role:"row","aria-rowindex":ue+1,"data-aqsp-row":ue,"data-aqsp-cells":"",className:"aqsp-row"}),[]),Pe=i.useCallback((ue,Ne,Ue)=>{let je=ue;return e.getCellFormat!==void 0&&(je=Wn(ue,Xg(Ee.current,Ne,Ue))),Y.jsx(Bg,{row:Ne,col:Ue,text:ue,display:je,renderCell:U,__onCellRender:F})},[K,U,F,e]);return Y.jsx("div",{ref:$,className:"aqsp-body","data-aqsp-body":"","data-testid":T?`${T}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":L,"aria-labelledby":H,"aria-readonly":_?"true":void 0,onPointerDownCapture:ue=>{if(!(ue.target instanceof Element&&ue.target.closest("[data-aqsp-cells]")!==null)&&ue.pointerType==="mouse"){if(ue.button!==0){ue.preventDefault();return}if(ue.preventDefault(),C?.()===!0){ue.stopPropagation(),x();return}if(z()&&!I()){ue.stopPropagation(),x();return}x()}},children:Y.jsx(Je.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:R,getRowHeight:G,getColWidth:J,getCell:te,getCellProps:xe,getRowProps:De,contentProps:Wg,behaviorOptions:le,scrollBarOptions:me,overscanRows:S,overscanCols:b,background:y,onRenderTruncated:a,__maxRenderedCells:O,locale:f,labels:E,callbackThrottleMs:0,onScroll:W,onRangeChange:k,testId:T,children:Pe})})},Jg=i.memo(Zg),In=6,rt=3,lo=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=t[0];o>0&&e.sizeOf(o-1)===0&&r.push({kind:"unhide",index:o-1,start:e.offsetOf(o),length:rt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=nn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-In,length:rt}),r.push({kind:"unhide",index:s+1,start:c-rt,length:rt})):l>=2*In?n.push({kind:"resize",index:s,start:c-In,length:In}):n.push({kind:"resize",index:s,start:c-rt,length:rt})}return[...n,...r]},Ka=(e,t)=>{const n=[],r=[];if(t.length===0)return n;const o=e.offsetOf(t[0]),s=e.totalSize()-o;for(const c of t){const u=e.sizeOf(c),h=e.offsetOf(c)-o;c>0&&e.sizeOf(c-1)===0?(r.push({kind:"unhide",index:c-1,start:h,length:rt}),n.push({kind:"resize",index:c,start:h+rt,length:rt})):u>=2*In?n.push({kind:"resize",index:c,start:h,length:In}):n.push({kind:"resize",index:c,start:h,length:rt})}const l=t[t.length-1];return l<e.count-1&&e.sizeOf(l+1)===0&&r.push({kind:"unhide",index:l+1,start:s-rt,length:rt}),[...n.reverse(),...r]},Qg=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const H=Je.useWheelBridge(o),L=i.useCallback(d=>(s.current=d,H(d)),[s,H]),_=i.useCallback(()=>{const{colStart:d,colEnd:$,colVersion:A}=e.get();return`${d}:${$}:${A}`},[e]),U=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(U,_,_);const{colStart:W,colEnd:k}=e.get(),x=t.count===0?0:t.offsetOf(Math.min(W,t.count-1));i.useLayoutEffect(()=>{c.current=x,u()},[x,c,u]);const z=d=>h.some($=>d>=$.startCol&&d<=$.endCol),I=Math.min(Math.max(0,n),t.count),T=ya(t,I),F=I>0?Bn(t,0,I-1):[],O=Math.min(Math.max(0,r),t.count-I),g=va(t,O),p=t.totalSize()-g,C=O>0?Bn(t,t.count-O,t.count-1):[],v=Bn(t,Math.max(W,I),Math.min(k,Math.max(0,t.count-1)-O)),S=[];for(const d of v)S.push(Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-x,width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d));const b=m?lo(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&g>0)),a=m&&I>0?lo(t,F):null,f=m&&O>0?Ka(t,C):null,E=Y.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[S,y?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-x,width:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-x,width:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:L,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:I===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[F.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),Y.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:T,right:O>0?`calc(${Te.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${Te.SPREADSHEET_SCROLLBAR_SIZE_PX+T}px)))`:void 0},children:[E,I>0?Y.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,O>0?Y.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-trailing",style:{right:0,top:0,bottom:0}}):null]}),O>0?Y.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${T}px, calc(100% - ${g+Te.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:Y.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[C.map(d=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":z(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:Te.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},ew=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const H=Je.useWheelBridge(n),L=i.useCallback(d=>(r.current=d,H(d)),[r,H]),_=d=>o.some($=>d>=$.startRow&&d<=$.endRow),U=i.useCallback(()=>{const{rowStart:d,rowEnd:$,rowGeomVersion:A}=e.get();return`${d}:${$}:${A}`},[e]),W=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(W,U,U);const{rowStart:k,rowEnd:x}=e.get(),z=t.count===0?0:t.offsetOf(Math.min(k,t.count-1));i.useLayoutEffect(()=>{l.current=z,c()},[z,l,c]);const I=Math.min(Math.max(0,h),t.count),T=Ra(t,I),F=I>0?Bn(t,0,I-1):[],O=Math.min(Math.max(0,m),t.count-I),g=Sa(t,O),p=t.totalSize()-g,C=O>0?Bn(t,t.count-O,t.count-1):[],v=Bn(t,Math.max(k,I),Math.min(x,Math.max(0,t.count-1)-O)),S=[];for(const d of v)S.push(Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-z,height:t.sizeOf(d)},children:d+1},d));const b=u?lo(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<I&&T>0||d.kind==="unhide"&&d.index>=t.count-O&&g>0)),a=u&&I>0?lo(t,F):null,f=u&&O>0?Ka(t,C):null,E=Y.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[S,y?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-z,height:d.length}},`r${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-z,height:d.length}},`u${d.index}`))]});return Y.jsx("div",{ref:L,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Te.SPREADSHEET_SCROLLBAR_SIZE_PX},children:I===0&&O===0?E:Y.jsxs(Y.Fragment,{children:[F.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d),height:t.sizeOf(d)},children:d+1},d)),a?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start,height:d.length}},`fr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start,height:d.length}},`fu${d.index}`)),Y.jsxs("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:T,bottom:O>0?`calc(min(${g}px, max(0px, 100% - ${T}px)))`:void 0},children:[E,I>0?Y.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,O>0?Y.jsx("div",{ref:N,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-trailing",style:{bottom:0,left:0,right:0}}):null]}),O>0?Y.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${T}px, calc(100% - ${g}px))`},children:Y.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[C.map(d=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":d,"data-aqsp-trailing-row-header":"","data-aqsp-in-selection":_(d)?"":void 0,style:{top:t.offsetOf(d)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},tw=9,nw=4,Ki=(e,t,n)=>{const r=t.get(e);if(r!==void 0)return r;const o=e.italic===!0?"italic":n.fontStyle,s=e.bold===!0?"bold":n.fontWeight,l=typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0?`${e.fontSize*4/3}px`:n.fontSize,c=typeof e.fontFamily=="string"&&e.fontFamily!==""?e.fontFamily:n.fontFamily,u=`${o} ${s} ${l} ${c}`;return t.set(e,u),u},Yi=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,rw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),R=i.useCallback(g=>s.current!==null?g.pointerId===s.current:g.pointerType==="mouse",[]),N=i.useCallback(()=>{const g=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),g.writeResizeGuide(null);const p=m.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),m.current=null);const C=c.current;C!==null&&s.current!==null&&C.hasPointerCapture?.(s.current)&&C.releasePointerCapture(s.current),c.current=null,s.current=null,g.repaintOverlay()},[]),H=i.useCallback((g,p)=>{const C=t.current;return g==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),L=i.useCallback((g,p)=>{const C=t.current,v=C.getSelection().ranges.filter(f=>H(g,f));if(!v.some(f=>g==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const b=v.reduce((f,E)=>f+(g==="col"?E.endCol-E.startCol+1:E.endRow-E.startRow+1),0),y=g==="row"?Math.floor(C.maxOperationCells/Rs):C.maxOperationCells;if(b>y)return C.onOperationRejected?.("resize",b,"limit"),null;const a=new Set;for(const f of v){const E=g==="col"?f.startCol:f.startRow,d=g==="col"?f.endCol:f.endRow;for(let $=E;$<=d;$+=1)a.add($)}return[...a]},[H]),_=i.useCallback((g,p,C)=>{const v=t.current,S=g==="col"?v.colAxis:v.rowAxis,b=vs(S,p,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:ys,axisKind:g});return b.ok?(v.resizeTracks(g,b.entries),!0):(v.onOperationRejected?.("resize",b.count,b.reason),!1)},[]),U=i.useCallback((g,p)=>{if(p===g.initialSize)return;const C=g.kind==="unhide"?[g.index]:L(g.axis,g.index);C!==null&&_(g.axis,C.map(v=>({index:v,size:p})),g.index)},[L,_]),W=i.useCallback((g,p,C,v)=>{const S=t.current,b=S.fontSourceRef.current;if(b===null)return!1;if(p.length===0)return!0;const y=g.length*p.length;if(y>C)return S.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(b),E=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),$={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},A=`${$.fontStyle} ${$.fontWeight} ${$.fontSize} ${$.fontFamily}`,D=S.adapter.getConditionalFormats===void 0?null:jg(S.adapter.getConditionalFormats()),q=qs(),j=new WeakMap,K=new WeakMap,G=new Map;for(const me of g){const Ee=D===null?null:Ba(D.filter(xe=>xe.ranges.some(De=>me>=De.startCol&&me<=De.endCol)));for(const xe of p){const De=S.adapter.getCellText(xe,me),Pe=S.adapter.getCellFormat===void 0?void 0:Is(S.adapter,Ee,q,xe,me,()=>De),ue=xe<S.headerRows,Ne=Pe===void 0?ue?A:E:ue?Ki(Pe,K,$):Ki(Pe,j,f),Ue=Wn(De,Pe===void 0?void 0:Pe.value),je=G.get(Ne);je===void 0?G.set(Ne,[{col:me,text:Ue}]):je.push({col:me,text:Ue})}}const J=b.ownerDocument.createElement("span");J.setAttribute("aria-hidden","true"),J.style.position="absolute",J.style.visibility="hidden",b.append(J);const te=new Map;for(const[me,Ee]of G){a.font=me,J.style.font=me;const xe=getComputedStyle(J);a.letterSpacing=xe.letterSpacing==="normal"?"0px":xe.letterSpacing,a.wordSpacing=xe.wordSpacing==="normal"?"0px":xe.wordSpacing;for(const De of Ee){const Pe=a.measureText(De.text).width,ue=te.get(De.col);(ue===void 0||Pe>ue)&&te.set(De.col,Pe)}}J.remove();const le=[];for(const me of g){const Ee=te.get(me);Ee!==void 0&&Ee>0&&le.push({index:me,size:Math.ceil(Ee)+tw})}return le.length===0?!0:_("col",le,v)},[_]),k=i.useCallback(g=>{const p=t.current,C=L("col",g);if(C===null)return!1;const v=p.handleRef.current,S=v===null?null:v.getFrozenSize(),b=S===null?0:S.rows,y=S===null?0:S.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),E=Math.min(f,p.rowAxis.count-1),d=[],$=new Set,A=D=>{!$.has(D)&&p.rowAxis.sizeOf(D)>0&&($.add(D),d.push(D))};for(let D=0;D<b;D+=1)A(D);for(let D=a;D<=E;D+=1)A(D);for(let D=p.rowAxis.count-y;D<p.rowAxis.count;D+=1)A(D);return W(C,d,Math.floor(p.maxOperationCells/nw),g)},[L,W]),x=i.useCallback((g,p,C)=>{const v=g==="col"?t.current.colAxis:t.current.rowAxis,S=Nu(v.sizeOf(p),C);if(S===v.sizeOf(p))return!0;const b=L(g,p);return b===null?!1:_(g,b.map(y=>({index:y,size:S})),p)},[L,_]),z=i.useCallback(g=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(g)===0?!0:k(g):!1},[k]),I=i.useCallback(g=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(g)].filter(S=>p.colAxis.sizeOf(S)>0);if(C.length===0)return!0;const v=[];for(let S=0;S<p.rowAxis.count;S+=1)p.rowAxis.sizeOf(S)>0&&v.push(S);return W(C,v,p.maxOperationCells,null)},[W]),{enabled:T,colBandRef:F,rowBandRef:O}=e;return i.useEffect(()=>{const g=F.current,p=O.current;if(!T||g===null||p===null)return;const C=j=>j==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(j,K)=>{if(!(K instanceof Element))return null;const G=K.closest(C(j));if(G===null)return null;const J=G.hasAttribute("data-aqsp-unhide"),te=Number(G.getAttribute(J?"data-aqsp-unhide":j==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),le=G.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:J?"unhide":"resize",index:te,anchor:le}},S=j=>{if(!(n.current&&R(j)))return;const K=r.current;if(K===null)return;const G=(K.axis==="col"?j.clientX-K.startClientX:j.clientY-K.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(K.anchor==="trailing"?K.initialSize-G:K.initialSize+G)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const J=r.current;if(!n.current||J===null)return;const te=t.current,le=J.axis==="col"?te.colAxis:te.rowAxis;te.writeResizeGuide({axis:J.axis,position:Yi(J,le,o.current),anchor:J.anchor})}))},b=()=>{const j=r.current,K=o.current;N(),j!==null&&U(j,K)},y=j=>{S(j),n.current&&R(j)&&(l.current&1)!==0&&(j.buttons&1)===0&&b()},a=j=>{j.button!==0||!(n.current&&R(j))||b()},f=(j,K)=>G=>{const J=t.current;if(h.current=G.pointerType,G.pointerType!=="mouse")return;if(G.button!==0){G.preventDefault();return}const te=v(j,G.target);if(te===null)return;if(G.stopPropagation(),G.preventDefault(),J.isPointing()){J.focusSink();return}if(J.isEditing()&&!J.requestCommit()){J.focusSink();return}J.focusSink();const le=j==="col"?J.colAxis:J.rowAxis,me={axis:j,kind:te.kind,index:te.index,anchor:te.anchor,initialSize:le.sizeOf(te.index),startClientX:G.clientX,startClientY:G.clientY};r.current=me,o.current=me.initialSize,l.current=G.buttons,n.current=!0,J.repaintOverlay(),s.current=G.pointerId,c.current=K;try{K.setPointerCapture(G.pointerId)}catch{s.current=null}const Ee=y,xe=a;m.current={move:Ee,up:xe},window.addEventListener("pointermove",Ee),window.addEventListener("pointerup",xe),J.writeResizeGuide({axis:j,position:Yi(me,le,o.current),anchor:me.anchor})},E=(j,K)=>G=>{const J=t.current;if(h.current!=="mouse")return;const te=K.getRootNode(),le=te instanceof ShadowRoot?te:K.ownerDocument,me=G.target instanceof Element&&G.target.closest(C(j))!==null?G.target:typeof le.elementFromPoint=="function"?le.elementFromPoint(G.clientX,G.clientY):null,Ee=v(j,me);if(Ee!==null){if(G.stopPropagation(),J.isEditing()){J.focusSink();return}if(Ee.kind==="unhide"){_(j,[{index:Ee.index,size:j==="col"?J.defaultColumnWidth:J.defaultRowHeight}],null);return}if(J.autofitEnabled){if(j==="row"){const xe=L("row",Ee.index);xe!==null&&_("row",xe.map(De=>({index:De,size:J.defaultRowHeight})),Ee.index);return}k(Ee.index)}}},d=j=>{!n.current||s.current===null||j.pointerId!==s.current||N()},$=f("col",g),A=f("row",p),D=E("col",g),q=E("row",p);return g.addEventListener("pointerdown",$,{capture:!0}),p.addEventListener("pointerdown",A,{capture:!0}),g.addEventListener("dblclick",D),p.addEventListener("dblclick",q),g.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{g.removeEventListener("pointerdown",$,{capture:!0}),p.removeEventListener("pointerdown",A,{capture:!0}),g.removeEventListener("dblclick",D),p.removeEventListener("dblclick",q),g.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),N()}},[T,F,O,R,N,U,_,L,k]),i.useMemo(()=>({stepTrack:x,autofitColumn:z,autofitColumnsInAllRows:I,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,x,z,I])},js=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,ow=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>js(n,t.ranges[r]))&&It(e.anchor,t.anchor)&&It(e.active,t.active),sw=(e,t,n)=>{const r=l=>l.row<t&&l.col<n,o=l=>l.endRow<t&&l.endCol<n;if(r(e.anchor)&&r(e.active)&&e.ranges.every(o))return e;const s=l=>ln(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:Re(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},lw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return js(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Cr=(e,t,n)=>n.extend?hn(e,t):n.append?{ranges:[...e.ranges,Re(t,t)],anchor:t,active:t}:e.ranges.length===1&&It(e.anchor,t)&&It(e.active,t)&&js(e.ranges[0],Re(t,t))?e:{ranges:[Re(t,t)],anchor:t,active:t},iw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),hn=(e,t)=>{const n=lw(e,Re(e.anchor,t));return n.ranges.some(r=>Cn(r,n.active))?n:{...n,active:iw(n.active,n.ranges[n.ranges.length-1])}},Ya=(e,t,n)=>{let r=!1;const o=[];for(const c of e.ranges){if(t.startRow>c.endRow||t.endRow<c.startRow||t.startCol>c.endCol||t.endCol<c.startCol){o.push(c);continue}r=!0,t.startRow>c.startRow&&o.push(Re({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(Re({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const u=Math.max(c.startRow,t.startRow),h=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(Re({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(Re({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[Re(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Cn(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},cw=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},Ua=(e,t)=>{const n=e.ranges.findIndex(o=>Cn(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=cw(e.ranges,r.rangeIndex,r.cell,t),!It(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Ft=24,Ui=32,io=4,zn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),R=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),N=i.useCallback(()=>{const L=u.current,_=e.current,U=m.current;if(L===null||_===null||U===null){c.current=null;return}const{clientX:W,clientY:k}=L.getPointerPosition(),x=l.current,z=(W-U.left)/x,I=(k-U.top)/x,T=_.getViewportSize(),F=T.width,O=T.height;if(F<=0||O<=0){c.current=requestAnimationFrame(N);return}const g=y=>Math.min(Ui,Math.ceil(y/Ft*Ui));let p=0,C=0;if(s!=="x"){const y=_.getFrozenSize(),a=y.trailingVisibleHeight;I>O-a-Ft?L.anchorRow!==void 0&&y.trailingRows>0&&L.anchorRow>=t.count-y.trailingRows&&a>0&&I>=O-a||(p=g(I-(O-a-Ft))):I<y.height+Ft&&(L.anchorRow!==void 0&&L.anchorRow<y.rows&&y.height>0&&I<y.height||(p=-g(y.height+Ft-I)))}if(s!=="y"){const y=_.getFrozenSize(),a=y.trailingVisibleWidth;z>F-a-Ft?L.anchorCol!==void 0&&y.trailingCols>0&&L.anchorCol>=n.count-y.trailingCols&&a>0&&z>=F-a||(C=g(z-(F-a-Ft))):z<y.width+Ft&&(L.anchorCol!==void 0&&L.anchorCol<y.cols&&y.width>0&&z<y.width||(C=-g(y.width+Ft-z)))}const v=C!==0||p!==0?_.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):_.getScrollPosition(),S=v.y,b=v.x;if(S>=0&&b>=0&&t.totalSize()>0&&n.totalSize()>0){const y=_.getFrozenSize(),a=ln({row:kr(t,I,{scroll:S,frozenSize:y.height,trailingSize:y.trailingHeight,extent:T.height}),col:Sr(n,z,{scroll:b,frozenSize:y.width,trailingSize:y.trailingWidth,extent:T.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(L.buildRange(a)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),H=i.useCallback(L=>{R(),u.current=L,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[R,N,r]);return i.useEffect(()=>{const L=()=>{document.visibilityState==="hidden"&&R()};return document.addEventListener("visibilitychange",L),()=>{document.removeEventListener("visibilitychange",L),R()}},[R]),i.useMemo(()=>({start:H,stop:R}),[H,R])},Xi=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(!1),N=i.useRef(0),H=i.useCallback((T,F)=>{const{axis:O,mainAxis:g,handleRef:p,zoomRef:C}=t.current,v=s.current;if(v===null||g.totalSize()===0)return null;const S=C.current,b=p.current;if(b===null)return null;if(O==="col"){const E=b.getScrollPosition().x;if(E<0)return null;const d=b.getFrozenSize(),$=b.getViewportSize();return Math.min(Math.max(Sr(g,(T-v.left)/S,{scroll:E,frozenSize:d.width,trailingSize:d.trailingWidth,extent:$.width}),0),g.count-1)}const y=b.getScrollPosition().y;if(y<0)return null;const a=b.getFrozenSize(),f=b.getViewportSize();return Math.min(Math.max(kr(g,(F-v.top)/S,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),L=i.useCallback((T,F)=>{const{axis:O,crossCount:g}=t.current;return O==="col"?{press:{row:0,col:T},extend:{row:g-1,col:F}}:{press:{row:T,col:0},extend:{row:F,col:g-1}}},[]),_=i.useCallback((T,F)=>{const{axis:O,crossCount:g}=t.current;return T.ranges.some(p=>O==="col"?p.startRow===0&&p.endRow===g-1&&F>=p.startCol&&F<=p.endCol:p.startCol===0&&p.endCol===g-1&&F>=p.startRow&&F<=p.endRow)},[]),U=i.useRef(!1),W=i.useRef({clientX:0,clientY:0}),k=i.useCallback(()=>{U.current=!1;const{autoScroller:T,headerRef:F,onDragFrame:O}=t.current;n.current=!1,r.current=null,m.current=null,R.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const g=F.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,O(null),t.current.repaintOverlay()},[]),x=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.setSelection(T),k()},[k]),{enabled:z,headerRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const F=b=>{const y=t.current;if(b.pointerType!=="mouse")return;if(b.button!==0){b.preventDefault();return}if(R.current=!1,y.pointing?.getPointing()){s.current=T.getBoundingClientRect();const d=H(b.clientX,b.clientY);if(d===null)return;b.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){b.preventDefault(),y.focusSink();return}s.current=T.getBoundingClientRect();const a=H(b.clientX,b.clientY);if(a===null)return;b.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const E=b.ctrlKey||b.metaKey;if(b.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:$}=L(a,a),A={...f,anchor:d};y.setSelection(hn(A,$)),o.current=y.axis==="col"?d.col:d.row}else if(E&&_(f,a))R.current=!0,N.current=a,o.current=a;else{const{press:d,extend:$}=L(a,a),A=Cr(f,d,{extend:!1,append:E});y.setSelection(hn(A,$)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:b.clientX,clientY:b.clientY},u.current=b.pointerId,h.current=b.buttons;try{T.setPointerCapture(b.pointerId)}catch{u.current=null}m.current=d=>{const $=t.current.axis==="col"?d.col:d.row,{press:A}=L(o.current,o.current),{extend:D}=L(o.current,$);return Re(A,D)},y.autoScroller.stop(),U.current=!1,W.current={clientX:b.clientX,clientY:b.clientY}},O=b=>u.current!==null?b.pointerId===u.current:b.pointerType==="mouse",g=b=>{if(n.current&&O(b)){if(R.current){const y=b.clientX!==l.current.clientX||b.clientY!==l.current.clientY;if(l.current={clientX:b.clientX,clientY:b.clientY},!y)return;const a=H(b.clientX,b.clientY);if(a===null||a===N.current)return;R.current=!1;const f=t.current,{press:E,extend:d}=L(N.current,N.current),$=Cr(f.getSelection(),E,{extend:!1,append:!0});f.setSelection(hn($,d));const A=m.current,D=Math.abs(b.clientX-W.current.clientX),q=Math.abs(b.clientY-W.current.clientY);A!==null&&Math.max(D,q)>=io&&(U.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:A,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:b.clientX,clientY:b.clientY},!U.current&&m.current!==null){const y=Math.abs(b.clientX-W.current.clientX),a=Math.abs(b.clientY-W.current.clientY);Math.max(y,a)>=io&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=m.current;if(!n.current||y===null)return;const a=H(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=b=>{g(b),n.current&&O(b)&&(h.current&1)!==0&&(b.buttons&1)===0&&v(b)},C=b=>{b.button!==0||!(n.current&&O(b))||v(b)},v=b=>{const y=t.current;if(R.current){const{press:f,extend:E}=L(N.current,N.current);y.setSelection(Ya(y.getSelection(),Re(f,E),f)),k();return}const a=H(b.clientX,b.clientY);if(a!==null){const{extend:f}=L(o.current,a);y.setSelection(hn(y.getSelection(),f))}k()},S=b=>{!n.current||u.current===null||b.pointerId!==u.current||x()};return T.addEventListener("pointerdown",F),T.addEventListener("pointermove",p),T.addEventListener("pointerup",C),T.addEventListener("lostpointercapture",S),()=>{T.removeEventListener("pointerdown",F),T.removeEventListener("pointermove",p),T.removeEventListener("pointerup",C),T.removeEventListener("lostpointercapture",S),k()}},[z,I,H,L,k,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:x,cancelDrag:k}),[x,k])},aw=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),R=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):R>l+u-h.trailingVisibleHeight&&o.scrollBy({y:R-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),R=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):R>s+c-h.trailingVisibleWidth&&o.scrollBy({x:R-(s+c-h.trailingVisibleWidth)})}},uw=50,dw=100,Xa=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<uw:!1,ir={selectAll:Qt("Ctrl+A"),undo:Qt("Ctrl+Z"),redo:Qt("Ctrl+Y"),redoShiftZ:Qt("Ctrl+Shift+Z"),pasteValues:Qt("Ctrl+Shift+V")},fw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),pw={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},hw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",mw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,R=u.current;if(!l||m===null||R===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},H=(a,f,E)=>nn(a,f,E)??f,L=(a,f)=>{const E=s.current;return f==="left"||f==="right"?{row:a.row,col:H(E.colAxis,a.col,f==="right"?1:-1)}:{row:H(E.rowAxis,a.row,f==="down"?1:-1),col:a.col}},_=a=>a.indexAt(0),U=a=>a.indexAt(a.totalSize()-1),W=(a,f,E,d)=>{if(a.sizeOf(f)>0)return f;const $=nn(a,f,E);if($!==null)return $;const A=nn(a,f,E===1?-1:1);return A!==null?A:d},k=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},x=a=>L(k(),a),z=(a,f)=>{const E=s.current,d=f==="left"||f==="right",$=f==="right"||f==="down"?1:-1;let A;return E.findDataEdge!==void 0?(A=E.findDataEdge({row:a.row,col:a.col},f),I(A,a,f)):A={row:f==="down"?E.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?E.colAxis.count-1:f==="left"?0:a.col},d?{row:A.row,col:W(E.colAxis,A.col,$,a.col)}:{row:W(E.rowAxis,A.row,$,a.row),col:A.col}},I=(a,f,E)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const $=E==="left"||E==="right";if($?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${$?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},T=(a,f,E)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${E} component ${a} (count ${f})`)},F=a=>{const f=s.current,E=f.getSelection();if(Ua(E,a)===E){f.moveActive({mode:"reset",cell:L(E.active,a)});return}f.moveActive({mode:"cycle",direction:a})},O=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,E=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
|
|
14
|
-
${a.value.slice(E)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const E=s.current,d=E.pageExtent();if(d<=0)return H(E.rowAxis,a,f==="down"?1:-1);const $=E.rowAxis.indexAt(E.rowAxis.offsetOf(a)+(f==="down"?d:-d));return $===a?H(E.rowAxis,a,f==="down"?1:-1):$},p=a=>{const f=s.current;if(r.current=!1,Xa(a,t.current))return;const E=a.ctrlKey||a.metaKey,d=a.altKey,$=pw[a.key];if(o.current&&!fw.has(a.key)&&!f.isDragging()&&N(),f.isEditing()){const D=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!E&&!a.shiftKey&&!d&&f.abortDrag();return}const q=f.pointing;if(q!==void 0){if($!==void 0&&!d){const K=q.getReferenceCursor();if(K!==null){a.preventDefault();const G=ln(K.cursor,f.rowAxis.count,f.colAxis.count),J=ln(K.origin,f.rowAxis.count,f.colAxis.count),te=E?z(G,$):L(G,$);if(f.ensureCellVisible(te),q.insertReference(a.shiftKey?Re(J,te):te,K.axis),f.onPointFrame!==void 0){const le=a.shiftKey?Re(J,te):Re(te,te);f.onPointFrame(K.axis==="columns"?Re({row:0,col:le.startCol},{row:f.rowAxis.count-1,col:le.endCol}):K.axis==="rows"?Re({row:le.startRow,col:0},{row:le.endRow,col:f.colAxis.count-1}):le),o.current=!0}return}}if(a.key==="F2"&&!E&&!a.shiftKey&&!d&&q.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!E&&!a.shiftKey&&!d&&q.cycleAnchorAtCaret()){a.preventDefault();return}}const j=f.commands;if(j!==void 0){const K=ai(j.table,a);if(K!==null&&Ps.has(K)&&j.isAvailable(K)){a.preventDefault(),j.execute(K);return}}if($!==void 0&&!d){if(E&&a.shiftKey){a.preventDefault();return}if(E)return;if(D==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:x($)}):f.moveActive({mode:"reset",cell:L(f.getSelection().active,$)});return}return}if(a.key==="Enter"&&d&&!E&&!a.shiftKey){a.preventDefault(),O();return}if((a.key==="Enter"||a.key==="Tab")&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const K=!a.shiftKey;F(a.key==="Tab"?K?"right":"left":K?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const K=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(K.row,a.key==="PageDown"?"down":"up"),col:K.col}});return}if(a.key==="Escape"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const A=f.commands;if(A!==void 0){const D=ai(A.table,a);if(D!==null&&A.isAvailable(D)){a.preventDefault(),A.execute(D);return}}if($!==void 0&&!d){const D=$==="left"||$==="right",q=$==="right"||$==="down"?1:-1;if(E&&a.shiftKey){a.preventDefault();const j=f.getSelection(),K=k();let G;if(f.findDataEdge!==void 0){const J=D?{row:j.active.row,col:K.col}:{row:K.row,col:j.active.col},te=f.findDataEdge(J,$);G=D?te.col:te.row,T(G,D?f.colAxis.count:f.rowAxis.count,D?"col":"row"),G=W(D?f.colAxis:f.rowAxis,G,q,D?K.col:K.row)}else{const J=D?f.colAxis:f.rowAxis;G=q===1?U(J):_(J)}f.moveActive({mode:"extend",cell:D?{row:K.row,col:G}:{row:G,col:K.col}});return}if(E){a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,$)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:x($)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:L(f.getSelection().active,$)});return}if(hw(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!E&&!d){a.preventDefault();const D=!a.shiftKey;F(a.key==="Tab"?D?"right":"left":D?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const q=k();f.moveActive({mode:"extend",cell:{row:E?_(f.rowAxis):q.row,col:_(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?_(f.rowAxis):D.row,col:_(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const q=k();f.moveActive({mode:"extend",cell:{row:E?U(f.rowAxis):q.row,col:U(f.colAxis)}});return}const D=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?U(f.rowAxis):D.row,col:U(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!E&&!d){a.preventDefault();const D=a.key==="PageDown"?"down":"up";if(a.shiftKey){const j=k();f.moveActive({mode:"extend",cell:{row:g(j.row,D),col:j.col}});return}const q=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(q.row,D),col:q.col}});return}if(a.key==="F2"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection(),q=At(D.ranges);if(q>f.maxOperationCells){f.onOperationRejected?.("delete",q,"limit");return}if(f.adapter!==void 0&&qn(f.adapter,D.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:q});return}const j=[],K=f.adapter!==void 0&&eo(f.adapter).hyperlink;Jt(D.ranges,G=>{j.push(K?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),f.commitEdits(j,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(E||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(or(ir.selectAll,a)){a.preventDefault();const D=f.getSelection(),q=Re({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[q],anchor:D.anchor,active:D.active});return}if(or(ir.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(or(ir.redo,a)||or(ir.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!E&&!d||a.key==="ContextMenu"&&!E&&!a.shiftKey&&!d){a.preventDefault();const D=f.getSelection().active;f.ensureCellVisible(D);const q=h.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),K=Math.max(0,j.y),G=Math.max(0,j.x),J=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),te=q===null?{width:0,height:0}:q.getViewportSize(),le=f.zoomRef.current;f.onCellContextMenu?.(D,{kind:"keyboard",cellRect:{top:wn(f.rowAxis,D.row,{scroll:K,frozenCount:J.rows,trailingCount:J.trailingRows,extent:te.height})*le,left:gn(f.colAxis,D.col,{scroll:G,frozenCount:J.cols,trailingCount:J.trailingCols,extent:te.width})*le,width:f.colAxis.sizeOf(D.col)*le,height:f.rowAxis.sizeOf(D.row)*le}});return}if(a.key===" "&&!d&&E!==a.shiftKey){a.preventDefault();const D=f.getSelection(),q=D.ranges.map(j=>E?Re({row:0,col:j.startCol},{row:f.rowAxis.count-1,col:j.endCol}):Re({row:j.startRow,col:0},{row:j.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:q,anchor:D.anchor,active:D.active});return}if(f.pendingPasteOptionsRef!==void 0&&or(ir.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},v=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},dw)},S=()=>{const a=s.current;if(N(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},b=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),N()};return m.addEventListener("keydown",p),m.addEventListener("keyup",b),m.addEventListener("blur",y),m.addEventListener("compositionstart",C),m.addEventListener("compositionend",v),m.addEventListener("input",S),()=>{m.removeEventListener("keydown",p),m.removeEventListener("keyup",b),m.removeEventListener("blur",y),m.removeEventListener("compositionstart",C),m.removeEventListener("compositionend",v),m.removeEventListener("input",S),n.current!==null&&window.clearTimeout(n.current),N()}},[l,c,u,h])},gw=()=>{let e={vy:0,rowStart:0,rowEnd:0,colStart:0,colEnd:0,colVersion:0,rowGeomVersion:0,editVersion:0};const t=new Set;let n=null;const r=()=>{n=null;for(const l of[...t])l()},o=()=>{t.size!==0&&n===null&&(n=requestAnimationFrame(r))},s=l=>{e={...e,...l},o()};return{get:()=>e,setVy:l=>{l!==e.vy&&s({vy:l})},setRowRange:(l,c)=>{(l!==e.rowStart||c!==e.rowEnd)&&s({rowStart:l,rowEnd:c})},setColRange:(l,c)=>{(l!==e.colStart||c!==e.colEnd)&&s({colStart:l,colEnd:c})},bumpColVersion:()=>s({colVersion:e.colVersion+1}),bumpRowGeometry:()=>s({rowGeomVersion:e.rowGeomVersion+1}),bumpEdit:()=>s({editVersion:e.editVersion+1}),subscribeCoalesced:l=>(t.add(l),()=>{t.delete(l),t.size===0&&n!==null&&(cancelAnimationFrame(n),n=null)})}},ww=4,Cw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),bw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),R=i.useRef(0),N=i.useRef(null),H=i.useRef(null),L=i.useRef(!1),_=i.useCallback(T=>m.current!==null?T.pointerId===m.current:T.pointerType==="mouse",[]),U=i.useCallback((T,F)=>{const{handleRef:O,rowAxis:g,colAxis:p}=t.current,C=O.current,v=s.current;if(C===null||v===null)return null;const{x:S,y:b}=C.getScrollPosition();if(b<0||S<0||g.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return ln({row:kr(g,(F-v.top)/y,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Sr(p,(T-v.left)/y,{scroll:S,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,p.count)},[]),W=i.useCallback(T=>{const F=r.current;if(F===null)return Re(T,T);const O=Re({row:Math.min(F.startRow,T.row),col:Math.min(F.startCol,T.col)},{row:Math.max(F.endRow,T.row),col:Math.max(F.endCol,T.col)}),g=O.startRow!==F.startRow||O.endRow!==F.endRow||O.startCol!==F.startCol||O.endCol!==F.endCol;return o.current=g?O:null,g?O:F},[]),k=i.useCallback(()=>{const T=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),T.xAutoScroller.stop(),T.yAutoScroller.stop(),L.current=!1,u.current=!1,h.current={dx:0,dy:0},T.writeFillPreview(null);const F=H.current;F!==null&&(window.removeEventListener("pointermove",F.move),window.removeEventListener("pointerup",F.up),H.current=null);const O=t.current.handleNodeRef.current;O!==null&&m.current!==null&&O.hasPointerCapture?.(m.current)&&O.releasePointerCapture(m.current),m.current=null,T.repaintOverlay()},[]),x=i.useCallback(()=>{const T=t.current,F=r.current,O=o.current;if(k(),F===null||O===null)return;const g=yh(F,O);if(g>T.maxOperationCells){T.onOperationRejected?.("fill",g,"limit");return}if(qn(T.adapter,Rh(F,O))){const v=(O.endRow-O.startRow+1)*(O.endCol-O.startCol+1),S=(F.endRow-F.startRow+1)*(F.endCol-F.startCol+1);T.rejectReadOnly({kind:"operation",op:"fill",cellCount:v-S});return}const p=vh((v,S)=>sa(T.adapter,v,S),F,O,la);if(T.commitEdits(p,{source:"fill"})===null)return;const C=T.getSelection();T.setSelection({ranges:[O],anchor:C.anchor,active:C.active})},[k]),{enabled:z,handleNodeRef:I}=e;return i.useEffect(()=>{const T=I.current;if(!z||T===null)return;const F=v=>{O(v),n.current&&_(v)&&(R.current&1)!==0&&(v.buttons&1)===0&&x()},O=v=>{if(!(n.current&&_(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const S=Math.abs(v.clientX-c.current.clientX),b=Math.abs(v.clientY-c.current.clientY);if(!u.current&&Math.max(S,b)>=ww&&(u.current=!0),!!u.current){if(!L.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:W,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),L.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&u.current))return;const y=U(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(W(y))}))}},g=v=>{v.button!==0||!(n.current&&_(v))||x()},p=v=>{const S=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),S.focusSink();const b=S.getSelection(),y=b.ranges[b.ranges.length-1];r.current=y,o.current=null,u.current=!1,S.xAutoScroller.stop(),S.yAutoScroller.stop(),L.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,R.current=v.buttons,n.current=!0,S.repaintOverlay(),s.current=S.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=S.handleRef.current?.getScrollPosition()??{x:-1,y:-1},E=f.y;if(a!==null&&E>=0&&f.x>=0){const A=f.x,D=S.zoomRef.current,q=S.handleRef.current?.getFrozenSize()??Cw,j=S.handleRef.current?.getViewportSize()??{width:0,height:0},K={scroll:A,frozenCount:q.cols,trailingCount:q.trailingCols,extent:j.width},G={scroll:E,frozenCount:q.rows,trailingCount:q.trailingRows,extent:j.height},J=gn(S.colAxis,y.endCol,K)+S.colAxis.sizeOf(y.endCol),te=wn(S.rowAxis,y.endRow,G)+S.rowAxis.sizeOf(y.endRow),le=J-1,me=y.endCol>=q.cols&&q.width>0?Math.max(le,q.width):le,xe=!(y.endCol>=S.colAxis.count-q.trailingCols)&&q.trailingWidth>0?Math.min(me,j.width-q.trailingVisibleWidth-1):me,De=te-1,Pe=y.endRow>=q.rows&&q.height>0?Math.max(De,q.height):De,Ne=!(y.endRow>=S.rowAxis.count-q.trailingRows)&&q.trailingHeight>0?Math.min(Pe,j.height-q.trailingVisibleHeight-1):Pe;h.current={dx:v.clientX-(a.left+xe*D),dy:v.clientY-(a.top+Ne*D)}}else h.current={dx:0,dy:0};m.current=v.pointerId;try{T.setPointerCapture(v.pointerId)}catch{m.current=null}const d=F,$=g;H.current={move:d,up:$},window.addEventListener("pointermove",d),window.addEventListener("pointerup",$),S.writeFillPreview(r.current)},C=v=>{!n.current||m.current===null||v.pointerId!==m.current||k()};return T.addEventListener("pointerdown",p),T.addEventListener("lostpointercapture",C),()=>{T.removeEventListener("pointerdown",p),T.removeEventListener("lostpointercapture",C),k()}},[z,I,_,U,W,k,x]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&k()},cancelDrag:k}),[k])},yw=320,to=8,Rw=64,vw=150,Ga=e=>Math.max(0,Math.min(yw,e.width-Te.SPREADSHEET_SCROLLBAR_SIZE_PX-to)),Sw=(e,t,n)=>{const r=n.width-Te.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Te.SPREADSHEET_SCROLLBAR_SIZE_PX,s=Ga(n),l=Math.max(0,Math.min(t,o-to)),c=e.left+e.width,u=e.top+e.height,h=_=>_>=0&&_+s<=r,m=[e.left,c-s],R=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of R)if(h(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const N=o-u,H=e.top,L=Math.min(l,Math.max(N,H));if(L>=Rw){const _=N>=H?u:e.top-L;for(const U of m)if(h(U))return{left:U,top:_,width:s,height:L}}return{left:to,top:to,width:s,height:l}},kw=(e,t,n,r)=>t===null||e!==null&&It(e,t)||n?!1:r(t),Ew=(e,t)=>{switch(e.kind){case"note":return Y.jsx($a,{ctx:e,labels:t});case"note-tip":return Y.jsx(La,{ctx:e,labels:t});case"comment":return Y.jsx(Aa,{ctx:e,labels:t});case"link":return Y.jsx(Oa,{ctx:e,labels:t});case"list":return Y.jsx(xa,{ctx:e,labels:t});default:return Y.jsx(Ta,{ctx:e,labels:t})}},ns=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Aw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const R=ns(s),N=ns(l),H=i.useRef(null),L=(x,z)=>{const I=m.current.getLayerSize();x.style.width=`${Ga(I)}px`,x.style.maxHeight="";const T=Sw(z,x.offsetHeight,I);x.style.left=`${T.left-z.left}px`,x.style.top=`${T.top-z.top}px`,x.style.maxHeight=`${T.height}px`};i.useLayoutEffect(()=>{const x=c.current;if(x===null||s===null){H.current=null;return}if(L(x,s.anchorRect),s.kind==="message")return;const z=ns(s);if(H.current===z)return;H.current=z;const I=x.querySelector("[data-aqsp-popover-autofocus]");I!==null?I.focus({preventScroll:!0}):x.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const x=u.current,z=h.current;x===null||z===null||L(x,z.anchorRect)},[N]);const _=x=>t===void 0?Ew(x,n):t(x),U=x=>{e.isCompositionKey(x.nativeEvent)&&x.stopPropagation()},W=x=>{x.key==="Escape"&&!x.defaultPrevented&&(x.preventDefault(),e.close())},k=x=>{e.registerCompositionEnd(x.timeStamp)};return Y.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:U,onKeyDown:W,onCompositionEnd:k,children:[Y.jsx("div",{ref:r,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"interactive","data-aqsp-popover-open":s===null?void 0:"",inert:s===null,children:s===null?null:Y.jsx("div",{ref:c,className:"aqsp-popover","data-aqsp-popover-frame":s.kind,tabIndex:-1,children:_(s)},R)}),Y.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:Y.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:_(l)})})]})},Ow=["note","note-tip","comment","link","list","message"],xw=(e,t)=>{switch(t){case"note":case"note-tip":return e.getCellNote!==void 0;case"comment":return e.getCellComments!==void 0;case"link":return e.getCellHyperlink!==void 0;default:return e.getCellValidation!==void 0}},cr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&xw(e,n),Tw=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),R=i.useRef(null),N=i.useRef(null),H=i.useRef(null),L=i.useId(),_=i.useCallback(A=>{const D=t.current,q=D.handleRef.current,j=q===null?{x:0,y:0}:q.getScrollPosition(),K=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),G=q===null?{width:0,height:0}:q.getViewportSize();return{top:wn(D.rowAxis,A.row,{scroll:Math.max(0,j.y),frozenCount:K.rows,trailingCount:K.trailingRows,extent:G.height}),left:gn(D.colAxis,A.col,{scroll:Math.max(0,j.x),frozenCount:K.cols,trailingCount:K.trailingCols,extent:G.width}),width:D.colAxis.sizeOf(A.col),height:D.rowAxis.sizeOf(A.row)}},[]),U=i.useCallback(A=>{const D=t.current;D.anchors.current={...D.anchors.current,...A},D.repaintOverlay()},[]),W=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),k=i.useCallback(()=>{const A=t.current.sinkRef.current;if(A===null)return;const D=c.current;D!==null&&It(D,t.current.getActive())?A.setAttribute("aria-describedby",L):A.getAttribute("aria-describedby")===L&&A.removeAttribute("aria-describedby")},[L]),x=i.useCallback(()=>(W(),h.current=!1,c.current===null?!1:(c.current=null,s(null),U({tip:null}),k(),!0)),[W,U,k]),z=i.useCallback(()=>{W(),m.current=window.setTimeout(()=>{m.current=null,x()},vw)},[W,x]),I=i.useCallback(A=>{const D=t.current;W();const q=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(A.row,A.col);q===void 0||q===""||(c.current=A,s({kind:"note-tip",cell:A,anchorRect:_(A),current:q,close:x}),U({tip:A}),k())},[_,W,x,U,k]),T=i.useCallback(A=>{const D=t.current;if(A===null&&h.current)return;const q=u.current;u.current=A;const j=c.current;if(j!==null&&A!==null&&It(j,A)){W();return}const K=G=>{const J=D.adapter.getCellNote===void 0?void 0:D.adapter.getCellNote(G.row,G.col);return J!==void 0&&J!==""};if(kw(q,A,D.isDraggingAny(),K)){A!==null&&I(A);return}j!==null&&z()},[I,W,z]),F=i.useCallback((A,D)=>{const q=t.current,j=q.bodyRef.current,K=q.handleRef.current;if(j===null||K===null)return null;const G=j.getBoundingClientRect(),J=q.zoomRef.current,te=K.getScrollPosition(),le=K.getFrozenSize(),me=K.getViewportSize();return ln({row:kr(q.rowAxis,(D-G.top)/J,{scroll:Math.max(0,te.y),frozenSize:le.height,trailingSize:le.trailingHeight,extent:me.height}),col:Sr(q.colAxis,(A-G.left)/J,{scroll:Math.max(0,te.x),frozenSize:le.width,trailingSize:le.trailingWidth,extent:me.width})},q.rowAxis.count,q.colAxis.count)},[]),O=i.useCallback(A=>{N.current=A,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const D=N.current;T(D===null?null:"cell"in D?D.cell:F(D.clientX,D.clientY))}))},[T,F]),g=i.useCallback(A=>O({cell:A}),[O]),p=i.useCallback(()=>x(),[x]),C=i.useCallback(A=>{if(l.current===null)return;const D=t.current;l.current=null,r(null),U({interactive:null}),(A===void 0||A.restoreFocus)&&D.focusSink({preventScroll:!0}),D.isEditing()||D.rearmSink()},[U]),v=i.useCallback(A=>{l.current=A.kind,r(A),U({interactive:A.cell})},[U]),S=i.useCallback(A=>{const D=t.current;return na(D.adapter)?{cellReadOnly:Ye(D.adapter,A.row,A.col)}:{}},[]),b=i.useCallback((A,D)=>{const q=t.current;if(Ye(q.adapter,A.cell.row,A.cell.col)){q.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...A,...S(A.cell)});return}if(q.commitEdits(D,{source:"annotate"})===null){v({...A,rejected:!0});return}C()},[v,C,S]),y=i.useCallback((A,D)=>{const q=t.current;if(!cr(q.adapter,q.popovers,A))throw new RangeError(`[spreadsheet] openPopover("${A}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const j=q.getActive();if(A==="list"&&Ye(q.adapter,j.row,j.col)){q.rejectReadOnly({kind:"edit",cell:j,editSession:"none"});return}if(A==="note-tip"){I(j);return}if(A==="message"){if(l.current!==null&&l.current!=="message")return;const te=D!==void 0&&D.message!==void 0?D.message:void 0,le=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col),me=te!==void 0?te:le===void 0?void 0:le.inputMessage;if(me===void 0)return;const Ee=D!==void 0&&D.rejected===!0;v({kind:"message",cell:j,anchorRect:_(j),current:{title:ze(q.labels,"messageTitle"),message:me,rejected:Ee},close:C});return}if(q.isEditing()&&!q.requestCommit())return;if(A==="list"){const te=q.adapter.getCellValidation===void 0?void 0:q.adapter.getCellValidation(j.row,j.col);if(te===void 0||te.type!=="list")return;const le=D!==void 0&&D.typed!==void 0?D.typed:"";x(),q.focusSink({preventScroll:!0}),v({kind:"list",cell:j,anchorRect:_(j),current:te.values,typed:le,commit:me=>{if(Ye(t.current.adapter,j.row,j.col)){t.current.rejectReadOnly({kind:"edit",cell:j,editSession:"none"}),C();return}t.current.commitEdits([{row:j.row,col:j.col,text:me}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(x(),q.focusSink({preventScroll:!0}),A==="note"){const te=q.adapter.getCellNote===void 0?void 0:q.adapter.getCellNote(j.row,j.col),le={kind:"note",cell:j,anchorRect:_(j),current:te,commit:me=>{b(le,[{row:j.row,col:j.col,note:me}])},close:C,rejected:!1,...S(j)};v(le);return}if(A==="comment"){const te=q.adapter.getCellComments===void 0?void 0:q.adapter.getCellComments(j.row,j.col),le={kind:"comment",cell:j,anchorRect:_(j),current:te===void 0?[]:te,commit:me=>{b(le,[{row:j.row,col:j.col,comments:me}])},close:C,rejected:!1,...S(j)};v(le);return}const K=q.adapter.getCellHyperlink===void 0?void 0:Un(q.adapter.getCellHyperlink(j.row,j.col)),G=q.adapter.getCellText(j.row,j.col),J={kind:"link",cell:j,anchorRect:_(j),current:{text:G,url:K},commit:te=>{const le=te.url===null?null:sn(te.url);if(le===null&&te.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(te.url)}`);const me=te.text===G?{row:j.row,col:j.col,hyperlink:le}:{row:j.row,col:j.col,text:te.text,hyperlink:le};b(J,[me])},close:C,canOpen:q.onHyperlinkOpen!==void 0,open:()=>{const te=t.current.onHyperlinkOpen;te!==void 0&&K!==void 0&&te(K,j)},rejected:!1,...S(j)};v(J)},[_,C,b,x,v,I,S]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const A=f.current;if(!a||A===null)return;const D=j=>{const K=t.current;cr(K.adapter,K.popovers,"note-tip")&&O({clientX:j.clientX,clientY:j.clientY})},q=()=>{cr(t.current.adapter,t.current.popovers,"note-tip")&&O({cell:null})};return A.addEventListener("pointermove",D),A.addEventListener("pointerleave",q),()=>{A.removeEventListener("pointermove",D),A.removeEventListener("pointerleave",q)}},[a,f,O]),i.useEffect(()=>()=>{R.current!==null&&cancelAnimationFrame(R.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:E,popovers:d}=e,$=i.useMemo(()=>Ow.some(A=>cr(E,d,A)),[E,d]);return i.useMemo(()=>({layerEnabled:$,isKindEnabled:A=>cr(t.current.adapter,t.current.popovers,A),open:y,close:C,isOpen:()=>l.current,onCellHover:g,hideTip:p,onTipPointerEnter:()=>{h.current=!0,W()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&z()},syncTipAriaDescribedBy:k,context:n,tipContext:o,registerCompositionEnd:A=>{H.current=A},isCompositionKey:A=>Xa(A,H.current),getLayerSize:()=>{const A=t.current.handleRef.current;return A===null?{width:0,height:0}:A.getViewportSize()},tipId:L}),[$,y,C,g,p,W,z,k,n,o,L])},$w=(e,t,n)=>{let r=null,o=0;if(typeof document.caretPositionFromPoint=="function"){const l=document.caretPositionFromPoint(e,t);if(l===null)return;r=l.offsetNode,o=l.offset}else if(typeof document.caretRangeFromPoint=="function"){const l=document.caretRangeFromPoint(e,t);if(l===null)return;r=l.startContainer,o=l.startOffset}else return;if(r===null||r.nodeType!==Node.TEXT_NODE)return;const s=r.parentElement?.closest("[data-aqsp-cell]")??null;if(!(s===null||Number(s.getAttribute("data-row"))!==n.row||Number(s.getAttribute("data-col"))!==n.col))return o},Za=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:u}=e.getScrollPosition();if(u<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const h=e.getFrozenSize(),m=e.getViewportSize();return ln({row:kr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:Sr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},Lw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),R=i.useRef(null),N=i.useRef(""),H=i.useRef(!1),L=i.useRef(!1),_=i.useCallback((O,g)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:S}=t.current;return Za(p.current,o.current,C,v,S.current,O,g)},[]),U=i.useRef(!1),W=i.useRef(null),k=i.useRef(null),x=i.useRef({clientX:0,clientY:0}),z=i.useCallback(()=>{const{autoScroller:O,bodyRef:g,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,U.current=!1,W.current=null,k.current=null,m.current=!1,R.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),O.stop();const C=g.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),I=i.useCallback(()=>{if(!n.current)return;const O=r.current;O!==null&&t.current.setSelection(O),z()},[z]),{enabled:T,bodyRef:F}=e;return i.useEffect(()=>{const O=F.current;if(!T||O===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const $=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,R.current=null,L.current=!1),H.current=g(d.target),!H.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if($.getPointing?.()){$.focusSink();return}if($.isEditing()&&!$.requestCommit()){d.stopPropagation(),$.focusSink();return}$.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if(($.pointDragRef===void 0?null:$.pointDragRef.current)?.onPointerDown(d))return;if($.isEditing()&&!$.requestCommit()){d.preventDefault(),$.focusSink();return}o.current=O.getBoundingClientRect();const D=_(d.clientX,d.clientY);if(D===null)return;if(d.preventDefault(),$.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&$.openHyperlinkAt?.(D)===!0){L.current=!0;return}const q=$.getSelection();r.current=q;const j=d.shiftKey,K=d.ctrlKey||d.metaKey,G=K&&!j&&q.ranges.some(te=>Cn(te,D));m.current=G,R.current=G?D:null,G||$.setSelection(Cr(q,D,{extend:j,append:K})),n.current=!0,$.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{O.setPointerCapture(d.pointerId)}catch{c.current=null}const J=G?D:$.getSelection().anchor;h.current=te=>Re(J,te),W.current=J.col,k.current=J.row,$.autoScroller.stop(),U.current=!1,x.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",v=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!U.current&&h.current!==null){const $=Math.abs(d.clientX-x.current.clientX),A=Math.abs(d.clientY-x.current.clientY);Math.max($,A)>=io&&(U.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:W.current??void 0,anchorRow:k.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const $=h.current;if(!n.current||$===null)return;const A=t.current,D=_(s.current.clientX,s.current.clientY);D!==null&&A.onDragFrame($(D))}))}},S=d=>{v(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},b=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const $=t.current,A=_(d.clientX,d.clientY);if(A!==null){const D=R.current;m.current&&D!==null?$.setSelection(Ya($.getSelection(),Re(D,A),D)):$.setSelection(hn($.getSelection(),A))}z()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||I()},f=d=>{const $=t.current;if(!g(d.target)||N.current!=="mouse"||$.isAnyDragging())return;if($.isEditing()&&!$.requestCommit()){$.focusSink();return}$.focusSink(),o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);if(A===null)return;const D=$.getSelection();D.ranges.some(j=>Cn(j,A))||$.setSelection(Cr(D,A,{extend:!1,append:!1})),$.onContextMenuSelect(A,d)},E=d=>{const $=t.current;if(!H.current||N.current!=="mouse"||$.getPointing?.()||L.current)return;o.current=O.getBoundingClientRect();const A=_(d.clientX,d.clientY);A!==null&&It($.getSelection().active,A)&&$.onRequestEdit(A,$.caretFromPointEnabled(A)?$w(d.clientX,d.clientY,A):void 0)};return O.addEventListener("pointerdown",p),O.addEventListener("pointermove",S),O.addEventListener("pointerup",b),O.addEventListener("lostpointercapture",a),O.addEventListener("contextmenu",f),O.addEventListener("dblclick",E),()=>{O.removeEventListener("pointerdown",p),O.removeEventListener("pointermove",S),O.removeEventListener("pointerup",b),O.removeEventListener("lostpointercapture",a),O.removeEventListener("contextmenu",f),O.removeEventListener("dblclick",E),z()}},[T,F,_,z,I]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:I,cancelDrag:z}),[I,z])},Dw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(null),N=i.useRef(!1),H=i.useCallback((x,z)=>{const{handleRef:I,rowAxis:T,colAxis:F,zoomRef:O}=t.current;return Za(I.current,o.current,T,F,O.current,x,z)},[]),L=i.useCallback(()=>{const{autoScroller:x,bodyRef:z,onDragFrame:I}=t.current;n.current=!1,r.current=null,m.current=null,R.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),x.stop();const T=z.current;T!==null&&u.current!==null&&T.hasPointerCapture?.(u.current)&&T.releasePointerCapture(u.current),u.current=null,I(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const x=r.current;x!==null&&t.current.restoreSink(x),L()},[L]),U=i.useCallback(x=>{const z=t.current,I=z.bodyRef.current;if(!z.enabled||I===null||!z.getPointing())return!1;o.current=I.getBoundingClientRect();const T=H(x.clientX,x.clientY);if(T===null)return o.current=null,!1;const F=z.captureSink();if(F===null)return o.current=null,!1;x.preventDefault(),z.focusSink(),r.current=F,R.current=T,z.insertReference(T,"cells"),n.current=!0,s.current={clientX:x.clientX,clientY:x.clientY},l.current={clientX:x.clientX,clientY:x.clientY},u.current=x.pointerId,h.current=x.buttons;try{I.setPointerCapture(x.pointerId)}catch{u.current=null}return m.current=O=>{const g=Re(T,O);return t.current.insertReference(g,"cells"),g},z.autoScroller.stop(),N.current=!1,z.onDragFrame(Re(T,T)),!0},[H]),{enabled:W,bodyRef:k}=e;return i.useEffect(()=>{const x=k.current;if(!W||x===null)return;const z=O=>u.current!==null?O.pointerId===u.current:O.pointerType==="mouse",I=O=>{if(!(n.current&&z(O)))return;s.current={clientX:O.clientX,clientY:O.clientY};const g=m.current,p=R.current;if(!N.current&&g!==null&&p!==null){const C=Math.abs(O.clientX-l.current.clientX),v=Math.abs(O.clientY-l.current.clientY);Math.max(C,v)>=io&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=m.current;if(!n.current||C===null)return;const v=H(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(h.current&1)!==0&&(O.buttons&1)===0&&L()},T=O=>{O.button!==0||!(n.current&&z(O))||L()},F=O=>{!n.current||u.current===null||O.pointerId!==u.current||L()};return x.addEventListener("pointermove",I),x.addEventListener("pointerup",T),x.addEventListener("lostpointercapture",F),()=>{x.removeEventListener("pointermove",I),x.removeEventListener("pointerup",T),x.removeEventListener("lostpointercapture",F),L()}},[W,k,H,L]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:L,onPointerDown:U}),[_,L,U])},Mw=Object.freeze({width:0,height:0}),rs=33,zw=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,Nw=(e,t,n)=>{const r=(n-t)/(rs-1);let o=-1,s=-1;for(let c=0;c<rs;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,u)=>{let h=c,m=u;for(;Math.abs(m-h)>1;){const R=(h+m)/2;e(R)?m=R:h=R}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===rs-1?n:l(t+r*(s+1),t+r*s)}},Fw=(e,t)=>{if(!Number.isInteger(e)||e<0||e>0&&e>t)throw new RangeError(`[spreadsheet] headerRows must be a whole number from 0 to frozenRows = ${t} (got ${e})`)},Pw=e=>{if(e!==void 0&&(typeof e!="string"||e===""||/\s/u.test(e)))throw new RangeError(`[spreadsheet] labelledBy must be one non-empty id without whitespace (got ${JSON.stringify(e)})`)},Gi=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${typeof t=="string"?JSON.stringify(t):String(t)})`);return t},_w=24,qw=200,Ja=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Zi=5,Iw=/^#[0-9A-Fa-f]{6}$/,jw=Object.freeze({row:!1,column:!1,intersection:!1}),Ji=Object.freeze({ok:!0}),Qi=(e,t)=>{if(t===void 0)return Ja;if(t.length!==Zi)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Zi} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!Iw.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},Hw=e=>{for(const t of["row","column","intersection"])if(Ze(e[t])===null)throw new RangeError(`[spreadsheet] highlightColors.${t} is not a colour (got ${JSON.stringify(e[t])})`);if(!(Number.isFinite(e.opacity)&&e.opacity>=0&&e.opacity<=1))throw new RangeError(`[spreadsheet] highlightColors.opacity must be a number in [0, 1] (got ${e.opacity})`);return e},Bw=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ka},Vw=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},Ww=e=>{const t=i.useRef(null),n=t.current;return n!==null&&Je.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},Nn={ranges:[Re({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},Kw=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=_w,defaultColumnWidth:l=Te.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:m=0,tapScrollCircleOptions:R,overscanRows:N,overscanCols:H,background:L,onRenderTruncated:_,renderCell:U,onSelectionChange:W,onCellContextMenu:k,onUndoRequest:x,onRedoRequest:z,onCopyMultiRange:I,onOperationRejected:T,onEditRejected:F,onReadOnlyRejected:O,formatReadOnlyAnnouncement:g,dataVersion:p,maxOperationCells:C=Te.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:v=!0,enableResizeUI:S=!0,headings:b=!0,onContentSizeChange:y,formatCellAnnouncement:a,formatSelectionAnnouncement:f,formatCommandAnnouncement:E,formatResizeAnnouncement:d,locale:$,labels:A,shortcuts:D,colors:q,formats:j,highlight:K,defaultHighlight:G,onHighlightChange:J,highlightColors:te,popovers:le,renderPopover:me,onClipChange:Ee,onHyperlinkOpen:xe,onValidationRejected:De,onPasteSpecialRequest:Pe,onClipboardUnavailable:ue,onPasteResolved:Ne,now:Ue=Date.now,zoom:je,defaultZoom:Ot,onZoomChange:xt,testId:He,className:wt,__onCellRender:bn,__onVirtualKeyboardRaise:lt,__maxRenderedCells:Er},yn){const oe=i.useMemo(()=>r?hh(t):t,[t,r]),fe=qi(oe.rowCount,s),pe=qi(oe.colCount,l),Ht=i.useRef(null);Ht.current===null&&(Ht.current=gw());const Ae=Ht.current,Bt=Je.resolveVirtualScrollLocale($),it=i.useMemo(()=>fa($,A),[$,A]),Rn=Ww(Ih(it)),Vt=i.useMemo(()=>Fh(D),[D]),Ar=i.useMemo(()=>{if(!S)return;const P=[...Vt].filter(([,Z])=>Uo.includes(Z)).sort(([,Z],[,Q])=>Uo.indexOf(Z)-Uo.indexOf(Q)).map(([Z])=>$h(Z)).filter(Z=>Z!==null);return P.length===0?void 0:P.join(" ")},[Vt,S]),Xn=i.useMemo(()=>({fill:Qi("fill",q===void 0?void 0:q.fill),font:Qi("font",q===void 0?void 0:q.font)}),[q]),mo=i.useMemo(()=>te===void 0?void 0:Hw(te),[te]);if(oe.getConditionalFormats!==void 0&&oe.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");Fw(n,u),Pw(o);const Or=i.useCallback(()=>Ae.get().editVersion,[Ae]),go=i.useCallback(w=>Ae.subscribeCoalesced(w),[Ae]),wo=i.useSyncExternalStore(go,Or,Or)+(p===void 0?0:p),Wt=oe.getConditionalFormats===void 0?null:oe.getConditionalFormats(),vn=i.useMemo(()=>({index:Wt===null?null:Ba(Wt),memo:qs()}),[oe,Wt,wo]),Gn=i.useRef(vn.index);Gn.current=vn.index;const M=i.useRef(vn.memo);M.current=vn.memo;const B=i.useCallback((w,P,Z)=>Is(oe,Gn.current,M.current,w,P,Z),[oe]),X=i.useRef(null),[V,ee]=i.useState(()=>Te.clampSpreadsheetZoom(Ot??1)),se=Te.clampSpreadsheetZoom(je??V),ne=i.useRef(se);ne.current=se;const Oe=i.useRef(se);Oe.current=se;const Se=i.useRef(null),Be=i.useRef(xt);Be.current=xt;const Ve=i.useRef(je!==void 0);Ve.current=je!==void 0;const _e=i.useCallback(w=>{const P=Te.clampSpreadsheetZoom(w);P!==Oe.current&&(Oe.current=P,Ve.current||ee(P),Be.current?.(P))},[]),ve=oe.rowCount===0||oe.colCount===0,ie=!ve;i.useEffect(()=>{const w=X.current;if(!ie||w===null)return;const P=Q=>{Q.defaultPrevented||!Q.altKey||Q.ctrlKey||Q.metaKey||Q.shiftKey||Q.deltaY!==0&&(Q.preventDefault(),Q.stopPropagation(),!Se.current?.()&&_e(Te.stepSpreadsheetZoom(Oe.current,Q.deltaY<0?1:-1)))},Z=Q=>{if(Q.defaultPrevented||!(Q.ctrlKey&&Q.altKey)||Q.metaKey||Q.getModifierState("AltGraph"))return;const de=Q.key==="="||Q.key==="+"?Te.stepSpreadsheetZoom(Oe.current,1):Q.key==="-"?Te.stepSpreadsheetZoom(Oe.current,-1):Q.key==="0"?1:null;de!==null&&(Q.preventDefault(),Q.stopPropagation(),!Se.current?.()&&_e(de))};return w.addEventListener("wheel",P,{passive:!1,capture:!0}),w.addEventListener("keydown",Z,!0),()=>{w.removeEventListener("wheel",P,{capture:!0}),w.removeEventListener("keydown",Z,!0)}},[_e,ie]);const ce=i.useRef(null),ge=i.useRef(null),Ce=i.useRef(null),he=i.useRef(null),re=i.useRef(null),ke=i.useRef(null),Me=i.useRef(null),Ct=i.useRef(0),ct=i.useRef(null),bt=i.useRef(0),Tt=i.useRef(null),$t=i.useRef(null),Kt=i.useRef(null),yt=i.useRef(null),Sn=i.useRef(null),kn=i.useRef(null),Bs=i.useRef(null),[En,Co]=i.useState(Nn),Rt=i.useRef(En),Lt=i.useCallback(()=>Rt.current,[]),[Qa,eu]=i.useState(()=>G===void 0?jw:G),An=K!==void 0?K:Qa,bo=i.useRef(An);bo.current=An;const tu=Bw(mo,An),Vs=i.useRef(K!==void 0);Vs.current=K!==void 0;const Ws=i.useRef(J);Ws.current=J;const nu=i.useCallback(w=>{Vs.current||eu(w),Ws.current?.(w)},[]),Ks=i.useRef(null),yo=i.useRef(null),Dt=i.useRef(null),Ro=i.useRef(()=>!1),Ys=i.useRef(()=>{}),Us=i.useRef(()=>null),Xs=i.useRef(()=>{}),cn=i.useCallback(()=>Ro.current(),[]),vo=i.useMemo(()=>({getPointing:()=>Ro.current(),insertReference:(w,P)=>Ys.current(w,P)}),[]),Gs=i.useRef(Pt),Zs=i.useRef(null),So=i.useRef({interactive:null,tip:null}),Js=i.useRef(null),Qs=i.useRef(null),xr=i.useRef(()=>{}),el=i.useRef(()=>!1),Yt=i.useRef(null),Zn=i.useCallback(()=>{const w=Yt.current;if(w===null||w.isOpen()!=="message")return!1;const P=w.context;return P===null||P.kind!=="message"||!P.current.rejected?!1:(w.close(),!0)},[]),ko=i.useRef(()=>!1),tl=i.useRef(()=>!1),nl=i.useRef(null),Eo=i.useRef(()=>Promise.resolve("rejected")),Le=i.useCallback(()=>{Ks.current?.()},[]),Mt=i.useCallback(w=>{ke.current?.focus(w)},[]),qe=i.useCallback(()=>{Mt({preventScroll:!0})},[Mt]),Ao=i.useRef(!1),ru=i.useCallback(()=>{const w=X.current;if(w!==null){Ao.current=!0;try{w.focus()}finally{Ao.current=!1}}},[]),Qe=i.useCallback(()=>{const w=ke.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),On=i.useCallback((w,P)=>{if(w===null)return;const Z=P?"":"none";w.style.display!==Z&&(w.style.display=Z)},[]),at=i.useCallback(()=>{const w=Me.current;if(w!==null){const Z=Math.max(0,re.current?.getScrollPosition().y??0),Q=re.current?.getFrozenSize().height??0;w.style.transform=`translateY(${Ct.current-Z-Q}px)`}const P=re.current;if(P!==null&&(Sn.current!==null||kn.current!==null)){const Z=P.getFrozenSize();On(Sn.current,Z.height>0),On(kn.current,Z.trailingHeight>0)}},[On]),ut=i.useCallback(()=>{const w=ct.current;if(w!==null){const Z=Math.max(0,re.current?.getScrollPosition().x??0),Q=re.current?.getFrozenSize().width??0;w.style.transform=`translateX(${bt.current-Z-Q}px)`}const P=re.current;if(P!==null&&(Kt.current!==null||yt.current!==null)){const Z=P.getFrozenSize();On(Kt.current,Z.width>0),On(yt.current,Z.trailingWidth>0)}},[On]),Jn=i.useRef(null),xn=i.useCallback(()=>{Kt.current===null&&yt.current===null&&Sn.current===null&&kn.current===null||Jn.current===null&&(Jn.current=requestAnimationFrame(()=>{Jn.current=null,at(),ut(),Le()}))},[at,ut,Le]);i.useEffect(()=>()=>{Jn.current!==null&&cancelAnimationFrame(Jn.current)},[]);const Oo=i.useRef(null),xo=i.useRef(null);(Oo.current===null||xo.current?.rowAxis!==fe||xo.current?.colAxis!==pe)&&(xo.current={rowAxis:fe,colAxis:pe},Oo.current=aw({handleRef:re,rowAxis:fe,colAxis:pe}));const Tr=i.useCallback(w=>{const P=re.current,Z=P===null?{x:0,y:0}:P.getScrollPosition(),Q=P===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:P.getFrozenSize(),de=P===null?{width:0,height:0}:P.getViewportSize(),be=ne.current;return{top:wn(fe,w.row,{scroll:Math.max(0,Z.y),frozenCount:Q.rows,trailingCount:Q.trailingRows,extent:de.height})*be,left:gn(pe,w.col,{scroll:Math.max(0,Z.x),frozenCount:Q.cols,trailingCount:Q.trailingCols,extent:de.width})*be,width:pe.sizeOf(w.col)*be,height:fe.sizeOf(w.row)*be}},[fe,pe]),rl=i.useCallback(w=>{const P=he.current,Z=X.current,Q=ge.current;if(P===null||Z===null||Q===null||re.current===null)return;const de=ne.current,be=Tr(w),Ke=Q.offsetTop*de+be.top,tt=Q.offsetLeft*de+be.left,Ie=Math.max(0,Ke),Et=Math.max(0,tt),Gt=Math.min(Z.clientHeight,Ke+be.height),Mr=Math.min(Z.clientWidth,tt+be.width);if(Gt<=Ie||Mr<=Et)return;P.style.top=`${Ie}px`,P.style.left=`${Et}px`,P.style.width=`${Mr-Et}px`,P.style.height=`${Gt-Ie}px`;const Dn=P.getBoundingClientRect();Dn.width===0&&Dn.height===0||P.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Tr]),Ut=i.useCallback(w=>{Oo.current?.(w),rl(w)},[rl]),ou=i.useCallback(()=>{const w=re.current,P=w===null?-1:w.getViewportSize().height,Z=ce.current,Q=X.current;if(P<=0||Z===null||Q===null)return P;const de=Z.getBoundingClientRect(),be=Q.getRootNode();if(de.height<=0||Z.offsetHeight<=0||!zw(be))return P;const Ke=Q.ownerDocument.documentElement,tt=Math.max(de.left,0),Ie=Math.min(de.right,Ke.clientWidth),Et=Math.max(de.top,0)+.5,Gt=Math.min(de.bottom,Ke.clientHeight)-.5,Mr=(tt+Ie)/2,Dn=Ie>tt&&Gt>=Et?Nw(zu=>{const Ml=be.elementFromPoint(Mr,zu);return Ml!==null&&Q.contains(Ml)},Et,Gt):null,Mu=Dn===null?Ke.clientHeight:Dn.bottom-Dn.top+1;return Math.min(P,Mu*(Z.offsetHeight/de.height))},[]),ol=i.useRef(y);ol.current=y;const To=i.useRef(null),zt=i.useCallback(()=>{const w=ol.current;if(w===void 0)return;const P=ge.current;let Z;if(P===null)Z=Mw;else{if(P.getClientRects().length===0)return;{const de=Ce.current,be=ne.current;Z={width:((de===null?0:de.offsetWidth)+pe.totalSize()+Te.SPREADSHEET_SCROLLBAR_SIZE_PX)*be,height:((de===null?0:de.offsetHeight)+fe.totalSize()+Te.SPREADSHEET_SCROLLBAR_SIZE_PX)*be}}}const Q=To.current;Q!==null&&Q.width===Z.width&&Q.height===Z.height||(To.current=Z,w(Z))},[fe,pe]);i.useLayoutEffect(()=>{if(y===void 0){To.current=null;return}zt()});const sl=y!==void 0;i.useEffect(()=>{const w=ge.current;if(!sl||w===null)return;const P=new ResizeObserver(()=>zt());return P.observe(w),()=>P.disconnect()},[sl,zt,ve]);const Tn=i.useRef(null),an=i.useRef(null),$n=i.useCallback(w=>{Tn.current!==null&&window.clearTimeout(Tn.current),an.current!==null&&(cancelAnimationFrame(an.current),an.current=null),Tn.current=window.setTimeout(()=>{Tn.current=null;const P=Bs.current;P!==null&&(P.textContent="",an.current=requestAnimationFrame(()=>{an.current=null,P.textContent=w}))},qw)},[]);i.useEffect(()=>()=>{Tn.current!==null&&window.clearTimeout(Tn.current),an.current!==null&&cancelAnimationFrame(an.current)},[]);const Ln=i.useCallback(w=>{O?.(w),g!==void 0&&$n(g(w))},[O,g,$n]),ll=i.useCallback((w,P)=>{if(a===void 0&&f===void 0)return;const Z=P.ranges[P.ranges.length-1],Q=st(Z),de=P.ranges.length===1&&Q.rows===1&&Q.cols===1,be=w.ranges[w.ranges.length-1],Ke=w.ranges.length!==P.ranges.length||be.startRow!==Z.startRow||be.startCol!==Z.startCol||be.endRow!==Z.endRow||be.endCol!==Z.endCol,tt=()=>{if(a!==void 0){const Ie=P.active,Et=oe.getCellText(Ie.row,Ie.col),Gt=oe.getCellFormat===void 0?void 0:B(Ie.row,Ie.col,()=>Et);$n(a({row:Ie.row,col:Ie.col,text:Et,displayText:Wn(Et,Gt===void 0?void 0:Gt.value),columnName:Te.columnIndexToName(Ie.col),...na(oe)?{readOnly:Ye(oe,Ie.row,Ie.col)}:{}}))}};if(de){tt();return}if(Ke){f!==void 0&&$n(f({range:Z,anchor:P.anchor,active:P.active,rangeRowCount:Q.rows,rangeColCount:Q.cols,rangeCount:P.ranges.length}));return}tt()},[oe,a,f,$n,B]),We=i.useCallback(w=>{const P=Rt.current;Object.is(w,P)||ow(w,P)||(Rt.current=w,Co(w),W?.(w),ll(P,w),(Dt.current?.()??!1)||Qe())},[W,ll,Qe]),su=i.useCallback(w=>{const P=Rt.current;if(w.mode==="cycle"){const Q=Ua(P,w.direction);We(Q),Ut(Q.active);return}const Z=ln(w.cell,fe.count,pe.count);if(w.mode==="extend"){We(hn(P,Z)),Ut(Z);return}We(Cr(P,Z,{extend:!1,append:!1})),Ut(Z)},[We,Ut,fe,pe]),Xe=i.useCallback(()=>Dt.current?.()??!1,[]),il=i.useRef(null),dt=i.useCallback(()=>il.current?.()??!0,[]),cl=i.useRef(null),Qn=i.useCallback((w,P)=>{const Z=Dt.current?.()??!1;cl.current?.(w,P),!Z&&(Dt.current?.()??!1)&&Zn()},[Zn]),[lu,$o]=i.useState(!1),al=i.useCallback(()=>{lt?.(),$o(!0)},[lt]),iu=i.useCallback((w,P)=>{Ye(oe,w.row,w.col)||al(),Qn("edit",P)},[oe,al,Qn]),ul=i.useRef(null),$r=i.useCallback(()=>ul.current?.()??null,[]),dl=i.useRef(null),vt=i.useCallback(()=>{dl.current?.()},[]),fl=i.useRef(null),pl=i.useCallback(w=>{fl.current?.(w)},[]),hl=i.useRef(()=>{}),Lr=i.useRef(0),un=i.useCallback((w,P,Z)=>{let Q;if(P.source==="paste"){const de=Vw(Z);if(w.length===0&&de.conditionalFormats.length===0)return null;Lr.current+=1,Q={transaction:Lr.current,source:"paste",sameSheet:de.sameSheet,conditionalFormats:de.conditionalFormats}}else{if(w.length===0)return null;Lr.current+=1,Q={transaction:Lr.current,source:P.source}}try{oe.applyEdits(w,Q)}catch(de){return F?.(de,P),null}return Ae.bumpEdit(),pl(P.source),Q.transaction},[oe,Ae,F,pl]),cu=i.useCallback((w,P)=>un(w,{source:"paste"},P),[un]),au=i.useCallback(w=>{Ae.setVy(w.y),at(),ut(),Le()},[Ae,at,ut,Le]),ml=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),uu=i.useCallback(w=>{Ae.setRowRange(w.renderingRowStart,w.renderingRowEnd),Ae.setColRange(w.renderingColStart,w.renderingColEnd);const P=ml.current;(P.rowStart!==w.renderingRowStart||P.rowEnd!==w.renderingRowEnd||P.colStart!==w.renderingColStart||P.colEnd!==w.renderingColEnd)&&(ml.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},Le())},[Ae,Le]),gl=i.useRef(()=>"add"),Xt=i.useCallback(w=>{yo.current?.(w,gl.current())},[]),du=i.useCallback(w=>{yo.current?.(w,"point")},[]),wl=i.useRef(null),Lo=i.useCallback(w=>{wl.current?.(w)},[]),Cl=i.useRef(null),fu=i.useCallback(w=>{Cl.current?.(w)},[]),bl=i.useRef(null),Do=i.useCallback((w,P)=>{if(P.length===0)return;const Z=re.current;if(w==="col"){for(const Q of P){const de=Math.round(Q.size);pe.resize(Q.index,de),Z?.updateColSize(Q.index,de)}Ae.bumpColVersion(),ut(),Le(),xn(),zt();return}for(const Q of P){const de=Math.round(Q.size);fe.resize(Q.index,de),Z?.updateRowSize(Q.index,de)}Ae.bumpRowGeometry(),at(),Le(),xn(),zt()},[fe,pe,Ae,ut,at,Le,xn,zt]),pu=i.useCallback((w,P)=>{k?.(w,{kind:"pointer",event:P})},[k]),hu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"both",zoomRef:ne}),mu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"x",zoomRef:ne}),gu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"y",zoomRef:ne}),wu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Lo,axis:"x",zoomRef:ne}),Cu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Lo,axis:"y",zoomRef:ne}),bu=zn({handleRef:re,rowAxis:fe,colAxis:pe,bodyRef:ce,onDragFrame:Xt,axis:"both",zoomRef:ne}),yl=i.useRef(null),Rl=i.useRef(()=>!1),Mo=i.useCallback(()=>Rl.current(),[]),ft=Lw({zoomRef:ne,enabled:!ve,rowAxis:fe,colAxis:pe,handleRef:re,bodyRef:ce,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,onContextMenuSelect:pu,onRequestEdit:iu,caretFromPointEnabled:w=>{if(U!==void 0||oe.getCellFormula!==void 0&&oe.getCellFormula(w.row,w.col)!==void 0)return!1;if(oe.getCellFormat===void 0)return!0;const P=oe.getCellText(w.row,w.col);return Wn(P,oe.getCellFormat(w.row,w.col)?.value)===P},isAnyDragging:Mo,autoScroller:hu,repaintOverlay:Le,pointDragRef:yl,getPointing:cn,openHyperlinkAt:xe===void 0||oe.getCellHyperlink===void 0?void 0:w=>{const P=oe.getCellHyperlink===void 0?void 0:Un(oe.getCellHyperlink(w.row,w.col));return P===void 0?!1:(xe(P,w),!0)}}),St=Xi({zoomRef:ne,enabled:!ve&&b,axis:"col",headerRef:Tt,mainAxis:pe,crossCount:oe.rowCount,handleRef:re,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,autoScroller:mu,repaintOverlay:Le,pointing:vo}),kt=Xi({zoomRef:ne,enabled:!ve&&b,axis:"row",headerRef:$t,mainAxis:fe,crossCount:oe.colCount,handleRef:re,isEditing:Xe,requestCommit:dt,getSelection:Lt,setSelection:We,focusSink:qe,onDragFrame:Xt,autoScroller:gu,repaintOverlay:Le,pointing:vo}),et=rw({zoomRef:ne,enabled:!ve&&S&&b,colBandRef:Tt,rowBandRef:$t,fontSourceRef:ce,colAxis:pe,rowAxis:fe,viewStore:Ae,handleRef:re,isEditing:Xe,requestCommit:dt,focusSink:qe,getSelection:Lt,adapter:oe,autofitEnabled:U===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:T,resizeTracks:Do,writeResizeGuide:fu,repaintOverlay:Le,isPointing:cn}),pt=bw({zoomRef:ne,enabled:!ve&&v,handleNodeRef:bl,bodyRef:ce,rowAxis:fe,colAxis:pe,handleRef:re,getSelection:Lt,setSelection:We,focusSink:qe,adapter:oe,commitEdits:un,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,writeFillPreview:Lo,repaintOverlay:Le,xAutoScroller:wu,yAutoScroller:Cu}),nt=Dw({zoomRef:ne,enabled:!ve,bodyRef:ce,handleRef:re,rowAxis:fe,colAxis:pe,getPointing:cn,insertReference:vo.insertReference,captureSink:()=>Us.current(),restoreSink:w=>Xs.current(w),focusSink:qe,autoScroller:bu,onDragFrame:Xt});yl.current=nt;const er=i.useCallback(()=>ft.isDragging()||St.isDragging()||kt.isDragging()||et.isDragging()||pt.isDragging()||nt.isDragging(),[ft,St,kt,et,pt,nt]);Se.current=er,Rl.current=er,gl.current=()=>nt.isDragging()?"point":ft.getDragMode();const yu=i.useCallback(()=>{ft.abortDrag(),St.abortDrag(),kt.abortDrag(),et.abortDrag(),pt.abortDrag(),nt.abortDrag()},[ft,St,kt,et,pt,nt]),zo=i.useCallback(()=>Rt.current.active,[]),vl=i.useCallback((w,P)=>{const Z=oe.getCellValidation===void 0?void 0:oe.getCellValidation(w.row,w.col);if(Z===void 0)return Ji;const Q=oe.evaluateFormula,de=ma(Z,P,Bt,Q===void 0?void 0:be=>Q(be,w));return de.ok||Z.strict!==!0?Ji:(De?.({cell:w,rule:Z,text:P,message:de.message}),Yt.current?.isKindEnabled("message")&&xr.current("message",{message:de.message,rejected:!0}),de)},[oe,De,Bt]),Fe=bg({enabled:!ve,sinkRef:ke,rootRef:X,adapter:oe,commitEdits:un,getActive:zo,ensureCellVisible:Ut,focusSink:Mt,rearmSink:Qe,discardClip:vt,isDragging:Mo,rejectReadOnly:Ln,resolveEditAlign:w=>{if(oe.getCellFormat===void 0)return null;const P=Qr(oe,w.row,w.col);return ta(B(w.row,w.col,P),P)},resolveEditPaint:w=>oe.getCellFormat===void 0?null:df(B(w.row,w.col,Qr(oe,w.row,w.col))),editPaintRef:Gs,repaintOverlay:Le,validateCommit:vl});Dt.current=Fe.isEditing,il.current=Fe.requestCommit,cl.current=Fe.startEdit,Ro.current=Fe.getPointing,Ys.current=Fe.insertReference,Us.current=Fe.captureSink,Xs.current=Fe.restoreSink;const Sl=i.useCallback(()=>{Fe.cancelEdit(),Zn()},[Fe.cancelEdit,Zn]),tr=eg({enabled:!ve,sinkRef:ke,adapter:oe,isEditing:Xe,getSelection:Lt,setSelection:We,commitPaste:cu,maxOperationCells:C,onOperationRejected:T,onCopyMultiRange:I,repaintOverlay:Le,isDragging:Mo,resize:{rowAxis:fe,colAxis:pe,resizeTracks:Do},pendingPasteOptionsRef:Zs,formats:j,onClipChange:Ee,onClipboardUnavailable:ue,onEditRejected:F,rejectReadOnly:Ln,onPasteResolved:Ne});ul.current=tr.getClip,dl.current=tr.discardClip,fl.current=tr.discardClipOnCommit,hl.current=tr.onAdapterSwitch,Eo.current=tr.paste;const nr=Tw({enabled:!ve,adapter:oe,popovers:le,sinkRef:ke,bodyRef:ce,handleRef:re,rowAxis:fe,colAxis:pe,zoomRef:ne,getActive:zo,isEditing:Xe,requestCommit:dt,focusSink:Mt,rearmSink:Qe,isDraggingAny:er,commitEdits:un,labels:it,onHyperlinkOpen:xe,anchors:So,repaintOverlay:Le,rejectReadOnly:Ln});Yt.current=nr,xr.current=nr.open,el.current=nr.hideTip;const Ru=i.useCallback(()=>{const w=Rt.current.active;return Ut(w),Tr(w)},[Ut,Tr]),No=gg({adapter:oe,trackResize:S&&!ve?et:void 0,getSelection:Lt,commitEdits:un,getActive:zo,isEditing:Xe,requestCommit:dt,cancelEdit:Sl,getSessionText:Fe.getSessionText,validateCommit:vl,insertAtCaret:Fe.insertAtCaret,refreshEditPaint:Fe.refreshPaint,maxOperationCells:C,onOperationRejected:T,colors:Xn,formats:j,getHighlight:()=>bo.current,setHighlight:nu,popovers:le,openPopover:w=>xr.current(w),onHyperlinkOpen:xe,onPasteSpecialRequest:Pe,paste:w=>Eo.current(w),rowAxis:fe,colAxis:pe,resizeTracks:Do,defaultRowHeight:s,defaultColumnWidth:l,now:Ue,announce:$n,formatCommandAnnouncement:E,formatResizeAnnouncement:d,keyboardCellRect:Ru,rejectReadOnly:Ln});nl.current=No,ko.current=No.executeCommand,tl.current=No.isCommandAvailable;const vu=i.useMemo(()=>({table:Vt,execute:w=>ko.current(w),isAvailable:w=>tl.current(w)}),[Vt]),Su=i.useCallback(()=>{vt(),x?.()},[vt,x]),ku=i.useCallback(()=>{vt(),z?.()},[vt,z]);mw({zoomRef:ne,enabled:!ve,sinkRef:ke,rootRef:X,handOffFocusToRoot:ru,getSelection:Lt,setSelection:We,moveActive:su,ensureCellVisible:Ut,pageExtent:ou,isEditing:Xe,requestCommit:dt,startEdit:Qn,commitEdits:un,maxOperationCells:C,onOperationRejected:T,rejectReadOnly:Ln,getClip:$r,discardClip:vt,isDragging:er,abortDrag:yu,findDataEdge:oe.findDataEdge,getEditingMode:Fe.getEditingMode,cancelEdit:Sl,onUndoRequest:Su,onRedoRequest:ku,onCellContextMenu:k,rowAxis:fe,colAxis:pe,handleRef:re,rearmSink:Qe,commands:vu,pointing:Fe,adapter:oe,hideNoteTip:()=>el.current(),closeRejectedMessage:Zn,pendingPasteOptionsRef:Zs,onPointFrame:du});const Eu=En.active.row,Au=En.active.col;i.useLayoutEffect(()=>{const w=Yt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[Eu,Au]),i.useLayoutEffect(()=>{Le()},[Le,An.row,An.column,An.intersection]);const Ou=i.useCallback(w=>{(Dt.current?.()??!1)||(w.preventDefault(),qe(),Qe())},[qe,Qe]),xu=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget,Q=P!==null&&!P.matches(":focus-visible");if(P!==null&&Z instanceof Node&&P.contains(Z)){w.target===P&&Z===ke.current&&!Ao.current&&Mt({preventScroll:Q});return}(Dt.current?.()??!1)||(Mt({preventScroll:Q}),Qe())},[Mt,Qe]),Tu=i.useCallback(w=>{const P=X.current,Z=w.relatedTarget;P!==null&&Z instanceof Node&&P.contains(Z)||Fe.isFocusoutSuppressed()||$o(!1)},[Fe]),Dr=i.useRef(null),rr=i.useCallback(()=>{const w=Dr.current;w!==null&&(Dr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Fo=i.useCallback(()=>{if(Dr.current!==null)return;const w=Z=>{Z.pointerType==="mouse"&&(rr(),Z.button===1&&Z.preventDefault())},P=Z=>{Z.pointerType==="mouse"&&rr()};Dr.current={up:w,cancel:P},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",P,!0)},[rr]);i.useEffect(()=>rr,[rr]),i.useEffect(()=>{const w=X.current;if(ve||w===null)return;let P=0;const Z=be=>{if(be.pointerType!=="mouse"){(Dt.current?.()??!1)||$o(!1);return}P=be.buttons,be.button===1&&(be.target===ke.current&&(Dt.current?.()??!1)||Fo())},Q=be=>{be.pointerType==="mouse"&&(P=be.buttons)},de=be=>{if(be.pointerType!=="mouse"||be.buttons===P)return;const Ke=be.buttons&~P;P=be.buttons,be.preventDefault(),(Ke&4)!==0&&Fo()};return w.addEventListener("pointerdown",Z,!0),w.addEventListener("pointerup",Q,!0),w.addEventListener("pointermove",de,!0),()=>{w.removeEventListener("pointerdown",Z,!0),w.removeEventListener("pointerup",Q,!0),w.removeEventListener("pointermove",de,!0)}},[ve,Fo]);const $u=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(cn()){qe();return}if(Xe()&&!dt()){qe();return}qe()}},[qe,Xe,dt,cn]),Po=i.useRef(!1);i.useLayoutEffect(()=>{if(ve){Po.current=!1;return}if(Po.current)return;Po.current=!0,Qe();const w=(X.current?.clientHeight??0)/ne.current;w>0&&fe.totalSize()>0&&Ae.setRowRange(0,fe.indexAt(Math.min(w-1,fe.totalSize()-1)));const P=(X.current?.clientWidth??0)/ne.current;P>0&&pe.totalSize()>0&&Ae.setColRange(0,pe.indexAt(Math.min(P-1,pe.totalSize()-1)))},[ve,Qe,Ae,fe,pe]);const kl=i.useRef(t);i.useLayoutEffect(()=>{kl.current!==t&&(kl.current=t,ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag(),Fe.cancelEdit(),Yt.current?.hideTip(),Yt.current?.close(),ve?(Rt.current=Nn,Co(Nn)):We(Nn),hl.current())},[t,ve,We,ft,St,kt,et,pt,nt,Ae,Fe.cancelEdit]);const El=i.useRef({adapter:oe,rows:fe.count,cols:pe.count}),{getSessionCell:Al,cancelEdit:Ol}=Fe;i.useLayoutEffect(()=>{const w=El.current,P=fe.count,Z=pe.count;if(El.current={adapter:oe,rows:P,cols:Z},w.adapter!==oe||P>=w.rows&&Z>=w.cols)return;ve?(Rt.current=Nn,Co(Nn)):We(sw(Rt.current,P,Z)),ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag();const Q=tt=>ve||tt.row>=P||tt.col>=Z,de=Al();de!==null&&Q(de)&&Ol();const be=So.current;if(be.tip!==null&&Q(be.tip)&&Yt.current?.hideTip(),be.interactive!==null&&Q(be.interactive)){const tt=X.current?.contains(document.activeElement)===!0;Yt.current?.close({restoreFocus:tt})}const Ke=$r();Ke!==null&&!Ke.foreign&&Q({row:Ke.range.endRow,col:Ke.range.endCol})&&vt()},[oe,fe.count,pe.count,ve,We,ft,St,kt,et,pt,nt,Al,Ol,$r,vt]);const xl=i.useRef(c),Tl=i.useRef(u),$l=i.useRef(h),Ll=i.useRef(m);i.useLayoutEffect(()=>{(xl.current!==c||Tl.current!==u||$l.current!==h||Ll.current!==m)&&(xl.current=c,Tl.current=u,$l.current=h,Ll.current=m,ft.cancelDrag(),St.cancelDrag(),kt.cancelDrag(),et.cancelDrag(),pt.cancelDrag(),nt.cancelDrag())},[c,u,h,m,ft,St,kt,et,pt,nt]),i.useLayoutEffect(()=>{at(),ut(),Le()},[c,u,h,m,at,ut,Le]);const Dl=i.useRef(p);i.useLayoutEffect(()=>{Dl.current!==p&&(Dl.current=p,vt())},[p,vt]),i.useLayoutEffect(()=>{Le()},[Le,En]);const dn=i.useCallback(()=>{const w=nl.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(yn,()=>({resizeRow:(w,P)=>{const Z=Math.round(P);fe.resize(w,Z),re.current?.updateRowSize(w,Z),Ae.bumpRowGeometry(),at(),Le(),xn(),zt()},resizeColumn:(w,P)=>{const Z=Math.round(P);pe.resize(w,Z),re.current?.updateColSize(w,Z),Ae.bumpColVersion(),ut(),Le(),xn(),zt()},autoFitColumns:w=>{for(const P of w)if(!Number.isInteger(P)||P<0||P>=pe.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${pe.count-1} (got ${String(P)})`);return et.autofitColumnsInAllRows(w)},scrollToCell:(w,P)=>{re.current?.scrollToCell(w.row,w.col,P)},focus:w=>{Mt(w),Xe()||Qe()},executeCommand:w=>ko.current(w),applyFormat:w=>dn().applyFormat(w),setBorders:(w,P)=>dn().setBorders(w,P),setHyperlink:w=>dn().setHyperlink(w),setNote:w=>dn().setNote(w),addComment:w=>dn().addComment(w),setValidation:w=>dn().setValidation(w),paste:w=>Eo.current(w),getSelection:()=>Rt.current,getBaseFormat:w=>oe.getCellFormat===void 0?void 0:oe.getCellFormat(w.row,w.col),getPaintedFormat:w=>oe.getCellFormat===void 0?void 0:B(w.row,w.col,Qr(oe,w.row,w.col)),startEdit:w=>{Qn(w)},openPopover:w=>{xr.current(w)}}),[fe,pe,Ae,ut,at,Le,xn,zt,et,Mt,Xe,Qe,oe,B,Qn,dn]),ve)return Y.jsx("div",{className:wt?`aqsp-root ${wt}`:"aqsp-root","data-aqsp-empty":"","data-testid":He});const Lu=a!==void 0||f!==void 0||E!==void 0||g!==void 0||d!==void 0,Du=o===void 0?{"aria-label":it.rootAriaLabel}:{"aria-labelledby":o};return Y.jsxs("div",{ref:X,className:wt?`aqsp-root ${wt}`:"aqsp-root",role:"group",...Du,tabIndex:0,onFocus:xu,onBlur:Tu,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-testid":He,children:[Y.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":se,onPointerDown:$u,style:se===1?void 0:{width:`${100/se}%`,height:`${100/se}%`,transform:`scale(${se})`,"--_aqsp-zoom":String(se)},children:[b?Y.jsxs(Y.Fragment,{children:[Y.jsx("div",{ref:Ce,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(cn()){qe();return}if(Xe()&&!dt()){qe();return}qe(),We({ranges:[Re({row:0,col:0},{row:oe.rowCount-1,col:oe.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),Y.jsx(Qg,{viewStore:Ae,colAxis:pe,frozenCols:c,frozenTrailingCols:h,handleRef:re,bandRef:Tt,colTrackRef:ct,windowOriginXRef:bt,repaintColHeaders:ut,selectionRanges:En.ranges,enableResizeUI:S,dividerLeadingRef:Kt,dividerTrailingRef:yt}),Y.jsx(ew,{viewStore:Ae,rowAxis:fe,handleRef:re,bandRef:$t,selectionRanges:En.ranges,rowTrackRef:Me,windowOriginYRef:Ct,repaintHeaders:at,enableResizeUI:S,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:Sn,dividerTrailingRef:kn})]}):null,Y.jsxs("div",{ref:ge,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[Y.jsx(Jg,{adapter:oe,rowAxis:fe,colAxis:pe,viewStore:Ae,handleRef:re,bodyRef:ce,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:m,headerRows:n,labelledBy:o,gridLabel:o===void 0?it.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:R,overscanRows:Gi("overscanRows",N),overscanCols:Gi("overscanCols",H),background:L,onRenderTruncated:_,renderCell:U,onScroll:au,onRangeChange:uu,focusSink:qe,isEditing:Xe,requestCommit:dt,testId:He?`${He}-vs`:void 0,__onCellRender:bn,__maxRenderedCells:Er,cfIndexRef:Gn,cfMemoRef:M,isPointing:cn,locale:Bt,scrollLabels:Rn}),Y.jsx(xm,{rowAxis:fe,colAxis:pe,handleRef:re,sinkRef:ke,getSelection:Lt,editing:Fe.editing,virtualKeyboard:lu,repaintRef:Ks,dragFrameRef:yo,getClip:$r,getIsDraggingAny:er,getIsFillDragging:pt.isDragging,fillFrameRef:wl,resizeGuideFrameRef:Cl,fillHandleNodeRef:bl,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:m,sinkAriaLabel:it.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:Ar,onSinkMouseDown:Ou,editPaintRef:Gs,highlightRef:bo,highlightColors:tu,popoverAnchors:So,interactiveAnchorRef:Js,tipAnchorRef:Qs}),nr.layerEnabled?Y.jsx(Aw,{controller:nr,labels:it,renderPopover:me,interactiveAnchorRef:Js,tipAnchorRef:Qs}):null]}),Lu?Y.jsx("div",{ref:Bs,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),Y.jsx("div",{ref:he,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=qt.iterateTsvPrefixRows;exports.iterateTsvRows=qt.iterateTsvRows;exports.measureTsv=qt.measureTsv;exports.parseTsv=qt.parseTsv;exports.serializeClipboardTsv=qt.serializeClipboardTsv;exports.serializeTsv=qt.serializeTsv;exports.columnIndexToName=Te.columnIndexToName;exports.columnNameToIndex=Te.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Ss;exports.CommentPopover=Aa;exports.DEFAULT_CUSTOM_COLORS=Ja;exports.DEFAULT_HIGHLIGHT_COLORS=ka;exports.DEFAULT_SHORTCUTS=ua;exports.LinkPopover=Oa;exports.ListPopover=xa;exports.MessagePopover=Ta;exports.NotePopover=$a;exports.NoteTip=La;exports.SPREADSHEET_LABEL_CATALOGS=da;exports.SPREADSHEET_RESERVED_SHORTCUTS=Lh;exports.Spreadsheet=Kw;exports.canonicalizeFormat=gt;exports.detectClipSource=ac;exports.enumerateRangeCells=Jt;exports.estimatePasteCellCount=Ch;exports.expandPaste=bh;exports.formatCellValue=Wn;exports.formatEquals=Wu;exports.fromR1C1=Rr;exports.makeRange=Re;exports.mergeFormat=Es;exports.normalizeHyperlink=sn;exports.parseChord=Qt;exports.parseClipPayload=ls;exports.parseHtmlTable=ea;exports.rangeContains=Cn;exports.rangeSize=st;exports.resolveLabel=ze;exports.resolveLabels=fa;exports.serializeClipPayload=lc;exports.serializeHtmlTable=Gc;exports.shiftFormula=Mc;exports.toR1C1=uo;exports.validateCellText=ma;
|
|
12
|
+
`)},mh=(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)}vs(t,ha(e,r))},gh=(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"?ca(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<di.length?di[l]:null}return null},ma=(e,t,n)=>t!==void 0&&ua(t)?kp(e,t,n):e,wh=(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!==""&&wt(c)!==null)if(n!==void 0&&n.type==="date"){const u=ca(Number(c));if(u!==null)return u}else return c;return ma(t,n,r)},Ch=(e,t,n,r)=>{const o=ha(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:ch(o)};for(const m of vh(e))fh(m,l);ph(l,o,s,r.rules);const c=hh(l.text,l.mode),u=uh(o,s,r.kind),h={t:""};if(r.kind==="sheets"){const m=e.getAttribute("data-sheets-numberformat"),R=m===null?void 0:wp(m,r.options);R!==void 0&&(u.value=R);const N=e.getAttribute("data-sheets-value"),W=N===null?null:gh(N,R);h.t=W===null?ma(c,R,oa):W;const z=e.getAttribute("data-sheets-formula");z?.startsWith("=")&&(h.f=z);const I=e.getAttribute("data-sheets-hyperlink"),X=I!==null?I:l.href,Y=X===null?null:an(X);Y!==null&&(h.link=Y);const O=e.getAttribute("data-sheets-note");O!==null&&O!==""&&(h.note=O)}else{const m=o.get("mso-number-format"),R=m===void 0?void 0:Bs(Rs(po(m)),r.options);R!==void 0&&(u.value=R),h.t=wh(e,c,R,r.separators);const N=e.getAttribute("x:fmla");N?.startsWith("=")&&(h.f=yo(N,{row:t,col:n}));const W=l.href===null?null:an(l.href);W!==null&&(h.link=W)}return{cell:h,format:u}},Ss=(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},bh=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)},yh=(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]))},ga=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:vo(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:bh(l);if(c!==null)return Math.min(c,cn)}const o=yh(e,t);return o===null?null:Math.min(o,cn)},Rh=(e,t)=>{const n=[],r=o=>{const s=ga(o,"width");for(let l=Ss(o,"span",Ps);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Er(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Er(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Er(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*vh(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Sh(e){for(const t of["thead","tbody","tfoot"])for(const n of Er(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Er(n))o.localName==="tr"&&(yield o)}}const ts=()=>({t:""}),kh=(e,t,n)=>{const r=Mc(),o=[],s=[],l=[];let c=0;for(const W of Sh(e)){const z=o.length,I=(z+1)*Math.max(c,1);if(I>n)return{outcome:"limit",cells:I};const X=[];for(let O=0;O<l.length;O+=1)l[O]>0&&(X[O]=ts(),l[O]-=1);let Y=0;for(const O of Er(W)){const T=O.localName;if(T!=="td"&&T!=="th")continue;for(;X[Y]!==void 0;)Y+=1;const F=Ss(O,"colspan",Ps),H=Ss(O,"rowspan",Ac),$=(z+1)*Math.max(c,Y+F);if($>n)return{outcome:"limit",cells:$};const _=Ch(O,z,Y,t),x=r.intern(_.format);x!==void 0&&(_.cell.fmt=x),X[Y]=_.cell;for(let g=1;g<F;g+=1)X[Y+g]===void 0&&(X[Y+g]=ts());if(H>1)for(let g=0;g<F;g+=1){const p=H-1,C=Y+g;l[C]=l[C]===void 0||l[C]<p?p:l[C]}Y+=F}X.length>c&&(c=X.length),o.push(X),s.push(ga(W,"height"))}if(o.length===0||c===0)return{outcome:"none"};const u=o.map(W=>{const z=[];for(let I=0;I<c;I+=1){const X=W[I];z.push(X===void 0?ts():X)}return z}),h=Rh(e,c),m=h.length===c&&h.every(W=>W!==null)?h.map(W=>W===null?0:W):void 0,R=s.every(W=>W!==null)?s.map(W=>W===null?0:W):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:Ns(),formats:[...r.entries],validations:[],cells:u,...m===void 0?{}:{colWidths:m},...R===void 0?{}:{rowHeights:R},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},wa=(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=_p(o);return kh(s,{kind:t,rules:l,options:n,separators:l.separators},r)},ve=(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)}),On=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,Ct=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),Mt=e=>e.reduce((t,n)=>t+Ct(n).rows*Ct(n).cols,0),tn=(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}))}},un=(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)}},Yt=(e,t)=>e.row===t.row&&e.col===t.col,Ca=(e,t)=>e===void 0?Bl(void 0,void 0,t()):Bl(e.align,e.value,e.align===void 0?t():""),co=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},Jn=(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}},ao=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}),ba=e=>e.isCellReadOnly!==void 0,Qe=(e,t,n)=>e.isCellReadOnly?.(t,n)===!0,Eh=["rowCount","colCount","getCellText","applyEdits","findDataEdge","getCellFormat","getCellFormula","getCellNote","getCellComments","getCellHyperlink","getCellValidation","getConditionalFormats","isCellReadOnly","getCellAttributes","getRangeExtrema","evaluateFormula"],Oh=()=>!0,Ah=e=>{const t=new WeakMap,n={};for(const r of Eh)r!=="isCellReadOnly"&&Object.defineProperty(n,r,{enumerable:!0,get:()=>{const o=Reflect.get(e,r,e);if(typeof o!="function")return o;const s=t.get(o);if(s!==void 0)return s;const l=o.bind(e);return t.set(o,l),l}});return Object.defineProperty(n,"isCellReadOnly",{enumerable:!0,value:Oh}),n},xh=/^data-[a-z0-9-]+$/,Th=e=>{if(typeof e!="object"||e===null||Array.isArray(e))return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},$h=(e,t,n)=>{if(e.getCellAttributes===void 0)return null;const r=e.getCellAttributes(t,n);if(r===null)return null;if(!Th(r))throw new RangeError(`[spreadsheet] getCellAttributes must return a plain data-* record or null (got ${Object.prototype.toString.call(r)})`);for(const[o,s]of Object.entries(r)){if(!xh.test(o))throw new RangeError(`[spreadsheet] getCellAttributes key must be a lowercase data-* name (got ${JSON.stringify(o)})`);if(o.startsWith("data-aqsp")||o.startsWith("data-aqvs")||o==="data-row"||o==="data-col")throw new RangeError(`[spreadsheet] getCellAttributes key ${JSON.stringify(o)} shadows a package- or engine-emitted cell attribute`);if(typeof s!="string")throw new RangeError(`[spreadsheet] getCellAttributes value for ${JSON.stringify(o)} must be a string (got ${typeof s})`)}return r},Cr=(e,t)=>{const n=e.isCellReadOnly;if(n===void 0)return!1;for(let r=t.startRow;r<=t.endRow;r+=1)for(let o=t.startCol;o<=t.endCol;o+=1)if(n(r,o))return!0;return!1},Wn=(e,t)=>{for(const n of t)if(Cr(e,n))return!0;return!1},Lh=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=Ct(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},ks=(e,t,n,r,o)=>{if(e.rows===0||e.cols===0)return null;const s=Ct(t),l=s.rows===1&&s.cols===1,c=!l&&s.rows%e.rows===0&&s.cols%e.cols===0,u=c?s.rows:e.rows,h=c?s.cols:e.cols,m=l?n:{row:t.startRow,col:t.startCol},R=Math.min(u,r-m.row),N=Math.min(h,o-m.col);return R<=0||N<=0?null:ve(m,{row:m.row+R-1,col:m.col+N-1})},ya=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0,u=ks({rows:l,cols:c},t,n,r,o);if(u===null)return[];const h={row:u.startRow,col:u.startCol},m=u.endRow-u.startRow+1,R=u.endCol-u.startCol+1,N=[];for(let W=0;W<m;W+=l){const z=[];for(let X=0;X<R;X+=c){const Y={row:h.row+W,col:h.col+X};z.push(Y),N.push(Y)}const I=Math.min(l,m-W);for(let X=0;X<I;X+=1){const Y=h.row+W+X,O=e[X];for(let T=0;T<z.length;T+=1){const F=T*c,H=Math.min(c,R-F);for(let $=0;$<H;$+=1)s(Y,h.col+F+$,O[$],z[T])}}}return N},Dh=(e,t,n,r,o)=>{const s=[];return ya(e,t,n,r,o,(l,c,u)=>{s.push({row:l,col:c,text:u})}),s},hi=(e,t,n,r,o,s)=>{const l=[],c=ya(e,t,n,r,o,(u,h,m,R)=>{const N=s(m,u,h,R);N!==null&&l.push({...N,row:u,col:h})});return{edits:l,tiles:c}},Ra=(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)})`)},zh=(e,t)=>{Ra(e,t);const n=Ct(t),r=Ct(e),o=n.rows-r.rows,s=n.cols-r.cols,l=s>0?r.rows:Math.min(r.rows,o),c=o>0?r.cols:Math.min(r.cols,s);return n.rows*n.cols-r.rows*r.cols+l*c},Mh=(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(ve({row:t.startRow,col:t.startCol},{row:e.startRow-1,col:t.endCol})),t.endRow>e.endRow&&r.push(ve({row:e.endRow+1,col:t.startCol},{row:t.endRow,col:t.endCol})),t.startCol<e.startCol&&r.push(ve({row:e.startRow,col:t.startCol},{row:e.endRow,col:e.startCol-1})),t.endCol>e.endCol&&r.push(ve({row:e.startRow,col:e.endCol+1},{row:e.endRow,col:t.endCol})),r},Nh=(e,t,n,r)=>{Ra(t,n);const o=Ct(t).rows,s=Ct(t).cols,l=[],c=new Map;for(let u=n.startRow;u<=n.endRow;u+=1){const h=t.startRow+((u-t.startRow)%o+o)%o,m=u>=t.startRow&&u<=t.endRow;for(let R=n.startCol;R<=n.endCol;R+=1){if(m&&R>=t.startCol&&R<=t.endCol)continue;const N=t.startCol+((R-t.startCol)%s+s)%s,W=h*2**21+N;let z=c.get(W);z===void 0&&(z={value:e(h,N),origin:{row:h,col:N}},c.set(W,z)),l.push(r(z.value,z.origin,{row:u,col:R}))}}return l},va=(e,t,n)=>{const r=Jn(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:xt(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=Qn(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},Sa=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Gc(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},So=["bold","italic","underline","strikethrough","clearFormatting","alignLeft","alignCenter","alignRight","formatNumber","formatTime","formatDate","formatCurrency","formatPercent","formatScientific","bordersOuter","bordersClear","borderTop","borderRight","borderBottom","borderLeft","insertLink","insertNote","insertComment","openHyperlink","openValidationList","pasteSpecial","fillDown","fillRight","fillSelection","insertDate","insertTime","hideRows","hideColumns","unhideRows","unhideColumns","increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth","formatGeneral","bordersAll","pasteFormats","pasteFormulas","pasteAdd","pasteSubtract","pasteMultiply","pasteDivide","multiplyBy100","multiplyBy1000","divideBy100","divideBy1000","signReversal","fillColorYellow","fillColorBlue","fillColorGreen","fillColorRed","fillColorCustom1","fillColorCustom2","fillColorCustom3","fillColorCustom4","fillColorCustom5","fontColorYellow","fontColorBlue","fontColorGreen","fontColorRed","fontColorCustom1","fontColorCustom2","fontColorCustom3","fontColorCustom4","fontColorCustom5","toggleRowHighlight","toggleColumnHighlight","toggleBothHighlight","toggleIntersectionHighlight"],Fh=/^[A-Z]$/,Ph=/^[A-Za-z]$/,_h=/^Key([A-Z])$/,ka=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"]),qh=e=>Fh.test(e)||ka.has(e),nn=e=>{const t=e.split("+");let n=0;const r=t[n]==="Ctrl";r&&(n+=1);const o=t[n]==="Alt";o&&(n+=1);const s=t[n]==="Shift";s&&(n+=1);const l=t[n];if(n!==t.length-1||l===void 0||!qh(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}},Ih=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,Ea=e=>{if(Ph.test(e.key))return e.key.toUpperCase();const t=_h.exec(e.code);return t!==null?t[1]:ka.has(e.code)?e.code:null},fr=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:Ea(t)===e.key,we=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),Re=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),jh=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(we(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(we(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(we(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(we(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},Hh=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(we(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(we(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},$r=[...jh(),we("Home","idle","row start (first visible column)"),we("Ctrl+Home","idle","first visible cell"),we("Shift+Home","idle","extend to row start"),we("Ctrl+Shift+Home","idle","extend to first visible cell"),we("End","idle","row end (last visible column)"),we("Ctrl+End","idle","last visible cell"),we("Shift+End","idle","extend to row end"),we("Ctrl+Shift+End","idle","extend to last visible cell"),we("PageUp","both","page up (idle) / commit + page up (editing)"),we("PageDown","both","page down (idle) / commit + page down (editing)"),we("Shift+PageUp","idle","extend one page up"),we("Shift+PageDown","idle","extend one page down"),we("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),we("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),we("Tab","both","cycle right (idle) / commit + cycle right (editing)"),we("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),we("Enter","both","cycle down (idle) / commit + cycle down (editing)"),we("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),we("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),we("F2","both","start editing (idle) / toggle the pointing arm (editing)"),we("F4","editing","cycle the reference anchor under the caret (formula session)"),we("Delete","idle","clear every selected cell"),we("Backspace","idle","clear every selected cell"),we("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),we("Ctrl+A","idle","select all"),we("Ctrl+Z","idle","undo request"),we("Ctrl+Y","idle","redo request"),we("Ctrl+Shift+Z","idle","redo request"),we("Shift+F10","idle","keyboard context menu"),we("ContextMenu","idle","keyboard context menu"),we("Ctrl+Space","idle","column bands"),we("Shift+Space","idle","row bands"),we("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),we("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),we("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),we("Ctrl+Shift+V","idle","pasteValues: arms the paste options, the native paste follows (not a command)"),{chord:"Ctrl+Alt+V",column:"idle",rebindable:!1,command:"pasteSpecial",note:"paste special (onPasteSpecialRequest / formats-only branch) — a command row that cannot be rebound"},...Hh(),Re("bold","Ctrl+B","both","toggle bold"),Re("italic","Ctrl+I","both","toggle italic"),Re("underline","Ctrl+U","both","toggle underline"),Re("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),Re("clearFormatting","Ctrl+Backslash","idle","clear formatting"),Re("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),Re("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),Re("alignLeft","Ctrl+Shift+L","both","align left"),Re("alignCenter","Ctrl+Shift+E","both","align center"),Re("alignRight","Ctrl+Shift+R","both","align right"),Re("formatNumber","Ctrl+Shift+Digit1","both","number format"),Re("formatTime","Ctrl+Shift+Digit2","both","time format"),Re("formatDate","Ctrl+Shift+Digit3","both","date format"),Re("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),Re("formatPercent","Ctrl+Shift+Digit5","both","percent format"),Re("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),Re("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),Re("bordersClear","Alt+Shift+Digit6","idle","clear borders"),Re("borderTop","Alt+Shift+Digit1","idle","top border"),Re("borderRight","Alt+Shift+Digit2","idle","right border"),Re("borderBottom","Alt+Shift+Digit3","idle","bottom border"),Re("borderLeft","Alt+Shift+Digit4","idle","left border"),Re("insertLink","Ctrl+K","idle","insert / edit hyperlink"),Re("insertNote","Shift+F2","idle","insert / edit note"),Re("insertComment","Ctrl+Alt+M","idle","insert comment"),Re("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),Re("openValidationList","Alt+ArrowDown","idle","open the validation list"),Re("fillDown","Ctrl+D","idle","fill down"),Re("fillRight","Ctrl+R","idle","fill right"),Re("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),Re("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),Re("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),Re("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),Re("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),Re("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns"),Re("increaseColumnWidth","Alt+Shift+ArrowRight","idle","widen the active column by one step (x 2^(1/4))"),Re("decreaseColumnWidth","Alt+Shift+ArrowLeft","idle","narrow the active column by one step (/ 2^(1/4), never below 1 px)"),Re("increaseRowHeight","Alt+Shift+ArrowDown","idle","make the active row taller by one step (x 2^(1/4))"),Re("decreaseRowHeight","Alt+Shift+ArrowUp","idle","make the active row shorter by one step (/ 2^(1/4), never below 1 px)"),Re("autoFitColumnWidth","Alt+Shift+Equal","idle","fit the active column to its content (the strip double-click)")],ns=Object.freeze(["increaseColumnWidth","decreaseColumnWidth","increaseRowHeight","decreaseRowHeight","autoFitColumnWidth"]),mi=Object.freeze({Equal:"=",Minus:"-",Semicolon:";",Quote:"'",Comma:",",Period:".",Slash:"/",Backslash:"\\",BracketLeft:"[",BracketRight:"]",Backquote:"`",NumpadAdd:"+",NumpadSubtract:"-",NumpadMultiply:"*",NumpadDivide:"/",NumpadDecimal:".",NumpadEnter:"Enter"}),Bh=e=>{const t=nn(e);if(t.key==="IntlYen"||t.key==="IntlRo"||t.key==="IntlBackslash")return null;const n=/^(?:Digit|Numpad)(\d)$/u.exec(t.key),r=n!==null?n[1]:t.key in mi?mi[t.key]:t.key;return`${t.ctrl?"Control+":""}${t.alt?"Alt+":""}${t.shift?"Shift+":""}${r}`},ho=(e,t)=>e.column==="both"||e.column===t,Wh=Array.from(new Set($r.filter(e=>!e.rebindable&&ho(e,"idle")).map(e=>e.chord))),Ys=new Set($r.filter(e=>e.command!==void 0&&ho(e,"editing")).map(e=>e.command)),Vh=new Set($r.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),Oa=e=>{const t={};for(const n of So)t[n]=e(n);return t},Aa=Oa(e=>$r.filter(t=>t.command===e).map(t=>t.chord)),Yh=e=>{const t=new Map;for(const n of So){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},Kh=e=>{const t=new Set(So);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(Vh.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`)}}}},Uh=(e,t)=>{const n=nn(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Ys.has(e);for(const o of $r)if(!(o.rebindable||o.command===e||o.chord!==t)&&(ho(o,"idle")||r&&ho(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},Xh=e=>{e!==void 0&&Kh(e);const t=Oa(r=>{const o=e===void 0?void 0:e[r];return o===void 0?Aa[r]:o===null?[]:o});for(const r of So)for(const o of t[r])Uh(r,o);const n=new Map;for(const[r,o]of Yh(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},gi=(e,t)=>{const n=Ea(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(Ih({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},Ks=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","noteViewerHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","popoverClose"],wi=[...lt.VIRTUAL_SCROLL_LABEL_KEYS,...Ks],Es=Object.freeze({en:Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",noteViewerHint:"Escape closes without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",popoverClose:"Close"}),ja:Object.freeze({sinkAriaLabel:"スプレッドシートのグリッド。Escape キーでグリッドの外へフォーカスを移動します。",rootAriaLabel:"スプレッドシート",noteTitle:"メモ",noteSave:"保存",noteEscapeHint:"Escape で保存して閉じます",noteRejectedHint:"メモは拒否されました。Ctrl+Enter で再試行、Escape で保存せずに閉じます",noteViewerHint:"Escape で保存せずに閉じます",commentTitle:"コメント",commentReply:"返信",commentPost:"投稿",commentCount:e=>`${e} 件のコメント`,linkTitle:"リンク",linkTextField:"表示テキスト",linkUrlField:"URL",linkOpen:"開く",linkSave:"保存",listTitle:"値を選択",listEmpty:"一致する値がありません",listMore:e=>`ほかに ${e} 件 — 入力して絞り込んでください`,messageTitle:"データの入力規則",popoverClose:"閉じる"})}),xa=Object.freeze({en:Object.freeze({...lt.VIRTUAL_SCROLL_LABEL_CATALOGS.en,...Es.en}),ja:Object.freeze({...lt.VIRTUAL_SCROLL_LABEL_CATALOGS.ja,...Es.ja})}),Sn=e=>typeof e=="string"?JSON.stringify(e):e===null?"null":typeof e,Ci=e=>e==="commentCount"||e==="listMore",Gh=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 ${Sn(t)}`);for(const n of Ks){const r=e[n];if(!(Ci(n)&&typeof r=="function")&&(typeof r!="string"||r.trim()==="")){const o=Ci(n)?"a non-blank string or a function":"a non-blank string";throw new RangeError(`[spreadsheet] labels.${n} must be ${o}; got ${Sn(r)}`)}}},Zh=e=>{const t={};let n=!1;for(const r of lt.VIRTUAL_SCROLL_LABEL_KEYS){const o=Object.hasOwn(e,r)?e[r]:void 0;o!==void 0&&(t[r]=o,n=!0)}return n?t:void 0},Jh=(e,t,n)=>{e[t]=n},Ta=(e,t)=>{const n=lt.resolveVirtualScrollLocale(e);if(t===void 0)return xa[n];if(t===null||typeof t!="object")throw new RangeError(`[spreadsheet] labels must be an object; got ${Sn(t)}`);const r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new RangeError(`[spreadsheet] labels must be a plain object (prototype Object.prototype or null); got ${Array.isArray(t)?"an array":"an object with a non-plain prototype"}`);for(const l of Object.keys(t))if(!wi.includes(l))throw new RangeError(`[spreadsheet] labels.${l} is not a known label key; expected one of ${wi.join(", ")}`);const s={...lt.resolveVirtualScrollLabels(n,Zh(t)),...Es[n]};for(const l of Ks){const c=Object.hasOwn(t,l)?t[l]:void 0;c!==void 0&&Jh(s,l,c)}return Gh(s),Object.freeze(s)},Qh=e=>{const t={};for(const n of lt.VIRTUAL_SCROLL_LABEL_KEYS)t[n]=e[n];return Object.freeze(t)},_e=(e,t,n)=>{const r=e[t];if(typeof r=="function"){if(n===void 0)throw new RangeError(`[spreadsheet] labels.${t} is count-aware; resolveLabel needs n`);return r(n)}return r},bi={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},em={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},tm=(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}`}},rs=(e,t)=>{const n=r=>(o,s)=>`${e} ${tm(r,o,s,t)}.`;return Object.freeze({gt:n("gt"),gte:n("gte"),lt:n("lt"),lte:n("lte"),eq:n("eq"),neq:n("neq"),between:n("between"),notBetween:n("notBetween")})},nm=Object.freeze({list:"Value must be one of the list items.",number:rs("Value must be a number",bi),textLength:rs("Text length must be",bi),date:rs("Value must be a date",em),text:Object.freeze({contains:e=>`Value must contain "${e}".`,notContains:e=>`Value must not contain "${e}".`,startsWith:e=>`Value must start with "${e}".`,endsWith:e=>`Value must end with "${e}".`,isEmail:"Value must be a valid email address.",isUrl:"Value must be a valid URL."}),checkbox:(e,t)=>`Value must be "${e}" or "${t}".`,custom:e=>`Value does not satisfy the formula ${e}.`}),rm=Object.freeze({list:"リストの項目のいずれかを入力してください。",number:Object.freeze({gt:e=>`${e} より大きい数値を入力してください。`,gte:e=>`${e} 以上の数値を入力してください。`,lt:e=>`${e} より小さい数値を入力してください。`,lte:e=>`${e} 以下の数値を入力してください。`,eq:e=>`${e} に等しい数値を入力してください。`,neq:e=>`${e} 以外の数値を入力してください。`,between:(e,t)=>`${e} から ${t} までの数値を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の数値を入力してください。`}),textLength:Object.freeze({gt:e=>`${e} 文字より長いテキストを入力してください。`,gte:e=>`${e} 文字以上のテキストを入力してください。`,lt:e=>`${e} 文字より短いテキストを入力してください。`,lte:e=>`${e} 文字以下のテキストを入力してください。`,eq:e=>`${e} 文字のテキストを入力してください。`,neq:e=>`${e} 文字以外の長さのテキストを入力してください。`,between:(e,t)=>`${e} 文字から ${t} 文字までのテキストを入力してください。`,notBetween:(e,t)=>`${e} 文字から ${t} 文字までの範囲外の長さのテキストを入力してください。`}),date:Object.freeze({gt:e=>`${e} より後の日付を入力してください。`,gte:e=>`${e} 以降の日付を入力してください。`,lt:e=>`${e} より前の日付を入力してください。`,lte:e=>`${e} 以前の日付を入力してください。`,eq:e=>`${e} の日付を入力してください。`,neq:e=>`${e} 以外の日付を入力してください。`,between:(e,t)=>`${e} から ${t} までの日付を入力してください。`,notBetween:(e,t)=>`${e} から ${t} までの範囲外の日付を入力してください。`}),text:Object.freeze({contains:e=>`「${e}」を含む値を入力してください。`,notContains:e=>`「${e}」を含まない値を入力してください。`,startsWith:e=>`「${e}」で始まる値を入力してください。`,endsWith:e=>`「${e}」で終わる値を入力してください。`,isEmail:"有効なメールアドレスを入力してください。",isUrl:"有効な URL を入力してください。"}),checkbox:(e,t)=>`「${e}」または「${t}」を入力してください。`,custom:e=>`数式 ${e} を満たす値を入力してください。`}),os=Object.freeze({en:nm,ja:rm}),om=Object.freeze({ok:!0}),sm="TRUE",lm="FALSE",im=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),cm=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),am=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,um=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,dm=/^[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])?)+$/,yi=e=>{const t=e.trim();if(!(am.test(t)&&Number.isFinite(Number(t))))return null;const n=t.startsWith("-"),r=t.replace(/^[+-]/,""),o=r.search(/[eE]/),s=o<0?r:r.slice(0,o),l=o<0?0:Number(r.slice(o+1)),c=s.indexOf("."),u=c<0?s:s.slice(0,c),h=c<0?"":s.slice(c+1),m=u+h,R=m.search(/[^0]/);return R<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:m.slice(R).replace(/0+$/,""),point:u.length+l-R}},fm=e=>e===1?-1:e===-1?1:0,pm=(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:fm(n)},hm=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Ri=e=>{const t=um.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>hm(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},mm=(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},gm=(e,t)=>e<t?-1:e>t?1:0,wm=e=>e==="between"||e==="notBetween",Cm=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!wm(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},bm=(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}},ss=(e,t,n,r,o,s)=>{const l=Cm(e,t,n,r);return l===null?!0:o===null?!1:bm(e,s(o,l.a),l.b===null?0:s(o,l.b))},ym=e=>Number.isFinite(e)?e:null,Rm=e=>{let t=0;for(const n of e)t+=1;return t},vm=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Sm=(e,t)=>{switch(e.op){case"isEmail":return dm.test(t);case"isUrl":return vm(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)}},km=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,$a=e=>({checked:e.checked===void 0?sm:e.checked,unchecked:e.unchecked===void 0?lm:e.unchecked}),Em=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!im.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Sn(e.op)} for type "${e.type}"`);return;case"text":if(!cm.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op ${Sn(e.op)} for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type ${Sn(e.type)}`)}},Om=(e,t,n)=>{switch(e.type){case"list":return Tm(e).has(t);case"number":return ss(e.op,e.a,e.b,yi,yi(t),pm);case"textLength":return ss(e.op,e.a,e.b,ym,Rm(t),gm);case"date":return ss(e.op,e.a,e.b,Ri,Ri(t),mm);case"text":return Sm(e,t);case"checkbox":{const r=$a(e);return t===r.checked||t===r.unchecked}default:return n===void 0||km(n(e.formula))}},La=(e,t,n)=>(Em(e),t===""||Om(e,t,n)),vi=e=>e===void 0?void 0:e.trim(),Am=(e,t)=>{switch(e.type){case"list":return t.list;case"number":return t.number[e.op](e.a.trim(),vi(e.b));case"textLength":return t.textLength[e.op](String(e.a),e.b===void 0?void 0:String(e.b));case"date":return t.date[e.op](e.a.trim(),vi(e.b));case"text":return xm(e,t.text);case"checkbox":{const n=$a(e);return t.checkbox(n.checked,n.unchecked)}default:return t.custom(e.formula)}},xm=(e,t)=>{switch(e.op){case"isEmail":return t.isEmail;case"isUrl":return t.isUrl;default:return t[e.op](e.value)}},Si=new WeakMap,Tm=e=>{const t=Si.get(e);if(t!==void 0)return t;const n=new Set(e.values);return Si.set(e,n),n},Da=(e,t,n,r)=>{if(typeof n!="string"||!Object.hasOwn(os,n)){const o=Object.keys(os).map(s=>JSON.stringify(s)).join(", ");throw new RangeError(`[spreadsheet] validateCellText locale must be one of ${o}; got ${Sn(n)}`)}return La(e,t,r)?om:{ok:!1,message:e.errorMessage===void 0?Am(e,os[n]):e.errorMessage}},$m=e=>e.type!=="custom",Lm=(e,t)=>$m(e)&&!La(e,t,void 0),za=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),Ma=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.totalSize()-e.offsetOf(e.count-t),Na=(e,t,{scroll:n,frozenCount:r,trailingCount:o,extent:s})=>t<r?e.offsetOf(t):o>0&&s>0&&t>=e.count-o?s-(e.totalSize()-e.offsetOf(t)):e.offsetOf(t)-n,Fa=(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),Pa=(e,t)=>za(e,t),_a=(e,t)=>za(e,t),qa=(e,t)=>Ma(e,t),Ia=(e,t)=>Ma(e,t),kn=(e,t,n)=>Na(e,t,n),En=(e,t,n)=>Na(e,t,n),Lr=(e,t,n)=>Fa(e,t,n),Dr=(e,t,n)=>Fa(e,t,n),Dm=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),zt=1,br=3,Kr=e=>`${-Math.min(br,Math.max(0,Math.floor(e)))}px`,zm=(e,t,n)=>{const r=Math.min(e.endRow,t-1),o=Math.min(e.endCol,n-1);return e.startRow>r||e.startCol>o?null:{startRow:e.startRow,startCol:e.startCol,endRow:r,endCol:o}},ki=(e,t,n,r)=>e==="m"?t:e==="s"?Math.max(0,t-n-r):null,Ei=(e,t)=>t===null?e:Math.min(e,t),Oi=e=>e===null?"100%":`min(100%, ${e}px)`,Ai=e=>e===null?"0px":`max(0px, calc(100% - ${e}px))`,xi=(e,t,n,r)=>{switch(e){case"f":return[0,n-1];case"s":return[n,t-r-1];case"t":return[t-r,t-1];case"m":return[0,t-1]}},Ti=Object.freeze([0,-1]),$i=(e,t,n,r,o,s,l,c)=>{if(c<=0||o<r||n<r||t>o)return!1;const u=-c*zt,h=c*(1+zt),m=t>=r,R=n<=o,N=m?s:u,W=R?l:h;return W<=u||N>=h?!1:(e.near=Math.max(N,u),e.far=Math.min(W,h),e.nearOpen=!m||N<u,e.farOpen=!R||W>h,!0)},Ur=()=>({near:Number.NaN,far:Number.NaN,nearOpen:!1,farOpen:!1}),Li=(e,t)=>e.near===t.near&&e.far===t.far&&e.nearOpen===t.nearOpen&&e.farOpen===t.farOpen,Di=(e,t)=>{e.near=t.near,e.far=t.far,e.nearOpen=t.nearOpen,e.farOpen=t.farOpen},Mm=Object.freeze(["top","right","bottom","left"]),Nm=(e,t)=>(t.nearOpen?1:0)|(e.farOpen?2:0)|(t.farOpen?4:0)|(e.nearOpen?8:0),Fm=e=>Mm.filter((t,n)=>(e&1<<n)!==0).join(" "),ja=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),Pm=16,_m=450,qm=e=>e>4?Math.floor(_m/(5*e)):Pm,pr=(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},zi=()=>({rowLeft:pr("row","left"),rowRight:pr("row","right"),colAbove:pr("column","above"),colBelow:pr("column","below"),cross:pr("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1,rowLeftTransform:"",rowRightTransform:"",colAboveTransform:"",colBelowTransform:"",crossTransform:""}}),Os=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},Gr=(e,t)=>Math.min(Math.max(e,0),t),Mi="inset(100%)",Kn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Im=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,Kn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const N=`${t.height}px`;e.rowLeft.style.height=N,e.rowRight.style.height=N}const m=`translate(${Gr(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`;m!==s.rowLeftTransform&&(s.rowLeftTransform=m,e.rowLeft.style.transform=m);const R=`translate(${Gr(t.left+t.width,n.clampWidth)}px, ${t.top}px)`;R!==s.rowRightTransform&&(s.rowRightTransform=R,e.rowRight.style.transform=R)}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,Kn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const N=`${t.width}px`;e.colAbove.style.width=N,e.colBelow.style.width=N}const m=`translate(${t.left}px, ${Gr(t.top,n.clampHeight)-n.clampHeight}px)`;m!==s.colAboveTransform&&(s.colAboveTransform=m,e.colAbove.style.transform=m);const R=`translate(${t.left}px, ${Gr(t.top+t.height,n.clampHeight)}px)`;R!==s.colBelowTransform&&(s.colBelowTransform=R,e.colBelow.style.transform=R)}const u=r.intersection?"intersection":l!==c?l?"row":"column":null,h=u!==null;if(h!==s.crossShown&&(s.crossShown=h,Kn([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)}},Ni=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,Kn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,Kn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,Kn([e.cross],!1))},Zr=e=>{for(const t of Os(e))t.remove()},jm=(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)},Hm=Object.freeze([]),Fi=e=>e.farOpen?{start:`${e.near}px`,end:"0px",size:""}:{start:`${e.near}px`,end:"",size:`${e.far-e.near}px`},Pi=e=>e.chrome[0]??e.active,_i=e=>{e.chrome.length=0;for(const t of e.dividerSlots)t!==null&&e.chrome.push(t);e.frame!==null&&e.chrome.push(e.frame.node)},Bm={left:"0px",right:"0px",width:""},Wm={top:"0px",bottom:"0px",height:""},qi=()=>({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],dividerEnd:["0px","0px","0px","0px"],frame:null,bandClip:null,bandClipWidth:"",bandClipHeight:"",chrome:[]}),Ii=["mm","mf","ms","mt","fm","ff","fs","ft","sm","sf","ss","st","tm","tf","ts","tt"],ji=6,Vm=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:u,getClip:h,getIsDraggingAny:m,getIsFillDragging:R,fillFrameRef:N,resizeGuideFrameRef:W,fillHandleNodeRef:z,enableFillHandle:I,frozenCols:X,frozenRows:Y,trailingCols:O,trailingRows:T,sinkAriaLabel:F,sinkReadOnly:H,sinkKeyShortcuts:$,onSinkMouseDown:_,editPaintRef:x,highlightRef:g,frameRange:p,highlightColors:C,popoverAnchors:v,interactiveAnchorRef:k,tipAnchorRef:b})=>{const y=i.useRef(null),a=i.useRef(p);a.current=p;const f=p!==void 0,E=i.useRef(null),d=i.useRef(null),L=i.useRef(new Map(Ii.map(S=>[S,qi()]))),A=i.useCallback(S=>{const D=L.current.get(S);if(D!==void 0)return D;const V=qi();return L.current.set(S,V),V},[]),M=i.useCallback((S,D,V)=>{if(S===null)return;const P=S.style;P.left!==D.left&&(P.left=D.left),P.right!==D.right&&(P.right=D.right),P.width!==D.width&&(P.width=D.width),P.top!==V.top&&(P.top=V.top),P.bottom!==V.bottom&&(P.bottom=V.bottom),P.height!==V.height&&(P.height=V.height)},[]),B=i.useCallback((S,D,V)=>{if(!(S.bandClampWidth===D&&S.bandClampHeight===V)){S.bandClampWidth=D,S.bandClampHeight=V;for(const P of S.bandPool)Xr(P,D,V);S.dragBand!==null&&Xr(S.dragBand,D,V)}},[]),j=i.useRef({rowAxis:e,colAxis:t});j.current={rowAxis:e,colAxis:t};const G=i.useCallback((S,D,V)=>{const P=S.dividerSlots[D];P===null||S.dividerShown[D]===V||(S.dividerShown[D]=V,P.style.display=V?"":"none")},[]),Z=i.useCallback((S,D,V)=>{const P=S.bandClip;P!==null&&(S.bandClipWidth!==D&&(S.bandClipWidth=D,P.style.width=D),S.bandClipHeight!==V&&(S.bandClipHeight=V,P.style.height=V))},[]),Q=i.useCallback((S,D,V)=>{const P=S.dividerSlots[D];P===null||S.dividerEnd[D]===V||(S.dividerEnd[D]=V,D<2?P.style.bottom=V:P.style.right=V)},[]),ne=i.useRef({x:0,y:0}),ie=i.useRef(null),le=i.useCallback((S,D)=>{const V=n.current,P=V?.getFrozenSize()??Dm,U=V?.getViewportSize(),te=U?.width??-1,re=U?.height??-1,Ae=ne.current;Ae.x=S,Ae.y=D;const Ee=a.current!==void 0,Se=j.current,ue=Ee?Se.rowAxis.count:-1,Fe=Ee?Se.colAxis.count:-1,qe=Ee?Se.rowAxis.totalSize():-1,de=Ee?Se.colAxis.totalSize():-1;let se=ie.current;if(se===null||se.framed!==Ee||se.rowCount!==ue||se.colCount!==Fe||se.rowsTotal!==qe||se.colsTotal!==de||se.frozenCols!==P.cols||se.frozenWidth!==P.width||se.frozenRows!==P.rows||se.frozenHeight!==P.height||se.trailingCols!==P.trailingCols||se.trailingWidth!==P.trailingWidth||se.trailingVisibleWidth!==P.trailingVisibleWidth||se.trailingRows!==P.trailingRows||se.trailingHeight!==P.trailingHeight||se.trailingVisibleHeight!==P.trailingVisibleHeight||se.bodyWidth!==te||se.bodyHeight!==re){const ce=P.trailingVisibleWidth,xe=P.trailingVisibleHeight,tt=P.cols<=0&&P.trailingCols<=0?[{kind:"m",map:ke=>ke-Ae.x,clamp:te,style:Bm,seamLead:!1,seamTrail:!1}]:[...P.cols>0?[{kind:"f",map:ke=>ke,clamp:P.width,style:{left:"0px",width:`${P.width}px`,right:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ke=>ke-Ae.x-P.width,clamp:Math.max(0,te-P.width-ce),style:{left:`${P.width}px`,right:`${ce}px`,width:""},seamLead:P.cols>0,seamTrail:P.trailingCols>0},...P.trailingCols>0?[{kind:"t",map:ke=>ke-j.current.colAxis.totalSize()+ce,clamp:ce,style:{left:"",right:"0px",width:`${ce}px`},seamLead:!0,seamTrail:!1}]:[]],at=P.rows<=0&&P.trailingRows<=0?[{kind:"m",map:ke=>ke-Ae.y,clamp:re,style:Wm,seamLead:!1,seamTrail:!1}]:[...P.rows>0?[{kind:"f",map:ke=>ke,clamp:P.height,style:{top:"0px",height:`${P.height}px`,bottom:""},seamLead:!1,seamTrail:!0}]:[],{kind:"s",map:ke=>ke-Ae.y-P.height,clamp:Math.max(0,re-P.height-xe),style:{top:`${P.height}px`,bottom:`${xe}px`,height:""},seamLead:P.rows>0,seamTrail:P.trailingRows>0},...P.trailingRows>0?[{kind:"t",map:ke=>ke-j.current.rowAxis.totalSize()+xe,clamp:xe,style:{top:"",bottom:"0px",height:`${xe}px`},seamLead:!0,seamTrail:!1}]:[]],We=[];for(const ke of tt){const Ie=Ee?ki(ke.kind,de,P.width,P.trailingWidth):null,[Ge,Pt]=Ee?xi(ke.kind,Fe,P.cols,P.trailingCols):Ti;for(const nt of at){const ht=Ee?ki(nt.kind,qe,P.height,P.trailingHeight):null,[or,Ao]=Ee?xi(nt.kind,ue,P.rows,P.trailingRows):Ti;We.push({nodes:A(`${ke.kind}${nt.kind}`),xKind:ke.kind,yKind:nt.kind,mapX:ke.map,clampWidth:ke.clamp,xStyle:ke.style,xSeamLead:ke.seamLead,xSeamTrail:ke.seamTrail,xFirst:Ge,xLast:Pt,mapY:nt.map,clampHeight:nt.clamp,yStyle:nt.style,ySeamLead:nt.seamLead,ySeamTrail:nt.seamTrail,yFirst:or,yLast:Ao,cells:{clampWidth:Ei(ke.clamp,Ie),clampHeight:Ei(nt.clamp,ht)},xCellsSizeCss:Oi(Ie),yCellsSizeCss:Oi(ht),xCellsEndCss:Ai(Ie),yCellsEndCss:Ai(ht)})}}se={frozenCols:P.cols,frozenWidth:P.width,frozenRows:P.rows,frozenHeight:P.height,trailingCols:P.trailingCols,trailingWidth:P.trailingWidth,trailingVisibleWidth:P.trailingVisibleWidth,trailingRows:P.trailingRows,trailingHeight:P.trailingHeight,trailingVisibleHeight:P.trailingVisibleHeight,bodyWidth:te,bodyHeight:re,framed:Ee,rowCount:ue,colCount:Fe,rowsTotal:qe,colsTotal:de,ctxs:We},ie.current=se}const be=P.width>0,ge=P.trailingWidth>0,he=P.height>0,Xe=P.trailingHeight>0;for(const ce of se.ctxs)M(ce.nodes.container,ce.xStyle,ce.yStyle),B(ce.nodes,ce.clampWidth,ce.clampHeight),G(ce.nodes,0,be),G(ce.nodes,1,ge),G(ce.nodes,2,he),G(ce.nodes,3,Xe),Q(ce.nodes,0,ce.yCellsEndCss),Q(ce.nodes,1,ce.yCellsEndCss),Q(ce.nodes,2,ce.xCellsEndCss),Q(ce.nodes,3,ce.xCellsEndCss),Z(ce.nodes,ce.xCellsSizeCss,ce.yCellsSizeCss);return se.ctxs},[n,A,M,B,G,Q,Z]),Oe=i.useCallback((S,D,V)=>{S.dividerSlots[D]=V,S.dividerShown[D]=!1,S.dividerEnd[D]="0px",_i(S)},[]),ze=i.useCallback((S,D)=>{S.frame=D===null?null:{node:D,x:Ur(),y:Ur(),drawnX:Ur(),drawnY:Ur(),last:{shown:!1,left:"",top:"",right:"",bottom:"",width:"",height:"",open:-1}},_i(S)},[]),Ne=i.useCallback((S,D)=>{for(const P of S.bandPool)Zr(P);S.bandPool.length=0,S.dragBand!==null&&(Zr(S.dragBand),S.dragBand=null),S.bandClampWidth=-1,S.bandClampHeight=-1,S.bandClip=D,S.bandClipWidth="",S.bandClipHeight="";const V=D===null?null:D.parentElement;D!==null&&V!==null&&V.firstChild!==D&&V.insertBefore(D,V.firstChild)},[]),He=i.useCallback(S=>{const D=()=>A(S);return{container:V=>{const P=D();P.container=V,V===null&&(P.fillPool.length=0,P.bandPool.length=0,P.dragBand=null,P.bandClampWidth=-1,P.bandClampHeight=-1)},dividerXLeading:V=>Oe(D(),0,V),dividerXTrailing:V=>Oe(D(),1,V),dividerYLeading:V=>Oe(D(),2,V),dividerYTrailing:V=>Oe(D(),3,V),frame:V=>ze(D(),V),bandClip:V=>Ne(D(),V),active:V=>{D().active=V},dragRect:V=>{D().dragRect=V},marquee:V=>{D().marquee=V},fillPreview:V=>{D().fillPreview=V},resizeGuide:V=>{D().resizeGuide=V}}},[A,Oe,ze,Ne]),me=i.useMemo(()=>Object.fromEntries(Ii.map(S=>[S,He(S)])),[He]),Me=Math.min(Math.max(0,X),t.count),it=Pa(t,Me),Be=Math.min(Math.max(0,Y),e.count),Nt=_a(e,Be),bt=O===void 0?0:Math.min(Math.max(0,O),t.count-Me),ct=qa(t,bt),et=T===void 0?0:Math.min(Math.max(0,T),e.count-Be),dn=Ia(e,et),er=i.useRef(null),tr=i.useRef("add"),An=i.useRef(s);An.current=s;const zr=i.useRef(!1),oe=lt.useWheelBridge(n,{enableBridge:!s}),Ce=i.useCallback(S=>(r.current=S,oe(S)),[r,oe]),fe=i.useCallback((S,D)=>({top:D.mapY(e.offsetOf(S.startRow)),bottom:D.mapY(e.offsetOf(S.endRow)+e.sizeOf(S.endRow)),left:D.mapX(t.offsetOf(S.startCol)),right:D.mapX(t.offsetOf(S.endCol)+t.sizeOf(S.endCol))}),[e,t]),pt=i.useCallback((S,D)=>{if(D.clampHeight<=0||D.clampWidth<=0)return null;const{top:V,bottom:P,left:U,right:te}=fe(S,D),re=-D.clampHeight*zt,Ae=D.clampHeight*(1+zt),Ee=-D.clampWidth*zt,Se=D.clampWidth*(1+zt);if(P<re||V>Ae||te<Ee||U>Se)return null;const ue=Math.max(V,re),Fe=Math.max(U,Ee);return{top:ue,left:Fe,width:Math.min(te,Se)-Fe,height:Math.min(P,Ae)-ue}},[fe]),Te=i.useCallback((S,D)=>{if(D.clampHeight<=0||D.clampWidth<=0)return null;const V=fe(S,D),P=-D.clampHeight*zt,U=D.clampHeight*(1+zt),te=-D.clampWidth*zt,re=D.clampWidth*(1+zt),Ae=Math.min(Math.max(V.top,P),U),Ee=Math.min(Math.max(V.left,te),re);return{top:Ae,left:Ee,width:Math.min(Math.max(V.right,te),re)-Ee,height:Math.min(Math.max(V.bottom,P),U)-Ae}},[fe]),Ut=i.useCallback(()=>{if(g===void 0)return null;const S=g.current;return S.row||S.column||S.intersection?S:null},[g]),yt=i.useCallback((S,D,V)=>{if(D.bandClip!==null){for(const U of Os(V))D.bandClip.appendChild(U);return}const P=D.fillPool[0]?.node??Pi(D);for(const U of Os(V))S.insertBefore(U,P)},[]),ko=i.useRef({range:void 0,rows:-1,cols:-1,within:null}),fn=i.useCallback(S=>{const D=S.nodes.frame;if(D===null)return;const V=ko.current,P=a.current;(V.range!==P||V.rows!==e.count||V.cols!==t.count)&&(V.range=P,V.rows=e.count,V.cols=t.count,V.within=P===void 0?null:zm(P,e.count,t.count));const U=V.within,te=D.last,re=D.node.style;if(!(U!==null&&$i(D.x,U.startCol,U.endCol,S.xFirst,S.xLast,S.mapX(t.offsetOf(U.startCol)),S.mapX(t.offsetOf(U.endCol)+t.sizeOf(U.endCol)),S.clampWidth)&&$i(D.y,U.startRow,U.endRow,S.yFirst,S.yLast,S.mapY(e.offsetOf(U.startRow)),S.mapY(e.offsetOf(U.endRow)+e.sizeOf(U.endRow)),S.clampHeight))){te.shown&&(te.shown=!1,re.display="none");return}if(te.shown||(te.shown=!0,re.display="block"),!Li(D.x,D.drawnX)){Di(D.drawnX,D.x);const Se=Fi(D.x);Se.start!==te.left&&(te.left=Se.start,re.left=Se.start),Se.end!==te.right&&(te.right=Se.end,re.right=Se.end),Se.size!==te.width&&(te.width=Se.size,re.width=Se.size)}if(!Li(D.y,D.drawnY)){Di(D.drawnY,D.y);const Se=Fi(D.y);Se.start!==te.top&&(te.top=Se.start,re.top=Se.start),Se.end!==te.bottom&&(te.bottom=Se.end,re.bottom=Se.end),Se.size!==te.height&&(te.height=Se.size,re.height=Se.size)}const Ee=Nm(D.x,D.y);Ee!==te.open&&(te.open=Ee,Ee===0?D.node.removeAttribute("data-aqsp-frame-open"):D.node.setAttribute("data-aqsp-frame-open",Fm(Ee)))},[e,t]),xn=i.useCallback((S,D,V,P)=>{const U=Te(D,V);if(U===null){Ni(S);return}Im(S,U,V,P,Nc(D,t.count)||Fc(D,e.count))},[Te,e,t]),Mr=i.useCallback((S,D,V,P)=>{const U=S.nodes.bandPool;for(;U.length>V.length;){const te=U.pop();te!==void 0&&Zr(te)}if(P===null){S.nodes.dragBand!==null&&(Zr(S.nodes.dragBand),S.nodes.dragBand=null);return}for(let te=0;te<V.length;te+=1){let re=U[te];re===void 0&&(re=zi(),Xr(re,S.clampWidth,S.clampHeight),yt(D,S.nodes,re),U.push(re)),xn(re,V[te],S,P)}},[yt,xn]),Tn=i.useCallback((S,D,V)=>{const P=S.nodes.container;if(P===null)return;if(D===null||V===null){S.nodes.dragBand!==null&&Ni(S.nodes.dragBand);return}let U=S.nodes.dragBand;U===null&&(U=zi(),Xr(U,S.clampWidth,S.clampHeight),yt(P,S.nodes,U),S.nodes.dragBand=U),xn(U,D,S,V)},[yt,xn]),Ft=i.useCallback((S,D)=>{if(S!==null){if(D===null){S.style.display="none";return}S.style.display="block",S.style.transform=`translate(${D.left}px, ${D.top}px)`,S.style.width=`${D.width}px`,S.style.height=`${D.height}px`}},[]),$n=i.useCallback((S,D,V,P)=>{const U=P==="point"?null:Ut();for(const te of le(V,D))Ft(te.nodes.dragRect,pt(S,te)),Tn(te,S,U)},[pt,le,Ft,Ut,Tn]),nr=i.useCallback((S,D,V)=>{for(const P of le(V,D))Ft(P.nodes.fillPreview,S===null?null:pt(S,P))},[pt,le,Ft]),Ln=i.useCallback((S,D,V)=>{for(const P of le(V,D)){const U=P.nodes.resizeGuide;if(U===null)continue;if(S===null){U.style.display="none";continue}const te=S.anchor==="trailing";if(S.axis==="col"){if(te&&P.xKind!=="t"){U.style.display="none";continue}U.style.display="block";const re=P.mapX(S.position);U.style.transform=`translate(${te?Math.max(0,re):re}px, 0px)`,U.style.width="1px",U.style.height="100%"}else{if(te&&P.yKind!=="t"){U.style.display="none";continue}U.style.display="block";const re=P.mapY(S.position);U.style.transform=`translate(0px, ${te?Math.max(0,re):re}px)`,U.style.width="100%",U.style.height="1px"}}},[le]),pn=i.useCallback((S,D,V,P,U,te,re)=>{if(S===null)return;if(D===null||re<=0||te<=0){S.style.clipPath=Mi;return}const Ae=En(e,D.row,P),Ee=kn(t,D.col,V),Se=t.sizeOf(D.col),ue=e.sizeOf(D.row),Fe=Ee>=te||Ae>=re,qe=D.col>=U.cols&&Ee<U.width,de=D.row>=U.rows&&Ae<U.height,se=U.trailingWidth>0&&D.col<t.count-U.trailingCols&&Ee+Se>te-U.trailingVisibleWidth,be=U.trailingHeight>0&&D.row<e.count-U.trailingRows&&Ae+ue>re-U.trailingVisibleHeight;if(Fe||qe||de||se||be){S.style.clipPath=Mi;return}S.style.clipPath="",S.style.transform=`translate(${Ee}px, ${Ae}px)`;const ge=`${Se} ${ue}`;S.dataset.aqspAnchorSig!==ge&&(S.dataset.aqspAnchorSig=ge,S.style.width=`${Se}px`,S.style.height=`${ue}px`)},[e,t]),hn=i.useCallback((S,D,V)=>{if(v===void 0)return;const P=v.current,{width:U,height:te}=S.getViewportSize(),re=S.getFrozenSize(),Ae={scroll:V,frozenCount:re.cols,trailingCount:re.trailingCols,extent:U},Ee={scroll:D,frozenCount:re.rows,trailingCount:re.trailingRows,extent:te};pn(k===void 0?null:k.current,P.interactive,Ae,Ee,re,U,te),pn(b===void 0?null:b.current,P.tip,Ae,Ee,re,U,te)},[v,k,b,pn]),mn=i.useCallback(()=>{const S=y.current,D=n.current;if(S===null||D===null)return;const V=D.getScrollPosition(),P=Math.max(0,V.y),U=Math.max(0,V.x),te=o(),re=le(U,P),Ae=Ut(),Ee=Ae===null?Hm:te.ranges.slice(-qm(re.length));for(const de of re){const se=de.nodes.container;if(se===null)continue;const be=de.nodes.fillPool;for(let ge=0;ge<Math.max(be.length,te.ranges.length);ge+=1){let he=be[ge];if(he===void 0){const xe=document.createElement("div");xe.className="aqsp-selection-fill",xe.setAttribute("data-aqsp-fill",""),xe.style.display="none",se.insertBefore(xe,Pi(de.nodes)),he={node:xe,last:{shown:!1,width:-1,height:-1,transform:""}},be.push(he)}const Xe=te.ranges[ge],ce=Xe===void 0?null:pt(Xe,de);if(ce===null)he.last.shown&&(he.last.shown=!1,he.node.style.display="none");else{he.last.shown||(he.last.shown=!0,he.node.style.display="block");const xe=`translate(${ce.left}px, ${ce.top}px)`;xe!==he.last.transform&&(he.last.transform=xe,he.node.style.transform=xe),ce.width!==he.last.width&&(he.last.width=ce.width,he.node.style.width=`${ce.width}px`),ce.height!==he.last.height&&(he.last.height=ce.height,he.node.style.height=`${ce.height}px`)}}for(;be.length>te.ranges.length;)be.pop()?.node.remove();Ft(de.nodes.active,pt(ve(te.active,te.active),de)),fn(de),Mr(de,se,Ee,Ae)}const Se=h(),ue=Se===null||Se.foreign?null:Se;for(const de of re){const se=de.nodes.marquee;if(se===null)continue;const be=ue===null?null:pt(ue.range,de),ge=be!==null&&(de.xSeamTrail&&be.left>=de.clampWidth&&be.left<de.clampWidth+br||de.xSeamLead&&be.left+be.width<=0&&be.left+be.width>-br||de.ySeamTrail&&be.top>=de.clampHeight&&be.top<de.clampHeight+br||de.ySeamLead&&be.top+be.height<=0&&be.top+be.height>-br)?null:be;if(ge===null)se.style.display="none";else{se.style.display="block",se.style.transform=`translate(${ge.left}px, ${ge.top}px)`,se.style.width=`${ge.width}px`,se.style.height=`${ge.height}px`;const ce=Kr(ge.top),xe=Kr(ge.left),tt=Kr(de.cells.clampHeight-(ge.top+ge.height)),at=Kr(de.cells.clampWidth-(ge.left+ge.width)),We=`${ce} ${at} ${tt} ${xe}`;We!==se.dataset.aqspOutsetSig&&(se.dataset.aqspOutsetSig=We,se.style.setProperty("--aqsp-clip-outset-top",ce),se.style.setProperty("--aqsp-clip-outset-right",at),se.style.setProperty("--aqsp-clip-outset-bottom",tt),se.style.setProperty("--aqsp-clip-outset-left",xe))}const he=ge===null?null:ue?.kind??null,Xe=se.dataset.aqspClipKindLast??null;he!==Xe&&(he===null?(delete se.dataset.aqspClipKindLast,se.removeAttribute("data-aqsp-clip-kind")):(se.dataset.aqspClipKindLast=he,se.setAttribute("data-aqsp-clip-kind",he)))}er.current!==null&&$n(er.current,P,U,tr.current),d.current!==null&&Ln(d.current,P,U),E.current!==null&&nr(E.current,P,U);const Fe=z.current;if(Fe!==null&&!R()){const{width:de,height:se}=D.getViewportSize(),be=te.ranges[te.ranges.length-1];if(!(te.ranges.length===1&&!An.current&&!m())||se<=0||de<=0)Fe.style.display="none";else{const he=D.getFrozenSize(),Xe={scroll:U,frozenCount:he.cols,trailingCount:he.trailingCols,extent:de},ce={scroll:P,frozenCount:he.rows,trailingCount:he.trailingRows,extent:se},xe=be.endCol<he.cols,tt=be.endRow<he.rows,at=be.endCol>=t.count-he.trailingCols,We=be.endRow>=e.count-he.trailingRows,ke=kn(t,be.endCol,Xe)+t.sizeOf(be.endCol),Ie=En(e,be.endRow,ce)+e.sizeOf(be.endRow),Ge=xe||at?0:he.width,Pt=tt||We?0:he.height,nt=at?de:de-he.trailingVisibleWidth,ht=We?se:se-he.trailingVisibleHeight;Ie<=Pt||Ie>ht||ke<=Ge||ke>nt?Fe.style.display="none":(Fe.style.display="block",Fe.style.transform=`translate(${ke-ji+1}px, ${Ie-ji+1}px)`)}}const qe=r.current;if(qe!==null){const de=te.active,{width:se,height:be}=D.getViewportSize(),ge=D.getFrozenSize(),he={scroll:U,frozenCount:ge.cols,trailingCount:ge.trailingCols,extent:se},Xe={scroll:P,frozenCount:ge.rows,trailingCount:ge.trailingRows,extent:be},ce=En(e,de.row,Xe),xe=kn(t,de.col,he),tt=be>0?Math.min(Math.max(ce,0),Math.max(0,be-1)):0,at=se>0?Math.min(Math.max(xe,0),Math.max(0,se-1)):0;qe.style.top=`${tt}px`,qe.style.left=`${at}px`,An.current?(qe.style.width=`${t.sizeOf(de.col)}px`,qe.style.height=`${e.sizeOf(de.row)}px`,qe.style.paddingTop=`${jm(e.sizeOf(de.row),x===void 0?Bt:x.current)}px`):(qe.style.width="1px",qe.style.height="1px",qe.style.paddingTop="0px");const We=de.col>=ge.cols&&xe<ge.width,ke=de.row>=ge.rows&&ce<ge.height,Ie=ge.trailingWidth>0&&de.col<t.count-ge.trailingCols&&xe+t.sizeOf(de.col)>se-ge.trailingVisibleWidth,Ge=ge.trailingHeight>0&&de.row<e.count-ge.trailingRows&&ce+e.sizeOf(de.row)>be-ge.trailingVisibleHeight,Pt=An.current&&ce===tt&&xe===at&&!We&&!ke&&!Ie&&!Ge;Pt!==zr.current&&(zr.current=Pt,Pt?qe.setAttribute("data-aqsp-editing",""):qe.removeAttribute("data-aqsp-editing"))}hn(D,P,U)},[n,pt,le,Ft,$n,Ln,nr,h,o,m,R,z,r,e,t,Ut,Mr,fn,x,hn]),rr=i.useCallback((S,D)=>{er.current=S,tr.current=D;const V=S===null?"add":D;for(const te of le(0,0)){const re=te.nodes.dragRect;if(re===null)continue;const Ae=re.dataset.aqspDragModeLast??"add";V!==Ae&&(re.dataset.aqspDragModeLast=V,V==="add"?re.removeAttribute("data-aqsp-drag-mode"):re.setAttribute("data-aqsp-drag-mode",V))}const P=n.current;if(S===null||P===null){for(const te of le(0,0))te.nodes.dragRect!==null&&(te.nodes.dragRect.style.display="none"),Tn(te,null,null);return}const U=P.getScrollPosition();$n(S,Math.max(0,U.y),Math.max(0,U.x),D)},[n,$n,le,Tn]),Xt=i.useCallback(S=>{E.current=S;const D=n.current;if(D===null){for(const P of le(0,0))P.nodes.fillPreview!==null&&(P.nodes.fillPreview.style.display="none");return}const V=D.getScrollPosition();nr(S,Math.max(0,V.y),Math.max(0,V.x))},[n,nr,le]),Ke=i.useCallback(S=>{d.current=S;const D=n.current;if(D===null){for(const P of le(0,0))P.nodes.resizeGuide!==null&&(P.nodes.resizeGuide.style.display="none");return}const V=D.getScrollPosition();Ln(S,Math.max(0,V.y),Math.max(0,V.x))},[n,Ln,le]);i.useLayoutEffect(()=>{const S=y.current;if(!(S===null||C===void 0))return S.style.setProperty("--aqsp-band-row",C.row),S.style.setProperty("--aqsp-band-column",C.column),S.style.setProperty("--aqsp-band-intersection",C.intersection),S.style.setProperty("--aqsp-band-opacity",String(C.opacity)),()=>{S.style.removeProperty("--aqsp-band-row"),S.style.removeProperty("--aqsp-band-column"),S.style.removeProperty("--aqsp-band-intersection"),S.style.removeProperty("--aqsp-band-opacity")}},[C]),i.useEffect(()=>(c.current=mn,u.current=rr,N.current=Xt,W.current=Ke,()=>{c.current=null,u.current=null,N.current=null,W.current=null})),i.useEffect(()=>{mn()},[mn,s,Me,Be,bt,et]),i.useEffect(()=>{const S=r.current;if(S===null)return;const D=V=>_(V);return S.addEventListener("mousedown",D),()=>S.removeEventListener("mousedown",D)},[r,_]);const Eo=Me>0||bt>0?[...Me>0?[{k:"f",style:{left:0,width:it}}]:[],{k:"s",style:{left:it,right:ct}},...bt>0?[{k:"t",style:{right:0,width:ct}}]:[]]:[{k:"m",style:{left:0,right:0}}],Oo=Be>0||et>0?[...Be>0?[{k:"f",style:{top:0,height:Nt}}]:[],{k:"s",style:{top:Nt,bottom:dn}},...et>0?[{k:"t",style:{bottom:0,height:dn}}]:[]]:[{k:"m",style:{top:0,bottom:0}}],Ue=S=>S==="m"?0:S==="s"?1:S==="t"?2:3,Pe=Eo.flatMap(S=>Oo.map(D=>({xk:S.k,yk:D.k,key:`${S.k}${D.k}`,style:{...S.style,...D.style}}))).sort((S,D)=>Ue(S.key[0])+Ue(S.key[1])-(Ue(D.key[0])+Ue(D.key[1]))),Gt=S=>S==="mm"?{"data-aqsp-overlay-main":""}:S==="fm"?{"data-aqsp-overlay-frozen":""}:S==="sm"?{"data-aqsp-overlay-scroll":""}:{};return K.jsxs("div",{ref:y,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,bottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:[Pe.map(({xk:S,yk:D,key:V,style:P})=>{const U=me[V];return K.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":V,...Gt(V),style:P,ref:U.container,children:[f?K.jsx("div",{className:"aqsp-band-clip","data-aqsp-band-clip":"",ref:U.bandClip}):null,S==="s"&&Me>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:U.dividerXLeading}):null,S==="s"&&bt>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:U.dividerXTrailing}):null,D==="s"&&Be>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:U.dividerYLeading}):null,D==="s"&&et>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:U.dividerYTrailing}):null,f?K.jsx("div",{className:"aqsp-frame","data-aqsp-frame":"",style:{display:"none"},ref:U.frame}):null,K.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:U.active}),K.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:U.dragRect}),K.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:U.marquee}),K.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:U.fillPreview}),K.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:U.resizeGuide})]},V)}),K.jsx("textarea",{ref:Ce,className:"aqsp-sink","aria-label":F,"aria-readonly":H?"true":void 0,"aria-keyshortcuts":$,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),I?K.jsx("div",{ref:z,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},Ha=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=e.cellReadOnly===!0,s=i.useId(),l=i.useRef(!1),c=R=>{l.current=!0;try{R()}finally{l.current=!1}},u=()=>{o||n.trim()!==""&&c(()=>e.commit([...e.current,{text:n}]))},h=R=>{if(R.key==="Escape"){R.preventDefault(),c(e.close);return}R.key==="Enter"&&(R.ctrlKey||R.metaKey)&&!R.altKey&&!R.shiftKey&&(R.preventDefault(),u())},m=R=>{l.current||R.relatedTarget instanceof Node&&R.currentTarget.contains(R.relatedTarget)||e.rejected||c(e.close)};return 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:[_e(t,"commentTitle"),K.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:_e(t,"commentCount",e.current.length)})]}),K.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(R=>K.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":R.id,children:[K.jsx("span",{className:"aqsp-popover-comment-author",children:R.author}),K.jsx("time",{className:"aqsp-popover-comment-time",dateTime:R.createdAt,children:R.createdAt}),K.jsx("p",{className:"aqsp-popover-comment-text",children:R.text})]},R.id))}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":_e(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:R=>r(R.currentTarget.value),onKeyDown:h}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",disabled:o,"aria-disabled":o?"true":void 0,onClick:u,children:_e(t,"commentPost")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>c(e.close),children:"×"})]})]})},Ba=({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:an(o),m=o.trim()!==""&&h===null,R=I=>{u.current=!0;try{I()}finally{u.current=!1}},N=()=>{l||m||R(()=>e.commit({text:n===""&&h!==null?h:n,url:h}))},W=I=>{if(I.key==="Escape"){I.preventDefault(),R(e.close);return}I.key==="Enter"&&!I.altKey&&!I.shiftKey&&(I.preventDefault(),N())},z=I=>{u.current||I.relatedTarget instanceof Node&&I.currentTarget.contains(I.relatedTarget)||e.rejected||R(e.close)};return K.jsxs("div",{className:"aqsp-popover-link","data-aqsp-popover":"link","data-aqsp-popover-rejected":e.rejected?"":void 0,"data-aqsp-link-invalid":m?"":void 0,role:"dialog","aria-labelledby":c,onBlur:z,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:c,children:_e(t,"linkTitle")}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:_e(t,"linkTextField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:I=>r(I.currentTarget.value),onKeyDown:W})]}),K.jsxs("label",{className:"aqsp-popover-field",children:[K.jsx("span",{className:"aqsp-popover-field-label",children:_e(t,"linkUrlField")}),K.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-url":"","data-aqsp-popover-autofocus":"",type:"url",value:o,"aria-invalid":m||e.rejected?!0:void 0,onChange:I=>s(I.currentTarget.value),onKeyDown:W})]}),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:N,children:_e(t,"linkSave")}),e.canOpen&&e.current.url!==void 0?K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-link-open":"",onClick:e.open,children:_e(t,"linkOpen")}):null,K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>R(e.close),children:"×"})]})]})},Hi=500,Wa=({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 Y=n.toLowerCase();return e.current.filter(O=>O.toLowerCase().startsWith(Y))},[e.current,n]),h=i.useMemo(()=>u.length>Hi?u.slice(0,Hi):u,[u]),m=u.length-h.length,R=h.length===0?-1:Math.min(o,h.length-1),N=Y=>{c.current=!0;try{Y()}finally{c.current=!1}},W=()=>{R<0||N(()=>e.commit(h[R]))},z=Y=>{if(Y.key==="Escape"){Y.preventDefault(),N(e.close);return}if(Y.key==="Enter"){Y.preventDefault(),W();return}if(Y.key==="ArrowDown"){Y.preventDefault(),s(R+1);return}Y.key==="ArrowUp"&&(Y.preventDefault(),s(Math.max(R-1,0)))},I=Y=>{c.current||Y.relatedTarget instanceof Node&&Y.currentTarget.contains(Y.relatedTarget)||N(e.close)},X=Y=>`${l}-${Y}`;return K.jsxs("div",{className:"aqsp-popover-list","data-aqsp-popover":"list",onBlur:I,children:[K.jsx("input",{className:"aqsp-popover-input","data-aqsp-list-input":"","data-aqsp-popover-autofocus":"",type:"text",role:"combobox","aria-label":_e(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":R<0?void 0:X(R),value:n,onChange:Y=>{r(Y.currentTarget.value),s(0)},onKeyDown:z}),K.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":_e(t,"listTitle"),children:[h.length===0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:_e(t,"listEmpty")}):h.map((Y,O)=>K.jsx("div",{className:"aqsp-popover-option",id:X(O),role:"option",tabIndex:-1,"aria-selected":O===R,"data-aqsp-list-option":Y,onPointerDown:T=>T.preventDefault(),onClick:()=>N(()=>e.commit(Y)),children:Y},X(O))),m>0?K.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:_e(t,"listMore",m)}):null]})]})},Va=({ctx:e,labels:t})=>K.jsxs("div",{className:"aqsp-popover-message","data-aqsp-popover":"message","data-aqsp-popover-rejected":e.current.rejected?"":void 0,role:"status",children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",children:e.current.title}),K.jsx("p",{className:"aqsp-popover-message-text","data-aqsp-popover-message-text":"",children:e.current.message}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:e.close,children:"×"})]}),Ya=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=e.cellReadOnly===!0,l=i.useId(),c=i.useId(),u=i.useRef(!1),h=z=>{u.current=!0;try{z()}finally{u.current=!1}},m=()=>{s||h(()=>e.commit(r===""?null:r))},R=()=>{r!==n&&!s?m():h(e.close)},N=z=>{if(z.key==="Escape"){z.preventDefault(),e.rejected?h(e.close):R();return}z.key==="Enter"&&(z.ctrlKey||z.metaKey)&&!z.altKey&&!z.shiftKey&&(z.preventDefault(),m())},W=z=>{u.current||z.relatedTarget instanceof Node&&z.currentTarget.contains(z.relatedTarget)||e.rejected||R()};return K.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":l,onBlur:W,children:[K.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:_e(t,"noteTitle")}),K.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":c,"aria-invalid":e.rejected?!0:void 0,onChange:z=>o(z.currentTarget.value),onKeyDown:N}),K.jsx("p",{className:"aqsp-popover-hint",id:c,"data-aqsp-popover-hint":"",children:_e(t,s?"noteViewerHint":e.rejected?"noteRejectedHint":"noteEscapeHint")}),K.jsxs("div",{className:"aqsp-popover-actions",children:[K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:s,"aria-disabled":s?"true":void 0,onClick:m,children:_e(t,"noteSave")}),K.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":_e(t,"popoverClose"),onClick:()=>h(e.close),children:"×"})]})]})},Ka=({ctx:e})=>K.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),jt=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")}),Bi=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],Ua=Object.freeze({all:jt(Bi),values:jt(["text"]),formats:jt(["format","borders","cf"]),formulas:jt(["text","formula"]),noBorders:jt(Bi.filter(e=>e!=="borders")),columnWidths:jt(["sizes"]),validation:jt(["validation"]),conditionalFormats:jt(["cf"]),commentsAndNotes:jt(["note","comments"])}),Wi=Object.freeze({mode:"all"}),As=Object.freeze({t:""}),Vi=Object.freeze({row:1<<30,col:1<<30}),Ym=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),Km=e=>e.t===""&&e.f===void 0,Um=e=>e.length>1&&e.startsWith("="),Xm=(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}},Yi=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,Gm=(e,t,n,r)=>{const o=Um(e),s=e===""?"0":wt(e);if(!o&&s===null)return null;const l=Ym[n];if(t.f!==void 0){const h=Tr(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:Yi(Number(s));const c=wt(t.t);if(c===null)return null;const u=Number(c);return n==="divide"&&u===0?null:o?`=(${e.slice(1)})${l}(${c})`:Yi(Xm(Number(s),u,n))},Ki=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),Zm=e=>{switch(e.kind){case"cell":return e.absRow||e.absCol?e:{...e,row:e.col,col:e.row};case"range":return e.start.absRow||e.start.absCol||e.end.absRow||e.end.absCol?e:{...e,start:Ki(e.start),end:Ki(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}}}},Jm=e=>{const t=Tr(e,Vi),n=xr(t);let r="",o=0,s=!1;for(const l of n){const c=Zm(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${on(c)}`,o=l.end,s=!0)}return s?yo(`${r}${t.slice(o)}`,Vi):e},Qm=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return As;const o=r[n];return o===void 0?As:o},eg=e=>{const{rows:t,cols:n}=e,r=Xc(Jm);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=Qm(e,h,c);let R=m;if(m.f!==void 0){const N=r(m.f);R=N===m.f?m:{...m,f:N}}(R!==m||m===As)&&(o=!1),u.push(R)}s.push(u)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(u=>({startRow:u.startCol,startCol:u.startRow,endRow:u.endCol,endCol:u.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},tg=(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,ng=(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},Ui=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let u=!1;const h=[];for(const m of c)tg(m,t)?(h.push(ng(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},Xi=new WeakMap,Xa=e=>{const t=Xi.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>xt(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:xt({...s,borders:void 0})),o={canonical:n,borderless:r};return Xi.set(e,o),o},mo=(e,t)=>t===void 0?void 0:e[t],rg=(e,t,n,r)=>{const o=Xa(e);if(n){const h=mo(o.canonical,t.fmt);return h===void 0?null:h}const s=mo(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=xt(s===void 0?{borders:c}:{...s,borders:c});return u===void 0?null:u},og=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?Gm(n.readText(),o,r,n):o.f===void 0?o.t:Tr(o.f,n)},Gi=(e,t,n,r,o)=>{const s=Ua[r.mode];if(r.skipBlanks===!0&&Km(e))return null;const l={};let c=!1;if(s.text){const u=og(e,s.formula&&o.formula,n,r.operation);u!==null&&(l.text=u,c=!0)}if(o.format){if(s.format)l.format=rg(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const u=mo(Xa(t).canonical,e.fmt);u!==void 0&&(l.format=u,c=!0)}}if(s.note&&o.note&&(l.note=e.note===void 0?null:e.note,c=!0),s.comments&&o.comments&&(l.comments=e.comments===void 0?null:e.comments,c=!0),s.hyperlink&&o.hyperlink&&(l.hyperlink=e.link===void 0?null:e.link,c=!0),s.validation&&o.validation){const u=mo(t.validations,e.val);l.validation=u===void 0?null:u,c=!0}return c?l:null},Zi=(e,t)=>e.length===0?e:t.length===0?[]:e.map(n=>{const r=[];for(const o of t)for(const s of n.ranges)r.push({startRow:o.row+s.startRow,startCol:o.col+s.startCol,endRow:o.row+s.endRow,endCol:o.col+s.endCol});return{...n,ranges:r}}),sg=["text/html","text/plain"],lg=(e,t,n)=>{if(e===0||t===0)return 0;const r=Ct(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},ig=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,cg=e=>e.text||e.formula||e.format||e.borders||e.note||e.comments||e.hyperlink||e.validation,ag=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}}},Ji=e=>{const t=e.clipboardData;return t??null},ug=(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}},dg=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=ug(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},fg=(e,t,n,r,o)=>{const s=Jn(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=yo(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=Qn(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},Ga=(e,t)=>{const n=Mc(),r=pf(),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(fg(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:dg(e.getConditionalFormats(),t)}},Qi=e=>e.kind==="cut"?{...e.payload,...Ga(e.sourceAdapter,e.range)}:e.payload,pg=e=>({v:1,rows:e.length,cols:e[0].length,clipId:Ns(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),hg=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=an(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:u,...h}=l;s.push(h)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},mg=(e,t,n)=>{const r={row:e,col:t,text:""};return n.format&&(r.format=null),n.note&&(r.note=null),n.comments&&(r.comments=null),n.hyperlink&&(r.hyperlink=null),n.validation&&(r.validation=null),r},gg=(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 ve({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},wg=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(O=>{const T=n.current;if(T===null||O==="format"||O==="annotate")return;const F=r.current;F==="own"||F==="foreign"&&T.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const O=n.current;if(O===null)return;if(O.kind==="copy"){o();return}const T=t.current;T.repaintOverlay(),T.onClipChange?.({kind:"cut",range:O.range,foreign:O.sourceAdapter!==T.adapter})},[o]),c=i.useCallback((O,T,F)=>{const H=t.current;n.current={kind:O,range:T,clipId:F.clipId,sourceAdapter:H.adapter,payload:F},H.repaintOverlay(),H.onClipChange?.({kind:O,range:T,foreign:!1})},[]),u=i.useCallback(O=>{const T=t.current,F=T.adapter,H=Ct(O),$={v:1,rows:H.rows,cols:H.cols,clipId:Ns(),...Ga(F,O),wholeRows:Nc(O,F.colCount),wholeCols:Fc(O,F.rowCount)};if(T.resize!==void 0){if($.wholeCols){const _=[];for(let x=O.startCol;x<=O.endCol;x+=1)_.push(Math.min(T.resize.colAxis.sizeOf(x),cn));$.colWidths=_}if($.wholeRows){const _=[];for(let x=O.startRow;x<=O.endRow;x+=1)_.push(Math.min(T.resize.rowAxis.sizeOf(x),cn));$.rowHeights=_}}return $},[]),h=i.useCallback((O,T)=>{const F=t.current,H=F.getSelection(),$=H.ranges[H.ranges.length-1],_=Mt([$]);if(_>F.maxOperationCells)return O.preventDefault(),F.onOperationRejected?.(T,_,"limit"),null;if(T==="cut"&&Cr(F.adapter,$))return O.preventDefault(),F.rejectReadOnly({kind:"operation",op:"cut",cellCount:_}),null;H.ranges.length>1&&F.onCopyMultiRange?.();const x=u($),g=Sc(x),p=Ji(O);return p!==null&&(p.setData("text/plain",Vt.serializeClipboardTsv(x.cells.map(C=>C.map(v=>v.t)))),p.setData("text/html",pa(x,g)),p.setData(fo,g)),O.preventDefault(),{payload:x,range:$}},[u]),m=i.useCallback((O,T)=>t.current.commitPaste(O,T)!==null,[]),R=i.useCallback((O,T,F)=>{const H=t.current;if(!F.sizes||H.resize===void 0)return;const{rowAxis:$,colAxis:_,resizeTracks:x}=H.resize,g=(p,C,v)=>{const k=Ls(C,v,null,{maxOperationCells:H.maxOperationCells,rowHiddenLimit:Ts,axisKind:p});if(!k.ok){H.onOperationRejected?.("resize",k.count,k.reason);return}x(p,k.entries)};if(O.colWidths!==void 0){const p=[];for(let C=T.startCol;C<=T.endCol;C+=1)p.push({index:C,size:O.colWidths[(C-T.startCol)%O.cols]});g("col",_,p)}if(O.rowHeights!==void 0){const p=[];for(let C=T.startRow;C<=T.endRow;C+=1)p.push({index:C,size:O.rowHeights[(C-T.startRow)%O.rows]});g("row",$,p)}},[]),N=i.useCallback((O,T)=>{const F=t.current,H=F.adapter,$=O.payload,_={row:T.startRow,col:T.startCol},x=$.rows*$.cols+Mt([O.range]);if(x>F.maxOperationCells)return F.onOperationRejected?.("paste",x,"limit"),"rejected";if(_.row+$.rows>H.rowCount||_.col+$.cols>H.colCount||O.range.endRow>=O.sourceAdapter.rowCount||O.range.endCol>=O.sourceAdapter.colCount)return F.onOperationRejected?.("paste",x,"bounds"),"rejected";const g=ks({rows:$.rows,cols:$.cols},ve(_,_),_,H.rowCount,H.colCount);if(g!==null&&Cr(H,g))return F.rejectReadOnly({kind:"operation",op:"paste",cellCount:$.rows*$.cols}),"rejected";if(Cr(O.sourceAdapter,O.range))return F.rejectReadOnly({kind:"operation",op:"cut",cellCount:Mt([O.range])}),"rejected";const p=Qi(O),C=ao(H),v=Ui(p,C),k={row:0,col:0,readText:()=>Jn(H,k.row,k.col).text,readFormat:()=>H.getCellFormat===void 0?void 0:H.getCellFormat(k.row,k.col)},{edits:b,tiles:y}=hi(v.cells,ve(_,_),_,H.rowCount,H.colCount,(E,d,L)=>(k.row=O.range.startRow+(d-_.row),k.col=O.range.startCol+(L-_.col),Gi(E,v,k,Wi,C))),a=ao(O.sourceAdapter),f=[];if(tn([O.range],E=>{f.push(mg(E.row,E.col,a))}),O.sourceAdapter===H){if(!m([...f,...b],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const E=F.commitPaste(b,{sameSheet:!1,conditionalFormats:Zi(v.conditionalFormats,y)});if(E===null)return"rejected";try{O.sourceAdapter.applyEdits(f,{transaction:E,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){F.onEditRejected?.(d,{source:"paste"})}}return F.setSelection({ranges:[ve(_,{row:_.row+p.rows-1,col:_.col+p.cols-1})],anchor:_,active:_}),"applied"},[m]),W=i.useCallback((O,T,F)=>{const H=t.current,$=H.adapter,_=G=>(H.onClipboardUnavailable?.(G),"rejected"),x=Oc(O,T);if(x==="none")return T==="menu"?_("empty"):"empty";const g=H.getSelection(),p=g.ranges[g.ranges.length-1],C=F.transpose===!0,v=(G,Z)=>{const Q=lg(C?Z:G,C?G:Z,p);return Q>H.maxOperationCells?(H.onOperationRejected?.("paste",Q,"limit"),!0):!1};let k,b=null;if(x==="aqsp"){const G=qd(O,T);if(G===null)return _("unreadable");const Z=n.current;if(Z!==null&&G.clipId===Z.clipId&&(b=Z),b!==null&&b.kind==="cut"&&ig(F))return N(b,p);if(v(G.rows,G.cols))return"rejected";if(b!==null){if(b.kind==="cut"&&(b.range.endRow>=b.sourceAdapter.rowCount||b.range.endCol>=b.sourceAdapter.colCount))return H.onOperationRejected?.("paste",b.payload.rows*b.payload.cols,"bounds"),"rejected";k=Qi(b)}else{const Q=Id(O,T);if(Q===null)return _("unreadable");if(v(Q.rows,Q.cols))return"rejected";k=hg(Q)}}else if(x==="tsv"){const G=O.getData("text/plain"),Z=Vt.measureTsv(G);if(v(Z.rows,Z.cols))return"rejected";k=pg(Vt.parseTsv(G))}else{const G=O.getData("text/html"),Z=ff(G);if(Z.cols===0&&Z.rows>H.maxOperationCells)return H.onOperationRejected?.("paste",Z.rows,"limit"),"rejected";if(v(Z.rows,Z.cols))return"rejected";const Q=wa(G,x,H.formats===void 0?{}:{currency:H.formats.currency,locale:H.formats.locale},H.maxOperationCells);if(Q.outcome==="none")return _("unreadable");if(Q.outcome==="limit")return H.onOperationRejected?.("paste",Q.cells,"limit"),"rejected";if(v(Q.payload.rows,Q.payload.cols))return"rejected";k=Q.payload}const y=ao($),a=Ui(C?eg(k):k,y),f=Ua[F.mode];if(cg(f)){const G=ks({rows:a.rows,cols:a.cols},p,g.active,$.rowCount,$.colCount);if(G!==null&&Cr($,G))return H.rejectReadOnly({kind:"operation",op:"paste",cellCount:Mt([G])}),"rejected"}const E={row:0,col:0,readText:()=>Jn($,E.row,E.col).text,readFormat:()=>$.getCellFormat===void 0?void 0:$.getCellFormat(E.row,E.col)},{edits:d,tiles:L}=hi(a.cells,p,g.active,$.rowCount,$.colCount,(G,Z,Q)=>(E.row=Z,E.col=Q,Gi(G,a,E,F,y))),A=gg(L,a.rows,a.cols,$.rowCount,$.colCount);if(A===null)return"empty";if(f.cf&&a.conditionalFormats.length>0){let G=0;for(const Q of a.conditionalFormats)G+=Q.ranges.length;const Z=L.length*G;if(Z>H.maxOperationCells)return H.onOperationRejected?.("paste",Z,"limit"),"rejected"}const M=f.cf?Zi(a.conditionalFormats,L):[];if(d.length===0&&M.length===0)return R(a,A,f),"empty";r.current=b===null?"foreign":"own";let B=!1;try{B=m(d,{sameSheet:b!==null&&b.sourceAdapter===$,conditionalFormats:M})}finally{r.current="none"}if(!B)return"rejected";R(a,A,f);const j={row:A.startRow,col:A.startCol};return H.setSelection({ranges:[A],anchor:j,active:j}),"applied"},[N,m,R]),z=i.useCallback(async O=>{const T=C=>(t.current.onClipboardUnavailable?.(C),"rejected"),F=navigator;if(F.clipboard===void 0)return T("insecure-origin");let H;try{H=await F.clipboard.read({unsanitized:["text/html"]})}catch{return T("permission-denied")}if(H.length===0)return T("empty");const $=H[0],_=Array.from($.types),x=new Map;try{for(const C of sg)_.includes(C)&&x.set(C,await(await $.getType(C)).text())}catch{return T("unreadable")}const g={types:_,getData:C=>{const v=x.get(C);if(v===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${C} was not materialised for the menu path`);return v}},p=t.current;return!p.enabled||p.isDragging()||p.isEditing()?"rejected":W(g,"menu",O)},[W]),I=i.useCallback(async O=>{const T=await z(O);return t.current.onPasteResolved?.(T,"menu"),T},[z]),{enabled:X,sinkRef:Y}=e;return i.useEffect(()=>{const O=Y.current;if(!X||O===null)return;const T=_=>t.current.isDragging()?(_.preventDefault(),!0):!1,F=_=>{const x=t.current;if(T(_)||x.isEditing())return;const g=h(_,"copy");g!==null&&c("copy",g.range,g.payload)},H=_=>{const x=t.current;if(T(_)||x.isEditing())return;const g=h(_,"cut");g!==null&&c("cut",g.range,g.payload)},$=_=>{const x=t.current;if(T(_)||x.isEditing())return;_.preventDefault();let g=Wi;const p=x.pendingPasteOptionsRef;p!==void 0&&p.current!==null&&(g=p.current,p.current=null);const C=Ji(_);if(C===null)return;const v=W(ag(C),"event",g);x.onPasteResolved?.(v,"event")};return O.addEventListener("copy",F),O.addEventListener("cut",H),O.addEventListener("paste",$),()=>{O.removeEventListener("copy",F),O.removeEventListener("cut",H),O.removeEventListener("paste",$)}},[X,Y,h,c,W]),i.useMemo(()=>({getClip:()=>{const O=n.current;return O===null?null:{kind:O.kind,range:O.range,foreign:O.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:I}),[o,s,l,I])},Za=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)}`)},Ja=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}},ec=(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}`}`},Qa=(e,t)=>{let n;if(e.exponent===null)n=ec(e.negative,e.digits,e.point+t);else{const r=ec(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return wt(n)===null?null:n},Cg=(e,t)=>{Za(t);const n=wt(e);return n===null?null:Qa(Ja(n),t)},bg=e=>{const t=wt(e);if(t!==null){const r=Ja(t);return Qa({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},eu=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)},yg=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},tu=(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 yg(r)?r:null},Rg=(e,t)=>{Za(t);const n=eu(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=tu(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},vg=e=>{const t=eu(e),n=tu(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},hr=(e,t,n,r)=>{const o=Mt(t);return o>n?(r?.(e,o,"limit"),!1):!0},Jr={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},Qr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},tc={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:Jr.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:Jr.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:Jr.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:Jr.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:Qr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:Qr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:Qr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:Qr.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},increaseColumnWidth:{kind:"resize",axis:"col",step:1},decreaseColumnWidth:{kind:"resize",axis:"col",step:-1},increaseRowHeight:{kind:"resize",axis:"row",step:1},decreaseRowHeight:{kind:"resize",axis:"row",step:-1},autoFitColumnWidth:{kind:"resize",axis:"col",step:"fit"},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},Sg={value:null,align:null,verticalAlign:null,wrap:null,background:null,color:null,bold:null,italic:null,underline:null,strikethrough:null,fontFamily:null,fontSize:null,borders:null},Sr=e=>e<10?`0${e}`:String(e),kg=e=>{const t=new Date(e);return`${t.getFullYear()}-${Sr(t.getMonth()+1)}-${Sr(t.getDate())}`},Eg=e=>{const t=new Date(e);return`${Sr(t.getHours())}:${Sr(t.getMinutes())}:${Sr(t.getSeconds())}`},Og=(e,t)=>(e.row===t.startRow?1:0)|(e.col===t.endCol?2:0)|(e.row===t.endRow?4:0)|(e.col===t.startCol?8:0),Ag=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),xg=e=>e===void 0||e.borders===void 0?{}:e.borders,Tg={top:1,right:2,bottom:4,left:8},$g={style:"thin",color:Ds},Lg=(e,t)=>{if(e===void 0)return!1;const n=st(e);return n!==null&&n===st(t)},Dg=(e,t)=>{const n=t===void 0||t.locale===void 0?{}:{locale:t.locale};switch(e){case"number":return{type:"number",decimals:2,grouping:!0,...n};case"time":return{type:"date",pattern:"HH:mm:ss"};case"date":return{type:"date"};case"currency":if(t===void 0)throw new RangeError("[spreadsheet] formatCurrency requires the formats prop (currency)");return{type:"currency",currency:t.currency,decimals:2,...n};case"percent":return{type:"percent",decimals:2,...n};default:return{type:"scientific",decimals:2,...n}}},zg=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const g=t.current;if(g.isEditing()){const p=g.getActive();return[ve(p,p)]}return g.getSelection().ranges},[]),r=i.useCallback(()=>{const g=t.current,p=g.getActive();return g.adapter.getCellFormat===void 0?void 0:g.adapter.getCellFormat(p.row,p.col)},[]),o=i.useCallback(g=>{const p=t.current,C=n();if(!hr("format",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"format",cellCount:Mt(C)}),!1;const v=new Map,k=[],b=p.adapter.getCellFormat;for(const y of C)tn([y],a=>{const f=b===void 0?void 0:b(a.row,a.col),{bucket:E,patch:d}=g(a,y,f);let L=v.get(E);L===void 0&&(L=new Map,v.set(E,L));let A;L.has(f)?A=L.get(f):(A=Ms(f,d),L.set(f,A)),A!==f&&k.push({row:a.row,col:a.col,format:A===void 0?null:A})});return k.length===0?!0:p.commitEdits(k,{source:"format"})===null?!1:(p.isEditing()&&p.refreshEditPaint(),!0)},[n]),s=i.useCallback(g=>o(()=>({bucket:0,patch:g})),[o]),l=i.useCallback((g,p)=>{const C=t.current;C.formatCommandAnnouncement!==void 0&&C.announce(C.formatCommandAnnouncement({command:g,state:p}))},[]),c=i.useCallback((g,p=$g)=>{if(g==="clear")return s({borders:null});if(g==="all")return s({borders:{top:p,right:p,bottom:p,left:p}});const C=g==="outer"?15:Tg[g];return o((v,k,b)=>{const y=Og(v,k)&C;return{bucket:y,patch:{borders:{...xg(b),...Ag(y,p)}}}})},[s,o]),u=i.useCallback((g,p,C)=>{const v=va(t.current.adapter,g.row,g.col);for(const k of p)C.push(Sa(v,g,k))},[]),h=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("fill",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;const v=[];if(g==="selection"){const b=C.active,y=[];tn(C.ranges,a=>{(a.row!==b.row||a.col!==b.col)&&y.push(a)}),v.push({source:b,targets:y})}else for(const b of C.ranges)if(g==="down"){const y=b.startRow===b.endRow;if(y&&b.startRow===0)continue;const a=y?b.startRow-1:b.startRow;for(let f=b.startCol;f<=b.endCol;f+=1){const E=[];for(let d=y?b.startRow:b.startRow+1;d<=b.endRow;d+=1)E.push({row:d,col:f});v.push({source:{row:a,col:f},targets:E})}}else{const y=b.startCol===b.endCol;if(y&&b.startCol===0)continue;const a=y?b.startCol-1:b.startCol;for(let f=b.startRow;f<=b.endRow;f+=1){const E=[];for(let d=y?b.startCol:b.startCol+1;d<=b.endCol;d+=1)E.push({row:f,col:d});v.push({source:{row:f,col:a},targets:E})}}for(const b of v)for(const y of b.targets)if(Qe(p.adapter,y.row,y.col)){let a=0;for(const f of v)a+=f.targets.length;return p.rejectReadOnly({kind:"operation",op:"fill",cellCount:a}),!1}const k=[];for(const b of v)u(b.source,b.targets,k);return k.length===0?!0:p.commitEdits(k,{source:"fill"})!==null},[u]),m=i.useCallback(()=>{const g=t.current,p=g.getSessionText();if(p===null)return!1;const C=g.getSelection();if(!hr("fill",C.ranges,g.maxOperationCells,g.onOperationRejected))return!1;if(Wn(g.adapter,C.ranges))return g.rejectReadOnly({kind:"operation",op:"fill",cellCount:Mt(C.ranges)}),!1;const v=[];let k=!1;return tn(C.ranges,b=>{if(!k){if(!g.validateCommit(b,p).ok){k=!0;return}v.push({row:b.row,col:b.col,text:p})}}),k||g.commitEdits(v,{source:"fill"})===null?!1:(g.cancelEdit(),!0)},[]),R=i.useCallback(g=>{const p=t.current,C=p.getSelection();if(!hr("calc",C.ranges,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C.ranges))return p.rejectReadOnly({kind:"operation",op:"calc",cellCount:Mt(C.ranges)}),!1;const v=[],k=p.adapter;return tn(C.ranges,b=>{const y=k.getCellFormula===void 0?void 0:k.getCellFormula(b.row,b.col),a=y===void 0?g.text(k.getCellText(b.row,b.col)):g.formula(y);a!==null&&v.push({row:b.row,col:b.col,text:a})}),v.length===0?!0:p.commitEdits(v,{source:"calc"})!==null},[]),N=i.useCallback((g,p)=>{const C=t.current,v=g==="row"?C.rowAxis:C.colAxis,k=C.getSelection(),b=g==="row"?Math.floor(C.maxOperationCells/$s):C.maxOperationCells;let y=0;for(const L of k.ranges)y+=g==="row"?L.endRow-L.startRow+1:L.endCol-L.startCol+1;if(y>b)return C.onOperationRejected?.("resize",y,"limit"),!1;const a=new Set,f=[],E=p?0:g==="row"?C.defaultRowHeight:C.defaultColumnWidth;for(const L of k.ranges){const A=g==="row"?L.startRow:L.startCol,M=g==="row"?L.endRow:L.endCol;for(let B=A;B<=M;B+=1){if(a.has(B))continue;a.add(B),v.sizeOf(B)===0!==p&&f.push({index:B,size:E})}}const d=Ls(v,f,null,{maxOperationCells:C.maxOperationCells,rowHiddenLimit:Ts,axisKind:g});return d.ok?(d.entries.length>0&&C.resizeTracks(g,d.entries),!0):(C.onOperationRejected?.("resize",d.count,d.reason),!1)},[]),W=i.useCallback(()=>{const g=t.current;if(g.adapter.getCellHyperlink===void 0)return;const p=g.getActive();return Qn(g.adapter.getCellHyperlink(p.row,p.col))},[]),z=i.useCallback(g=>{const p=t.current,C=p.adapter,v=tc[g],k=C.getCellFormat!==void 0,b=y=>p.popovers===void 0?!0:p.popovers[y]!==!1;switch(v.kind){case"resize":return p.trackResize!==void 0;case"toggle":case"patch":case"clear":case"borders":case"color":return k;case"value":return k&&(v.value!=="currency"||p.formats!==void 0);case"popover":switch(v.popover){case"link":return C.getCellHyperlink!==void 0&&b("link");case"note":return C.getCellNote!==void 0&&b("note");case"comment":return C.getCellComments!==void 0&&b("comment");default:return C.getCellValidation!==void 0&&b("list")}case"openHyperlink":return C.getCellHyperlink!==void 0&&(p.onHyperlinkOpen!==void 0?W()!==void 0:b("link"));case"paste":return v.options.mode==="formats"?k:v.options.mode==="formulas"?C.getCellFormula!==void 0:!0;default:return!0}},[W]),I=i.useCallback(g=>{const p=t.current,C=g.kind==="popover"?g.popover:g.kind==="openHyperlink"&&p.onHyperlinkOpen===void 0?"link":void 0;if(C===void 0)return!0;const v=p.getActive();if(!Qe(p.adapter,v.row,v.col))return!0;if(C==="list")return p.rejectReadOnly({kind:"edit",cell:v,editSession:"none"}),!1;let k;if(C==="link")k=W()!==void 0;else if(C==="note"){const b=p.adapter.getCellNote===void 0?void 0:p.adapter.getCellNote(v.row,v.col);k=b!==void 0&&b!==""}else{const b=p.adapter.getCellComments===void 0?void 0:p.adapter.getCellComments(v.row,v.col);k=b!==void 0&&b.length>0}return k?!0:(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1)},[W]),X=i.useCallback((g,p,C)=>{const v=t.current,k=v.trackResize;if(k===void 0)return!1;const b=v.getActive(),y=p==="col"?b.col:b.row,a=C==="fit"?k.autofitColumn(y):k.stepTrack(p,y,C),f=(p==="col"?v.colAxis:v.rowAxis).sizeOf(y);return a&&f>0&&v.formatResizeAnnouncement!==void 0&&v.announce(v.formatResizeAnnouncement({command:g,axis:p==="col"?"column":"row",index:y,size:f})),a},[]),Y=i.useCallback(g=>{const p=t.current;if(!z(g))return!1;const C=tc[g];if(!I(C))return!1;const v=p.isEditing();if(v&&!Ys.has(g)&&!p.requestCommit())return!1;switch(C.kind){case"toggle":{const k=r(),b=k!==void 0&&k[C.key]===!0;return s({[C.key]:b?null:!0})?(l(g,!b),!0):!1}case"patch":return s(C.patch)?(l(g,null),!0):!1;case"clear":return s(Sg)?(l(g,null),!0):!1;case"value":return s({value:Dg(C.value,p.formats)})?(l(g,null),!0):!1;case"borders":return c(C.preset)?(l(g,null),!0):!1;case"color":{const k=C.key==="background"?p.colors.fill:p.colors.font,b=C.preset!==null?C.preset:C.custom!==null&&C.custom<k.length?k[C.custom]:void 0;if(b===void 0)return!1;const y=r(),a=Lg(y===void 0?void 0:y[C.key],b);return s({[C.key]:a?null:b})?(l(g,!a),!0):!1}case"calc":return R({text:k=>Cg(k,C.exponent),formula:k=>Rg(k,C.exponent)});case"sign":return R({text:bg,formula:vg});case"fill":return v&&C.direction==="selection"?m():h(C.direction);case"popover":return p.openPopover(C.popover),!0;case"openHyperlink":{if(p.onHyperlinkOpen!==void 0){const k=W();return k===void 0?!1:(p.onHyperlinkOpen(k,p.getActive()),!0)}return p.openPopover("link"),!0}case"pasteSpecial":return p.onPasteSpecialRequest!==void 0?(p.onPasteSpecialRequest({kind:"keyboard",cellRect:p.keyboardCellRect()}),!0):(p.paste({mode:"formats"}),!0);case"paste":return p.paste(C.options),!0;case"insertNow":{const k=C.unit==="date"?kg(p.now()):Eg(p.now());if(v)return p.insertAtCaret(k),!0;const b=p.getActive();return Qe(p.adapter,b.row,b.col)?(p.rejectReadOnly({kind:"edit",cell:b,editSession:"none"}),!1):p.validateCommit(b,k).ok?p.commitEdits([{row:b.row,col:b.col,text:k}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return N(C.axis,C.hide);case"resize":return X(g,C.axis,C.step);default:{const k=p.getHighlight();switch(C.target){case"row":return p.setHighlight({...k,row:!k.row}),!0;case"column":return p.setHighlight({...k,column:!k.column}),!0;case"both":{const b=k.row&&k.column;return p.setHighlight({...k,row:!b,column:!b}),!0}default:return p.setHighlight({...k,intersection:!k.intersection}),!0}}}},[z,I,W,r,s,l,c,R,h,m,N,X]),O=i.useCallback(()=>{const g=t.current;return!(g.isEditing()&&!g.requestCommit())},[]),T=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const C=g===null?null:an(g);if(g!==null&&C===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(g)}`);if(!O())return!1;const v=p.getActive();return Qe(p.adapter,v.row,v.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:v.row,col:v.col,hyperlink:C}],{source:"annotate"})!==null},[O]),F=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!O())return!1;const C=p.getActive();return Qe(p.adapter,C.row,C.col)?(p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1):p.commitEdits([{row:C.row,col:C.col,note:g}],{source:"annotate"})!==null},[O]),H=i.useCallback(g=>{const p=t.current,C=p.adapter.getCellComments;if(C===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!O())return!1;const v=p.getActive();if(Qe(p.adapter,v.row,v.col))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),!1;const k=C(v.row,v.col),b=k===void 0?[g]:[...k,g];return p.commitEdits([{row:v.row,col:v.col,comments:b}],{source:"annotate"})!==null},[O]),$=i.useCallback(g=>{const p=t.current;if(p.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!O())return!1;const C=p.getSelection().ranges;if(!hr("annotate",C,p.maxOperationCells,p.onOperationRejected))return!1;if(Wn(p.adapter,C))return p.rejectReadOnly({kind:"operation",op:"annotate",cellCount:Mt(C)}),!1;const v=[];return tn(C,k=>{v.push({row:k.row,col:k.col,validation:g})}),p.commitEdits(v,{source:"annotate"})!==null},[O]),_=i.useCallback(g=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(g)},[s]),x=i.useCallback((g,p)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(g,p)},[c]);return i.useMemo(()=>({executeCommand:Y,applyFormat:_,setBorders:x,setHyperlink:T,setNote:F,addComment:H,setValidation:$,isCommandAvailable:z}),[Y,_,x,T,F,H,$,z])},eo="data-aqsp-pointing",Mg=(e,t)=>{const n=ea(e,t);return n!==null&&"insertAt"in n},Ng=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Fg=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(Bt),m=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||!c.current||a===null)return null;const f=ea(a.value,a.selectionStart);return f===null?null:{sink:a,target:f}},[]),R=i.useCallback(()=>{const y=t.current.sinkRef.current;if(y===null)return;const a=m()!==null;a!==y.hasAttribute(eo)&&(a?y.setAttribute(eo,""):y.removeAttribute(eo))},[m]),N=i.useCallback((y,a)=>{const f=t.current;if(f.resolveEditPaint===void 0)return;const E=f.resolveEditPaint(a),d=E===null?Bt:E;d!==Bt&&Object.assign(y.style,d.style),h.current=d,f.editPaintRef!==void 0&&(f.editPaintRef.current=d)},[]),W=i.useCallback(y=>{Ng(y,Object.keys(h.current.style)),h.current=Bt;const a=t.current.editPaintRef;a!==void 0&&(a.current=Bt)},[]),z=i.useCallback(y=>{const a=t.current,f=n.current;if(f===null)return!0;const E=()=>{n.current=null,u.current=null;const d=a.sinkRef.current;d!==null&&(d.style.removeProperty("text-align"),W(d),d.removeAttribute(eo)),o(!1)};if(y.commit){const d=a.sinkRef.current,L=d===null?"":d.value,A=Jn(a.adapter,f.cell.row,f.cell.col).text.replace(/\r\n?/g,`
|
|
13
|
+
`),M=L===A;let B;if(M)B=!0;else if(Qe(a.adapter,f.cell.row,f.cell.col))a.rejectReadOnly({kind:"edit",cell:f.cell,editSession:y.onReject==="keep"?"kept":"discarded"}),B=!1;else{const j={source:"edit",editSession:y.onReject==="keep"?"kept":"discarded"};B=(a.validateCommit===void 0||a.validateCommit(f.cell,L).ok)&&a.commitEdits([{row:f.cell.row,col:f.cell.col,text:L}],j)!==null}if(!B)return y.onReject==="discard"&&(E(),a.rearmSink()),!1}return E(),y.rearm&&a.rearmSink(),!0},[W]),I=i.useCallback((y,a)=>{const f=t.current;if(f.isDragging()||n.current!==null)return;const E=f.sinkRef.current;if(E===null)return;const d=f.getActive();if(Qe(f.adapter,d.row,d.col)){f.rejectReadOnly({kind:"edit",cell:d,editSession:"none"});return}if(f.discardClip(),f.ensureCellVisible(d),y==="edit"){const{text:A,isFormula:M}=Jn(f.adapter,d.row,d.col);E.value=A;const B=a===void 0||M?A.length:Math.min(a,A.length);E.setSelectionRange(B,B)}else E.value="";const L=f.resolveEditAlign(d);L!==null&&(E.style.textAlign=L),N(E,d),c.current=!1,u.current=null,n.current={cell:d,mode:y},o(!0)},[N]),X=i.useCallback(()=>{z({rearm:!0,commit:!1})},[z]),Y=i.useCallback(()=>{const y=t.current;if(n.current===null)return!0;const a=y.sinkRef.current;if(s.current&&a!==null){l.current=!0;try{a.blur()}finally{l.current=!1}return z({rearm:!1,commit:!0,onReject:"keep"})?(y.focusSink(),y.rearmSink(),!0):(y.focusSink(),!1)}return z({rearm:!0,commit:!0,onReject:"keep"})},[z]),O=i.useCallback(()=>m()!==null,[m]),T=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,R(),!0),[R]),F=i.useCallback(()=>{const y=m(),a=n.current;if(y===null||a===null)return null;if("insertAt"in y.target)return u.current=a.cell,{origin:a.cell,cursor:a.cell,axis:"cells"};const f=Qc(y.sink.value,y.sink.selectionStart);if(f===null)return null;const E=f.token,d=u.current;switch(E.kind){case"cell":{const L={row:E.row,col:E.col};return u.current=L,{origin:L,cursor:L,axis:"cells"}}case"range":{const L=d!==null&&(d.row===E.start.row||d.row===E.end.row)&&(d.col===E.start.col||d.col===E.end.col)?{row:d.row,col:d.col}:{row:E.start.row,col:E.start.col};return u.current=L,{origin:L,cursor:{row:L.row===E.start.row?E.end.row:E.start.row,col:L.col===E.start.col?E.end.col:E.start.col},axis:"cells"}}case"column":{const L=d!==null&&(d.col===E.start.col||d.col===E.end.col)?d.col:E.start.col,A={row:a.cell.row,col:L};return u.current=A,{origin:A,cursor:{row:a.cell.row,col:L===E.start.col?E.end.col:E.start.col},axis:"columns"}}case"row":{const L=d!==null&&(d.row===E.start.row||d.row===E.end.row)?d.row:E.start.row,A={row:L,col:a.cell.col};return u.current=A,{origin:A,cursor:{row:L===E.start.row?E.end.row:E.start.row,col:a.cell.col},axis:"rows"}}}},[m]),H=i.useCallback((y,a)=>{const f=m();if(f===null)return;const E=Yf(y,a),{sink:d}=f,[L,A]="replace"in f.target?f.target.replace:[f.target.insertAt,f.target.insertAt],M=d.value;d.value=`${M.slice(0,L)}${E}${M.slice(A)}`;const B=L+E.length;d.setSelectionRange(B,B),"row"in y&&(u.current={row:y.row,col:y.col}),R()},[m,R]),$=i.useCallback(()=>{const y=t.current.sinkRef.current;return y===null?null:{value:y.value,selectionStart:y.selectionStart,selectionEnd:y.selectionEnd}},[]),_=i.useCallback(y=>{const a=t.current.sinkRef.current;a!==null&&(a.value=y.value,a.setSelectionRange(y.selectionStart,y.selectionEnd),u.current=null,R())},[R]),x=i.useCallback(()=>{const y=t.current,a=y.sinkRef.current;if(y.adapter.getCellFormula===void 0||n.current===null||a===null)return!1;const f=np(a.value,a.selectionStart);return f===null?!1:(a.value=f.text,a.setSelectionRange(f.caret,f.caret),R(),!0)},[R]),g=i.useCallback(y=>{const a=t.current.sinkRef.current;if(n.current===null||a===null)return;const f=a.selectionStart,E=a.selectionEnd;a.value=`${a.value.slice(0,f)}${y}${a.value.slice(E)}`;const d=f+y.length;a.setSelectionRange(d,d),u.current=null,R()},[R]),p=i.useCallback(()=>{const y=t.current.sinkRef.current;return n.current===null||y===null?null:y.value},[]),C=i.useCallback(()=>n.current===null?null:n.current.cell,[]),v=i.useCallback(()=>{const y=t.current,a=n.current,f=y.sinkRef.current;a===null||f===null||(W(f),N(f,a.cell),y.repaintOverlay?.())},[W,N]),{enabled:k,sinkRef:b}=e;return i.useEffect(()=>{const y=b.current;if(!k||y===null)return;const a=()=>{s.current=!0},f=()=>{s.current=!1},E=A=>{const M=t.current;if(l.current||n.current===null)return;const B=M.rootRef.current,j=A.relatedTarget;B!==null&&j instanceof Node&&B.contains(j)||z({rearm:!1,commit:!0,onReject:"discard"})},d=()=>{const A=t.current;u.current=null,A.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&Mg(y.value,y.selectionStart)&&(c.current=!0),R()},L=()=>{n.current!==null&&R()};return y.addEventListener("compositionstart",a),y.addEventListener("compositionend",f),y.addEventListener("focusout",E),y.addEventListener("input",d),document.addEventListener("selectionchange",L),()=>{y.removeEventListener("compositionstart",a),y.removeEventListener("compositionend",f),y.removeEventListener("focusout",E),y.removeEventListener("input",d),document.removeEventListener("selectionchange",L)}},[k,b,z,R]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:Y,cancelEdit:X,startEdit:I,getPointing:O,togglePointingArm:T,getReferenceCursor:F,insertReference:H,captureSink:$,restoreSink:_,cycleAnchorAtCaret:x,insertAtCaret:g,getSessionText:p,getSessionCell:C,refreshPaint:v,editing:r}),[Y,X,I,O,T,F,H,$,_,x,g,p,C,v,r])},Pg=(e,t,n)=>{const r=new lt.FenwickMapTree(e,t);let o=0;if(n)for(let s=0;s<e;s+=1){const l=Math.round(n(s));l!==t&&r.update(s,l),l===0&&(o+=1)}return{tree:r,initialHidden:o}},_g=(e,t,n)=>{const{tree:r,initialHidden:o}=Pg(e,t,n);let s=o;const u={count:e,sizeOf:h=>r.get(h),offsetOf:h=>{const{cumulative:m,currentValue:R}=r.prefixSum(h);return m-R},indexAt:h=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const m=Math.floor(h),R=Math.min(Math.max(m,0),r.getTotal()-1);return r.findIndexAtOrAfter(R+.5).index},totalSize:()=>r.getTotal(),resize:(h,m)=>{if(!(Number.isFinite(m)&&m>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${m}`);const R=Math.round(m);r.get(h)===0!=(R===0)&&(s+=R===0?1:-1),r.update(h,R)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:u}},sn=(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)},Un=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:sn(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=sn(e,o,1);return r},nc=(e,t,n)=>{if(!(Number.isInteger(t)&&t>0))throw new TypeError(`[spreadsheet] useAxisModel requires a positive integer defaultSize, received ${t}`);const r=i.useRef(n).current,o=i.useRef(null),s=`${e}:${t}`;return(o.current===null||o.current.key!==s)&&(o.current=_g(e,t,r)),o.current.model},Xn=256,ls=256,qg=2**32,Ig=4096,nu=Object.freeze([]),ru=["background","color","bold","italic","underline","strikethrough"],ou=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},ln=(e,t,n)=>(e.size>=Ig&&e.clear(),e.set(t,n),n),su=e=>(ou(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),lu=(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},jg=(e,t,n)=>{const r=Math.floor(t/Xn),o=Math.floor(n/ls),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*Xn,u=o*ls,h=[];for(const m of e.rules)lu(m.ranges,c,c+Xn-1,u,u+ls-1)&&h.push(m);return ln(e.buckets,s,h.length===0?nu:h)},Hg=(e,t,n)=>{const r=Math.floor(t/Xn),o=r*qg+n,s=e.columns.get(o);if(s!==void 0)return s;const l=jg(e,t,n),c=r*Xn,u=[];for(const h of l)lu(h.ranges,c,c+Xn-1,n,n)&&u.push(h);return ln(e.columns,o,u.length===0?nu:u)},Bg=(e,t)=>{for(const n of e)if(On(n,t))return!0;return!1},Us=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),to=(e,t)=>e<t?-1:e>t?1:0,rc=(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}},oc=new WeakMap,xs=e=>e===null?null:Number(e),Wg=e=>{const t=oc.get(e);if(t!==void 0)return t;const n=e.b,r={a:xs(wt(e.a)),b:n===void 0?null:xs(wt(n))};return oc.set(e,r),r},iu=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:ln(e.numbers,r,xs(wt(n())))},Vg=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Wg(e),l=iu(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return rc(e.op,to(l,s.a),c===null?null:to(l,c));const u=n(),h=e.b;return rc(e.op,to(u,e.a),h===void 0?null:to(u,h))},Yg=(e,t)=>{switch(e.op){case"contains":return t.includes(e.value);case"notContains":return!t.includes(e.value);case"startsWith":return t.startsWith(e.value);case"endsWith":return t.endsWith(e.value);default:return!1}},is=e=>{const t=st(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]},no=e=>e.toString(16).padStart(2,"0"),cs=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${no(r(0))}${no(r(1))}${no(r(2))}`,s=r(3);return s===255?o:`${o}${no(s)}`},as=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),Kg=(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=is(t.color),u=is(r.color);const h=n===void 0?void 0:is(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||u===null||h===null)return null;if(s>l){const R=s;s=l,l=R;const N=c;c=u,u=N}if(n!==void 0&&h!==void 0){const R=n.value===void 0?(s+l)/2:n.value;if(s<R&&R<l)return e<=R?cs(c,h,as(e,s,R)):cs(h,u,as(e,R,l))}return cs(c,u,as(e,s,l))},Ug=(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 ln(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 ln(r.extrema,e.id,null);c=Math.min(c,m.min),u=Math.max(u,m.max)}return ln(r.extrema,e.id,{min:c,max:u})},Xg=(e,t,n,r,o,s)=>{const l=iu(s,n,r);if(l===null)return null;const c=Ug(e,t,o,s);return c===null?null:Kg(l,t.min,t.mid,t.max,c)},Gg=(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:ln(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},Zg=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Vg(s,t,n,o)?e.style:null;case"text":return Yg(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=Xg(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return Gg(e,s,t,r,o)?e.style:null;default:return null}},sc=(e,t)=>Ms(e,t),Jg=(e,t,n)=>{e[t]=n},Qg=(e,t)=>{let n=e;for(const r of ru)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),Jg(n,r,t[r]));return n},ew=e=>{let t="";for(const n of ru){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},lc=new WeakMap,tw=Object.freeze({}),nw=e=>{const t=e===void 0?tw:e,n=lc.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return lc.set(t,r),r},rw=(e,t,n)=>{const r=nw(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const u=sc(e,t);return u!==void 0&&r.byStyle.set(t,u),u}const o=ew(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=sc(e,t);return l!==void 0&&ln(r.byKey,o,l),l},Xs=(e,t,n,r,o,s)=>{if(e.getCellFormat===void 0)return;const l=e.getCellFormat(r,o);if(t===null)return l;const c=Hg(t,r,o);if(c.length===0)return l;const u={row:r,col:o};let h=null,m=!0;for(const R of c){if(!Bg(R.ranges,u))continue;const N=Zg(R,u,s,e,n);if(N!==null){if(N!==R.style&&(m=!1),h===null)h=N;else{const W=Qg(h,N);W!==h&&(m=!1,h=W)}if(R.stopIfTrue===!0)break}}return h===null?l:rw(l,h,m)},ic=new WeakMap,ow=e=>{ou(e,"widthRelevantRules");const t=ic.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 ic.set(e,r),r},sw=({row:e,col:t,text:n,display:r,renderCell:o,__onCellRender:s})=>{const l=i.useRef(!1);if(i.useEffect(()=>{const c=l.current?"update":"mount";l.current=!0,s?.(`cell-${e}-${t}`,c,0,0,0,0)}),o!==void 0){const c=o({row:e,col:t,text:n,displayText:r});return c===void 0?r:c}return r},lw=i.memo(sw),iw=Object.freeze({left:Object.freeze({justifyContent:yr("left")}),center:Object.freeze({justifyContent:yr("center")}),right:Object.freeze({justifyContent:yr("right")})}),cw=Object.freeze({role:"rowgroup"}),aw=4096,cc=new WeakMap,ro=new Map,uw=(e,t)=>{if(e===null)return iw[t];let n=cc.get(e);n===void 0&&(n={},cc.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:yr(t)},s=JSON.stringify(o);let l=ro.get(s);return l===void 0&&(ro.size>=aw&&ro.clear(),l=Object.freeze(o),ro.set(s,l)),n[t]=l,l},dw=Us(),fw=(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},pw=(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=co(e,o,s),c={};let u=null,h;if(e.getCellFormat!==void 0){const m=Xs(e,r===null?null:r.indexRef.current,r===null?dw:r.memoRef.current,o,s,l);h=m===void 0?void 0:m.value;const R=Ca(m,l),N=sn(n,s,1),W=sn(t,o,1),z=Sf(m,N===null?void 0:e.getCellFormat(o,N),W===null?void 0:e.getCellFormat(W,s),n.offsetOf(s)===0,t.offsetOf(o)===0);z!==null&&Object.assign(c,z.attrs),c["data-aqsp-align"]=R,u=uw(z,R)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const m=e.getCellComments(o,s);m!==void 0&&m.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&Qn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const m=e.getCellValidation(o,s);m!==void 0&&Lm(m,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:u,value:h}},hw=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:u,frozenRows:h,frozenTrailingColumns:m,frozenTrailingRows:R,headerRows:N,labelledBy:W,gridLabel:z,readOnly:I,renderCell:X,onScroll:Y,onRangeChange:O,focusSink:T,isEditing:F,requestCommit:H,testId:$,__onCellRender:_,__maxRenderedCells:x,cfIndexRef:g,cfMemoRef:p,isPointing:C,tapScrollCircleOptions:v,overscanRows:k,overscanCols:b,background:y,onRenderTruncated:a,locale:f,scrollLabels:E})=>{const d=i.useRef(null),L=s??d;if(g===void 0!=(p===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const A=i.useMemo(()=>g===void 0||p===void 0?null:{indexRef:g,memoRef:p},[g,p]),M=i.useCallback(()=>r.get().editVersion,[r]),B=i.useCallback(me=>r.subscribeCoalesced(me),[r]),G=i.useSyncExternalStore(B,M,M)+(l??0),Z=i.useCallback(me=>t.sizeOf(me),[t]),Q=i.useCallback(me=>n.sizeOf(me),[n]),ne=i.useCallback((me,Me)=>e.getCellText(me,Me),[e]),ie=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),le=i.useMemo(()=>({width:Le.SPREADSHEET_SCROLLBAR_SIZE_PX,tapScrollCircleOptions:v,enableArrowButtonTabStops:!1}),[v]),Oe=i.useRef({row:-1,col:-1,value:void 0}),ze=i.useCallback((me,Me)=>{const it=me<N,Be={role:it?"columnheader":"gridcell","aria-rowindex":me+1,"aria-colindex":Me+1,"data-aqsp-cell":"","data-row":me,"data-col":Me,className:"aqsp-cell",...Qe(e,me,Me)?{"aria-readonly":"true","data-aqsp-readonly":""}:{},...it?{"data-aqsp-header-row":""}:{}},Nt=$h(e,me,Me),bt=Nt===null?Be:{...Be,...Nt},ct=pw(e,t,n,A,me,Me),et=Oe.current;return et.row=me,et.col=Me,et.value=ct===null?void 0:ct.value,ct===null?bt:ct.style===null?{...bt,...ct.attrs}:{...bt,...ct.attrs,style:ct.style}},[e,t,n,A,N]),Ne=i.useCallback(me=>({role:"row","aria-rowindex":me+1,"data-aqsp-row":me,"data-aqsp-cells":"",className:"aqsp-row"}),[]),He=i.useCallback((me,Me,it)=>{let Be=me;return e.getCellFormat!==void 0&&(Be=Gn(me,fw(Oe.current,Me,it))),K.jsx(lw,{row:Me,col:it,text:me,display:Be,renderCell:X,__onCellRender:_})},[G,X,_,e]);return K.jsx("div",{ref:L,className:"aqsp-body","data-aqsp-body":"","data-testid":$?`${$}-body`:void 0,role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-label":z,"aria-labelledby":W,"aria-readonly":I?"true":void 0,onPointerDownCapture:me=>{if(!(me.target instanceof Element&&me.target.closest("[data-aqsp-cells]")!==null)&&me.pointerType==="mouse"){if(me.button!==0){me.preventDefault();return}if(me.preventDefault(),C?.()===!0){me.stopPropagation(),T();return}if(F()&&!H()){me.stopPropagation(),T();return}T()}},children:K.jsx(lt.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:u,frozenLeadingRows:h,frozenTrailingCols:m,frozenTrailingRows:R,getRowHeight:Z,getColWidth:Q,getCell:ne,getCellProps:ze,getRowProps:Ne,contentProps:cw,behaviorOptions:ie,scrollBarOptions:le,overscanRows:k,overscanCols:b,background:y,onRenderTruncated:a,__maxRenderedCells:x,locale:f,labels:E,callbackThrottleMs:0,onScroll:Y,onRangeChange:O,testId:$,children:He})})},mw=i.memo(hw),Vn=6,gt=3,go=(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:gt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,u=sn(e,s,1);s<e.count-1&&(u===null||u>s+1)?(n.push({kind:"resize",index:s,start:c-Vn,length:gt}),r.push({kind:"unhide",index:s+1,start:c-gt,length:gt})):l>=2*Vn?n.push({kind:"resize",index:s,start:c-Vn,length:Vn}):n.push({kind:"resize",index:s,start:c-gt,length:gt})}return[...n,...r]},cu=(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:gt}),n.push({kind:"resize",index:c,start:h+gt,length:gt})):u>=2*Vn?n.push({kind:"resize",index:c,start:h,length:Vn}):n.push({kind:"resize",index:c,start:h,length:gt})}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-gt,length:gt}),[...n.reverse(),...r]},gw=({viewStore:e,colAxis:t,frozenCols:n,frozenTrailingCols:r,handleRef:o,bandRef:s,colTrackRef:l,windowOriginXRef:c,repaintColHeaders:u,selectionRanges:h,enableResizeUI:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const W=lt.useWheelBridge(o),z=i.useCallback(d=>(s.current=d,W(d)),[s,W]),I=i.useCallback(()=>{const{colStart:d,colEnd:L,colVersion:A}=e.get();return`${d}:${L}:${A}`},[e]),X=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(X,I,I);const{colStart:Y,colEnd:O}=e.get(),T=t.count===0?0:t.offsetOf(Math.min(Y,t.count-1));i.useLayoutEffect(()=>{c.current=T,u()},[T,c,u]);const F=d=>h.some(L=>d>=L.startCol&&d<=L.endCol),H=Math.min(Math.max(0,n),t.count),$=Pa(t,H),_=H>0?Un(t,0,H-1):[],x=Math.min(Math.max(0,r),t.count-H),g=qa(t,x),p=t.totalSize()-g,C=x>0?Un(t,t.count-x,t.count-1):[],v=Un(t,Math.max(Y,H),Math.min(O,Math.max(0,t.count-1)-x)),k=[];for(const d of v)k.push(K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-T,width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d));const b=m?go(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<H&&$>0||d.kind==="unhide"&&d.index>=t.count-x&&g>0)),a=m&&H>0?go(t,_):null,f=m&&x>0?cu(t,C):null,E=K.jsxs("div",{ref:l,className:"aqsp-col-header-track",children:[k,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start-T,width:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start-T,width:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:H===0&&x===0?E:K.jsxs(K.Fragment,{children:[_.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-frozen-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d),width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d)),a?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,style:{left:d.start,width:d.length}},`fr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{left:d.start,width:d.length}},`fu${d.index}`)),K.jsxs("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:$,right:x>0?`calc(${Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px + min(${g}px, max(0px, 100% - ${Le.SPREADSHEET_SCROLLBAR_SIZE_PX+$}px)))`:void 0},children:[E,H>0?K.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-v","data-aqsp-freeze-divider":"x-leading",style:{left:0,top:0,bottom:0}}):null,x>0?K.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]}),x>0?K.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-trailing":"",style:{left:`max(${$}px, calc(100% - ${g+Le.SPREADSHEET_SCROLLBAR_SIZE_PX}px))`,right:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:K.jsxs("div",{style:{position:"absolute",top:0,height:"100%",right:0,width:g},children:[C.map(d=>K.jsx("div",{className:"aqsp-col-header-cell","data-col":d,"data-aqsp-trailing-header":"","data-aqsp-in-selection":F(d)?"":void 0,style:{left:t.offsetOf(d)-p,width:t.sizeOf(d)},children:Le.columnIndexToName(d)},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{left:d.start,width:d.length}},`tu${d.index}`))]})}):null]})})},ww=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:u,frozenRows:h,frozenTrailingRows:m,dividerLeadingRef:R,dividerTrailingRef:N})=>{const W=lt.useWheelBridge(n),z=i.useCallback(d=>(r.current=d,W(d)),[r,W]),I=d=>o.some(L=>d>=L.startRow&&d<=L.endRow),X=i.useCallback(()=>{const{rowStart:d,rowEnd:L,rowGeomVersion:A}=e.get();return`${d}:${L}:${A}`},[e]),Y=i.useCallback(d=>e.subscribeCoalesced(d),[e]);i.useSyncExternalStore(Y,X,X);const{rowStart:O,rowEnd:T}=e.get(),F=t.count===0?0:t.offsetOf(Math.min(O,t.count-1));i.useLayoutEffect(()=>{l.current=F,c()},[F,l,c]);const H=Math.min(Math.max(0,h),t.count),$=_a(t,H),_=H>0?Un(t,0,H-1):[],x=Math.min(Math.max(0,m),t.count-H),g=Ia(t,x),p=t.totalSize()-g,C=x>0?Un(t,t.count-x,t.count-1):[],v=Un(t,Math.max(O,H),Math.min(T,Math.max(0,t.count-1)-x)),k=[];for(const d of v)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)-F,height:t.sizeOf(d)},children:d+1},d));const b=u?go(t,v):null,y=b===null?null:b.filter(d=>!(d.kind==="unhide"&&d.index<H&&$>0||d.kind==="unhide"&&d.index>=t.count-x&&g>0)),a=u&&H>0?go(t,_):null,f=u&&x>0?cu(t,C):null,E=K.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[k,y?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,style:{top:d.start-F,height:d.length}},`r${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,style:{top:d.start-F,height:d.length}},`u${d.index}`))]});return K.jsx("div",{ref:z,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:Le.SPREADSHEET_SCROLLBAR_SIZE_PX},children:H===0&&x===0?E:K.jsxs(K.Fragment,{children:[_.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:$,bottom:x>0?`calc(min(${g}px, max(0px, 100% - ${$}px)))`:void 0},children:[E,H>0?K.jsx("div",{ref:R,className:"aqsp-freeze-divider aqsp-freeze-divider-h","data-aqsp-freeze-divider":"y-leading",style:{top:0,left:0,right:0}}):null,x>0?K.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]}),x>0?K.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-trailing":"",style:{top:`max(${$}px, calc(100% - ${g}px))`},children:K.jsxs("div",{style:{position:"absolute",left:0,right:0,bottom:0,height:g},children:[C.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)-p,height:t.sizeOf(d)},children:d+1},d)),f?.map(d=>d.kind==="resize"?K.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tr${d.index}`):K.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":d.index,"data-aqsp-resize-anchor":"trailing",style:{top:d.start,height:d.length}},`tu${d.index}`))]})}):null]})})},Cw=9,bw=4,ac=(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},uc=(e,t,n)=>e.anchor==="trailing"?t.offsetOf(e.index)+e.initialSize-n:t.offsetOf(e.index)+n,yw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef(0),c=i.useRef(null),u=i.useRef(null),h=i.useRef(""),m=i.useRef(null),R=i.useCallback(g=>s.current!==null?g.pointerId===s.current:g.pointerType==="mouse",[]),N=i.useCallback(()=>{const g=t.current;n.current=!1,r.current=null,u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),g.writeResizeGuide(null);const p=m.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),m.current=null);const C=c.current;C!==null&&s.current!==null&&C.hasPointerCapture?.(s.current)&&C.releasePointerCapture(s.current),c.current=null,s.current=null,g.repaintOverlay()},[]),W=i.useCallback((g,p)=>{const C=t.current;return g==="col"?p.startRow===0&&p.endRow===C.rowAxis.count-1:p.startCol===0&&p.endCol===C.colAxis.count-1},[]),z=i.useCallback((g,p)=>{const C=t.current,v=C.getSelection().ranges.filter(f=>W(g,f));if(!v.some(f=>g==="col"?p>=f.startCol&&p<=f.endCol:p>=f.startRow&&p<=f.endRow))return[p];const b=v.reduce((f,E)=>f+(g==="col"?E.endCol-E.startCol+1:E.endRow-E.startRow+1),0),y=g==="row"?Math.floor(C.maxOperationCells/$s):C.maxOperationCells;if(b>y)return C.onOperationRejected?.("resize",b,"limit"),null;const a=new Set;for(const f of v){const E=g==="col"?f.startCol:f.startRow,d=g==="col"?f.endCol:f.endRow;for(let L=E;L<=d;L+=1)a.add(L)}return[...a]},[W]),I=i.useCallback((g,p,C)=>{const v=t.current,k=g==="col"?v.colAxis:v.rowAxis,b=Ls(k,p,C,{maxOperationCells:v.maxOperationCells,rowHiddenLimit:Ts,axisKind:g});return b.ok?(v.resizeTracks(g,b.entries),!0):(v.onOperationRejected?.("resize",b.count,b.reason),!1)},[]),X=i.useCallback((g,p)=>{if(p===g.initialSize)return;const C=g.kind==="unhide"?[g.index]:z(g.axis,g.index);C!==null&&I(g.axis,C.map(v=>({index:v,size:p})),g.index)},[z,I]),Y=i.useCallback((g,p,C,v)=>{const k=t.current,b=k.fontSourceRef.current;if(b===null)return!1;if(p.length===0)return!0;const y=g.length*p.length;if(y>C)return k.onOperationRejected?.("resize",y,"limit"),!1;const a=document.createElement("canvas").getContext("2d");if(a===null)return!0;const f=getComputedStyle(b),E=`${f.fontStyle} ${f.fontWeight} ${f.fontSize} ${f.fontFamily}`,d=f.getPropertyValue("--_aqsp-header-row-font-weight").trim(),L={fontStyle:f.fontStyle,fontWeight:d===""?f.fontWeight:d,fontSize:f.fontSize,fontFamily:f.fontFamily},A=`${L.fontStyle} ${L.fontWeight} ${L.fontSize} ${L.fontFamily}`,M=k.adapter.getConditionalFormats===void 0?null:ow(k.adapter.getConditionalFormats()),B=Us(),j=new WeakMap,G=new WeakMap,Z=new Map;for(const le of g){const Oe=M===null?null:su(M.filter(ze=>ze.ranges.some(Ne=>le>=Ne.startCol&&le<=Ne.endCol)));for(const ze of p){const Ne=k.adapter.getCellText(ze,le),He=k.adapter.getCellFormat===void 0?void 0:Xs(k.adapter,Oe,B,ze,le,()=>Ne),me=ze<k.headerRows,Me=He===void 0?me?A:E:me?ac(He,G,L):ac(He,j,f),it=Gn(Ne,He===void 0?void 0:He.value),Be=Z.get(Me);Be===void 0?Z.set(Me,[{col:le,text:it}]):Be.push({col:le,text:it})}}const Q=b.ownerDocument.createElement("span");Q.setAttribute("aria-hidden","true"),Q.style.position="absolute",Q.style.visibility="hidden",b.append(Q);const ne=new Map;for(const[le,Oe]of Z){a.font=le,Q.style.font=le;const ze=getComputedStyle(Q);a.letterSpacing=ze.letterSpacing==="normal"?"0px":ze.letterSpacing,a.wordSpacing=ze.wordSpacing==="normal"?"0px":ze.wordSpacing;for(const Ne of Oe){const He=a.measureText(Ne.text).width,me=ne.get(Ne.col);(me===void 0||He>me)&&ne.set(Ne.col,He)}}Q.remove();const ie=[];for(const le of g){const Oe=ne.get(le);Oe!==void 0&&Oe>0&&ie.push({index:le,size:Math.ceil(Oe)+Cw})}return ie.length===0?!0:I("col",ie,v)},[I]),O=i.useCallback(g=>{const p=t.current,C=z("col",g);if(C===null)return!1;const v=p.handleRef.current,k=v===null?null:v.getFrozenSize(),b=k===null?0:k.rows,y=k===null?0:k.trailingRows,{rowStart:a,rowEnd:f}=p.viewStore.get(),E=Math.min(f,p.rowAxis.count-1),d=[],L=new Set,A=M=>{!L.has(M)&&p.rowAxis.sizeOf(M)>0&&(L.add(M),d.push(M))};for(let M=0;M<b;M+=1)A(M);for(let M=a;M<=E;M+=1)A(M);for(let M=p.rowAxis.count-y;M<p.rowAxis.count;M+=1)A(M);return Y(C,d,Math.floor(p.maxOperationCells/bw),g)},[z,Y]),T=i.useCallback((g,p,C)=>{const v=g==="col"?t.current.colAxis:t.current.rowAxis,k=Uu(v.sizeOf(p),C);if(k===v.sizeOf(p))return!0;const b=z(g,p);return b===null?!1:I(g,b.map(y=>({index:y,size:k})),p)},[z,I]),F=i.useCallback(g=>{const p=t.current;return p.autofitEnabled?p.colAxis.sizeOf(g)===0?!0:O(g):!1},[O]),H=i.useCallback(g=>{const p=t.current;if(!p.autofitEnabled)return!1;const C=[...new Set(g)].filter(k=>p.colAxis.sizeOf(k)>0);if(C.length===0)return!0;const v=[];for(let k=0;k<p.rowAxis.count;k+=1)p.rowAxis.sizeOf(k)>0&&v.push(k);return Y(C,v,p.maxOperationCells,null)},[Y]),{enabled:$,colBandRef:_,rowBandRef:x}=e;return i.useEffect(()=>{const g=_.current,p=x.current;if(!$||g===null||p===null)return;const C=j=>j==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",v=(j,G)=>{if(!(G instanceof Element))return null;const Z=G.closest(C(j));if(Z===null)return null;const Q=Z.hasAttribute("data-aqsp-unhide"),ne=Number(Z.getAttribute(Q?"data-aqsp-unhide":j==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize")),ie=Z.hasAttribute("data-aqsp-resize-anchor")?"trailing":"leading";return{kind:Q?"unhide":"resize",index:ne,anchor:ie}},k=j=>{if(!(n.current&&R(j)))return;const G=r.current;if(G===null)return;const Z=(G.axis==="col"?j.clientX-G.startClientX:j.clientY-G.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(G.anchor==="trailing"?G.initialSize-Z:G.initialSize+Z)),u.current===null&&(u.current=requestAnimationFrame(()=>{u.current=null;const Q=r.current;if(!n.current||Q===null)return;const ne=t.current,ie=Q.axis==="col"?ne.colAxis:ne.rowAxis;ne.writeResizeGuide({axis:Q.axis,position:uc(Q,ie,o.current),anchor:Q.anchor})}))},b=()=>{const j=r.current,G=o.current;N(),j!==null&&X(j,G)},y=j=>{k(j),n.current&&R(j)&&(l.current&1)!==0&&(j.buttons&1)===0&&b()},a=j=>{j.button!==0||!(n.current&&R(j))||b()},f=(j,G)=>Z=>{const Q=t.current;if(h.current=Z.pointerType,Z.pointerType!=="mouse")return;if(Z.button!==0){Z.preventDefault();return}const ne=v(j,Z.target);if(ne===null)return;if(Z.stopPropagation(),Z.preventDefault(),Q.isPointing()){Q.focusSink();return}if(Q.isEditing()&&!Q.requestCommit()){Q.focusSink();return}Q.focusSink();const ie=j==="col"?Q.colAxis:Q.rowAxis,le={axis:j,kind:ne.kind,index:ne.index,anchor:ne.anchor,initialSize:ie.sizeOf(ne.index),startClientX:Z.clientX,startClientY:Z.clientY};r.current=le,o.current=le.initialSize,l.current=Z.buttons,n.current=!0,Q.repaintOverlay(),s.current=Z.pointerId,c.current=G;try{G.setPointerCapture(Z.pointerId)}catch{s.current=null}const Oe=y,ze=a;m.current={move:Oe,up:ze},window.addEventListener("pointermove",Oe),window.addEventListener("pointerup",ze),Q.writeResizeGuide({axis:j,position:uc(le,ie,o.current),anchor:le.anchor})},E=(j,G)=>Z=>{const Q=t.current;if(h.current!=="mouse")return;const ne=G.getRootNode(),ie=ne instanceof ShadowRoot?ne:G.ownerDocument,le=Z.target instanceof Element&&Z.target.closest(C(j))!==null?Z.target:typeof ie.elementFromPoint=="function"?ie.elementFromPoint(Z.clientX,Z.clientY):null,Oe=v(j,le);if(Oe!==null){if(Z.stopPropagation(),Q.isEditing()){Q.focusSink();return}if(Oe.kind==="unhide"){I(j,[{index:Oe.index,size:j==="col"?Q.defaultColumnWidth:Q.defaultRowHeight}],null);return}if(Q.autofitEnabled){if(j==="row"){const ze=z("row",Oe.index);ze!==null&&I("row",ze.map(Ne=>({index:Ne,size:Q.defaultRowHeight})),Oe.index);return}O(Oe.index)}}},d=j=>{!n.current||s.current===null||j.pointerId!==s.current||N()},L=f("col",g),A=f("row",p),M=E("col",g),B=E("row",p);return g.addEventListener("pointerdown",L,{capture:!0}),p.addEventListener("pointerdown",A,{capture:!0}),g.addEventListener("dblclick",M),p.addEventListener("dblclick",B),g.addEventListener("lostpointercapture",d),p.addEventListener("lostpointercapture",d),()=>{g.removeEventListener("pointerdown",L,{capture:!0}),p.removeEventListener("pointerdown",A,{capture:!0}),g.removeEventListener("dblclick",M),p.removeEventListener("dblclick",B),g.removeEventListener("lostpointercapture",d),p.removeEventListener("lostpointercapture",d),N()}},[$,_,x,R,N,X,I,z,O]),i.useMemo(()=>({stepTrack:T,autofitColumn:F,autofitColumnsInAllRows:H,isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&N()},cancelDrag:N}),[N,T,F,H])},Gs=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Rw=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Gs(n,t.ranges[r]))&&Yt(e.anchor,t.anchor)&&Yt(e.active,t.active),vw=(e,t,n)=>{const r=l=>l.row<t&&l.col<n,o=l=>l.endRow<t&&l.endCol<n;if(r(e.anchor)&&r(e.active)&&e.ranges.every(o))return e;const s=l=>un(l,t,n);return{ranges:e.ranges.map(l=>o(l)?l:ve(s({row:l.startRow,col:l.startCol}),s({row:l.endRow,col:l.endCol}))),anchor:r(e.anchor)?e.anchor:s(e.anchor),active:r(e.active)?e.active:s(e.active)}},Sw=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Gs(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Or=(e,t,n)=>n.extend?vn(e,t):n.append?{ranges:[...e.ranges,ve(t,t)],anchor:t,active:t}:e.ranges.length===1&&Yt(e.anchor,t)&&Yt(e.active,t)&&Gs(e.ranges[0],ve(t,t))?e:{ranges:[ve(t,t)],anchor:t,active:t},kw=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),vn=(e,t)=>{const n=Sw(e,ve(e.anchor,t));return n.ranges.some(r=>On(r,n.active))?n:{...n,active:kw(n.active,n.ranges[n.ranges.length-1])}},au=(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(ve({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(ve({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(ve({row:u,col:c.startCol},{row:h,col:t.startCol-1})),t.endCol<c.endCol&&o.push(ve({row:u,col:t.endCol+1},{row:h,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[ve(n,n)],anchor:n,active:n};const s=o.findIndex(c=>On(c,e.active));if(s>=0){const[c]=o.splice(s,1);return o.push(c),{ranges:o,anchor:e.active,active:e.active}}const l={row:o[o.length-1].startRow,col:o[o.length-1].startCol};return{ranges:o,anchor:l,active:l}},Ew=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,u=e[c];return{rangeIndex:c,cell:{row:u.startRow,col:u.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},uu=(e,t)=>{const n=e.ranges.findIndex(o=>On(o,e.active));if(n===-1)throw new RangeError("[spreadsheet] reduceActiveCycle requires active inside some range (invariant violation)");let r={rangeIndex:n,cell:e.active};do if(r=Ew(e.ranges,r.rangeIndex,r.cell,t),!Yt(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},Ht=24,dc=32,wo=4,qn=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),u=i.useRef(null),h=i.useRef(null),m=i.useRef(null),R=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),u.current=null,m.current=null,h.current=null},[]),N=i.useCallback(()=>{const z=u.current,I=e.current,X=m.current;if(z===null||I===null||X===null){c.current=null;return}const{clientX:Y,clientY:O}=z.getPointerPosition(),T=l.current,F=(Y-X.left)/T,H=(O-X.top)/T,$=I.getViewportSize(),_=$.width,x=$.height;if(_<=0||x<=0){c.current=requestAnimationFrame(N);return}const g=y=>Math.min(dc,Math.ceil(y/Ht*dc));let p=0,C=0;if(s!=="x"){const y=I.getFrozenSize(),a=y.trailingVisibleHeight;H>x-a-Ht?z.anchorRow!==void 0&&y.trailingRows>0&&z.anchorRow>=t.count-y.trailingRows&&a>0&&H>=x-a||(p=g(H-(x-a-Ht))):H<y.height+Ht&&(z.anchorRow!==void 0&&z.anchorRow<y.rows&&y.height>0&&H<y.height||(p=-g(y.height+Ht-H)))}if(s!=="y"){const y=I.getFrozenSize(),a=y.trailingVisibleWidth;F>_-a-Ht?z.anchorCol!==void 0&&y.trailingCols>0&&z.anchorCol>=n.count-y.trailingCols&&a>0&&F>=_-a||(C=g(F-(_-a-Ht))):F<y.width+Ht&&(z.anchorCol!==void 0&&z.anchorCol<y.cols&&y.width>0&&F<y.width||(C=-g(y.width+Ht-F)))}const v=C!==0||p!==0?I.scrollBy({x:C!==0?C:void 0,y:p!==0?p:void 0}):I.getScrollPosition(),k=v.y,b=v.x;if(k>=0&&b>=0&&t.totalSize()>0&&n.totalSize()>0){const y=I.getFrozenSize(),a=un({row:Dr(t,H,{scroll:k,frozenSize:y.height,trailingSize:y.trailingHeight,extent:$.height}),col:Lr(n,F,{scroll:b,frozenSize:y.width,trailingSize:y.trailingWidth,extent:$.width})},t.count,n.count),f=h.current;(p!==0||C!==0||f===null||f.row!==a.row||f.col!==a.col)&&(h.current=a,o(z.buildRange(a)))}c.current=requestAnimationFrame(N)},[e,t,n,s,o]),W=i.useCallback(z=>{R(),u.current=z,m.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(N)},[R,N,r]);return i.useEffect(()=>{const z=()=>{document.visibilityState==="hidden"&&R()};return document.addEventListener("visibilitychange",z),()=>{document.removeEventListener("visibilitychange",z),R()}},[R]),i.useMemo(()=>({start:W,stop:R}),[W,R])},fc=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(0),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(!1),N=i.useRef(0),W=i.useCallback(($,_)=>{const{axis:x,mainAxis:g,handleRef:p,zoomRef:C}=t.current,v=s.current;if(v===null||g.totalSize()===0)return null;const k=C.current,b=p.current;if(b===null)return null;if(x==="col"){const E=b.getScrollPosition().x;if(E<0)return null;const d=b.getFrozenSize(),L=b.getViewportSize();return Math.min(Math.max(Lr(g,($-v.left)/k,{scroll:E,frozenSize:d.width,trailingSize:d.trailingWidth,extent:L.width}),0),g.count-1)}const y=b.getScrollPosition().y;if(y<0)return null;const a=b.getFrozenSize(),f=b.getViewportSize();return Math.min(Math.max(Dr(g,(_-v.top)/k,{scroll:y,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),0),g.count-1)},[]),z=i.useCallback(($,_)=>{const{axis:x,crossCount:g}=t.current;return x==="col"?{press:{row:0,col:$},extend:{row:g-1,col:_}}:{press:{row:$,col:0},extend:{row:_,col:g-1}}},[]),I=i.useCallback(($,_)=>{const{axis:x,crossCount:g}=t.current;return $.ranges.some(p=>x==="col"?p.startRow===0&&p.endRow===g-1&&_>=p.startCol&&_<=p.endCol:p.startCol===0&&p.endCol===g-1&&_>=p.startRow&&_<=p.endRow)},[]),X=i.useRef(!1),Y=i.useRef({clientX:0,clientY:0}),O=i.useCallback(()=>{X.current=!1;const{autoScroller:$,headerRef:_,onDragFrame:x}=t.current;n.current=!1,r.current=null,m.current=null,R.current=!1,N.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),$.stop();const g=_.current;g!==null&&u.current!==null&&g.hasPointerCapture?.(u.current)&&g.releasePointerCapture(u.current),u.current=null,x(null),t.current.repaintOverlay()},[]),T=i.useCallback(()=>{if(!n.current)return;const $=r.current;$!==null&&t.current.setSelection($),O()},[O]),{enabled:F,headerRef:H}=e;return i.useEffect(()=>{const $=H.current;if(!F||$===null)return;const _=b=>{const y=t.current;if(b.pointerType!=="mouse")return;if(b.button!==0){b.preventDefault();return}if(R.current=!1,y.pointing?.getPointing()){s.current=$.getBoundingClientRect();const d=W(b.clientX,b.clientY);if(d===null)return;b.preventDefault(),y.focusSink(),y.pointing.insertReference(y.axis==="col"?{row:0,col:d}:{row:d,col:0},y.axis==="col"?"columns":"rows");return}if(y.isEditing()&&!y.requestCommit()){b.preventDefault(),y.focusSink();return}s.current=$.getBoundingClientRect();const a=W(b.clientX,b.clientY);if(a===null)return;b.preventDefault(),y.focusSink();const f=y.getSelection();r.current=f;const E=b.ctrlKey||b.metaKey;if(b.shiftKey){const d=y.axis==="col"?{row:0,col:f.anchor.col}:{row:f.anchor.row,col:0},{extend:L}=z(a,a),A={...f,anchor:d};y.setSelection(vn(A,L)),o.current=y.axis==="col"?d.col:d.row}else if(E&&I(f,a))R.current=!0,N.current=a,o.current=a;else{const{press:d,extend:L}=z(a,a),A=Or(f,d,{extend:!1,append:E});y.setSelection(vn(A,L)),o.current=a}n.current=!0,y.repaintOverlay(),l.current={clientX:b.clientX,clientY:b.clientY},u.current=b.pointerId,h.current=b.buttons;try{$.setPointerCapture(b.pointerId)}catch{u.current=null}m.current=d=>{const L=t.current.axis==="col"?d.col:d.row,{press:A}=z(o.current,o.current),{extend:M}=z(o.current,L);return ve(A,M)},y.autoScroller.stop(),X.current=!1,Y.current={clientX:b.clientX,clientY:b.clientY}},x=b=>u.current!==null?b.pointerId===u.current:b.pointerType==="mouse",g=b=>{if(n.current&&x(b)){if(R.current){const y=b.clientX!==l.current.clientX||b.clientY!==l.current.clientY;if(l.current={clientX:b.clientX,clientY:b.clientY},!y)return;const a=W(b.clientX,b.clientY);if(a===null||a===N.current)return;R.current=!1;const f=t.current,{press:E,extend:d}=z(N.current,N.current),L=Or(f.getSelection(),E,{extend:!1,append:!0});f.setSelection(vn(L,d));const A=m.current,M=Math.abs(b.clientX-Y.current.clientX),B=Math.abs(b.clientY-Y.current.clientY);A!==null&&Math.max(M,B)>=wo&&(X.current=!0,f.autoScroller.start({getPointerPosition:()=>l.current,buildRange:A,anchorCol:f.axis==="col"?o.current:void 0,anchorRow:f.axis==="row"?o.current:void 0}))}else if(l.current={clientX:b.clientX,clientY:b.clientY},!X.current&&m.current!==null){const y=Math.abs(b.clientX-Y.current.clientX),a=Math.abs(b.clientY-Y.current.clientY);Math.max(y,a)>=wo&&(X.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:m.current,anchorCol:t.current.axis==="col"?o.current:void 0,anchorRow:t.current.axis==="row"?o.current:void 0}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const y=m.current;if(!n.current||y===null)return;const a=W(l.current.clientX,l.current.clientY);a!==null&&t.current.onDragFrame(y(t.current.axis==="col"?{row:0,col:a}:{row:a,col:0}))}))}},p=b=>{g(b),n.current&&x(b)&&(h.current&1)!==0&&(b.buttons&1)===0&&v(b)},C=b=>{b.button!==0||!(n.current&&x(b))||v(b)},v=b=>{const y=t.current;if(R.current){const{press:f,extend:E}=z(N.current,N.current);y.setSelection(au(y.getSelection(),ve(f,E),f)),O();return}const a=W(b.clientX,b.clientY);if(a!==null){const{extend:f}=z(o.current,a);y.setSelection(vn(y.getSelection(),f))}O()},k=b=>{!n.current||u.current===null||b.pointerId!==u.current||T()};return $.addEventListener("pointerdown",_),$.addEventListener("pointermove",p),$.addEventListener("pointerup",C),$.addEventListener("lostpointercapture",k),()=>{$.removeEventListener("pointerdown",_),$.removeEventListener("pointermove",p),$.removeEventListener("pointerup",C),$.removeEventListener("lostpointercapture",k),O()}},[F,H,W,z,O,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:T,cancelDrag:O}),[T,O])},Ow=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:u}=o.getViewportSize();if(l<0||s<0)return;const h=o.getFrozenSize();if(u>0&&r.row>=h.rows&&r.row<t.count-h.trailingRows){const m=t.offsetOf(r.row),R=m+t.sizeOf(r.row);m<h.height+l?o.scrollBy({y:m-(h.height+l)}):R>l+u-h.trailingVisibleHeight&&o.scrollBy({y:R-(l+u-h.trailingVisibleHeight)})}if(c>0){if(r.col<h.cols||r.col>=n.count-h.trailingCols)return;const m=n.offsetOf(r.col),R=m+n.sizeOf(r.col);m<h.width+s?o.scrollBy({x:m-(h.width+s)}):R>s+c-h.trailingVisibleWidth&&o.scrollBy({x:R-(s+c-h.trailingVisibleWidth)})}},Aw=50,xw=100,du=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Aw:!1,mr={selectAll:nn("Ctrl+A"),undo:nn("Ctrl+Z"),redo:nn("Ctrl+Y"),redoShiftZ:nn("Ctrl+Shift+Z"),pasteValues:nn("Ctrl+Shift+V")},Tw=new Set(["Shift","Control","Alt","Meta","AltGraph"]),$w={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},Lw=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",Dw=e=>{const t=i.useRef(null),n=i.useRef(null),r=i.useRef(!1),o=i.useRef(!1),s=i.useRef(e);s.current=e;const{enabled:l,sinkRef:c,rootRef:u,handleRef:h}=e;i.useEffect(()=>{const m=c.current,R=u.current;if(!l||m===null||R===null)return;const N=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},W=(a,f,E)=>sn(a,f,E)??f,z=(a,f)=>{const E=s.current;return f==="left"||f==="right"?{row:a.row,col:W(E.colAxis,a.col,f==="right"?1:-1)}:{row:W(E.rowAxis,a.row,f==="down"?1:-1),col:a.col}},I=a=>a.indexAt(0),X=a=>a.indexAt(a.totalSize()-1),Y=(a,f,E,d)=>{if(a.sizeOf(f)>0)return f;const L=sn(a,f,E);if(L!==null)return L;const A=sn(a,f,E===1?-1:1);return A!==null?A:d},O=()=>{const a=s.current.getSelection(),f=a.ranges[a.ranges.length-1];return{row:a.anchor.row===f.startRow?f.endRow:f.startRow,col:a.anchor.col===f.startCol?f.endCol:f.startCol}},T=a=>z(O(),a),F=(a,f)=>{const E=s.current,d=f==="left"||f==="right",L=f==="right"||f==="down"?1:-1;let A;return E.findDataEdge!==void 0?(A=E.findDataEdge({row:a.row,col:a.col},f),H(A,a,f)):A={row:f==="down"?E.rowAxis.count-1:f==="up"?0:a.row,col:f==="right"?E.colAxis.count-1:f==="left"?0:a.col},d?{row:A.row,col:Y(E.colAxis,A.col,L,a.col)}:{row:Y(E.rowAxis,A.row,L,a.row),col:A.col}},H=(a,f,E)=>{const d=s.current;if(!(Number.isInteger(a.row)&&Number.isInteger(a.col)&&a.row>=0&&a.row<d.rowAxis.count&&a.col>=0&&a.col<d.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${a.row}, col: ${a.col}} for a ${d.rowAxis.count} x ${d.colAxis.count} grid`);const L=E==="left"||E==="right";if(L?a.row!==f.row:a.col!==f.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${L?"row":"column"} (received {row: ${a.row}, col: ${a.col}} from {row: ${f.row}, col: ${f.col}})`)},$=(a,f,E)=>{if(!(Number.isInteger(a)&&a>=0&&a<f))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${E} component ${a} (count ${f})`)},_=a=>{const f=s.current,E=f.getSelection();if(uu(E,a)===E){f.moveActive({mode:"reset",cell:z(E.active,a)});return}f.moveActive({mode:"cycle",direction:a})},x=()=>{const a=c.current;if(a===null)return;const f=a.selectionStart??a.value.length,E=a.selectionEnd??f;a.value=`${a.value.slice(0,f)}
|
|
14
|
+
${a.value.slice(E)}`,a.setSelectionRange(f+1,f+1)},g=(a,f)=>{const E=s.current,d=E.pageExtent();if(d<=0)return W(E.rowAxis,a,f==="down"?1:-1);const L=E.rowAxis.indexAt(E.rowAxis.offsetOf(a)+(f==="down"?d:-d));return L===a?W(E.rowAxis,a,f==="down"?1:-1):L},p=a=>{const f=s.current;if(r.current=!1,du(a,t.current))return;const E=a.ctrlKey||a.metaKey,d=a.altKey,L=$w[a.key];if(o.current&&!Tw.has(a.key)&&!f.isDragging()&&N(),f.isEditing()){const M=f.getEditingMode();if(f.isDragging()){a.preventDefault(),a.key==="Escape"&&!E&&!a.shiftKey&&!d&&f.abortDrag();return}const B=f.pointing;if(B!==void 0){if(L!==void 0&&!d){const G=B.getReferenceCursor();if(G!==null){a.preventDefault();const Z=un(G.cursor,f.rowAxis.count,f.colAxis.count),Q=un(G.origin,f.rowAxis.count,f.colAxis.count),ne=E?F(Z,L):z(Z,L);if(f.ensureCellVisible(ne),B.insertReference(a.shiftKey?ve(Q,ne):ne,G.axis),f.onPointFrame!==void 0){const ie=a.shiftKey?ve(Q,ne):ve(ne,ne);f.onPointFrame(G.axis==="columns"?ve({row:0,col:ie.startCol},{row:f.rowAxis.count-1,col:ie.endCol}):G.axis==="rows"?ve({row:ie.startRow,col:0},{row:ie.endRow,col:f.colAxis.count-1}):ie),o.current=!0}return}}if(a.key==="F2"&&!E&&!a.shiftKey&&!d&&B.togglePointingArm()){a.preventDefault();return}if(a.key==="F4"&&!E&&!a.shiftKey&&!d&&B.cycleAnchorAtCaret()){a.preventDefault();return}}const j=f.commands;if(j!==void 0){const G=gi(j.table,a);if(G!==null&&Ys.has(G)&&j.isAvailable(G)){a.preventDefault(),j.execute(G);return}}if(L!==void 0&&!d){if(E&&a.shiftKey){a.preventDefault();return}if(E)return;if(M==="replace"){if(a.preventDefault(),!f.requestCommit())return;a.shiftKey?f.moveActive({mode:"extend",cell:T(L)}):f.moveActive({mode:"reset",cell:z(f.getSelection().active,L)});return}return}if(a.key==="Enter"&&d&&!E&&!a.shiftKey){a.preventDefault(),x();return}if((a.key==="Enter"||a.key==="Tab")&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const G=!a.shiftKey;_(a.key==="Tab"?G?"right":"left":G?"down":"up");return}if((a.key==="PageUp"||a.key==="PageDown")&&!a.shiftKey&&!E&&!d){if(a.preventDefault(),!f.requestCommit())return;const G=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(G.row,a.key==="PageDown"?"down":"up"),col:G.col}});return}if(a.key==="Escape"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.cancelEdit();return}return}if(a.defaultPrevented)return;if(f.isDragging()&&a.key!=="Escape"){a.preventDefault();return}const A=f.commands;if(A!==void 0){const M=gi(A.table,a);if(M!==null&&A.isAvailable(M)){a.preventDefault(),A.execute(M);return}}if(L!==void 0&&!d){const M=L==="left"||L==="right",B=L==="right"||L==="down"?1:-1;if(E&&a.shiftKey){a.preventDefault();const j=f.getSelection(),G=O();let Z;if(f.findDataEdge!==void 0){const Q=M?{row:j.active.row,col:G.col}:{row:G.row,col:j.active.col},ne=f.findDataEdge(Q,L);Z=M?ne.col:ne.row,$(Z,M?f.colAxis.count:f.rowAxis.count,M?"col":"row"),Z=Y(M?f.colAxis:f.rowAxis,Z,B,M?G.col:G.row)}else{const Q=M?f.colAxis:f.rowAxis;Z=B===1?X(Q):I(Q)}f.moveActive({mode:"extend",cell:M?{row:G.row,col:Z}:{row:Z,col:G.col}});return}if(E){a.preventDefault(),f.moveActive({mode:"reset",cell:F(f.getSelection().active,L)});return}if(a.shiftKey){a.preventDefault(),f.moveActive({mode:"extend",cell:T(L)});return}a.preventDefault(),f.moveActive({mode:"reset",cell:z(f.getSelection().active,L)});return}if(Lw(a)){a.preventDefault();return}if((a.key==="Tab"||a.key==="Enter")&&!E&&!d){a.preventDefault();const M=!a.shiftKey;_(a.key==="Tab"?M?"right":"left":M?"down":"up");return}if(a.key==="Home"&&!d){if(a.preventDefault(),a.shiftKey){const B=O();f.moveActive({mode:"extend",cell:{row:E?I(f.rowAxis):B.row,col:I(f.colAxis)}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?I(f.rowAxis):M.row,col:I(f.colAxis)}});return}if(a.key==="End"&&!d){if(a.preventDefault(),a.shiftKey){const B=O();f.moveActive({mode:"extend",cell:{row:E?X(f.rowAxis):B.row,col:X(f.colAxis)}});return}const M=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:E?X(f.rowAxis):M.row,col:X(f.colAxis)}});return}if((a.key==="PageUp"||a.key==="PageDown")&&!E&&!d){a.preventDefault();const M=a.key==="PageDown"?"down":"up";if(a.shiftKey){const j=O();f.moveActive({mode:"extend",cell:{row:g(j.row,M),col:j.col}});return}const B=f.getSelection().active;f.moveActive({mode:"reset",cell:{row:g(B.row,M),col:B.col}});return}if(a.key==="F2"&&!E&&!a.shiftKey&&!d){a.preventDefault(),f.startEdit("edit");return}if((a.key==="Delete"||a.key==="Backspace")&&!E&&!a.shiftKey&&!d){a.preventDefault();const M=f.getSelection(),B=Mt(M.ranges);if(B>f.maxOperationCells){f.onOperationRejected?.("delete",B,"limit");return}if(f.adapter!==void 0&&Wn(f.adapter,M.ranges)){f.rejectReadOnly({kind:"operation",op:"delete",cellCount:B});return}const j=[],G=f.adapter!==void 0&&ao(f.adapter).hyperlink;tn(M.ranges,Z=>{j.push(G?{row:Z.row,col:Z.col,text:"",hyperlink:null}:{row:Z.row,col:Z.col,text:""})}),f.commitEdits(j,{source:"delete"});return}if(a.key==="Escape"){if(f.isDragging()){a.preventDefault(),f.abortDrag();return}if(E||a.shiftKey||d||(a.preventDefault(),f.hideNoteTip?.())||f.closeRejectedMessage?.())return;if(f.getClip()!==null){f.discardClip();return}f.handOffFocusToRoot();return}if(fr(mr.selectAll,a)){a.preventDefault();const M=f.getSelection(),B=ve({row:0,col:0},{row:f.rowAxis.count-1,col:f.colAxis.count-1});f.setSelection({ranges:[B],anchor:M.anchor,active:M.active});return}if(fr(mr.undo,a)){a.preventDefault(),f.onUndoRequest?.();return}if(fr(mr.redo,a)||fr(mr.redoShiftZ,a)){a.preventDefault(),f.onRedoRequest?.();return}if(a.key==="F10"&&a.shiftKey&&!E&&!d||a.key==="ContextMenu"&&!E&&!a.shiftKey&&!d){a.preventDefault();const M=f.getSelection().active;f.ensureCellVisible(M);const B=h.current,j=B===null?{x:0,y:0}:B.getScrollPosition(),G=Math.max(0,j.y),Z=Math.max(0,j.x),Q=B===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:B.getFrozenSize(),ne=B===null?{width:0,height:0}:B.getViewportSize(),ie=f.zoomRef.current;f.onCellContextMenu?.(M,{kind:"keyboard",cellRect:{top:En(f.rowAxis,M.row,{scroll:G,frozenCount:Q.rows,trailingCount:Q.trailingRows,extent:ne.height})*ie,left:kn(f.colAxis,M.col,{scroll:Z,frozenCount:Q.cols,trailingCount:Q.trailingCols,extent:ne.width})*ie,width:f.colAxis.sizeOf(M.col)*ie,height:f.rowAxis.sizeOf(M.row)*ie}});return}if(a.key===" "&&!d&&E!==a.shiftKey){a.preventDefault();const M=f.getSelection(),B=M.ranges.map(j=>E?ve({row:0,col:j.startCol},{row:f.rowAxis.count-1,col:j.endCol}):ve({row:j.startRow,col:0},{row:j.endRow,col:f.colAxis.count-1}));f.setSelection({ranges:B,anchor:M.anchor,active:M.active});return}if(f.pendingPasteOptionsRef!==void 0&&fr(mr.pasteValues,a)){f.pendingPasteOptionsRef.current={mode:"values"};return}if(a.key.length===1&&!a.metaKey&&a.ctrlKey===a.altKey){if(a.ctrlKey&&a.altKey){r.current=!0;return}f.startEdit("replace");return}},C=()=>{const a=s.current;a.isEditing()||a.startEdit("replace")},v=a=>{t.current=a.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},xw)},k=()=>{const a=s.current;if(N(),!a.isEditing()){if(r.current){r.current=!1;const f=m.value;if(f!==""&&(a.startEdit("replace"),a.isEditing())){m.value=f,m.setSelectionRange(f.length,f.length);return}}a.rearmSink()}},b=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null)},y=()=>{r.current=!1;const a=s.current.pendingPasteOptionsRef;a!==void 0&&(a.current=null),N()};return m.addEventListener("keydown",p),m.addEventListener("keyup",b),m.addEventListener("blur",y),m.addEventListener("compositionstart",C),m.addEventListener("compositionend",v),m.addEventListener("input",k),()=>{m.removeEventListener("keydown",p),m.removeEventListener("keyup",b),m.removeEventListener("blur",y),m.removeEventListener("compositionstart",C),m.removeEventListener("compositionend",v),m.removeEventListener("input",k),n.current!==null&&window.clearTimeout(n.current),N()}},[l,c,u,h])},zw=()=>{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)})}},Mw=4,Nw=Object.freeze({cols:0,width:0,rows:0,height:0,trailingCols:0,trailingRows:0,trailingWidth:0,trailingHeight:0,trailingVisibleWidth:0,trailingVisibleHeight:0}),Fw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef(null),l=i.useRef({clientX:0,clientY:0}),c=i.useRef({clientX:0,clientY:0}),u=i.useRef(!1),h=i.useRef({dx:0,dy:0}),m=i.useRef(null),R=i.useRef(0),N=i.useRef(null),W=i.useRef(null),z=i.useRef(!1),I=i.useCallback($=>m.current!==null?$.pointerId===m.current:$.pointerType==="mouse",[]),X=i.useCallback(($,_)=>{const{handleRef:x,rowAxis:g,colAxis:p}=t.current,C=x.current,v=s.current;if(C===null||v===null)return null;const{x:k,y:b}=C.getScrollPosition();if(b<0||k<0||g.totalSize()===0||p.totalSize()===0)return null;const y=t.current.zoomRef.current,a=C.getFrozenSize(),f=C.getViewportSize();return un({row:Dr(g,(_-v.top)/y,{scroll:b,frozenSize:a.height,trailingSize:a.trailingHeight,extent:f.height}),col:Lr(p,($-v.left)/y,{scroll:k,frozenSize:a.width,trailingSize:a.trailingWidth,extent:f.width})},g.count,p.count)},[]),Y=i.useCallback($=>{const _=r.current;if(_===null)return ve($,$);const x=ve({row:Math.min(_.startRow,$.row),col:Math.min(_.startCol,$.col)},{row:Math.max(_.endRow,$.row),col:Math.max(_.endCol,$.col)}),g=x.startRow!==_.startRow||x.endRow!==_.endRow||x.startCol!==_.startCol||x.endCol!==_.endCol;return o.current=g?x:null,g?x:_},[]),O=i.useCallback(()=>{const $=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,N.current!==null&&(cancelAnimationFrame(N.current),N.current=null),$.xAutoScroller.stop(),$.yAutoScroller.stop(),z.current=!1,u.current=!1,h.current={dx:0,dy:0},$.writeFillPreview(null);const _=W.current;_!==null&&(window.removeEventListener("pointermove",_.move),window.removeEventListener("pointerup",_.up),W.current=null);const x=t.current.handleNodeRef.current;x!==null&&m.current!==null&&x.hasPointerCapture?.(m.current)&&x.releasePointerCapture(m.current),m.current=null,$.repaintOverlay()},[]),T=i.useCallback(()=>{const $=t.current,_=r.current,x=o.current;if(O(),_===null||x===null)return;const g=zh(_,x);if(g>$.maxOperationCells){$.onOperationRejected?.("fill",g,"limit");return}if(Wn($.adapter,Mh(_,x))){const v=(x.endRow-x.startRow+1)*(x.endCol-x.startCol+1),k=(_.endRow-_.startRow+1)*(_.endCol-_.startCol+1);$.rejectReadOnly({kind:"operation",op:"fill",cellCount:v-k});return}const p=Nh((v,k)=>va($.adapter,v,k),_,x,Sa);if($.commitEdits(p,{source:"fill"})===null)return;const C=$.getSelection();$.setSelection({ranges:[x],anchor:C.anchor,active:C.active})},[O]),{enabled:F,handleNodeRef:H}=e;return i.useEffect(()=>{const $=H.current;if(!F||$===null)return;const _=v=>{x(v),n.current&&I(v)&&(R.current&1)!==0&&(v.buttons&1)===0&&T()},x=v=>{if(!(n.current&&I(v)))return;l.current={clientX:v.clientX,clientY:v.clientY};const k=Math.abs(v.clientX-c.current.clientX),b=Math.abs(v.clientY-c.current.clientY);if(!u.current&&Math.max(k,b)>=Mw&&(u.current=!0),!!u.current){if(!z.current){const y=t.current,a={getPointerPosition:()=>({clientX:l.current.clientX-h.current.dx,clientY:l.current.clientY-h.current.dy}),buildRange:Y,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};y.xAutoScroller.start(a),y.yAutoScroller.start(a),z.current=!0}N.current===null&&(N.current=requestAnimationFrame(()=>{if(N.current=null,!(n.current&&u.current))return;const y=X(l.current.clientX-h.current.dx,l.current.clientY-h.current.dy);y!==null&&t.current.writeFillPreview(Y(y))}))}},g=v=>{v.button!==0||!(n.current&&I(v))||T()},p=v=>{const k=t.current;if(v.pointerType!=="mouse")return;if(v.button!==0){v.preventDefault();return}v.preventDefault(),v.stopPropagation(),k.focusSink();const b=k.getSelection(),y=b.ranges[b.ranges.length-1];r.current=y,o.current=null,u.current=!1,k.xAutoScroller.stop(),k.yAutoScroller.stop(),z.current=!1,c.current={clientX:v.clientX,clientY:v.clientY},l.current=c.current,R.current=v.buttons,n.current=!0,k.repaintOverlay(),s.current=k.bodyRef.current?.getBoundingClientRect()??null;const a=s.current,f=k.handleRef.current?.getScrollPosition()??{x:-1,y:-1},E=f.y;if(a!==null&&E>=0&&f.x>=0){const A=f.x,M=k.zoomRef.current,B=k.handleRef.current?.getFrozenSize()??Nw,j=k.handleRef.current?.getViewportSize()??{width:0,height:0},G={scroll:A,frozenCount:B.cols,trailingCount:B.trailingCols,extent:j.width},Z={scroll:E,frozenCount:B.rows,trailingCount:B.trailingRows,extent:j.height},Q=kn(k.colAxis,y.endCol,G)+k.colAxis.sizeOf(y.endCol),ne=En(k.rowAxis,y.endRow,Z)+k.rowAxis.sizeOf(y.endRow),ie=Q-1,le=y.endCol>=B.cols&&B.width>0?Math.max(ie,B.width):ie,ze=!(y.endCol>=k.colAxis.count-B.trailingCols)&&B.trailingWidth>0?Math.min(le,j.width-B.trailingVisibleWidth-1):le,Ne=ne-1,He=y.endRow>=B.rows&&B.height>0?Math.max(Ne,B.height):Ne,Me=!(y.endRow>=k.rowAxis.count-B.trailingRows)&&B.trailingHeight>0?Math.min(He,j.height-B.trailingVisibleHeight-1):He;h.current={dx:v.clientX-(a.left+ze*M),dy:v.clientY-(a.top+Me*M)}}else h.current={dx:0,dy:0};m.current=v.pointerId;try{$.setPointerCapture(v.pointerId)}catch{m.current=null}const d=_,L=g;W.current={move:d,up:L},window.addEventListener("pointermove",d),window.addEventListener("pointerup",L),k.writeFillPreview(r.current)},C=v=>{!n.current||m.current===null||v.pointerId!==m.current||O()};return $.addEventListener("pointerdown",p),$.addEventListener("lostpointercapture",C),()=>{$.removeEventListener("pointerdown",p),$.removeEventListener("lostpointercapture",C),O()}},[F,H,I,X,Y,O,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&O()},cancelDrag:O}),[O])},Pw=320,uo=8,_w=64,qw=150,fu=e=>Math.max(0,Math.min(Pw,e.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX-uo)),Iw=(e,t,n)=>{const r=n.width-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,o=n.height-Le.SPREADSHEET_SCROLLBAR_SIZE_PX,s=fu(n),l=Math.max(0,Math.min(t,o-uo)),c=e.left+e.width,u=e.top+e.height,h=I=>I>=0&&I+s<=r,m=[e.left,c-s],R=[{left:e.left,top:u},{left:c-s,top:u},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const I of R)if(h(I.left)&&I.top>=0&&I.top+l<=o)return{left:I.left,top:I.top,width:s,height:l};const N=o-u,W=e.top,z=Math.min(l,Math.max(N,W));if(z>=_w){const I=N>=W?u:e.top-z;for(const X of m)if(h(X))return{left:X,top:I,width:s,height:z}}return{left:uo,top:uo,width:s,height:l}},jw=(e,t,n,r)=>t===null||e!==null&&Yt(e,t)||n?!1:r(t),Hw=(e,t)=>{switch(e.kind){case"note":return K.jsx(Ya,{ctx:e,labels:t});case"note-tip":return K.jsx(Ka,{ctx:e,labels:t});case"comment":return K.jsx(Ha,{ctx:e,labels:t});case"link":return K.jsx(Ba,{ctx:e,labels:t});case"list":return K.jsx(Wa,{ctx:e,labels:t});default:return K.jsx(Va,{ctx:e,labels:t})}},us=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Bw=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),u=i.useRef(null),h=i.useRef(l);h.current=l;const m=i.useRef(e);m.current=e;const R=us(s),N=us(l),W=i.useRef(null),z=(T,F)=>{const H=m.current.getLayerSize();T.style.width=`${fu(H)}px`,T.style.maxHeight="";const $=Iw(F,T.offsetHeight,H);T.style.left=`${$.left-F.left}px`,T.style.top=`${$.top-F.top}px`,T.style.maxHeight=`${$.height}px`};i.useLayoutEffect(()=>{const T=c.current;if(T===null||s===null){W.current=null;return}if(z(T,s.anchorRect),s.kind==="message")return;const F=us(s);if(W.current===F)return;W.current=F;const H=T.querySelector("[data-aqsp-popover-autofocus]");H!==null?H.focus({preventScroll:!0}):T.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const T=u.current,F=h.current;T===null||F===null||z(T,F.anchorRect)},[N]);const I=T=>t===void 0?Hw(T,n):t(T),X=T=>{e.isCompositionKey(T.nativeEvent)&&T.stopPropagation()},Y=T=>{T.key==="Escape"&&!T.defaultPrevented&&(T.preventDefault(),e.close())},O=T=>{e.registerCompositionEnd(T.timeStamp)};return K.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:X,onKeyDown:Y,onCompositionEnd:O,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)},R)}),K.jsx("div",{ref:o,className:"aqsp-popover-anchor","data-aqsp-popover-anchor":"tip","data-aqsp-popover-open":l===null?void 0:"",inert:l===null,onPointerEnter:e.onTipPointerEnter,onPointerLeave:e.onTipPointerLeave,children:l===null?null:K.jsx("div",{ref:u,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:I(l)})})]})},Ww=["note","note-tip","comment","link","list","message"],Vw=(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}},gr=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Vw(e,n),Yw=e=>{const t=i.useRef(e);t.current=e;const[n,r]=i.useState(null),[o,s]=i.useState(null),l=i.useRef(null),c=i.useRef(null),u=i.useRef(null),h=i.useRef(!1),m=i.useRef(null),R=i.useRef(null),N=i.useRef(null),W=i.useRef(null),z=i.useId(),I=i.useCallback(A=>{const M=t.current,B=M.handleRef.current,j=B===null?{x:0,y:0}:B.getScrollPosition(),G=B===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:B.getFrozenSize(),Z=B===null?{width:0,height:0}:B.getViewportSize();return{top:En(M.rowAxis,A.row,{scroll:Math.max(0,j.y),frozenCount:G.rows,trailingCount:G.trailingRows,extent:Z.height}),left:kn(M.colAxis,A.col,{scroll:Math.max(0,j.x),frozenCount:G.cols,trailingCount:G.trailingCols,extent:Z.width}),width:M.colAxis.sizeOf(A.col),height:M.rowAxis.sizeOf(A.row)}},[]),X=i.useCallback(A=>{const M=t.current;M.anchors.current={...M.anchors.current,...A},M.repaintOverlay()},[]),Y=i.useCallback(()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]),O=i.useCallback(()=>{const A=t.current.sinkRef.current;if(A===null)return;const M=c.current;M!==null&&Yt(M,t.current.getActive())?A.setAttribute("aria-describedby",z):A.getAttribute("aria-describedby")===z&&A.removeAttribute("aria-describedby")},[z]),T=i.useCallback(()=>(Y(),h.current=!1,c.current===null?!1:(c.current=null,s(null),X({tip:null}),O(),!0)),[Y,X,O]),F=i.useCallback(()=>{Y(),m.current=window.setTimeout(()=>{m.current=null,T()},qw)},[Y,T]),H=i.useCallback(A=>{const M=t.current;Y();const B=M.adapter.getCellNote===void 0?void 0:M.adapter.getCellNote(A.row,A.col);B===void 0||B===""||(c.current=A,s({kind:"note-tip",cell:A,anchorRect:I(A),current:B,close:T}),X({tip:A}),O())},[I,Y,T,X,O]),$=i.useCallback(A=>{const M=t.current;if(A===null&&h.current)return;const B=u.current;u.current=A;const j=c.current;if(j!==null&&A!==null&&Yt(j,A)){Y();return}const G=Z=>{const Q=M.adapter.getCellNote===void 0?void 0:M.adapter.getCellNote(Z.row,Z.col);return Q!==void 0&&Q!==""};if(jw(B,A,M.isDraggingAny(),G)){A!==null&&H(A);return}j!==null&&F()},[H,Y,F]),_=i.useCallback((A,M)=>{const B=t.current,j=B.bodyRef.current,G=B.handleRef.current;if(j===null||G===null)return null;const Z=j.getBoundingClientRect(),Q=B.zoomRef.current,ne=G.getScrollPosition(),ie=G.getFrozenSize(),le=G.getViewportSize();return un({row:Dr(B.rowAxis,(M-Z.top)/Q,{scroll:Math.max(0,ne.y),frozenSize:ie.height,trailingSize:ie.trailingHeight,extent:le.height}),col:Lr(B.colAxis,(A-Z.left)/Q,{scroll:Math.max(0,ne.x),frozenSize:ie.width,trailingSize:ie.trailingWidth,extent:le.width})},B.rowAxis.count,B.colAxis.count)},[]),x=i.useCallback(A=>{N.current=A,R.current===null&&(R.current=requestAnimationFrame(()=>{R.current=null;const M=N.current;$(M===null?null:"cell"in M?M.cell:_(M.clientX,M.clientY))}))},[$,_]),g=i.useCallback(A=>x({cell:A}),[x]),p=i.useCallback(()=>T(),[T]),C=i.useCallback(A=>{if(l.current===null)return;const M=t.current;l.current=null,r(null),X({interactive:null}),(A===void 0||A.restoreFocus)&&M.focusSink({preventScroll:!0}),M.isEditing()||M.rearmSink()},[X]),v=i.useCallback(A=>{l.current=A.kind,r(A),X({interactive:A.cell})},[X]),k=i.useCallback(A=>{const M=t.current;return ba(M.adapter)?{cellReadOnly:Qe(M.adapter,A.row,A.col)}:{}},[]),b=i.useCallback((A,M)=>{const B=t.current;if(Qe(B.adapter,A.cell.row,A.cell.col)){B.rejectReadOnly({kind:"operation",op:"annotate",cellCount:1}),v({...A,...k(A.cell)});return}if(B.commitEdits(M,{source:"annotate"})===null){v({...A,rejected:!0});return}C()},[v,C,k]),y=i.useCallback((A,M)=>{const B=t.current;if(!gr(B.adapter,B.popovers,A))throw new RangeError(`[spreadsheet] openPopover("${A}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const j=B.getActive();if(A==="list"&&Qe(B.adapter,j.row,j.col)){B.rejectReadOnly({kind:"edit",cell:j,editSession:"none"});return}if(A==="note-tip"){H(j);return}if(A==="message"){if(l.current!==null&&l.current!=="message")return;const ne=M!==void 0&&M.message!==void 0?M.message:void 0,ie=B.adapter.getCellValidation===void 0?void 0:B.adapter.getCellValidation(j.row,j.col),le=ne!==void 0?ne:ie===void 0?void 0:ie.inputMessage;if(le===void 0)return;const Oe=M!==void 0&&M.rejected===!0;v({kind:"message",cell:j,anchorRect:I(j),current:{title:_e(B.labels,"messageTitle"),message:le,rejected:Oe},close:C});return}if(B.isEditing()&&!B.requestCommit())return;if(A==="list"){const ne=B.adapter.getCellValidation===void 0?void 0:B.adapter.getCellValidation(j.row,j.col);if(ne===void 0||ne.type!=="list")return;const ie=M!==void 0&&M.typed!==void 0?M.typed:"";T(),B.focusSink({preventScroll:!0}),v({kind:"list",cell:j,anchorRect:I(j),current:ne.values,typed:ie,commit:le=>{if(Qe(t.current.adapter,j.row,j.col)){t.current.rejectReadOnly({kind:"edit",cell:j,editSession:"none"}),C();return}t.current.commitEdits([{row:j.row,col:j.col,text:le}],{source:"edit",editSession:"discarded"}),C()},close:C});return}if(T(),B.focusSink({preventScroll:!0}),A==="note"){const ne=B.adapter.getCellNote===void 0?void 0:B.adapter.getCellNote(j.row,j.col),ie={kind:"note",cell:j,anchorRect:I(j),current:ne,commit:le=>{b(ie,[{row:j.row,col:j.col,note:le}])},close:C,rejected:!1,...k(j)};v(ie);return}if(A==="comment"){const ne=B.adapter.getCellComments===void 0?void 0:B.adapter.getCellComments(j.row,j.col),ie={kind:"comment",cell:j,anchorRect:I(j),current:ne===void 0?[]:ne,commit:le=>{b(ie,[{row:j.row,col:j.col,comments:le}])},close:C,rejected:!1,...k(j)};v(ie);return}const G=B.adapter.getCellHyperlink===void 0?void 0:Qn(B.adapter.getCellHyperlink(j.row,j.col)),Z=B.adapter.getCellText(j.row,j.col),Q={kind:"link",cell:j,anchorRect:I(j),current:{text:Z,url:G},commit:ne=>{const ie=ne.url===null?null:an(ne.url);if(ie===null&&ne.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(ne.url)}`);const le=ne.text===Z?{row:j.row,col:j.col,hyperlink:ie}:{row:j.row,col:j.col,text:ne.text,hyperlink:ie};b(Q,[le])},close:C,canOpen:B.onHyperlinkOpen!==void 0,open:()=>{const ne=t.current.onHyperlinkOpen;ne!==void 0&&G!==void 0&&ne(G,j)},rejected:!1,...k(j)};v(Q)},[I,C,b,T,v,H,k]),{enabled:a,bodyRef:f}=e;i.useEffect(()=>{const A=f.current;if(!a||A===null)return;const M=j=>{const G=t.current;gr(G.adapter,G.popovers,"note-tip")&&x({clientX:j.clientX,clientY:j.clientY})},B=()=>{gr(t.current.adapter,t.current.popovers,"note-tip")&&x({cell:null})};return A.addEventListener("pointermove",M),A.addEventListener("pointerleave",B),()=>{A.removeEventListener("pointermove",M),A.removeEventListener("pointerleave",B)}},[a,f,x]),i.useEffect(()=>()=>{R.current!==null&&cancelAnimationFrame(R.current),m.current!==null&&window.clearTimeout(m.current)},[]);const{adapter:E,popovers:d}=e,L=i.useMemo(()=>Ww.some(A=>gr(E,d,A)),[E,d]);return i.useMemo(()=>({layerEnabled:L,isKindEnabled:A=>gr(t.current.adapter,t.current.popovers,A),open:y,close:C,isOpen:()=>l.current,onCellHover:g,hideTip:p,onTipPointerEnter:()=>{h.current=!0,Y()},onTipPointerLeave:()=>{h.current=!1,c.current!==null&&F()},syncTipAriaDescribedBy:O,context:n,tipContext:o,registerCompositionEnd:A=>{W.current=A},isCompositionKey:A=>du(A,W.current),getLayerSize:()=>{const A=t.current.handleRef.current;return A===null?{width:0,height:0}:A.getViewportSize()},tipId:z}),[L,y,C,g,p,Y,F,O,n,o,z])},Kw=(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},pu=(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 un({row:Dr(n,(l-t.top)/o,{scroll:u,frozenSize:h.height,trailingSize:h.trailingHeight,extent:m.height}),col:Lr(r,(s-t.left)/o,{scroll:c,frozenSize:h.width,trailingSize:h.trailingWidth,extent:m.width})},n.count,r.count)},Uw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),u=i.useRef(0),h=i.useRef(null),m=i.useRef(!1),R=i.useRef(null),N=i.useRef(""),W=i.useRef(!1),z=i.useRef(!1),I=i.useCallback((x,g)=>{const{handleRef:p,rowAxis:C,colAxis:v,zoomRef:k}=t.current;return pu(p.current,o.current,C,v,k.current,x,g)},[]),X=i.useRef(!1),Y=i.useRef(null),O=i.useRef(null),T=i.useRef({clientX:0,clientY:0}),F=i.useCallback(()=>{const{autoScroller:x,bodyRef:g,onDragFrame:p}=t.current;n.current=!1,r.current=null,h.current=null,X.current=!1,Y.current=null,O.current=null,m.current=!1,R.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),x.stop();const C=g.current;C!==null&&c.current!==null&&C.hasPointerCapture?.(c.current)&&C.releasePointerCapture(c.current),c.current=null,p(null),t.current.repaintOverlay()},[]),H=i.useCallback(()=>{if(!n.current)return;const x=r.current;x!==null&&t.current.setSelection(x),F()},[F]),{enabled:$,bodyRef:_}=e;return i.useEffect(()=>{const x=_.current;if(!$||x===null)return;const g=d=>d instanceof Element&&d.closest("[data-aqsp-cells]")!==null,p=d=>{const L=t.current;if(d.pointerType==="mouse"&&d.button===0&&(m.current=!1,R.current=null,z.current=!1),W.current=g(d.target),!W.current){if(d.pointerType==="mouse"){if(d.preventDefault(),d.button!==0)return;if(L.getPointing?.()){L.focusSink();return}if(L.isEditing()&&!L.requestCommit()){d.stopPropagation(),L.focusSink();return}L.focusSink()}return}if(N.current=d.pointerType,d.pointerType!=="mouse")return;if(d.button!==0){d.preventDefault();return}if((L.pointDragRef===void 0?null:L.pointDragRef.current)?.onPointerDown(d))return;if(L.isEditing()&&!L.requestCommit()){d.preventDefault(),L.focusSink();return}o.current=x.getBoundingClientRect();const M=I(d.clientX,d.clientY);if(M===null)return;if(d.preventDefault(),L.focusSink(),(d.ctrlKey||d.metaKey)&&!d.shiftKey&&L.openHyperlinkAt?.(M)===!0){z.current=!0;return}const B=L.getSelection();r.current=B;const j=d.shiftKey,G=d.ctrlKey||d.metaKey,Z=G&&!j&&B.ranges.some(ne=>On(ne,M));m.current=Z,R.current=Z?M:null,Z||L.setSelection(Or(B,M,{extend:j,append:G})),n.current=!0,L.repaintOverlay(),s.current={clientX:d.clientX,clientY:d.clientY},c.current=d.pointerId,u.current=d.buttons;try{x.setPointerCapture(d.pointerId)}catch{c.current=null}const Q=Z?M:L.getSelection().anchor;h.current=ne=>ve(Q,ne),Y.current=Q.col,O.current=Q.row,L.autoScroller.stop(),X.current=!1,T.current={clientX:d.clientX,clientY:d.clientY}},C=d=>c.current!==null?d.pointerId===c.current:d.pointerType==="mouse",v=d=>{if(n.current&&C(d)){if(s.current={clientX:d.clientX,clientY:d.clientY},!X.current&&h.current!==null){const L=Math.abs(d.clientX-T.current.clientX),A=Math.abs(d.clientY-T.current.clientY);Math.max(L,A)>=wo&&(X.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:h.current,anchorCol:Y.current??void 0,anchorRow:O.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const L=h.current;if(!n.current||L===null)return;const A=t.current,M=I(s.current.clientX,s.current.clientY);M!==null&&A.onDragFrame(L(M))}))}},k=d=>{v(d),n.current&&C(d)&&(u.current&1)!==0&&(d.buttons&1)===0&&y(d)},b=d=>{d.button!==0||!(n.current&&C(d))||y(d)},y=d=>{const L=t.current,A=I(d.clientX,d.clientY);if(A!==null){const M=R.current;m.current&&M!==null?L.setSelection(au(L.getSelection(),ve(M,A),M)):L.setSelection(vn(L.getSelection(),A))}F()},a=d=>{!n.current||c.current===null||d.pointerId!==c.current||H()},f=d=>{const L=t.current;if(!g(d.target)||N.current!=="mouse"||L.isAnyDragging())return;if(L.isEditing()&&!L.requestCommit()){L.focusSink();return}L.focusSink(),o.current=x.getBoundingClientRect();const A=I(d.clientX,d.clientY);if(A===null)return;const M=L.getSelection();M.ranges.some(j=>On(j,A))||L.setSelection(Or(M,A,{extend:!1,append:!1})),L.onContextMenuSelect(A,d)},E=d=>{const L=t.current;if(!W.current||N.current!=="mouse"||L.getPointing?.()||z.current)return;o.current=x.getBoundingClientRect();const A=I(d.clientX,d.clientY);A!==null&&Yt(L.getSelection().active,A)&&L.onRequestEdit(A,L.caretFromPointEnabled(A)?Kw(d.clientX,d.clientY,A):void 0)};return x.addEventListener("pointerdown",p),x.addEventListener("pointermove",k),x.addEventListener("pointerup",b),x.addEventListener("lostpointercapture",a),x.addEventListener("contextmenu",f),x.addEventListener("dblclick",E),()=>{x.removeEventListener("pointerdown",p),x.removeEventListener("pointermove",k),x.removeEventListener("pointerup",b),x.removeEventListener("lostpointercapture",a),x.removeEventListener("contextmenu",f),x.removeEventListener("dblclick",E),F()}},[$,_,I,F,H]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>m.current?"subtract":"add",abortDrag:H,cancelDrag:F}),[H,F])},Xw=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef({clientX:0,clientY:0}),c=i.useRef(null),u=i.useRef(null),h=i.useRef(0),m=i.useRef(null),R=i.useRef(null),N=i.useRef(!1),W=i.useCallback((T,F)=>{const{handleRef:H,rowAxis:$,colAxis:_,zoomRef:x}=t.current;return pu(H.current,o.current,$,_,x.current,T,F)},[]),z=i.useCallback(()=>{const{autoScroller:T,bodyRef:F,onDragFrame:H}=t.current;n.current=!1,r.current=null,m.current=null,R.current=null,N.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),T.stop();const $=F.current;$!==null&&u.current!==null&&$.hasPointerCapture?.(u.current)&&$.releasePointerCapture(u.current),u.current=null,H(null)},[]),I=i.useCallback(()=>{if(!n.current)return;const T=r.current;T!==null&&t.current.restoreSink(T),z()},[z]),X=i.useCallback(T=>{const F=t.current,H=F.bodyRef.current;if(!F.enabled||H===null||!F.getPointing())return!1;o.current=H.getBoundingClientRect();const $=W(T.clientX,T.clientY);if($===null)return o.current=null,!1;const _=F.captureSink();if(_===null)return o.current=null,!1;T.preventDefault(),F.focusSink(),r.current=_,R.current=$,F.insertReference($,"cells"),n.current=!0,s.current={clientX:T.clientX,clientY:T.clientY},l.current={clientX:T.clientX,clientY:T.clientY},u.current=T.pointerId,h.current=T.buttons;try{H.setPointerCapture(T.pointerId)}catch{u.current=null}return m.current=x=>{const g=ve($,x);return t.current.insertReference(g,"cells"),g},F.autoScroller.stop(),N.current=!1,F.onDragFrame(ve($,$)),!0},[W]),{enabled:Y,bodyRef:O}=e;return i.useEffect(()=>{const T=O.current;if(!Y||T===null)return;const F=x=>u.current!==null?x.pointerId===u.current:x.pointerType==="mouse",H=x=>{if(!(n.current&&F(x)))return;s.current={clientX:x.clientX,clientY:x.clientY};const g=m.current,p=R.current;if(!N.current&&g!==null&&p!==null){const C=Math.abs(x.clientX-l.current.clientX),v=Math.abs(x.clientY-l.current.clientY);Math.max(C,v)>=wo&&(N.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:g,anchorCol:p.col,anchorRow:p.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const C=m.current;if(!n.current||C===null)return;const v=W(s.current.clientX,s.current.clientY);v!==null&&t.current.onDragFrame(C(v))})),(h.current&1)!==0&&(x.buttons&1)===0&&z()},$=x=>{x.button!==0||!(n.current&&F(x))||z()},_=x=>{!n.current||u.current===null||x.pointerId!==u.current||z()};return T.addEventListener("pointermove",H),T.addEventListener("pointerup",$),T.addEventListener("lostpointercapture",_),()=>{T.removeEventListener("pointermove",H),T.removeEventListener("pointerup",$),T.removeEventListener("lostpointercapture",_),z()}},[Y,O,W,z]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:I,cancelDrag:z,onPointerDown:X}),[I,z,X])},Gw=Object.freeze({width:0,height:0}),ds=33,Zw=e=>e.nodeType===Node.DOCUMENT_NODE||e.nodeType===Node.DOCUMENT_FRAGMENT_NODE,Jw=(e,t,n)=>{const r=(n-t)/(ds-1);let o=-1,s=-1;for(let c=0;c<ds;c++)e(t+r*c)&&(o===-1&&(o=c),s=c);if(o===-1)return null;const l=(c,u)=>{let h=c,m=u;for(;Math.abs(m-h)>1;){const R=(h+m)/2;e(R)?m=R:h=R}return m};return{top:o===0?t:l(t+r*(o-1),t+r*o),bottom:s===ds-1?n:l(t+r*(s+1),t+r*s)}},Qw=(e,t)=>{if(!Number.isInteger(e)||e<0||e>0&&e>t)throw new RangeError(`[spreadsheet] headerRows must be a whole number from 0 to frozenRows = ${t} (got ${e})`)},e0=e=>{if(e!==void 0&&(typeof e!="string"||e===""||/\s/u.test(e)))throw new RangeError(`[spreadsheet] labelledBy must be one non-empty id without whitespace (got ${JSON.stringify(e)})`)},t0=e=>{if(e===void 0)return;if(![e.startRow,e.startCol,e.endRow,e.endCol].every(n=>Number.isInteger(n)&&n>=0)||e.startRow>e.endRow||e.startCol>e.endCol)throw new RangeError(`[spreadsheet] frame must hold non-negative integer bounds with each start at most its end (got startRow ${String(e.startRow)}, startCol ${String(e.startCol)}, endRow ${String(e.endRow)}, endCol ${String(e.endCol)})`)},pc=(e,t)=>{if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw new RangeError(`[spreadsheet] ${e} must be a non-negative integer (got ${typeof t=="string"?JSON.stringify(t):String(t)})`);return t},n0=24,r0=200,hu=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),hc=5,o0=/^#[0-9A-Fa-f]{6}$/,s0=Object.freeze({row:!1,column:!1,intersection:!1}),mc=Object.freeze({ok:!0}),gc=(e,t)=>{if(t===void 0)return hu;if(t.length!==hc)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${hc} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!o0.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},l0=e=>{for(const t of["row","column","intersection"])if(st(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},i0=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return ja},c0=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},a0=e=>{const t=i.useRef(null),n=t.current;return n!==null&<.VIRTUAL_SCROLL_LABEL_KEYS.every(r=>n[r]===e[r])?n:(t.current=e,e)},In={ranges:[ve({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},u0=i.forwardRef(function({adapter:t,headerRows:n=0,readOnly:r=!1,labelledBy:o,defaultRowHeight:s=n0,defaultColumnWidth:l=Le.SPREADSHEET_DEFAULT_COLUMN_WIDTH_PX,frozenColumns:c=0,frozenRows:u=0,frozenTrailingColumns:h=0,frozenTrailingRows:m=0,tapScrollCircleOptions:R,overscanRows:N,overscanCols:W,background:z,onRenderTruncated:I,renderCell:X,onSelectionChange:Y,onCellContextMenu:O,onUndoRequest:T,onRedoRequest:F,onCopyMultiRange:H,onOperationRejected:$,onEditRejected:_,onReadOnlyRejected:x,formatReadOnlyAnnouncement:g,dataVersion:p,maxOperationCells:C=Le.SPREADSHEET_MAX_OPERATION_CELLS,enableFillHandle:v=!0,enableResizeUI:k=!0,headings:b=!0,onContentSizeChange:y,frame:a,formatCellAnnouncement:f,formatSelectionAnnouncement:E,formatCommandAnnouncement:d,formatResizeAnnouncement:L,locale:A,labels:M,shortcuts:B,colors:j,formats:G,highlight:Z,defaultHighlight:Q,onHighlightChange:ne,highlightColors:ie,popovers:le,renderPopover:Oe,onClipChange:ze,onHyperlinkOpen:Ne,onValidationRejected:He,onPasteSpecialRequest:me,onClipboardUnavailable:Me,onPasteResolved:it,now:Be=Date.now,zoom:Nt,defaultZoom:bt,onZoomChange:ct,testId:et,className:dn,__onCellRender:er,__onVirtualKeyboardRaise:tr,__maxRenderedCells:An},zr){const oe=i.useMemo(()=>r?Ah(t):t,[t,r]),Ce=nc(oe.rowCount,s),fe=nc(oe.colCount,l),pt=i.useRef(null);pt.current===null&&(pt.current=zw());const Te=pt.current,Ut=lt.resolveVirtualScrollLocale(A),yt=i.useMemo(()=>Ta(A,M),[A,M]),ko=a0(Qh(yt)),fn=i.useMemo(()=>Xh(B),[B]),xn=i.useMemo(()=>{if(!k)return;const q=[...fn].filter(([,J])=>ns.includes(J)).sort(([,J],[,ee])=>ns.indexOf(J)-ns.indexOf(ee)).map(([J])=>Bh(J)).filter(J=>J!==null);return q.length===0?void 0:q.join(" ")},[fn,k]),Mr=i.useMemo(()=>({fill:gc("fill",j===void 0?void 0:j.fill),font:gc("font",j===void 0?void 0:j.font)}),[j]),Tn=i.useMemo(()=>ie===void 0?void 0:l0(ie),[ie]);if(oe.getConditionalFormats!==void 0&&oe.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");Qw(n,u),e0(o),t0(a);const Ft=i.useCallback(()=>Te.get().editVersion,[Te]),$n=i.useCallback(w=>Te.subscribeCoalesced(w),[Te]),Ln=i.useSyncExternalStore($n,Ft,Ft)+(p===void 0?0:p),pn=oe.getConditionalFormats===void 0?null:oe.getConditionalFormats(),hn=i.useMemo(()=>({index:pn===null?null:su(pn),memo:Us()}),[oe,pn,Ln]),mn=i.useRef(hn.index);mn.current=hn.index;const rr=i.useRef(hn.memo);rr.current=hn.memo;const Xt=i.useCallback((w,q,J)=>Xs(oe,mn.current,rr.current,w,q,J),[oe]),Ke=i.useRef(null),[Eo,Oo]=i.useState(()=>Le.clampSpreadsheetZoom(bt??1)),Ue=Le.clampSpreadsheetZoom(Nt??Eo),Pe=i.useRef(Ue);Pe.current=Ue;const Gt=i.useRef(Ue);Gt.current=Ue;const S=i.useRef(null),D=i.useRef(ct);D.current=ct;const V=i.useRef(Nt!==void 0);V.current=Nt!==void 0;const P=i.useCallback(w=>{const q=Le.clampSpreadsheetZoom(w);q!==Gt.current&&(Gt.current=q,V.current||Oo(q),D.current?.(q))},[]),U=oe.rowCount===0||oe.colCount===0,te=!U;i.useEffect(()=>{const w=Ke.current;if(!te||w===null)return;const q=ee=>{ee.defaultPrevented||!ee.altKey||ee.ctrlKey||ee.metaKey||ee.shiftKey||ee.deltaY!==0&&(ee.preventDefault(),ee.stopPropagation(),!S.current?.()&&P(Le.stepSpreadsheetZoom(Gt.current,ee.deltaY<0?1:-1)))},J=ee=>{if(ee.defaultPrevented||!(ee.ctrlKey&&ee.altKey)||ee.metaKey||ee.getModifierState("AltGraph"))return;const pe=ee.key==="="||ee.key==="+"?Le.stepSpreadsheetZoom(Gt.current,1):ee.key==="-"?Le.stepSpreadsheetZoom(Gt.current,-1):ee.key==="0"?1:null;pe!==null&&(ee.preventDefault(),ee.stopPropagation(),!S.current?.()&&P(pe))};return w.addEventListener("wheel",q,{passive:!1,capture:!0}),w.addEventListener("keydown",J,!0),()=>{w.removeEventListener("wheel",q,{capture:!0}),w.removeEventListener("keydown",J,!0)}},[P,te]);const re=i.useRef(null),Ae=i.useRef(null),Ee=i.useRef(null),Se=i.useRef(null),ue=i.useRef(null),Fe=i.useRef(null),qe=i.useRef(null),de=i.useRef(0),se=i.useRef(null),be=i.useRef(0),ge=i.useRef(null),he=i.useRef(null),Xe=i.useRef(null),ce=i.useRef(null),xe=i.useRef(null),tt=i.useRef(null),at=i.useRef(null),[We,ke]=i.useState(In),Ie=i.useRef(We),Ge=i.useCallback(()=>Ie.current,[]),[Pt,nt]=i.useState(()=>Q===void 0?s0:Q),ht=Z!==void 0?Z:Pt,or=i.useRef(ht);or.current=ht;const Ao=i0(Tn,ht),Zs=i.useRef(Z!==void 0);Zs.current=Z!==void 0;const Js=i.useRef(ne);Js.current=ne;const mu=i.useCallback(w=>{Zs.current||nt(w),Js.current?.(w)},[]),Qs=i.useRef(null),xo=i.useRef(null),_t=i.useRef(null),To=i.useRef(()=>!1),el=i.useRef(()=>{}),tl=i.useRef(()=>null),nl=i.useRef(()=>{}),gn=i.useCallback(()=>To.current(),[]),$o=i.useMemo(()=>({getPointing:()=>To.current(),insertReference:(w,q)=>el.current(w,q)}),[]),rl=i.useRef(Bt),ol=i.useRef(null),Lo=i.useRef({interactive:null,tip:null}),sl=i.useRef(null),ll=i.useRef(null),Nr=i.useRef(()=>{}),il=i.useRef(()=>!1),Zt=i.useRef(null),sr=i.useCallback(()=>{const w=Zt.current;if(w===null||w.isOpen()!=="message")return!1;const q=w.context;return q===null||q.kind!=="message"||!q.current.rejected?!1:(w.close(),!0)},[]),Do=i.useRef(()=>!1),cl=i.useRef(()=>!1),al=i.useRef(null),zo=i.useRef(()=>Promise.resolve("rejected")),$e=i.useCallback(()=>{Qs.current?.()},[]),qt=i.useCallback(w=>{Fe.current?.focus(w)},[]),Ve=i.useCallback(()=>{qt({preventScroll:!0})},[qt]),Mo=i.useRef(!1),gu=i.useCallback(()=>{const w=Ke.current;if(w!==null){Mo.current=!0;try{w.focus()}finally{Mo.current=!1}}},[]),ut=i.useCallback(()=>{const w=Fe.current;w!==null&&(w.value=" ",w.setSelectionRange(0,1))},[]),Dn=i.useCallback((w,q)=>{if(w===null)return;const J=q?"":"none";w.style.display!==J&&(w.style.display=J)},[]),Rt=i.useCallback(()=>{const w=qe.current;if(w!==null){const J=Math.max(0,ue.current?.getScrollPosition().y??0),ee=ue.current?.getFrozenSize().height??0;w.style.transform=`translateY(${de.current-J-ee}px)`}const q=ue.current;if(q!==null&&(xe.current!==null||tt.current!==null)){const J=q.getFrozenSize();Dn(xe.current,J.height>0),Dn(tt.current,J.trailingHeight>0)}},[Dn]),vt=i.useCallback(()=>{const w=se.current;if(w!==null){const J=Math.max(0,ue.current?.getScrollPosition().x??0),ee=ue.current?.getFrozenSize().width??0;w.style.transform=`translateX(${be.current-J-ee}px)`}const q=ue.current;if(q!==null&&(Xe.current!==null||ce.current!==null)){const J=q.getFrozenSize();Dn(Xe.current,J.width>0),Dn(ce.current,J.trailingWidth>0)}},[Dn]),lr=i.useRef(null),zn=i.useCallback(()=>{Xe.current===null&&ce.current===null&&xe.current===null&&tt.current===null||lr.current===null&&(lr.current=requestAnimationFrame(()=>{lr.current=null,Rt(),vt(),$e()}))},[Rt,vt,$e]);i.useEffect(()=>()=>{lr.current!==null&&cancelAnimationFrame(lr.current)},[]);const No=i.useRef(null),Fo=i.useRef(null);(No.current===null||Fo.current?.rowAxis!==Ce||Fo.current?.colAxis!==fe)&&(Fo.current={rowAxis:Ce,colAxis:fe},No.current=Ow({handleRef:ue,rowAxis:Ce,colAxis:fe}));const Fr=i.useCallback(w=>{const q=ue.current,J=q===null?{x:0,y:0}:q.getScrollPosition(),ee=q===null?{rows:0,cols:0,trailingRows:0,trailingCols:0}:q.getFrozenSize(),pe=q===null?{width:0,height:0}:q.getViewportSize(),ye=Pe.current;return{top:En(Ce,w.row,{scroll:Math.max(0,J.y),frozenCount:ee.rows,trailingCount:ee.trailingRows,extent:pe.height})*ye,left:kn(fe,w.col,{scroll:Math.max(0,J.x),frozenCount:ee.cols,trailingCount:ee.trailingCols,extent:pe.width})*ye,width:fe.sizeOf(w.col)*ye,height:Ce.sizeOf(w.row)*ye}},[Ce,fe]),ul=i.useCallback(w=>{const q=Se.current,J=Ke.current,ee=Ae.current;if(q===null||J===null||ee===null||ue.current===null)return;const pe=Pe.current,ye=Fr(w),Je=ee.offsetTop*pe+ye.top,ft=ee.offsetLeft*pe+ye.left,Ye=Math.max(0,Je),Dt=Math.max(0,ft),en=Math.min(J.clientHeight,Je+ye.height),Ir=Math.min(J.clientWidth,ft+ye.width);if(en<=Ye||Ir<=Dt)return;q.style.top=`${Ye}px`,q.style.left=`${Dt}px`,q.style.width=`${Ir-Dt}px`,q.style.height=`${en-Ye}px`;const Pn=q.getBoundingClientRect();Pn.width===0&&Pn.height===0||q.scrollIntoView({block:"nearest",inline:"nearest",behavior:"instant"})},[Fr]),Jt=i.useCallback(w=>{No.current?.(w),ul(w)},[ul]),wu=i.useCallback(()=>{const w=ue.current,q=w===null?-1:w.getViewportSize().height,J=re.current,ee=Ke.current;if(q<=0||J===null||ee===null)return q;const pe=J.getBoundingClientRect(),ye=ee.getRootNode();if(pe.height<=0||J.offsetHeight<=0||!Zw(ye))return q;const Je=ee.ownerDocument.documentElement,ft=Math.max(pe.left,0),Ye=Math.min(pe.right,Je.clientWidth),Dt=Math.max(pe.top,0)+.5,en=Math.min(pe.bottom,Je.clientHeight)-.5,Ir=(ft+Ye)/2,Pn=Ye>ft&&en>=Dt?Jw(Ku=>{const Il=ye.elementFromPoint(Ir,Ku);return Il!==null&&ee.contains(Il)},Dt,en):null,Yu=Pn===null?Je.clientHeight:Pn.bottom-Pn.top+1;return Math.min(q,Yu*(J.offsetHeight/pe.height))},[]),dl=i.useRef(y);dl.current=y;const Po=i.useRef(null),It=i.useCallback(()=>{const w=dl.current;if(w===void 0)return;const q=Ae.current;let J;if(q===null)J=Gw;else{if(q.getClientRects().length===0)return;{const pe=Ee.current,ye=Pe.current;J={width:((pe===null?0:pe.offsetWidth)+fe.totalSize()+Le.SPREADSHEET_SCROLLBAR_SIZE_PX)*ye,height:((pe===null?0:pe.offsetHeight)+Ce.totalSize()+Le.SPREADSHEET_SCROLLBAR_SIZE_PX)*ye}}}const ee=Po.current;ee!==null&&ee.width===J.width&&ee.height===J.height||(Po.current=J,w(J))},[Ce,fe]);i.useLayoutEffect(()=>{if(y===void 0){Po.current=null;return}It()});const fl=y!==void 0;i.useEffect(()=>{const w=Ae.current;if(!fl||w===null)return;const q=new ResizeObserver(()=>It());return q.observe(w),()=>q.disconnect()},[fl,It,U]);const Mn=i.useRef(null),wn=i.useRef(null),Nn=i.useCallback(w=>{Mn.current!==null&&window.clearTimeout(Mn.current),wn.current!==null&&(cancelAnimationFrame(wn.current),wn.current=null),Mn.current=window.setTimeout(()=>{Mn.current=null;const q=at.current;q!==null&&(q.textContent="",wn.current=requestAnimationFrame(()=>{wn.current=null,q.textContent=w}))},r0)},[]);i.useEffect(()=>()=>{Mn.current!==null&&window.clearTimeout(Mn.current),wn.current!==null&&cancelAnimationFrame(wn.current)},[]);const Fn=i.useCallback(w=>{x?.(w),g!==void 0&&Nn(g(w))},[x,g,Nn]),pl=i.useCallback((w,q)=>{if(f===void 0&&E===void 0)return;const J=q.ranges[q.ranges.length-1],ee=Ct(J),pe=q.ranges.length===1&&ee.rows===1&&ee.cols===1,ye=w.ranges[w.ranges.length-1],Je=w.ranges.length!==q.ranges.length||ye.startRow!==J.startRow||ye.startCol!==J.startCol||ye.endRow!==J.endRow||ye.endCol!==J.endCol,ft=()=>{if(f!==void 0){const Ye=q.active,Dt=oe.getCellText(Ye.row,Ye.col),en=oe.getCellFormat===void 0?void 0:Xt(Ye.row,Ye.col,()=>Dt);Nn(f({row:Ye.row,col:Ye.col,text:Dt,displayText:Gn(Dt,en===void 0?void 0:en.value),columnName:Le.columnIndexToName(Ye.col),...ba(oe)?{readOnly:Qe(oe,Ye.row,Ye.col)}:{}}))}};if(pe){ft();return}if(Je){E!==void 0&&Nn(E({range:J,anchor:q.anchor,active:q.active,rangeRowCount:ee.rows,rangeColCount:ee.cols,rangeCount:q.ranges.length}));return}ft()},[oe,f,E,Nn,Xt]),Ze=i.useCallback(w=>{const q=Ie.current;Object.is(w,q)||Rw(w,q)||(Ie.current=w,ke(w),Y?.(w),pl(q,w),(_t.current?.()??!1)||ut())},[Y,pl,ut]),Cu=i.useCallback(w=>{const q=Ie.current;if(w.mode==="cycle"){const ee=uu(q,w.direction);Ze(ee),Jt(ee.active);return}const J=un(w.cell,Ce.count,fe.count);if(w.mode==="extend"){Ze(vn(q,J)),Jt(J);return}Ze(Or(q,J,{extend:!1,append:!1})),Jt(J)},[Ze,Jt,Ce,fe]),rt=i.useCallback(()=>_t.current?.()??!1,[]),hl=i.useRef(null),St=i.useCallback(()=>hl.current?.()??!0,[]),ml=i.useRef(null),ir=i.useCallback((w,q)=>{const J=_t.current?.()??!1;ml.current?.(w,q),!J&&(_t.current?.()??!1)&&sr()},[sr]),[bu,_o]=i.useState(!1),gl=i.useCallback(()=>{tr?.(),_o(!0)},[tr]),yu=i.useCallback((w,q)=>{Qe(oe,w.row,w.col)||gl(),ir("edit",q)},[oe,gl,ir]),wl=i.useRef(null),Pr=i.useCallback(()=>wl.current?.()??null,[]),Cl=i.useRef(null),Tt=i.useCallback(()=>{Cl.current?.()},[]),bl=i.useRef(null),yl=i.useCallback(w=>{bl.current?.(w)},[]),Rl=i.useRef(()=>{}),_r=i.useRef(0),Cn=i.useCallback((w,q,J)=>{let ee;if(q.source==="paste"){const pe=c0(J);if(w.length===0&&pe.conditionalFormats.length===0)return null;_r.current+=1,ee={transaction:_r.current,source:"paste",sameSheet:pe.sameSheet,conditionalFormats:pe.conditionalFormats}}else{if(w.length===0)return null;_r.current+=1,ee={transaction:_r.current,source:q.source}}try{oe.applyEdits(w,ee)}catch(pe){return _?.(pe,q),null}return Te.bumpEdit(),yl(q.source),ee.transaction},[oe,Te,_,yl]),Ru=i.useCallback((w,q)=>Cn(w,{source:"paste"},q),[Cn]),vu=i.useCallback(w=>{Te.setVy(w.y),Rt(),vt(),$e()},[Te,Rt,vt,$e]),vl=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Su=i.useCallback(w=>{Te.setRowRange(w.renderingRowStart,w.renderingRowEnd),Te.setColRange(w.renderingColStart,w.renderingColEnd);const q=vl.current;(q.rowStart!==w.renderingRowStart||q.rowEnd!==w.renderingRowEnd||q.colStart!==w.renderingColStart||q.colEnd!==w.renderingColEnd)&&(vl.current={rowStart:w.renderingRowStart,rowEnd:w.renderingRowEnd,colStart:w.renderingColStart,colEnd:w.renderingColEnd},$e())},[Te,$e]),Sl=i.useRef(()=>"add"),Qt=i.useCallback(w=>{xo.current?.(w,Sl.current())},[]),ku=i.useCallback(w=>{xo.current?.(w,"point")},[]),kl=i.useRef(null),qo=i.useCallback(w=>{kl.current?.(w)},[]),El=i.useRef(null),Eu=i.useCallback(w=>{El.current?.(w)},[]),Ol=i.useRef(null),Io=i.useCallback((w,q)=>{if(q.length===0)return;const J=ue.current;if(w==="col"){for(const ee of q){const pe=Math.round(ee.size);fe.resize(ee.index,pe),J?.updateColSize(ee.index,pe)}Te.bumpColVersion(),vt(),$e(),zn(),It();return}for(const ee of q){const pe=Math.round(ee.size);Ce.resize(ee.index,pe),J?.updateRowSize(ee.index,pe)}Te.bumpRowGeometry(),Rt(),$e(),zn(),It()},[Ce,fe,Te,vt,Rt,$e,zn,It]),Ou=i.useCallback((w,q)=>{O?.(w,{kind:"pointer",event:q})},[O]),Au=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:Qt,axis:"both",zoomRef:Pe}),xu=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:Qt,axis:"x",zoomRef:Pe}),Tu=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:Qt,axis:"y",zoomRef:Pe}),$u=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:qo,axis:"x",zoomRef:Pe}),Lu=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:qo,axis:"y",zoomRef:Pe}),Du=qn({handleRef:ue,rowAxis:Ce,colAxis:fe,bodyRef:re,onDragFrame:Qt,axis:"both",zoomRef:Pe}),Al=i.useRef(null),xl=i.useRef(()=>!1),jo=i.useCallback(()=>xl.current(),[]),kt=Uw({zoomRef:Pe,enabled:!U,rowAxis:Ce,colAxis:fe,handleRef:ue,bodyRef:re,isEditing:rt,requestCommit:St,getSelection:Ge,setSelection:Ze,focusSink:Ve,onDragFrame:Qt,onContextMenuSelect:Ou,onRequestEdit:yu,caretFromPointEnabled:w=>{if(X!==void 0||oe.getCellFormula!==void 0&&oe.getCellFormula(w.row,w.col)!==void 0)return!1;if(oe.getCellFormat===void 0)return!0;const q=oe.getCellText(w.row,w.col);return Gn(q,oe.getCellFormat(w.row,w.col)?.value)===q},isAnyDragging:jo,autoScroller:Au,repaintOverlay:$e,pointDragRef:Al,getPointing:gn,openHyperlinkAt:Ne===void 0||oe.getCellHyperlink===void 0?void 0:w=>{const q=oe.getCellHyperlink===void 0?void 0:Qn(oe.getCellHyperlink(w.row,w.col));return q===void 0?!1:(Ne(q,w),!0)}}),$t=fc({zoomRef:Pe,enabled:!U&&b,axis:"col",headerRef:ge,mainAxis:fe,crossCount:oe.rowCount,handleRef:ue,isEditing:rt,requestCommit:St,getSelection:Ge,setSelection:Ze,focusSink:Ve,onDragFrame:Qt,autoScroller:xu,repaintOverlay:$e,pointing:$o}),Lt=fc({zoomRef:Pe,enabled:!U&&b,axis:"row",headerRef:he,mainAxis:Ce,crossCount:oe.colCount,handleRef:ue,isEditing:rt,requestCommit:St,getSelection:Ge,setSelection:Ze,focusSink:Ve,onDragFrame:Qt,autoScroller:Tu,repaintOverlay:$e,pointing:$o}),dt=yw({zoomRef:Pe,enabled:!U&&k&&b,colBandRef:ge,rowBandRef:he,fontSourceRef:re,colAxis:fe,rowAxis:Ce,viewStore:Te,handleRef:ue,isEditing:rt,requestCommit:St,focusSink:Ve,getSelection:Ge,adapter:oe,autofitEnabled:X===void 0,headerRows:n,defaultRowHeight:s,defaultColumnWidth:l,maxOperationCells:C,onOperationRejected:$,resizeTracks:Io,writeResizeGuide:Eu,repaintOverlay:$e,isPointing:gn}),Et=Fw({zoomRef:Pe,enabled:!U&&v,handleNodeRef:Ol,bodyRef:re,rowAxis:Ce,colAxis:fe,handleRef:ue,getSelection:Ge,setSelection:Ze,focusSink:Ve,adapter:oe,commitEdits:Cn,maxOperationCells:C,onOperationRejected:$,rejectReadOnly:Fn,writeFillPreview:qo,repaintOverlay:$e,xAutoScroller:$u,yAutoScroller:Lu}),mt=Xw({zoomRef:Pe,enabled:!U,bodyRef:re,handleRef:ue,rowAxis:Ce,colAxis:fe,getPointing:gn,insertReference:$o.insertReference,captureSink:()=>tl.current(),restoreSink:w=>nl.current(w),focusSink:Ve,autoScroller:Du,onDragFrame:Qt});Al.current=mt;const cr=i.useCallback(()=>kt.isDragging()||$t.isDragging()||Lt.isDragging()||dt.isDragging()||Et.isDragging()||mt.isDragging(),[kt,$t,Lt,dt,Et,mt]);S.current=cr,xl.current=cr,Sl.current=()=>mt.isDragging()?"point":kt.getDragMode();const zu=i.useCallback(()=>{kt.abortDrag(),$t.abortDrag(),Lt.abortDrag(),dt.abortDrag(),Et.abortDrag(),mt.abortDrag()},[kt,$t,Lt,dt,Et,mt]),Ho=i.useCallback(()=>Ie.current.active,[]),Tl=i.useCallback((w,q)=>{const J=oe.getCellValidation===void 0?void 0:oe.getCellValidation(w.row,w.col);if(J===void 0)return mc;const ee=oe.evaluateFormula,pe=Da(J,q,Ut,ee===void 0?void 0:ye=>ee(ye,w));return pe.ok||J.strict!==!0?mc:(He?.({cell:w,rule:J,text:q,message:pe.message}),Zt.current?.isKindEnabled("message")&&Nr.current("message",{message:pe.message,rejected:!0}),pe)},[oe,He,Ut]),je=Fg({enabled:!U,sinkRef:Fe,rootRef:Ke,adapter:oe,commitEdits:Cn,getActive:Ho,ensureCellVisible:Jt,focusSink:qt,rearmSink:ut,discardClip:Tt,isDragging:jo,rejectReadOnly:Fn,resolveEditAlign:w=>{if(oe.getCellFormat===void 0)return null;const q=co(oe,w.row,w.col);return Ca(Xt(w.row,w.col,q),q)},resolveEditPaint:w=>oe.getCellFormat===void 0?null:kf(Xt(w.row,w.col,co(oe,w.row,w.col))),editPaintRef:rl,repaintOverlay:$e,validateCommit:Tl});_t.current=je.isEditing,hl.current=je.requestCommit,ml.current=je.startEdit,To.current=je.getPointing,el.current=je.insertReference,tl.current=je.captureSink,nl.current=je.restoreSink;const $l=i.useCallback(()=>{je.cancelEdit(),sr()},[je.cancelEdit,sr]),ar=wg({enabled:!U,sinkRef:Fe,adapter:oe,isEditing:rt,getSelection:Ge,setSelection:Ze,commitPaste:Ru,maxOperationCells:C,onOperationRejected:$,onCopyMultiRange:H,repaintOverlay:$e,isDragging:jo,resize:{rowAxis:Ce,colAxis:fe,resizeTracks:Io},pendingPasteOptionsRef:ol,formats:G,onClipChange:ze,onClipboardUnavailable:Me,onEditRejected:_,rejectReadOnly:Fn,onPasteResolved:it});wl.current=ar.getClip,Cl.current=ar.discardClip,bl.current=ar.discardClipOnCommit,Rl.current=ar.onAdapterSwitch,zo.current=ar.paste;const ur=Yw({enabled:!U,adapter:oe,popovers:le,sinkRef:Fe,bodyRef:re,handleRef:ue,rowAxis:Ce,colAxis:fe,zoomRef:Pe,getActive:Ho,isEditing:rt,requestCommit:St,focusSink:qt,rearmSink:ut,isDraggingAny:cr,commitEdits:Cn,labels:yt,onHyperlinkOpen:Ne,anchors:Lo,repaintOverlay:$e,rejectReadOnly:Fn});Zt.current=ur,Nr.current=ur.open,il.current=ur.hideTip;const Mu=i.useCallback(()=>{const w=Ie.current.active;return Jt(w),Fr(w)},[Jt,Fr]),Bo=zg({adapter:oe,trackResize:k&&!U?dt:void 0,getSelection:Ge,commitEdits:Cn,getActive:Ho,isEditing:rt,requestCommit:St,cancelEdit:$l,getSessionText:je.getSessionText,validateCommit:Tl,insertAtCaret:je.insertAtCaret,refreshEditPaint:je.refreshPaint,maxOperationCells:C,onOperationRejected:$,colors:Mr,formats:G,getHighlight:()=>or.current,setHighlight:mu,popovers:le,openPopover:w=>Nr.current(w),onHyperlinkOpen:Ne,onPasteSpecialRequest:me,paste:w=>zo.current(w),rowAxis:Ce,colAxis:fe,resizeTracks:Io,defaultRowHeight:s,defaultColumnWidth:l,now:Be,announce:Nn,formatCommandAnnouncement:d,formatResizeAnnouncement:L,keyboardCellRect:Mu,rejectReadOnly:Fn});al.current=Bo,Do.current=Bo.executeCommand,cl.current=Bo.isCommandAvailable;const Nu=i.useMemo(()=>({table:fn,execute:w=>Do.current(w),isAvailable:w=>cl.current(w)}),[fn]),Fu=i.useCallback(()=>{Tt(),T?.()},[Tt,T]),Pu=i.useCallback(()=>{Tt(),F?.()},[Tt,F]);Dw({zoomRef:Pe,enabled:!U,sinkRef:Fe,rootRef:Ke,handOffFocusToRoot:gu,getSelection:Ge,setSelection:Ze,moveActive:Cu,ensureCellVisible:Jt,pageExtent:wu,isEditing:rt,requestCommit:St,startEdit:ir,commitEdits:Cn,maxOperationCells:C,onOperationRejected:$,rejectReadOnly:Fn,getClip:Pr,discardClip:Tt,isDragging:cr,abortDrag:zu,findDataEdge:oe.findDataEdge,getEditingMode:je.getEditingMode,cancelEdit:$l,onUndoRequest:Fu,onRedoRequest:Pu,onCellContextMenu:O,rowAxis:Ce,colAxis:fe,handleRef:ue,rearmSink:ut,commands:Nu,pointing:je,adapter:oe,hideNoteTip:()=>il.current(),closeRejectedMessage:sr,pendingPasteOptionsRef:ol,onPointFrame:ku});const _u=We.active.row,qu=We.active.col;i.useLayoutEffect(()=>{const w=Zt.current;w!==null&&(w.syncTipAriaDescribedBy(),w.isKindEnabled("message")&&(w.isOpen()==="message"&&w.close(),w.open("message")))},[_u,qu]),i.useLayoutEffect(()=>{$e()},[$e,ht.row,ht.column,ht.intersection]),i.useLayoutEffect(()=>{$e()},[$e,a?.startRow,a?.startCol,a?.endRow,a?.endCol]);const Iu=i.useCallback(w=>{(_t.current?.()??!1)||(w.preventDefault(),Ve(),ut())},[Ve,ut]),ju=i.useCallback(w=>{const q=Ke.current,J=w.relatedTarget,ee=q!==null&&!q.matches(":focus-visible");if(q!==null&&J instanceof Node&&q.contains(J)){w.target===q&&J===Fe.current&&!Mo.current&&qt({preventScroll:ee});return}(_t.current?.()??!1)||(qt({preventScroll:ee}),ut())},[qt,ut]),Hu=i.useCallback(w=>{const q=Ke.current,J=w.relatedTarget;q!==null&&J instanceof Node&&q.contains(J)||je.isFocusoutSuppressed()||_o(!1)},[je]),qr=i.useRef(null),dr=i.useCallback(()=>{const w=qr.current;w!==null&&(qr.current=null,window.removeEventListener("pointerup",w.up,!0),window.removeEventListener("pointercancel",w.cancel,!0))},[]),Wo=i.useCallback(()=>{if(qr.current!==null)return;const w=J=>{J.pointerType==="mouse"&&(dr(),J.button===1&&J.preventDefault())},q=J=>{J.pointerType==="mouse"&&dr()};qr.current={up:w,cancel:q},window.addEventListener("pointerup",w,!0),window.addEventListener("pointercancel",q,!0)},[dr]);i.useEffect(()=>dr,[dr]),i.useEffect(()=>{const w=Ke.current;if(U||w===null)return;let q=0;const J=ye=>{if(ye.pointerType!=="mouse"){(_t.current?.()??!1)||_o(!1);return}q=ye.buttons,ye.button===1&&(ye.target===Fe.current&&(_t.current?.()??!1)||Wo())},ee=ye=>{ye.pointerType==="mouse"&&(q=ye.buttons)},pe=ye=>{if(ye.pointerType!=="mouse"||ye.buttons===q)return;const Je=ye.buttons&~q;q=ye.buttons,ye.preventDefault(),(Je&4)!==0&&Wo()};return w.addEventListener("pointerdown",J,!0),w.addEventListener("pointerup",ee,!0),w.addEventListener("pointermove",pe,!0),()=>{w.removeEventListener("pointerdown",J,!0),w.removeEventListener("pointerup",ee,!0),w.removeEventListener("pointermove",pe,!0)}},[U,Wo]);const Bu=i.useCallback(w=>{if(!(w.target!==w.currentTarget||w.pointerType!=="mouse")&&(w.preventDefault(),w.button===0)){if(gn()){Ve();return}if(rt()&&!St()){Ve();return}Ve()}},[Ve,rt,St,gn]),Vo=i.useRef(!1);i.useLayoutEffect(()=>{if(U){Vo.current=!1;return}if(Vo.current)return;Vo.current=!0,ut();const w=(Ke.current?.clientHeight??0)/Pe.current;w>0&&Ce.totalSize()>0&&Te.setRowRange(0,Ce.indexAt(Math.min(w-1,Ce.totalSize()-1)));const q=(Ke.current?.clientWidth??0)/Pe.current;q>0&&fe.totalSize()>0&&Te.setColRange(0,fe.indexAt(Math.min(q-1,fe.totalSize()-1)))},[U,ut,Te,Ce,fe]);const Ll=i.useRef(t);i.useLayoutEffect(()=>{Ll.current!==t&&(Ll.current=t,kt.cancelDrag(),$t.cancelDrag(),Lt.cancelDrag(),dt.cancelDrag(),Et.cancelDrag(),mt.cancelDrag(),je.cancelEdit(),Zt.current?.hideTip(),Zt.current?.close(),U?(Ie.current=In,ke(In)):Ze(In),Rl.current())},[t,U,Ze,kt,$t,Lt,dt,Et,mt,Te,je.cancelEdit]);const Dl=i.useRef({adapter:oe,rows:Ce.count,cols:fe.count}),{getSessionCell:zl,cancelEdit:Ml}=je;i.useLayoutEffect(()=>{const w=Dl.current,q=Ce.count,J=fe.count;if(Dl.current={adapter:oe,rows:q,cols:J},w.adapter!==oe||q>=w.rows&&J>=w.cols)return;U?(Ie.current=In,ke(In)):Ze(vw(Ie.current,q,J)),kt.cancelDrag(),$t.cancelDrag(),Lt.cancelDrag(),dt.cancelDrag(),Et.cancelDrag(),mt.cancelDrag();const ee=ft=>U||ft.row>=q||ft.col>=J,pe=zl();pe!==null&&ee(pe)&&Ml();const ye=Lo.current;if(ye.tip!==null&&ee(ye.tip)&&Zt.current?.hideTip(),ye.interactive!==null&&ee(ye.interactive)){const ft=Ke.current?.contains(document.activeElement)===!0;Zt.current?.close({restoreFocus:ft})}const Je=Pr();Je!==null&&!Je.foreign&&ee({row:Je.range.endRow,col:Je.range.endCol})&&Tt()},[oe,Ce.count,fe.count,U,Ze,kt,$t,Lt,dt,Et,mt,zl,Ml,Pr,Tt]);const Nl=i.useRef(c),Fl=i.useRef(u),Pl=i.useRef(h),_l=i.useRef(m);i.useLayoutEffect(()=>{(Nl.current!==c||Fl.current!==u||Pl.current!==h||_l.current!==m)&&(Nl.current=c,Fl.current=u,Pl.current=h,_l.current=m,kt.cancelDrag(),$t.cancelDrag(),Lt.cancelDrag(),dt.cancelDrag(),Et.cancelDrag(),mt.cancelDrag())},[c,u,h,m,kt,$t,Lt,dt,Et,mt]),i.useLayoutEffect(()=>{Rt(),vt(),$e()},[c,u,h,m,Rt,vt,$e]);const ql=i.useRef(p);i.useLayoutEffect(()=>{ql.current!==p&&(ql.current=p,Tt())},[p,Tt]),i.useLayoutEffect(()=>{$e()},[$e,We]);const bn=i.useCallback(()=>{const w=al.current;if(w===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return w},[]);if(i.useImperativeHandle(zr,()=>({resizeRow:(w,q)=>{const J=Math.round(q);Ce.resize(w,J),ue.current?.updateRowSize(w,J),Te.bumpRowGeometry(),Rt(),$e(),zn(),It()},resizeColumn:(w,q)=>{const J=Math.round(q);fe.resize(w,J),ue.current?.updateColSize(w,J),Te.bumpColVersion(),vt(),$e(),zn(),It()},autoFitColumns:w=>{for(const q of w)if(!Number.isInteger(q)||q<0||q>=fe.count)throw new RangeError(`[spreadsheet] autoFitColumns: each column must be a whole number from 0 to ${fe.count-1} (got ${String(q)})`);return dt.autofitColumnsInAllRows(w)},scrollToCell:(w,q)=>{ue.current?.scrollToCell(w.row,w.col,q)},focus:w=>{qt(w),rt()||ut()},executeCommand:w=>Do.current(w),applyFormat:w=>bn().applyFormat(w),setBorders:(w,q)=>bn().setBorders(w,q),setHyperlink:w=>bn().setHyperlink(w),setNote:w=>bn().setNote(w),addComment:w=>bn().addComment(w),setValidation:w=>bn().setValidation(w),paste:w=>zo.current(w),getSelection:()=>Ie.current,getBaseFormat:w=>oe.getCellFormat===void 0?void 0:oe.getCellFormat(w.row,w.col),getPaintedFormat:w=>oe.getCellFormat===void 0?void 0:Xt(w.row,w.col,co(oe,w.row,w.col)),startEdit:w=>{ir(w)},openPopover:w=>{Nr.current(w)}}),[Ce,fe,Te,vt,Rt,$e,zn,It,dt,qt,rt,ut,oe,Xt,ir,bn]),U)return K.jsx("div",{className:dn?`aqsp-root ${dn}`:"aqsp-root","data-aqsp-empty":"","data-testid":et});const Wu=f!==void 0||E!==void 0||d!==void 0||g!==void 0||L!==void 0,Vu=o===void 0?{"aria-label":yt.rootAriaLabel}:{"aria-labelledby":o};return K.jsxs("div",{ref:Ke,className:dn?`aqsp-root ${dn}`:"aqsp-root",role:"group",...Vu,tabIndex:0,onFocus:ju,onBlur:Hu,"data-aqsp-root":"","data-aqsp-headings-hidden":b?void 0:"","data-aqsp-framed":a===void 0?void 0:"","data-testid":et,children:[K.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":Ue,onPointerDown:Bu,style:Ue===1?void 0:{width:`${100/Ue}%`,height:`${100/Ue}%`,transform:`scale(${Ue})`,"--_aqsp-zoom":String(Ue)},children:[b?K.jsxs(K.Fragment,{children:[K.jsx("div",{ref:Ee,className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:w=>{if(w.pointerType==="mouse"&&(w.preventDefault(),w.button===0)){if(gn()){Ve();return}if(rt()&&!St()){Ve();return}Ve(),Ze({ranges:[ve({row:0,col:0},{row:oe.rowCount-1,col:oe.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),K.jsx(gw,{viewStore:Te,colAxis:fe,frozenCols:c,frozenTrailingCols:h,handleRef:ue,bandRef:ge,colTrackRef:se,windowOriginXRef:be,repaintColHeaders:vt,selectionRanges:We.ranges,enableResizeUI:k,dividerLeadingRef:Xe,dividerTrailingRef:ce}),K.jsx(ww,{viewStore:Te,rowAxis:Ce,handleRef:ue,bandRef:he,selectionRanges:We.ranges,rowTrackRef:qe,windowOriginYRef:de,repaintHeaders:Rt,enableResizeUI:k,frozenRows:u,frozenTrailingRows:m,dividerLeadingRef:xe,dividerTrailingRef:tt})]}):null,K.jsxs("div",{ref:Ae,className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[K.jsx(mw,{adapter:oe,rowAxis:Ce,colAxis:fe,viewStore:Te,handleRef:ue,bodyRef:re,dataVersion:p,defaultColumnWidth:l,frozenColumns:c,frozenRows:u,frozenTrailingColumns:h,frozenTrailingRows:m,headerRows:n,labelledBy:o,gridLabel:o===void 0?yt.rootAriaLabel:void 0,readOnly:r,tapScrollCircleOptions:R,overscanRows:pc("overscanRows",N),overscanCols:pc("overscanCols",W),background:z,onRenderTruncated:I,renderCell:X,onScroll:vu,onRangeChange:Su,focusSink:Ve,isEditing:rt,requestCommit:St,testId:et?`${et}-vs`:void 0,__onCellRender:er,__maxRenderedCells:An,cfIndexRef:mn,cfMemoRef:rr,isPointing:gn,locale:Ut,scrollLabels:ko}),K.jsx(Vm,{rowAxis:Ce,colAxis:fe,handleRef:ue,sinkRef:Fe,getSelection:Ge,editing:je.editing,virtualKeyboard:bu,repaintRef:Qs,dragFrameRef:xo,getClip:Pr,getIsDraggingAny:cr,getIsFillDragging:Et.isDragging,fillFrameRef:kl,resizeGuideFrameRef:El,fillHandleNodeRef:Ol,enableFillHandle:v,frozenCols:c,frozenRows:u,trailingCols:h,trailingRows:m,sinkAriaLabel:yt.sinkAriaLabel,sinkReadOnly:r,sinkKeyShortcuts:xn,onSinkMouseDown:Iu,editPaintRef:rl,highlightRef:or,frameRange:a,highlightColors:Ao,popoverAnchors:Lo,interactiveAnchorRef:sl,tipAnchorRef:ll}),ur.layerEnabled?K.jsx(Bw,{controller:ur,labels:yt,renderPopover:Oe,interactiveAnchorRef:sl,tipAnchorRef:ll}):null]}),Wu?K.jsx("div",{ref:at,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]}),K.jsx("div",{ref:Se,className:"aqsp-reveal","aria-hidden":"true","data-aqsp-reveal":""})]})});exports.iterateTsvPrefixRows=Vt.iterateTsvPrefixRows;exports.iterateTsvRows=Vt.iterateTsvRows;exports.measureTsv=Vt.measureTsv;exports.parseTsv=Vt.parseTsv;exports.serializeClipboardTsv=Vt.serializeClipboardTsv;exports.serializeTsv=Vt.serializeTsv;exports.columnIndexToName=Le.columnIndexToName;exports.columnNameToIndex=Le.columnNameToIndex;exports.BORDER_DEFAULT_COLOR=Ds;exports.CommentPopover=Ha;exports.DEFAULT_CUSTOM_COLORS=hu;exports.DEFAULT_HIGHLIGHT_COLORS=ja;exports.DEFAULT_SHORTCUTS=Aa;exports.LinkPopover=Ba;exports.ListPopover=Wa;exports.MessagePopover=Va;exports.NotePopover=Ya;exports.NoteTip=Ka;exports.SPREADSHEET_LABEL_CATALOGS=xa;exports.SPREADSHEET_RESERVED_SHORTCUTS=Wh;exports.Spreadsheet=u0;exports.canonicalizeFormat=xt;exports.detectClipSource=Oc;exports.enumerateRangeCells=tn;exports.estimatePasteCellCount=Lh;exports.expandPaste=Dh;exports.formatCellValue=Gn;exports.formatEquals=od;exports.fromR1C1=Tr;exports.makeRange=ve;exports.mergeFormat=Ms;exports.normalizeHyperlink=an;exports.parseChord=nn;exports.parseClipPayload=hs;exports.parseHtmlTable=wa;exports.rangeContains=On;exports.rangeSize=Ct;exports.resolveLabel=_e;exports.resolveLabels=Ta;exports.serializeClipPayload=Sc;exports.serializeHtmlTable=pa;exports.shiftFormula=Gc;exports.toR1C1=yo;exports.validateCellText=Da;
|