@grid-is/agent-tools 0.2.2 → 0.3.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.
@@ -0,0 +1,165 @@
1
+ import{C as e,_ as t,a as n,b as r,d as i,f as a,h as o,i as s,m as c,o as l,p as u,r as d,s as f,t as p,u as m,w as h}from"./dist-BJH7vBTb.js";import{Cell as g,CellVertexId as _,FormulaError as v,Matrix as y,NameVertexId as b,RangeVertexId as ee,Reference as x,ValueSnapshot as te,a1ToRowColumn as ne,colFromOffs as re,describeWorkbook as ie,parseReference as ae,unbox as oe,vertexIdToCell as se,vertexIdToReference as ce}from"@grid-is/apiary";import{z as S}from"zod";var C=`operator`,le=`operator-trim`,ue=`bool`,de=`error`,fe=`number`,pe=`func`,me=`newline`,he=`whitespace`,ge=`string`,w=`context_quote`,T=`context`,E=`range`,D=`range_beam`,O=`range_ternary`,k=`range_named`,_e=`structured`,A=`cell`,ve=`fx_prefix`,ye=`unknown`,be=`UnaryExpression`,xe=`BinaryExpression`,Se=`ReferenceIdentifier`,Ce=`Literal`,we=`ErrorLiteral`,Te=`CallExpression`,Ee=`LambdaExpression`,De=`LetExpression`,Oe=`ArrayExpression`,ke=`Identifier`,Ae=`LetDeclarator`,je=2**14-1,j=2**20-1,Me=`$`,Ne=[[A,`:`,A],[A,`.:`,A],[A,`:.`,A],[A,`.:.`,A],[E],[D],[O],[T,`!`,A,`:`,A],[T,`!`,A,`.:`,A],[T,`!`,A,`:.`,A],[T,`!`,A,`.:.`,A],[T,`!`,A],[T,`!`,E],[T,`!`,D],[T,`!`,O],[w,`!`,A,`:`,A],[w,`!`,A,`.:`,A],[w,`!`,A,`:.`,A],[w,`!`,A,`.:.`,A],[w,`!`,A],[w,`!`,E],[w,`!`,D],[w,`!`,O],[k],[T,`!`,k],[w,`!`,k],[_e],[k,_e],[T,`!`,k,_e],[w,`!`,k,_e]],Pe={};function Fe(e,t){if(e.length){let n=e[0];t[n]||(t[n]={}),Fe(e.slice(1),t[n])}else t[Me]=!0}Ne.forEach(e=>Fe(e.concat().reverse(),Pe));var Ie=(e,t,n,r=0)=>{let i=r,a=t,o=e.length-r;for(;i<=o;){let t=e[n-i];if(t){let e=t.value,n=t.type===C?e:t.type;if(n===E&&!e.includes(`:`)&&(n=A),n in a){a=a[n],i+=1;continue}}return a[Me]?i:0}};function Le(e){let t=[];for(let n=e.length-1;n>=0;n--){let r=e[n],i=r.type;if(i===E||i===D||i===O||i===k||i===_e){let t=Ie(e,Pe,n);if(t>1){r={...r,value:``};let i=n-t+1;for(let t=i;t<=n;t++)r.value+=e[t].value;r.loc&&e[i].loc&&(r.loc[0]=e[i].loc[0]),n-=t-1}}t[t.length]=r}return t.reverse()}var Re=/#(?:NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|SYNTAX\?|ERROR!|CONNECT!|BLOCKED!|EXTERNAL!)/iy,ze=35;function Be(e,t){if(e.charCodeAt(t)===ze){Re.lastIndex=t;let n=Re.exec(e);if(n)return{type:de,value:n[0]}}}var Ve=46,He=58;function Ue(e,t){let n=e.charCodeAt(t);if(n===Ve||n===He){let r=e.charCodeAt(t+1);if(n!==r){if(r===He)return{type:le,value:e.slice(t,t+(e.charCodeAt(t+2)===Ve?3:2))};if(r===Ve)return{type:le,value:e.slice(t,t+2)}}}}function We(e,t){let n=e.charCodeAt(t),r=e.charCodeAt(t+1);if(n===60&&r===61||n===62&&r===61||n===60&&r===62)return{type:C,value:e.slice(t,t+2)};if(n===123||n===125||n===33||n===35||n===37||n===38||n>=40&&n<=45||n===47||n>=58&&n<=62||n===64||n===94)return{type:C,value:e[t]}}function Ge(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===95||e===92||e===40||e===46||e===63||e>160}function Ke(e,t){let n=e.charCodeAt(t);if(n===84||n===116){let n=e.charCodeAt(t+1);if(n===82||n===114){let n=e.charCodeAt(t+2);if(n===85||n===117){let n=e.charCodeAt(t+3);if((n===69||n===101)&&!Ge(e.charCodeAt(t+4)))return{type:ue,value:e.slice(t,t+4)}}}}if(n===70||n===102){let n=e.charCodeAt(t+1);if(n===65||n===97){let n=e.charCodeAt(t+2);if(n===76||n===108){let n=e.charCodeAt(t+3);if(n===83||n===115){let n=e.charCodeAt(t+4);if((n===69||n===101)&&!Ge(e.charCodeAt(t+5)))return{type:ue,value:e.slice(t,t+5)}}}}}}function qe(e,t){let n=t;for(;e.charCodeAt(t)===10;)t++;if(t!==n)return{type:me,value:e.slice(n,t)}}function Je(e){return e===9||e===11||e===12||e===13||e===32||e===160||e===5760||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279||e>=8192&&e<=8202}function Ye(e,t){let n=t;for(;Je(e.charCodeAt(t));)t++;if(t!==n)return{type:he,value:e.slice(n,t)}}var Xe=34;function Ze(e,t){let n=t;if(e.charCodeAt(t)===Xe){for(t++;t<e.length;){if(e.charCodeAt(t)===Xe&&(t++,e.charCodeAt(t)!==Xe))return{type:ge,value:e.slice(n,t)};t++}return{type:ge,value:e.slice(n,t),unterminated:!0}}}var Qe=39,$e=91,et=93,tt=33;function nt(e,t,n){let r=e.charCodeAt(t),i,a;if(r===Qe){let r=t;for(t++;t<e.length;){let o=e.charCodeAt(t);if(o===$e){if(i)return;i=t}else if(o===et){if(a)return;a=t}else if(o===Qe&&(t++,e.charCodeAt(t)!==Qe)){let o=i==null&&a==null;return n.xlsx&&i===r+1&&a===t-2&&(o=!0),i>=r+1&&a<t-2&&a>i+1&&(o=!0),o&&e.charCodeAt(t)===tt?{type:w,value:e.slice(r,t)}:void 0}t++}}}function rt(e,t,n){let r=e.charCodeAt(t),i,a;if(r!==Qe&&r!==tt){let r=t;for(;t<e.length;){let o=e.charCodeAt(t);if(o===$e){if(i)return;i=t}else if(o===et){if(a)return;a=t}else if(o===tt){let o=i==null&&a==null;if(n.xlsx&&i===r&&a===t-1&&(o=!0),i>=r&&a<t-1&&a>i+1&&(o=!0),o)return{type:T,value:e.slice(r,t)}}else if((i==null||a!=null)&&!(o>=65&&o<=90||o>=97&&o<=122||o>=48&&o<=57||o===46||o===95||o===161||o===164||o===167||o===168||o===170||o===173||o>=175))return;t++}}}var it=46,at=58;function ot(e,t){let n=e.charCodeAt(t);if(n===it){if(e.charCodeAt(t+1)===at)return e.charCodeAt(t+2)===it?3:2}else if(n===at)return e.charCodeAt(t+1)===it?2:1;return 0}function st(e,t){let n=e.charCodeAt(t);return!(n>=65&&n<=90||n>=97&&n<=122||n>=48&&n<=57||n===95||n===40||n>160)}function ct(e,t){let n=e.charCodeAt(t);return!(n>=65&&n<=90||n>=97&&n<=122||n>=48&&n<=57||n===95||n===40||n===36||n===46||n===33)}function lt(e,t){let n=t;e.charCodeAt(t)===36&&t++;let r=t+3,i=0;do{let n=e.charCodeAt(t);if(n>=65&&n<=90)i=26*i+n-64,t++;else if(n>=97&&n<=122)i=26*i+n-96,t++;else break}while(t<r&&t<e.length);return i&&i<=je+1?t-n:0}function ut(e,t){let n=t;e.charCodeAt(t)===36&&t++;let r=t+7,i=0,a=e.charCodeAt(t);if(a>=49&&a<=57){i=i*10+a-48,t++;do if(a=e.charCodeAt(t),a>=48&&a<=57)i=i*10+a-48,t++;else break;while(t<r&&t<e.length)}return i&&i<=j+1?t-n:0}function dt(e,t,n){let r=t,i=lt(e,r),a=0,o=0;if(i){r+=i;let s=ut(e,r);r+=s;let c=ot(e,r),l=r;if(c){if(r+=c,a=lt(e,r),r+=a,o=ut(e,r),r+=o,s&&o&&a){if(st(e,r)&&n.mergeRefs)return{type:E,value:e.slice(t,r)}}else if(!s&&!o){if(st(e,r))return{type:D,value:e.slice(t,r)}}else if(n.allowTernary&&(o||a)&&ct(e,r))return{type:O,value:e.slice(t,r)}}if(s&&st(e,l)&&e.charCodeAt(l)!==33)return{type:E,value:e.slice(t,l)}}else{let i=ut(e,r);if(i){r+=i;let s=ot(e,r);if(s){if(r+=s,a=lt(e,r),a&&(r+=a),o=ut(e,r),r+=o,a&&o&&n.allowTernary&&ct(e,r))return{type:O,value:e.slice(t,r)};if(!a&&o&&st(e,r))return{type:D,value:e.slice(t,r)}}}}}var ft=91,pt=93,mt=82,ht=114,gt=67,_t=99,vt=43,yt=45,bt=33;function xt(e,t,n=!1){let r=t,i=e.charCodeAt(t);if(n?i===mt||i===ht:i===gt||i===_t){t++;let i=0,a=0,o=e.length,s=e.charCodeAt(t),c,l=1,u=s===ft;if(u)o=Math.min(o,t+(n?8:6)),t++,c=e.charCodeAt(t),(c===vt||c===yt)&&(t++,o++,l=c===yt?-1:1);else if(s<49||s>57||isNaN(s))return 1;do{let n=e.charCodeAt(t);if(n>=48&&n<=57)a=a*10+n-48,i++,t++;else break}while(t<o);let d=n?j:je;return u?e.charCodeAt(t)===pt?(t++,a*=l,i&&-d<=a&&a<=d?t-r:0):0:i&&a<=d+1?t-r:0}return 0}function St(e,t,n){let r=t,i=xt(e,r,!0);r+=i;let a=xt(e,r);if(r+=a,(a||i)&&e.charCodeAt(r)!==bt){let o=ot(e,r),s=r;if(o){r+=o;let s=xt(e,r,!0);r+=s;let c=xt(e,r);if(r+=c,i&&!a&&s&&c||!i&&a&&s&&c||i&&a&&s&&!c||i&&a&&!s&&c){if(n.allowTernary&&st(e,r))return{type:O,value:e.slice(t,r)}}else if((a&&c&&!i&&!s||!a&&!c&&i&&s)&&st(e,r))return{type:D,value:e.slice(t,r)}}if(st(e,s))return{type:i&&a?E:D,value:e.slice(t,s)}}}function Ct(e,t,n){return n.r1c1?St(e,t,n):dt(e,t,n)}var wt=64,Tt=93,Et=91,Dt=58,Ot=44,kt=35,At=39,jt={headers:1,data:2,totals:4,all:8,"this row":16,"@":16},Mt=(...e)=>Object.freeze(e),Nt={0:Mt(),1:Mt(`headers`),2:Mt(`data`),4:Mt(`totals`),8:Mt(`all`),16:Mt(`this row`),3:Mt(`headers`,`data`),6:Mt(`data`,`totals`)};function Pt(e,t){let n=t;if(e.charCodeAt(n++)===Et&&e.charCodeAt(n++)===kt){do{let t=e.charCodeAt(n);if(t>=65&&t<=90||t>=97&&t<=122||t===32)n++;else break}while(n<t+11);if(e.charCodeAt(n++)===Tt)return n-t}}function Ft(e,t){let n=t;for(;Je(e.charCodeAt(n));)n++;return n-t}function It(e,t,n=!0){let r=t,i=``;if(e.charCodeAt(r)===Et){r++;let n;do if(n=e.charCodeAt(r),n===At)if(r++,n=e.charCodeAt(r),n===At||n===kt||n===wt||n===Et||n===Tt)i+=String.fromCharCode(n),r++;else return;else if(n===At||n===kt||n===wt||n===Et)return;else if(n===Tt)return r++,[e.slice(t,r),i];else i+=String.fromCharCode(n),r++;while(r<e.length)}else if(n){let n;do{if(n=e.charCodeAt(r),n===At||n===kt||n===wt||n===Et||n===Tt||n===Dt)break;i+=String.fromCharCode(n),r++}while(r<e.length);if(r!==t)return[i,i]}}function Lt(e,t=0){let n=[],r=t,i,a=0;if(e.charCodeAt(t)!==Et)return;if(i=Pt(e,t)){let n=e.slice(t+2,t+i-1);t+=i;let r=jt[n.toLowerCase()];if(!r)return;a|=r}else if(i=It(e,t,!1))t+=i[0].length,i[1]&&n.push(i[1]);else{let r=!0;for(t++,t+=Ft(e,t);r&&(i=Pt(e,t));){let n=jt[e.slice(t+2,t+i-1).toLowerCase()];if(!n)return;a|=n,t+=i,t+=Ft(e,t),r=e.charCodeAt(t)===Ot,r&&(t++,t+=Ft(e,t))}if(r&&e.charCodeAt(t)===wt&&(a|=jt[`@`],t+=1,r=e.charCodeAt(t)!==Tt),!Nt[a])return;let o=r&&It(e,t,!0);if(o){if(t+=o[0].length,n.push(o[1]),e.charCodeAt(t)===Dt){t++;let r=It(e,t,!0);if(r)t+=r[0].length,n.push(r[1]);else return}r=!1}if(t+=Ft(e,t),r||e.charCodeAt(t)!==Tt)return;t++}let o=Nt[a];return{columns:n,sections:o&&o.concat(),length:t-r,token:e.slice(r,t)}}var Rt=33;function zt(e,t){let n=Lt(e,t);if(n&&n.length){let r=n.length;for(;Je(e.charCodeAt(t+r));)r++;if(e.charCodeAt(t+r)!==Rt)return{type:_e,value:n.token}}}function Bt(e,t){let n=t;do{let n=e.charCodeAt(t);if(n<48||n>57)break;t++}while(t<e.length);return t-n}function Vt(e,t){let n=t,r=Bt(e,t);if(!r)return;if(t+=r,e.charCodeAt(t)===46){t++;let n=Bt(e,t);if(!n)return;t+=n}let i=e.charCodeAt(t);if(i===69||i===101){t++;let n=e.charCodeAt(t);(n===43||n===45)&&t++;let r=Bt(e,t);if(!r)return;t+=r}return{type:fe,value:e.slice(n,t)}}function Ht(e,t){let n=t,r=e.charCodeAt(t);if(r>=65&&r<=90||r>=97&&r<=122||r===95||r===92||r>160)t++;else return;let i;do if(i=e.charCodeAt(t),i>=65&&i<=90||i>=97&&i<=122||i>=48&&i<=57||i===95||i===92||i===46||i===63||i>160)t++;else break;while(isFinite(i));let a=t-n;if(a&&a<255)return r===92&&a<3||a===1&&(r===114||r===82||r===99||r===67)?void 0:{type:k,value:e.slice(n,t)}}var Ut=33;function Wt(e,t,n){if(e.charCodeAt(t)===Ut)return{type:C,value:e[t]};if(!n.r1c1){let n=ot(e,t);if(n)return{type:C,value:e.slice(t,t+n)}}}var Gt=91,Kt=40,qt=33,Jt=32,Yt=new Uint8Array(180-Jt),Xt=1,Zt=2,Qt=4,$t=8,en=16,tn=32,nn=Xt|Zt|Qt,rn=$t|en|tn,an=Xt|$t|Qt|tn;for(let e=Jt;e<180;e++){let t=String.fromCharCode(e),n=/^[a-zA-Z_\\\u00a1-\uffff]$/.test(t),r=/^[a-zA-Z_]$/.test(t),i=/^[a-zA-Z0-9_.\\?\u00a1-\uffff]$/.test(t),a=/^[a-zA-Z0-9_.]$/.test(t),o=/^[a-zA-Z0-9_.¡¤§¨ª\u00ad¯-\uffff]$/.test(t);Yt[e-Jt]=(n?Xt:0)|(i?$t:0)|(r?Zt:0)|(a?en:0)|(o?Qt:0)|(o?tn:0)}function on(e,t,n,r,i){let a=r-n;return i&&a&&a<255?t===92&&a<3||a===1&&(t===114||t===82||t===99||t===67)?void 0:{type:k,value:e.slice(n,r)}:{type:ye,value:e.slice(n,r)}}function sn(e,t,n){let r=t,i=e.charCodeAt(t),a=i>180?an:Yt[i-Jt];if(a&Qt&&!(a&Xt)&&!(a&Zt)||i===Gt)return rt(e,t,n);if(!(a&nn))return;let o=a&Xt?1:0,s=a&Zt?1:0,c=a&Qt?1:0;t++;let l;do{l=e.charCodeAt(t);let n=i>180?an:Yt[l-Jt]??0;if(n&rn)o&&!(n&$t)&&(o=0),s&&!(n&en)&&(s=0),c&&!(n&tn)&&(c=0);else return l===Kt&&s?{type:pe,value:e.slice(r,t)}:l===qt&&c?{type:T,value:e.slice(r,t)}:on(e,i,r,t,o);t++}while((o||s||c)&&t<e.length);if(r!==t)return on(e,i,r,t,o)}var cn=[Be,Ue,We,qe,Ye,Ze,Ct,Vt,Ke,nt,sn,zt],ln=[Wt,nt,rt,Ct,zt,Ht];function un(e){return e===`r`||e===`R`||e===`c`||e===`C`}var dn=/^l(?:ambda|et)$/i,fn=(e,t)=>e&&e.type===t,pn=e=>e===k||e===pe,mn=e=>!fn(e,C)||e.value===`%`||e.value===`}`||e.value===`)`||e.value===`#`;function hn(e,t){let n=0,r=0,i;for(let a of e){let e=a.type;e===C?a.value===`(`?(r++,i.type===pe&&dn.test(i.value)&&(n=r)):a.value===`)`&&(r--,r<n&&(n=0)):(n&&e===ye&&un(a.value)||n&&t&&e===D&&un(a.value))&&(a.type=k),i=a}return e}function gn(e,t,n={}){let{withLocation:r=!1,mergeRefs:i=!0,negativeNumbers:a=!0}=n,o={withLocation:r,mergeRefs:i,allowTernary:n.allowTernary??!1,negativeNumbers:a,r1c1:n.r1c1??!1,xlsx:n.xlsx??!1},s=[],c=0,l=0,u=0,d=[],f,p,m,h=e=>{let t=e.type,n=t===ye,i=m&&m.type===ye;m&&(n&&i||n&&pn(m.type)||i&&pn(t))?(m.value+=e.value,m.type=ye,r&&(m.loc[1]=e.loc[1])):(t===le&&(d.push(s.length),t=ye,e.type=ye),s[s.length]=e,m=e,t!==he&&t!==me&&(p=f,f=e))};if(e.startsWith(`=`)){let e={type:ve,value:`=`};r&&(e.loc=[0,1]),c++,h(e)}let g=t.length;for(;c<e.length;){let n=c,i;for(let n=0;n<g;n++)if(i=t[n](e,c,o),i){c+=i.value.length;break}if(i||(i={type:ye,value:e[c]},c++),r&&(i.loc=[n,c]),m&&i.value===`(`&&m.type===pe&&dn.test(m.value)&&l++,i.value.length===1&&(i.type===ye||o.r1c1&&i.type===D)&&(u+=+!!un(i.value)),a&&i.type===fe){let e=m;if(e?.type===C&&e.value===`-`&&(!p||p.type===ve||!mn(p))){let e=s.pop();i.value=`-`+i.value,i.loc&&(i.loc[0]=e.loc[0]),f=p,m=s[s.length-1]}}h(i)}u&&l&&hn(s,o.r1c1);for(let e of d){let t=s[e-1],n=s[e+1];s[e].type=t?.type===E&&n?.type===E?C:ye}return i?Le(s):s}function _n(e,t={}){return gn(e,cn,{withLocation:t.withLocation??!1,mergeRefs:t.mergeRefs??!0,allowTernary:t.allowTernary??!1,negativeNumbers:t.negativeNumbers??!0,r1c1:t.r1c1??!1,xlsx:!0})}function vn(e){return!!e&&(e.type===E||e.type===D||e.type===O||e.type===_e||e.type===k)}function yn(e){return!!e&&(e.type===ue||e.type===de||e.type===fe||e.type===ge)}function bn(e){return!!e&&e.type===de}function xn(e){return!!e&&(e.type===he||e.type===me)}function Sn(e){return!!e&&e.type===pe}function Cn(e){return!!e&&e.type===C}var wn=`(END)`,Tn=`(FUNCTION)`,En=`(WHITESPACE)`,Dn=[`ANCHORARRAY`,`CHOOSE`,`DROP`,`IF`,`IFS`,`INDEX`,`INDIRECT`,`LAMBDA`,`LET`,`OFFSET`,`REDUCE`,`SINGLE`,`SWITCH`,`TAKE`,`TRIMRANGE`,`XLOOKUP`],On={},M,kn,N,An=!1,jn=e=>An||Dn.includes(e.toUpperCase()),Mn=(e,t=!1)=>{let n=(e&&e.value)+``;return!!(vn(e)||t&&Cn(e)&&(n===`:`||n===`,`||!n.trim())||Sn(e)&&jn(n)||bn(e)&&n===`#REF!`)},Nn=e=>!!e&&(e.type===Se||(e.type===we||e.type===de)&&e.value===`#REF!`||e.type===xe&&(e.operator===`:`||e.operator===` `||e.operator===`,`)||vn(e)||e.type===Te&&jn(e.callee.name));function P(e,t=null){let n=Error(e);throw n.source=kn.map(e=>e.value).join(``),n.sourceOffset=kn.slice(0,t??N).reduce((e,t)=>e+t.value.length,0),n}function Pn(e=!1){let t=N,n;do n=kn[++t];while(n&&(xn(n)||Cn(n)&&n.value===`(`));return Mn(n,e)}function F(e=null,t=null){if(e&&e!==M.id&&P(`Expected ${e} but got ${M.id}`),xn(kn[N])){let e=Nn(t),n=e&&Pn(!1),r=e&&kn[N+1]&&kn[N+1].value===`(`;if(!n&&!r)for(;xn(kn[N]);)N++}if(N>=kn.length){M=On[wn];return}let n=kn[N];N+=1,n.unterminated&&P(`Encountered an unterminated token`);let r;return Cn(n)?(r=On[n.value],r||P(`Unknown operator ${n.value}`)):xn(n)?r=On[En]:yn(n)?r=On[Ce]:vn(n)?r=On[Se]:Sn(n)?r=On[Tn]:P(`Unexpected ${n.type} token: ${n.value}`),M=Object.create(r),M.type=n.type,M.value=n.value,n.loc&&(M.loc=[...n.loc]),M}function Fn(e){let t=M;F(null,t);let n=t.nud();for(;e<M.lbp;)t=M,F(null,t),n=t.led(n);return n}var In={nud:()=>P(`Invalid syntax`),led:()=>P(`Missing operator`)};function Ln(e,t=0){let n=On[e];return n?t>=n.lbp&&(n.lbp=t):(n={...In},n.id=e,n.value=e,n.lbp=t,On[e]=n),n}function I(e,t,n){let r=Ln(e,t);return r.led=n||function(e){this.type=xe,this.operator=this.value,delete this.value;let n=Fn(t);return this.arguments=[e,n],this.loc&&=[e.loc[0],n.loc[1]],this},r}function Rn(e,t){let n=Ln(e,0);return n.lbp=70,n.led=t||function(e){return this.type=be,this.operator=this.value,delete this.value,this.arguments=[e],this.loc&&(this.loc[0]=e.loc[0]),this},n}function zn(e,t){let n=Ln(e);return n.nud=t||function(){this.type=be,this.operator=this.value,delete this.value;let e=Fn(70);return this.arguments=[e],this.loc&&(this.loc[1]=e.loc[1]),this},n}function Bn(e,t){return I(e,t,function(n){Nn(n)||P(`Unexpected ${e} operator`);let r=Fn(t);return Nn(r)||P(`Unexpected ${M.type} following ${this.id}`),this.type=xe,this.operator=this.value.trim()?this.value:` `,delete this.value,this.arguments=[n,r],this.loc&&=[n.loc[0],r.loc[1]],this})}Ln(wn),Bn(`:`,80);var Vn=Bn(`,`,80);Bn(En,80);var L=e=>{let t=Vn.lbp>0;return e!=null&&(Vn.lbp=e?80:0),t};Rn(`%`),Rn(`#`,function(e){return Nn(e)||P(`# expects a reference`),this.type=be,this.operator=this.value,delete this.value,this.arguments=[e],this}),zn(`+`),zn(`-`),zn(`@`),I(`^`,50),I(`*`,40),I(`/`,40),I(`+`,30),I(`-`,30),I(`&`,20),I(`=`,10),I(`<`,10),I(`>`,10),I(`<=`,10),I(`>=`,10),I(`<>`,10),Ln(Ce).nud=function(){let{type:e,value:t}=this;if(this.type=Ce,this.raw=t,e===fe)this.value=+t;else if(e===ue)this.value=t.toUpperCase()===`TRUE`;else if(e===de)this.type=we,this.value=t.toUpperCase();else if(e===ge)this.value=t.slice(1,-1).replace(/""/g,`"`);else throw Error(`Unsupported literal type: `+e);return this},Ln(Se).nud=function(){return this.type===k?this.kind=`name`:this.type===_e?this.kind=`table`:this.type===D?this.kind=`beam`:this.kind=`range`,this.type=Se,this},Ln(`)`),zn(`(`,function(){let e=L(!0),t=Fn(0);return F(`)`,t),L(e),t}),Ln(Tn).nud=function(){return this},I(`(`,90,function(e){let t={type:ke,name:e.value};e.id!==Tn&&(e.type===Ee||e.type===Te||e.type===De||e.type===Se||e.type===be&&e.value===`#`||e.type===we&&e.value===`#REF!`?t=e:P(`Unexpected call`,N-1));let n=e.value.toLowerCase();if(n===`lambda`)return Hn.call(this,e);if(n===`let`)return Un.call(this,e);let r=[],i=!1;if(M.id!==`)`){let e=L(!1);for(;M.id!==`)`;)if(xn(M)&&F(),M.id===`,`)r.push(null),i=!0,F();else{let e=Fn(0);r.push(e),i=!1,M.id===`,`&&(F(`,`),i=!0)}L(e)}i&&r.push(null);let a=M;return delete this.value,this.type=Te,this.callee=t,e.loc&&(this.callee.loc=[...e.loc]),this.arguments=r,e.loc&&(this.loc=[e.loc[0],a.loc[1]]),F(`)`,this),this});function Hn(e){let t=[],n={},r,i=!1,a=L(!1);if(M.id!==`)`)for(;!i;){xn(M)&&F();let e=N,a=Fn(0);if(M.id===`,`){if(a.type===Se&&a.kind===`name`){let e=a.value.toLowerCase();e in n&&P(`Duplicate name: `+a.value),n[e]=1;let r={type:ke,name:a.value};a.loc&&(r.loc=a.loc),t.push(r)}else N=e,P(`LAMBDA argument is not a name`);F(`,`)}else r=a,i=!0}return L(a),delete this.value,this.type=Ee,this.params=t,this.body=r||null,e.loc&&(this.loc=[e.loc[0],M.loc[1]]),F(`)`,this),this}function Un(e){let t=[],n=[],r={},i,a=0,o=(e,o)=>{if(i&&P(`Unexpected argument following calculation`),o&&a>=2)i=e;else if(a%2)n.push(e);else if(e&&e.type===Se&&e.kind===`name`){let n=e.value.toLowerCase();n in r&&P(`Duplicate name: `+e.value),r[n]=1,t.push({type:ke,name:e.value,loc:e.loc})}else a>=2?i=e:P(`Argument is not a name`);a++},s=L(!1),c=!1;if(M.id!==`)`){for(;M.id!==`)`;)xn(M)&&F(),M.id===`,`?(o(null),c=!0,F()):(o(Fn(0),M.id!==`,`),c=!1,M.id===`,`&&(F(`,`),c=!0));L(s)}c&&o(null,!0),i===void 0&&P(`Unexpected end of arguments`),L(s),delete this.value,this.type=De,this.declarations=[],t.length||P(`Unexpected end of arguments`);for(let e=0;e<t.length;e++){let r={type:Ae,id:t[e],init:n[e],loc:t[e].loc&&[t[e].loc[0],n[e].loc[1]]};this.declarations.push(r)}return this.body=i,e.loc&&(this.loc=[e.loc[0],M.loc[1]]),F(`)`,this),this}Ln(`}`),Ln(`;`),zn(`{`,function(){M.id===`}`&&P(`Unexpected empty array`);let e=[],t=!1,n=[e],r=L(!1);for(;!t;)xn(M)&&F(),yn(M)?(e.push(On[Ce].nud.call(M)),F()):P(`Unexpected ${M.type} in array: ${M.value}`),M.id===`,`?F(`,`):M.id===`;`?(F(`;`),e=[],n.push(e)):t=!0;let i=M;return F(`}`),L(r),this.type=Oe,this.elements=n,this.loc&&(this.loc[1]=i.loc[1]),delete this.value,this});var Wn=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/,Gn=/^(R|C|RC|[A-Z]{1,3}\d{1,7})$/i;function Kn(e,t=0){return t||e&&(Wn.test(e)||Gn.test(e)||/^\d/.test(e))?1:0}function qn(e){return`'`+e.replace(/'/g,`''`)+`'`}function Jn(e){let t=``,n=0,{workbookName:r,sheetName:i}=e;return r&&(t+=`[`+r+`]`,n+=Kn(r)),i&&(t+=i,n+=Kn(i)),n&&(t=qn(t)),t&&t+`!`}function Yn(e){return e===`both`?`.:.`:e===`head`?`.:`:e===`tail`?`:.`:`:`}var Xn=(e,t,n)=>Math.min(Math.max(t,e),n);function Zn(e,t){return t?String(e+1):e?`[`+e+`]`:``}function Qn(e){let{r0:t,c0:n,r1:r,c1:i}=e,{$c0:a,$c1:o,$r0:s,$r1:c}=e,l=t==null,u=n==null,d=r==null,f=i==null,p=Yn(e.trim),m=!!e.trim;if(t=Xn(s?0:-j,t|0,j),n=Xn(a?0:-je,n|0,je),!l&&d&&!u&&f?(r=t,d=!1,i=n,f=!1):(r=Xn(c?0:-j,r|0,j),i=Xn(o?0:-je,i|0,je)),t===0&&r>=j&&!u&&!f||l&&d){let e=Zn(n,a),t=Zn(i,o);return`C`+(e===t&&!m?e:e+p+`C`+t)}if(n===0&&i>=je&&!l&&!d||u&&f){let e=Zn(t,s),n=Zn(r,c);return`R`+(e===n&&!m?e:e+p+`R`+n)}let h=Zn(t,s),g=Zn(r,c),_=Zn(n,a),v=Zn(i,o);return l||d||u||f?(l?``:`R`+h)+(u?``:`C`+_)+p+(d?``:`R`+g)+(f?``:`C`+v):h!==g||_!==v?`R`+h+`C`+_+p+`R`+g+`C`+v:`R`+h+`C`+_}function $n(e){return Jn(e)+(`name`in e?e.name:Qn(e.range))}var er=36,tr=46,nr=58,rr=97,ir=65,ar=122,or=90,sr=48,cr=49,lr=57;function ur(e,t){let n=e.charCodeAt(t);if(n===tr){if(e.charCodeAt(t+1)===nr)return e.charCodeAt(t+2)===tr?[3,`both`]:[2,`head`]}else if(n===nr)return e.charCodeAt(t+1)===tr?[2,`tail`]:[1,``];return[0,``]}function dr(e,t){let n=t,r=e.charCodeAt(t)===er;r&&t++;let i=t+3,a=0;do{let n=e.charCodeAt(t);if(n>=ir&&n<=or)a=26*a+n-(ir-1),t++;else if(n>=rr&&n<=ar)a=26*a+n-(rr-1),t++;else break}while(t<i&&t<e.length);return a&&a<=je+1?[t-n,a-1,r]:[0,0,!1]}function fr(e,t){let n=t,r=e.charCodeAt(t)===er;r&&t++;let i=t+7,a=0,o=e.charCodeAt(t);if(o>=cr&&o<=lr){a=a*10+o-sr,t++;do if(o=e.charCodeAt(t),o>=sr&&o<=lr)a=a*10+o-sr,t++;else break;while(t<i&&t<e.length)}return a&&a<=j+1?[t-n,a-1,r]:[0,0,!1]}function pr(e,t,n,r,i,a,o,s,c){o!=null&&(n==null||n!=null&&o<n)&&([n,o,r,s]=[o,n,s,r]),i!=null&&(e==null||e!=null&&i<e)&&([e,i,t,a]=[i,e,a,t]);let l={top:e,left:n,bottom:i,right:o,$top:t,$left:r,$bottom:a,$right:s};return c&&(l.trim=c),l}function mr(e,t=!0){let n=0,[r,i,a]=dr(e,n),o=0,s=!1,c=0,l=!1,u,d;if(r){n+=r;let[f,p,m]=fr(e,n);n+=f;let[h,g]=ur(e,n);if(h){if(n+=h,[u,o,s]=dr(e,n),n+=u,[d,c,l]=fr(e,n),n+=d,f&&d&&u){if(n===e.length)return pr(p,m,i,a,c,l,o,s,g)}else if(!f&&!d){if(n===e.length)return pr(null,!1,i,a,null,!1,o,s,g)}else if(t&&(d||u)&&n===e.length)return f?d?pr(p,m,i,a,c,l,null,!1,g):pr(p,m,i,a,null,!1,o,s,g):pr(null,!1,i,a,c,l,o,s,g)}if(f&&n===e.length)return pr(p,m,i,a,p,m,i,a,g)}else{let[r,i,a]=fr(e,n);if(r){n+=r;let[f,p]=ur(e,n);if(f){if(n+=f,[u,o,s]=dr(e,n),n+=u,[d,c,l]=fr(e,n),n+=d,u&&d&&t){if(n===e.length)return pr(i,a,null,!1,c,l,o,s,p)}else if(!u&&d&&n===e.length)return pr(i,a,null,!1,c,l,null,!1,p)}}}}function hr(e){let t=``;for(let n of e)t+=n.value;return t}function gr(e){let t={type:e.type,value:e.value};return e.loc&&(t.loc=[e.loc[0],e.loc[1]]),e.unterminated!=null&&(t.unterminated=e.unterminated),typeof e.index==`number`&&(t.index=e.index,typeof e.groupId==`string`&&(t.groupId=e.groupId),typeof e.depth==`number`&&(t.depth=e.depth),typeof e.error==`boolean`&&(t.error=e.error)),t}function _r(e,t=!1){let n=!1,r=``,i=[],a=()=>{r&&i.push(t?r:{value:r,braced:n}),r=``};for(let t=0;t<e.length;t++){let i=e[t];i===`[`?(a(),n=!0):i===`]`?(a(),n=!1):r+=i}return a(),i}function vr(e,t,n){let r=_r(e,!n);if(n){if(r.length>1)t.workbookName=r[r.length-2].value,t.sheetName=r[r.length-1].value;else if(r.length===1){let e=r[0];e.braced?t.workbookName=e.value:t.sheetName=e.value}}else t.context=r}var yr=e=>e.slice(1,-1).replace(/''/g,`'`),br=(e,t)=>{let n=e?.value;if(n===`:`||n===`.:`||n===`:.`||n===`.:.`)return t.operator=n,1},xr=(e,t)=>{if(e?.type===E)return t.r0=e.value,1},Sr=(e,t)=>{if(e?.type===O)return t.r0=e.value,1},Cr=(e,t)=>{if(e?.type===E)return t.r1=e.value,1},wr=e=>{if(e?.type===C&&e.value===`!`)return 1},Tr=(e,t)=>{if(e?.type===D)return t.r0=e.value,1},Er=(e,t)=>{if(e.type===_e)return t.struct=e.value,1},Dr=(e,t,n)=>{let r=e?.type;if(r===T)return vr(e.value,t,n),1;if(r===w)return vr(yr(e.value),t,n),1},Or=(e,t)=>{if(e?.type===k)return t.name=e.value,1},kr=[[Sr],[xr,br,Cr],[xr],[Tr],[Dr,wr,Sr],[Dr,wr,xr,br,Cr],[Dr,wr,xr],[Dr,wr,Tr]],Ar=kr.concat([[Or],[Dr,wr,Or],[Er],[Or,Er],[Dr,wr,Or,Er]]);function jr(e,t={}){let n={withLocation:t.withLocation??!1,mergeRefs:t.mergeRefs??!1,allowTernary:t.allowTernary??!1,allowNamed:t.allowNamed??!0,r1c1:t.r1c1??!1,xlsx:!0},r=gn(e,ln,n);r.length&&r[0].type===ve&&r.shift();let i=n.allowNamed?Ar:kr;for(let e of i)if(e.length===r.length){let t={workbookName:``,sheetName:``,r0:``,r1:``,name:``,struct:``,operator:``};if(e.every((e,n)=>e(r[n],t,!0)))return t}}var Mr=/^l(?:ambda|et)$/i,Nr=(e,t,n)=>t==null?null:e?t:t-n,Pr=e=>e.slice(1,-1).replace(/''/g,`'`);function Fr(e){let t=e.lastIndexOf(`!`),n={};return t>-1?(e.startsWith(`'`)?vr(Pr(e.slice(0,t)),n,!0):vr(e.slice(0,t),n,!0),n.range=mr(e.slice(t+1))):n.range=mr(e),n}function Ir(e,t){let n=mr(t);if(!n)throw Error(`translateTokensToR1C1 got an invalid anchorCell: `+t);let{top:r,left:i}=n,a=0,o=0,s=0,c=[];for(let t of e){let e=t?.type;if(e===C)if(t.value===`(`){o++;let e=c[c.length-1];e&&e.type===pe&&Mr.test(e.value)&&(a=o)}else t.value===`)`&&(o--,o<a&&(a=0));if(e===E||e===D||e===O){t=gr(t);let e=t.value,n=Fr(e);if(n){let e=n.range,o={};o.r0=Nr(e.$top,e.top,r),o.r1=Nr(e.$bottom,e.bottom,r),o.c0=Nr(e.$left,e.left,i),o.c1=Nr(e.$right,e.right,i),o.$r0=e.$top,o.$r1=e.$bottom,o.$c0=e.$left,o.$c1=e.$right,e.trim&&(o.trim=e.trim),n.range=o;let s=$n(n);un(s)&&a&&(s+=`[0]`),t.value=s}t.loc&&(t.loc[0]+=s,s+=t.value.length-e.length,t.loc[1]+=s)}else s&&t.loc&&(t=gr(t),t.loc[0]+=s,t.loc[1]+=s);c[c.length]=t}return c}function Lr(e,t,n={}){if(typeof e==`string`)return hr(Ir(_n(e,{mergeRefs:!1,allowTernary:n.allowTernary??!0}),t));throw Error(`translateFormulaToA1 expects a formula string`)}var Rr=String.fromCharCode;function zr(e){return(e>=702?Rr(((e-702)/676-0)%26+65):``)+(e>=26?Rr((e/26-1)%26+65):``)+Rr(e%26+65)}var Br=(e,t,n)=>Math.min(Math.max(t,e),n),R=(e,t)=>(t?`$`:``)+zr(e),z=(e,t)=>(t?`$`:``)+Vr(e),Vr=e=>String(e+1);function Hr(e){let{top:t,left:n,bottom:r,right:i,trim:a}=e,{$left:o,$right:s,$top:c,$bottom:l}=e,u=n==null,d=i==null,f=t==null,p=r==null;t=Br(0,t|0,j),n=Br(0,n|0,je),!u&&!f&&d&&p?(r=t,i=n):(r=Br(0,r|0,j),i=Br(0,i|0,je));let m=Yn(a);return t===0&&r>=j&&!u&&!d&&(!(o&&!u||s&&!d)||n===i)||f&&p?R(n,o)+m+R(i,s):n===0&&i>=je&&!f&&!p&&(!(c&&!f||l&&!p)||t===r)||u&&d?z(t,c)+m+z(r,l):!u&&!f&&!d&&p?R(n,o)+z(t,c)+m+R(i,s):!u&&f&&!d&&!p?R(n,o)+z(r,l)+m+R(i,s):!u&&!f&&d&&!p?R(n,o)+z(t,c)+m+z(r,l):u&&!f&&!d&&!p?R(i,s)+z(t,c)+m+z(r,l):i!==n||r!==t||s!==o||l!==c?R(n,o)+z(t,c)+m+R(i,s)+z(r,l):R(n,o)+z(t,c)}function Ur(e){return Jn(e)+(`name`in e?e.name:Hr(e.range))}function Wr(e,{allowNamed:t=!0,allowTernary:n=!1}={}){let r=jr(e,{allowNamed:t,allowTernary:n,r1c1:!1});if(r){if(r.name)return{workbookName:r.workbookName,sheetName:r.sheetName,name:r.name};if(r.r0&&r.r0){let e=mr(r.r1?r.r0+r.operator+r.r1:r.r0);if(e)return{workbookName:r.workbookName,sheetName:r.sheetName,range:e}}}}Object.freeze({OPERATOR:C,BOOLEAN:ue,ERROR:de,NUMBER:fe,FUNCTION:pe,NEWLINE:me,WHITESPACE:he,STRING:ge,CONTEXT:T,CONTEXT_QUOTE:w,REF_RANGE:E,REF_BEAM:D,REF_TERNARY:O,REF_NAMED:k,REF_STRUCT:_e,FX_PREFIX:ve,UNKNOWN:ye}),Object.freeze({UNARY:be,BINARY:xe,REFERENCE:Se,LITERAL:Ce,ERROR:we,CALL:Te,ARRAY:Oe,IDENTIFIER:ke,LAMBDA:Ee,LET:De,LET_DECL:Ae});var Gr={"\n":.28,"\r":.28," ":.28,"\xA0":.28," ":.28,"᠎":0," ":.5," ":1," ":.5," ":1," ":.33," ":.25," ":.16," ":.56," ":.28," ":.2," ":.15,"​":0," ":.16," ":.22," ":1,"":0},Kr=/^((?:[a-z\d-]+\s+)*)([\d.]+(%|em|px)|(?:x+-)?large|(?:x+-)?small|medium)(?:\s*\/\s*(normal|[\d.]+(%|px|em)?))?(\s.+)?$/,qr=/\bsmall-caps\b/,Jr=/\b(?:italic|oblique)\b/,Yr=/\bbold(?:er)?\b/,Xr=16,Zr=13.3333333,Qr=.01*Xr,$r={"xx-small":9,"x-small":10,smaller:13.3333,small:13,medium:16,large:18,larger:19.2,"x-large":24,"xx-large":32},ei=new Map;function ti(e){if(ei.has(e))return ei.get(e);let t=Kr.exec(e);if(!t)return{};let n=(t[6]||``).trim(),r=$r[t[2]]||parseFloat(t[2]);t[3]===`%`?r*=Qr:t[3]===`em`?r*=Xr:t[3]===`pt`&&(r*=Zr);let i;i=t[4]===`normal`||t[4]===`inherit`||!t[4]?Math.round(7/6*r):!t[5]||t[5]===`em`?parseFloat(t[4]||``)*r:t[5]===`pt`?parseFloat(t[4]||``)*Zr:t[5]===`%`?r*.01:parseFloat(t[4]||``);let a=qr.test(t[1])?`small-caps`:`normal`,o=Jr.test(t[1])?`italic`:`normal`,s=400;if(Yr.test(t[1]))s=700;else{let e=/\b(\d+)\b/.exec(t[1]),n=e?parseInt(e[1],10):400;s=n>=100&&n!==400?n:400}let c={family:n,size:r,height:i??7/6*r,weight:s,variant:a,style:o};return ei.set(e,c),c}function ni(e,t){let n=``;if(e.style&&e.style!==`normal`&&(n+=e.style),e.variant&&e.variant!==`normal`&&(n+=(n?` `:``)+e.variant),e.weight&&e.weight!==400&&(n+=n?` `:``,e.weight===700?n+=`bold`:n+=e.weight),e.size){let r=e.size;!t&&e.sizeAdjust&&e.sizeAdjust!==1&&(r*=e.sizeAdjust),n+=(n?` `:``)+r+`px`,e.height!==e.size&&(n+=`/`+e.height+`px`)}return e.family&&(n+=(n?` `:``)+e.family),t&&(n+=`::`+e.baseline),t&&(n+=`::`+e.color),t&&(n+=`::`+e.tracking),t&&(n+=`::`+(e.sizeAdjust??``)),n}var ri=ti(`12px/14px sans-serif`),ii={trim:!0,collapse:!0},ai={};function oi(){return(e,t)=>{let n=typeof t==`string`?ti(t):t,r=n.size??12;return n.family&&/\bmonospace\b/.test(n.family)?r*=.6:(r*=.45,n.weight&&n.weight>400&&(r*=1.18)),e.length*r}}function si(e){if(e&&e.getContext){let t=e.getContext(`2d`);if(t&&typeof t.measureText==`function`)return(e,n)=>(t.font=String(n),t.measureText(e).width)}}function ci(){let e=typeof document<`u`?document:null;return typeof OffscreenCanvas<`u`&&new OffscreenCanvas(100,100)||e&&e.createElement&&e.createElement(`canvas`)||null}var li=si(ci())||oi();function ui(e){if(e==null)li=si(ci())||oi();else if(e)li=si(e)||oi();else throw Error(`setMeasureCanvas argument is not a canvas or null`)}function di(e,t,n=ii){t=typeof t==`string`?ti(t):{...ri,...t};let r=Object.assign({},ii,n),i=String(e);if(!i)return 0;if(i in Gr){let e=ni(t,!0)+`/`+i;return e in ai||(ai[e]=li(`_${i}_`,ni(t))-li(`__`,ni(t))),ai[e]}!r.trim||!r.collapse?i=i.replace(/\n/g,` `):r.trim?i=i.replace(/\n/g,` `).trim():r.collapse&&(i=i.replace(/\s+/g,` `));let a=typeof e==`string`?0:e.font.tracking||0;return li(i,ni(t))+(t.size??12)*a}var B=class{value;width;whitespace;font;line;constructor(e=``,t={}){this.value=e,this.font=t,this.width=0}valueOf(){return this.value}toString(){return this.value}toJSON(){let e=this,t={type:`TK`,val:e.value??``};return e.font.style===`italic`&&(t.style=e.font.style),e.font.family&&e.font.family!==`sans-serif`&&(t.font=e.font.family),e.font.weight&&e.font.weight!==400&&(t.weight=e.font.weight),e.font.baseline&&(t[e.font.baseline<0?`sub`:`sup`]=!0),[`href`,`color`,`class`,`target`,`rel`].forEach(n=>{e.font[n]&&(t[n]=e.font[n])}),t}},fi=class extends B{toJSON(){let e=super.toJSON();return e.type=`BR`,delete e.val,e}},V=class extends B{toJSON(){let e=super.toJSON();return e.type=`NL`,delete e.val,e}},pi=class extends B{toJSON(){let e=super.toJSON();return e.type=`SH`,delete e.val,e}},mi=/[\r\n\xA0]+/g;function hi(e,t){return{family:t.family??e.family??`sans-serif`,style:t.style??e.style??`normal`,variant:t.variant??e.variant??`normal`,weight:t.weight??e.weight??400,height:t.height??e.height??14,size:t.size??e.size??12,sizeAdjust:t.sizeAdjust??e.sizeAdjust??void 0,baseline:t.baseline??e.baseline??0,tracking:t.tracking??e.tracking??0,href:t.href??e.href??``,color:t.color??e.color??``,rel:t.rel??e.rel??``,target:t.target??e.target??``,class:t.class??e.class??``}}function gi(e,t,n){let r=e.width,i,a;for(;r+n.width>t&&e.length;)i=e[e.length-1],a=i.width??0,i.width&&i.width>n.width?(i.value=i.value.slice(0,-1),i.width=di(i,i.font),r+=i.width):e.pop(),r-=a;e[e.length-1]instanceof pi&&e.pop(),i&&(i=e[e.length-1]||i||{},n.font=Object.create(i.font),n.font.href=e.length?i.font.href:void 0,n.font.rel=e.length?i.font.rel:void 0,n.font.target=e.length?i.font.target:void 0,e.push(n))}function _i(e){return Object.assign([],{height:0,font:e,width:0,hasOverflow:!1,hasLineOverflow:!1})}function vi(e){let t=new B(e.value);return t.width=e.width??0,t.whitespace=e.whitespace,t.font=e.font,t}function yi(e,t){let n=ti(t.font);if(!e.length)return _i(n);let r=typeof t.height==`function`?t.height:()=>t.height,i=typeof t.width==`function`?t.width:()=>t.width,a=t.overflowLine,o=t.overflowWrap,s={...n,weight:700},c=n.height??n.size??12,l=isFinite(r())?Math.floor(r()/c):1/0;if(!r()&&!i(0)||!l)return _i(n);let u=0,d=0,f=0,p=[],m=[],h=!1;for(;u<e.length&&d<l;){let t=e[u],r=hi(n,t.font);if(t.width=di(t,r),t.font=r,t.line=d,t.whitespace=t.value in Gr,t.value&&=t.value.replace(mi,` `),!(!f&&t.whitespace||h&&t.whitespace))if(t instanceof V)f=0,m=[],p.push(u+1),d++;else if(t instanceof fi||t instanceof pi)m.push({index:u,width:f});else if(t.whitespace||f+t.width<i(d))f+=t.width;else if(m.length){let t,r;do{r=!0,t=m.pop();let a=e[t.index],o;a instanceof pi&&(o=di(`-`,a.font||n),t.width+o>i(d)&&(r=!m.length))}while(!r);p.push(t.index+1),f=0,d++,u=t.index,m=[]}else if(o===`break-word`){let r=i(d);if(f+t.width>r){let i=vi(t);do t.value=t.value.slice(0,-1),t.width=di(t,t.font||n),f+=t.width;while(t.value&&t.width>r);i.value=i.value.slice(t.value.length),e.splice(u+1,0,new fi,i)}p.push(u+1),f=0,d++}else f+=t.width;u++,h=t.whitespace}u!==p[p.length-1]&&p.push(u);let g=0,_=0,v=p.map(t=>{let r=g,i;for(;(i=e[r])&&(i.whitespace||!i.value);)r++;let a=t,o=null;for(;a>r&&(i=e[a-1])&&(i.whitespace||!(i.value||i instanceof pi));)i instanceof V&&(o=i),a--;i instanceof pi&&(i.value=`-`,i.width=di(`-`,i.font||n)),g=t;let s=Object.assign(e.slice(r,a).filter(e=>e.value),{width:0});return o&&s.push(o),s.width=s.reduce((e,t)=>e+(t.width||0),0),s.width>_&&(_=s.width),s}),y=!1;if(a){let e=a===`ellipsis`?`…`:a;v.forEach((t,r)=>{let a=i(r);if(t.width>a){let r=new B(e);r.font=n,r.width=di(e,s),gi(t,a,r),y=!0}})}let b=!1,ee=t.overflow===`ellipsis`?`…`:t.overflow;if(ee&&u!==e.length){let e=i(v.length-1),t=v[v.length-1],r=new B(ee);r.font=n,r.width=di(ee,s),gi(t,e,r),b=!0}else b=!1;return Object.assign(v,{height:v.length*c,font:n,width:_,hasOverflow:b,hasLineOverflow:y})}function bi(e){return Math.round(e*1e6)/1e6}var xi={center:`middle`,right:`end`},Si={middle:.5,center:.5,bottom:1,end:1},Ci=(e,t)=>!e&&!t||e===t;function wi(e,t){let n=[],r=ti(t.font),i=r.size??12,a=r.family??`sans-serif`,o=t.align??`left`,s=t.createElement;if(e.length){let c=r.height??7/6*i,l=t.valign,u=typeof t.height==`function`?t.height():t.height,d=typeof t.width==`function`?t.width(0):t.width,f=typeof t.x==`function`?t.x:()=>t.x,p=!isFinite(d)&&e.length===1,m=bi(c/i)??0,h=p?0:bi(c/(i*1.15+(c-i)/2));if(Si[l]&&isFinite(u)){let t=l===`bottom`?1:.5;h=(h||0)+(u*t-c*e.length*t)/i}let g=o===`justify`,_=0;o===`right`?_=d:o===`center`&&(_=d/2);let v=[],y=`tspan`,b=null,ee=``,x=()=>{if(ee){let e=s(y,b,ee);v.push(e)}y=`tspan`,b=null,ee=``};for(let t=0,r=e.length;t<r;t++){let o=``,c=``,l=0,u=e[t];if(!u.length){n.push(s(`tspan`,{x:f(t),dy:bi(t?m:h)+`em`},`\xA0`));continue}v=[];let te=0,ne=0,re=``;for(let e=0,t=u.length;e<t;e++){let t=u[e],n=t.font,r=ni(n,!0);if(t.whitespace&&te++,ne+=t.width,e&&!t.font.tracking&&!l&&Ci(r,o)&&Ci(t.font.class,c)&&Ci(re,t.font.href))ee+=t.value;else{x();let e=(n.size??i)*(n.sizeAdjust??1);ee=t.value,b={fontFamily:n.family!==a&&n.family||null,fontSize:e===i?null:e,fontWeight:n.weight===400?null:n.weight||null,fontStyle:n.style===`normal`?null:n.style||null,fontVariant:n.variant===`normal`?null:n.variant||null,fill:n.color||null,baselineShift:n.baseline?n.baseline*100+`%`:null,className:t.font.class||null,dx:0,href:null,rel:null,target:null},l&&=(b.dx=bi(l),0),t.font.tracking&&(l=e*t.font.tracking),t.font.href&&!re?(re=t.font.href,y=`a`,b.href=re,b.rel=t.font.rel,b.target=t.font.target):re=``,o=r,c=t.font.class??``}}if(x(),p)n.push(...v);else{let e=null,i=t===r-1||u[u.length-1]instanceof V;g&&u.length>1&&!i&&(e=bi((d-ne)/te)),n.push(s(`tspan`,{wordSpacing:e,x:f(t)+_,dy:bi(t?m:h)+`em`},...v))}}}return s(`text`,{fontFamily:a,fontSize:i,textAnchor:xi[o]||`start`},...n)}var Ti={middle:.5,center:.5,bottom:1,end:1};function Ei(e){return e.color||(e.href?`#00C`:`#000`)}function Di(e,t,n){if(!e.length)return;n.textBaseline=`middle`;let r=ti(t.font),i=r.size??12,a=r.height??7/6*i,o=t.valign,s=typeof t.height==`function`?t.height():t.height,c=typeof t.width==`function`?t.width(0):t.width,l=typeof t.x==`function`?t.x:()=>t.x,u=t.align,d=u===`justify`,f=a*.5,p=Ti[o];if(p&&isFinite(s)){let t=e.length*a;f+=s*p-t*p}let m;e.forEach((t,r)=>{m=null;let o=l(r),s=r*a+f,p=0,h=0;t.forEach(e=>{e.whitespace&&p++,h+=e.width});let g=0,_=r===e.length-1||t[t.length-1]instanceof V;d&&t.length>1&&!_&&(g=(c-h)/p);for(let e of t){n.font=ni(e.font);let t=e.font,r=t.baseline?i*-t.baseline+i*.15:0;n.fillStyle=Ei(t);let a=0;if(u===`right`?a+=c-h:u===`center`?a+=c/2-h/2:u===`justify`&&(e.whitespace||e instanceof V)&&(o+=g),n.fillText(e.value,o+a,s+r),e.font.href){n.beginPath(),n.strokeStyle=n.fillStyle;let t=Math.floor(s+i*.45)+.5;m||=[o+a,t],n.moveTo(...m),n.lineTo(o+a+e.width,t),n.stroke()}else m=null;o+=e.width}})}var Oi=Object.prototype.hasOwnProperty,ki={};function Ai(e){return ki[e]||(ki[e]=e.replace(/([a-z])([A-Z])/g,(e,t,n)=>t+`-`+n.toLowerCase())),ki[e]}function ji(e,t){if(Array.isArray(t))t.forEach(t=>ji(e,t));else if(typeof t==`string`){let n=document.createTextNode(t);e.appendChild(n)}else e.appendChild(t)}function Mi(e,t,...n){if(typeof document>`u`)throw Error(`No document found, cannot create elements`);let r=typeof e==`string`?document.createElementNS(`http://www.w3.org/2000/svg`,e):e;if(t&&r.setAttribute)for(let e in t)Oi.call(t,e)&&t[e]!=null&&r.setAttribute(e===`className`?`class`:Ai(e),String(t[e]));return n!=null&&n.length&&n.forEach(e=>{e&&ji(r,e)}),r}var Ni=/^[\n\r\t\x20\xA0\u2000-\u200B\u205F\u3000]/,Pi=/^[^\n\r\t\u0020\u2000-\u200B\u205F\u3000]{2,}/,Fi=/^[\xA0\u2011\u202F\u2060\uFEFF]/,Ii=/^(?:[;\xAD%?…]|,(?!\d))/,Li=/^[´±°¢£¤$¥\u2212]/,Ri=`'“‘[「【﹝〔<‹«{『((<《`.split(``),zi=`',,,!!??”]」】》>’»﹞〕〗〉}))』。`.split(``),Bi=e=>{let t=e.charCodeAt(0);return t>=19968&&t<=40959};function Vi(e){e||=``;let t=[],n=e.charAt(0),r=``,i=``,a=0;for(let o=1,s=e.length;o<s;o++){r=e.charAt(o),i=e.charAt(o+1);let s=Ni.test(n),c=Ni.test(r),l=c||s||Bi(n)||Bi(r);if((Li.test(r)&&!Fi.test(n)||Ii.test(n+i)&&!Fi.test(r))&&(l=!0),l&&(zi.includes(r)||Ri.includes(n))&&(l=!1),n===`-`||n===`‐`||n===`–`||n===`—`){let t=Ni.test(e.charAt(o-2));t&&!c&&(l=!1),!t&&Pi.test(r+i)&&(l=!0)}if(l){let n=e.slice(a,o);n.endsWith(`­`)?(t.push(new B(n.slice(0,-1))),t.push(new pi)):(t.push(new B(n)),t.push(new fi)),a=o}n=r}return t.push(new B(e.slice(a))),t}var Hi={nbsp:`\xA0`,iexcl:`¡`,cent:`¢`,pound:`£`,curren:`¤`,yen:`¥`,brvbar:`¦`,sect:`§`,uml:`¨`,copy:`©`,ordf:`ª`,laquo:`«`,not:`¬`,shy:`­`,reg:`®`,macr:`¯`,deg:`°`,plusmn:`±`,sup2:`²`,sup3:`³`,acute:`´`,micro:`µ`,para:`¶`,middot:`·`,cedil:`¸`,sup1:`¹`,ordm:`º`,raquo:`»`,frac14:`¼`,frac12:`½`,frac34:`¾`,iquest:`¿`,Agrave:`À`,Aacute:`Á`,Acirc:`Â`,Atilde:`Ã`,Auml:`Ä`,Aring:`Å`,AElig:`Æ`,Ccedil:`Ç`,Egrave:`È`,Eacute:`É`,Ecirc:`Ê`,Euml:`Ë`,Igrave:`Ì`,Iacute:`Í`,Icirc:`Î`,Iuml:`Ï`,ETH:`Ð`,Ntilde:`Ñ`,Ograve:`Ò`,Oacute:`Ó`,Ocirc:`Ô`,Otilde:`Õ`,Ouml:`Ö`,times:`×`,Oslash:`Ø`,Ugrave:`Ù`,Uacute:`Ú`,Ucirc:`Û`,Uuml:`Ü`,Yacute:`Ý`,THORN:`Þ`,szlig:`ß`,agrave:`à`,aacute:`á`,acirc:`â`,atilde:`ã`,auml:`ä`,aring:`å`,aelig:`æ`,ccedil:`ç`,egrave:`è`,eacute:`é`,ecirc:`ê`,euml:`ë`,igrave:`ì`,iacute:`í`,icirc:`î`,iuml:`ï`,eth:`ð`,ntilde:`ñ`,ograve:`ò`,oacute:`ó`,ocirc:`ô`,otilde:`õ`,ouml:`ö`,divide:`÷`,oslash:`ø`,ugrave:`ù`,uacute:`ú`,ucirc:`û`,uuml:`ü`,yacute:`ý`,thorn:`þ`,yuml:`ÿ`,fnof:`ƒ`,Alpha:`Α`,Beta:`Β`,Gamma:`Γ`,Delta:`Δ`,Epsilon:`Ε`,Zeta:`Ζ`,Eta:`Η`,Theta:`Θ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Xi:`Ξ`,Omicron:`Ο`,Pi:`Π`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Upsilon:`Υ`,Phi:`Φ`,Chi:`Χ`,Psi:`Ψ`,Omega:`Ω`,alpha:`α`,beta:`β`,gamma:`γ`,delta:`δ`,epsilon:`ε`,zeta:`ζ`,eta:`η`,theta:`θ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,xi:`ξ`,omicron:`ο`,pi:`π`,rho:`ρ`,sigmaf:`ς`,sigma:`σ`,tau:`τ`,upsilon:`υ`,phi:`φ`,chi:`χ`,psi:`ψ`,omega:`ω`,thetasym:`ϑ`,upsih:`ϒ`,piv:`ϖ`,bull:`•`,hellip:`…`,prime:`′`,Prime:`″`,oline:`‾`,frasl:`⁄`,weierp:`℘`,image:`ℑ`,real:`ℜ`,trade:`™`,alefsym:`ℵ`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,crarr:`↵`,lArr:`⇐`,uArr:`⇑`,rArr:`⇒`,dArr:`⇓`,hArr:`⇔`,forall:`∀`,part:`∂`,exist:`∃`,empty:`∅`,nabla:`∇`,isin:`∈`,notin:`∉`,ni:`∋`,prod:`∏`,sum:`∑`,minus:`−`,lowast:`∗`,radic:`√`,prop:`∝`,infin:`∞`,ang:`∠`,and:`⊥`,or:`⊦`,cap:`∩`,cup:`∪`,int:`∫`,there4:`∴`,sim:`∼`,cong:`≅`,asymp:`≈`,ne:`≠`,equiv:`≡`,le:`≤`,ge:`≥`,sub:`⊂`,sup:`⊃`,nsub:`⊄`,sube:`⊆`,supe:`⊇`,oplus:`⊕`,otimes:`⊗`,perp:`⊥`,sdot:`⋅`,lceil:`⌈`,rceil:`⌉`,lfloor:`⌊`,rfloor:`⌋`,lang:`〈`,rang:`〉`,loz:`◊`,spades:`♠`,clubs:`♣`,hearts:`♥`,diams:`♦`,quot:`"`,amp:`&`,lt:`<`,gt:`>`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,permil:`‰`,lsaquo:`‹`,rsaquo:`›`},Ui=-.3,Wi=.45,Gi=.7,Ki={weight:400,style:`normal`,variant:`normal`,baseline:0,tracking:0,href:``},qi=/^[\n\r\x20\u2000-\u200B\u205F\u3000]/,Ji=class{tokens;stack;props;constructor(){this.tokens=[],this.stack=[],this.props={...Ki}}add_token(e){return e.font=this.props,this.tokens.push(e),e}open_context(){this.stack.push(this.props),this.props=Object.create(this.props)}close_context(){if(!this.stack.length)throw Error(`Unexpected }`);this.props=this.stack.pop()}trimEnd(){let e=this.tokens[this.tokens.length-1];for(;e instanceof V;)this.tokens.pop(),e=this.tokens[this.tokens.length-1]}setProps(e){for(let[t,n]of Object.entries(e))n!=null&&(this.props[t]=n)}maybeLineBreak(e){let t=this.tokens.length;if(t>0&&e&&e>0){let n=t-1;for(;this.tokens[n]&&(this.tokens[n]instanceof fi||qi.test(this.tokens[n].value));)n--;for(;e&&this.tokens[n]&&this.tokens[n]instanceof V;)n--,e--;for(;e-->0;)this.tokens.push(new V)}}},Yi=/^<\/([a-zA-Z0-9]+)([^>]*)>/,Xi=/^<([a-zA-Z0-9]+)((?:\s[^=\s/]+(?:\s*=\s*(?:"[^"]+"|'[^']+'|[^>\\s]+))?)+)?\s*(\/?)>(\n*)/,Zi=/^<!--(.+?)-->/,Qi=/&(?:#(\d\d{2,})|#x([\da-fA-F]{2,})|([a-zA-Z][a-zA-Z1-4]{1,8}));/g,$i={b:e=>e.weight=700,strong:e=>e.weight=700,i:e=>e.style=`italic`,em:e=>e.style=`italic`,dfn:e=>e.style=`italic`,cite:e=>e.style=`italic`,code:e=>e.family=`monospace`,kbd:e=>e.family=`monospace`,samp:e=>e.family=`monospace`,var:e=>e.family=`monospace`,tt:e=>e.family=`monospace`,sub:e=>{e.baseline=Ui,e.sizeAdjust=Gi},sup:e=>{e.baseline=Wi,e.sizeAdjust=Gi}},ea={div:1,li:1,blockquote:2,h1:2,h2:2,h3:2,h4:2,h5:2,h6:2,ul:2,ol:2,hr:2,p:2};function ta(e){return e.replace(Qi,function(e,t,n,r){if(t||n){let e=t?10:16;return String.fromCharCode(parseInt(t||n,e))}else if(r in Hi)return Hi[r];return e})}function na(e){return e&&e.length>1&&(e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`))?e.slice(1,-1):e}var ra=/^\s*([^=\s&]+)(?:\s*=\s*("[^"]+"|'[^']+'|[^>\s]+))?/;function ia(e){let t,n={};if(e){do if(t=ra.exec(e),t){let r=ta(na(t[2]||``)).replace(/[ \r\n\t]+/g,` `).trim();if(n[t[1]]=r,e=e.slice(t[0].length),e.length&&/^\S/.test(e[0]))throw Error(`Attribute error`)}while(t&&e.length);if(/\S/.test(e))throw Error(`Attribute error`)}return n}function aa(e){e=String(e||``).trim();let t,n,r=new Ji;for(;e.length;){if(t=/^[^<]+/.exec(e))Vi(ta(t[0])).forEach(e=>r.add_token(e));else if(!(t=Zi.exec(e)))if(t=Yi.exec(e))r.close_context(),r.maybeLineBreak(ea[t[1]]);else if(t=Xi.exec(e)){let e=t[1];r.maybeLineBreak(ea[e]),r.open_context(),$i[e]&&$i[e].call(r,r.props);let i=ia(t[2]);e===`a`&&r.setProps({href:i.href,rel:i.rel,target:i.target}),i.class&&(r.props.class=r.props.class?r.props.class+` `+i.class:i.class),i.style&&(n=/(?:^|\s|;)color\s*:\s*([^;\s"']+)/.exec(i.style),n&&n[1]&&(r.props.color=n[1])),e===`br`&&r.tokens.push(new V)}else t=[e.slice(0,1)],r.add_token(new B(t[0]));e=e.slice(t[0].length)}return r.trimEnd(),r.tokens}var oa={copyright:`©`,textcopyright:`©`,dag:`†`,textdagger:`†`,ddag:`‡`,textdaggerdbl:`‡`,guillemotleft:`«`,guillemotright:`»`,guilsinglleft:`‹`,guilsinglright:`›`,ldots:`…`,dots:`…`,textellipsis:`…`,lq:`‘`,P:`¶`,textparagraph:`¶`,pounds:`£`,textsterling:`£`,quotedblbase:`„`,quotesinglbase:`‚`,rq:`’`,S:`§`,sim:`~`,textasciicircum:`^`,textasciitilde:`˜`,texttildelow:`~`,textasteriskcentered:`*`,textbackslash:`'`,textbar:`|`,textbardbl:`╎`,textbigcircle:`◯`,textbraceleft:`{`,textbraceright:`}`,textbullet:`•`,textdollar:`$`,textemdash:`—`,textendash:`—`,texteuro:`€`,eurosym:`€`,euro:`€`,textexclamdown:`¡`,textgreater:`>`,textless:`<`,textordfeminine:`ª`,textordmasculine:`º`,textperiodcentered:`·`,cdot:`·`,textquestiondown:`¿`,textquotedblleft:`“`,textquotedblright:`”`,textquoteleft:`‘`,textquoteright:`’`,textquotestraightbase:`‚`,textquotestraightdblbase:`„`,textregistered:`®`,textthreequartersemdash:`-`,texttrademark:`™`,texttwelveudash:`-`,textunderscore:`_`,textvisiblespace:`␣`,gets:`←`,textleftarrow:`←`,to:`→`,textrightarrow:`→`,textdegree:`°`,infty:`∞`,triangle:`△`,triangledown:`▽`,blacktriangle:`▲`,blacktriangledown:`▼`,angle:`∠`,sphericalangle:`∢`,aleph:`ℵ`,hbar:`ħ`,imath:`𝚤`,jmath:`𝚥`,ell:`ℓ`,wp:`℘`,Re:`ℜ`,Im:`ℑ`,mho:`℧`,prime:`′`,emptyset:`∅`,nabla:`∇`,surd:`√`,partial:`∂`,top:`⟙`,bot:`⟂`,vdash:`⟝`,dashv:`⟞`,forall:`∀`,exists:`∃`,nexists:`∄`,neg:`¬`,lnot:`¬`,flat:`♭`,natural:`♮`,sharp:`♯`,backslash:`\\`,Box:`□`,Diamond:`♢`,clubsuit:`♣`,diamondsuit:`♦`,heartsuit:`♥`,spadesuit:`♠`,Join:`⨝`,blacksquare:`■`,bigstar:`★`,diagdown:`╲`,diagup:`╱`,blacklozenge:`⧫`,rfloor:`⌋`,lfloor:`⌊`,rceil:`⌉`,lceil:`⌈`,rangle:`⟩`,langle:`⟨`,sum:`∑`,int:`∫`,oint:`∮`,prod:`∏`,coprod:`∏`,bigcap:`∩`,bigcup:`∪`,bigsqcup:`⊔`,bigvee:`∨`,bigwedge:`∧`,bigodot:`⊙`,bigotimes:`⊗`,bigoplus:`⊕`,biguplus:`⊎`,alpha:`α`,beta:`β`,chi:`χ`,delta:`δ`,epsilon:`ε`,eta:`η`,gamma:`γ`,iota:`ι`,kappa:`κ`,lambda:`λ`,mu:`μ`,nu:`ν`,omega:`ω`,phi:`φ`,pi:`π`,psi:`ψ`,rho:`ρ`,sigma:`σ`,tau:`τ`,theta:`θ`,upsilon:`υ`,xi:`ξ`,zeta:`ζ`,Alpha:`Α`,Beta:`Β`,Chi:`Χ`,Delta:`Δ`,Epsilon:`Ε`,Eta:`Η`,Gamma:`Γ`,Iota:`Ι`,Kappa:`Κ`,Lambda:`Λ`,Mu:`Μ`,Nu:`Ν`,Omega:`Ω`,Phi:`Φ`,Pi:`Π`,Psi:`Ψ`,Rho:`Ρ`,Sigma:`Σ`,Tau:`Τ`,Theta:`Θ`,Upsilon:`Υ`,Xi:`Ξ`,Zeta:`Ζ`,aa:`å`,AA:`Å`,ae:`æ`,AE:`Æ`,dh:`ð`,DH:`Ð`,dj:`đ`,DJ:`Đ`,ij:`ij`,IJ:`IJ`,l:`ł`,L:`Ł`,ng:`ŋ`,NG:`Ŋ`,o:`ø`,O:`Ø`,oe:`œ`,OE:`Œ`,ss:`ß`,SS:`SS`,th:`þ`,TH:`Þ`},sa=/^(\^|_|\\[^#$%&~_^\\{}()\s]+)(\{)?/,ca=/^%[^\n]+(?:\n|$)/,la=/^[^#$%&~_^\\{}]+/,ua=/^\\([&{}$%#_])/,da=/(?:\\[\\@,!:;-]|-{2,3}|[!?]`|``?|,,|''?|~|<<|>>)/g,fa={"---":`—`,"--":`–`,"!`":`¡`,"?`":`¿`,"``":`“`,",,":`„`,"''":`”`,"`":`‘`,"'":`’`,"<<":`«`,">>":`»`,"~":`\xA0`,"\\-":`­`,"\\,":` `,"\\;":` `,"\\:":` `,"\\!":` `,"\\@":``,"\\\\":`\\newline{}`},H={bf:e=>e.weight=700,emph:e=>{e.style===`italic`?e.style=`normal`:e.style=`italic`},it:e=>e.style=`italic`,sl:e=>e.style=`italic`,color:(e,t)=>e.color=t,href:(e,t)=>e.href=t,"^":e=>{e.baseline=Wi,e.sizeAdjust=Gi},_:e=>{e.baseline=Ui,e.sizeAdjust=Gi},par:function(){this.tokens.push(new V,new V)},newline:function(){this.tokens.push(new V)},url:function(e,t){this.open_context(),this.props.href=t,this.add_token(new B(t)),this.close_context()}};H.textsuperscript=H[`^`],H.textsubscript=H._,H.textsl=H.sl,H.mathbf=H.bf,H.mathit=H.it,H.textbf=H.bf,H.textit=H.it,H.textcolor=H.color;function pa(e){e=String(e||``).trim();let t=[``];e=e.replace(/\\verb,(.*?),/,(e,n)=>(t.push(n),`\\verb,`+(t.length-1)+`,`)).replace(/\\\\\n/g,()=>`\\\\`).replace(da,(e,t,n)=>n.charAt(t-1)===`\\`?e:fa[e]).replace(/\n\s+/g,e=>e.slice(1).includes(`
2
+ `)?`\\par `:e).replace(/\\symbol\{(\d+)\}/,(e,t,n,r)=>r.charAt(n-1)===`\\`?e:String.fromCharCode(1*t)).replace(/(^|[^\\])(\^|_)(\d|[^{]\S*)/g,(e,t,n,r)=>t+n+`{`+r+`}`).replace(/\\verb,(.*?),/,(e,n)=>`\\verb,${t[+n]},`);let n=new Ji,r;for(;e.length;){if(r=la.exec(e))Vi(r[0]).forEach(e=>n.add_token(e));else if(r=ua.exec(e))n.add_token(new B(r[1]));else if(!(r=ca.exec(e))){if(r=/^\{/.exec(e))n.open_context();else if(r=/^\}/.exec(e))n.close_context();else if(!(r=/^\$/.exec(e)))if(r=/^\\verb,([^,]+),/.exec(e))n.add_token(new B(r[1]));else if(r=sa.exec(e)){let t=r[1].slice(1)||r[1],i=!!r[2];if(/^(La)?TeX$/i.test(t)){n.open_context(),n.props.family=`serif`;let e;t===`LaTeX`&&(e=n.add_token(new B(`L`)),e.font=Object.create(e.font),e.font.tracking=-.25,e=n.add_token(new B(`A`)),e.font=Object.create(e.font),e.font.sizeAdjust=.7,e.font.baseline=.3,e.font.tracking=-.1),e=n.add_token(new B(`T`)),e.font=Object.create(e.font),e.font.tracking=-.17,e=n.add_token(new B(`E`)),e.font=Object.create(e.font),e.font.baseline=-.22,e.font.tracking=-.13,e=n.add_token(new B(`X`)),n.close_context()}else if(t in oa)n.add_token(new B(oa[t])),i&&n.open_context();else if(t in H){let a=[],o=Math.max(0,H[t].length-1),s;if(o){for(i=!1,e=e.slice(r[0].length-1);o--;)if(s=/^\{([^}]+)\}/.exec(e))a.push(s[1]),e=e.slice(s[0].length);else throw Error(t+` is missing an argument`);r[0]=/^\{/.exec(e)?`{`:``,i=!!r[0]}i&&n.open_context(),H[t].apply(n,[n.props,...a])}else n.add_token(new B(r[1])),i&&n.open_context()}else r=[e.slice(0,1)],n.add_token(new B(r[0]))}e=e.slice(r[0].length)}return n.tokens}var U={overflow:`ellipsis`,overflowWrap:`normal`,overflowLine:``,align:`left`,valign:`top`,width:1/0,height:1/0,x:0,font:`12px/14px sans-serif`},ma=class e{static createElement=Mi;static defaultparser=Vi;static measureText=di;static setMeasureCanvas=ui;props;constructor(t){this.props={overflow:t?.overflow??U.overflow,overflowWrap:t?.overflowWrap??U.overflowWrap,overflowLine:t?.overflowLine??U.overflowLine,align:t?.align??U.align,valign:t?.valign??U.valign,width:t?.width??U.width,height:t?.height??U.height,x:t?.x??U.x,font:t?.font??U.font,parser:t?.parser??e.defaultparser,createElement:t?.createElement??e.createElement},t?.parser&&this.parser(t.parser)}linebreak(e){return yi(this.props.parser(String(e).trim()),this.props)}font(e){return arguments.length?(this.props.font=e??U.font,this):this.props.font||U.font}overflow(e){return arguments.length?(this.props.overflow=e??U.overflow,this):this.props.overflow}overflowLine(e){return arguments.length?(this.props.overflowLine=e??U.overflowLine,this):this.props.overflowLine}overflowWrap(e){if(!arguments.length)return this.props.overflowWrap;let t=String(e).toLowerCase();return this.props.overflowWrap=t===`break-word`?t:U.overflowWrap,this}valign(e){return arguments.length?(this.props.valign=e??U.valign,this):this.props.valign}align(e){return arguments.length?(this.props.align=e??U.align,this):this.props.align}width(e){return arguments.length?(this.props.width=e??U.width,this):this.props.width}height(e){return arguments.length?(this.props.height=e??U.height,this):this.props.height}x(e){return arguments.length?(this.props.x=e??U.x,this):this.props.height}parser(t){return arguments.length?(t===`html`?this.props.parser=aa:t===`text`?this.props.parser=Vi:t===`latex`?this.props.parser=pa:this.props.parser=t??e.defaultparser,this):this.props.parser}createElement(t){return arguments.length?(this.props.createElement=t??e.createElement,this):this.props.createElement}renderSVG(e){return wi(typeof e==`string`?this.linebreak(e):e,this.props)}renderCanvas(e,t){let n=typeof e==`string`?this.linebreak(e):e;if(t instanceof CanvasRenderingContext2D)Di(n,this.props,t);else{let e=t.getContext(`2d`);e instanceof CanvasRenderingContext2D&&Di(n,this.props,e)}}render(e,t){let n=typeof e==`string`?this.linebreak(e):e;return t?this.renderCanvas(n,t):this.renderSVG(n)}},ha=[`sans-serif`,`serif`,`cursive`,`monospace`,`fantasy`],ga=`Abadi,Arial,Abadi Extra Light,Helvetica Light,Abadi MT Condensed Extra Bold,Abadi MT Condensed Light,Academy Engraved LET,Colonna MT,Academy Engraved LET PLAIN:1.0,Akzidenz Grotesk,Helvetica Neue,AkzidenzGroteskBQ-Ext,Amatic SC,Chalkboard,American Typewriter,Courier,American Typewriter Condensed,American Typewriter Light,Andale Mono,Lucida Console,Andale Mono WT,Angsana New,Times New Roman,Apple Chancery,Bradley Hand ITC,Apple SD Gothic Neo,MS Gothic,Apple SD Gothic Neo Regular,AppleGothic,Century Gothic,Apple Gothic,AppleGothic Regular,AppleMyungio,Aptos,Aptos Display,Aptos Mono,Aptos Narrow,Calibri,Aptos Serif,Century,Arial Nova,Arial Black,Arial Narrow,Arial Rounded,Arial Rounded MT,Arial Rounded MT Bold,Arvo,Roboto Slab,Avant Garde,Avantgarde,Avenir,Museo Sans,Avenir Next,Avenir Next Regular,Avenir Book,Avenir Next Condensed Regular,Bahnschrift,DIN 1451,Baskerville,Big Caslon,Baskerville Old Face,Bauhaus 93,Futura,Beirut,Beirut Regular,Bell MT,Bodoni MT,Berlin Sans FB,Verdana,Bernard MT Condensed,Big Caslon Medium,Bitstream Vera Sans Mono,Consolas,BlinkMacSystemFont,Roboto,Bodoni Moda,Didot,Bodoni,Bodoni 72 Book,Bodoni 72 Oldstyle Book,Bodoni 72 Smallcaps Book,Book Antiqua,Palatino,Bookman Old Style,PT Serif,Tempus Sans ITC,Bradley Hand Bold,Braggadocio,Britannic,Lucida Grande,Britannic Bold,Brush Script,Brush Script MT,Brush Script MT Italic,Cabin,Tahoma,Caladea,Hoefler Text,Carlito,Calibri Light,Carlito Light,Calisto MT,Cambria,Cambria Math,Candara,Segoe,Canela Text,Canela Text Regular,Caveat,CenturyGothic,Century Schoolbook,Comic Sans MS,Chalkboard SE Regular,Chalkboard SE,Chalkduster,Charcoal,Helvetica Inserat,Charter Roman,Chivo,Helvetica,Cochin,Comfortaa,ComicSansMS,Comic Sans MS Bold,Comic Sans Pro,monaco,Constantia,Lucida Bright,Constantina,Cooper Black,Cooper,Copperplate,Copperplate Gothic Light,Copperplate Gothic Bold,Copperplate Light,Corbel,Cordia New,CordiaUPC,Corsiva,Lucida Handwriting,Corsiva Hebrew,Liberation Mono,Courier New,Courier Prime,Curlz MT,Party LET,Damascus,Damascus Regular,David,DecoType Naskh,DecoType Naskh Regular,Dejavu Sans,DejaVu Sans Condensed,DejaVu Sans Mono,Desdemona,Didot LT STD,DIN,DIN Alternate,DIN Alternate Bold,DIN Condensed,DIN Condensed Bold,DM Sans,Domine,Droid Sans,Myriad,Droid Serif,Liberation Serif,Edwardian Script ITC,Savoye LET,Engravers MT,Eurostile,Franklin Gothic,Fira Sans,Footlight MT,Footlight MT Light,Franklin Gothic Medium,ITC Franklin Gothic,Franklin Gothic Book,Frutiger,Frutiger Linotype,Trebuchet MS,Futura Medium,Gabriola,Garamond,EB Garamond,Geneva,Georgia,Georgia Pro,Gigi,Gill Sans,Gill Sans MT,Gill Sans Nova,Gill Sans Condensed,Gill Sans MT Condensed,Gill Sans Nova Cond,Gill Sans MT Ext Condensed Bold,Gill Sans Light,Gill Sans MT Light,Gill Sans Nova Light,Gill Sans Ultra Bold,Gill Sans Nova Ultra Bold,Gloucester MT,Lucida Sans,Gloucester MT Extra Condensed,Gotham Rounded,GothamRounded-Medium,Goudy Old Style,Haettenschweiler,Harrington,Liberation Sans,Helvetica Neue Condensed,Helvetica Neue Condensed Bold,Helvetica Neue Light,Herculanum,Papyrus,Impact,Imprint MT Shadow,Ink Free,Segoe Print,Inter,helvetica,Jokerman,Josefin Sans,futura,Juice ITC,Jumble,Kannada MN,Optima,Kefa,Rockwell Nova,Kefa Regular,Kino MN,Kristen ITC,Latha,Libre Baskerville,Libre Franklin,Lobster,Lora,Lucida Blackletter,Lucidabright,Lucida Calligraphy,Lucida Calligraphy Italic,Lucida Fax,Lucida Fax Regular,Lucida Sans Unicode,Monotype Corsiva,Lucida Handwriting Italic,Lucida Sans Regular,Lucida Sans Typewriter,Lucida Sans Typewriter Regular,Luminari,Marker Felt,Mistral,Marker Felt Thin,Marlett,Matura MT Script Capitals,Zapfino,Menlo,Menlo Regular,Merriweather,Microsoft Himalaya,Microsoft Sans Serif,Modern No. 20,Moderne Fractur,Monaco,Montserrat,Roboto Sans,MS Mincho,MS UI Gothic,Myriad Pro,Neue Haas Grotesk Text Pro,News Gothic MT,Noteworthy,Noteworthy Light,Nunito,Onyx,Open Sans,Segoe UI,Open Sans Medium,Optima Regular,Oswald,Overpass,Pacifico,Palatino Linotype,Party LET Plain,Perpetua,Phosphate,Playfair Display,Poppins,Proxima Nova,Proxima Nova Extrabold,Proxima Nova Light,PT Mono,PT Sans,PT Sans Caption,PT Serif Caption,Publico Text,PublicoText-Roman,Raleway,Roboto Mono,Rockwell Condensed,Rockwell Extra Bold,Rockwell,Rockwell Nova Cond,Rockwell Nova Extra Bold,Rockwell Nova Light,Rubik,Savoye LET Plain:1.0,Script MT,Script MT Bold,Segoe Historic,Segoe Print Bold,Segoe Script,Segoe Script Bold,Segoe Symbol,SignPainter,SignPainter-HouseScript,Skia,Snap ITC,Snell Roundhand,Source Sans Pro,Source Sans Pro Regular,Source Serif Pro,Space Mono,Spectral,Stencil,Symbol,Syncopate,Times,Trattatello,Ubuntu,Univers,Univers Condensed,Univers Light,Verdana Pro,Verdana Pro Black,Verdana Pro Cond,Westminster,OCR-A,Wide Latin,Work Sans`.split(`,`),_a=[[0,1,0],[2,3,0],[4,null,0],[5,1,0],[6,7,1,8],[8,7,1,6],[9,10,0,9,11],[9,10,0,9,11],[11,10,0,9,9],[12,13,2],[14,15,3],[16,null,3],[17,15,3],[18,19,3,20],[20,19,3,18],[21,22,1],[23,24,2],[25,26,0,27],[27,26,0,25],[28,29,0,30,31],[30,29,0,28,31],[31,29,0,28,30],[32,22,1],[33,1,0],[34,26,0],[35,18,3],[36,37,0],[38,39,1],[1,10,0,40],[40,10,0,1],[41,1,0],[42,1,0],[40,1,0],[43,1,0,44,45],[44,1,0,43,45],[45,1,0,43,44],[46,47,0],[48,29,0,49],[49,29,0,48],[50,51,0,52,53,54],[52,51,0,50,53,54],[53,51,0,50,52,54],[54,51,0,50,52,53],[55,null,0],[56,57,0],[58,59,1],[60,58,1],[61,62,0],[63,null,1,64],[64,null,1,63],[65,66,1],[67,68,0],[69,57,0],[59,22,1],[70,59,1],[71,72,3],[73,74,0],[75,66,1],[66,76,1,77,78,79,80],[77,76,1,66,78,79,80],[78,76,1,66,77,79,80],[79,76,1,66,77,78,80],[80,76,1,66,77,78,79],[81,82,1],[83,84,1],[24,85,2,86],[86,85,2,24],[87,null,0],[88,89,0,90],[90,89,0,88],[91,null,2,92,93],[92,null,2,91,93],[93,null,2,91,92],[94,95,0],[96,97,1],[37,98,0],[99,100,0],[101,82,1],[102,96,1,103],[103,96,1,102],[104,105,0],[106,81,1,107],[107,81,1,106],[98,104,0],[108,13,2],[39,null,1],[29,28,0,109],[109,28,0,29],[110,39,1],[13,111,2,112,113],[112,111,2,13,113],[113,111,2,13,112],[114,13,2],[115,116,0],[117,null,1],[118,119,0],[120,58,1],[7,6,1],[121,62,0],[111,13,2,122,123,124],[122,13,2,111,123,124],[123,13,2,111,122,124],[124,13,2,111,122,123],[72,125,3],[126,127,1],[128,127,1],[129,null,1,130],[130,null,1,129],[131,132,4],[133,131,4],[132,131,4],[134,132,4],[135,89,0],[136,119,0,137],[137,119,0,136],[138,139,2,140],[140,139,2,138],[15,141,3,142],[142,141,3,15],[143,15,3],[144,145,4],[146,null,0,147],[147,null,0,146],[148,22,1],[149,null,1,150],[150,null,1,149],[151,10,0],[152,68,0],[153,71,3],[154,null,4],[76,97,1,155],[155,97,1,76],[57,56,0,156,157,158],[156,56,0,57,157,158],[157,56,0,57,156,158],[158,56,0,57,156,157],[159,57,0,160],[160,57,0,159],[161,73,0],[162,101,1],[163,164,0],[165,166,1],[167,168,2],[169,null,1],[170,171,0],[172,119,0],[173,null,1,174],[174,null,1,173],[171,30,0,175,176,177],[175,30,0,171,176,177],[176,30,0,171,175,177],[177,30,0,171,175,176],[178,151,0,179],[179,151,0,178],[62,180,0,181],[181,180,0,62],[182,139,2],[183,81,1,184],[184,81,1,183],[185,95,0],[186,22,1,187],[187,22,1,186],[188,null,2],[189,37,0,190,191],[190,37,0,189,191],[191,37,0,189,190],[192,null,0,193,194,195],[193,null,0,192,194,195],[194,null,0,192,193,195],[195,null,0,192,193,194],[196,null,0,197,198],[197,null,0,196,198],[198,null,0,196,197],[199,null,0,200],[200,null,0,199],[201,202,1,203],[203,202,1,201],[204,43,0,205],[205,43,0,204],[206,183,1],[207,115,0],[208,144,4],[119,209,0],[116,41,0],[3,null,0],[10,119,0],[210,null,0,211],[211,null,0,210],[212,3,0],[213,214,4],[97,166,1],[215,207,0],[216,6,1],[217,218,2],[219,220,0],[221,145,2],[222,223,0],[224,null,1],[225,111,2],[226,227,0],[228,229,1,230],[230,229,1,228],[231,null,0],[232,218,2],[233,null,0],[141,125,3],[209,1,0],[166,22,0],[234,58,1],[235,171,0],[236,91,2],[237,82,1],[238,null,4],[127,38,1,239],[239,38,1,127],[240,139,2,241],[241,139,2,240],[19,71,3],[242,127,1,243],[243,127,1,242],[89,244,0],[139,245,2,246],[246,245,2,139],[202,185,0,247],[247,185,0,202],[248,19,3,249],[249,19,3,248],[244,202,0],[250,null,4],[251,252,2,253],[253,252,2,251],[254,92,2],[255,256,4],[257,19,0,258],[258,19,0,257],[259,82,1],[260,22,1],[261,10,0],[252,92,2],[262,110,1],[263,238,4],[264,19,3],[245,24,2],[265,266,0],[26,null,0],[267,null,1],[268,null,0],[51,29,0],[164,178,0,269],[269,178,0,164],[270,10,0],[271,171,0],[272,218,4,273],[273,218,4,272],[274,74,0],[275,null,1],[276,277,0],[278,277,0],[227,105,0,279],[279,105,0,227],[280,5,0],[281,119,0],[282,null,2],[82,283,1],[283,183,1],[214,null,4],[284,221,4,145],[145,221,4,284],[285,58,1],[286,62,0],[287,66,1],[288,89,0],[289,265,0],[290,null,0],[291,null,0],[292,18,3],[293,null,0],[294,null,0],[84,null,1],[295,null,1],[296,null,1,297],[297,null,1,296],[298,1,0],[74,119,0,266],[266,119,0,74],[299,72,3],[47,229,0],[300,null,1],[301,null,1],[229,171,1,302],[302,171,1,229],[303,null,1],[304,null,1],[305,null,1],[306,1,0],[168,139,2,307],[307,139,2,168],[308,139,2,309],[309,139,2,308],[310,119,0],[218,218,2,311],[311,218,2,218],[312,111,2,313],[313,111,2,312],[314,null,0],[277,178,0,105],[105,178,0,277],[315,null,2,316],[316,null,2,315],[317,null,0],[318,null,1],[319,168,2],[320,74,0,321],[321,74,0,320],[322,186,1],[323,15,3],[324,22,0],[325,null,1],[326,22,1],[327,62,0],[95,152,0],[85,139,2],[328,22,0],[22,166,1,328],[328,166,1,22],[329,null,4],[180,89,0],[330,37,0],[331,null,0],[332,null,0],[333,null,0],[68,185,0],[334,185,0],[335,null,0],[336,null,0],[337,338,3],[339,null,1],[340,89,0],[256,null,2]].map(e=>({name:ga[e[0]],next:e[1]?ga[e[1]]:null,type:ha[e[2]],alt:e.slice(3).filter(e=>e!==null).map(e=>ga[e])})),va=new Map;function ya(e,t=`sans-serif`){if(!e)return t;let n=va.get(e);if(n)return n;let r=ba(e);return va.set(e,r),r}function ba(e){e=e.replace(/\(\w+\)/i,``).trim();let t=``,n=new Set,r=e=>{let i=e&&_a.find(t=>t.name.toLowerCase()===e.toLowerCase());i&&(t||=i.type,n.add(i.name),i.alt&&i.alt.forEach(e=>n.add(e)),i.next&&!n.has(i.next)&&r(i.next))};return r(e),t&&n.add(t),n.size||n.add(e),Array.from(n).map(e=>/[ ,]/.test(e)?`"`+e+`"`:e).join(`, `)}var W=class e{x;y;width;height;constructor(e,t,n,r){if(!isFinite(e)||!isFinite(t)||!isFinite(n)||!isFinite(r))throw Error(`Invalid Rect coords: x=${e}, y=${t}, w=${n}, h=${r}`);this.x=e,this.y=t,this.width=n,this.height=r}get top(){return this.y}get left(){return this.x}get bottom(){return this.y+this.height}get right(){return this.x+this.width}get size(){return[this.width,this.height]}equals(e){return this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height}intersects(e){return!(this.x>e.right||this.right<e.x||this.y>e.bottom||this.bottom<e.y)}contains(e){return e.x>=this.x&&e.y>=this.y&&e.right<=this.right&&e.bottom<=this.bottom}resize(t,n){return new e(this.x,this.y,t,n)}translate(t=0,n=0){return new e(this.x+t,this.y+n,this.width,this.height)}getTopEdge(){return[[this.x,this.y],[this.x+this.width,this.y]]}getBottomEdge(){return[[this.x,this.y+this.height],[this.x+this.width,this.y+this.height]]}getLeftEdge(){return[[this.x,this.y],[this.x,this.y+this.height]]}getRightEdge(){return[[this.x+this.width,this.y],[this.x+this.width,this.y+this.height]]}getBorders(){let{x:e,y:t}=this,n=e+this.width,r=t+this.height;return[[[e,t],[n,t],[12,6]],[[n,t],[n,r],[3,6]],[[e,r],[n,r],[9,3]],[[e,t],[e,r],[9,12]]]}};const G=2**14-1,xa=2**20-1;var Sa=class e{range;workbookName;sheetName;constructor(t,n){if(t instanceof e)this.workbookName=t.workbookName||n?.workbookName||``,this.sheetName=t.sheetName||n?.sheetName||``,this.range=Object.assign({},t.range);else if(typeof t==`string`){let e=Wr(t);if(!e||!(`range`in e)||!e.range)throw Error(`Not a valid reference: ${t}`);this.workbookName=e.workbookName||n?.workbookName||``,this.sheetName=e.sheetName||n?.sheetName||``,this.range={top:e.range.top||0,left:e.range.left||0,bottom:e.range.bottom||e.range.top||0,right:e.range.right||e.range.left||0}}else this.workbookName=n?.workbookName||``,this.sheetName=n?.sheetName||``,this.range=Object.assign({top:0,left:0,right:0,bottom:0},t);let r=this.range;if(r.left<0||r.left>G||r.right<0||r.right>G||r.top<0||r.top>xa||r.bottom<0||r.bottom>xa)throw Error(`Not a valid reference: ${String(t)}`)}get left(){return this.range.left}get right(){return this.range.right}get top(){return this.range.top}get bottom(){return this.range.bottom}get height(){return this.range.bottom-this.range.top+1}get width(){return this.range.right-this.range.left+1}toString(){return Ur({range:this.range,workbookName:this.workbookName,sheetName:this.sheetName})}};const Ca=65536,wa=16383,Ta=1048575;function K(e,t){return(e&wa)*1+(t&Ta)*Ca}function Ea(e){return[e/1&wa,e/Ca&Ta]}const Da={style:`none`,color:`none`},Oa={style:`hair`,color:`#d8d9e5`};var q=class e{static TOP=`T`;static LEFT=`L`;static BOTTOM=`B`;static RIGHT=`R`;_;constructor(){this._=new Map}clear(){this._.clear()}set(t,n,r){let[i,a]=t;if(n===e.BOTTOM)this.set([i,a+1],e.TOP,r);else if(n===e.RIGHT)this.set([i+1,a],e.LEFT,r);else if(n===e.LEFT||n===e.TOP){let i=K(t[0],t[1]),a=this._.get(i);a||(a={[e.TOP]:Da,[e.LEFT]:Da},this._.set(i,a)),r==null||r.style===`none`?a[n]=Da:a[n]=r}}get(t,n){if(n===e.BOTTOM)return this.get([t[0],t[1]+1],e.TOP);if(n===e.RIGHT)return this.get([t[0]+1,t[1]],e.LEFT);if(n===e.LEFT||n===e.TOP){let e=K(t[0],t[1]),r=this._.get(e);if(r&&r[n])return r[n]}return Da}isSet(e,t){let n=this.get(e,t).style;return n!==`none`&&n!==`hair`}getJoin(t,n){let r=0;return this.isSet([t,n],e.TOP)&&(r|=8),this.isSet([t,n],e.LEFT)&&(r|=4),this.isSet([t-1,n],e.TOP)&&(r|=2),this.isSet([t,n-1],e.LEFT)&&(r|=1),r}forEach(t){for(let[n,r]of this._.entries()){let i=Ea(n),a=r[e.TOP];a&&a.color!==`none`&&a.style!==`none`&&t(i,e.TOP,a);let o=r[e.LEFT];o&&o.color!==`none`&&o.style!==`none`&&t(i,e.LEFT,o)}}*[Symbol.iterator](){for(let[t,n]of this._.entries()){let r=Ea(t),i=n[e.TOP];i&&i.color!==`none`&&i.style!==`none`&&(yield[r,e.TOP,i]);let a=n[e.LEFT];a&&a.color!==`none`&&a.style!==`none`&&(yield[r,e.LEFT,a])}}fillGridLines(t){let[n,r]=t[0],[i,a]=t[1];for(let t=n;t<=i;t++)for(let n=r;n<=a;n++)this.set([t,n],e.TOP,Oa),this.set([t,n],e.LEFT,Oa)}};function ka(e){return Aa(e.v)}function Aa(e){return e&&typeof e==`object`}const ja=`#282b3e`,Ma=`#f5f5f5`,Na=`#d8d9e5`,Pa={fontFamily:`Calibri`,fontSize:11},Fa={...Pa,color:ja},Ia={...Pa,fillColor:Ma,color:ja,borderTopColor:Na,borderTopStyle:`medium`,borderBottomColor:Na,borderBottomStyle:`medium`,borderLeftColor:Na,borderLeftStyle:`medium`,borderRightColor:Na,borderRightStyle:`medium`,horizontalAlignment:`center`,verticalAlignment:`bottom`,fontSize:11},La={fillColor:Ma,patternColor:Na,patternStyle:`lightDown`},Ra={name:`Office`,colorScheme:{name:`Office`,dk1:{type:`system`,value:`windowText`},lt1:{type:`system`,value:`window`},dk2:{type:`srgb`,value:`44546A`},lt2:{type:`srgb`,value:`E7E6E6`},accent1:{type:`srgb`,value:`4472C4`},accent2:{type:`srgb`,value:`ED7D31`},accent3:{type:`srgb`,value:`A5A5A5`},accent4:{type:`srgb`,value:`FFC000`},accent5:{type:`srgb`,value:`5B9BD5`},accent6:{type:`srgb`,value:`70AD47`},hlink:{type:`srgb`,value:`0563C1`},folHlink:{type:`srgb`,value:`954F72`}},fontScheme:{name:`Office`,major:{latin:{typeface:`Aptos Display`},eastAsian:{typeface:``},complexScript:{typeface:``}},minor:{latin:{typeface:`Aptos Narrow`},eastAsian:{typeface:``},complexScript:{typeface:``}}}},za=[`color`,`fillColor`,`patternColor`,`borderTopColor`,`borderLeftColor`,`borderBottomColor`,`borderRightColor`];var Ba=class{_;constructor(){this._=new Map}clear(){this._.clear()}setMerges(e){this.clear();for(let t of e){let e=c(t);if(!e||e.left==null||e.top==null||e.bottom==null||e.right==null)continue;let n=K(e.left,e.top),r=Object.freeze({top:e.top,left:e.left,bottom:e.bottom,right:e.right});this._.set(n,r)}}find(e,t){for(let n of this)if(n.left<=e&&n.right>=e&&n.top<=t&&n.bottom>=t)return n}*[Symbol.iterator](){for(let e of this._.values())yield e}getByCellId(e){if(e){let t=c(e);if(t&&t.left!=null&&t.top!=null){let e=K(t.left,t.top);return this._.get(e)??null}}return null}};function Va(e,t=!1){let[n,r]=e.getSize();if(e.merged_cells.forEach(e=>{let t=c(e);t&&t.right!=null&&t.right>=n&&(n=t.right+1),t&&t.bottom!=null&&t.bottom>=r&&(r=t.bottom+1)}),t){if(e.columns&&e.columns.length){let t=e.columns.at(-1)?.end??1;t>n&&(n=t)}if(e.rows&&e.rows.length){let t=e.rows.at(-1)?.end??1;t>r&&(r=t)}}return[n,r]}const Ha=1.17,Ua=1.3;function Wa(e,t,n,r=1,i=!1){let a=[],o=(e,t,n,r)=>{let i={index:e-1,start:t,size:n,hidden:!1,end:t+n};return r!=null&&(i.style=r),a[e-1]=i},s=0,c=1,l=n*r;for(let t of e){for(;c<t.start;)o(c,s,l),c++,s+=l;for(c=t.start;c<=t.end;c++){let e=!t.size&&i?l:(t.size??n)*r,a=o(c,s,e,t.s);t.size||(a.hidden=!0),s+=e}}for(;c<=t;)o(c,s,l),c++,s+=l;return a}function Ga(e){for(let t=e.length-1;t>=0;t--)if(e[t].size>0)return t;return-1}var Ka=class e{defaultCellHeight=21;defaultCellWidth=76;tilt=[0,0];viewBox={top:0,left:0,bottom:xa,right:G};renderBox={top:0,left:0,bottom:xa,right:G};col;row;width;height;lastSizedColIndex=-1;lastSizedRowIndex=-1;constructor(){this.col=[],this.width=0,this.row=[],this.height=0}get viewWidth(){let e=this.getCellRect(this.viewBox.left,this.viewBox.top);return this.getCellRect(this.viewBox.right,this.viewBox.bottom).right-e.left}get viewHeight(){let e=this.getCellRect(this.viewBox.left,this.viewBox.top);return this.getCellRect(this.viewBox.right,this.viewBox.bottom).bottom-e.top}get viewLeft(){return this.getCol(this.viewBox.left).start}get viewTop(){return this.getCol(this.viewBox.left).start}get rows(){return this.row.length}get columns(){return this.col.length}_offsetDims(e,t,n){let r=Array(e);for(let i=e-1;i>=0;i--){let a=t[i]||n;i===e-1?r[i]=a:r[i]=a+r[i+1]}return r}toMeasure(e,t,n,r=10,i=1/0){if((e<0||!isFinite(e))&&(e=0),e<=n){let n=t.find(t=>e>=t.start&&e<=t.end);if(n)return n}let a=t[t.length-1],o=r<1?100:r;if(!a){let t=Math.floor(e/o);return{index:t,start:t*o,size:r,end:(t+1)*o,hidden:!1}}if(r<1||a.index>=i)return a;let s=e-a.end,c=Math.ceil(s/o)+a.index;return{index:c,start:c*o-o,size:r,end:c*o,hidden:!1}}getCol(e){let t=this.columns;if(e<t)return this.col[e];let n=0;t&&(n=this.col[t-1].end);let r=n+(e-t)*this.defaultCellWidth;return{index:e,size:this.defaultCellWidth,start:r,end:r+this.defaultCellWidth,hidden:!1}}toCol(e){return this.toMeasure(e,this.col,this.width,this.defaultCellWidth,G)}getRow(e){let t=this.rows;if(e<t)return this.row[e];let n=0;t&&(n=this.row[t-1].end);let r=n+(e-t)*this.defaultCellHeight;return{index:e,size:this.defaultCellHeight,start:r,end:r+this.defaultCellHeight,hidden:!1}}toRow(e){return this.toMeasure(e,this.row,this.height,this.defaultCellHeight,xa)}dims(e,t){let n=this.getCol(e),r=this.getRow(t);return{index:[e,t],size:[n.size,r.size],start:[n.start,r.start],end:[n.end,r.end]}}getCellRect(e,t){let n=this.getCol(e),r=this.getRow(t),i=this.getCol(this.viewBox.left),a=this.getRow(this.viewBox.top);return new W(n.start-i.start,r.start-a.start,n.size,r.size)}getColSize(e){let t=this.getCol(e),n=this.getCol(this.viewBox.left);return{index:t.index,size:t.size,hidden:!!t.hidden,start:t.start-n.start,end:t.end-n.start}}getRowSize(e){let t=this.getRow(e),n=this.getRow(this.viewBox.top);return{index:t.index,size:t.size,hidden:!!t.hidden,start:t.start-n.start,end:t.end-n.start}}rangeToRect(e){let t=this.getCol(e.left),n=e.right===e.left?t:this.getCol(e.right),r=this.getRow(e.top),i=e.top===e.bottom?r:this.getRow(e.bottom),a=this.getCol(this.viewBox.left),o=this.getRow(this.viewBox.top);return new W(t.start-a.start,r.start-o.start,n.end-t.start,i.end-r.start)}rectToRange(e){let t=this.toRow(e.top).index,n=this.toCol(e.left).index;return{top:t,left:n,bottom:e.bottom===e.top?t:Math.max(0,this.toRow(e.bottom).index),right:e.right===e.left?n:Math.max(0,this.toCol(e.right).index)}}setView(e,t,n,r){let i=new W(e,t,n,r);this.viewBox=this.rectToRange(i),this.renderBox={top:this.viewBox.top,left:this.viewBox.left,right:this._clampTail(this.viewBox.right,this.col,this.lastSizedColIndex,this.defaultCellWidth,G),bottom:this._clampTail(this.viewBox.bottom,this.row,this.lastSizedRowIndex,this.defaultCellHeight,xa)},this.tilt=[this.getCol(this.viewBox.left).start-e,this.getRow(this.viewBox.top).start-t]}_clampTail(e,t,n,r,i){let a=t[t.length-1];return r<1||a&&a.index>=i?Math.min(e,Math.max(n,0)):e}addHeights(e,t,n=16,r=!1){this.row=Wa(e,t,n,Ua,r),this.defaultCellHeight=n*Ua,this.height=this.row.at(-1)?.end||0,this.lastSizedRowIndex=Ga(this.row)}addWidths(e,t,n=65,r=!1){this.col=Wa(e,t,n,Ha,r),this.defaultCellWidth=n*Ha,this.width=this.col.at(-1)?.end||0,this.lastSizedColIndex=Ga(this.col)}static from(t,n,r=!1){let i=new e,a=n.getSheet(t.sheetName);if(a){let[e,t]=Va(a,!0);i.addHeights(a.rows??[],t,a.defaults?.rowHeight,r),i.addWidths(a.columns??[],e,a.defaults?.colWidth,r)}return i}};function*qa(e){for(let t=e.left;t<=e.right;t++)for(let n=e.top;n<=e.bottom;n++)yield[t,n]}const Ja={dashDot:{lineWidth:.5,lineDash:[7,3,3,3]},dashDotDot:{lineWidth:.5,lineDash:[7,3,3,3,3,3]},dashed:{lineWidth:.5,lineDash:[3,3,3,3]},dotted:{lineWidth:.5,lineDash:[3,3,3,3]},double:{lineWidth:.8,lineDash:null,gap:1,slant:0},hair:{lineWidth:.5,lineDash:null},medium:{lineWidth:1.5,lineDash:null},mediumDashDot:{lineWidth:2,lineDash:[7,3,3,3]},mediumDashDotDot:{lineWidth:1.5,lineDash:[7,3,3,3,3,3]},mediumDashed:{lineWidth:1.5,lineDash:[7,3]},slantDashDot:{lineWidth:1,lineDash:[7,1,3,1],gap:0,slant:.5},thick:{lineWidth:3,lineDash:null},thin:{lineWidth:.5,lineDash:null},none:{lineWidth:0,lineDash:null},default:{lineWidth:1,lineDash:null}},Ya=e=>e&&typeof e==`object`;function Xa(e){return e==null||e===``?`left`:typeof e==`boolean`||Ya(e)?`center`:typeof e==`number`?`right`:`left`}function Za(e,t){let n;if(typeof window<`u`&&`OffscreenCanvas`in window)n=new OffscreenCanvas(e,t);else if(typeof OffscreenCanvas<`u`)n=new OffscreenCanvas(e,t);else if(typeof Canvas<`u`)n=new Canvas(e,t);else if(typeof document<`u`)n=document.createElement(`canvas`),n.width=e,n.height=t;else throw Error(`No canvas implementation available`);return n}const Qa=new Map;Qa.set(`none`,[0,0,0,0]);function $a(e){let t=e.toLowerCase(),n=Qa.get(t);if(n)return n;let r=Za(1,1).getContext(`2d`);if(!r)return[0,0,0,0];r.clearRect(0,0,1,1),r.fillStyle=`#000`,r.fillStyle=e;let i=r.fillStyle;if(r.fillStyle=`#fff`,r.fillStyle=e,i!==r.fillStyle)return[0,0,0,0];r.fillRect(0,0,1,1);let a=r.getImageData(0,0,1,1).data,o=[a[0],a[1],a[2],a[3]];return Qa.set(t,o),o}function eo(e,t=null,n=null){let r=Za(8,8),i=r.getContext(`2d`);if(i){let r=p(e,$a(t??`rgba(0,0,0,1)`),$a(n??`rgba(0,0,0,0)`)),a=i.createImageData(8,8);a.data.set(r),i.putImageData(a,0,0)}return r}let J,to=1.2;const no=1.4;function ro(e=null){return e&&(J=e),J}function io(e){to=e}function ao(e,t,n=null){return e&&e[t]?e[t]:n}function oo(e){let t=ao(e,`fontSize`,11);return Math.round(t*to)}function so(e){let t=``;ao(e,`italic`,!1)===!0&&(t+=`italic `),ao(e,`bold`,!1)===!0&&(t+=`bold `);let n=oo(e);t+=n+`px/`+Math.round(n*no)+`px `;let r=ao(e,`fontFamily`,`Calibri`);return t+=ya(String(r)),t}function co(e,t){return lo(e&&typeof e==`object`?e.v:e,e?.z??``,t)}function lo(e,t,r){let i,a=typeof e;if(e==null||e===``)i=``;else if(a===`boolean`||Aa(e))i=String(e).toUpperCase();else try{i=n(t||`General`,e,{locale:r})}catch{i=`#########`}return i}function uo(e,t){if(t)try{return l(t,e,{indexColors:!0})}catch{return null}return null}function fo(e,t,n){J.restore();let r=co(e,n);return J.font=so(t||Fa),J.measureText(r).width}function po(e,t,n,r){let i=ao(r,`underline`,`none`);if(i!==`none`){let a=ao(r,`color`,ja),[o,s]=e;J.beginPath(),J.strokeStyle=String(a),J.lineWidth=.7,i===`single`?(J.translate(0,.5),J.moveTo(o,s+1),J.lineTo(o+t,s+1)):i===`singleAccounting`?(J.translate(0,.5),J.moveTo(8,s+1),J.lineTo(8+n-16,s+1)):i===`double`?(J.moveTo(o,s+2),J.lineTo(o+t,s+2),J.moveTo(o,s+.5),J.lineTo(o+t,s+.5)):i===`doubleAccounting`&&(J.moveTo(8,s+2),J.lineTo(8+n-16,s+2),J.moveTo(8,s+.5),J.lineTo(8+n-16,s+.5)),J.stroke(),J.closePath()}}function mo(e,t,n,r,i){let a=t.width-8;J.beginPath(),J.rect(.5,.5,t.width,t.height),J.clip();let o=oo(n),s=Math.round(o*no),c=new ma({width:a,font:so(n||Fa),align:r,valign:i}).linebreak(e),l=4,u=0;r===`right`?l=t.width-c.width-4:r===`center`&&(l=(t.width-c.width)/2),i===`bottom`?u=t.height-c.height:i===`center`&&(u=(t.height-c.height)/2),c.forEach((e,i)=>{let a=u+i*s+s*.5,d=0,f=e.width;r===`right`?d+=c.width-f:r===`center`&&(d+=c.width/2-f/2);let p=a+Math.floor(o*.35)+.5;po([l+d,p],f,t.width,n),J.textBaseline=`middle`,e.reduce((e,t)=>{J.font=String(t.font);let n=t.font.baseline?o*-t.font.baseline+o*.15:0;return J.fillText(t.value,e+d,a+n),e+t.width},l)})}function ho(e,t,n){let r=n.cellRect,i=n.clipRect||r,a=n.locale||`en-US`;J.save();let o=ao(t,`numberFormat`,`General`),s=lo(e,o,a);if(s){let n=Xa(e),a=ao(t,`horizontalAlignment`,n);a.toLowerCase()===`general`&&(a=n);let c=ao(t,`verticalAlignment`,`bottom`);if(J.font=so(t),J.fillStyle=uo(e,o)??String(ao(t,`color`,`#282b3e`)),ao(t,`wrapText`,!1))J.translate(r.x,r.y),mo(s,r,t,a,c);else{J.translate(i.x,i.y),J.save(),J.beginPath(),J.rect(.5,.5,i.width,i.height),J.clip(),J.closePath(),J.textBaseline=`middle`;let e=J.measureText(s).width,n=oo(t),o=n*no,l=o*.5;c===`bottom`?l=r.height-o*.5:c===`center`&&(l=r.height/2);let u=4;a===`center`?u=r.x-i.x+r.width/2-e/2:a===`right`&&(u=i.width-e-4),J.fillText(s,u,l),J.closePath();let d=l+Math.floor(n*.35)+.5;po([u,d],e,r.width,t),J.restore()}}J.restore()}function go(e,t,n,r=1,i=[],a=1){J.save(),J.globalAlpha=a??1,J.beginPath(),J.strokeStyle=n||`#d8d9e5`,J.lineWidth=r,J.setLineDash(i),J.moveTo(e[0],e[1]),J.lineTo(t[0],t[1]),J.stroke(),J.setLineDash([]),J.closePath(),J.globalAlpha=1,J.restore()}function _o(e){J.save(),J.translate(e.x,e.y),(e.width<6||e.height<6)&&(J.beginPath(),J.rect(0,0,e.width,e.height),J.clip()),J.fillStyle=`#d93025`,J.beginPath(),J.moveTo(0,0),J.lineTo(6,0),J.lineTo(0,6),J.fill(),J.restore()}function vo(e){J.save(),J.translate(e.x+e.width,e.y),(e.width<6||e.height<6)&&(J.beginPath(),J.rect(-e.width,0,e.width,e.height),J.clip()),J.fillStyle=`#fcbc03`,J.beginPath(),J.moveTo(0,0),J.lineTo(-6,0),J.lineTo(0,6),J.fill(),J.restore()}function yo(e,t,n,r,i){let a=n+r*.5,o=i?1:2,s=i?4:8,c=n,l=n,u=-n,d=-n;return e&o&&!(e&s)?l=-a:e&s&&!(e&o)?c=-a:!(e&o)&&!(e&s)&&(c=0,l=0),t&o&&!(t&s)?d=a:t&s&&!(t&o)?u=a:!(t&o)&&!(t&s)&&(u=0,d=0),[c,l,u,d]}function bo(e,t,n,r,i=0,a=0,o=1){let s=Ja[n]||Ja.thin,c=s.lineDash||[],l=s.lineWidth,u=s.slant||0,d=s.gap||(u?l*.5:0),f=r||`#282b3e`;if(d||u){let[n,r]=e,[s,p]=t;if(r===p){let[e,t,m,h]=u?[0,0,0,0]:yo(i,a,l,d,!0);go([n+u+e,r-d],[s+u+m,p-d],f,l,c,o),go([n-u+t,r+d],[s-u+h,p+d],f,l,c,o)}else{let[e,t,m,h]=u?[0,0,0,0]:yo(i,a,l,d,!1);go([n-d,r+u+e],[s-d,p+u+m],f,l,c,o),go([n+d,r-u+t],[s+d,p-u+h],f,l,c,o)}}else go(e,t,f,l,c,o)}function xo(e,t){J.save(),t.fillColor&&(J.globalAlpha=t.fillOpacity??1,J.fillStyle=t.fillColor||`transparent`,J.fillRect(e.x,e.y,e.width,e.height),J.globalAlpha=1),J.restore()}function So(e,t){J.save(),t||={};let n=eo(t.patternStyle,t.patternColor,t.fillColor),r=J.createPattern(n,`repeat`);r&&(J.fillStyle=r),J.fillRect(e.x,e.y,e.width,e.height),J.restore()}function Co(e,t){J.save(),J.translate(e.x,e.y),t&&(J.fillStyle=t,J.fillRect(-.2,-.2,e.width+.4,e.height+.4)),J.restore()}function wo(e){let t=c(e);if(t&&t.top!=null&&t.left!=null)return[t.top,t.left];throw Error(`Invalid A1-reference`)}function Y(e){return{type:`srgb`,value:e}}function X(e,t=`thin`){return{borderTopColor:e,borderTopStyle:t,borderBottomColor:e,borderBottomStyle:t,borderLeftColor:e,borderLeftStyle:t,borderRightColor:e,borderRightStyle:t}}function To(e,t,n){return{table:{borderTopColor:e,borderTopStyle:`thin`,borderBottomColor:e,borderBottomStyle:`thin`},header:{borderBottomColor:e,borderBottomStyle:`thin`,color:n??e,bold:!0},footer:{borderTopColor:e,borderTopStyle:`thin`,color:n??e,bold:!0},cell:{color:n??e},altRow:{fillColor:t},altCol:{fillColor:t},emFirst:{bold:!0},emLast:{bold:!0}}}function Eo(e){return{table:X(e),header:{fillColor:e,color:Y(`ffffff`),bold:!0},footer:{borderTopColor:e,borderTopStyle:`double`,bold:!0},altRow:{borderTopColor:e,borderTopStyle:`thin`,borderBottomColor:e,borderBottomStyle:`thin`},altCol:{borderLeftColor:e,borderLeftStyle:`thin`,borderRightColor:e,borderRightStyle:`thin`},emFirst:{bold:!0},emLast:{bold:!0}}}function Do(e,t){return{table:X(e),header:{bold:!0,fillColor:Y(`ffffff`),...X(e),borderBottomColor:e,borderBottomStyle:`medium`},cell:{...X(e)},footer:{...X(e),borderTopColor:e,borderTopStyle:`double`,bold:!0},altRow:{fillColor:t},altCol:{fillColor:t},emFirst:{bold:!0},emLast:{bold:!0}}}function Oo(e,t,n){return{table:X(n),header:{borderBottomColor:n,borderBottomStyle:`thin`,fillColor:e,color:Y(`ffffff`),bold:!0},footer:{borderTopColor:n,borderTopStyle:`double`,bold:!0},cell:{borderTopColor:n,borderTopStyle:`thin`,borderBottomColor:n,borderBottomStyle:`thin`},altRow:{fillColor:t},altCol:{fillColor:t},emFirst:{bold:!0},emLast:{bold:!0}}}function ko(e,t,n){return{header:{...X(Y(`ffffff`)),borderBottomColor:Y(`ffffff`),borderBottomStyle:`thick`,fillColor:e,color:Y(`ffffff`),bold:!0},footer:{...X(Y(`ffffff`)),borderTopStyle:`thick`,fillColor:e,color:Y(`ffffff`),bold:!0},cell:{...X(Y(`ffffff`)),fillColor:t},altRow:{fillColor:n},altCol:{fillColor:n},emFirst:{fillColor:e,color:Y(`ffffff`),bold:!0},emLast:{fillColor:e,color:Y(`ffffff`),bold:!0}}}function Ao(e){return{table:{borderTopColor:Y(`000000`),borderTopStyle:`medium`,borderBottomColor:Y(`000000`),borderBottomStyle:`medium`},header:{fillColor:e,color:Y(`ffffff`),bold:!0},cell:{...X(Y(`000000`))},altRow:{fillColor:Y(`dddddd`)},altCol:{fillColor:Y(`dddddd`)},footer:{...X(Y(`000000`)),borderTopColor:Y(`000000`),borderTopStyle:`double`},emFirst:{fillColor:e,color:Y(`ffffff`),bold:!0},emLast:{fillColor:e,color:Y(`ffffff`),bold:!0}}}function jo(e,t,n){return{cell:{...X(n),fillColor:e},header:{...X(n),fillColor:e,bold:!0},footer:{...X(n),borderTopStyle:`medium`,fillColor:e,bold:!0},altRow:{fillColor:t},altCol:{fillColor:t},emFirst:{bold:!0},emLast:{bold:!0}}}function Mo(e,t){return{header:{borderBottomColor:Y(`ffffff`),borderBottomStyle:`medium`,fillColor:Y(`000000`),color:Y(`ffffff`),bold:!0},footer:{borderTopColor:Y(`ffffff`),borderTopStyle:`medium`,fillColor:Y(`000000`),color:Y(`ffffff`),bold:!0},cell:{color:Y(`ffffff`),fillColor:e},altRow:{fillColor:t},altCol:{fillColor:t},emFirst:{fillColor:t,borderRightColor:Y(`ffffff`),borderRightStyle:`medium`,bold:!0},emLast:{fillColor:t,borderLeftColor:Y(`ffffff`),borderLeftStyle:`medium`,bold:!0}}}function No(e,t,n){return{header:{fillColor:e,color:Y(`ffffff`)},footer:{borderTopColor:Y(`000000`),borderTopStyle:`double`,fillColor:t,bold:!0},cell:{fillColor:t},altRow:{fillColor:n},altCol:{fillColor:n},emFirst:{bold:!0},emLast:{bold:!0}}}const Po={TableStyleLight1:To(Y(`000000`),Y(`dddddd`)),TableStyleLight2:To(Y(`134c6f`),Y(`b4e1f3`)),TableStyleLight3:To(Y(`e25a26`),Y(`f9dccc`),Y(`ae3c11`)),TableStyleLight4:To(Y(`165a1a`),Y(`b6efbc`)),TableStyleLight5:To(Y(`168ccc`),Y(`c0e9fb`),Y(`10628d`)),TableStyleLight6:To(Y(`8c1180`),Y(`efc1ec`),Y(`63105d`)),TableStyleLight7:To(Y(`409b23`),Y(`d2f1c6`),Y(`306d1a`)),TableStyleLight8:Eo(Y(`000000`)),TableStyleLight9:Eo(Y(`134c6f`)),TableStyleLight10:Eo(Y(`e25a26`)),TableStyleLight11:Eo(Y(`165a1a`)),TableStyleLight12:Eo(Y(`168ccc`)),TableStyleLight13:Eo(Y(`8c1180`)),TableStyleLight14:Eo(Y(`409b23`)),TableStyleLight15:Do(Y(`000000`),Y(`dddddd`)),TableStyleLight16:Do(Y(`134c6f`),Y(`b4e1f3`)),TableStyleLight17:Do(Y(`e25a26`),Y(`f9dccc`)),TableStyleLight18:Do(Y(`165a1a`),Y(`b6efbc`)),TableStyleLight19:Do(Y(`168ccc`),Y(`c0e9fb`)),TableStyleLight20:Do(Y(`8c1180`),Y(`efc1ec`)),TableStyleLight21:Do(Y(`409b23`),Y(`d2f1c6`)),TableStyleMedium1:Oo(Y(`000000`),Y(`dddddd`),Y(`000000`)),TableStyleMedium2:Oo(Y(`134c6f`),Y(`b4e1f3`),Y(`39a3da`)),TableStyleMedium3:Oo(Y(`e25a26`),Y(`f9dccc`),Y(`ec9870`)),TableStyleMedium4:Oo(Y(`165a1a`),Y(`b6efbc`),Y(`3ece47`)),TableStyleMedium5:Oo(Y(`168ccc`),Y(`c0e9fb`),Y(`52c0f0`)),TableStyleMedium6:Oo(Y(`8c1180`),Y(`efc1ec`),Y(`cd50c2`)),TableStyleMedium7:Oo(Y(`409b23`),Y(`d2f1c6`),Y(`7ed560`)),TableStyleMedium8:ko(Y(`000000`),Y(`dddddd`),Y(`bbbbbb`)),TableStyleMedium9:ko(Y(`134c6f`),Y(`b4e1f3`),Y(`73c0e7`)),TableStyleMedium10:ko(Y(`e25a26`),Y(`f9dccc`),Y(`f4ba9c`)),TableStyleMedium11:ko(Y(`165a1a`),Y(`b6efbc`),Y(`74df7b`)),TableStyleMedium12:ko(Y(`168ccc`),Y(`c0e9fb`),Y(`84d5f7`)),TableStyleMedium13:ko(Y(`8c1180`),Y(`efc1ec`),Y(`dc87d6`)),TableStyleMedium14:ko(Y(`409b23`),Y(`d2f1c6`),Y(`a9e391`)),TableStyleMedium15:Ao(Y(`000000`)),TableStyleMedium16:Ao(Y(`134c6f`)),TableStyleMedium17:Ao(Y(`e25a26`)),TableStyleMedium18:Ao(Y(`165a1a`)),TableStyleMedium19:Ao(Y(`168ccc`)),TableStyleMedium20:Ao(Y(`8c1180`)),TableStyleMedium21:Ao(Y(`409b23`)),TableStyleMedium22:jo(Y(`dddddd`),Y(`bbbbbb`),Y(`000000`)),TableStyleMedium23:jo(Y(`b4e1f3`),Y(`73c0e7`),Y(`39a4da`)),TableStyleMedium24:jo(Y(`f9dccc`),Y(`f4ba9c`),Y(`ed9870`)),TableStyleMedium25:jo(Y(`b6efbc`),Y(`74df7b`),Y(`3ecf47`)),TableStyleMedium26:jo(Y(`c0e9fb`),Y(`84d5f7`),Y(`52c0f1`)),TableStyleMedium27:jo(Y(`efc1ec`),Y(`dc87d6`),Y(`cd50c2`)),TableStyleMedium28:jo(Y(`d2f1c6`),Y(`a9e391`),Y(`7ed560`)),TableStyleDark1:Mo(Y(`606060`),Y(`313131`)),TableStyleDark2:Mo(Y(`134d6f`),Y(`0f384e`)),TableStyleDark3:Mo(Y(`e25b26`),Y(`af3b11`)),TableStyleDark4:Mo(Y(`175a1b`),Y(`114113`)),TableStyleDark5:Mo(Y(`158ccc`),Y(`11628d`)),TableStyleDark6:Mo(Y(`8d1181`),Y(`640f5d`)),TableStyleDark7:Mo(Y(`409b22`),Y(`306c19`)),TableStyleDark8:No(Y(`000000`),Y(`dddddd`),Y(`bbbbbb`)),TableStyleDark9:No(Y(`e25b26`),Y(`b5e0f3`),Y(`73c0e7`)),TableStyleDark10:No(Y(`158ccc`),Y(`b5f0bc`),Y(`74df7b`)),TableStyleDark11:No(Y(`409b22`),Y(`eec0eb`),Y(`dc87d6`))},Fo=[[`font-name`,`fontFamily`],[`font-size`,`fontSize`],[`font-color`,`color`],[`bold`,`bold`],[`italic`,`italic`],[`underline`,`underline`],[`fill-color`,`fillColor`],[`border-left-style`,`borderLeftStyle`],[`border-left-color`,`borderLeftColor`],[`border-right-style`,`borderRightStyle`],[`border-right-color`,`borderRightColor`],[`border-top-style`,`borderTopStyle`],[`border-top-color`,`borderTopColor`],[`border-bottom-style`,`borderBottomStyle`],[`border-bottom-color`,`borderBottomColor`],[`horizontal-alignment`,`horizontalAlignment`],[`vertical-alignment`,`verticalAlignment`],[`wrap-text`,`wrapText`],[`shrink-to-fit`,`shrinkToFit`],[`number-format`,`numberFormat`],[`stroke-opacity`,`strokeOpacity`],[`fill-opacity`,`fillOpacity`]];function Io(e){if(typeof e==`object`&&e){let t=e;for(let[e,n]of Fo)t[e]!=null&&(t[n]=t[e])}return e}const Lo=(e,t,n)=>Math.max(e,Math.min(t,n)),Ro=[[`top`,q.TOP],[`left`,q.LEFT],[`bottom`,q.BOTTOM],[`right`,q.RIGHT]],zo={top:[`borderTopColor`,`borderTopStyle`],bottom:[`borderBottomColor`,`borderBottomStyle`],left:[`borderLeftColor`,`borderLeftStyle`],right:[`borderRightColor`,`borderRightStyle`]},Bo={color:{type:`srgb`,value:`999999`},horizontalAlignment:`left`,verticalAlignment:`bottom`,fillColor:void 0,numberFormat:`@`,wrapText:!1,bold:!1,italic:!1,underline:`none`};function Vo(e){return e===`centerContinuous`?e=`center`:(e===`distributed`||e===`justify`||e===`fill`||e===`general`)&&(e=`left`),e}var Ho=class{workbook;sheetName;highlightColor;locale;viewRef;headers;headerStyle={...Ia};hiddenStyle={...Ia,...La};allowRangeSelections;allowHeaderSelections;showHidden=!1;showValuelessFormulas=!1;showAnnotations=!0;skipCells;borders;merges;fontAdjust;scale;tables=new Map;annotatedCells;onCellContent;constructor(e={}){this.workbook=null,this.sheetName=``,this.highlightColor=`#39c6d9`,this.viewRef=new Sa(`A1`),this.headers=!0,this.allowRangeSelections=!0,this.allowHeaderSelections=!0,this.locale=`en-us`,this.setOptions(e),this.skipCells=new Map,this.borders=new q,this.merges=new Ba,this.scale=new Ka,this.fontAdjust=1.2,this.annotatedCells=new Set,this.onCellContent=e.onCellContent}setOptions(e){this.headers=e.headers??this.headers,this.locale=e.locale??this.locale,this.highlightColor=e.highlightColor??this.highlightColor,this.headerStyle=Object.assign({},Ia,e.headerStyle),this.hiddenStyle=Object.assign({},this.headerStyle,La,e.hiddenStyle),this.allowRangeSelections=e.allowRangeSelections??!0,this.allowHeaderSelections=e.allowHeaderSelections??!0,this.showHidden=e.showHidden??!1,this.showValuelessFormulas=e.showValuelessFormulas??!1,this.showAnnotations=e.showAnnotations??!0}getFullSheetRef(){let e=this.workbook?.getSheet(this.sheetName);if(!e)throw Error(`sheet "${this.sheetName}" not found`);let t=Va(e);return new Sa({top:0,left:0,right:Math.max(0,t[0]-1),bottom:Math.max(0,t[1]-1)},{workbookName:this.workbook?.name,sheetName:e.name})}updateTables(){let e=new Map;this.workbook?.tables.getAll().map(t=>{if(t.sheetName===this.sheetName){let n=new Sa(t.ref);if(n){let r=n.range;for(let[n,i]of qa(r))e.set(K(n,i),[t.name,r])}}}),this.tables=e}updateAnnotatedCells(){let e=this.getCurrentSheet(),t=new Set;if(e&&this.workbook){if(this.workbook.comments)for(let n of this.workbook.comments.get(e.name,{excludeReplies:!0,excludeResolved:!0})){let[e,r]=wo(n.ref);t.add(K(r,e))}if(this.workbook.notes)for(let n of this.workbook.notes.get(e.name)){let[e,r]=wo(n.ref);t.add(K(r,e))}}this.annotatedCells=t}updateScale(){this.workbook&&(this.viewRef=this.getFullSheetRef(),this.scale=Ka.from(this.viewRef,this.workbook,this.showHidden),this.updateTables(),this.updateAnnotatedCells())}getVisibleColumns(){let e=[],t=this.getHeadersSize(),n=this.scale.renderBox,[r]=this.scale.tilt;for(let i=n.left;i<=n.right;i++){let n=this.scale.getColSize(i);e.push({index:i,offset:t.width+n.start+r,height:t.height,width:n.size})}return e}getColumnSize(e){return e<0||e>G||e!==Math.trunc(e)?0:this.scale.getColSize(e).size}setColumnSize(e,t){e>=0&&e<=G&&e===Math.trunc(e)&&(this.workbook?.setColumnWidth(this.sheetName,e,t),this.updateScale())}getVisibleRows(){let e=[],t=this.getHeadersSize(),n=this.scale.renderBox,[,r]=this.scale.tilt;for(let i=n.top;i<=n.bottom;i++){let n=this.scale.getRowSize(i);e.push({index:i,offset:t.height+n.start+r,height:n.size,width:t.width})}return e}getRowSize(e){return e<0||e>xa||e!==Math.trunc(e)?0:this.scale.getRowSize(e).size}setRowSize(e,t){e>=0&&e<=xa&&e===Math.trunc(e)&&(this.workbook?.setRowHeight(this.sheetName,e,t/1.3),this.updateScale())}setWorkbook(e){this.workbook=e;let t=e.getSheet(null);if(!t)throw Error(`workbook has no sheets`);this.setSheet(t.name)}setSheet(e){this.sheetName=e,this.viewRef.sheetName=e,this.updateScale()}refToRect(e,t=!0){let n=this.scale.rangeToRect(e.range);if(t){let e=this.getHeadersSize();return new W(n.x,n.y,n.width+e.width,n.height+e.height)}return n}getHeadersSize(){let e=this.headerStyle.fontSize||11;return{height:this.headers?Math.round(e*1.64):0,width:this.headers?Math.round(e*2.27):0}}getCurrentSheet(){return this.workbook?.getSheet(this.viewRef?.sheetName)??null}getColumnStyle(e){let t=this.getCurrentSheet();if(t&&t.columns){let n=e+1,r=t.columns.find(e=>e.start<=n&&n<=e.end);if(r?.s!=null)return this.workbook?.styles.get(r.s)??null}return null}getTableStyle(e,t){let n={},r=this.tables.get(K(e,t));if(r){let[i,a]=r,o=this.workbook?.tables.get(i);if(o){let r=o.jsf.style??{name:`TableStyleMedium2`,showRowStripes:!0},i=Po[r.name??``]??{},s=t-a.top<(o.headerRowCount??0),c=a.bottom-t<(o.totalsRowCount??0);if(s)Object.assign(n,i.header);else if(c)Object.assign(n,i.footer);else{let s=t-a.top-(o.headerRowCount??0),c=s%2,l=(e-a.left)%2;Object.assign(n,i.cell,c||!r.showRowStripes?null:i.altRow,l||!r.showColumnStripes?null:i.altCol,e===a.left&&r.showFirstColumn?i.emFirst:null,e===a.right&&r.showLastColumn?i.emLast:null),s===0&&i.header?.borderBottomStyle&&(n.borderTopColor=i.header.borderBottomColor,n.borderTopStyle=i.header.borderBottomStyle)}if(i.table){let r=[[`top`,t===a.top],[`bottom`,t===a.bottom],[`left`,e===a.left],[`right`,e===a.right]];for(let[e,t]of r)if(t){let[t,r]=zo[e];i.table[r]&&(n[t]=i.table[t],n[r]=i.table[r])}}}}return n}getStyles(e,t){let n=this.getCurrentSheet(),r=n&&n.getCellByCoords(t,e)||null,i=this.getTableStyle(e,t),a=this.workbook?.styles.get(r?.s??0)??{},o=this.getColumnStyle(e),c={...i,...o,...a};r&&r.f!=null&&r.v==null&&this.showValuelessFormulas&&Object.assign(c,Bo);let l=this.workbook?.theme?.get()??Ra;!c.fontFamily&&c.fontScheme&&(c.fontFamily=l.fontScheme[c.fontScheme].latin.typeface||`Aptos Narrow`);let u={};return za.forEach(e=>{if(e in c){let t=c[e];t&&typeof t!=`string`&&(u[e]=`#`+d(s(t,l.colorScheme)))}}),{...c,...u}}getMergeRange(e){return this.merges.getByCellId(e?.M)}resize(e,t){if(!e)return;let n=e.getContext(`2d`,{alpha:!1});if(!n)return;let r,i;if(t)r=t.width,i=t.height;else{let e=this.getHeadersSize(),t=this.scale.rangeToRect(this.viewRef.range);r=t.width+e.width,i=t.height+e.height}r>1e4&&(r=1e4),i>1e4&&(i=1e4);let a=(typeof window>`u`?1:window.devicePixelRatio)||1;e.style&&(e.style.height=i+`px`,e.style.width=r+`px`),e.height=i*a,e.width=r*a,n.scale(a,a)}getCellAt(e,t){let n=this.getCurrentSheet();return n&&n.getCellByCoords(t,e)||null}shouldRenderGridLines(){let e=this.getCurrentSheet();return e?.views?e.views.find(e=>!e.activeLayout||e.activeLayout===`normal`)?.showGridLines??!0:!0}detectBorders(){let e=this.shouldRenderGridLines(),{renderBox:t}=this.scale,n=Lo(0,t.left,G),r=Lo(0,t.right,G),i=Lo(0,t.top,xa),a=Lo(0,t.bottom,xa);if(e){for(let e=n;e<=r+1;e++)for(let t=i;t<=a+1;t++){let n=[e,t];this.borders.set(n,q.TOP,Oa),this.borders.set(n,q.LEFT,Oa)}for(let e=n;e<=r+1;e++)for(let t=i;t<=a+1;t++){let n=this.getStyles(e,t);if(n&&n.fillColor){let n=[e,t];this.borders.set(n,q.TOP,null),this.borders.set(n,q.LEFT,null),this.borders.set(n,q.BOTTOM,null),this.borders.set(n,q.RIGHT,null)}}for(let e of this.merges)for(let t=e.left;t<=e.right;t++)for(let n=e.top;n<=e.bottom;n++){let r=[t,n];n>e.top&&this.borders.set(r,q.TOP,null),t>e.left&&this.borders.set(r,q.LEFT,null)}}for(let e=n;e<=r;e++)for(let t=i;t<=a;t++){let n=this.getStyles(e,t);if(n)for(let[r,i]of Ro){let[a,o]=zo[r],s=n[o],c=n[a]||`#000`;s&&s!==`none`&&this.borders.set([e,t],i,{style:s,color:c})}}}getCellAlignment(e){let t=(this.workbook?.styles.get(e.s??0)??{}).horizontalAlignment;return(t===`general`||!t)&&(t=Xa(e?e.v:null)),t}canOverflow(e){if(!e||typeof e.v!=`string`||!e.v||e.M||(this.workbook?.styles.get(e.s??0)??{}).wrapText)return 0;let t=Vo(this.getCellAlignment(e));return t===`center`||t===`left`?1:-1}absolutePosition(e){let{scale:t}=this,n=t.dims(e.left,e.top),r=t.dims(e.right,e.bottom);return new W(n.start[0],n.start[1],r.end[0]-n.start[0],r.end[1]-n.start[1])}renderCellText(e,t,n=!1){let{scale:r}=this,i=this.getCurrentSheet();if(!i)return;let{skipCells:a,borders:o}=this,s=this.getCellAt(e,t),c=s&&s.v==null&&s.f!=null;if(!s||c&&!this.showValuelessFormulas||s.v===``)return;let l=r.getCol(e),u=this.getStyles(e,t),d=fo(s,u,this.locale)+8,f=Vo(this.getCellAlignment(s)),p=f===`left`||f===`center`?1:-1,m=(d>l.size?p:0)&&this.canOverflow(s);if(n&&!m)return;let h=r.renderBox.left,g=r.renderBox.right;if(m||(h=e,g=e),m&&(f===`left`||f===`center`)){let n=i.nextValueCellByCoords(t,e,`right`);n&&(g=wo(n.id)[1]-1)}if(m&&(f===`right`||f===`center`)){let n=i.nextValueCellByCoords(t,e,`left`);n&&(h=wo(n.id)[1]+1)}let _=l.start,v=l.end;if(m){if(f===`left`&&g>e){let n=r.toCol(l.start+d).index,i=Math.min(g,n??G);v=r.getCol(i).end;for(let n=e+1;n<=i;n++)o.set([n,t],q.LEFT,null),a.set(K(n,t),1)}else if(f===`right`&&h<e){let n=r.toCol(l.end-d).index,i=Math.max(h,n||0);_=r.getCol(i).start;for(let n=e;n>=i;n--)o.set([n,t],q.LEFT,null),a.set(K(n,t),1)}else if(f===`center`){let n=l.start+l.size/2,i=r.toCol(n+d/2).index,s=Math.min(g,i??G);v=r.getCol(s).end;for(let n=e+1;n<=s;n++)o.set([n,t],q.LEFT,null),a.set(K(n,t),1);let c=r.toCol(n-d/2).index,u=Math.max(h,c||0);_=r.getCol(u).start;for(let n=e;n>u;n--)o.set([n,t],q.LEFT,null),a.set(K(n,t),1)}}let y=this.getHeadersSize(),b=r.getCellRect(e,t).translate(y.width,y.height),ee=new W(y.width+_-r.viewLeft,b.y,v-_,b.height),x=s.v;c&&this.showValuelessFormulas&&(x=`=${s.f}`),ho(x,u,{cellRect:b.translate(...r.tilt),clipRect:ee.translate(...r.tilt),locale:this.locale})}renderBackgrounds(){let{scale:e}=this,t=this.getHeadersSize();for(let n of qa(e.renderBox)){let[r,i]=n,a=this.getMergeRange(this.getCellAt(r,i)),o=a?this.getStyles(a.left,a.top):this.getStyles(r,i),s=e.getCellRect(r,i).translate(t.width,t.height).translate(...e.tilt),c=o.fillColor?String(o.fillColor):null,{patternStyle:l}=o;l?So(s,{...o,patternStyle:l}):c&&Co(s,c)}}renderContent(){let{scale:e}=this,t=this.getCurrentSheet();if(!t)return;let n=this.getHeadersSize(),r=e.renderBox;for(let i=r.top;i<=r.bottom;i++){if(r.left>0){let e=t.nextValueCellByCoords(i,r.left,`left`);if(e&&this.canOverflow(e)){let t=c(e.id);t&&t.left!=null&&this.renderCellText(t.left,i,!0)}}if(r.right<G){let e=t.nextValueCellByCoords(i,r.right,`right`);if(e&&this.canOverflow(e)){let t=c(e.id);t&&t.left!=null&&this.renderCellText(t.left,i,!0)}}for(let t=r.left;t<=r.right;t++){if(this.skipCells.has(K(t,i)))continue;let r=this.getCellAt(t,i),a=this.getMergeRange(r);a&&r?.M!==r?.id&&(r=this.getCellAt(a.left,a.top));let o=r?.v==null&&r?.f!=null;if(!r||o&&!this.showValuelessFormulas||r.v===``)continue;let s;if(a){s=e.rangeToRect(a).translate(n.width,n.height).translate(...e.tilt);for(let[e,t]of qa(a))this.skipCells.set(K(e,t),1)}else s=e.getCellRect(t,i).translate(n.width,n.height).translate(...e.tilt);let c=!0;if(s.width>0&&s.height>0){if(this.onCellContent)try{c=this.onCellContent.call(this,{rect:s,cell:r,ctx:ro()})}catch(e){console.error(e)}}else c=!1;c!==!1&&(a?ho(r.v,this.getStyles(t,i),{cellRect:s,locale:this.locale}):this.renderCellText(t,i),this.showAnnotations&&s.width>0&&s.height>0&&this.annotatedCells.has(K(t,i))&&vo(s),ka(r)&&s.width>0&&s.height>0&&_o(s))}}}renderBorders(e){e||=this.borders;let{scale:t}=this,[n,r]=t.tilt,i=this.getHeadersSize();e.forEach((a,o,s)=>{let c=t.getCellRect(a[0],a[1]).translate(i.width,i.height);o===q.TOP?bo([c.x+n,c.y+r],[c.right+n,c.y+r],s.style||`none`,s.color,e.getJoin(a[0],a[1]),e.getJoin(a[0]+1,a[1])):o===q.LEFT&&bo([c.x+n,c.y+r],[c.x+n,c.bottom+r],s.style||`none`,s.color,e.getJoin(a[0],a[1]),e.getJoin(a[0],a[1]+1))})}renderHighlight(e){if(e&&e.range&&(!e.workbookName||e.workbookName===this.workbook?.name)&&(!e.sheetName||e.sheetName===this.sheetName)){Io(e);let t=e.fill||`none`,n=Lo(0,e.fillOpacity??1,1),r=e.stroke||this.highlightColor||`#39c6d9`,i=e.style||`medium`,a=Lo(0,e.strokeOpacity??1,1),o=this.getHeadersSize(),s=this.scale.rangeToRect(e.range).translate(o.width,o.height).translate(...this.scale.tilt);t&&t!==`none`&&t!==`transparent`&&xo(s,{fillOpacity:n,fillColor:t}),s.getBorders().forEach(([e,t,n])=>{bo(e,t,i,r,n[0],n[1],a)})}}renderHeaderBorders(e){let{scale:t}=this,[n,r]=t.tilt,i=this.getHeadersSize(),a=t.renderBox,o=i.height,s=i.width,c=(t,n,r)=>{let[i,a]=t,o=e.getJoin(i,a),s=e.getJoin(i+1,a),c=e.getJoin(i,a+1),l=e.getJoin(i+1,a+1);if(n.includes(q.TOP)){let n=e.get(t,q.TOP),i=r.getTopEdge();bo(i[0],i[1],n.style,n.color,o,s)}if(n.includes(q.BOTTOM)){let n=e.get(t,q.BOTTOM),i=r.getBottomEdge();bo(i[0],i[1],n.style,n.color,c,l)}if(n.includes(q.LEFT)){let n=e.get(t,q.LEFT),i=r.getLeftEdge();bo(i[0],i[1],n.style,n.color,o,c)}if(n.includes(q.RIGHT)){let n=e.get(t,q.RIGHT),i=r.getRightEdge();bo(i[0],i[1],n.style,n.color,s,l)}};for(let e=a.left;e<=a.right;e++){let r=t.getColSize(e);r.size&&c([e+1,0],[q.BOTTOM,q.TOP,q.RIGHT],new W(s+r.start+n+0,0,r.size,o))}for(let e=a.top;e<=a.bottom;e++){let n=t.getRowSize(e);n.size&&c([0,e+1],[q.BOTTOM,q.LEFT,q.RIGHT],new W(0,0+o+n.start+r,s,n.size))}c([0,0],[q.TOP,q.BOTTOM,q.LEFT,q.RIGHT],new W(0,0,s,o))}renderHeaders(){if(!this.headers)return;let e=(e,t,n=!1)=>{if(n){let{patternStyle:n}=this.hiddenStyle;n&&So(e,{...this.hiddenStyle,patternStyle:n}),ho(t,this.hiddenStyle,{cellRect:e})}else xo(e,this.headerStyle),ho(t,this.headerStyle,{cellRect:e})},t=this.headerStyle,n=new q,i=(e,r)=>{for(let[i,a]of Ro){let[o,s]=zo[i],c=t[s]||`none`,l=t[o]||`#000`;c!==`none`&&l!==`transparent`&&n.set([e,r],a,{style:c,color:l})}},a=this.getHeadersSize(),{scale:o}=this,s=o.renderBox,[c,l]=o.tilt;for(let t=s.top;t<=s.bottom;t++){let n=o.getRowSize(t);n.size&&(e(new W(0,a.height+n.start-1+l,a.width,n.size),String(t+1),n.hidden),i(0,t+1))}for(let t=s.left;t<=s.right;t++){let n=o.getColSize(t);n.size&&(e(new W(a.width+n.start+c,0,n.size,a.height),r(t),n.hidden),i(t+1,0))}e(new W(0,0,a.width,a.height),``),i(0,0),this.renderHeaderBorders(n)}toRect(e){let t=this.getHeadersSize(),n=this.scale.tilt;return this.scale.rangeToRect(e).translate(t.width,t.height).translate(n[0],n[1])}invert(e,t=null){let n=this.getHeadersSize();e[0]<n.width&&(e=[n.width+1,e[1]]),e[1]<n.height&&(e=[e[0],n.height+1]);let r=e[0]+(t?.left||0),i=e[1]+(t?.top||0),a=new W(r-n.width,i-n.height,0,0),o=Object.freeze(this.scale.rectToRange(a));return{cellPos:this.merges.find(o.left,o.top)||o,gridPos:o}}rectToRanges(e,t,n){let r=this.allowRangeSelections,i=this.allowHeaderSelections,a=this.getHeadersSize(),o=r&&i&&e[0]<a.width,s=r&&i&&e[1]<a.height,c=this.invert(e,n);if(c){let e=this.invert(t,n);r||(c=e);let i=s||o?c.gridPos:c.cellPos,a=s||o?e.gridPos:e.cellPos;return{focus:e.cellPos,anchor:c.cellPos,selection:{top:s?0:Math.min(i.top,a.top),bottom:s?1048575:Math.max(i.bottom,a.bottom),left:o?0:Math.min(i.left,a.left),right:o?16383:Math.max(i.right,a.right)}}}return null}render(e,t=null,n){if(!e)return;let r=e.getContext(`2d`,{alpha:!1});if(!r)return;let i=(typeof window>`u`?1:window.devicePixelRatio)||1,a=(e.width||e.clientWidth||0)/i,o=(e.height||e.clientHeight||0)/i;if(a<=0||o<=0)return;if(!isFinite(a))throw Error(`Canvas width cannot be infinite: `+a);if(!isFinite(o))throw Error(`Canvas height cannot be infinite: `+o);this.scale.setView(t?.left||0,t?.top||0,a,o),r.fillStyle=`#fff`,r.fillRect(0,0,a,o),ro(r),io(this.fontAdjust),this.skipCells.clear(),this.merges.clear();let s=this.getCurrentSheet();if(s&&this.merges.setMerges(s.merged_cells),this.borders.clear(),this.detectBorders(),this.renderBackgrounds(),this.renderContent(),this.renderBorders(),n)for(let e of n)e&&this.renderHighlight(e);this.renderHeaders(),this.borders.clear(),this.skipCells.clear()}};function Uo(e){return e._recalcState}function Wo(e){return typeof e==`object`&&!!e&&`error`in e&&typeof e.error==`string`}var Z=class{name;description;parameters;_run;constructor(e){this.name=e.name,this.description=e.description,this.parameters=e.parameters,this._run=e.run}execute(e,t){try{return this._run(e,t)}catch(e){return{error:e instanceof Error?e.message:String(e)}}}};function Go(e){if(!e)return{error:`Workbook not found`};let t=e.getWorkbook();return t?{workbook:t}:{error:`Model has no workbook`}}function Ko(e){return ne(`${e}1`)[1]}function qo(e){let t=e.lastIndexOf(`!`);return t>=0?e.slice(t+1):e}function Jo(e){return e instanceof v?`Unable to solve goalSeek: ${e.detail}`:null}var Yo=class extends Error{sheetRef;availableSheets;constructor(e,t){super(`Sheet "${e}" not found. Available sheets: ${t.join(`, `)}`),this.name=`SheetNotFoundError`,this.sheetRef=e,this.availableSheets=t}};function Xo(e){let t=e.match(/^\[([^\]]+)\](.*)$/);return t?{workbookName:t[1]??``,sheetName:t[2]??``}:{workbookName:null,sheetName:e}}function Zo(e,t){let{workbookName:n,sheetName:r}=Xo(e),i=t.resolveSheet(r,n);return i?n?{workbookName:t.resolveWorkbook(n)?.name??n,sheetName:i.name}:{workbookName:null,sheetName:i.name}:null}function Qo(e){let t=e.getWorkbook(),n=[];for(let r of e.getWorkbooks()){let e=t!=null&&r===t;for(let t of r.getSheets())n.push(e?t.name:`[${r.name}]${t.name}`)}return n}function Q(e,n){let r=o(e);if(r){if(r.context&&r.context.length>0){let e=r.context[r.context.length-1]??``,i=r.context.length>1?r.context[0]??null:null,a=i?`[${i}]${e}`:e,o=Zo(a,n);if(o){let e=o.workbookName?[o.workbookName,o.sheetName]:[o.sheetName];return t({...r,context:e})}throw $o(a,n)}return t(r)}let i=e.lastIndexOf(`!`);if(i===-1)return e;let a=e.slice(0,i),s=e.slice(i+1),c=Zo(a,n);if(!c&&a.startsWith(`'`)&&a.endsWith(`'`)&&(c=Zo(a.slice(1,-1),n)),c){let n=c.workbookName?[c.workbookName,c.sheetName]:[c.sheetName],r=o(s);if(r)return t({...r,context:n});let i=o(`X!${s}`);return i?t({...i,context:n}):e}throw $o(a,n)}function $o(e,t){return new Yo(e,Qo(t))}function es(e,t){return e.people.find(e=>e.id===t)?.displayName??t}function ts(e,t){return new x(t,{sheetName:e}).toString()}function ns(e){let t=e.replace(/\s+/g,` `).trim(),n=[...t];return n.length<=100?{preview:t,truncated:!1}:{preview:`${n.slice(0,99).join(``)}…`,truncated:!0}}function rs(e){let t=new Map;for(let n of e)n.parentId===void 0&&t.set(n.id,{root:n,replies:[]});for(let n of e)n.parentId!==void 0&&t.get(n.parentId)?.replies.push(n);return[...t.values()]}function is(e,t){let n=[];for(let r of rs(e.comments.get(t))){let{preview:i,truncated:a}=ns(r.root.text),o={address:ts(t,r.root.ref),kind:`thread`,author:es(e,r.root.personId),preview:i};r.root.datetime!==void 0&&(o.datetime=r.root.datetime),r.replies.length>0&&(o.replyCount=r.replies.length),r.root.resolved!==void 0&&(o.resolved=r.root.resolved),a&&(o.truncated=!0),n.push(o)}for(let r of e.notes.get(t)){let{preview:e,truncated:i}=ns(r.text),a={address:ts(t,r.ref),kind:`note`,author:r.author,preview:e};i&&(a.truncated=!0),n.push(a)}return n}const as=new Z({name:`getComment`,description:'Read the full text of the comment or note on a specific cell, including all replies for threaded comments. Returns kind="none" if the cell has neither. Use after `getComments` to see the body of an entry whose preview was truncated, or when an agent message refers to a specific cell with a TODO/question on it.',parameters:S.object({address:S.string().describe(`Sheet-qualified cell reference, e.g. "'LBO Model'!E46" or "Sheet1!B2". For non-default sheets you must include the sheet name; otherwise the first sheet is assumed.`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return n;let{workbook:r}=n,i=new x(Q(t.address,e.model));if(!i.range)return{error:`Address "${t.address}" is a name reference, not a cell reference.`};let a=i.sheetName||r.getSheets()[0]?.name;if(!a)return{error:`Workbook has no sheets.`};let o=i.getCellId(),s=ts(a,o),c=r.comments.getByCell(a,o);if(c.length>0){let e=c.find(e=>e.parentId===void 0),t={address:s,kind:`thread`,entries:(e?[e,...c.filter(t=>t.parentId===e.id)]:c).map(e=>{let t={author:es(r,e.personId),text:e.text,isReply:e.parentId!==void 0};return e.datetime!==void 0&&(t.datetime=e.datetime),t})};return e?.resolved!==void 0&&(t.resolved=e.resolved),t}let l=r.notes.getByCell(a,o);return l?{address:s,kind:`note`,author:l.author,text:l.text}:{address:s,kind:`none`}}}),os=new Z({name:`getComments`,description:"List the cells in the workbook that have a comment or note attached, with author, kind (threaded comment vs. legacy note), reply count, and a short text preview. Comments are how a reviewer flags TODOs, justifies a number, or asks a question on a specific cell — read them when auditing, debugging, or completing a partly-built workbook. Returns up to 25 entries; pass `offset` to page. Use `getComment` to read the full text or thread for a specific cell.",parameters:S.object({sheet:S.string().optional().describe(`Restrict to a single sheet by name. Omit to list across the whole workbook.`),offset:S.number().int().nonnegative().optional().describe(`Pagination offset; results are returned in pages of 25.`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return n;let{workbook:r}=n,i;if(t.sheet!==void 0){if(!r.getSheet(t.sheet))return{error:`Sheet "${t.sheet}" not found.`};i=[t.sheet]}else i=r.getSheets().map(e=>e.name);let a=[];for(let e of i)a.push(...is(r,e));let o=t.offset??0,s=a.slice(o,o+25),c=o+s.length<a.length,l={comments:s,total:a.length,offset:o,hasMore:c};return c&&(l.nextOffset=o+s.length),l}});function ss(e){let t=e.getWorkbook();if(!t)return{};let n={};for(let e of t.getSheets()){let t=0;for(let n of e.getCells())n.v instanceof v&&t++;t>0&&(n[e.name]=t)}return n}function cs(e,t){let n=new Map,r=e.getWorkbook();if(!r)return{};for(let i of t){let t=new x(i,{ctx:e}),a=t.sheetName||r.getSheets()[0]?.name,o=a?r.getSheet(a):null;if(o&&!t.name?.startsWith(`_xlnm.`))for(let e of t){let t=o.getCellByRange({top:e.top,left:e.left});if(t&&t.v instanceof v){let e=`${t.v}: ${t.v.detail}`,r=n.get(e);r?r.push(t.id):n.set(e,[t.id])}}}return Object.fromEntries(n)}function ls(e,t){return t.map(t=>{let n=new x(t);if(!n.isAddress)throw Error(`Defined-name references are not supported as write targets: "${t}".`);if(n.size!==1)throw Error(`Range references are not supported as write targets: "${t}". Target a single cell.`);let r=n.getCellId(),i=e.getCell(r,n.sheetName||null,n.workbookName||null);return{refId:n.getRefId(),cellId:r,sheetName:n.sheetName,workbookName:n.workbookName,existed:i!==null,f:i?.f??null}})}function us(e,t){for(let n of t){let t=e.getCell(n.cellId,n.sheetName||null,n.workbookName||null);n.existed?(t?.f??null)!==n.f&&e.getWorkbook(n.workbookName||null)?.editCell(n.refId,{f:n.f}):t!==null&&e.clearCells(n.refId)}}function ds(e,t,n=[]){let r=ls(e,n),i=te.capture(e);try{return t(e)}finally{us(e,r),i.applyTo(e)}}function fs(e){let t=new Map;for(let n of e.getCells()){if(!(n.v instanceof v))continue;let r=new x(n.id,{sheetName:e.name}).toString(),i=n.v.detail?`${n.v.name} (${n.v.detail})`:n.v.name,a=t.get(i);a||(a={key:i,cells:[]},t.set(i,a)),a.cells.push(r)}return Array.from(t.values()).sort((e,t)=>t.cells.length-e.cells.length).slice(0,3).map(e=>({key:e.key,count:e.cells.length,cells:e.cells.slice(0,5)}))}const ps=new Z({name:`describeStructure`,description:`Analyzes the spreadsheet and returns a structured description of all data regions, headers, and labels.
3
+ This helps you understand:
4
+ - Where data tables are located (islands/regions)
5
+ - Which rows are headers vs data
6
+ - Column and row labels for each data region
7
+ - Sheet names and their contents
8
+
9
+ Labels are limited to 50 per sheet. Use totalLabels to check if more exist, and labelOffset to paginate.
10
+
11
+ Use this information to write accurate formulas that reference the correct cells and ranges.`,parameters:S.object({sheets:S.array(S.string()).optional().describe(`Optional: limit analysis to specific sheet names. If omitted, all sheets are analyzed.`),labelOffset:S.number().optional().describe(`Optional: skip N labels before returning up to 50. Use for pagination when totalLabels > 50.`)}),run:(e,t)=>{let n=ss(e.model),r=Object.values(n).reduce((e,t)=>e+t,0),i={},a=e.model.getWorkbook();if(a)for(let e of a.getSheets())(n[e.name]??0)>0&&(i[e.name]=fs(e));return ds(e.model,e=>{let a=e.getWorkbook();if(!a)return{error:`Model has no workbook`};let o=ie(a,{which:[`summary`],recognize2dTables:!0}),s={sheets:[],summary:``,...r>0?{totalErrors:r}:{}},c=t.sheets?.length?new Set(t.sheets.map(e=>e.toLowerCase())):null;for(let e of o.sheets){if(c&&!c.has(e.name.toLowerCase()))continue;let r=n[e.name]??0,a={name:e.name,cellCount:e.cells,formulaCount:e.formulas,...r>0?{errorCount:r}:{},labels:[]};r>0&&i[e.name]&&(a.errorSample=i[e.name]);let o=Math.max(0,t.labelOffset??0),l=e.labels.length,u=e.labels.slice(o);for(let e of u){if(a.labels.length>=50)break;let t=e.for.map(e=>e.ref).join(`, `);a.labels.push(`${e.text} | ${t}`)}l>0&&(a.totalLabels=l),s.sheets.push(a)}return s.summary=`Found ${s.sheets.length} sheet(s).`,s})}}),ms=S.enum([`none`,`dashDot`,`dashDotDot`,`dashed`,`dotted`,`double`,`hair`,`medium`,`mediumDashDot`,`mediumDashDotDot`,`mediumDashed`,`slantDashDot`,`thick`,`thin`]),hs=S.enum([`none`,`single`,`singleAccounting`,`double`,`doubleAccounting`]),gs=S.enum([`general`,`left`,`center`,`right`,`fill`,`justify`,`centerContinuous`,`distributed`]),_s=S.enum([`bottom`,`top`,`center`,`justify`,`distributed`]),vs=S.object({bold:S.boolean().describe(`Bold text`).optional(),borderBottomColor:S.string().describe(`Bottom border color`).optional(),borderBottomStyle:ms.describe(`Bottom border style`).optional(),borderLeftColor:S.string().describe(`Left border color`).optional(),borderLeftStyle:ms.describe(`Left border style`).optional(),borderRightColor:S.string().describe(`Right border color`).optional(),borderRightStyle:ms.describe(`Right border style`).optional(),borderTopColor:S.string().describe(`Top border color`).optional(),borderTopStyle:ms.describe(`Top border style`).optional(),fillColor:S.string().describe(`Cell background color as hex code`).optional(),fontColor:S.string().describe(`Font color as hex code`).optional(),fontName:S.string().describe(`Font family name`).optional(),fontSize:S.number().describe(`Font size in points`).optional(),horizontalAlignment:gs.describe(`Horizontal text alignment`).optional(),italic:S.boolean().describe(`Italic text`).optional(),numberFormat:S.string().describe(`Number format pattern`).optional(),numberFormatFromFormula:S.string().describe(`Number format from formula`).optional(),shrinkToFit:S.boolean().describe(`Shrink text to fit cell`).optional(),underline:hs.describe(`Text underline style`).optional(),verticalAlignment:_s.describe(`Vertical text alignment`).optional(),wrapText:S.boolean().describe(`Wrap text within cell`).optional()}).describe(`Cell style properties`);function ys(e,t){let n=new x(e,{sheetName:t});return(n.height||0)*(n.width||0)<=1e5}function bs(e){let t=e.trim().replace(/^#/,``);return/^[0-9a-fA-F]{6}$/.test(t)?t.toUpperCase():/^[0-9a-fA-F]{3}$/.test(t)?[...t].map(e=>e+e).join(``).toUpperCase():null}const xs=e=>({type:`srgb`,value:e});function Ss(e){let{fillColor:t,fontColor:n,fontName:r,borderTopColor:i,borderBottomColor:a,borderLeftColor:o,borderRightColor:s,...c}=e,l={...c};r!==void 0&&(l.fontFamily=r);let u=[[`fillColor`,t,`fillColor`],[`color`,n,`fontColor`],[`borderTopColor`,i,`borderTopColor`],[`borderBottomColor`,a,`borderBottomColor`],[`borderLeftColor`,o,`borderLeftColor`],[`borderRightColor`,s,`borderRightColor`]];for(let[e,t,n]of u){if(t===void 0)continue;let r=bs(t);if(r===null)return{error:`Invalid ${n} "${t}": expected a hex color such as "#RRGGBB"`};l[e]=xs(r)}return{style:l}}const Cs=new Z({name:`editCellStyles`,description:`Apply formatting styles to cells without changing values.
12
+
13
+ IMPORTANT: After using fillCells, you MUST call this to apply formatting to the filled range.`,parameters:S.object({sheet:S.string().describe(`Sheet name to operate on`),apply:S.array(S.object({target:S.string().describe(`Cell or range reference (e.g., "A1", "B2:D10")`),styles:vs})).describe(`Array of style applications`),note:S.string().optional().describe(`Description of this operation for version history`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n,i=r.getSheet(t.sheet);if(!i)return{error:`Sheet not found: ${t.sheet}`};for(let e of t.apply){if(!ys(e.target,t.sheet))return{error:`Target range too large: ${e.target}`};let n=Ss(e.styles);if(`error`in n)return{error:n.error};let a=new x(e.target,{sheetName:t.sheet});for(let e of a){let t=i.getCellByRange({top:e.top,left:e.left}),a={s:{...t?.style??{},...n.style}};t?.v!=null&&(a.v=t.v),t?.f!=null&&(a.f=t.f),r.editCell(e,a)}}return e.model.recalculate(),{success:!0,rangesStyled:t.apply.length}}});function ws(e){let t=[],n=n=>{if(n.type===`trigger`){if(n.what===`edited`||n.what===`written`){let r=ce(e,n.where,!1);r&&t.push(r)}}else n.type===`evaluate`&&n.changed.length>0&&t.push(...n.changed)};e.on(`recalcEvent`,n);try{e.recalculate()}finally{e.off(`recalcEvent`,n)}return Ts(t)}function Ts(e){let t=[];if(e.length===0)return[];let n=[];for(let r of e){if(r.name){t.push(r);continue}let e=r.sheetName??``;for(let t of r)n.push({sheet:e,row:t.top,col:t.left})}let r=new Set,i=n.filter(e=>{let t=`${e.sheet}|${e.row}|${e.col}`;return r.has(t)?!1:(r.add(t),!0)});i.sort((e,t)=>e.sheet===t.sheet?e.col===t.col?e.row-t.row:e.col-t.col:e.sheet.localeCompare(t.sheet));let a=[],o=0;for(;o<i.length;){let e=i[o];if(!e)break;let t=e,n=i[o+1];for(;n&&n.sheet===e.sheet&&n.col===e.col&&n.row===t.row+1;)o++,t=n,n=i[o+1];let r=re(e.col),s=e.row+1,c=t.row+1,l=s===c?`${r}${s}`:`${r}${s}:${r}${c}`,u=e.sheet?new x(l,{sheetName:e.sheet}):new x(l);a.push(u.toString()),o++}return a.concat(t.map(e=>e.toString()))}const Es=S.object({apply:S.array(S.object({target:S.string().describe(`Cell reference (e.g., "A1", "Sheet1!B2")`),value:S.union([S.string(),S.number(),S.boolean(),S.null()]).optional().describe(`Value or formula to write. Formulas start with "=". Omit to only apply style.`),styleIndex:S.number().optional().describe(`Index into the styles array to apply`)})).describe(`Array of cell edits to apply`),styles:S.array(vs).optional().describe(`Array of style objects referenced by styleIndex in apply items`),note:S.string().optional().describe(`Description of this edit for version history`),merge:S.array(S.string()).optional().describe(`Array of ranges to merge (e.g., ["A1:B2", "D4:E6"]). Each range must span at least 2 cells.`),unmerge:S.array(S.string()).optional().describe(`Array of ranges to unmerge. Can specify exact merged range or any cell within a merge.`)});function Ds(e,t){let n=t.range;if(!n||n.size<2)return`Range must span at least 2 cells`;try{return e.mergeCells(n.toString()),null}catch(e){return e instanceof Error?e.message:`Unknown error`}}function Os(e,t){let n=[],r={};for(let i of t)try{let t=new x(i),a=t.sheetName||e.getSheets()[0]?.name;if(!a){r[i]=`No sheet available`;continue}let o=e.getSheet(a);if(!o){r[i]=`Sheet not found: ${a}`;continue}let s=Ds(o,t);s?r[i]=s:n.push(i)}catch(e){r[i]=e instanceof Error?e.message:`Unknown error`}return{merged:n,errors:r}}function ks(e,t){let n=[],r={};for(let i of t)try{let t=new x(i),a=t.sheetName||e.getSheets()[0]?.name;if(!a){r[i]=`No sheet available`;continue}let o=e.getSheet(a);if(!o){r[i]=`Sheet not found: ${a}`;continue}let s=t.range;if(!s){r[i]=`No merge found in range`;continue}let c=Object.keys(o.merges).length;if(o.unmergeCells(s.toString()),Object.keys(o.merges).length===c){r[i]=`No merge found in range`;continue}n.push(i)}catch(e){r[i]=e instanceof Error?e.message:`Unknown error`}return{unmerged:n,errors:r}}function As(e,t,n){if(typeof n!=`string`||n.startsWith(`=`))return null;let r;try{r=new x(t)}catch{return null}let a=r.sheetName||e.getSheets()[0]?.name,o=(a?e.getSheet(a):void 0)?.getCellByRange({top:r.top,left:r.left});if(!o||o.f||typeof o.v!=`number`)return null;let s=f(o.style?.numberFormat??``)?`date`:`number`,c=i(n);return{level:s===`date`||c!=null&&typeof c.v==`number`?`high`:`low`,note:`wrote text "${n}" over a ${s} value — the cell now holds text, not a ${s}`}}const js=new Z({name:`editCells`,description:`Permanently write values or formulas to cells. Merge or unmerge cells.
14
+
15
+ IMPORTANT: After editing, you MUST call readCalculatedValues to see the resulting changes.
16
+ The tool returns a delta showing changes, but you should verify formulas propagated correctly.
17
+
18
+ Writing text over a cell that held a number or date is reported in \`warnings\` (level "high" or "low"). A "high" warning usually means a real value was turned into a text string that only looks the same — write the value itself, not its displayed text.
19
+
20
+ Examples:
21
+ - Set value: { "apply": [{ "target": "A1", "value": 100 }], "note": "Set initial value" }
22
+ - Set formula: { "apply": [{ "target": "B1", "value": "=A1*2" }], "note": "Add formula" }
23
+ - With style: { "apply": [{ "target": "A1", "value": 100, "styleIndex": 0 }], "styles": [{ "bold": true }], "note": "Bold value" }
24
+ - Merge cells: { "apply": [], "merge": ["A1:B2"], "note": "Merge header" }
25
+ - Unmerge: { "apply": [], "unmerge": ["A1:B2"], "note": "Unmerge cells" }
26
+
27
+ Formulas must start with "=". Values are auto-detected as number, boolean, or string.`,parameters:Es,run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n,i={},a={},o=[];for(let[e,n]of(t.styles??[]).entries()){let t=Ss(n);if(`error`in t)return{error:`styles[${e}]: ${t.error}`};o.push(t.style)}let s=t.apply.map(t=>({...t,target:Q(t.target,e.model)})),c=t.merge?.map(t=>Q(t,e.model)),l=t.unmerge?.map(t=>Q(t,e.model)),u=[];for(let{target:e}of s)try{let t=new x(e),n=t.sheetName??r.getSheets()[0]?.name;if(!n)continue;let i=r.getSheet(n);if(!i)continue;let a=i.getCellByRange({top:t.top,left:t.left}),o=t.getCellId();a?.M&&a.M!==o&&u.push(`${e} is merged into ${a.M}`)}catch{}if(u.length>0)return{error:`Cannot write to non-anchor merged cells: ${u.join(`, `)}. Write to anchor cells instead.`};for(let{target:e,value:t,styleIndex:n}of s)try{let i=As(r,e,t),s={};if(typeof t==`string`&&t.startsWith(`=`)?s.f=t.replace(/^=/,``):t!==void 0&&(s.v=t),n!==void 0&&o[n]&&(s.s=o[n]),s.f===void 0&&s.v===void 0&&s.s===void 0)continue;r.editCell(e,s),i&&(a[e]=i)}catch(t){i[e]=t instanceof Error?t.message:`Unknown error`}let d=c?Os(r,c):{merged:[],errors:{}},f=l?ks(r,l):{unmerged:[],errors:{}},p={...d.errors,...f.errors},m=ws(e.model),h=cs(e.model,m);return{success:!0,cellsModified:s.length,changedCells:m,merged:d.merged.length>0?d.merged:void 0,unmerged:f.unmerged.length>0?f.unmerged:void 0,errors:Object.keys(i).length>0?i:void 0,mergeErrors:Object.keys(p).length>0?p:void 0,cell_errors:Object.keys(h).length>0?h:void 0,warnings:Object.keys(a).length>0?a:void 0}}});function Ms(e){return e?.z||``}var Ns=class{_stepsize;_dir;_anchor;_cells;_style;constructor(e,t,n){this._anchor=n,this._dir=t||`row`,this._cells=e}_cellIdToFillIndex(e){let[t,n]=ne(this._anchor),[r,i]=ne(e),a=r-t;return this._dir===`col`&&(a=i-n),a}_matchingCellByIndex(e){let t=Math.abs(e);e<0&&this._stepsize&&--t,t>this._cells.length-1&&(t%=this._cells.length);let n=this._cells[t];if(!n)throw Error(`No cell at index ${t}`);return n}_numfmtAt(e){let t=this._cellIdToFillIndex(e);return Ms(this._matchingCellByIndex(t))}_formulaAt(t,n){let r=n.f;if(!r)throw Error(`Cell has no formula`);let i=h(r,n.id),a=this._numfmtAt(t);return{f:e(i,t,{wrapEdges:!1}),z:a}}at(e){let t=this._cellIdToFillIndex(e),n=this._matchingCellByIndex(t);if(n.f)return this._formulaAt(e,n);let r={z:this._numfmtAt(e),s:this._style??void 0};return n.v!==null&&(r.v=n.v),r}},Ps=class extends Ns{constructor(e,t,n){super(e,t||`col`,n),this._constructSequence(e)}_constructSequence(e){if(e.length===1)return;let t=e[0],n=e[1];if(!t||!n||(this._style=t.style,typeof t.v!=`number`||typeof n.v!=`number`))return;let r=n.v-t.v;if(r!==0){for(let t=2;t<e.length;t++){let n=e[t]?.v,i=e[t-1]?.v;if(typeof n!=`number`||typeof i!=`number`||r!==n-i)return}this._stepsize=r}}_getDecimalPlaces(e){let t=e.toString(),n=t.indexOf(`.`);return n===-1?0:t.length-n-1}at(e){if(this._stepsize){let t=this._cellIdToFillIndex(e),n=this._matchingCellByIndex(this._cellIdToFillIndex(this._anchor));if(typeof n.v!=`number`)return super.at(e);let r=n.v,i=r+t*this._stepsize,a=Math.max(this._getDecimalPlaces(r),this._getDecimalPlaces(this._stepsize));return i=Number(i.toFixed(a)),{v:i,z:this._numfmtAt(e),s:this._style??void 0}}return super.at(e)}},Fs=class extends Ns{_granularity;constructor(e,t,n){super(e,t||`col`,n),this._constructSequence(e)}_constructSequence(e){if(e.length===1)this._stepsize=1,this._granularity=`day`;else{let t=this._dateStepsize(e,`day`),n=this._dateStepsize(e,`month`),r=this._dateStepsize(e,`year`),i=null;t&&(i=`day`),n&&(i=`month`),r&&(i=`year`),i&&(this._stepsize=r||n||t,this._granularity=i)}}_dateStepsize(e,t=`day`){let n=e[0],r=e[1];if(!n||!r)return null;let i=this._stepBetweenDates(n,r,t);if(i===0)return null;for(let n=2;n<e.length;n++){let r=e[n],a=e[n-1];if(!r||!a||this._stepBetweenDates(a,r,t)!==i)return null}return i}_stepBetweenDates(e,t,n=`day`){let[r=0,i=0]=a(e.v),[o=0,s=0]=a(t.v);if(n===`year`)return o-r;if(n===`month`)return s-i;if(n===`day`)return typeof t.v!=`number`||typeof e.v!=`number`?0:t.v-e.v;throw Error(`Only supports [year, month, day] as steps but received: ${String(n)}`)}at(e){if(this._stepsize&&this._granularity){let t=this._cellIdToFillIndex(e),n=this._cells[0];if(!n)return super.at(e);let r=n.v,i=a(r),o={day:2,month:1,year:0}[this._granularity];return i[o]=(i[o]??0)+t*this._stepsize,{v:u(i),z:this._numfmtAt(e)}}return super.at(e)}};function Is(e){return e.f?`formula`:typeof e.v==`number`?f(Ms(e))?`date`:`number`:typeof e.v==`string`&&(e.v===`true`||e.v===`false`)?`boolean`:`unknown`}function Ls(e,t){let n=new x(e).range,r=new x(t).range;if(!n||!r)throw Error(`Both selection and extend_to must be valid ranges`);let i=n.top===r.top&&n.bottom===r.bottom,a=n.left===r.left&&n.right===r.right;if(a&&!i)return`row`;if(i&&!a)return`col`;throw Error(a&&i?`Selection and extend_to ranges are identical — nothing to fill`:`Selection and extend_to differ in both dimensions — cannot determine fill direction`)}var Rs=class{_dir;_anchor;_seq;constructor(e,t,n){let r=e.range,i=t.range;if(!r||!i)throw Error(`Selection and extend_to must be valid ranges`);this._dir=Ls(e.toString(),t.toString()),this._anchor=r.collapse().toString(),this._seq=new Map,this._constructSequences(e,n)}_cellIdToSeqIndex(e){let[t,n]=ne(this._anchor),[r,i]=ne(e);return this._dir===`col`?r-t:i-n}_constructSequences(e,t){let n=new Map;for(let r of e){let e=t(r.top,r.left);if(!e)continue;let i=this._cellIdToSeqIndex(e.id),a=n.get(i);a||(a=[],n.set(i,a)),a.push(e)}for(let[e,t]of n){let n=new Set(t.map(Is));n.size===1&&n.has(`number`)?this._seq.set(e,new Ps(t,this._dir,this._anchor)):n.size===1&&n.has(`date`)?this._seq.set(e,new Fs(t,this._dir,this._anchor)):this._seq.set(e,new Ns(t,this._dir,this._anchor))}}at(e){let t=this._cellIdToSeqIndex(e),n=this._seq.get(t);return n?n.at(e):{}}};const zs=new Z({name:`fillCells`,description:`Extend a selection by filling cells with auto-detected patterns (numbers, dates, formulas).
28
+ Similar to Excel's fill handle - detects sequences and continues them.
29
+ Fill direction is inferred from selection and extend_to: the dimension that changes determines the fill axis.
30
+
31
+ IMPORTANT: After filling, you MUST call editCellStyles to apply formatting to the filled cells.
32
+
33
+ Examples:
34
+ - Fill down: { "sheet": "Sheet1", "selection": "A1:A3", "extend_to": "A1:A10", "note": "Extend series" }
35
+ - Fill right: { "sheet": "Sheet1", "selection": "A1:C1", "extend_to": "A1:F1", "note": "Extend headers" }
36
+ - Fill up: { "sheet": "Sheet1", "selection": "A8:B10", "extend_to": "A1:B10", "note": "Extend upward" }`,parameters:S.object({sheet:S.string().describe(`Sheet name to operate on`),selection:S.string().describe(`Source range containing the pattern (e.g., "A1:A3")`),extend_to:S.string().describe(`Target range to fill to (e.g., "A1:A10")`),note:S.string().optional().describe(`Description of this operation for version history`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n,i=r.getSheet(t.sheet);if(!i)return{error:`Sheet not found: ${t.sheet}`};if(!ys(t.selection,t.sheet))return{error:`Selection range too large: ${t.selection}`};if(!ys(t.extend_to,t.sheet))return{error:`Extend_to range too large: ${t.extend_to}`};let a=new x(t.selection),o=new x(t.extend_to);if(!a.range||!o.range)return{error:`Invalid range: ${t.selection} or ${t.extend_to}`};let s=new Rs(a,o,(e,t)=>i.getCellByRange({top:e,left:t})),c=new x(t.extend_to,{sheetName:i.name});for(let e of c){let t=qo(e.range.toString()),n=s.at(t);r.editCell(e,n)}let l=ws(e.model),u=cs(e.model,l);return{success:!0,filledRange:t.extend_to,changedCells:l,cell_errors:Object.keys(u).length>0?u:void 0}}});function Bs(e){switch(e.type){case`srgb`:case`preset`:case`system`:case`theme`:return e.value.toLowerCase();case`scrgb`:return`scrgb(${e.red}%,${e.green}%,${e.blue}%)`;case`hsl`:return`hsl(${e.hue},${e.saturation}%,${e.lightness}%)`;case`indexed`:return`indexed(${e.value})`;case`auto`:return`auto`;default:return e}}function Vs(e){return e==null?null:e instanceof v?String(e):typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}function Hs(e){return e===null?`null`:typeof e==`string`?JSON.stringify(e):e.toString()}function Us(e){let t=e.origin?e.origin.withPrefix({workbookName:``}).toString():void 0;return{name:e.name,code:e.code,...e.detail?{detail:e.detail}:{},...t?{origin:t}:{}}}const Ws=65536;function Gs(e){if(e==null)return`z`;if(typeof e==`boolean`)return`b`;if(typeof e==`number`)return`n`;if(typeof e==`string`)return`s`;if(e instanceof v)return`e`}function Ks(e){return e.replace(/^=?/,`=`)}function qs(e,t){return re(e)+(t+1)}function Js(e,t,r,i,a,o){if(!e)return{t:`z`,ref:t};let s={ref:t},c=e.v,l=Gs(c);l&&(s.t=l);let u=Vs(c);u!=null&&(s.v=u),e.f&&(s.f=e.f),c instanceof v&&(s.error=Us(c));let d=e.style?.numberFormat;if(d){s.num_format=d;try{s.formatted=n(d,c)}catch{s.formatted=`######`}}let{numberFormatFromFormula:f,...p}=e.style??{};if(r&&Object.keys(p).length>0&&(s.style_index=r.styles.findOrCreate(p)),i){let t=e.style;t&&(s.style=t);let n=e.href;n&&(s.href=n)}if(a&&o){let e=a.get(o,t);e&&(s.mismatch={note:`Excel cached ${Hs(e.cachedValue)}; Apiary computed ${Hs(e.calculatedValue)}`,cachedValue:e.cachedValue,calculatedValue:e.calculatedValue})}return s}function Ys(e,t,n){let r=Ks(t),i=e.runFormula(r,n?.evalContext??null);if(i instanceof x&&(i=i.withContext(e),i.name&&(i=oe(i.resolveToNonName()))),i==null)return{t:`z`,ref:`#RESULT`};let a=!1;if((typeof i==`number`||typeof i==`string`||typeof i==`boolean`||i instanceof v)&&(i=y.of(i),a=!0),i instanceof y||i instanceof x){let t=i.size??0;if(t>Ws)throw Error(`Query exceeds ${Ws} cell limit`);let r=i.resolveAreaCells(`any-cell-information`),o=i.width??0,s=i.height??0,c=i instanceof x?i.left??0:0,l=i instanceof x?i.top??0:0,u=e.getWorkbook(),d=i instanceof x?i.sheetName||u?.getSheets()[0]?.name:void 0,f=d?u?.getSheet(d)??null:null;if(t===1){let e=r?.[0]?.[0]??null,t=a?`#RESULT`:qs(c,l),o=Js(e,t,u,n?.includeStyles,n?.mismatches,a?void 0:d);if(e?.M&&i instanceof x&&f){let n=e.M;if(t===n){let e=f.merges[n];if(e){let[t,r]=e,i=new x(n);o.mergedRange=`${n}:${qs(i.left+t-1,i.top+r-1)}`}}else o.mergedInto=n}return o}let p={},m=n?.maxFormulas!=null&&t>n.maxFormulas;for(let e=0;e<s;e++){let t=r[e];for(let r=0;r<o;r++){let i=t?.[r];if(!i)continue;let a=qs(c+r,l+e),{ref:o,...s}=Js(i,a,u,n?.includeStyles,n?.mismatches,d);if(s.t!==`z`){if(m&&s.f&&(s.f=`[formula]`),i.M&&f&&a===i.M){let e=f.merges[i.M];if(e){let[t,n]=e,r=new x(i.M),a=qs(r.left+t-1,r.top+n-1);s.mergedRange=`${i.M}:${a}`}}p[a]=s}}}return m&&(p._note=`Formulas suppressed (${t} cells). Read ≤${n?.maxFormulas} cells to see formulas.`),p}throw Error(`Cannot read expression: ${t}`)}function Xs(e,t,n,r){let i=e.getWorkbook();if(!i)throw Error(`readCellsByCoords: model has no workbook`);let a=t||i.getSheets()[0]?.name;if(!a)throw Error(`readCellsByCoords: workbook has no sheets`);let o=i.getSheet(a);if(!o)throw Error(`readCellsByCoords: sheet "${a}" not found`);let s=r?.maxFormulas!=null&&n.length>r.maxFormulas,c={};for(let{row:e,column:t}of n){let n=o.getCellByRange({top:e,left:t});if(!n)continue;let l=qs(t,e),{ref:u,...d}=Js(n,l,i,r?.includeStyles,r?.mismatches,a);if(d.t!==`z`){if(s&&d.f&&(d.f=`[formula]`),n.M&&l===n.M){let e=o.merges[n.M];if(e){let[t,r]=e,i=new x(n.M),a=qs(i.left+t-1,i.top+r-1);d.mergedRange=`${n.M}:${a}`}}c[l]=d}}return s&&(c._note=`Formulas suppressed (${n.length} cells). Read ≤${r?.maxFormulas} cells to see formulas.`),c}const Zs=1e4,Qs={red:`FF0000`,darkred:`8B0000`,lightcoral:`F08080`,crimson:`DC143C`,firebrick:`B22222`,indianred:`CD5C5C`,salmon:`FA8072`,darksalmon:`E9967A`,lightsalmon:`FFA07A`,tomato:`FF6347`,orangered:`FF4500`,orange:`FFA500`,darkorange:`FF8C00`,coral:`FF7F50`,yellow:`FFFF00`,lightyellow:`FFFFE0`,lemonchiffon:`FFFACD`,lightgoldenrodyellow:`FAFAD2`,papayawhip:`FFEFD5`,moccasin:`FFE4B5`,peachpuff:`FFDAB9`,palegoldenrod:`EEE8AA`,khaki:`F0E68C`,darkkhaki:`BDB76B`,gold:`FFD700`,goldenrod:`DAA520`,darkgoldenrod:`B8860B`,green:`008000`,darkgreen:`006400`,lightgreen:`90EE90`,palegreen:`98FB98`,lime:`00FF00`,limegreen:`32CD32`,forestgreen:`228B22`,seagreen:`2E8B57`,mediumseagreen:`3CB371`,darkseagreen:`8FBC8F`,lightseagreen:`20B2AA`,springgreen:`00FF7F`,mediumspringgreen:`00FA9A`,yellowgreen:`9ACD32`,greenyellow:`ADFF2F`,chartreuse:`7FFF00`,lawngreen:`7CFC00`,olivedrab:`6B8E23`,olive:`808000`,darkolivegreen:`556B2F`,teal:`008080`,cyan:`00FFFF`,aqua:`00FFFF`,aquamarine:`7FFFD4`,mediumaquamarine:`66CDAA`,turquoise:`40E0D0`,mediumturquoise:`48D1CC`,darkturquoise:`00CED1`,paleturquoise:`AFEEEE`,lightcyan:`E0FFFF`,blue:`0000FF`,darkblue:`00008B`,mediumblue:`0000CD`,lightblue:`ADD8E6`,powderblue:`B0E0E6`,skyblue:`87CEEB`,lightskyblue:`87CEFA`,deepskyblue:`00BFFF`,dodgerblue:`1E90FF`,cornflowerblue:`6495ED`,royalblue:`4169E1`,steelblue:`4682B4`,lightsteelblue:`B0C4DE`,cadetblue:`5F9EA0`,purple:`800080`,darkmagenta:`8B008B`,magenta:`FF00FF`,fuchsia:`FF00FF`,mediumpurple:`9370DB`,blueviolet:`8A2BE2`,darkviolet:`9400D3`,darkorchid:`9932CC`,mediumorchid:`BA55D3`,orchid:`DA70D6`,violet:`EE82EE`,plum:`DDA0DD`,thistle:`D8BFD8`,lavender:`E6E6FA`,indigo:`4B0082`,slateblue:`6A5ACD`,mediumslateblue:`7B68EE`,darkslateblue:`483D8B`,rebeccapurple:`663399`,pink:`FFC0CB`,lightpink:`FFB6C1`,hotpink:`FF69B4`,deeppink:`FF1493`,mediumvioletred:`C71585`,palevioletred:`DB7093`,brown:`A52A2A`,maroon:`800000`,saddlebrown:`8B4513`,sienna:`A0522D`,chocolate:`D2691E`,peru:`CD853F`,sandybrown:`F4A460`,rosybrown:`BC8F8F`,tan:`D2B48C`,burlywood:`DEB887`,wheat:`F5DEB3`,navajowhite:`FFDEAD`,bisque:`FFE4C4`,blanchedalmond:`FFEBCD`,cornsilk:`FFF8DC`,white:`FFFFFF`,snow:`FFFAFA`,honeydew:`F0FFF0`,mintcream:`F5FFFA`,azure:`F0FFFF`,aliceblue:`F0F8FF`,ghostwhite:`F8F8FF`,whitesmoke:`F5F5F5`,seashell:`FFF5EE`,beige:`F5F5DC`,oldlace:`FDF5E6`,floralwhite:`FFFAF0`,ivory:`FFFFF0`,antiquewhite:`FAEBD7`,linen:`FAF0E6`,lavenderblush:`FFF0F5`,mistyrose:`FFE4E1`,gainsboro:`DCDCDC`,lightgray:`D3D3D3`,lightgrey:`D3D3D3`,silver:`C0C0C0`,darkgray:`A9A9A9`,darkgrey:`A9A9A9`,gray:`808080`,grey:`808080`,dimgray:`696969`,dimgrey:`696969`,lightslategray:`778899`,lightslategrey:`778899`,slategray:`708090`,slategrey:`708090`,darkslategray:`2F4F4F`,darkslategrey:`2F4F4F`,black:`000000`,navy:`000080`,midnightblue:`191970`},$s={};for(let[e,t]of Object.entries(Qs)){let n=$s[t];(!n||n.length>e.length)&&($s[t]=e)}function ec(e){let t=e.toLowerCase().trim().replace(/^#/,``).replace(/\s+/g,``),n=Qs[t];return n?[t,n.toLowerCase()]:[t]}const tc=S.enum([`AND`,`OR`]),nc=S.object({sheet:S.string().optional().describe(`Restrict search to a single sheet by name.`),range:S.string().optional().describe(`Restrict search to an A1-style range, e.g. 'Sheet1!B2:D10' or 'B2:D10'. An unqualified range resolves against 'sheet' if given, otherwise the first sheet. Defined names are not accepted. Ranges larger than 10,000 cells are rejected.`),matchMode:tc.optional().describe(`"AND" = all criteria must match (narrows results). "OR" = any criterion matches (broader sweep). Defaults to "AND".`),hasFormula:S.boolean().optional().describe(`Match cells that have (true) or don't have (false) a formula.`),fillColor:S.string().min(1,`fillColor must not be an empty string`).optional().describe(`Match cells whose fill color matches this search term. Accepts hex values ("FFFF00", "#FF0000"), partial hex ("FF"), named colors ("yellow", "light blue", "dark green"), and Excel preset names. Case-insensitive.`),formulaContains:S.string().min(1,`formulaContains must not be an empty string`).optional().describe(`Match cells whose formula text contains this substring (case-insensitive).`),valueContains:S.string().min(1,`valueContains must not be an empty string`).optional().describe(`Match cells whose value (converted to text) contains this substring (case-insensitive).`),valueWithin:S.array(S.number()).length(2).optional().describe(`Match cells whose numeric value falls within this inclusive range [min, max].`)});function rc(e){let t=e?.fillColor;if(!t)return;let n=Bs(t),r=$s[n.toUpperCase()];return r?`${n} (${r})`:n}function ic(e,t){let n=e?.fillColor;if(!n)return!1;let r=Bs(n);return t.some(e=>r.includes(e))}function ac(e){return e==null?``:typeof e==`string`?e:String(e)}const oc=new Z({name:`findCells`,description:`Search for cells matching specified criteria within a sheet or range. Returns up to 200 matches. Use matchMode to control whether all criteria must match (AND, default) or any (OR). Range iteration is limited to ${Zs.toLocaleString()} cells — use sheet scope for larger searches.`,parameters:nc,run:(e,t)=>{let n=Go(e.model);if(`error`in n)return n;let{workbook:r}=n,i=t.matchMode??`AND`,a,o;if(t.range){if(o=new x(Q(t.range,e.model),{ctx:e.model,sheetName:t.sheet}),!o.range)return{error:`"${t.range}" is a name reference, which is not supported for 'range'. Pass an A1-style range like 'Sheet1!B2:D10' instead.`};let n=o.sheetName||r.getSheets()[0]?.name||``,i=n?r.getSheet(n):null;if(!i)return{error:`Sheet "${n}" not found.`};a=[i];let s=o.range?.size;if(s!==void 0&&s>Zs)return{error:`Range "${t.range}" covers ${s.toLocaleString()} cells, exceeding the ${Zs.toLocaleString()}-cell limit. Narrow the range or search by sheet instead.`}}else if(t.sheet){let e=r.getSheet(t.sheet);if(!e)return{error:`Sheet "${t.sheet}" not found.`};a=[e]}else a=r.getSheets();let s=[`fillColor`,`formulaContains`,`valueContains`].find(e=>t[e]===``);if(s)return{error:`Parameter "${s}" must not be an empty string.`};if(t.hasFormula===void 0&&t.fillColor===void 0&&t.formulaContains===void 0&&t.valueContains===void 0&&t.valueWithin===void 0)return{error:`At least one search criterion is required (hasFormula, fillColor, formulaContains, valueContains, or valueWithin).`};let[c,l]=t.valueWithin??[];if(c!==void 0&&l!==void 0&&c>l)return{error:`valueWithin bounds are inverted: min ${c} is greater than max ${l}. Pass [min, max].`};let u=t.fillColor?ec(t.fillColor):void 0,d={matchMode:i,hasFormula:t.hasFormula,fillColorTerms:u,formulaContainsLower:t.formulaContains?.toLowerCase(),valueContainsLower:t.valueContains?.toLowerCase(),valueWithinMin:c,valueWithinMax:l},f=0,p=[];for(let e of a)if(o?.range)for(let{row:t,column:n}of o.range.iterCoordinates()){let r=e.getCellByRange({top:t,left:n});if(!r)continue;let i=sc(r,d);if(i&&(f++,p.length<200)){let r=new x(qs(n,t),{sheetName:e.name}).toString();p.push({ref:r,...i})}}else for(let t of e.getCells(!0)){let n=sc(t,d);if(n&&(f++,p.length<200)){let r=new x(t.id,{sheetName:e.name}).toString();p.push({ref:r,...n})}}let m=f>p.length;return{matches:p,totalMatches:f,...m?{truncated:{maxMatches:200,hint:`Search reached the maximum of 200 matches. Narrow the scope or add more criteria to find specific cells.`}}:{}}}});function sc(e,t){let n=[];if(t.hasFormula!==void 0){let r=e.f!=null;n.push(r===t.hasFormula)}if(t.formulaContainsLower!==void 0){let r=e.f!=null&&e.f.toLowerCase().includes(t.formulaContainsLower);n.push(r)}if(t.valueContainsLower!==void 0){let r=ac(e.v).toLowerCase();n.push(r.includes(t.valueContainsLower))}if(t.valueWithinMin!==void 0&&t.valueWithinMax!==void 0){let r=typeof e.v==`number`&&e.v>=t.valueWithinMin&&e.v<=t.valueWithinMax;n.push(r)}if(t.fillColorTerms!==void 0&&n.push(ic(e.style,t.fillColorTerms)),n.length===0)return null;if(t.matchMode===`AND`){if(!n.every(Boolean))return null}else if(!n.some(Boolean))return null;let r={};e.v!==null&&(r.value=ac(e.v)),e.f&&(r.formula=e.f);let i=rc(e.style);return i&&(r.fillColor=i),r}const cc=new Z({name:`getStyles`,description:`Get the workbook's style definitions. Returns styles where each index corresponds to a style_index in cell data. Use this to understand what formatting (colors, fonts, borders, etc.) is applied to cells.
37
+
38
+ If no indices are provided, returns all styles as an array.
39
+ If indices are provided, returns only those styles as an object keyed by index.`,parameters:S.object({indices:S.array(S.number()).optional().describe(`Optional array of style indices to fetch. If omitted, returns all styles.`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n;if(t.indices&&t.indices.length>0){let e={};for(let n of t.indices)e[n]=r.styles.get(n);return e}return r.styles.toArray()}}),lc=new Z({name:`goalSeek`,description:`Find the input value needed to achieve a target result (like Excel's Goal Seek).
40
+ Iteratively adjusts the control cell until the target cell reaches the desired value.`,parameters:S.object({write:S.array(S.object({cell:S.string().describe(`Cell reference`),value:S.union([S.string(),S.number(),S.boolean(),S.null()]).describe(`Value to write before running goal seek`)})).describe(`Values to write before goal seeking`),goalSeek:S.object({targetCell:S.string().describe(`Cell containing the formula to reach target value`),targetValue:S.number().describe(`Desired value for the target cell`),controlCell:S.string().describe(`Cell to adjust to achieve the target`)}).describe(`Goal seek parameters`),persist:S.boolean().optional().describe(`Whether to persist the solved control cell (and any pre-seek writes) to the workbook. Defaults to false: a pure calculation that reports the solution without changing the model.`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let r=Q(t.goalSeek.targetCell,e.model),i=Q(t.goalSeek.controlCell,e.model),a=x.from(r);if(!a)return{error:`goalSeek targetCell is not a valid reference`};let o=x.from(i);if(!o)return{error:`goalSeek controlCell is not a valid reference`};let s=(t.write??[]).map(({cell:t,value:n})=>({cell:Q(t,e.model),value:n})),c=new Set([r]),l=e=>{if(s.length>0){let t=s.filter(({cell:e})=>!c.has(e)).map(({cell:e,value:t})=>[e,t]);t.length>0&&(e.writeMultiple(t,{skipRecalc:!0}),e.recalculate())}let n=e.goalSeek(o,a,t.goalSeek.targetValue),l=Jo(n);return l?{error:l}:{success:!0,goalSeek:{targetCell:r,targetValue:t.goalSeek.targetValue,controlCell:i,solution:n}}};if(!t.persist){let t=s.map(({cell:e})=>e).filter(e=>!c.has(e)).concat(i);return ds(e.model,l,t)}let u=e.model.readValue(`=${i}`),d=l(e.model);if(`error`in d){let t=e.model.readValue(`=${i}`);return{error:`${d.error} Control cell ${i} was not reverted and is left at ${String(t)} (previously ${String(u)}).`}}return d}});function uc(e,t){let n=e.chunkedGraph._getVertices(t.workbookKey)?.get(t);if(n?.data)return{id:t,data:n.data};for(let n of e.calculated)if(n.vertexId.contains(t))return{id:n.vertexId,data:n};let r=null;return e.chunkedGraph.visitRangeVertices(e=>{!r&&e.data&&e.id.contains(t)&&(r={id:e.id,data:e.data})}),r||null}var dc=class{desc;direction;maxDepth;maxNodes;visited=new Set;queue=[];nodeCount=0;constructor(e,t,n,r){this.desc=e,this.direction=t,this.maxDepth=n,this.maxNodes=r}walk(e,t){let n=this.createNode(t);this.nodeCount=1,this.enqueueIfWalkable(n,e,t,0);for(let e=this.queue.shift();e!=null;e=this.queue.shift())this.populateChildren(e.node,e.id,e.depth);return{[t.ref.toString()]:n}}createNode(e){let t={type:e.type,labels:e.labels.map(e=>e.text),formula:e.formula??null};return e.rootHeight!=null&&(t.rootHeight=e.rootHeight),e.leafDepth!=null&&(t.leafDepth=e.leafDepth),t}enqueueIfWalkable(e,t,n,r){this.direction===`precedents`&&!n.formula||this.queue.push({node:e,id:t,depth:r})}populateChildren(e,t,n){if(this.visited.has(t.key)){e.alreadyVisited=!0;return}if(n>=this.maxDepth){e.truncated={reason:`maxDepth`};return}this.visited.add(t.key);let r=(this.direction===`precedents`?this.desc.chunkedGraph.getOutgoingEdges(t):this.desc.chunkedGraph.getIncomingEdges(t)).filter(e=>e.kind!==`nonvalue`),i={},a=0,o=0;for(let e of r){let t=this.direction===`precedents`?e.to:e.from,r=t.data;if(!r||(o+=1,this.nodeCount>=this.maxNodes))continue;let s=this.createNode(r);this.nodeCount+=1,this.enqueueIfWalkable(s,t.id,r,n+1),i[r.ref.toString()]=s,a+=1}a>0&&(this.direction===`precedents`?e.precedents=i:e.dependents=i),o>a&&(e.truncated={reason:`maxNodes`,totalChildren:o})}};function fc(e,t){try{let n=ce(e,t,!1);return n?n.toString():t.key}catch{return t.key}}var pc=class{model;direction;maxDepth;maxNodes;graph;visited=new Set;queue=[];nodeCount=0;constructor(e,t,n,r){this.model=e,this.direction=t,this.maxDepth=n,this.maxNodes=r,this.graph=e._graph}walk(e){let t=this.createCellNode(e);this.nodeCount=1,this.enqueueIfWalkable(t,e,0);for(let e=this.queue.shift();e!=null;e=this.queue.shift())this.populateChildren(e.node,e.id,e.depth);return{[fc(this.model,e)]:t}}enqueueIfWalkable(e,t,n){this.direction===`precedents`&&!e.formula||this.queue.push({node:e,id:t,depth:n})}createCellNode(e){let t=se(this.model,e),n={kind:`cell`,formula:t?.f??null};return mc(n,t),n}createNameNode(e){let t=se(this.model,e),n={kind:`name`,formula:t?.f??null};return mc(n,t),n}createRangeNode(e,t){let n={kind:`range`,formula:null};this.nodeCount+=1;let r=[];if(e.visitCells(e=>r.push(e)),!r.some(e=>se(this.model,e)?.f!=null))return n;let i={},a=0;for(let e of r){if(this.nodeCount>=this.maxNodes)break;let n=this.createCellNode(e);this.nodeCount+=1,i[fc(this.model,e)]=n,this.enqueueIfWalkable(n,e,t),a+=1}return n.precedents=i,r.length>a&&(n.truncated={reason:`maxNodes`,totalChildren:r.length}),n}populateChildren(e,t,n){if(this.visited.has(t.key)){e.alreadyVisited=!0;return}if(n>=this.maxDepth){e.truncated={reason:`maxDepth`};return}this.visited.add(t.key);let r=(this.direction===`precedents`?this.graph.getOutgoingEdges(t):this.graph.getIncomingEdges(t)).filter(e=>e.kind!==`nonvalue`),i={},a=0;for(let e of r){if(this.nodeCount>=this.maxNodes)break;let t=this.direction===`precedents`?e.to.id:e.from.id,r=this.createChildForId(t,n+1);r&&(i[fc(this.model,t)]=r,a+=1)}a>0&&(this.direction===`precedents`?e.precedents=i:e.dependents=i),r.length>a&&(e.truncated={reason:`maxNodes`,totalChildren:r.length})}createChildForId(e,t){if(e instanceof _){let n=this.createCellNode(e);return this.nodeCount+=1,this.enqueueIfWalkable(n,e,t),n}if(e instanceof b){let n=this.createNameNode(e);return this.nodeCount+=1,this.enqueueIfWalkable(n,e,t),n}return e instanceof ee?this.createRangeNode(e,t):null}};function mc(e,t){if(!t){e.value=null;return}let n=t.v;if(n instanceof v){e.value=null,e.errorValue=n.name;return}if(n==null||typeof n==`string`||typeof n==`number`||typeof n==`boolean`){e.value=n;return}e.value=String(n)}function hc(e,t){let n=Ks(Q(t,e)),r=e.readCell(n);return r instanceof g?r:{error:`Could not resolve reference to a cell.`}}const gc=S.object({reference:S.string().describe(`Cell reference to trace (e.g. 'C1', 'Sheet2!A1')`),mode:S.enum([`cells`,`grouped`]).default(`grouped`).describe(`Output mode: 'grouped' (default) shows chunks of cells sharing a formula pattern, labeled from nearby headers — token-efficient for structure. 'cells' drills into individual cells.`),maxDepth:S.number().int().positive().max(50).optional().describe(`Maximum recursion depth through formula cells (default 10). Range expansion does not consume depth.`),maxNodes:S.number().int().positive().max(500).optional().describe(`Total node budget for the returned tree (default 100). When the budget is exhausted, the node whose children were cut is marked truncated with totalChildren; re-query a specific cell to drill deeper.`)});function _c(e,t,n){return new Z({name:t,description:n,parameters:gc,run:(t,n)=>n.mode===`cells`?vc(t.model,e,n):yc(t.model,e,n)})}function vc(e,t,n){let r=hc(e,n.reference);return Wo(r)?r:new pc(e,t,n.maxDepth??10,n.maxNodes??100).walk(new _(r.workbookKey,r.sheetIndex,r.rowIndex,r.colIndex))}function yc(e,t,n){let r=hc(e,n.reference);if(Wo(r))return r;let i=e.getWorkbook();if(!i)return{error:`Model has no workbook.`};let a=ie(i,{which:[`parameters`,`calculated`,`chunkedGraph`],recognize2dTables:!0}),o=uc(a,new _(r.workbookKey,r.sheetIndex,r.rowIndex,r.colIndex));return o?new dc(a,t,n.maxDepth??10,n.maxNodes??100).walk(o.id,o.data):{error:`Cell ${n.reference} has no formula dependencies in this workbook.`}}const bc=_c(`dependents`,`dependents`,`Trace downstream dependents — the cells that read from a given cell, transitively.
41
+ Default mode 'grouped': cells sharing a formula pattern are collapsed into labeled chunks,
42
+ labeled from nearby headers. This provides a token-efficient structural view that shows how
43
+ values flow from parameters through intermediate calculations to outputs.
44
+
45
+ Switch to mode: "cells" to drill into individual cells: each node carries the formula, value,
46
+ and error of the dependent cell so you can see exactly how a value propagates through the sheet.
47
+ When a formula uses a range, Apiary resolves range containment internally; the dependent formula
48
+ appears as a direct child of the queried cell rather than via an intermediate range node.
49
+
50
+ "grouped" response shape — each node carries:
51
+ - type: "output" (computed, no dependents), "inter" (computed, has dependents), "data" (value range), "param" (single value cell)
52
+ - labels: human-readable names derived from nearby headers
53
+ - formula: the formula pattern for this chunk (with relative references)
54
+ - rootHeight: dependency distance from graph roots (parameters/data)
55
+ - leafDepth: dependency distance from graph leaves (outputs)
56
+ - dependents: dict of downstream chunk nodes keyed by their ref (omitted for terminal outputs)
57
+ - alreadyVisited: true when this chunk was expanded elsewhere in the tree (diamond/cycle cut)
58
+ - truncated: present when traversal stopped early; reason is "maxDepth" or "maxNodes"; totalChildren reports the real count when children were cut short
59
+
60
+ "cells" response shape — each node carries:
61
+ - kind: "cell" or "name"
62
+ - formula: the formula string, or null for value cells
63
+ - value: the calculated value
64
+ - errorValue: present only when the cell evaluates to a formula error
65
+ - dependents: a dict of child nodes keyed by their own ref (omitted for leaves with no downstream consumers)
66
+ - alreadyVisited: true when this node has been fully expanded elsewhere in the tree (diamond/cycle cut)
67
+ - truncated: present when traversal stopped early; reason is "maxDepth" or "maxNodes"; totalChildren reports the real count when children were cut short
68
+
69
+ Both modes use maxDepth (default 10, max 50) to bound recursion and maxNodes (default 100, max 500) as a global budget on the returned tree.`);function xc(e,t){let{limit:n}=t,r=t.offset??0;if(!Number.isInteger(n)||n<=0)throw Error(`sliceRange: limit must be a positive integer (got ${n})`);if(!Number.isInteger(r)||r<0)throw Error(`sliceRange: offset must be a non-negative integer (got ${r})`);let i=typeof e==`string`?new x(e):e,a=i.range;if(!a)throw Error(`sliceRange: reference has no range (got "${i.toString()}")`);let o=a.size;if(r>o)throw Error(`sliceRange: offset ${r} exceeds totalCells ${o} for "${i.toString()}"`);let s=a.width,c=Math.min(r+n,o),l=[];for(let e=r;e<c;e++)l.push({row:a.top+Math.floor(e/s),column:a.left+e%s});let u=l.length,d=r+u,f=d<o;return{coords:l,sheetName:i.sheetName,reference:i.toString(),totalCells:o,returnedCells:u,offset:r,nextOffset:f?d:void 0,truncated:f}}function Sc(e,t,n){let r=n.offset??0,i=new x(t),a=i.range?.size??1,o={includeStyles:n.includeStyles,maxFormulas:n.maxFormulas,mismatches:n.mismatches};if(i.range===null||a===1&&r===0)return Ys(e,t,o);let s=xc(i,{offset:r,limit:n.limit}),c=Xs(e,s.sheetName,s.coords,o);return s.truncated&&s.nextOffset!==void 0?{data:c,truncated:!0,totalCells:s.totalCells,returnedCells:s.returnedCells,offset:s.offset,nextOffset:s.nextOffset,reference:s.reference}:c}const Cc=new Z({name:`inspect`,description:`Inspect detailed per-cell information including value, formula, number format, style, and hyperlink.
70
+ Returns up to 20 cells per call. When the range is larger, the response is truncated and includes \`nextOffset\` — call again with the same \`reference\` and \`offset: <nextOffset>\` to continue.
71
+
72
+ Examples:
73
+ - Single cell: { "reference": "A1" }
74
+ - Range: { "reference": "B2:C5" }
75
+ - Cross-sheet: { "reference": "Sheet2!A1" }
76
+ - Next page: { "reference": "A1:K10", "offset": 20 }`,parameters:S.object({reference:S.string().describe(`Cell reference or range to inspect (e.g. 'A1', 'B2:C5', 'Sheet2!A1')`),offset:S.number().int().nonnegative().optional().describe("Pagination offset into the range (0-based, row-major). When the previous response had `nextOffset`, pass that value here to read the next page.")}),run:(e,t)=>Sc(e.model,Q(t.reference,e.model),{offset:t.offset,limit:20,includeStyles:!0,mismatches:e.mismatches})}),wc=_c(`precedents`,`precedents`,`Trace upstream dependencies — the cells a formula reads from, transitively.
77
+ Default mode 'grouped': cells sharing a formula pattern are collapsed into labeled chunks,
78
+ labeled from nearby headers. This provides a token-efficient structural view that surfaces
79
+ which parameters feed into which outputs.
80
+
81
+ Switch to mode: "cells" to drill into individual cells: each node carries the formula,
82
+ calculated value, and error (e.g. #DIV/0!) so you can follow error propagation to its source.
83
+ Ranges referenced by formulas appear as 'range' nodes. If every range member is a leaf value
84
+ cell, the range is collapsed into a single node with no further children.
85
+
86
+ "grouped" response shape — each node carries:
87
+ - type: "output" (computed, no dependents), "inter" (computed, has dependents), "data" (value range), "param" (single value cell)
88
+ - labels: human-readable names derived from nearby headers
89
+ - formula: the formula pattern for this chunk (with relative references)
90
+ - rootHeight: dependency distance from graph roots (parameters/data)
91
+ - leafDepth: dependency distance from graph leaves (outputs)
92
+ - precedents: dict of upstream chunk nodes keyed by their ref (omitted for leaves)
93
+ - alreadyVisited: true when this chunk was expanded elsewhere in the tree (diamond/cycle cut)
94
+ - truncated: present when traversal stopped early; reason is "maxDepth" or "maxNodes"; totalChildren reports the real count when children were cut short
95
+
96
+ "cells" response shape — each node carries:
97
+ - kind: "cell", "range", or "name"
98
+ - formula: the formula string, or null for value cells and range vertices
99
+ - value: the calculated value (cell and name nodes)
100
+ - errorValue: present only when the cell evaluates to a formula error
101
+ - precedents: a dict of child nodes keyed by their own ref (omitted for leaves)
102
+ - alreadyVisited: true when this node has been fully expanded elsewhere in the tree (diamond/cycle cut)
103
+ - truncated: present when traversal stopped early; reason is "maxDepth" or "maxNodes"; totalChildren reports the real count when children were cut short
104
+
105
+ Both modes use maxDepth (default 10, max 50) to bound recursion and maxNodes (default 100, max 500) as a global budget on the returned tree.`),Tc=new Z({name:`symbols`,description:`Get workbook structural metadata: sheet dimensions, named ranges, tables, and dependency graph stats.
106
+ Complements describeStructure (which provides labels and data regions) with structural/entity information.
107
+
108
+ Use this to understand the workbook's overall shape before inspecting specific cells.`,parameters:S.object({}),run:(e,t)=>{let n=e.model.getWorkbook();if(!n)return{error:`No workbook loaded`};let r=n.getSheets().map(e=>({name:e.name,size:e.getSize()})),i=[],a=[];for(let t of e.model.getEntities())t.type===`name`?i.push({name:t.name,formula:t.resolvesTo,scope:`workbook`}):t.type===`table`&&a.push({name:t.name,sheet:t.sheetName,ref:t.resolvesTo,headers:t.headers,totals:t.totals});let o=e.model.meta;return{sheets:r,namedRanges:i,tables:a,stats:{cells:o.cellCount,graphNodes:o.graphNodes,graphEdges:o.graphEdges}}}}),Ec=new Z({name:`whatIf`,description:`Test hypothetical value changes and see which formula cells are affected.
109
+ Applies temporary changes, recalculates, shows before/after diff of affected formula cells,
110
+ then restores the original state. A string value starting with "=" is applied as a temporary
111
+ formula. Max 20 changes, max 100 affected cells reported.
112
+
113
+ Example: { "changes": { "A1": 50, "B1": "=A1*2" } }`,parameters:S.object({changes:S.record(S.string(),S.union([S.string(),S.number(),S.boolean(),S.null()])).describe(`Map of cell references to hypothetical values (e.g. { 'A1': 50, 'B1': 100 })`)}),run:(e,t)=>{let n=Object.entries(t.changes);return n.length===0?{error:`No changes provided.`}:n.length>20?{error:`Too many changes (${n.length}). Maximum is 20.`}:ds(e.model,e=>{let t=[],r=[];for(let[e,i]of n)typeof i==`string`&&i.startsWith(`=`)?r.push([e,i.slice(1)]):t.push([e,i]);t.length>0&&e.writeMultiple(t,{skipRecalc:!0});for(let[t,n]of r)e.getWorkbook(new x(t).workbookName||null)?.editCell(t,{f:n});e.recalculate();let i=Uo(e).lastRecalc,a={},o=0;if(i?.formulaCellsUpdated){for(let[t,n]of i.formulaCellsUpdated)if(o++,o<=100&&t instanceof g){let r=fc(e,new _(t.workbookKey,t.sheetIndex,t.rowIndex,t.colIndex));a[r]={before:Vs(n),after:Vs(t.v),formula:t.f??null}}}let s={};for(let[e,t]of n)s[e]=t;let c={applied:s,affected:a};return o>100&&(c.truncated=!0,c.totalAffected=o),c},n.map(([e])=>e))}}),Dc=S.object({sheet:S.string().optional().describe(`Restrict to a single sheet by name.`),range:S.string().optional().describe(`Restrict to a range, e.g. 'Sheet1!B2:D10' or 'B2:D10' (resolved against the default/first sheet). Takes precedence over 'sheet' if both are given.`),max:S.number().int().positive().optional().describe(`Max cells listed per formula-error group (default 50).`)});function Oc(e){return e>=3?`ERROR`:e===2?`WARNING`:`NOTICE`}function kc(e,t,n,r){if(!t&&!n)return!0;let i=Array.from(e.references);if(n&&!t){let e=`${n}!`;return i.some(t=>t.startsWith(e)||!t.includes(`!`))}return!t||i.some(e=>{if(e.startsWith(`[`))return!1;try{let n=new x(e,{ctx:r});return t.contains(n)}catch{return!1}})}const Ac=new Z({name:`listErrors`,description:`List all formula errors and model errors in a workbook, grouped by error kind. Results are scoped to a sheet or range when provided, and truncated per group when the default cell limit is exceeded.`,parameters:Dc,run:(e,t)=>{let n=t.max??50,r=e.model.getWorkbook();if(!r)return{error:`Model has no workbook.`};let i,a;t.range?(i=new x(t.range,{ctx:e.model}),a=i.sheetName??r.getSheets()[0]?.name):t.sheet&&(a=t.sheet);let o=a===void 0?r.getSheets():[r.getSheet(a)].filter(e=>e!==null),s=new Map;function c(e,t,n){let r=t.detail?`${t.name} (${t.detail})`:t.name,i=`${n}\x00${r}`,a=s.get(i);a||(a={key:r,cells:[],sheet:n},s.set(i,a)),a.cells.push(e.toString())}for(let e of o)if(i)for(let t of i){let n=e.getCell(t.getCellId());!n||!(n.v instanceof v)||c(new x(n.id,{sheetName:e.name}),n.v,e.name)}else for(let t of e.getCells())t.v instanceof v&&c(new x(t.id,{sheetName:e.name}),t.v,e.name);let l=[],u=0,d={},f=0;for(let[,e]of s){let t=e.cells.length;u+=t,d[e.sheet]=(d[e.sheet]??0)+t;let r=e.cells.slice(0,n),i=t-r.length;l.push({key:e.key,count:t,cells:r,...i>0?{omittedCells:i}:{}}),i>0&&f++}let p=[];for(let t of r.errors)kc(t,i,a,e.model)&&p.push({type:t.type,level:Oc(t.level),message:t.message,references:Array.from(t.references)});return{formulaErrors:{groups:l,totalCells:u,perSheet:d},modelErrors:{entries:p,total:p.length},...f>0?{truncated:{groupsWithOmittedCells:f,hint:`Some groups had cells omitted. Narrow the scope using the sheet or range parameter, or increase max.`}}:{}}}}),jc=96/72,Mc={W:1.5,M:1.4,"@":1.4,m:1.2,w:1.2,i:.4,l:.4,I:.4,j:.4," ":.5,".":.5,",":.5,":":.5,";":.5};function Nc(e,t){let{fontSize:n,isBold:r}=t,i=0;for(let t of e){let e=Mc[t]||1;i+=e}let a=n/11,o=r?1.2:1,s=t.isItalic?.95:1,c=i*a*o*s;return Math.min(500,c*7)}function Pc(e,t){return t.fontSize*jc}function Fc(e,t,n){let r=7*(t.fontSize/11)*(t.isBold?1.2:1),i=n-7,a=Math.max(1,Math.floor(i/r));return Math.ceil(e.length/a)*Pc(e,t)}function Ic(e){try{return n(e.z||`General`,e.v)}catch{return`######`}}function Lc(e){let t=e.style;return{fontFamily:t?.fontFamily||`Calibri`,fontSize:t?.fontSize||12,isBold:t?.bold||!1,isItalic:t?.italic||!1,isWrapped:t?.wrapText||!1}}function Rc(e,t){let[,n]=e.getSize(),r=0,i=0;for(let a=0;a<n&&i<300;a++){let n=e.getCellByRange({top:a,left:t});if(!n||n.v==null)continue;i++;let o=Ic(n);if(!o)continue;let s=Nc(o,Lc(n));if(s>r&&(r=s),r>=500)break}return(r+7)/7+.5}function zc(e,t){let n=e.col_widths?.[t],r=e.defaults?.col_width;return((n??r??8.43)-.5)*7}function Bc(e,t){let[n]=e.getSize(),r=0,i=0;for(let a=0;a<n&&i<300;a++){let n=e.getCellByRange({top:t,left:a});if(!n||n.v==null)continue;i++;let o=Ic(n);if(!o)continue;let s=Lc(n),c=s.isWrapped?Fc(o,s,zc(e,a)):Pc(o,s);if(c>r&&(r=c),r>=409*1.3333333333333333)break}let a=(r+5)/jc;return Math.max(a,16)}const Vc=new Z({name:`manageRowsAndColumns`,description:`Insert, delete, or auto-size rows and columns.
114
+ Operations are executed in order: column insert → column delete → row insert → row delete → column autosize → row autosize.`,parameters:S.object({sheet:S.string().describe(`Sheet name to operate on`),columns:S.object({insert:S.object({column:S.string().describe(`Column letter (e.g., "A", "B", "AA")`),count:S.number().describe(`Number of columns to insert`)}).optional(),delete:S.object({column:S.string().describe(`Column letter (e.g., "A", "B", "AA")`),count:S.number().describe(`Number of columns to delete`)}).optional(),autoSize:S.array(S.string()).optional().describe(`Array of column letters to auto-size (e.g., ["A", "B", "C"])`)}).optional().describe(`Column operations`),rows:S.object({insert:S.object({row:S.number().describe(`1-based row number (e.g., 1, 2, 10)`),count:S.number().describe(`Number of rows to insert`)}).optional(),delete:S.object({row:S.number().describe(`1-based row number (e.g., 1, 2, 10)`),count:S.number().describe(`Number of rows to delete`)}).optional(),autoSize:S.array(S.number()).optional().describe(`Array of 1-based row numbers to auto-size (e.g., [1, 2, 3])`)}).optional().describe(`Row operations`),note:S.string().optional().describe(`Description of this operation for version history`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n,i=r.getSheet(t.sheet);if(!i)return{error:`Sheet not found: ${t.sheet}`};let{columns:a,rows:o}=t;if(a?.insert){let e=Ko(a.insert.column);r.insertColumns(t.sheet,e,a.insert.count,!1)}if(a?.delete){let e=Ko(a.delete.column);r.deleteColumns(t.sheet,e,a.delete.count)}if(o?.insert){let e=o.insert.row-1;r.insertRows(t.sheet,e,o.insert.count,!1)}if(o?.delete){let e=o.delete.row-1;r.deleteRows(t.sheet,e,o.delete.count)}if(a?.autoSize)for(let e of a.autoSize){let n=Ko(e),a=Rc(i,n);r.setColumnWidth(t.sheet,n,a)}if(o?.autoSize)for(let e of o.autoSize){let n=e-1,a=Bc(i,n);r.setRowHeight(t.sheet,n,a)}return{success:!0,changedCells:ws(e.model)}}}),Hc={visible:0,hidden:1,veryHidden:2},Uc=new Z({name:`manageSheets`,description:`Add, remove, rename, or change visibility of sheets.
115
+ Operations are executed in order: add → rename → setVisibility → remove.`,parameters:S.object({add:S.object({name:S.string().describe(`Name for the new sheet`)}).optional().describe(`Add a new sheet`),remove:S.object({sheet:S.string().describe(`Name of the sheet to remove`)}).optional().describe(`Remove a sheet`),rename:S.object({sheet:S.string().describe(`Current name of the sheet`),name:S.string().describe(`New name for the sheet`)}).optional().describe(`Rename a sheet`),setVisibility:S.object({sheet:S.string().describe(`Name of the sheet`),hidden:S.enum([`visible`,`hidden`,`veryHidden`]).describe(`visible = normal, hidden = hidden tab, veryHidden = cannot be unhidden from UI`)}).optional().describe(`Set sheet visibility`),note:S.string().optional().describe(`Description of this operation for version history`)}),run:(e,t)=>{let n=Go(e.model);if(`error`in n)return{error:n.error};let{workbook:r}=n;if(t.add&&r.addSheet(t.add.name),t.rename){if(!r.getSheet(t.rename.sheet))return{error:`Sheet not found: ${t.rename.sheet}`};r.renameSheet(t.rename.sheet,t.rename.name)}if(t.setVisibility){let e=r.getSheet(t.setVisibility.sheet);if(!e)return{error:`Sheet not found: ${t.setVisibility.sheet}`};e.hidden=Hc[t.setVisibility.hidden]}return t.remove&&!r.removeSheet(t.remove.sheet)?{error:`Sheet not found: ${t.remove.sheet}`}:{success:!0,sheets:r.getSheets().map(e=>e.name)}}});function Wc(e){return/QUERY/i.test(e)?e.replace(/QUERY\s*\(([^,]+),\s*"(.+)"(.*)\)/gi,(e,t,n,r)=>`QUERY(${t}, "${n.replace(/"/g,`'`)}"${r})`):e}const Gc=S.object({read:S.array(S.string()).describe(`Cell references, ranges, or formulas to read. Examples: "A1", "B1:B10", "Sheet1!C5", "=XLOOKUP(\\"Revenue\\", A1:A10, B1:B10)", "=AVERAGE(C1:C10)"`),apply:S.array(S.object({cell:S.string(),value:S.union([S.string(),S.number(),S.boolean(),S.null()])})).optional().describe(`Temporary values to apply before reading (not persisted)`),cursors:S.record(S.string(),S.number().int().nonnegative()).optional().describe("Optional pagination cursors keyed by entries in `read`. Pass `nextOffset` from a previous truncated response to continue paging through that range. Formula entries (those starting with `=`) ignore cursors.")});function Kc(e){return e.startsWith(`=`)||/^[A-Z]+\s*\(/i.test(e)}function qc(e,t){let n=e.read.map(e=>{if(Kc(e))return{original:e,normalized:e};let n=Q(e,t);if(ae(n)===null)throw Error(`Invalid cell reference: "${e}". Sheet names with special characters must be quoted (e.g., "'My Sheet'!A1").`);return{original:e,normalized:n}});return{reads:n,apply:(e.apply??[]).map(({cell:e,value:n})=>{let r=Q(e,t);if(ae(r)===null)throw Error(`Invalid cell reference: "${e}". Sheet names with special characters must be quoted (e.g., "'My Sheet'!A1").`);return{cell:r,value:n}}),cursors:Jc(e.cursors,n,t)}}function Jc(e,t,n){if(!e)return;let r=new Map;for(let e of t)r.set(e.original,e.original),r.has(e.normalized)||r.set(e.normalized,e.original);let i={};for(let[t,a]of Object.entries(e)){let e=r.get(t);if(!e)try{e=r.get(Q(t,n))}catch{}if(!e)throw Error(`Unknown cursor key "${t}". Cursor keys must match an entry in \`read\` (either verbatim or in the canonical form echoed by \`reference\`).`);i[e]=a}return i}function Yc(e,t,n){try{return Ys(e,t,n)}catch(r){if(r instanceof Error&&/QUERY/i.test(t)){let r=Wc(t);if(r!==t)try{return Ys(e,r,n)}catch{}}return{error:r instanceof Error?r.message:`Unknown error`}}}function Xc(e,t,n,r){let i={},a={maxFormulas:10,mismatches:r};for(let{original:r,normalized:o}of t)try{if(Kc(o)){i[r]=Yc(e,o,a);continue}i[r]=Sc(e,o,{offset:n?.[r],limit:500,...a})}catch(e){i[r]={error:e instanceof Error?e.message:`Unknown error`}}return i}const Zc=new Z({name:`readCalculatedValues`,description:`Read cell values, formula results, and lookups from spreadsheets, and optionally apply temporary values for what-if calculations.
116
+ The 'read' array accepts cell references, ranges, and formulas. Use formulas like XLOOKUP, QUERY, AVERAGE, etc. directly in 'read' to find and compute values in a single call.
117
+
118
+ Examples:
119
+ - Read cells: { "read": ["A1", "B1:B10", "Sheet2!C5"] }
120
+ - Lookup: { "read": ["=XLOOKUP(\\"Revenue\\", A1:A10, B1:B10)"] }
121
+ - Filtered average: { "read": ["=QUERY(Sheet1!A1:D100, \\"SELECT AVG(D) WHERE A = 'Category1'\\")"] }
122
+ - What-if: { "read": ["C8"], "apply": [{ "cell": "B1", "value": 100 }] }
123
+
124
+ Large ranges are automatically truncated. When a range entry is truncated the response includes \`nextOffset\` — call again with \`cursors: { "<same expression>": <nextOffset> }\` to read the next page.`,parameters:Gc,run:(e,t)=>{let n=qc(t,e.model);return n.apply.length>0?ds(e.model,t=>{let r=n.apply.map(({cell:e,value:t})=>[e,t]);return t.writeMultiple(r,{skipRecalc:!0}),t.recalculate(),Xc(t,n.reads,n.cursors,e.mismatches)},n.apply.map(({cell:e})=>e)):Xc(e.model,n.reads,n.cursors,e.mismatches)}}),Qc=S.object({apply:S.array(S.object({cell:S.string().describe(`Cell reference`),value:S.union([S.string(),S.number(),S.boolean(),S.null()]).describe(`Temporary value to apply`)})).optional().describe(`Optional temporary values to apply before running formula(s)`),formula:S.string().optional().describe(`Single formula to evaluate (must start with "=")`),formulas:S.array(S.string()).optional().describe(`Array of formulas to evaluate (more efficient for multiple formulas)`),sheet:S.string().optional().describe(`Sheet name against which bare cell references (e.g. A1, SUM(A:A)) resolve. Defaults to the primary workbook's first sheet. Use this when you need formulas to evaluate in the context of a different sheet. Sheet names are matched across all workbooks in the model; on a name collision the primary workbook's sheet wins, so external sheets with colliding names are only reachable via workbook-qualified references in the formula itself.`)});function $c(e,t,n){try{return Ys(e,t,{evalContext:n})}catch(r){if(r instanceof Error&&/QUERY/i.test(t)){let r=Wc(t);if(r!==t)try{return Ys(e,r,{evalContext:n})}catch{}}return{error:r instanceof Error?r.message:`Unknown error`}}}const el=new Z({name:`runFormula`,description:`Run one or more formulas without writing to any cell. Returns the calculated results.
125
+ Useful for testing formulas or computing values without modifying the workbook.
126
+
127
+ Examples:
128
+ - Single: { "formula": "=SUM(A1:A10)" }
129
+ - Batch: { "formulas": ["=SUM(A1:A10)", "=AVERAGE(B1:B10)", "=COUNT(C1:C10)"] }
130
+ - With temp values: { "formula": "=A1*B1", "apply": [{ "cell": "A1", "value": 5 }] }
131
+ - Against a specific sheet: { "formula": "=SUM(A:A)", "sheet": "Sheet2" }
132
+
133
+ Use "formulas" array to test multiple formulas in one call (more efficient than multiple calls).
134
+
135
+ Bare cell references (e.g. A1, SUM(A:A)) resolve against the primary workbook's first sheet
136
+ by default. Use the "sheet" parameter when you need them to resolve against a different sheet.
137
+ The response includes a "_note" field identifying the sheet bare references resolved
138
+ against, so you can verify they resolved where you intended.
139
+
140
+ Sheets in external (linked) workbooks can be read with workbook-qualified references inside
141
+ the formula itself, e.g. ='[external.xlsx]Sheet1'!A1. If an external sheet shares its name
142
+ with a sheet in the primary workbook, the primary workbook's sheet always wins for plain
143
+ references — only the workbook-qualified form reaches the external one.`,parameters:Qc,run:(e,t)=>{let n=t.formulas??(t.formula?[t.formula]:[]);if(n.length===0)return{error:`Either "formula" or "formulas" is required`};let r=(t.apply??[]).map(({cell:t,value:n})=>({cell:Q(t,e.model),value:n})),i=e.model.resolveSheet(t.sheet);if(t.sheet&&!i)return{error:`Sheet "${t.sheet}" not found.`};let a=e.model.getWorkbook()?.name??null,o=i?.name??null,s={workbookName:a,sheetName:o},c=e=>{let r={};for(let t of n){let n=$c(e,t,s);if(n&&typeof n==`object`&&`ref`in n){let{ref:e,...i}=n;r[t]=i}else r[t]=n}return o&&(r._note=t.sheet?`Resolved bare cell references against sheet "${o}"`:`Resolved bare cell references against ${a?`[${a}]`:``}${o}`),r};return r.length>0?ds(e.model,e=>{let t=r.map(({cell:e,value:t})=>[e,t]);return e.writeMultiple(t,{skipRecalc:!0}),e.recalculate(),c(e)},r.map(({cell:e})=>e)):c(e.model)}}),tl=S.enum([`value`,`rawValue`,`fontColor`,`fill`,`numberFormat`,`formula`]),nl=S.object({reference:S.string().describe(`A1 range to view, sheet-qualified where needed (e.g. "'LBO Model'!B40:N80"). A single cell is allowed.`),show:tl.optional().describe(`What each cell renders. 'value' (default): formatted display values; a † marks a number whose format hides that it is numeric (a date, an accounting dash) — a legend below the grid explains it. 'rawValue': underlying unformatted values. 'fontColor'/'fill'/'numberFormat': that style property ('-' when unset; colors as lowercase hex for RGB, raw token for theme/preset/indexed colors). 'formula': formula cells render a short key like [1] with a legend below the grid — formulas are compared in R1C1 form, so a formula filled across a range shares one key and anomalies stand out; non-formula cells show their raw value, so hardcoded overrides stand out too.`)});function rl(e,t){if(!e)return`-`;if(t===`numberFormat`)return e.numberFormat??`-`;let n=t===`fill`?e.fillColor:e.color;return n?Bs(n):`-`}function il(e){return e?e.t===`e`?e.error?.name??String(e.v??``):typeof e.formatted==`string`?e.formatted:al(e.v):``}function al(e){return e==null?``:typeof e==`boolean`?e?`TRUE`:`FALSE`:String(e)}function ol(e,t){let n=e.getWorkbook(),r=t||n?.getSheets()[0]?.name,i=r?n?.getSheet(r):null;if(!i)throw Error(`viewRange: sheet "${r}" not found`);return i}function sl(e,t,n){let r=ol(e,t);return{textAt:(e,t)=>rl(r.getCellByRange({top:t,left:e})?.style,n)}}function cl(e,t){let n=ol(e,t);return{textAt:(e,t)=>al(n.getCellByRange({top:t,left:e})?.v)}}function ll(e,t){let n=ol(e,t),r=new Map,i=[];return{textAt:(e,t)=>{let a=n.getCellByRange({top:t,left:e});if(!a)return``;if(!a.f)return al(a.v);let o=Lr(a.f,a.id),s=r.get(o);return s===void 0&&(s=r.size+1,r.set(o,s),i.push(`[${s}] =${o}`)),`[${s}]`},footer:()=>i.length>0?[``,`Formulas:`,...i]:[]}}function ul(e,t){return e?.t===`n`&&m(t)==null}function dl(e,t,n){let r=[];for(let e=0;e<n.rowsShown;e++)for(let t=0;t<n.colsShown;t++)r.push({row:n.top+e,column:n.left+t});let i=Xs(e,t,r),a=!1;return{textAt:(e,t)=>{let n=i[qs(e,t)],r=il(n);return ul(n,r)?(a=!0,`${r}†`):r},footer:()=>a?[``,`† = formatted number (date/time/accounting); the value is numeric, not text — write the number or date, not this string.`]:[]}}function fl(e,t,n,r){switch(n){case`value`:return dl(e,t,r);case`rawValue`:return cl(e,t);case`fontColor`:case`fill`:case`numberFormat`:return sl(e,t,n);case`formula`:return ll(e,t)}}function pl(e,t,n=`value`){let r=new x(Q(t,e)),i=r.range;if(!i)throw Error(`viewRange: "${t}" is not a cell or range reference`);let{top:a,left:o,width:s,height:c}=i,l=Math.min(s,500),u=Math.min(c,Math.max(1,Math.floor(500/l))),d=fl(e,r.sheetName,n,{top:a,left:o,rowsShown:u,colsShown:l}),{textAt:f}=d,p=Array.from({length:l},(e,t)=>re(o+t)),m=Array.from({length:u},(e,t)=>String(a+t+1)),h=m.map((e,t)=>p.map((e,n)=>f(o+n,a+t))),g=Math.max(...m.map(e=>e.length),0),_=p.map((e,t)=>Math.max(e.length,...h.map(e=>e[t]?.length??0))),v=(e,t)=>`${e.padStart(g)} | ${t.map((e,t)=>e.padEnd(_[t]??0)).join(` | `)}`,y=[v(``,p),`${`-`.repeat(g)}-+-${_.map(e=>`-`.repeat(e)).join(`-+-`)}`,...h.map((e,t)=>v(m[t]??``,e))],b=[];return u<c&&b.push(`rows ${a+u+1}–${i.bottom+1}`),l<s&&b.push(`columns ${re(o+l)}–${re(i.right)}`),b.length>0&&y.push(``,`… showing ${u}×${l} of ${c}×${s} cells (cap 500). Request ${b.join(` and `)} in a follow-up call.`),y.push(...d.footer?.()??[]),y.join(`
144
+ `)}const ml=new Z({name:`viewRange`,description:`Render a worksheet rectangle as a compact text grid — by default the displayed (number-formatted) values, what a human sees in the cells — with column letters and row numbers.
145
+ Use this FIRST to scan or orient in an area (a financial statement, a block, a table): one call returns the whole rectangle instead of reading it cell-by-cell.
146
+ Pass \`show\` to audit other layers of the same grid: raw unformatted values, a style property ('-' marks unset cells), or the formula structure — formula cells get a legend key, identical fills share one key, so a miscolored cell, a wrong format, or a hardcoded override stands out against the value grid you just read.
147
+ For precedents/dependents or error provenance, use \`inspect\`.
148
+ Returns at most 500 cells; a larger rectangle renders the cells that fit and names the rows or columns that remain — request those in a follow-up call.
149
+
150
+ Examples:
151
+ - Range: { "reference": "B40:N80" }
152
+ - Sheet-qualified: { "reference": "'LBO Model'!B40:N80" }
153
+ - Single cell: { "reference": "C12" }
154
+ - Font colors: { "reference": "B40:N80", "show": "fontColor" }
155
+ - Formula structure: { "reference": "B40:N80", "show": "formula" }`,parameters:nl,run:(e,t)=>pl(e.model,t.reference,t.show)}),hl=S.object({reference:S.string().describe(`A1 range to capture, sheet-qualified where needed (e.g. "'LBO Model'!B40:N80"). A single cell is allowed.`),headers:S.boolean().default(!0).describe(`Draw row/column headers (A, B, C … / 1, 2, 3 …).`),scale:S.number().min(1).max(4).default(2).describe(`Output pixel density for headless (Node/Worker) rendering — 2 = crisp/retina. Ignored on a browser main thread, where the display's devicePixelRatio governs.`)});function gl(e){return import(e)}let _l;function vl(e){return _l??=(async()=>{try{let[t,n,r,i]=await Promise.all([gl(`node:fs`),gl(`node:module`),gl(`node:path`),gl(`@grid-is/fontstack`)]),a=r.join(r.dirname(n.createRequire(import.meta.url).resolve(`@grid-is/fontstack`)),`..`,`fonts`);for(let n of i.availableFonts()){let{id:r,license:i}=n,o=[n.regular?`${a}/${i}/${r}/${r}-regular.ttf`:``,n.bold?`${a}/${i}/${r}/${r}-bold.ttf`:``,n.italic?`${a}/${i}/${r}/${r}-italic.ttf`:``,n.boldItalic?`${a}/${i}/${r}/${r}-bolditalic.ttf`:``].filter(e=>e!==``&&t.existsSync(e));o.length>0&&e.use(n.name,o)}}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`captureRange: font registration unavailable (${t}); rendering with system fonts.`)}})(),_l}function yl(e,t,n,r){let i=`window`in globalThis,a=Reflect.get(globalThis,`window`);Reflect.set(globalThis,`window`,{devicePixelRatio:r});try{e.resize(t,n),e.render(t,n)}finally{i?Reflect.set(globalThis,`window`,a):Reflect.deleteProperty(globalThis,`window`)}}async function bl(e,t,n){if(typeof OffscreenCanvas<`u`){let r=new OffscreenCanvas(t.width,t.height);yl(e,r,t,n);let i=await r.convertToBlob({type:`image/png`});return new Uint8Array(await i.arrayBuffer())}let r=await gl(`skia-canvas`).catch(()=>{throw Error(`captureRange: no canvas backend (browser OffscreenCanvas or Node skia-canvas).`)});await vl(r.FontLibrary);let i=new r.Canvas(t.width,t.height);return yl(e,i,t,n),i.toBufferSync(`png`)}const xl=new Z({name:`captureRange`,description:`Render a range as a PNG image and return its raw bytes (Uint8Array).
156
+
157
+ Use this when the formatting itself is the information — fills, font colors, borders,
158
+ merged cells, number formats — that the text-grid tools (viewRange) can't convey, or when
159
+ the user asks to *see* part of the workbook. The bytes are ready to attach to a multimodal
160
+ message or write to a file; this tool does no LLM wiring itself.
161
+
162
+ Gridlines and row/column headers render as Excel shows them. Renders against the browser's
163
+ native canvas when available, and skia-canvas in Node.`,parameters:hl,run:async(e,t)=>{try{let n=Go(e.model);if(`error`in n)return n;let{workbook:r}=n,i=Q(t.reference,e.model),a=new x(i);if(!a.range)return{error:`captureRange: "${t.reference}" is not a cell or range reference`};let o=a.sheetName||r.getSheets()[0]?.name;if(!o)return{error:`captureRange: no sheet to render`};let s=new Ho({headers:t.headers});return s.setWorkbook(r),s.setSheet(o),await bl(s,s.refToRect(new Sa(i,{sheetName:o})),t.scale)}catch(e){return{error:e instanceof Error?e.message:String(e)}}}});function $(e,t,n=`${t}s`){return`${e} ${e===1?t:n}`}function Sl(e){try{return new x(e).withPrefix({workbookName:``}).toString()}catch{return e}}function Cl(e){let t=Tc.execute({model:e},{});if(Wo(t))return null;let n=ps.execute({model:e},{});return Wo(n)?null:wl(t,n,e.getWorkbook()?.name??void 0)}function wl(e,t,n){let r=[];if(r.push(`## Workbook Summary`),r.push(``),e.stats.cells===0){let t=`${$(e.sheets.length,`sheet`)}, 0 cells. The workbook is empty.`;return r.push(n?`"${n}" — ${t}`:t),r.join(`
164
+ `).trimEnd()}let i=t.sheets.reduce((e,t)=>e+t.formulaCount,0),a=`${$(e.sheets.length,`sheet`)}, ${$(e.stats.cells,`total cell`)}, ${$(i,`formula`)}.`;if(r.push(n?`"${n}" \u2014 ${a}`:a),r.push(``),e.namedRanges.length>0){r.push(`Defined names:`);let t=e.namedRanges.slice(0,10);for(let e of t){let t=e.formula==null?``:` = ${Sl(e.formula)}`;r.push(`- ${e.name}${t}`)}e.namedRanges.length>10&&r.push(`- ... ${$(e.namedRanges.length-10,`more defined name`)}`),r.push(``)}if(e.tables.length>0){r.push(`Tables:`);let t=e.tables.slice(0,10);for(let e of t){let t=e.headers?`, ${$(e.headers,`header row`)}`:``,n=e.totals?`, ${$(e.totals,`totals row`)}`:``;r.push(`- ${e.name} on "${e.sheet}" (${Sl(e.ref)}${t}${n})`)}e.tables.length>10&&r.push(`- ... ${$(e.tables.length-10,`more table`)}`),r.push(``)}let o=new Map(t.sheets.map(e=>[e.name,e]));for(let[t,n]of e.sheets.entries()){let e=o.get(n.name),[i,a]=n.size,s=e?.cellCount??0,c=e?.formulaCount??0,l=e?.errorCount,u=`${$(a,`row`)}, ${$(i,`column`)}, ${$(s,`cell`)}, ${$(c,`formula`)}`;if(l&&(u+=`, ${$(l,`error`)}`),r.push(`Sheet "${n.name}" \u2014 ${u}`),e){let i=e.totalLabels??e.labels.length;if(t<8){let t=e.labels.slice(0,15);for(let e of t)r.push(`- ${e}`);if(i>t.length){let e=i-t.length,a=JSON.stringify([n.name]);r.push(`- ... ${$(e,`more label`)} (use describeStructure({sheets: ${a}, labelOffset: ${t.length}}) to page forward)`)}}else if(i>0){let e=JSON.stringify([n.name]);r.push(`- ${$(i,`label`)} (use describeStructure({sheets: ${e}}) to see them)`)}}r.push(``)}return r.join(`
165
+ `).trimEnd()}const Tl=[ps,Zc,el,js,zs,Uc,Vc,Cs,cc,lc,Tc,ml,Cc,Ec,wc,bc,Ac,os,as,oc];export{Tc as C,Tl as S,Ec as T,Vc as _,Cs as a,Zc as b,oc as c,os as d,cc as f,Ac as g,Wo as h,ps as i,Cl as l,Cc as m,xl as n,js as o,lc as p,bc as r,zs as s,Z as t,as as u,Uc as v,ml as w,el as x,wc as y};