@aiquants/spreadsheet 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1103 -0
- package/LICENSE.md +155 -0
- package/README.md +817 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +1960 -0
- package/dist/index.d.ts +1960 -0
- package/dist/index.js +7711 -0
- package/dist/styles/spreadsheet.css +2 -0
- package/dist/styles/spreadsheet.standalone.css +3 -0
- package/package.json +94 -0
- package/src/Spreadsheet.tsx +2313 -0
- package/src/clipboard/clipPayload.ts +1242 -0
- package/src/clipboard/fixtures/excel.fixture.ts +301 -0
- package/src/clipboard/fixtures/html.fixture.ts +90 -0
- package/src/clipboard/fixtures/sheets.fixture.ts +83 -0
- package/src/clipboard/htmlInterop.ts +1694 -0
- package/src/clipboard/numberFormatCodec.ts +870 -0
- package/src/clipboard/pasteSpecial.ts +608 -0
- package/src/clipboard/tiling.ts +370 -0
- package/src/clipboard/tsv.ts +186 -0
- package/src/clipboard/useClipboard.ts +1154 -0
- package/src/commands/selfCalc.ts +279 -0
- package/src/commands/useCommands.ts +946 -0
- package/src/editor/useCellEditor.ts +708 -0
- package/src/grid/CellView.tsx +51 -0
- package/src/grid/GridBody.tsx +489 -0
- package/src/header/ColumnHeader.tsx +167 -0
- package/src/header/RowHeader.tsx +144 -0
- package/src/header/columnName.ts +31 -0
- package/src/header/resizeGates.ts +146 -0
- package/src/header/resizeStrips.ts +79 -0
- package/src/header/useHeaderResize.ts +598 -0
- package/src/header/useHeaderSelection.ts +454 -0
- package/src/index.ts +122 -0
- package/src/keyboard/compositionGuard.ts +53 -0
- package/src/keyboard/ensureCellVisible.ts +77 -0
- package/src/keyboard/shortcuts.ts +718 -0
- package/src/keyboard/useGridKeyboard.ts +940 -0
- package/src/model/axisModel.ts +186 -0
- package/src/model/cellAnnotations.ts +92 -0
- package/src/model/cellCoord.ts +114 -0
- package/src/model/cellFormat.ts +562 -0
- package/src/model/cellPaint.ts +537 -0
- package/src/model/conditionalFormat.ts +805 -0
- package/src/model/dataAdapter.ts +478 -0
- package/src/model/dataValidation.ts +542 -0
- package/src/model/formulaRefs.ts +984 -0
- package/src/model/frozenPartition.ts +100 -0
- package/src/model/labels.ts +228 -0
- package/src/model/viewStore.ts +124 -0
- package/src/overlay/SelectionOverlay.tsx +1425 -0
- package/src/overlay/useFillHandle.ts +432 -0
- package/src/popover/CommentPopover.tsx +109 -0
- package/src/popover/LinkPopover.tsx +108 -0
- package/src/popover/ListPopover.tsx +161 -0
- package/src/popover/MessagePopover.tsx +36 -0
- package/src/popover/NotePopover.tsx +106 -0
- package/src/popover/NoteTip.tsx +26 -0
- package/src/popover/PopoverLayer.tsx +210 -0
- package/src/popover/placement.ts +138 -0
- package/src/popover/usePopovers.ts +642 -0
- package/src/selection/selectionState.ts +239 -0
- package/src/selection/useAutoScroller.ts +226 -0
- package/src/selection/usePointDrag.ts +273 -0
- package/src/selection/useSelectionEngine.ts +687 -0
- package/src/styles/components.entry.css +10 -0
- package/src/styles/spreadsheet.css +1029 -0
- package/src/styles/standalone.entry.css +9 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("react/jsx-runtime"),Mn=require("@aiquants/virtualscroll"),i=require("react"),Fo=1e3,rn=1e4,$o=10,Ns=(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),No=(e,t,n,r)=>{if(t.length===0)return{ok:!0,entries:[]};const o=r.axisKind==="row"?Math.floor(r.maxOperationCells/$o):r.maxOperationCells;if(t.length>o)return{ok:!1,reason:"limit",count:t.length};const s=new Map;for(const a of t){if(!(Number.isFinite(a.size)&&a.size>=0))throw new RangeError(`[spreadsheet] gateResizeEntries requires a finite size >= 0, received ${a.size} at index ${a.index}`);s.set(a.index,Math.min(Math.round(a.size),rn))}let l=[...s].map(([a,m])=>({index:a,size:m}));if(e.count-e.hiddenCount()-Ns(e,l)===0){const a=n===null?l[0].index:n;l=l.map(m=>m.index===a?{index:m.index,size:1}:m)}if(r.axisKind==="row"){const a=e.hiddenCount()+Ns(e,l);if(a>r.rowHiddenLimit)return{ok:!1,reason:"bounds",count:a}}return{ok:!0,entries:l}},Lo="#000000",Vn=e=>e===void 0?{}:{minimumFractionDigits:e,maximumFractionDigits:e},wa=20,Ca=256,Kn=new Map,Zr=new WeakMap,qe=e=>{const t=e.trim();return/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/.test(t)&&Number.isFinite(Number(t))?t:null},ba=(e,t)=>{const n=e.search(/[eE]/);return n<0?`${e}e${t}`:`${e.slice(0,n)}e${Number(e.slice(n+1))+t}`},ya=e=>{switch(e.type){case"number":return{signDisplay:"negative",useGrouping:e.grouping??!1,...e.decimals===void 0?{maximumFractionDigits:wa}:Vn(e.decimals)};case"percent":return{signDisplay:"negative",style:"percent",...Vn(e.decimals)};case"currency":return{signDisplay:"negative",style:"currency",currency:e.currency,...Vn(e.decimals)};case"scientific":return{signDisplay:"negative",notation:"scientific",...Vn(e.decimals)};default:return null}},va=e=>{const t=Zr.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=Kn.get(n);if(r!==void 0)return Zr.set(e,r),r;Kn.size>=Ca&&Kn.clear();const o=ya(e);let s=null;if(o!==null)try{s=new Intl.NumberFormat(e.locale,o)}catch{s=null}return Kn.set(n,s),Zr.set(e,s),s},Ra=(e,t)=>{switch(t){case 2:return e%4===0&&e%100!==0||e%400===0?29:28;case 4:case 6:case 9:case 11:return 30;default:return 31}},Ul=e=>{const t=/^(\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>Ra(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},ka=(e,t)=>{const n=Ul(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)}})},on=(e,t)=>{if(t===void 0||t.type==="text"||e==="")return e;if(t.type==="date")return ka(e,t.pattern??"yyyy/MM/dd");const n=qe(e);if(n===null)return e;const r=va(t);return r===null?e:r.format(t.type==="percent"&&t.scale===!1?ba(n,-2):n)},Ls=(e,t,n)=>e!==void 0?e:t!==void 0&&t.type==="text"?"left":t!==void 0&&t.type==="date"?Ul(n)!==null?"right":"left":qe(n)!==null?"right":"left",En=e=>e==="center"?"center":e==="right"?"flex-end":"flex-start",Yl=["align","background","bold","borders","color","fontFamily","fontSize","italic","strikethrough","underline","value","verticalAlign","wrap"],Ea=["bottom","left","right","top"],Xl=(e,t,n)=>{e[t]=n},Gl=e=>{const t=e,n={};for(const r of Object.keys(t).sort())t[r]!==void 0&&(n[r]=t[r]);return n},Sa=e=>{if(e===void 0)return;const t={};for(const n of Ea){const r=e[n];r!==void 0&&(t[n]=Gl(r))}return Object.keys(t).length===0?void 0:t},Ke=e=>{const t={};for(const n of Yl){const r=n==="borders"?Sa(e.borders):n==="value"?e.value===void 0?void 0:Gl(e.value):e[n];r!==void 0&&r!==!1&&Xl(t,n,r)}return Object.keys(t).length===0?void 0:t},Po=(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]||!Po(o[c],s[c]))return!1}return!0},Aa=(e,t)=>e===t?!0:Po(e===void 0?void 0:Ke(e),t===void 0?void 0:Ke(t)),zo=(e,t)=>{const n={};for(const o of Yl){const s=t[o];Xl(n,o,s===void 0?e?.[o]:s===null?void 0:s)}const r=Ke(n);return Po(r,e===void 0?void 0:Ke(e))?e:r},Zl="data-aqsp-clip",mr="application/x-aqsp-clip",wo=512,Ps=16*1024,Co=`${Zl}=`,xa=16,qo=()=>{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(xa));let n="";for(const r of t)n+=r.toString(16).padStart(2,"0");return n},Fn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),re=e=>typeof e=="string",Me=e=>typeof e=="boolean",vt=e=>typeof e=="number"&&Number.isFinite(e),Ve=e=>typeof e=="number"&&Number.isInteger(e)&&e>=0,zs=e=>Ve(e)&&e>=1,Oa=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=rn,it=e=>{const t=new Set(e);return n=>typeof n=="string"&&t.has(n)},Da=e=>t=>Array.isArray(t)&&t.every(e),we=(e,t)=>({fields:new Map(Object.entries(e)),required:t}),at=(e,t)=>{if(!Fn(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},_o=e=>t=>{if(!Fn(t)||typeof t.type!="string")return!1;const n=e.get(t.type);return n!==void 0&&at(t,n)},Ta=["left","center","right"],Ma=["top","middle","bottom"],Fa=["thin","medium","thick","dashed","dotted","double","hair"],Jr=["gt","gte","lt","lte","eq","neq","between","notBetween"],$a=["contains","notContains","startsWith","endsWith","isEmail","isUrl"],Na=["eq","neq","gt","gte","lt","lte","between","notBetween"],La=["contains","notContains","startsWith","endsWith"],Pa=new Map([["number",we({type:re,decimals:vt,grouping:Me,locale:re},["type"])],["percent",we({type:re,decimals:vt,scale:Me,locale:re},["type"])],["currency",we({type:re,currency:re,decimals:vt,locale:re},["type","currency"])],["scientific",we({type:re,decimals:vt,locale:re},["type"])],["date",we({type:re,pattern:re},["type"])],["text",we({type:re},["type"])]]),za=we({style:it(Fa),color:re},["style"]),Un=e=>at(e,za),qa=we({top:Un,right:Un,bottom:Un,left:Un},[]),_a=we({value:_o(Pa),align:it(Ta),verticalAlign:it(Ma),wrap:Me,background:re,color:re,bold:Me,italic:Me,underline:Me,strikethrough:Me,fontFamily:re,fontSize:vt,borders:e=>at(e,qa)},[]),Ia=e=>at(e,_a),Lt={strict:Me,inputMessage:re,errorMessage:re},Ha=new Map([["list",we({...Lt,type:re,values:Da(re),showDropdown:Me},["type","values"])],["number",we({...Lt,type:re,op:it(Jr),a:re,b:re},["type","op","a"])],["textLength",we({...Lt,type:re,op:it(Jr),a:vt,b:vt},["type","op","a"])],["date",we({...Lt,type:re,op:it(Jr),a:re,b:re},["type","op","a"])],["text",we({...Lt,type:re,op:it($a),value:re},["type","op"])],["checkbox",we({...Lt,type:re,checked:re,unchecked:re},["type"])],["custom",we({...Lt,type:re,formula:re},["type","formula"])]]),ja=_o(Ha),Ba=we({startRow:Ve,startCol:Ve,endRow:Ve,endCol:Ve},["startRow","startCol","endRow","endCol"]),Wa=e=>{if(!at(e,Ba))return!1;const{startRow:t,startCol:n,endRow:r,endCol:o}=e;return Ve(t)&&Ve(r)&&Ve(n)&&Ve(o)&&t<=r&&n<=o},Va=we({color:re,value:vt},["color"]),Qr=e=>at(e,Va),Ka=new Map([["cellValue",we({type:re,op:it(Na),a:re,b:re},["type","op","a"])],["text",we({type:re,op:it(La),value:re},["type","op","value"])],["empty",we({type:re},["type"])],["notEmpty",we({type:re},["type"])],["colorScale",we({type:re,min:Qr,mid:Qr,max:Qr},["type","min","max"])],["customFormula",we({type:re,formula:re},["type","formula"])]]),Ua=we({background:re,color:re,bold:Me,italic:Me,underline:Me,strikethrough:Me},[]),Ya=we({sourceRuleId:re,ranges:Array.isArray,condition:_o(Ka),style:e=>at(e,Ua),stopIfTrue:Me},["sourceRuleId","ranges","condition","style"]),Xa=(e,t,n)=>{if(!at(e,Ya))return!1;const r=e.ranges;if(!Array.isArray(r))return!1;for(const o of r)if(!Wa(o)||o.endRow>=t||o.endCol>=n)return!1;return!0},Ga=we({text:re,author:re,createdAt:re},["text","author","createdAt"]),Za=e=>at(e,Ga),Ja=(e,t,n)=>{if(!Fn(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(!Ve(o)||o>=t)return!1;break;case"val":if(!Ve(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(Za)))return!1;break;default:return!1}}return!0},qs=(e,t)=>Array.isArray(e)&&e.length===t&&e.every(Oa),Qa=new Set(["v","rows","cols","clipId","formats","validations","cells","colWidths","rowHeights","wholeRows","wholeCols","conditionalFormats"]),Jl=e=>{if(!Fn(e))return!1;for(const c of Object.keys(e))if(e[c]!==void 0&&!Qa.has(c))return!1;if(e.v!==1)return!1;const t=e.rows,n=e.cols;if(!(zs(t)&&zs(n))||typeof e.clipId!="string"||e.clipId==="")return!1;const r=e.formats;if(!(Array.isArray(r)&&r.every(Ia)))return!1;const o=e.validations;if(!(Array.isArray(o)&&o.every(ja)))return!1;const s=e.cells;if(!Array.isArray(s)||s.length!==t)return!1;for(const c of s){if(!Array.isArray(c)||c.length!==n)return!1;for(const a of c)if(!Ja(a,r.length,o.length))return!1}if(e.colWidths!==void 0&&!qs(e.colWidths,n)||e.rowHeights!==void 0&&!qs(e.rowHeights,t)||typeof e.wholeRows!="boolean"||typeof e.wholeCols!="boolean")return!1;const l=e.conditionalFormats;return Array.isArray(l)&&l.every(c=>Xa(c,t,n))},On=e=>Array.isArray(e)?`[${e.map(On).join(",")}]`:Fn(e)?`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${On(e[n])}`).join(",")}}`:JSON.stringify(e),eu=e=>{const t=Ke(e);return t===void 0?"{}":JSON.stringify(t)},tu=e=>`{"text":${JSON.stringify(e.text)},"author":${JSON.stringify(e.author)},"createdAt":${JSON.stringify(e.createdAt)}}`,nu=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(tu).join(",")}]`),e.link!==void 0&&(t+=`,"link":${JSON.stringify(e.link)}`),`${t}}`},Ql=e=>{if(!Jl(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(eu).join(","),r=e.validations.map(On).join(","),o=e.cells.map(a=>`[${a.map(nu).join(",")}]`).join(","),s=e.colWidths===void 0?"":`,"colWidths":[${e.colWidths.join(",")}]`,l=e.rowHeights===void 0?"":`,"rowHeights":[${e.rowHeights.join(",")}]`,c=e.conditionalFormats.map(On).join(",");return`${t},"formats":[${n}],"validations":[${r}],"cells":[${o}]${s}${l},"wholeRows":${e.wholeRows},"wholeCols":${e.wholeCols},"conditionalFormats":[${c}]}`},bo=e=>{let t;try{t=JSON.parse(e)}catch{return null}return Jl(t)?t:null},ru=/&(?:amp|lt|gt|quot|#39|nbsp);/g,ou=Object.freeze({"&":"&","<":"<",">":">",""":'"',"'":"'"," ":" "}),ei=e=>e.includes("&")?e.replace(ru,t=>ou[t]):e,su=/^\{"v":1,"rows":([1-9]\d{0,14}),"cols":([1-9]\d{0,14}),"clipId":"([^"\\]+)"/,_s=e=>{const t=e.length>wo?e.slice(0,wo):e,n=su.exec(ei(t));return n===null?null:{v:1,rows:Number(n[1]),cols:Number(n[2]),clipId:n[3]}},lu=e=>{const t=e.indexOf(Co);if(t===-1)return null;const n=t+Co.length,r=e.charAt(n);return r!=="'"&&r!=='"'?null:{start:n+1,quote:r}},ti=(e,t)=>{if(t==="event"&&e.types.includes(mr))return{kind:"mime",json:e.getData(mr)};if(!e.types.includes("text/html"))return null;const n=e.getData("text/html"),r=lu(n);return r===null?null:{kind:"attribute",html:n,at:r}},iu=(e,t)=>{const n=ti(e,t);return n===null?null:n.kind==="mime"?_s(n.json):_s(n.html.slice(n.at.start,n.at.start+wo))},cu=(e,t)=>{const n=ti(e,t);if(n===null)return null;if(n.kind==="mime")return bo(n.json);const r=n.html.indexOf(n.at.quote,n.at.start);return r===-1?null:bo(ei(n.html.slice(n.at.start,r)))},au=/<google-sheets-html-origin[\s>]/,uu='data-sheets-root="1"',du=/<meta\s+name=["']?Generator["']?\s+content=["']?Microsoft Excel/,fu="mso-",pu=/\.xl\d+\s*\{/,hu="<table",mu=e=>e.includes(Co)?"aqsp":au.test(e)&&e.includes(uu)?"sheets":du.test(e)||e.includes(fu)||pu.test(e)?"excel":null,ni=(e,t)=>{if(t==="event"&&e.types.includes(mr))return"aqsp";if(e.types.includes("text/html")){const n=e.getData("text/html"),r=n.length>Ps?n.slice(0,Ps):n,o=mu(r);if(o==="aqsp")return"aqsp";if(n.includes(hu))return o===null?"html":o}return e.types.includes("text/plain")&&e.getData("text/plain")!==""?"tsv":"none"},Io=1e3,ri=65534,gu=9,wu=10,Cu=12,bu=13,yu=32,oi=34,si=39,vu=43,Ho=47,Is=48,Ru=57,ku=61,Eu=62,Su=97,Au=98,xu=100,Ou=102,li=104,ii=114,ci=116,Du=["able","body","head","foot"],Sn=e=>e===yu||e===gu||e===wu||e===bu||e===Cu,yo=e=>e===Eu||e===Ho||Sn(e),Tu=e=>Sn(e)||e===Ho||e===oi||e===si,Mu=(e,t,n,r)=>{if(t===0||!Tu(e.charCodeAt(t-1)))return null;let o=t+n;for(;Sn(e.charCodeAt(o));)o+=1;if(e.charCodeAt(o)!==ku)return 1;for(o+=1;Sn(e.charCodeAt(o));)o+=1;const s=e.charCodeAt(o);for((s===oi||s===si)&&(o+=1);Sn(e.charCodeAt(o));)o+=1;e.charCodeAt(o)===vu&&(o+=1);let l=0,c=0;for(let a=e.charCodeAt(o);a>=Is&&a<=Ru;a=e.charCodeAt(o))l=l*10+(a-Is),c+=1,o+=1;return c===0||l===0?1:l>r?r:l},Hs=(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=Mu(e,r,t.length,n);if(l!==null)return l}return 1}},Fu=(e,t)=>{if(e.charCodeAt(t+2)!==ci)return!1;const n=e.charCodeAt(t+3);if(n===ii)return yo(e.charCodeAt(t+4));if(n!==Su&&n!==Au&&n!==li&&n!==Ou)return!1;for(const r of Du)if(e.startsWith(r,t+3)&&yo(e.charCodeAt(t+3+r.length)))return!0;return!1},$u=e=>{const t=e.toLowerCase(),n=Hs(t,"colspan",Io),r=Hs(t,"rowspan",ri);let o=0;const s=_=>(o!==-1&&o<_&&(o=t.indexOf(">",_)),o===-1?t.length:o);let l=0,c=0,a=0,m=0,f=!1;const A=new Map,L=(_,V)=>{const v=A.get(_);A.set(_,v===void 0?V:v+V)},$=()=>{f&&a+m>c&&(c=a+m),f=!1},T=()=>{$(),l+=1,f=!0,a=0;const _=A.get(l-1);_!==void 0&&(m+=_)};for(let _=t.indexOf("<");_!==-1;_=t.indexOf("<",_+1)){const V=t.charCodeAt(_+1);if(V===Ho){Fu(t,_)&&$();continue}if(V!==ci||!yo(t.charCodeAt(_+3)))continue;const v=t.charCodeAt(_+2);if(v===ii)T();else if(v===xu||v===li){f||T();const M=_+3,D=s(M),x=n(M,D);a+=x;const N=r(M,D);N>1&&(L(l,x),L(l-1+N,-x))}}return $(),{rows:l,cols:c}},ai=e=>{const t=[],n=new Map;return{intern:o=>{const s=e(o),l=n.get(s);if(l!==void 0)return l;const c=t.length;return t.push(o),n.set(s,c),c},entries:t}},ui=()=>{const e=new WeakMap,t=ai(r=>JSON.stringify(r));return{intern:r=>{if(e.has(r))return e.get(r);const o=Ke(r),s=o===void 0?void 0:t.intern(o);return e.set(r,s),s},entries:t.entries}},Nu=()=>{const e=new WeakMap,t=ai(On);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}},Lu=new Set(["http:","https:","mailto:","tel:"]),St=e=>{const t=e.trim();if(!URL.canParse(t))return null;const n=new URL(t);return Lu.has(n.protocol)?n.href:null},cn=e=>{if(e===void 0)return;const t=St(e);return t===null?void 0:t},di=(e,t)=>e.startCol===0&&e.endCol===t-1,fi=(e,t)=>e.startRow===0&&e.endRow===t-1,vo=13,lt=Object.freeze({style:Object.freeze({}),lineBoxPx:vo,verticalAlign:"middle"}),Pu={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"},zu=new Map(Object.entries(Pu)),qu=/^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/,_u=/^rgba?\((.*)\)$/,pi=/^(\d+(?:\.\d+)?)%$/,Yn=e=>e.toString(16).padStart(2,"0"),eo=e=>{const t=pi.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},Iu=e=>{const t=pi.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},Hu=e=>{const t=e.trim().split(/\s*[,/]\s*|\s+/);if(t.length!==3&&t.length!==4)return null;const n=eo(t[0]),r=eo(t[1]),o=eo(t[2]);if(n===null||r===null||o===null)return null;const s=`#${Yn(n)}${Yn(r)}${Yn(o)}`;if(t.length===3)return s;const l=Iu(t[3]);return l===null?null:l===255?s:`${s}${Yn(l)}`},Fe=e=>{const t=e.trim().toLowerCase(),n=qu.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=_u.exec(t);if(r!==null)return Hu(r[1]);const o=zu.get(t);return o===void 0?null:o},js={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"}},Bs=e=>{if(!Object.hasOwn(js,e.style))return null;const t=js[e.style],n=e.color===void 0?Lo:Fe(e.color);return n===null?null:`${t.width}px ${t.line} ${n}`},ju={top:"flex-start",middle:"center",bottom:"flex-end"},Bu=e=>e==="left"||e==="center"||e==="right",hi=e=>e==="top"||e==="middle"||e==="bottom",mi=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e*4/3:null,gi=(e,t)=>{if(typeof e.background=="string"){const s=Fe(e.background);s!==null&&(t.background=s)}if(typeof e.color=="string"){const s=Fe(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=mi(e.fontSize);o!==null&&(t.fontSize=`${o}px`),e.wrap===!0&&(t.whiteSpace="pre-wrap")},Xn=(e,t)=>{const n=e===void 0?null:Bs(e);return n!==null?n:t===void 0?null:Bs(t)},to=(e,t,n,r,o)=>{const s={},l={};e!==void 0&&(Bu(e.align)&&(l["data-aqsp-align"]=e.align,s.justifyContent=En(e.align)),hi(e.verticalAlign)&&(l["data-aqsp-valign"]=e.verticalAlign,s.alignItems=ju[e.verticalAlign]),e.wrap===!0&&(l["data-aqsp-wrap"]=""),gi(e,s));const c=e?.borders,a=Xn(c?.right,t);a!==null&&(s.borderRight=a);const m=Xn(c?.bottom,n);if(m!==null&&(s.borderBottom=m),r){const f=Xn(c?.left,void 0);f!==null&&(s.borderLeft=f)}if(o){const f=Xn(c?.top,void 0);f!==null&&(s.borderTop=f)}return Object.keys(s).length===0&&Object.keys(l).length===0?null:Object.freeze({style:Object.freeze(s),attrs:Object.freeze(l)})},Ws=new WeakMap,Wu=(e,t,n,r,o)=>{const s=t?.borders?.left,l=n?.borders?.top,c=!(r||o)&&s===void 0&&l===void 0;if(e===void 0)return c?null:to(void 0,s,l,r,o);if(!c)return to(e,s,l,r,o);const a=Ws.get(e);if(a!==void 0)return a;const m=to(e,void 0,void 0,!1,!1);return Ws.set(e,m),m},Vu=e=>{if(e===void 0)return lt;const t={};gi(e,t);const n=mi(e.fontSize),r=n===null?vo:Math.round(n),o=hi(e.verticalAlign)?e.verticalAlign:"middle";return Object.keys(t).length===0&&r===vo&&o==="middle"?lt:Object.freeze({style:Object.freeze(t),lineBoxPx:r,verticalAlign:o})},Ku="#REF!",Uu=11,Yu=15,Xu=4096,cr=33,An=34,jo=36,Gu=38,Ro=39,wi=40,Zu=42,Ju=43,Qu=44,Ci=45,ed=46,td=47,en=58,nd=59,rd=60,bi=61,od=62,sd=67,ld=82,Er=91,yi=93,id=94,cd=95,vi=e=>e>=65&&e<=90||e>=97&&e<=122,Ri=e=>e>=48&&e<=57,Bo=e=>vi(e)||Ri(e)||e===cd||e===ed||e===jo||e>=128,ad=e=>e===32||e>=9&&e<=13||e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279,ud=e=>e===bi||e===wi||e===Qu||e===nd||e===Ju||e===Ci||e===Zu||e===td||e===id||e===Gu||e===rd||e===od||e===en,ki=(e,t)=>{if(t>=e.length)return!0;const n=e.charCodeAt(t);return!(Bo(n)||n===wi||n===cr||n===Er)},Vs=(e,t)=>{let n=t;for(;n<e.length&&Bo(e.charCodeAt(n));)n+=1;return n},ko=(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},dd=(e,t)=>{let n=0,r=t;for(;r<e.length;){const o=e.charCodeAt(r);if(o===Ro){r+=2;continue}if(o===Er)n+=1;else if(o===yi&&(n-=1,n===0))return r+1;r+=1}return e.length},Ks=(e,t,n,r,o)=>{const s=r(e,n+1);return s!==null&&ki(e,s.end)?(o.push({start:t,end:s.end,token:{...s.token,sheet:e.slice(t,n)}}),s.end):n+1},Ei=(e,t)=>{const n=[],r=e.length;let o=0;for(;o<r;){const s=e.charCodeAt(o);if(s===An){o=ko(e,o,An);continue}if(s===Ro){const a=ko(e,o,Ro);o=e.charCodeAt(a)===cr?Ks(e,o,a,t,n):a;continue}if(s===Er){o=dd(e,o);continue}if(!Bo(s)){o+=1;continue}const l=t(e,o);if(l!==null&&ki(e,l.end)){n.push({start:o,end:l.end,token:l.token}),o=l.end;continue}let c=Vs(e,o);if(e.charCodeAt(c)===en){const a=Vs(e,c+1);a>c+1&&e.charCodeAt(a)===cr&&(c=a)}o=e.charCodeAt(c)===cr?Ks(e,o,c,t,n):c}return n},no=(e,t)=>{let n=t;const r=e.charCodeAt(n)===jo;r&&(n+=1);let o=0,s=0;for(;n<e.length;){const l=e.charCodeAt(n);if(!vi(l))break;if(s+=1,s>Uu)return null;o=o*26+(l&31),n+=1}return s===0?null:{end:n,col:o-1,abs:r}},Eo=(e,t)=>{let n=t,r=0;for(;n<e.length;){const o=e.charCodeAt(n);if(!Ri(o))break;if(n-t>=Yu)return null;r=r*10+(o-48),n+=1}return n===t?null:{end:n,value:r}},Gn=(e,t)=>{const n=e.charCodeAt(t)===jo,r=Eo(e,n?t+1:t);return r===null||r.value===0?null:{end:r.end,index:r.value-1,abs:n}},fd=(e,t)=>{const n=no(e,t);if(n!==null){const o=Gn(e,n.end);if(o!==null){if(e.charCodeAt(o.end)===en){const s=no(e,o.end+1);if(s!==null){const l=Gn(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)===en){const s=no(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=Gn(e,t);if(r!==null&&e.charCodeAt(r.end)===en){const o=Gn(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},$n=e=>Ei(e,fd),Si=(e,t=Xu)=>{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}},So=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},ro=e=>`${e.absCol?"$":""}${So(e.col)}${e.absRow?"$":""}${e.row+1}`,Wo=e=>e.sheet===void 0?"":`${e.sheet}!`,Rt=e=>{const t=Wo(e);switch(e.kind){case"cell":return`${t}${ro(e)}`;case"range":return`${t}${ro(e.start)}:${ro(e.end)}`;case"column":return`${t}${e.start.abs?"$":""}${So(e.start.col)}:${e.end.abs?"$":""}${So(e.end.col)}`;case"row":return`${t}${e.start.abs?"$":""}${e.start.row+1}:${e.end.abs?"$":""}${e.end.row+1}`}},Zt=(e,t)=>{if(!Number.isInteger(e)||e<0)throw new RangeError(`[spreadsheet] ${t} must be a non-negative integer, received ${e}`)},pd=(e,t)=>{const n="startRow"in e?e:{startRow:e.row,startCol:e.col,endRow:e.row,endCol:e.col};switch(Zt(n.startRow,"formatRangeReference startRow"),Zt(n.startCol,"formatRangeReference startCol"),Zt(n.endRow,"formatRangeReference endRow"),Zt(n.endCol,"formatRangeReference endCol"),t){case"columns":return Rt({kind:"column",start:{col:n.startCol,abs:!1},end:{col:n.endCol,abs:!1}});case"rows":return Rt({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?Rt({kind:"cell",row:n.startRow,col:n.startCol,absRow:!1,absCol:!1}):Rt({kind:"range",start:{row:n.startRow,col:n.startCol,absRow:!1,absCol:!1},end:{row:n.endRow,col:n.endCol,absRow:!1,absCol:!1}})}},Vo=(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?`${Wo(s.token)}${Ku}`:l),o=s.end}return r+e.slice(o)},Sr=e=>e.charCodeAt(0)===bi,oo=(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}},hd=(e,t,n)=>{switch(e.kind){case"cell":{const r=oo(e,t,n);return r===null?null:{...e,...r}}case"range":{const r=oo(e.start,t,n),o=oo(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}}}}},Ai=(e,t,n)=>{if(!(Number.isInteger(t)&&Number.isInteger(n)))throw new RangeError(`[spreadsheet] shiftFormula requires integer deltas, received ${t}, ${n}`);return Sr(e)?Vo(e,$n(e),r=>{const o=hd(r,t,n);return o===null?null:Rt(o)}):e},xi=(e,t)=>{Zt(e.row,`${t} origin.row`),Zt(e.col,`${t} origin.col`)},Jt=(e,t,n,r)=>n?`${e}${t+1}`:`${e}[${t-r}]`,so=(e,t)=>`${Jt("R",e.row,e.absRow,t.row)}${Jt("C",e.col,e.absCol,t.col)}`,md=(e,t)=>{const n=Wo(e);switch(e.kind){case"cell":return`${n}${so(e,t)}`;case"range":return`${n}${so(e.start,t)}:${so(e.end,t)}`;case"column":return`${n}${Jt("C",e.start.col,e.start.abs,t.col)}:${Jt("C",e.end.col,e.end.abs,t.col)}`;case"row":return`${n}${Jt("R",e.start.row,e.start.abs,t.row)}:${Jt("R",e.end.row,e.end.abs,t.row)}`}},Ar=(e,t)=>(xi(t,"toR1C1"),Sr(e)?Vo(e,$n(e),n=>md(n,t)):e),Us=(e,t,n)=>{const r=e.charCodeAt(t);if(r!==n&&r!==n+32)return null;const o=t+1;if(e.charCodeAt(o)===Er){const l=e.charCodeAt(o+1)===Ci,c=Eo(e,l?o+2:o+1);return c===null||e.charCodeAt(c.end)!==yi?null:{end:c.end+1,axis:{rel:!0,n:l?-c.value:c.value}}}const s=Eo(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}}},Ys=(e,t)=>{const n=Us(e,t,ld),r=Us(e,n===null?t:n.end,sd);return n!==null&&r!==null?{end:r.end,shape:"cell",cell:{row:n.axis,col:r.axis}}:n!==null?{end:n.end,shape:"row",row:n.axis}:r===null?null:{end:r.end,shape:"column",col:r.axis}},gd=e=>{switch(e.shape){case"cell":return{shape:"cell",start:e.cell,end:null};case"row":return{shape:"row",start:e.row,end:null};case"column":return{shape:"column",start:e.col,end:null}}},wd=(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,Cd=(e,t)=>{const n=Ys(e,t);if(n===null)return null;if(e.charCodeAt(n.end)===en){const r=Ys(e,n.end+1);if(r!==null){const o=wd(n,r);if(o!==null)return{end:r.end,token:o}}}return{end:n.end,token:gd(n)}},bd=e=>Ei(e,Cd),yd=Si(bd),Qt=(e,t)=>e.rel?t+e.n:e.n-1,Xs=(e,t)=>{const n=Qt(e.row,t.row),r=Qt(e.col,t.col);return n<0||r<0?null:{row:n,col:r,absRow:!e.row.rel,absCol:!e.col.rel}},vd=(e,t)=>{const n=e.sheet===void 0?{}:{sheet:e.sheet};switch(e.shape){case"cell":{const r=Xs(e.start,t);if(r===null)return null;if(e.end===null)return{kind:"cell",...r,...n};const o=Xs(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=Qt(e.start,t.row),s=Qt(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=Qt(e.start,t.col),s=Qt(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}}}},Nn=(e,t)=>(xi(t,"fromR1C1"),Sr(e)?Vo(e,yd(e),n=>{const r=vd(n,t);return r===null?null:Rt(r)}):e),Gs=(e,t)=>e||t?e&&t?{absCol:!1,absRow:!0}:!e&&t?{absCol:!0,absRow:!1}:{absCol:!1,absRow:!1}:{absCol:!0,absRow:!0},Rd=e=>{switch(e.kind){case"cell":return{...e,...Gs(e.absCol,e.absRow)};case"range":{const t=Gs(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}}}}},Oi=(e,t)=>Sr(e)&&Number.isInteger(t)&&t>=1&&t<=e.length,Di=(e,t)=>{if(!Oi(e,t))return null;for(const n of $n(e))if(n.start<=t&&t<=n.end)return n;return null},kd=(e,t)=>{const n=Di(e,t);if(n===null)return null;const r=Rt(Rd(n.token));return{text:`${e.slice(0,n.start)}${r}${e.slice(n.end)}`,caret:n.start+r.length}},Zs=(e,t)=>{let n=-1,r=0;for(;r<t;){const o=e.charCodeAt(r);if(o===An){const s=ko(e,r,An);if(s>t)return!1;n=An,r=s;continue}ad(o)||(n=o),r+=1}return ud(n)},Ti=(e,t)=>{if(!Oi(e,t))return null;for(const n of $n(e))if(n.start<=t&&t<=n.end)return Zs(e,n.start)?{replace:[n.start,n.end]}:null;return Zs(e,t)?{insertAt:t}:null},sn=[{code:"JPY",symbol:"¥",lcid:"411",locale:"ja-JP",digits:0},{code:"USD",symbol:"$",lcid:"409",locale:"en-US",digits:2},{code:"EUR",symbol:"€",lcid:"407",locale:"de-DE",digits:2},{code:"GBP",symbol:"£",lcid:"809",locale:"en-GB",digits:2},{code:"CNY",symbol:"¥",lcid:"804",locale:"zh-CN",digits:2},{code:"KRW",symbol:"₩",lcid:"412",locale:"ko-KR",digits:0},{code:"AUD",symbol:"$",lcid:"c09",locale:"en-AU",digits:2},{code:"CAD",symbol:"$",lcid:"1009",locale:"en-CA",digits:2},{code:"CHF",symbol:"CHF",lcid:"807",locale:"de-CH",digits:2},{code:"INR",symbol:"₹",lcid:"4009",locale:"en-IN",digits:2},{code:"HKD",symbol:"HK$",lcid:"c04",locale:"zh-HK",digits:2},{code:"SGD",symbol:"$",lcid:"1004",locale:"zh-SG",digits:2},{code:"TWD",symbol:"NT$",lcid:"404",locale:"zh-TW",digits:2},{code:"EUR",symbol:"€",lcid:"40c",locale:"fr-FR",digits:2},{code:"EUR",symbol:"€",lcid:"410",locale:"it-IT",digits:2},{code:"EUR",symbol:"€",lcid:"c0a",locale:"es-ES",digits:2},{code:"EUR",symbol:"€",lcid:"413",locale:"nl-NL",digits:2},{code:"EUR",symbol:"€",lcid:"816",locale:"pt-PT",digits:2},{code:"EUR",symbol:"€",lcid:"1809",locale:"en-IE",digits:2},{code:"NZD",symbol:"$",lcid:"1409",locale:"en-NZ",digits:2},{code:"MXN",symbol:"$",lcid:"80a",locale:"es-MX",digits:2},{code:"BRL",symbol:"R$",lcid:"416",locale:"pt-BR",digits:2}],xr=(e,t)=>`[$${e}-${t}]`,Ed=new Map(sn.map(e=>[xr(e.symbol,e.lcid),e])),Sd=new Map(sn.filter((e,t)=>sn.findIndex(n=>n.code===e.code)===t).map(e=>[e.code,e]));new Map(sn.map(e=>[xr(e.symbol,e.lcid),e.code]));const Ad=new Set([...sn.map(e=>e.symbol),...sn.map(e=>e.code),"¥"]),xd=20,Od="yyyy/MM/dd",Mi=/yyyy|MM|dd|HH|mm|ss/g,Fi=" -+/():!^&'~{}<>=",Dd="$¥€£₩₹¥",Ao=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},Td=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},Md=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),a=c.lastIndexOf("-"),m=a<0?c:c.slice(0,a),f=a<0?null:c.slice(a+1);if(f!==null&&!/^[0-9a-fA-F]{1,8}$/.test(f)||m===""&&f===null)return null;const A=f===null?null:Number.parseInt(f,16).toString(16);t.push(m===""?{kind:"locale"}:{kind:"currency",symbol:m,lcid:A}),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(Fi.includes(o)||Dd.includes(o)||o.charCodeAt(0)>=128)n(o),r+=1;else return null}return t},We=e=>e===void 0?{}:{locale:e},Fd=/^(0|#,##0)(?:\.(0+))?$/,Js=(e,t,n,r)=>{if(t!==null){const o=Ed.get(xr(e,t));return o===void 0?void 0:{type:"currency",currency:o.code,decimals:n,locale:o.locale}}if(!(!Ad.has(e)||r.currency===void 0))return{type:"currency",currency:r.currency,decimals:n,...We(r.locale)}},$d=(e,t)=>{let n="",r=!1,o=null,s=!1,l=0,c="",a="";for(const T of e)switch(T.kind){case"locale":break;case"literal":r?a+=T.text:c+=T.text;break;case"digits":if(r)return;n=T.text,r=!0;break;case"currency":if(o!==null)return;o=T;break;case"percent":l+=1;break;case"exponent":if(s||!r)return;s=!0;break;default:return}const m=Fd.exec(n);if(m===null)return;const f=m[1]==="#,##0",A=m[2]===void 0?0:m[2].length,L=c.trim(),$=a.trim();if(s)return l===0&&o===null&&!f&&L===""&&$===""?{type:"scientific",decimals:A,...We(t.locale)}:void 0;if(l>0)return l===1&&o===null&&L===""&&$===""?{type:"percent",decimals:A,...We(t.locale)}:void 0;if($==="%"&&L===""&&o===null)return{type:"percent",decimals:A,scale:!1,...We(t.locale)};if(o!==null)return L===""&&$===""?Js(o.symbol,o.lcid,A,t):void 0;if(!(L!==""&&$!==""))return L!==""||$!==""?Js(L+$,null,A,t):{type:"number",decimals:A,...f?{grouping:!0}:{},...We(t.locale)}},Nd=new Map([["yyyy","yyyy"],["dd","dd"],["hh","HH"],["ss","ss"]]),Ld=(e,t)=>{const n=[...e.matchAll(Mi)];return n.length===t.length&&n.every((r,o)=>r.index===t[o].index&&r[0]===t[o].text)},Pd=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":Nd.get(s.text);if(o+=1,l===void 0)return;n.push({index:r.length,text:l}),r+=l}return n.length>0&&Ld(r,n)?{type:"date",pattern:r}:void 0},zd=new Map([["General",()=>{}],["@",()=>({type:"text"})],["Fixed",e=>({type:"number",decimals:2,...We(e.locale)})],["Standard",e=>({type:"number",decimals:2,grouping:!0,...We(e.locale)})],["Percent",e=>({type:"percent",decimals:2,...We(e.locale)})],["Scientific",e=>({type:"scientific",decimals:2,...We(e.locale)})],["Currency",e=>e.currency===void 0?void 0:{type:"currency",currency:e.currency,decimals:2,...We(e.locale)}],["Euro Currency",e=>({type:"currency",currency:"EUR",decimals:2,...We(e.locale)})],["Short Date",()=>({type:"date"})],["Short Time",()=>({type:"date",pattern:"HH:mm"})]]),Ko=(e,t)=>{const n=Td(e).trim(),r=zd.get(n);if(r!==void 0)return r(t);const o=Md(n);if(o!==null){if(o.some(s=>s.kind==="digits"))return $d(o,t);if(o.some(s=>s.kind==="date"))return Pd(o)}},qd=(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:Ko(s,t);return o===5?l!==void 0&&l.type==="date"?l:{type:"date"}:l},kn=e=>e===0?"":`.${"0".repeat(e)}`,ar=e=>e!==void 0&&Number.isInteger(e)&&e>=0&&e<=xd,_d=`${Fi}.,`,Qs=e=>e.includes('"')?null:[...e].every(t=>_d.includes(t))?e:`"${e}"`,Id=e=>{const t=[];let n=0,r=0;for(const c of e.matchAll(Mi)){const a=Qs(e.slice(r,c.index));if(a===null)return null;t.push(a,c[0].toLowerCase()),n+=1,r=c.index+c[0].length}const o=Qs(e.slice(r));if(o===null||n===0)return null;t.push(o);const s=t.join(""),l=Ko(s,{});return l!==void 0&&l.type==="date"&&l.pattern===e?s:null},Hd=e=>{const t=Sd.get(e.currency.toUpperCase());if(t===void 0)return null;const n=e.decimals===void 0?t.digits:e.decimals;if(!ar(n))return null;const r=`#,##0${kn(n)}`;return t.code==="USD"&&e.locale==="en-US"?`"$"${r}`:`${xr(t.symbol,t.lcid)}${r}`},$i=e=>{switch(e.type){case"text":return"@";case"date":return Id(e.pattern===void 0?Od:e.pattern);case"number":return ar(e.decimals)?`${e.grouping===!0?"#,##0":"0"}${kn(e.decimals)}`:null;case"percent":{const t=e.decimals===void 0?0:e.decimals;return ar(t)?e.scale===!1?`0${kn(t)}"%"`:`0${kn(t)}%`:null}case"scientific":return ar(e.decimals)?`0${kn(e.decimals)}E+00`:null;case"currency":return Hd(e);default:return null}},el="-−",jd=(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("")},Bd=(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 a=c.length===2?c[1]:"";if(c.length===2&&!/^\d+$/.test(a))return null;const m=jd(c[0],t);return m===null?null:{integer:m,fraction:a,exponent:l}},Wd=(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 a=c===""?l:`${l}.${c}`;return r&&a!=="0"?`-${a}`:a},Vd=(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",a=x=>x>="0"&&x<="9"||l!==""&&l.includes(x)||n.decimal.includes(x)||c&&(x==="e"||x==="E");let m=0;for(;m<o.length&&!a(o[m]);)m+=1;let f=o.length;for(;f>m&&!a(o[f-1]);)f-=1;let A=0,L=0,$=0,T="";for(const x of o.slice(0,m))el.includes(x)?A+=1:x==="("?L+=1:T+=x;for(const x of o.slice(f))el.includes(x)?A+=1:x===")"?$+=1:T+=x;const _=A+L;if(L!==$||_>1||_===1&&s||(s=s||_===1,r!=="currency"&&T.trim()!==""))return e;const V=Bd(o.slice(m,f).trim(),l,n.decimal,r==="scientific"?"required":r==="general"?"optional":"none");if(V===null)return e;const v=t!==void 0&&t.type==="percent"&&t.scale!==!1?-2:0,M=V.exponent+v;if(M>330||M<-330)return e;const D=Wd(V.integer,V.fraction,M,s);return Number.isFinite(Number(D))?D:e},tl="google-sheets-html-origin",Ni=Object.freeze({group:",",decimal:"."}),nl=Object.freeze({thin:".5pt solid",medium:"1.0pt solid",thick:"1.5pt solid",dashed:".5pt dashed",dotted:".5pt dotted",double:"1.5pt double",hair:".5pt hairline"}),Li=["top","right","bottom","left"],Kd=new Set(["solid","dashed","dotted","double","hairline","none","hidden","groove","ridge","inset","outset"]),Ud=new Set(["windowtext","currentcolor","inherit","initial","unset"]),Yd=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"]),rl=["","#NULL!","#DIV/0!","#VALUE!","#REF!","#NAME?","#NUM!","#N/A","#ERROR!"],Xd=Object.freeze({number:2,percent:3,currency:4,scientific:8}),Gd=new Set(["script","style","template","noscript","rt","rp","img","svg","video","audio","picture","canvas","iframe","object","textarea","select","button","input"]),Zd=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"]),Jd=new Set(["b","strong","i","em","u","s","strike","del","a","font","span"]),Qd=3,ef=1,Pi=-25569,ur=86400,tf=-693959,nf=2958465,rf=" ",Or=e=>{const t=new Map;let n=0,r=null,o=0;const s=l=>{const c=e.slice(n,l),a=c.indexOf(":");if(a>0){const m=c.slice(0,a).trim().toLowerCase(),f=c.slice(a+1).trim();m!==""&&f!==""&&t.set(m,f)}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},gr=e=>{const t=e[0];return e.length>=2&&(t==='"'||t==="'")&&e.endsWith(t)?e.slice(1,-1):e},Uo=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},of=/^(?:[a-z][a-z0-9]*)?\.([A-Za-z_-][\w-]*)$/i,sf=e=>{const t=new Map;let n=null,r=null;for(const s of e.querySelectorAll("style")){const l=s.innerHTML.replaceAll("<!--","").replaceAll("-->","").replace(/\/\*[\s\S]*?\*\//g,"");let c=0;for(;c<l.length;){const a=l.indexOf("{",c);if(a===-1)break;const m=l.indexOf("}",a+1);if(m===-1)break;const f=l.slice(c,a),A=l.slice(a+1,m);if(c=m+1,f.trim().startsWith("@"))continue;const L=Or(A);for(const $ of f.split(",")){const T=$.trim(),_=of.exec(T);if(_!==null){const V=t.get(_[1]);if(V===void 0)t.set(_[1],new Map(L));else for(const[v,M]of L)V.set(v,M)}else if(T.toLowerCase()==="table"){const V=L.get("mso-displayed-decimal-separator"),v=L.get("mso-displayed-thousand-separator");V!==void 0&&(n=Ao(gr(V))),v!==void 0&&(r=Ao(gr(v)))}}}}return{classes:t,separators:n!==null&&r!==null&&n!==""&&r!==n?{group:r,decimal:n}:Ni}},lf="%_-*? ",cf=e=>{let t="";for(const n of e)n==='"'?t+="\\0022":n==="\\"?t+="\\\\":/[A-Za-z0-9]/.test(n)||lf.includes(n)||n.charCodeAt(0)>=128?t+=n:t+=`\\${n}`;return t},af=(e,t,n)=>{const r=t<=2?e-1:e,o=Math.floor(r/400),s=r-o*400,l=t>2?t-3:t+9,c=Math.floor((153*l+2)/5)+n-1,a=s*365+Math.floor(s/4)-Math.floor(s/100)+c;return o*146097+a-719468},zi=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,a=l<10?l+3:l-9;return{year:o+n*400+(a<=2?1:0),month:a,day:c}},Yt=(e,t)=>String(e).padStart(t,"0"),qi=e=>{if(e<tf||e>nf)return null;let t=Math.floor(e),n=Math.round((e-t)*ur);n>=ur&&(t+=1,n-=ur);const r=zi(t+Pi),o=`${Yt(r.year,4)}-${Yt(r.month,2)}-${Yt(r.day,2)}`;if(n===0)return o;const s=Math.floor(n/3600),l=Math.floor(n%3600/60);return`${o} ${Yt(s,2)}:${Yt(l,2)}:${Yt(n%60,2)}`},uf=/^(\d{4})([-/])(\d{2})\2(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/,df=e=>{const t=uf.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 a=af(n,r,o),m=zi(a);return m.year!==n||m.month!==r||m.day!==o?null:a-Pi+(s*3600+l*60+c)/ur},Yo=e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">"),Pt=e=>Yo(e).replaceAll('"',"""),_i=e=>Yo(e).replaceAll("'","'"),ff=e=>Yo(e).replaceAll(`\r
|
|
2
|
+
`,`
|
|
3
|
+
`).replaceAll("\r",`
|
|
4
|
+
`).replaceAll(`
|
|
5
|
+
`,'<br style="mso-data-placement:same-cell">').replaceAll(" ","	"),dr=(e,t)=>`${e}="${Pt(JSON.stringify(t))}"`,Ii=e=>e.type==="number"||e.type==="percent"||e.type==="currency"||e.type==="scientific",pf=e=>{if(qe(e)===null)return null;const t=Number(e);return Number.isFinite(t)?t:null},hf=e=>{const t=/yyyy|MM|dd/.test(e),n=/HH|mm|ss/.test(e);return t&&n?7:n?6:5},mf=e=>{if(e.type==="text")return{1:1};const t=$i(e);return t===null?null:{1:e.type==="date"?hf(e.pattern===void 0?"yyyy/MM/dd":e.pattern):Xd[e.type],2:t,3:1}},gf=/[;"'{}<>&\\]/,Hi=e=>e==="left"||e==="center"||e==="right",ji=e=>e==="top"||e==="middle"||e==="bottom",wf=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"?Fe(e.color):null;r!==null&&t.push(`color:${r}`);const o=typeof e.background=="string"?Fe(e.background):null;if(o!==null&&t.push(`background-color:${o}`),Hi(e.align)&&t.push(`text-align:${e.align}`),ji(e.verticalAlign)&&t.push(`vertical-align:${e.verticalAlign}`),typeof e.fontFamily=="string"&&e.fontFamily.trim()!==""&&!gf.test(e.fontFamily)&&t.push(`font-family:${e.fontFamily.trim()}`),typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)&&e.fontSize>0&&t.push(`font-size:${e.fontSize}pt`),e.borders!==void 0)for(const s of Li){const l=e.borders[s];if(l===void 0||!Object.hasOwn(nl,l.style))continue;const c=l.color===void 0?"windowtext":Fe(l.color);c!==null&&t.push(`border-${s}:${nl[l.style]} ${c}`)}if(e.value!==void 0){const s=$i(e.value);s!==null&&t.push(`mso-number-format:"${cf(s)}"`)}return t},Cf={value:void 0,style:"white-space:pre",numberFormatAttribute:null},bf=e=>{const t=e.value,n=e.wrap===!0?"white-space:pre-wrap;word-wrap:break-word":"white-space:pre",r=_i([n,...wf(e)].join(";"));let o=null;if(t!==void 0){const s=mf(t);s!==null&&(o=dr("data-sheets-numberformat",s))}return{value:t,style:r,numberFormatAttribute:o}},yf=(e,t,n,r)=>{const o=t.value,s=o===void 0?e.t:on(e.t,o),l=e.t!==""&&(o!==void 0&&o.type==="text"||e.t.startsWith("=")),c=!l&&o!==void 0&&Ii(o)?pf(e.t):null,a=!l&&c===null&&o!==void 0&&o.type==="date"?df(e.t):null,m=[];if(l?m.push(dr("data-sheets-value",{1:2,2:e.t})):c!==null?m.push(dr("data-sheets-value",{1:3,3:c})):a!==null&&m.push(dr("data-sheets-value",{1:3,3:a})),e.f!==void 0&&m.push(`data-sheets-formula="${Pt(e.f)}"`),t.numberFormatAttribute!==null&&m.push(t.numberFormatAttribute),e.link!==void 0&&m.push(`data-sheets-hyperlink="${Pt(e.link)}"`),e.note!==void 0&&m.push(`data-sheets-note="${Pt(e.note)}"`),l?m.push("x:str"):c!==null?m.push(`x:num="${Pt(e.t)}"`):a!==null&&m.push(`x:num="${a}"`),e.f!==void 0){const L=Nn(e.f,{row:n,col:r});L.includes("#REF!")||m.push(`x:fmla="${Pt(L)}"`)}const f=ff(s),A=e.link===void 0?f:`<a href="${Pt(e.link)}">${f}</a>`;return`<td style='${t.style}'${m.map(L=>` ${L}`).join("")}>${A}</td>`},Bi=(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(bf);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 a=0;a<e.cols;a+=1){const m=e.cells[s][a],f=m.fmt===void 0?void 0:r[m.fmt];c+=yf(m,f===void 0?Cf:f,s,a)}o+=`<tr${l}>${c}</tr>`}return`<${tl}><style type="text/css">br{mso-data-placement:same-cell;}</style><table ${Zl}='${_i(t)}' data-sheets-root="1" cellspacing="0" cellpadding="0" border="1" style="table-layout:fixed;border-collapse:collapse">${n}<tbody>${o}</tbody></table></${tl}>`},xo=(e,t)=>{for(const[n,r]of t)e.set(n,r)},Wi=(e,t)=>{const n=new Map,r=e.getAttribute("bgcolor");r!==null&&r.trim()!==""&&n.set("background",r);for(const s of e.classList){const l=t.classes.get(s);l!==void 0&&xo(n,l)}const o=e.getAttribute("style");return o!==null&&xo(n,Or(o)),n},vf=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"}},Rf=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"},kf=new Map([["dashed","dashed"],["dotted","dotted"],["double","double"],["hairline","hair"]]),Ef={pt:1.5,unit:"px"},ol=e=>{let t=null,n=null;const r=[];for(const a of Uo(e)){const m=a.toLowerCase(),f=vf(a);Kd.has(m)?n=m:f!==null?t=f:r.push(a)}if(n===null||n==="none"||n==="hidden")return null;const o=kf.get(n),s=o===void 0?Rf(t===null?Ef:t):o,l=r.join(" ");if(l===""||Ud.has(l.toLowerCase()))return{style:s};const c=Fe(l);return c===null||c.length===9?null:{style:s,color:c}},Sf=e=>e.style==="thin"&&e.color==="#cccccc",Af=e=>{const t=Fe(e);if(t!==null)return t;for(const n of Uo(e)){const r=Fe(n);if(r!==null)return r}return null},xf=e=>{const t=gr(Uo(e.split(",")[0]).join(" ").trim()).trim();return t===""||Yd.has(t.toLowerCase())?null:t},Of=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},Df=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},Tf=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"},Mf=new Set(["normal","pre-wrap","pre-line"]),Ff=(e,t,n)=>{const r={},o=e.get("font-weight");if(o!==void 0){const h=o.toLowerCase();(h==="bold"||h==="bolder"||Number(h)>=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=Df(e);(t.underline||l.has("underline"))&&(r.underline=!0),(t.strikethrough||l.has("line-through"))&&(r.strikethrough=!0);const c=e.get("color"),a=c===void 0?null:Fe(c);a!==null&&a.length!==9&&(r.color=a);const m=e.has("background-color")?e.get("background-color"):e.get("background"),f=m===void 0?null:Af(m);f!==null&&f.length!==9&&(r.background=f);const A=e.get("text-align"),L=A===void 0?"":A.toLowerCase();Hi(L)&&(r.align=L);const $=e.get("vertical-align"),T=$===void 0?"":$.toLowerCase();ji(T)&&(r.verticalAlign=T);const _=e.get("font-family"),V=_===void 0?null:xf(_);V!==null&&(r.fontFamily=V);const v=e.get("font-size"),M=v===void 0?null:Of(v);M!==null&&(r.fontSize=M);const D=e.get("white-space");D!==void 0&&Mf.has(D.toLowerCase())&&(r.wrap=!0);const x={},N=e.get("border"),p=N===void 0?null:ol(N);for(const h of Li){const w=e.get(`border-${h}`),O=w===void 0?p:ol(w);O!==null&&!(n==="sheets"&&Sf(O))&&(x[h]=O)}return Object.keys(x).length>0&&(r.borders=x),r},sl=e=>{e.text!==""&&!e.text.endsWith(`
|
|
6
|
+
`)&&(e.text+=`
|
|
7
|
+
`)},$f=e=>{const t=e.getAttribute("style");return t!==null&&Or(t).get("mso-spacerun")==="yes"},Nf=(e,t)=>{const n=[{kind:"enter",node:e}];for(let r=n.pop();r!==void 0;r=n.pop()){if(r.kind==="exit"){Jd.has(r.element.localName)&&t.runs.push({element:r.element,before:r.before,end:t.text.length}),r.block&&sl(t);continue}const o=r.node;if(o.nodeType===Qd){const a=o.data;t.text+=t.mode==="collapse"?a.replace(/[\r\n\t\f]/g," "):a.replace(/\r\n?/g,`
|
|
8
|
+
`);continue}if(o.nodeType!==ef)continue;const s=o,l=s.localName;if(Gd.has(l)||$f(s))continue;if(l==="br"){t.text+=`
|
|
9
|
+
`;continue}const c=t.mode==="collapse"&&Zd.has(l);if(c&&sl(t),t.mode==="collapse"&&(l==="td"||l==="th")&&t.text!==""&&!/\s$/.test(t.text)&&(t.text+=" "),l==="a"&&t.href===null){const a=s.getAttribute("href");a!==null&&(t.href=a)}n.push({kind:"exit",element:s,before:t.text.length,block:c});for(let a=s.lastChild;a!==null;a=a.previousSibling)n.push({kind:"enter",node:a})}},Lf=(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&&zf(l.element,t,n,r)},Pf=(e,t)=>{const n=e.replaceAll(rf," ");if(t==="pre")return n;const r=n.split(`
|
|
10
|
+
`).map(l=>l.replace(/[ \t\f\r]+/g," ").trim());if(t==="pre-line")return r.join(`
|
|
11
|
+
`);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
|
+
`)},zf=(e,t,n,r)=>{const o=e.localName;if(o==="b"||o==="strong")t.set("font-weight","bold");else if(o==="i"||o==="em")t.set("font-style","italic");else if(o==="u")n.underline=!0;else if(o==="s"||o==="strike"||o==="del")n.strikethrough=!0;else if(o==="font"){const s=e.getAttribute("color"),l=e.getAttribute("face");s!==null&&s.trim()!==""&&t.set("color",s),l!==null&&l.trim()!==""&&t.set("font-family",l)}xo(t,Wi(e,r))},qf=(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"?qi(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<rl.length?rl[l]:null}return null},Vi=(e,t,n)=>t!==void 0&&Ii(t)?Vd(e,t,n):e,_f=(e,t,n,r)=>{const o=e.getAttribute("x:str");if(o!==null)return o===""?t:o;const s=e.getAttribute("x:bool");if(s!==null){const a=s.toUpperCase();return a==="TRUE"||a==="FALSE"?a:t}const l=e.getAttribute("x:err");if(l!==null)return l===""?t:l;const c=e.getAttribute("x:num");if(c!==null&&c!==""&&qe(c)!==null)if(n!==void 0&&n.type==="date"){const a=qi(Number(c));if(a!==null)return a}else return c;return Vi(t,n,r)},If=(e,t,n,r)=>{const o=Wi(e,r.rules),s={underline:!1,strikethrough:!1},l={text:"",runs:[],href:null,mode:Tf(o)};for(const f of Wf(e))Nf(f,l);Lf(l,o,s,r.rules);const c=Pf(l.text,l.mode),a=Ff(o,s,r.kind),m={t:""};if(r.kind==="sheets"){const f=e.getAttribute("data-sheets-numberformat"),A=f===null?void 0:qd(f,r.options);A!==void 0&&(a.value=A);const L=e.getAttribute("data-sheets-value"),$=L===null?null:qf(L,A);m.t=$===null?Vi(c,A,Ni):$;const T=e.getAttribute("data-sheets-formula");T?.startsWith("=")&&(m.f=T);const _=e.getAttribute("data-sheets-hyperlink"),V=_!==null?_:l.href,v=V===null?null:St(V);v!==null&&(m.link=v);const M=e.getAttribute("data-sheets-note");M!==null&&M!==""&&(m.note=M)}else{const f=o.get("mso-number-format"),A=f===void 0?void 0:Ko(Ao(gr(f)),r.options);A!==void 0&&(a.value=A),m.t=_f(e,c,A,r.separators);const L=e.getAttribute("x:fmla");L?.startsWith("=")&&(m.f=Ar(L,{row:t,col:n}));const $=l.href===null?null:St(l.href);$!==null&&(m.link=$)}return{cell:m,format:a}},Oo=(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},Hf=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)},jf=(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]))},Ki=(e,t)=>{const n=e.getAttribute("style"),r=n===null?null:Or(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:Hf(l);if(c!==null)return Math.min(c,rn)}const o=jf(e,t);return o===null?null:Math.min(o,rn)},Bf=(e,t)=>{const n=[],r=o=>{const s=Ki(o,"width");for(let l=Oo(o,"span",Io);l>0&&n.length<t;l-=1)n.push(s)};for(const o of Dn(e)){if(n.length>=t)break;if(o.localName==="col")r(o);else if(o.localName==="colgroup")for(const s of Dn(o))s.localName==="col"&&n.length<t&&r(s)}return n};function*Dn(e){for(let t=e.firstElementChild;t!==null;t=t.nextElementSibling)yield t}function*Wf(e){for(let t=e.firstChild;t!==null;t=t.nextSibling)yield t}function*Vf(e){for(const t of["thead","tbody","tfoot"])for(const n of Dn(e)){const r=n.localName;if(t==="tbody"&&r==="tr")yield n;else if(r===t)for(const o of Dn(n))o.localName==="tr"&&(yield o)}}const lo=()=>({t:""}),Kf=(e,t,n)=>{const r=ui(),o=[],s=[],l=[];let c=0;for(const $ of Vf(e)){const T=o.length,_=(T+1)*Math.max(c,1);if(_>n)return{outcome:"limit",cells:_};const V=[];for(let M=0;M<l.length;M+=1)l[M]>0&&(V[M]=lo(),l[M]-=1);let v=0;for(const M of Dn($)){const D=M.localName;if(D!=="td"&&D!=="th")continue;for(;V[v]!==void 0;)v+=1;const x=Oo(M,"colspan",Io),N=Oo(M,"rowspan",ri),p=(T+1)*Math.max(c,v+x);if(p>n)return{outcome:"limit",cells:p};const h=If(M,T,v,t),w=r.intern(h.format);w!==void 0&&(h.cell.fmt=w),V[v]=h.cell;for(let O=1;O<x;O+=1)V[v+O]===void 0&&(V[v+O]=lo());if(N>1)for(let O=0;O<x;O+=1){const y=N-1,g=v+O;l[g]=l[g]===void 0||l[g]<y?y:l[g]}v+=x}V.length>c&&(c=V.length),o.push(V),s.push(Ki($,"height"))}if(o.length===0||c===0)return{outcome:"none"};const a=o.map($=>{const T=[];for(let _=0;_<c;_+=1){const V=$[_];T.push(V===void 0?lo():V)}return T}),m=Bf(e,c),f=m.length===c&&m.every($=>$!==null)?m.map($=>$===null?0:$):void 0,A=s.every($=>$!==null)?s.map($=>$===null?0:$):void 0;return{outcome:"payload",payload:{v:1,rows:o.length,cols:c,clipId:qo(),formats:[...r.entries],validations:[],cells:a,...f===void 0?{}:{colWidths:f},...A===void 0?{}:{rowHeights:A},wholeRows:!1,wholeCols:!1,conditionalFormats:[]}}},Ui=(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=sf(o);return Kf(s,{kind:t,rules:l,options:n,separators:l.separators},r)},ue=(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)}),Ht=(e,t)=>t.row>=e.startRow&&t.row<=e.endRow&&t.col>=e.startCol&&t.col<=e.endCol,_e=e=>({rows:e.endRow-e.startRow+1,cols:e.endCol-e.startCol+1}),wr=e=>e.reduce((t,n)=>t+_e(n).rows*_e(n).cols,0),yt=(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)}},ct=(e,t)=>e.row===t.row&&e.col===t.col,Yi=(e,t)=>e===void 0?Ls(void 0,void 0,t()):Ls(e.align,e.value,e.align===void 0?t():""),fr=(e,t,n)=>{let r=null;return()=>(r===null&&(r=e.getCellText(t,n)),r)},ln=(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}},pr=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}),Uf=(e,t)=>{const n=e.length,r=e[0]?.length??0;if(n===0||r===0)return 0;const o=_e(t);return!(o.rows===1&&o.cols===1)&&o.rows%n===0&&o.cols%r===0?o.rows*o.cols:n*r},Xi=(e,t,n,r,o,s)=>{const l=e.length,c=e[0]?.length??0;if(l===0||c===0)return[];const a=_e(t),m=a.rows===1&&a.cols===1,f=!m&&a.rows%l===0&&a.cols%c===0,A=f?a.rows:l,L=f?a.cols:c,$=m?n:{row:t.startRow,col:t.startCol},T=Math.min(A,r-$.row),_=Math.min(L,o-$.col),V=[];for(let v=0;v<T;v+=l){const M=[];for(let x=0;x<_;x+=c){const N={row:$.row+v,col:$.col+x};M.push(N),V.push(N)}const D=Math.min(l,T-v);for(let x=0;x<D;x+=1){const N=$.row+v+x,p=e[x];for(let h=0;h<M.length;h+=1){const w=h*c,O=Math.min(c,_-w);for(let y=0;y<O;y+=1)s(N,$.col+w+y,p[y],M[h])}}}return V},Yf=(e,t,n,r,o)=>{const s=[];return Xi(e,t,n,r,o,(l,c,a)=>{s.push({row:l,col:c,text:a})}),s},ll=(e,t,n,r,o,s)=>{const l=[],c=Xi(e,t,n,r,o,(a,m,f,A)=>{const L=s(f,a,m,A);L!==null&&l.push({...L,row:a,col:m})});return{edits:l,tiles:c}},Gi=(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)})`)},Xf=(e,t)=>{Gi(e,t);const n=_e(t),r=_e(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},Gf=(e,t,n,r)=>{Gi(t,n);const o=_e(t).rows,s=_e(t).cols,l=[],c=new Map;for(let a=n.startRow;a<=n.endRow;a+=1){const m=t.startRow+((a-t.startRow)%o+o)%o,f=a>=t.startRow&&a<=t.endRow;for(let A=n.startCol;A<=n.endCol;A+=1){if(f&&A>=t.startCol&&A<=t.endCol)continue;const L=t.startCol+((A-t.startCol)%s+s)%s,$=m*2**21+L;let T=c.get($);T===void 0&&(T={value:e(m,L),origin:{row:m,col:L}},c.set($,T)),l.push(r(T.value,T.origin,{row:a,col:A}))}}return l},Zi=(e,t,n)=>{const r=ln(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:Ke(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=cn(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},Ji=(e,t,n)=>{const r={row:n.row,col:n.col,text:e.isFormula?Ai(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},Qi=e=>`${e.map(t=>t.map(Zf).join(" ")).join(`\r
|
|
13
|
+
`)}\r
|
|
14
|
+
`,Zf=e=>/[\t\r\n]/.test(e)?`"${e.replaceAll('"','""')}"`:e,ec=e=>e.endsWith(`\r
|
|
15
|
+
`)?e.slice(0,-2):e.endsWith(`
|
|
16
|
+
`)||e.endsWith("\r")?e.slice(0,-1):e,tc=(e,t,n)=>{let r=0;for(;;){let o;if(e[r]==='"'){const s=Qf(e,r);if(s!==null)o=s.value,r=s.nextIndex;else{const l=il(e,r);o=e.slice(r,l),r=l}}else{const s=il(e,r);o=e.slice(r,s),r=s}if(t(o),r>=e.length){n();return}e[r]===" "?r+=1:(r+=e[r]==="\r"&&e[r+1]===`
|
|
17
|
+
`?2:1,n())}},nc=e=>{const t=ec(e);if(t==="")return[[""]];const n=[];let r=[];tc(t,s=>{r.push(s)},()=>{n.push(r),r=[]});let o=0;for(const s of n)s.length>o&&(o=s.length);return n.map(s=>s.length===o?s:[...s,...Array(o-s.length).fill("")])},Jf=e=>{const t=ec(e);if(t==="")return{rows:1,cols:1};let n=0,r=0,o=0;return tc(t,()=>{o+=1},()=>{n+=1,o>r&&(r=o),o=0}),{rows:n,cols:r}},Qf=(e,t)=>{let n="",r=t+1;for(;r<e.length;)if(e[r]==='"')if(e[r+1]==='"')n+='"',r+=2;else{const o=r+1;return(o>=e.length||e[o]===" "||e[o]===`
|
|
18
|
+
`||e[o]==="\r")&&/[\t\r\n]/.test(n)?{value:n,nextIndex:o}:null}else n+=e[r],r+=1;return null},il=(e,t)=>{for(let n=t;n<e.length;n+=1)if(e[n]===" "||e[n]===`
|
|
19
|
+
`||e[n]==="\r")return n;return e.length},Cr=e=>{if(!(Number.isInteger(e)&&e>=0))throw new RangeError(`[spreadsheet] columnIndexToName requires a non-negative integer, received ${e}`);let t="",n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.trunc(n/26)-1;return t},ep=e=>{if(!/^[A-Z]+$/.test(e))throw new RangeError(`[spreadsheet] columnNameToIndex requires /^[A-Z]+$/, received "${e}"`);let t=0;for(const n of e)t=t*26+(n.charCodeAt(0)-64);return t-1},Dr=["bold","italic","underline","strikethrough","clearFormatting","alignLeft","alignCenter","alignRight","formatNumber","formatTime","formatDate","formatCurrency","formatPercent","formatScientific","bordersOuter","bordersClear","borderTop","borderRight","borderBottom","borderLeft","insertLink","insertNote","insertComment","openHyperlink","openValidationList","pasteSpecial","fillDown","fillRight","fillSelection","insertDate","insertTime","hideRows","hideColumns","unhideRows","unhideColumns","formatGeneral","bordersAll","pasteFormats","pasteFormulas","pasteAdd","pasteSubtract","pasteMultiply","pasteDivide","multiplyBy100","multiplyBy1000","divideBy100","divideBy1000","signReversal","fillColorYellow","fillColorBlue","fillColorGreen","fillColorRed","fillColorCustom1","fillColorCustom2","fillColorCustom3","fillColorCustom4","fillColorCustom5","fontColorYellow","fontColorBlue","fontColorGreen","fontColorRed","fontColorCustom1","fontColorCustom2","fontColorCustom3","fontColorCustom4","fontColorCustom5","toggleRowHighlight","toggleColumnHighlight","toggleBothHighlight","toggleIntersectionHighlight"],tp=/^[A-Z]$/,np=/^[A-Za-z]$/,rp=/^Key([A-Z])$/,rc=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"]),op=e=>tp.test(e)||rc.has(e),zt=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||!op(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}},sp=e=>`${e.ctrl?"Ctrl+":""}${e.alt?"Alt+":""}${e.shift?"Shift+":""}${e.key}`,oc=e=>{if(np.test(e.key))return e.key.toUpperCase();const t=rp.exec(e.code);return t!==null?t[1]:rc.has(e.code)?e.code:null},Cn=(e,t)=>e.ctrl!==(t.ctrlKey||t.metaKey)||e.alt!==t.altKey||e.shift!==t.shiftKey||e.alt&&t.getModifierState("AltGraph")?!1:oc(t)===e.key,se=(e,t,n)=>({chord:e,column:t,rebindable:!1,note:n}),ae=(e,t,n,r)=>({chord:t,column:n,rebindable:!0,command:e,note:r}),lp=()=>{const e=[];for(const t of["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"])e.push(se(t,"both","move active (idle) / commit + move in replace mode, caret in edit mode, reference cursor while pointing")),e.push(se(`Shift+${t}`,"both","extend selection (idle) / commit + extend in replace mode, text selection in edit mode")),e.push(se(`Ctrl+${t}`,"both","data-edge jump (idle) / native word caret (editing), Ctrl reference cursor while pointing")),e.push(se(`Ctrl+Shift+${t}`,"both","extend to data edge (idle) / consume + no-op (editing)"));return e},ip=()=>{const e=[];for(const t of["Equal","Minus","Digit0","NumpadAdd","NumpadSubtract","Numpad0"])e.push(se(`Ctrl+Alt+${t}`,"both","zoom token space (root capture listener, produced-character matching — v0.3.3 contract)")),e.push(se(`Ctrl+Alt+Shift+${t}`,"both","zoom token space, Shift-independent (JIS `=` is Shift+Minus, AZERTY `0` is Shift+Digit0)"));return e},Pn=[...lp(),se("Home","idle","row start (first visible column)"),se("Ctrl+Home","idle","first visible cell"),se("Shift+Home","idle","extend to row start"),se("Ctrl+Shift+Home","idle","extend to first visible cell"),se("End","idle","row end (last visible column)"),se("Ctrl+End","idle","last visible cell"),se("Shift+End","idle","extend to row end"),se("Ctrl+Shift+End","idle","extend to last visible cell"),se("PageUp","both","page up (idle) / commit + page up (editing)"),se("PageDown","both","page down (idle) / commit + page down (editing)"),se("Shift+PageUp","idle","extend one page up"),se("Shift+PageDown","idle","extend one page down"),se("Ctrl+Shift+PageUp","idle","consume + no-op (sheet-switch class)"),se("Ctrl+Shift+PageDown","idle","consume + no-op (sheet-switch class)"),se("Tab","both","cycle right (idle) / commit + cycle right (editing)"),se("Shift+Tab","both","cycle left (idle) / commit + cycle left (editing)"),se("Enter","both","cycle down (idle) / commit + cycle down (editing)"),se("Shift+Enter","both","cycle up (idle) / commit + cycle up (editing)"),se("Alt+Enter","editing","newline at the caret (editing column only — coexists with the idle openHyperlink default)"),se("F2","both","start editing (idle) / toggle the pointing arm (editing)"),se("F4","editing","cycle the reference anchor under the caret (formula session)"),se("Delete","idle","clear every selected cell"),se("Backspace","idle","clear every selected cell"),se("Escape","both","abort drag > hide note tip > close rejected message > discard clip > hand off focus (idle) / cancel editing"),se("Ctrl+A","idle","select all"),se("Ctrl+Z","idle","undo request"),se("Ctrl+Y","idle","redo request"),se("Ctrl+Shift+Z","idle","redo request"),se("Shift+F10","idle","keyboard context menu"),se("ContextMenu","idle","keyboard context menu"),se("Ctrl+Space","idle","column bands"),se("Shift+Space","idle","row bands"),se("Ctrl+C","idle","native copy (ClipboardEvent path — never preventDefault)"),se("Ctrl+X","idle","native cut (ClipboardEvent path — never preventDefault)"),se("Ctrl+V","idle","native paste (ClipboardEvent path — never preventDefault)"),se("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"},...ip(),ae("bold","Ctrl+B","both","toggle bold"),ae("italic","Ctrl+I","both","toggle italic"),ae("underline","Ctrl+U","both","toggle underline"),ae("strikethrough","Alt+Shift+Digit5","both","toggle strikethrough"),ae("clearFormatting","Ctrl+Backslash","idle","clear formatting"),ae("clearFormatting","Ctrl+IntlYen","idle","clear formatting (JIS ¥ key)"),ae("clearFormatting","Ctrl+IntlRo","idle","clear formatting (JIS ろ key)"),ae("alignLeft","Ctrl+Shift+L","both","align left"),ae("alignCenter","Ctrl+Shift+E","both","align center"),ae("alignRight","Ctrl+Shift+R","both","align right"),ae("formatNumber","Ctrl+Shift+Digit1","both","number format"),ae("formatTime","Ctrl+Shift+Digit2","both","time format"),ae("formatDate","Ctrl+Shift+Digit3","both","date format"),ae("formatCurrency","Ctrl+Shift+Digit4","both","currency format"),ae("formatPercent","Ctrl+Shift+Digit5","both","percent format"),ae("formatScientific","Ctrl+Shift+Digit6","both","scientific format"),ae("bordersOuter","Alt+Shift+Digit7","idle","outer borders"),ae("bordersClear","Alt+Shift+Digit6","idle","clear borders"),ae("borderTop","Alt+Shift+Digit1","idle","top border"),ae("borderRight","Alt+Shift+Digit2","idle","right border"),ae("borderBottom","Alt+Shift+Digit3","idle","bottom border"),ae("borderLeft","Alt+Shift+Digit4","idle","left border"),ae("insertLink","Ctrl+K","idle","insert / edit hyperlink"),ae("insertNote","Shift+F2","idle","insert / edit note"),ae("insertComment","Ctrl+Alt+M","idle","insert comment"),ae("openHyperlink","Alt+Enter","idle","open the hyperlink (idle column — the editing Alt+Enter row is a different column)"),ae("openValidationList","Alt+ArrowDown","idle","open the validation list"),ae("fillDown","Ctrl+D","idle","fill down"),ae("fillRight","Ctrl+R","idle","fill right"),ae("fillSelection","Ctrl+Enter","both","fill the selection with the active / session text"),ae("insertDate","Ctrl+Semicolon","both","insert today's date (active cell / caret)"),ae("insertTime","Ctrl+Shift+Semicolon","both","insert the current time (active cell / caret)"),ae("hideRows","Ctrl+Alt+Digit9","idle","hide the selected rows"),ae("unhideRows","Ctrl+Shift+Digit9","idle","unhide rows"),ae("unhideColumns","Ctrl+Shift+Digit0","idle","unhide columns")],br=(e,t)=>e.column==="both"||e.column===t,cp=Array.from(new Set(Pn.filter(e=>!e.rebindable&&br(e,"idle")).map(e=>e.chord))),Xo=new Set(Pn.filter(e=>e.command!==void 0&&br(e,"editing")).map(e=>e.command)),ap=new Set(Pn.filter(e=>e.command!==void 0&&!e.rebindable).map(e=>e.command)),sc=e=>{const t={};for(const n of Dr)t[n]=e(n);return t},lc=sc(e=>Pn.filter(t=>t.command===e).map(t=>t.chord)),up=e=>{const t=new Map;for(const n of Dr){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},dp=e=>{const t=new Set(Dr);for(const n of Object.keys(e)){if(!t.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not a SpreadsheetCommand`);const r=e[n];if(r!==void 0){if(ap.has(n))throw new RangeError(`[spreadsheet] shortcuts.${n} is not rebindable`);if(r!==null){if(!Array.isArray(r))throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array or null`);for(const o of r)if(typeof o!="string")throw new RangeError(`[spreadsheet] shortcuts.${n} must be an array of chord strings`)}}}},fp=(e,t)=>{const n=zt(t);if(!(n.ctrl||n.alt||n.shift))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} has no modifier`);const r=Xo.has(e);for(const o of Pn)if(!(o.rebindable||o.command===e||o.chord!==t)&&(br(o,"idle")||r&&br(o,"editing")))throw new RangeError(`[spreadsheet] shortcut ${t} for ${e} is reserved by a built-in row (${o.column} column: ${o.note})`)},pp=e=>{e!==void 0&&dp(e);const t=sc(r=>{const o=e===void 0?void 0:e[r];return o===void 0?lc[r]:o===null?[]:o});for(const r of Dr)for(const o of t[r])fp(r,o);const n=new Map;for(const[r,o]of up(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},cl=(e,t)=>{const n=oc(t);if(n===null)return null;const r=t.altKey;if(r&&t.getModifierState("AltGraph"))return null;const o=e.get(sp({ctrl:t.ctrlKey||t.metaKey,alt:r,shift:t.shiftKey,key:n}));return o===void 0?null:o},hp=Object.freeze({ok:!0}),mp="TRUE",gp="FALSE",wp=new Set(["gt","gte","lt","lte","eq","neq","between","notBetween"]),Cp=new Set(["contains","notContains","startsWith","endsWith","isEmail","isUrl"]),bp=/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d{1,4})?$/,yp=/^(\d{4})([-/])(\d{1,2})\2(\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/,vp=/^[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])?)+$/,al={gt:"greater than",gte:"greater than or equal to",lt:"less than",lte:"less than or equal to"},Rp={gt:"after",gte:"on or after",lt:"before",lte:"on or before"},ul=e=>{const t=e.trim();if(!(bp.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("."),a=c<0?s:s.slice(0,c),m=c<0?"":s.slice(c+1),f=a+m,A=f.search(/[^0]/);return A<0?{sign:0,digits:"",point:0}:{sign:n?-1:1,digits:f.slice(A).replace(/0+$/,""),point:a.length+l-A}},kp=e=>e===1?-1:e===-1?1:0,Ep=(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:kp(n)},Sp=(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}},dl=e=>{const t=yp.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>Sp(n,r)||s>23||l>59||c>59?null:{year:n,month:r,day:o,hour:s,minute:l,second:c}},Ap=(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},xp=(e,t)=>e<t?-1:e>t?1:0,Op=e=>e==="between"||e==="notBetween",Dp=(e,t,n,r)=>{const o=r(t);if(o===null)return null;if(!Op(e))return{a:o,b:null};const s=n===void 0?null:r(n);return s===null?null:{a:o,b:s}},Tp=(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}},io=(e,t,n,r,o,s)=>{const l=Dp(e,t,n,r);return l===null?!0:o===null?!1:Tp(e,s(o,l.a),l.b===null?0:s(o,l.b))},Mp=e=>Number.isFinite(e)?e:null,Fp=e=>{let t=0;for(const n of e)t+=1;return t},$p=e=>URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol),Np=(e,t)=>{switch(e.op){case"isEmail":return vp.test(t);case"isUrl":return $p(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)}},Lp=e=>e===!0||typeof e=="number"&&Number.isFinite(e)&&e!==0,ic=e=>({checked:e.checked===void 0?mp:e.checked,unchecked:e.unchecked===void 0?gp:e.unchecked}),Pp=e=>{switch(e.type){case"list":case"checkbox":case"custom":return;case"number":case"textLength":case"date":if(!wp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "${e.type}"`);return;case"text":if(!Cp.has(e.op))throw new RangeError(`[spreadsheet] unknown data-validation op "${String(e.op)}" for type "text"`);return;default:throw new RangeError(`[spreadsheet] unknown data-validation rule type "${String(e.type)}"`)}},zp=(e,t,n)=>{switch(e.type){case"list":return Ip(e).has(t);case"number":return io(e.op,e.a,e.b,ul,ul(t),Ep);case"textLength":return io(e.op,e.a,e.b,Mp,Fp(t),xp);case"date":return io(e.op,e.a,e.b,dl,dl(t),Ap);case"text":return Np(e,t);case"checkbox":{const r=ic(e);return t===r.checked||t===r.unchecked}default:return n===void 0||Lp(n(e.formula))}},cc=(e,t,n)=>(Pp(e),t===""||zp(e,t,n)),co=(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}`}},fl=e=>e===void 0?void 0:e.trim(),qp=e=>{switch(e.type){case"list":return"Value must be one of the list items.";case"number":return`Value must be a number ${co(e.op,e.a.trim(),fl(e.b),al)}.`;case"textLength":return`Text length must be ${co(e.op,String(e.a),e.b===void 0?void 0:String(e.b),al)}.`;case"date":return`Value must be a date ${co(e.op,e.a.trim(),fl(e.b),Rp)}.`;case"text":return _p(e);case"checkbox":{const t=ic(e);return`Value must be "${t.checked}" or "${t.unchecked}".`}default:return`Value does not satisfy the formula ${e.formula}.`}},_p=e=>{switch(e.op){case"contains":return`Value must contain "${e.value}".`;case"notContains":return`Value must not contain "${e.value}".`;case"startsWith":return`Value must start with "${e.value}".`;case"endsWith":return`Value must end with "${e.value}".`;case"isEmail":return"Value must be a valid email address.";default:return"Value must be a valid URL."}},pl=new WeakMap,Ip=e=>{const t=pl.get(e);if(t!==void 0)return t;const n=new Set(e.values);return pl.set(e,n),n},ac=(e,t,n)=>cc(e,t,n)?hp:{ok:!1,message:e.errorMessage===void 0?qp(e):e.errorMessage},Hp=e=>e.type!=="custom",jp=(e,t)=>Hp(e)&&!cc(e,t,void 0),Bp=["sinkAriaLabel","rootAriaLabel","noteTitle","noteSave","noteEscapeHint","noteRejectedHint","commentTitle","commentReply","commentPost","commentCount","linkTitle","linkTextField","linkUrlField","linkOpen","linkSave","listTitle","listEmpty","listMore","messageTitle","validationRejected","popoverClose","indicatorNote","indicatorComment","indicatorInvalid"],Do=Object.freeze({sinkAriaLabel:"Spreadsheet grid. Press Escape to move focus out of the grid.",rootAriaLabel:"Spreadsheet",noteTitle:"Note",noteSave:"Save",noteEscapeHint:"Escape saves and closes",noteRejectedHint:"The note was rejected. Press Ctrl+Enter to retry or Escape to close without saving",commentTitle:"Comments",commentReply:"Reply",commentPost:"Post",commentCount:e=>e===1?"1 comment":`${e} comments`,linkTitle:"Link",linkTextField:"Text",linkUrlField:"URL",linkOpen:"Open",linkSave:"Save",listTitle:"Choose a value",listEmpty:"No matching values",listMore:e=>e===1?"1 more value — keep typing to narrow":`${e} more values — keep typing to narrow`,messageTitle:"Data validation",validationRejected:"The value does not satisfy this cell's validation rule",popoverClose:"Close",indicatorNote:"Has a note",indicatorComment:"Has comments",indicatorInvalid:"Invalid value"}),Wp=e=>{const t=e.sinkAriaLabel;if(typeof t!="string"||!t.includes("Escape"))throw new RangeError(`[spreadsheet] labels.sinkAriaLabel must be a string mentioning "Escape" (WCAG 2.1.2 escape advisement, spec 00 §10-4); got ${JSON.stringify(t)}`)},Vp=(e,t,n)=>{e[t]=n},Kp=e=>{if(e===void 0)return Do;const t={...Do};for(const n of Bp){const r=e[n];r!==void 0&&Vp(t,n,r)}return Wp(t),Object.freeze(t)},Re=(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},uc=(e,t)=>t<=0||e.count===0?0:t>=e.count?e.totalSize():e.offsetOf(t),dc=(e,t,n,r)=>t<r?e.offsetOf(t):e.offsetOf(t)-n,fc=(e,t,n,r)=>r>0&&t<r?e.indexAt(t):e.indexAt(t+n),pc=(e,t)=>uc(e,t),hc=(e,t)=>uc(e,t),_t=(e,t,n,r)=>dc(e,t,n,r),It=(e,t,n,r)=>dc(e,t,n,r),zn=(e,t,n,r)=>fc(e,t,n,r),qn=(e,t,n,r)=>fc(e,t,n,r),jt=12,Up=()=>{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)})}},bt=1,Yp=3,Zn=e=>`${-Math.min(Yp,Math.max(0,Math.floor(e)))}px`,mc=Object.freeze({row:"#0084FF",column:"#42FF4F",intersection:"#E1FF00",opacity:.2}),bn=(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},hl=()=>({rowLeft:bn("row","left"),rowRight:bn("row","right"),colAbove:bn("column","above"),colBelow:bn("column","below"),cross:bn("intersection",null),last:{rowShown:!1,colShown:!1,crossShown:!1,crossTint:"intersection",rowHeight:-1,colWidth:-1,crossWidth:-1,crossHeight:-1}}),gc=e=>[e.rowLeft,e.rowRight,e.colAbove,e.colBelow,e.cross],Jn=(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},Qn=(e,t)=>Math.min(Math.max(e,0),t),ml="inset(100%)",tn=(e,t)=>{for(const n of e)n.style.display=t?"block":"none"},Xp=(e,t,n,r,o)=>{const s=e.last,l=r.row&&!o;if(l!==s.rowShown&&(s.rowShown=l,tn([e.rowLeft,e.rowRight],l)),l){if(t.height!==s.rowHeight){s.rowHeight=t.height;const f=`${t.height}px`;e.rowLeft.style.height=f,e.rowRight.style.height=f}e.rowLeft.style.transform=`translate(${Qn(t.left,n.clampWidth)-n.clampWidth}px, ${t.top}px)`,e.rowRight.style.transform=`translate(${Qn(t.left+t.width,n.clampWidth)}px, ${t.top}px)`}const c=r.column&&!o;if(c!==s.colShown&&(s.colShown=c,tn([e.colAbove,e.colBelow],c)),c){if(t.width!==s.colWidth){s.colWidth=t.width;const f=`${t.width}px`;e.colAbove.style.width=f,e.colBelow.style.width=f}e.colAbove.style.transform=`translate(${t.left}px, ${Qn(t.top,n.clampHeight)-n.clampHeight}px)`,e.colBelow.style.transform=`translate(${t.left}px, ${Qn(t.top+t.height,n.clampHeight)}px)`}const a=r.intersection?"intersection":l!==c?l?"row":"column":null,m=a!==null;m!==s.crossShown&&(s.crossShown=m,tn([e.cross],m)),a!==null&&(a!==s.crossTint&&(s.crossTint=a,e.cross.style.background=a==="intersection"?"":`var(--aqsp-band-${a})`),(t.width!==s.crossWidth||t.height!==s.crossHeight)&&(s.crossWidth=t.width,s.crossHeight=t.height,e.cross.style.width=`${t.width}px`,e.cross.style.height=`${t.height}px`),e.cross.style.transform=`translate(${t.left}px, ${t.top}px)`)},gl=e=>{const t=e.last;t.rowShown&&(t.rowShown=!1,tn([e.rowLeft,e.rowRight],!1)),t.colShown&&(t.colShown=!1,tn([e.colAbove,e.colBelow],!1)),t.crossShown&&(t.crossShown=!1,tn([e.cross],!1))},wl=e=>{for(const t of gc(e))t.remove()},Gp=(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)},Zp=Object.freeze([]),Jp={left:"0px",right:"0px",width:""},Qp={top:"0px",bottom:"0px",height:""},Cl=()=>({container:null,active:null,dragRect:null,marquee:null,fillPreview:null,resizeGuide:null,fillPool:[],bandPool:[],dragBand:null,bandClampWidth:-1,bandClampHeight:-1}),bl=["mm","fm","sm","mf","ms","ff","sf","fs","ss"],yl=6,eh=({rowAxis:e,colAxis:t,handleRef:n,sinkRef:r,getSelection:o,editing:s,virtualKeyboard:l,repaintRef:c,dragFrameRef:a,getClip:m,getIsDraggingAny:f,getIsFillDragging:A,fillFrameRef:L,resizeGuideFrameRef:$,fillHandleNodeRef:T,enableFillHandle:_,frozenCols:V,frozenRows:v,sinkAriaLabel:M,onSinkMouseDown:D,editPaintRef:x,highlightRef:N,highlightColors:p,popoverAnchors:h,interactiveAnchorRef:w,tipAnchorRef:O})=>{const y=i.useRef(null),g=i.useRef(null),q=i.useRef(null),H=i.useRef(new Map(bl.map(F=>[F,Cl()]))),R=i.useCallback(F=>{const W=H.current.get(F);if(W!==void 0)return W;const X=Cl();return H.current.set(F,X),X},[]),E=i.useCallback((F,W,X)=>{if(F===null)return;const j=F.style;j.left!==W.left&&(j.left=W.left),j.right!==W.right&&(j.right=W.right),j.width!==W.width&&(j.width=W.width),j.top!==X.top&&(j.top=X.top),j.bottom!==X.bottom&&(j.bottom=X.bottom),j.height!==X.height&&(j.height=X.height)},[]),u=i.useCallback((F,W,X)=>{if(!(F.bandClampWidth===W&&F.bandClampHeight===X)){F.bandClampWidth=W,F.bandClampHeight=X;for(const j of F.bandPool)Jn(j,W,X);F.dragBand!==null&&Jn(F.dragBand,W,X)}},[]),d=i.useRef({x:0,y:0}),P=i.useRef(null),S=i.useCallback((F,W)=>{const X=n.current,j=X?.getFrozenSize()??{cols:0,width:0,rows:0,height:0},Q=X?.getViewportSize(),oe=Q?.width??-1,ce=Q?.height??-1,be=d.current;be.x=F,be.y=W;let ge=P.current;if(ge===null||ge.frozenCols!==j.cols||ge.frozenWidth!==j.width||ge.frozenRows!==j.rows||ge.frozenHeight!==j.height||ge.bodyWidth!==oe||ge.bodyHeight!==ce){const Ee=j.cols<=0?[{kind:"m",map:ie=>ie-be.x,clamp:oe,style:Jp}]:[{kind:"f",map:ie=>ie,clamp:j.width,style:{left:"0px",width:`${j.width}px`,right:""}},{kind:"s",map:ie=>ie-be.x-j.width,clamp:Math.max(0,oe-j.width),style:{left:`${j.width}px`,right:"0px",width:""}}],xe=j.rows<=0?[{kind:"m",map:ie=>ie-be.y,clamp:ce,style:Qp}]:[{kind:"f",map:ie=>ie,clamp:j.height,style:{top:"0px",height:`${j.height}px`,bottom:""}},{kind:"s",map:ie=>ie-be.y-j.height,clamp:Math.max(0,ce-j.height),style:{top:`${j.height}px`,bottom:"0px",height:""}}],Oe=[];for(const ie of Ee)for(const le of xe)Oe.push({nodes:R(`${ie.kind}${le.kind}`),mapX:ie.map,clampWidth:ie.clamp,xStyle:ie.style,mapY:le.map,clampHeight:le.clamp,yStyle:le.style});ge={frozenCols:j.cols,frozenWidth:j.width,frozenRows:j.rows,frozenHeight:j.height,bodyWidth:oe,bodyHeight:ce,ctxs:Oe},P.current=ge}for(const Ee of ge.ctxs)E(Ee.nodes.container,Ee.xStyle,Ee.yStyle),u(Ee.nodes,Ee.clampWidth,Ee.clampHeight);return ge.ctxs},[n,R,E,u]),b=i.useCallback(F=>{const W=()=>R(F);return{container:X=>{const j=W();j.container=X,X===null&&(j.fillPool.length=0,j.bandPool.length=0,j.dragBand=null,j.bandClampWidth=-1,j.bandClampHeight=-1)},active:X=>{W().active=X},dragRect:X=>{W().dragRect=X},marquee:X=>{W().marquee=X},fillPreview:X=>{W().fillPreview=X},resizeGuide:X=>{W().resizeGuide=X}}},[R]),I=i.useMemo(()=>Object.fromEntries(bl.map(F=>[F,b(F)])),[b]),k=Math.min(Math.max(0,V),t.count),z=pc(t,k),B=Math.min(Math.max(0,v),e.count),U=hc(e,B),G=i.useRef(null),J=i.useRef("add"),Z=i.useRef(s);Z.current=s;const te=i.useRef(!1),Ie=Mn.useWheelBridge(n,{enableBridge:!s}),fe=i.useCallback(F=>(r.current=F,Ie(F)),[r,Ie]),Ze=i.useCallback((F,W)=>({top:W.mapY(e.offsetOf(F.startRow)),bottom:W.mapY(e.offsetOf(F.endRow)+e.sizeOf(F.endRow)),left:W.mapX(t.offsetOf(F.startCol)),right:W.mapX(t.offsetOf(F.endCol)+t.sizeOf(F.endCol))}),[e,t]),He=i.useCallback((F,W)=>{if(W.clampHeight<=0||W.clampWidth<=0)return null;const{top:X,bottom:j,left:Q,right:oe}=Ze(F,W),ce=-W.clampHeight*bt,be=W.clampHeight*(1+bt),ge=-W.clampWidth*bt,Ee=W.clampWidth*(1+bt);if(j<ce||X>be||oe<ge||Q>Ee)return null;const xe=Math.max(X,ce),Oe=Math.max(Q,ge);return{top:xe,left:Oe,width:Math.min(oe,Ee)-Oe,height:Math.min(j,be)-xe}},[Ze]),_n=i.useCallback((F,W)=>{if(W.clampHeight<=0||W.clampWidth<=0)return null;const X=Ze(F,W),j=-W.clampHeight*bt,Q=W.clampHeight*(1+bt),oe=-W.clampWidth*bt,ce=W.clampWidth*(1+bt),be=Math.min(Math.max(X.top,j),Q),ge=Math.min(Math.max(X.left,oe),ce);return{top:be,left:ge,width:Math.min(Math.max(X.right,oe),ce)-ge,height:Math.min(Math.max(X.bottom,j),Q)-be}},[Ze]),Bt=i.useCallback(()=>{if(N===void 0)return null;const F=N.current;return F.row||F.column||F.intersection?F:null},[N]),At=i.useCallback((F,W,X)=>{const j=W.fillPool.length>0?W.fillPool[0]:W.active;for(const Q of gc(X))F.insertBefore(Q,j)},[]),Wt=i.useCallback((F,W,X,j)=>{const Q=_n(W,X);if(Q===null){gl(F);return}Xp(F,Q,X,j,di(W,t.count)||fi(W,e.count))},[_n,e,t]),Tr=i.useCallback((F,W,X,j)=>{const Q=F.nodes.bandPool;for(;Q.length>X.length;){const oe=Q.pop();oe!==void 0&&wl(oe)}if(j===null){F.nodes.dragBand!==null&&(wl(F.nodes.dragBand),F.nodes.dragBand=null);return}for(let oe=0;oe<X.length;oe+=1){let ce=Q[oe];ce===void 0&&(ce=hl(),Jn(ce,F.clampWidth,F.clampHeight),At(W,F.nodes,ce),Q.push(ce)),Wt(ce,X[oe],F,j)}},[At,Wt]),Vt=i.useCallback((F,W,X)=>{const j=F.nodes.container;if(j===null)return;if(W===null||X===null){F.nodes.dragBand!==null&&gl(F.nodes.dragBand);return}let Q=F.nodes.dragBand;Q===null&&(Q=hl(),Jn(Q,F.clampWidth,F.clampHeight),At(j,F.nodes,Q),F.nodes.dragBand=Q),Wt(Q,W,F,X)},[At,Wt]),Ue=i.useCallback((F,W)=>{if(F!==null){if(W===null){F.style.display="none";return}F.style.display="block",F.style.transform=`translate(${W.left}px, ${W.top}px)`,F.style.width=`${W.width}px`,F.style.height=`${W.height}px`}},[]),Je=i.useCallback((F,W,X,j)=>{const Q=j==="point"?null:Bt();for(const oe of S(X,W))Ue(oe.nodes.dragRect,He(F,oe)),Vt(oe,F,Q)},[He,S,Ue,Bt,Vt]),ut=i.useCallback((F,W,X)=>{for(const j of S(X,W))Ue(j.nodes.fillPreview,F===null?null:He(F,j))},[He,S,Ue]),dt=i.useCallback((F,W,X)=>{for(const j of S(X,W)){const Q=j.nodes.resizeGuide;if(Q!==null){if(F===null){Q.style.display="none";continue}Q.style.display="block",F.axis==="col"?(Q.style.transform=`translate(${j.mapX(F.position)}px, 0px)`,Q.style.width="1px",Q.style.height="100%"):(Q.style.transform=`translate(0px, ${j.mapY(F.position)}px)`,Q.style.width="100%",Q.style.height="1px")}}},[S]),Ye=i.useCallback((F,W,X,j,Q,oe,ce)=>{if(F===null)return;if(W===null||ce<=0||oe<=0){F.style.clipPath=ml;return}const be=It(e,W.row,X,Q.rows),ge=_t(t,W.col,j,Q.cols),Ee=ge>=oe||be>=ce,xe=W.col>=Q.cols&&ge<Q.width,Oe=W.row>=Q.rows&&be<Q.height;if(Ee||xe||Oe){F.style.clipPath=ml;return}F.style.clipPath="",F.style.transform=`translate(${ge}px, ${be}px)`;const ie=t.sizeOf(W.col),le=e.sizeOf(W.row),de=`${ie} ${le}`;F.dataset.aqspAnchorSig!==de&&(F.dataset.aqspAnchorSig=de,F.style.width=`${ie}px`,F.style.height=`${le}px`)},[e,t]),$e=i.useCallback((F,W,X)=>{if(h===void 0)return;const j=h.current,{width:Q,height:oe}=F.getViewportSize(),ce=F.getFrozenSize();Ye(w===void 0?null:w.current,j.interactive,W,X,ce,Q,oe),Ye(O===void 0?null:O.current,j.tip,W,X,ce,Q,oe)},[h,w,O,Ye]),an=i.useCallback(()=>{const F=y.current,W=n.current;if(F===null||W===null)return;const X=W.getScrollPosition(),j=Math.max(0,X.y),Q=Math.max(0,X.x),oe=o(),ce=Bt(),be=ce===null?Zp:oe.ranges.slice(-16),ge=S(Q,j);for(const le of ge){const de=le.nodes.container;if(de===null)continue;const pe=le.nodes.fillPool;for(let Ce=0;Ce<Math.max(pe.length,oe.ranges.length);Ce+=1){let me=pe[Ce];me===void 0&&(me=document.createElement("div"),me.className="aqsp-selection-fill",me.setAttribute("data-aqsp-fill",""),de.insertBefore(me,le.nodes.active),pe.push(me));const Ne=oe.ranges[Ce],De=Ne===void 0?null:He(Ne,le);De===null?me.style.display="none":(me.style.display="block",me.style.transform=`translate(${De.left}px, ${De.top}px)`,me.style.width=`${De.width}px`,me.style.height=`${De.height}px`)}for(;pe.length>oe.ranges.length;)pe.pop()?.remove();Ue(le.nodes.active,He(ue(oe.active,oe.active),le)),Tr(le,de,be,ce)}const Ee=m(),xe=Ee===null||Ee.foreign?null:Ee;for(const le of ge){const de=le.nodes.marquee;if(de===null)continue;const pe=xe===null?null:He(xe.range,le);if(pe===null)de.style.display="none";else{de.style.display="block",de.style.transform=`translate(${pe.left}px, ${pe.top}px)`,de.style.width=`${pe.width}px`,de.style.height=`${pe.height}px`;const Ne=Zn(pe.top),De=Zn(pe.left),ze=Zn(le.clampHeight-(pe.top+pe.height)),Xe=Zn(le.clampWidth-(pe.left+pe.width)),Qe=`${Ne} ${Xe} ${ze} ${De}`;Qe!==de.dataset.aqspOutsetSig&&(de.dataset.aqspOutsetSig=Qe,de.style.setProperty("--aqsp-clip-outset-top",Ne),de.style.setProperty("--aqsp-clip-outset-right",Xe),de.style.setProperty("--aqsp-clip-outset-bottom",ze),de.style.setProperty("--aqsp-clip-outset-left",De))}const Ce=pe===null?null:xe?.kind??null,me=de.dataset.aqspClipKindLast??null;Ce!==me&&(Ce===null?(delete de.dataset.aqspClipKindLast,de.removeAttribute("data-aqsp-clip-kind")):(de.dataset.aqspClipKindLast=Ce,de.setAttribute("data-aqsp-clip-kind",Ce)))}G.current!==null&&Je(G.current,j,Q,J.current),q.current!==null&&dt(q.current,j,Q),g.current!==null&&ut(g.current,j,Q);const Oe=T.current;if(Oe!==null&&!A()){const{width:le,height:de}=W.getViewportSize(),pe=oe.ranges[oe.ranges.length-1];if(!(oe.ranges.length===1&&!Z.current&&!f())||de<=0||le<=0)Oe.style.display="none";else{const me=W.getFrozenSize(),Ne=pe.endCol<me.cols,De=pe.endRow<me.rows,ze=_t(t,pe.endCol,Q,me.cols)+t.sizeOf(pe.endCol),Xe=It(e,pe.endRow,j,me.rows)+e.sizeOf(pe.endRow),Qe=Ne?0:me.width,et=De?0:me.height;Xe<=et||Xe>de||ze<=Qe||ze>le?Oe.style.display="none":(Oe.style.display="block",Oe.style.transform=`translate(${ze-yl+1}px, ${Xe-yl+1}px)`)}}const ie=r.current;if(ie!==null){const le=oe.active,{width:de,height:pe}=W.getViewportSize(),Ce=W.getFrozenSize(),me=It(e,le.row,j,Ce.rows),Ne=_t(t,le.col,Q,Ce.cols),De=pe>0?Math.min(Math.max(me,0),Math.max(0,pe-1)):0,ze=de>0?Math.min(Math.max(Ne,0),Math.max(0,de-1)):0;ie.style.top=`${De}px`,ie.style.left=`${ze}px`,Z.current?(ie.style.width=`${t.sizeOf(le.col)}px`,ie.style.height=`${e.sizeOf(le.row)}px`,ie.style.paddingTop=`${Gp(e.sizeOf(le.row),x===void 0?lt:x.current)}px`):(ie.style.width="1px",ie.style.height="1px",ie.style.paddingTop="0px");const Xe=le.col>=Ce.cols&&Ne<Ce.width,Qe=le.row>=Ce.rows&&me<Ce.height,et=Z.current&&me===De&&Ne===ze&&!Xe&&!Qe;et!==te.current&&(te.current=et,et?ie.setAttribute("data-aqsp-editing",""):ie.removeAttribute("data-aqsp-editing"))}$e(W,j,Q)},[n,He,S,Ue,Je,dt,ut,m,o,f,A,T,r,e,t,Bt,Tr,x,$e]),Mr=i.useCallback((F,W)=>{G.current=F,J.current=W;const X=F===null?"add":W;for(const oe of S(0,0)){const ce=oe.nodes.dragRect;if(ce===null)continue;const be=ce.dataset.aqspDragModeLast??"add";X!==be&&(ce.dataset.aqspDragModeLast=X,X==="add"?ce.removeAttribute("data-aqsp-drag-mode"):ce.setAttribute("data-aqsp-drag-mode",X))}const j=n.current;if(F===null||j===null){for(const oe of S(0,0))oe.nodes.dragRect!==null&&(oe.nodes.dragRect.style.display="none"),Vt(oe,null,null);return}const Q=j.getScrollPosition();Je(F,Math.max(0,Q.y),Math.max(0,Q.x),W)},[n,Je,S,Vt]),je=i.useCallback(F=>{g.current=F;const W=n.current;if(W===null){for(const j of S(0,0))j.nodes.fillPreview!==null&&(j.nodes.fillPreview.style.display="none");return}const X=W.getScrollPosition();ut(F,Math.max(0,X.y),Math.max(0,X.x))},[n,ut,S]),ke=i.useCallback(F=>{q.current=F;const W=n.current;if(W===null){for(const j of S(0,0))j.nodes.resizeGuide!==null&&(j.nodes.resizeGuide.style.display="none");return}const X=W.getScrollPosition();dt(F,Math.max(0,X.y),Math.max(0,X.x))},[n,dt,S]);i.useLayoutEffect(()=>{const F=y.current;if(!(F===null||p===void 0))return F.style.setProperty("--aqsp-band-row",p.row),F.style.setProperty("--aqsp-band-column",p.column),F.style.setProperty("--aqsp-band-intersection",p.intersection),F.style.setProperty("--aqsp-band-opacity",String(p.opacity)),()=>{F.style.removeProperty("--aqsp-band-row"),F.style.removeProperty("--aqsp-band-column"),F.style.removeProperty("--aqsp-band-intersection"),F.style.removeProperty("--aqsp-band-opacity")}},[p]),i.useEffect(()=>(c.current=an,a.current=Mr,L.current=je,$.current=ke,()=>{c.current=null,a.current=null,L.current=null,$.current=null})),i.useEffect(()=>{an()},[an,s,k,B]),i.useEffect(()=>{const F=r.current;if(F===null)return;const W=X=>D(X);return F.addEventListener("mousedown",W),()=>F.removeEventListener("mousedown",W)},[r,D]);const ft=k>0?[{k:"f",style:{left:0,width:z}},{k:"s",style:{left:z,right:0}}]:[{k:"m",style:{left:0,right:0}}],un=B>0?[{k:"f",style:{top:0,height:U}},{k:"s",style:{top:U,bottom:0}}]:[{k:"m",style:{top:0,bottom:0}}],xt=F=>F==="m"?0:F==="s"?1:2,In=ft.flatMap(F=>un.map(W=>({key:`${F.k}${W.k}`,style:{...F.style,...W.style}}))).sort((F,W)=>xt(F.key[0])+xt(F.key[1])-(xt(W.key[0])+xt(W.key[1]))),dn=F=>F==="mm"?{"data-aqsp-overlay-main":""}:F==="fm"?{"data-aqsp-overlay-frozen":""}:F==="sm"?{"data-aqsp-overlay-scroll":""}:{};return Y.jsxs("div",{ref:y,className:"aqsp-overlay","data-aqsp-overlay":"",style:{right:jt,bottom:jt},children:[In.map(({key:F,style:W})=>{const X=I[F];return Y.jsxs("div",{className:"aqsp-overlay-quad","data-aqsp-overlay-quad":F,...dn(F),style:W,ref:X.container,children:[Y.jsx("div",{className:"aqsp-active-frame","data-aqsp-active":"",style:{display:"none"},ref:X.active}),Y.jsx("div",{className:"aqsp-drag-rect","data-aqsp-drag-rect":"",style:{display:"none"},ref:X.dragRect}),Y.jsx("div",{className:"aqsp-clip-marquee","data-aqsp-clip-marquee":"",style:{display:"none"},ref:X.marquee}),Y.jsx("div",{className:"aqsp-autofill-preview","data-aqsp-autofill-preview":"",style:{display:"none"},ref:X.fillPreview}),Y.jsx("div",{className:"aqsp-resize-guide","data-aqsp-resize-guide":"",style:{display:"none"},ref:X.resizeGuide})]},F)}),Y.jsx("textarea",{ref:fe,className:"aqsp-sink","aria-label":M,tabIndex:-1,defaultValue:" ",inputMode:l?"text":"none",spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",autoComplete:"off","data-aqsp-sink":""}),_?Y.jsx("div",{ref:T,className:"aqsp-autofill-handle","data-aqsp-autofill-handle":"",style:{display:"none"}}):null]})},wc=({ctx:e,labels:t})=>{const[n,r]=i.useState(""),o=i.useId(),s=i.useRef(!1),l=f=>{s.current=!0;try{f()}finally{s.current=!1}},c=()=>{n.trim()!==""&&l(()=>e.commit([...e.current,{text:n}]))},a=f=>{if(f.key==="Escape"){f.preventDefault(),l(e.close);return}f.key==="Enter"&&(f.ctrlKey||f.metaKey)&&!f.altKey&&!f.shiftKey&&(f.preventDefault(),c())},m=f=>{s.current||f.relatedTarget instanceof Node&&f.currentTarget.contains(f.relatedTarget)||e.rejected||l(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":o,onBlur:m,children:[Y.jsxs("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:o,children:[Re(t,"commentTitle"),Y.jsx("span",{className:"aqsp-popover-count","data-aqsp-comment-count":"",children:Re(t,"commentCount",e.current.length)})]}),Y.jsx("ul",{className:"aqsp-popover-thread","data-aqsp-comment-thread":"",children:e.current.map(f=>Y.jsxs("li",{className:"aqsp-popover-comment-item","data-aqsp-comment-id":f.id,children:[Y.jsx("span",{className:"aqsp-popover-comment-author",children:f.author}),Y.jsx("time",{className:"aqsp-popover-comment-time",dateTime:f.createdAt,children:f.createdAt}),Y.jsx("p",{className:"aqsp-popover-comment-text",children:f.text})]},f.id))}),Y.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-comment-input":"","data-aqsp-popover-autofocus":"",value:n,"aria-label":Re(t,"commentReply"),"aria-invalid":e.rejected?!0:void 0,onChange:f=>r(f.currentTarget.value),onKeyDown:a}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-post":"",onClick:c,children:Re(t,"commentPost")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Re(t,"popoverClose"),onClick:()=>l(e.close),children:"×"})]})]})},Cc=({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=i.useId(),c=i.useRef(!1),a=o.trim()===""?null:St(o),m=o.trim()!==""&&a===null,f=T=>{c.current=!0;try{T()}finally{c.current=!1}},A=()=>{m||f(()=>e.commit({text:n===""&&a!==null?a:n,url:a}))},L=T=>{if(T.key==="Escape"){T.preventDefault(),f(e.close);return}T.key==="Enter"&&!T.altKey&&!T.shiftKey&&(T.preventDefault(),A())},$=T=>{c.current||T.relatedTarget instanceof Node&&T.currentTarget.contains(T.relatedTarget)||e.rejected||f(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":l,onBlur:$,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:l,children:Re(t,"linkTitle")}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:Re(t,"linkTextField")}),Y.jsx("input",{className:"aqsp-popover-input","data-aqsp-link-text":"",type:"text",value:n,onChange:T=>r(T.currentTarget.value),onKeyDown:L})]}),Y.jsxs("label",{className:"aqsp-popover-field",children:[Y.jsx("span",{className:"aqsp-popover-field-label",children:Re(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:T=>s(T.currentTarget.value),onKeyDown:L})]}),Y.jsxs("div",{className:"aqsp-popover-actions",children:[Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-save":"",disabled:m,onClick:A,children:Re(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:Re(t,"linkOpen")}):null,Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Re(t,"popoverClose"),onClick:()=>f(e.close),children:"×"})]})]})},vl=500,bc=({ctx:e,labels:t})=>{const[n,r]=i.useState(e.typed),[o,s]=i.useState(0),l=i.useId(),c=i.useRef(!1),a=i.useMemo(()=>{const v=n.toLowerCase();return e.current.filter(M=>M.toLowerCase().startsWith(v))},[e.current,n]),m=i.useMemo(()=>a.length>vl?a.slice(0,vl):a,[a]),f=a.length-m.length,A=m.length===0?-1:Math.min(o,m.length-1),L=v=>{c.current=!0;try{v()}finally{c.current=!1}},$=()=>{A<0||L(()=>e.commit(m[A]))},T=v=>{if(v.key==="Escape"){v.preventDefault(),L(e.close);return}if(v.key==="Enter"){v.preventDefault(),$();return}if(v.key==="ArrowDown"){v.preventDefault(),s(A+1);return}v.key==="ArrowUp"&&(v.preventDefault(),s(Math.max(A-1,0)))},_=v=>{c.current||v.relatedTarget instanceof Node&&v.currentTarget.contains(v.relatedTarget)||L(e.close)},V=v=>`${l}-${v}`;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":Re(t,"listTitle"),"aria-expanded":"true","aria-autocomplete":"list","aria-controls":l,"aria-activedescendant":A<0?void 0:V(A),value:n,onChange:v=>{r(v.currentTarget.value),s(0)},onKeyDown:T}),Y.jsxs("div",{className:"aqsp-popover-options",id:l,role:"listbox","aria-label":Re(t,"listTitle"),children:[m.length===0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-empty":"",children:Re(t,"listEmpty")}):m.map((v,M)=>Y.jsx("div",{className:"aqsp-popover-option",id:V(M),role:"option",tabIndex:-1,"aria-selected":M===A,"data-aqsp-list-option":v,onPointerDown:D=>D.preventDefault(),onClick:()=>L(()=>e.commit(v)),children:v},V(M))),f>0?Y.jsx("div",{className:"aqsp-popover-empty","data-aqsp-list-more":"",children:Re(t,"listMore",f)}):null]})]})},yc=({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":Re(t,"popoverClose"),onClick:e.close,children:"×"})]}),vc=({ctx:e,labels:t})=>{const n=e.current===void 0?"":e.current,[r,o]=i.useState(n),s=i.useId(),l=i.useId(),c=i.useRef(!1),a=$=>{c.current=!0;try{$()}finally{c.current=!1}},m=()=>{a(()=>e.commit(r===""?null:r))},f=()=>{r!==n?m():a(e.close)},A=$=>{if($.key==="Escape"){$.preventDefault(),e.rejected?a(e.close):f();return}$.key==="Enter"&&($.ctrlKey||$.metaKey)&&!$.altKey&&!$.shiftKey&&($.preventDefault(),m())},L=$=>{c.current||$.relatedTarget instanceof Node&&$.currentTarget.contains($.relatedTarget)||e.rejected||f()};return Y.jsxs("div",{className:"aqsp-popover-note","data-aqsp-popover":"note","data-aqsp-popover-rejected":e.rejected?"":void 0,role:"dialog","aria-labelledby":s,onBlur:L,children:[Y.jsx("div",{className:"aqsp-popover-title","data-aqsp-popover-title":"",id:s,children:Re(t,"noteTitle")}),Y.jsx("textarea",{className:"aqsp-popover-textarea","data-aqsp-note-input":"","data-aqsp-popover-autofocus":"",value:r,"aria-describedby":l,"aria-invalid":e.rejected?!0:void 0,onChange:$=>o($.currentTarget.value),onKeyDown:A}),Y.jsx("p",{className:"aqsp-popover-hint",id:l,"data-aqsp-popover-hint":"",children:Re(t,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":"",onClick:m,children:Re(t,"noteSave")}),Y.jsx("button",{type:"button",className:"aqsp-popover-button","data-aqsp-popover-close":"","aria-label":Re(t,"popoverClose"),onClick:()=>a(e.close),children:"×"})]})]})},Rc=({ctx:e})=>Y.jsx("div",{className:"aqsp-popover-note-tip","data-aqsp-popover":"note-tip",role:"tooltip",children:e.current}),ot=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")}),Rl=["text","formula","format","borders","cf","note","comments","hyperlink","validation","sizes"],kc=Object.freeze({all:ot(Rl),values:ot(["text"]),formats:ot(["format","borders","cf"]),formulas:ot(["text","formula"]),noBorders:ot(Rl.filter(e=>e!=="borders")),columnWidths:ot(["sizes"]),validation:ot(["validation"]),conditionalFormats:ot(["cf"]),commentsAndNotes:ot(["note","comments"])}),kl=Object.freeze({mode:"all"}),To=Object.freeze({t:""}),El=Object.freeze({row:1<<30,col:1<<30}),th=Object.freeze({add:"+",subtract:"-",multiply:"*",divide:"/"}),nh=e=>e.t===""&&e.f===void 0,rh=e=>e.length>1&&e.startsWith("="),oh=(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}},Sl=e=>Number.isFinite(e)?String(Number(e.toPrecision(15))):null,sh=(e,t,n,r)=>{const o=rh(e),s=e===""?"0":qe(e);if(!o&&s===null)return null;const l=th[n];if(t.f!==void 0){const m=Nn(t.f,r),f=m.startsWith("=")?m.slice(1):m;return`=(${o?e.slice(1):s})${l}(${f})`}if(t.t==="")return n==="multiply"||n==="divide"||o||e===""?null:Sl(Number(s));const c=qe(t.t);if(c===null)return null;const a=Number(c);return n==="divide"&&a===0?null:o?`=(${e.slice(1)})${l}(${c})`:Sl(oh(Number(s),a,n))},Al=e=>({row:e.col,col:e.row,absRow:!1,absCol:!1}),lh=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:Al(e.start),end:Al(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}}}},ih=e=>{const t=Nn(e,El),n=$n(t);let r="",o=0,s=!1;for(const l of n){const c=lh(l.token);c!==l.token&&(r+=`${t.slice(o,l.start)}${Rt(c)}`,o=l.end,s=!0)}return s?Ar(`${r}${t.slice(o)}`,El):e},ch=(e,t,n)=>{const r=e.cells[t];if(r===void 0)return To;const o=r[n];return o===void 0?To:o},ah=e=>{const{rows:t,cols:n}=e,r=Si(ih);let o=t===1&&n===1&&e.colWidths===void 0&&e.rowHeights===void 0&&!e.wholeRows&&!e.wholeCols;const s=[];for(let c=0;c<n;c+=1){const a=[];for(let m=0;m<t;m+=1){const f=ch(e,m,c);let A=f;if(f.f!==void 0){const L=r(f.f);A=L===f.f?f:{...f,f:L}}(A!==f||f===To)&&(o=!1),a.push(A)}s.push(a)}if(o)return e;const l=e.conditionalFormats.length===0?e.conditionalFormats:e.conditionalFormats.map(c=>({...c,ranges:c.ranges.map(a=>({startRow:a.startCol,startCol:a.startRow,endRow:a.endCol,endCol:a.endRow}))}));return{v:1,rows:n,cols:t,clipId:e.clipId,formats:e.formats,validations:e.validations,cells:s,wholeRows:!1,wholeCols:!1,conditionalFormats:l}},uh=(e,t)=>!t.formula&&e.f!==void 0||!t.format&&e.fmt!==void 0||!t.validation&&e.val!==void 0||!t.note&&e.note!==void 0||!t.comments&&e.comments!==void 0||!t.hyperlink&&e.link!==void 0,dh=(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},xl=(e,t)=>{let n=!1;const r=[];for(const c of e.cells){let a=!1;const m=[];for(const f of c)uh(f,t)?(m.push(dh(f,t)),a=!0):m.push(f);a&&(n=!0),r.push(a?m:c)}const o=!t.format&&e.formats.length>0?[]:e.formats,s=!t.validation&&e.validations.length>0?[]:e.validations,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},Ol=new WeakMap,Ec=e=>{const t=Ol.get(e);if(t!==void 0)return t;const n=e.formats.map(s=>Ke(s)),r=n.map(s=>s===void 0||s.borders===void 0?s:Ke({...s,borders:void 0})),o={canonical:n,borderless:r};return Ol.set(e,o),o},yr=(e,t)=>t===void 0?void 0:e[t],fh=(e,t,n,r)=>{const o=Ec(e);if(n){const m=yr(o.canonical,t.fmt);return m===void 0?null:m}const s=yr(o.borderless,t.fmt),l=r.readFormat(),c=l===void 0?void 0:l.borders;if(c===void 0)return s===void 0?null:s;const a=Ke(s===void 0?{borders:c}:{...s,borders:c});return a===void 0?null:a},ph=(e,t,n,r)=>{const o=t||e.f===void 0?e:{t:e.t};return r!==void 0?sh(n.readText(),o,r,n):o.f===void 0?o.t:Nn(o.f,n)},Dl=(e,t,n,r,o)=>{const s=kc[r.mode];if(r.skipBlanks===!0&&nh(e))return null;const l={};let c=!1;if(s.text){const a=ph(e,s.formula&&o.formula,n,r.operation);a!==null&&(l.text=a,c=!0)}if(o.format){if(s.format)l.format=fh(t,e,s.borders,n),c=!0;else if(r.injectIntoEmpty===!0&&e.fmt!==void 0&&n.readText()===""){const a=yr(Ec(t).canonical,e.fmt);a!==void 0&&(l.format=a,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 a=yr(t.validations,e.val);l.validation=a===void 0?null:a,c=!0}return c?l:null},Tl=(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}}),hh=["text/html","text/plain"],mh=(e,t,n)=>{if(e===0||t===0)return 0;const r=_e(n);return!(r.rows===1&&r.cols===1)&&r.rows%e===0&&r.cols%t===0?r.rows*r.cols:e*t},gh=e=>e.mode==="all"&&e.operation===void 0&&e.transpose!==!0&&e.skipBlanks!==!0,wh=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}}},Ml=e=>{const t=e.clipboardData;return t??null},Ch=(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}},bh=(e,t)=>{const n=[];for(const r of e){const o=[];for(const l of r.ranges){const c=Ch(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},yh=(e,t,n,r,o)=>{const s=ln(e,r,o),l={t:s.isFormula?e.getCellText(r,o):s.text};if(s.isFormula&&(l.f=Ar(s.text,{row:r,col:o})),e.getCellFormat!==void 0){const c=e.getCellFormat(r,o);if(c!==void 0){const a=t.intern(c);a!==void 0&&(l.fmt=a)}}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:a,author:m,createdAt:f})=>({text:a,author:m,createdAt:f})))}if(e.getCellHyperlink!==void 0){const c=cn(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},Sc=(e,t)=>{const n=ui(),r=Nu(),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(yh(e,n,r,s,c));o.push(l)}return{formats:n.entries,validations:r.entries,cells:o,conditionalFormats:e.getConditionalFormats===void 0?[]:bh(e.getConditionalFormats(),t)}},Fl=e=>e.kind==="cut"?{...e.payload,...Sc(e.sourceAdapter,e.range)}:e.payload,vh=e=>({v:1,rows:e.length,cols:e[0].length,clipId:qo(),formats:[],validations:[],cells:e.map(t=>t.map(n=>({t:n}))),wholeRows:!1,wholeCols:!1,conditionalFormats:[]}),Rh=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=St(l.link);if(c===l.link){s.push(l);continue}if(o=!0,c===null){const{link:a,...m}=l;s.push(m)}else s.push({...l,link:c})}o&&(t=!0),n.push(o?s:r)}return t?{...e,cells:n}:e},kh=(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},Eh=(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 ue({row:e[0].row,col:e[0].col},{row:Math.min(s,r-1),col:Math.min(l,o-1)})},Sh=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(v=>{const M=n.current;if(M===null||v==="format"||v==="annotate")return;const D=r.current;D==="own"||D==="foreign"&&M.kind==="copy"||o()},[o]),l=i.useCallback(()=>{const v=n.current;if(v===null)return;if(v.kind==="copy"){o();return}const M=t.current;M.repaintOverlay(),M.onClipChange?.({kind:"cut",range:v.range,foreign:v.sourceAdapter!==M.adapter})},[o]),c=i.useCallback((v,M,D)=>{const x=t.current;n.current={kind:v,range:M,clipId:D.clipId,sourceAdapter:x.adapter,payload:D},x.repaintOverlay(),x.onClipChange?.({kind:v,range:M,foreign:!1})},[]),a=i.useCallback(v=>{const M=t.current,D=M.adapter,x=_e(v),N={v:1,rows:x.rows,cols:x.cols,clipId:qo(),...Sc(D,v),wholeRows:di(v,D.colCount),wholeCols:fi(v,D.rowCount)};if(M.resize!==void 0){if(N.wholeCols){const p=[];for(let h=v.startCol;h<=v.endCol;h+=1)p.push(Math.min(M.resize.colAxis.sizeOf(h),rn));N.colWidths=p}if(N.wholeRows){const p=[];for(let h=v.startRow;h<=v.endRow;h+=1)p.push(Math.min(M.resize.rowAxis.sizeOf(h),rn));N.rowHeights=p}}return N},[]),m=i.useCallback((v,M)=>{const D=t.current,x=D.getSelection(),N=x.ranges[x.ranges.length-1],p=wr([N]);if(p>D.maxOperationCells)return v.preventDefault(),D.onOperationRejected?.(M,p,"limit"),null;x.ranges.length>1&&D.onCopyMultiRange?.();const h=a(N),w=Ql(h),O=Ml(v);return O!==null&&(O.setData("text/plain",Qi(h.cells.map(y=>y.map(g=>g.t)))),O.setData("text/html",Bi(h,w)),O.setData(mr,w)),v.preventDefault(),{payload:h,range:N}},[a]),f=i.useCallback((v,M)=>t.current.commitPaste(v,M)!==null,[]),A=i.useCallback((v,M,D)=>{const x=t.current;if(!D.sizes||x.resize===void 0)return;const{rowAxis:N,colAxis:p,resizeTracks:h}=x.resize,w=(O,y,g)=>{const q=No(y,g,null,{maxOperationCells:x.maxOperationCells,rowHiddenLimit:Fo,axisKind:O});if(!q.ok){x.onOperationRejected?.("resize",q.count,q.reason);return}h(O,q.entries)};if(v.colWidths!==void 0){const O=[];for(let y=M.startCol;y<=M.endCol;y+=1)O.push({index:y,size:v.colWidths[(y-M.startCol)%v.cols]});w("col",p,O)}if(v.rowHeights!==void 0){const O=[];for(let y=M.startRow;y<=M.endRow;y+=1)O.push({index:y,size:v.rowHeights[(y-M.startRow)%v.rows]});w("row",N,O)}},[]),L=i.useCallback((v,M)=>{const D=t.current,x=D.adapter,N=v.payload,p={row:M.startRow,col:M.startCol},h=N.rows*N.cols+wr([v.range]);if(h>D.maxOperationCells)return D.onOperationRejected?.("paste",h,"limit"),"rejected";if(p.row+N.rows>x.rowCount||p.col+N.cols>x.colCount||v.range.endRow>=v.sourceAdapter.rowCount||v.range.endCol>=v.sourceAdapter.colCount)return D.onOperationRejected?.("paste",h,"bounds"),"rejected";const w=Fl(v),O=pr(x),y=xl(w,O),g={row:0,col:0,readText:()=>ln(x,g.row,g.col).text,readFormat:()=>x.getCellFormat===void 0?void 0:x.getCellFormat(g.row,g.col)},{edits:q,tiles:H}=ll(y.cells,ue(p,p),p,x.rowCount,x.colCount,(u,d,P)=>(g.row=v.range.startRow+(d-p.row),g.col=v.range.startCol+(P-p.col),Dl(u,y,g,kl,O))),R=pr(v.sourceAdapter),E=[];if(yt([v.range],u=>{E.push(kh(u.row,u.col,R))}),v.sourceAdapter===x){if(!f([...E,...q],{sameSheet:!0,conditionalFormats:[]}))return"rejected"}else{const u=D.commitPaste(q,{sameSheet:!1,conditionalFormats:Tl(y.conditionalFormats,H)});if(u===null)return"rejected";try{v.sourceAdapter.applyEdits(E,{transaction:u,source:"paste",sameSheet:!1,conditionalFormats:[]})}catch(d){D.onEditRejected?.(d,{source:"paste"})}}return D.setSelection({ranges:[ue(p,{row:p.row+w.rows-1,col:p.col+w.cols-1})],anchor:p,active:p}),"applied"},[f]),$=i.useCallback((v,M,D)=>{const x=t.current,N=x.adapter,p=B=>(x.onClipboardUnavailable?.(B),"rejected"),h=ni(v,M);if(h==="none")return M==="menu"?p("empty"):"empty";const w=x.getSelection(),O=w.ranges[w.ranges.length-1],y=D.transpose===!0,g=(B,U)=>{const G=mh(y?U:B,y?B:U,O);return G>x.maxOperationCells?(x.onOperationRejected?.("paste",G,"limit"),!0):!1};let q,H=null;if(h==="aqsp"){const B=iu(v,M);if(B===null)return p("unreadable");const U=n.current;if(U!==null&&B.clipId===U.clipId&&(H=U),H!==null&&H.kind==="cut"&&gh(D))return L(H,O);if(g(B.rows,B.cols))return"rejected";if(H!==null){if(H.kind==="cut"&&(H.range.endRow>=H.sourceAdapter.rowCount||H.range.endCol>=H.sourceAdapter.colCount))return x.onOperationRejected?.("paste",H.payload.rows*H.payload.cols,"bounds"),"rejected";q=Fl(H)}else{const G=cu(v,M);if(G===null)return p("unreadable");if(g(G.rows,G.cols))return"rejected";q=Rh(G)}}else if(h==="tsv"){const B=v.getData("text/plain"),U=Jf(B);if(g(U.rows,U.cols))return"rejected";q=vh(nc(B))}else{const B=v.getData("text/html"),U=$u(B);if(U.cols===0&&U.rows>x.maxOperationCells)return x.onOperationRejected?.("paste",U.rows,"limit"),"rejected";if(g(U.rows,U.cols))return"rejected";const G=Ui(B,h,x.formats===void 0?{}:{currency:x.formats.currency,locale:x.formats.locale},x.maxOperationCells);if(G.outcome==="none")return p("unreadable");if(G.outcome==="limit")return x.onOperationRejected?.("paste",G.cells,"limit"),"rejected";if(g(G.payload.rows,G.payload.cols))return"rejected";q=G.payload}const R=pr(N),E=xl(y?ah(q):q,R),u=kc[D.mode],d={row:0,col:0,readText:()=>ln(N,d.row,d.col).text,readFormat:()=>N.getCellFormat===void 0?void 0:N.getCellFormat(d.row,d.col)},{edits:P,tiles:S}=ll(E.cells,O,w.active,N.rowCount,N.colCount,(B,U,G)=>(d.row=U,d.col=G,Dl(B,E,d,D,R))),b=Eh(S,E.rows,E.cols,N.rowCount,N.colCount);if(b===null)return"empty";if(u.cf&&E.conditionalFormats.length>0){let B=0;for(const G of E.conditionalFormats)B+=G.ranges.length;const U=S.length*B;if(U>x.maxOperationCells)return x.onOperationRejected?.("paste",U,"limit"),"rejected"}const I=u.cf?Tl(E.conditionalFormats,S):[];if(P.length===0&&I.length===0)return A(E,b,u),"empty";r.current=H===null?"foreign":"own";let k=!1;try{k=f(P,{sameSheet:H!==null&&H.sourceAdapter===N,conditionalFormats:I})}finally{r.current="none"}if(!k)return"rejected";A(E,b,u);const z={row:b.startRow,col:b.startCol};return x.setSelection({ranges:[b],anchor:z,active:z}),"applied"},[L,f,A]),T=i.useCallback(async v=>{const M=y=>(t.current.onClipboardUnavailable?.(y),"rejected"),D=navigator;if(D.clipboard===void 0)return M("insecure-origin");let x;try{x=await D.clipboard.read({unsanitized:["text/html"]})}catch{return M("permission-denied")}if(x.length===0)return M("empty");const N=x[0],p=Array.from(N.types),h=new Map;try{for(const y of hh)p.includes(y)&&h.set(y,await(await N.getType(y)).text())}catch{return M("unreadable")}const w={types:p,getData:y=>{const g=h.get(y);if(g===void 0)throw new RangeError(`[spreadsheet] clipboard flavour ${y} was not materialised for the menu path`);return g}},O=t.current;return!O.enabled||O.isDragging()||O.isEditing()?"rejected":$(w,"menu",v)},[$]),{enabled:_,sinkRef:V}=e;return i.useEffect(()=>{const v=V.current;if(!_||v===null)return;const M=p=>t.current.isDragging()?(p.preventDefault(),!0):!1,D=p=>{const h=t.current;if(M(p)||h.isEditing())return;const w=m(p,"copy");w!==null&&c("copy",w.range,w.payload)},x=p=>{const h=t.current;if(M(p)||h.isEditing())return;const w=m(p,"cut");w!==null&&c("cut",w.range,w.payload)},N=p=>{const h=t.current;if(M(p)||h.isEditing())return;p.preventDefault();let w=kl;const O=h.pendingPasteOptionsRef;O!==void 0&&O.current!==null&&(w=O.current,O.current=null);const y=Ml(p);y!==null&&$(wh(y),"event",w)};return v.addEventListener("copy",D),v.addEventListener("cut",x),v.addEventListener("paste",N),()=>{v.removeEventListener("copy",D),v.removeEventListener("cut",x),v.removeEventListener("paste",N)}},[_,V,m,c,$]),i.useMemo(()=>({getClip:()=>{const v=n.current;return v===null?null:{kind:v.kind,range:v.range,foreign:v.sourceAdapter!==t.current.adapter}},discardClip:o,discardClipOnCommit:s,onAdapterSwitch:l,paste:T}),[o,s,l,T])},Ac=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)}`)},xc=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}},$l=(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}`}`},Oc=(e,t)=>{let n;if(e.exponent===null)n=$l(e.negative,e.digits,e.point+t);else{const r=$l(e.negative,e.digits,e.point);n=r==="0"?"0":`${r}e${e.exponent+t}`}return qe(n)===null?null:n},Ah=(e,t)=>{Ac(t);const n=qe(e);return n===null?null:Oc(xc(n),t)},xh=e=>{const t=qe(e);if(t!==null){const r=xc(t);return Oc({...r,negative:!r.negative},0)}const n=e.trim().toUpperCase();return n==="TRUE"?"FALSE":n==="FALSE"?"TRUE":null},Dc=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)},Oh=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},Tc=(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 Oh(r)?r:null},Dh=(e,t)=>{Ac(t);const n=Dc(e),r=Math.abs(t)===2?"100":"1000",o=t>0?"*":"/",s=t>0?"/":"*",l=Tc(n,"(",`)${s}${r}`);return l===null?`=(${n})${o}${r}`:`=${l}`},Th=e=>{const t=Dc(e),n=Tc(t,"-(",")");return n===null?`=-(${t})`:`=${n}`},yn=(e,t,n,r)=>{const o=wr(t);return o>n?(r?.(e,o,"limit"),!1):!0},er={Yellow:"#FFFF99",Blue:"#CCFFFF",Green:"#CCFFCC",Red:"#FFCCCC"},tr={Yellow:"#FFFF00",Blue:"#0000FF",Green:"#00FF00",Red:"#FF0000"},Nl={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:er.Yellow,custom:null},fillColorBlue:{kind:"color",key:"background",preset:er.Blue,custom:null},fillColorGreen:{kind:"color",key:"background",preset:er.Green,custom:null},fillColorRed:{kind:"color",key:"background",preset:er.Red,custom:null},fillColorCustom1:{kind:"color",key:"background",preset:null,custom:0},fillColorCustom2:{kind:"color",key:"background",preset:null,custom:1},fillColorCustom3:{kind:"color",key:"background",preset:null,custom:2},fillColorCustom4:{kind:"color",key:"background",preset:null,custom:3},fillColorCustom5:{kind:"color",key:"background",preset:null,custom:4},fontColorYellow:{kind:"color",key:"color",preset:tr.Yellow,custom:null},fontColorBlue:{kind:"color",key:"color",preset:tr.Blue,custom:null},fontColorGreen:{kind:"color",key:"color",preset:tr.Green,custom:null},fontColorRed:{kind:"color",key:"color",preset:tr.Red,custom:null},fontColorCustom1:{kind:"color",key:"color",preset:null,custom:0},fontColorCustom2:{kind:"color",key:"color",preset:null,custom:1},fontColorCustom3:{kind:"color",key:"color",preset:null,custom:2},fontColorCustom4:{kind:"color",key:"color",preset:null,custom:3},fontColorCustom5:{kind:"color",key:"color",preset:null,custom:4},toggleRowHighlight:{kind:"highlight",target:"row"},toggleColumnHighlight:{kind:"highlight",target:"column"},toggleBothHighlight:{kind:"highlight",target:"both"},toggleIntersectionHighlight:{kind:"highlight",target:"intersection"}},Mh={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},xn=e=>e<10?`0${e}`:String(e),Fh=e=>{const t=new Date(e);return`${t.getFullYear()}-${xn(t.getMonth()+1)}-${xn(t.getDate())}`},$h=e=>{const t=new Date(e);return`${xn(t.getHours())}:${xn(t.getMinutes())}:${xn(t.getSeconds())}`},Nh=(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),Lh=(e,t)=>({...(e&1)!==0?{top:t}:{},...(e&2)!==0?{right:t}:{},...(e&4)!==0?{bottom:t}:{},...(e&8)!==0?{left:t}:{}}),Ph=e=>e===void 0||e.borders===void 0?{}:e.borders,zh={top:1,right:2,bottom:4,left:8},qh={style:"thin",color:Lo},_h=(e,t)=>{if(e===void 0)return!1;const n=Fe(e);return n!==null&&n===Fe(t)},Ih=(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}}},Hh=e=>{const t=i.useRef(e);t.current=e;const n=i.useCallback(()=>{const p=t.current;if(p.isEditing()){const h=p.getActive();return[ue(h,h)]}return p.getSelection().ranges},[]),r=i.useCallback(()=>{const p=t.current,h=p.getActive();return p.adapter.getCellFormat===void 0?void 0:p.adapter.getCellFormat(h.row,h.col)},[]),o=i.useCallback(p=>{const h=t.current,w=n();if(!yn("format",w,h.maxOperationCells,h.onOperationRejected))return!1;const O=new Map,y=[],g=h.adapter.getCellFormat;for(const q of w)yt([q],H=>{const R=g===void 0?void 0:g(H.row,H.col),{bucket:E,patch:u}=p(H,q,R);let d=O.get(E);d===void 0&&(d=new Map,O.set(E,d));let P;d.has(R)?P=d.get(R):(P=zo(R,u),d.set(R,P)),P!==R&&y.push({row:H.row,col:H.col,format:P===void 0?null:P})});return y.length===0?!0:h.commitEdits(y,{source:"format"})===null?!1:(h.isEditing()&&h.refreshEditPaint(),!0)},[n]),s=i.useCallback(p=>o(()=>({bucket:0,patch:p})),[o]),l=i.useCallback((p,h)=>{const w=t.current;w.formatCommandAnnouncement!==void 0&&w.announce(w.formatCommandAnnouncement({command:p,state:h}))},[]),c=i.useCallback((p,h=qh)=>{if(p==="clear")return s({borders:null});if(p==="all")return s({borders:{top:h,right:h,bottom:h,left:h}});const w=p==="outer"?15:zh[p];return o((O,y,g)=>{const q=Nh(O,y)&w;return{bucket:q,patch:{borders:{...Ph(g),...Lh(q,h)}}}})},[s,o]),a=i.useCallback((p,h,w)=>{const O=Zi(t.current.adapter,p.row,p.col);for(const y of h)w.push(Ji(O,p,y))},[]),m=i.useCallback(p=>{const h=t.current,w=h.getSelection();if(!yn("fill",w.ranges,h.maxOperationCells,h.onOperationRejected))return!1;const O=[];if(p==="selection"){const y=w.active,g=[];yt(w.ranges,q=>{(q.row!==y.row||q.col!==y.col)&&g.push(q)}),a(y,g,O)}else for(const y of w.ranges)if(p==="down"){const g=y.startRow===y.endRow;if(g&&y.startRow===0)continue;const q=g?y.startRow-1:y.startRow;for(let H=y.startCol;H<=y.endCol;H+=1){const R=[];for(let E=g?y.startRow:y.startRow+1;E<=y.endRow;E+=1)R.push({row:E,col:H});a({row:q,col:H},R,O)}}else{const g=y.startCol===y.endCol;if(g&&y.startCol===0)continue;const q=g?y.startCol-1:y.startCol;for(let H=y.startRow;H<=y.endRow;H+=1){const R=[];for(let E=g?y.startCol:y.startCol+1;E<=y.endCol;E+=1)R.push({row:H,col:E});a({row:H,col:q},R,O)}}return O.length===0?!0:h.commitEdits(O,{source:"fill"})!==null},[a]),f=i.useCallback(p=>{const h=t.current,w=h.getSelection();if(!yn("calc",w.ranges,h.maxOperationCells,h.onOperationRejected))return!1;const O=[],y=h.adapter;return yt(w.ranges,g=>{const q=y.getCellFormula===void 0?void 0:y.getCellFormula(g.row,g.col),H=q===void 0?p.text(y.getCellText(g.row,g.col)):p.formula(q);H!==null&&O.push({row:g.row,col:g.col,text:H})}),O.length===0?!0:h.commitEdits(O,{source:"calc"})!==null},[]),A=i.useCallback((p,h)=>{const w=t.current,O=p==="row"?w.rowAxis:w.colAxis,y=w.getSelection(),g=p==="row"?Math.floor(w.maxOperationCells/$o):w.maxOperationCells;let q=0;for(const d of y.ranges)q+=p==="row"?d.endRow-d.startRow+1:d.endCol-d.startCol+1;if(q>g)return w.onOperationRejected?.("resize",q,"limit"),!1;const H=new Set,R=[],E=h?0:p==="row"?w.defaultRowHeight:w.defaultColumnWidth;for(const d of y.ranges){const P=p==="row"?d.startRow:d.startCol,S=p==="row"?d.endRow:d.endCol;for(let b=P;b<=S;b+=1){if(H.has(b))continue;H.add(b),O.sizeOf(b)===0!==h&&R.push({index:b,size:E})}}const u=No(O,R,null,{maxOperationCells:w.maxOperationCells,rowHiddenLimit:Fo,axisKind:p});return u.ok?(u.entries.length>0&&w.resizeTracks(p,u.entries),!0):(w.onOperationRejected?.("resize",u.count,u.reason),!1)},[]),L=i.useCallback(()=>{const p=t.current;if(p.adapter.getCellHyperlink===void 0)return;const h=p.getActive();return cn(p.adapter.getCellHyperlink(h.row,h.col))},[]),$=i.useCallback(p=>{const h=t.current,w=h.adapter,O=Nl[p],y=w.getCellFormat!==void 0,g=q=>h.popovers===void 0?!0:h.popovers[q]!==!1;switch(O.kind){case"toggle":case"patch":case"clear":case"borders":case"color":return y;case"value":return y&&(O.value!=="currency"||h.formats!==void 0);case"popover":switch(O.popover){case"link":return w.getCellHyperlink!==void 0&&g("link");case"note":return w.getCellNote!==void 0&&g("note");case"comment":return w.getCellComments!==void 0&&g("comment");default:return w.getCellValidation!==void 0&&g("list")}case"openHyperlink":return w.getCellHyperlink!==void 0&&(h.onHyperlinkOpen!==void 0?L()!==void 0:g("link"));case"paste":return O.options.mode==="formats"?y:O.options.mode==="formulas"?w.getCellFormula!==void 0:!0;default:return!0}},[L]),T=i.useCallback(p=>{const h=t.current;if(!$(p))return!1;const w=Nl[p],O=h.isEditing();if(O&&!Xo.has(p)&&!h.requestCommit())return!1;switch(w.kind){case"toggle":{const y=r(),g=y!==void 0&&y[w.key]===!0;return s({[w.key]:g?null:!0})?(l(p,!g),!0):!1}case"patch":return s(w.patch)?(l(p,null),!0):!1;case"clear":return s(Mh)?(l(p,null),!0):!1;case"value":return s({value:Ih(w.value,h.formats)})?(l(p,null),!0):!1;case"borders":return c(w.preset)?(l(p,null),!0):!1;case"color":{const y=w.key==="background"?h.colors.fill:h.colors.font,g=w.preset!==null?w.preset:w.custom!==null&&w.custom<y.length?y[w.custom]:void 0;if(g===void 0)return!1;const q=r(),H=_h(q===void 0?void 0:q[w.key],g);return s({[w.key]:H?null:g})?(l(p,!H),!0):!1}case"calc":return f({text:y=>Ah(y,w.exponent),formula:y=>Dh(y,w.exponent)});case"sign":return f({text:xh,formula:Th});case"fill":{if(O&&w.direction==="selection"){const y=h.getSessionText();if(y===null)return!1;const g=h.getSelection();if(!yn("fill",g.ranges,h.maxOperationCells,h.onOperationRejected))return!1;const q=[];let H=!1;return yt(g.ranges,R=>{if(!H){if(!h.validateCommit(R,y).ok){H=!0;return}q.push({row:R.row,col:R.col,text:y})}}),H||h.commitEdits(q,{source:"fill"})===null?!1:(h.cancelEdit(),!0)}return m(w.direction)}case"popover":return h.openPopover(w.popover),!0;case"openHyperlink":{if(h.onHyperlinkOpen!==void 0){const y=L();return y===void 0?!1:(h.onHyperlinkOpen(y,h.getActive()),!0)}return h.openPopover("link"),!0}case"pasteSpecial":return h.onPasteSpecialRequest!==void 0?(h.onPasteSpecialRequest({kind:"keyboard",cellRect:h.keyboardCellRect()}),!0):(h.paste({mode:"formats"}),!0);case"paste":return h.paste(w.options),!0;case"insertNow":{const y=w.unit==="date"?Fh(h.now()):$h(h.now());if(O)return h.insertAtCaret(y),!0;const g=h.getActive();return h.validateCommit(g,y).ok?h.commitEdits([{row:g.row,col:g.col,text:y}],{source:"edit",editSession:"discarded"})!==null:!1}case"hide":return A(w.axis,w.hide);default:{const y=h.getHighlight();switch(w.target){case"row":return h.setHighlight({...y,row:!y.row}),!0;case"column":return h.setHighlight({...y,column:!y.column}),!0;case"both":{const g=y.row&&y.column;return h.setHighlight({...y,row:!g,column:!g}),!0}default:return h.setHighlight({...y,intersection:!y.intersection}),!0}}}},[$,L,r,s,l,c,f,m,A]),_=i.useCallback(()=>{const p=t.current;return!(p.isEditing()&&!p.requestCommit())},[]),V=i.useCallback(p=>{const h=t.current;if(h.adapter.getCellHyperlink===void 0)throw new RangeError("[spreadsheet] setHyperlink requires the getCellHyperlink capability");const w=p===null?null:St(p);if(p!==null&&w===null)throw new RangeError(`[spreadsheet] setHyperlink received an unnormalisable url ${JSON.stringify(p)}`);if(!_())return!1;const O=h.getActive();return h.commitEdits([{row:O.row,col:O.col,hyperlink:w}],{source:"annotate"})!==null},[_]),v=i.useCallback(p=>{const h=t.current;if(h.adapter.getCellNote===void 0)throw new RangeError("[spreadsheet] setNote requires the getCellNote capability");if(!_())return!1;const w=h.getActive();return h.commitEdits([{row:w.row,col:w.col,note:p}],{source:"annotate"})!==null},[_]),M=i.useCallback(p=>{const h=t.current,w=h.adapter.getCellComments;if(w===void 0)throw new RangeError("[spreadsheet] addComment requires the getCellComments capability");if(!_())return!1;const O=h.getActive(),y=w(O.row,O.col),g=y===void 0?[p]:[...y,p];return h.commitEdits([{row:O.row,col:O.col,comments:g}],{source:"annotate"})!==null},[_]),D=i.useCallback(p=>{const h=t.current;if(h.adapter.getCellValidation===void 0)throw new RangeError("[spreadsheet] setValidation requires the getCellValidation capability");if(!_())return!1;const w=h.getSelection().ranges;if(!yn("annotate",w,h.maxOperationCells,h.onOperationRejected))return!1;const O=[];return yt(w,y=>{O.push({row:y.row,col:y.col,validation:p})}),h.commitEdits(O,{source:"annotate"})!==null},[_]),x=i.useCallback(p=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] applyFormat requires the getCellFormat capability");return s(p)},[s]),N=i.useCallback((p,h)=>{if(t.current.adapter.getCellFormat===void 0)throw new RangeError("[spreadsheet] setBorders requires the getCellFormat capability");return c(p,h)},[c]);return i.useMemo(()=>({executeCommand:T,applyFormat:x,setBorders:N,setHyperlink:V,setNote:v,addComment:M,setValidation:D,isCommandAvailable:$}),[T,x,N,V,v,M,D,$])},nr="data-aqsp-pointing",jh=(e,t)=>{const n=Ti(e,t);return n!==null&&"insertAt"in n},Bh=(e,t)=>{Object.assign(e.style,Object.fromEntries(t.map(n=>[n,""])))},Wh=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),a=i.useRef(null),m=i.useRef(lt),f=i.useCallback(()=>{const R=t.current,E=R.sinkRef.current;if(R.adapter.getCellFormula===void 0||n.current===null||!c.current||E===null)return null;const u=Ti(E.value,E.selectionStart);return u===null?null:{sink:E,target:u}},[]),A=i.useCallback(()=>{const R=t.current.sinkRef.current;if(R===null)return;const E=f()!==null;E!==R.hasAttribute(nr)&&(E?R.setAttribute(nr,""):R.removeAttribute(nr))},[f]),L=i.useCallback((R,E)=>{const u=t.current;if(u.resolveEditPaint===void 0)return;const d=u.resolveEditPaint(E),P=d===null?lt:d;P!==lt&&Object.assign(R.style,P.style),m.current=P,u.editPaintRef!==void 0&&(u.editPaintRef.current=P)},[]),$=i.useCallback(R=>{Bh(R,Object.keys(m.current.style)),m.current=lt;const E=t.current.editPaintRef;E!==void 0&&(E.current=lt)},[]),T=i.useCallback(R=>{const E=t.current,u=n.current;if(u===null)return!0;const d=()=>{n.current=null,a.current=null;const P=E.sinkRef.current;P!==null&&(P.style.removeProperty("text-align"),$(P),P.removeAttribute(nr)),o(!1)};if(R.commit){const P=E.sinkRef.current,S=P===null?"":P.value,b=ln(E.adapter,u.cell.row,u.cell.col).text.replace(/\r\n?/g,`
|
|
20
|
+
`),I=S===b,k={source:"edit",editSession:R.onReject==="keep"?"kept":"discarded"};if(!(I||(E.validateCommit===void 0||E.validateCommit(u.cell,S).ok)&&E.commitEdits([{row:u.cell.row,col:u.cell.col,text:S}],k)!==null))return R.onReject==="discard"&&(d(),E.rearmSink()),!1}return d(),R.rearm&&E.rearmSink(),!0},[$]),_=i.useCallback((R,E)=>{const u=t.current;if(u.isDragging()||n.current!==null)return;const d=u.sinkRef.current;if(d===null)return;u.discardClip();const P=u.getActive();if(u.ensureCellVisible(P),R==="edit"){const{text:b,isFormula:I}=ln(u.adapter,P.row,P.col);d.value=b;const k=E===void 0||I?b.length:Math.min(E,b.length);d.setSelectionRange(k,k)}else d.value="";const S=u.resolveEditAlign(P);S!==null&&(d.style.textAlign=S),L(d,P),c.current=!1,a.current=null,n.current={cell:P,mode:R},o(!0)},[L]),V=i.useCallback(()=>{T({rearm:!0,commit:!1})},[T]),v=i.useCallback(()=>{const R=t.current;if(n.current===null)return!0;const E=R.sinkRef.current;if(s.current&&E!==null){l.current=!0;try{E.blur()}finally{l.current=!1}return T({rearm:!1,commit:!0,onReject:"keep"})?(R.focusSink(),R.rearmSink(),!0):(R.focusSink(),!1)}return T({rearm:!0,commit:!0,onReject:"keep"})},[T]),M=i.useCallback(()=>f()!==null,[f]),D=i.useCallback(()=>t.current.adapter.getCellFormula===void 0||n.current===null?!1:(c.current=!c.current,A(),!0),[A]),x=i.useCallback(()=>{const R=f(),E=n.current;if(R===null||E===null)return null;if("insertAt"in R.target)return a.current=E.cell,{origin:E.cell,cursor:E.cell,axis:"cells"};const u=Di(R.sink.value,R.sink.selectionStart);if(u===null)return null;const d=u.token,P=a.current;switch(d.kind){case"cell":{const S={row:d.row,col:d.col};return a.current=S,{origin:S,cursor:S,axis:"cells"}}case"range":{const S=P!==null&&(P.row===d.start.row||P.row===d.end.row)&&(P.col===d.start.col||P.col===d.end.col)?{row:P.row,col:P.col}:{row:d.start.row,col:d.start.col};return a.current=S,{origin:S,cursor:{row:S.row===d.start.row?d.end.row:d.start.row,col:S.col===d.start.col?d.end.col:d.start.col},axis:"cells"}}case"column":{const S=P!==null&&(P.col===d.start.col||P.col===d.end.col)?P.col:d.start.col,b={row:E.cell.row,col:S};return a.current=b,{origin:b,cursor:{row:E.cell.row,col:S===d.start.col?d.end.col:d.start.col},axis:"columns"}}case"row":{const S=P!==null&&(P.row===d.start.row||P.row===d.end.row)?P.row:d.start.row,b={row:S,col:E.cell.col};return a.current=b,{origin:b,cursor:{row:S===d.start.row?d.end.row:d.start.row,col:E.cell.col},axis:"rows"}}}},[f]),N=i.useCallback((R,E)=>{const u=f();if(u===null)return;const d=pd(R,E),{sink:P}=u,[S,b]="replace"in u.target?u.target.replace:[u.target.insertAt,u.target.insertAt],I=P.value;P.value=`${I.slice(0,S)}${d}${I.slice(b)}`;const k=S+d.length;P.setSelectionRange(k,k),"row"in R&&(a.current={row:R.row,col:R.col}),A()},[f,A]),p=i.useCallback(()=>{const R=t.current.sinkRef.current;return R===null?null:{value:R.value,selectionStart:R.selectionStart,selectionEnd:R.selectionEnd}},[]),h=i.useCallback(R=>{const E=t.current.sinkRef.current;E!==null&&(E.value=R.value,E.setSelectionRange(R.selectionStart,R.selectionEnd),a.current=null,A())},[A]),w=i.useCallback(()=>{const R=t.current,E=R.sinkRef.current;if(R.adapter.getCellFormula===void 0||n.current===null||E===null)return!1;const u=kd(E.value,E.selectionStart);return u===null?!1:(E.value=u.text,E.setSelectionRange(u.caret,u.caret),A(),!0)},[A]),O=i.useCallback(R=>{const E=t.current.sinkRef.current;if(n.current===null||E===null)return;const u=E.selectionStart,d=E.selectionEnd;E.value=`${E.value.slice(0,u)}${R}${E.value.slice(d)}`;const P=u+R.length;E.setSelectionRange(P,P),a.current=null,A()},[A]),y=i.useCallback(()=>{const R=t.current.sinkRef.current;return n.current===null||R===null?null:R.value},[]),g=i.useCallback(()=>{const R=t.current,E=n.current,u=R.sinkRef.current;E===null||u===null||($(u),L(u,E.cell),R.repaintOverlay?.())},[$,L]),{enabled:q,sinkRef:H}=e;return i.useEffect(()=>{const R=H.current;if(!q||R===null)return;const E=()=>{s.current=!0},u=()=>{s.current=!1},d=b=>{const I=t.current;if(l.current||n.current===null)return;const k=I.rootRef.current,z=b.relatedTarget;k!==null&&z instanceof Node&&k.contains(z)||T({rearm:!1,commit:!0,onReject:"discard"})},P=()=>{const b=t.current;a.current=null,b.adapter.getCellFormula!==void 0&&n.current!==null&&!c.current&&jh(R.value,R.selectionStart)&&(c.current=!0),A()},S=()=>{n.current!==null&&A()};return R.addEventListener("compositionstart",E),R.addEventListener("compositionend",u),R.addEventListener("focusout",d),R.addEventListener("input",P),document.addEventListener("selectionchange",S),()=>{R.removeEventListener("compositionstart",E),R.removeEventListener("compositionend",u),R.removeEventListener("focusout",d),R.removeEventListener("input",P),document.removeEventListener("selectionchange",S)}},[q,H,T,A]),i.useMemo(()=>({isEditing:()=>n.current!==null,getEditingMode:()=>n.current?.mode??null,isFocusoutSuppressed:()=>l.current,requestCommit:v,cancelEdit:V,startEdit:_,getPointing:M,togglePointingArm:D,getReferenceCursor:x,insertReference:N,captureSink:p,restoreSink:h,cycleAnchorAtCaret:w,insertAtCaret:O,getSessionText:y,refreshPaint:g,editing:r}),[v,V,_,M,D,x,N,p,h,w,O,y,g,r])},Vh=(e,t,n)=>{const r=new Mn.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}},Kh=(e,t,n)=>{const{tree:r,initialHidden:o}=Vh(e,t,n);let s=o;const a={count:e,sizeOf:m=>r.get(m),offsetOf:m=>{const{cumulative:f,currentValue:A}=r.prefixSum(m);return f-A},indexAt:m=>{if(e===0||r.getTotal()===0)throw new RangeError("[spreadsheet] indexAt requires a non-empty axis with positive total size");const f=Math.floor(m),A=Math.min(Math.max(f,0),r.getTotal()-1);return r.findIndexAtOrAfter(A+.5).index},totalSize:()=>r.getTotal(),resize:(m,f)=>{if(!(Number.isFinite(f)&&f>=0))throw new RangeError(`[spreadsheet] resize requires a finite size >= 0, received ${f}`);const A=Math.round(f);r.get(m)===0!=(A===0)&&(s+=A===0?1:-1),r.update(m,A)},hiddenCount:()=>s};return{key:`${e}:${t}`,model:a}},kt=(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)},vr=(e,t,n)=>{if(t>n||e.count===0||e.totalSize()===0)return[];const r=[];let o=e.sizeOf(t)>0?t:kt(e,t,1);for(;o!==null&&o<=n;)r.push(o),o=kt(e,o,1);return r},Ll=(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=Kh(e,t,r)),o.current.model},nn=256,ao=256,Uh=2**32,Yh=4096,Mc=Object.freeze([]),Fc=["background","color","bold","italic","underline","strikethrough"],$c=(e,t)=>{if(!Array.isArray(e))throw new RangeError(`[spreadsheet] ${t} requires an array of conditional-format rules, received ${typeof e}`)},Et=(e,t,n)=>(e.size>=Yh&&e.clear(),e.set(t,n),n),Nc=e=>($c(e,"buildCfIndex"),{rules:e,buckets:new Map,columns:new Map}),Lc=(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},Xh=(e,t,n)=>{const r=Math.floor(t/nn),o=Math.floor(n/ao),s=r*65536+o,l=e.buckets.get(s);if(l!==void 0)return l;const c=r*nn,a=o*ao,m=[];for(const f of e.rules)Lc(f.ranges,c,c+nn-1,a,a+ao-1)&&m.push(f);return Et(e.buckets,s,m.length===0?Mc:m)},Gh=(e,t,n)=>{const r=Math.floor(t/nn),o=r*Uh+n,s=e.columns.get(o);if(s!==void 0)return s;const l=Xh(e,t,n),c=r*nn,a=[];for(const m of l)Lc(m.ranges,c,c+nn-1,n,n)&&a.push(m);return Et(e.columns,o,a.length===0?Mc:a)},Zh=(e,t)=>{for(const n of e)if(Ht(n,t))return!0;return!1},Go=()=>({extrema:new Map,formulas:new Map,numbers:new Map}),rr=(e,t)=>e<t?-1:e>t?1:0,Pl=(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}},zl=new WeakMap,Mo=e=>e===null?null:Number(e),Jh=e=>{const t=zl.get(e);if(t!==void 0)return t;const n=e.b,r={a:Mo(qe(e.a)),b:n===void 0?null:Mo(qe(n))};return zl.set(e,r),r},Pc=(e,t,n)=>{const r=`${t.row}\0${t.col}`,o=e.numbers.get(r);return o!==void 0?o:Et(e.numbers,r,Mo(qe(n())))},Qh=(e,t,n,r)=>{const o=e.op==="between"||e.op==="notBetween",s=Jh(e),l=Pc(r,t,n),c=o?s.b:null;if(l!==null&&s.a!==null&&(!o||c!==null))return Pl(e.op,rr(l,s.a),c===null?null:rr(l,c));const a=n(),m=e.b;return Pl(e.op,rr(a,e.a),m===void 0?null:rr(a,m))},em=(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}},uo=e=>{const t=Fe(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]},or=e=>e.toString(16).padStart(2,"0"),fo=(e,t,n)=>{const r=l=>Math.round(e[l]+(t[l]-e[l])*n),o=`#${or(r(0))}${or(r(1))}${or(r(2))}`,s=r(3);return s===255?o:`${o}${or(s)}`},po=(e,t,n)=>t===n?e<=t?0:1:Math.min(1,Math.max(0,(e-t)/(n-t))),tm=(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=uo(t.color),a=uo(r.color);const m=n===void 0?void 0:uo(n.color);if(!(Number.isFinite(e)&&Number.isFinite(s)&&Number.isFinite(l))||c===null||a===null||m===null)return null;if(s>l){const A=s;s=l,l=A;const L=c;c=a,a=L}if(n!==void 0&&m!==void 0){const A=n.value===void 0?(s+l)/2:n.value;if(s<A&&A<l)return e<=A?fo(c,m,po(e,s,A)):fo(m,a,po(e,A,l))}return fo(c,a,po(e,s,l))},nm=(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 Et(r.extrema,e.id,{min:s.value,max:l.value});if(n.getRangeExtrema===void 0)return null;let c=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const m of e.ranges){const f=n.getRangeExtrema(m);if(f===null)return Et(r.extrema,e.id,null);c=Math.min(c,f.min),a=Math.max(a,f.max)}return Et(r.extrema,e.id,{min:c,max:a})},rm=(e,t,n,r,o,s)=>{const l=Pc(s,n,r);if(l===null)return null;const c=nm(e,t,o,s);return c===null?null:tm(l,t.min,t.mid,t.max,c)},om=(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:Et(o.formulas,s,r.evaluateFormula(t.formula,n));return c===!0||typeof c=="number"&&Number.isFinite(c)&&c!==0},sm=(e,t,n,r,o)=>{const s=e.condition;switch(s.type){case"cellValue":return Qh(s,t,n,o)?e.style:null;case"text":return em(s,n())?e.style:null;case"empty":return n()===""?e.style:null;case"notEmpty":return n()!==""?e.style:null;case"colorScale":{const l=rm(e,s,t,n,r,o);return l===null?null:{...e.style,background:l}}case"customFormula":return om(e,s,t,r,o)?e.style:null;default:return null}},ql=(e,t)=>zo(e,t),lm=(e,t,n)=>{e[t]=n},im=(e,t)=>{let n=e;for(const r of Fc)e[r]===void 0&&t[r]!==void 0&&(n===e&&(n={...e}),lm(n,r,t[r]));return n},cm=e=>{let t="";for(const n of Fc){const r=e[n];t+=r===void 0?"":typeof r=="boolean"?r?"t":"f":`s${r.length}:${r}`,t+="\0"}return t},_l=new WeakMap,am=Object.freeze({}),um=e=>{const t=e===void 0?am:e,n=_l.get(t);if(n!==void 0)return n;const r={byStyle:new WeakMap,byKey:new Map};return _l.set(t,r),r},dm=(e,t,n)=>{const r=um(e);if(n){const c=r.byStyle.get(t);if(c!==void 0)return c;const a=ql(e,t);return a!==void 0&&r.byStyle.set(t,a),a}const o=cm(t),s=r.byKey.get(o);if(s!==void 0)return s;const l=ql(e,t);return l!==void 0&&Et(r.byKey,o,l),l},Zo=(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=Gh(t,r,o);if(c.length===0)return l;const a={row:r,col:o};let m=null,f=!0;for(const A of c){if(!Zh(A.ranges,a))continue;const L=sm(A,a,s,e,n);if(L!==null){if(L!==A.style&&(f=!1),m===null)m=L;else{const $=im(m,L);$!==m&&(f=!1,m=$)}if(A.stopIfTrue===!0)break}}return m===null?l:dm(l,m,f)},Il=new WeakMap,fm=e=>{$c(e,"widthRelevantRules");const t=Il.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 Il.set(e,r),r},pm=({row:e,col:t,text:n,renderCell:r,__onCellRender:o})=>{const s=i.useRef(!1);return i.useEffect(()=>{const l=s.current?"update":"mount";s.current=!0,o?.(`cell-${e}-${t}`,l,0,0,0,0)}),r?r({row:e,col:t,text:n}):n},hm=i.memo(pm),mm=Object.freeze({left:Object.freeze({justifyContent:En("left")}),center:Object.freeze({justifyContent:En("center")}),right:Object.freeze({justifyContent:En("right")})}),gm=4096,Hl=new WeakMap,sr=new Map,wm=(e,t)=>{if(e===null)return mm[t];let n=Hl.get(e);n===void 0&&(n={},Hl.set(e,n));const r=n[t];if(r!==void 0)return r;const o={...e.style,justifyContent:En(t)},s=JSON.stringify(o);let l=sr.get(s);return l===void 0&&(sr.size>=gm&&sr.clear(),l=Object.freeze(o),sr.set(s,l)),n[t]=l,l},Cm=Go(),bm=(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},ym=(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=fr(e,o,s),c={};let a=null,m;if(e.getCellFormat!==void 0){const f=Zo(e,r===null?null:r.indexRef.current,r===null?Cm:r.memoRef.current,o,s,l);m=f===void 0?void 0:f.value;const A=Yi(f,l),L=kt(n,s,1),$=kt(t,o,1),T=Wu(f,L===null?void 0:e.getCellFormat(o,L),$===null?void 0:e.getCellFormat($,s),n.offsetOf(s)===0,t.offsetOf(o)===0);T!==null&&Object.assign(c,T.attrs),c["data-aqsp-align"]=A,a=wm(T,A)}if(e.getCellNote!==void 0&&e.getCellNote(o,s)!==void 0&&(c["data-aqsp-note"]=""),e.getCellComments!==void 0){const f=e.getCellComments(o,s);f!==void 0&&f.length>0&&(c["data-aqsp-comment"]="")}if(e.getCellHyperlink!==void 0&&cn(e.getCellHyperlink(o,s))!==void 0&&(c["data-aqsp-link"]=""),e.getCellValidation!==void 0){const f=e.getCellValidation(o,s);f!==void 0&&jp(f,l())&&(c["data-aqsp-invalid"]="")}return{attrs:c,style:a,value:m}},vm=({adapter:e,rowAxis:t,colAxis:n,viewStore:r,handleRef:o,bodyRef:s,dataVersion:l,defaultColumnWidth:c,frozenColumns:a,frozenRows:m,renderCell:f,onScroll:A,onRangeChange:L,focusSink:$,isEditing:T,requestCommit:_,testId:V,__onCellRender:v,cfIndexRef:M,cfMemoRef:D,isPointing:x})=>{const N=i.useRef(null),p=s??N;if(M===void 0!=(D===void 0))throw new RangeError("[spreadsheet] cfIndexRef and cfMemoRef must be passed together");const h=i.useMemo(()=>M===void 0||D===void 0?null:{indexRef:M,memoRef:D},[M,D]),w=i.useCallback(()=>r.get().editVersion,[r]),O=i.useCallback(k=>r.subscribeCoalesced(k),[r]),g=i.useSyncExternalStore(O,w,w)+(l??0),q=i.useCallback(k=>t.sizeOf(k),[t]),H=i.useCallback(k=>n.sizeOf(k),[n]),R=i.useCallback((k,z)=>e.getCellText(k,z),[e]),E=i.useMemo(()=>({role:"grid","aria-rowcount":e.rowCount,"aria-colcount":e.colCount,"aria-multiselectable":!0}),[e.rowCount,e.colCount]),u=i.useMemo(()=>({enableKeyboardNavigation:!1,pointerDragInputs:["pen","touch"],resetOnGetItemHeightChange:!0,resetOnGetColWidthChange:!0,defaultColWidth:c}),[c]),d=i.useMemo(()=>({width:jt}),[]),P=i.useRef({row:-1,col:-1,value:void 0}),S=i.useCallback((k,z)=>{const B={role:"gridcell","aria-rowindex":k+1,"aria-colindex":z+1,"data-aqsp-cell":"","data-row":k,"data-col":z,className:"aqsp-cell"},U=ym(e,t,n,h,k,z),G=P.current;return G.row=k,G.col=z,G.value=U===null?void 0:U.value,U===null?B:U.style===null?{...B,...U.attrs}:{...B,...U.attrs,style:U.style}},[e,t,n,h]),b=i.useCallback(k=>({role:"row","aria-rowindex":k+1,"data-aqsp-row":k,"data-aqsp-cells":"",className:"aqsp-row"}),[]),I=i.useCallback((k,z,B)=>{let U=k;return f===void 0&&e.getCellFormat!==void 0&&(U=on(k,bm(P.current,z,B))),Y.jsx(hm,{row:z,col:B,text:U,renderCell:f,__onCellRender:v})},[g,f,v,e]);return Y.jsx("div",{ref:p,className:"aqsp-body","data-aqsp-body":"","data-testid":V?`${V}-body`:void 0,onPointerDownCapture:k=>{if(!(k.target instanceof Element&&k.target.closest("[data-aqsp-cells]")!==null)&&k.pointerType==="mouse"){if(k.button!==0){k.preventDefault();return}if(k.preventDefault(),x?.()===!0){k.stopPropagation(),$();return}if(T()&&!_()){k.stopPropagation(),$();return}$()}},children:Y.jsx(Mn.VirtualGrid,{ref:o,rowCount:e.rowCount,colCount:e.colCount,frozenLeadingCols:a,frozenLeadingRows:m,getRowHeight:q,getColWidth:H,getCell:R,getCellProps:S,getRowProps:b,contentProps:E,behaviorOptions:u,scrollBarOptions:d,callbackThrottleMs:0,onScroll:A,onRangeChange:L,testId:V,children:I})})},Rm=i.memo(vm),lr=6,Xt=3,Rr=(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:Xt});for(const s of t){const l=e.sizeOf(s),c=e.offsetOf(s)+l,a=kt(e,s,1);s<e.count-1&&(a===null||a>s+1)?(n.push({kind:"resize",index:s,start:c-lr,length:Xt}),r.push({kind:"unhide",index:s+1,start:c-Xt,length:Xt})):l>=2*lr?n.push({kind:"resize",index:s,start:c-lr,length:lr}):n.push({kind:"resize",index:s,start:c-Xt,length:Xt})}return[...n,...r]},km=({viewStore:e,colAxis:t,frozenCols:n,handleRef:r,bandRef:o,colTrackRef:s,windowOriginXRef:l,repaintColHeaders:c,selectionRanges:a,enableResizeUI:m})=>{const f=Mn.useWheelBridge(r),A=i.useCallback(g=>(o.current=g,f(g)),[o,f]),L=i.useCallback(()=>{const{colStart:g,colEnd:q,colVersion:H}=e.get();return`${g}:${q}:${H}`},[e]),$=i.useCallback(g=>e.subscribeCoalesced(g),[e]);i.useSyncExternalStore($,L,L);const{colStart:T,colEnd:_}=e.get(),V=t.count===0?0:t.offsetOf(Math.min(T,t.count-1));i.useLayoutEffect(()=>{l.current=V,c()},[V,l,c]);const v=g=>a.some(q=>g>=q.startCol&&g<=q.endCol),M=Math.min(Math.max(0,n),t.count),D=pc(t,M),x=M>0?vr(t,0,M-1):[],N=vr(t,Math.max(T,M),Math.min(_,Math.max(0,t.count-1))),p=[];for(const g of N)p.push(Y.jsx("div",{className:"aqsp-col-header-cell","data-col":g,"data-aqsp-in-selection":v(g)?"":void 0,style:{left:t.offsetOf(g)-V,width:t.sizeOf(g)},children:Cr(g)},g));const h=m?Rr(t,N):null,w=h===null?null:h.filter(g=>!(g.kind==="unhide"&&g.index<M&&D>0)),O=m&&M>0?Rr(t,x):null,y=Y.jsxs("div",{ref:s,className:"aqsp-col-header-track",children:[p,w?.map(g=>g.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":g.index,style:{left:g.start-V,width:g.length}},`r${g.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":g.index,style:{left:g.start-V,width:g.length}},`u${g.index}`))]});return Y.jsx("div",{ref:A,className:"aqsp-col-header","aria-hidden":"true","data-aqsp-col-header":"",children:M===0?y:Y.jsxs(Y.Fragment,{children:[x.map(g=>Y.jsx("div",{className:"aqsp-col-header-cell","data-col":g,"data-aqsp-frozen-header":"","data-aqsp-in-selection":v(g)?"":void 0,style:{left:t.offsetOf(g),width:t.sizeOf(g)},children:Cr(g)},g)),O?.map(g=>g.kind==="resize"?Y.jsx("div",{className:"aqsp-col-resize-strip","data-aqsp-col-resize":g.index,style:{left:g.start,width:g.length}},`fr${g.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":g.index,style:{left:g.start,width:g.length}},`fu${g.index}`)),Y.jsx("div",{className:"aqsp-col-header-scroll","data-aqsp-col-header-scroll":"",style:{left:D},children:y})]})})},Em=({viewStore:e,rowAxis:t,handleRef:n,bandRef:r,selectionRanges:o,rowTrackRef:s,windowOriginYRef:l,repaintHeaders:c,enableResizeUI:a,frozenRows:m})=>{const f=Mn.useWheelBridge(n),A=i.useCallback(g=>(r.current=g,f(g)),[r,f]),L=g=>o.some(q=>g>=q.startRow&&g<=q.endRow),$=i.useCallback(()=>{const{rowStart:g,rowEnd:q,rowGeomVersion:H}=e.get();return`${g}:${q}:${H}`},[e]),T=i.useCallback(g=>e.subscribeCoalesced(g),[e]);i.useSyncExternalStore(T,$,$);const{rowStart:_,rowEnd:V}=e.get(),v=t.count===0?0:t.offsetOf(Math.min(_,t.count-1));i.useLayoutEffect(()=>{l.current=v,c()},[v,l,c]);const M=Math.min(Math.max(0,m),t.count),D=hc(t,M),x=M>0?vr(t,0,M-1):[],N=vr(t,Math.max(_,M),Math.min(V,Math.max(0,t.count-1))),p=[];for(const g of N)p.push(Y.jsx("div",{className:"aqsp-row-header-cell","data-row":g,"data-aqsp-in-selection":L(g)?"":void 0,style:{top:t.offsetOf(g)-v,height:t.sizeOf(g)},children:g+1},g));const h=a?Rr(t,N):null,w=h===null?null:h.filter(g=>!(g.kind==="unhide"&&g.index<M&&D>0)),O=a&&M>0?Rr(t,x):null,y=Y.jsxs("div",{ref:s,className:"aqsp-row-header-track",children:[p,w?.map(g=>g.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":g.index,style:{top:g.start-v,height:g.length}},`r${g.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":g.index,style:{top:g.start-v,height:g.length}},`u${g.index}`))]});return Y.jsx("div",{ref:A,className:"aqsp-row-header","aria-hidden":"true","data-aqsp-row-header":"",style:{marginBottom:jt},children:M===0?y:Y.jsxs(Y.Fragment,{children:[x.map(g=>Y.jsx("div",{className:"aqsp-row-header-cell","data-row":g,"data-aqsp-frozen-row-header":"","data-aqsp-in-selection":L(g)?"":void 0,style:{top:t.offsetOf(g),height:t.sizeOf(g)},children:g+1},g)),O?.map(g=>g.kind==="resize"?Y.jsx("div",{className:"aqsp-row-resize-strip","data-aqsp-row-resize":g.index,style:{top:g.start,height:g.length}},`fr${g.index}`):Y.jsx("div",{className:"aqsp-unhide-marker","data-aqsp-unhide":g.index,style:{top:g.start,height:g.length}},`fu${g.index}`)),Y.jsx("div",{className:"aqsp-row-header-scroll","data-aqsp-row-header-scroll":"",style:{top:D},children:y})]})})},Sm=9,Am=4,xm=(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,a=`${o} ${s} ${l} ${c}`;return t.set(e,a),a},Om=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),a=i.useRef(null),m=i.useRef(""),f=i.useRef(null),A=i.useCallback(N=>s.current!==null?N.pointerId===s.current:N.pointerType==="mouse",[]),L=i.useCallback(()=>{const N=t.current;n.current=!1,r.current=null,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null),N.writeResizeGuide(null);const p=f.current;p!==null&&(window.removeEventListener("pointermove",p.move),window.removeEventListener("pointerup",p.up),f.current=null);const h=c.current;h!==null&&s.current!==null&&h.hasPointerCapture?.(s.current)&&h.releasePointerCapture(s.current),c.current=null,s.current=null,N.repaintOverlay()},[]),$=i.useCallback((N,p)=>{const h=t.current;return N==="col"?p.startRow===0&&p.endRow===h.rowAxis.count-1:p.startCol===0&&p.endCol===h.colAxis.count-1},[]),T=i.useCallback((N,p)=>{const h=t.current,w=h.getSelection().ranges.filter(H=>$(N,H));if(!w.some(H=>N==="col"?p>=H.startCol&&p<=H.endCol:p>=H.startRow&&p<=H.endRow))return[p];const y=w.reduce((H,R)=>H+(N==="col"?R.endCol-R.startCol+1:R.endRow-R.startRow+1),0),g=N==="row"?Math.floor(h.maxOperationCells/$o):h.maxOperationCells;if(y>g)return h.onOperationRejected?.("resize",y,"limit"),null;const q=new Set;for(const H of w){const R=N==="col"?H.startCol:H.startRow,E=N==="col"?H.endCol:H.endRow;for(let u=R;u<=E;u+=1)q.add(u)}return[...q]},[$]),_=i.useCallback((N,p,h)=>{const w=t.current,O=N==="col"?w.colAxis:w.rowAxis,y=No(O,p,h,{maxOperationCells:w.maxOperationCells,rowHiddenLimit:Fo,axisKind:N});if(!y.ok){w.onOperationRejected?.("resize",y.count,y.reason);return}w.resizeTracks(N,y.entries)},[]),V=i.useCallback((N,p)=>{if(p===N.initialSize)return;const h=N.kind==="unhide"?[N.index]:T(N.axis,N.index);h!==null&&_(N.axis,h.map(w=>({index:w,size:p})),N.index)},[T,_]),v=i.useCallback((N,p)=>{const h=t.current,w=T("col",p);if(w===null)return;const{rowStart:O,rowEnd:y}=h.viewStore.get(),g=Math.min(y,h.rowAxis.count-1),q=[];for(let B=O;B<=g;B+=1)h.rowAxis.sizeOf(B)>0&&q.push(B);if(q.length===0)return;const H=w.length*q.length,R=Math.floor(h.maxOperationCells/Am);if(H>R){h.onOperationRejected?.("resize",H,"limit");return}const E=document.createElement("canvas").getContext("2d");if(E===null)return;const u=getComputedStyle(N),d=`${u.fontStyle} ${u.fontWeight} ${u.fontSize} ${u.fontFamily}`,P=h.adapter.getConditionalFormats===void 0?null:fm(h.adapter.getConditionalFormats()),S=Go(),b=new WeakMap,I=new Map;for(const B of w){const U=P===null?null:Nc(P.filter(G=>G.ranges.some(J=>B>=J.startCol&&B<=J.endCol)));for(const G of q){const J=h.adapter.getCellText(G,B),Z=h.adapter.getCellFormat===void 0?void 0:Zo(h.adapter,U,S,G,B,()=>J),te=Z===void 0?d:xm(Z,b,u),Ie=on(J,Z===void 0?void 0:Z.value),fe=I.get(te);fe===void 0?I.set(te,[{col:B,text:Ie}]):fe.push({col:B,text:Ie})}}const k=new Map;for(const[B,U]of I){E.font=B;for(const G of U){const J=E.measureText(G.text).width,Z=k.get(G.col);(Z===void 0||J>Z)&&k.set(G.col,J)}}const z=[];for(const B of w){const U=k.get(B);U!==void 0&&U>0&&z.push({index:B,size:Math.ceil(U)+Sm})}z.length!==0&&_("col",z,p)},[T,_]),{enabled:M,colBandRef:D,rowBandRef:x}=e;return i.useEffect(()=>{const N=D.current,p=x.current;if(!M||N===null||p===null)return;const h=b=>b==="col"?"[data-aqsp-col-resize], [data-aqsp-unhide]":"[data-aqsp-row-resize], [data-aqsp-unhide]",w=(b,I)=>{if(!(I instanceof Element))return null;const k=I.closest(h(b));if(k===null)return null;const z=k.hasAttribute("data-aqsp-unhide"),B=Number(k.getAttribute(z?"data-aqsp-unhide":b==="col"?"data-aqsp-col-resize":"data-aqsp-row-resize"));return{kind:z?"unhide":"resize",index:B}},O=b=>{if(!(n.current&&A(b)))return;const I=r.current;if(I===null)return;const k=(I.axis==="col"?b.clientX-I.startClientX:b.clientY-I.startClientY)/t.current.zoomRef.current;o.current=Math.max(0,Math.round(I.initialSize+k)),a.current===null&&(a.current=requestAnimationFrame(()=>{a.current=null;const z=r.current;if(!n.current||z===null)return;const B=t.current,U=z.axis==="col"?B.colAxis:B.rowAxis;B.writeResizeGuide({axis:z.axis,position:U.offsetOf(z.index)+o.current})}))},y=()=>{const b=r.current,I=o.current;L(),b!==null&&V(b,I)},g=b=>{O(b),n.current&&A(b)&&(l.current&1)!==0&&(b.buttons&1)===0&&y()},q=b=>{b.button!==0||!(n.current&&A(b))||y()},H=(b,I)=>k=>{const z=t.current;if(m.current=k.pointerType,k.pointerType!=="mouse")return;if(k.button!==0){k.preventDefault();return}const B=w(b,k.target);if(B===null)return;if(k.stopPropagation(),k.preventDefault(),z.isPointing()){z.focusSink();return}if(z.isEditing()&&!z.requestCommit()){z.focusSink();return}z.focusSink();const U=b==="col"?z.colAxis:z.rowAxis;r.current={axis:b,kind:B.kind,index:B.index,initialSize:U.sizeOf(B.index),startClientX:k.clientX,startClientY:k.clientY},o.current=r.current.initialSize,l.current=k.buttons,n.current=!0,z.repaintOverlay(),s.current=k.pointerId,c.current=I;try{I.setPointerCapture(k.pointerId)}catch{s.current=null}const G=g,J=q;f.current={move:G,up:J},window.addEventListener("pointermove",G),window.addEventListener("pointerup",J),z.writeResizeGuide({axis:b,position:U.offsetOf(B.index)+o.current})},R=(b,I)=>k=>{const z=t.current;if(m.current!=="mouse")return;const B=I.getRootNode(),U=B instanceof ShadowRoot?B:I.ownerDocument,G=k.target instanceof Element&&k.target.closest(h(b))!==null?k.target:typeof U.elementFromPoint=="function"?U.elementFromPoint(k.clientX,k.clientY):null,J=w(b,G);if(J!==null){if(k.stopPropagation(),z.isEditing()){z.focusSink();return}if(J.kind==="unhide"){_(b,[{index:J.index,size:b==="col"?z.defaultColumnWidth:z.defaultRowHeight}],null);return}if(z.autofitEnabled){if(b==="row"){const Z=T("row",J.index);Z!==null&&_("row",Z.map(te=>({index:te,size:z.defaultRowHeight})),J.index);return}v(I,J.index)}}},E=b=>{!n.current||s.current===null||b.pointerId!==s.current||L()},u=H("col",N),d=H("row",p),P=R("col",N),S=R("row",p);return N.addEventListener("pointerdown",u,{capture:!0}),p.addEventListener("pointerdown",d,{capture:!0}),N.addEventListener("dblclick",P),p.addEventListener("dblclick",S),N.addEventListener("lostpointercapture",E),p.addEventListener("lostpointercapture",E),()=>{N.removeEventListener("pointerdown",u,{capture:!0}),p.removeEventListener("pointerdown",d,{capture:!0}),N.removeEventListener("dblclick",P),p.removeEventListener("dblclick",S),N.removeEventListener("lostpointercapture",E),p.removeEventListener("lostpointercapture",E),L()}},[M,D,x,A,L,V,_,T,v]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&L()},cancelDrag:L}),[L])},Jo=(e,t)=>e.startRow===t.startRow&&e.startCol===t.startCol&&e.endRow===t.endRow&&e.endCol===t.endCol,Dm=(e,t)=>e.ranges.length===t.ranges.length&&e.ranges.every((n,r)=>Jo(n,t.ranges[r]))&&ct(e.anchor,t.anchor)&&ct(e.active,t.active),Tm=(e,t)=>{const n=e.ranges[e.ranges.length-1];return Jo(n,t)?e:{...e,ranges:[...e.ranges.slice(0,-1),t]}},Tn=(e,t,n)=>n.extend?qt(e,t):n.append?{ranges:[...e.ranges,ue(t,t)],anchor:t,active:t}:e.ranges.length===1&&ct(e.anchor,t)&&ct(e.active,t)&&Jo(e.ranges[0],ue(t,t))?e:{ranges:[ue(t,t)],anchor:t,active:t},Mm=(e,t)=>({row:Math.min(Math.max(e.row,t.startRow),t.endRow),col:Math.min(Math.max(e.col,t.startCol),t.endCol)}),qt=(e,t)=>{const n=Tm(e,ue(e.anchor,t));return n.ranges.some(r=>Ht(r,n.active))?n:{...n,active:Mm(n.active,n.ranges[n.ranges.length-1])}},zc=(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(ue({row:c.startRow,col:c.startCol},{row:t.startRow-1,col:c.endCol})),t.endRow<c.endRow&&o.push(ue({row:t.endRow+1,col:c.startCol},{row:c.endRow,col:c.endCol}));const a=Math.max(c.startRow,t.startRow),m=Math.min(c.endRow,t.endRow);t.startCol>c.startCol&&o.push(ue({row:a,col:c.startCol},{row:m,col:t.startCol-1})),t.endCol<c.endCol&&o.push(ue({row:a,col:t.endCol+1},{row:m,col:c.endCol}))}if(!r)return e;if(o.length===0)return{ranges:[ue(n,n)],anchor:n,active:n};const s=o.findIndex(c=>Ht(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}},Fm=(e,t,n,r)=>{const o=e[t];if(r==="right"){if(n.col<o.endCol)return{rangeIndex:t,cell:{row:n.row,col:n.col+1}};if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:o.startCol}}}else if(r==="left"){if(n.col>o.startCol)return{rangeIndex:t,cell:{row:n.row,col:n.col-1}};if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:o.endCol}}}else if(r==="down"){if(n.row<o.endRow)return{rangeIndex:t,cell:{row:n.row+1,col:n.col}};if(n.col<o.endCol)return{rangeIndex:t,cell:{row:o.startRow,col:n.col+1}}}else{if(n.row>o.startRow)return{rangeIndex:t,cell:{row:n.row-1,col:n.col}};if(n.col>o.startCol)return{rangeIndex:t,cell:{row:o.endRow,col:n.col-1}}}if(r==="right"||r==="down"){const c=(t+1)%e.length,a=e[c];return{rangeIndex:c,cell:{row:a.startRow,col:a.startCol}}}const s=(t-1+e.length)%e.length,l=e[s];return{rangeIndex:s,cell:{row:l.endRow,col:l.endCol}}},qc=(e,t)=>{const n=e.ranges.findIndex(o=>Ht(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=Fm(e.ranges,r.rangeIndex,r.cell,t),!ct(r.cell,e.active))return{...e,active:r.cell};while(r.rangeIndex!==n);return e},st=24,jl=32,kr=4,Gt=({handleRef:e,rowAxis:t,colAxis:n,bodyRef:r,onDragFrame:o,axis:s="both",zoomRef:l})=>{const c=i.useRef(null),a=i.useRef(null),m=i.useRef(null),f=i.useRef(null),A=i.useCallback(()=>{c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),a.current=null,f.current=null,m.current=null},[]),L=i.useCallback(()=>{const T=a.current,_=e.current,V=f.current;if(T===null||_===null||V===null){c.current=null;return}const{clientX:v,clientY:M}=T.getPointerPosition(),D=l.current,x=(v-V.left)/D,N=(M-V.top)/D,p=_.getViewportSize(),h=p.width,w=p.height;if(h<=0||w<=0){c.current=requestAnimationFrame(L);return}const O=E=>Math.min(jl,Math.ceil(E/st*jl));let y=0,g=0;if(s!=="x"){const E=_.getFrozenSize();N>w-st?y=O(N-(w-st)):N<E.height+st&&(T.anchorRow!==void 0&&T.anchorRow<E.rows&&E.height>0&&N<E.height||(y=-O(E.height+st-N)))}if(s!=="y"){const E=_.getFrozenSize();x>h-st?g=O(x-(h-st)):x<E.width+st&&(T.anchorCol!==void 0&&T.anchorCol<E.cols&&E.width>0&&x<E.width||(g=-O(E.width+st-x)))}const q=g!==0||y!==0?_.scrollBy({x:g!==0?g:void 0,y:y!==0?y:void 0}):_.getScrollPosition(),H=q.y,R=q.x;if(H>=0&&R>=0&&t.totalSize()>0&&n.totalSize()>0){const E=_.getFrozenSize(),u=Ln({row:qn(t,N,H,E.height),col:zn(n,x,R,E.width)},t.count,n.count),d=m.current;(y!==0||g!==0||d===null||d.row!==u.row||d.col!==u.col)&&(m.current=u,o(T.buildRange(u)))}c.current=requestAnimationFrame(L)},[e,t,n,s,o]),$=i.useCallback(T=>{A(),a.current=T,f.current=r.current?.getBoundingClientRect()??null,c.current=requestAnimationFrame(L)},[A,L,r]);return i.useEffect(()=>{const T=()=>{document.visibilityState==="hidden"&&A()};return document.addEventListener("visibilitychange",T),()=>{document.removeEventListener("visibilitychange",T),A()}},[A]),i.useMemo(()=>({start:$,stop:A}),[$,A])},Bl=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),a=i.useRef(null),m=i.useRef(0),f=i.useRef(null),A=i.useRef(!1),L=i.useRef(0),$=i.useCallback((p,h)=>{const{axis:w,mainAxis:O,handleRef:y,zoomRef:g}=t.current,q=s.current;if(q===null||O.totalSize()===0)return null;const H=g.current;if(w==="col"){const u=y.current?.getScrollPosition().x??-1;if(u<0)return null;const d=y.current?.getFrozenSize().width??0;return Math.min(Math.max(zn(O,(p-q.left)/H,u,d),0),O.count-1)}const R=y.current?.getScrollPosition().y??-1;if(R<0)return null;const E=y.current?.getFrozenSize().height??0;return Math.min(Math.max(qn(O,(h-q.top)/H,R,E),0),O.count-1)},[]),T=i.useCallback((p,h)=>{const{axis:w,crossCount:O}=t.current;return w==="col"?{press:{row:0,col:p},extend:{row:O-1,col:h}}:{press:{row:p,col:0},extend:{row:h,col:O-1}}},[]),_=i.useCallback((p,h)=>{const{axis:w,crossCount:O}=t.current;return p.ranges.some(y=>w==="col"?y.startRow===0&&y.endRow===O-1&&h>=y.startCol&&h<=y.endCol:y.startCol===0&&y.endCol===O-1&&h>=y.startRow&&h<=y.endRow)},[]),V=i.useRef(!1),v=i.useRef({clientX:0,clientY:0}),M=i.useCallback(()=>{V.current=!1;const{autoScroller:p,headerRef:h,onDragFrame:w}=t.current;n.current=!1,r.current=null,f.current=null,A.current=!1,L.current=0,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),p.stop();const O=h.current;O!==null&&a.current!==null&&O.hasPointerCapture?.(a.current)&&O.releasePointerCapture(a.current),a.current=null,w(null),t.current.repaintOverlay()},[]),D=i.useCallback(()=>{if(!n.current)return;const p=r.current;p!==null&&t.current.setSelection(p),M()},[M]),{enabled:x,headerRef:N}=e;return i.useEffect(()=>{const p=N.current;if(!x||p===null)return;const h=R=>{const E=t.current;if(R.pointerType!=="mouse")return;if(R.button!==0){R.preventDefault();return}if(A.current=!1,E.pointing?.getPointing()){s.current=p.getBoundingClientRect();const S=$(R.clientX,R.clientY);if(S===null)return;R.preventDefault(),E.focusSink(),E.pointing.insertReference(E.axis==="col"?{row:0,col:S}:{row:S,col:0},E.axis==="col"?"columns":"rows");return}if(E.isEditing()&&!E.requestCommit()){R.preventDefault(),E.focusSink();return}s.current=p.getBoundingClientRect();const u=$(R.clientX,R.clientY);if(u===null)return;R.preventDefault(),E.focusSink();const d=E.getSelection();r.current=d;const P=R.ctrlKey||R.metaKey;if(R.shiftKey){const S=E.axis==="col"?{row:0,col:d.anchor.col}:{row:d.anchor.row,col:0},{extend:b}=T(u,u),I={...d,anchor:S};E.setSelection(qt(I,b)),o.current=E.axis==="col"?S.col:S.row}else if(P&&_(d,u))A.current=!0,L.current=u,o.current=u;else{const{press:S,extend:b}=T(u,u),I=Tn(d,S,{extend:!1,append:P});E.setSelection(qt(I,b)),o.current=u}n.current=!0,E.repaintOverlay(),l.current={clientX:R.clientX,clientY:R.clientY},a.current=R.pointerId,m.current=R.buttons;try{p.setPointerCapture(R.pointerId)}catch{a.current=null}f.current=S=>{const b=t.current.axis==="col"?S.col:S.row,{press:I}=T(o.current,o.current),{extend:k}=T(o.current,b);return ue(I,k)},E.autoScroller.stop(),V.current=!1,v.current={clientX:R.clientX,clientY:R.clientY}},w=R=>a.current!==null?R.pointerId===a.current:R.pointerType==="mouse",O=R=>{if(n.current&&w(R)){if(A.current){const E=R.clientX!==l.current.clientX||R.clientY!==l.current.clientY;if(l.current={clientX:R.clientX,clientY:R.clientY},!E)return;const u=$(R.clientX,R.clientY);if(u===null||u===L.current)return;A.current=!1;const d=t.current,{press:P,extend:S}=T(L.current,L.current),b=Tn(d.getSelection(),P,{extend:!1,append:!0});d.setSelection(qt(b,S));const I=f.current,k=Math.abs(R.clientX-v.current.clientX),z=Math.abs(R.clientY-v.current.clientY);I!==null&&Math.max(k,z)>=kr&&(V.current=!0,d.autoScroller.start({getPointerPosition:()=>l.current,buildRange:I,anchorCol:d.axis==="col"?o.current:void 0,anchorRow:d.axis==="row"?o.current:void 0}))}else if(l.current={clientX:R.clientX,clientY:R.clientY},!V.current&&f.current!==null){const E=Math.abs(R.clientX-v.current.clientX),u=Math.abs(R.clientY-v.current.clientY);Math.max(E,u)>=kr&&(V.current=!0,t.current.autoScroller.start({getPointerPosition:()=>l.current,buildRange:f.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 E=f.current;if(!n.current||E===null)return;const u=$(l.current.clientX,l.current.clientY);u!==null&&t.current.onDragFrame(E(t.current.axis==="col"?{row:0,col:u}:{row:u,col:0}))}))}},y=R=>{O(R),n.current&&w(R)&&(m.current&1)!==0&&(R.buttons&1)===0&&q(R)},g=R=>{R.button!==0||!(n.current&&w(R))||q(R)},q=R=>{const E=t.current;if(A.current){const{press:d,extend:P}=T(L.current,L.current);E.setSelection(zc(E.getSelection(),ue(d,P),d)),M();return}const u=$(R.clientX,R.clientY);if(u!==null){const{extend:d}=T(o.current,u);E.setSelection(qt(E.getSelection(),d))}M()},H=R=>{!n.current||a.current===null||R.pointerId!==a.current||D()};return p.addEventListener("pointerdown",h),p.addEventListener("pointermove",y),p.addEventListener("pointerup",g),p.addEventListener("lostpointercapture",H),()=>{p.removeEventListener("pointerdown",h),p.removeEventListener("pointermove",y),p.removeEventListener("pointerup",g),p.removeEventListener("lostpointercapture",H),M()}},[x,N,$,T,M,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:D,cancelDrag:M}),[D,M])},$m=({handleRef:e,rowAxis:t,colAxis:n})=>r=>{const o=e.current;if(o===null)return;const{x:s,y:l}=o.getScrollPosition(),{width:c,height:a}=o.getViewportSize();if(!(l<0||s<0)){if(a>0&&r.row>=o.getFrozenSize().rows){const m=o.getFrozenSize().height,f=t.offsetOf(r.row),A=f+t.sizeOf(r.row);f<m+l?o.scrollBy({y:f-(m+l)}):A>l+a&&o.scrollBy({y:A-(l+a)})}if(c>0){const m=o.getFrozenSize();if(r.col<m.cols)return;const f=n.offsetOf(r.col),A=f+n.sizeOf(r.col);f<m.width+s?o.scrollBy({x:f-(m.width+s)}):A>s+c&&o.scrollBy({x:A-(s+c)})}}},Nm=50,Lm=100,_c=(e,t)=>e.isComposing||e.keyCode===229?!0:(e.key==="Enter"||e.key==="Escape")&&t!==null?e.timeStamp-t<Nm:!1,vn={selectAll:zt("Ctrl+A"),undo:zt("Ctrl+Z"),redo:zt("Ctrl+Y"),redoShiftZ:zt("Ctrl+Shift+Z"),pasteValues:zt("Ctrl+Shift+V")},Pm=new Set(["Shift","Control","Alt","Meta","AltGraph"]),zm={ArrowRight:"right",ArrowLeft:"left",ArrowDown:"down",ArrowUp:"up"},qm=e=>!e.shiftKey||e.altKey||!(e.ctrlKey||e.metaKey)?!1:e.key==="PageUp"||e.key==="PageDown",_m=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:a,handleRef:m}=e;i.useEffect(()=>{const f=c.current,A=a.current;if(!l||f===null||A===null)return;const L=()=>{o.current&&(o.current=!1,s.current.onPointFrame?.(null))},$=(u,d,P)=>kt(u,d,P)??d,T=(u,d)=>{const P=s.current;return d==="left"||d==="right"?{row:u.row,col:$(P.colAxis,u.col,d==="right"?1:-1)}:{row:$(P.rowAxis,u.row,d==="down"?1:-1),col:u.col}},_=u=>u.indexAt(0),V=u=>u.indexAt(u.totalSize()-1),v=(u,d,P,S)=>{if(u.sizeOf(d)>0)return d;const b=kt(u,d,P);if(b!==null)return b;const I=kt(u,d,P===1?-1:1);return I!==null?I:S},M=()=>{const u=s.current.getSelection(),d=u.ranges[u.ranges.length-1];return{row:u.anchor.row===d.startRow?d.endRow:d.startRow,col:u.anchor.col===d.startCol?d.endCol:d.startCol}},D=u=>T(M(),u),x=(u,d)=>{const P=s.current,S=d==="left"||d==="right",b=d==="right"||d==="down"?1:-1;let I;return P.findDataEdge!==void 0?(I=P.findDataEdge({row:u.row,col:u.col},d),N(I,u,d)):I={row:d==="down"?P.rowAxis.count-1:d==="up"?0:u.row,col:d==="right"?P.colAxis.count-1:d==="left"?0:u.col},S?{row:I.row,col:v(P.colAxis,I.col,b,u.col)}:{row:v(P.rowAxis,I.row,b,u.row),col:I.col}},N=(u,d,P)=>{const S=s.current;if(!(Number.isInteger(u.row)&&Number.isInteger(u.col)&&u.row>=0&&u.row<S.rowAxis.count&&u.col>=0&&u.col<S.colAxis.count))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-grid coordinate {row: ${u.row}, col: ${u.col}} for a ${S.rowAxis.count} x ${S.colAxis.count} grid`);const b=P==="left"||P==="right";if(b?u.row!==d.row:u.col!==d.col)throw new RangeError(`[spreadsheet] findDataEdge must stay on the origin ${b?"row":"column"} (received {row: ${u.row}, col: ${u.col}} from {row: ${d.row}, col: ${d.col}})`)},p=(u,d,P)=>{if(!(Number.isInteger(u)&&u>=0&&u<d))throw new RangeError(`[spreadsheet] findDataEdge returned an out-of-axis ${P} component ${u} (count ${d})`)},h=u=>{const d=s.current,P=d.getSelection();if(qc(P,u)===P){d.moveActive({mode:"reset",cell:T(P.active,u)});return}d.moveActive({mode:"cycle",direction:u})},w=()=>{const u=c.current;if(u===null)return;const d=u.selectionStart??u.value.length,P=u.selectionEnd??d;u.value=`${u.value.slice(0,d)}
|
|
21
|
+
${u.value.slice(P)}`,u.setSelectionRange(d+1,d+1)},O=(u,d)=>{const P=s.current,S=m.current?.getViewportSize().height??-1;return S<=0?$(P.rowAxis,u,d==="down"?1:-1):P.rowAxis.indexAt(P.rowAxis.offsetOf(u)+(d==="down"?S:-S))},y=u=>{const d=s.current;if(r.current=!1,_c(u,t.current))return;const P=u.ctrlKey||u.metaKey,S=u.altKey,b=zm[u.key];if(o.current&&!Pm.has(u.key)&&!d.isDragging()&&L(),d.isEditing()){const k=d.getEditingMode();if(d.isDragging()){u.preventDefault(),u.key==="Escape"&&!P&&!u.shiftKey&&!S&&d.abortDrag();return}const z=d.pointing;if(z!==void 0){if(b!==void 0&&!S){const U=z.getReferenceCursor();if(U!==null){u.preventDefault();const G=P?x(U.cursor,b):T(U.cursor,b);if(d.ensureCellVisible(G),z.insertReference(u.shiftKey?ue(U.origin,G):G,U.axis),d.onPointFrame!==void 0){const J=u.shiftKey?ue(U.origin,G):ue(G,G);d.onPointFrame(U.axis==="columns"?ue({row:0,col:J.startCol},{row:d.rowAxis.count-1,col:J.endCol}):U.axis==="rows"?ue({row:J.startRow,col:0},{row:J.endRow,col:d.colAxis.count-1}):J),o.current=!0}return}}if(u.key==="F2"&&!P&&!u.shiftKey&&!S&&z.togglePointingArm()){u.preventDefault();return}if(u.key==="F4"&&!P&&!u.shiftKey&&!S&&z.cycleAnchorAtCaret()){u.preventDefault();return}}const B=d.commands;if(B!==void 0){const U=cl(B.table,u);if(U!==null&&Xo.has(U)&&B.isAvailable(U)){u.preventDefault(),B.execute(U);return}}if(b!==void 0&&!S){if(P&&u.shiftKey){u.preventDefault();return}if(P)return;if(k==="replace"){if(u.preventDefault(),!d.requestCommit())return;u.shiftKey?d.moveActive({mode:"extend",cell:D(b)}):d.moveActive({mode:"reset",cell:T(d.getSelection().active,b)});return}return}if(u.key==="Enter"&&S&&!P&&!u.shiftKey){u.preventDefault(),w();return}if((u.key==="Enter"||u.key==="Tab")&&!P&&!S){if(u.preventDefault(),!d.requestCommit())return;const U=!u.shiftKey;h(u.key==="Tab"?U?"right":"left":U?"down":"up");return}if((u.key==="PageUp"||u.key==="PageDown")&&!u.shiftKey&&!P&&!S){if(u.preventDefault(),!d.requestCommit())return;const U=d.getSelection().active;d.moveActive({mode:"reset",cell:{row:O(U.row,u.key==="PageDown"?"down":"up"),col:U.col}});return}if(u.key==="Escape"&&!P&&!u.shiftKey&&!S){u.preventDefault(),d.cancelEdit();return}return}if(u.defaultPrevented)return;if(d.isDragging()&&u.key!=="Escape"){u.preventDefault();return}const I=d.commands;if(I!==void 0){const k=cl(I.table,u);if(k!==null&&I.isAvailable(k)){u.preventDefault(),I.execute(k);return}}if(b!==void 0&&!S){const k=b==="left"||b==="right",z=b==="right"||b==="down"?1:-1;if(P&&u.shiftKey){u.preventDefault();const B=d.getSelection(),U=M();let G;if(d.findDataEdge!==void 0){const J=k?{row:B.active.row,col:U.col}:{row:U.row,col:B.active.col},Z=d.findDataEdge(J,b);G=k?Z.col:Z.row,p(G,k?d.colAxis.count:d.rowAxis.count,k?"col":"row"),G=v(k?d.colAxis:d.rowAxis,G,z,k?U.col:U.row)}else{const J=k?d.colAxis:d.rowAxis;G=z===1?V(J):_(J)}d.moveActive({mode:"extend",cell:k?{row:U.row,col:G}:{row:G,col:U.col}});return}if(P){u.preventDefault(),d.moveActive({mode:"reset",cell:x(d.getSelection().active,b)});return}if(u.shiftKey){u.preventDefault(),d.moveActive({mode:"extend",cell:D(b)});return}u.preventDefault(),d.moveActive({mode:"reset",cell:T(d.getSelection().active,b)});return}if(qm(u)){u.preventDefault();return}if((u.key==="Tab"||u.key==="Enter")&&!P&&!S){u.preventDefault();const k=!u.shiftKey;h(u.key==="Tab"?k?"right":"left":k?"down":"up");return}if(u.key==="Home"&&!S){if(u.preventDefault(),u.shiftKey){const z=M();d.moveActive({mode:"extend",cell:{row:P?_(d.rowAxis):z.row,col:_(d.colAxis)}});return}const k=d.getSelection().active;d.moveActive({mode:"reset",cell:{row:P?_(d.rowAxis):k.row,col:_(d.colAxis)}});return}if(u.key==="End"&&!S){if(u.preventDefault(),u.shiftKey){const z=M();d.moveActive({mode:"extend",cell:{row:P?V(d.rowAxis):z.row,col:V(d.colAxis)}});return}const k=d.getSelection().active;d.moveActive({mode:"reset",cell:{row:P?V(d.rowAxis):k.row,col:V(d.colAxis)}});return}if((u.key==="PageUp"||u.key==="PageDown")&&!P&&!S){u.preventDefault();const k=u.key==="PageDown"?"down":"up";if(u.shiftKey){const B=M();d.moveActive({mode:"extend",cell:{row:O(B.row,k),col:B.col}});return}const z=d.getSelection().active;d.moveActive({mode:"reset",cell:{row:O(z.row,k),col:z.col}});return}if(u.key==="F2"&&!P&&!u.shiftKey&&!S){u.preventDefault(),d.startEdit("edit");return}if((u.key==="Delete"||u.key==="Backspace")&&!P&&!u.shiftKey&&!S){u.preventDefault();const k=d.getSelection(),z=wr(k.ranges);if(z>d.maxOperationCells){d.onOperationRejected?.("delete",z,"limit");return}const B=[],U=d.adapter!==void 0&&pr(d.adapter).hyperlink;yt(k.ranges,G=>{B.push(U?{row:G.row,col:G.col,text:"",hyperlink:null}:{row:G.row,col:G.col,text:""})}),d.commitEdits(B,{source:"delete"});return}if(u.key==="Escape"){if(d.isDragging()){u.preventDefault(),d.abortDrag();return}if(P||u.shiftKey||S||(u.preventDefault(),d.hideNoteTip?.())||d.closeRejectedMessage?.())return;if(d.getClip()!==null){d.discardClip();return}d.handOffFocusToRoot();return}if(Cn(vn.selectAll,u)){u.preventDefault();const k=d.getSelection(),z=ue({row:0,col:0},{row:d.rowAxis.count-1,col:d.colAxis.count-1});d.setSelection({ranges:[z],anchor:k.anchor,active:k.active});return}if(Cn(vn.undo,u)){u.preventDefault(),d.onUndoRequest?.();return}if(Cn(vn.redo,u)||Cn(vn.redoShiftZ,u)){u.preventDefault(),d.onRedoRequest?.();return}if(u.key==="F10"&&u.shiftKey&&!P&&!S||u.key==="ContextMenu"&&!P&&!u.shiftKey&&!S){u.preventDefault();const k=d.getSelection().active;d.ensureCellVisible(k);const z=m.current,B=z?.getScrollPosition()??{x:0,y:0},U=Math.max(0,B.y),G=Math.max(0,B.x),J=d.zoomRef.current;d.onCellContextMenu?.(k,{kind:"keyboard",cellRect:{top:It(d.rowAxis,k.row,U,z?.getFrozenSize().rows??0)*J,left:_t(d.colAxis,k.col,G,z?.getFrozenSize().cols??0)*J,width:d.colAxis.sizeOf(k.col)*J,height:d.rowAxis.sizeOf(k.row)*J}});return}if(u.key===" "&&!S&&P!==u.shiftKey){u.preventDefault();const k=d.getSelection(),z=k.ranges.map(B=>P?ue({row:0,col:B.startCol},{row:d.rowAxis.count-1,col:B.endCol}):ue({row:B.startRow,col:0},{row:B.endRow,col:d.colAxis.count-1}));d.setSelection({ranges:z,anchor:k.anchor,active:k.active});return}if(d.pendingPasteOptionsRef!==void 0&&Cn(vn.pasteValues,u)){d.pendingPasteOptionsRef.current={mode:"values"};return}if(u.key.length===1&&!u.metaKey&&u.ctrlKey===u.altKey){if(u.ctrlKey&&u.altKey){r.current=!0;return}d.startEdit("replace");return}},g=()=>{const u=s.current;u.isEditing()||u.startEdit("replace")},q=u=>{t.current=u.timeStamp,n.current!==null&&window.clearTimeout(n.current),n.current=window.setTimeout(()=>{t.current=null,n.current=null},Lm)},H=()=>{const u=s.current;if(L(),!u.isEditing()){if(r.current){r.current=!1;const d=f.value;if(d!==""&&(u.startEdit("replace"),u.isEditing())){f.value=d,f.setSelectionRange(d.length,d.length);return}}u.rearmSink()}},R=()=>{r.current=!1;const u=s.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null)},E=()=>{r.current=!1;const u=s.current.pendingPasteOptionsRef;u!==void 0&&(u.current=null),L()};return f.addEventListener("keydown",y),f.addEventListener("keyup",R),f.addEventListener("blur",E),f.addEventListener("compositionstart",g),f.addEventListener("compositionend",q),f.addEventListener("input",H),()=>{f.removeEventListener("keydown",y),f.removeEventListener("keyup",R),f.removeEventListener("blur",E),f.removeEventListener("compositionstart",g),f.removeEventListener("compositionend",q),f.removeEventListener("input",H),n.current!==null&&window.clearTimeout(n.current),L()}},[l,c,a,m])},Im=4,Hm=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}),a=i.useRef(!1),m=i.useRef({dx:0,dy:0}),f=i.useRef(null),A=i.useRef(0),L=i.useRef(null),$=i.useRef(null),T=i.useRef(!1),_=i.useCallback(p=>f.current!==null?p.pointerId===f.current:p.pointerType==="mouse",[]),V=i.useCallback((p,h)=>{const{handleRef:w,rowAxis:O,colAxis:y}=t.current,g=w.current,q=s.current;if(g===null||q===null)return null;const{x:H,y:R}=g.getScrollPosition();if(R<0||H<0||O.totalSize()===0||y.totalSize()===0)return null;const E=t.current.zoomRef.current,u=g.getFrozenSize();return Ln({row:qn(O,(h-q.top)/E,R,u.height),col:zn(y,(p-q.left)/E,H,u.width)},O.count,y.count)},[]),v=i.useCallback(p=>{const h=r.current;if(h===null)return ue(p,p);const w=ue({row:Math.min(h.startRow,p.row),col:Math.min(h.startCol,p.col)},{row:Math.max(h.endRow,p.row),col:Math.max(h.endCol,p.col)}),O=w.startRow!==h.startRow||w.endRow!==h.endRow||w.startCol!==h.startCol||w.endCol!==h.endCol;return o.current=O?w:null,O?w:h},[]),M=i.useCallback(()=>{const p=t.current;n.current=!1,r.current=null,o.current=null,s.current=null,L.current!==null&&(cancelAnimationFrame(L.current),L.current=null),p.xAutoScroller.stop(),p.yAutoScroller.stop(),T.current=!1,a.current=!1,m.current={dx:0,dy:0},p.writeFillPreview(null);const h=$.current;h!==null&&(window.removeEventListener("pointermove",h.move),window.removeEventListener("pointerup",h.up),$.current=null);const w=t.current.handleNodeRef.current;w!==null&&f.current!==null&&w.hasPointerCapture?.(f.current)&&w.releasePointerCapture(f.current),f.current=null,p.repaintOverlay()},[]),D=i.useCallback(()=>{const p=t.current,h=r.current,w=o.current;if(M(),h===null||w===null)return;const O=Xf(h,w);if(O>p.maxOperationCells){p.onOperationRejected?.("fill",O,"limit");return}const y=Gf((q,H)=>Zi(p.adapter,q,H),h,w,Ji);if(p.commitEdits(y,{source:"fill"})===null)return;const g=p.getSelection();p.setSelection({ranges:[w],anchor:g.anchor,active:g.active})},[M]),{enabled:x,handleNodeRef:N}=e;return i.useEffect(()=>{const p=N.current;if(!x||p===null)return;const h=q=>{w(q),n.current&&_(q)&&(A.current&1)!==0&&(q.buttons&1)===0&&D()},w=q=>{if(!(n.current&&_(q)))return;l.current={clientX:q.clientX,clientY:q.clientY};const H=Math.abs(q.clientX-c.current.clientX),R=Math.abs(q.clientY-c.current.clientY);if(!a.current&&Math.max(H,R)>=Im&&(a.current=!0),!!a.current){if(!T.current){const E=t.current,u={getPointerPosition:()=>({clientX:l.current.clientX-m.current.dx,clientY:l.current.clientY-m.current.dy}),buildRange:v,anchorCol:r.current?.endCol,anchorRow:r.current?.endRow};E.xAutoScroller.start(u),E.yAutoScroller.start(u),T.current=!0}L.current===null&&(L.current=requestAnimationFrame(()=>{if(L.current=null,!(n.current&&a.current))return;const E=V(l.current.clientX-m.current.dx,l.current.clientY-m.current.dy);E!==null&&t.current.writeFillPreview(v(E))}))}},O=q=>{q.button!==0||!(n.current&&_(q))||D()},y=q=>{const H=t.current;if(q.pointerType!=="mouse")return;if(q.button!==0){q.preventDefault();return}q.preventDefault(),q.stopPropagation(),H.focusSink();const R=H.getSelection(),E=R.ranges[R.ranges.length-1];r.current=E,o.current=null,a.current=!1,H.xAutoScroller.stop(),H.yAutoScroller.stop(),T.current=!1,c.current={clientX:q.clientX,clientY:q.clientY},l.current=c.current,A.current=q.buttons,n.current=!0,H.repaintOverlay(),s.current=H.bodyRef.current?.getBoundingClientRect()??null;const u=s.current,d=H.handleRef.current?.getScrollPosition()??{x:-1,y:-1},P=d.y;if(u!==null&&P>=0&&d.x>=0){const I=d.x,k=H.zoomRef.current,z=H.handleRef.current?.getFrozenSize()??{cols:0,width:0,rows:0,height:0},B=_t(H.colAxis,E.endCol,I,z.cols)+H.colAxis.sizeOf(E.endCol),U=It(H.rowAxis,E.endRow,P,z.rows)+H.rowAxis.sizeOf(E.endRow),G=B-1,J=E.endCol>=z.cols&&z.width>0?Math.max(G,z.width):G,Z=U-1,te=E.endRow>=z.rows&&z.height>0?Math.max(Z,z.height):Z;m.current={dx:q.clientX-(u.left+J*k),dy:q.clientY-(u.top+te*k)}}else m.current={dx:0,dy:0};f.current=q.pointerId;try{p.setPointerCapture(q.pointerId)}catch{f.current=null}const S=h,b=O;$.current={move:S,up:b},window.addEventListener("pointermove",S),window.addEventListener("pointerup",b),H.writeFillPreview(r.current)},g=q=>{!n.current||f.current===null||q.pointerId!==f.current||M()};return p.addEventListener("pointerdown",y),p.addEventListener("lostpointercapture",g),()=>{p.removeEventListener("pointerdown",y),p.removeEventListener("lostpointercapture",g),M()}},[x,N,_,V,v,M,D]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"add",abortDrag:()=>{n.current&&M()},cancelDrag:M}),[M])},jm=320,hr=8,Bm=64,Wm=150,Ic=e=>Math.max(0,Math.min(jm,e.width-jt-hr)),Vm=(e,t,n)=>{const r=n.width-jt,o=n.height-jt,s=Ic(n),l=Math.max(0,Math.min(t,o-hr)),c=e.left+e.width,a=e.top+e.height,m=_=>_>=0&&_+s<=r,f=[e.left,c-s],A=[{left:e.left,top:a},{left:c-s,top:a},{left:e.left,top:e.top-l},{left:c-s,top:e.top-l}];for(const _ of A)if(m(_.left)&&_.top>=0&&_.top+l<=o)return{left:_.left,top:_.top,width:s,height:l};const L=o-a,$=e.top,T=Math.min(l,Math.max(L,$));if(T>=Bm){const _=L>=$?a:e.top-T;for(const V of f)if(m(V))return{left:V,top:_,width:s,height:T}}return{left:hr,top:hr,width:s,height:l}},Km=(e,t,n,r)=>t===null||e!==null&&ct(e,t)||n?!1:r(t),Um=(e,t)=>{switch(e.kind){case"note":return Y.jsx(vc,{ctx:e,labels:t});case"note-tip":return Y.jsx(Rc,{ctx:e,labels:t});case"comment":return Y.jsx(wc,{ctx:e,labels:t});case"link":return Y.jsx(Cc,{ctx:e,labels:t});case"list":return Y.jsx(bc,{ctx:e,labels:t});default:return Y.jsx(yc,{ctx:e,labels:t})}},ho=e=>e===null?null:`${e.kind}:${e.cell.row}:${e.cell.col}`,Ym=({controller:e,renderPopover:t,labels:n,interactiveAnchorRef:r,tipAnchorRef:o})=>{const{context:s,tipContext:l}=e,c=i.useRef(null),a=i.useRef(null),m=i.useRef(l);m.current=l;const f=i.useRef(e);f.current=e;const A=ho(s),L=ho(l),$=i.useRef(null),T=(D,x)=>{const N=f.current.getLayerSize();D.style.width=`${Ic(N)}px`,D.style.maxHeight="";const p=Vm(x,D.offsetHeight,N);D.style.left=`${p.left-x.left}px`,D.style.top=`${p.top-x.top}px`,D.style.maxHeight=`${p.height}px`};i.useLayoutEffect(()=>{const D=c.current;if(D===null||s===null){$.current=null;return}if(T(D,s.anchorRect),s.kind==="message")return;const x=ho(s);if($.current===x)return;$.current=x;const N=D.querySelector("[data-aqsp-popover-autofocus]");N!==null?N.focus({preventScroll:!0}):D.focus({preventScroll:!0})},[s]),i.useLayoutEffect(()=>{const D=a.current,x=m.current;D===null||x===null||T(D,x.anchorRect)},[L]);const _=D=>t===void 0?Um(D,n):t(D),V=D=>{e.isCompositionKey(D.nativeEvent)&&D.stopPropagation()},v=D=>{D.key==="Escape"&&!D.defaultPrevented&&(D.preventDefault(),e.close())},M=D=>{e.registerCompositionEnd(D.timeStamp)};return Y.jsxs("div",{className:"aqsp-popover-layer","data-aqsp-popover-layer":"",onKeyDownCapture:V,onKeyDown:v,onCompositionEnd:M,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)},A)}),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:a,id:e.tipId,className:"aqsp-popover","data-aqsp-popover-frame":"note-tip",children:_(l)})})]})},Xm=["note","note-tip","comment","link","list","message"],Gm=(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}},Rn=(e,t,n)=>(t===void 0?!0:t[n]!==!1)&&Gm(e,n),Zm=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),a=i.useRef(null),m=i.useRef(!1),f=i.useRef(null),A=i.useRef(null),L=i.useRef(null),$=i.useRef(null),T=i.useId(),_=i.useCallback(b=>{const I=t.current,k=I.handleRef.current,z=k===null?{x:0,y:0}:k.getScrollPosition(),B=k===null?{rows:0,cols:0}:k.getFrozenSize();return{top:It(I.rowAxis,b.row,Math.max(0,z.y),B.rows),left:_t(I.colAxis,b.col,Math.max(0,z.x),B.cols),width:I.colAxis.sizeOf(b.col),height:I.rowAxis.sizeOf(b.row)}},[]),V=i.useCallback(b=>{const I=t.current;I.anchors.current={...I.anchors.current,...b},I.repaintOverlay()},[]),v=i.useCallback(()=>{f.current!==null&&(window.clearTimeout(f.current),f.current=null)},[]),M=i.useCallback(()=>{const b=t.current.sinkRef.current;if(b===null)return;const I=c.current;I!==null&&ct(I,t.current.getActive())?b.setAttribute("aria-describedby",T):b.getAttribute("aria-describedby")===T&&b.removeAttribute("aria-describedby")},[T]),D=i.useCallback(()=>(v(),m.current=!1,c.current===null?!1:(c.current=null,s(null),V({tip:null}),M(),!0)),[v,V,M]),x=i.useCallback(()=>{v(),f.current=window.setTimeout(()=>{f.current=null,D()},Wm)},[v,D]),N=i.useCallback(b=>{const I=t.current;v();const k=I.adapter.getCellNote===void 0?void 0:I.adapter.getCellNote(b.row,b.col);k===void 0||k===""||(c.current=b,s({kind:"note-tip",cell:b,anchorRect:_(b),current:k,close:D}),V({tip:b}),M())},[_,v,D,V,M]),p=i.useCallback(b=>{const I=t.current;if(b===null&&m.current)return;const k=a.current;a.current=b;const z=c.current;if(z!==null&&b!==null&&ct(z,b)){v();return}const B=U=>{const G=I.adapter.getCellNote===void 0?void 0:I.adapter.getCellNote(U.row,U.col);return G!==void 0&&G!==""};if(Km(k,b,I.isDraggingAny(),B)){b!==null&&N(b);return}z!==null&&x()},[N,v,x]),h=i.useCallback((b,I)=>{const k=t.current,z=k.bodyRef.current,B=k.handleRef.current;if(z===null||B===null)return null;const U=z.getBoundingClientRect(),G=k.zoomRef.current,J=B.getScrollPosition(),Z=B.getFrozenSize();return Ln({row:qn(k.rowAxis,(I-U.top)/G,Math.max(0,J.y),Z.height),col:zn(k.colAxis,(b-U.left)/G,Math.max(0,J.x),Z.width)},k.rowAxis.count,k.colAxis.count)},[]),w=i.useCallback(b=>{L.current=b,A.current===null&&(A.current=requestAnimationFrame(()=>{A.current=null;const I=L.current;p(I===null?null:"cell"in I?I.cell:h(I.clientX,I.clientY))}))},[p,h]),O=i.useCallback(b=>w({cell:b}),[w]),y=i.useCallback(()=>D(),[D]),g=i.useCallback(()=>{if(l.current===null)return;const b=t.current;l.current=null,r(null),V({interactive:null}),b.focusSink({preventScroll:!0}),b.isEditing()||b.rearmSink()},[V]),q=i.useCallback(b=>{l.current=b.kind,r(b),V({interactive:b.cell})},[V]),H=i.useCallback((b,I)=>{if(t.current.commitEdits(I,{source:"annotate"})===null){q({...b,rejected:!0});return}g()},[q,g]),R=i.useCallback((b,I)=>{const k=t.current;if(!Rn(k.adapter,k.popovers,b))throw new RangeError(`[spreadsheet] openPopover("${b}") is unavailable: the kind is disabled by the popovers prop or its adapter capability is undeclared`);const z=k.getActive();if(b==="note-tip"){N(z);return}if(b==="message"){if(l.current!==null&&l.current!=="message")return;const J=I!==void 0&&I.message!==void 0?I.message:void 0,Z=k.adapter.getCellValidation===void 0?void 0:k.adapter.getCellValidation(z.row,z.col),te=J!==void 0?J:Z===void 0?void 0:Z.inputMessage;if(te===void 0)return;const Ie=I!==void 0&&I.rejected===!0;q({kind:"message",cell:z,anchorRect:_(z),current:{title:Re(k.labels,"messageTitle"),message:te,rejected:Ie},close:g});return}if(k.isEditing()&&!k.requestCommit())return;if(b==="list"){const J=k.adapter.getCellValidation===void 0?void 0:k.adapter.getCellValidation(z.row,z.col);if(J===void 0||J.type!=="list")return;const Z=I!==void 0&&I.typed!==void 0?I.typed:"";D(),k.focusSink({preventScroll:!0}),q({kind:"list",cell:z,anchorRect:_(z),current:J.values,typed:Z,commit:te=>{t.current.commitEdits([{row:z.row,col:z.col,text:te}],{source:"edit",editSession:"discarded"}),g()},close:g});return}if(D(),k.focusSink({preventScroll:!0}),b==="note"){const J=k.adapter.getCellNote===void 0?void 0:k.adapter.getCellNote(z.row,z.col),Z={kind:"note",cell:z,anchorRect:_(z),current:J,commit:te=>{H(Z,[{row:z.row,col:z.col,note:te}])},close:g,rejected:!1};q(Z);return}if(b==="comment"){const J=k.adapter.getCellComments===void 0?void 0:k.adapter.getCellComments(z.row,z.col),Z={kind:"comment",cell:z,anchorRect:_(z),current:J===void 0?[]:J,commit:te=>{H(Z,[{row:z.row,col:z.col,comments:te}])},close:g,rejected:!1};q(Z);return}const B=k.adapter.getCellHyperlink===void 0?void 0:cn(k.adapter.getCellHyperlink(z.row,z.col)),U=k.adapter.getCellText(z.row,z.col),G={kind:"link",cell:z,anchorRect:_(z),current:{text:U,url:B},commit:J=>{const Z=J.url===null?null:St(J.url);if(Z===null&&J.url!==null)throw new RangeError(`[spreadsheet] link commit received an unnormalisable url ${JSON.stringify(J.url)}`);const te=J.text===U?{row:z.row,col:z.col,hyperlink:Z}:{row:z.row,col:z.col,text:J.text,hyperlink:Z};H(G,[te])},close:g,canOpen:k.onHyperlinkOpen!==void 0,open:()=>{const J=t.current.onHyperlinkOpen;J!==void 0&&B!==void 0&&J(B,z)},rejected:!1};q(G)},[_,g,H,D,q,N]),{enabled:E,bodyRef:u}=e;i.useEffect(()=>{const b=u.current;if(!E||b===null)return;const I=z=>{const B=t.current;Rn(B.adapter,B.popovers,"note-tip")&&w({clientX:z.clientX,clientY:z.clientY})},k=()=>{Rn(t.current.adapter,t.current.popovers,"note-tip")&&w({cell:null})};return b.addEventListener("pointermove",I),b.addEventListener("pointerleave",k),()=>{b.removeEventListener("pointermove",I),b.removeEventListener("pointerleave",k)}},[E,u,w]),i.useEffect(()=>()=>{A.current!==null&&cancelAnimationFrame(A.current),f.current!==null&&window.clearTimeout(f.current)},[]);const{adapter:d,popovers:P}=e,S=i.useMemo(()=>Xm.some(b=>Rn(d,P,b)),[d,P]);return i.useMemo(()=>({layerEnabled:S,isKindEnabled:b=>Rn(t.current.adapter,t.current.popovers,b),open:R,close:g,isOpen:()=>l.current,onCellHover:O,hideTip:y,onTipPointerEnter:()=>{m.current=!0,v()},onTipPointerLeave:()=>{m.current=!1,c.current!==null&&x()},syncTipAriaDescribedBy:M,context:n,tipContext:o,registerCompositionEnd:b=>{$.current=b},isCompositionKey:b=>_c(b,$.current),getLayerSize:()=>{const b=t.current.handleRef.current;return b===null?{width:0,height:0}:b.getViewportSize()},tipId:T}),[S,R,g,O,y,v,x,M,n,o,T])},Jm=(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},Hc=(e,t,n,r,o,s,l)=>{if(e===null||t===null)return null;const{x:c,y:a}=e.getScrollPosition();if(a<0||c<0||n.totalSize()===0||r.totalSize()===0)return null;const m=e.getFrozenSize();return Ln({row:qn(n,(l-t.top)/o,a,m.height),col:zn(r,(s-t.left)/o,c,m.width)},n.count,r.count)},Qm=e=>{const t=i.useRef(e);t.current=e;const n=i.useRef(!1),r=i.useRef(null),o=i.useRef(null),s=i.useRef({clientX:0,clientY:0}),l=i.useRef(null),c=i.useRef(null),a=i.useRef(0),m=i.useRef(null),f=i.useRef(!1),A=i.useRef(null),L=i.useRef(""),$=i.useRef(!1),T=i.useRef(!1),_=i.useCallback((w,O)=>{const{handleRef:y,rowAxis:g,colAxis:q,zoomRef:H}=t.current;return Hc(y.current,o.current,g,q,H.current,w,O)},[]),V=i.useRef(!1),v=i.useRef(null),M=i.useRef(null),D=i.useRef({clientX:0,clientY:0}),x=i.useCallback(()=>{const{autoScroller:w,bodyRef:O,onDragFrame:y}=t.current;n.current=!1,r.current=null,m.current=null,V.current=!1,v.current=null,M.current=null,f.current=!1,A.current=null,l.current!==null&&(cancelAnimationFrame(l.current),l.current=null),w.stop();const g=O.current;g!==null&&c.current!==null&&g.hasPointerCapture?.(c.current)&&g.releasePointerCapture(c.current),c.current=null,y(null),t.current.repaintOverlay()},[]),N=i.useCallback(()=>{if(!n.current)return;const w=r.current;w!==null&&t.current.setSelection(w),x()},[x]),{enabled:p,bodyRef:h}=e;return i.useEffect(()=>{const w=h.current;if(!p||w===null)return;const O=S=>S instanceof Element&&S.closest("[data-aqsp-cells]")!==null,y=S=>{const b=t.current;if(S.pointerType==="mouse"&&S.button===0&&(f.current=!1,A.current=null,T.current=!1),$.current=O(S.target),!$.current){if(S.pointerType==="mouse"){if(S.preventDefault(),S.button!==0)return;if(b.getPointing?.()){b.focusSink();return}if(b.isEditing()&&!b.requestCommit()){S.stopPropagation(),b.focusSink();return}b.focusSink()}return}if(L.current=S.pointerType,S.pointerType!=="mouse")return;if(S.button!==0){S.preventDefault();return}if((b.pointDragRef===void 0?null:b.pointDragRef.current)?.onPointerDown(S))return;if(b.isEditing()&&!b.requestCommit()){S.preventDefault(),b.focusSink();return}o.current=w.getBoundingClientRect();const k=_(S.clientX,S.clientY);if(k===null)return;if(S.preventDefault(),b.focusSink(),(S.ctrlKey||S.metaKey)&&!S.shiftKey&&b.openHyperlinkAt?.(k)===!0){T.current=!0;return}const z=b.getSelection();r.current=z;const B=S.shiftKey,U=S.ctrlKey||S.metaKey,G=U&&!B&&z.ranges.some(Z=>Ht(Z,k));f.current=G,A.current=G?k:null,G||b.setSelection(Tn(z,k,{extend:B,append:U})),n.current=!0,b.repaintOverlay(),s.current={clientX:S.clientX,clientY:S.clientY},c.current=S.pointerId,a.current=S.buttons;try{w.setPointerCapture(S.pointerId)}catch{c.current=null}const J=G?k:b.getSelection().anchor;m.current=Z=>ue(J,Z),v.current=J.col,M.current=J.row,b.autoScroller.stop(),V.current=!1,D.current={clientX:S.clientX,clientY:S.clientY}},g=S=>c.current!==null?S.pointerId===c.current:S.pointerType==="mouse",q=S=>{if(n.current&&g(S)){if(s.current={clientX:S.clientX,clientY:S.clientY},!V.current&&m.current!==null){const b=Math.abs(S.clientX-D.current.clientX),I=Math.abs(S.clientY-D.current.clientY);Math.max(b,I)>=kr&&(V.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:m.current,anchorCol:v.current??void 0,anchorRow:M.current??void 0}))}l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const b=m.current;if(!n.current||b===null)return;const I=t.current,k=_(s.current.clientX,s.current.clientY);k!==null&&I.onDragFrame(b(k))}))}},H=S=>{q(S),n.current&&g(S)&&(a.current&1)!==0&&(S.buttons&1)===0&&E(S)},R=S=>{S.button!==0||!(n.current&&g(S))||E(S)},E=S=>{const b=t.current,I=_(S.clientX,S.clientY);if(I!==null){const k=A.current;f.current&&k!==null?b.setSelection(zc(b.getSelection(),ue(k,I),k)):b.setSelection(qt(b.getSelection(),I))}x()},u=S=>{!n.current||c.current===null||S.pointerId!==c.current||N()},d=S=>{const b=t.current;if(!O(S.target)||L.current!=="mouse"||b.isAnyDragging())return;if(b.isEditing()&&!b.requestCommit()){b.focusSink();return}b.focusSink(),o.current=w.getBoundingClientRect();const I=_(S.clientX,S.clientY);if(I===null)return;const k=b.getSelection();k.ranges.some(B=>Ht(B,I))||b.setSelection(Tn(k,I,{extend:!1,append:!1})),b.onContextMenuSelect(I,S)},P=S=>{const b=t.current;if(!$.current||L.current!=="mouse"||b.getPointing?.()||T.current)return;o.current=w.getBoundingClientRect();const I=_(S.clientX,S.clientY);I!==null&&ct(b.getSelection().active,I)&&b.onRequestEdit(I,b.caretFromPointEnabled(I)?Jm(S.clientX,S.clientY,I):void 0)};return w.addEventListener("pointerdown",y),w.addEventListener("pointermove",H),w.addEventListener("pointerup",R),w.addEventListener("lostpointercapture",u),w.addEventListener("contextmenu",d),w.addEventListener("dblclick",P),()=>{w.removeEventListener("pointerdown",y),w.removeEventListener("pointermove",H),w.removeEventListener("pointerup",R),w.removeEventListener("lostpointercapture",u),w.removeEventListener("contextmenu",d),w.removeEventListener("dblclick",P),x()}},[p,h,_,x,N]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>f.current?"subtract":"add",abortDrag:N,cancelDrag:x}),[N,x])},eg=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),a=i.useRef(null),m=i.useRef(0),f=i.useRef(null),A=i.useRef(null),L=i.useRef(!1),$=i.useCallback((D,x)=>{const{handleRef:N,rowAxis:p,colAxis:h,zoomRef:w}=t.current;return Hc(N.current,o.current,p,h,w.current,D,x)},[]),T=i.useCallback(()=>{const{autoScroller:D,bodyRef:x,onDragFrame:N}=t.current;n.current=!1,r.current=null,f.current=null,A.current=null,L.current=!1,o.current=null,c.current!==null&&(cancelAnimationFrame(c.current),c.current=null),D.stop();const p=x.current;p!==null&&a.current!==null&&p.hasPointerCapture?.(a.current)&&p.releasePointerCapture(a.current),a.current=null,N(null)},[]),_=i.useCallback(()=>{if(!n.current)return;const D=r.current;D!==null&&t.current.restoreSink(D),T()},[T]),V=i.useCallback(D=>{const x=t.current,N=x.bodyRef.current;if(!x.enabled||N===null||!x.getPointing())return!1;o.current=N.getBoundingClientRect();const p=$(D.clientX,D.clientY);if(p===null)return o.current=null,!1;const h=x.captureSink();if(h===null)return o.current=null,!1;D.preventDefault(),x.focusSink(),r.current=h,A.current=p,x.insertReference(p,"cells"),n.current=!0,s.current={clientX:D.clientX,clientY:D.clientY},l.current={clientX:D.clientX,clientY:D.clientY},a.current=D.pointerId,m.current=D.buttons;try{N.setPointerCapture(D.pointerId)}catch{a.current=null}return f.current=w=>{const O=ue(p,w);return t.current.insertReference(O,"cells"),O},x.autoScroller.stop(),L.current=!1,x.onDragFrame(ue(p,p)),!0},[$]),{enabled:v,bodyRef:M}=e;return i.useEffect(()=>{const D=M.current;if(!v||D===null)return;const x=w=>a.current!==null?w.pointerId===a.current:w.pointerType==="mouse",N=w=>{if(!(n.current&&x(w)))return;s.current={clientX:w.clientX,clientY:w.clientY};const O=f.current,y=A.current;if(!L.current&&O!==null&&y!==null){const g=Math.abs(w.clientX-l.current.clientX),q=Math.abs(w.clientY-l.current.clientY);Math.max(g,q)>=kr&&(L.current=!0,t.current.autoScroller.start({getPointerPosition:()=>s.current,buildRange:O,anchorCol:y.col,anchorRow:y.row}))}c.current===null&&(c.current=requestAnimationFrame(()=>{c.current=null;const g=f.current;if(!n.current||g===null)return;const q=$(s.current.clientX,s.current.clientY);q!==null&&t.current.onDragFrame(g(q))})),(m.current&1)!==0&&(w.buttons&1)===0&&T()},p=w=>{w.button!==0||!(n.current&&x(w))||T()},h=w=>{!n.current||a.current===null||w.pointerId!==a.current||T()};return D.addEventListener("pointermove",N),D.addEventListener("pointerup",p),D.addEventListener("lostpointercapture",h),()=>{D.removeEventListener("pointermove",N),D.removeEventListener("pointerup",p),D.removeEventListener("lostpointercapture",h),T()}},[v,M,$,T]),i.useMemo(()=>({isDragging:()=>n.current,getDragMode:()=>"point",abortDrag:_,cancelDrag:T,onPointerDown:V}),[_,T,V])},tg=.25,ng=4,mo=e=>{if(!Number.isFinite(e))throw new RangeError(`[spreadsheet] zoom must be a finite number (got ${e})`);return Math.min(ng,Math.max(tg,e))},go=(e,t)=>t>0?(Math.floor(e*10+1e-6)+1)/10:(Math.ceil(e*10-1e-6)-1)/10,rg=24,og=100,sg=1e5,lg=200,jc=Object.freeze(["#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF"]),Wl=5,ig=/^#[0-9A-Fa-f]{6}$/,cg=Object.freeze({row:!1,column:!1,intersection:!1}),Vl=Object.freeze({ok:!0}),Kl=(e,t)=>{if(t===void 0)return jc;if(t.length!==Wl)throw new RangeError(`[spreadsheet] colors.${e} must contain exactly ${Wl} colours (got ${t.length})`);for(const n of t)if(typeof n!="string"||!ig.test(n))throw new RangeError(`[spreadsheet] colors.${e} entries must be #rrggbb strings (got ${JSON.stringify(n)})`);return t},ag=e=>{for(const t of["row","column","intersection"])if(Fe(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},ug=(e,t)=>{if(e!==void 0)return e;if(t.row||t.column||t.intersection)return mc},dg=e=>{if(e===void 0)throw new RangeError("[spreadsheet] commitEdits: a paste commit requires its sheet context (sameSheet / conditionalFormats)");return e},ir={ranges:[ue({row:0,col:0},{row:0,col:0})],anchor:{row:0,col:0},active:{row:0,col:0}},fg=i.forwardRef(function({adapter:t,defaultRowHeight:n=rg,defaultColumnWidth:r=og,frozenColumns:o=0,frozenRows:s=0,renderCell:l,onSelectionChange:c,onCellContextMenu:a,onUndoRequest:m,onRedoRequest:f,onCopyMultiRange:A,onOperationRejected:L,onEditRejected:$,dataVersion:T,maxOperationCells:_=sg,enableFillHandle:V=!0,enableResizeUI:v=!0,formatCellAnnouncement:M,formatSelectionAnnouncement:D,formatCommandAnnouncement:x,labels:N,shortcuts:p,colors:h,formats:w,highlight:O,defaultHighlight:y,onHighlightChange:g,highlightColors:q,popovers:H,renderPopover:R,onClipChange:E,onHyperlinkOpen:u,onValidationRejected:d,onPasteSpecialRequest:P,onClipboardUnavailable:S,now:b=Date.now,zoom:I,defaultZoom:k,onZoomChange:z,testId:B,className:U,__onCellRender:G},J){const Z=Ll(t.rowCount,n),te=Ll(t.colCount,r),Ie=i.useRef(null);Ie.current===null&&(Ie.current=Up());const fe=Ie.current,Ze=i.useMemo(()=>Kp(N),[N]),He=i.useMemo(()=>pp(p),[p]),_n=i.useMemo(()=>({fill:Kl("fill",h===void 0?void 0:h.fill),font:Kl("font",h===void 0?void 0:h.font)}),[h]),Bt=i.useMemo(()=>q===void 0?void 0:ag(q),[q]);if(t.getConditionalFormats!==void 0&&t.getCellFormat===void 0)throw new RangeError("[spreadsheet] getConditionalFormats requires getCellFormat");const At=i.useCallback(()=>fe.get().editVersion,[fe]),Wt=i.useCallback(C=>fe.subscribeCoalesced(C),[fe]),Vt=i.useSyncExternalStore(Wt,At,At)+(T===void 0?0:T),Ue=t.getConditionalFormats===void 0?null:t.getConditionalFormats(),Je=i.useMemo(()=>({index:Ue===null?null:Nc(Ue),memo:Go()}),[t,Ue,Vt]),ut=i.useRef(Je.index);ut.current=Je.index;const dt=i.useRef(Je.memo);dt.current=Je.memo;const Ye=i.useCallback((C,K,ee)=>Zo(t,ut.current,dt.current,C,K,ee),[t]),$e=i.useRef(null),[an,Mr]=i.useState(()=>mo(k??1)),je=mo(I??an),ke=i.useRef(je);ke.current=je;const ft=i.useRef(je);ft.current=je;const un=i.useRef(null),xt=i.useRef(z);xt.current=z;const In=i.useRef(I!==void 0);In.current=I!==void 0;const dn=i.useCallback(C=>{const K=mo(C);K!==ft.current&&(ft.current=K,In.current||Mr(K),xt.current?.(K))},[]),F=t.rowCount===0||t.colCount===0,W=!F;i.useEffect(()=>{const C=$e.current;if(!W||C===null)return;const K=ne=>{ne.defaultPrevented||!ne.altKey||ne.ctrlKey||ne.metaKey||ne.shiftKey||ne.deltaY!==0&&(ne.preventDefault(),ne.stopPropagation(),!un.current?.()&&dn(go(ft.current,ne.deltaY<0?1:-1)))},ee=ne=>{if(ne.defaultPrevented||!(ne.ctrlKey&&ne.altKey)||ne.metaKey||ne.getModifierState("AltGraph"))return;const he=ne.key==="="||ne.key==="+"?go(ft.current,1):ne.key==="-"?go(ft.current,-1):ne.key==="0"?1:null;he!==null&&(ne.preventDefault(),ne.stopPropagation(),!un.current?.()&&dn(he))};return C.addEventListener("wheel",K,{passive:!1,capture:!0}),C.addEventListener("keydown",ee,!0),()=>{C.removeEventListener("wheel",K,{capture:!0}),C.removeEventListener("keydown",ee,!0)}},[dn,W]);const X=i.useRef(null),j=i.useRef(null),Q=i.useRef(null),oe=i.useRef(null),ce=i.useRef(0),be=i.useRef(null),ge=i.useRef(0),Ee=i.useRef(null),[xe,Oe]=i.useState(ir),ie=i.useRef(xe),le=i.useCallback(()=>ie.current,[]),[de,pe]=i.useState(()=>y===void 0?cg:y),Ce=O!==void 0?O:de,me=i.useRef(Ce);me.current=Ce;const Ne=ug(Bt,Ce),De=i.useRef(O!==void 0);De.current=O!==void 0;const ze=i.useRef(g);ze.current=g;const Xe=i.useCallback(C=>{De.current||pe(C),ze.current?.(C)},[]),Qe=i.useRef(null),et=i.useRef(null),tt=i.useRef(null),Fr=i.useRef(()=>!1),Qo=i.useRef(()=>{}),es=i.useRef(()=>null),ts=i.useRef(()=>{}),Ot=i.useCallback(()=>Fr.current(),[]),$r=i.useMemo(()=>({getPointing:()=>Fr.current(),insertReference:(C,K)=>Qo.current(C,K)}),[]),ns=i.useRef(lt),rs=i.useRef(null),os=i.useRef({interactive:null,tip:null}),ss=i.useRef(null),ls=i.useRef(null),Hn=i.useRef(()=>{}),is=i.useRef(()=>!1),Kt=i.useRef(null),fn=i.useCallback(()=>{const C=Kt.current;if(C===null||C.isOpen()!=="message")return!1;const K=C.context;return K===null||K.kind!=="message"||!K.current.rejected?!1:(C.close(),!0)},[]),Nr=i.useRef(()=>!1),cs=i.useRef(()=>!1),as=i.useRef(null),Lr=i.useRef(()=>Promise.resolve("rejected")),ve=i.useCallback(()=>{Qe.current?.()},[]),ye=i.useCallback(C=>{Q.current?.focus(C)},[]),Pr=i.useRef(!1),Bc=i.useCallback(()=>{const C=$e.current;if(C!==null){Pr.current=!0;try{C.focus()}finally{Pr.current=!1}}},[]),Le=i.useCallback(()=>{const C=Q.current;C!==null&&(C.value=" ",C.setSelectionRange(0,1))},[]),Dt=i.useCallback(()=>{const C=oe.current;if(C!==null){const K=Math.max(0,j.current?.getScrollPosition().y??0),ee=j.current?.getFrozenSize().height??0;C.style.transform=`translateY(${ce.current-K-ee}px)`}},[]),Tt=i.useCallback(()=>{const C=be.current;if(C!==null){const K=Math.max(0,j.current?.getScrollPosition().x??0),ee=j.current?.getFrozenSize().width??0;C.style.transform=`translateX(${ge.current-K-ee}px)`}},[]),zr=i.useRef(null),qr=i.useRef(null);(zr.current===null||qr.current?.rowAxis!==Z||qr.current?.colAxis!==te)&&(qr.current={rowAxis:Z,colAxis:te},zr.current=$m({handleRef:j,rowAxis:Z,colAxis:te}));const pt=i.useCallback(C=>{zr.current?.(C)},[]),Ut=i.useRef(null),Mt=i.useRef(null),jn=i.useCallback(C=>{Ut.current!==null&&window.clearTimeout(Ut.current),Mt.current!==null&&(cancelAnimationFrame(Mt.current),Mt.current=null),Ut.current=window.setTimeout(()=>{Ut.current=null;const K=Ee.current;K!==null&&(K.textContent="",Mt.current=requestAnimationFrame(()=>{Mt.current=null,K.textContent=C}))},lg)},[]);i.useEffect(()=>()=>{Ut.current!==null&&window.clearTimeout(Ut.current),Mt.current!==null&&cancelAnimationFrame(Mt.current)},[]);const us=i.useCallback((C,K)=>{if(M===void 0&&D===void 0)return;const ee=K.ranges[K.ranges.length-1],ne=_e(ee),he=K.ranges.length===1&&ne.rows===1&&ne.cols===1,Se=C.ranges[C.ranges.length-1],Xr=C.ranges.length!==K.ranges.length||Se.startRow!==ee.startRow||Se.startCol!==ee.startCol||Se.endRow!==ee.endRow||Se.endCol!==ee.endCol,Fs=()=>{if(M!==void 0){const Nt=K.active,Gr=t.getCellText(Nt.row,Nt.col),$s=t.getCellFormat===void 0?void 0:Ye(Nt.row,Nt.col,()=>Gr);jn(M({row:Nt.row,col:Nt.col,text:Gr,displayText:on(Gr,$s===void 0?void 0:$s.value),columnName:Cr(Nt.col)}))}};if(he){Fs();return}if(Xr){D!==void 0&&jn(D({range:ee,anchor:K.anchor,active:K.active,rangeRowCount:ne.rows,rangeColCount:ne.cols,rangeCount:K.ranges.length}));return}Fs()},[t,M,D,jn,Ye]),Pe=i.useCallback(C=>{const K=ie.current;Object.is(C,K)||Dm(C,K)||(ie.current=C,Oe(C),c?.(C),us(K,C),(tt.current?.()??!1)||Le())},[c,us,Le]),Wc=i.useCallback(C=>{const K=ie.current;if(C.mode==="cycle"){const ne=qc(K,C.direction);Pe(ne),pt(ne.active);return}const ee=Ln(C.cell,Z.count,te.count);if(C.mode==="extend"){Pe(qt(K,ee)),pt(ee);return}Pe(Tn(K,ee,{extend:!1,append:!1})),pt(ee)},[Pe,pt,Z,te]),Te=i.useCallback(()=>tt.current?.()??!1,[]),ds=i.useRef(null),Be=i.useCallback(()=>ds.current?.()??!0,[]),fs=i.useRef(null),pn=i.useCallback((C,K)=>{const ee=tt.current?.()??!1;fs.current?.(C,K),!ee&&(tt.current?.()??!1)&&fn()},[fn]),[Vc,_r]=i.useState(!1),Kc=i.useCallback((C,K)=>{_r(!0),pn("edit",K)},[pn]),ps=i.useRef(null),hs=i.useCallback(()=>ps.current?.()??null,[]),ms=i.useRef(null),ht=i.useCallback(()=>{ms.current?.()},[]),gs=i.useRef(null),ws=i.useCallback(C=>{gs.current?.(C)},[]),Cs=i.useRef(()=>{}),Bn=i.useRef(0),Ft=i.useCallback((C,K,ee)=>{let ne;if(K.source==="paste"){const he=dg(ee);if(C.length===0&&he.conditionalFormats.length===0)return null;Bn.current+=1,ne={transaction:Bn.current,source:"paste",sameSheet:he.sameSheet,conditionalFormats:he.conditionalFormats}}else{if(C.length===0)return null;Bn.current+=1,ne={transaction:Bn.current,source:K.source}}try{t.applyEdits(C,ne)}catch(he){return $?.(he,K),null}return fe.bumpEdit(),ws(K.source),ne.transaction},[t,fe,$,ws]),Uc=i.useCallback((C,K)=>Ft(C,{source:"paste"},K),[Ft]),Yc=i.useCallback(C=>{fe.setVy(C.y),Dt(),Tt(),ve()},[fe,Dt,Tt,ve]),bs=i.useRef({rowStart:-1,rowEnd:-1,colStart:-1,colEnd:-1}),Xc=i.useCallback(C=>{fe.setRowRange(C.renderingRowStart,C.renderingRowEnd),fe.setColRange(C.renderingColStart,C.renderingColEnd);const K=bs.current;(K.rowStart!==C.renderingRowStart||K.rowEnd!==C.renderingRowEnd||K.colStart!==C.renderingColStart||K.colEnd!==C.renderingColEnd)&&(bs.current={rowStart:C.renderingRowStart,rowEnd:C.renderingRowEnd,colStart:C.renderingColStart,colEnd:C.renderingColEnd},ve())},[fe,ve]),ys=i.useRef(()=>"add"),mt=i.useCallback(C=>{et.current?.(C,ys.current())},[]),Gc=i.useCallback(C=>{et.current?.(C,"point")},[]),vs=i.useRef(null),Ir=i.useCallback(C=>{vs.current?.(C)},[]),Rs=i.useRef(null),Zc=i.useCallback(C=>{Rs.current?.(C)},[]),ks=i.useRef(null),Hr=i.useCallback((C,K)=>{if(K.length===0)return;const ee=j.current;if(C==="col"){for(const ne of K){const he=Math.round(ne.size);te.resize(ne.index,he),ee?.updateColSize(ne.index,he)}fe.bumpColVersion(),Tt(),ve();return}for(const ne of K){const he=Math.round(ne.size);Z.resize(ne.index,he),ee?.updateRowSize(ne.index,he)}fe.bumpRowGeometry(),Dt(),ve()},[Z,te,fe,Tt,Dt,ve]),Jc=i.useCallback((C,K)=>{a?.(C,{kind:"pointer",event:K})},[a]),Qc=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:mt,axis:"both",zoomRef:ke}),jr=i.useRef(null),Br=i.useRef(null),ea=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:mt,axis:"x",zoomRef:ke}),ta=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:mt,axis:"y",zoomRef:ke}),na=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:Ir,axis:"x",zoomRef:ke}),ra=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:Ir,axis:"y",zoomRef:ke}),oa=Gt({handleRef:j,rowAxis:Z,colAxis:te,bodyRef:X,onDragFrame:mt,axis:"both",zoomRef:ke}),Es=i.useRef(null),Ss=i.useRef(()=>!1),Wr=i.useCallback(()=>Ss.current(),[]),nt=Qm({zoomRef:ke,enabled:!F,rowAxis:Z,colAxis:te,handleRef:j,bodyRef:X,isEditing:Te,requestCommit:Be,getSelection:le,setSelection:Pe,focusSink:ye,onDragFrame:mt,onContextMenuSelect:Jc,onRequestEdit:Kc,caretFromPointEnabled:C=>{if(l!==void 0||t.getCellFormula!==void 0&&t.getCellFormula(C.row,C.col)!==void 0)return!1;if(t.getCellFormat===void 0)return!0;const K=t.getCellText(C.row,C.col);return on(K,t.getCellFormat(C.row,C.col)?.value)===K},isAnyDragging:Wr,autoScroller:Qc,repaintOverlay:ve,pointDragRef:Es,getPointing:Ot,openHyperlinkAt:u===void 0||t.getCellHyperlink===void 0?void 0:C=>{const K=t.getCellHyperlink===void 0?void 0:cn(t.getCellHyperlink(C.row,C.col));return K===void 0?!1:(u(K,C),!0)}}),gt=Bl({zoomRef:ke,enabled:!F,axis:"col",headerRef:jr,mainAxis:te,crossCount:t.rowCount,handleRef:j,isEditing:Te,requestCommit:Be,getSelection:le,setSelection:Pe,focusSink:ye,onDragFrame:mt,autoScroller:ea,repaintOverlay:ve,pointing:$r}),wt=Bl({zoomRef:ke,enabled:!F,axis:"row",headerRef:Br,mainAxis:Z,crossCount:t.colCount,handleRef:j,isEditing:Te,requestCommit:Be,getSelection:le,setSelection:Pe,focusSink:ye,onDragFrame:mt,autoScroller:ta,repaintOverlay:ve,pointing:$r}),Ct=Om({zoomRef:ke,enabled:!F&&v,colBandRef:jr,rowBandRef:Br,colAxis:te,rowAxis:Z,viewStore:fe,handleRef:j,isEditing:Te,requestCommit:Be,focusSink:ye,getSelection:le,adapter:t,autofitEnabled:l===void 0,defaultRowHeight:n,defaultColumnWidth:r,maxOperationCells:_,onOperationRejected:L,resizeTracks:Hr,writeResizeGuide:Zc,repaintOverlay:ve,isPointing:Ot}),rt=Hm({zoomRef:ke,enabled:!F&&V,handleNodeRef:ks,bodyRef:X,rowAxis:Z,colAxis:te,handleRef:j,getSelection:le,setSelection:Pe,focusSink:ye,adapter:t,commitEdits:Ft,maxOperationCells:_,onOperationRejected:L,writeFillPreview:Ir,repaintOverlay:ve,xAutoScroller:na,yAutoScroller:ra}),Ge=eg({zoomRef:ke,enabled:!F,bodyRef:X,handleRef:j,rowAxis:Z,colAxis:te,getPointing:Ot,insertReference:$r.insertReference,captureSink:()=>es.current(),restoreSink:C=>ts.current(C),focusSink:ye,autoScroller:oa,onDragFrame:mt});Es.current=Ge;const hn=i.useCallback(()=>nt.isDragging()||gt.isDragging()||wt.isDragging()||Ct.isDragging()||rt.isDragging()||Ge.isDragging(),[nt,gt,wt,Ct,rt,Ge]);un.current=hn,Ss.current=hn,ys.current=()=>Ge.isDragging()?"point":nt.getDragMode();const sa=i.useCallback(()=>{nt.abortDrag(),gt.abortDrag(),wt.abortDrag(),Ct.abortDrag(),rt.abortDrag(),Ge.abortDrag()},[nt,gt,wt,Ct,rt,Ge]),Vr=i.useCallback(()=>ie.current.active,[]),As=i.useCallback((C,K)=>{const ee=t.getCellValidation===void 0?void 0:t.getCellValidation(C.row,C.col);if(ee===void 0)return Vl;const ne=t.evaluateFormula,he=ac(ee,K,ne===void 0?void 0:Se=>ne(Se,C));return he.ok||ee.strict!==!0?Vl:(d?.({cell:C,rule:ee,text:K,message:he.message}),Kt.current?.isKindEnabled("message")&&Hn.current("message",{message:he.message,rejected:!0}),he)},[t,d]),Ae=Wh({enabled:!F,sinkRef:Q,rootRef:$e,adapter:t,commitEdits:Ft,getActive:Vr,ensureCellVisible:pt,focusSink:ye,rearmSink:Le,discardClip:ht,isDragging:Wr,resolveEditAlign:C=>{if(t.getCellFormat===void 0)return null;const K=fr(t,C.row,C.col);return Yi(Ye(C.row,C.col,K),K)},resolveEditPaint:C=>t.getCellFormat===void 0?null:Vu(Ye(C.row,C.col,fr(t,C.row,C.col))),editPaintRef:ns,repaintOverlay:ve,validateCommit:As});tt.current=Ae.isEditing,ds.current=Ae.requestCommit,fs.current=Ae.startEdit,Fr.current=Ae.getPointing,Qo.current=Ae.insertReference,es.current=Ae.captureSink,ts.current=Ae.restoreSink;const xs=i.useCallback(()=>{Ae.cancelEdit(),fn()},[Ae.cancelEdit,fn]),mn=Sh({enabled:!F,sinkRef:Q,adapter:t,isEditing:Te,getSelection:le,setSelection:Pe,commitPaste:Uc,maxOperationCells:_,onOperationRejected:L,onCopyMultiRange:A,repaintOverlay:ve,isDragging:Wr,resize:{rowAxis:Z,colAxis:te,resizeTracks:Hr},pendingPasteOptionsRef:rs,formats:w,onClipChange:E,onClipboardUnavailable:S,onEditRejected:$});ps.current=mn.getClip,ms.current=mn.discardClip,gs.current=mn.discardClipOnCommit,Cs.current=mn.onAdapterSwitch,Lr.current=mn.paste;const gn=Zm({enabled:!F,adapter:t,popovers:H,sinkRef:Q,bodyRef:X,handleRef:j,rowAxis:Z,colAxis:te,zoomRef:ke,getActive:Vr,isEditing:Te,requestCommit:Be,focusSink:ye,rearmSink:Le,isDraggingAny:hn,commitEdits:Ft,labels:Ze,onHyperlinkOpen:u,anchors:os,repaintOverlay:ve});Kt.current=gn,Hn.current=gn.open,is.current=gn.hideTip;const la=i.useCallback(()=>{const C=ie.current.active;pt(C);const K=j.current,ee=K===null?{x:0,y:0}:K.getScrollPosition(),ne=K===null?{rows:0,cols:0}:K.getFrozenSize(),he=ke.current;return{top:It(Z,C.row,Math.max(0,ee.y),ne.rows)*he,left:_t(te,C.col,Math.max(0,ee.x),ne.cols)*he,width:te.sizeOf(C.col)*he,height:Z.sizeOf(C.row)*he}},[Z,te,pt]),Kr=Hh({adapter:t,getSelection:le,commitEdits:Ft,getActive:Vr,isEditing:Te,requestCommit:Be,cancelEdit:xs,getSessionText:Ae.getSessionText,validateCommit:As,insertAtCaret:Ae.insertAtCaret,refreshEditPaint:Ae.refreshPaint,maxOperationCells:_,onOperationRejected:L,colors:_n,formats:w,getHighlight:()=>me.current,setHighlight:Xe,popovers:H,openPopover:C=>Hn.current(C),onHyperlinkOpen:u,onPasteSpecialRequest:P,paste:C=>Lr.current(C),rowAxis:Z,colAxis:te,resizeTracks:Hr,defaultRowHeight:n,defaultColumnWidth:r,now:b,announce:jn,formatCommandAnnouncement:x,keyboardCellRect:la});as.current=Kr,Nr.current=Kr.executeCommand,cs.current=Kr.isCommandAvailable;const ia=i.useMemo(()=>({table:He,execute:C=>Nr.current(C),isAvailable:C=>cs.current(C)}),[He]),ca=i.useCallback(()=>{ht(),m?.()},[ht,m]),aa=i.useCallback(()=>{ht(),f?.()},[ht,f]);_m({zoomRef:ke,enabled:!F,sinkRef:Q,rootRef:$e,handOffFocusToRoot:Bc,getSelection:le,setSelection:Pe,moveActive:Wc,ensureCellVisible:pt,isEditing:Te,requestCommit:Be,startEdit:pn,commitEdits:Ft,maxOperationCells:_,onOperationRejected:L,getClip:hs,discardClip:ht,isDragging:hn,abortDrag:sa,findDataEdge:t.findDataEdge,getEditingMode:Ae.getEditingMode,cancelEdit:xs,onUndoRequest:ca,onRedoRequest:aa,onCellContextMenu:a,rowAxis:Z,colAxis:te,handleRef:j,rearmSink:Le,commands:ia,pointing:Ae,adapter:t,hideNoteTip:()=>is.current(),closeRejectedMessage:fn,pendingPasteOptionsRef:rs,onPointFrame:Gc});const ua=xe.active.row,da=xe.active.col;i.useLayoutEffect(()=>{const C=Kt.current;C!==null&&(C.syncTipAriaDescribedBy(),C.isKindEnabled("message")&&(C.isOpen()==="message"&&C.close(),C.open("message")))},[ua,da]),i.useLayoutEffect(()=>{ve()},[ve,Ce.row,Ce.column,Ce.intersection]);const fa=i.useCallback(C=>{(tt.current?.()??!1)||(C.preventDefault(),ye(),Le())},[ye,Le]),pa=i.useCallback(C=>{const K=$e.current,ee=C.relatedTarget;if(K!==null&&ee instanceof Node&&K.contains(ee)){C.target===K&&ee===Q.current&&!Pr.current&&ye();return}(tt.current?.()??!1)||(ye(),Le())},[ye,Le]),ha=i.useCallback(C=>{const K=$e.current,ee=C.relatedTarget;K!==null&&ee instanceof Node&&K.contains(ee)||Ae.isFocusoutSuppressed()||_r(!1)},[Ae]),Wn=i.useRef(null),wn=i.useCallback(()=>{const C=Wn.current;C!==null&&(Wn.current=null,window.removeEventListener("pointerup",C.up,!0),window.removeEventListener("pointercancel",C.cancel,!0))},[]),Ur=i.useCallback(()=>{if(Wn.current!==null)return;const C=ee=>{ee.pointerType==="mouse"&&(wn(),ee.button===1&&ee.preventDefault())},K=ee=>{ee.pointerType==="mouse"&&wn()};Wn.current={up:C,cancel:K},window.addEventListener("pointerup",C,!0),window.addEventListener("pointercancel",K,!0)},[wn]);i.useEffect(()=>wn,[wn]),i.useEffect(()=>{const C=$e.current;if(F||C===null)return;let K=0;const ee=Se=>{if(Se.pointerType!=="mouse"){(tt.current?.()??!1)||_r(!1);return}K=Se.buttons,Se.button===1&&(Se.target===Q.current&&(tt.current?.()??!1)||Ur())},ne=Se=>{Se.pointerType==="mouse"&&(K=Se.buttons)},he=Se=>{if(Se.pointerType!=="mouse"||Se.buttons===K)return;const Xr=Se.buttons&~K;K=Se.buttons,Se.preventDefault(),(Xr&4)!==0&&Ur()};return C.addEventListener("pointerdown",ee,!0),C.addEventListener("pointerup",ne,!0),C.addEventListener("pointermove",he,!0),()=>{C.removeEventListener("pointerdown",ee,!0),C.removeEventListener("pointerup",ne,!0),C.removeEventListener("pointermove",he,!0)}},[F,Ur]);const ma=i.useCallback(C=>{if(!(C.target!==C.currentTarget||C.pointerType!=="mouse")&&(C.preventDefault(),C.button===0)){if(Ot()){ye();return}if(Te()&&!Be()){ye();return}ye()}},[ye,Te,Be,Ot]),Yr=i.useRef(!1);i.useLayoutEffect(()=>{if(F){Yr.current=!1;return}if(Yr.current)return;Yr.current=!0,Le();const C=($e.current?.clientHeight??0)/ke.current;C>0&&Z.totalSize()>0&&fe.setRowRange(0,Z.indexAt(Math.min(C-1,Z.totalSize()-1)));const K=($e.current?.clientWidth??0)/ke.current;K>0&&te.totalSize()>0&&fe.setColRange(0,te.indexAt(Math.min(K-1,te.totalSize()-1)))},[F,Le,fe,Z,te]);const Os=i.useRef(t);i.useLayoutEffect(()=>{Os.current!==t&&(Os.current=t,nt.cancelDrag(),gt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),rt.cancelDrag(),Ge.cancelDrag(),Ae.cancelEdit(),Kt.current?.hideTip(),Kt.current?.close(),F?(ie.current=ir,Oe(ir)):Pe(ir),Cs.current())},[t,F,Pe,nt,gt,wt,Ct,rt,Ge,fe,Ae.cancelEdit]);const Ds=i.useRef(o),Ts=i.useRef(s);i.useLayoutEffect(()=>{(Ds.current!==o||Ts.current!==s)&&(Ds.current=o,Ts.current=s,nt.cancelDrag(),gt.cancelDrag(),wt.cancelDrag(),Ct.cancelDrag(),rt.cancelDrag(),Ge.cancelDrag())},[o,s,nt,gt,wt,Ct,rt,Ge]);const Ms=i.useRef(T);i.useLayoutEffect(()=>{Ms.current!==T&&(Ms.current=T,ht())},[T,ht]),i.useLayoutEffect(()=>{ve()},[ve,xe]);const $t=i.useCallback(()=>{const C=as.current;if(C===null)throw new RangeError("[spreadsheet] the command runner is not mounted");return C},[]);if(i.useImperativeHandle(J,()=>({resizeRow:(C,K)=>{const ee=Math.round(K);Z.resize(C,ee),j.current?.updateRowSize(C,ee),fe.bumpRowGeometry(),Dt(),ve()},resizeColumn:(C,K)=>{const ee=Math.round(K);te.resize(C,ee),j.current?.updateColSize(C,ee),fe.bumpColVersion(),Tt(),ve()},scrollToCell:(C,K)=>{j.current?.scrollToCell(C.row,C.col,K)},focus:C=>{ye(C),Te()||Le()},executeCommand:C=>Nr.current(C),applyFormat:C=>$t().applyFormat(C),setBorders:(C,K)=>$t().setBorders(C,K),setHyperlink:C=>$t().setHyperlink(C),setNote:C=>$t().setNote(C),addComment:C=>$t().addComment(C),setValidation:C=>$t().setValidation(C),paste:C=>Lr.current(C),getSelection:()=>ie.current,getBaseFormat:C=>t.getCellFormat===void 0?void 0:t.getCellFormat(C.row,C.col),getPaintedFormat:C=>t.getCellFormat===void 0?void 0:Ye(C.row,C.col,fr(t,C.row,C.col)),startEdit:C=>{pn(C)},openPopover:C=>{Hn.current(C)}}),[Z,te,fe,Tt,Dt,ve,ye,Te,Le,t,Ye,pn,$t]),F)return Y.jsx("div",{className:U?`aqsp-root ${U}`:"aqsp-root","data-aqsp-empty":"","data-testid":B});const ga=M!==void 0||D!==void 0||x!==void 0;return Y.jsx("div",{ref:$e,className:U?`aqsp-root ${U}`:"aqsp-root",role:"group","aria-label":Ze.rootAriaLabel,tabIndex:0,onFocus:pa,onBlur:ha,"data-aqsp-root":"","data-testid":B,children:Y.jsxs("div",{className:"aqsp-zoom","data-aqsp-zoom":je,onPointerDown:ma,style:je===1?void 0:{width:`${100/je}%`,height:`${100/je}%`,transform:`scale(${je})`},children:[Y.jsx("div",{className:"aqsp-corner","aria-hidden":"true","data-aqsp-corner":"",onPointerDown:C=>{if(C.pointerType==="mouse"&&(C.preventDefault(),C.button===0)){if(Ot()){ye();return}if(Te()&&!Be()){ye();return}ye(),Pe({ranges:[ue({row:0,col:0},{row:t.rowCount-1,col:t.colCount-1})],anchor:{row:0,col:0},active:{row:0,col:0}})}}}),Y.jsx(km,{viewStore:fe,colAxis:te,frozenCols:o,handleRef:j,bandRef:jr,colTrackRef:be,windowOriginXRef:ge,repaintColHeaders:Tt,selectionRanges:xe.ranges,enableResizeUI:v}),Y.jsx(Em,{viewStore:fe,rowAxis:Z,handleRef:j,bandRef:Br,selectionRanges:xe.ranges,rowTrackRef:oe,windowOriginYRef:ce,repaintHeaders:Dt,enableResizeUI:v,frozenRows:s}),Y.jsxs("div",{className:"aqsp-body-stack","data-aqsp-body-stack":"",children:[Y.jsx(Rm,{adapter:t,rowAxis:Z,colAxis:te,viewStore:fe,handleRef:j,bodyRef:X,dataVersion:T,defaultColumnWidth:r,frozenColumns:o,frozenRows:s,renderCell:l,onScroll:Yc,onRangeChange:Xc,focusSink:ye,isEditing:Te,requestCommit:Be,testId:B?`${B}-vs`:void 0,__onCellRender:G,cfIndexRef:ut,cfMemoRef:dt,isPointing:Ot}),Y.jsx(eh,{rowAxis:Z,colAxis:te,handleRef:j,sinkRef:Q,getSelection:le,editing:Ae.editing,virtualKeyboard:Vc,repaintRef:Qe,dragFrameRef:et,getClip:hs,getIsDraggingAny:hn,getIsFillDragging:rt.isDragging,fillFrameRef:vs,resizeGuideFrameRef:Rs,fillHandleNodeRef:ks,enableFillHandle:V,frozenCols:o,frozenRows:s,sinkAriaLabel:Ze.sinkAriaLabel,onSinkMouseDown:fa,editPaintRef:ns,highlightRef:me,highlightColors:Ne,popoverAnchors:os,interactiveAnchorRef:ss,tipAnchorRef:ls}),gn.layerEnabled?Y.jsx(Ym,{controller:gn,labels:Ze,renderPopover:R,interactiveAnchorRef:ss,tipAnchorRef:ls}):null]}),ga?Y.jsx("div",{ref:Ee,className:"aqsp-live-region","aria-live":"polite","data-aqsp-live-region":""}):null]})})});exports.BORDER_DEFAULT_COLOR=Lo;exports.CommentPopover=wc;exports.DEFAULT_CUSTOM_COLORS=jc;exports.DEFAULT_HIGHLIGHT_COLORS=mc;exports.DEFAULT_LABELS=Do;exports.DEFAULT_SHORTCUTS=lc;exports.LinkPopover=Cc;exports.ListPopover=bc;exports.MessagePopover=yc;exports.NotePopover=vc;exports.NoteTip=Rc;exports.SPREADSHEET_RESERVED_SHORTCUTS=cp;exports.Spreadsheet=fg;exports.canonicalizeFormat=Ke;exports.columnIndexToName=Cr;exports.columnNameToIndex=ep;exports.detectClipSource=ni;exports.enumerateRangeCells=yt;exports.estimatePasteCellCount=Uf;exports.expandPaste=Yf;exports.formatCellValue=on;exports.formatEquals=Aa;exports.fromR1C1=Nn;exports.makeRange=ue;exports.mergeFormat=zo;exports.normalizeHyperlink=St;exports.parseChord=zt;exports.parseClipPayload=bo;exports.parseHtmlTable=Ui;exports.parseTsv=nc;exports.rangeContains=Ht;exports.rangeSize=_e;exports.resolveLabel=Re;exports.serializeClipPayload=Ql;exports.serializeHtmlTable=Bi;exports.serializeTsv=Qi;exports.shiftFormula=Ai;exports.toR1C1=Ar;exports.validateCellText=ac;
|