@trebco/treb 36.1.2 → 36.1.4

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.
@@ -1,8 +1,8 @@
1
- /*! TREB v36.1.2. Copyright 2018-2026 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
- import{A as or,B as fe,C as ae,D as Re,E as R,F as we,G as Ee,H as ir,I as Pe,J as ft,K as gt,L as sr,M as lr,O as cr,P as ur,Q as dr,R as mr,c as Ue,d as Jt,e as K,f as bt,g as z,h as X,i as pt,j as Ae,k as Yt,l as Zt,n as ee,o as Kt,q as Qt,r as er,s as ht,t as T,u as B,v as tr,w as le,x as rr,y as nr,z as ar}from"./chunk-4CKS56PE.mjs";var He=class a{static type="vertex";type=a.type;color=0;edges_in=new Set;edges_out=new Set;get has_inbound_edges(){return this.edges_in.size>0}get has_outbound_edges(){return this.edges_out.size>0}Reset(){for(let e of this.edges_out)e.RemoveDependency(this);for(let e of this.edges_in)e.RemoveDependent(this);this.edges_out.clear(),this.edges_in.clear()}ClearDependencies(){for(let e of this.edges_in)e.RemoveDependent(this);this.edges_in.clear()}AddDependent(e){e!==this&&(this.edges_out.has(e)||this.edges_out.add(e))}RemoveDependent(e){this.edges_out.delete(e)}AddDependency(e){e!==this&&(this.edges_in.has(e)||this.edges_in.add(e))}RemoveDependency(e){this.edges_in.delete(e)}LinkTo(e){this.AddDependent(e),e.AddDependency(this)}DependsOn(e){this.AddDependency(e),e.AddDependent(this)}LoopCheck(){let e=[this];for(;e.length;){let t=e[e.length-1],r=!0;if(t.color!==2){t.color=1;for(let n of t.edges_out){if(n.color===1)return this.color=0,!0;n.color===0&&n.edges_out.size&&(e.push(n),r=!1)}}r&&(t.color=2,e.pop())}return this.color=2,!1}};var Ce=class extends He{dirty=!1};var br={error:"NOTIMPL"},Y=()=>({type:7,value:"N/A"}),q=()=>({type:7,value:"EXPR"});var W=()=>({type:7,value:"DIV/0"}),_=()=>({type:7,value:"ARG"}),k=()=>({type:7,value:"VALUE"}),D=()=>({type:7,value:"REF"}),vt=()=>({type:7,value:"NAME"}),pr=()=>({type:7,value:"SPILL"}),Oe=()=>({type:7,value:"UNK"});var oe=class a extends Ce{static type="spreadsheet-vertex";reference;error=0;address;result={type:0};expression={type:"missing",id:-1};expression_error=!1;short_circuit=!1;type=a.type;get array_head(){return this.address?!!this.reference&&!!this.reference.area&&this.reference.area.start.column===this.address.column&&this.reference.area.start.row===this.address.row:!1}TakeReferenceValue(){this.reference&&(this.result=T(this.reference.GetValue()))}Calculate(e){if(this.dirty){if(this.color===0&&this.LoopCheck()&&(this.dirty=!1,this.edges_in.size)){this.reference&&(this.array_head||this.reference.type===1)&&this.reference.SetCalculationError("LOOP");for(let t of this.edges_out)t.Calculate(e);return}for(let t of this.edges_in)if(t.dirty)return;if(this.reference){if(this.reference.type===1){this.short_circuit=!1;let t=e.CalculationCallback.call(e,this);if(this.result=t.value,this.short_circuit)return;t.volatile&&e.volatile_list.push(this)}else this.result=this.reference.GetValue4();if(this.array_head)e.SpreadCallback.call(e,this,this.result);else if(this.reference.type===1)if(this.result.type===9){let t=e.SpillCallback.call(e,this,this.result);if(t)for(let r of t)for(let n of r.edges_out)n.dirty=!0,n.Calculate(e)}else this.reference.SetCalculatedValue(this.result.value,this.result.type)}else console.info("skip dirty constant? [or dangling...]");this.dirty=!1;for(let t of this.edges_out)t.dirty&&e.calculation_list.push(t)}}};var ge=class a extends Ce{static type="array-vertex";static list=[];type=a.type;area;static GetVertex(e){for(let t of this.list)if(t.area.start.sheet_id===e.start.sheet_id&&t.area.Equals(e))return[t,!1];return[new a(e),!0]}static Clear(){this.list=[]}static GetContainingArrays(e){let t=[];for(let r of this.list)r.area.start.sheet_id===e.sheet_id&&r.area.Contains(e)&&t.push(r);return t}static CreateImplicitEdges(e,t){for(let r of this.list)r.area.start.sheet_id===t.sheet_id&&r.area.Contains(t)&&r.DependsOn(e)}constructor(e){super(),this.area=e.Clone(),a.list.push(this)}RemoveDependent(e){super.RemoveDependent(e),this.edges_out.size||(this.Reset(),a.list=a.list.filter(t=>t!==this))}Calculate(e){if(this.dirty){if(this.color===0&&this.LoopCheck()&&(this.dirty=!1,this.edges_in.size)){for(let t of this.edges_out)t.Calculate(e);return}for(let t of this.edges_in)if(t.dirty)return;this.dirty=!1;for(let t of this.edges_out)t.Calculate(e)}}};var Be=class{vertices=[[]];volatile_list=[];calculation_list=[];spill_data=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===oe.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),ge.Clear()}ResolveArrayHead(e){if(!e.sheet_id)throw new Error("resolve array head with no sheet id");let t=this.model.sheets.Find(e.sheet_id)?.cells;if(!t)throw new Error("no cells? sheet id "+e.sheet_id);let r=t.data[e.row];if(r){let n=r[e.column];if(n&&n.area){let o={row:n.area.start.row,column:n.area.start.column,sheet_id:e.sheet_id};return console.info("array head",e,o),o}}return e}*IterateVertices(e,t=!1){for(let r of cr.Iterate(e)){let n=this.GetVertex(r,t);n&&(yield n)}}GetVertex(e,t){if(!e.sheet_id)throw console.info(JSON.stringify({address:e,create:t})),console.trace(),new Error("getvertex with no sheet id");let r=this.model.sheets.Find(e.sheet_id)?.cells;if(!r)throw new Error("no cells? sheet id "+e.sheet_id);if(!this.vertices[e.sheet_id]){if(!t)return;this.vertices[e.sheet_id]=[]}if(this.vertices[e.sheet_id][e.column]){let o=this.vertices[e.sheet_id][e.column][e.row];if(o)return o;if(!t)return}else{if(!t)return;this.vertices[e.sheet_id][e.column]=[]}let n=new oe;return n.address={row:e.row,column:e.column,absolute_row:e.absolute_row,absolute_column:e.absolute_column,sheet_id:e.sheet_id},n.reference=r.EnsureCell(e),this.vertices[e.sheet_id][e.column][e.row]=n,ge.CreateImplicitEdges(n,e),n}RemoveVertex(e){if(!e.sheet_id)throw new Error("removevertex with no sheet id");let t=this.GetVertex(e,!1);t&&(t.Reset(),this.vertices[e.sheet_id][e.column][e.row]=void 0)}ResetVertex(e){let t=this.GetVertex(e,!1);t&&t.Reset()}RIBcount=0;ResetInbound(e,t=!1,r=!0,n=!1){this.RIBcount++;let o=this.GetVertex(e,r);if(!o){if(t){let s=ge.GetContainingArrays(e);for(let l of s)this.SetVertexDirty(l)}return}let i=[];if(n&&(i=Array.from(o.edges_in)),o.ClearDependencies(),t&&this.SetVertexDirty(o),n){o.has_outbound_edges||this.RemoveVertex(e);for(let s of i)if(!s.has_inbound_edges&&!s.has_outbound_edges){let l=s;l.address&&this.RemoveVertex(l.address)}}}ResetLoopState(){for(let e of this.vertices)if(e){for(let t of e)if(t)for(let r of t)r&&(r.color=r.edges_out.size?0:2)}for(let e of this.leaf_vertices)e.color=2}LoopCheck(e=!1){if(!this.loop_check_required&&!e)return!1;let t=[];for(let n of this.vertices)if(n){for(let o of n)if(o)for(let i of o)i&&(i.color=i.edges_out.size?0:2,t.push(i))}let r=[];for(let n of t)if(n.color===0){for(n.color=1,r.push(n);r.length;){let o=r[r.length-1],i=!0;if(o.color!==2)for(let s of o.edges_out){if(s.color===1)return this.loop_hint=this.RenderAddress(n.address),console.info("loop detected @",this.loop_hint),!0;s.color===0&&(r.push(s),i=!1)}i&&(r.pop(),o.color=2)}n.color=2}return this.loop_check_required=!1,this.loop_hint=void 0,!1}RenderAddress(e){if(!e)return"undefined";let t="";if(e.sheet_id){let n=this.model.sheets.Find(e.sheet_id);n&&(t=n.name+"!")}let r=new z(e);return t+r.spreadsheet_label}CompositeAddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let[r,n]=ge.GetVertex(e);if(t.DependsOn(r),this.loop_check_required=!0,!n)return;let o=this.vertices[e.start.sheet_id];if(o){if(e.entire_row){for(let i=0;i<o.length;i++)if(o[i])for(let s=e.start.row;s<=e.end.row;s++){let l=o[i][s];l&&r.DependsOn(l)}}else if(e.entire_column){for(let i=e.start.column;i<=e.end.column;i++)if(o[i])for(let s of o[i])s?.address&&r.DependsOn(s)}else for(let i=e.start.row;i<=e.end.row;i++)for(let s=e.start.column;s<=e.end.column;s++)if(o[s]){let l=o[s][i];l&&r.DependsOn(l)}}}AddLeafVertexArrayEdge(e,t){this.CompositeAddArrayEdge(e,t)}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0);this.CompositeAddArrayEdge(e,r)}AddEdge(e,t){let r=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(r),r.reference&&r.reference.area&&!r.array_head&&this.AddEdge({...e,row:r.reference.area.start.row,column:r.reference.area.start.column},t),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),n=this.GetVertex(t,!1);!r||!n||(r.RemoveDependent(n),n.RemoveDependency(r))}SetAreaDirty(e){if(e.start.column===1/0||e.end.column===1/0||e.start.row===1/0||e.end.row===1/0)throw new Error("don't iterate over infinite area");let t=e.start.sheet_id;if(!t)throw new Error("invalid area, missing sheet id");for(let r=e.start.column;r<=e.end.column;r++)for(let n=e.start.row;n<=e.end.row;n++){let o={row:n,column:r,sheet_id:t};this.GetVertex(o,!1)&&this.SetDirty(o)}}SetVertexDirty(e){if(!e.dirty){this.dirty_list.push(e),e.dirty=!0;for(let t of e.edges_out)this.SetVertexDirty(t)}}SetDirty(e){let t=this.GetVertex(e,!0);this.SetVertexDirty(t)}AddLeafVertex(e){this.leaf_vertices.add(e)}RemoveLeafVertex(e){this.leaf_vertices.delete(e)}AddLeafVertexEdge(e,t){let r=this.GetVertex(e,!0);return t.DependsOn(r),0}RemoveLeafVertexEdge(e,t){let r=this.GetVertex(e,!1);r&&(r.RemoveDependent(t),t.RemoveDependency(r))}InitializeGraph(){for(let e of this.dirty_list)this.IsSpreadsheetVertex(e)&&(e.TakeReferenceValue(),this.CheckVolatile(e)&&this.volatile_list.push(e)),e.dirty=!1;this.dirty_list=[]}Recalculate(){for(let e of this.volatile_list)this.SetVertexDirty(e);this.spill_data=this.spill_data.filter(({area:e,vertex:t})=>{if(t.dirty){t.Reset();let r=e.start.sheet_id?this.model.sheets.Find(e.start.sheet_id)?.cells:void 0;if(r)for(let{cell:n,row:o,column:i}of r.IterateRC(new z(e.start,e.end)))n.spill&&(n.spill=void 0,typeof n.value>"u"&&n.Reset()),this.SetDirty({row:o,column:i,sheet_id:e.start.sheet_id});return!1}return!0}),this.calculation_list=this.dirty_list.slice(0),this.volatile_list=[],this.dirty_list=[],this.loop_check_required&&(this.ResetLoopState(),this.loop_check_required=!1);for(let e=0;e<this.calculation_list.length;e++)this.calculation_list[e].Calculate(this);this.calculation_list=[]}};var Cn=a=>{let e={m:a,n:a,array:[]};for(let t=0;t<a;t++){let r=[];for(let n=0;n<a;n++)r.push({real:0,imaginary:0});e.array.push(r)}return e};var _n=a=>{let{r:e,theta:t}=a,r=e*Math.cos(t),n=e*Math.sin(t);return{real:r,imaginary:n}},$e=a=>{let e=Math.sqrt(a.real*a.real+a.imaginary*a.imaginary),t=Math.atan2(a.imaginary,a.real);return{r:e,theta:t}},fr=a=>{let e={real:Math.sinh(a.real)*Math.cos(a.imaginary),imaginary:Math.cosh(a.real)*Math.sin(a.imaginary)},t={real:Math.cosh(a.real)*Math.cos(a.imaginary),imaginary:Math.sinh(a.real)*Math.sin(a.imaginary)};return ce(e,t)},gr=a=>ce({real:Math.tan(a.real),imaginary:Math.tanh(a.imaginary)},{real:1,imaginary:-(Math.tan(a.real)*Math.tanh(a.imaginary))}),vr=a=>({real:Math.cosh(a.real)*Math.cos(a.imaginary),imaginary:Math.sinh(a.real)*Math.sin(a.imaginary)}),yr=a=>({real:Math.cos(a.real)*Math.cosh(a.imaginary),imaginary:Math.sin(a.real)*Math.sinh(a.imaginary)}),xr=a=>({real:Math.sinh(a.real)*Math.cos(a.imaginary),imaginary:Math.cosh(a.real)*Math.sin(a.imaginary)}),Ge=a=>({real:Math.sin(a.real)*Math.cosh(a.imaginary),imaginary:Math.cos(a.real)*Math.sinh(a.imaginary)}),xt=a=>{if(a.imaginary===0)return{real:Math.asin(a.real),imaginary:0};let e=Math.hypot(a.real+1,a.imaginary)/2,t=Math.hypot(a.real-1,a.imaginary)/2,r=e+t,n=e-t,o={real:Math.asin(n),imaginary:Math.log(r+Math.sqrt(r*r-1))};return(a.imaginary<0||a.imaginary===0&&a.real>1)&&(o.imaginary=-o.imaginary),o},wr=a=>{if(a.imaginary===0)return{real:Math.acos(a.real),imaginary:0};let e=xt(a);return{real:Math.PI/2-e.real,imaginary:e.imaginary}},Cr=a=>{let{real:e,imaginary:t}=a;if(e===0){if(t>1)return{real:Math.PI/2,imaginary:.5*Math.log((t-1)/(t+1))};if(t<-1)return{real:-Math.PI/2,imaginary:.5*Math.log((1-t)/(-1-t))}}let r=e*e,n=t*t,o=.5*Math.atan2(2*e,1-r-n),i=.25*Math.log((r+(t+1)*(t+1))/(r+(t-1)*(t-1)));return{real:o,imaginary:i}},_r=(a,e)=>{if(e.real===0&&e.imaginary===0&&a.real===0&&a.imaginary===0)return!1;let t=e.real*e.real+e.imaginary*e.imaginary,r={real:(a.real*e.real+a.imaginary*e.imaginary)/t,imaginary:(a.imaginary*e.real-a.real*e.imaginary)/t},n=r.real*r.real,o=r.imaginary*r.imaginary,i={real:.5*Math.atan2(2*r.real,1-n-o),imaginary:.25*Math.log((n+(r.imaginary+1)*(r.imaginary+1))/(n+(r.imaginary-1)*(r.imaginary-1)))};return e.real<0&&(i.real+=a.real>=0||a.imaginary>=0?Math.PI:-Math.PI),i},kr=(...a)=>{let e=a.shift();if(!e)return{real:0,imaginary:0};for(let t of a)e=H(e,t);return e},H=(a,e)=>({real:a.real*e.real-a.imaginary*e.imaginary,imaginary:a.real*e.imaginary+a.imaginary*e.real}),kn=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<a.n;o++)n.push(a.array[r][o]+e.array[r][o]);t.push(n)}return{m:a.m,n:a.n,array:t}},yt=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<e.n;o++){let i=0;for(let s=0;s<a.n;s++)i+=a.array[r][s]*e.array[s][o];n.push(i)}t.push(n)}return{array:t,m:a.m,n:e.n}},Sr=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<e.n;o++){let i={real:0,imaginary:0};for(let s=0;s<a.n;s++)i.real+=a.array[r][s].real*e.array[s][o].real-a.array[r][s].imaginary*e.array[s][o].imaginary,i.imaginary+=a.array[r][s].real*e.array[s][o].imaginary+a.array[r][s].imaginary*e.array[s][o].real;n.push(i)}t.push(n)}return t},je=a=>{let e={real:0,imaginary:0},t=a.n;if(t==2){let n=H(a.array[0][0],a.array[1][1]),o=H(a.array[1][0],a.array[0][1]);return{real:n.real-o.real,imaginary:n.imaginary-o.imaginary}}let r=Cn(a.n);for(let n=0;n<t;n++){let o=0;for(let l=1;l<t;l++){let c=0;for(let u=0;u<t;u++)u!=n&&(r.array[o][c]={...a.array[l][u]},c++);o++}r.m=r.n=t-1;let i=Math.pow(-1,n),s=H({real:a.array[0][n].real*i,imaginary:a.array[0][n].imaginary*i},je(r));e.real+=s.real,e.imaginary+=s.imaginary}return e};var Sn=a=>{let e={real_values:!1,imaginary_values:!1,square:a.m===a.n,unit_diagonal:!0},t={m:a.m,n:a.n,array:[]},r={m:a.m,n:a.n,array:[]};for(let n=0;n<a.m;n++){let o=a.array[n],i=[],s=[];for(let l=0;l<a.n;l++)o[l].real&&(e.real_values=!0),o[l].imaginary&&(e.imaginary_values=!0),l===n&&e.unit_diagonal&&(o[l].real!==1||o[l].imaginary!==0)&&(e.unit_diagonal=!1),i.push(o[l].real),s.push(o[l].imaginary);t.array.push(i),r.array.push(s)}return{real:t,imaginary:r,flags:e}},Mn=a=>{let e=a.array.map(t=>t.slice(0));return{m:a.m,n:a.n,array:e}},hr=a=>{if(a.m!==a.n)return;let e=Mn(a),t=e.array,r=0,n=0,o=0,i=0,s=a.m;for(n=1;n<s;n++)t[0][n]/=t[0][0];for(n=1;n<s;n++){for(o=n;o<s;o++){for(r=0,i=0;i<n;i++)r+=t[o][i]*t[i][n];t[o][n]-=r}if(n!=s-1)for(o=n+1;o<s;o++){for(r=0,i=0;i<n;i++)r+=t[n][i]*t[i][o];t[n][o]=(t[n][o]-r)/t[n][n]}}for(n=0;n<s;n++)for(o=n;o<s;o++){let l=1;if(n!=o)for(l=0,i=n;i<o;i++)l-=t[o][i]*t[i][n];t[o][n]=l/t[o][o]}for(n=0;n<s;n++)for(o=n;o<s;o++)if(n!=o){for(r=0,i=n;i<o;i++)r+=t[i][o]*(n==i?1:t[n][i]);t[n][o]=-r}for(n=0;n<s;n++)for(o=0;o<s;o++){for(r=0,i=n>o?n:o;i<s;i++)r+=(o==i?1:t[o][i])*t[i][n];t[o][n]=r}return e},Mr=a=>{let e=[];if(a.m!==a.n)return;let{real:t,imaginary:r,flags:n}=Sn(a),o=hr(t);if(!o)return;if(!n.imaginary_values){for(let d=0;d<a.m;d++){let m=[];for(let b=0;b<a.n;b++)m.push({real:o.array[d][b],imaginary:0});e.push(m)}return e}let i=yt(o,r),s=yt(r,i),l=kn(t,s),c=hr(l);if(!c)return;let u=yt(i,c);for(let d=0;d<a.m;d++){let m=[];for(let b=0;b<a.n;b++)m.push({real:c.array[d][b],imaginary:-u.array[d][b]});e.push(m)}return e},ce=(a,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=H(a,t),n=H(e,t);return{real:r.real/n.real,imaginary:r.imaginary/n.real}},ze=a=>{let e=a.real||0,t=a.imaginary||0;return H({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},wt=a=>{let e=$e(a);return{real:Math.log(e.r),imaginary:e.theta}},J=(a,e)=>{if(e.imaginary)return ze(H(e,wt(a)));{let t=$e(a);return _n({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var Vr=(a,e=0)=>a&&a.type===8?a:{type:8,value:{real:e,imaginary:0}},ve=a=>a.imaginary?{type:8,value:a}:{type:3,value:a.real},ye=(a,e)=>{if(a.type===7)return[0,0,a];if(e.type===7)return[0,0,e];let t=[0,0];switch(a.type){case 3:t[0]=a.value;break;case 4:t[0]=a.value?1:0;break;case 0:break;case 8:t[3]=a;break;default:return[0,0,k()]}switch(e.type){case 3:t[1]=e.value;break;case 4:t[1]=e.value?1:0;break;case 0:break;case 8:t[4]=e;break;default:return[0,0,k()]}return(t[3]||t[4])&&(t[3]=Vr(t[3],t[0]),t[4]=Vr(t[4],t[1])),t},Vn=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve({real:o.value.real+i.value.real,imaginary:o.value.imaginary+i.value.imaginary}):{value:t+r,type:3})},kt=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve({real:o.value.real-i.value.real,imaginary:o.value.imaginary-i.value.imaginary}):{value:t-r,type:3})},Un=(a,e)=>{let[t,r,n,o,i]=ye(a,e);if(n)return n;if(o&&i)return ve(J(o.value,i.value));let s=Math.pow(t,r);return isNaN(s)?k():{type:3,value:s}},An=(a,e)=>{let[t,r,n,o,i]=ye(a,e);if(n)return n;if(o&&i)return ve(J(o.value,i.value));if(t<0&&r!==0&&Math.abs(r)<1)return ve(J({real:t,imaginary:0},{real:r,imaginary:0}));let s=Math.pow(t,r);return isNaN(s)?k():{type:3,value:s}},Ct=Un,Rn=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve(H(o.value,i.value)):{value:t*r,type:3})},En=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?i.value.real===0&&i.value.imaginary===0?W():ve(ce(o.value,i.value)):r===0?W():{value:t/r,type:3})},zn=(a,e)=>{let[t,r,n]=ye(a,e);return n||(r===0?W():{value:t%r,type:3})},_t=(a,e)=>a.type===7?a:e.type===7?e:a.type===0&&(e.value===""||e.value===0||e.type===8&&e.value.real===0&&e.value.imaginary===0)||e.type===0&&(a.value===""||a.value===0||a.type===8&&a.value.real===0&&a.value.imaginary===0)?{type:4,value:!0}:a.type===8?e.type===8?{type:4,value:a.value.imaginary===e.value.imaginary&&a.value.real===e.value.real}:{type:4,value:!a.value.imaginary&&a.value.real===e.value}:e.type===8?{type:4,value:!e.value.imaginary&&a.value===e.value.real}:a.type===2&&e.type===2?{type:4,value:a.value.toLowerCase()===e.value.toLowerCase()}:{type:4,value:a.value==e.value},Ur=(a,e)=>{let t=_t(a,e);return t.type===7?t:{type:4,value:!t.value}},Tn=(a,e)=>a.type===7?a:e.type===7?e:a.type===8||e.type===8?k():{type:4,value:(a.value||0)>(e.value||0)},St=(a,e)=>!(a.type===8||a.type===9||a.type===10||a.type===5||e.type===8||e.type===9||e.type===10||e.type===5),Dn=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)>=(e.value||0)}:k(),Ln=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)<(e.value||0)}:k(),Fn=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)<=(e.value||0)}:k(),Ar=()=>{Ct=An},Rr=a=>{switch(a){case"+":return Vn;case"-":return kt;case"*":return Rn;case"/":return En;case"^":return Ct;case"**":return Ct;case"%":return zn;case"=":return _t;case"==":return _t;case"!=":return Ur;case"<>":return Ur;case">":return Tn;case">=":return Dn;case"<":return Ln;case"<=":return Fn}};var Mt=a=>!Array.isArray(a)&&a.type===5&&!!a.value.type,$=a=>a.type===5&&a.key==="metadata",Xe=class{constructor(e,t,r){this.data_model=e;this.library=t;this.parser=r}context={address:{row:-1,column:-1},volatile:!1,bindings:[]};Calculate(e,t,r,n=!1){return n||(this.context.address=t,this.context.volatile=!1,this.context.area=r),{value:this.CalculateExpression(e),volatile:this.context.volatile}}CellFunction2(e){if(!e.sheet_id)if(e.sheet)e.sheet_id=this.data_model.sheets.ID(e.sheet)||0;else return()=>D();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>D();let r=t.GetCell(e);return r?e.spill&&r.spill&&r.spill.start.row===e.row&&r.spill.start.column===e.column?()=>r.spill?t.GetRange4(r.spill.start,r.spill.end,!0)||D():pr():()=>r.GetValue4():()=>({type:3,value:0})}CellFunction4(e,t){return e.sheet_id?this.data_model.sheets.Find(e.sheet_id)?.cells?.GetRange4(e,t,!0)||D():D()}GetMetadata(e,t){let r,n;switch(e.type){case"address":if(e.spill){let o;if(e.sheet_id&&(o=this.data_model.sheets.Find(e.sheet_id)),!o)return console.error("missing sheet [da6]"),D();let i=o.CellData(e);i.spill&&(n=i.spill)}else r=e;break;case"range":n=e;break;case"structured-reference":{let o=this.data_model.ResolveStructuredReference(e,this.context.address);o&&(o.type==="address"?r=o:o.type==="range"&&(n=o))}break;case"identifier":{let o=this.data_model.GetName(e.name,this.context.address.sheet_id||0);o?.type==="range"&&(o.area.count===1?r=o.area.start:n=o.area)}break;case"call":{let o=this.CalculateExpression(e,!0);if(Mt(o))if(o.value.type==="address")r=o.value;else if(o.value.type==="range")n=o.value;else return o;else return o}break;default:return this.CalculateExpression(e)}if(r){let o;if(r.sheet_id&&(o=this.data_model.sheets.Find(r.sheet_id)),!o)return console.error("missing sheet [ac8]"),D();let i=o.CellData(r),s=i.calculated_type?i.calculated:i.value,l={type:"metadata",address:{...r,position:0,id:0,type:"address",label:new z(r).spreadsheet_label},value:s,format:i.style?i.style.number_format:void 0,...t(i,r)};return{type:5,value:l,key:"metadata"}}else if(n){if(n.start.row===1/0||n.start.column===1/0)return D();let o;if(n.start.sheet_id&&(o=this.data_model.sheets.Find(n.start.sheet_id)),!o)throw new Error("missing sheet [ac9]");let i=[];for(let s=n.start.column;s<=n.end.column;s++){let l=[];for(let c=n.start.row;c<=n.end.row;c++){let u=o.CellData({row:c,column:s});r={...n.start,row:c,column:s};let d=u.calculated_type?u.calculated:u.value,m={type:"metadata",address:r,value:d,format:u.style?u.style.number_format:void 0,...t(u,r)};l.push({type:5,value:m,key:"metadata"})}i.push(l)}return{type:9,value:i}}return this.CalculateExpression(e)}RewriteMacro(e,t){let r;switch(e.type){case"identifier":if(r=t[e.name.toUpperCase()],r)return JSON.parse(JSON.stringify(r));break;case"binary":e.left=this.RewriteMacro(e.left,t),e.right=this.RewriteMacro(e.right,t);break;case"unary":e.operand=this.RewriteMacro(e.operand,t);break;case"group":e.elements=e.elements.map(n=>this.RewriteMacro(n,t));break;case"call":e.args=e.args.map(n=>this.RewriteMacro(n,t));break}return e}CallMacro(e,t){if(!t.expression)return()=>q();let r=JSON.stringify(t.expression),n={},o=t.argument_names?.map(i=>i.toUpperCase())||[];return i=>{let s=JSON.parse(r);for(let l=0;l<o.length;l++)n[o[l]]=i.args[l]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(s,n))}}ImplicitCallTail(e,t){let r=e.value;if(!r.func||!r.bindings)return q();let n={};for(let i=0;i<r.bindings.length;i++){let s=r.bindings[i];if(s?.type==="identifier")n[s.name.toUpperCase()]=t[i]||{type:"missing"};else return q()}let o=JSON.parse(JSON.stringify(r.func));return this.parser.Walk2(o,i=>{if(i.type==="identifier"){let s=i.name.toUpperCase(),l=n[s];if(l)return JSON.parse(JSON.stringify(l))}return!0}),this.CalculateExpression(o)}Apply(e,t){let r=t.map(n=>{switch(n.type){case 3:case 4:case 2:return{type:"literal",value:n.value,id:0,position:0};case 7:return{type:"literal",value:"#"+n.value,id:0,position:0};case 9:{let o=[];for(let i=0;i<n.value.length;i++){let s=n.value[i],l=[];for(let c=0;c<s.length;c++){let u=s[c];switch(u.type){case 4:case 3:case 2:l.push(u.value||void 0);break;default:console.warn("unhandled array value",u),l.push(void 0)}}o.push(l)}return{type:"array",values:o,id:0,position:0}}case 0:return{type:"missing",id:0};default:console.warn("unhandled parameter value",n)}return{type:"missing",id:0}});return this.ImplicitCallTail(e,r)}ImplicitCall(){return e=>{e.type==="call"&&(e={type:"implicit-call",args:e.args,call:{type:"identifier",name:e.name,position:e.position,id:0},position:e.position,id:0});let t=this.CalculateExpression(e.call);return t.type===6?this.ImplicitCallTail(t,e.args):q()}}NormalizeBindings(e){let t={};for(let[r,n]of Object.entries(e))t[r.toUpperCase()]=n;return t}CallExpression(e,t=!1){let r=this.library.Get(e.name);if(!r){let n=e.name.toUpperCase();return this.LookupBinding(n)?this.ImplicitCall():this.data_model.GetName(n,this.context.address.sheet_id||0)?this.ImplicitCall():()=>vt()}return n=>{this.context.volatile=this.context.volatile||!!r.volatile;let o=e.name.toLowerCase()==="if",i=-1,s,l=n.args,c=r.arguments||[],u;r.create_binding_context&&(u=r.create_binding_context.call(0,{args:n.args,descriptors:c}),u?(l=u.args,u.argument_descriptors&&(c=u.argument_descriptors),this.context.bindings.unshift(this.NormalizeBindings(u.context))):s=_());let d=l.map((p,h)=>{if(s)return;let f=c[Math.min(h,c.length-1)]||{};if(f.passthrough)return p;if(h===i)return f.boxed?{type:0}:void 0;if(typeof p>"u")return o&&h===0&&(i=1),f.boxed?{type:0}:void 0;if(f.address)return f.boxed?{type:2,value:this.parser.Render(p).replace(/\$/g,"")}:this.parser.Render(p).replace(/\$/g,"");if(f.metadata)return this.GetMetadata(p,()=>({}));{let y=this.CalculateExpression(p);if(y.type===7){if(f.allow_error)return y;s=y;return}if(o&&h===0&&y.type!==9){let x=!1;if(y.type===2){let v=y.value.toLowerCase().trim();x=v!=="false"&&v!=="f"}else x=!!y.value;i=x?2:1}return f.boxed?y:y.type===9?y.value.map(x=>x.map(v=>v.value)):y.value}});if(u&&this.context.bindings.shift(),s)return s;let m={address:{...this.context.address},area:this.context.area?{start:{...this.context.area.start},end:{...this.context.area.end}}:void 0,apply:r.fp?this.Apply.bind(this):void 0},b=r.fn.apply(m,d);if(r.return_type==="reference"){if(t)return b;if(Mt(b)){if(b.value.type==="address")return this.CellFunction2(b.value)();if(b.value.type==="range")return this.CellFunction4(b.value.start,b.value.end)}return b}return b}}ResolveStructuredReference(e){let t=this.data_model.ResolveStructuredReference(e,this.context.address);if(t){if(t.type==="address")return this.CellFunction2(t);if(t.type==="range")return()=>this.CellFunction4(t.start,t.end)}return()=>D()}ResolveDimensionedQuantity(){return e=>{let t=this.CalculateExpression(e.expression);return{type:10,value:{value:t.value,unit:e.unit.name}}}}UnaryExpression(e,t=!1){switch(e.operator){case"+":return r=>this.CalculateExpression(r.operand);case"-":{let r=kt,n={type:3,value:0};return o=>{let i=this.CalculateExpression(o.operand);return i.type===9?{type:9,value:i.value.map(s=>s.map(l=>r(n,l)))}:r(n,i)}}case"@":return r=>{let n;switch(r.operand.type){case"address":if(r.operand.spill){let i=this.CellFunction2(r.operand)();if(i.type===9){let s=this.context.address.row??-1,l=this.context.address.column??-1;if(s>=r.operand.row&&s<r.operand.row+i.value[0]?.length&&i.value.length===1){if(!t)return i.value[0][s-r.operand.row];n={...r.operand,row:s,spill:!1}}else if(l>=r.operand.column&&l<r.operand.column+i.value.length&&i.value[0]?.length===1){if(!t)return i.value[l-r.operand.column][0];n={...r.operand,column:l,spill:!1}}else return k()}}break;case"range":{let i=this.context.address.row??-1,s=this.context.address.column??-1;if(i>=r.operand.start.row&&i<=r.operand.end.row&&r.operand.start.column===r.operand.end.column)n={...r.operand.start,row:i,spill:!1};else if(s>=r.operand.start.column&&s<=r.operand.end.column&&r.operand.start.row===r.operand.end.row)n={...r.operand.start,column:s,spill:!1};else return k()}}if(n)return t?{type:5,value:n}:this.CellFunction2(n)();let o=this.CalculateExpression(r.operand);return o.type===9?o.value[0][0]:o};default:return()=>(console.warn("unexpected unary operator:",e.operator),q())}}RecycleArray(e,t,r){if(e[0].length<r){let n=e[0].length;for(let o of e)for(let i=n;i<r;i++)o[i]=o[i%n]}if(e.length<t){let n=e.length;for(let o=n;o<t;o++)e[o]=e[o%n].slice(0)}return e}ElementwiseBinaryExpression(e,t,r){let n=Math.max(t.value.length,r.value.length),o=Math.max(t.value[0].length,r.value[0].length),i=this.RecycleArray(t.value,n,o),s=this.RecycleArray(r.value,n,o),l=[];for(let c=0;c<n;c++){let u=[];for(let d=0;d<o;d++)u[d]=e(i[c][d]||{type:0},s[c][d]||{type:0});l.push(u)}return{type:9,value:l}}AsReference(e){switch(e.type){case"address":return e;case"range":if(e.start.row===e.end.row&&e.start.column===e.end.column)return e.start;break;default:{let t=this.CalculateExpression(e,!0);if(Mt(t)){if(t.value.type==="address")return t.value;if(t.value.type==="range"&&t.value.start.row===t.value.end.row&&t.value.start.column===t.value.end.column)return t.value.start}}break}}BinaryExpression(e){let t=e.operator==="&"?(r,n)=>{if(r.type===7)return r;if(n.type===7)return n;let o=[r,n].map(i=>i.type===0?"":i.type===4?i.value?this.data_model.language_model?.boolean_true||"TRUE":this.data_model.language_model?.boolean_false||"FALSE":i.value);return{type:2,value:`${o[0]}${o[1]}`}}:Rr(e.operator);return t?r=>{let n=this.CalculateExpression(r.left),o=this.CalculateExpression(r.right);return n.type===9?o.type===9?this.ElementwiseBinaryExpression(t,n,o):this.ElementwiseBinaryExpression(t,n,{type:9,value:[[o]]}):o.type===9?this.ElementwiseBinaryExpression(t,{type:9,value:[[n]]},o):t(n,o)}:e.operator===":"?r=>{let n=this.AsReference(r.left),o=this.AsReference(r.right);return n&&o?this.CellFunction4(n,o):q()}:()=>(console.info(`(unexpected binary operator: ${e.operator})`),q())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>D();let r=t.toUpperCase();switch(r){case"FALSE":return()=>({value:!1,type:4});case"TRUE":return()=>({value:!0,type:4});case"UNDEFINED":return()=>({value:void 0,type:0})}return()=>{let n=this.LookupBinding(r);if(n)return this.CalculateExpression(n);let o=this.data_model.GetName(r,this.context.address.sheet_id||0);switch(o?.type){case"range":return o.area.count===1?this.CellFunction4(o.area.start,o.area.start):this.CellFunction4(o.area.start,o.area.end);case"expression":return this.CalculateExpression(o.expression)}return vt()}}LookupBinding(e){e=e.toUpperCase();for(let t of this.context.bindings){let r=t[e];if(r)return r}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>q()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.fn)return e.fn(e);switch(e.type){case"implicit-call":return(e.fn=this.ImplicitCall())(e);case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.fn=this.CallMacro(e,r))(e):(e.fn=this.CallExpression(e,t))(e)}case"address":return(e.fn=this.CellFunction2(e))();case"range":return(e.fn=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.fn=this.BinaryExpression(e))(e);case"unary":return(e.fn=this.UnaryExpression(e,t))(e);case"identifier":return(e.fn=this.Identifier(e))();case"missing":return(e.fn=()=>({value:void 0,type:0}))();case"dimensioned":return(e.fn=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:Ae(e.value)};return(e.fn=()=>r)()}case"group":return(e.fn=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:8};return(e.fn=()=>r)()}case"structured-reference":return(e.fn=this.ResolveStructuredReference(e))();case"array":return(e.fn=()=>({type:9,value:e.values.map(r=>(Array.isArray(r)?r:[r]).map(n=>({type:Ae(n),value:n})))}))();default:return console.warn("Unhandled parse expr:",e),Oe()}}};var Ea=1e3*60*60*24;var We=a=>{let e=[],t=a.length,r=a[0].length;for(let n=0;n<r;n++){e[n]=[];for(let o=0;o<t;o++)e[n][o]=a[o][n]}return e},Vt=a=>{if(!a)return[];if(typeof a[0]>"u")return[];let e=[],t=a.length,r=a[0].length;for(let n=0;n<r;n++){e[n]=[];for(let o=0;o<t;o++)e[n][o]=a[o][n]}return e};var O=a=>{let e=[];for(let t of a)if(t?.type===9)for(let r of t.value)e=e.concat(O(r));else e.push(t);return e},F=(a,e=!1)=>Array.isArray(a)?a.reduce((t,r)=>typeof r>"u"&&!e?t:Array.isArray(r)?t.concat(F(r,e)):r instanceof Float32Array||r instanceof Float64Array?t.concat(Array.from(r)):t.concat([r]),[]):[a],P=a=>F(a).filter(e=>typeof e=="number"),Ut=(a,e=!1)=>e?a.map((t=>{switch(typeof t){case"number":case"undefined":case"string":case"boolean":return t}})):a.filter(t=>{switch(typeof t){case"number":case"undefined":case"string":case"boolean":return!0}return!1}),In=a=>!!a&&typeof a=="object"&&a.type===9,zr=(a,e)=>(...t)=>{let r=[],n=[];for(let[o,i]of t.entries())if(i&&a[o]){let s=Array.isArray(i)?i:In(i)?i.value:void 0;s&&(r[o]=s,n.length||(n=s))}return r.length?{type:9,value:n.map((o,i)=>o.map((s,l)=>{let c=t.map((u,d)=>r[d]?r[d][i][l]??{type:0}:u);return e(...c)}))}:e(...t)},Te=a=>{let e=[],t=a.length,r="[\\^$.|?*+()";for(let n=0;n<t;n++){let o=a[n];switch(o){case"*":e.push(".","*");break;case"?":e.push(".");break;case"~":o=a[++n]||"";default:for(let i=0;i<r.length;i++)if(o===r[i]){e.push("\\");break}e.push(o);break}}return e.join("")},Tr=a=>({type:2,value:a});var Ye=class{functions={};Register(...e){for(let t of e)for(let r of Object.keys(t)){if(/[^a-zA-Z0-9._]/.test(r))throw new Error("invalid function name (invalid character)");if(r.length>255)throw new Error("invalid function name (too long, > 255)");if(/^[^a-zA-Z]/.test(r))throw new Error("invalid function name (start with an ascii letter)");let n=r.toLowerCase();if(this.functions[n])throw new Error(`function name (${n}) is already in use`);let o=t[r];if(o.canonical_name=r,!o.unrolled){let i=o.arguments?.map(s=>!!s.unroll);i?.some(s=>!!s)&&(o.fn=zr(i,o.fn),o.unrolled=!0)}this.functions[n]=o}}Get(e){let t=e.toLowerCase();return this.functions[t]}List(e=!0){let t={};for(let r of Object.keys(this.functions))e&&this.functions[r].visibility==="internal"||(t[r]=this.functions[r]);return t}Alias(e,t){let r=this.Get(t);if(!r)throw new Error(`referenced function ${t} does not exist`);this.Register({[e]:{...r}})}};var De=class{static default_color="#888";static UnpackValues(e){if(Array.isArray(e)){let t=e[0];return Array.isArray(t)||t instanceof Float64Array||t instanceof Float32Array?e.reduce((r,n)=>r.concat(this.UnpackValues(n)),[]):e.map(r=>isNaN(r)?void 0:r)}else{if(e instanceof Float32Array||e instanceof Float64Array)return Array.prototype.slice.call(e);if(e&&typeof e=="object"){let r=Object.keys(e).length;if(typeof e[0]<"u"&&typeof e[(r-1).toString()]<"u"){let n=[];for(let o=0;o<r;o++)n[o]=e[o.toString()];return n}}}return[]}static SparklineCommon(e,t){let r=[],n=Qt(t.text)?t.text.text:this.default_color,o=[n,n];return Array.isArray(e.calculated)&&(r=this.UnpackValues(e.calculated[0]),typeof e.calculated[1]=="string"&&(o[0]=e.calculated[1]),typeof e.calculated[2]=="string"&&(o[1]=e.calculated[2])),{values:r,colors:o}}static RenderLine(e,t,r,n,o){let{values:i,colors:s}=this.SparklineCommon(n,o),l=.05,c=.1,u=1;Array.isArray(n.calculated)&&typeof n.calculated[2]=="number"&&(u=n.calculated[2]);let d=0,m=0,b=-1;for(let p=0;p<i.length;p++){let h=i[p];typeof h=="number"&&(b>=0?(d=Math.min(d,h),m=Math.max(m,h)):(b=p,d=m=h))}if(d===m&&(d&&(d-=1),m+=1),d!==m){let p=e*(1-2*l)/(i.length-1),h=m-d,f=t*(1-2*c),y=t*c;r.strokeStyle=s[0],r.lineWidth=u,r.lineCap="round",r.lineJoin="round",r.beginPath();let x=0;for(let v=b;v<i.length;v++){let w=i[v];if(typeof w=="number"){let g=e*l+p*v,C=t-(w-d)*f/h-y;x===0?(r.moveTo(g,C),x=1):r.lineTo(g,C)}else x=0}r.stroke()}}static RenderColumn(e,t,r,n,o){let{values:i,colors:s}=this.SparklineCommon(n,o),l=3,c=2.5,u=0,d=0,m=!1;for(let b of i)typeof b=="number"&&(m?(u=Math.min(u,b),d=Math.max(d,b)):(m=!0,u=d=b));if(u===d&&(u&&(u-=1),d+=1),i.length){let b=(e-2*l-2)/(i.length-0),p=t-2*c,h=c;if(u!==d)if(u<0&&d>0){let f=d-u,y=h+d/f*p;for(let x=0;x<i.length;x++){let v=i[x];if(typeof v=="number"){let w=l+x*b,g=Math.abs(v)/f*p;if(v>=0){r.fillStyle=s[0];let C=y-g;r.fillRect(w+2,C,b-2,g)}else{r.fillStyle=s[1];let C=y;r.fillRect(w+2,C,b-2,g)}}}}else if(d>0){r.fillStyle=s[0];let f=d-u;for(let y=0;y<i.length;y++){let x=i[y];if(typeof x=="number"){let v=l+y*b,w=Math.max(1,(x-u)/f*p),g=t-h-w;r.fillRect(v+2,g,b-2,w)}}}else{r.fillStyle=s[1];let f=d-u;for(let y=0;y<i.length;y++){let x=i[y];if(typeof x=="number"){let v=l+y*b,w=Math.max(1,Math.abs(d-x)/f*p),g=h;r.fillRect(v+2,g,b-2,w)}}}}}};var Dr=a=>{let{x:e,y:t,width:r,height:n,cell:o}=a,i={},s=3,l=Math.round(16*(a.scale||1));if(o&&r&&n&&e&&t){let c={x:s,y:n-s-l};if(o.style){switch(o.style.vertical_align){case"top":c.y=s;break;case"middle":c.y=Math.round((n-l)/2);break}switch(o.style.horizontal_align){case"right":c.x=Math.round(r-s-l);break;case"center":c.x=Math.round((r-l)/2);break}}e>=c.x&&e<=c.x+l&&t>=c.y&&t<=c.y+l&&(i.value=`=Checkbox(${o.calculated?"FALSE":"TRUE"})`,i.block_selection=!0)}return i},Lr=a=>{let{context:e,width:t,height:r,cell:n}=a,o=a.scale||1;e.lineJoin="round",e.lineCap="round";let i=3*o,s=16*o,l=i,c=r-i-s;if(n.style){switch(n.style.vertical_align){case"top":c=i;break;case"middle":c=(r-s)/2;break}switch(n.style.horizontal_align){case"right":l=t-i-s;break;case"center":l=(t-s)/2;break}}l=Math.floor(l)+.5,c=Math.floor(c)+.5;let u=Math.floor(l+s)+.5,d=Math.floor(c+s)+.5;if(n&&n.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(l,c),e.lineTo(l+16*o,c),e.lineTo(l+16*o,c+16*o),e.lineTo(l,c+16*o),e.closePath(),e.moveTo(l+15*o,c+4*o);for(let m of[[13.59,2.58],[6,10.17],[2.41,6.59],[1,8],[6,13]])e.lineTo(l+m[0]*o,c+m[1]*o);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(l,c),e.lineTo(u,c),e.lineTo(u,d),e.lineTo(l,d),e.closePath(),e.stroke();return{handled:!0}};var ue=a=>{switch(a.type){case 8:return a.value;case 3:return{real:a.value,imaginary:0};case 4:return{real:a.value?1:0,imaginary:0};case 0:return{real:0,imaginary:0}}return!1};var Fr=(a,e,t)=>{let r=new Date;return r.setMilliseconds(0),r.setSeconds(0),r.setMinutes(0),r.setHours(0),a<0||a>1e4||(a<1899&&(a+=1900),r.setFullYear(a),e<1||e>12)||(r.setMonth(e-1),t<1||t>31)?!1:(r.setDate(t),ae(r.getTime()))};var Ir=(a,e)=>{let t=new Date(fe(a)),r=t.getUTCMonth()+e,n=t.getUTCFullYear();for(t.setUTCHours(12),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);r<0;)r+=12,n--;for(;r>11;)r-=12,n++;if(t.setUTCMonth(r),t.setUTCFullYear(n),t.getUTCMonth()!==r){let i=t.getUTCDate();t=new Date(t.getTime()-i*86400*1e3)}return t},Pr=[{name:"Lookup value"},{name:"Table"},{name:"Result index"},{name:"Inexact",default:!0}],Hr=(a,e,t,r=!0,n=!1)=>{if(n&&(e=Vt(e)),t=Math.max(0,t-1),r){let o=e[t][0];if(typeof a=="number"){let i=Number(e[0][0]);if(isNaN(i)||i>a)return Y();for(let s=1;s<e[0].length&&(i=Number(e[0][s]),!(isNaN(i)||i>a));s++)o=e[t][s]}else{a=(a||"").toString().toLowerCase();let i=(e[0][0]||"").toString().toLowerCase();if(i.localeCompare(a)>0)return Y();for(let s=1;s<e[0].length&&(i=(e[0][s]||"").toString().toLowerCase(),!(i.localeCompare(a)>0));s++)o=e[t][s]}return T(o)}else{for(let o=0;o<e[0].length;o++)if(e[0][o]==a)return T(e[t][o]);return Y()}},Ze=(a,e=!1)=>{if(!a)return e;switch(a.type){case 3:return a.value;case 0:return e}return!1},ie=(a,e,t)=>({description:t,arguments:[{name:"number",boxed:!0,unroll:!0}],fn:r=>r.type===3?{type:3,value:a(r.value)}:r.type===8?{type:8,value:e(r.value)}:_()}),Or=(a,e,t)=>{if(e===t)return 0;if(e===void 0)return 1;if(t===void 0)return-1;if(typeof e=="number"&&typeof t=="number")return(e-t)*a;if(typeof e=="string"&&typeof t=="string")return e.toLocaleLowerCase().localeCompare(t.toLowerCase())*a;if(typeof e=="boolean"&&typeof t=="boolean")return e?a:-a;if(X(e)&&X(t))return 0;let r=[e,t].map(n=>{switch(typeof n){case"number":return 0;case"string":return 2;case"boolean":return 3;default:return X(n)?1:4}});return(r[0]-r[1])*a},At={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=J(a.value,{real:.5,imaginary:0});return B(e)}else{if(a.type===0||!a.value)return{type:3,value:0};if(a.type===3&&a.value<0){let e=J({real:a.value,imaginary:0},{real:.5,imaginary:0});return{type:8,value:e}}else if(a.type===3){let e=Math.sqrt(a.value);return isNaN(e)?k():{type:3,value:e}}else return k()}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(a,e)=>{if(a.type===3&&e.type===3&&(a.value>=0||e.value===0||Math.abs(e.value)>=1)){let n=Math.pow(a.value,e.value);return isNaN(n)?k():{type:3,value:n}}let t=ue(a),r=ue(e);if(t&&r){let n=J(t,r);return B(n)}return k()}}},_e={True:{fn:()=>({type:4,value:!0})},False:{fn:()=>({type:4,value:!1})},Int:{fn:a=>({type:3,value:Math.floor(a)})},Rand:{volatile:!0,fn:()=>({type:3,value:Math.random()})},RandArray:{volatile:!0,arguments:[{name:"rows"},{name:"columns"},{name:"min"},{name:"max"},{name:"integer"}],description:"Returns an array of uniformly-distributed random numbers",fn:(a=1,e=1,t=0,r=1,n=!1)=>{let o=[];if(n){let i=r-t+1;for(let s=0;s<e;s++){let l=[];for(let c=0;c<a;c++)l.push({type:3,value:Math.floor(Math.random()*i+t)});o.push(l)}}else{let i=r-t;for(let s=0;s<e;s++){let l=[];for(let c=0;c<a;c++)l.push({type:3,value:Math.random()*i+t});o.push(l)}}return{type:9,value:o}}},RandBetween:{arguments:[{name:"min"},{name:"max"}],volatile:!0,fn:(a=0,e=1)=>{if(a>e){let t=a;a=e,e=t}return{type:3,value:Math.floor(Math.random()*(e+1-a)+a)}}},Sum:{description:"Adds arguments and ranges",arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:0,imaginary:0},t=O(a);for(let r of t)switch(r.type){case 3:e.real+=r.value;break;case 4:break;case 8:e.real+=r.value.real,e.imaginary+=r.value.imaginary;break;case 7:return r}return B(e)}},SumSQ:{description:"Returns the sum of the squares of all arguments",arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:0,imaginary:0},t=O(a);for(let r of t)switch(r.type){case 3:e.real+=r.value*r.value;break;case 4:break;case 8:{let n=H(r.value,r.value);e.real+=n.real,e.imaginary+=n.imaginary}break;case 7:return r}return B(e)}},EDate:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(a,e=0)=>{if(typeof a!="number"||typeof e!="number")return _();let t=Ir(a,e);return{type:3,value:ae(t.getTime(),!1)}}},EOMonth:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(a,e=0)=>{if(typeof a!="number"||typeof e!="number")return _();let t=Ir(a,e);switch(t.getUTCMonth()){case 1:{let n=t.getUTCFullYear();n%4===0&&(n===1900||n%400===0||n%100!==0)?t.setUTCDate(29):t.setUTCDate(28)}break;case 0:case 2:case 4:case 6:case 7:case 9:case 11:t.setUTCDate(31);break;default:t.setUTCDate(30);break}return{type:3,value:ae(t.getTime(),!1)}}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:ae(new Date().getTime())})},YearFrac:{description:"Returns the fraction of a year between two dates",arguments:[{name:"Start"},{name:"End"},{name:"Basis",default:0}],fn:(a,e,t)=>{if(e<a){let o=a;a=e,e=o}let r=Math.max(0,e-a),n=360;if(t&&t<0||t>4)return _();switch(t){case 1:break;case 2:break;case 3:n=365;break}return{type:3,value:r/n}}},Date:{description:"Constructs a date from year/month/day",arguments:[{name:"year",unroll:!0},{name:"month",unroll:!0},{name:"day",unroll:!0}],fn:(a,e,t)=>{let r=Fr(a,e,t);return r===!1?_():{type:3,value:r}}},Today:{description:"Returns current day",volatile:!0,fn:()=>{let a=new Date;return a.setMilliseconds(0),a.setSeconds(0),a.setMinutes(0),a.setHours(12),{type:3,value:ae(a.getTime())}}},IfError:{description:"Returns the original value, or the alternate value if the original value contains an error",arguments:[{name:"original value",allow_error:!0,boxed:!0},{name:"alternate value"}],fn:(a,e=0)=>a&&a.type===7?{value:e,type:Ae(e)}:a},IsNA:{description:"Checks if another cell contains a #NA error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7&&t.value==="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsErr:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7&&t.value!=="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7)return{type:4,value:!0};return{type:4,value:!1}}},Year:{description:"Returns year from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees",unroll:!0}],fn:a=>T(a*Math.PI/180)},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians",unroll:!0}],fn:a=>T(a/Math.PI*180)},CountA:{description:"Counts cells that are not empty",fn:(...a)=>T(F(a).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...a)=>T(F(a).reduce((e,t)=>typeof t=="number"||X(t)?e+1:e,0))},Or:{fn:(...a)=>{let e=!1;a=F(a);for(let t of a)e=e||!!t;return T(e)}},And:{fn:(...a)=>{let e=!0;a=F(a);for(let t of a)e=e&&!!t;return T(e)}},Not:{arguments:[{unroll:!0,boxed:!0}],fn:a=>{let e=!1;if(a)switch(a.type){case 0:e=!1;break;case 2:case 4:case 3:e=!!a.value;break;case 7:return a}return T(!e)}},If:{arguments:[{name:"test value",boxed:!0},{name:"value if true",boxed:!0,allow_error:!0},{name:"value if false",boxed:!0,allow_error:!0}],fn:(a,e={type:4,value:!0},t={type:4,value:!1})=>{let r=e.type===9,n=t.type===9;return a.type===9?{type:9,value:a.value.map((i,s)=>i.map((l,c)=>(l.type===2?l.value.toLowerCase()!=="false"&&l.value.toLowerCase()!=="f":!!l.value)?r?e.value[s][c]:e:n?t.value[s][c]:t))}:(a.type===2?a.value.toLowerCase()!=="false"&&a.value.toLowerCase()!=="f":!!a.value)?e:t}},Fact:{description:"Returns the factorial of a number",arguments:[{name:"number",unroll:!0}],fn:a=>{a=Math.round(a);let e=1;for(;a>1;)e*=a,a--;return{type:3,value:e}}},Factdouble:{description:"Returns the double factorial of a number",arguments:[{name:"number",unroll:!0}],fn:a=>{a=Math.round(a);let e=1;for(;a>1;)e*=a,a-=2;return{type:3,value:e}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(a,e)=>{let t=ue(a),r=ue(e);if(!t||!r)return k();if(a.type===8||e.type===8)return B(J(t,r));{let n=Math.pow(t.real,r.real);return isNaN(n)?k():{type:3,value:n}}}},Mod:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e)=>e?T(a%e):W()},Large:{description:"Returns the nth numeric value from the data, in descending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(a,e)=>{if(e<=0)return _();let t=P(a);return t.sort((r,n)=>n-r),e<=t.length?{type:3,value:t[e-1]}:_()}},Small:{description:"Returns the nth numeric value from the data, in ascending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(a,e)=>{if(e<=0)return _();let t=P(a);return t.sort((r,n)=>r-n),e<=t.length?{type:3,value:t[e-1]}:_()}},Filter:{description:"Filter an array using a second array.",arguments:[{name:"source",description:"Source array"},{name:"filter",description:"Filter array"}],fn:(a,e)=>{if(typeof a>"u"||typeof e>"u")return _();Array.isArray(a)||(a=[[a]]),Array.isArray(e)||(e=[[e]]);let t=a.length,r=a[0].length,n=e.length,o=e[0].length;if(r===o){let i=[];for(let s=0;s<t;s++)i.push([]);for(let[s,l]of e[0].entries())if(l)for(let c=0;c<t;c++)i[c].push(T(a[c][s]));return{type:9,value:i}}else if(t===n){let i=[];for(let[s,[l]]of e.entries())l&&i.push(a[s].map(c=>T(c)));return{type:9,value:i}}return _()}},SortBy:{arguments:[{name:"array"},{name:"index"},{name:"order",description:"Set to -1 to sort in descending order",default:1}],fn:(a,...e)=>{if(Array.isArray(a)||(a=[[a]]),e.length<1)return _();let t=a[0]?.length||0,r=[],n=[];for(let l=0;l<e.length;l+=2){let c=l/2,u=e[l];if(Array.isArray(u)||(u=[[u]]),(u[0]?.length||0)!==t)return _();let m=1,b=e[l+1];typeof b=="number"&&b<0&&(m=-1),r[c]=m,n[c]=u[0]}let o=a[0]?.map((l,c)=>c);o.sort((l,c)=>{for(let u=0;u<r.length;u++){let d=r[u],m=n[u],b=Or(d,m[l],m[c]);if(b)return b}return 0});let i=a.length,s=[];for(let l=0;l<i;l++){let c=[];for(let u of o)c.push(T(a[l][u]));s.push(c)}return{type:9,value:s}}},Sort:{arguments:[{name:"array"},{name:"index"},{name:"order",description:"Set to -1 to sort in descending order",default:1}],fn:(a,e=1,t=1)=>{Array.isArray(a)||(a=[[a]]);let r=a[e-1];if(!r)return _();t<0?t=-1:t=1;let n=r.map((s,l)=>({value:s,index:l}));n.sort((s,l)=>Or(t,s.value,l.value));let o=a.length,i=[];for(let s=0;s<o;s++){let l=[];for(let{index:c}of n)l.push(T(a[s][c]));i.push(l)}return{type:9,value:i}}},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>a.type===9?{type:9,value:We(a.value)}:a},Max:{fn:(...a)=>({type:3,value:Math.max.apply(0,P(a))})},Min:{fn:(...a)=>({type:3,value:Math.min.apply(0,P(a))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...a)=>{let e=a.map(n=>F(n)),t=Math.max.apply(0,e.map(n=>n.length)),r=0;for(let n=0;n<t;n++)r+=e.reduce((o,i)=>{let s=i[n];return s===!0&&(s=1),typeof s=="number"?o*s:0},1);return{type:3,value:r}}},Row:{arguments:[{name:"reference",metadata:!0}],fn:function(a){if(!a)if(this?.area){let e=[];for(let t=this.area.start.column;t<=this.area.end.column;t++){let r=[];for(let n=this.area.start.row;n<=this.area.end.row;n++)r.push({type:3,value:n+1});e.push(r)}return{type:9,value:e}}else return{type:3,value:this?this.address.row+1:-1};if(a.type===9){let e=a.value,t=e[0][0];if($(t))return{type:9,value:[e[0].map((r,n)=>({type:3,value:n+t.value.address.row+1}))]}}else if($(a))return{type:3,value:a.value.address.row+1};return _()}},Column:{arguments:[{name:"reference",metadata:!0}],fn:function(a){if(!a)if(this?.area){let e=[];for(let t=this.area.start.column;t<=this.area.end.column;t++){let r=[];for(let n=this.area.start.row;n<=this.area.end.row;n++)r.push({type:3,value:t+1});e.push(r)}return{type:9,value:e}}else return{type:3,value:this?this.address.column+1:-1};if(a.type===9){let e=a.value,t=e[0][0];if($(t))return{type:9,value:e.map((r,n)=>[{type:3,value:n+t.value.address.column+1}])}}else if($(a))return{type:3,value:a.value.address.row+1};return _()}},Choose:{arguments:[{name:"Selected index"},{name:"Choice 1...",metadata:!0}],return_type:"reference",description:"Returns one of a list of choices",fn:(a,...e)=>{if(a<1||a>e.length)return k();let t=e[a-1];if($(t))return{type:5,value:t.value.address};if(t.type===9){let r=t.value,n=r.length,o=r[0].length,i=r[0][0],s=r[n-1][o-1];if(n===1&&o===1){if($(i))return{type:5,value:i.value.address}}else if($(i)&&$(s))return{type:5,value:{type:"range",position:0,id:0,label:"",start:i.value.address,end:s.value.address}}}return{...t}}},XLOOKUP:{arguments:[{name:"Lookup value"},{name:"Lookup array"},{name:"Return array",metadata:!0},{name:"Not found",boxed:!0},{name:"Match mode",default:0},{name:"Search mode",default:1}],return_type:"reference",xlfn:!0,fn:(a,e,t,r,n=0,o=1)=>{if(!t)return _();let i,s=!1;if(t.type===9){let d=t.value,m=d.length,b=d[0].length,p=d[0][0],h=d[m-1][b-1];$(p)&&$(h)?i=new z(p.value.address,h.value.address):s=!0}if(!i&&!s)return console.info("invalid range"),D();if(!Array.isArray(e))return console.info("lookup is not an array"),k();let l=e[0];if(!Array.isArray(l))return console.info("lookup is not a 2d array"),k();if(e.length!==1&&l.length!==1)return console.info("lookup array has invalid dimensions"),k();let c=e.length===1;c&&(e=Vt(e)),o<0&&e.reverse();let u=d=>{if(s&&t.type===9){let p=t.value.length,h=t.value[0]?.length||0,f=[],y=0,x=h-1,v=0,w=p-1;c?(o<0&&(d=h-1-d),y=x=d):(o<0&&(d=p-1-d),v=w=d);for(let g=v;g<=w;g++){let C=[];for(let U=y;U<=x;U++)C.push(t.value[g][U]);f.push(C)}return{type:9,value:f}}if(!i)throw new Error("invalid range");let m,b;if(c?(o<0&&(d=i.rows-1-d),d>=0&&d<i.rows&&(m={type:"address",position:0,id:1,label:"",row:i.start.row+d,column:i.start.column,sheet_id:i.start.sheet_id},b={type:"address",position:0,id:2,label:"",row:i.start.row+d,column:i.end.column,sheet_id:i.start.sheet_id})):(o<0&&(d=i.columns-1-d),d>=0&&d<i.columns&&(m={type:"address",position:0,id:1,label:"",row:i.start.row,column:i.start.column+d,sheet_id:i.start.sheet_id},b={type:"address",position:0,id:2,label:"",row:i.end.row,column:i.start.column+d,sheet_id:i.start.sheet_id})),m&&b){let p={type:"range",position:0,id:0,label:"",start:m,end:b};return{type:5,value:p}}return{type:0}};if(n===2&&typeof a!="string"&&(n=0),(n===1||n===-1)&&typeof a=="number"){let d=0,m=-1;for(let b=0;b<e.length;b++){let p=e[b][0];if(typeof p=="number"){if(p===a)return u(b);let h=Math.abs(p-a);(n===1&&p>a||n===-1&&p<a)&&(m<0||h<d)&&(d=h,m=b)}}if(m>=0)return u(m)}switch(n){case 2:{let d=Te(a?.toString()||""),m=new RegExp("^"+d+"$","i");for(let b=0;b<e.length;b++){let p=e[b][0];if(typeof p=="string"&&m.exec(p))return u(b)}}break;case 0:typeof a=="string"&&(a=a.toLowerCase());for(let d=0;d<e.length;d++){let m=e[d][0];if(typeof m=="string"&&(m=m.toLowerCase()),m===a)return u(d)}break}return r&&r.type!==0?r:Y()}},HLookup:{arguments:[...Pr],fn:(a,e,t,r=!0)=>Hr(a,e,t,r,!0)},VLookup:{arguments:[...Pr],fn:(a,e,t,r=!0)=>Hr(a,e,t,r,!1)},Product:{arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:1,imaginary:0};a=O(a);for(let t of a)t.type===8?e=H(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return B(e)}},Log:{arguments:[{name:"number",unroll:!0},{name:"base",unroll:!0}],fn:(a,e=10)=>({type:3,value:Math.log(a)/Math.log(e)})},Log10:{arguments:[{name:"number",unroll:!0}],fn:a=>({type:3,value:Math.log(a)/Math.log(10)})},Ln:{arguments:[{name:"number",unroll:!0}],fn:a=>({type:3,value:Math.log(a)})},"Ceiling.Math":{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0},{name:"away from zero",unroll:!0}],xlfn:!0,fn:(a,e=1,t)=>{let r=0;return t&&a<0?r=-Math.ceil(-a/e)*e:r=Math.ceil(a/e)*e,{type:3,value:r}}},"Floor.Math":{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0},{name:"away from zero",unroll:!0}],fn:(a,e=1,t)=>{let r=0;return t&&a<0?r=-Math.floor(-a/e)*e:r=Math.floor(a/e)*e,{type:3,value:r}}},Floor:{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0}],fn:(a,e=1)=>({type:3,value:Math.floor(a/e)*e})},Ceiling:{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0}],fn:(a,e=1)=>({type:3,value:Math.ceil(a/e)*e})},Round:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*a)/t}}},RoundDown:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e),r=a>=0;return{type:3,value:r?Math.floor(t*a)/t:Math.ceil(t*a)/t}}},RoundUp:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e),r=a>=0;return{type:3,value:r?Math.ceil(t*a)/t:Math.floor(t*a)/t}}},Reverse:{arguments:[{boxed:!0}],fn:a=>a.type===9?(a.value.length===1?a.value[0].reverse():a.value.reverse(),a):{type:2,value:(a.value??"").toString().split("").reverse().join("")}},Exp:{arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=ze(a.value);return B(e)}return a.type!==3?k():{type:3,value:Math.exp(a.value)}}},Abs:{arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:Math.sqrt(a.value.real*a.value.real+a.value.imaginary*a.value.imaginary)}:a.type!==3?k():{type:3,value:Math.abs(a.value||0)}},Simplify:{arguments:[{name:"value",unroll:!0},{name:"significant digits",unroll:!0}],fn:(a,e=2)=>{if(e=e||2,a===0)return{type:3,value:a};let t=a<0?-1:1;a*=t;let r=Math.pow(10,Math.floor(Math.log10(a))+1-e);return{type:3,value:Math.round(a/r)*r*t}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=J(a.value,{real:.5,imaginary:0});return B(e)}else{if(a.type===0||!a.value)return{type:3,value:0};if(a.type===3)return{type:3,value:Math.sqrt(a.value)}}return k()}},HexToDec:{arguments:[{description:"hexadecimal string",unroll:!0}],fn:a=>({type:3,value:parseInt(a,16)})},DecToHex:{arguments:[{description:"number",unroll:!0}],fn:a=>({type:2,value:a.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Dr,render:Lr,fn:a=>({value:!!a,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:a=>(De.RenderColumn(a.width,a.height,a.context,a.cell,a.style),{handled:!0}),fn:(...a)=>({type:5,value:a,key:"sparkline-data",source:"sparkline.column"})},"Sparkline.Line":{arguments:[{name:"data"},{name:"color"},{name:"line width"}],render:a=>(De.RenderLine(a.width,a.height,a.context,a.cell,a.style),{handled:!0}),fn:(...a)=>({type:5,value:a,key:"sparkline-data",source:"sparkline.line"})},UniqueValues:{arguments:[{name:"range",boxed:!0}],visibility:"internal",fn:a=>{if(a.type===9){let e=o=>{if(o)switch(o.type){case 2:case 3:case 4:return o.value;case 0:return"";default:return console.info("check",o,o.value),o.value?.toString()||""}else return""},t=new Set,r=new Set;for(let o of a.value)for(let i of o){let s=e(i);t.has(s)?r.add(s):t.add(s)}let n=[];for(let o of a.value){let i=[];for(let s of o){let l=e(s);i.push({type:4,value:!r.has(l)})}n.push(i)}return{type:9,value:n}}return{type:4,value:!0}}},Between:{arguments:[{name:"target",boxed:!0,unroll:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(a,e=0,t=1)=>({type:4,value:a.type===3&&a.value>=e&&a.value<=t})},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"},{name:"parameters"}],visibility:"internal",fn:(a,e,t,r)=>{let n=O([a]),o=0,i=0,s=0;for(let d of n){if(d.type===7)return d;d.type===3&&(o===0&&!r?(i=d.value,s=d.value):(i=Math.min(i,d.value),s=Math.max(s,d.value)),o++)}typeof t=="number"&&(s=t),typeof e=="number"&&(i=e);let l=s-i,c=1,u=1;if(a.type===9){c=a.value.length,u=a.value[0]?.length||0;let d=[];for(let m=0;m<c;m++){let b=[];for(let p=0;p<u;p++){let h=a.value[m][p];if(h.type===3){let f=0;s===i?h.value>s?f=1:h.value<s?f=0:f=.5:l>0&&(f=(h.value-i)/l),r?b.push({type:9,value:[[{type:3,value:f},{type:3,value:(0-i)/l}]]}):b.push({type:3,value:f})}else b.push({type:0})}d.push(b)}return{type:9,value:d}}else return _()}},ATan2:{arguments:[{name:"y",boxed:!0,unroll:!0},{name:"x",boxed:!0,unroll:!0}],fn:(a,e)=>{if(a.type===3&&e.type===3)return{type:3,value:Math.atan2(a.value,e.value)};if(a.type===3&&(a={type:8,value:{real:a.value,imaginary:0}}),e.type===3&&(e={type:8,value:{real:e.value,imaginary:0}}),a.type===8&&e.type===8){let t=_r(a.value,e.value);return t===!1?_():{type:8,value:t}}return _()}},Sin:ie(Math.sin,Ge),SinH:ie(Math.sinh,xr),ASin:ie(Math.asin,xt),Cos:ie(Math.cos,yr),CosH:ie(Math.cosh,vr),ACos:ie(Math.acos,wr),Tan:ie(Math.tan,gr),TanH:ie(Math.tanh,fr),ATan:ie(Math.atan,Cr),E:{fn:()=>({type:3,value:Math.E})},PI:{fn:()=>({type:3,value:Math.PI})},SQRT2:{fn:()=>({type:3,value:Math.SQRT2})},SQRT1_2:{fn:()=>({type:3,value:Math.SQRT1_2})},Sequence:{arguments:[{name:"rows",boxed:!0},{name:"columns",default:1,boxed:!0},{name:"start",default:1,boxed:!0},{name:"step",default:1,boxed:!0}],fn:(a,e,t,r)=>{let n=Ze(a,1),o=Ze(e,1),i=Ze(r,1),s=Ze(t,1);if(n===!1||o===!1||i===!1||s===!1)return _();let l=[];for(let c=0;c<o;c++){let u=[];for(let d=0;d<n;d++)u.push({type:3,value:s+d*i*o+c*i});l.push(u)}return{type:9,value:l}}}},Nr={};for(let a of Object.keys(_e))Nr[a.toLowerCase()]=a;var Pn=["ceil","pow","ln10","ln2","log10","log10e","log1p","log2","log2e","random","imul","clz32","fround","f16round"],Br={};for(let a of Pn)Br[a.toLowerCase()]=a;for(let a of Object.getOwnPropertyNames(Math)){let e=a.toLowerCase();if(Nr[e]||Br[e])continue;let t=Object.getOwnPropertyDescriptor(Math,a);if(!t)continue;let r=t.value,n=typeof r;switch(n){case"number":_e[a]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":_e[a]={fn:(...o)=>T(r(...o)),category:["Math Functions"]};break;default:console.info("unexpected type:",n,a);break}}Math.log10||(Math.log10=a=>Math.log(a)/Math.log(10));var Le=(a,e,t=0,r=0,n=0)=>n?-(t*(a/(1-Math.pow(1+a,-e))))/(1+a)-r*(1/((1+a)*((Math.pow(1+a,e)-1)/a))):-(t*a*Math.pow(1+a,e)+r*a)/(Math.pow(1+a,e)-1),Gr=(a,e,t,r=0,n=0)=>n?(1+a)*-t/a*(Math.pow(1+a,e)-1)-r*Math.pow(1+a,e):-t/a*(Math.pow(1+a,e)-1)-r*Math.pow(1+a,e),Rt=(a,e,t,r=0,n=0,o=0)=>{if(e<1)return NaN;if(e===1&&o)return 0;let i=Le(a,t,r,n,o),s=Gr(a,e-1,i,r,o)*a;return o?s/(1+a):s},$r=(a,e,t,r=0,n=0,o=0)=>Le(a,t,r,n,o)-Rt(a,e,t,r,n,o),jr={NPV:{description:"Returns the present value of a series of future cashflows",arguments:[{name:"Rate"},{name:"Cashflow",repeat:!0}],fn:(a=0,...e)=>{let t=0,r=F(e);for(let n=0;n<r.length;n++){let o=r[n];typeof o=="number"&&(t+=Math.pow(1+a,-(n+1))*o)}return{type:3,value:t}}},XNPV:{description:"returns the NPV of a nonperiodic stream of payments at a given rate",arguments:[{name:"Discount rate"},{name:"Values"},{name:"Dates"}],fn:(a,e,t)=>{if(typeof a!="number")return _();if(e=F(e),t=F(t),e.length!==t.length)return _();let r=[];for(let i of e){if(typeof i!="number")return _();r.push(i)}let n=[];for(let i of t){if(typeof i!="number")return _();n.push(Math.floor(i))}let o=0;for(let i=0;i<r.length;i++)o+=(r[i]||0)/Math.pow(1+a,(n[i]-n[0])/365);return{type:3,value:o}}},XIRR:{description:"returns the internal rate of return of a nonperiodic stream of payments",arguments:[{name:"Values"},{name:"Dates"},{name:"Guess",default:.1}],fn:(a,e,t=.1)=>{if(a=F(a),e=F(e),a.length!==e.length)return _();let r=0,n=0,o=[];for(let d of a){if(typeof d!="number")return _();d>0&&r++,d<0&&n++,o.push(d)}if(r<=0||n<=0)return _();let i=[];for(let d of e){if(typeof d!="number")return _();i.push(Math.floor(d))}let s=i[0];for(let d of i)if(d<s)return _();let l=.1,c=[{found:!1,value:0},{found:!1,value:0}],u=o.length;for(let d=0;d<100;d++){let m=0;for(let b=0;b<u;b++)m+=(o[b]||0)/Math.pow(1+t,(i[b]-i[0])/365);if(Math.abs(m)<=1e-6)return{type:3,value:t};if(m>0){if(c[0].value=c[0].found?Math.max(c[0].value,t):t,c[0].found=!0,!c[1].found){t+=l;continue}}else if(c[1].value=c[1].found?Math.min(c[1].value,t):t,c[1].found=!0,!c[0].found){t-=l;continue}t=c[0].value+(c[1].value-c[0].value)/2}return k()}},IRR:{description:"Calculates the internal rate of return of a series of cashflows",arguments:[{name:"Cashflows"},{name:"Guess",default:.1}],fn:(a,e=.1)=>{let t=F(a).map(o=>typeof o=="number"?o:0),r=.1,n=[{found:!1,value:0},{found:!1,value:0}];for(let o=0;o<50;o++){let i=0;for(let s=0;s<t.length;s++)i+=Math.pow(1+e,-(s+1))*t[s];if(Math.abs(i)<=.00125)return{type:3,value:e};if(i>0){if(n[0].value=n[0].found?Math.max(n[0].value,e):e,n[0].found=!0,!n[1].found){e+=r;continue}}else if(n[1].value=n[1].found?Math.min(n[1].value,e):e,n[1].found=!0,!n[0].found){e-=r;continue}e=n[0].value+(n[1].value-n[0].value)/2}return{type:7,value:"NUM"}}},CUMPRINC:{description:"Returns cumulative principal paid on a loan between two periods",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Start Period"},{name:"End Period"},{name:"Type",default:0}],fn:(a,e,t,r,n,o=0)=>{let i=0;for(let s=r;s<=n;s++)i+=$r(a,s,e,t,0,o);return{type:3,value:i}}},CUMIPMT:{description:"Returns cumulative interest paid on a loan between two periods",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Start Period"},{name:"End Period"},{name:"Type",default:0}],fn:(a,e,t,r,n,o=0)=>{let i=0;for(let s=r;s<=n;s++)i+=Rt(a,s,e,t,0,o);return{type:3,value:i}}},IPMT:{description:"Returns the interest portion of a payment",arguments:[{name:"Rate"},{name:"Period"},{name:"Periods"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0,o=0)=>({type:3,value:Rt(a,e,t,r,n,o)})},PPMT:{description:"Returns the principal portion of a payment",arguments:[{name:"Rate"},{name:"Period"},{name:"Periods"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0,o=0)=>({type:3,value:$r(a,e,t,r,n,o)})},Rate:{description:"Returns the interest rate of a loan",arguments:[{name:"Periods"},{name:"Payment"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t=0,r=0,n=0)=>{let o=.25,i=[-1,1],s=32,l=1e-6;for(let c=0;c<s;c++){let u=Le(o,a,t,r,n);if(Math.abs(u-e)<=l)return{type:3,value:o};let d=Le(i[1],a,t,r,n);e>=u&&e<=d||e>=d&&e<=u?i[0]=o:i[1]=o,o=i[0]+(i[1]-i[0])/2}return{type:3,value:o}}},FV:{description:"Returns the future value of an investment",arguments:[{name:"Rate"},{name:"Periods"},{name:"Payment"},{name:"Present Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>({type:3,value:Gr(a,e,t,r,n)})},PV:{description:"Returns the present value of an investment",arguments:[{name:"Rate"},{name:"Periods"},{name:"Payment"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>n?(t+=r*(1/((1+a)*((Math.pow(1+a,e)-1)/a))),{type:3,value:-(t+t/a*(1-Math.pow(1+a,-(e-1))))}):{type:3,value:-(r+t/a*(Math.pow(1+a,e)-1))/Math.pow(1+a,e)}},NPER:{description:"Returns the number of periods of an investment",arguments:[{name:"Rate"},{name:"Payment"},{name:"Present Value"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t=0,r=0,n=0)=>n?{type:3,value:1+(-Math.log(1+a*(1-t/-e))+Math.log(1+r*a/(-e*(1+a))))/Math.log(1+a)}:{type:3,value:(Math.log(Math.pow(1-t*a/-e,-1))+Math.log(1+r*a/-e))/Math.log(1+a)}},PMT:{description:"Returns the periodic payment of a loan",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>({type:3,value:Le(a,e,t,r,n)})}};var qr={Char:{arguments:[{name:"number"}],fn:a=>({type:2,value:String.fromCodePoint(a||32)}),category:["text"]},Code:{arguments:[{name:"string"}],fn:a=>({type:3,value:a.codePointAt(0)||0}),category:["text"]},Value:{arguments:[{name:"text"}],fn:a=>{let e=we.TryParse(a);return e.type===3?{type:3,value:e.value}:_()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(a,e="0.00####")=>({type:2,value:R.Get(e).Format(a||0)}),category:["text"]},WildcardMatch:{visibility:"internal",arguments:[{name:"text",unroll:!0},{name:"text",unroll:!0},{name:"invert"}],fn:(a,e,t=!1)=>{if(typeof a=="string"&&typeof e=="string"){let r=Te(e),n=new RegExp("^"+r+"$","i").exec(a);return{type:4,value:t?!n:!!n}}return{type:4,value:a===e||a?.toString()===e?.toString()}}},Exact:{arguments:[{name:"text",boxed:!0,unroll:!0},{name:"text",boxed:!0,unroll:!0}],category:["text"],fn:(a,e)=>({type:4,value:a?.value?.toString()===e?.value?.toString()})},Len:{arguments:[{name:"string",unroll:!0}],fn:a=>({type:3,value:a.toString().length})},Substitute:{arguments:[{name:"text"},{name:"search"},{name:"replacement"},{name:"index"}],fn:(a,e,t,r)=>{if(typeof r=="number"){if(r<1)return k();let n=1;return{type:2,value:a.replaceAll(e,(...o)=>(console.info(o),n++===r?t:e))}}else return{type:2,value:a.replaceAll(e,t)}}},Left:{arguments:[{name:"string"},{name:"count"}],fn:(a,e=1)=>({type:2,value:a.substr(0,e)}),category:["text"]},Right:{arguments:[{name:"string"},{name:"count"}],fn:(a,e=1)=>({type:2,value:a.slice(-e)}),category:["text"]},Mid:{arguments:[{name:"string"},{name:"left"},{name:"count"}],fn:(a,e=0,t=1)=>({type:2,value:a.substr(Math.max(0,e-1),t)}),category:["text"]},Search:{description:"Find a string (needle) in another string (haystack). Case-insensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(a,e,t=1)=>{if(t>=1){if(!a)return{type:3,value:t};let r=Te(a),n=new RegExp(r,"i").exec(e.substr(t-1));if(n)return{type:3,value:n.index+t}}return k()}},Find:{description:"Find a string (needle) in another string (haystack). Case-sensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(a,e,t=1)=>{if(t>=1){if(!a)return{type:3,value:t};a=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let r=new RegExp(a).exec(e.substr(t-1));if(r)return{type:3,value:r.index+t}}return k()}},Upper:{description:"Converts text to upper case",arguments:[{name:"text",unroll:!0}],fn:a=>a==null?{type:0}:{type:2,value:a.toString().toUpperCase()}},Lower:{description:"Converts text to lower case",arguments:[{name:"text",unroll:!0}],fn:a=>a==null?{type:0}:{type:2,value:a.toString().toLowerCase()}},Concat:{description:"Pastes strings together",arguments:[{name:"text",repeat:!0}],fn:(...a)=>{let t=F(a).map(r=>{let n=r?.toString()||"";return typeof r=="number"&&ee.decimal_separator===","?n.replace(/\./,","):n}).join("");return{type:2,value:t}}}},Et={Concatenate:"Concat"};var Ke=(a,e)=>({type:4,value:typeof e.value?.value===a}),Qe=[{name:"Reference",metadata:!0,unroll:!0}],Xr={IsBlank:{description:"Returns true if the reference is blank",arguments:Qe,fn:Ke.bind(0,"undefined")},IsNumber:{description:"Returns true if the reference is a number",arguments:Qe,fn:Ke.bind(0,"number")},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:Qe,fn:Ke.bind(0,"boolean")},IsText:{description:"Returns true if the reference is text",arguments:Qe,fn:Ke.bind(0,"string")}};var Wr=2220446049250313e-31,Hn=a=>{let e=1+a;return Math.log(e)-(e-1-a)/e},et=(a,e,t,r)=>{let n=2*Number.MIN_VALUE,o=0,i=1,s=1-(a+e)*t/(a+1);Math.abs(s)<n&&(s=Number.NaN),s=1/s,o=s;for(let l=1;l<=512;l++){let c=l*(e-l)*t/((a-1+2*l)*(a+2*l)),u=0;if(s=1+c*s,i=1+c/i,Math.abs(s)<n&&(s=Number.NaN),Math.abs(i)<n&&(i=Number.NaN),s=1/s,u=s*i,o*=u,c=-(a+l)*(a+e+l)*t/((a+2*l)*(a+2*l+1)),s=1+c*s,i=1+c/i,Math.abs(s)<n&&(s=Number.NaN),Math.abs(i)<n&&(i=Number.NaN),s=1/s,u=s*i,o*=u,Math.abs(u-1)<2*Wr||o*Math.abs(u-1)<r)return o}return Number.NaN},zt=(a,e,t)=>{if(e<0||t<0)return Number.NaN;if(a<=0)return 0;if(a>=1)return 1;if(a>.5)return 1-zt(1-a,t,e);let r=e/(e+t),n=0;if(a<.1){let o=(Math.log(e)+N(e)+N(t)-N(e+t)+Math.log(a))/e;o<=0?(n=Math.exp(o),n*=Math.pow(1-n,-(t-1)/e)):n=r,n>r&&(n=r)}else n=r;for(let o=0;o<64;o++){let i=a-Dt(n,e,t),s=Tt(n,e,t);if(i===0)return n;let l=i/Math.max(2*Math.abs(i/n),s),c=l,u=-((e-1)/n-(t-1)/(1-n))*l*l/2,d=c;if(Math.abs(u)<Math.abs(c)?d+=u:d*=2*Math.abs(c/u),n+d>0&&n+d<1?n+=d:n=Math.sqrt(n)*Math.sqrt(r),Math.abs(c)<=1e-10*n)return n}return n},N=a=>{let e=a-1,t=e+5.5;t-=(e+.5)*Math.log(t);let r=1,n=[76.18009173,-86.50532033,24.01409822,-1.231739516,.00120858003,-536382e-11];for(let o of n)r+=o/++e;return-t+Math.log(2.50662827465*r)},Tt=(a,e,t)=>a<0||a>1?0:Math.exp(N(e+t)-N(e)-N(t))*Math.pow(a,e-1)*Math.pow(1-a,t-1),Dt=(a,e,t)=>{if(a<=0)return 0;if(a>=1)return 1;let n=-(N(e)+N(t)-N(e+t))+e*Math.log(a)+t*Hn(-a),o=Math.exp(n);if(a<(e+1)/(e+t+2)){let i=et(e,t,a,0);return o*i/e}else{let i=Math.abs(t/o)*Wr,s=et(t,e,1-a,i);return 1-o*s/t}},Jr=(a,e,t)=>{if(a<0||a>1)return 0;let r=a===0||a===1?0:Math.exp(N(e+t)-N(e)-N(t)+e*Math.log(a)+t*Math.log(1-a));return a<(e+1)/(e+t+2)?r*et(e,t,a,0)/e:1-r*et(t,e,1-a,0)/t};var Yr=a=>{let e=a-1,t=e+5.5;t-=(e+.5)*Math.log(t);let r=1,n=[76.18009173,-86.50532033,24.01409822,-1.231739516,.00120858003,-536382e-11];for(let o of n)r+=o/++e;return-t+Math.log(2.50662827465*r)},On=(a,e)=>{let t=Yr(a);if(e===0)return 0;let r=a,n=1/a,o=n;for(let i=1;i<1e3;i++)if(++r,o*=e/r,n+=o,Math.abs(o)<Math.abs(n)*3e-9)return n*Math.exp(-e+a*Math.log(e)-t);return console.error("too many iterations"),!1},Nn=(a,e)=>{let t=Yr(a),r=e+1-a,n=1/1e-30,o=1/r,i=o;for(let s=1;s<=1e3;s++){let l=-s*(s-a);r+=2,o=l*o+r,Math.abs(o)<1e-30&&(o=1e-30),n=r+l/n,Math.abs(n)<1e-30&&(n=1e-30),o=1/o;let c=o*n;if(i*=c,Math.abs(c-1)<3e-9)return Math.exp(-e+a*Math.log(e)-t)*i}return console.error("too many iterations"),!1},tt=(a,e)=>{if(e<0||a<=0)return console.error("invalid parameter"),!1;if(e<a+1)return On(a,e);{let t=Nn(a,e);return t===!1?!1:1-t}};var Fe=a=>{if(a===.5)return 0;let e=a<1&&a>.5?1-a:a,t=Math.sqrt(Math.log(1/Math.pow(e,2))),r=t-(2.515517+.802853*t+.010328*Math.pow(t,2))/(1+1.432788*t+.189269*Math.pow(t,2)+.001308*Math.pow(t,3));return a>.5?r:-r};var Lt=(a,e)=>{let t=e/(e+a*a),r=e/2,o=Jr(t,r,.5);return a>=0?1-.5*o:.5*o},Ft=(a,e)=>{let t=N((e+1)/2),r=N(e/2)+.5*Math.log(e*Math.PI),n=-((e+1)/2)*Math.log(1+a*a/e),o=t-r+n;return Math.exp(o)},It=(a,e)=>{let r=1;{let n=Fe(a),o=(Math.pow(n,3)+n)/4,i=(5*Math.pow(n,5)+16*Math.pow(n,3)+3*n)/96,s=(3*Math.pow(n,7)+19*Math.pow(n,5)+17*Math.pow(n,3)-15*n)/384,l=(79*Math.pow(n,9)+776*Math.pow(n,7)+1482*Math.pow(n,5)-1920*Math.pow(n,3)-945*n)/92160;r=n+o/e+i/Math.pow(e,2)+s/Math.pow(e,3)+l/Math.pow(e,4)}for(let n=0;n<16;n++){let o=Lt(r,e)-a;if(Math.abs(o)<1e-12)break;let i=Ft(r,e);if(i===0)break;let s=o/i,l=Math.max(-1,Math.min(1,s));r-=l}return r};var Kr=a=>{let e=.254829592,t=-.284496736,r=1.421413741,n=-1.453152027,o=1.061405429,i=.3275911;a=Math.abs(a);let s=1/(1+i*a);return 1-((((o*s+n)*s+r)*s+t)*s+e)*s*Math.exp(-1*a*a)},Bn=Math.sqrt(2*Math.PI),Pt=(a,e,t,r)=>{let n=0;return r?n=.5*(1+(a<e?-1:1)*Kr(Math.abs(a-e)/(t*Math.sqrt(2)))):n=Math.exp(-1/2*Math.pow((a-e)/t,2))/(t*Bn),n},Ht=a=>{let e=a.length;return e%2?a[Math.floor(e/2)]:(a[e/2]+a[e/2-1])/2},Zr=(a,e=!0)=>{a.sort((n,o)=>n-o);let t=a.length,r=(n,o,i)=>{let s=o*n+i,l=s%1;if(l){let c=a[Math.floor(s)],u=a[Math.ceil(s)];return c+(u-c)*l}else return a[s]};return e?[a[0],r(.25,t-1,0),Ht(a),r(.75,t-1,0),a[t-1]]:t%1?[a[0],r(.25,t-2,0),Ht(a),r(.75,t-2,1),a[t-1]]:[a[0],r(.25,t-3,0),Ht(a),r(.75,t-3,2),a[t-1]]},rt=a=>{let e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],t=Math.PI,r=Ge,n=ce,o=H,i=p=>({real:p,imaginary:0}),s=(p,h)=>({real:p.real+h.real,imaginary:p.imaginary+h.imaginary}),l=J,c=ze,u=p=>({real:-p.real,imaginary:-p.imaginary}),d=kr;if(a.real<.5)return n(i(t),o(r(o(i(t),a)),rt({real:1-a.real,imaginary:-a.imaginary})));a.real-=1;let m=i(e[0]);for(let p=1;p<e.length;p++)m=s(m,n(i(e[p]),s(a,i(p))));let b=s(a,i(7.5));return d(i(Math.sqrt(2*t)),l(b,s(a,i(.5))),c(u(b)),m)},$n=(a,e,t)=>{let r=rt({real:e,imaginary:0}).real;return Math.pow(a,e-1)*Math.exp(-a/t)/(r*Math.pow(t,e))},Gn=(a,e,t)=>{let r=0,n=e*10,o=1e-6,i=0;for(;n-r>o;){i++;let s=(n+r)/2,l=tt(e,r/t),c=tt(e,s/t);if(l===!1||c===!1)return!1;(c-a)*(l-a)<0?n=s:r=s}return(r+n)/2},te=(a,e=!1)=>{let t=a.length,r=0,n=0;for(let o=0;o<t;o++)r+=a[o];r/=t;for(let o=0;o<t;o++){let i=a[o]-r;n+=i*i}return e?n/(t-1):n/t},Qr={Slope:{arguments:[{name:"known_y"},{name:"known_x"}],fn:(a,e)=>{let t=P(e),r=P(a);if(t.length!==r.length)return _();let n=0,o=0,i=0,s=0;for(let c=0;c<t.length;c++){let u=t[c],d=r[c];i+=u*d,n+=u,o+=d,s+=u*u}let l=(t.length*i-n*o)/(t.length*s-n*n);return{type:3,value:l}}},Intercept:{arguments:[{name:"known_y"},{name:"known_x"}],fn:(a,e)=>{let t=P(e),r=P(a);if(t.length!==r.length)return _();let n=t.length,o=0,i=0,s=0,l=0;for(let u=0;u<n;u++){let d=t[u],m=r[u];s+=d*m,o+=d,i+=m,l+=d*d}let c=n*s-o*i;return c/=n*l-o*o,{type:3,value:(i-c*o)/n}}},Phi:{arguments:[{name:"x",boxed:!0,unroll:!0}],fn:a=>a.type===3?{type:3,value:1/Math.sqrt(Math.PI*2)*Math.exp(-a.value*a.value/2)}:_()},"Z.Test":{arguments:[{name:"Array",boxed:!0},{name:"x",boxed:!0,unroll:!0},{name:"Sigma",boxed:!0,unroll:!0}],fn:(a,e,t)=>{let r=[];if(a.type===9)for(let n of a.value)for(let o of n)o.type===3&&r.push(o.value);else a.type===3&&r.push(a.value);if(r.length&&e.type===3){let n=0,o=r.length;for(let s of r)n+=s;n/=o;let i=t?.type===3?t.value:Math.sqrt(te(r,!0));return{type:3,value:1-Pt((n-e.value)/(i/Math.sqrt(o)),0,1,!0)}}return _()}},"Beta.Dist":{description:"beta distribution",arguments:[{name:"x",unroll:!0},{name:"a"},{name:"b"},{name:"cumulative"}],fn:(a,e,t,r)=>e<0||t<0?_():r?{type:3,value:Dt(a,e,t)}:{type:3,value:Tt(a,e,t)}},"Beta.Inv":{description:"Inverse of the beta distribution",arguments:[{name:"probability",unroll:!0},{name:"a"},{name:"b"}],fn:(a,e,t)=>e<0||t<0?_():{type:3,value:zt(a,e,t)}},Erf:{fn:a=>({type:3,value:Kr(a)})},"Norm.Inv":{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"},{name:"mean",default:0},{name:"standard deviation",default:1}],xlfn:!0,fn:(a,e=0,t=1)=>({type:3,value:Fe(a)*t+e})},"Norm.S.Inv":{description:"Inverse of the standard normal cumulative distribution",arguments:[{name:"probability",unroll:!0}],xlfn:!0,fn:a=>({type:3,value:Fe(a)})},"Norm.Dist":{description:"Cumulative normal distribution",arguments:[{name:"value"},{name:"mean",default:0},{name:"standard deviation",default:1},{name:"cumulative",default:!0}],xlfn:!0,fn:(a,e=0,t=1,r=!0)=>({type:3,value:Pt(a,e,t,r)})},"Norm.S.Dist":{description:"Cumulative normal distribution",arguments:[{name:"value"},{name:"cumulative",default:!0}],xlfn:!0,fn:(a,e=!0)=>({type:3,value:Pt(a,0,1,e)})},"StDev.P":{description:"Returns the standard deviation of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:Math.sqrt(te(P(a),!1))})},"StDev.S":{description:"Returns the standard deviation of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:Math.sqrt(te(P(a),!0))})},"Var.P":{description:"Returns the variance of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:te(P(a),!1)})},"Var.S":{description:"Returns the variance of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:te(P(a),!0)})},Covar:{description:"Returns the covariance between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(a,e)=>{if(!Array.isArray(a)||!Array.isArray(e))return k();if(!Array.isArray(a[0])||!Array.isArray(e[0]))return k();if(a.length!==e.length)return _();let t=0,r=0,n={x:0,y:0},o={x:[],y:[]};for(let i=0;i<a.length;i++){if(!a[i]||!e[i])continue;if(a[i].length!==e[i].length)return _();let s=a[i].length;r+=s;for(let l=0;l<s;l++)n.x+=a[i][l]||0,n.y+=e[i][l]||0,o.x.push(a[i][l]||0),o.y.push(e[i][l]||0)}if(r===0)return Y();n.x/=r,n.y/=r;for(let i=0;i<r;i++)t+=(o.x[i]-n.x)*(o.y[i]-n.y);return{type:3,value:t/r}}},Correl:{description:"Returns the correlation between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(a,e)=>{if(!Array.isArray(a)||!Array.isArray(e))return k();if(!Array.isArray(a[0])||!Array.isArray(e[0]))return k();let t=0,r=0,n=0,o=0,i=0,s=0,l=0;for(let c=0;c<a.length;c++){if(!a[c]||!e[c])continue;let u=a[c].length;for(let d=0;d<u;d++){let m=Number(a[c][d]),b=Number(e[c][d]);isNaN(m)||isNaN(b)||(r+=m*b,n+=m,o+=b,i+=m*m,s+=b*b,l++)}}return t=l*r-n*o,t&&(t/=Math.sqrt((l*i-n*n)*(l*s-o*o))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=0,t={real:1,imaginary:0},r=!1,n=!1;for(let o of a)o.type===8?(r=!0,t=H(t,o.value),e++):o.type===3&&(o.value<0&&(n=!0),e++,t.real*=o.value,t.imaginary*=o.value);if(r){let o=J(t,{real:1/e,imaginary:0});return o.imaginary?{type:8,value:o}:{type:3,value:o.real}}else return n?k():{type:3,value:Math.pow(t.real,1/e)}}},LCM:{description:"Retuns the least common mulitple of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=[];for(let n of a){if(n.type===7)return n;if(n.type===3)e.push(n.value);else if(n.type!==0)return console.info("RT",n.type),_()}let t=(n,o)=>n%o==0?o:t(o,n%o);if(e.length===0)return{type:3,value:0};let r=e[0];for(let n=1;n<e.length;n++)r=r*e[n]/t(r,e[n]);return{type:3,value:r}}},"Gamma.Inv":{description:"Returns the inverse of the gamma distribution",arguments:[{name:"probability",unroll:!0},{name:"alpha"},{name:"beta"}],fn:(a,e,t)=>{if(a<0||a>1)return _();let r=Gn(a,e,t);return r===!1?k():{type:3,value:r}}},"Gamma.Dist":{fn:(a,e,t,r)=>{if(a<0||e<=0||t<=0)return _();let n=r?tt(e,a/t):$n(a,e,t);return n===!1?k():{type:3,value:n}}},"T.DIST":{description:"Returns the left-tailed Student's t-distribution",arguments:[{name:"X",unroll:!0,boxed:!0},{name:"degrees of freedom",unroll:!0,boxed:!0},{name:"cumulative",unroll:!0,boxed:!0}],fn:(a,e,t)=>{let r=t?!!t.value:!1;return e.type!==3||a.type!==3||e.value<1?_():{type:3,value:r?Lt(a.value,e.value):Ft(a.value,e.value)}}},"T.Inv":{description:"Returns the left-tailed inverse of the Student's t-distribution",arguments:[{name:"Probability",boxed:!0,unroll:!0},{name:"Degrees of freedom",boxed:!0,unroll:!0}],fn:(a,e)=>e.type!==3||e.value<1||a.type!==3||a.value<=0||a.value>=1?_():{type:3,value:It(a.value,e.value)}},"T.Inv.2T":{description:"Returns the two-tailed inverse of the Student's t-distribution",arguments:[{name:"Probability",boxed:!0,unroll:!0},{name:"Degrees of freedom",boxed:!0,unroll:!0}],fn:(a,e)=>e.type!==3||e.value<1||a.type!==3||a.value<=0||a.value>=1?_():{type:3,value:Math.abs(It(1-a.value/2,e.value))}},GammaLn:{description:"Returns the natural log of the gamma function",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>a.type===3?{type:3,value:N(a.value)}:_()},"GammaLn.Precise":{description:"Returns the natural log of the gamma function",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>{let e;if(a.type===3?e={real:a.value,imaginary:0}:a.type===8&&(e=a.value),e){let t=rt(e);return B(wt(t))}return _()}},Gamma:{description:"Returns the gamma function for the given value",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>{let e={real:0,imaginary:0};if(a.type===8)e={...a.value};else if(a.type===3)e.real=a.value;else return _();if(e.imaginary===0&&e.real%1===0&&e.real<=0)return k();let t=rt(e);return Math.abs(t.imaginary)<=1e-7?{type:3,value:t.real}:{type:8,value:t}}},Delta:{arguments:[{name:"number"},{name:"number",default:0}],fn:(a,e=0)=>typeof a!="number"||typeof e!="number"?k():{type:3,value:a===e?1:0}},GCD:{description:"Finds the greatest common divisor of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=[];for(let n of a){if(n.type===7)return n;if(n.type===3)e.push(n.value);else if(n.type!==0)return console.info("RT",n.type),_()}let t=(n,o)=>n%o==0?o:t(o,n%o);if(e.length===0)return k();if(e.length===1)return{type:3,value:e[0]};let r=e[0];for(let n=1;n<e.length;n++)r=t(r,e[n]);return{type:3,value:r}}},HarMean:{description:"Returns the harmonic mean of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e={real:0,imaginary:0},t=0;for(let r of a){if(r.type===7)return r;if(r.type===3&&(e.real+=1/r.value,t++),r.type===8){let n=ce({real:1,imaginary:0},r.value);e.real+=n.real,e.imaginary+=n.imaginary,t++}}return e.imaginary?{type:8,value:ce({real:t,imaginary:0},e)}:{type:3,value:t/e.real}}},Average:{description:"Returns the arithmetic mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e={real:0,imaginary:0},t=0;for(let r of a){if(r.type===7)return r;r.type===3&&(e.real+=r.value,t++),r.type===8&&(e.real+=r.value.real,e.imaginary+=r.value.imaginary,t++)}return e.real/=t,e.imaginary/=t,e.imaginary?{type:8,value:e}:{type:3,value:e.real}}},Percentile:{description:"Returns the kth percentile value from the range of data",arguments:[{name:"range"},{name:"percentile"}],fn:(a,e)=>{let t=P(a);t.sort((l,c)=>l-c);let r=t.length,n=Math.pow(10,8),o=Math.round((1+(r-1)*e)*n)/n,i=Math.floor(o),s=Math.ceil(o);return{type:3,value:(t[i-1]+t[s-1])/2}}},"Quartile.Inc":{description:"Returns the interpolated quartile of the data set (including median)",arguments:[{name:"range"},{name:"quartile"}],xlfn:!0,fn:(a,e)=>{if(typeof e!="number"||e<0||e>4||e%1)return _();let t=P(a),r=Zr(t,!0);return{type:3,value:r[e]}}},"Quartile.Exc":{description:"Returns the interpolated quartile of the data set (excluding median)",arguments:[{name:"range"},{name:"quartile"}],xlfn:!0,fn:(a,e)=>{if(typeof e!="number"||e<1||e>3||e%1)return _();let t=P(a),r=Zr(t,!1);return{type:3,value:r[e]}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...a)=>{let e=P(a);e.sort((i,s)=>i-s);let r=1+(e.length-1)*.5,n=Math.floor(r),o=Math.ceil(r);return{type:3,value:(e[n-1]+e[o-1])/2}}},Rank:{arguments:[{name:"Value"},{name:"Source"},{name:"Order"}],fn:(a,e,t=0)=>{if(typeof a!="number")return _();let r=P(e);r.sort(t?(n,o)=>n-o:(n,o)=>o-n);for(let n=0;n<r.length;n++)if(r[n]===a)return{type:3,value:n+1};return k()}}},Ot={Mean:"Average",StDev:"StDev.S",StDevA:"StDev.S",StDevPA:"StDev.P",Var:"Var.S",Quartile:"Quartile.Inc",NormSInv:"Norm.S.Inv",NormSDist:"Norm.S.Dist",NormDist:"Norm.Dist"};var en={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0,unroll:!0}],fn:a=>({type:4,value:!!a?.value&&X(a.value.value)})},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===3?{...a}:a.type===8?{type:3,value:a.value.real||0}:a.type===0||a.type===2&&a.value===""?{type:3,value:0}:k()},Imaginary:{description:"Returns the imaginary part of a complex number (as real)",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:a.value.imaginary||0}:a.type===3||a.type===0||a.type===2&&a.value===""?{type:3,value:0}:k()},Conjugate:{description:"Returns the conjugate of a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>{let e=ue(a);return e?e.imaginary?{type:8,value:{real:e.real,imaginary:-e.imaginary}}:{type:3,value:e.real}:k()}},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:Math.atan2(a.value.imaginary,a.value.real)}:a.type===3||a.type===0||a.type===2&&a.value===""?{type:3,value:Math.atan2(0,a.value||0)}:k()},Rectangular:{description:"Converts a complex number in polar form to rectangular form",arguments:[{name:"r"},{name:"\u03B8 in radians"}],fn:(a=0,e=0)=>({type:8,value:{real:a*Math.cos(e),imaginary:a*Math.sin(e)}})},Complex:{description:"Ensures that the given value will be treated as a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>{let e=ue(a);return e?{type:8,value:e}:k()}},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===3){if(!a.value)return k();a={type:8,value:{real:a.value,imaginary:0}}}else if(a.type===0||a.type===2&&a.value==="")return k();if(a.type===8){let e=$e(a.value),t={real:Math.log(e.r),imaginary:e.theta};return t.imaginary?{type:8,value:t}:{type:3,value:t.real}}return k()}}};var nt=a=>{let e=[];a.type===9?e=a.value:e=[[a]];let t=e.length,r=t?e[0].length:0,n=[];if(!t||!r)return{m:t,n:r,array:n};for(let o=0;o<t;o++){let i=[];for(let s=0;s<r;s++){let l=e[o][s];if(l.type===8)i.push({...l.value});else if(l.type===3)i.push({real:l.value,imaginary:0});else if(l.type===0||l.value==="")i.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}n.push(i)}return{m:t,n:r,array:n}},tn={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>{let e=nt(a);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return k();let t=je(e);return t?B(t):k()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>{let e=nt(a);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return k();let t=je(e);if(t&&t.real===0&&t?.imaginary===0)return k();let r=Mr(e);return r?{type:9,value:r.map(n=>n.map(o=>B(o)))}:k()}},MMult:{description:"Returns the dot product A \u22C5 B",arguments:[{name:"A",boxed:!0},{name:"B",boxed:!0}],fn:(a,e)=>{let t=nt(a),r=nt(e);if(!t.array||t.error||!r.array||r.error)return k();if(t.m!==r.n)return k();let n=Sr(r,t);return{type:9,value:n.map(o=>o.map(i=>B(i)))}}}};var rn={RegexExtract:{description:"Extract text using a regular expression",arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"return mode",unroll:!0,default:0},{name:"case insensitive",unroll:!0,default:!1}],fn:(a,e="",t=0,r=!1)=>{let n=[];r&&n.push("i"),t===1&&n.push("g");let o=String(a??""),i;try{i=new RegExp(e,n.length?n.join(""):void 0)}catch{return _()}switch(t){case 0:{let s=o.match(i);return{type:2,value:s===null?"":s[0]??""}}case 1:{let s=Array.from(o.matchAll(i));return console.info({result:s}),{type:9,value:[s.map(l=>({type:2,value:l[0]||""}))]}}case 2:{let s=o.match(i);if(s===null)return{type:2,value:""};let l=Array.from(s).slice(1);return{type:9,value:[l.map(c=>({type:2,value:c}))]}}default:return _()}}},RegexReplace:{arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"replacement",unroll:!0},{name:"occurrence",unroll:!0,default:0},{name:"case insensitive",unroll:!0,default:!1}],description:"Replace text in a string using a regex",fn:(a,e,t,r=0,n=!1)=>{let o=["g"];n&&o.push("i");let i=new RegExp(e,o.length?o.join(""):void 0);if(r===0)return{type:2,value:a.replaceAll(i,t)};if(r<0){let l=Array.from(a.matchAll(i)).length;r+=l+1}let s=a.replace(i,l=>--r===0?t:l);return{type:2,value:s}}},RegexTest:{arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"case insensitive",unroll:!0,default:!1}],description:"Match text against a regular expression",fn:(a,e,t=!1)=>{let r=new RegExp(e,t?"i":void 0);return{type:4,value:r.test(a)}}}};var nn={Lambda:{description:"Creates a function",arguments:[{name:"Argument",repeat:!0,boxed:!0,passthrough:!0},{name:"Function",boxed:!0,passthrough:!0}],pass_through_ui:"indirect",fn:(...a)=>({type:6,value:{bindings:a.slice(0,a.length-1),func:a[a.length-1],alt:"LAMBDA",type:"function"}})},Let:{description:"Binds values to names for a calculation",arguments:[{name:"Name",repeat:!0},{name:"Value",repeat:!0},{name:"Calculation",boxed:!0}],create_binding_context:({args:a,descriptors:e})=>{if(a.length%2!==1)return;let t={};for(let r=0;r<a.length-1;r+=2){let n=a[r],o=a[r+1];if(n.type==="identifier")t[n.name]=o;else return}return{context:t,args:a.slice(-1),argument_descriptors:e.slice(-1)}},fn:a=>a||{type:0}}};var an={MakeArray:{description:"Create an array using a function",arguments:[{name:"rows"},{name:"columns"},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(a>0&&e>0&&t?.type===6){let r=this?.apply;if(!r)return k();let n=[];for(let o=0;o<e;o++){let i=[];for(let s=0;s<a;s++)i.push(r(t,[{type:3,value:s+1},{type:3,value:o+1}]));n.push(i)}return{type:9,value:n}}return _()}},ChooseCols:{description:"Returns one or more columns from an array, by column index",arguments:[{name:"array"},{name:"column",repeat:!0}],fn:function(a,...e){Array.isArray(a)||(a=[[a]]);let t=F(e),r=a.length,n=[];for(let o of t)if(typeof o=="number"){o<0?o=r+o:o--;let i=a[o];if(i){let s=[];for(let l of i)s.push(T(l));n.push(s)}else return _()}return n.length||n.push([]),{type:9,value:n}}},ChooseRows:{description:"Returns one or more rows from an array, by row index",arguments:[{name:"array"},{name:"row",repeat:!0}],fn:function(a,...e){Array.isArray(a)||(a=[[a]]);let t=F(e),r=a[0]?.length||0,n=[];for(let o of t)if(typeof o=="number"){o<0?o=r+o:o--;for(let[i,s]of a.entries()){let l=n[i]||[];if(o<0||o>=s.length)return _();l.push(T(s[o])),n[i]=l}}return n.length||n.push([]),{type:9,value:n}}},Take:{description:"Returns some number of rows/columns from the start or end of an array",arguments:[{name:"array"},{name:"rows"},{name:"columns"}],fn:function(a,e,t){if(!e&&!t||e===0||t===0||typeof e!="number"&&typeof e<"u"||typeof t!="number"&&typeof t<"u")return _();Array.isArray(a)||(a=[[a]]);let r=a.length,n=a[0].length,o=[],i=0,s=r-1,l=0,c=n-1;typeof t=="number"&&(t>0?s=Math.min(t,r)-1:t<0&&(s=r-1,i=Math.max(0,s+t+1))),typeof e=="number"&&(e>0?c=Math.min(e,n)-1:e<0&&(c=n-1,l=Math.max(0,c+e+1)));for(let u=i;u<=s;u++){let d=[];for(let m=l;m<=c;m++)d.push(T(a[u][m]));o.push(d)}return{type:9,value:o}}},Reduce:{description:"Accumulates a value by applying a function to a set of values",arguments:[{name:"initial value",boxed:!0},{name:"data",description:"Input data",boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(!this?.apply)return k();if(t.type!==6)return _();e.type!==9&&(e={type:9,value:[[e]]});let r=e.value.length,n=e.value[0].length;for(let o=0;o<n;o++)for(let i=0;i<r;i++){let s=[a,e.value[i][o]];a=this.apply(t,s)}return a}},Scan:{description:"Applies a function to a set of values, iteratively",arguments:[{name:"initial value",boxed:!0},{name:"data",description:"Input data",boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(!this?.apply)return k();if(t.type!==6)return _();e.type!==9&&(e={type:9,value:[[e]]});let r=[],n=e.value.length,o=e.value[0].length;for(let i=0;i<n;i++)r.push([]);for(let i=0;i<o;i++)for(let s=0;s<n;s++){let l=[a,e.value[s][i]],c=this.apply(t,l);r[s][i]=c,a=c}return{type:9,value:r}}},ByRow:{description:"Apply a function to each row in an array",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e){if(!this?.apply)return k();if(e.type!==6)return _();a.type!==9&&(a={type:9,value:[[a]]});let t=a.value.length,r=a.value[0].length,n=[[]];for(let o=0;o<r;o++){let i=[];for(let s=0;s<t;s++)i.push(a.value[s][o]);n[0].push(this.apply(e,[{type:9,value:[i]}]))}return{type:9,value:n}}},ByCol:{description:"Apply a function to each column in an array",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e){if(!this?.apply)return k();if(e.type!==6)return _();a.type!==9&&(a={type:9,value:[[a]]});let t=a.value.length,r=a.value[0].length,n=[];for(let o=0;o<t;o++){let i=[];for(let s=0;s<r;s++)i.push(a.value[o][s]);n.push([this.apply(e,[{type:9,value:[i]}])])}return{type:9,value:n}}},Map:{description:"Apply a function to a set of values",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(...a){if(a.length<2)return _();let e=a[a.length-1];if(e.type!==6)return _();let t=this?.apply;if(!t)return k();for(let o=0;o<a.length-1;o++){let i=a[o];i.type!==9&&(a[o]={type:9,value:[[i]]})}let r=a[0],n=[];if(r.type===9)for(let o=0;o<r.value.length;o++){let i=r.value[o],s=[];for(let l=0;l<i.length;l++){let c=[i[l]];for(let u=1;u<a.length-1;u++){let d=a[u];d.type===9&&c.push(d.value[o][l])}s.push(t(e,c))}n.push(s)}return{type:9,value:n}}}};var ke=class a extends oe{static type="state-leaf-vertex";state_id=0;type=a.type;color=2;Calculate(){if(this.dirty){for(let e of this.edges_in)if(e.dirty)return;this.state_id++,this.dirty=!1}}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var at=class a extends oe{static type="calculation-leaf-vertex";type=a.type;address={row:-1,column:-1};use;updated=!1;color=2;Calculate(e){if(!this.dirty)return;for(let r of this.edges_in)if(r.dirty)return;let t=e.CalculationCallback.call(e,this);this.result=t.value,this.dirty=!1,this.updated=!0}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var qn=a=>{if(typeof a=="string")switch(a=a.toUpperCase(),a){case"AVERAGE":case"MEAN":a=101;break;case"COUNT":a=102;break;case"COUNTA":a=103;break;case"MAX":a=104;break;case"MIN":a=105;break;case"PRODUCT":a=106;break;case"STDEV":a=107;break;case"STDEVP":a=108;break;case"SUM":a=109;break;case"VAR":a=110;break;case"VARP":a=111;break;default:a=0;break}return a},Xn={complex_numbers:"off",spill:!1},ot=class extends Be{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Xe(this.model,this.library,this.parser),this.options={...Xn,...r},this.options.complex_numbers==="on"){for(let i of Object.keys(At))_e[i]=At[i];Ar()}this.UpdateLocale(),this.library.Register(_e,qr,Qr,jr,Xr,en,tn,rn,nn,an);for(let i of Object.keys(Ot))this.library.Alias(i,Ot[i]);for(let i of Object.keys(Et))this.library.Alias(i,Et[i]);let n=(i,s,...l)=>{Array.isArray(s)||(s=[[s]]);let c=[];for(let b=0;b<l.length;b+=2){let p=l[b];Array.isArray(p)||(p=[[p]]);{let h=o(p,l[b+1]);if(h.type!==9)return h;for(let[f,y]of h.value[0].entries())c[f]=!!y.value&&c[f]!==!1}}let u=F(s,!0),d=0,m=0;for(let[b,p]of c.entries())if(p){d++;let h=u[b];typeof h=="number"&&(m+=h)}switch(i){case"count":return{type:3,value:d};case"sum":return{type:3,value:m};case"average":return d===0?W():{type:3,value:m/d}}},o=(i,s)=>{let l=F(i,!0),c,u,d="=";if(typeof s=="string"){s=s.trim();let b=s.match(/^([=<>]+)/);b&&(d=b[1],s=s.substring(d.length));let p=we.TryParse(s);if(p?.type===2?s=`"${p.value}"`:s=p?.value?.toString()||"",/[?*]/.test(s)){let h=this.parser.argument_separator;if(d==="="||d==="<>"){if(c=this.parser.Parse(`=WildcardMatch({}${h} ${s}${h} ${d==="<>"})`),u=c.expression,c.error||!u)return q();u?.type==="call"&&u.args[0]?.type==="array"&&(u.args[0].values=[Ut(l,!0)])}}}else s=(s||0).toString();if(!c){if(c=this.parser.Parse("{}"+d+s),u=c.expression,c.error||!u)return q();if(u.type!=="binary")return console.warn("invalid expression [1]",u),q();if(u.left.type!=="array")return console.warn("invalid expression [1]",u),q();u.right.type==="identifier"&&(console.warn("will never happen"),u.right={...u.right,type:"literal",value:u.right.name}),u.left.values=[Ut(l,!0)]}return u?this.CalculateExpression(u):k()};this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(i,...s)=>{if(i=qn(i),i>100&&(i-=100),i<1||i>11)return _();let l=O(s),c=[],u=0,d=0,m;for(let p of l){let h=p.value?.address;if(!h)return D();if(!m||m.id!==h.sheet_id){if(!h.sheet_id)return console.warn("invalid reference in metadata"),D();if(m=this.model.sheets.Find(h.sheet_id),!m)return console.warn("invalid sheet in metadata"),D()}if(!m.GetRowHeight(h.row))continue;let y=p.value?.value;typeof y>"u"||(u++,typeof y=="number"&&(d+=y,c.push(y)))}let b=0;switch(i){case 1:if(c.length===0)return W();b=d/c.length;break;case 2:b=c.length;break;case 3:b=u;break;case 4:if(c.length===0)return k();b=Math.max.apply(0,c);break;case 5:if(c.length===0)return k();b=Math.min.apply(0,c);break;case 6:if(c.length===0)return k();b=1;for(let p of c)b*=p;break;case 7:if(c.length<2)return W();b=Math.sqrt(te(c,!0));break;case 8:if(c.length===0)return W();b=Math.sqrt(te(c,!1));break;case 9:b=d;break;case 10:if(c.length<2)return W();b=te(c,!0);break;case 11:if(c.length===0)return W();b=te(c,!1);break}return{type:3,value:b}}},Cell:{description:"Returns data about a cell",arguments:[{name:"type",description:"Type of data to return",unroll:!0},{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:(i,s)=>{if(!$(s))return D();if(i)switch(i.toString().toLowerCase()){case"format":return s.value.format?{type:2,value:s.value.format}:D();case"address":{let l="";return s.value.address.sheet_id&&(l=this.model.sheets.Find(s.value.address.sheet_id)?.name||""),l&&(Ue.test(l)&&(l=`'${l}'`),l+="!"),{type:2,value:"[]"+l+s.value.address.label.replace(/\$/g,"")}}}return{type:7,value:br.error}}},Address:{arguments:[{name:"row"},{name:"column"},{name:"absolute"},{name:"a1"},{name:"sheet name"}],fn:(i=1,s=1,l=1,c=!0,u)=>{let d={type:"address",id:0,position:0,label:"",row:i-1,column:s-1};switch(l){case 2:d.absolute_row=!0;break;case 3:d.absolute_column=!0;break;case 4:break;default:d.absolute_column=!0,d.absolute_row=!0}return u&&(d.sheet=u),Tr(this.parser.Render(d,{r1c1:!c}))}},CountIfs:{arguments:[{name:"range"},{name:"criteria"},{name:"range"},{name:"criteria"}],fn:(...i)=>n("count",i[0],...i)},AverageIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s,l)=>n("average",l||i,i,s)},AverageIfs:{arguments:[{name:"value range"},{name:"criteria range"},{name:"criteria"},{name:"criteria range"},{name:"criteria"}],fn:(i,...s)=>n("average",i,...s)},SumIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s,l)=>n("sum",l||i,i,s)},SumIfs:{arguments:[{name:"value range"},{name:"criteria range"},{name:"criteria"},{name:"criteria range"},{name:"criteria"}],fn:(i,...s)=>n("sum",i,...s)},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s)=>n("count",i,i,s)},Offset:{arguments:[{name:"reference",description:"Base reference",metadata:!0},{name:"rows",description:"number of rows to offset"},{name:"columns",description:"number of columns to offset"},{name:"height"},{name:"width"}],return_type:"reference",volatile:!0,fn:((i,s=0,l=0,c,u)=>{if(!i)return _();if(i.type===9){let m=typeof c=="number"?s+c:void 0,b=typeof u=="number"?l+u:void 0;return{type:9,value:i.value.slice(s,m).map(h=>h.slice(l,b))}}if(!$(i))return console.info("e2",{reference:i}),D();let d=this.DynamicDependencies(i.value.address,this.expression_calculator.context.address,!0,s,l,u,c);if(!d)return console.info("e1",{check_result:d}),D();if(d.dirty){let m=this.GetVertex(this.expression_calculator.context.address,!0);return m.short_circuit=!0,{type:0,value:void 0}}if(d.area){let m={type:"address",...d.area.start,label:"",position:0,id:0},b={type:"address",...d.area.end,label:"",position:0,id:0},p=d.area.count===1?m:{type:"range",start:m,end:b,label:"",position:0,id:0};return{type:5,value:p}}return k()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:"reference",volatile:!0,fn:(i=>{if(!i||typeof i!="string")return _();let s=this.parser.Parse(i);if(s.error||!s.expression||s.expression.type!=="address"&&s.expression.type!=="range")return D();let l=this.DynamicDependencies(s.expression,this.expression_calculator.context.address);if(!l)return D();if(l.dirty){let c=this.GetVertex(this.expression_calculator.context.address,!0);return c.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:s.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(i,s,l=0)=>{if(l)return console.warn("inexact match not supported",{value:i,range:s,type:l}),Y();if(s.type===9){if(s.value.length===1){let c=s.value[0];for(let u=0;u<c.length;u++)if(i.type==c[u].type&&i.value===c[u].value)return{type:3,value:u+1}}else for(let c=0;c<s.value.length;c++){let u=s.value[c];if(u.length!==1)return Y();if(i.type==u[0].type&&i.value===u[0].value)return{type:3,value:c+1}}return Y()}else return i.type===s.type&&i.value===s.value?{type:3,value:1}:Y();return _()}},Index:{return_type:"reference",arguments:[{name:"range",metadata:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(i,s,l)=>{if(!i)return _();if(s===void 0&&l===void 0)return _();s=s||0,l=l||0;let c=[];if(i.type===9)c=i.value;else if(i.type===5){let m=i.value;m.type==="metadata"&&m.address&&c.push([i])}let u=c.length,d=c[0]?.length||0;if(d<=0||u<=0||s>d||l>u||s<0||l<0)return _();if(l===0&&s===0){let m=u===1&&d===1?{...c[0][0].value.address}:{type:"range",start:c[0][0].value.address,end:c[u-1][d-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}if((s||d===1)&&(l||u===1))return{type:5,value:c[l?l-1:0][s?s-1:0].value.address};if(s){let m={type:"range",start:c[0][s-1].value.address,end:c[u-1][s-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}else if(l){let m={type:"range",start:c[l-1][0].value.address,end:c[l-1][d-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}return _()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:i=>{if(!i)return _();if(Array.isArray(i)){let s=i[0];return Array.isArray(s)?{type:3,value:s.length}:k()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:i=>i?Array.isArray(i)?{type:3,value:i.length}:{type:3,value:1}:_()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:i=>{if(!$(i))return D();let s=this.model.sheets.Find(i.value?.address?.sheet_id||0);if(s){let l=s.cells.GetCell(i.value.address,!1);return{type:2,value:l?.value?.toString()||""}}return D()}},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",unroll:!0,metadata:!0}],fn:i=>{let s=i?.value?.address,l=this.model.sheets.Find(s?.sheet_id||0);if(s&&l){let c=l.cells.GetCell(s,!1);return{type:4,value:c?.type===1}}return{type:4,value:!1}}}})}get parser(){return this.model.parser}library=new Ye;registered_libraries={};expression_calculator;full_rebuild_required=!1;options;async_resource_init=!1;grid_expanded=!1;async InitResources(){this.async_resource_init||(this.async_resource_init=!0)}ExportCalculatedValues(){let t={};for(let r of this.model.sheets.list){let n=r.cells.toJSON({calculated_value:!0}).data;t[r.id]=n.filter(o=>o.calculated!==void 0)}return t}ApplyCalculatedValues(t){for(let r of this.model.sheets.list){let n=t[r.id];if(!n)console.info("mismatch",r.id);else for(let o of n)r.cells.data[o.row][o.column].SetCalculatedValue(o.calculated)}}AttachSpillData(t,r){if(r||(r=(t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):void 0)?.cells),!r)throw console.info({area:t,cells:r}),new Error("invalid sheet ID in attach spill data");let n=new ke,o=0,i=!1;for(let{cell:s,row:l,column:c}of r.IterateRC(t,!0))o++&&(s.type!==0||s.area||s.merge_area||s.table)&&(i=!0),this.AddLeafVertexEdge({row:l,column:c,sheet_id:t.start.sheet_id},n);return this.spill_data.push({area:t,vertex:n}),{vertex:n,area:t,error:i}}SpillCallback(t,r){let{reference:n,address:o}=t,{value:i}=r,s=[];if(!n)return console.error("invalid reference in spill callback"),s;if(!o||!o.sheet_id)return console.error("invalid address in spill callback"),s;if(i.length===1&&i[0].length===1||!this.options.spill)return n.SetCalculatedValue(i[0][0].value),s;let l=this.model.sheets.Find(o.sheet_id),c=l?.cells;if(c){let u=r.value.length,d=r.value[0].length,m=new z(o).Reshape(d,u),{error:b}=this.AttachSpillData(m,c);if(b)return n.SetCalculationError("SPILL"),s;l.rows<m.end.row+1&&(l.cells.EnsureRow(m.end.row+1),this.grid_expanded=!0),l.columns<m.end.column+1&&(l.cells.EnsureColumn(m.end.column+1),this.grid_expanded=!0);let p=o.sheet_id;for(let{row:h,column:f}of c.IterateRC(m)){if(h===o.row&&f===o.column)continue;let y=this.GetVertex({sheet_id:p,row:h,column:f},!1);y&&(y.dirty||s.push(y))}for(let{cell:h,row:f,column:y}of c.IterateRC(m)){h.spill=m,f-=o.row,y-=o.column;let x=r.value[y][f];switch(x.type){case 5:case 9:case 6:break;default:h.SetCalculatedValue(x.value,x.type);break}}return s}return console.error("invalid cell reference in spill callback"),n.SetCalculationError("SPILL"),[]}SpreadCallback(t,r){if(!t.address||!t.address.sheet_id)throw new Error("spread callback called without sheet id");let n=this.model.sheets.Find(t.address.sheet_id)?.cells;if(!n)throw new Error("spread callback called without cells");if(!t||!t.reference)return;let o=t.reference.area;if(o){let i=o.rows,s=o.columns;if(r.type===9){let l=We(r.value);for(let c=0;c<i;c++)if(l[c]){let u=0;for(;u<s&&u<l[c].length;u++){let d=l[c][u];switch(d.type===9&&(d=d.value[0][0]),d.type){case 9:case 5:case 6:n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0);break;default:n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(d.value,d.type)}}for(;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0,0)}else for(let u=0;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0,0)}else{let l={...r};(l.type===5||l.type===6)&&(l={type:0,value:void 0});for(let c=0;c<i;c++)for(let u=0;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(l.value,l.type)}}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:Oe()}:this.expression_calculator.Calculate(t.expression,t.address,t.reference?.area)}DynamicDependencies(t,r,n=!1,o=0,i=0,s=1,l=1){let c=this.ResolveExpressionAddress(t,r);if(!c)return;let u=!1,d;if(t.type==="address"||t.type==="range"){let b=t.type==="range"?t.start:t;b.sheet_id?d=this.model.sheets.Find(b.sheet_id):b.sheet&&(d=this.model.sheets.Find(b.sheet))}if(!d&&r?.sheet_id&&(d=this.model.sheets.Find(r.sheet_id)),!d)throw new Error("missing sheet in dynamic dependencies [b21]");c=d.RealArea(c);let m=c.start.sheet_id;n&&(c=new z({column:c.start.column+i,row:c.start.row+o,sheet_id:c.start.sheet_id},{column:c.start.column+i+s-1,row:c.start.row+o+l-1,sheet_id:c.end.sheet_id}));for(let b=c.start.row;b<=c.end.row;b++)for(let p=c.start.column;p<=c.end.column;p++){let h=this.GetVertex({row:b,column:p,sheet_id:m},!1);h&&h.dirty&&(this.AddEdge({row:b,column:p,sheet_id:m},this.expression_calculator.context.address),u=!0)}return{dirty:u,area:c}}UpdateLocale(){ee.decimal_separator===","?this.parser.SetLocaleSettings(","):this.parser.SetLocaleSettings(".")}SupportedFunctions(){let t=this.library.List(),r=Object.keys(t).map(n=>{let o=t[n].canonical_name;return o||(o=n.replace(/_/g,".")),{name:o,description:t[n].description,arguments:(t[n].arguments||[]).map(i=>({name:i.name||""})),type:"function"}});for(let n of this.model.macro_functions.values())r.push({name:n.name,description:n.description,arguments:(n.argument_names||[]).map(o=>({name:o})),type:"function"});return r}RegisterLibrary(t,r){return this.registered_libraries[t]?!1:(this.RegisterFunction(r),this.registered_libraries[t]=!0,!0)}RegisterFunction(t){for(let r of Object.keys(t)){let n=t[r];this.library.Register({[r]:n})}}Calculate(t){if(t&&!t.start.sheet_id)throw new Error("CalculateInternal called with subset w/out sheet ID");this.full_rebuild_required&&(t=void 0,this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.full_rebuild_required=!1),this.RebuildGraph(t),this.grid_expanded=!1;try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let n of Object.keys(r)){let o=r[n];o.xlfn?t[n]="_xlfn":o.extension&&(t[n]="_xll")}return t}Evaluate(t,r,n={},o=!1){let i=n?.preparsed;if(!i){this.parser.Save(),n.argument_separator&&(n.argument_separator===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",")),n.r1c1&&(this.parser.flags.r1c1=n.r1c1);let s=this.parser.Parse(t);if(this.parser.Restore(),i=s.expression,s.error)throw new Error(s.error)}if(i){this.parser.Walk(i,l=>{if(l.type==="address"||l.type==="range"){if(l.type==="address"){if(l.offset_column||l.offset_row)throw new Error("Evaluate does not support offset references")}else if(l.start.offset_column||l.start.offset_row||l.end.offset_column||l.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(l,void 0,r)}return!0});let s=this.CalculateExpression(i,n.address);return o?s:s.type===9?s.value.map(l=>l.map(c=>c.value)):s.value}throw new Error("invalid expression")}CalculateExpression(t,r={row:-1,column:-1},n=!1){return this.expression_calculator.Calculate(t,r,void 0,n).value}RebuildClean(t=!1){this.full_rebuild_required=!1,this.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},n=[];for(let o of t){let i={column:o.column,row:o.row,sheet_id:o.sheet_id},s=z.CellAddressToLabel(i,!0);r[s]||(r[s]=s,n.push(i))}return n}Unresolve(t,r,n=!0,o=!0){let i="",s=K(t)?new z(t):new z(t.start,t.end);if(o){let u=this.model.named.MatchSelection(s);if(u)return u}if(i=s.spreadsheet_label,!n)return i;let l=s.start.sheet_id||r?.id,c=this.ResolveSheetName(l,!0);return c?c+"!"+i:i}ResolveSheetName(t,r=!1){let n=this.model.sheets.Find(t);if(n)return r&&Ue.test(n.name)?`'${n.name}'`:n.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}RemoveConnectedELement(t){let r=t.internal;return r?.vertex?(this.RemoveLeafVertex(r.vertex),!0):!1}UpdateConnectedElements(t,r){if(t||(t=this.model.sheets.list[0]),r){let o=r.internal;o?.vertex&&this.RemoveLeafVertex(o.vertex)}let n=r?[r]:this.model.connected_elements.values();for(let o of n){let i=o.internal;i||(i={vertex:new ke},o.internal=i);let s=i.vertex;this.AddLeafVertex(s),this.UpdateLeafVertex(s,o.formula,t)}}UpdateConditionals(t,r){if(!t){for(let n of this.model.sheets.list)n.conditional_formats?.length&&this.UpdateConditionals(n.conditional_formats,n);return}if(!r)throw new Error("invalid call to update conditionals without context");t&&!Array.isArray(t)&&(t=[t]);for(let n of t){let o="";switch(n.type){case"cell-match":n.between?o=`BETWEEN(${[this.Unresolve(n.area,r,!0,!1),...n.between].join(", ")})`:o=this.Unresolve(n.area,r,!0,!1)+" "+n.expression;break;case"expression":o=n.expression;break;case"duplicate-values":o=`UniqueValues(${this.Unresolve(n.area,r,!0,!1)})`,n.unique||(o=`NOT(${o})`);break;case"data-bar":case"gradient":o=`=Gradient(${[this.Unresolve(n.area,r,!0,!1),n.min??"",n.max??"",...n.type==="data-bar"?["TRUE"]:[]].join(",")})`;break;default:continue}if(!o)continue;if(n.internal||(n.internal={}),!n.internal.vertex){let s=new at;s.use="conditional",n.internal.vertex=s;let l={argument_separator:","};n.type!=="gradient"&&n.type!=="duplicate-values"&&n.type!=="data-bar"&&(l={...n.options,...l});let c=this.Evaluate(o,r,l,!0);n.internal.vertex.result=c,n.internal.vertex.updated=!0}let i=n.internal.vertex;this.AddLeafVertex(i),this.UpdateLeafVertex(i,o,r,".")}}RemoveAnnotation(t){let r=t.temp;r.vertex&&(r.vertex.Reset(),this.RemoveLeafVertex(r.vertex))}UpdateAnnotations(t,r){if(!t){for(let n of this.model.sheets.list)this.UpdateAnnotations(n.annotations,n);return}if(!r)throw new Error("invalid call to UpdateAnnotations with list but no sheet");typeof t<"u"&&!Array.isArray(t)&&(t=[t]);for(let n of t)if(n.data.formula){let o=n.temp;o.vertex||(o.vertex=new ke),this.AddLeafVertex(o.vertex),this.UpdateLeafVertex(o.vertex,n.data.formula,r)}}ResolveExpressionAddress(t,r){switch(t.type){case"address":if(this.model.ResolveSheetID(t,r))return new z(t);break;case"range":if(this.model.ResolveSheetID(t,r))return new z(t.start,t.end);break;case"identifier":{let n=this.model.GetName(t.name,r?.sheet_id||0);if(n&&n.type==="range")return new z(n.area.start,n.area.end)}break}}NamedRangeToAddressUnit(t,r){let n=t.name.toUpperCase(),o=this.model.GetName(n,r.sheet_id||0);if(o&&o.type==="range")return o.area.count===1?this.ConstructAddressUnit(o.area.start,n,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(o.area.start,n,t.id,t.position),end:this.ConstructAddressUnit(o.area.end,n,t.id,t.position),label:n,id:t.id,position:t.position}}ConstructAddressUnit(t,r,n,o){return{type:"address",row:t.row,column:t.column,sheet_id:t.sheet_id,label:r,id:n,position:o}}RebuildDependencies(t,r,n,o={addresses:{},ranges:{}},i){if(!n){let s=this.model.sheets.Find(r);s&&(n=s.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let s=this.model.GetName(t.name,i.sheet_id||0);if(s?.type==="expression")this.RebuildDependencies(s.expression,r,n,o,i);else{let l=this.NamedRangeToAddressUnit(t,i);l&&(l.type==="address"?o.addresses[l.label]=l:o.ranges[l.label]=l)}}break;case"structured-reference":{let s=this.model.ResolveStructuredReference(t,i);s&&(s.type==="address"?o.addresses[s.sheet_id+"!"+s.label]=s:o.ranges[s.label]=s);let l=this.model.tables.get(t.table.toLowerCase());if(l){let c=i.row;if(c<l.area.start.row||c>l.area.end.row)break;let u=t.column.toLowerCase(),d=-1;if(l.columns){for(let m=0;m<l.columns.length;m++)if(u===l.columns[m]){d=l.area.start.column+m;break}}if(d>=0){let m={label:t.label,type:"address",row:c,column:d,sheet_id:l.area.start.sheet_id,id:t.id,position:t.position};o.addresses[m.sheet_id+"!"+m.label]=m}}}break;case"address":if(!t.sheet_id)if(t.sheet){let s=this.model.sheets.Find(t.sheet);s&&(t.sheet_id=s.id)}else t.sheet_id=r,t.sheet=n;t.sheet_id?o.addresses[t.sheet_id+"!"+t.label]=t:console.warn("invalid address in range [9d]");break;case"range":if(!t.start.sheet_id)if(t.start.sheet){let s=this.model.sheets.Find(t.start.sheet);s&&(t.start.sheet_id=s.id)}else t.start.sheet_id=r,t.start.sheet=n;t.start.sheet_id?o.ranges[t.start.sheet_id+"!"+t.start.label+":"+t.end.label]=t:console.warn("invalid sheet in range",t);break;case"unary":this.RebuildDependencies(t.operand,r,n,o,i);break;case"binary":this.RebuildDependencies(t.left,r,n,o,i),this.RebuildDependencies(t.right,r,n,o,i);break;case"group":t.elements.forEach(s=>this.RebuildDependencies(s,r,n,o,i));break;case"implicit-call":{for(let s of t.args)this.RebuildDependencies(s,r,n,o,i);this.RebuildDependencies(t.call,r,n,o,i)}break;case"call":{let s=t.args.slice(0),l=this.library.Get(t.name);l&&l.arguments&&l.arguments.forEach((c,u)=>{c&&c.address&&(this.RebuildDependencies(s[u],r,n,void 0,i),s[u]={type:"missing",id:-1})}),s.forEach(c=>this.RebuildDependencies(c,r,n,o,i))}break}return o}UpdateLeafVertex(t,r,n,o){t.Reset(),o&&(this.parser.Save(),this.parser.SetLocaleSettings(o));let i=this.parser.Parse(r);if(i.expression){let s=this.RebuildDependencies(i.expression,n.id,n.name,void 0,{row:0,column:0});for(let l of Object.keys(s.ranges)){let c=s.ranges[l],u=new z(c.start,c.end);u.entire_column||u.entire_row||u.count>1?this.AddLeafVertexArrayEdge(u,t):this.AddLeafVertexEdge(u.start,t)}for(let l of Object.keys(s.addresses)){let c=s.addresses[l];this.AddLeafVertexEdge(c,t)}}t.expression=i.expression||{type:"missing",id:-1},t.expression_error=!i.valid,o&&this.parser.Restore()}RebuildGraphCell(t,r){if(t.spill&&this.options.spill&&(t.spill.start.row===r.row&&t.spill.start.column===r.column?this.AttachSpillData(new z(t.spill.start,t.spill.end)):this.AddEdge(t.spill.start,r)),t.area&&t.area.start.column===r.column&&t.area.start.row===r.row){let{start:n,end:o}=t.area,i=n.sheet_id||r.sheet_id;n.sheet_id||(n.sheet_id=i);for(let s=n.column;s<=o.column;s++)for(let l=n.row;l<=o.row;l++)this.ResetInbound({column:s,row:l,sheet_id:i},!0,!1);this.SetDirty(r);for(let s=n.column;s<=o.column;s++)for(let l=n.row;l<=o.row;l++)l===n.row&&s===n.column||this.AddEdge(n,{...n,row:l,column:s})}if(t.type===1){this.ResetInbound(r,!0);let n=this.parser.Parse(t.value);if(n.expression){let i,s=n.expression;for(s?.type==="implicit-call"?s.call.type==="call"&&(s=s.call):s?.type==="call"&&(i=this.library.Get(s.name),i?.pass_through_ui==="indirect"&&(s=void 0));s?.type==="call";)if(i=this.library.Get(s.name),i)if(i.pass_through_ui&&s.args.length)s=s.args[s.args.length-1];else break;else{let c=this.model.GetName(s.name,r.sheet_id);if(c?.type==="expression")s=c.expression;else break}i&&(t.render_function=i.render,t.click_function=i.click);let l=this.RebuildDependencies(n.expression,r.sheet_id,"",void 0,r);for(let c of Object.keys(l.ranges)){let u=l.ranges[c],d=new z(u.start,u.end);if(d.entire_row||d.entire_column)this.AddArrayEdge(d,r);else for(let m of d)this.AddEdge(m,r)}for(let c of Object.keys(l.addresses)){let u=l.addresses[c];this.AddEdge(u,r)}}let o=this.GetVertex(r,!0);o&&(o.expression=n.expression||{type:"missing",id:-1},o.expression_error=!n.valid)}else t.value!==t.calculated?this.ResetInbound(r,!0,!1):t.type===0&&this.ResetInbound(r,!0,!1,!0)}RebuildGraph(t){if(t){if(!t.start.sheet_id)throw new Error("subset missing sheet id");let r=this.model.sheets.Find(t.start.sheet_id)?.cells;if(r)for(let n=t.start.row;n<=t.end.row;n++){let o=r.data[n];if(o)for(let i=t.start.column;i<=t.end.column;i++){let s=o[i];s&&this.RebuildGraphCell(s,{row:n,column:i,sheet_id:t.start.sheet_id})}}}else for(let r of this.model.sheets.list||[]){let n=r.cells.data.length;for(let o=0;o<n;o++){let i=r.cells.data[o];if(i){let s=i.length;for(let l=0;l<s;l++){let c=i[l];c&&this.RebuildGraphCell(c,{row:o,column:l,sheet_id:r.id})}}}}}CheckVolatile(t){if(!t.expression||t.expression_error)return!1;let r=!1;return this.parser.Walk(t.expression,n=>{if(n.type==="call"){let o=this.library.Get(n.name);o&&o.volatile&&(r=!0)}return!r}),r}};var it=class{model={};layout_element;visible_=!1;timeout=0;pending_dialog_resoltion=[];options_={type:"initial"};set options(e){if(e.type==="about"&&(e.close_box=!0,e.icon=!0),this.options_.icon!==e.icon&&(this.model.left.style.display=e.icon?"block":"none"),this.options_.close_box!==e.close_box&&(this.model.close.style.display=e.close_box?"block":"none"),this.options_.message!==e.message&&(this.model.message.textContent=e.message||"",this.model.message.style.display=e.message?"block":"none"),this.options_.title!==e.title&&(this.model.title.textContent=e.title||"",this.model.title.style.display=e.title?"block":"none"),this.options_.type!==e.type){let t=this.model.dialog.className.replace(/dialog-type-\S+/g,"").trim();e.type&&(t+=` dialog-type-${e.type}`),this.model.dialog.className=t,e.type==="about"?this.model.about.style.display="block":this.model.about.style.display="none"}this.options_=e}event_handler=e=>{(e.key==="Escape"||e.key==="Esc")&&(e.stopPropagation(),e.preventDefault(),this.visible=!1)};get visible(){return this.visible_}set visible(e){if(e!==this.visible_)if(this.visible_=e,e)this.layout_element?.setAttribute("dialog",""),window.addEventListener("keydown",this.event_handler);else{this.layout_element?.removeAttribute("dialog"),window.removeEventListener("keydown",this.event_handler);let t=this.pending_dialog_resoltion.slice(0);this.pending_dialog_resoltion=[],Promise.resolve().then(()=>{for(let r of t)r()})}}constructor(e){this.layout_element=e.parentElement;let t=this.layout_element?.querySelector(".treb-dialog-mask");if(t){let r=t.querySelectorAll("[data-bind]");for(let n of Array.from(r)){let o=n.dataset.bind;o&&(this.model[o]=n)}}if(this.model.about){let r=["<div>TREB version 36.1.2"];r.push("<small><a target=_blank href='https://treb.app'>http://treb.app</a></small>"),this.model.about.innerHTML=r.join(`
3
- `)}this.model.close?.addEventListener("click",r=>{r.stopPropagation(),r.preventDefault(),this.HideDialog()})}Node(e){return this.model[e]}Update(e,t=!0){t&&(e={...this.options_,...e}),this.options=e}HideDialog(){this.visible=!1}ShowDialog(e){return new Promise(t=>{this.pending_dialog_resoltion.push(t),this.options=e,this.visible=!0,this.timeout&&(window.clearTimeout(this.timeout),this.timeout=0),e.timeout&&(this.timeout=window.setTimeout(()=>this.HideDialog(),e.timeout))})}};var st=class{constructor(e){this.container=e;let t=le.GetInstance(e.ownerDocument);this.node=t.Div("treb-spinner",e,{html:"<div><div></div><div></div><div></div><div></div></div>"})}node;visible=!1;Show(){this.node.classList.add("visible")}Hide(){this.node.classList.remove("visible")}};var on={formula_bar:!0,in_cell_editor:!0,undo:!0,scrollbars:!0,headers:!0,export:!0,tab_bar:"auto",resizable:!0,hyperlinks:"_blank",max_file_size:94208,tint_theme_colors:!0,dnd:!1,add_tab:!1,expand_formula_button:!1,expand:!0,markdown:!1,spinner:!1,complex:"off",spill:!0};var Z=a=>!!a&&typeof a=="object"&&a.key==="metadata"&&!!a.value&&a.value.type==="metadata",Nt=a=>!!a&&typeof a=="object"&&a.key==="series"&&typeof a.value=="object",sn=a=>!!a&&typeof a=="object"&&a.type===9&&Array.isArray(a.value);var E=class{static Scale(e,t,r=6.5,n,o){return or(e,t,r,n,o)}static Range(e){let t,r;for(let o of e)typeof o>"u"||((typeof t>"u"||t>o)&&(t=o),(typeof r>"u"||r<o)&&(r=o));let n=typeof t>"u"||typeof r>"u"?0:r-t;return{min:t,max:r,range:n}}static ApplyScale(e,t,r){return t*(e-r.min)/(r.max-r.min)}static Flatten(e){let t=[];if(Array.isArray(e))for(let r of e)Array.isArray(r)?t=t.concat(this.Flatten(r)):t.push(r);else typeof e<"u"&&t.push(e);return t}};var cn=a=>{Bt(a,0,a.length)},Wn=(a,e,t)=>{let r=a[t-1],n=e;for(let o=e;o<t-1;o+=1)a[o]<=r&&(ln(a,o,n),n+=1);return ln(a,n,t-1),n},ln=(a,e,t)=>{let r=a[e];a[e]=a[t],a[t]=r},Bt=(a,e,t)=>{if(e<t){let r=Wn(a,e,t);Bt(a,e,r),Bt(a,r+1,t)}};var $t="#,##0.00",Se=a=>{let e=a[0],t=a[0];for(let r of a)r<e&&(e=r),r>t&&(t=r);return{min:e,max:t}},un=a=>{let{label:e,x:t,y:r,z:n,index:o,subtype:i,data_labels:s,axis:l}=a,c={x:{data:[]},y:{data:[]}};if(typeof l=="number"&&(c.axis=l),typeof o=="number"&&(c.index=o),i&&(c.subtype=i.toString()),s){let m=E.Flatten(Array.isArray(s)?s:[s]);c.labels=m.map(b=>typeof b>"u"?"":b.toString())}e&&(c.label=e.toString());let u=(m,b=!1)=>{let p;if(Z(m)&&(m={type:9,value:[[m]]}),sn(m)){p={data:[]};let h=E.Flatten(m.value);if(p.data=h.map(f=>{if(Z(f)){if(typeof f.value.value=="number")return f.value.value}else if(f.type===3)return f.value}),Z(h[0])&&h[0].value?.format&&(p.format=h[0].value.format,b)){let f=R.Get(p.format);p.labels=p.data.map(y=>y===void 0?void 0:f.Format(y))}}return p};c.y=u(r,!0)||{data:[]},c.x=u(t)||{data:[]},c.z=u(n);let d=[c.x,c.y];for(let m of d)if(m.data.length){let b=m.data.filter(p=>p||p===0);m.range=Se(b)}return c},dn=a=>{let e={x:{data:[]},y:{data:[]}},t=E.Flatten(a.value),r=[];for(let[o,i]of t.entries()){let s=0;if(typeof i.value=="number")s=i.value,r.push(i.value);else if(Z(i))if(X(i.value.value))e.x.data[o]=i.value.value.real,s=i.value.value.imaginary;else if(typeof i.value.value=="number")s=i.value.value;else continue;else continue;e.y.data[o]=s,r.push(s)}let n="";if(Z(t[0])&&(n=t[0].value.format||""),n){e.y.format=n;let o=R.Get(e.y.format||"");e.y.labels=e.y.data.map(i=>i===void 0?void 0:o.Format(i))}if(e.y.range=Se(r),e.x.data.length){let o=e.x.data.filter(i=>typeof i=="number");if(e.x.range=Se(o),n){e.x.format=n;let i=R.Get(e.x.format||"");e.x.labels=e.x.data.map(s=>s===void 0?void 0:i.Format(s))}}return e},Ie=(a,e)=>{if(!a)return[];let t=[];if(a.type===5){if(a.key==="group"){if(Array.isArray(a.value)){for(let[o,i]of a.value.entries())if(i&&typeof i=="object")if(Nt(i)){let s=un(i.value);typeof s.index>"u"&&(s.index=o+1),t.push(s)}else i.type===9&&t.push(dn(i))}}else if(Nt(a)){let o=un(a.value);t.push(o)}}else a.type===9&&t.push(dn(a));let r,n=0;if(e?.type===9){let o=E.Flatten(e.value),i="0.00###";Z(o[0])&&o[0].value.format&&(i=o[0].value.format);let s=o.map(c=>{if(c.type===3)return c.value;if(Z(c)&&typeof c.value.value=="number")return c.value.value}),l=s.filter(c=>typeof c=="number");r={data:s,format:i,range:Se(l)}}for(let o of t)n=Math.max(n,o.y.data.length),o.x.data.length&&(r||(r=o.x));if(!r){r={data:[],range:{min:0,max:Math.max(0,n-1)}};for(let o=0;o<n;o++)r.data.push(o)}for(let o of t)o.x.data.length||(o.x=r);return t},mn=a=>{let e=Math.abs(a.step)%1;if(e){if(Math.log10(Math.abs(e))<-4)return"Scientific";let r=0;for(let o=0;o<a.count;o++){let i=((a.min+a.step*o)%1).toFixed(6).replace(/0+$/,"");r=Math.max(r,i.length-2)}let n="#,##0.";for(let o=0;o<r;o++)n+="0";return n}else return Math.log10(Math.abs(a.step))>=5?"Scientific":"#,##0"},Me=(a,e,t,r,n,o)=>{let i="",s="",l="";for(let M of a)M.axis?M.y.format&&!l&&(l=M.y.format):M.y.format&&!s&&(s=M.y.format),M.x.format&&!i&&(i=M.x.format);let c;a.some(M=>M.label&&M.label.length>0)&&(c=a.map((M,A)=>({label:M.label||`Series ${A+1}`,index:typeof M.index=="number"?M.index:A+1})));let u=a.filter(M=>M.x.range),d=Math.min.apply(0,u.map(M=>M.x.range?.min||0)),m=Math.max.apply(0,u.map(M=>M.x.range?.max||0)),b=u.filter(M=>!M.axis),p=u.filter(M=>M.axis),h=Math.min.apply(0,b.map(M=>M.y.range?.min||0)),f=Math.max.apply(0,b.map(M=>M.y.range?.max||0)),y=-1,x=-1;p.length&&(y=Math.min.apply(0,p.map(M=>M.y.range?.min||0)),x=Math.max.apply(0,p.map(M=>M.y.range?.max||0)));for(let M of a)if(M.z){for(let[A,G]of M.z.data.entries())if(typeof G<"u"){let j=M.x.data[A],se=Math.max(0,G/2);typeof j<"u"&&(d=Math.min(d,j-se),m=Math.max(m,j+se));let de=M.y.data[A];typeof de<"u"&&(h=Math.min(h,de-se),f=Math.max(f,de+se))}}typeof r<"u"&&(d=Math.min(d,r)),typeof n<"u"&&(d=Math.max(d,n)),typeof e<"u"&&(h=Math.min(h,e)),typeof t<"u"&&(f=Math.max(f,t));let v=E.Scale(d,m,7),w=E.Scale(h,f,7),g=E.Scale(y,x,7);if(y!==x&&w&&g&&w.count!==g.count){let M=Math.max(w.count,g.count),A=w.count<M?w:g;for(let G=A.count;G<M;G+=2)A.max+=A.step,A.count++,A.count<M&&(A.min-=A.step,A.count++)}let C,U,V;if(i){C=[];let M=R.Get(i);for(let A=0;A<=v.count;A++)C.push(M.Format(v.min+A*v.step))}if(!s&&o&&(s=mn(w)),!l&&o&&(l=mn(g)),s){U=[];let M=R.Get(s);for(let A=0;A<=w.count;A++)U.push(M.Format(w.min+A*w.step))}if(l){V=[];let M=R.Get(l);for(let A=0;A<=g.count;A++)V.push(M.Format(g.min+A*g.step))}let L={x:{format:i,scale:v,labels:C},y:{format:s,scale:w,labels:U},legend:c};return y!==x&&(L.y2={format:l,scale:g,labels:V}),L},lt=(a,e,t)=>{for(let r of a){let n={x:R.Get(r.x.format||""),y:R.Get(r.y.format||"")};r.y.labels=[];for(let o=0;o<r.y.data.length;o++){let i=t?t[o]:typeof r.x.data[o]=="number"?n.x.Format(r.x.data[o]):"",s=typeof r.y.data[o]=="number"?n.y.Format(r.y.data[o]):"";r.y.labels[o]=e.replace(/\bx\b/g,i).replace(/\by\b/g,s)}}},Yn=a=>{let e=(s,l=0,c=s.length)=>c%2?s[Math.floor(c/2)+l]:(s[c/2+l]+s[c/2-1+l])/2,t=a.length,r=[0,e(a),0];if(t%2){let s=Math.floor(t/2);r[0]=e(a,0,Math.ceil(t/2)),r[2]=e(a,s,a.length-s)}else r[0]=e(a,0,t/2),r[2]=e(a,t/2,a.length-t/2);let n=r[2]-r[0],o=[0,0],i=0;for(let s=0;s<t;s++)i+=a[s];for(let s=0;s<t;s++){let l=a[s];if(l>=r[0]-n*1.5){o[0]=l;break}}for(let s=t-1;s>=0;s--){let l=a[s];if(l<=r[2]+n*1.5){o[1]=l;break}}return{data:a,quartiles:r,whiskers:o,iqr:n,n:t,mean:t?i/t:0,min:a[0],max:a[t-1]}},bn=a=>{let e=Ie(a[0]),t=Me(e,void 0,void 0,void 0,void 0,!0),r=0,n=!!a[2],o=e.map(d=>{let m=[];for(let p of d.y.data)p!==void 0&&m.push(p);cn(m);let b=Yn(m);return r=Math.max(r,b.n),n&&(b.whiskers[0]=b.min,b.whiskers[1]=b.max),b}),i=a[1]?.toString()||void 0,s=[],l=[],c=R.Get("#,##0");for(let[d,m]of o.entries()){s.push(c.Format(m.n));let b=e[d];l.push(b.label||`Series ${d+1}`)}return{type:"box",series:e,title:i,max_n:r,data:o,x_labels:s,series_names:e.some(d=>!!d.label)?l:void 0,scale:t.y.scale,y_labels:t.y.labels}},pn=a=>{let e=Ie(a[0]),t,r;for(let s of e)typeof s.x.range?.min=="number"&&s.x.range.min>0&&s.x.range.min<50&&(r=0),typeof s.y.range?.min=="number"&&s.y.range.min>0&&s.y.range.min<50&&(t=0);let n=Me(e,t,void 0,r),o=a[1]?.toString()||void 0;return{legend:n.legend,legend_style:2,type:"bubble",series:e,title:o,x_scale:n.x.scale,x_labels:n.x.labels,y_scale:n.y.scale,y_labels:n.y.labels}},Gt=(a,e="plot")=>{let t=Ie(a[0]),r=Me(t),n=a[1]?.toString()||void 0,o=a[2]?.toString()||void 0,i={legend:r.legend,style:e,type:"scatter2",series:t,title:n,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,y2_scale:r.y2?.scale,y2_labels:r.y2?.labels,lines:e==="line",points:e==="plot"};if(o){i.markers=/marker/i.test(o),i.smooth=/smooth/i.test(o),i.data_labels=/labels/i.test(o);let s=o.match(/labels="(.*?)"/);s&&i.series?lt(i.series,s[1]):(s=o.match(/labels=([^\s\r\n,]+)(?:\W|$)/),s&&i.series&&lt(i.series,s[1])),s=o.match(/class=([\w_-]+)(?:\W|$)/),s&&(i.class_name=s[1])}return i},jt=(a,e)=>{let[t,r,n,o]=a,i=o?.toString()||void 0,s=/stacked/i.test(i||""),l=Ie(t),c=Me(l),u;if(r){u=(r.type===9?E.Flatten(r.value):E.Flatten(r)).map(y=>!y||!y.value?"":Z(y)?typeof y.value.value=="number"?R.Get(y.value.format||$t).Format(y.value.value):y.value.value?.toString()||"":typeof y.value=="number"?R.Get($t).Format(y.value):y.value.toString());let f=l.reduce((y,x)=>Math.max(y,x.y.data.length),0);for(f<u.length&&(u=u.slice(0,f));f>u.length;)u.push("")}let d,m=c.legend;if(s){d=l;let h=new Map;for(let x of l)for(let[v,w]of x.x.data.entries())if(w!==void 0){let g=x.y.data[v]||0;h.set(w,g+(h.get(w)||0))}let f=Array.from(h.keys()).sort((x,v)=>x-v),y=f.map(x=>h.get(x)||0);l=[{x:{data:f,format:d[0]?.x?.format},y:{data:y,format:d[0]?.y?.format}}],l[0].x.range=Se(f),l[0].y.range=Se(y),c=Me(l,Math.min(0,...y))}let b=n?.toString()||void 0,p={type:e,legend:m,legend_style:1,series2:l,stacked_series:d,scale:c.y.scale,title:b,y_labels:e==="bar"?u:c.y.labels,x_labels:e==="bar"?c.y.labels:u};if(i){p.stacked=s,p.round=/round/i.test(i),p.data_labels=/labels/i.test(i);let h=i.match(/labels="(.*?)"/);h&&l?lt(l,h[1],u):(h=i.match(/labels=([^\s\r\n,]+)(?:\W|$)/),h&&l&&lt(l,h[1],u)),h=i.match(/class=([\w_-]+)(?:\W|$)/),h&&(p.class_name=h[1])}return p},qt=(a,e)=>{let t=Ie(a[0],a[1]),r=Me(t,0,0),n=a[2]?.toString()||void 0,o=a[3]?.toString()||void 0,i={legend:r.legend,type:"scatter2",series:t,title:n,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:!0,filled:e==="area"};if(o){i.smooth=/smooth/i.test(o);let s=o.match(/class=([\w_-]+)(?:\W|$)/);s&&(i.class_name=s[1])}return i},hn=(a,e=!1)=>{let[t,r,n,o,i]=a,s=a[0]?.type===9?a[0].value:a[0],l=s?E.Flatten(s):[],c=l.map(g=>{if(Z(g)&&typeof g.value.value=="number")return g.value.value}),u=a[1]?.type===9?a[1].value:a[1],d=E.Flatten(u||[]).map(g=>Z(g)?typeof g.value.value=="number"&&g.value.format?R.Get(g.value.format).Format(g.value.value):g.value.value?.toString()||"":g.value?.toString()||""),m=!1;c=c.map(g=>g&&g<0?(m||(console.warn("pie/donut chart does not support negative values (omitted)"),m=!0),0):g);let b=0,p=c.map((g,C)=>(typeof g<"u"&&(b+=g),{value:g||0,label:d[C]||"",index:C+1,percent:0}));if(b)for(let g of p)g.percent=(g.value||0)/b;let h="";for(let g of l)if(Z(g)){h=g.value.format||"";break}let f=R.Get(h||$t),y=R.Get("percent");typeof a[4]>"u"&&a[1]&&(a[4]="label");let x=a[4]||"";if(x)for(let g of p){let C=f.Format(g.value||0),U=y.Format(g.percent);g.title=x.replace(/value%/ig,y.Format(g.value||0)).replace(/value/ig,C).replace(/percent/ig,U).replace(/label/ig,g.label||"").trim()}let v=(o||"").toUpperCase();if(v==="ASC"||v==="ASCENDING"||v==="INC")p.sort((g,C)=>(g.value||0)-(C.value||0));else if(v==="DESC"||v==="DESCENDING"||v==="DEC")p.sort((g,C)=>(C.value||0)-(g.value||0));else{let g=(o||"").match(/sort=([\w]+)(?:\W|$)/i);g&&(v=g[1],/^(asc|inc)/i.test(v)?p.sort((C,U)=>(C.value||0)-(U.value||0)):/^(desc|dec)/i.test(v)&&p.sort((C,U)=>(U.value||0)-(C.value||0)))}let w={type:e?"pie":"donut",slices:p,title:n||""};if(o){let g=o.match(/class=([_-\w]+)(?:\W|$)/);g&&(w.class_name=g[1])}return w};var re=class{constructor(e=0,t=0,r=100,n=100){this.left=e;this.top=t;this.right=r;this.bottom=n}get width(){return this.right-this.left}get height(){return this.bottom-this.top}get center(){return{x:this.left+this.width/2,y:this.top+this.height/2}}};var ea="http://www.w3.org/2000/svg",S=(a,e={},t)=>{let r=document.createElementNS(ea,a);for(let n of Object.keys(e))if(e[n]!==void 0){let o=e[n]??"";r.setAttribute(n,Array.isArray(o)?o.join(" "):o.toString())}return t&&(r.textContent=t),r},ct=class{parent;svg_node;text_measurement_node;container_group;group;axis_group;label_group;size={width:0,height:0};bounds=new re;constructor(){this.container_group=S("g"),this.group=S("g"),this.axis_group=S("g",{class:"axis-group"}),this.label_group=S("g",{class:"label-group"}),this.container_group.appendChild(this.axis_group),this.container_group.appendChild(this.group),this.container_group.appendChild(this.label_group)}Initialize(e){this.parent=e,this.svg_node=S("svg",{class:"treb-chart"}),this.svg_node.style.overflow="hidden",this.svg_node.style.position="relative",this.svg_node.style.width="100%",this.svg_node.style.height="100%",this.svg_node.appendChild(this.container_group),this.parent.appendChild(this.svg_node),this.Resize()}Legend(e){let t=S("g");this.group.appendChild(t);let r=S("text");t.appendChild(r),t.setAttribute("class","legend");let n=[[]],o=10,i=e.area.width,s=0,l=0,c=e.area.width,u=e.style===1?14:26,d=e.labels.map((f,y)=>{r.textContent=f.label;let x=r.getBoundingClientRect(),v={width:x.width,height:x.height},w=v.width+u+o;return l=Math.max(l,v.height),e.layout===1?n[y]=[y]:w>i?n[s].length===0?(n[s].push(y),s++,n[s]=[],i=c):(s++,n[s]=[y],i=c-w):(n[s].push(y),i-=w),v});t.removeChild(r);let m=l,b=e.layout||0;b===0&&n.every(f=>f.length<=1)&&(b=0);for(let f=0;f<n.length;f++){let y=n[f].reduce((w,g)=>w+d[g].width+u,(n[f].length-1)*o),x=0,v=b===0?Math.round((c-y)/2):Math.round(o/2);for(let w=0;w<n[f].length;w++){let g=n[f][w],C=d[g],U=e.labels[g],V=m-1,L=!1;typeof navigator<"u"&&(L=/trident/i.test(navigator?.userAgent||""));let M=typeof U.index=="number"?U.index:g+1;switch(t.appendChild(S("text",{"dominant-baseline":"middle",x:v+u,y:m,dy:L?".3em":void 0},U.label)),e.style){case 1:t.appendChild(S("rect",{class:`series-${M}`,x:v,y:V-4,width:8,height:8}));break;case 2:t.appendChild(S("circle",{class:`series-${M}`,cx:v+u-11,cy:V-4+3}));break;default:t.appendChild(S("rect",{class:`series-${M}`,x:v,y:V-1,width:u-3,height:2}));break}x=Math.max(x,C.height),v+=C.width+u+o}m=Math.round(m+x*1.1)}let p=t.getBoundingClientRect(),h={width:p.width,height:p.height+l};switch(e.position){case 1:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.bottom-h.height})`);break;case 2:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`);break;case 3:t.setAttribute("transform",`translate(${e.area.right-h.width}, ${e.area.top})`);break;case 0:default:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`)}e.position===0?e.area.top+=h.height||0:e.position===3?e.area.right-=(h.width||0)+8:e.position===2?e.area.left+=(h.width||0)+8:e.area.bottom-=h.height||0}Clear(e){this.group.textContent="",this.axis_group.textContent="",this.label_group.textContent="",e="treb-chart"+(e?" "+e:""),this.svg_node.setAttribute("class",e)}Resize(){let e=this.svg_node.getBoundingClientRect();this.svg_node.setAttribute("width",e.width.toString()),this.svg_node.setAttribute("height",e.height.toString()),this.size={width:e.width,height:e.height}}Prerender(){let e=this.svg_node.getBoundingClientRect();this.bounds.top=e.top,this.bounds.left=e.left,this.bounds.right=e.right,this.bounds.bottom=e.bottom}RenderTitle(e,t,r,n){let o=S("text",{class:"chart-title",x:Math.round(t.width/2)},e);o.style.textAnchor="middle",this.group.appendChild(o);let i=o.getBoundingClientRect();n==="bottom"?(o.setAttribute("y",Math.round(t.bottom-i.height).toString()),t.bottom-=i.height+r):(o.setAttribute("y",Math.round(t.top+r+i.height).toString()),t.top+=i.height+r)}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=S("text",{x:"-100px",y:"-100px"}),this.svg_node.appendChild(this.text_measurement_node)),typeof t<"u"?(typeof t=="string"&&(t=[t]),this.text_measurement_node.setAttribute("class",t.join(" "))):this.text_measurement_node.setAttribute("class",""),this.text_measurement_node.textContent=e;let n=this.text_measurement_node.getBoundingClientRect(),o={width:n.width,height:n.height,y_offset:n.height-(this.bounds.top-n.top-100)};return r&&(o.width=Math.ceil(o.width),o.height=Math.ceil(o.height),o.y_offset=Math.ceil(o.y_offset)),o}RenderTicks(e,t,r,n,o){let i=[],s=e.width/n;for(let l=0;l<n;l++){let c=Math.round(e.left+s/2+s*l)-.5;i.push(`M${c} ${t} L${c} ${r}`)}this.group.appendChild(S("path",{d:i,class:o}))}RenderXAxisBar(e,t,r,n,o){let i=r.length;if(!i)return;let s=4,l=t?e.width/i:e.width/(i-1),c=t?l/2:0,u=1,d=!0;for(;d;){d=!1;let m=0;for(let b=0;b<i;b+=u){let p=Math.round(e.left+c+l*b),h=p-n[b].width/2;if(m&&h<=m){u++,d=!0;break}m=p+n[b].width/2+s}}for(let m=0;m<i;m+=u){let b=Math.round(e.left+c+l*m);this.RenderText(this.axis_group,r[m],"center",{x:b,y:e.bottom},o)}}RenderXAxisTicks(e,t,r){let n=t?e.width/r:e.width/(r-1),o=t?n/2:0,i=[];for(let s=0;s<r;s++){let l=Math.round(e.left+o+n*s)+.5;i.push(`M${l},${e.bottom+.5} v6`)}this.axis_group.appendChild(S("path",{d:i.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,n,o){let i=r.length;if(!i)return;let s=4,l=t?e.width/i:e.width/(i-1),c=t?l/2:0,u=1,d=!0,m=(r.length-1)%2===0,b=(r.length-1)%3===0;for(;d;){d=!1;let p=0;for(let h=0;h<i;h+=u){let f=Math.round(e.left+c+l*h),y=f-n[h].width/2;if(p&&y<=p){u++,d=!0;break}p=f+n[h].width/2+s}}u===3&&!b&&m&&u++;for(let p=0;p<i;p+=u){let h=Math.round(e.left+c+l*p);this.RenderText(this.axis_group,r[p],"center",{x:h,y:e.bottom},o)}}RenderYAxisBar(e,t,r,n){r=r.slice(0),r.reverse();let o=r.length;if(!o)return;let i=e.height/o,s=1,l=!0;for(;l;){l=!1;let c=0;for(let u=0;u<o;u+=s){let d=r[u],m=Math.round(e.bottom-i*(u+.5)+d.metrics.height/4);if(c&&m>=c){s++,l=!0;break}c=m-d.metrics.height}}for(let c=0;c<o;c+=s){let u=r[c],d=Math.round(e.bottom-i*(c+.5)+u.metrics.height/4);this.RenderText(this.axis_group,u.label,"right",{x:t,y:d},n)}}RenderYAxis(e,t,r,n,o="right"){let i=r.length;if(!i)return;let s=e.height/(i-1),l=1,c=!0;for(;c;){c=!1;let u=0;for(let d=0;d<i;d+=l){let m=r[d],b=Math.round(e.bottom-s*d+m.metrics.height/4);if(u&&b>=u){l++,c=!0;break}u=b-m.metrics.height}}for(let u=0;u<i;u+=l){let d=r[u],m=Math.round(e.bottom-s*u+d.metrics.height/4);this.RenderText(this.axis_group,d.label,o,{x:t,y:m},n)}}LineProperties(e,t){let r=t.x-e.x,n=t.y-e.y;return{length:Math.sqrt(r*r+n*n),angle:Math.atan2(n,r)}}RenderSmoothLine(e,t,r=!1,n,o){let i=S("g"),s=[],l=[],c=t.length,u=c-1,d=e.width/c/2,m=[],b=t.map((f,y)=>{if(!(typeof f>"u"))return{x:Math.round(e.left+e.width/u*y),y:e.bottom-f}}),p=[],h=()=>{if(p.length<2)return;let f="",y=p[0],x=p[p.length-1];p.length===2?f=`${p[0].x},${p[0].y} L${p[1].x},${p[1].y}`:p.length>2&&(f=""+this.CatmullRomChain(p).map(w=>`${w.x},${w.y}`).join(" L")),f&&(s.push("M"+f),r&&(l.push(`M ${y.x},${e.bottom} L ${y.x},${y.y}`),l.push("L"+f),l.push(`L ${x.x},${e.bottom}`)))};for(let f of b)f?p.push(f):(h(),p=[]);if(p.length&&h(),r&&i.appendChild(S("path",{class:"fill",d:l})),i.appendChild(S("path",{class:"line",d:s})),typeof o<"u"&&(typeof o=="string"&&(o=[o]),i.setAttribute("class",o.join(" "))),this.group.appendChild(i),n&&m.length){let f=S("g");for(let y of m){let x=S("circle",{cx:y.x,cy:y.y,r:d});x.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n[y.i]||"")}),x.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),f.appendChild(x)}f.setAttribute("class","mouse-layer"),this.group.appendChild(f)}}RenderLine(e,t,r=!1,n,o){let i=S("g"),s=[],l=[],c=t.length,u=c-1,d=e.width/c/2,m=[],b=0,p=!0,h;for(;b<c;b++){let f=t[b];if(typeof f>"u"){p=!0,r&&typeof h<"u"&&l.push(`L${h} ${e.bottom}Z`),h=void 0;continue}let y=Math.round(+e.left+e.width/u*b);p?(r&&l.push(`M${y} ${e.bottom} L${y} ${e.bottom-f}`),s.push(`M${y} ${e.bottom-f}`)):(s.push(`L${y} ${e.bottom-f}`),l.push(`L${y} ${e.bottom-f}`)),m.push({x:y,y:e.bottom-f,i:b}),h=y,p=!1}if(r&&typeof h<"u"&&l.push(`L${h} ${e.bottom}Z`),r&&i.appendChild(S("path",{class:"fill",d:l})),i.appendChild(S("path",{class:"line",d:s})),typeof o<"u"&&(typeof o=="string"&&(o=[o]),i.setAttribute("class",o.join(" "))),this.group.appendChild(i),n&&m.length){let f=S("g");for(let y of m){let x=S("circle",{cx:y.x,cy:y.y,r:d});x.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n[y.i]||"")}),x.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),f.appendChild(x)}f.setAttribute("class","mouse-layer"),this.group.appendChild(f)}}RenderBarGrid(e,t,r){let n=[],o=e.width/t;for(let i=0;i<=t;i++){let s=Math.round(e.left+o*i)-.5;n.push(`M${s} ${e.top} L${s} ${e.bottom}`)}this.group.appendChild(S("path",{d:n,class:r}))}RenderGrid(e,t,r=0,n,o){let i=[],s=[],l=e.height/t;for(let c=0;c<=t;c++){let u=Math.round(e.top+l*c)-.5;o&&o[1]===c?s.push(`M${e.left} ${u} L${e.right} ${u}`):i.push(`M${e.left} ${u} L${e.right} ${u}`)}l=e.width/(r-1);for(let c=0;c<r;c++){let u=Math.round(e.left+l*c)-.5;o&&o[0]===c?s.push(`M${u} ${e.top} L${u} ${e.bottom}`):i.push(`M${u} ${e.top} L${u} ${e.bottom}`)}this.group.appendChild(S("path",{d:i,class:n})),s.length&&(n?Array.isArray(n)?n.push("zero"):n=n+" zero":n="zero",this.group.appendChild(S("path",{d:s,class:n})))}MultiplyPoint(e,t){return{x:e.x*t,y:e.y*t}}AddPoints(e,t){return{x:e.x+t.x,y:e.y+t.y}}CatmullRomSpline(e,t){let r=.5;r=r/2;let n=(d,m,b)=>{let{x:p,y:h}=m,{x:f,y}=b;return((f-p)**2+(y-h)**2)**r+d},o=0,i=n(o,e[0],e[1]),s=n(i,e[1],e[2]),l=n(s,e[2],e[3]),c=(s-i)/t,u=[];for(let d=0;d<t;d++){let m=i+c*d,b=this.AddPoints(this.MultiplyPoint(e[0],(i-m)/(i-o)),this.MultiplyPoint(e[1],(m-o)/(i-o))),p=this.AddPoints(this.MultiplyPoint(e[1],(s-m)/(s-i)),this.MultiplyPoint(e[2],(m-i)/(s-i))),h=this.AddPoints(this.MultiplyPoint(e[2],(l-m)/(l-s)),this.MultiplyPoint(e[3],(m-s)/(l-s))),f=this.AddPoints(this.MultiplyPoint(b,(s-m)/(s-o)),this.MultiplyPoint(p,(m-o)/(s-o))),y=this.AddPoints(this.MultiplyPoint(p,(l-m)/(l-i)),this.MultiplyPoint(h,(m-i)/(l-i))),x=this.AddPoints(this.MultiplyPoint(f,(s-m)/(s-i)),this.MultiplyPoint(y,(m-i)/(s-i)));u.push(x)}return u}CatmullRomChain(e,t=30){let r=e.slice(0),n=[],o=r.length;if(o){let i=r[o-1].x-r[o-2].x,s=r[o-1].y-r[o-2].y;r.push({x:r[o-1].x+i,y:r[o-1].y+s}),r.push({x:r[o-1].x+i,y:r[o-1].y+s}),i=r[1].x-r[0].x,s=r[1].y-r[0].y,r.unshift({x:r[0].x-i,y:r[0].y-s});for(let l=0;l<r.length-4;l++){let c=r.slice(l,l+4),u=this.CatmullRomSpline(c,t);n.push(...u)}}return n}RenderDataLabels(e,t,r,n,o,i,s){let l=Math.max(t.length,r.length),c=n.max-n.min||1,u=o.max-o.min||1;for(let d=0;d<l;d++){let m=t[d],b=r[d];if(m!==void 0&&b!==void 0){let p={x:e.left+(m-n.min)/c*e.width,y:e.bottom-(b-o.min)/u*e.height},h=i[d];if(h){this.label_group.appendChild(S("circle",{class:"label-target",cx:p.x,cy:p.y,r:10}));let f=S("g",{class:"data-label",transform:`translate(${p.x+10},${p.y})`});this.label_group.appendChild(f);let y=S("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${s}`});f.appendChild(y);let x=S("text",{x:4,y:0},h);f.appendChild(x);let v=x.getBoundingClientRect(),w=v.height,g=v.width+8;g+15+p.x>=e.right&&(f.setAttribute("transform",`translate(${p.x-g-15},${p.y})`),y.setAttribute("cx",(g+15).toString()));let C=S("path",{d:`M0,5 h${g} v-${w} h-${g} Z`});f.insertBefore(C,x)}}}}RenderBoxAndWhisker(e,t,r,n,o,i,s){let l=S("g",{class:s});this.group.appendChild(l);let c=e.width/i,u=c*.2,m=Math.min(c-2*u,90);n>0&&(m=m*Math.sqrt(t.n)/Math.sqrt(n));let b=y=>e.top+e.height-(y-o.min)/(o.max-o.min)*e.height,p=e.left+r*c+c/2,h=b(t.quartiles[0]),f=b(t.quartiles[2]);l.appendChild(S("rect",{class:"iqr",x:e.left+r*c+(c-m)/2,y:f,width:m,height:h-f})),l.appendChild(S("line",{class:"median",x1:p-m*.5,x2:p+m*.5,y1:b(t.quartiles[1]),y2:b(t.quartiles[1])})),l.appendChild(S("line",{class:"whisker",x1:p-m*.25,x2:p+m*.25,y1:b(t.whiskers[0]),y2:b(t.whiskers[0])})),l.appendChild(S("line",{class:"whisker-extent",x1:p,x2:p,y1:b(t.whiskers[0])-2,y2:b(t.quartiles[0])+2})),l.appendChild(S("line",{class:"whisker",x1:p-m*.25,x2:p+m*.25,y1:b(t.whiskers[1]),y2:b(t.whiskers[1])})),l.appendChild(S("line",{class:"whisker-extent",x1:p,x2:p,y1:b(t.whiskers[1])+2,y2:b(t.quartiles[2])-2}));for(let y of t.data)(y<t.whiskers[0]||y>t.whiskers[1])&&l.appendChild(S("circle",{class:"outlier",cx:p,cy:b(y),r:3}))}RenderBubbleSeries(e,t,r,n,o){let i=r.max-r.min||1,s=n.max-n.min||1,l=[],c=[],u=S("g",{class:o});if(this.group.appendChild(u),t.z)for(let[d,m]of t.z.data.entries()){let b=t.x.data[d],p=t.y.data[d];if(typeof b<"u"&&typeof p<"u"&&typeof m<"u"&&m>0){let h=m/i*e.width,f=m/s*e.height,y=Math.max(h,f),x={x:e.left+(b-r.min)/i*e.width,y:e.bottom-(p-n.min)/s*e.height,z:y};if(l.push(x),t.labels?.[d]){let v=x.z/2;c.push({x:x.x,y:x.y,text:t.labels?.[d]||"",offset:Math.cos(Math.PI/4)*v})}}}for(let d of l)d&&u.appendChild(S("circle",{cx:d.x,cy:d.y,r:d.z/2,class:"point"}));if(c.length){let d=this.label_group.getBoundingClientRect();for(let m of c)if(m.text){let b=this.label_group.appendChild(S("g",{class:"bubble-label"})),p=b.appendChild(S("rect",{x:m.x,y:m.y,class:"label-background"})),f=b.appendChild(S("text",{x:m.x,y:m.y,offset:m.offset,class:"label-text","text-anchor":"middle","alignment-baseline":"middle",style:`--translate-offset: ${Math.round(m.offset)}px`},m.text)).getBoundingClientRect();p.setAttribute("x",(f.left-d.left-2).toString()),p.setAttribute("y",(f.top-d.top-1).toString()),p.style.height=f.height+2+"px",p.style.width=f.width+4+"px"}}}RenderScatterSeries(e,t,r,n,o,i=!0,s=!1,l=!1,c=!1,u=!1,d){let m=Math.max(t.length,r.length),b=n.max-n.min||1,p=o.max-o.min||1,h=[],f=[],y=[],x=S("g",{class:d});this.group.appendChild(x);for(let v=0;v<m;v++){let w=t[v],g=r[v];typeof w>"u"||typeof g>"u"?h.push(void 0):h.push({x:e.left+(w-n.min)/b*e.width,y:e.bottom-(g-o.min)/p*e.height})}if(i){let v=[],w=u?()=>v.length===2?`${v[0].x},${v[0].y} L${v[1].x},${v[1].y}`:v.length>2?this.CatmullRomChain(v).map(C=>`${C.x},${C.y}`).join(" L"):"":()=>v.map(g=>`${g.x},${g.y}`).join(" L");for(let g of h)if(g)v.push(g);else{if(v.length>=2){let C=w();f.push("M"+C),y.push(`M${v[0].x},${e.bottom}L`+C+`L${v[v.length-1].x},${e.bottom}Z`)}v=[]}if(v.length>=2){let g=w();f.push("M"+g),y.push(`M${v[0].x},${e.bottom}L`+g+`L${v[v.length-1].x},${e.bottom}Z`)}}if(l&&x.appendChild(S("path",{d:y,class:"fill"})),i&&x.appendChild(S("path",{d:f,class:"line"})),s)for(let v of h)v&&x.appendChild(S("circle",{cx:v.x,cy:v.y,r:1,class:"point"}));if(c)for(let v of h)v&&x.appendChild(S("circle",{cx:v.x,cy:v.y,r:3,class:"marker"}))}RenderPoints(e,t,r,n){let o=[];for(let i=0;i<t.length;i++){let s=t[i]*e.width+e.left,l=e.bottom-r[i]*e.height;o.push(`M${s-1},${l-1} L${s+1},${l+1}`),o.push(`M${s-1},${l+1} L${s+1},${l-1}`)}this.group.appendChild(S("path",{d:o,class:n}))}RenderPoint(e,t,r){this.group.appendChild(S("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=S("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(S("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,n,o,i){let s="";if(t)if(t[0]&&t[0]===t[1]&&t[0]>=e.height){let c=t[0],u=t[0]-e.height,d=Math.sqrt(c*c-u*u);s=`M${e.left+e.width/2-d},${e.bottom} a${c},${c} 0 0 1 ${d*2},0 z`}else if(t[1]&&t[1]===t[2]&&t[1]>=e.width){let c=t[1],u=t[1]-e.width,d=Math.sqrt(c*c-u*u);s=`M${e.left},${e.top+e.height/2-d} a${c},${c} 0 0 1 0,${d*2} z`}else s=`M${e.left},${e.top+t[0]} a${t[0]},${t[0]} 0 0 1 ${t[0]},${-t[0]} h${e.width-t[0]-t[1]} a${t[1]},${t[1]} 0 0 1 ${t[1]},${t[1]} v${e.height-t[1]-t[2]} a${t[2]},${t[2]} 0 0 1 ${-t[2]},${t[2]} h${-e.width+t[2]+t[3]} a${t[3]},${t[3]} 0 0 1 ${-t[3]},${-t[3]} v${-e.height+t[3]+t[0]} `;else s=`M${e.left},${e.top} h${e.width} v${e.height} h${-e.width} v${-e.height} `;let l=S("path",{d:s,class:r});if(n&&(l.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n)}),l.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")})),this.group.appendChild(l),o){this.label_group.appendChild(S("path",{class:"label-target",d:s}));let c=i||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},u=S("g",{class:"data-label",transform:`translate(${c.x},${c.y})`});this.label_group.appendChild(u);let d=S("text",{x:0,y:0},o);u.appendChild(d);let m=d.getBoundingClientRect(),b=m.height,p=m.width+8;c.y-m.height<4&&(c.y-=c.y-m.height-4,u.setAttribute("transform",`translate(${c.x},${c.y})`)),d.setAttribute("x",Math.floor(-m.width/2).toString());let h=Math.ceil(b*.125),f=S("rect",{rx:3,x:-p/2,y:Math.round(-b+h*2/3),width:p,height:b+h});u.insertBefore(f,d)}}RenderText(e,t,r,n,o){let i=S("text",{x:n.x,y:n.y,class:o},t);switch(r){case"right":i.style.textAnchor="end";break;case"center":i.style.textAnchor="middle";break;default:i.style.textAnchor="start";break}(e||this.group).appendChild(i)}RenderDonut(e,t,r,n,o,i,s){let l=-Math.PI/2,c=0;i&&(r*=.8,n*=.7);let u=(d,m,b)=>[Math.cos(b)*m+d.x,Math.sin(b)*m+d.y];for(let d of e){let m=d.title||"",b=d.percent,p=d.index,h=[],f=0,y=u.bind(0,t,r),x=u.bind(0,t,n);if(b>.5){f=l+b/2*Math.PI*2,c=l+b*Math.PI*2;let g=f-l,C=c-f;h.push(`M${y(l)}`,`A${r},${r},${g},0,1,${y(f)}`,`A${r},${r},${C},0,1,${y(c)}`,`L${x(c)}`,`A${n},${n},${C},0,0,${x(f)}`,`A${n},${n},${g},0,0,${x(l)}`,"Z")}else{c=l+b*Math.PI*2,f=(c-l)/2+l;let g=c-l;h.push(`M${y(l)}`,`A${r},${r},${g},0,1,${y(c)}`,`L${x(c)}`,`A${n},${n},${g},0,0,${x(l)}`,"Z")}let v=S("path",{d:h,class:typeof p>"u"?void 0:`series-${p}`});typeof p<"u"&&v.setAttribute("data-index",p.toString());let w=S("g",{class:s});if(w.appendChild(v),this.group.appendChild(w),b>=.05&&m){let g=r-n;h=[];let C=u(t,n+(r-n)/2+g,f);h.push(`M${u(t,n+(r-n)/2,f)}`),h.push(`L${C}`),w.appendChild(S("path",{d:h,class:"callout"}));let U=[],V=S("text",{class:"callout-label"});w.appendChild(V);let L=f+Math.PI/2,M=m;V.textContent=M;let A=V.getBoundingClientRect(),G={width:A.width,height:A.height},[j,se]=C;j+=G.height/2*Math.cos(f),se+=G.height/4+G.height/2*Math.sin(f);let de=!1;L>Math.PI?j-G.width<=o.left&&(de=!0):j+G.width>o.right&&(de=!0);let Wt=/[\s-]/;if(de&&Wt.test(M)){let me=-1,be=1;for(let pe=0;pe<M.length;pe++)if(Wt.test(M[pe])){let Q=Math.abs(.5-pe/M.length);Q<be&&(be=Q,me=pe)}me>0&&(U.push(M.substr(0,me+1).trim()),U.push(M.substr(me+1).trim()))}if(U.length){let me=0,be=0,pe=U.map(Q=>{V.textContent=Q,A=V.getBoundingClientRect();let he={width:A.width,height:A.height};return be=Math.max(be,he.width),{text:Q,metrics:he}});V.textContent="";for(let Q of pe){let he=S("tspan");he.textContent=Q.text;let wn=L>Math.PI?j-(be-Q.metrics.width)/2:j+(be-Q.metrics.width)/2;he.setAttribute("x",wn.toString()),he.setAttribute("dy",me.toString()),V.appendChild(he),me=Q.metrics.height}}let xn=L>Math.PI?"end":"start";V.setAttribute("text-anchor",xn),V.setAttribute("x",j.toString()),V.setAttribute("y",se.toString()),typeof p<"u"&&V.setAttribute("data-index",p.toString())}l=c}}};var ut=class{renderer=new ct;margin={top:.025,left:.05,bottom:.025,right:.075};Resize(e,t){this.renderer.Resize()}Initialize(e){this.renderer.Initialize(e)}Update(e,t){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(t.class_name);let r=new re(0,0,this.renderer.size.width,this.renderer.size.height),n={top:Math.round(r.height)*this.margin.top,bottom:Math.round(r.height)*this.margin.bottom,left:Math.round(r.width)*this.margin.left,right:Math.round(r.width)*this.margin.right},o=t.title;if(o&&this.renderer.RenderTitle(o,r,n.top,t.title_layout||"top"),r.top+=n.top,r.left+=n.left,r.bottom-=n.bottom,r.right-=n.right,t.legend&&t.legend.length){let s=0;t.title&&(!t.title_layout||t.title_layout==="top")&&(s=1);let l=t.legend_position||s;this.renderer.Legend({labels:t.legend,position:l,style:t.legend_style,layout:l===0||l===1?0:1,area:r})}if(t.type==="histogram"||t.type==="line"||t.type==="area"||t.type==="column"||t.type==="histogram2"||t.type==="bar"||t.type==="scatter2"||t.type==="bubble"||t.type==="box"){let s=[],l=0;t.x_labels&&t.x_labels.length&&(s=t.x_labels.map(m=>{let b=this.renderer.MeasureText(m,["axis-label","x-axis-label"],!0);return l=Math.max(l,b.height),b}));let c=[],u=0;t.type==="box"&&t.series_names?.length&&(c=t.series_names.map(m=>{let b=this.renderer.MeasureText(m,["axis-label","x-axis-label","series-name"],!0);return u=Math.max(u,b.height),b}));let d=l&&u?4:0;if(t.y_labels&&t.y_labels.length){let m=[],b=0,p=0,h=t.type==="scatter2"||t.type==="bubble"?t.y_scale:t.scale,f=t.type==="bar"?t.y_labels.length:h.count+1;for(let y=0;y<f;y++){let x=this.renderer.MeasureText(t.y_labels[y],["axis-label","y-axis-label"]);m.push({label:t.y_labels[y],metrics:x}),b=Math.max(b,x.width),p=Math.max(p,x.height)}r.bottom=Math.round(r.bottom-p/2),r.top=Math.round(r.top+p/2),s.length&&(r.bottom-=l+n.bottom),c.length&&(r.bottom-=u+n.bottom),d&&(r.bottom-=d),t.type==="bar"?this.renderer.RenderYAxisBar(r,r.left+b,m,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(r,r.left+b,m,["axis-label","y-axis-label"]),r.left+=b+n.left}if(t.type==="scatter2"&&t.y2_labels&&t.y2_labels.length&&t.y2_scale){let m=[],b=0,p=0,f=t.y2_scale.count+1;for(let y=0;y<f;y++){let x=this.renderer.MeasureText(t.y2_labels[y],["axis-label","y-axis-label"]);m.push({label:t.y2_labels[y],metrics:x}),b=Math.max(b,x.width),p=Math.max(p,x.height)}this.renderer.RenderYAxis(r,r.right-b,m,["axis-label","y-axis-label"],"left"),r.right-=b+n.left}if(s.length&&t.x_labels?.length){let m=t.type==="histogram2",b=t.type!=="line"&&t.type!=="area"&&t.type!=="bar"&&t.type!=="scatter2"&&t.type!=="bubble"&&t.type!=="histogram2";m&&this.renderer.RenderXAxisTicks(r,b,t.x_labels.length),t.y_labels&&(r.bottom+=l+n.bottom),this.renderer.RenderXAxis(r,b,t.x_labels,s,["axis-label","x-axis-label"]),r.bottom-=l+n.bottom}d&&(r.bottom+=d),t.type==="box"&&c.length&&t.series_names?.length&&(t.y_labels&&(r.bottom+=l+u+d+n.bottom),this.renderer.RenderXAxis(r,!0,t.series_names,c,["axis-label","x-axis-label","series-name"]),r.bottom-=l+u+n.bottom+n.bottom)}let i=[];switch(t.type){case"scatter":this.renderer.RenderPoints(r,t.x,t.y,"mc mc-correlation series-1");break;case"box":this.renderer.RenderGrid(r,t.scale.count,void 0,"chart-grid",i);for(let[s,l]of t.data.entries())l.iqr>0&&this.renderer.RenderBoxAndWhisker(r,l,s,t.max_n,t.scale,t.data.length,`box-plot series-${s}`);break;case"bubble":t.x_scale.min<=0&&t.x_scale.max>=0&&(i[0]=Math.round(Math.abs(t.x_scale.min/t.x_scale.step))),t.y_scale.min<=0&&t.y_scale.max>=0&&(i[1]=Math.round(Math.abs(t.y_scale.max/t.y_scale.step))),this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid",i);for(let[s,l]of t.series.entries()){let c=typeof l.index=="number"?l.index:s+1;this.renderer.RenderBubbleSeries(r,l,t.x_scale,t.y_scale,`bubble-chart series-${c}`)}break;case"scatter2":if(this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid"),t.series){for(let s=0;s<t.series.length;s++){let l=t.series[s],c=!!t.lines,u=!!t.points;l.subtype==="plot"?(u=!0,c=!1):l.subtype==="line"&&(u=!1,c=!0);let d=typeof l.index=="number"?l.index:s+1;this.renderer.RenderScatterSeries(r,l.x.data,l.y.data,t.x_scale,l.axis&&t.y2_scale?t.y2_scale:t.y_scale,c,u,!!t.filled,!!t.markers,!!t.smooth,`scatter-plot series-${d}`)}if(t.data_labels)for(let s=0;s<t.series.length;s++){let l=t.series[s];l.y.labels&&this.renderer.RenderDataLabels(r,l.x.data,l.y.data,t.x_scale,t.y_scale,l.y.labels,s+1)}}break;case"pie":case"donut":{let s=Math.min(r.height,r.width)/2*.9,l=t.type==="pie"?0:s*.8;this.renderer.RenderDonut(t.slices,r.center,s,l,r,!0,"donut")}break;case"line":case"area":{let s=t.scale;if(t.series){let l=t.x_scale?t.x_scale.max:Math.max.apply(0,t.series.map(d=>d.length)),c=t.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(r,t.scale.count,t.x_scale?t.x_scale.count+1:l,"chart-grid");let u=0;for(let d of t.series){let m=d.map(p=>{if(!(typeof p>"u"))return E.ApplyScale(p,r.height,s)});if(m.length<l)for(let p=m.length;p<l;p++)m.push(void 0);let b=[t.type==="area"?"chart-area":"chart-line",`series-${u+1}`];c.call(this.renderer,r,m,t.type==="area",t.titles,b),u++}}}break;case"bar":{let s;if(this.renderer.RenderBarGrid(r,t.scale.count,"chart-grid"),t.series2){let l=0,c=t.series2.length;for(let h of t.series2)l=Math.max(l,h.y.data.length);let u=r.height/l,d=.7;typeof t.space=="number"&&(d=Math.max(0,Math.min(1,1-t.space)));let m=u*(1-d)/2,b=(u-m*2)/c,p=0;if(t.scale.min<0&&(p=E.ApplyScale(0,r.width,t.scale)),t.round){let h=Math.floor(b/2);s=[0,h,h,0]}for(let h=0;h<c;h++){let f=t.series2[h],y=typeof f.index=="number"?f.index:h+1;for(let x=0;x<f.y.data.length;x++){let v=f.y.data[x];if(typeof v=="number"){let w=Math.round(r.top+x*u+m)+h*b,g=0,C=0;p?v>0?(C=E.ApplyScale(v+t.scale.min,r.width,t.scale),g=r.left+p):(C=E.ApplyScale(t.scale.min-v,r.width,t.scale),g=r.left+p-C):(C=E.ApplyScale(v,r.width,t.scale),g=r.left),C&&this.renderer.RenderRectangle(new re(g,w,g+C,w+b),s,["chart-column",`series-${y}`],void 0||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid"),t.series2){let s=0,l=t.series2.length;for(let h of t.series2)s=Math.max(s,h.y.data.length);let c=r.width/s,u=.7;typeof t.space=="number"&&(u=Math.max(0,Math.min(1,1-t.space)));let d=c*(1-u)/2,m=(c-d*2)/l,b=0;if(t.scale.min<0&&(b=E.ApplyScale(0,r.height,t.scale)),t.callouts&&t.x_scale){let h=t.x_scale,f=t.callouts.map((y,x)=>{let v=Math.round(r.left+E.ApplyScale(y.value,r.width,h))+.5;return{x1:v,y1:r.bottom-r.height,x2:v,y2:r.bottom,classes:`callout-${x+1}`}});this.renderer.RenderCalloutLines(f)}let p;if(t.round){let h=Math.floor(m/2);p=[h,h,0,0]}if(t.stacked_series)for(let h=0;h<t.stacked_series[0].y.data.length;h++){let f=r.left+h*c+d,y=0;for(let x=0;x<t.stacked_series.length;x++){let v=t.stacked_series[x],w=typeof v.index=="number"?v.index:x+1,g=0,C=v.y.data[h]||0;x===0&&(y=Math.min(t.scale.min||0,C)),g=E.ApplyScale(C,r.height,t.scale);let U=r.bottom-g-E.ApplyScale(y,r.height,t.scale);this.renderer.RenderRectangle(new re(f,U,f+m,U+g),p,["chart-column",`series-${w}`],void 0||void 0,void 0,void 0),y+=C}}else for(let h=0;h<l;h++){let f=t.series2[h],y=typeof f.index=="number"?f.index:h+1;for(let x=0;x<f.y.data.length;x++){let v=f.y.data[x];if(typeof v=="number"){let w=r.left+x*c+d+h*m,g=0,C=0;b?v>0?(g=E.ApplyScale(v+t.scale.min,r.height,t.scale),C=r.bottom-g-b):(g=E.ApplyScale(t.scale.min-v,r.height,t.scale),C=r.bottom-b):(g=E.ApplyScale(v,r.height,t.scale),C=r.bottom-g);let U=void 0;if(g){let V=t.data_labels&&f.y.labels?f.y.labels[x]:"",L={x:Math.round(w+m/2),y:Math.round(C-10)};this.renderer.RenderRectangle(new re(w,C,w+m,C+g),p,["chart-column",`series-${y}`],U||void 0,V,L)}}}}}break;case"histogram":{this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid");let s=r.width/t.count,l=t.column_width,c=s*(1-l)/2;for(let u=0;u<t.count;u++){let d=Math.round(r.left+u*s+c),m=s-c*2,b=E.ApplyScale(t.bins[u],r.height,t.scale),p=r.bottom-b,h=t.titles?t.titles[u]:void 0;this.renderer.RenderRectangle(new re(d,p,d+m,p+b),void 0,"chart-column series-1",h||void 0)}}break}}};var xe=class{constructor(e=new ut){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};node;Initialize(e){this.node=e,this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.chart_data=jt(r,"column");break;case"bar.chart":this.chart_data=jt(r,"bar");break;case"line.chart":this.chart_data=qt(r,"line");break;case"area.chart":this.chart_data=qt(r,"area");break;case"donut.chart":case"pie.chart":this.chart_data=hn(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.chart_data=Gt(r,"plot");break;case"scatter.line":this.chart_data=Gt(r,"line");break;case"bubble.chart":this.chart_data=pn(r);break;case"box.plot":this.chart_data=bn(r);break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}Resize(){this.node&&this.renderer.Resize(this.node,this.chart_data)}Update(){this.node&&this.renderer.Update(this.node,this.chart_data)}};var ne=(...a)=>({type:5,value:a,key:"arguments"}),Xt={Group:{arguments:[{name:"Array...",metadata:!0}],fn:(...a)=>({type:5,value:a,key:"group"}),category:["grouping"]},Series:{arguments:[{name:"Label"},{name:"X",metadata:!0},{name:"Y",metadata:!0},{name:"Z",metadata:!0},{name:"Index"},{name:"Subtype"},{name:"Labels",description:"Labels for bubble charts only (atm)"},{name:"Axis",description:"Series axis (scatter plot only)"}],fn:(...a)=>({type:5,value:{label:a[0],x:a[1],y:a[2],z:a[3],index:a[4],subtype:a[5],data_labels:a[6],axis:a[7]},key:"series"}),category:["chart functions"]},"Bar.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Line.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Area.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Pie.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels"},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:ne,category:["chart functions"]},"Donut.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels",metadata:!0},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:ne,category:["chart functions"]},"Scatter.Line":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Scatter.Plot":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Column.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"Chart Title"}],fn:ne,category:["chart functions"]},"Bubble.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"}],fn:ne,category:["chart functions"]},"Box.Plot":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"},{name:"Min/Max Style"}],fn:ne,category:["chart functions"]}};var dt=class a{_ready_state=[];get ready(){return Promise.all(this._ready_state)}static treb_base_path="";static failed_dynamic_modules=[];static one_time_warnings={};static clipboard;DOM=le.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return ee}events=new rr;calculation=0;file_version=0;last_save_version=0;initial_load_source=void 0;calculator;grid;model;dialog;spinner;file_chooser;file_chooser_operation=0;get parser(){return this.model.parser}view_node;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;get active_sheet(){let e=this.grid.active_sheet.name;return Ue.test(e)?`'${e}'`:e}get modified(){return this.undo_stack.length!==1}get document_name(){return this.grid.model.document_name}set document_name(e){this.grid.model.document_name=e,this.DocumentChange()}get user_data(){return this.grid.model.user_data}set user_data(e){this.grid.model.user_data=e,this.DocumentChange()}get scale(){return this.grid.scale}set scale(e){this.grid.scale=e}get headless(){return this.grid.headless}set headless(e){this.grid.headless!==e&&(this.grid.headless=e,e||(this.grid.Update(!0),this.RebuildAllAnnotations()))}get state(){return this.file_version}get can_revert(){return!this.options.inline_document&&!this.options.document?!1:this.initial_load_source==="local-storage"?!0:this.dirty}get dirty(){return this.file_version!==this.last_save_version}set dirty(e){e?this.file_version++:this.last_save_version=this.file_version}get sheet_names(){return this.model.sheets.list.map(e=>e.name)}constructor(e){e.storage_key&&!e.local_storage&&(e.local_storage=e.storage_key),this.options={...on,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(Re.imaginary_character=this.options.imaginary_value),this.options.network_document&&(console.warn("the option `network_document` is deprecated. please use `document` instead."),this.options.document||(this.options.document=this.options.network_document)),this.options.document&&this.options.inline_document&&console.warn("both document and inline-document are provided");let t=this.options.document,r,n;this.options.local_storage&&!this.options.toll_initial_load&&!e.model&&(r=localStorage.getItem(this.options.local_storage)||void 0,r&&(n="local-storage")),!r&&!this.options.toll_initial_load&&!e.model&&e.inline_document&&(r=e.inline_document,n="inline-document"),this.options.local_storage&&!e.model&&window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.options.local_storage&&this.dirty&&this.SaveLocalStorage(this.options.local_storage)});let o;typeof this.options.container=="string"?o=document.querySelector(this.options.container):this.options.container&&(o=this.options.container);let i={in_cell_editor:!0,repaint_on_cell_change:!1,scrollbars:this.options.scrollbars,markdown:!!this.options.markdown,formula_bar:this.options.formula_bar,expand_formula_button:this.options.expand_formula_button,tab_bar:this.options.tab_bar,add_tab:this.options.add_tab,expand:this.options.expand,support_font_stacks:!!this.options.font_stack};if(this.options.scale&&(i.initial_scale=this.options.scale),this.options.stats&&(i.stats=this.options.stats,i.tab_bar=!0),this.options.scale_control&&(i.scale_control=!0,i.tab_bar=!0,this.options.persist_scale&&(i.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),i.persist_scale_key))){let l=localStorage.getItem(i.persist_scale_key);if(l)try{let c=JSON.parse(l);i.initial_scale=c.scale||1}catch{console.warn("parsing persisted scale failed")}}e.model?(this.model=e.model.model,this.calculator=e.model.calculator,this.DOM=e.model.DOM):(this.model=new ur,this.model.sheets.Add(dr.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,this.options));let s=this.calculator.InitResources();if(this._ready_state.push(s),o&&(this.DOM=le.GetInstance(o.ownerDocument)),e.custom_grid?this.grid=e.custom_grid(i,this.model,void 0,!!o,this.DOM):this.grid=new ir(i,this.model,void 0,!!o,this.DOM),this.options.headless&&(this.grid.headless=!0),this.LoadLanguage(e.language),o){this.DOM=le.GetInstance(o.ownerDocument),this.parent_view||(Ee.is_windows?o.parentElement?.classList.add("treb-ua-windows"):Ee.is_mac&&o.parentElement?.classList.add("treb-ua-osx"),Ee.is_iphone&&o.parentElement?.classList.add("treb-ua-iphone"));let l=o.querySelector(".treb-view-template");this.view_node=l.content.firstElementChild?.cloneNode(!0),o.prepend(this.view_node),this.view_node.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=u=>this.HandleKeyDown(u),o.addEventListener("keydown",this.key_listener);let c=!!(r||this.options.document);this.grid.Initialize(this.view_node,c),this.options.dnd&&(this.view_node.addEventListener("dragenter",u=>this.HandleDrag(u)),this.view_node.addEventListener("dragover",u=>this.HandleDrag(u)),this.view_node.addEventListener("drop",u=>this.HandleDrop(u))),this.grid.grid_events.Subscribe(u=>{switch(u.type){case"error":this.dialog?.ShowDialog({type:"error",...this.TranslateGridError(u.code),timeout:3e3,close_box:!0});break;case"selection":this.UpdateSelection(u.selection,u.reason),this.UpdateSelectionStyle(u.selection);break;case"sheet-change":this.OnSheetChange(u),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.Publish({type:"view-change"});break;case"cell-event":this.HandleCellEvent(u);break;case"composite":{let d=this.last_selection;this.calculation===0&&this.Recalculate(u),this.DocumentChange(d),this.UpdateDocumentStyles(),this.UpdateSelectionStyle()}break;case"data":{let d=this.last_selection;this.calculation===0&&this.Recalculate(u),this.DocumentChange(d)}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(),this.UpdateSelectionStyle();break;case"annotation":if(u.annotation){let d=u.annotation.view[this.grid.view_index]||{},m=!1;if(u.event==="select")m=!0;else switch(this.DocumentChange(),u.event){case"create":this.InflateAnnotation(u.annotation),this.calculator.UpdateAnnotations(u.annotation,this.grid.active_sheet),this.grid.AnnotationUpdated(u.annotation),m=u.annotation===this.grid.selected_annotation;break;case"delete":this.calculator.RemoveAnnotation(u.annotation);break;case"update":d.update_callback?(d.update_callback(),this.grid.AnnotationUpdated(u.annotation)):console.info("annotation update event without update callback"),this.calculator.UpdateAnnotations(u.annotation,this.grid.active_sheet),m=u.annotation===this.grid.selected_annotation;break;case"resize":d.resize_callback&&(d.resize_callback(),this.grid.AnnotationUpdated(u.annotation));break}if(m){this.UpdateSelectionStyleAnnotation(u.annotation),this.Publish({type:"annotation-selection"});break}}else console.info("annotation event without annotation");break;case"structure":{let d=this.last_selection;u.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),u.rebuild_required?(this.calculator.Reset(),this.calculation===0&&this.Recalculate(u),this.DocumentChange(d)):this.DocumentChange(d)}this.UpdateSelectionStyle();break}}),this.options.prompt_save&&window.addEventListener("beforeunload",u=>{this.last_save_version!==this.file_version&&(u.preventDefault(),u.returnValue="")})}else e.custom_grid&&(console.info("creating subscription for custom grid (TODO: capabilities)"),this.grid.grid_events.Subscribe(l=>{switch(l.type){case"error":break;case"selection":this.UpdateSelection(l.selection,l.reason),this.UpdateSelectionStyle(l.selection);break;case"sheet-change":this.OnSheetChange(l),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.Publish({type:"view-change"});break;case"cell-event":this.HandleCellEvent(l);break;case"composite":{let c=this.last_selection;this.calculation===0&&this.Recalculate(l),this.DocumentChange(c),this.UpdateDocumentStyles(),this.UpdateSelectionStyle()}break;case"data":{let c=this.last_selection;this.calculation===0&&this.Recalculate(l),this.DocumentChange(c)}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(),this.UpdateSelectionStyle();break;case"annotation":break;case"structure":{let c=this.last_selection;l.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),l.rebuild_required?(this.calculator.Reset(),this.calculation===0&&this.Recalculate(l),this.DocumentChange(c)):this.DocumentChange(c)}this.UpdateSelectionStyle();break}})),a.one_time_warnings.headless||e.headless||(a.one_time_warnings.headless=!0,console.info("not initializing layout; don't call UI functions"));if(e.preload&&e.preload.call(0,this),r?(typeof r=="string"&&(r=JSON.parse(r)),r?s.then(()=>{this.LoadDocument(r,{recalculate:!!this.options.recalculate,source:n})}):this.UpdateDocumentStyles()):t||(this.calculator.RebuildClean(!0),this.UpdateDocumentStyles()),this.FlushUndo(),this.grid.ShowHeaders(this.options.headers),this.options.scroll&&!this.options.document){let l=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(l)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),o&&this.options.spinner&&(this.spinner=new st(o)),t&&!e.model&&!r&&s.then(()=>{this.LoadNetworkDocument(t,this.options)}),o&&(this.dialog=new it(o))}UpdateAC(){let e=this.calculator.SupportedFunctions();if(this.model.language_model?.functions){let t={};for(let r of this.model.language_model.functions||[])t[r.base.toUpperCase()]=r;e=e.map(r=>{let n=t[r.name.toUpperCase()];if(n){let o=JSON.parse(JSON.stringify({...r,name:n.name}));if(n.description&&(o.description=n.description),n.arguments&&o.arguments)for(let[i,s]of n.arguments.entries())o.arguments[i]&&(o.arguments[i].name=s);return o}return r})}this.grid.SetAutocompleteFunctions(e)}CreateCalculator(e,t){return new ot(e,{complex_numbers:t.complex,spill:t.spill,headless:t.headless})}TranslateGridError(e){switch(e){case 0:return{message:"No error"};case 2:return{message:"You can't change part of an array"};case 5:return{message:"Invalid area for paste"};case 4:return{message:"Invalid area for table"};case 3:return{message:"Invalid value (data validation)"};default:return{message:`Unknown error (${e})`}}}CreateView(){let e=new a({...this.options,global_name:void 0,model:this});return e.parent_view=this,e}Unsplit(){let e=this.views.pop();if(e){let t=e.view;t.grid.grid_events.CancelAll(),t.events.CancelAll(),t.view_node?.parentElement&&(t.key_listener&&t.view_node.parentElement.removeEventListener("keydown",t.key_listener),t.view_node.parentElement.removeChild(t.view_node)),this.view_node?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view_node?.addEventListener("focusin",()=>{this.focus_target!==e&&(this.Publish({type:"focus-view"}),this.focus_target=e)}),e.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(this.grid.EnsureActiveSheet(),this.grid.UpdateLayout(),this.grid.UpdateTabBar(),r.update_annotations&&(this.grid.RefreshAnnotations(),this.InflateAnnotations()))}),e.Subscribe(r=>{r.type==="selection"||(e.UpdateAnnotations(),this.grid.Update(!0),this.grid.UpdateAnnotations())}),this.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(e.grid.EnsureActiveSheet(),e.grid.UpdateLayout(),e.grid.UpdateTabBar(),r.update_annotations&&(e.grid.RefreshAnnotations(),e.InflateAnnotations()))});let t=this.Subscribe(r=>{switch(r.type){case"selection":break;case"load":case"reset":e.grid.EnsureActiveSheet(!0),e.UpdateAnnotations(),e.grid.UpdateAnnotations(),e.grid.Update(!0);break;default:e.UpdateAnnotations(),e.grid.Update(!0),e.grid.UpdateAnnotations()}});this.views.push({view:e,subscription:t})}ListConditionalFormats(e){return(typeof e>"u"?this.grid.active_sheet:this.model.sheets.Find(e))?.conditional_formats||[]}ConditionalFormatDuplicateValues(e,t){return this.AddConditionalFormat({type:"duplicate-values",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t})}ConditionalFormatGradient(e,t){let r=this.RangeOrSelection(e,"invalid range (no selection)"),n=typeof t=="object"?{type:"gradient",area:r,...t}:{type:"gradient",area:r,...mr[t]};return this.AddConditionalFormat(n),n}ConditionalFormatDataBars(e,t){let n={type:"data-bar",area:this.RangeOrSelection(e,"invalid range (no selection)"),fill:{theme:4,tint:.5},...t};return this.AddConditionalFormat(n),n}ConditionalFormatCellMatch(e,t){let r={type:"cell-match",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t};return this.AddConditionalFormat(r),r}ConditionalFormatExpression(e,t){let r={type:"expression",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t};return this.AddConditionalFormat(r),r}AddConditionalFormat(e){return this.grid.AddConditionalFormat(e),e}RemoveConditionalFormat(e){this.grid.RemoveConditionalFormat({format:e})}RemoveConditionalFormats(e){let t=this.RangeOrSelection(e);t&&this.grid.RemoveConditionalFormat({area:t})}HandleToolbarMessage(e){if(this.focus_target!==this){this.focus_target.HandleToolbarMessage(e);return}let t={};if(this.grid.AnnotationSelected()){switch(e.command){case"adjust-font-scale":{let n=Number(e.delta||0),o=this.grid.GetAnnotationStyle()?.font_size;(!o||o.unit!=="em")&&(o={unit:"em",value:1}),o&&(o.value+=n,t.font_size=o,this.grid.ApplyAnnotationStyle(t))}break;case"font-scale":{let n=Number(e.scale||1);n&&!isNaN(n)&&(t.font_size={unit:"em",value:n},this.grid.ApplyAnnotationStyle(t))}break;case"font-stack":e.font_stack&&(t.font_face="stack:"+e.font_stack),this.grid.ApplyAnnotationStyle(t);break}this.Focus();return}let r=n=>{let o=this.grid.GetSelection();if(o&&!o.empty){let i=o.area.spreadsheet_label;n==="Scatter.Plot"||n==="Scatter.Line"||n==="Box.Plot"?this.InsertAnnotation(`=${n}(Series(,,${i}),"${i}")`,void 0,void 0,","):this.InsertAnnotation(`=${n}(${i},,"${i}")`,void 0,void 0,",")}};if(/^border-/.test(e.command))if(e.command==="border-color")try{t.border_top_fill=t.border_bottom_fill=t.border_left_fill=t.border_right_fill=e.color||{}}catch(n){console.error(n)}else{let n=1,o=e.command.substring(7);e.command==="border-double-bottom"&&(o="bottom",n=2),this.grid.ApplyBorders2(void 0,o,e.color||{},n)}else switch(e.command){case"about":this.About();break;case"number-format":t.number_format=e.format||"General";break;case"font-stack":e.font_stack&&(t.font_face="stack:"+e.font_stack);break;case"adjust-font-scale":{let n=this.selection_state.style?.font_size,o=this.grid.GetSelection(),i=this.grid.active_sheet.RealArea(o.area),s=Number(e.delta||0);if((!n||n.unit!=="em")&&(n={unit:"em",value:1}),n&&s&&!isNaN(s)){n.value+=s,this.grid.ApplyStyle(void 0,{font_size:n},!0);let l=[];for(let c=i.start.row;c<=i.end.row;c++)l.push(c);this.selection_state?.merge||this.grid.SetRowHeight(l,void 0,!1)}}break;case"font-scale":{let n=this.grid.GetSelection(),o=this.grid.active_sheet.RealArea(n.area),i=Number(e.scale||1);if(i&&!isNaN(i)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:i}},!0);let s=[];for(let l=o.start.row;l<=o.end.row;l++)s.push(l);this.selection_state?.merge||this.grid.SetRowHeight(s,void 0,!1)}}break;case"update-comment":this.SetNote(void 0,e.comment||"");break;case"clear-comment":this.SetNote(void 0,"");break;case"text-color":case"fill-color":try{let n=e.color||{};e.command==="text-color"?t.text=n:e.command==="fill-color"&&(t.fill=n)}catch(n){console.error(n)}break;case"insert-table":this.InsertTable();break;case"remove-table":this.RemoveTable();break;case"insert-row":this.InsertRows();break;case"insert-column":this.InsertColumns();break;case"delete-row":this.DeleteRows();break;case"delete-column":this.DeleteColumns();break;case"insert-sheet":this.grid.InsertSheet();break;case"delete-sheet":this.grid.DeleteSheet();break;case"freeze-panes":{let n=this.grid.GetFreeze();n.rows||n.columns?this.Freeze(0,0):this.FreezeSelection()}break;case"insert-image":this.InsertImage();break;case"insert-donut-chart":r("Donut.Chart");break;case"insert-column-chart":r("Column.Chart");break;case"insert-bar-chart":r("Bar.Chart");break;case"insert-line-chart":r("Line.Chart");break;case"insert-scatter-plot":r("Scatter.Plot");break;case"insert-box-plot":r("Box.Plot");break;case"toggle-grouping":if(this.selection_state?.style){let n=R.Get(this.selection_state.style.number_format||"General");if(n.date_format)break;let o=new Re(n.pattern);o.ToggleGrouping();let i=o.toString();t.number_format=R.SymbolicName(i)||i}break;case"increase-precision":case"decrease-precision":if(this.selection_state?.style){let n=R.Get(this.selection_state.style.number_format||"General");if(n.date_format)break;let o=new Re(n.pattern);e.command==="increase-precision"?o.IncreaseDecimal():o.DecreaseDecimal();let i=o.toString();t.number_format=R.SymbolicName(i)||i}break;case"merge-cells":this.grid.MergeCells();break;case"unmerge-cells":this.grid.UnmergeCells();break;case"lock-cells":t={locked:this.selection_state?.style?!this.selection_state.style.locked:!0};break;case"wrap-text":t={wrap:this.selection_state?.style?!this.selection_state?.style.wrap:!0};break;case"justify-left":t={horizontal_align:"left"};break;case"justify-center":t={horizontal_align:"center"};break;case"justify-right":t={horizontal_align:"right"};break;case"align-top":t={vertical_align:"top"};break;case"align-middle":t={vertical_align:"middle"};break;case"align-bottom":t={vertical_align:"bottom"};break;case"reset":this.Reset();break;case"import-file":this.LoadLocalFile();break;case"save-json":this.SaveToDesktop();break;case"save-csv":this.SaveToDesktop("csv");break;case"export-xlsx":this.Export();break;case"revert":this.Revert();break;case"recalculate":this.Recalculate();break;case"toggle-toolbar":case"show-toolbar":case"hide-toolbar":this.ShowToolbar(e.command==="toggle-toolbar"?void 0:e.command==="show-toolbar");break;case"toggle-sidebar":case"show-sidebar":case"hide-sidebar":this.ShowSidebar(e.command==="toggle-sidebar"?void 0:e.command==="show-sidebar");break;case"revert-indicator":this.dialog?.ShowDialog({title:`This is a modified version of the document.
1
+ /*! TREB v36.1.4. Copyright 2018-2026 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
+ import{A as or,B as fe,C as ae,D as Re,E as R,F as we,G as Ee,H as ir,I as Pe,J as ft,K as gt,L as sr,M as lr,O as cr,P as ur,Q as dr,R as mr,c as Ue,d as Jt,e as K,f as bt,g as z,h as X,i as pt,j as Ae,k as Yt,l as Zt,n as ee,o as Kt,q as Qt,r as er,s as ht,t as T,u as B,v as tr,w as le,x as rr,y as nr,z as ar}from"./chunk-Z4XFMZ2X.mjs";var He=class a{static type="vertex";type=a.type;color=0;edges_in=new Set;edges_out=new Set;get has_inbound_edges(){return this.edges_in.size>0}get has_outbound_edges(){return this.edges_out.size>0}Reset(){for(let e of this.edges_out)e.RemoveDependency(this);for(let e of this.edges_in)e.RemoveDependent(this);this.edges_out.clear(),this.edges_in.clear()}ClearDependencies(){for(let e of this.edges_in)e.RemoveDependent(this);this.edges_in.clear()}AddDependent(e){e!==this&&(this.edges_out.has(e)||this.edges_out.add(e))}RemoveDependent(e){this.edges_out.delete(e)}AddDependency(e){e!==this&&(this.edges_in.has(e)||this.edges_in.add(e))}RemoveDependency(e){this.edges_in.delete(e)}LinkTo(e){this.AddDependent(e),e.AddDependency(this)}DependsOn(e){this.AddDependency(e),e.AddDependent(this)}LoopCheck(){let e=[this];for(;e.length;){let t=e[e.length-1],r=!0;if(t.color!==2){t.color=1;for(let n of t.edges_out){if(n.color===1)return this.color=0,!0;n.color===0&&n.edges_out.size&&(e.push(n),r=!1)}}r&&(t.color=2,e.pop())}return this.color=2,!1}};var Ce=class extends He{dirty=!1};var br={error:"NOTIMPL"},Y=()=>({type:7,value:"N/A"}),q=()=>({type:7,value:"EXPR"});var W=()=>({type:7,value:"DIV/0"}),_=()=>({type:7,value:"ARG"}),k=()=>({type:7,value:"VALUE"}),D=()=>({type:7,value:"REF"}),vt=()=>({type:7,value:"NAME"}),pr=()=>({type:7,value:"SPILL"}),Oe=()=>({type:7,value:"UNK"});var oe=class a extends Ce{static type="spreadsheet-vertex";reference;error=0;address;result={type:0};expression={type:"missing",id:-1};expression_error=!1;short_circuit=!1;type=a.type;get array_head(){return this.address?!!this.reference&&!!this.reference.area&&this.reference.area.start.column===this.address.column&&this.reference.area.start.row===this.address.row:!1}TakeReferenceValue(){this.reference&&(this.result=T(this.reference.GetValue()))}Calculate(e){if(this.dirty){if(this.color===0&&this.LoopCheck()&&(this.dirty=!1,this.edges_in.size)){this.reference&&(this.array_head||this.reference.type===1)&&this.reference.SetCalculationError("LOOP");for(let t of this.edges_out)t.Calculate(e);return}for(let t of this.edges_in)if(t.dirty)return;if(this.reference){if(this.reference.type===1){this.short_circuit=!1;let t=e.CalculationCallback.call(e,this);if(this.result=t.value,this.short_circuit)return;t.volatile&&e.volatile_list.push(this)}else this.result=this.reference.GetValue4();if(this.array_head)e.SpreadCallback.call(e,this,this.result);else if(this.reference.type===1)if(this.result.type===9){let t=e.SpillCallback.call(e,this,this.result);if(t)for(let r of t)for(let n of r.edges_out)n.dirty=!0,n.Calculate(e)}else this.reference.SetCalculatedValue(this.result.value,this.result.type)}else console.info("skip dirty constant? [or dangling...]");this.dirty=!1;for(let t of this.edges_out)t.dirty&&e.calculation_list.push(t)}}};var ge=class a extends Ce{static type="array-vertex";static list=[];type=a.type;area;static GetVertex(e){for(let t of this.list)if(t.area.start.sheet_id===e.start.sheet_id&&t.area.Equals(e))return[t,!1];return[new a(e),!0]}static Clear(){this.list=[]}static GetContainingArrays(e){let t=[];for(let r of this.list)r.area.start.sheet_id===e.sheet_id&&r.area.Contains(e)&&t.push(r);return t}static CreateImplicitEdges(e,t){for(let r of this.list)r.area.start.sheet_id===t.sheet_id&&r.area.Contains(t)&&r.DependsOn(e)}constructor(e){super(),this.area=e.Clone(),a.list.push(this)}RemoveDependent(e){super.RemoveDependent(e),this.edges_out.size||(this.Reset(),a.list=a.list.filter(t=>t!==this))}Calculate(e){if(this.dirty){if(this.color===0&&this.LoopCheck()&&(this.dirty=!1,this.edges_in.size)){for(let t of this.edges_out)t.Calculate(e);return}for(let t of this.edges_in)if(t.dirty)return;this.dirty=!1;for(let t of this.edges_out)t.Calculate(e)}}};var Be=class{vertices=[[]];volatile_list=[];calculation_list=[];spill_data=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===oe.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),ge.Clear()}ResolveArrayHead(e){if(!e.sheet_id)throw new Error("resolve array head with no sheet id");let t=this.model.sheets.Find(e.sheet_id)?.cells;if(!t)throw new Error("no cells? sheet id "+e.sheet_id);let r=t.data[e.row];if(r){let n=r[e.column];if(n&&n.area){let o={row:n.area.start.row,column:n.area.start.column,sheet_id:e.sheet_id};return console.info("array head",e,o),o}}return e}*IterateVertices(e,t=!1){for(let r of cr.Iterate(e)){let n=this.GetVertex(r,t);n&&(yield n)}}GetVertex(e,t){if(!e.sheet_id)throw console.info(JSON.stringify({address:e,create:t})),console.trace(),new Error("getvertex with no sheet id");let r=this.model.sheets.Find(e.sheet_id)?.cells;if(!r)throw new Error("no cells? sheet id "+e.sheet_id);if(!this.vertices[e.sheet_id]){if(!t)return;this.vertices[e.sheet_id]=[]}if(this.vertices[e.sheet_id][e.column]){let o=this.vertices[e.sheet_id][e.column][e.row];if(o)return o;if(!t)return}else{if(!t)return;this.vertices[e.sheet_id][e.column]=[]}let n=new oe;return n.address={row:e.row,column:e.column,absolute_row:e.absolute_row,absolute_column:e.absolute_column,sheet_id:e.sheet_id},n.reference=r.EnsureCell(e),this.vertices[e.sheet_id][e.column][e.row]=n,ge.CreateImplicitEdges(n,e),n}RemoveVertex(e){if(!e.sheet_id)throw new Error("removevertex with no sheet id");let t=this.GetVertex(e,!1);t&&(t.Reset(),this.vertices[e.sheet_id][e.column][e.row]=void 0)}ResetVertex(e){let t=this.GetVertex(e,!1);t&&t.Reset()}RIBcount=0;ResetInbound(e,t=!1,r=!0,n=!1){this.RIBcount++;let o=this.GetVertex(e,r);if(!o){if(t){let s=ge.GetContainingArrays(e);for(let l of s)this.SetVertexDirty(l)}return}let i=[];if(n&&(i=Array.from(o.edges_in)),o.ClearDependencies(),t&&this.SetVertexDirty(o),n){o.has_outbound_edges||this.RemoveVertex(e);for(let s of i)if(!s.has_inbound_edges&&!s.has_outbound_edges){let l=s;l.address&&this.RemoveVertex(l.address)}}}ResetLoopState(){for(let e of this.vertices)if(e){for(let t of e)if(t)for(let r of t)r&&(r.color=r.edges_out.size?0:2)}for(let e of this.leaf_vertices)e.color=2}LoopCheck(e=!1){if(!this.loop_check_required&&!e)return!1;let t=[];for(let n of this.vertices)if(n){for(let o of n)if(o)for(let i of o)i&&(i.color=i.edges_out.size?0:2,t.push(i))}let r=[];for(let n of t)if(n.color===0){for(n.color=1,r.push(n);r.length;){let o=r[r.length-1],i=!0;if(o.color!==2)for(let s of o.edges_out){if(s.color===1)return this.loop_hint=this.RenderAddress(n.address),console.info("loop detected @",this.loop_hint),!0;s.color===0&&(r.push(s),i=!1)}i&&(r.pop(),o.color=2)}n.color=2}return this.loop_check_required=!1,this.loop_hint=void 0,!1}RenderAddress(e){if(!e)return"undefined";let t="";if(e.sheet_id){let n=this.model.sheets.Find(e.sheet_id);n&&(t=n.name+"!")}let r=new z(e);return t+r.spreadsheet_label}CompositeAddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let[r,n]=ge.GetVertex(e);if(t.DependsOn(r),this.loop_check_required=!0,!n)return;let o=this.vertices[e.start.sheet_id];if(o){if(e.entire_row){for(let i=0;i<o.length;i++)if(o[i])for(let s=e.start.row;s<=e.end.row;s++){let l=o[i][s];l&&r.DependsOn(l)}}else if(e.entire_column){for(let i=e.start.column;i<=e.end.column;i++)if(o[i])for(let s of o[i])s?.address&&r.DependsOn(s)}else for(let i=e.start.row;i<=e.end.row;i++)for(let s=e.start.column;s<=e.end.column;s++)if(o[s]){let l=o[s][i];l&&r.DependsOn(l)}}}AddLeafVertexArrayEdge(e,t){this.CompositeAddArrayEdge(e,t)}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0);this.CompositeAddArrayEdge(e,r)}AddEdge(e,t){let r=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(r),r.reference&&r.reference.area&&!r.array_head&&this.AddEdge({...e,row:r.reference.area.start.row,column:r.reference.area.start.column},t),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),n=this.GetVertex(t,!1);!r||!n||(r.RemoveDependent(n),n.RemoveDependency(r))}SetAreaDirty(e){if(e.start.column===1/0||e.end.column===1/0||e.start.row===1/0||e.end.row===1/0)throw new Error("don't iterate over infinite area");let t=e.start.sheet_id;if(!t)throw new Error("invalid area, missing sheet id");for(let r=e.start.column;r<=e.end.column;r++)for(let n=e.start.row;n<=e.end.row;n++){let o={row:n,column:r,sheet_id:t};this.GetVertex(o,!1)&&this.SetDirty(o)}}SetVertexDirty(e){if(!e.dirty){this.dirty_list.push(e),e.dirty=!0;for(let t of e.edges_out)this.SetVertexDirty(t)}}SetDirty(e){let t=this.GetVertex(e,!0);this.SetVertexDirty(t)}AddLeafVertex(e){this.leaf_vertices.add(e)}RemoveLeafVertex(e){this.leaf_vertices.delete(e)}AddLeafVertexEdge(e,t){let r=this.GetVertex(e,!0);return t.DependsOn(r),0}RemoveLeafVertexEdge(e,t){let r=this.GetVertex(e,!1);r&&(r.RemoveDependent(t),t.RemoveDependency(r))}InitializeGraph(){for(let e of this.dirty_list)this.IsSpreadsheetVertex(e)&&(e.TakeReferenceValue(),this.CheckVolatile(e)&&this.volatile_list.push(e)),e.dirty=!1;this.dirty_list=[]}Recalculate(){for(let e of this.volatile_list)this.SetVertexDirty(e);this.spill_data=this.spill_data.filter(({area:e,vertex:t})=>{if(t.dirty){t.Reset();let r=e.start.sheet_id?this.model.sheets.Find(e.start.sheet_id)?.cells:void 0;if(r)for(let{cell:n,row:o,column:i}of r.IterateRC(new z(e.start,e.end)))n.spill&&(n.spill=void 0,typeof n.value>"u"&&n.Reset()),this.SetDirty({row:o,column:i,sheet_id:e.start.sheet_id});return!1}return!0}),this.calculation_list=this.dirty_list.slice(0),this.volatile_list=[],this.dirty_list=[],this.loop_check_required&&(this.ResetLoopState(),this.loop_check_required=!1);for(let e=0;e<this.calculation_list.length;e++)this.calculation_list[e].Calculate(this);this.calculation_list=[]}};var Cn=a=>{let e={m:a,n:a,array:[]};for(let t=0;t<a;t++){let r=[];for(let n=0;n<a;n++)r.push({real:0,imaginary:0});e.array.push(r)}return e};var _n=a=>{let{r:e,theta:t}=a,r=e*Math.cos(t),n=e*Math.sin(t);return{real:r,imaginary:n}},$e=a=>{let e=Math.sqrt(a.real*a.real+a.imaginary*a.imaginary),t=Math.atan2(a.imaginary,a.real);return{r:e,theta:t}},fr=a=>{let e={real:Math.sinh(a.real)*Math.cos(a.imaginary),imaginary:Math.cosh(a.real)*Math.sin(a.imaginary)},t={real:Math.cosh(a.real)*Math.cos(a.imaginary),imaginary:Math.sinh(a.real)*Math.sin(a.imaginary)};return ce(e,t)},gr=a=>ce({real:Math.tan(a.real),imaginary:Math.tanh(a.imaginary)},{real:1,imaginary:-(Math.tan(a.real)*Math.tanh(a.imaginary))}),vr=a=>({real:Math.cosh(a.real)*Math.cos(a.imaginary),imaginary:Math.sinh(a.real)*Math.sin(a.imaginary)}),yr=a=>({real:Math.cos(a.real)*Math.cosh(a.imaginary),imaginary:Math.sin(a.real)*Math.sinh(a.imaginary)}),xr=a=>({real:Math.sinh(a.real)*Math.cos(a.imaginary),imaginary:Math.cosh(a.real)*Math.sin(a.imaginary)}),Ge=a=>({real:Math.sin(a.real)*Math.cosh(a.imaginary),imaginary:Math.cos(a.real)*Math.sinh(a.imaginary)}),xt=a=>{if(a.imaginary===0)return{real:Math.asin(a.real),imaginary:0};let e=Math.hypot(a.real+1,a.imaginary)/2,t=Math.hypot(a.real-1,a.imaginary)/2,r=e+t,n=e-t,o={real:Math.asin(n),imaginary:Math.log(r+Math.sqrt(r*r-1))};return(a.imaginary<0||a.imaginary===0&&a.real>1)&&(o.imaginary=-o.imaginary),o},wr=a=>{if(a.imaginary===0)return{real:Math.acos(a.real),imaginary:0};let e=xt(a);return{real:Math.PI/2-e.real,imaginary:e.imaginary}},Cr=a=>{let{real:e,imaginary:t}=a;if(e===0){if(t>1)return{real:Math.PI/2,imaginary:.5*Math.log((t-1)/(t+1))};if(t<-1)return{real:-Math.PI/2,imaginary:.5*Math.log((1-t)/(-1-t))}}let r=e*e,n=t*t,o=.5*Math.atan2(2*e,1-r-n),i=.25*Math.log((r+(t+1)*(t+1))/(r+(t-1)*(t-1)));return{real:o,imaginary:i}},_r=(a,e)=>{if(e.real===0&&e.imaginary===0&&a.real===0&&a.imaginary===0)return!1;let t=e.real*e.real+e.imaginary*e.imaginary,r={real:(a.real*e.real+a.imaginary*e.imaginary)/t,imaginary:(a.imaginary*e.real-a.real*e.imaginary)/t},n=r.real*r.real,o=r.imaginary*r.imaginary,i={real:.5*Math.atan2(2*r.real,1-n-o),imaginary:.25*Math.log((n+(r.imaginary+1)*(r.imaginary+1))/(n+(r.imaginary-1)*(r.imaginary-1)))};return e.real<0&&(i.real+=a.real>=0||a.imaginary>=0?Math.PI:-Math.PI),i},kr=(...a)=>{let e=a.shift();if(!e)return{real:0,imaginary:0};for(let t of a)e=H(e,t);return e},H=(a,e)=>({real:a.real*e.real-a.imaginary*e.imaginary,imaginary:a.real*e.imaginary+a.imaginary*e.real}),kn=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<a.n;o++)n.push(a.array[r][o]+e.array[r][o]);t.push(n)}return{m:a.m,n:a.n,array:t}},yt=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<e.n;o++){let i=0;for(let s=0;s<a.n;s++)i+=a.array[r][s]*e.array[s][o];n.push(i)}t.push(n)}return{array:t,m:a.m,n:e.n}},Sr=(a,e)=>{let t=[];for(let r=0;r<a.m;r++){let n=[];for(let o=0;o<e.n;o++){let i={real:0,imaginary:0};for(let s=0;s<a.n;s++)i.real+=a.array[r][s].real*e.array[s][o].real-a.array[r][s].imaginary*e.array[s][o].imaginary,i.imaginary+=a.array[r][s].real*e.array[s][o].imaginary+a.array[r][s].imaginary*e.array[s][o].real;n.push(i)}t.push(n)}return t},je=a=>{let e={real:0,imaginary:0},t=a.n;if(t==2){let n=H(a.array[0][0],a.array[1][1]),o=H(a.array[1][0],a.array[0][1]);return{real:n.real-o.real,imaginary:n.imaginary-o.imaginary}}let r=Cn(a.n);for(let n=0;n<t;n++){let o=0;for(let l=1;l<t;l++){let c=0;for(let u=0;u<t;u++)u!=n&&(r.array[o][c]={...a.array[l][u]},c++);o++}r.m=r.n=t-1;let i=Math.pow(-1,n),s=H({real:a.array[0][n].real*i,imaginary:a.array[0][n].imaginary*i},je(r));e.real+=s.real,e.imaginary+=s.imaginary}return e};var Sn=a=>{let e={real_values:!1,imaginary_values:!1,square:a.m===a.n,unit_diagonal:!0},t={m:a.m,n:a.n,array:[]},r={m:a.m,n:a.n,array:[]};for(let n=0;n<a.m;n++){let o=a.array[n],i=[],s=[];for(let l=0;l<a.n;l++)o[l].real&&(e.real_values=!0),o[l].imaginary&&(e.imaginary_values=!0),l===n&&e.unit_diagonal&&(o[l].real!==1||o[l].imaginary!==0)&&(e.unit_diagonal=!1),i.push(o[l].real),s.push(o[l].imaginary);t.array.push(i),r.array.push(s)}return{real:t,imaginary:r,flags:e}},Mn=a=>{let e=a.array.map(t=>t.slice(0));return{m:a.m,n:a.n,array:e}},hr=a=>{if(a.m!==a.n)return;let e=Mn(a),t=e.array,r=0,n=0,o=0,i=0,s=a.m;for(n=1;n<s;n++)t[0][n]/=t[0][0];for(n=1;n<s;n++){for(o=n;o<s;o++){for(r=0,i=0;i<n;i++)r+=t[o][i]*t[i][n];t[o][n]-=r}if(n!=s-1)for(o=n+1;o<s;o++){for(r=0,i=0;i<n;i++)r+=t[n][i]*t[i][o];t[n][o]=(t[n][o]-r)/t[n][n]}}for(n=0;n<s;n++)for(o=n;o<s;o++){let l=1;if(n!=o)for(l=0,i=n;i<o;i++)l-=t[o][i]*t[i][n];t[o][n]=l/t[o][o]}for(n=0;n<s;n++)for(o=n;o<s;o++)if(n!=o){for(r=0,i=n;i<o;i++)r+=t[i][o]*(n==i?1:t[n][i]);t[n][o]=-r}for(n=0;n<s;n++)for(o=0;o<s;o++){for(r=0,i=n>o?n:o;i<s;i++)r+=(o==i?1:t[o][i])*t[i][n];t[o][n]=r}return e},Mr=a=>{let e=[];if(a.m!==a.n)return;let{real:t,imaginary:r,flags:n}=Sn(a),o=hr(t);if(!o)return;if(!n.imaginary_values){for(let d=0;d<a.m;d++){let m=[];for(let b=0;b<a.n;b++)m.push({real:o.array[d][b],imaginary:0});e.push(m)}return e}let i=yt(o,r),s=yt(r,i),l=kn(t,s),c=hr(l);if(!c)return;let u=yt(i,c);for(let d=0;d<a.m;d++){let m=[];for(let b=0;b<a.n;b++)m.push({real:c.array[d][b],imaginary:-u.array[d][b]});e.push(m)}return e},ce=(a,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=H(a,t),n=H(e,t);return{real:r.real/n.real,imaginary:r.imaginary/n.real}},ze=a=>{let e=a.real||0,t=a.imaginary||0;return H({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},wt=a=>{let e=$e(a);return{real:Math.log(e.r),imaginary:e.theta}},J=(a,e)=>{if(e.imaginary)return ze(H(e,wt(a)));{let t=$e(a);return _n({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var Vr=(a,e=0)=>a&&a.type===8?a:{type:8,value:{real:e,imaginary:0}},ve=a=>a.imaginary?{type:8,value:a}:{type:3,value:a.real},ye=(a,e)=>{if(a.type===7)return[0,0,a];if(e.type===7)return[0,0,e];let t=[0,0];switch(a.type){case 3:t[0]=a.value;break;case 4:t[0]=a.value?1:0;break;case 0:break;case 8:t[3]=a;break;default:return[0,0,k()]}switch(e.type){case 3:t[1]=e.value;break;case 4:t[1]=e.value?1:0;break;case 0:break;case 8:t[4]=e;break;default:return[0,0,k()]}return(t[3]||t[4])&&(t[3]=Vr(t[3],t[0]),t[4]=Vr(t[4],t[1])),t},Vn=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve({real:o.value.real+i.value.real,imaginary:o.value.imaginary+i.value.imaginary}):{value:t+r,type:3})},kt=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve({real:o.value.real-i.value.real,imaginary:o.value.imaginary-i.value.imaginary}):{value:t-r,type:3})},Un=(a,e)=>{let[t,r,n,o,i]=ye(a,e);if(n)return n;if(o&&i)return ve(J(o.value,i.value));let s=Math.pow(t,r);return isNaN(s)?k():{type:3,value:s}},An=(a,e)=>{let[t,r,n,o,i]=ye(a,e);if(n)return n;if(o&&i)return ve(J(o.value,i.value));if(t<0&&r!==0&&Math.abs(r)<1)return ve(J({real:t,imaginary:0},{real:r,imaginary:0}));let s=Math.pow(t,r);return isNaN(s)?k():{type:3,value:s}},Ct=Un,Rn=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?ve(H(o.value,i.value)):{value:t*r,type:3})},En=(a,e)=>{let[t,r,n,o,i]=ye(a,e);return n||(o&&i?i.value.real===0&&i.value.imaginary===0?W():ve(ce(o.value,i.value)):r===0?W():{value:t/r,type:3})},zn=(a,e)=>{let[t,r,n]=ye(a,e);return n||(r===0?W():{value:t%r,type:3})},_t=(a,e)=>a.type===7?a:e.type===7?e:a.type===0&&(e.value===""||e.value===0||e.type===8&&e.value.real===0&&e.value.imaginary===0)||e.type===0&&(a.value===""||a.value===0||a.type===8&&a.value.real===0&&a.value.imaginary===0)?{type:4,value:!0}:a.type===8?e.type===8?{type:4,value:a.value.imaginary===e.value.imaginary&&a.value.real===e.value.real}:{type:4,value:!a.value.imaginary&&a.value.real===e.value}:e.type===8?{type:4,value:!e.value.imaginary&&a.value===e.value.real}:a.type===2&&e.type===2?{type:4,value:a.value.toLowerCase()===e.value.toLowerCase()}:{type:4,value:a.value==e.value},Ur=(a,e)=>{let t=_t(a,e);return t.type===7?t:{type:4,value:!t.value}},Tn=(a,e)=>a.type===7?a:e.type===7?e:a.type===8||e.type===8?k():{type:4,value:(a.value||0)>(e.value||0)},St=(a,e)=>!(a.type===8||a.type===9||a.type===10||a.type===5||e.type===8||e.type===9||e.type===10||e.type===5),Dn=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)>=(e.value||0)}:k(),Ln=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)<(e.value||0)}:k(),Fn=(a,e)=>a.type===7?a:e.type===7?e:St(a,e)?{type:4,value:(a.value||0)<=(e.value||0)}:k(),Ar=()=>{Ct=An},Rr=a=>{switch(a){case"+":return Vn;case"-":return kt;case"*":return Rn;case"/":return En;case"^":return Ct;case"**":return Ct;case"%":return zn;case"=":return _t;case"==":return _t;case"!=":return Ur;case"<>":return Ur;case">":return Tn;case">=":return Dn;case"<":return Ln;case"<=":return Fn}};var Mt=a=>!Array.isArray(a)&&a.type===5&&!!a.value.type,$=a=>a.type===5&&a.key==="metadata",Xe=class{constructor(e,t,r){this.data_model=e;this.library=t;this.parser=r}context={address:{row:-1,column:-1},volatile:!1,bindings:[]};Calculate(e,t,r,n=!1){return n||(this.context.address=t,this.context.volatile=!1,this.context.area=r),{value:this.CalculateExpression(e),volatile:this.context.volatile}}CellFunction2(e){if(!e.sheet_id)if(e.sheet)e.sheet_id=this.data_model.sheets.ID(e.sheet)||0;else return()=>D();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>D();let r=t.GetCell(e);return r?e.spill&&r.spill&&r.spill.start.row===e.row&&r.spill.start.column===e.column?()=>r.spill?t.GetRange4(r.spill.start,r.spill.end,!0)||D():pr():()=>r.GetValue4():()=>({type:3,value:0})}CellFunction4(e,t){return e.sheet_id?this.data_model.sheets.Find(e.sheet_id)?.cells?.GetRange4(e,t,!0)||D():D()}GetMetadata(e,t){let r,n;switch(e.type){case"address":if(e.spill){let o;if(e.sheet_id&&(o=this.data_model.sheets.Find(e.sheet_id)),!o)return console.error("missing sheet [da6]"),D();let i=o.CellData(e);i.spill&&(n=i.spill)}else r=e;break;case"range":n=e;break;case"structured-reference":{let o=this.data_model.ResolveStructuredReference(e,this.context.address);o&&(o.type==="address"?r=o:o.type==="range"&&(n=o))}break;case"identifier":{let o=this.data_model.GetName(e.name,this.context.address.sheet_id||0);o?.type==="range"&&(o.area.count===1?r=o.area.start:n=o.area)}break;case"call":{let o=this.CalculateExpression(e,!0);if(Mt(o))if(o.value.type==="address")r=o.value;else if(o.value.type==="range")n=o.value;else return o;else return o}break;default:return this.CalculateExpression(e)}if(r){let o;if(r.sheet_id&&(o=this.data_model.sheets.Find(r.sheet_id)),!o)return console.error("missing sheet [ac8]"),D();let i=o.CellData(r),s=i.calculated_type?i.calculated:i.value,l={type:"metadata",address:{...r,position:0,id:0,type:"address",label:new z(r).spreadsheet_label},value:s,format:i.style?i.style.number_format:void 0,...t(i,r)};return{type:5,value:l,key:"metadata"}}else if(n){if(n.start.row===1/0||n.start.column===1/0)return D();let o;if(n.start.sheet_id&&(o=this.data_model.sheets.Find(n.start.sheet_id)),!o)throw new Error("missing sheet [ac9]");let i=[];for(let s=n.start.column;s<=n.end.column;s++){let l=[];for(let c=n.start.row;c<=n.end.row;c++){let u=o.CellData({row:c,column:s});r={...n.start,row:c,column:s};let d=u.calculated_type?u.calculated:u.value,m={type:"metadata",address:r,value:d,format:u.style?u.style.number_format:void 0,...t(u,r)};l.push({type:5,value:m,key:"metadata"})}i.push(l)}return{type:9,value:i}}return this.CalculateExpression(e)}RewriteMacro(e,t){let r;switch(e.type){case"identifier":if(r=t[e.name.toUpperCase()],r)return JSON.parse(JSON.stringify(r));break;case"binary":e.left=this.RewriteMacro(e.left,t),e.right=this.RewriteMacro(e.right,t);break;case"unary":e.operand=this.RewriteMacro(e.operand,t);break;case"group":e.elements=e.elements.map(n=>this.RewriteMacro(n,t));break;case"call":e.args=e.args.map(n=>this.RewriteMacro(n,t));break}return e}CallMacro(e,t){if(!t.expression)return()=>q();let r=JSON.stringify(t.expression),n={},o=t.argument_names?.map(i=>i.toUpperCase())||[];return i=>{let s=JSON.parse(r);for(let l=0;l<o.length;l++)n[o[l]]=i.args[l]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(s,n))}}ImplicitCallTail(e,t){let r=e.value;if(!r.func||!r.bindings)return q();let n={};for(let i=0;i<r.bindings.length;i++){let s=r.bindings[i];if(s?.type==="identifier")n[s.name.toUpperCase()]=t[i]||{type:"missing"};else return q()}let o=JSON.parse(JSON.stringify(r.func));return this.parser.Walk2(o,i=>{if(i.type==="identifier"){let s=i.name.toUpperCase(),l=n[s];if(l)return JSON.parse(JSON.stringify(l))}return!0}),this.CalculateExpression(o)}Apply(e,t){let r=t.map(n=>{switch(n.type){case 3:case 4:case 2:return{type:"literal",value:n.value,id:0,position:0};case 7:return{type:"literal",value:"#"+n.value,id:0,position:0};case 9:{let o=[];for(let i=0;i<n.value.length;i++){let s=n.value[i],l=[];for(let c=0;c<s.length;c++){let u=s[c];switch(u.type){case 4:case 3:case 2:l.push(u.value||void 0);break;default:console.warn("unhandled array value",u),l.push(void 0)}}o.push(l)}return{type:"array",values:o,id:0,position:0}}case 0:return{type:"missing",id:0};default:console.warn("unhandled parameter value",n)}return{type:"missing",id:0}});return this.ImplicitCallTail(e,r)}ImplicitCall(){return e=>{e.type==="call"&&(e={type:"implicit-call",args:e.args,call:{type:"identifier",name:e.name,position:e.position,id:0},position:e.position,id:0});let t=this.CalculateExpression(e.call);return t.type===6?this.ImplicitCallTail(t,e.args):q()}}NormalizeBindings(e){let t={};for(let[r,n]of Object.entries(e))t[r.toUpperCase()]=n;return t}CallExpression(e,t=!1){let r=this.library.Get(e.name);if(!r){let n=e.name.toUpperCase();return this.LookupBinding(n)?this.ImplicitCall():this.data_model.GetName(n,this.context.address.sheet_id||0)?this.ImplicitCall():()=>vt()}return n=>{this.context.volatile=this.context.volatile||!!r.volatile;let o=e.name.toLowerCase()==="if",i=-1,s,l=n.args,c=r.arguments||[],u;r.create_binding_context&&(u=r.create_binding_context.call(0,{args:n.args,descriptors:c}),u?(l=u.args,u.argument_descriptors&&(c=u.argument_descriptors),this.context.bindings.unshift(this.NormalizeBindings(u.context))):s=_());let d=l.map((p,h)=>{if(s)return;let f=c[Math.min(h,c.length-1)]||{};if(f.passthrough)return p;if(h===i)return f.boxed?{type:0}:void 0;if(typeof p>"u")return o&&h===0&&(i=1),f.boxed?{type:0}:void 0;if(f.address)return f.boxed?{type:2,value:this.parser.Render(p).replace(/\$/g,"")}:this.parser.Render(p).replace(/\$/g,"");if(f.metadata)return this.GetMetadata(p,()=>({}));{let y=this.CalculateExpression(p);if(y.type===7){if(f.allow_error)return y;s=y;return}if(o&&h===0&&y.type!==9){let x=!1;if(y.type===2){let v=y.value.toLowerCase().trim();x=v!=="false"&&v!=="f"}else x=!!y.value;i=x?2:1}return f.boxed?y:y.type===9?y.value.map(x=>x.map(v=>v.value)):y.value}});if(u&&this.context.bindings.shift(),s)return s;let m={address:{...this.context.address},area:this.context.area?{start:{...this.context.area.start},end:{...this.context.area.end}}:void 0,apply:r.fp?this.Apply.bind(this):void 0},b=r.fn.apply(m,d);if(r.return_type==="reference"){if(t)return b;if(Mt(b)){if(b.value.type==="address")return this.CellFunction2(b.value)();if(b.value.type==="range")return this.CellFunction4(b.value.start,b.value.end)}return b}return b}}ResolveStructuredReference(e){let t=this.data_model.ResolveStructuredReference(e,this.context.address);if(t){if(t.type==="address")return this.CellFunction2(t);if(t.type==="range")return()=>this.CellFunction4(t.start,t.end)}return()=>D()}ResolveDimensionedQuantity(){return e=>{let t=this.CalculateExpression(e.expression);return{type:10,value:{value:t.value,unit:e.unit.name}}}}UnaryExpression(e,t=!1){switch(e.operator){case"+":return r=>this.CalculateExpression(r.operand);case"-":{let r=kt,n={type:3,value:0};return o=>{let i=this.CalculateExpression(o.operand);return i.type===9?{type:9,value:i.value.map(s=>s.map(l=>r(n,l)))}:r(n,i)}}case"@":return r=>{let n;switch(r.operand.type){case"address":if(r.operand.spill){let i=this.CellFunction2(r.operand)();if(i.type===9){let s=this.context.address.row??-1,l=this.context.address.column??-1;if(s>=r.operand.row&&s<r.operand.row+i.value[0]?.length&&i.value.length===1){if(!t)return i.value[0][s-r.operand.row];n={...r.operand,row:s,spill:!1}}else if(l>=r.operand.column&&l<r.operand.column+i.value.length&&i.value[0]?.length===1){if(!t)return i.value[l-r.operand.column][0];n={...r.operand,column:l,spill:!1}}else return k()}}break;case"range":{let i=this.context.address.row??-1,s=this.context.address.column??-1;if(i>=r.operand.start.row&&i<=r.operand.end.row&&r.operand.start.column===r.operand.end.column)n={...r.operand.start,row:i,spill:!1};else if(s>=r.operand.start.column&&s<=r.operand.end.column&&r.operand.start.row===r.operand.end.row)n={...r.operand.start,column:s,spill:!1};else return k()}}if(n)return t?{type:5,value:n}:this.CellFunction2(n)();let o=this.CalculateExpression(r.operand);return o.type===9?o.value[0][0]:o};default:return()=>(console.warn("unexpected unary operator:",e.operator),q())}}RecycleArray(e,t,r){if(e[0].length<r){let n=e[0].length;for(let o of e)for(let i=n;i<r;i++)o[i]=o[i%n]}if(e.length<t){let n=e.length;for(let o=n;o<t;o++)e[o]=e[o%n].slice(0)}return e}ElementwiseBinaryExpression(e,t,r){let n=Math.max(t.value.length,r.value.length),o=Math.max(t.value[0].length,r.value[0].length),i=this.RecycleArray(t.value,n,o),s=this.RecycleArray(r.value,n,o),l=[];for(let c=0;c<n;c++){let u=[];for(let d=0;d<o;d++)u[d]=e(i[c][d]||{type:0},s[c][d]||{type:0});l.push(u)}return{type:9,value:l}}AsReference(e){switch(e.type){case"address":return e;case"range":if(e.start.row===e.end.row&&e.start.column===e.end.column)return e.start;break;default:{let t=this.CalculateExpression(e,!0);if(Mt(t)){if(t.value.type==="address")return t.value;if(t.value.type==="range"&&t.value.start.row===t.value.end.row&&t.value.start.column===t.value.end.column)return t.value.start}}break}}BinaryExpression(e){let t=e.operator==="&"?(r,n)=>{if(r.type===7)return r;if(n.type===7)return n;let o=[r,n].map(i=>i.type===0?"":i.type===4?i.value?this.data_model.language_model?.boolean_true||"TRUE":this.data_model.language_model?.boolean_false||"FALSE":i.value);return{type:2,value:`${o[0]}${o[1]}`}}:Rr(e.operator);return t?r=>{let n=this.CalculateExpression(r.left),o=this.CalculateExpression(r.right);return n.type===9?o.type===9?this.ElementwiseBinaryExpression(t,n,o):this.ElementwiseBinaryExpression(t,n,{type:9,value:[[o]]}):o.type===9?this.ElementwiseBinaryExpression(t,{type:9,value:[[n]]},o):t(n,o)}:e.operator===":"?r=>{let n=this.AsReference(r.left),o=this.AsReference(r.right);return n&&o?this.CellFunction4(n,o):q()}:()=>(console.info(`(unexpected binary operator: ${e.operator})`),q())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>D();let r=t.toUpperCase();switch(r){case"FALSE":return()=>({value:!1,type:4});case"TRUE":return()=>({value:!0,type:4});case"UNDEFINED":return()=>({value:void 0,type:0})}return()=>{let n=this.LookupBinding(r);if(n)return this.CalculateExpression(n);let o=this.data_model.GetName(r,this.context.address.sheet_id||0);switch(o?.type){case"range":return o.area.count===1?this.CellFunction4(o.area.start,o.area.start):this.CellFunction4(o.area.start,o.area.end);case"expression":return this.CalculateExpression(o.expression)}return vt()}}LookupBinding(e){e=e.toUpperCase();for(let t of this.context.bindings){let r=t[e];if(r)return r}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>q()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.fn)return e.fn(e);switch(e.type){case"implicit-call":return(e.fn=this.ImplicitCall())(e);case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.fn=this.CallMacro(e,r))(e):(e.fn=this.CallExpression(e,t))(e)}case"address":return(e.fn=this.CellFunction2(e))();case"range":return(e.fn=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.fn=this.BinaryExpression(e))(e);case"unary":return(e.fn=this.UnaryExpression(e,t))(e);case"identifier":return(e.fn=this.Identifier(e))();case"missing":return(e.fn=()=>({value:void 0,type:0}))();case"dimensioned":return(e.fn=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:Ae(e.value)};return(e.fn=()=>r)()}case"group":return(e.fn=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:8};return(e.fn=()=>r)()}case"structured-reference":return(e.fn=this.ResolveStructuredReference(e))();case"array":return(e.fn=()=>({type:9,value:e.values.map(r=>(Array.isArray(r)?r:[r]).map(n=>({type:Ae(n),value:n})))}))();default:return console.warn("Unhandled parse expr:",e),Oe()}}};var Ea=1e3*60*60*24;var We=a=>{let e=[],t=a.length,r=a[0].length;for(let n=0;n<r;n++){e[n]=[];for(let o=0;o<t;o++)e[n][o]=a[o][n]}return e},Vt=a=>{if(!a)return[];if(typeof a[0]>"u")return[];let e=[],t=a.length,r=a[0].length;for(let n=0;n<r;n++){e[n]=[];for(let o=0;o<t;o++)e[n][o]=a[o][n]}return e};var O=a=>{let e=[];for(let t of a)if(t?.type===9)for(let r of t.value)e=e.concat(O(r));else e.push(t);return e},F=(a,e=!1)=>Array.isArray(a)?a.reduce((t,r)=>typeof r>"u"&&!e?t:Array.isArray(r)?t.concat(F(r,e)):r instanceof Float32Array||r instanceof Float64Array?t.concat(Array.from(r)):t.concat([r]),[]):[a],P=a=>F(a).filter(e=>typeof e=="number"),Ut=(a,e=!1)=>e?a.map((t=>{switch(typeof t){case"number":case"undefined":case"string":case"boolean":return t}})):a.filter(t=>{switch(typeof t){case"number":case"undefined":case"string":case"boolean":return!0}return!1}),In=a=>!!a&&typeof a=="object"&&a.type===9,zr=(a,e)=>(...t)=>{let r=[],n=[];for(let[o,i]of t.entries())if(i&&a[o]){let s=Array.isArray(i)?i:In(i)?i.value:void 0;s&&(r[o]=s,n.length||(n=s))}return r.length?{type:9,value:n.map((o,i)=>o.map((s,l)=>{let c=t.map((u,d)=>r[d]?r[d][i][l]??{type:0}:u);return e(...c)}))}:e(...t)},Te=a=>{let e=[],t=a.length,r="[\\^$.|?*+()";for(let n=0;n<t;n++){let o=a[n];switch(o){case"*":e.push(".","*");break;case"?":e.push(".");break;case"~":o=a[++n]||"";default:for(let i=0;i<r.length;i++)if(o===r[i]){e.push("\\");break}e.push(o);break}}return e.join("")},Tr=a=>({type:2,value:a});var Ye=class{functions={};Register(...e){for(let t of e)for(let r of Object.keys(t)){if(/[^a-zA-Z0-9._]/.test(r))throw new Error("invalid function name (invalid character)");if(r.length>255)throw new Error("invalid function name (too long, > 255)");if(/^[^a-zA-Z]/.test(r))throw new Error("invalid function name (start with an ascii letter)");let n=r.toLowerCase();if(this.functions[n])throw new Error(`function name (${n}) is already in use`);let o=t[r];if(o.canonical_name=r,!o.unrolled){let i=o.arguments?.map(s=>!!s.unroll);i?.some(s=>!!s)&&(o.fn=zr(i,o.fn),o.unrolled=!0)}this.functions[n]=o}}Get(e){let t=e.toLowerCase();return this.functions[t]}List(e=!0){let t={};for(let r of Object.keys(this.functions))e&&this.functions[r].visibility==="internal"||(t[r]=this.functions[r]);return t}Alias(e,t){let r=this.Get(t);if(!r)throw new Error(`referenced function ${t} does not exist`);this.Register({[e]:{...r}})}};var De=class{static default_color="#888";static UnpackValues(e){if(Array.isArray(e)){let t=e[0];return Array.isArray(t)||t instanceof Float64Array||t instanceof Float32Array?e.reduce((r,n)=>r.concat(this.UnpackValues(n)),[]):e.map(r=>isNaN(r)?void 0:r)}else{if(e instanceof Float32Array||e instanceof Float64Array)return Array.prototype.slice.call(e);if(e&&typeof e=="object"){let r=Object.keys(e).length;if(typeof e[0]<"u"&&typeof e[(r-1).toString()]<"u"){let n=[];for(let o=0;o<r;o++)n[o]=e[o.toString()];return n}}}return[]}static SparklineCommon(e,t){let r=[],n=Qt(t.text)?t.text.text:this.default_color,o=[n,n];return Array.isArray(e.calculated)&&(r=this.UnpackValues(e.calculated[0]),typeof e.calculated[1]=="string"&&(o[0]=e.calculated[1]),typeof e.calculated[2]=="string"&&(o[1]=e.calculated[2])),{values:r,colors:o}}static RenderLine(e,t,r,n,o){let{values:i,colors:s}=this.SparklineCommon(n,o),l=.05,c=.1,u=1;Array.isArray(n.calculated)&&typeof n.calculated[2]=="number"&&(u=n.calculated[2]);let d=0,m=0,b=-1;for(let p=0;p<i.length;p++){let h=i[p];typeof h=="number"&&(b>=0?(d=Math.min(d,h),m=Math.max(m,h)):(b=p,d=m=h))}if(d===m&&(d&&(d-=1),m+=1),d!==m){let p=e*(1-2*l)/(i.length-1),h=m-d,f=t*(1-2*c),y=t*c;r.strokeStyle=s[0],r.lineWidth=u,r.lineCap="round",r.lineJoin="round",r.beginPath();let x=0;for(let v=b;v<i.length;v++){let w=i[v];if(typeof w=="number"){let g=e*l+p*v,C=t-(w-d)*f/h-y;x===0?(r.moveTo(g,C),x=1):r.lineTo(g,C)}else x=0}r.stroke()}}static RenderColumn(e,t,r,n,o){let{values:i,colors:s}=this.SparklineCommon(n,o),l=3,c=2.5,u=0,d=0,m=!1;for(let b of i)typeof b=="number"&&(m?(u=Math.min(u,b),d=Math.max(d,b)):(m=!0,u=d=b));if(u===d&&(u&&(u-=1),d+=1),i.length){let b=(e-2*l-2)/(i.length-0),p=t-2*c,h=c;if(u!==d)if(u<0&&d>0){let f=d-u,y=h+d/f*p;for(let x=0;x<i.length;x++){let v=i[x];if(typeof v=="number"){let w=l+x*b,g=Math.abs(v)/f*p;if(v>=0){r.fillStyle=s[0];let C=y-g;r.fillRect(w+2,C,b-2,g)}else{r.fillStyle=s[1];let C=y;r.fillRect(w+2,C,b-2,g)}}}}else if(d>0){r.fillStyle=s[0];let f=d-u;for(let y=0;y<i.length;y++){let x=i[y];if(typeof x=="number"){let v=l+y*b,w=Math.max(1,(x-u)/f*p),g=t-h-w;r.fillRect(v+2,g,b-2,w)}}}else{r.fillStyle=s[1];let f=d-u;for(let y=0;y<i.length;y++){let x=i[y];if(typeof x=="number"){let v=l+y*b,w=Math.max(1,Math.abs(d-x)/f*p),g=h;r.fillRect(v+2,g,b-2,w)}}}}}};var Dr=a=>{let{x:e,y:t,width:r,height:n,cell:o}=a,i={},s=3,l=Math.round(16*(a.scale||1));if(o&&r&&n&&e&&t){let c={x:s,y:n-s-l};if(o.style){switch(o.style.vertical_align){case"top":c.y=s;break;case"middle":c.y=Math.round((n-l)/2);break}switch(o.style.horizontal_align){case"right":c.x=Math.round(r-s-l);break;case"center":c.x=Math.round((r-l)/2);break}}e>=c.x&&e<=c.x+l&&t>=c.y&&t<=c.y+l&&(i.value=`=Checkbox(${o.calculated?"FALSE":"TRUE"})`,i.block_selection=!0)}return i},Lr=a=>{let{context:e,width:t,height:r,cell:n}=a,o=a.scale||1;e.lineJoin="round",e.lineCap="round";let i=3*o,s=16*o,l=i,c=r-i-s;if(n.style){switch(n.style.vertical_align){case"top":c=i;break;case"middle":c=(r-s)/2;break}switch(n.style.horizontal_align){case"right":l=t-i-s;break;case"center":l=(t-s)/2;break}}l=Math.floor(l)+.5,c=Math.floor(c)+.5;let u=Math.floor(l+s)+.5,d=Math.floor(c+s)+.5;if(n&&n.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(l,c),e.lineTo(l+16*o,c),e.lineTo(l+16*o,c+16*o),e.lineTo(l,c+16*o),e.closePath(),e.moveTo(l+15*o,c+4*o);for(let m of[[13.59,2.58],[6,10.17],[2.41,6.59],[1,8],[6,13]])e.lineTo(l+m[0]*o,c+m[1]*o);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(l,c),e.lineTo(u,c),e.lineTo(u,d),e.lineTo(l,d),e.closePath(),e.stroke();return{handled:!0}};var ue=a=>{switch(a.type){case 8:return a.value;case 3:return{real:a.value,imaginary:0};case 4:return{real:a.value?1:0,imaginary:0};case 0:return{real:0,imaginary:0}}return!1};var Fr=(a,e,t)=>{let r=new Date;return r.setMilliseconds(0),r.setSeconds(0),r.setMinutes(0),r.setHours(0),a<0||a>1e4||(a<1899&&(a+=1900),r.setFullYear(a),e<1||e>12)||(r.setMonth(e-1),t<1||t>31)?!1:(r.setDate(t),ae(r.getTime()))};var Ir=(a,e)=>{let t=new Date(fe(a)),r=t.getUTCMonth()+e,n=t.getUTCFullYear();for(t.setUTCHours(12),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);r<0;)r+=12,n--;for(;r>11;)r-=12,n++;if(t.setUTCMonth(r),t.setUTCFullYear(n),t.getUTCMonth()!==r){let i=t.getUTCDate();t=new Date(t.getTime()-i*86400*1e3)}return t},Pr=[{name:"Lookup value"},{name:"Table"},{name:"Result index"},{name:"Inexact",default:!0}],Hr=(a,e,t,r=!0,n=!1)=>{if(n&&(e=Vt(e)),t=Math.max(0,t-1),r){let o=e[t][0];if(typeof a=="number"){let i=Number(e[0][0]);if(isNaN(i)||i>a)return Y();for(let s=1;s<e[0].length&&(i=Number(e[0][s]),!(isNaN(i)||i>a));s++)o=e[t][s]}else{a=(a||"").toString().toLowerCase();let i=(e[0][0]||"").toString().toLowerCase();if(i.localeCompare(a)>0)return Y();for(let s=1;s<e[0].length&&(i=(e[0][s]||"").toString().toLowerCase(),!(i.localeCompare(a)>0));s++)o=e[t][s]}return T(o)}else{for(let o=0;o<e[0].length;o++)if(e[0][o]==a)return T(e[t][o]);return Y()}},Ze=(a,e=!1)=>{if(!a)return e;switch(a.type){case 3:return a.value;case 0:return e}return!1},ie=(a,e,t)=>({description:t,arguments:[{name:"number",boxed:!0,unroll:!0}],fn:r=>r.type===3?{type:3,value:a(r.value)}:r.type===8?{type:8,value:e(r.value)}:_()}),Or=(a,e,t)=>{if(e===t)return 0;if(e===void 0)return 1;if(t===void 0)return-1;if(typeof e=="number"&&typeof t=="number")return(e-t)*a;if(typeof e=="string"&&typeof t=="string")return e.toLocaleLowerCase().localeCompare(t.toLowerCase())*a;if(typeof e=="boolean"&&typeof t=="boolean")return e?a:-a;if(X(e)&&X(t))return 0;let r=[e,t].map(n=>{switch(typeof n){case"number":return 0;case"string":return 2;case"boolean":return 3;default:return X(n)?1:4}});return(r[0]-r[1])*a},At={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=J(a.value,{real:.5,imaginary:0});return B(e)}else{if(a.type===0||!a.value)return{type:3,value:0};if(a.type===3&&a.value<0){let e=J({real:a.value,imaginary:0},{real:.5,imaginary:0});return{type:8,value:e}}else if(a.type===3){let e=Math.sqrt(a.value);return isNaN(e)?k():{type:3,value:e}}else return k()}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(a,e)=>{if(a.type===3&&e.type===3&&(a.value>=0||e.value===0||Math.abs(e.value)>=1)){let n=Math.pow(a.value,e.value);return isNaN(n)?k():{type:3,value:n}}let t=ue(a),r=ue(e);if(t&&r){let n=J(t,r);return B(n)}return k()}}},_e={True:{fn:()=>({type:4,value:!0})},False:{fn:()=>({type:4,value:!1})},Int:{fn:a=>({type:3,value:Math.floor(a)})},Rand:{volatile:!0,fn:()=>({type:3,value:Math.random()})},RandArray:{volatile:!0,arguments:[{name:"rows"},{name:"columns"},{name:"min"},{name:"max"},{name:"integer"}],description:"Returns an array of uniformly-distributed random numbers",fn:(a=1,e=1,t=0,r=1,n=!1)=>{let o=[];if(n){let i=r-t+1;for(let s=0;s<e;s++){let l=[];for(let c=0;c<a;c++)l.push({type:3,value:Math.floor(Math.random()*i+t)});o.push(l)}}else{let i=r-t;for(let s=0;s<e;s++){let l=[];for(let c=0;c<a;c++)l.push({type:3,value:Math.random()*i+t});o.push(l)}}return{type:9,value:o}}},RandBetween:{arguments:[{name:"min"},{name:"max"}],volatile:!0,fn:(a=0,e=1)=>{if(a>e){let t=a;a=e,e=t}return{type:3,value:Math.floor(Math.random()*(e+1-a)+a)}}},Sum:{description:"Adds arguments and ranges",arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:0,imaginary:0},t=O(a);for(let r of t)switch(r.type){case 3:e.real+=r.value;break;case 4:break;case 8:e.real+=r.value.real,e.imaginary+=r.value.imaginary;break;case 7:return r}return B(e)}},SumSQ:{description:"Returns the sum of the squares of all arguments",arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:0,imaginary:0},t=O(a);for(let r of t)switch(r.type){case 3:e.real+=r.value*r.value;break;case 4:break;case 8:{let n=H(r.value,r.value);e.real+=n.real,e.imaginary+=n.imaginary}break;case 7:return r}return B(e)}},EDate:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(a,e=0)=>{if(typeof a!="number"||typeof e!="number")return _();let t=Ir(a,e);return{type:3,value:ae(t.getTime(),!1)}}},EOMonth:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(a,e=0)=>{if(typeof a!="number"||typeof e!="number")return _();let t=Ir(a,e);switch(t.getUTCMonth()){case 1:{let n=t.getUTCFullYear();n%4===0&&(n===1900||n%400===0||n%100!==0)?t.setUTCDate(29):t.setUTCDate(28)}break;case 0:case 2:case 4:case 6:case 7:case 9:case 11:t.setUTCDate(31);break;default:t.setUTCDate(30);break}return{type:3,value:ae(t.getTime(),!1)}}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:ae(new Date().getTime())})},YearFrac:{description:"Returns the fraction of a year between two dates",arguments:[{name:"Start"},{name:"End"},{name:"Basis",default:0}],fn:(a,e,t)=>{if(e<a){let o=a;a=e,e=o}let r=Math.max(0,e-a),n=360;if(t&&t<0||t>4)return _();switch(t){case 1:break;case 2:break;case 3:n=365;break}return{type:3,value:r/n}}},Date:{description:"Constructs a date from year/month/day",arguments:[{name:"year",unroll:!0},{name:"month",unroll:!0},{name:"day",unroll:!0}],fn:(a,e,t)=>{let r=Fr(a,e,t);return r===!1?_():{type:3,value:r}}},Today:{description:"Returns current day",volatile:!0,fn:()=>{let a=new Date;return a.setMilliseconds(0),a.setSeconds(0),a.setMinutes(0),a.setHours(12),{type:3,value:ae(a.getTime())}}},IfError:{description:"Returns the original value, or the alternate value if the original value contains an error",arguments:[{name:"original value",allow_error:!0,boxed:!0},{name:"alternate value"}],fn:(a,e=0)=>a&&a.type===7?{value:e,type:Ae(e)}:a},IsNA:{description:"Checks if another cell contains a #NA error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7&&t.value==="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsErr:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7&&t.value!=="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...a)=>{let e=O(a);for(let t of e)if(t.type===7)return{type:4,value:!0};return{type:4,value:!1}}},Year:{description:"Returns year from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date",unroll:!0}],fn:a=>T(new Date(fe(a)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees",unroll:!0}],fn:a=>T(a*Math.PI/180)},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians",unroll:!0}],fn:a=>T(a/Math.PI*180)},CountA:{description:"Counts cells that are not empty",fn:(...a)=>T(F(a).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...a)=>T(F(a).reduce((e,t)=>typeof t=="number"||X(t)?e+1:e,0))},Or:{fn:(...a)=>{let e=!1;a=F(a);for(let t of a)e=e||!!t;return T(e)}},And:{fn:(...a)=>{let e=!0;a=F(a);for(let t of a)e=e&&!!t;return T(e)}},Not:{arguments:[{unroll:!0,boxed:!0}],fn:a=>{let e=!1;if(a)switch(a.type){case 0:e=!1;break;case 2:case 4:case 3:e=!!a.value;break;case 7:return a}return T(!e)}},If:{arguments:[{name:"test value",boxed:!0},{name:"value if true",boxed:!0,allow_error:!0},{name:"value if false",boxed:!0,allow_error:!0}],fn:(a,e={type:4,value:!0},t={type:4,value:!1})=>{let r=e.type===9,n=t.type===9;return a.type===9?{type:9,value:a.value.map((i,s)=>i.map((l,c)=>(l.type===2?l.value.toLowerCase()!=="false"&&l.value.toLowerCase()!=="f":!!l.value)?r?e.value[s][c]:e:n?t.value[s][c]:t))}:(a.type===2?a.value.toLowerCase()!=="false"&&a.value.toLowerCase()!=="f":!!a.value)?e:t}},Fact:{description:"Returns the factorial of a number",arguments:[{name:"number",unroll:!0}],fn:a=>{a=Math.round(a);let e=1;for(;a>1;)e*=a,a--;return{type:3,value:e}}},Factdouble:{description:"Returns the double factorial of a number",arguments:[{name:"number",unroll:!0}],fn:a=>{a=Math.round(a);let e=1;for(;a>1;)e*=a,a-=2;return{type:3,value:e}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(a,e)=>{let t=ue(a),r=ue(e);if(!t||!r)return k();if(a.type===8||e.type===8)return B(J(t,r));{let n=Math.pow(t.real,r.real);return isNaN(n)?k():{type:3,value:n}}}},Mod:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e)=>e?T(a%e):W()},Large:{description:"Returns the nth numeric value from the data, in descending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(a,e)=>{if(e<=0)return _();let t=P(a);return t.sort((r,n)=>n-r),e<=t.length?{type:3,value:t[e-1]}:_()}},Small:{description:"Returns the nth numeric value from the data, in ascending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(a,e)=>{if(e<=0)return _();let t=P(a);return t.sort((r,n)=>r-n),e<=t.length?{type:3,value:t[e-1]}:_()}},Filter:{description:"Filter an array using a second array.",arguments:[{name:"source",description:"Source array"},{name:"filter",description:"Filter array"}],fn:(a,e)=>{if(typeof a>"u"||typeof e>"u")return _();Array.isArray(a)||(a=[[a]]),Array.isArray(e)||(e=[[e]]);let t=a.length,r=a[0].length,n=e.length,o=e[0].length;if(r===o){let i=[];for(let s=0;s<t;s++)i.push([]);for(let[s,l]of e[0].entries())if(l)for(let c=0;c<t;c++)i[c].push(T(a[c][s]));return{type:9,value:i}}else if(t===n){let i=[];for(let[s,[l]]of e.entries())l&&i.push(a[s].map(c=>T(c)));return{type:9,value:i}}return _()}},SortBy:{arguments:[{name:"array"},{name:"index"},{name:"order",description:"Set to -1 to sort in descending order",default:1}],fn:(a,...e)=>{if(Array.isArray(a)||(a=[[a]]),e.length<1)return _();let t=a[0]?.length||0,r=[],n=[];for(let l=0;l<e.length;l+=2){let c=l/2,u=e[l];if(Array.isArray(u)||(u=[[u]]),(u[0]?.length||0)!==t)return _();let m=1,b=e[l+1];typeof b=="number"&&b<0&&(m=-1),r[c]=m,n[c]=u[0]}let o=a[0]?.map((l,c)=>c);o.sort((l,c)=>{for(let u=0;u<r.length;u++){let d=r[u],m=n[u],b=Or(d,m[l],m[c]);if(b)return b}return 0});let i=a.length,s=[];for(let l=0;l<i;l++){let c=[];for(let u of o)c.push(T(a[l][u]));s.push(c)}return{type:9,value:s}}},Sort:{arguments:[{name:"array"},{name:"index"},{name:"order",description:"Set to -1 to sort in descending order",default:1}],fn:(a,e=1,t=1)=>{Array.isArray(a)||(a=[[a]]);let r=a[e-1];if(!r)return _();t<0?t=-1:t=1;let n=r.map((s,l)=>({value:s,index:l}));n.sort((s,l)=>Or(t,s.value,l.value));let o=a.length,i=[];for(let s=0;s<o;s++){let l=[];for(let{index:c}of n)l.push(T(a[s][c]));i.push(l)}return{type:9,value:i}}},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>a.type===9?{type:9,value:We(a.value)}:a},Max:{fn:(...a)=>({type:3,value:Math.max.apply(0,P(a))})},Min:{fn:(...a)=>({type:3,value:Math.min.apply(0,P(a))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...a)=>{let e=a.map(n=>F(n)),t=Math.max.apply(0,e.map(n=>n.length)),r=0;for(let n=0;n<t;n++)r+=e.reduce((o,i)=>{let s=i[n];return s===!0&&(s=1),typeof s=="number"?o*s:0},1);return{type:3,value:r}}},Row:{arguments:[{name:"reference",metadata:!0}],fn:function(a){if(!a)if(this?.area){let e=[];for(let t=this.area.start.column;t<=this.area.end.column;t++){let r=[];for(let n=this.area.start.row;n<=this.area.end.row;n++)r.push({type:3,value:n+1});e.push(r)}return{type:9,value:e}}else return{type:3,value:this?this.address.row+1:-1};if(a.type===9){let e=a.value,t=e[0][0];if($(t))return{type:9,value:[e[0].map((r,n)=>({type:3,value:n+t.value.address.row+1}))]}}else if($(a))return{type:3,value:a.value.address.row+1};return _()}},Column:{arguments:[{name:"reference",metadata:!0}],fn:function(a){if(!a)if(this?.area){let e=[];for(let t=this.area.start.column;t<=this.area.end.column;t++){let r=[];for(let n=this.area.start.row;n<=this.area.end.row;n++)r.push({type:3,value:t+1});e.push(r)}return{type:9,value:e}}else return{type:3,value:this?this.address.column+1:-1};if(a.type===9){let e=a.value,t=e[0][0];if($(t))return{type:9,value:e.map((r,n)=>[{type:3,value:n+t.value.address.column+1}])}}else if($(a))return{type:3,value:a.value.address.row+1};return _()}},Choose:{arguments:[{name:"Selected index"},{name:"Choice 1...",metadata:!0}],return_type:"reference",description:"Returns one of a list of choices",fn:(a,...e)=>{if(a<1||a>e.length)return k();let t=e[a-1];if($(t))return{type:5,value:t.value.address};if(t.type===9){let r=t.value,n=r.length,o=r[0].length,i=r[0][0],s=r[n-1][o-1];if(n===1&&o===1){if($(i))return{type:5,value:i.value.address}}else if($(i)&&$(s))return{type:5,value:{type:"range",position:0,id:0,label:"",start:i.value.address,end:s.value.address}}}return{...t}}},XLOOKUP:{arguments:[{name:"Lookup value"},{name:"Lookup array"},{name:"Return array",metadata:!0},{name:"Not found",boxed:!0},{name:"Match mode",default:0},{name:"Search mode",default:1}],return_type:"reference",xlfn:!0,fn:(a,e,t,r,n=0,o=1)=>{if(!t)return _();let i,s=!1;if(t.type===9){let d=t.value,m=d.length,b=d[0].length,p=d[0][0],h=d[m-1][b-1];$(p)&&$(h)?i=new z(p.value.address,h.value.address):s=!0}if(!i&&!s)return console.info("invalid range"),D();if(!Array.isArray(e))return console.info("lookup is not an array"),k();let l=e[0];if(!Array.isArray(l))return console.info("lookup is not a 2d array"),k();if(e.length!==1&&l.length!==1)return console.info("lookup array has invalid dimensions"),k();let c=e.length===1;c&&(e=Vt(e)),o<0&&e.reverse();let u=d=>{if(s&&t.type===9){let p=t.value.length,h=t.value[0]?.length||0,f=[],y=0,x=h-1,v=0,w=p-1;c?(o<0&&(d=h-1-d),y=x=d):(o<0&&(d=p-1-d),v=w=d);for(let g=v;g<=w;g++){let C=[];for(let U=y;U<=x;U++)C.push(t.value[g][U]);f.push(C)}return{type:9,value:f}}if(!i)throw new Error("invalid range");let m,b;if(c?(o<0&&(d=i.rows-1-d),d>=0&&d<i.rows&&(m={type:"address",position:0,id:1,label:"",row:i.start.row+d,column:i.start.column,sheet_id:i.start.sheet_id},b={type:"address",position:0,id:2,label:"",row:i.start.row+d,column:i.end.column,sheet_id:i.start.sheet_id})):(o<0&&(d=i.columns-1-d),d>=0&&d<i.columns&&(m={type:"address",position:0,id:1,label:"",row:i.start.row,column:i.start.column+d,sheet_id:i.start.sheet_id},b={type:"address",position:0,id:2,label:"",row:i.end.row,column:i.start.column+d,sheet_id:i.start.sheet_id})),m&&b){let p={type:"range",position:0,id:0,label:"",start:m,end:b};return{type:5,value:p}}return{type:0}};if(n===2&&typeof a!="string"&&(n=0),(n===1||n===-1)&&typeof a=="number"){let d=0,m=-1;for(let b=0;b<e.length;b++){let p=e[b][0];if(typeof p=="number"){if(p===a)return u(b);let h=Math.abs(p-a);(n===1&&p>a||n===-1&&p<a)&&(m<0||h<d)&&(d=h,m=b)}}if(m>=0)return u(m)}switch(n){case 2:{let d=Te(a?.toString()||""),m=new RegExp("^"+d+"$","i");for(let b=0;b<e.length;b++){let p=e[b][0];if(typeof p=="string"&&m.exec(p))return u(b)}}break;case 0:typeof a=="string"&&(a=a.toLowerCase());for(let d=0;d<e.length;d++){let m=e[d][0];if(typeof m=="string"&&(m=m.toLowerCase()),m===a)return u(d)}break}return r&&r.type!==0?r:Y()}},HLookup:{arguments:[...Pr],fn:(a,e,t,r=!0)=>Hr(a,e,t,r,!0)},VLookup:{arguments:[...Pr],fn:(a,e,t,r=!0)=>Hr(a,e,t,r,!1)},Product:{arguments:[{boxed:!0,name:"values or ranges",repeat:!0}],fn:(...a)=>{let e={real:1,imaginary:0};a=O(a);for(let t of a)t.type===8?e=H(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return B(e)}},Log:{arguments:[{name:"number",unroll:!0},{name:"base",unroll:!0}],fn:(a,e=10)=>({type:3,value:Math.log(a)/Math.log(e)})},Log10:{arguments:[{name:"number",unroll:!0}],fn:a=>({type:3,value:Math.log(a)/Math.log(10)})},Ln:{arguments:[{name:"number",unroll:!0}],fn:a=>({type:3,value:Math.log(a)})},"Ceiling.Math":{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0},{name:"away from zero",unroll:!0}],xlfn:!0,fn:(a,e=1,t)=>{let r=0;return t&&a<0?r=-Math.ceil(-a/e)*e:r=Math.ceil(a/e)*e,{type:3,value:r}}},"Floor.Math":{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0},{name:"away from zero",unroll:!0}],fn:(a,e=1,t)=>{let r=0;return t&&a<0?r=-Math.floor(-a/e)*e:r=Math.floor(a/e)*e,{type:3,value:r}}},Floor:{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0}],fn:(a,e=1)=>({type:3,value:Math.floor(a/e)*e})},Ceiling:{arguments:[{name:"number",unroll:!0},{name:"significance",unroll:!0}],fn:(a,e=1)=>({type:3,value:Math.ceil(a/e)*e})},Round:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*a)/t}}},RoundDown:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e),r=a>=0;return{type:3,value:r?Math.floor(t*a)/t:Math.ceil(t*a)/t}}},RoundUp:{arguments:[{unroll:!0},{unroll:!0}],fn:(a,e=0)=>{let t=Math.pow(10,e),r=a>=0;return{type:3,value:r?Math.ceil(t*a)/t:Math.floor(t*a)/t}}},Reverse:{arguments:[{boxed:!0}],fn:a=>a.type===9?(a.value.length===1?a.value[0].reverse():a.value.reverse(),a):{type:2,value:(a.value??"").toString().split("").reverse().join("")}},Exp:{arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=ze(a.value);return B(e)}return a.type!==3?k():{type:3,value:Math.exp(a.value)}}},Abs:{arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:Math.sqrt(a.value.real*a.value.real+a.value.imaginary*a.value.imaginary)}:a.type!==3?k():{type:3,value:Math.abs(a.value||0)}},Simplify:{arguments:[{name:"value",unroll:!0},{name:"significant digits",unroll:!0}],fn:(a,e=2)=>{if(e=e||2,a===0)return{type:3,value:a};let t=a<0?-1:1;a*=t;let r=Math.pow(10,Math.floor(Math.log10(a))+1-e);return{type:3,value:Math.round(a/r)*r*t}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===8){let e=J(a.value,{real:.5,imaginary:0});return B(e)}else{if(a.type===0||!a.value)return{type:3,value:0};if(a.type===3)return{type:3,value:Math.sqrt(a.value)}}return k()}},HexToDec:{arguments:[{description:"hexadecimal string",unroll:!0}],fn:a=>({type:3,value:parseInt(a,16)})},DecToHex:{arguments:[{description:"number",unroll:!0}],fn:a=>({type:2,value:a.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Dr,render:Lr,fn:a=>({value:!!a,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:a=>(De.RenderColumn(a.width,a.height,a.context,a.cell,a.style),{handled:!0}),fn:(...a)=>({type:5,value:a,key:"sparkline-data",source:"sparkline.column"})},"Sparkline.Line":{arguments:[{name:"data"},{name:"color"},{name:"line width"}],render:a=>(De.RenderLine(a.width,a.height,a.context,a.cell,a.style),{handled:!0}),fn:(...a)=>({type:5,value:a,key:"sparkline-data",source:"sparkline.line"})},UniqueValues:{arguments:[{name:"range",boxed:!0}],visibility:"internal",fn:a=>{if(a.type===9){let e=o=>{if(o)switch(o.type){case 2:case 3:case 4:return o.value;case 0:return"";default:return console.info("check",o,o.value),o.value?.toString()||""}else return""},t=new Set,r=new Set;for(let o of a.value)for(let i of o){let s=e(i);t.has(s)?r.add(s):t.add(s)}let n=[];for(let o of a.value){let i=[];for(let s of o){let l=e(s);i.push({type:4,value:!r.has(l)})}n.push(i)}return{type:9,value:n}}return{type:4,value:!0}}},Between:{arguments:[{name:"target",boxed:!0,unroll:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(a,e=0,t=1)=>({type:4,value:a.type===3&&a.value>=e&&a.value<=t})},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"},{name:"parameters"}],visibility:"internal",fn:(a,e,t,r)=>{let n=O([a]),o=0,i=0,s=0;for(let d of n){if(d.type===7)return d;d.type===3&&(o===0&&!r?(i=d.value,s=d.value):(i=Math.min(i,d.value),s=Math.max(s,d.value)),o++)}typeof t=="number"&&(s=t),typeof e=="number"&&(i=e);let l=s-i,c=1,u=1;if(a.type===9){c=a.value.length,u=a.value[0]?.length||0;let d=[];for(let m=0;m<c;m++){let b=[];for(let p=0;p<u;p++){let h=a.value[m][p];if(h.type===3){let f=0;s===i?h.value>s?f=1:h.value<s?f=0:f=.5:l>0&&(f=(h.value-i)/l),r?b.push({type:9,value:[[{type:3,value:f},{type:3,value:(0-i)/l}]]}):b.push({type:3,value:f})}else b.push({type:0})}d.push(b)}return{type:9,value:d}}else return _()}},ATan2:{arguments:[{name:"y",boxed:!0,unroll:!0},{name:"x",boxed:!0,unroll:!0}],fn:(a,e)=>{if(a.type===3&&e.type===3)return{type:3,value:Math.atan2(a.value,e.value)};if(a.type===3&&(a={type:8,value:{real:a.value,imaginary:0}}),e.type===3&&(e={type:8,value:{real:e.value,imaginary:0}}),a.type===8&&e.type===8){let t=_r(a.value,e.value);return t===!1?_():{type:8,value:t}}return _()}},Sin:ie(Math.sin,Ge),SinH:ie(Math.sinh,xr),ASin:ie(Math.asin,xt),Cos:ie(Math.cos,yr),CosH:ie(Math.cosh,vr),ACos:ie(Math.acos,wr),Tan:ie(Math.tan,gr),TanH:ie(Math.tanh,fr),ATan:ie(Math.atan,Cr),E:{fn:()=>({type:3,value:Math.E})},PI:{fn:()=>({type:3,value:Math.PI})},SQRT2:{fn:()=>({type:3,value:Math.SQRT2})},SQRT1_2:{fn:()=>({type:3,value:Math.SQRT1_2})},Sequence:{arguments:[{name:"rows",boxed:!0},{name:"columns",default:1,boxed:!0},{name:"start",default:1,boxed:!0},{name:"step",default:1,boxed:!0}],fn:(a,e,t,r)=>{let n=Ze(a,1),o=Ze(e,1),i=Ze(r,1),s=Ze(t,1);if(n===!1||o===!1||i===!1||s===!1)return _();let l=[];for(let c=0;c<o;c++){let u=[];for(let d=0;d<n;d++)u.push({type:3,value:s+d*i*o+c*i});l.push(u)}return{type:9,value:l}}}},Nr={};for(let a of Object.keys(_e))Nr[a.toLowerCase()]=a;var Pn=["ceil","pow","ln10","ln2","log10","log10e","log1p","log2","log2e","random","imul","clz32","fround","f16round"],Br={};for(let a of Pn)Br[a.toLowerCase()]=a;for(let a of Object.getOwnPropertyNames(Math)){let e=a.toLowerCase();if(Nr[e]||Br[e])continue;let t=Object.getOwnPropertyDescriptor(Math,a);if(!t)continue;let r=t.value,n=typeof r;switch(n){case"number":_e[a]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":_e[a]={fn:(...o)=>T(r(...o)),category:["Math Functions"]};break;default:console.info("unexpected type:",n,a);break}}Math.log10||(Math.log10=a=>Math.log(a)/Math.log(10));var Le=(a,e,t=0,r=0,n=0)=>n?-(t*(a/(1-Math.pow(1+a,-e))))/(1+a)-r*(1/((1+a)*((Math.pow(1+a,e)-1)/a))):-(t*a*Math.pow(1+a,e)+r*a)/(Math.pow(1+a,e)-1),Gr=(a,e,t,r=0,n=0)=>n?(1+a)*-t/a*(Math.pow(1+a,e)-1)-r*Math.pow(1+a,e):-t/a*(Math.pow(1+a,e)-1)-r*Math.pow(1+a,e),Rt=(a,e,t,r=0,n=0,o=0)=>{if(e<1)return NaN;if(e===1&&o)return 0;let i=Le(a,t,r,n,o),s=Gr(a,e-1,i,r,o)*a;return o?s/(1+a):s},$r=(a,e,t,r=0,n=0,o=0)=>Le(a,t,r,n,o)-Rt(a,e,t,r,n,o),jr={NPV:{description:"Returns the present value of a series of future cashflows",arguments:[{name:"Rate"},{name:"Cashflow",repeat:!0}],fn:(a=0,...e)=>{let t=0,r=F(e);for(let n=0;n<r.length;n++){let o=r[n];typeof o=="number"&&(t+=Math.pow(1+a,-(n+1))*o)}return{type:3,value:t}}},XNPV:{description:"returns the NPV of a nonperiodic stream of payments at a given rate",arguments:[{name:"Discount rate"},{name:"Values"},{name:"Dates"}],fn:(a,e,t)=>{if(typeof a!="number")return _();if(e=F(e),t=F(t),e.length!==t.length)return _();let r=[];for(let i of e){if(typeof i!="number")return _();r.push(i)}let n=[];for(let i of t){if(typeof i!="number")return _();n.push(Math.floor(i))}let o=0;for(let i=0;i<r.length;i++)o+=(r[i]||0)/Math.pow(1+a,(n[i]-n[0])/365);return{type:3,value:o}}},XIRR:{description:"returns the internal rate of return of a nonperiodic stream of payments",arguments:[{name:"Values"},{name:"Dates"},{name:"Guess",default:.1}],fn:(a,e,t=.1)=>{if(a=F(a),e=F(e),a.length!==e.length)return _();let r=0,n=0,o=[];for(let d of a){if(typeof d!="number")return _();d>0&&r++,d<0&&n++,o.push(d)}if(r<=0||n<=0)return _();let i=[];for(let d of e){if(typeof d!="number")return _();i.push(Math.floor(d))}let s=i[0];for(let d of i)if(d<s)return _();let l=.1,c=[{found:!1,value:0},{found:!1,value:0}],u=o.length;for(let d=0;d<100;d++){let m=0;for(let b=0;b<u;b++)m+=(o[b]||0)/Math.pow(1+t,(i[b]-i[0])/365);if(Math.abs(m)<=1e-6)return{type:3,value:t};if(m>0){if(c[0].value=c[0].found?Math.max(c[0].value,t):t,c[0].found=!0,!c[1].found){t+=l;continue}}else if(c[1].value=c[1].found?Math.min(c[1].value,t):t,c[1].found=!0,!c[0].found){t-=l;continue}t=c[0].value+(c[1].value-c[0].value)/2}return k()}},IRR:{description:"Calculates the internal rate of return of a series of cashflows",arguments:[{name:"Cashflows"},{name:"Guess",default:.1}],fn:(a,e=.1)=>{let t=F(a).map(o=>typeof o=="number"?o:0),r=.1,n=[{found:!1,value:0},{found:!1,value:0}];for(let o=0;o<50;o++){let i=0;for(let s=0;s<t.length;s++)i+=Math.pow(1+e,-(s+1))*t[s];if(Math.abs(i)<=.00125)return{type:3,value:e};if(i>0){if(n[0].value=n[0].found?Math.max(n[0].value,e):e,n[0].found=!0,!n[1].found){e+=r;continue}}else if(n[1].value=n[1].found?Math.min(n[1].value,e):e,n[1].found=!0,!n[0].found){e-=r;continue}e=n[0].value+(n[1].value-n[0].value)/2}return{type:7,value:"NUM"}}},CUMPRINC:{description:"Returns cumulative principal paid on a loan between two periods",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Start Period"},{name:"End Period"},{name:"Type",default:0}],fn:(a,e,t,r,n,o=0)=>{let i=0;for(let s=r;s<=n;s++)i+=$r(a,s,e,t,0,o);return{type:3,value:i}}},CUMIPMT:{description:"Returns cumulative interest paid on a loan between two periods",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Start Period"},{name:"End Period"},{name:"Type",default:0}],fn:(a,e,t,r,n,o=0)=>{let i=0;for(let s=r;s<=n;s++)i+=Rt(a,s,e,t,0,o);return{type:3,value:i}}},IPMT:{description:"Returns the interest portion of a payment",arguments:[{name:"Rate"},{name:"Period"},{name:"Periods"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0,o=0)=>({type:3,value:Rt(a,e,t,r,n,o)})},PPMT:{description:"Returns the principal portion of a payment",arguments:[{name:"Rate"},{name:"Period"},{name:"Periods"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0,o=0)=>({type:3,value:$r(a,e,t,r,n,o)})},Rate:{description:"Returns the interest rate of a loan",arguments:[{name:"Periods"},{name:"Payment"},{name:"Present Value",default:0},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t=0,r=0,n=0)=>{let o=.25,i=[-1,1],s=32,l=1e-6;for(let c=0;c<s;c++){let u=Le(o,a,t,r,n);if(Math.abs(u-e)<=l)return{type:3,value:o};let d=Le(i[1],a,t,r,n);e>=u&&e<=d||e>=d&&e<=u?i[0]=o:i[1]=o,o=i[0]+(i[1]-i[0])/2}return{type:3,value:o}}},FV:{description:"Returns the future value of an investment",arguments:[{name:"Rate"},{name:"Periods"},{name:"Payment"},{name:"Present Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>({type:3,value:Gr(a,e,t,r,n)})},PV:{description:"Returns the present value of an investment",arguments:[{name:"Rate"},{name:"Periods"},{name:"Payment"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>n?(t+=r*(1/((1+a)*((Math.pow(1+a,e)-1)/a))),{type:3,value:-(t+t/a*(1-Math.pow(1+a,-(e-1))))}):{type:3,value:-(r+t/a*(Math.pow(1+a,e)-1))/Math.pow(1+a,e)}},NPER:{description:"Returns the number of periods of an investment",arguments:[{name:"Rate"},{name:"Payment"},{name:"Present Value"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t=0,r=0,n=0)=>n?{type:3,value:1+(-Math.log(1+a*(1-t/-e))+Math.log(1+r*a/(-e*(1+a))))/Math.log(1+a)}:{type:3,value:(Math.log(Math.pow(1-t*a/-e,-1))+Math.log(1+r*a/-e))/Math.log(1+a)}},PMT:{description:"Returns the periodic payment of a loan",arguments:[{name:"Rate"},{name:"Periods"},{name:"Present Value"},{name:"Future Value",default:0},{name:"Type",default:0}],fn:(a,e,t,r=0,n=0)=>({type:3,value:Le(a,e,t,r,n)})}};var qr={Char:{arguments:[{name:"number"}],fn:a=>({type:2,value:String.fromCodePoint(a||32)}),category:["text"]},Code:{arguments:[{name:"string"}],fn:a=>({type:3,value:a.codePointAt(0)||0}),category:["text"]},Value:{arguments:[{name:"text"}],fn:a=>{let e=we.TryParse(a);return e.type===3?{type:3,value:e.value}:_()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(a,e="0.00####")=>({type:2,value:R.Get(e).Format(a||0)}),category:["text"]},WildcardMatch:{visibility:"internal",arguments:[{name:"text",unroll:!0},{name:"text",unroll:!0},{name:"invert"}],fn:(a,e,t=!1)=>{if(typeof a=="string"&&typeof e=="string"){let r=Te(e),n=new RegExp("^"+r+"$","i").exec(a);return{type:4,value:t?!n:!!n}}return{type:4,value:a===e||a?.toString()===e?.toString()}}},Exact:{arguments:[{name:"text",boxed:!0,unroll:!0},{name:"text",boxed:!0,unroll:!0}],category:["text"],fn:(a,e)=>({type:4,value:a?.value?.toString()===e?.value?.toString()})},Len:{arguments:[{name:"string",unroll:!0}],fn:a=>({type:3,value:a.toString().length})},Substitute:{arguments:[{name:"text"},{name:"search"},{name:"replacement"},{name:"index"}],fn:(a,e,t,r)=>{if(typeof r=="number"){if(r<1)return k();let n=1;return{type:2,value:a.replaceAll(e,(...o)=>(console.info(o),n++===r?t:e))}}else return{type:2,value:a.replaceAll(e,t)}}},Left:{arguments:[{name:"string"},{name:"count"}],fn:(a,e=1)=>({type:2,value:a.substr(0,e)}),category:["text"]},Right:{arguments:[{name:"string"},{name:"count"}],fn:(a,e=1)=>({type:2,value:a.slice(-e)}),category:["text"]},Mid:{arguments:[{name:"string"},{name:"left"},{name:"count"}],fn:(a,e=0,t=1)=>({type:2,value:a.substr(Math.max(0,e-1),t)}),category:["text"]},Search:{description:"Find a string (needle) in another string (haystack). Case-insensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(a,e,t=1)=>{if(t>=1){if(!a)return{type:3,value:t};let r=Te(a),n=new RegExp(r,"i").exec(e.substr(t-1));if(n)return{type:3,value:n.index+t}}return k()}},Find:{description:"Find a string (needle) in another string (haystack). Case-sensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(a,e,t=1)=>{if(t>=1){if(!a)return{type:3,value:t};a=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let r=new RegExp(a).exec(e.substr(t-1));if(r)return{type:3,value:r.index+t}}return k()}},Upper:{description:"Converts text to upper case",arguments:[{name:"text",unroll:!0}],fn:a=>a==null?{type:0}:{type:2,value:a.toString().toUpperCase()}},Lower:{description:"Converts text to lower case",arguments:[{name:"text",unroll:!0}],fn:a=>a==null?{type:0}:{type:2,value:a.toString().toLowerCase()}},Concat:{description:"Pastes strings together",arguments:[{name:"text",repeat:!0}],fn:(...a)=>{let t=F(a).map(r=>{let n=r?.toString()||"";return typeof r=="number"&&ee.decimal_separator===","?n.replace(/\./,","):n}).join("");return{type:2,value:t}}}},Et={Concatenate:"Concat"};var Ke=(a,e)=>({type:4,value:typeof e.value?.value===a}),Qe=[{name:"Reference",metadata:!0,unroll:!0}],Xr={IsBlank:{description:"Returns true if the reference is blank",arguments:Qe,fn:Ke.bind(0,"undefined")},IsNumber:{description:"Returns true if the reference is a number",arguments:Qe,fn:Ke.bind(0,"number")},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:Qe,fn:Ke.bind(0,"boolean")},IsText:{description:"Returns true if the reference is text",arguments:Qe,fn:Ke.bind(0,"string")}};var Wr=2220446049250313e-31,Hn=a=>{let e=1+a;return Math.log(e)-(e-1-a)/e},et=(a,e,t,r)=>{let n=2*Number.MIN_VALUE,o=0,i=1,s=1-(a+e)*t/(a+1);Math.abs(s)<n&&(s=Number.NaN),s=1/s,o=s;for(let l=1;l<=512;l++){let c=l*(e-l)*t/((a-1+2*l)*(a+2*l)),u=0;if(s=1+c*s,i=1+c/i,Math.abs(s)<n&&(s=Number.NaN),Math.abs(i)<n&&(i=Number.NaN),s=1/s,u=s*i,o*=u,c=-(a+l)*(a+e+l)*t/((a+2*l)*(a+2*l+1)),s=1+c*s,i=1+c/i,Math.abs(s)<n&&(s=Number.NaN),Math.abs(i)<n&&(i=Number.NaN),s=1/s,u=s*i,o*=u,Math.abs(u-1)<2*Wr||o*Math.abs(u-1)<r)return o}return Number.NaN},zt=(a,e,t)=>{if(e<0||t<0)return Number.NaN;if(a<=0)return 0;if(a>=1)return 1;if(a>.5)return 1-zt(1-a,t,e);let r=e/(e+t),n=0;if(a<.1){let o=(Math.log(e)+N(e)+N(t)-N(e+t)+Math.log(a))/e;o<=0?(n=Math.exp(o),n*=Math.pow(1-n,-(t-1)/e)):n=r,n>r&&(n=r)}else n=r;for(let o=0;o<64;o++){let i=a-Dt(n,e,t),s=Tt(n,e,t);if(i===0)return n;let l=i/Math.max(2*Math.abs(i/n),s),c=l,u=-((e-1)/n-(t-1)/(1-n))*l*l/2,d=c;if(Math.abs(u)<Math.abs(c)?d+=u:d*=2*Math.abs(c/u),n+d>0&&n+d<1?n+=d:n=Math.sqrt(n)*Math.sqrt(r),Math.abs(c)<=1e-10*n)return n}return n},N=a=>{let e=a-1,t=e+5.5;t-=(e+.5)*Math.log(t);let r=1,n=[76.18009173,-86.50532033,24.01409822,-1.231739516,.00120858003,-536382e-11];for(let o of n)r+=o/++e;return-t+Math.log(2.50662827465*r)},Tt=(a,e,t)=>a<0||a>1?0:Math.exp(N(e+t)-N(e)-N(t))*Math.pow(a,e-1)*Math.pow(1-a,t-1),Dt=(a,e,t)=>{if(a<=0)return 0;if(a>=1)return 1;let n=-(N(e)+N(t)-N(e+t))+e*Math.log(a)+t*Hn(-a),o=Math.exp(n);if(a<(e+1)/(e+t+2)){let i=et(e,t,a,0);return o*i/e}else{let i=Math.abs(t/o)*Wr,s=et(t,e,1-a,i);return 1-o*s/t}},Jr=(a,e,t)=>{if(a<0||a>1)return 0;let r=a===0||a===1?0:Math.exp(N(e+t)-N(e)-N(t)+e*Math.log(a)+t*Math.log(1-a));return a<(e+1)/(e+t+2)?r*et(e,t,a,0)/e:1-r*et(t,e,1-a,0)/t};var Yr=a=>{let e=a-1,t=e+5.5;t-=(e+.5)*Math.log(t);let r=1,n=[76.18009173,-86.50532033,24.01409822,-1.231739516,.00120858003,-536382e-11];for(let o of n)r+=o/++e;return-t+Math.log(2.50662827465*r)},On=(a,e)=>{let t=Yr(a);if(e===0)return 0;let r=a,n=1/a,o=n;for(let i=1;i<1e3;i++)if(++r,o*=e/r,n+=o,Math.abs(o)<Math.abs(n)*3e-9)return n*Math.exp(-e+a*Math.log(e)-t);return console.error("too many iterations"),!1},Nn=(a,e)=>{let t=Yr(a),r=e+1-a,n=1/1e-30,o=1/r,i=o;for(let s=1;s<=1e3;s++){let l=-s*(s-a);r+=2,o=l*o+r,Math.abs(o)<1e-30&&(o=1e-30),n=r+l/n,Math.abs(n)<1e-30&&(n=1e-30),o=1/o;let c=o*n;if(i*=c,Math.abs(c-1)<3e-9)return Math.exp(-e+a*Math.log(e)-t)*i}return console.error("too many iterations"),!1},tt=(a,e)=>{if(e<0||a<=0)return console.error("invalid parameter"),!1;if(e<a+1)return On(a,e);{let t=Nn(a,e);return t===!1?!1:1-t}};var Fe=a=>{if(a===.5)return 0;let e=a<1&&a>.5?1-a:a,t=Math.sqrt(Math.log(1/Math.pow(e,2))),r=t-(2.515517+.802853*t+.010328*Math.pow(t,2))/(1+1.432788*t+.189269*Math.pow(t,2)+.001308*Math.pow(t,3));return a>.5?r:-r};var Lt=(a,e)=>{let t=e/(e+a*a),r=e/2,o=Jr(t,r,.5);return a>=0?1-.5*o:.5*o},Ft=(a,e)=>{let t=N((e+1)/2),r=N(e/2)+.5*Math.log(e*Math.PI),n=-((e+1)/2)*Math.log(1+a*a/e),o=t-r+n;return Math.exp(o)},It=(a,e)=>{let r=1;{let n=Fe(a),o=(Math.pow(n,3)+n)/4,i=(5*Math.pow(n,5)+16*Math.pow(n,3)+3*n)/96,s=(3*Math.pow(n,7)+19*Math.pow(n,5)+17*Math.pow(n,3)-15*n)/384,l=(79*Math.pow(n,9)+776*Math.pow(n,7)+1482*Math.pow(n,5)-1920*Math.pow(n,3)-945*n)/92160;r=n+o/e+i/Math.pow(e,2)+s/Math.pow(e,3)+l/Math.pow(e,4)}for(let n=0;n<16;n++){let o=Lt(r,e)-a;if(Math.abs(o)<1e-12)break;let i=Ft(r,e);if(i===0)break;let s=o/i,l=Math.max(-1,Math.min(1,s));r-=l}return r};var Kr=a=>{let e=.254829592,t=-.284496736,r=1.421413741,n=-1.453152027,o=1.061405429,i=.3275911;a=Math.abs(a);let s=1/(1+i*a);return 1-((((o*s+n)*s+r)*s+t)*s+e)*s*Math.exp(-1*a*a)},Bn=Math.sqrt(2*Math.PI),Pt=(a,e,t,r)=>{let n=0;return r?n=.5*(1+(a<e?-1:1)*Kr(Math.abs(a-e)/(t*Math.sqrt(2)))):n=Math.exp(-1/2*Math.pow((a-e)/t,2))/(t*Bn),n},Ht=a=>{let e=a.length;return e%2?a[Math.floor(e/2)]:(a[e/2]+a[e/2-1])/2},Zr=(a,e=!0)=>{a.sort((n,o)=>n-o);let t=a.length,r=(n,o,i)=>{let s=o*n+i,l=s%1;if(l){let c=a[Math.floor(s)],u=a[Math.ceil(s)];return c+(u-c)*l}else return a[s]};return e?[a[0],r(.25,t-1,0),Ht(a),r(.75,t-1,0),a[t-1]]:t%1?[a[0],r(.25,t-2,0),Ht(a),r(.75,t-2,1),a[t-1]]:[a[0],r(.25,t-3,0),Ht(a),r(.75,t-3,2),a[t-1]]},rt=a=>{let e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23],t=Math.PI,r=Ge,n=ce,o=H,i=p=>({real:p,imaginary:0}),s=(p,h)=>({real:p.real+h.real,imaginary:p.imaginary+h.imaginary}),l=J,c=ze,u=p=>({real:-p.real,imaginary:-p.imaginary}),d=kr;if(a.real<.5)return n(i(t),o(r(o(i(t),a)),rt({real:1-a.real,imaginary:-a.imaginary})));a.real-=1;let m=i(e[0]);for(let p=1;p<e.length;p++)m=s(m,n(i(e[p]),s(a,i(p))));let b=s(a,i(7.5));return d(i(Math.sqrt(2*t)),l(b,s(a,i(.5))),c(u(b)),m)},$n=(a,e,t)=>{let r=rt({real:e,imaginary:0}).real;return Math.pow(a,e-1)*Math.exp(-a/t)/(r*Math.pow(t,e))},Gn=(a,e,t)=>{let r=0,n=e*10,o=1e-6,i=0;for(;n-r>o;){i++;let s=(n+r)/2,l=tt(e,r/t),c=tt(e,s/t);if(l===!1||c===!1)return!1;(c-a)*(l-a)<0?n=s:r=s}return(r+n)/2},te=(a,e=!1)=>{let t=a.length,r=0,n=0;for(let o=0;o<t;o++)r+=a[o];r/=t;for(let o=0;o<t;o++){let i=a[o]-r;n+=i*i}return e?n/(t-1):n/t},Qr={Slope:{arguments:[{name:"known_y"},{name:"known_x"}],fn:(a,e)=>{let t=P(e),r=P(a);if(t.length!==r.length)return _();let n=0,o=0,i=0,s=0;for(let c=0;c<t.length;c++){let u=t[c],d=r[c];i+=u*d,n+=u,o+=d,s+=u*u}let l=(t.length*i-n*o)/(t.length*s-n*n);return{type:3,value:l}}},Intercept:{arguments:[{name:"known_y"},{name:"known_x"}],fn:(a,e)=>{let t=P(e),r=P(a);if(t.length!==r.length)return _();let n=t.length,o=0,i=0,s=0,l=0;for(let u=0;u<n;u++){let d=t[u],m=r[u];s+=d*m,o+=d,i+=m,l+=d*d}let c=n*s-o*i;return c/=n*l-o*o,{type:3,value:(i-c*o)/n}}},Phi:{arguments:[{name:"x",boxed:!0,unroll:!0}],fn:a=>a.type===3?{type:3,value:1/Math.sqrt(Math.PI*2)*Math.exp(-a.value*a.value/2)}:_()},"Z.Test":{arguments:[{name:"Array",boxed:!0},{name:"x",boxed:!0,unroll:!0},{name:"Sigma",boxed:!0,unroll:!0}],fn:(a,e,t)=>{let r=[];if(a.type===9)for(let n of a.value)for(let o of n)o.type===3&&r.push(o.value);else a.type===3&&r.push(a.value);if(r.length&&e.type===3){let n=0,o=r.length;for(let s of r)n+=s;n/=o;let i=t?.type===3?t.value:Math.sqrt(te(r,!0));return{type:3,value:1-Pt((n-e.value)/(i/Math.sqrt(o)),0,1,!0)}}return _()}},"Beta.Dist":{description:"beta distribution",arguments:[{name:"x",unroll:!0},{name:"a"},{name:"b"},{name:"cumulative"}],fn:(a,e,t,r)=>e<0||t<0?_():r?{type:3,value:Dt(a,e,t)}:{type:3,value:Tt(a,e,t)}},"Beta.Inv":{description:"Inverse of the beta distribution",arguments:[{name:"probability",unroll:!0},{name:"a"},{name:"b"}],fn:(a,e,t)=>e<0||t<0?_():{type:3,value:zt(a,e,t)}},Erf:{fn:a=>({type:3,value:Kr(a)})},"Norm.Inv":{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"},{name:"mean",default:0},{name:"standard deviation",default:1}],xlfn:!0,fn:(a,e=0,t=1)=>({type:3,value:Fe(a)*t+e})},"Norm.S.Inv":{description:"Inverse of the standard normal cumulative distribution",arguments:[{name:"probability",unroll:!0}],xlfn:!0,fn:a=>({type:3,value:Fe(a)})},"Norm.Dist":{description:"Cumulative normal distribution",arguments:[{name:"value"},{name:"mean",default:0},{name:"standard deviation",default:1},{name:"cumulative",default:!0}],xlfn:!0,fn:(a,e=0,t=1,r=!0)=>({type:3,value:Pt(a,e,t,r)})},"Norm.S.Dist":{description:"Cumulative normal distribution",arguments:[{name:"value"},{name:"cumulative",default:!0}],xlfn:!0,fn:(a,e=!0)=>({type:3,value:Pt(a,0,1,e)})},"StDev.P":{description:"Returns the standard deviation of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:Math.sqrt(te(P(a),!1))})},"StDev.S":{description:"Returns the standard deviation of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:Math.sqrt(te(P(a),!0))})},"Var.P":{description:"Returns the variance of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:te(P(a),!1)})},"Var.S":{description:"Returns the variance of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...a)=>({type:3,value:te(P(a),!0)})},Covar:{description:"Returns the covariance between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(a,e)=>{if(!Array.isArray(a)||!Array.isArray(e))return k();if(!Array.isArray(a[0])||!Array.isArray(e[0]))return k();if(a.length!==e.length)return _();let t=0,r=0,n={x:0,y:0},o={x:[],y:[]};for(let i=0;i<a.length;i++){if(!a[i]||!e[i])continue;if(a[i].length!==e[i].length)return _();let s=a[i].length;r+=s;for(let l=0;l<s;l++)n.x+=a[i][l]||0,n.y+=e[i][l]||0,o.x.push(a[i][l]||0),o.y.push(e[i][l]||0)}if(r===0)return Y();n.x/=r,n.y/=r;for(let i=0;i<r;i++)t+=(o.x[i]-n.x)*(o.y[i]-n.y);return{type:3,value:t/r}}},Correl:{description:"Returns the correlation between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(a,e)=>{if(!Array.isArray(a)||!Array.isArray(e))return k();if(!Array.isArray(a[0])||!Array.isArray(e[0]))return k();let t=0,r=0,n=0,o=0,i=0,s=0,l=0;for(let c=0;c<a.length;c++){if(!a[c]||!e[c])continue;let u=a[c].length;for(let d=0;d<u;d++){let m=Number(a[c][d]),b=Number(e[c][d]);isNaN(m)||isNaN(b)||(r+=m*b,n+=m,o+=b,i+=m*m,s+=b*b,l++)}}return t=l*r-n*o,t&&(t/=Math.sqrt((l*i-n*n)*(l*s-o*o))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=0,t={real:1,imaginary:0},r=!1,n=!1;for(let o of a)o.type===8?(r=!0,t=H(t,o.value),e++):o.type===3&&(o.value<0&&(n=!0),e++,t.real*=o.value,t.imaginary*=o.value);if(r){let o=J(t,{real:1/e,imaginary:0});return o.imaginary?{type:8,value:o}:{type:3,value:o.real}}else return n?k():{type:3,value:Math.pow(t.real,1/e)}}},LCM:{description:"Retuns the least common mulitple of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=[];for(let n of a){if(n.type===7)return n;if(n.type===3)e.push(n.value);else if(n.type!==0)return console.info("RT",n.type),_()}let t=(n,o)=>n%o==0?o:t(o,n%o);if(e.length===0)return{type:3,value:0};let r=e[0];for(let n=1;n<e.length;n++)r=r*e[n]/t(r,e[n]);return{type:3,value:r}}},"Gamma.Inv":{description:"Returns the inverse of the gamma distribution",arguments:[{name:"probability",unroll:!0},{name:"alpha"},{name:"beta"}],fn:(a,e,t)=>{if(a<0||a>1)return _();let r=Gn(a,e,t);return r===!1?k():{type:3,value:r}}},"Gamma.Dist":{fn:(a,e,t,r)=>{if(a<0||e<=0||t<=0)return _();let n=r?tt(e,a/t):$n(a,e,t);return n===!1?k():{type:3,value:n}}},"T.DIST":{description:"Returns the left-tailed Student's t-distribution",arguments:[{name:"X",unroll:!0,boxed:!0},{name:"degrees of freedom",unroll:!0,boxed:!0},{name:"cumulative",unroll:!0,boxed:!0}],fn:(a,e,t)=>{let r=t?!!t.value:!1;return e.type!==3||a.type!==3||e.value<1?_():{type:3,value:r?Lt(a.value,e.value):Ft(a.value,e.value)}}},"T.Inv":{description:"Returns the left-tailed inverse of the Student's t-distribution",arguments:[{name:"Probability",boxed:!0,unroll:!0},{name:"Degrees of freedom",boxed:!0,unroll:!0}],fn:(a,e)=>e.type!==3||e.value<1||a.type!==3||a.value<=0||a.value>=1?_():{type:3,value:It(a.value,e.value)}},"T.Inv.2T":{description:"Returns the two-tailed inverse of the Student's t-distribution",arguments:[{name:"Probability",boxed:!0,unroll:!0},{name:"Degrees of freedom",boxed:!0,unroll:!0}],fn:(a,e)=>e.type!==3||e.value<1||a.type!==3||a.value<=0||a.value>=1?_():{type:3,value:Math.abs(It(1-a.value/2,e.value))}},GammaLn:{description:"Returns the natural log of the gamma function",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>a.type===3?{type:3,value:N(a.value)}:_()},"GammaLn.Precise":{description:"Returns the natural log of the gamma function",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>{let e;if(a.type===3?e={real:a.value,imaginary:0}:a.type===8&&(e=a.value),e){let t=rt(e);return B(wt(t))}return _()}},Gamma:{description:"Returns the gamma function for the given value",arguments:[{name:"value",boxed:!0,unroll:!0}],fn:a=>{let e={real:0,imaginary:0};if(a.type===8)e={...a.value};else if(a.type===3)e.real=a.value;else return _();if(e.imaginary===0&&e.real%1===0&&e.real<=0)return k();let t=rt(e);return Math.abs(t.imaginary)<=1e-7?{type:3,value:t.real}:{type:8,value:t}}},Delta:{arguments:[{name:"number"},{name:"number",default:0}],fn:(a,e=0)=>typeof a!="number"||typeof e!="number"?k():{type:3,value:a===e?1:0}},GCD:{description:"Finds the greatest common divisor of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e=[];for(let n of a){if(n.type===7)return n;if(n.type===3)e.push(n.value);else if(n.type!==0)return console.info("RT",n.type),_()}let t=(n,o)=>n%o==0?o:t(o,n%o);if(e.length===0)return k();if(e.length===1)return{type:3,value:e[0]};let r=e[0];for(let n=1;n<e.length;n++)r=t(r,e[n]);return{type:3,value:r}}},HarMean:{description:"Returns the harmonic mean of the arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e={real:0,imaginary:0},t=0;for(let r of a){if(r.type===7)return r;if(r.type===3&&(e.real+=1/r.value,t++),r.type===8){let n=ce({real:1,imaginary:0},r.value);e.real+=n.real,e.imaginary+=n.imaginary,t++}}return e.imaginary?{type:8,value:ce({real:t,imaginary:0},e)}:{type:3,value:t/e.real}}},Average:{description:"Returns the arithmetic mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...a)=>{a=O(a);let e={real:0,imaginary:0},t=0;for(let r of a){if(r.type===7)return r;r.type===3&&(e.real+=r.value,t++),r.type===8&&(e.real+=r.value.real,e.imaginary+=r.value.imaginary,t++)}return e.real/=t,e.imaginary/=t,e.imaginary?{type:8,value:e}:{type:3,value:e.real}}},Percentile:{description:"Returns the kth percentile value from the range of data",arguments:[{name:"range"},{name:"percentile"}],fn:(a,e)=>{let t=P(a);t.sort((l,c)=>l-c);let r=t.length,n=Math.pow(10,8),o=Math.round((1+(r-1)*e)*n)/n,i=Math.floor(o),s=Math.ceil(o);return{type:3,value:(t[i-1]+t[s-1])/2}}},"Quartile.Inc":{description:"Returns the interpolated quartile of the data set (including median)",arguments:[{name:"range"},{name:"quartile"}],xlfn:!0,fn:(a,e)=>{if(typeof e!="number"||e<0||e>4||e%1)return _();let t=P(a),r=Zr(t,!0);return{type:3,value:r[e]}}},"Quartile.Exc":{description:"Returns the interpolated quartile of the data set (excluding median)",arguments:[{name:"range"},{name:"quartile"}],xlfn:!0,fn:(a,e)=>{if(typeof e!="number"||e<1||e>3||e%1)return _();let t=P(a),r=Zr(t,!1);return{type:3,value:r[e]}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...a)=>{let e=P(a);e.sort((i,s)=>i-s);let r=1+(e.length-1)*.5,n=Math.floor(r),o=Math.ceil(r);return{type:3,value:(e[n-1]+e[o-1])/2}}},Rank:{arguments:[{name:"Value"},{name:"Source"},{name:"Order"}],fn:(a,e,t=0)=>{if(typeof a!="number")return _();let r=P(e);r.sort(t?(n,o)=>n-o:(n,o)=>o-n);for(let n=0;n<r.length;n++)if(r[n]===a)return{type:3,value:n+1};return k()}}},Ot={Mean:"Average",StDev:"StDev.S",StDevA:"StDev.S",StDevPA:"StDev.P",Var:"Var.S",Quartile:"Quartile.Inc",NormSInv:"Norm.S.Inv",NormSDist:"Norm.S.Dist",NormDist:"Norm.Dist"};var en={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0,unroll:!0}],fn:a=>({type:4,value:!!a?.value&&X(a.value.value)})},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===3?{...a}:a.type===8?{type:3,value:a.value.real||0}:a.type===0||a.type===2&&a.value===""?{type:3,value:0}:k()},Imaginary:{description:"Returns the imaginary part of a complex number (as real)",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:a.value.imaginary||0}:a.type===3||a.type===0||a.type===2&&a.value===""?{type:3,value:0}:k()},Conjugate:{description:"Returns the conjugate of a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>{let e=ue(a);return e?e.imaginary?{type:8,value:{real:e.real,imaginary:-e.imaginary}}:{type:3,value:e.real}:k()}},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0,unroll:!0}],fn:a=>a.type===8?{type:3,value:Math.atan2(a.value.imaginary,a.value.real)}:a.type===3||a.type===0||a.type===2&&a.value===""?{type:3,value:Math.atan2(0,a.value||0)}:k()},Rectangular:{description:"Converts a complex number in polar form to rectangular form",arguments:[{name:"r"},{name:"\u03B8 in radians"}],fn:(a=0,e=0)=>({type:8,value:{real:a*Math.cos(e),imaginary:a*Math.sin(e)}})},Complex:{description:"Ensures that the given value will be treated as a complex number",arguments:[{boxed:!0,unroll:!0}],fn:a=>{let e=ue(a);return e?{type:8,value:e}:k()}},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0,unroll:!0}],fn:a=>{if(a.type===3){if(!a.value)return k();a={type:8,value:{real:a.value,imaginary:0}}}else if(a.type===0||a.type===2&&a.value==="")return k();if(a.type===8){let e=$e(a.value),t={real:Math.log(e.r),imaginary:e.theta};return t.imaginary?{type:8,value:t}:{type:3,value:t.real}}return k()}}};var nt=a=>{let e=[];a.type===9?e=a.value:e=[[a]];let t=e.length,r=t?e[0].length:0,n=[];if(!t||!r)return{m:t,n:r,array:n};for(let o=0;o<t;o++){let i=[];for(let s=0;s<r;s++){let l=e[o][s];if(l.type===8)i.push({...l.value});else if(l.type===3)i.push({real:l.value,imaginary:0});else if(l.type===0||l.value==="")i.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}n.push(i)}return{m:t,n:r,array:n}},tn={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>{let e=nt(a);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return k();let t=je(e);return t?B(t):k()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:a=>{let e=nt(a);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return k();let t=je(e);if(t&&t.real===0&&t?.imaginary===0)return k();let r=Mr(e);return r?{type:9,value:r.map(n=>n.map(o=>B(o)))}:k()}},MMult:{description:"Returns the dot product A \u22C5 B",arguments:[{name:"A",boxed:!0},{name:"B",boxed:!0}],fn:(a,e)=>{let t=nt(a),r=nt(e);if(!t.array||t.error||!r.array||r.error)return k();if(t.m!==r.n)return k();let n=Sr(r,t);return{type:9,value:n.map(o=>o.map(i=>B(i)))}}}};var rn={RegexExtract:{description:"Extract text using a regular expression",arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"return mode",unroll:!0,default:0},{name:"case insensitive",unroll:!0,default:!1}],fn:(a,e="",t=0,r=!1)=>{let n=[];r&&n.push("i"),t===1&&n.push("g");let o=String(a??""),i;try{i=new RegExp(e,n.length?n.join(""):void 0)}catch{return _()}switch(t){case 0:{let s=o.match(i);return{type:2,value:s===null?"":s[0]??""}}case 1:{let s=Array.from(o.matchAll(i));return console.info({result:s}),{type:9,value:[s.map(l=>({type:2,value:l[0]||""}))]}}case 2:{let s=o.match(i);if(s===null)return{type:2,value:""};let l=Array.from(s).slice(1);return{type:9,value:[l.map(c=>({type:2,value:c}))]}}default:return _()}}},RegexReplace:{arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"replacement",unroll:!0},{name:"occurrence",unroll:!0,default:0},{name:"case insensitive",unroll:!0,default:!1}],description:"Replace text in a string using a regex",fn:(a,e,t,r=0,n=!1)=>{let o=["g"];n&&o.push("i");let i=new RegExp(e,o.length?o.join(""):void 0);if(r===0)return{type:2,value:a.replaceAll(i,t)};if(r<0){let l=Array.from(a.matchAll(i)).length;r+=l+1}let s=a.replace(i,l=>--r===0?t:l);return{type:2,value:s}}},RegexTest:{arguments:[{name:"text",unroll:!0},{name:"pattern",unroll:!0},{name:"case insensitive",unroll:!0,default:!1}],description:"Match text against a regular expression",fn:(a,e,t=!1)=>{let r=new RegExp(e,t?"i":void 0);return{type:4,value:r.test(a)}}}};var nn={Lambda:{description:"Creates a function",arguments:[{name:"Argument",repeat:!0,boxed:!0,passthrough:!0},{name:"Function",boxed:!0,passthrough:!0}],pass_through_ui:"indirect",fn:(...a)=>({type:6,value:{bindings:a.slice(0,a.length-1),func:a[a.length-1],alt:"LAMBDA",type:"function"}})},Let:{description:"Binds values to names for a calculation",arguments:[{name:"Name",repeat:!0},{name:"Value",repeat:!0},{name:"Calculation",boxed:!0}],create_binding_context:({args:a,descriptors:e})=>{if(a.length%2!==1)return;let t={};for(let r=0;r<a.length-1;r+=2){let n=a[r],o=a[r+1];if(n.type==="identifier")t[n.name]=o;else return}return{context:t,args:a.slice(-1),argument_descriptors:e.slice(-1)}},fn:a=>a||{type:0}}};var an={MakeArray:{description:"Create an array using a function",arguments:[{name:"rows"},{name:"columns"},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(a>0&&e>0&&t?.type===6){let r=this?.apply;if(!r)return k();let n=[];for(let o=0;o<e;o++){let i=[];for(let s=0;s<a;s++)i.push(r(t,[{type:3,value:s+1},{type:3,value:o+1}]));n.push(i)}return{type:9,value:n}}return _()}},ChooseCols:{description:"Returns one or more columns from an array, by column index",arguments:[{name:"array"},{name:"column",repeat:!0}],fn:function(a,...e){Array.isArray(a)||(a=[[a]]);let t=F(e),r=a.length,n=[];for(let o of t)if(typeof o=="number"){o<0?o=r+o:o--;let i=a[o];if(i){let s=[];for(let l of i)s.push(T(l));n.push(s)}else return _()}return n.length||n.push([]),{type:9,value:n}}},ChooseRows:{description:"Returns one or more rows from an array, by row index",arguments:[{name:"array"},{name:"row",repeat:!0}],fn:function(a,...e){Array.isArray(a)||(a=[[a]]);let t=F(e),r=a[0]?.length||0,n=[];for(let o of t)if(typeof o=="number"){o<0?o=r+o:o--;for(let[i,s]of a.entries()){let l=n[i]||[];if(o<0||o>=s.length)return _();l.push(T(s[o])),n[i]=l}}return n.length||n.push([]),{type:9,value:n}}},Take:{description:"Returns some number of rows/columns from the start or end of an array",arguments:[{name:"array"},{name:"rows"},{name:"columns"}],fn:function(a,e,t){if(!e&&!t||e===0||t===0||typeof e!="number"&&typeof e<"u"||typeof t!="number"&&typeof t<"u")return _();Array.isArray(a)||(a=[[a]]);let r=a.length,n=a[0].length,o=[],i=0,s=r-1,l=0,c=n-1;typeof t=="number"&&(t>0?s=Math.min(t,r)-1:t<0&&(s=r-1,i=Math.max(0,s+t+1))),typeof e=="number"&&(e>0?c=Math.min(e,n)-1:e<0&&(c=n-1,l=Math.max(0,c+e+1)));for(let u=i;u<=s;u++){let d=[];for(let m=l;m<=c;m++)d.push(T(a[u][m]));o.push(d)}return{type:9,value:o}}},Reduce:{description:"Accumulates a value by applying a function to a set of values",arguments:[{name:"initial value",boxed:!0},{name:"data",description:"Input data",boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(!this?.apply)return k();if(t.type!==6)return _();e.type!==9&&(e={type:9,value:[[e]]});let r=e.value.length,n=e.value[0].length;for(let o=0;o<n;o++)for(let i=0;i<r;i++){let s=[a,e.value[i][o]];a=this.apply(t,s)}return a}},Scan:{description:"Applies a function to a set of values, iteratively",arguments:[{name:"initial value",boxed:!0},{name:"data",description:"Input data",boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e,t){if(!this?.apply)return k();if(t.type!==6)return _();e.type!==9&&(e={type:9,value:[[e]]});let r=[],n=e.value.length,o=e.value[0].length;for(let i=0;i<n;i++)r.push([]);for(let i=0;i<o;i++)for(let s=0;s<n;s++){let l=[a,e.value[s][i]],c=this.apply(t,l);r[s][i]=c,a=c}return{type:9,value:r}}},ByRow:{description:"Apply a function to each row in an array",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e){if(!this?.apply)return k();if(e.type!==6)return _();a.type!==9&&(a={type:9,value:[[a]]});let t=a.value.length,r=a.value[0].length,n=[[]];for(let o=0;o<r;o++){let i=[];for(let s=0;s<t;s++)i.push(a.value[s][o]);n[0].push(this.apply(e,[{type:9,value:[i]}]))}return{type:9,value:n}}},ByCol:{description:"Apply a function to each column in an array",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(a,e){if(!this?.apply)return k();if(e.type!==6)return _();a.type!==9&&(a={type:9,value:[[a]]});let t=a.value.length,r=a.value[0].length,n=[];for(let o=0;o<t;o++){let i=[];for(let s=0;s<r;s++)i.push(a.value[o][s]);n.push([this.apply(e,[{type:9,value:[i]}])])}return{type:9,value:n}}},Map:{description:"Apply a function to a set of values",arguments:[{name:"data",description:"Input data",repeat:!0,boxed:!0},{name:"lambda",description:"Function to apply",boxed:!0}],fp:!0,fn:function(...a){if(a.length<2)return _();let e=a[a.length-1];if(e.type!==6)return _();let t=this?.apply;if(!t)return k();for(let o=0;o<a.length-1;o++){let i=a[o];i.type!==9&&(a[o]={type:9,value:[[i]]})}let r=a[0],n=[];if(r.type===9)for(let o=0;o<r.value.length;o++){let i=r.value[o],s=[];for(let l=0;l<i.length;l++){let c=[i[l]];for(let u=1;u<a.length-1;u++){let d=a[u];d.type===9&&c.push(d.value[o][l])}s.push(t(e,c))}n.push(s)}return{type:9,value:n}}}};var ke=class a extends oe{static type="state-leaf-vertex";state_id=0;type=a.type;color=2;Calculate(){if(this.dirty){for(let e of this.edges_in)if(e.dirty)return;this.state_id++,this.dirty=!1}}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var at=class a extends oe{static type="calculation-leaf-vertex";type=a.type;address={row:-1,column:-1};use;updated=!1;color=2;Calculate(e){if(!this.dirty)return;for(let r of this.edges_in)if(r.dirty)return;let t=e.CalculationCallback.call(e,this);this.result=t.value,this.dirty=!1,this.updated=!0}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var qn=a=>{if(typeof a=="string")switch(a=a.toUpperCase(),a){case"AVERAGE":case"MEAN":a=101;break;case"COUNT":a=102;break;case"COUNTA":a=103;break;case"MAX":a=104;break;case"MIN":a=105;break;case"PRODUCT":a=106;break;case"STDEV":a=107;break;case"STDEVP":a=108;break;case"SUM":a=109;break;case"VAR":a=110;break;case"VARP":a=111;break;default:a=0;break}return a},Xn={complex_numbers:"off",spill:!1},ot=class extends Be{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Xe(this.model,this.library,this.parser),this.options={...Xn,...r},this.options.complex_numbers==="on"){for(let i of Object.keys(At))_e[i]=At[i];Ar()}this.UpdateLocale(),this.library.Register(_e,qr,Qr,jr,Xr,en,tn,rn,nn,an);for(let i of Object.keys(Ot))this.library.Alias(i,Ot[i]);for(let i of Object.keys(Et))this.library.Alias(i,Et[i]);let n=(i,s,...l)=>{Array.isArray(s)||(s=[[s]]);let c=[];for(let b=0;b<l.length;b+=2){let p=l[b];Array.isArray(p)||(p=[[p]]);{let h=o(p,l[b+1]);if(h.type!==9)return h;for(let[f,y]of h.value[0].entries())c[f]=!!y.value&&c[f]!==!1}}let u=F(s,!0),d=0,m=0;for(let[b,p]of c.entries())if(p){d++;let h=u[b];typeof h=="number"&&(m+=h)}switch(i){case"count":return{type:3,value:d};case"sum":return{type:3,value:m};case"average":return d===0?W():{type:3,value:m/d}}},o=(i,s)=>{let l=F(i,!0),c,u,d="=";if(typeof s=="string"){s=s.trim();let b=s.match(/^([=<>]+)/);b&&(d=b[1],s=s.substring(d.length));let p=we.TryParse(s);if(p?.type===2?s=`"${p.value}"`:s=p?.value?.toString()||"",/[?*]/.test(s)){let h=this.parser.argument_separator;if(d==="="||d==="<>"){if(c=this.parser.Parse(`=WildcardMatch({}${h} ${s}${h} ${d==="<>"})`),u=c.expression,c.error||!u)return q();u?.type==="call"&&u.args[0]?.type==="array"&&(u.args[0].values=[Ut(l,!0)])}}}else s=(s||0).toString();if(!c){if(c=this.parser.Parse("{}"+d+s),u=c.expression,c.error||!u)return q();if(u.type!=="binary")return console.warn("invalid expression [1]",u),q();if(u.left.type!=="array")return console.warn("invalid expression [1]",u),q();u.right.type==="identifier"&&(console.warn("will never happen"),u.right={...u.right,type:"literal",value:u.right.name}),u.left.values=[Ut(l,!0)]}return u?this.CalculateExpression(u):k()};this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(i,...s)=>{if(i=qn(i),i>100&&(i-=100),i<1||i>11)return _();let l=O(s),c=[],u=0,d=0,m;for(let p of l){let h=p.value?.address;if(!h)return D();if(!m||m.id!==h.sheet_id){if(!h.sheet_id)return console.warn("invalid reference in metadata"),D();if(m=this.model.sheets.Find(h.sheet_id),!m)return console.warn("invalid sheet in metadata"),D()}if(!m.GetRowHeight(h.row))continue;let y=p.value?.value;typeof y>"u"||(u++,typeof y=="number"&&(d+=y,c.push(y)))}let b=0;switch(i){case 1:if(c.length===0)return W();b=d/c.length;break;case 2:b=c.length;break;case 3:b=u;break;case 4:if(c.length===0)return k();b=Math.max.apply(0,c);break;case 5:if(c.length===0)return k();b=Math.min.apply(0,c);break;case 6:if(c.length===0)return k();b=1;for(let p of c)b*=p;break;case 7:if(c.length<2)return W();b=Math.sqrt(te(c,!0));break;case 8:if(c.length===0)return W();b=Math.sqrt(te(c,!1));break;case 9:b=d;break;case 10:if(c.length<2)return W();b=te(c,!0);break;case 11:if(c.length===0)return W();b=te(c,!1);break}return{type:3,value:b}}},Cell:{description:"Returns data about a cell",arguments:[{name:"type",description:"Type of data to return",unroll:!0},{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:(i,s)=>{if(!$(s))return D();if(i)switch(i.toString().toLowerCase()){case"format":return s.value.format?{type:2,value:s.value.format}:D();case"address":{let l="";return s.value.address.sheet_id&&(l=this.model.sheets.Find(s.value.address.sheet_id)?.name||""),l&&(Ue.test(l)&&(l=`'${l}'`),l+="!"),{type:2,value:"[]"+l+s.value.address.label.replace(/\$/g,"")}}}return{type:7,value:br.error}}},Address:{arguments:[{name:"row"},{name:"column"},{name:"absolute"},{name:"a1"},{name:"sheet name"}],fn:(i=1,s=1,l=1,c=!0,u)=>{let d={type:"address",id:0,position:0,label:"",row:i-1,column:s-1};switch(l){case 2:d.absolute_row=!0;break;case 3:d.absolute_column=!0;break;case 4:break;default:d.absolute_column=!0,d.absolute_row=!0}return u&&(d.sheet=u),Tr(this.parser.Render(d,{r1c1:!c}))}},CountIfs:{arguments:[{name:"range"},{name:"criteria"},{name:"range"},{name:"criteria"}],fn:(...i)=>n("count",i[0],...i)},AverageIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s,l)=>n("average",l||i,i,s)},AverageIfs:{arguments:[{name:"value range"},{name:"criteria range"},{name:"criteria"},{name:"criteria range"},{name:"criteria"}],fn:(i,...s)=>n("average",i,...s)},SumIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s,l)=>n("sum",l||i,i,s)},SumIfs:{arguments:[{name:"value range"},{name:"criteria range"},{name:"criteria"},{name:"criteria range"},{name:"criteria"}],fn:(i,...s)=>n("sum",i,...s)},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(i,s)=>n("count",i,i,s)},Offset:{arguments:[{name:"reference",description:"Base reference",metadata:!0},{name:"rows",description:"number of rows to offset"},{name:"columns",description:"number of columns to offset"},{name:"height"},{name:"width"}],return_type:"reference",volatile:!0,fn:((i,s=0,l=0,c,u)=>{if(!i)return _();if(i.type===9){let m=typeof c=="number"?s+c:void 0,b=typeof u=="number"?l+u:void 0;return{type:9,value:i.value.slice(s,m).map(h=>h.slice(l,b))}}if(!$(i))return console.info("e2",{reference:i}),D();let d=this.DynamicDependencies(i.value.address,this.expression_calculator.context.address,!0,s,l,u,c);if(!d)return console.info("e1",{check_result:d}),D();if(d.dirty){let m=this.GetVertex(this.expression_calculator.context.address,!0);return m.short_circuit=!0,{type:0,value:void 0}}if(d.area){let m={type:"address",...d.area.start,label:"",position:0,id:0},b={type:"address",...d.area.end,label:"",position:0,id:0},p=d.area.count===1?m:{type:"range",start:m,end:b,label:"",position:0,id:0};return{type:5,value:p}}return k()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:"reference",volatile:!0,fn:(i=>{if(!i||typeof i!="string")return _();let s=this.parser.Parse(i);if(s.error||!s.expression||s.expression.type!=="address"&&s.expression.type!=="range")return D();let l=this.DynamicDependencies(s.expression,this.expression_calculator.context.address);if(!l)return D();if(l.dirty){let c=this.GetVertex(this.expression_calculator.context.address,!0);return c.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:s.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(i,s,l=0)=>{if(l)return console.warn("inexact match not supported",{value:i,range:s,type:l}),Y();if(s.type===9){if(s.value.length===1){let c=s.value[0];for(let u=0;u<c.length;u++)if(i.type==c[u].type&&i.value===c[u].value)return{type:3,value:u+1}}else for(let c=0;c<s.value.length;c++){let u=s.value[c];if(u.length!==1)return Y();if(i.type==u[0].type&&i.value===u[0].value)return{type:3,value:c+1}}return Y()}else return i.type===s.type&&i.value===s.value?{type:3,value:1}:Y();return _()}},Index:{return_type:"reference",arguments:[{name:"range",metadata:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(i,s,l)=>{if(!i)return _();if(s===void 0&&l===void 0)return _();s=s||0,l=l||0;let c=[];if(i.type===9)c=i.value;else if(i.type===5){let m=i.value;m.type==="metadata"&&m.address&&c.push([i])}let u=c.length,d=c[0]?.length||0;if(d<=0||u<=0||s>d||l>u||s<0||l<0)return _();if(l===0&&s===0){let m=u===1&&d===1?{...c[0][0].value.address}:{type:"range",start:c[0][0].value.address,end:c[u-1][d-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}if((s||d===1)&&(l||u===1))return{type:5,value:c[l?l-1:0][s?s-1:0].value.address};if(s){let m={type:"range",start:c[0][s-1].value.address,end:c[u-1][s-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}else if(l){let m={type:"range",start:c[l-1][0].value.address,end:c[l-1][d-1].value.address,label:"",position:0,id:0};return{type:5,value:m}}return _()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:i=>{if(!i)return _();if(Array.isArray(i)){let s=i[0];return Array.isArray(s)?{type:3,value:s.length}:k()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:i=>i?Array.isArray(i)?{type:3,value:i.length}:{type:3,value:1}:_()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:i=>{if(!$(i))return D();let s=this.model.sheets.Find(i.value?.address?.sheet_id||0);if(s){let l=s.cells.GetCell(i.value.address,!1);return{type:2,value:l?.value?.toString()||""}}return D()}},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",unroll:!0,metadata:!0}],fn:i=>{let s=i?.value?.address,l=this.model.sheets.Find(s?.sheet_id||0);if(s&&l){let c=l.cells.GetCell(s,!1);return{type:4,value:c?.type===1}}return{type:4,value:!1}}}})}get parser(){return this.model.parser}library=new Ye;registered_libraries={};expression_calculator;full_rebuild_required=!1;options;async_resource_init=!1;grid_expanded=!1;async InitResources(){this.async_resource_init||(this.async_resource_init=!0)}ExportCalculatedValues(){let t={};for(let r of this.model.sheets.list){let n=r.cells.toJSON({calculated_value:!0}).data;t[r.id]=n.filter(o=>o.calculated!==void 0)}return t}ApplyCalculatedValues(t){for(let r of this.model.sheets.list){let n=t[r.id];if(!n)console.info("mismatch",r.id);else for(let o of n)r.cells.data[o.row][o.column].SetCalculatedValue(o.calculated)}}AttachSpillData(t,r){if(r||(r=(t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):void 0)?.cells),!r)throw console.info({area:t,cells:r}),new Error("invalid sheet ID in attach spill data");let n=new ke,o=0,i=!1;for(let{cell:s,row:l,column:c}of r.IterateRC(t,!0))o++&&(s.type!==0||s.area||s.merge_area||s.table)&&(i=!0),this.AddLeafVertexEdge({row:l,column:c,sheet_id:t.start.sheet_id},n);return this.spill_data.push({area:t,vertex:n}),{vertex:n,area:t,error:i}}SpillCallback(t,r){let{reference:n,address:o}=t,{value:i}=r,s=[];if(!n)return console.error("invalid reference in spill callback"),s;if(!o||!o.sheet_id)return console.error("invalid address in spill callback"),s;if(i.length===1&&i[0].length===1||!this.options.spill)return n.SetCalculatedValue(i[0][0].value),s;let l=this.model.sheets.Find(o.sheet_id),c=l?.cells;if(c){let u=r.value.length,d=r.value[0].length,m=new z(o).Reshape(d,u),{error:b}=this.AttachSpillData(m,c);if(b)return n.SetCalculationError("SPILL"),s;l.rows<m.end.row+1&&(l.cells.EnsureRow(m.end.row+1),this.grid_expanded=!0),l.columns<m.end.column+1&&(l.cells.EnsureColumn(m.end.column+1),this.grid_expanded=!0);let p=o.sheet_id;for(let{row:h,column:f}of c.IterateRC(m)){if(h===o.row&&f===o.column)continue;let y=this.GetVertex({sheet_id:p,row:h,column:f},!1);y&&(y.dirty||s.push(y))}for(let{cell:h,row:f,column:y}of c.IterateRC(m)){h.spill=m,f-=o.row,y-=o.column;let x=r.value[y][f];switch(x.type){case 5:case 9:case 6:break;default:h.SetCalculatedValue(x.value,x.type);break}}return s}return console.error("invalid cell reference in spill callback"),n.SetCalculationError("SPILL"),[]}SpreadCallback(t,r){if(!t.address||!t.address.sheet_id)throw new Error("spread callback called without sheet id");let n=this.model.sheets.Find(t.address.sheet_id)?.cells;if(!n)throw new Error("spread callback called without cells");if(!t||!t.reference)return;let o=t.reference.area;if(o){let i=o.rows,s=o.columns;if(r.type===9){let l=We(r.value);for(let c=0;c<i;c++)if(l[c]){let u=0;for(;u<s&&u<l[c].length;u++){let d=l[c][u];switch(d.type===9&&(d=d.value[0][0]),d.type){case 9:case 5:case 6:n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0);break;default:n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(d.value,d.type)}}for(;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0,0)}else for(let u=0;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(void 0,0)}else{let l={...r};(l.type===5||l.type===6)&&(l={type:0,value:void 0});for(let c=0;c<i;c++)for(let u=0;u<s;u++)n.data[c+o.start.row][u+o.start.column].SetCalculatedValue(l.value,l.type)}}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:Oe()}:this.expression_calculator.Calculate(t.expression,t.address,t.reference?.area)}DynamicDependencies(t,r,n=!1,o=0,i=0,s=1,l=1){let c=this.ResolveExpressionAddress(t,r);if(!c)return;let u=!1,d;if(t.type==="address"||t.type==="range"){let b=t.type==="range"?t.start:t;b.sheet_id?d=this.model.sheets.Find(b.sheet_id):b.sheet&&(d=this.model.sheets.Find(b.sheet))}if(!d&&r?.sheet_id&&(d=this.model.sheets.Find(r.sheet_id)),!d)throw new Error("missing sheet in dynamic dependencies [b21]");c=d.RealArea(c);let m=c.start.sheet_id;n&&(c=new z({column:c.start.column+i,row:c.start.row+o,sheet_id:c.start.sheet_id},{column:c.start.column+i+s-1,row:c.start.row+o+l-1,sheet_id:c.end.sheet_id}));for(let b=c.start.row;b<=c.end.row;b++)for(let p=c.start.column;p<=c.end.column;p++){let h=this.GetVertex({row:b,column:p,sheet_id:m},!1);h&&h.dirty&&(this.AddEdge({row:b,column:p,sheet_id:m},this.expression_calculator.context.address),u=!0)}return{dirty:u,area:c}}UpdateLocale(){ee.decimal_separator===","?this.parser.SetLocaleSettings(","):this.parser.SetLocaleSettings(".")}SupportedFunctions(){let t=this.library.List(),r=Object.keys(t).map(n=>{let o=t[n].canonical_name;return o||(o=n.replace(/_/g,".")),{name:o,description:t[n].description,arguments:(t[n].arguments||[]).map(i=>({name:i.name||""})),type:"function"}});for(let n of this.model.macro_functions.values())r.push({name:n.name,description:n.description,arguments:(n.argument_names||[]).map(o=>({name:o})),type:"function"});return r}RegisterLibrary(t,r){return this.registered_libraries[t]?!1:(this.RegisterFunction(r),this.registered_libraries[t]=!0,!0)}RegisterFunction(t){for(let r of Object.keys(t)){let n=t[r];this.library.Register({[r]:n})}}Calculate(t){if(t&&!t.start.sheet_id)throw new Error("CalculateInternal called with subset w/out sheet ID");this.full_rebuild_required&&(t=void 0,this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.full_rebuild_required=!1),this.RebuildGraph(t),this.grid_expanded=!1;try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let n of Object.keys(r)){let o=r[n];o.xlfn?t[n]="_xlfn":o.extension&&(t[n]="_xll")}return t}Evaluate(t,r,n={},o=!1){let i=n?.preparsed;if(!i){this.parser.Save(),n.argument_separator&&(n.argument_separator===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",")),n.r1c1&&(this.parser.flags.r1c1=n.r1c1);let s=this.parser.Parse(t);if(this.parser.Restore(),i=s.expression,s.error)throw new Error(s.error)}if(i){this.parser.Walk(i,l=>{if(l.type==="address"||l.type==="range"){if(l.type==="address"){if(l.offset_column||l.offset_row)throw new Error("Evaluate does not support offset references")}else if(l.start.offset_column||l.start.offset_row||l.end.offset_column||l.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(l,void 0,r)}return!0});let s=this.CalculateExpression(i,n.address);return o?s:s.type===9?s.value.map(l=>l.map(c=>c.value)):s.value}throw new Error("invalid expression")}CalculateExpression(t,r={row:-1,column:-1},n=!1){return this.expression_calculator.Calculate(t,r,void 0,n).value}RebuildClean(t=!1){this.full_rebuild_required=!1,this.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},n=[];for(let o of t){let i={column:o.column,row:o.row,sheet_id:o.sheet_id},s=z.CellAddressToLabel(i,!0);r[s]||(r[s]=s,n.push(i))}return n}Unresolve(t,r,n=!0,o=!0){let i="",s=K(t)?new z(t):new z(t.start,t.end);if(o){let u=this.model.named.MatchSelection(s);if(u)return u}if(i=s.spreadsheet_label,!n)return i;let l=s.start.sheet_id||r?.id,c=this.ResolveSheetName(l,!0);return c?c+"!"+i:i}ResolveSheetName(t,r=!1){let n=this.model.sheets.Find(t);if(n)return r&&Ue.test(n.name)?`'${n.name}'`:n.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}RemoveConnectedELement(t){let r=t.internal;return r?.vertex?(this.RemoveLeafVertex(r.vertex),!0):!1}UpdateConnectedElements(t,r){if(t||(t=this.model.sheets.list[0]),r){let o=r.internal;o?.vertex&&this.RemoveLeafVertex(o.vertex)}let n=r?[r]:this.model.connected_elements.values();for(let o of n){let i=o.internal;i||(i={vertex:new ke},o.internal=i);let s=i.vertex;this.AddLeafVertex(s),this.UpdateLeafVertex(s,o.formula,t)}}UpdateConditionals(t,r){if(!t){for(let n of this.model.sheets.list)n.conditional_formats?.length&&this.UpdateConditionals(n.conditional_formats,n);return}if(!r)throw new Error("invalid call to update conditionals without context");t&&!Array.isArray(t)&&(t=[t]);for(let n of t){let o="";switch(n.type){case"cell-match":n.between?o=`BETWEEN(${[this.Unresolve(n.area,r,!0,!1),...n.between].join(", ")})`:o=this.Unresolve(n.area,r,!0,!1)+" "+n.expression;break;case"expression":o=n.expression;break;case"duplicate-values":o=`UniqueValues(${this.Unresolve(n.area,r,!0,!1)})`,n.unique||(o=`NOT(${o})`);break;case"data-bar":case"gradient":o=`=Gradient(${[this.Unresolve(n.area,r,!0,!1),n.min??"",n.max??"",...n.type==="data-bar"?["TRUE"]:[]].join(",")})`;break;default:continue}if(!o)continue;if(n.internal||(n.internal={}),!n.internal.vertex){let s=new at;s.use="conditional",n.internal.vertex=s;let l={argument_separator:","};n.type!=="gradient"&&n.type!=="duplicate-values"&&n.type!=="data-bar"&&(l={...n.options,...l});let c=this.Evaluate(o,r,l,!0);n.internal.vertex.result=c,n.internal.vertex.updated=!0}let i=n.internal.vertex;this.AddLeafVertex(i),this.UpdateLeafVertex(i,o,r,".")}}RemoveAnnotation(t){let r=t.temp;r.vertex&&(r.vertex.Reset(),this.RemoveLeafVertex(r.vertex))}UpdateAnnotations(t,r){if(!t){for(let n of this.model.sheets.list)this.UpdateAnnotations(n.annotations,n);return}if(!r)throw new Error("invalid call to UpdateAnnotations with list but no sheet");typeof t<"u"&&!Array.isArray(t)&&(t=[t]);for(let n of t)if(n.data.formula){let o=n.temp;o.vertex||(o.vertex=new ke),this.AddLeafVertex(o.vertex),this.UpdateLeafVertex(o.vertex,n.data.formula,r)}}ResolveExpressionAddress(t,r){switch(t.type){case"address":if(this.model.ResolveSheetID(t,r))return new z(t);break;case"range":if(this.model.ResolveSheetID(t,r))return new z(t.start,t.end);break;case"identifier":{let n=this.model.GetName(t.name,r?.sheet_id||0);if(n&&n.type==="range")return new z(n.area.start,n.area.end)}break}}NamedRangeToAddressUnit(t,r){let n=t.name.toUpperCase(),o=this.model.GetName(n,r.sheet_id||0);if(o&&o.type==="range")return o.area.count===1?this.ConstructAddressUnit(o.area.start,n,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(o.area.start,n,t.id,t.position),end:this.ConstructAddressUnit(o.area.end,n,t.id,t.position),label:n,id:t.id,position:t.position}}ConstructAddressUnit(t,r,n,o){return{type:"address",row:t.row,column:t.column,sheet_id:t.sheet_id,label:r,id:n,position:o}}RebuildDependencies(t,r,n,o={addresses:{},ranges:{}},i){if(!n){let s=this.model.sheets.Find(r);s&&(n=s.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let s=this.model.GetName(t.name,i.sheet_id||0);if(s?.type==="expression")this.RebuildDependencies(s.expression,r,n,o,i);else{let l=this.NamedRangeToAddressUnit(t,i);l&&(l.type==="address"?o.addresses[l.label]=l:o.ranges[l.label]=l)}}break;case"structured-reference":{let s=this.model.ResolveStructuredReference(t,i);s&&(s.type==="address"?o.addresses[s.sheet_id+"!"+s.label]=s:o.ranges[s.label]=s);let l=this.model.tables.get(t.table.toLowerCase());if(l){let c=i.row;if(c<l.area.start.row||c>l.area.end.row)break;let u=t.column.toLowerCase(),d=-1;if(l.columns){for(let m=0;m<l.columns.length;m++)if(u===l.columns[m]){d=l.area.start.column+m;break}}if(d>=0){let m={label:t.label,type:"address",row:c,column:d,sheet_id:l.area.start.sheet_id,id:t.id,position:t.position};o.addresses[m.sheet_id+"!"+m.label]=m}}}break;case"address":if(!t.sheet_id)if(t.sheet){let s=this.model.sheets.Find(t.sheet);s&&(t.sheet_id=s.id)}else t.sheet_id=r,t.sheet=n;t.sheet_id?o.addresses[t.sheet_id+"!"+t.label]=t:console.warn("invalid address in range [9d]");break;case"range":if(!t.start.sheet_id)if(t.start.sheet){let s=this.model.sheets.Find(t.start.sheet);s&&(t.start.sheet_id=s.id)}else t.start.sheet_id=r,t.start.sheet=n;t.start.sheet_id?o.ranges[t.start.sheet_id+"!"+t.start.label+":"+t.end.label]=t:console.warn("invalid sheet in range",t);break;case"unary":this.RebuildDependencies(t.operand,r,n,o,i);break;case"binary":this.RebuildDependencies(t.left,r,n,o,i),this.RebuildDependencies(t.right,r,n,o,i);break;case"group":t.elements.forEach(s=>this.RebuildDependencies(s,r,n,o,i));break;case"implicit-call":{for(let s of t.args)this.RebuildDependencies(s,r,n,o,i);this.RebuildDependencies(t.call,r,n,o,i)}break;case"call":{let s=t.args.slice(0),l=this.library.Get(t.name);l&&l.arguments&&l.arguments.forEach((c,u)=>{c&&c.address&&(this.RebuildDependencies(s[u],r,n,void 0,i),s[u]={type:"missing",id:-1})}),s.forEach(c=>this.RebuildDependencies(c,r,n,o,i))}break}return o}UpdateLeafVertex(t,r,n,o){t.Reset(),o&&(this.parser.Save(),this.parser.SetLocaleSettings(o));let i=this.parser.Parse(r);if(i.expression){let s=this.RebuildDependencies(i.expression,n.id,n.name,void 0,{row:0,column:0});for(let l of Object.keys(s.ranges)){let c=s.ranges[l],u=new z(c.start,c.end);u.entire_column||u.entire_row||u.count>1?this.AddLeafVertexArrayEdge(u,t):this.AddLeafVertexEdge(u.start,t)}for(let l of Object.keys(s.addresses)){let c=s.addresses[l];this.AddLeafVertexEdge(c,t)}}t.expression=i.expression||{type:"missing",id:-1},t.expression_error=!i.valid,o&&this.parser.Restore()}RebuildGraphCell(t,r){if(t.spill&&this.options.spill&&(t.spill.start.row===r.row&&t.spill.start.column===r.column?this.AttachSpillData(new z(t.spill.start,t.spill.end)):this.AddEdge(t.spill.start,r)),t.area&&t.area.start.column===r.column&&t.area.start.row===r.row){let{start:n,end:o}=t.area,i=n.sheet_id||r.sheet_id;n.sheet_id||(n.sheet_id=i);for(let s=n.column;s<=o.column;s++)for(let l=n.row;l<=o.row;l++)this.ResetInbound({column:s,row:l,sheet_id:i},!0,!1);this.SetDirty(r);for(let s=n.column;s<=o.column;s++)for(let l=n.row;l<=o.row;l++)l===n.row&&s===n.column||this.AddEdge(n,{...n,row:l,column:s})}if(t.type===1){this.ResetInbound(r,!0);let n=this.parser.Parse(t.value);if(n.expression){let i,s=n.expression;for(s?.type==="implicit-call"?s.call.type==="call"&&(s=s.call):s?.type==="call"&&(i=this.library.Get(s.name),i?.pass_through_ui==="indirect"&&(s=void 0));s?.type==="call";)if(i=this.library.Get(s.name),i)if(i.pass_through_ui&&s.args.length)s=s.args[s.args.length-1];else break;else{let c=this.model.GetName(s.name,r.sheet_id);if(c?.type==="expression")s=c.expression;else break}i&&(t.render_function=i.render,t.click_function=i.click);let l=this.RebuildDependencies(n.expression,r.sheet_id,"",void 0,r);for(let c of Object.keys(l.ranges)){let u=l.ranges[c],d=new z(u.start,u.end);if(d.entire_row||d.entire_column)this.AddArrayEdge(d,r);else for(let m of d)this.AddEdge(m,r)}for(let c of Object.keys(l.addresses)){let u=l.addresses[c];this.AddEdge(u,r)}}let o=this.GetVertex(r,!0);o&&(o.expression=n.expression||{type:"missing",id:-1},o.expression_error=!n.valid)}else t.value!==t.calculated?this.ResetInbound(r,!0,!1):t.type===0&&this.ResetInbound(r,!0,!1,!0)}RebuildGraph(t){if(t){if(!t.start.sheet_id)throw new Error("subset missing sheet id");let r=this.model.sheets.Find(t.start.sheet_id)?.cells;if(r)for(let n=t.start.row;n<=t.end.row;n++){let o=r.data[n];if(o)for(let i=t.start.column;i<=t.end.column;i++){let s=o[i];s&&this.RebuildGraphCell(s,{row:n,column:i,sheet_id:t.start.sheet_id})}}}else for(let r of this.model.sheets.list||[]){let n=r.cells.data.length;for(let o=0;o<n;o++){let i=r.cells.data[o];if(i){let s=i.length;for(let l=0;l<s;l++){let c=i[l];c&&this.RebuildGraphCell(c,{row:o,column:l,sheet_id:r.id})}}}}}CheckVolatile(t){if(!t.expression||t.expression_error)return!1;let r=!1;return this.parser.Walk(t.expression,n=>{if(n.type==="call"){let o=this.library.Get(n.name);o&&o.volatile&&(r=!0)}return!r}),r}};var it=class{model={};layout_element;visible_=!1;timeout=0;pending_dialog_resoltion=[];options_={type:"initial"};set options(e){if(e.type==="about"&&(e.close_box=!0,e.icon=!0),this.options_.icon!==e.icon&&(this.model.left.style.display=e.icon?"block":"none"),this.options_.close_box!==e.close_box&&(this.model.close.style.display=e.close_box?"block":"none"),this.options_.message!==e.message&&(this.model.message.textContent=e.message||"",this.model.message.style.display=e.message?"block":"none"),this.options_.title!==e.title&&(this.model.title.textContent=e.title||"",this.model.title.style.display=e.title?"block":"none"),this.options_.type!==e.type){let t=this.model.dialog.className.replace(/dialog-type-\S+/g,"").trim();e.type&&(t+=` dialog-type-${e.type}`),this.model.dialog.className=t,e.type==="about"?this.model.about.style.display="block":this.model.about.style.display="none"}this.options_=e}event_handler=e=>{(e.key==="Escape"||e.key==="Esc")&&(e.stopPropagation(),e.preventDefault(),this.visible=!1)};get visible(){return this.visible_}set visible(e){if(e!==this.visible_)if(this.visible_=e,e)this.layout_element?.setAttribute("dialog",""),window.addEventListener("keydown",this.event_handler);else{this.layout_element?.removeAttribute("dialog"),window.removeEventListener("keydown",this.event_handler);let t=this.pending_dialog_resoltion.slice(0);this.pending_dialog_resoltion=[],Promise.resolve().then(()=>{for(let r of t)r()})}}constructor(e){this.layout_element=e.parentElement;let t=this.layout_element?.querySelector(".treb-dialog-mask");if(t){let r=t.querySelectorAll("[data-bind]");for(let n of Array.from(r)){let o=n.dataset.bind;o&&(this.model[o]=n)}}if(this.model.about){let r=["<div>TREB version 36.1.4"];r.push("<small><a target=_blank href='https://treb.app'>http://treb.app</a></small>"),this.model.about.innerHTML=r.join(`
3
+ `)}this.model.close?.addEventListener("click",r=>{r.stopPropagation(),r.preventDefault(),this.HideDialog()})}Node(e){return this.model[e]}Update(e,t=!0){t&&(e={...this.options_,...e}),this.options=e}HideDialog(){this.visible=!1}ShowDialog(e){return new Promise(t=>{this.pending_dialog_resoltion.push(t),this.options=e,this.visible=!0,this.timeout&&(window.clearTimeout(this.timeout),this.timeout=0),e.timeout&&(this.timeout=window.setTimeout(()=>this.HideDialog(),e.timeout))})}};var st=class{constructor(e){this.container=e;let t=le.GetInstance(e.ownerDocument);this.node=t.Div("treb-spinner",e,{html:"<div><div></div><div></div><div></div><div></div></div>"})}node;visible=!1;Show(){this.node.classList.add("visible")}Hide(){this.node.classList.remove("visible")}};var on={formula_bar:!0,in_cell_editor:!0,undo:!0,scrollbars:!0,headers:!0,export:!0,tab_bar:"auto",resizable:!0,hyperlinks:"_blank",max_file_size:94208,tint_theme_colors:!0,dnd:!1,add_tab:!1,expand_formula_button:!1,expand:!0,markdown:!1,spinner:!1,complex:"off",spill:!0};var Z=a=>!!a&&typeof a=="object"&&a.key==="metadata"&&!!a.value&&a.value.type==="metadata",Nt=a=>!!a&&typeof a=="object"&&a.key==="series"&&typeof a.value=="object",sn=a=>!!a&&typeof a=="object"&&a.type===9&&Array.isArray(a.value);var E=class{static Scale(e,t,r=6.5,n,o){return or(e,t,r,n,o)}static Range(e){let t,r;for(let o of e)typeof o>"u"||((typeof t>"u"||t>o)&&(t=o),(typeof r>"u"||r<o)&&(r=o));let n=typeof t>"u"||typeof r>"u"?0:r-t;return{min:t,max:r,range:n}}static ApplyScale(e,t,r){return t*(e-r.min)/(r.max-r.min)}static Flatten(e){let t=[];if(Array.isArray(e))for(let r of e)Array.isArray(r)?t=t.concat(this.Flatten(r)):t.push(r);else typeof e<"u"&&t.push(e);return t}};var cn=a=>{Bt(a,0,a.length)},Wn=(a,e,t)=>{let r=a[t-1],n=e;for(let o=e;o<t-1;o+=1)a[o]<=r&&(ln(a,o,n),n+=1);return ln(a,n,t-1),n},ln=(a,e,t)=>{let r=a[e];a[e]=a[t],a[t]=r},Bt=(a,e,t)=>{if(e<t){let r=Wn(a,e,t);Bt(a,e,r),Bt(a,r+1,t)}};var $t="#,##0.00",Se=a=>{let e=a[0],t=a[0];for(let r of a)r<e&&(e=r),r>t&&(t=r);return{min:e,max:t}},un=a=>{let{label:e,x:t,y:r,z:n,index:o,subtype:i,data_labels:s,axis:l}=a,c={x:{data:[]},y:{data:[]}};if(typeof l=="number"&&(c.axis=l),typeof o=="number"&&(c.index=o),i&&(c.subtype=i.toString()),s){let m=E.Flatten(Array.isArray(s)?s:[s]);c.labels=m.map(b=>typeof b>"u"?"":b.toString())}e&&(c.label=e.toString());let u=(m,b=!1)=>{let p;if(Z(m)&&(m={type:9,value:[[m]]}),sn(m)){p={data:[]};let h=E.Flatten(m.value);if(p.data=h.map(f=>{if(Z(f)){if(typeof f.value.value=="number")return f.value.value}else if(f.type===3)return f.value}),Z(h[0])&&h[0].value?.format&&(p.format=h[0].value.format,b)){let f=R.Get(p.format);p.labels=p.data.map(y=>y===void 0?void 0:f.Format(y))}}return p};c.y=u(r,!0)||{data:[]},c.x=u(t)||{data:[]},c.z=u(n);let d=[c.x,c.y];for(let m of d)if(m.data.length){let b=m.data.filter(p=>p||p===0);m.range=Se(b)}return c},dn=a=>{let e={x:{data:[]},y:{data:[]}},t=E.Flatten(a.value),r=[];for(let[o,i]of t.entries()){let s=0;if(typeof i.value=="number")s=i.value,r.push(i.value);else if(Z(i))if(X(i.value.value))e.x.data[o]=i.value.value.real,s=i.value.value.imaginary;else if(typeof i.value.value=="number")s=i.value.value;else continue;else continue;e.y.data[o]=s,r.push(s)}let n="";if(Z(t[0])&&(n=t[0].value.format||""),n){e.y.format=n;let o=R.Get(e.y.format||"");e.y.labels=e.y.data.map(i=>i===void 0?void 0:o.Format(i))}if(e.y.range=Se(r),e.x.data.length){let o=e.x.data.filter(i=>typeof i=="number");if(e.x.range=Se(o),n){e.x.format=n;let i=R.Get(e.x.format||"");e.x.labels=e.x.data.map(s=>s===void 0?void 0:i.Format(s))}}return e},Ie=(a,e)=>{if(!a)return[];let t=[];if(a.type===5){if(a.key==="group"){if(Array.isArray(a.value)){for(let[o,i]of a.value.entries())if(i&&typeof i=="object")if(Nt(i)){let s=un(i.value);typeof s.index>"u"&&(s.index=o+1),t.push(s)}else i.type===9&&t.push(dn(i))}}else if(Nt(a)){let o=un(a.value);t.push(o)}}else a.type===9&&t.push(dn(a));let r,n=0;if(e?.type===9){let o=E.Flatten(e.value),i="0.00###";Z(o[0])&&o[0].value.format&&(i=o[0].value.format);let s=o.map(c=>{if(c.type===3)return c.value;if(Z(c)&&typeof c.value.value=="number")return c.value.value}),l=s.filter(c=>typeof c=="number");r={data:s,format:i,range:Se(l)}}for(let o of t)n=Math.max(n,o.y.data.length),o.x.data.length&&(r||(r=o.x));if(!r){r={data:[],range:{min:0,max:Math.max(0,n-1)}};for(let o=0;o<n;o++)r.data.push(o)}for(let o of t)o.x.data.length||(o.x=r);return t},mn=a=>{let e=Math.abs(a.step)%1;if(e){if(Math.log10(Math.abs(e))<-4)return"Scientific";let r=0;for(let o=0;o<a.count;o++){let i=((a.min+a.step*o)%1).toFixed(6).replace(/0+$/,"");r=Math.max(r,i.length-2)}let n="#,##0.";for(let o=0;o<r;o++)n+="0";return n}else return Math.log10(Math.abs(a.step))>=5?"Scientific":"#,##0"},Me=(a,e,t,r,n,o)=>{let i="",s="",l="";for(let M of a)M.axis?M.y.format&&!l&&(l=M.y.format):M.y.format&&!s&&(s=M.y.format),M.x.format&&!i&&(i=M.x.format);let c;a.some(M=>M.label&&M.label.length>0)&&(c=a.map((M,A)=>({label:M.label||`Series ${A+1}`,index:typeof M.index=="number"?M.index:A+1})));let u=a.filter(M=>M.x.range),d=Math.min.apply(0,u.map(M=>M.x.range?.min||0)),m=Math.max.apply(0,u.map(M=>M.x.range?.max||0)),b=u.filter(M=>!M.axis),p=u.filter(M=>M.axis),h=Math.min.apply(0,b.map(M=>M.y.range?.min||0)),f=Math.max.apply(0,b.map(M=>M.y.range?.max||0)),y=-1,x=-1;p.length&&(y=Math.min.apply(0,p.map(M=>M.y.range?.min||0)),x=Math.max.apply(0,p.map(M=>M.y.range?.max||0)));for(let M of a)if(M.z){for(let[A,G]of M.z.data.entries())if(typeof G<"u"){let j=M.x.data[A],se=Math.max(0,G/2);typeof j<"u"&&(d=Math.min(d,j-se),m=Math.max(m,j+se));let de=M.y.data[A];typeof de<"u"&&(h=Math.min(h,de-se),f=Math.max(f,de+se))}}typeof r<"u"&&(d=Math.min(d,r)),typeof n<"u"&&(d=Math.max(d,n)),typeof e<"u"&&(h=Math.min(h,e)),typeof t<"u"&&(f=Math.max(f,t));let v=E.Scale(d,m,7),w=E.Scale(h,f,7),g=E.Scale(y,x,7);if(y!==x&&w&&g&&w.count!==g.count){let M=Math.max(w.count,g.count),A=w.count<M?w:g;for(let G=A.count;G<M;G+=2)A.max+=A.step,A.count++,A.count<M&&(A.min-=A.step,A.count++)}let C,U,V;if(i){C=[];let M=R.Get(i);for(let A=0;A<=v.count;A++)C.push(M.Format(v.min+A*v.step))}if(!s&&o&&(s=mn(w)),!l&&o&&(l=mn(g)),s){U=[];let M=R.Get(s);for(let A=0;A<=w.count;A++)U.push(M.Format(w.min+A*w.step))}if(l){V=[];let M=R.Get(l);for(let A=0;A<=g.count;A++)V.push(M.Format(g.min+A*g.step))}let L={x:{format:i,scale:v,labels:C},y:{format:s,scale:w,labels:U},legend:c};return y!==x&&(L.y2={format:l,scale:g,labels:V}),L},lt=(a,e,t)=>{for(let r of a){let n={x:R.Get(r.x.format||""),y:R.Get(r.y.format||"")};r.y.labels=[];for(let o=0;o<r.y.data.length;o++){let i=t?t[o]:typeof r.x.data[o]=="number"?n.x.Format(r.x.data[o]):"",s=typeof r.y.data[o]=="number"?n.y.Format(r.y.data[o]):"";r.y.labels[o]=e.replace(/\bx\b/g,i).replace(/\by\b/g,s)}}},Yn=a=>{let e=(s,l=0,c=s.length)=>c%2?s[Math.floor(c/2)+l]:(s[c/2+l]+s[c/2-1+l])/2,t=a.length,r=[0,e(a),0];if(t%2){let s=Math.floor(t/2);r[0]=e(a,0,Math.ceil(t/2)),r[2]=e(a,s,a.length-s)}else r[0]=e(a,0,t/2),r[2]=e(a,t/2,a.length-t/2);let n=r[2]-r[0],o=[0,0],i=0;for(let s=0;s<t;s++)i+=a[s];for(let s=0;s<t;s++){let l=a[s];if(l>=r[0]-n*1.5){o[0]=l;break}}for(let s=t-1;s>=0;s--){let l=a[s];if(l<=r[2]+n*1.5){o[1]=l;break}}return{data:a,quartiles:r,whiskers:o,iqr:n,n:t,mean:t?i/t:0,min:a[0],max:a[t-1]}},bn=a=>{let e=Ie(a[0]),t=Me(e,void 0,void 0,void 0,void 0,!0),r=0,n=!!a[2],o=e.map(d=>{let m=[];for(let p of d.y.data)p!==void 0&&m.push(p);cn(m);let b=Yn(m);return r=Math.max(r,b.n),n&&(b.whiskers[0]=b.min,b.whiskers[1]=b.max),b}),i=a[1]?.toString()||void 0,s=[],l=[],c=R.Get("#,##0");for(let[d,m]of o.entries()){s.push(c.Format(m.n));let b=e[d];l.push(b.label||`Series ${d+1}`)}return{type:"box",series:e,title:i,max_n:r,data:o,x_labels:s,series_names:e.some(d=>!!d.label)?l:void 0,scale:t.y.scale,y_labels:t.y.labels}},pn=a=>{let e=Ie(a[0]),t,r;for(let s of e)typeof s.x.range?.min=="number"&&s.x.range.min>0&&s.x.range.min<50&&(r=0),typeof s.y.range?.min=="number"&&s.y.range.min>0&&s.y.range.min<50&&(t=0);let n=Me(e,t,void 0,r),o=a[1]?.toString()||void 0;return{legend:n.legend,legend_style:2,type:"bubble",series:e,title:o,x_scale:n.x.scale,x_labels:n.x.labels,y_scale:n.y.scale,y_labels:n.y.labels}},Gt=(a,e="plot")=>{let t=Ie(a[0]),r=Me(t),n=a[1]?.toString()||void 0,o=a[2]?.toString()||void 0,i={legend:r.legend,style:e,type:"scatter2",series:t,title:n,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,y2_scale:r.y2?.scale,y2_labels:r.y2?.labels,lines:e==="line",points:e==="plot"};if(o){i.markers=/marker/i.test(o),i.smooth=/smooth/i.test(o),i.data_labels=/labels/i.test(o);let s=o.match(/labels="(.*?)"/);s&&i.series?lt(i.series,s[1]):(s=o.match(/labels=([^\s\r\n,]+)(?:\W|$)/),s&&i.series&&lt(i.series,s[1])),s=o.match(/class=([\w_-]+)(?:\W|$)/),s&&(i.class_name=s[1])}return i},jt=(a,e)=>{let[t,r,n,o]=a,i=o?.toString()||void 0,s=/stacked/i.test(i||""),l=Ie(t),c=Me(l),u;if(r){u=(r.type===9?E.Flatten(r.value):E.Flatten(r)).map(y=>!y||!y.value?"":Z(y)?typeof y.value.value=="number"?R.Get(y.value.format||$t).Format(y.value.value):y.value.value?.toString()||"":typeof y.value=="number"?R.Get($t).Format(y.value):y.value.toString());let f=l.reduce((y,x)=>Math.max(y,x.y.data.length),0);for(f<u.length&&(u=u.slice(0,f));f>u.length;)u.push("")}let d,m=c.legend;if(s){d=l;let h=new Map;for(let x of l)for(let[v,w]of x.x.data.entries())if(w!==void 0){let g=x.y.data[v]||0;h.set(w,g+(h.get(w)||0))}let f=Array.from(h.keys()).sort((x,v)=>x-v),y=f.map(x=>h.get(x)||0);l=[{x:{data:f,format:d[0]?.x?.format},y:{data:y,format:d[0]?.y?.format}}],l[0].x.range=Se(f),l[0].y.range=Se(y),c=Me(l,Math.min(0,...y))}let b=n?.toString()||void 0,p={type:e,legend:m,legend_style:1,series2:l,stacked_series:d,scale:c.y.scale,title:b,y_labels:e==="bar"?u:c.y.labels,x_labels:e==="bar"?c.y.labels:u};if(i){p.stacked=s,p.round=/round/i.test(i),p.data_labels=/labels/i.test(i);let h=i.match(/labels="(.*?)"/);h&&l?lt(l,h[1],u):(h=i.match(/labels=([^\s\r\n,]+)(?:\W|$)/),h&&l&&lt(l,h[1],u)),h=i.match(/class=([\w_-]+)(?:\W|$)/),h&&(p.class_name=h[1])}return p},qt=(a,e)=>{let t=Ie(a[0],a[1]),r=Me(t,0,0),n=a[2]?.toString()||void 0,o=a[3]?.toString()||void 0,i={legend:r.legend,type:"scatter2",series:t,title:n,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:!0,filled:e==="area"};if(o){i.smooth=/smooth/i.test(o);let s=o.match(/class=([\w_-]+)(?:\W|$)/);s&&(i.class_name=s[1])}return i},hn=(a,e=!1)=>{let[t,r,n,o,i]=a,s=a[0]?.type===9?a[0].value:a[0],l=s?E.Flatten(s):[],c=l.map(g=>{if(Z(g)&&typeof g.value.value=="number")return g.value.value}),u=a[1]?.type===9?a[1].value:a[1],d=E.Flatten(u||[]).map(g=>Z(g)?typeof g.value.value=="number"&&g.value.format?R.Get(g.value.format).Format(g.value.value):g.value.value?.toString()||"":g.value?.toString()||""),m=!1;c=c.map(g=>g&&g<0?(m||(console.warn("pie/donut chart does not support negative values (omitted)"),m=!0),0):g);let b=0,p=c.map((g,C)=>(typeof g<"u"&&(b+=g),{value:g||0,label:d[C]||"",index:C+1,percent:0}));if(b)for(let g of p)g.percent=(g.value||0)/b;let h="";for(let g of l)if(Z(g)){h=g.value.format||"";break}let f=R.Get(h||$t),y=R.Get("percent");typeof a[4]>"u"&&a[1]&&(a[4]="label");let x=a[4]||"";if(x)for(let g of p){let C=f.Format(g.value||0),U=y.Format(g.percent);g.title=x.replace(/value%/ig,y.Format(g.value||0)).replace(/value/ig,C).replace(/percent/ig,U).replace(/label/ig,g.label||"").trim()}let v=(o||"").toUpperCase();if(v==="ASC"||v==="ASCENDING"||v==="INC")p.sort((g,C)=>(g.value||0)-(C.value||0));else if(v==="DESC"||v==="DESCENDING"||v==="DEC")p.sort((g,C)=>(C.value||0)-(g.value||0));else{let g=(o||"").match(/sort=([\w]+)(?:\W|$)/i);g&&(v=g[1],/^(asc|inc)/i.test(v)?p.sort((C,U)=>(C.value||0)-(U.value||0)):/^(desc|dec)/i.test(v)&&p.sort((C,U)=>(U.value||0)-(C.value||0)))}let w={type:e?"pie":"donut",slices:p,title:n||""};if(o){let g=o.match(/class=([_-\w]+)(?:\W|$)/);g&&(w.class_name=g[1])}return w};var re=class{constructor(e=0,t=0,r=100,n=100){this.left=e;this.top=t;this.right=r;this.bottom=n}get width(){return this.right-this.left}get height(){return this.bottom-this.top}get center(){return{x:this.left+this.width/2,y:this.top+this.height/2}}};var ea="http://www.w3.org/2000/svg",S=(a,e={},t)=>{let r=document.createElementNS(ea,a);for(let n of Object.keys(e))if(e[n]!==void 0){let o=e[n]??"";r.setAttribute(n,Array.isArray(o)?o.join(" "):o.toString())}return t&&(r.textContent=t),r},ct=class{parent;svg_node;text_measurement_node;container_group;group;axis_group;label_group;size={width:0,height:0};bounds=new re;constructor(){this.container_group=S("g"),this.group=S("g"),this.axis_group=S("g",{class:"axis-group"}),this.label_group=S("g",{class:"label-group"}),this.container_group.appendChild(this.axis_group),this.container_group.appendChild(this.group),this.container_group.appendChild(this.label_group)}Initialize(e){this.parent=e,this.svg_node=S("svg",{class:"treb-chart"}),this.svg_node.style.overflow="hidden",this.svg_node.style.position="relative",this.svg_node.style.width="100%",this.svg_node.style.height="100%",this.svg_node.appendChild(this.container_group),this.parent.appendChild(this.svg_node),this.Resize()}Legend(e){let t=S("g");this.group.appendChild(t);let r=S("text");t.appendChild(r),t.setAttribute("class","legend");let n=[[]],o=10,i=e.area.width,s=0,l=0,c=e.area.width,u=e.style===1?14:26,d=e.labels.map((f,y)=>{r.textContent=f.label;let x=r.getBoundingClientRect(),v={width:x.width,height:x.height},w=v.width+u+o;return l=Math.max(l,v.height),e.layout===1?n[y]=[y]:w>i?n[s].length===0?(n[s].push(y),s++,n[s]=[],i=c):(s++,n[s]=[y],i=c-w):(n[s].push(y),i-=w),v});t.removeChild(r);let m=l,b=e.layout||0;b===0&&n.every(f=>f.length<=1)&&(b=0);for(let f=0;f<n.length;f++){let y=n[f].reduce((w,g)=>w+d[g].width+u,(n[f].length-1)*o),x=0,v=b===0?Math.round((c-y)/2):Math.round(o/2);for(let w=0;w<n[f].length;w++){let g=n[f][w],C=d[g],U=e.labels[g],V=m-1,L=!1;typeof navigator<"u"&&(L=/trident/i.test(navigator?.userAgent||""));let M=typeof U.index=="number"?U.index:g+1;switch(t.appendChild(S("text",{"dominant-baseline":"middle",x:v+u,y:m,dy:L?".3em":void 0},U.label)),e.style){case 1:t.appendChild(S("rect",{class:`series-${M}`,x:v,y:V-4,width:8,height:8}));break;case 2:t.appendChild(S("circle",{class:`series-${M}`,cx:v+u-11,cy:V-4+3}));break;default:t.appendChild(S("rect",{class:`series-${M}`,x:v,y:V-1,width:u-3,height:2}));break}x=Math.max(x,C.height),v+=C.width+u+o}m=Math.round(m+x*1.1)}let p=t.getBoundingClientRect(),h={width:p.width,height:p.height+l};switch(e.position){case 1:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.bottom-h.height})`);break;case 2:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`);break;case 3:t.setAttribute("transform",`translate(${e.area.right-h.width}, ${e.area.top})`);break;case 0:default:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`)}e.position===0?e.area.top+=h.height||0:e.position===3?e.area.right-=(h.width||0)+8:e.position===2?e.area.left+=(h.width||0)+8:e.area.bottom-=h.height||0}Clear(e){this.group.textContent="",this.axis_group.textContent="",this.label_group.textContent="",e="treb-chart"+(e?" "+e:""),this.svg_node.setAttribute("class",e)}Resize(){let e=this.svg_node.getBoundingClientRect();this.svg_node.setAttribute("width",e.width.toString()),this.svg_node.setAttribute("height",e.height.toString()),this.size={width:e.width,height:e.height}}Prerender(){let e=this.svg_node.getBoundingClientRect();this.bounds.top=e.top,this.bounds.left=e.left,this.bounds.right=e.right,this.bounds.bottom=e.bottom}RenderTitle(e,t,r,n){let o=S("text",{class:"chart-title",x:Math.round(t.width/2)},e);o.style.textAnchor="middle",this.group.appendChild(o);let i=o.getBoundingClientRect();n==="bottom"?(o.setAttribute("y",Math.round(t.bottom-i.height).toString()),t.bottom-=i.height+r):(o.setAttribute("y",Math.round(t.top+r+i.height).toString()),t.top+=i.height+r)}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=S("text",{x:"-100px",y:"-100px"}),this.svg_node.appendChild(this.text_measurement_node)),typeof t<"u"?(typeof t=="string"&&(t=[t]),this.text_measurement_node.setAttribute("class",t.join(" "))):this.text_measurement_node.setAttribute("class",""),this.text_measurement_node.textContent=e;let n=this.text_measurement_node.getBoundingClientRect(),o={width:n.width,height:n.height,y_offset:n.height-(this.bounds.top-n.top-100)};return r&&(o.width=Math.ceil(o.width),o.height=Math.ceil(o.height),o.y_offset=Math.ceil(o.y_offset)),o}RenderTicks(e,t,r,n,o){let i=[],s=e.width/n;for(let l=0;l<n;l++){let c=Math.round(e.left+s/2+s*l)-.5;i.push(`M${c} ${t} L${c} ${r}`)}this.group.appendChild(S("path",{d:i,class:o}))}RenderXAxisBar(e,t,r,n,o){let i=r.length;if(!i)return;let s=4,l=t?e.width/i:e.width/(i-1),c=t?l/2:0,u=1,d=!0;for(;d;){d=!1;let m=0;for(let b=0;b<i;b+=u){let p=Math.round(e.left+c+l*b),h=p-n[b].width/2;if(m&&h<=m){u++,d=!0;break}m=p+n[b].width/2+s}}for(let m=0;m<i;m+=u){let b=Math.round(e.left+c+l*m);this.RenderText(this.axis_group,r[m],"center",{x:b,y:e.bottom},o)}}RenderXAxisTicks(e,t,r){let n=t?e.width/r:e.width/(r-1),o=t?n/2:0,i=[];for(let s=0;s<r;s++){let l=Math.round(e.left+o+n*s)+.5;i.push(`M${l},${e.bottom+.5} v6`)}this.axis_group.appendChild(S("path",{d:i.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,n,o){let i=r.length;if(!i)return;let s=4,l=t?e.width/i:e.width/(i-1),c=t?l/2:0,u=1,d=!0,m=(r.length-1)%2===0,b=(r.length-1)%3===0;for(;d;){d=!1;let p=0;for(let h=0;h<i;h+=u){let f=Math.round(e.left+c+l*h),y=f-n[h].width/2;if(p&&y<=p){u++,d=!0;break}p=f+n[h].width/2+s}}u===3&&!b&&m&&u++;for(let p=0;p<i;p+=u){let h=Math.round(e.left+c+l*p);this.RenderText(this.axis_group,r[p],"center",{x:h,y:e.bottom},o)}}RenderYAxisBar(e,t,r,n){r=r.slice(0),r.reverse();let o=r.length;if(!o)return;let i=e.height/o,s=1,l=!0;for(;l;){l=!1;let c=0;for(let u=0;u<o;u+=s){let d=r[u],m=Math.round(e.bottom-i*(u+.5)+d.metrics.height/4);if(c&&m>=c){s++,l=!0;break}c=m-d.metrics.height}}for(let c=0;c<o;c+=s){let u=r[c],d=Math.round(e.bottom-i*(c+.5)+u.metrics.height/4);this.RenderText(this.axis_group,u.label,"right",{x:t,y:d},n)}}RenderYAxis(e,t,r,n,o="right"){let i=r.length;if(!i)return;let s=e.height/(i-1),l=1,c=!0;for(;c;){c=!1;let u=0;for(let d=0;d<i;d+=l){let m=r[d],b=Math.round(e.bottom-s*d+m.metrics.height/4);if(u&&b>=u){l++,c=!0;break}u=b-m.metrics.height}}for(let u=0;u<i;u+=l){let d=r[u],m=Math.round(e.bottom-s*u+d.metrics.height/4);this.RenderText(this.axis_group,d.label,o,{x:t,y:m},n)}}LineProperties(e,t){let r=t.x-e.x,n=t.y-e.y;return{length:Math.sqrt(r*r+n*n),angle:Math.atan2(n,r)}}RenderSmoothLine(e,t,r=!1,n,o){let i=S("g"),s=[],l=[],c=t.length,u=c-1,d=e.width/c/2,m=[],b=t.map((f,y)=>{if(!(typeof f>"u"))return{x:Math.round(e.left+e.width/u*y),y:e.bottom-f}}),p=[],h=()=>{if(p.length<2)return;let f="",y=p[0],x=p[p.length-1];p.length===2?f=`${p[0].x},${p[0].y} L${p[1].x},${p[1].y}`:p.length>2&&(f=""+this.CatmullRomChain(p).map(w=>`${w.x},${w.y}`).join(" L")),f&&(s.push("M"+f),r&&(l.push(`M ${y.x},${e.bottom} L ${y.x},${y.y}`),l.push("L"+f),l.push(`L ${x.x},${e.bottom}`)))};for(let f of b)f?p.push(f):(h(),p=[]);if(p.length&&h(),r&&i.appendChild(S("path",{class:"fill",d:l})),i.appendChild(S("path",{class:"line",d:s})),typeof o<"u"&&(typeof o=="string"&&(o=[o]),i.setAttribute("class",o.join(" "))),this.group.appendChild(i),n&&m.length){let f=S("g");for(let y of m){let x=S("circle",{cx:y.x,cy:y.y,r:d});x.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n[y.i]||"")}),x.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),f.appendChild(x)}f.setAttribute("class","mouse-layer"),this.group.appendChild(f)}}RenderLine(e,t,r=!1,n,o){let i=S("g"),s=[],l=[],c=t.length,u=c-1,d=e.width/c/2,m=[],b=0,p=!0,h;for(;b<c;b++){let f=t[b];if(typeof f>"u"){p=!0,r&&typeof h<"u"&&l.push(`L${h} ${e.bottom}Z`),h=void 0;continue}let y=Math.round(+e.left+e.width/u*b);p?(r&&l.push(`M${y} ${e.bottom} L${y} ${e.bottom-f}`),s.push(`M${y} ${e.bottom-f}`)):(s.push(`L${y} ${e.bottom-f}`),l.push(`L${y} ${e.bottom-f}`)),m.push({x:y,y:e.bottom-f,i:b}),h=y,p=!1}if(r&&typeof h<"u"&&l.push(`L${h} ${e.bottom}Z`),r&&i.appendChild(S("path",{class:"fill",d:l})),i.appendChild(S("path",{class:"line",d:s})),typeof o<"u"&&(typeof o=="string"&&(o=[o]),i.setAttribute("class",o.join(" "))),this.group.appendChild(i),n&&m.length){let f=S("g");for(let y of m){let x=S("circle",{cx:y.x,cy:y.y,r:d});x.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n[y.i]||"")}),x.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),f.appendChild(x)}f.setAttribute("class","mouse-layer"),this.group.appendChild(f)}}RenderBarGrid(e,t,r){let n=[],o=e.width/t;for(let i=0;i<=t;i++){let s=Math.round(e.left+o*i)-.5;n.push(`M${s} ${e.top} L${s} ${e.bottom}`)}this.group.appendChild(S("path",{d:n,class:r}))}RenderGrid(e,t,r=0,n,o){let i=[],s=[],l=e.height/t;for(let c=0;c<=t;c++){let u=Math.round(e.top+l*c)-.5;o&&o[1]===c?s.push(`M${e.left} ${u} L${e.right} ${u}`):i.push(`M${e.left} ${u} L${e.right} ${u}`)}l=e.width/(r-1);for(let c=0;c<r;c++){let u=Math.round(e.left+l*c)-.5;o&&o[0]===c?s.push(`M${u} ${e.top} L${u} ${e.bottom}`):i.push(`M${u} ${e.top} L${u} ${e.bottom}`)}this.group.appendChild(S("path",{d:i,class:n})),s.length&&(n?Array.isArray(n)?n.push("zero"):n=n+" zero":n="zero",this.group.appendChild(S("path",{d:s,class:n})))}MultiplyPoint(e,t){return{x:e.x*t,y:e.y*t}}AddPoints(e,t){return{x:e.x+t.x,y:e.y+t.y}}CatmullRomSpline(e,t){let r=.5;r=r/2;let n=(d,m,b)=>{let{x:p,y:h}=m,{x:f,y}=b;return((f-p)**2+(y-h)**2)**r+d},o=0,i=n(o,e[0],e[1]),s=n(i,e[1],e[2]),l=n(s,e[2],e[3]),c=(s-i)/t,u=[];for(let d=0;d<t;d++){let m=i+c*d,b=this.AddPoints(this.MultiplyPoint(e[0],(i-m)/(i-o)),this.MultiplyPoint(e[1],(m-o)/(i-o))),p=this.AddPoints(this.MultiplyPoint(e[1],(s-m)/(s-i)),this.MultiplyPoint(e[2],(m-i)/(s-i))),h=this.AddPoints(this.MultiplyPoint(e[2],(l-m)/(l-s)),this.MultiplyPoint(e[3],(m-s)/(l-s))),f=this.AddPoints(this.MultiplyPoint(b,(s-m)/(s-o)),this.MultiplyPoint(p,(m-o)/(s-o))),y=this.AddPoints(this.MultiplyPoint(p,(l-m)/(l-i)),this.MultiplyPoint(h,(m-i)/(l-i))),x=this.AddPoints(this.MultiplyPoint(f,(s-m)/(s-i)),this.MultiplyPoint(y,(m-i)/(s-i)));u.push(x)}return u}CatmullRomChain(e,t=30){let r=e.slice(0),n=[],o=r.length;if(o){let i=r[o-1].x-r[o-2].x,s=r[o-1].y-r[o-2].y;r.push({x:r[o-1].x+i,y:r[o-1].y+s}),r.push({x:r[o-1].x+i,y:r[o-1].y+s}),i=r[1].x-r[0].x,s=r[1].y-r[0].y,r.unshift({x:r[0].x-i,y:r[0].y-s});for(let l=0;l<r.length-4;l++){let c=r.slice(l,l+4),u=this.CatmullRomSpline(c,t);n.push(...u)}}return n}RenderDataLabels(e,t,r,n,o,i,s){let l=Math.max(t.length,r.length),c=n.max-n.min||1,u=o.max-o.min||1;for(let d=0;d<l;d++){let m=t[d],b=r[d];if(m!==void 0&&b!==void 0){let p={x:e.left+(m-n.min)/c*e.width,y:e.bottom-(b-o.min)/u*e.height},h=i[d];if(h){this.label_group.appendChild(S("circle",{class:"label-target",cx:p.x,cy:p.y,r:10}));let f=S("g",{class:"data-label",transform:`translate(${p.x+10},${p.y})`});this.label_group.appendChild(f);let y=S("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${s}`});f.appendChild(y);let x=S("text",{x:4,y:0},h);f.appendChild(x);let v=x.getBoundingClientRect(),w=v.height,g=v.width+8;g+15+p.x>=e.right&&(f.setAttribute("transform",`translate(${p.x-g-15},${p.y})`),y.setAttribute("cx",(g+15).toString()));let C=S("path",{d:`M0,5 h${g} v-${w} h-${g} Z`});f.insertBefore(C,x)}}}}RenderBoxAndWhisker(e,t,r,n,o,i,s){let l=S("g",{class:s});this.group.appendChild(l);let c=e.width/i,u=c*.2,m=Math.min(c-2*u,90);n>0&&(m=m*Math.sqrt(t.n)/Math.sqrt(n));let b=y=>e.top+e.height-(y-o.min)/(o.max-o.min)*e.height,p=e.left+r*c+c/2,h=b(t.quartiles[0]),f=b(t.quartiles[2]);l.appendChild(S("rect",{class:"iqr",x:e.left+r*c+(c-m)/2,y:f,width:m,height:h-f})),l.appendChild(S("line",{class:"median",x1:p-m*.5,x2:p+m*.5,y1:b(t.quartiles[1]),y2:b(t.quartiles[1])})),l.appendChild(S("line",{class:"whisker",x1:p-m*.25,x2:p+m*.25,y1:b(t.whiskers[0]),y2:b(t.whiskers[0])})),l.appendChild(S("line",{class:"whisker-extent",x1:p,x2:p,y1:b(t.whiskers[0])-2,y2:b(t.quartiles[0])+2})),l.appendChild(S("line",{class:"whisker",x1:p-m*.25,x2:p+m*.25,y1:b(t.whiskers[1]),y2:b(t.whiskers[1])})),l.appendChild(S("line",{class:"whisker-extent",x1:p,x2:p,y1:b(t.whiskers[1])+2,y2:b(t.quartiles[2])-2}));for(let y of t.data)(y<t.whiskers[0]||y>t.whiskers[1])&&l.appendChild(S("circle",{class:"outlier",cx:p,cy:b(y),r:3}))}RenderBubbleSeries(e,t,r,n,o){let i=r.max-r.min||1,s=n.max-n.min||1,l=[],c=[],u=S("g",{class:o});if(this.group.appendChild(u),t.z)for(let[d,m]of t.z.data.entries()){let b=t.x.data[d],p=t.y.data[d];if(typeof b<"u"&&typeof p<"u"&&typeof m<"u"&&m>0){let h=m/i*e.width,f=m/s*e.height,y=Math.max(h,f),x={x:e.left+(b-r.min)/i*e.width,y:e.bottom-(p-n.min)/s*e.height,z:y};if(l.push(x),t.labels?.[d]){let v=x.z/2;c.push({x:x.x,y:x.y,text:t.labels?.[d]||"",offset:Math.cos(Math.PI/4)*v})}}}for(let d of l)d&&u.appendChild(S("circle",{cx:d.x,cy:d.y,r:d.z/2,class:"point"}));if(c.length){let d=this.label_group.getBoundingClientRect();for(let m of c)if(m.text){let b=this.label_group.appendChild(S("g",{class:"bubble-label"})),p=b.appendChild(S("rect",{x:m.x,y:m.y,class:"label-background"})),f=b.appendChild(S("text",{x:m.x,y:m.y,offset:m.offset,class:"label-text","text-anchor":"middle","alignment-baseline":"middle",style:`--translate-offset: ${Math.round(m.offset)}px`},m.text)).getBoundingClientRect();p.setAttribute("x",(f.left-d.left-2).toString()),p.setAttribute("y",(f.top-d.top-1).toString()),p.style.height=f.height+2+"px",p.style.width=f.width+4+"px"}}}RenderScatterSeries(e,t,r,n,o,i=!0,s=!1,l=!1,c=!1,u=!1,d){let m=Math.max(t.length,r.length),b=n.max-n.min||1,p=o.max-o.min||1,h=[],f=[],y=[],x=S("g",{class:d});this.group.appendChild(x);for(let v=0;v<m;v++){let w=t[v],g=r[v];typeof w>"u"||typeof g>"u"?h.push(void 0):h.push({x:e.left+(w-n.min)/b*e.width,y:e.bottom-(g-o.min)/p*e.height})}if(i){let v=[],w=u?()=>v.length===2?`${v[0].x},${v[0].y} L${v[1].x},${v[1].y}`:v.length>2?this.CatmullRomChain(v).map(C=>`${C.x},${C.y}`).join(" L"):"":()=>v.map(g=>`${g.x},${g.y}`).join(" L");for(let g of h)if(g)v.push(g);else{if(v.length>=2){let C=w();f.push("M"+C),y.push(`M${v[0].x},${e.bottom}L`+C+`L${v[v.length-1].x},${e.bottom}Z`)}v=[]}if(v.length>=2){let g=w();f.push("M"+g),y.push(`M${v[0].x},${e.bottom}L`+g+`L${v[v.length-1].x},${e.bottom}Z`)}}if(l&&x.appendChild(S("path",{d:y,class:"fill"})),i&&x.appendChild(S("path",{d:f,class:"line"})),s)for(let v of h)v&&x.appendChild(S("circle",{cx:v.x,cy:v.y,r:1,class:"point"}));if(c)for(let v of h)v&&x.appendChild(S("circle",{cx:v.x,cy:v.y,r:3,class:"marker"}))}RenderPoints(e,t,r,n){let o=[];for(let i=0;i<t.length;i++){let s=t[i]*e.width+e.left,l=e.bottom-r[i]*e.height;o.push(`M${s-1},${l-1} L${s+1},${l+1}`),o.push(`M${s-1},${l+1} L${s+1},${l-1}`)}this.group.appendChild(S("path",{d:o,class:n}))}RenderPoint(e,t,r){this.group.appendChild(S("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=S("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(S("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,n,o,i){let s="";if(t)if(t[0]&&t[0]===t[1]&&t[0]>=e.height){let c=t[0],u=t[0]-e.height,d=Math.sqrt(c*c-u*u);s=`M${e.left+e.width/2-d},${e.bottom} a${c},${c} 0 0 1 ${d*2},0 z`}else if(t[1]&&t[1]===t[2]&&t[1]>=e.width){let c=t[1],u=t[1]-e.width,d=Math.sqrt(c*c-u*u);s=`M${e.left},${e.top+e.height/2-d} a${c},${c} 0 0 1 0,${d*2} z`}else s=`M${e.left},${e.top+t[0]} a${t[0]},${t[0]} 0 0 1 ${t[0]},${-t[0]} h${e.width-t[0]-t[1]} a${t[1]},${t[1]} 0 0 1 ${t[1]},${t[1]} v${e.height-t[1]-t[2]} a${t[2]},${t[2]} 0 0 1 ${-t[2]},${t[2]} h${-e.width+t[2]+t[3]} a${t[3]},${t[3]} 0 0 1 ${-t[3]},${-t[3]} v${-e.height+t[3]+t[0]} `;else s=`M${e.left},${e.top} h${e.width} v${e.height} h${-e.width} v${-e.height} `;let l=S("path",{d:s,class:r});if(n&&(l.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",n)}),l.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")})),this.group.appendChild(l),o){this.label_group.appendChild(S("path",{class:"label-target",d:s}));let c=i||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},u=S("g",{class:"data-label",transform:`translate(${c.x},${c.y})`});this.label_group.appendChild(u);let d=S("text",{x:0,y:0},o);u.appendChild(d);let m=d.getBoundingClientRect(),b=m.height,p=m.width+8;c.y-m.height<4&&(c.y-=c.y-m.height-4,u.setAttribute("transform",`translate(${c.x},${c.y})`)),d.setAttribute("x",Math.floor(-m.width/2).toString());let h=Math.ceil(b*.125),f=S("rect",{rx:3,x:-p/2,y:Math.round(-b+h*2/3),width:p,height:b+h});u.insertBefore(f,d)}}RenderText(e,t,r,n,o){let i=S("text",{x:n.x,y:n.y,class:o},t);switch(r){case"right":i.style.textAnchor="end";break;case"center":i.style.textAnchor="middle";break;default:i.style.textAnchor="start";break}(e||this.group).appendChild(i)}RenderDonut(e,t,r,n,o,i,s){let l=-Math.PI/2,c=0;i&&(r*=.8,n*=.7);let u=(d,m,b)=>[Math.cos(b)*m+d.x,Math.sin(b)*m+d.y];for(let d of e){let m=d.title||"",b=d.percent,p=d.index,h=[],f=0,y=u.bind(0,t,r),x=u.bind(0,t,n);if(b>.5){f=l+b/2*Math.PI*2,c=l+b*Math.PI*2;let g=f-l,C=c-f;h.push(`M${y(l)}`,`A${r},${r},${g},0,1,${y(f)}`,`A${r},${r},${C},0,1,${y(c)}`,`L${x(c)}`,`A${n},${n},${C},0,0,${x(f)}`,`A${n},${n},${g},0,0,${x(l)}`,"Z")}else{c=l+b*Math.PI*2,f=(c-l)/2+l;let g=c-l;h.push(`M${y(l)}`,`A${r},${r},${g},0,1,${y(c)}`,`L${x(c)}`,`A${n},${n},${g},0,0,${x(l)}`,"Z")}let v=S("path",{d:h,class:typeof p>"u"?void 0:`series-${p}`});typeof p<"u"&&v.setAttribute("data-index",p.toString());let w=S("g",{class:s});if(w.appendChild(v),this.group.appendChild(w),b>=.05&&m){let g=r-n;h=[];let C=u(t,n+(r-n)/2+g,f);h.push(`M${u(t,n+(r-n)/2,f)}`),h.push(`L${C}`),w.appendChild(S("path",{d:h,class:"callout"}));let U=[],V=S("text",{class:"callout-label"});w.appendChild(V);let L=f+Math.PI/2,M=m;V.textContent=M;let A=V.getBoundingClientRect(),G={width:A.width,height:A.height},[j,se]=C;j+=G.height/2*Math.cos(f),se+=G.height/4+G.height/2*Math.sin(f);let de=!1;L>Math.PI?j-G.width<=o.left&&(de=!0):j+G.width>o.right&&(de=!0);let Wt=/[\s-]/;if(de&&Wt.test(M)){let me=-1,be=1;for(let pe=0;pe<M.length;pe++)if(Wt.test(M[pe])){let Q=Math.abs(.5-pe/M.length);Q<be&&(be=Q,me=pe)}me>0&&(U.push(M.substr(0,me+1).trim()),U.push(M.substr(me+1).trim()))}if(U.length){let me=0,be=0,pe=U.map(Q=>{V.textContent=Q,A=V.getBoundingClientRect();let he={width:A.width,height:A.height};return be=Math.max(be,he.width),{text:Q,metrics:he}});V.textContent="";for(let Q of pe){let he=S("tspan");he.textContent=Q.text;let wn=L>Math.PI?j-(be-Q.metrics.width)/2:j+(be-Q.metrics.width)/2;he.setAttribute("x",wn.toString()),he.setAttribute("dy",me.toString()),V.appendChild(he),me=Q.metrics.height}}let xn=L>Math.PI?"end":"start";V.setAttribute("text-anchor",xn),V.setAttribute("x",j.toString()),V.setAttribute("y",se.toString()),typeof p<"u"&&V.setAttribute("data-index",p.toString())}l=c}}};var ut=class{renderer=new ct;margin={top:.025,left:.05,bottom:.025,right:.075};Resize(e,t){this.renderer.Resize()}Initialize(e){this.renderer.Initialize(e)}Update(e,t){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(t.class_name);let r=new re(0,0,this.renderer.size.width,this.renderer.size.height),n={top:Math.round(r.height)*this.margin.top,bottom:Math.round(r.height)*this.margin.bottom,left:Math.round(r.width)*this.margin.left,right:Math.round(r.width)*this.margin.right},o=t.title;if(o&&this.renderer.RenderTitle(o,r,n.top,t.title_layout||"top"),r.top+=n.top,r.left+=n.left,r.bottom-=n.bottom,r.right-=n.right,t.legend&&t.legend.length){let s=0;t.title&&(!t.title_layout||t.title_layout==="top")&&(s=1);let l=t.legend_position||s;this.renderer.Legend({labels:t.legend,position:l,style:t.legend_style,layout:l===0||l===1?0:1,area:r})}if(t.type==="histogram"||t.type==="line"||t.type==="area"||t.type==="column"||t.type==="histogram2"||t.type==="bar"||t.type==="scatter2"||t.type==="bubble"||t.type==="box"){let s=[],l=0;t.x_labels&&t.x_labels.length&&(s=t.x_labels.map(m=>{let b=this.renderer.MeasureText(m,["axis-label","x-axis-label"],!0);return l=Math.max(l,b.height),b}));let c=[],u=0;t.type==="box"&&t.series_names?.length&&(c=t.series_names.map(m=>{let b=this.renderer.MeasureText(m,["axis-label","x-axis-label","series-name"],!0);return u=Math.max(u,b.height),b}));let d=l&&u?4:0;if(t.y_labels&&t.y_labels.length){let m=[],b=0,p=0,h=t.type==="scatter2"||t.type==="bubble"?t.y_scale:t.scale,f=t.type==="bar"?t.y_labels.length:h.count+1;for(let y=0;y<f;y++){let x=this.renderer.MeasureText(t.y_labels[y],["axis-label","y-axis-label"]);m.push({label:t.y_labels[y],metrics:x}),b=Math.max(b,x.width),p=Math.max(p,x.height)}r.bottom=Math.round(r.bottom-p/2),r.top=Math.round(r.top+p/2),s.length&&(r.bottom-=l+n.bottom),c.length&&(r.bottom-=u+n.bottom),d&&(r.bottom-=d),t.type==="bar"?this.renderer.RenderYAxisBar(r,r.left+b,m,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(r,r.left+b,m,["axis-label","y-axis-label"]),r.left+=b+n.left}if(t.type==="scatter2"&&t.y2_labels&&t.y2_labels.length&&t.y2_scale){let m=[],b=0,p=0,f=t.y2_scale.count+1;for(let y=0;y<f;y++){let x=this.renderer.MeasureText(t.y2_labels[y],["axis-label","y-axis-label"]);m.push({label:t.y2_labels[y],metrics:x}),b=Math.max(b,x.width),p=Math.max(p,x.height)}this.renderer.RenderYAxis(r,r.right-b,m,["axis-label","y-axis-label"],"left"),r.right-=b+n.left}if(s.length&&t.x_labels?.length){let m=t.type==="histogram2",b=t.type!=="line"&&t.type!=="area"&&t.type!=="bar"&&t.type!=="scatter2"&&t.type!=="bubble"&&t.type!=="histogram2";m&&this.renderer.RenderXAxisTicks(r,b,t.x_labels.length),t.y_labels&&(r.bottom+=l+n.bottom),this.renderer.RenderXAxis(r,b,t.x_labels,s,["axis-label","x-axis-label"]),r.bottom-=l+n.bottom}d&&(r.bottom+=d),t.type==="box"&&c.length&&t.series_names?.length&&(t.y_labels&&(r.bottom+=l+u+d+n.bottom),this.renderer.RenderXAxis(r,!0,t.series_names,c,["axis-label","x-axis-label","series-name"]),r.bottom-=l+u+n.bottom+n.bottom)}let i=[];switch(t.type){case"scatter":this.renderer.RenderPoints(r,t.x,t.y,"mc mc-correlation series-1");break;case"box":this.renderer.RenderGrid(r,t.scale.count,void 0,"chart-grid",i);for(let[s,l]of t.data.entries())l.iqr>0&&this.renderer.RenderBoxAndWhisker(r,l,s,t.max_n,t.scale,t.data.length,`box-plot series-${s}`);break;case"bubble":t.x_scale.min<=0&&t.x_scale.max>=0&&(i[0]=Math.round(Math.abs(t.x_scale.min/t.x_scale.step))),t.y_scale.min<=0&&t.y_scale.max>=0&&(i[1]=Math.round(Math.abs(t.y_scale.max/t.y_scale.step))),this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid",i);for(let[s,l]of t.series.entries()){let c=typeof l.index=="number"?l.index:s+1;this.renderer.RenderBubbleSeries(r,l,t.x_scale,t.y_scale,`bubble-chart series-${c}`)}break;case"scatter2":if(this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid"),t.series){for(let s=0;s<t.series.length;s++){let l=t.series[s],c=!!t.lines,u=!!t.points;l.subtype==="plot"?(u=!0,c=!1):l.subtype==="line"&&(u=!1,c=!0);let d=typeof l.index=="number"?l.index:s+1;this.renderer.RenderScatterSeries(r,l.x.data,l.y.data,t.x_scale,l.axis&&t.y2_scale?t.y2_scale:t.y_scale,c,u,!!t.filled,!!t.markers,!!t.smooth,`scatter-plot series-${d}`)}if(t.data_labels)for(let s=0;s<t.series.length;s++){let l=t.series[s];l.y.labels&&this.renderer.RenderDataLabels(r,l.x.data,l.y.data,t.x_scale,t.y_scale,l.y.labels,s+1)}}break;case"pie":case"donut":{let s=Math.min(r.height,r.width)/2*.9,l=t.type==="pie"?0:s*.8;this.renderer.RenderDonut(t.slices,r.center,s,l,r,!0,"donut")}break;case"line":case"area":{let s=t.scale;if(t.series){let l=t.x_scale?t.x_scale.max:Math.max.apply(0,t.series.map(d=>d.length)),c=t.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(r,t.scale.count,t.x_scale?t.x_scale.count+1:l,"chart-grid");let u=0;for(let d of t.series){let m=d.map(p=>{if(!(typeof p>"u"))return E.ApplyScale(p,r.height,s)});if(m.length<l)for(let p=m.length;p<l;p++)m.push(void 0);let b=[t.type==="area"?"chart-area":"chart-line",`series-${u+1}`];c.call(this.renderer,r,m,t.type==="area",t.titles,b),u++}}}break;case"bar":{let s;if(this.renderer.RenderBarGrid(r,t.scale.count,"chart-grid"),t.series2){let l=0,c=t.series2.length;for(let h of t.series2)l=Math.max(l,h.y.data.length);let u=r.height/l,d=.7;typeof t.space=="number"&&(d=Math.max(0,Math.min(1,1-t.space)));let m=u*(1-d)/2,b=(u-m*2)/c,p=0;if(t.scale.min<0&&(p=E.ApplyScale(0,r.width,t.scale)),t.round){let h=Math.floor(b/2);s=[0,h,h,0]}for(let h=0;h<c;h++){let f=t.series2[h],y=typeof f.index=="number"?f.index:h+1;for(let x=0;x<f.y.data.length;x++){let v=f.y.data[x];if(typeof v=="number"){let w=Math.round(r.top+x*u+m)+h*b,g=0,C=0;p?v>0?(C=E.ApplyScale(v+t.scale.min,r.width,t.scale),g=r.left+p):(C=E.ApplyScale(t.scale.min-v,r.width,t.scale),g=r.left+p-C):(C=E.ApplyScale(v,r.width,t.scale),g=r.left),C&&this.renderer.RenderRectangle(new re(g,w,g+C,w+b),s,["chart-column",`series-${y}`],void 0||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid"),t.series2){let s=0,l=t.series2.length;for(let h of t.series2)s=Math.max(s,h.y.data.length);let c=r.width/s,u=.7;typeof t.space=="number"&&(u=Math.max(0,Math.min(1,1-t.space)));let d=c*(1-u)/2,m=(c-d*2)/l,b=0;if(t.scale.min<0&&(b=E.ApplyScale(0,r.height,t.scale)),t.callouts&&t.x_scale){let h=t.x_scale,f=t.callouts.map((y,x)=>{let v=Math.round(r.left+E.ApplyScale(y.value,r.width,h))+.5;return{x1:v,y1:r.bottom-r.height,x2:v,y2:r.bottom,classes:`callout-${x+1}`}});this.renderer.RenderCalloutLines(f)}let p;if(t.round){let h=Math.floor(m/2);p=[h,h,0,0]}if(t.stacked_series)for(let h=0;h<t.stacked_series[0].y.data.length;h++){let f=r.left+h*c+d,y=0;for(let x=0;x<t.stacked_series.length;x++){let v=t.stacked_series[x],w=typeof v.index=="number"?v.index:x+1,g=0,C=v.y.data[h]||0;x===0&&(y=Math.min(t.scale.min||0,C)),g=E.ApplyScale(C,r.height,t.scale);let U=r.bottom-g-E.ApplyScale(y,r.height,t.scale);this.renderer.RenderRectangle(new re(f,U,f+m,U+g),p,["chart-column",`series-${w}`],void 0||void 0,void 0,void 0),y+=C}}else for(let h=0;h<l;h++){let f=t.series2[h],y=typeof f.index=="number"?f.index:h+1;for(let x=0;x<f.y.data.length;x++){let v=f.y.data[x];if(typeof v=="number"){let w=r.left+x*c+d+h*m,g=0,C=0;b?v>0?(g=E.ApplyScale(v+t.scale.min,r.height,t.scale),C=r.bottom-g-b):(g=E.ApplyScale(t.scale.min-v,r.height,t.scale),C=r.bottom-b):(g=E.ApplyScale(v,r.height,t.scale),C=r.bottom-g);let U=void 0;if(g){let V=t.data_labels&&f.y.labels?f.y.labels[x]:"",L={x:Math.round(w+m/2),y:Math.round(C-10)};this.renderer.RenderRectangle(new re(w,C,w+m,C+g),p,["chart-column",`series-${y}`],U||void 0,V,L)}}}}}break;case"histogram":{this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid");let s=r.width/t.count,l=t.column_width,c=s*(1-l)/2;for(let u=0;u<t.count;u++){let d=Math.round(r.left+u*s+c),m=s-c*2,b=E.ApplyScale(t.bins[u],r.height,t.scale),p=r.bottom-b,h=t.titles?t.titles[u]:void 0;this.renderer.RenderRectangle(new re(d,p,d+m,p+b),void 0,"chart-column series-1",h||void 0)}}break}}};var xe=class{constructor(e=new ut){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};node;Initialize(e){this.node=e,this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.chart_data=jt(r,"column");break;case"bar.chart":this.chart_data=jt(r,"bar");break;case"line.chart":this.chart_data=qt(r,"line");break;case"area.chart":this.chart_data=qt(r,"area");break;case"donut.chart":case"pie.chart":this.chart_data=hn(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.chart_data=Gt(r,"plot");break;case"scatter.line":this.chart_data=Gt(r,"line");break;case"bubble.chart":this.chart_data=pn(r);break;case"box.plot":this.chart_data=bn(r);break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}Resize(){this.node&&this.renderer.Resize(this.node,this.chart_data)}Update(){this.node&&this.renderer.Update(this.node,this.chart_data)}};var ne=(...a)=>({type:5,value:a,key:"arguments"}),Xt={Group:{arguments:[{name:"Array...",metadata:!0}],fn:(...a)=>({type:5,value:a,key:"group"}),category:["grouping"]},Series:{arguments:[{name:"Label"},{name:"X",metadata:!0},{name:"Y",metadata:!0},{name:"Z",metadata:!0},{name:"Index"},{name:"Subtype"},{name:"Labels",description:"Labels for bubble charts only (atm)"},{name:"Axis",description:"Series axis (scatter plot only)"}],fn:(...a)=>({type:5,value:{label:a[0],x:a[1],y:a[2],z:a[3],index:a[4],subtype:a[5],data_labels:a[6],axis:a[7]},key:"series"}),category:["chart functions"]},"Bar.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Line.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Area.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Pie.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels"},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:ne,category:["chart functions"]},"Donut.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels",metadata:!0},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:ne,category:["chart functions"]},"Scatter.Line":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Scatter.Plot":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:ne,category:["chart functions"]},"Column.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"Chart Title"}],fn:ne,category:["chart functions"]},"Bubble.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"}],fn:ne,category:["chart functions"]},"Box.Plot":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"},{name:"Min/Max Style"}],fn:ne,category:["chart functions"]}};var dt=class a{_ready_state=[];get ready(){return Promise.all(this._ready_state)}static treb_base_path="";static failed_dynamic_modules=[];static one_time_warnings={};static clipboard;DOM=le.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return ee}events=new rr;calculation=0;file_version=0;last_save_version=0;initial_load_source=void 0;calculator;grid;model;dialog;spinner;file_chooser;file_chooser_operation=0;get parser(){return this.model.parser}view_node;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;get active_sheet(){let e=this.grid.active_sheet.name;return Ue.test(e)?`'${e}'`:e}get modified(){return this.undo_stack.length!==1}get document_name(){return this.grid.model.document_name}set document_name(e){this.grid.model.document_name=e,this.DocumentChange()}get user_data(){return this.grid.model.user_data}set user_data(e){this.grid.model.user_data=e,this.DocumentChange()}get scale(){return this.grid.scale}set scale(e){this.grid.scale=e}get headless(){return this.grid.headless}set headless(e){this.grid.headless!==e&&(this.grid.headless=e,e||(this.grid.Update(!0),this.RebuildAllAnnotations()))}get state(){return this.file_version}get can_revert(){return!this.options.inline_document&&!this.options.document?!1:this.initial_load_source==="local-storage"?!0:this.dirty}get dirty(){return this.file_version!==this.last_save_version}set dirty(e){e?this.file_version++:this.last_save_version=this.file_version}get sheet_names(){return this.model.sheets.list.map(e=>e.name)}constructor(e){e.storage_key&&!e.local_storage&&(e.local_storage=e.storage_key),this.options={...on,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(Re.imaginary_character=this.options.imaginary_value),this.options.network_document&&(console.warn("the option `network_document` is deprecated. please use `document` instead."),this.options.document||(this.options.document=this.options.network_document)),this.options.document&&this.options.inline_document&&console.warn("both document and inline-document are provided");let t=this.options.document,r,n;this.options.local_storage&&!this.options.toll_initial_load&&!e.model&&(r=localStorage.getItem(this.options.local_storage)||void 0,r&&(n="local-storage")),!r&&!this.options.toll_initial_load&&!e.model&&e.inline_document&&(r=e.inline_document,n="inline-document"),this.options.local_storage&&!e.model&&window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.options.local_storage&&this.dirty&&this.SaveLocalStorage(this.options.local_storage)});let o;typeof this.options.container=="string"?o=document.querySelector(this.options.container):this.options.container&&(o=this.options.container);let i={in_cell_editor:!0,repaint_on_cell_change:!1,scrollbars:this.options.scrollbars,markdown:!!this.options.markdown,formula_bar:this.options.formula_bar,expand_formula_button:this.options.expand_formula_button,tab_bar:this.options.tab_bar,add_tab:this.options.add_tab,expand:this.options.expand,support_font_stacks:!!this.options.font_stack};if(this.options.scale&&(i.initial_scale=this.options.scale),this.options.stats&&(i.stats=this.options.stats,i.tab_bar=!0),this.options.scale_control&&(i.scale_control=!0,i.tab_bar=!0,this.options.persist_scale&&(i.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),i.persist_scale_key))){let l=localStorage.getItem(i.persist_scale_key);if(l)try{let c=JSON.parse(l);i.initial_scale=c.scale||1}catch{console.warn("parsing persisted scale failed")}}e.model?(this.model=e.model.model,this.calculator=e.model.calculator,this.DOM=e.model.DOM):(this.model=new ur,this.model.sheets.Add(dr.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,this.options));let s=this.calculator.InitResources();if(this._ready_state.push(s),o&&(this.DOM=le.GetInstance(o.ownerDocument)),e.custom_grid?this.grid=e.custom_grid.call(this,i,this.model,void 0,!!o,this.DOM):this.grid=new ir(i,this.model,void 0,!!o,this.DOM),this.options.headless&&(this.grid.headless=!0),this.LoadLanguage(e.language),o){this.DOM=le.GetInstance(o.ownerDocument),this.parent_view||(Ee.is_windows?o.parentElement?.classList.add("treb-ua-windows"):Ee.is_mac&&o.parentElement?.classList.add("treb-ua-osx"),Ee.is_iphone&&o.parentElement?.classList.add("treb-ua-iphone"));let l=o.querySelector(".treb-view-template");this.view_node=l.content.firstElementChild?.cloneNode(!0),o.prepend(this.view_node),this.view_node.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=u=>this.HandleKeyDown(u),o.addEventListener("keydown",this.key_listener);let c=!!(r||this.options.document);this.grid.Initialize(this.view_node,c),this.options.dnd&&(this.view_node.addEventListener("dragenter",u=>this.HandleDrag(u)),this.view_node.addEventListener("dragover",u=>this.HandleDrag(u)),this.view_node.addEventListener("drop",u=>this.HandleDrop(u))),this.grid.grid_events.Subscribe(u=>{switch(u.type){case"error":this.dialog?.ShowDialog({type:"error",...this.TranslateGridError(u.code),timeout:3e3,close_box:!0});break;case"selection":this.UpdateSelection(u.selection,u.reason),this.UpdateSelectionStyle(u.selection);break;case"sheet-change":this.OnSheetChange(u),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.Publish({type:"view-change"});break;case"cell-event":this.HandleCellEvent(u);break;case"composite":{let d=this.last_selection;this.calculation===0&&this.Recalculate(u),this.DocumentChange(d),this.UpdateDocumentStyles(),this.UpdateSelectionStyle()}break;case"data":{let d=this.last_selection;this.calculation===0&&this.Recalculate(u),this.DocumentChange(d)}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(),this.UpdateSelectionStyle();break;case"annotation":if(u.annotation){let d=u.annotation.view[this.grid.view_index]||{},m=!1;if(u.event==="select")m=!0;else switch(this.DocumentChange(),u.event){case"create":this.InflateAnnotation(u.annotation),this.calculator.UpdateAnnotations(u.annotation,this.grid.active_sheet),this.grid.AnnotationUpdated(u.annotation),m=u.annotation===this.grid.selected_annotation;break;case"delete":this.calculator.RemoveAnnotation(u.annotation);break;case"update":d.update_callback?(d.update_callback(),this.grid.AnnotationUpdated(u.annotation)):console.info("annotation update event without update callback"),this.calculator.UpdateAnnotations(u.annotation,this.grid.active_sheet),m=u.annotation===this.grid.selected_annotation;break;case"resize":d.resize_callback&&(d.resize_callback(),this.grid.AnnotationUpdated(u.annotation));break}if(m){this.UpdateSelectionStyleAnnotation(u.annotation),this.Publish({type:"annotation-selection"});break}}else console.info("annotation event without annotation");break;case"structure":{let d=this.last_selection;u.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),u.rebuild_required?(this.calculator.Reset(),this.calculation===0&&this.Recalculate(u),this.DocumentChange(d)):this.DocumentChange(d)}this.UpdateSelectionStyle();break}}),this.options.prompt_save&&window.addEventListener("beforeunload",u=>{this.last_save_version!==this.file_version&&(u.preventDefault(),u.returnValue="")})}else e.custom_grid&&(console.info("creating subscription for custom grid (TODO: capabilities)"),this.grid.grid_events.Subscribe(l=>{switch(l.type){case"error":break;case"selection":this.UpdateSelection(l.selection,l.reason),this.UpdateSelectionStyle(l.selection);break;case"sheet-change":this.OnSheetChange(l),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.Publish({type:"view-change"});break;case"cell-event":this.HandleCellEvent(l);break;case"composite":{let c=this.last_selection;this.calculation===0&&this.Recalculate(l),this.DocumentChange(c),this.UpdateDocumentStyles(),this.UpdateSelectionStyle()}break;case"data":{let c=this.last_selection;this.calculation===0&&this.Recalculate(l),this.DocumentChange(c)}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(),this.UpdateSelectionStyle();break;case"annotation":break;case"structure":{let c=this.last_selection;l.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),l.rebuild_required?(this.calculator.Reset(),this.calculation===0&&this.Recalculate(l),this.DocumentChange(c)):this.DocumentChange(c)}this.UpdateSelectionStyle();break}})),a.one_time_warnings.headless||e.headless||(a.one_time_warnings.headless=!0,console.info("not initializing layout; don't call UI functions"));if(e.preload&&e.preload.call(0,this),r?(typeof r=="string"&&(r=JSON.parse(r)),r?s.then(()=>{this.LoadDocument(r,{recalculate:!!this.options.recalculate,source:n})}):this.UpdateDocumentStyles()):t||(this.calculator.RebuildClean(!0),this.UpdateDocumentStyles()),this.FlushUndo(),this.grid.ShowHeaders(this.options.headers),this.options.scroll&&!this.options.document){let l=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(l)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),o&&this.options.spinner&&(this.spinner=new st(o)),t&&!e.model&&!r&&s.then(()=>{this.LoadNetworkDocument(t,this.options)}),o&&(this.dialog=new it(o))}UpdateAC(){let e=this.calculator.SupportedFunctions();if(this.model.language_model?.functions){let t={};for(let r of this.model.language_model.functions||[])t[r.base.toUpperCase()]=r;e=e.map(r=>{let n=t[r.name.toUpperCase()];if(n){let o=JSON.parse(JSON.stringify({...r,name:n.name}));if(n.description&&(o.description=n.description),n.arguments&&o.arguments)for(let[i,s]of n.arguments.entries())o.arguments[i]&&(o.arguments[i].name=s);return o}return r})}this.grid.SetAutocompleteFunctions(e)}CreateCalculator(e,t){return new ot(e,{complex_numbers:t.complex,spill:t.spill,headless:t.headless})}TranslateGridError(e){switch(e){case 0:return{message:"No error"};case 2:return{message:"You can't change part of an array"};case 5:return{message:"Invalid area for paste"};case 4:return{message:"Invalid area for table"};case 3:return{message:"Invalid value (data validation)"};default:return{message:`Unknown error (${e})`}}}CreateView(){let e=new a({...this.options,global_name:void 0,model:this});return e.parent_view=this,e}Unsplit(){let e=this.views.pop();if(e){let t=e.view;t.grid.grid_events.CancelAll(),t.events.CancelAll(),t.view_node?.parentElement&&(t.key_listener&&t.view_node.parentElement.removeEventListener("keydown",t.key_listener),t.view_node.parentElement.removeChild(t.view_node)),this.view_node?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view_node?.addEventListener("focusin",()=>{this.focus_target!==e&&(this.Publish({type:"focus-view"}),this.focus_target=e)}),e.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(this.grid.EnsureActiveSheet(),this.grid.UpdateLayout(),this.grid.UpdateTabBar(),r.update_annotations&&(this.grid.RefreshAnnotations(),this.InflateAnnotations()))}),e.Subscribe(r=>{r.type==="selection"||(e.UpdateAnnotations(),this.grid.Update(!0),this.grid.UpdateAnnotations())}),this.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(e.grid.EnsureActiveSheet(),e.grid.UpdateLayout(),e.grid.UpdateTabBar(),r.update_annotations&&(e.grid.RefreshAnnotations(),e.InflateAnnotations()))});let t=this.Subscribe(r=>{switch(r.type){case"selection":break;case"load":case"reset":e.grid.EnsureActiveSheet(!0),e.UpdateAnnotations(),e.grid.UpdateAnnotations(),e.grid.Update(!0);break;default:e.UpdateAnnotations(),e.grid.Update(!0),e.grid.UpdateAnnotations()}});this.views.push({view:e,subscription:t})}ListConditionalFormats(e){return(typeof e>"u"?this.grid.active_sheet:this.model.sheets.Find(e))?.conditional_formats||[]}ConditionalFormatDuplicateValues(e,t){return this.AddConditionalFormat({type:"duplicate-values",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t})}ConditionalFormatGradient(e,t){let r=this.RangeOrSelection(e,"invalid range (no selection)"),n=typeof t=="object"?{type:"gradient",area:r,...t}:{type:"gradient",area:r,...mr[t]};return this.AddConditionalFormat(n),n}ConditionalFormatDataBars(e,t){let n={type:"data-bar",area:this.RangeOrSelection(e,"invalid range (no selection)"),fill:{theme:4,tint:.5},...t};return this.AddConditionalFormat(n),n}ConditionalFormatCellMatch(e,t){let r={type:"cell-match",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t};return this.AddConditionalFormat(r),r}ConditionalFormatExpression(e,t){let r={type:"expression",area:this.RangeOrSelection(e,"invalid range (no selection)"),...t};return this.AddConditionalFormat(r),r}AddConditionalFormat(e){return this.grid.AddConditionalFormat(e),e}RemoveConditionalFormat(e){this.grid.RemoveConditionalFormat({format:e})}RemoveConditionalFormats(e){let t=this.RangeOrSelection(e);t&&this.grid.RemoveConditionalFormat({area:t})}HandleToolbarMessage(e){if(this.focus_target!==this){this.focus_target.HandleToolbarMessage(e);return}let t={};if(this.grid.AnnotationSelected()){switch(e.command){case"adjust-font-scale":{let n=Number(e.delta||0),o=this.grid.GetAnnotationStyle()?.font_size;(!o||o.unit!=="em")&&(o={unit:"em",value:1}),o&&(o.value+=n,t.font_size=o,this.grid.ApplyAnnotationStyle(t))}break;case"font-scale":{let n=Number(e.scale||1);n&&!isNaN(n)&&(t.font_size={unit:"em",value:n},this.grid.ApplyAnnotationStyle(t))}break;case"font-stack":e.font_stack&&(t.font_face="stack:"+e.font_stack),this.grid.ApplyAnnotationStyle(t);break}this.Focus();return}let r=n=>{let o=this.grid.GetSelection();if(o&&!o.empty){let i=o.area.spreadsheet_label;n==="Scatter.Plot"||n==="Scatter.Line"||n==="Box.Plot"?this.InsertAnnotation(`=${n}(Series(,,${i}),"${i}")`,void 0,void 0,","):this.InsertAnnotation(`=${n}(${i},,"${i}")`,void 0,void 0,",")}};if(/^border-/.test(e.command))if(e.command==="border-color")try{t.border_top_fill=t.border_bottom_fill=t.border_left_fill=t.border_right_fill=e.color||{}}catch(n){console.error(n)}else{let n=1,o=e.command.substring(7);e.command==="border-double-bottom"&&(o="bottom",n=2),this.grid.ApplyBorders2(void 0,o,e.color||{},n)}else switch(e.command){case"about":this.About();break;case"number-format":t.number_format=e.format||"General";break;case"font-stack":e.font_stack&&(t.font_face="stack:"+e.font_stack);break;case"adjust-font-scale":{let n=this.selection_state.style?.font_size,o=this.grid.GetSelection(),i=this.grid.active_sheet.RealArea(o.area),s=Number(e.delta||0);if((!n||n.unit!=="em")&&(n={unit:"em",value:1}),n&&s&&!isNaN(s)){n.value+=s,this.grid.ApplyStyle(void 0,{font_size:n},!0);let l=[];for(let c=i.start.row;c<=i.end.row;c++)l.push(c);this.selection_state?.merge||this.grid.SetRowHeight(l,void 0,!1)}}break;case"font-scale":{let n=this.grid.GetSelection(),o=this.grid.active_sheet.RealArea(n.area),i=Number(e.scale||1);if(i&&!isNaN(i)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:i}},!0);let s=[];for(let l=o.start.row;l<=o.end.row;l++)s.push(l);this.selection_state?.merge||this.grid.SetRowHeight(s,void 0,!1)}}break;case"update-comment":this.SetNote(void 0,e.comment||"");break;case"clear-comment":this.SetNote(void 0,"");break;case"text-color":case"fill-color":try{let n=e.color||{};e.command==="text-color"?t.text=n:e.command==="fill-color"&&(t.fill=n)}catch(n){console.error(n)}break;case"insert-table":this.InsertTable();break;case"remove-table":this.RemoveTable();break;case"insert-row":this.InsertRows();break;case"insert-column":this.InsertColumns();break;case"delete-row":this.DeleteRows();break;case"delete-column":this.DeleteColumns();break;case"insert-sheet":this.grid.InsertSheet();break;case"delete-sheet":this.grid.DeleteSheet();break;case"freeze-panes":{let n=this.grid.GetFreeze();n.rows||n.columns?this.Freeze(0,0):this.FreezeSelection()}break;case"insert-image":this.InsertImage();break;case"insert-donut-chart":r("Donut.Chart");break;case"insert-column-chart":r("Column.Chart");break;case"insert-bar-chart":r("Bar.Chart");break;case"insert-line-chart":r("Line.Chart");break;case"insert-scatter-plot":r("Scatter.Plot");break;case"insert-box-plot":r("Box.Plot");break;case"toggle-grouping":if(this.selection_state?.style){let n=R.Get(this.selection_state.style.number_format||"General");if(n.date_format)break;let o=new Re(n.pattern);o.ToggleGrouping();let i=o.toString();t.number_format=R.SymbolicName(i)||i}break;case"increase-precision":case"decrease-precision":if(this.selection_state?.style){let n=R.Get(this.selection_state.style.number_format||"General");if(n.date_format)break;let o=new Re(n.pattern);e.command==="increase-precision"?o.IncreaseDecimal():o.DecreaseDecimal();let i=o.toString();t.number_format=R.SymbolicName(i)||i}break;case"merge-cells":this.grid.MergeCells();break;case"unmerge-cells":this.grid.UnmergeCells();break;case"lock-cells":t={locked:this.selection_state?.style?!this.selection_state.style.locked:!0};break;case"wrap-text":t={wrap:this.selection_state?.style?!this.selection_state?.style.wrap:!0};break;case"justify-left":t={horizontal_align:"left"};break;case"justify-center":t={horizontal_align:"center"};break;case"justify-right":t={horizontal_align:"right"};break;case"align-top":t={vertical_align:"top"};break;case"align-middle":t={vertical_align:"middle"};break;case"align-bottom":t={vertical_align:"bottom"};break;case"reset":this.Reset();break;case"import-file":this.LoadLocalFile();break;case"save-json":this.SaveToDesktop();break;case"save-csv":this.SaveToDesktop("csv");break;case"export-xlsx":this.Export();break;case"revert":this.Revert();break;case"recalculate":this.Recalculate();break;case"toggle-toolbar":case"show-toolbar":case"hide-toolbar":this.ShowToolbar(e.command==="toggle-toolbar"?void 0:e.command==="show-toolbar");break;case"toggle-sidebar":case"show-sidebar":case"hide-sidebar":this.ShowSidebar(e.command==="toggle-sidebar"?void 0:e.command==="show-sidebar");break;case"revert-indicator":this.dialog?.ShowDialog({title:`This is a modified version of the document.
4
4
  You can revert to the original or save your
5
5
  changes in the sidebar.`,close_box:!0,timeout:5e3,type:"info"});break;case"indent":case"outdent":this.grid.Indent(void 0,e.command==="indent"?1:-1);break;default:console.info("unhandled",e.command);break}Object.keys(t).length&&this.grid.ApplyStyle(void 0,t,!0),this.Focus()}ShowToolbar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=!t.hasAttribute("toolbar")),e?t.setAttribute("toolbar",""):t.removeAttribute("toolbar"))}}ShowSidebar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=t.hasAttribute("collapsed")),e?t.removeAttribute("collapsed"):t.setAttribute("collapsed",""))}}CreateChart(){return this.calculator.RegisterLibrary("treb-charts",Xt)&&this.UpdateAC(),this.options.chart_renderer?typeof this.options.chart_renderer=="function"?new xe(this.options.chart_renderer()):new xe(this.options.chart_renderer):new xe}async LoadLanguage(e=""){(!e||e==="locale")&&(e=(ee.locale||"").split(/-/).map(i=>i.toLowerCase())[0]),e=e.toLowerCase();let t;if(e&&["es","fr","pt","nl","de","pl","sv","no","da","it"].includes(e))try{t=await import(`./languages/treb-i18n-${e}.mjs`)}catch(n){console.error(n)}t?this.model.SetLanguage(t.LanguageMap):this.model.SetLanguage(),this.grid.Reselect(),this.grid.Update(!0),this.UpdateAC(),this.Publish({type:"language-change"})}Batch(e,t=!1){let r=this.last_selection,n=this.grid.Batch(e,t),o=!1,i=!1;for(let s of n)switch(s.type){case"composite":case"data":o=!0;break;case"structure":s.rebuild_required&&(i=!0);break;default:}i&&this.calculator.Reset(),(o||i)&&(this.Recalculate(),this.DocumentChange(r))}Freeze(e=0,t=0){this.grid.Freeze(e,t,!0)}FreezeSelection(){let e=this.grid.GetSelection();if(e.empty)this.grid.Freeze(0,0);else{let t=e.area;t.entire_sheet||(t.entire_row?this.grid.Freeze(t.end.row+1,0):t.entire_column?this.grid.Freeze(0,t.end.column+1):this.grid.Freeze(t.end.row+1,t.end.column+1))}}GetFreeze(){return this.grid.GetFreeze()}UpdateTheme(){this.grid.UpdateTheme(void 0),this.UpdateDocumentStyles();for(let e of this.model.sheets.list){for(let t of e.conditional_formats)t.internal=void 0;for(let t of e.annotations)if(t.view&&t.data.type==="textbox"){let r=t.view[this.grid.view_index]||{};r.update_callback&&r.update_callback()}}this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0),this.Publish({type:"theme-change"})}GetSheetID(e){if(typeof e=="number"){let t=this.grid.model.sheets.list[e];if(t)return t.id}else{let t=this.model.sheets.Find(e);if(t)return t.id}}InsertTable(e,t={}){let r=e?this.model.ResolveArea(e,this.grid.active_sheet):this.GetSelectionReference().area,n=t.theme;typeof n=="number"&&(n=gt(n)),this.grid.InsertTable(r,t.totals_row,t.sortable,n)}RemoveTable(e){let t=this.ResolveTable(e||this.GetSelectionReference().target);t&&this.grid.RemoveTable(t)}UpdateTableStyle(e,t=4){let r=this.ResolveTable(e||this.GetSelectionReference().target);r&&(typeof t=="number"&&(t=gt(t)),r.theme=t,this.grid.active_sheet.FlushCellStyles(),this.grid.Update(!0),this.PushUndo())}SetTabColor(e,t){let r=typeof e>"u"?this.grid.active_sheet:this.model.sheets.Find(e);r&&this.grid.TabColor(r,t)}AddSheet(e){this.grid.AddSheet(e);let t=this.model.sheets.list[this.model.sheets.list.length-1];return this.calculator.Reset(),t.id}RemoveConnectedChart(e){let t=this.model.RemoveConnectedElement(e);if(t){let r=this.calculator.RemoveConnectedELement(t)}}UpdateConnectedChart(e,t){let r=this.model.connected_elements.get(e);if(r){r.formula=t;let n=r.internal;n?.state&&(n.state=void 0),this.calculator.UpdateConnectedElements(this.grid.active_sheet,r),r.update&&r.update.call(0,r)}}CreateConnectedFormula(e,t,r={}){let n=r?.r1c1||!1,o=r?.argument_separator||this.parser.argument_separator;this.parser.Save(),this.parser.flags.r1c1=n,o===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",");let i=this.parser.Parse(e);if(this.parser.Restore(),i.expression)e="="+this.parser.Render(i.expression,{missing:""});else throw console.warn("invalid formula",i.error),new Error("invalid formula");let s=this.model.AddConnectedElement({formula:e,update:t?l=>{t.call(0,l)}:void 0});return this.calculator.UpdateConnectedElements(this.grid.active_sheet),this.UpdateConnectedElements(),s}CreateConnectedChart(e,t,r){let n=this.CreateChart();n.Initialize(t);let o=i=>{let s=this.parser.Parse(i.formula);if(s&&s.expression&&s.expression.type==="call"){this.parser.Walk(s.expression,u=>((u.type==="address"||u.type==="range")&&this.model.ResolveSheetID(u,void 0,this.grid.active_sheet),!0));let l=s.expression.name.toLowerCase(),c=this.calculator.CalculateExpression(s.expression);n.Exec(l,c)}n.Update()};return this.CreateConnectedFormula(e,o,r)}InsertAnnotation(e,t="treb-chart",r,n){let o,i,s=!1;if(typeof n=="object"?(i=n.argument_separator,s=!!n.r1c1):(n===","||n===";")&&(i=n),r&&(o=Kt.IsRectangle(r)?r:this.model.ResolveArea(r,this.grid.active_sheet)),i&&i!==this.parser.argument_separator||s){this.parser.Save(),i===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(","),this.parser.flags.r1c1=!!s;let m=this.parser.Parse(e);this.parser.Restore(),m.expression&&(e="="+this.parser.Render(m.expression,{missing:""}))}let{x:l,y:c}=this.grid.GetScrollOffset(),u=this.grid.scale||1,d={width:301,height:301};this.grid.CreateAnnotation({type:t,formula:e},void 0,void 0,void 0,o||{top:c/u+30,left:l/u+30,...d})}InsertImage(){this.SelectFile2(".png, .jpg, .jpeg, .gif, .svg",2)}RenameSheet(e,t){let r;typeof e=="number"?r=this.grid.model.sheets.list[e]:typeof e=="string"?r=this.model.sheets.Find(e):r=this.grid.active_sheet,r&&this.grid.RenameSheet(r,t)}DeleteSheet(e){if(typeof e=="string"){let t=this.model.sheets.Find(e);t&&this.grid.DeleteSheetID(t.id)}else this.grid.DeleteSheet(e);this.calculator.Reset()}HideSheet(e=0,t=!0){this.grid.ShowSheet(e,!t)}ListSheets(){return this.model.sheets.list.map(e=>{let t={name:e.name};return e.visible||(t.hidden=!0),t})}ShowSheet(e=0,t=!0){this.grid.ShowSheet(e,t)}ActivateSheet(e){this.grid.ActivateSheet(e)}SetColumnWidth(e,t,r){this.grid.SetColumnWidth(e,t,r)}SetRowHeight(e,t){this.grid.SetRowHeight(e,t)}InsertRows(e,t=1){if(typeof e>"u"){let r=this.grid.GetSelection();if(r.empty)return;let n=r.area;e=n.entire_column?0:n.start.row}this.grid.InsertRows(e,t)}InsertColumns(e,t=1){if(typeof e>"u"){let r=this.grid.GetSelection();if(r.empty)return;let n=r.area;e=n.entire_row?0:n.start.column}this.grid.InsertColumns(e,t)}DeleteRows(e,t=1){if(typeof e>"u"){let r=this.grid.GetSelection();if(r.empty)return;let n=r.area;e=n.entire_column?0:n.start.row,t=n.rows}this.grid.InsertRows(e,-t)}DeleteColumns(e,t=1){if(typeof e>"u"){let r=this.grid.GetSelection();if(r.empty)return;let n=r.area;e=n.entire_row?0:n.start.column,t=n.columns}this.grid.InsertColumns(e,-t)}FilterTable(e,t=0,r){let n=this.ResolveTable(e);if(!n)throw new Error("invalid table reference");r?this.grid.FilterTable(n,t,o=>r.call(0,o.value,o.calculated||void 0,JSON.parse(JSON.stringify(o.style||{})))):this.grid.FilterTable(n,0,()=>!0)}SortTable(e,t={}){let r=this.ResolveTable(e);if(!r)throw new Error("invalid table reference");this.grid.SortTable(r,t)}MergeCells(e){this.grid.MergeCells(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0)}UnmergeCells(e){this.grid.UnmergeCells(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0)}async ExportBlob(e){return this.export_worker||(this.export_worker=await this.LoadWorker()),new Promise((t,r)=>{this.export_worker?(this.export_worker.OnMessage(n=>{n.data.type==="export-complete"&&t(n.data.blob)}),this.export_worker.OnError(n=>{console.error("export worker error"),console.info(n),r(n)}),e||(e=this.Serialize({rendered_values:!0,expand_arrays:!0,export_colors:!0,decorated_cells:!0,tables:!0,share_resources:!1,export_functions:!0,apply_row_pattern:!0})),e.decimal_mark=ee.decimal_separator,this.export_worker.PostMessage({type:"export",sheet:e,decorated:this.calculator.DecoratedFunctionList()})):r("worker failed")})}Revert(){if(this.options.inline_document){this.LoadDocument(this.options.inline_document),this.initial_load_source="inline-document",this.options.local_storage&&(this.SaveLocalStorage("reverted_backup"),localStorage.removeItem(this.options.local_storage));return}let e=this.options.document;if(e){this.LoadNetworkDocument(e),this.initial_load_source="network-file",this.options.local_storage&&(this.SaveLocalStorage("reverted_backup"),localStorage.removeItem(this.options.local_storage));return}console.warn("to revert, there must be a document set in options"),this.dialog?.ShowDialog({title:"Can't revert -- no document is set in options",close_box:!0,timeout:3e3,type:"error"})}Export(){this.ExportBlob().then(e=>{let t="export";this.grid.model.document_name&&(t=this.grid.model.document_name.toLowerCase().replace(/\s+/g,"-")),e&&(this.SaveAs(e,t+".xlsx"),this.last_save_version=this.file_version)}).catch(e=>{throw/invalid uri/i.test(e.message)&&this.dialog?.ShowDialog({title:"Error exporting file",close_box:!0,message:"The worker cannot run from the filesystem, please use a web server.",timeout:3e3,type:"error"}),e})}GetSelectionReference(){return this.grid.GetSelection()}Focus(){this.grid.Focus()}Resize(){this.grid.UpdateLayout();for(let e of this.views)e.view.grid.UpdateLayout();this.Publish({type:"resize"})}Reset(){if(this.parent_view)return this.parent_view.Reset();this.grid.Reset(),this.ResetInternal(),this.UpdateAC(),this.Publish({type:"reset"})}LoadFromLocalStorage(e){this.options.local_storage=e;let t=localStorage.getItem(e);if(t)try{let r=JSON.parse(t);return this.LoadDocument(r,{source:"local-storage"}),!0}catch(r){console.error(r)}return!1}async LoadNetworkDocument(e,t){let r=t?t.scroll:void 0,n=t?!!t.recalculate:!1,o=t?t.sheet:void 0,i=/csv(?:$|\?|&)/i.test(e),s=/tsv(?:$|\?|&)/i.test(e);try{this.spinner?.Show();let l=await fetch(e);if(this.spinner?.Hide(),!l.ok)throw new Error("network error");let c=await l.text();if(typeof c=="string")if(i)this.LoadCSV(c,"network-file");else{if(s)throw new Error("tsv not supported (TODO)");{c.substr(0,11)==="&&&START&&&"?c=c.substr(11):c.substr(0,8)==="for(;;);"&&(c=c.substr(8));let u=JSON.parse(c);this.LoadDocument(u,{scroll:r,recalculate:n,override_sheet:o,source:"network-file"})}}}catch(l){console.info("error loading network document",e),console.error(l),this.dialog?.ShowDialog({title:"Error loading file",close_box:!0,message:"The network document returned an error",type:"error",timeout:3e3}),this.Reset()}}async LoadLocalFile(){this.SelectFile2(".treb, .csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/json",1)}ExportDelimited(e={}){if(e={delimiter:",",...e},!e.delimiter||e.delimiter!==","&&e.delimiter!==" ")throw new Error("invalid delimiter");let t=this.grid.active_sheet;switch(typeof e.sheet){case"undefined":break;case"string":t=this.model.sheets.Find(e.sheet);break;case"number":t=this.grid.model.sheets.list[e.sheet];break;default:t=void 0;break}if(!t)throw new Error("invalid sheet identifier");let r=t.cells.toJSON({nested:!1,expand_arrays:!0,calculated_value:!0}),n=[];for(let s=0;s<r.columns;s++)n.push("");let o=[];for(let s=0;s<r.rows;s++)o.push(n.slice(0));let i=new RegExp(`[
6
6
  \r"${e.delimiter}]`);if(Zt(r.data))for(let s of r.data){let l="";!e.formulas&&typeof s.calculated<"u"?l=X(s.calculated)?pt(s.calculated):s.calculated.toString():typeof s.value=="string"&&s.value[0]==="'"?l=s.value.substr(1):typeof s.value<"u"&&(l=X(s.value)?pt(s.value):s.value.toString()),i.test(l)&&(l=l.replace(/"/g,'""'),l='"'+l+'"'),o[s.row][s.column]=l}return o.map(s=>s.join(e.delimiter)).join(`\r
7
- `)}SaveLocalFile(e="treb.json",t={}){this.SaveToDesktop(e,t)}SaveToDesktop(e="treb.json",t={}){let r=this.grid.model.document_name||"document",n,o,i=e.split(/\./).filter(l=>l.trim().length),s=i.length?i[i.length-1].toLowerCase():"treb";if(i.length<=1||e==="treb.json")if(e==="treb.json"&&(s=e),(s==="csv"||s==="tsv")&&this.grid.model.sheets.length>1){let l=this.grid.active_sheet.name;e=(r+"-"+l).toLowerCase().replace(/\W+/g,"-")+"."+s}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+s;switch(s){case"csv":o=this.ExportDelimited({delimiter:","});break;case"tsv":o=this.ExportDelimited({delimiter:" "});break;case"treb":case"json":case"treb.json":n=this.SerializeDocument({...t}),o=JSON.stringify(n,void 0,t.pretty?2:void 0),this.last_save_version=this.file_version;break;default:throw new Error("invalid file type")}if(o&&e){let l=new Blob([o],{type:"text/plain;charset=utf-8"});this.SaveAs(l,e)}}LoadCSV(e,t){if(this.parent_view)return this.parent_view.LoadCSV(e,t);this.grid.FromCSV(e),this.ResetInternal(),this.grid.Update(!0),this.Publish({type:"load",source:t}),this.UpdateDocumentStyles()}ScrollOffset(e){return this.grid.ScrollOffset(e)}LoadDocument(e,t={}){if(this.parent_view)return this.parent_view.LoadDocument(e,t);if(this.initial_load_source||(this.initial_load_source=t.source),t={flush:!0,recalculate:!1,...t},t.override_selection&&e.sheet_data){let r=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let n of r)if(n.id===t.override_selection.target.sheet_id){n.selection=t.override_selection;break}}if(this.ImportDocumentData(e,t.override_sheet),this.calculator.Reset(),e.rendered_values&&!t.recalculate?(this.calculator.RebuildClean(!0),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update()):this.Recalculate(),this.InflateAnnotations(),t.flush&&this.FlushUndo(),this.Publish({type:"load",source:t.source}),this.UpdateDocumentStyles(),this.loaded=!0,t.scroll){let r=t.scroll;Promise.resolve().then(()=>this.ScrollTo(r))}}SetNote(e,t){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}this.grid.SetNote(e,t)}SetValidation(e,t,r){if(typeof e=="string"){let n=this.model.ResolveAddress(e,this.grid.active_sheet);e=bt(n)?new z(n.start,n.end):new z(n)}if(K(e)&&(e=new z(e)),typeof t>"u"||Array.isArray(t))this.grid.SetValidation(e,t,r);else{let n=this.model.ResolveArea(t,this.grid.active_sheet);this.grid.SetValidation(e,n,r)}}RemoveFunction(e){let t=e.toUpperCase();this.model.macro_functions.delete(t),this.UpdateAC()}DefineFunction(e,t="",r="0"){if(!e.length||/^[^A-Za-z]/.test(e)||/[^\w_.]/.test(e))throw new Error("invalid function name");typeof t=="string"&&(t=t?t.split(this.parser.argument_separator).map(n=>n.trim()):[]);for(let n of t)if(!n.length||/^[^A-Za-z]/.test(n)||/[^\w_.]/.test(n))throw new Error("invalid argument name");this.RemoveFunction(e),this.grid.model.macro_functions.set(e.toUpperCase(),{name:e,function_def:r,argument_names:t,expression:this.parser.Parse(r).expression}),this.UpdateAC()}SerializeDocument(e={}){e={share_resources:!0,shrink:!0,...e};let t=this.Serialize(e),r={app:"@trebco/treb",version:"36.1.2",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:ee.decimal_separator,...t};if(e.share_resources){let n=1,o=new Map,i=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],s=c=>{let u=o.get(c);return u||(u=(n++).toString(),o.set(c,u)),`resource:${u}`};for(let c of i)if(c){c.background_image&&(c.background_image=s(c.background_image));for(let u of c.annotations||[])u.type==="image"&&u.data?.src&&(u.data.src=s(u.data.src))}let l={};for(let[c,u]of o.entries())l[u]=c;r.shared_resources=l}return e.rendered_values&&(r.rendered_values=!0),r}Recalculate(e){let t;switch(e?.type){case"data":t=e.area;break;case"composite":t=e.data_area;break}this.calculator.Calculate(t),this.calculator.grid_expanded&&!this.grid.headless&&this.grid.UpdateLayout(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0),this.UpdateAnnotations(),this.Publish({type:"data"}),this.grid.UpdateStats()}SaveLocalStorage(e=this.options.local_storage){if(!e){console.warn("not saving, no key");return}let t=JSON.stringify(this.SerializeDocument({rendered_values:!0,expand_arrays:!0}));localStorage.setItem(e,t)}Undo(){if(this.parent_view)return this.parent_view.Undo();if(this.undo_pointer<=1){console.warn("nothing to undo");return}let e=this.undo_stack[--this.undo_pointer-1],t=e.selection?JSON.parse(e.selection):void 0;this.LoadDocument(JSON.parse(e.data),{flush:!1,override_selection:t,source:"undo"})}About(){this.dialog?.ShowDialog({type:"about"})}ScrollIntoView(e,t=!1){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}this.grid.ScrollIntoView(e,t)}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}t={x:!0,y:!0,smooth:!1,...t},this.grid.ScrollTo(e,t.x,t.y,t.smooth)}Resolve(e,t){let r=this.model.ResolveAddress(e,this.grid.active_sheet,t);return K(r)?r.sheet_id?r:void 0:r.start.sheet_id?r:void 0}Unresolve(e,t=!0,r=!0){if(typeof e=="string"){let n=this.Resolve(e);if(!n)throw new Error("invalid reference");e=n}return this.calculator.Unresolve(e,this.grid.active_sheet,t,r)}Evaluate(e,t={}){return this.calculator.Evaluate(e,this.grid.active_sheet,t)}GetSelection(e=!0){let t=this.grid.GetSelection();if(t.empty)return"";let r="";if(t.area.count>1?r=z.CellAddressToLabel(t.area.start)+":"+z.CellAddressToLabel(t.area.end):r=z.CellAddressToLabel(t.area.start),!e)return r;let n=t.area.start.sheet_id||this.grid.active_sheet.id,o=this.calculator.ResolveSheetName(n,!0);return o?o+"!"+r:r}ParseNumber(e){return we.TryParse(e).value}FormatNumber(e,t="General"){return X(e)?Re.FormatPartsAsText(R.Get(t).FormatComplex(e)):R.Get(t).Format(e)}SpreadsheetDate(e){return e instanceof Date&&(e=e.getTime()),ae(e,!0)}JavascriptDate(e){return fe(e).getTime()}ApplyBorders(e,t,r=1){this.grid.ApplyBorders2(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,{},r)}ApplyStyle(e,t={},r=!0){this.grid.ApplyStyle(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,r)}ClearName(e){this.grid.SetName(e)}ListNames(){return this.model.SerializeNames()}DefineName(e,t,r,n=!1){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof r=="string"){let o=this.model.sheets.ID(r);if(typeof o=="number")r=o;else throw new Error("invalid scope; use a sheet name or sheet id")}if(typeof t=="object"&&(K(t)||bt(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet),void 0,r,n);return}if(typeof t=="string"){let o=this.parser.Parse(t);if(!o.expression)throw new Error("invalid expression");switch(o.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(o.expression,this.grid.active_sheet),void 0,r,n);return}this.grid.SetName(e,void 0,t,r,n)}else this.grid.SetName(e,void 0,t.toString(),r,n)}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}if(!e){let r=this.GetSelectionReference();if(r.empty)return;e=r.target}this.grid.SetLink(e,t)}Select(e){let t;e&&(t=this.model.ResolveArea(e,this.grid.active_sheet),t.start.sheet_id&&t.start.sheet_id!==this.grid.active_sheet.id&&this.grid.ActivateSheetID(t.start.sheet_id)),this.grid.SelectRange(t)}Paste(e,...t){let r=a.clipboard,n={};switch(t.length){case 1:Array.isArray(t[0])?r=t[0]:typeof t[0]=="object"&&(n=t[0]);break;case 2:t[0]&&Array.isArray(t[0])&&(r=t[0]),t[1]&&typeof t[1]=="object"&&(n=t[1]);break}if(!r)throw new Error("no clipboad data");this.grid.PasteArea(this.RangeOrSelection(e,"no range and no selection"),r,n)}Copy(e){let t=this.RangeOrSelection(e),r=t?this.grid.CopyArea(t,"copy"):[];return a.clipboard=structuredClone(r),r}Cut(e){let t=this.RangeOrSelection(e),r=t?this.grid.CopyArea(t,"cut"):[];return a.clipboard=structuredClone(r),r}GetRange(e,t={}){let r=this.RangeOrSelection(e);if(!r)return;let n=t.type;return n||(t.formatted&&(n="formatted"),t.formula&&(n="A1")),n==="formula"&&(n="A1"),this.grid.GetRange(r,n)}GetStyle(e,t=!1){let r=this.RangeOrSelection(e);if(r)return this.grid.GetRangeStyle(r,t)}SetRange(e,t=void 0,r={}){let n=this.RangeOrSelection(e);if(n){if(r.spill&&Array.isArray(t)){let o=t.length,i=Math.max(0,...t.map(l=>l.length)),s={row:n.start.row+o+1,column:n.start.column+i+1};n.ConsumeAddress(s)}return this.grid.SetRange(n,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}RangeOrSelection(e,t){if(!e){let r=this.GetSelectionReference();if(r.empty){if(t)throw t;return}else return r.area.Clone()}return this.model.ResolveArea(e,this.grid.active_sheet)}Serialize(e={}){let t=this.grid.active_sheet;t.selection=JSON.parse(JSON.stringify(this.grid.GetSelection()));let r=this.grid.ScrollOffset();r&&(t.scroll_offset=r);let n=this.model.sheets.list.map(l=>l.toJSON(e)),o;this.model.tables.size>0&&(o=Array.from(this.model.tables.values()));let i;if(this.model.macro_functions.size){i=[];for(let l of this.model.macro_functions.values())i.push({...l,expression:void 0})}let s=this.model.SerializeNames(t);return{sheet_data:n,active_sheet:t.id,named:s.length?s:void 0,macro_functions:i,tables:o}}ApplyConditionalFormats(e,t){let r=[];if(e.conditional_formats.length||e.flush_conditional_formats){for(let n of e.conditional_formats)switch(r.push(n.area),n.type){case"gradient":n.internal||(n.internal={}),n.internal.gradient||(n.internal.gradient=new sr(n.stops,this.grid.theme,n.color_space));break;case"data-bar":n.internal||(n.internal={});break}e.ApplyConditionalFormats()}t&&this.grid.Update(!0,r)}ResolveTable(e){let t;if(typeof e=="string"){let r=e.toLowerCase();this.model.tables.has(r)&&(t=this.model.tables.get(r))}if(!t){let r=this.model.ResolveAddress(e,this.grid.active_sheet);K(r)||(r=r.start),t=this.grid.GetTableReference(r)}return t}SaveAs(e,t){let r=this.DOM.Create("a");r.href=URL.createObjectURL(e),r.download=t,r.click(),URL.revokeObjectURL(r.href)}Publish(e){this.events.Publish(e)}async ImportXLSX(e,t,r){return this.parent_view?this.parent_view.ImportXLSX(e,t):(this.export_worker||(this.export_worker=await this.LoadWorker()),new Promise((n,o)=>{this.export_worker?(this.dialog?.ShowDialog({message:"Importing XLSX..."}),this.export_worker.OnMessage(i=>{if(i.data){if(i.data.type==="import-error")return o(i.data.error||"unknown error");if(i.data.type!=="import-complete")return o("unknown error (invalid message)");if(this.parser.decimal_mark!=="."){let s=this.parser.decimal_mark,l=this.parser.argument_separator;this.parser.Save(),this.parser.SetLocaleSettings(".");let c=u=>{let d=this.parser.Parse(u);if(d.expression)return"="+this.parser.Render(d.expression,{missing:"",convert_decimal:s,convert_argument_separator:l})};for(let u of i.data.results.named||[])u.expression=c(u.expression)||"";for(let u of i.data.results.sheets||[]){for(let d of u.cells||[])d.type==="formula"&&d.value&&(d.value=c(d.value));if(u.annotations)for(let d of u.annotations)d.formula&&(d.formula=c(d.formula))}this.parser.Restore()}this.grid.FromImportData(i.data.results),this.ResetInternal(),this.grid.Update(),this.UpdateAC(),this.Publish({type:"load",source:t,path:r}),this.UpdateDocumentStyles(),this.InflateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)}else return o("unknown error (missing data)");this.dialog?.HideDialog(),n()}),this.export_worker.OnError(i=>{console.error("import worker error"),console.info(i),o(i)}),this.export_worker.PostMessage({type:"import",data:e})):o("worker failed")}))}ResetInternal(){this.calculator.Reset(),this.FlushUndo(),this.file_version=this.last_save_version=0}HandleCellEvent(e){if(e.data?.type==="hyperlink"){let t="hyperlink invalid target",r=e.data.reference||"";if(typeof r=="string"){if(/^https{0,1}:\/\//i.test(r)){if(!this.options.hyperlinks){console.warn("hyperlinks are disabled");return}let n=this.DOM.Create("a");n.setAttribute("target",this.options.hyperlinks),n.setAttribute("href",r),n.setAttribute("noreferrer","true"),n.setAttribute("nofollow","true"),n.click();return}else{let n=this.parser.Parse(r);if(n.expression){if(n.expression.type==="address"){(n.expression.sheet||n.expression.sheet_id)&&this.ActivateSheet(n.expression.sheet||n.expression.sheet_id),this.Select(r);return}else if(n.expression.type==="range"){(n.expression.start.sheet||n.expression.start.sheet_id)&&this.ActivateSheet(n.expression.start.sheet||n.expression.start.sheet_id),this.Select(r);return}}}console.warn(t,2);return}}}OnSheetChange(e){for(let t of e.activate.annotations)this.InflateAnnotation(t),this.calculator.UpdateAnnotations(t,e.activate);this.UpdateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(e.activate,!0)}HandleDrag(e){if(e.dataTransfer&&e.dataTransfer.types){if(e.dataTransfer.types.some&&e.dataTransfer.types.some(t=>t==="Files"))e.preventDefault();else for(let t=0;t<e.dataTransfer.types.length;t++)if(e.dataTransfer.types[t]==="files"){e.preventDefault();return}}}HandleDrop(e){if(e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length){e.preventDefault();let t=e.dataTransfer.files[0];/^image/.test(t.type)?this.InsertImageInternal(t):this.LoadFileInternal(t,"drag-and-drop").catch(()=>{})}}SelectFile2(e,t){if(!this.file_chooser){let r=this.DOM.Create("input",void 0,void 0,{attrs:{type:"file"},events:{change:()=>{if(r.files&&r.files[0]){let n=r.files[0];switch(r.value="",this.file_chooser_operation){case 2:this.InsertImageInternal(n);break;case 1:this.LoadFileInternal(n,"local-file",!0);break;default:console.warn("file chooser: no operation");break}}}}});this.file_chooser=r}if(!this.file_chooser)throw new Error("could not create file chooser");this.file_chooser_operation=t,this.file_chooser.accept=e||"",this.file_chooser.click()}async InsertImageInternal(e){if(this.options.max_file_size&&e.size>this.options.max_file_size){this.dialog?.ShowDialog({type:"error",message:"This file exceeds the allowed image size. Please try a smaller image.",title:"Error adding image",timeout:3e3,close_box:!0});return}let t=e;await new Promise((r,n)=>{let o=new FileReader;o.onload=async()=>{try{if(o.result){let i;if(typeof o.result=="string")i=o.result;else{i="";let l=new Uint8Array(o.result);for(let c=0;c<l.byteLength;c++)i+=String.fromCharCode(l[c])}let s=this.DOM.Create("img");s.src=i,await Promise.resolve(),this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:i,original_size:{width:s.width||300,height:s.height||300}}},void 0,void 0,void 0,{top:30,left:30,width:s.width||300,height:s.height||300})}r()}catch(i){n(i)}},o.onabort=()=>{n("Aborted")},o.onerror=()=>{n("File error")},setTimeout(()=>{o.readAsDataURL(t)},100)})}LoadFileInternal(e,t,r=!0){if(!e)return Promise.resolve();let n=new FileReader;return new Promise((o,i)=>{let s=l=>{n.onload=null,n.onabort=null,n.onerror=null,l?(r&&(this.dialog?.ShowDialog({title:"Error reading file",close_box:!0,message:"Please make sure your file is a valid XLSX, CSV or TREB file.",type:"error",timeout:3e3}),console.error(l)),i(l)):o()};n.onload=()=>{try{if(n.result)if(/\.csv$/i.test(e.name))this.LoadCSV(n.result,t);else if(/\.xls[xm]$/i.test(e.name)){typeof n.result=="string"?s("Unsupported file"):this.ImportXLSX(n.result,t).then(()=>s()).catch(l=>s(l));return}else{let l=JSON.parse(n.result);this.LoadDocument(l,{source:t})}s()}catch(l){s(l?.toString())}},n.onabort=()=>{s("Aborted")},n.onerror=()=>{s("File error")},setTimeout(()=>{/\.xls[xm]$/i.test(e.name)?n.readAsArrayBuffer(e):n.readAsText(e)},100)})}UpdateAnnotations(){for(let e of this.grid.active_sheet.annotations){let t=e.temp;if(t.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;for(let n of e.view)n&&(n.dirty=!0)}let r=e.view[this.grid.view_index]||{};r.dirty&&(r.dirty=!1,r.update_callback&&r.update_callback(),this.grid.AnnotationUpdated(e))}this.UpdateConnectedElements()}UpdateConnectedElements(){for(let e of this.model.connected_elements.values()){let t=e.internal;if(t?.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;let r=e.update;r&&Promise.resolve().then(()=>r.call(0,e))}}}RebuildAllAnnotations(){for(let e of this.grid.active_sheet.annotations){this.InflateAnnotation(e);let t=e.view[this.grid.view_index]||{};t.resize_callback&&t.resize_callback(),t.update_callback&&t.update_callback()}}InflateAnnotations(){for(let e of this.grid.active_sheet.annotations)this.InflateAnnotation(e)}InflateAnnotation(e){if(this.grid.headless)return;let t=e.view[this.grid.view_index]||{};if(t.inflated){e.dirty&&(t.resize_callback&&t.resize_callback(),e.dirty=!1);return}if(t.inflated=!0,e.dirty&&(e.dirty=!1),t.content_node){if(e.data.type==="treb-chart"){let r=this.CreateChart();r.Initialize(t.content_node);let n=()=>{if(e.data.formula){let o=this.parser.Parse(e.data.formula);if(o&&o.expression&&o.expression.type==="call"){this.parser.Walk(o.expression,l=>((l.type==="address"||l.type==="range")&&this.model.ResolveSheetID(l,void 0,this.grid.active_sheet),!0));let i=o.expression.name.toLowerCase(),s=this.calculator.CalculateExpression(o.expression);r.Exec(i,s)}}r.Update()};t.resize_callback=()=>{this.grid.headless||(r.Resize(),r.Update())},t.update_callback=()=>{this.grid.headless||n()},t.node?.parentElement&&(this.grid.headless||n())}else if(e.data.type==="image"){if(typeof e.data.data?.src=="string"){let r=ar(e.data.data.src);if(r){let n=this.DOM.Create("img");n.src=r,e.data.data.scale==="fixed"?(n.style.position="relative",n.style.left="50%",n.style.top="50%",n.style.transform="translate(-50%, -50%)"):(n.style.width="100%",n.style.height="100%"),t.content_node.appendChild(n)}}}else if(e.data.type==="textbox"&&e.data.data){let r,n=document.createElement("div");n.classList.add("treb-annotation-textbox");for(let o of e.data.data.paragraphs){let i=document.createElement("p");o.style&&(o.style.horizontal_align==="right"||o.style.horizontal_align==="center")&&(i.style.textAlign=o.style.horizontal_align);for(let s of o.content){let l=document.createElement("span");if(r||(r=l),e.data.formula||(l.textContent=s.text||""),s.style?.bold&&(l.style.fontWeight="600"),s.style?.italic&&(l.style.fontStyle="italic"),i.appendChild(l),e.data.formula)break}if(n.append(i),e.data.formula)break}if(t.content_node.append(n),e.data.data.style){let o=e.data.data.style,i=()=>{if(o.fill){let s=ft(this.grid.theme,o.fill);n.style.background=s}};t.update_callback=()=>{if(this.grid.headless||i(),r&&e.data.formula){let s=this.parser.Parse(e.data.formula);if(s&&s.expression){this.parser.Walk(s.expression,d=>((d.type==="address"||d.type==="range")&&this.model.ResolveSheetID(d,void 0,this.grid.active_sheet),!0));let l=this.calculator.CalculateExpression(s.expression),c=R.Get("General"),u;switch(s.expression.type){case"address":u=s.expression;break;case"range":u=s.expression.start;break}if(u){let m=(u.sheet_id?this.model.sheets.Find(u.sheet_id):this.grid.active_sheet)?.CellStyleData(u);m?.number_format&&(c=R.Get(m.number_format))}switch(l.type){case 3:case 2:case 8:r.textContent=c.Format(l.value);break;default:r.textContent=l.value?.toString()||""}}}},t.update_callback()}}}}DocumentChange(e){Promise.resolve().then(()=>{this.file_version++,this.file_version>=65536&&(this.file_version=1);let t=JSON.stringify(this.SerializeDocument({optimize:"size",rendered_values:!0,expand_arrays:!0}));this.options.undo&&this.PushUndo(t,e,!1),this.Publish({type:"document-change"})})}ResolveStorageKey(e,t=""){if(e){if(e===!0){let r=0,n=document.location.href;for(let i=0,s=n.length;i<s;i++)r=(r<<5)-r+n.charCodeAt(i),r|=0;let o=Math.abs(r).toString(16);return t?t+"-"+o:o}return e}}PushUndo(e,t,r=!0){let n=t||this.last_selection;this.undo_stack[this.undo_pointer-1]&&(this.undo_stack[this.undo_pointer-1].selection=n),r&&(this.file_version++,this.file_version>=65536&&(this.file_version=1)),e||(e=JSON.stringify(this.SerializeDocument({optimize:"size",rendered_values:!0,expand_arrays:!0}))),this.undo_stack[this.undo_pointer++]={data:e,selection:void 0};let o=this.undo_stack.length;if(o>16){let i=o-16;this.undo_stack=this.undo_stack.slice(i),this.undo_pointer-=i}}FlushUndo(e=!0){this.undo_stack=[],this.undo_pointer=0,this.last_save_version=this.file_version,e&&this.PushUndo(void 0,void 0,!1)}UpdateSelection(e,t){this.last_selection=JSON.stringify(e);let r={type:"selection"};t==="sheet-change"&&(r.reason=t),this.Publish(r)}UpdateSelectionStyleAnnotation(e){let t={style:JSON.parse(JSON.stringify(e.data.style||{}))};t.style&&(t.style.font_face||(t.style.font_face="stack:ui"),t.style.font_size||(t.style.font_size={unit:"em",value:1})),t.relative_font_size=ht.RelativeFontSize(t.style||{},this.grid.theme.grid_cell||{}),this.selection_state=t}UpdateSelectionStyle(e){let t=this.grid.GetFreeze(),r={frozen:!!t.rows||!!t.columns};if(e||(e=this.grid.GetSelection()),e&&!e.empty){r.selection=e;let n=this.grid.active_sheet.CellData(e.target);r.table=!!n.table,r.merge=!!n.merge_area,r.merge&&n.merge_area&&(n.merge_area.start.row!==e.target.row||n.merge_area.start.column!==e.target.column)&&(n=this.grid.active_sheet.CellData(n.merge_area.start)),r.comment=n.note,r.style=n.style?{...n.style}:void 0,r.relative_font_size=ht.RelativeFontSize(r.style||{},this.grid.theme.grid_cell||{}),r.empty=typeof n.value>"u"&&!n.style?.font_face}this.grid?.edit_state&&(this.grid.edit_state.font_face=r.style?.font_face||void 0),this.selection_state=r}UpdateDocumentStyles(){let e={},t={};for(let n of this.grid.model.sheets.list)n.NumberFormatsAndColors(t,e);this.document_styles.colors=Object.keys(t),this.document_styles.number_formats=Object.keys(e),this.document_styles.theme_colors=[];let r=[.5,.25,0,-.25,-.5];for(let n=0;n<10;n++)this.document_styles.theme_colors.push(r.map(o=>{let i={theme:n,tint:o},s=ft(this.grid.theme,i);return{color:i,resolved:s}}))}ConvertLocale(e){let t=new Jt;t.flags={...this.parser.flags};let r,n;e.decimal_mark==="."?(t.SetLocaleSettings("."),r=",",n=";"):(t.SetLocaleSettings(","),r=".",n=",");let o=i=>{let s=t.Parse(i);if(s.expression)return"="+t.Render(s.expression,{missing:"",convert_decimal:r,convert_argument_separator:n})};if(e.macro_functions)for(let i of e.macro_functions){let s=o(i.function_def);s&&(i.function_def=s)}if(e.named)for(let i of e.named){let s=o(i.expression);s&&(i.expression=s)}if(e.sheet_data){let i=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let s of i){if(s.annotations){for(let l of s.annotations)if(l.formula){let c=o(l.formula);c&&(l.formula=c)}}if(s.data?.length)for(let l of s.data){let c=Yt(l)?[l]:l.cells;for(let u of c)if(u.value&&typeof u.value=="string"&&u.value[0]==="="){let d=o(u.value.slice(1));d&&(u.value=d)}}}}}CompareVersions(e="",t=""){let r=e.split(".").map(s=>Number(s)||0).concat([0,0,0]),n=t.split(".").map(s=>Number(s)||0).concat([0,0,0]),o=[0,1,2],i={match:0};for(let s=0;s<3;s++)if(r[s]!==n[s]){i.match=r[s]>n[s]?1:-1,i.level=o[s];break}return i}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],n=this.CompareVersions(e.version,"36.1.2");if(n.match>0&&(n.level===0||n.level===1)&&console.warn(`The file you are opening was created with a newer version of TREB (${e.version} vs 36.1.2).
8
- You may encounter compatibility errors.`),e.sheet_data&&(Array.isArray(e.sheet_data)?r=e.sheet_data:r.push(e.sheet_data)),e.shared_resources){let i=e.shared_resources,s=l=>/^resource:/.test(l)?i[l.substring(9)]||"":l;for(let l of r){l.background_image&&(l.background_image=s(l.background_image));for(let c of l.annotations||[])c.type==="image"&&c.data?.src&&(c.data.src=s(c.data.src))}}e.decimal_mark&&e.decimal_mark!==ee.decimal_separator&&this.ConvertLocale(e);let o=this.grid.model;if(o.tables.clear(),e.tables)for(let i of e.tables)o.tables.set(i.name.toLowerCase(),i);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let i of this.model.tables.values())if(i.area.start.sheet_id){let s=o.sheets.Find(i.area.start.sheet_id);if(s)for(let l=i.area.start.row;l<=i.area.end.row;l++)for(let c=i.area.start.column;c<=i.area.end.column;c++){let u=s.cells.GetCell({row:l,column:c},!0);u.table=i}}if(o.document_name=e.name,o.user_data=e.user_data,o.named.Reset(),e.named)this.model.UnserializeNames(e.named,this.grid.active_sheet);else{let i=e.named_ranges;if(!i&&r[0]&&r[0].named_ranges&&(i=r[0].named_ranges),i)for(let[s,l]of Object.entries(i))o.named.SetNamedRange(s,new z(l.start,l.end));if(e.named_expressions)for(let s of e.named_expressions)this.model.UnserializeNames([{name:s.name,expression:s.expression}],this.grid.active_sheet)}if(o.macro_functions.clear(),e.macro_functions)for(let i of e.macro_functions)o.macro_functions.set(i.name.toUpperCase(),{...i,expression:this.parser.Parse(i.function_def||"").expression});this.UpdateAC()}async LoadWorker(){let e=lr(!!this.options.in_process_workers);return await e.Init("./treb-export-worker.mjs",()=>new Worker(new URL("./treb-export-worker.mjs",import.meta.url),{type:"module"})),e}HandleKeyDown(e){e.key==="z"?(Ee.is_mac&&e.metaKey||e.ctrlKey)&&(e.stopPropagation(),e.preventDefault(),this.Undo()):e.key==="F9"&&this.options.recalculate_on_f9&&(e.stopPropagation(),e.preventDefault(),this.Recalculate())}};var fn=`@charset "UTF-8";.treb-main.treb-main .treb-mouse-mask{background:transparent;bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:9999}.treb-main.treb-main .treb-mouse-mask.column-resize{cursor:col-resize}.treb-main.treb-main .treb-mouse-mask.row-resize{cursor:row-resize}.treb-main.treb-main .treb-mouse-mask.nub-select{cursor:crosshair}.treb-main.treb-main .treb-mouse-mask.move{cursor:move}.treb-main.treb-main .treb-mouse-mask.nw-resize{cursor:nw-resize}.treb-main.treb-main .treb-note{max-width:15em;min-width:15em}.treb-main.treb-main .treb-hover-title,.treb-main.treb-main .treb-note{background:var(--treb-note-background,#fff);border:1px solid var(--treb-note-border-color,var(--treb-ui-border-color,#ddd));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-note-color,#333);font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:10.5pt;left:100px;line-height:normal;opacity:0;padding:7px 10px;position:fixed;top:100px;transition:opacity .2s;white-space:pre-line;z-index:39}.treb-main.treb-main .treb-hover-title{min-width:10em;pointer-events:none}.treb-main.treb-main .treb-sort-button{background:#fff;border:1px solid #ccc;border-radius:2px;height:1em;left:100px;opacity:0;pointer-events:none;position:absolute;top:100px;transition:opacity .1s ease;width:1em;z-index:39}.treb-main.treb-main .treb-sort-button:after{box-sizing:border-box}.treb-main.treb-main .treb-sort-button.asc:after{border:.4em solid transparent;border-top-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-25%);width:.8em}.treb-main.treb-main .treb-sort-button.desc:after{border:.4em solid transparent;border-bottom-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-80%);width:.8em}.treb-main.treb-main .treb-tooltip{border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;line-height:normal;padding:2px 10px;pointer-events:none;position:fixed;z-index:39}.treb-main.treb-main .treb-tooltip.arrow-up:after{border:4px solid transparent;border-bottom-color:inherit;box-sizing:border-box;content:" ";height:8px;left:calc(50% - 4px);overflow:hidden;position:absolute;top:-8px;width:8px}.treb-main.treb-main .treb-tooltip.arrow-left:after{border:4px solid transparent;border-right-color:inherit;box-sizing:border-box;content:" ";height:8px;left:-8px;overflow:hidden;position:absolute;top:calc(50% - 4px);width:8px}.treb-main.treb-main .treb-dropdown-caret{background:var(--treb-dropdown-caret-background,#fff);border:1px solid var(--treb-dropdown-caret-border-color,#ccc);border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;height:20px;position:absolute;width:20px;z-index:39}.treb-main.treb-main .treb-dropdown-caret path{fill:none;stroke:var(--treb-dropdown-caret-color,#444);stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.treb-main.treb-main .treb-dropdown-list{background:var(--treb-dropdown-background,#fff);border:1px solid var(--treb-dropdown-border-color,unset);box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-dropdown-color,inherit);display:none;font-size:10pt;max-height:10em;outline:none;overflow-y:auto;position:absolute;text-align:left;z-index:39}.treb-main.treb-main .treb-dropdown-list div{cursor:default;padding:2px}.treb-main.treb-main .treb-dropdown-list div.selected{background:var(--treb-dropdown-selected-background,#555);color:var(--treb-dropdown-selected-color,#fff)}.treb-main.treb-main .treb-dropdown-caret.active{background:var(--treb-dropdown-caret-active-background,#eee)}.treb-main.treb-main .treb-dropdown-caret.active+.treb-dropdown-list{display:block}.treb-main.treb-main .treb-error-highlight{background:rgba(255,0,0,.25);opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in-out;z-index:40}.treb-main.treb-main .treb-autocomplete{box-sizing:border-box;font-size:inherit;font-weight:400;line-height:normal;max-height:10em;overflow-y:auto;position:fixed;text-align:left;top:-1000px;z-index:39}.treb-main.treb-main .treb-autocomplete *{box-sizing:border-box}.treb-main.treb-main .treb-autocomplete ul{list-style-type:none}.treb-main.treb-main .treb-autocomplete ul,.treb-main.treb-main .treb-autocomplete ul li{font-size:inherit;font-weight:inherit;margin:0;padding:0}.treb-main.treb-main .treb-autocomplete ul li a{color:inherit;cursor:default;display:inline-block;font-size:inherit;font-weight:inherit;padding:3px 6px;text-decoration:none;width:100%}.treb-main.treb-main .treb-autocomplete-tooltip{position:fixed;top:-1000px;white-space:pre;z-index:39}.treb-main.treb-main .treb-formula-bar{display:flex;flex-direction:row;gap:.5em;grid-area:1/1/2/2;max-width:100%;overflow-x:hidden;padding:0 2px 12px;text-align:left}.treb-main.treb-main .treb-formula-bar[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .treb-address-label{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;height:1.75em;justify-content:center;min-height:1.5em;min-width:95px;padding-left:3px;width:95px}.treb-main.treb-main .treb-formula-bar .treb-address-label>div{outline:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button{background:transparent;border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;height:1.75em;min-height:1.5em}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .expand-button{background:transparent;border:0;border-radius:2px;height:1.75em;margin-left:2px;outline:none;padding:1px}.treb-main.treb-main .treb-formula-bar .expand-button:after{border:5px solid transparent;border-top-color:#999;content:" ";display:inline-block;margin:0;padding:0;position:relative;top:-6px;transition:transform .15s ease}.treb-main.treb-main .treb-formula-bar[expanded] .expand-button:after{transform:rotate(180deg) translateY(6px)}.treb-main.treb-main .treb-formula-bar .treb-editor-container{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;flex-grow:1;height:1.75em;justify-content:center;min-width:0}.treb-main.treb-main .treb-formula-bar .treb-editor-container>.treb-editor-shadow{opacity:.4}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container{height:4.5em;transition:height .1s ease-in-out}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container>div{overflow-y:auto}.treb-main.treb-main .treb-formula-bar .treb-editor-container>div{flex-grow:1;line-height:1.35;margin:2px;min-height:1em;outline:none;overflow-x:hidden;overflow-y:hidden;white-space:pre-wrap;width:100%}.treb-main.treb-main .treb-mouse-mask .ghost-tab{position:fixed}.treb-main.treb-main .treb-spreadsheet-footer{align-items:center;grid-area:3/1/4/2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tab-container{align-self:flex-start;height:2.2em;overflow:hidden}.treb-main.treb-main .treb-spreadsheet-footer,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{color:var(--treb-ui-color,inherit);display:flex;flex-direction:row;height:2.2em;list-style-type:none;max-width:100%;padding-inline-start:0;z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{height:auto;margin-block-start:0;margin:0;overflow-x:scroll;overflow-y:hidden;scrollbar-width:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-spreadsheet-footer[hidden]{display:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{display:inline-block;margin:0;position:relative}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{align-items:center;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top-width:1px;border:1px solid var(--treb-tab-bar-tab-border-color,var(--treb-ui-border-color,#ccc));border-top:0 solid var(--treb-tab-bar-tab-border-color,var(--treb-ui-border-color,#ccc));color:var(--treb-tab-bar-tab-color,var(--treb-ui-color,#fff));cursor:default;display:inline-flex;font-size:inherit;height:100%;justify-content:center;margin-right:-2px;overflow:hidden;padding:0 .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:focus{z-index:3}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{height:2.2em;overflow:visible;overflow-x:visible}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:last-of-type{margin-right:0}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab{margin-left:-1px}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control{align-items:center;display:flex;flex-direction:row;font-size:inherit;height:2.2em;justify-content:center;position:relative;width:5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input{background:transparent;border:1px solid transparent;border-radius:2px;color:inherit;font-family:inherit;font-size:inherit;padding:initial;text-align:center;transition:border-color .25s ease,background-color .25s ease;width:4em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container{accent-color:var(--treb-scale-slider-accent-color,undefined);align-items:center;background:var(--treb-scale-slider-background,#fff);border:1px solid var(--treb-scale-slider-border-color,var(--treb-ui-border-color,#ccc));display:flex;flex-direction:row;height:4em;justify-content:center;left:.5em;opacity:0;pointer-events:none;position:absolute;top:0;transform:rotate(-90deg);transform-origin:left top;transition:opacity .25s ease;width:10em;z-index:40}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-scale-input{border-color:var(--treb-ui-border-color,#ccc)}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container>input[type=range]{width:8.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus+.treb-slider-container,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container:focus-within,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-slider-container{opacity:.85;pointer-events:auto}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab{align-items:center;background:transparent;border:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top:0;color:currentColor;cursor:default;display:inline-flex;flex-direction:row;font-size:inherit;margin-right:-2px;min-width:2.5em;padding:.25em .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab svg{height:1em;opacity:.75;pointer-events:none;transition:opacity .125s ease-in-out;width:1em}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:hover svg{opacity:.75}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab path{stroke:currentColor;stroke-linecap:round;stroke-width:1.5px}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:focus{z-index:3}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel{flex:1 1;overflow:hidden;text-align:end;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel>*{margin-left:.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel .treb-stats-value{background:var(--treb-stats-value-background,#f8f8ff);border:1px solid var(--treb-stats-value-border-color,var(--treb-ui-border-color,#ddd));border-radius:3px;padding:0 .3em}.treb-main.treb-main .treb-grid .treb-overlay-container{margin:0;opacity:0;outline:none;padding:0;position:absolute;z-index:24}.treb-main.treb-main .treb-grid .treb-overlay-container.align-right .treb-overlay-inset{padding-right:3px;right:0;text-align:right}.treb-main.treb-main .treb-grid .treb-overlay-container.align-center .treb-overlay-inset{left:50%;text-align:center;transform:translateX(-50%)}.treb-main.treb-main .treb-grid .treb-overlay-inset{display:flex;flex-direction:column;height:100%;justify-content:flex-end;margin:0;min-width:100%;padding:0 4px;position:absolute}.treb-main.treb-main .treb-grid .treb-overlay-editor{outline:none;position:relative;white-space:nowrap;white-space:pre}.treb-main.treb-main .treb-grid .treb-overlay-editor.firefox:before{content:"\u200B"}.treb-main.treb-main .treb-spill-border{pointer-events:none;position:absolute;transform:translateZ(0)}.treb-main.treb-main .treb-spill-border rect{fill:none;filter:var(--treb-spill-border-filter,drop-shadow(3px 3px 2px rgba(0,0,0,.5)));stroke:var(--treb-spill-border-color,#5c5ce0);stroke-dasharray:var(--treb-spill-border-dasharray,0);stroke-width:var(--treb-spill-border-width,1px);z-index:35}.treb-main.treb-main .treb-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{grid-area:2/1/3/2;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{flex-grow:1;order:2;overflow:scroll;position:relative;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;grid-template-columns:100px auto;grid-template-rows:20px auto;outline:none;overscroll-behavior:none}.treb-main.treb-main .treb-grid .tile-cover.grid-cover{grid-area:2/2/3/3}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover{grid-area:1/2/2/3;position:-webkit-sticky;position:sticky;top:0}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover{grid-area:2/1/3/2;left:0;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-grid-selection{grid-area:1/1/2/2}.treb-main.treb-main .treb-grid .treb-corner{grid-area:1/1/2/2;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-left-header{display:grid;grid-area:2/1/3/2;grid-template-columns:auto;grid-template-rows:auto;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-top-header{display:grid;grid-area:1/2/2/3;grid-template-columns:auto;grid-template-rows:auto;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-contents{display:grid;grid-area:2/2/3/3;grid-template-columns:auto;grid-template-rows:auto}.treb-main.treb-main .treb-grid.safari::-webkit-scrollbar{-webkit-appearance:none;height:7px;width:7px}.treb-main.treb-main .treb-grid.safari::-webkit-scrollbar-thumb{background-color:rgba(0,0,0,.25);border-radius:4px;-webkit-box-shadow:0 0 1px hsla(0,0%,100%,.5)}.treb-main.treb-main .treb-grid canvas{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-grid .nub-select{cursor:crosshair}.treb-main.treb-main .treb-grid .link-pointer{cursor:pointer}.treb-main.treb-main .treb-grid .mock-selection-node{background:red;left:-100px;position:fixed;top:-100px}.treb-main.treb-main .treb-grid .tile-cover{background:transparent;position:relative;z-index:14}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover{z-index:22}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover.resize{cursor:col-resize}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover{z-index:22}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover.resize{cursor:row-resize}.treb-main.treb-main .treb-grid .frozen-annotation-container,.treb-main.treb-main .treb-grid .treb-annotation-container{left:0;pointer-events:none;position:absolute;top:0;z-index:16}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation{background:hsla(0,0%,100%,.5);border:1px solid #999;overflow:hidden;pointer-events:auto;position:absolute;z-index:1}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-content,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-content{font-family:inherit;font-size:inherit;height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-move-target,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-move-target{cursor:move;height:10%;left:0;min-height:14px;position:absolute;top:0;width:100%;z-index:2}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-resize-target,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-resize-target{bottom:0;cursor:nwse-resize;height:10%;min-height:14px;min-width:14px;position:absolute;right:0;width:10%;z-index:3}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation.clone-focus,.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation.retain-focus,.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation:focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation.clone-focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation.retain-focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation:focus{box-shadow:0 0 0 3px rgba(14,165,233,.33)}.treb-main.treb-main .treb-grid .frozen-annotation-container .move-buffer,.treb-main.treb-main .treb-grid .treb-annotation-container .move-buffer{border:1px solid red;cursor:move;height:10%;left:0;position:absolute;top:0;width:100%}.treb-main.treb-main .treb-grid .treb-grid-selection{background:transparent;position:absolute;transform:translateZ(0);-moz-transform:scale(1);z-index:10}.treb-main.treb-main .treb-grid .frozen-selection{overflow:hidden;pointer-events:none;position:absolute;transform:translateZ(0);-moz-transform:scale(1);transition:background .33s;z-index:12}.treb-main.treb-main .treb-grid .frozen-selection.frozen-selection-rows{border-bottom:1px solid transparent}.treb-main.treb-main .treb-grid .frozen-selection.frozen-selection-columns{border-right:1px solid transparent}.treb-main.treb-main .treb-grid .frozen-annotation-container{height:100%;left:0;overflow:hidden;position:absolute;top:0;width:100%}.treb-main.treb-main .treb-grid .treb-corner{left:0;top:0;z-index:20}.treb-main.treb-main .treb-grid .treb-corner canvas{left:0;pointer-events:none;position:absolute;top:0}.treb-main.treb-main .treb-grid .treb-left-header{left:0;pointer-events:none;z-index:18}.treb-main.treb-main .treb-grid .treb-top-header{pointer-events:none;top:0;z-index:18}.treb-main.treb-main .treb-grid .treb-contents{height:2000px;width:2000px}.treb-main.treb-main{--alternate-selection-color-1:#fbb13c;--alternate-selection-color-2:#40c040;--alternate-selection-color-3:#b66d0d;--alternate-selection-color-4:#2176ae;--alternate-selection-color-5:#fe6847;--text-reference-color-1:#e08a00;--text-reference-color-2:#3aad3a;--text-reference-color-3:#b66d0d;--text-reference-color-4:#2176ae;--text-reference-color-5:#fe2f01}.treb-main.treb-main:focus-within .treb-grid-selection .primary-selection,.treb-main.treb-main:focus-within .treb-header-overlay{color:var(--treb-selection-color,#4caaf1)}.treb-main.treb-main .theme-color-1{color:var(--treb-theme-color-1,#e7e6e6)}.treb-main.treb-main .theme-color-2{color:var(--treb-theme-color-2,#44546a)}.treb-main.treb-main .theme-color-3{color:var(--treb-theme-color-3,#4472c4)}.treb-main.treb-main .theme-color-4{color:var(--treb-theme-color-4,#ed7d31)}.treb-main.treb-main .theme-color-5{color:var(--treb-theme-color-5,#a5a5a5)}.treb-main.treb-main .theme-color-6{color:var(--treb-theme-color-6,#ffc000)}.treb-main.treb-main .theme-color-7{color:var(--treb-theme-color-7,#5b9bd5)}.treb-main.treb-main .theme-color-8{color:var(--treb-theme-color-8,#70ad47)}.treb-main.treb-main .theme-color-9{color:var(--treb-theme-color-9,#0563c1)}.treb-main.treb-main .theme-color-10{color:var(--treb-theme-color-10,#954f72)}.treb-main.treb-main .treb-offset-dark{color:#000}.treb-main.treb-main .treb-offset-light{color:#fff}.treb-main.treb-main .note-marker{background:var(--treb-note-marker-color,#6fab20)}.treb-main.treb-main .grid-headers{background:var(--treb-grid-header-background,#eeeef2);color:var(--treb-grid-header-color,var(--treb-grid-default-color,#666));font-family:var(--treb-grid-header-font-family,inherit);font-size:var(--treb-grid-header-font-size,10pt);font-style:var(--treb-grid-header-font-style,normal);font-weight:var(--treb-grid-header-font-weight,normal);stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4))}.treb-main.treb-main .grid-cells{background:var(--treb-grid-background,#fff);color:var(--treb-grid-default-color,inherit);font-family:var(--treb-grid-font-family,inherit);font-size:var(--treb-grid-font-size,14px);stroke:var(--treb-grid-grid-color,#ccccd4)}.treb-main.treb-main .frozen-selection.highlight-area{background:rgba(87,184,255,.25);border-bottom-color:#2176ae;border-left-color:#2176ae}.treb-main.treb-main .treb-autocomplete-tooltip{background:var(--treb-autocomplete-tooltip-background,#fffbb5);border:1px solid var(--treb-autocomplete-tooltip-border-color,unset);border-radius:2px;color:var(--treb-autocomplete-tooltip-color,inherit);font-size:14px;line-height:normal;margin:4px 0;padding:3px 8px}.treb-main.treb-main .treb-autocomplete-tooltip .active-argument{font-weight:700}.treb-main.treb-main .treb-autocomplete-tooltip .function-description{font-style:italic}.treb-main.treb-main .treb-autocomplete{background:var(--treb-autocomplete-background,#fff);border:1px solid var(--treb-autocomplete-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);font-size:14px}.treb-main.treb-main .treb-autocomplete li{color:var(--treb-autocomplete-entry-color,#333)}.treb-main.treb-main .treb-autocomplete li a.selected{background:var(--treb-autocomplete-selected-entry-background,#2e8dd6);color:var(--treb-autocomplete-selected-entry-color,#fff)}.treb-main.treb-main .treb-header-overlay{color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1));stroke:none}.treb-main.treb-main .treb-header-overlay .treb-overlay{fill:#000;opacity:.05;stroke:none}.treb-main.treb-main .treb-header-overlay .treb-highlight{fill:currentColor}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="1"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="1"]{color:var(--text-reference-color-1)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="2"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="2"]{color:var(--text-reference-color-2)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="3"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="3"]{color:var(--text-reference-color-3)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="4"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="4"]{color:var(--text-reference-color-4)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="5"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="5"]{color:var(--text-reference-color-5)}.treb-main.treb-main .treb-editor-container>div span.highlight-1,.treb-main.treb-main .treb-overlay-editor span.highlight-1{color:var(--text-reference-color-1)}.treb-main.treb-main .treb-editor-container>div span.highlight-2,.treb-main.treb-main .treb-overlay-editor span.highlight-2{color:var(--text-reference-color-2)}.treb-main.treb-main .treb-editor-container>div span.highlight-3,.treb-main.treb-main .treb-overlay-editor span.highlight-3{color:var(--text-reference-color-3)}.treb-main.treb-main .treb-editor-container>div span.highlight-4,.treb-main.treb-main .treb-overlay-editor span.highlight-4{color:var(--text-reference-color-4)}.treb-main.treb-main .treb-editor-container>div span.highlight-5,.treb-main.treb-main .treb-overlay-editor span.highlight-5{color:var(--text-reference-color-5)}.treb-main.treb-main .frozen-selection .selection,.treb-main.treb-main .treb-grid-selection .selection{stroke-width:var(--treb-selection-stroke-width,2px)}.treb-main.treb-main .frozen-selection .selection .treb-selection-outline,.treb-main.treb-main .treb-grid-selection .selection .treb-selection-outline{fill:none;stroke:currentColor}.treb-main.treb-main .frozen-selection .selection .treb-selection-fill,.treb-main.treb-main .treb-grid-selection .selection .treb-selection-fill{fill:currentColor;opacity:var(--treb-selection-fill-opacity,.1);stroke:none}.treb-main.treb-main .frozen-selection .alternate-selection,.treb-main.treb-main .treb-grid-selection .alternate-selection{stroke-dasharray:var(--treb-alternate-selection-dasharray,3 2)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(1n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(1n){color:var(--alternate-selection-color-1)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(2n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(2n){color:var(--alternate-selection-color-2)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(3n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(3n){color:var(--alternate-selection-color-3)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(4n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(4n){color:var(--alternate-selection-color-4)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(5n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(5n){color:var(--alternate-selection-color-5)}.treb-main.treb-main .frozen-selection .primary-selection,.treb-main.treb-main .treb-grid-selection .primary-selection{color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1))}.treb-main.treb-main .frozen-selection .primary-selection .treb-selection-nub,.treb-main.treb-main .treb-grid-selection .primary-selection .treb-selection-nub{fill:currentColor;stroke:#fff;stroke-width:1px}.treb-main.treb-main .treb-tooltip{background:var(--treb-resize-tooltip-background,rgba(0,0,0,.8));border-color:var(--treb-resize-tooltip-background,rgba(0,0,0,.8));color:var(--treb-resize-tooltip-color,#fff);font-size:11pt}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{background:var(--treb-tab-bar-tab-background,#eeeef2);color:var(--treb-tab-bar-tab-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab[selected],.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{background:var(--treb-tab-bar-active-tab-background,#fff);border-bottom-color:var(--treb-tab-bar-active-tab-border-color,currentColor);color:var(--treb-tab-bar-active-tab-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-formula-bar .treb-address-label,.treb-main.treb-main .treb-formula-bar .treb-editor-container{background:var(--treb-formula-bar-background,transparent);color:var(--treb-formula-bar-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-formula-bar .treb-address-label[locked],.treb-main.treb-main .treb-formula-bar .treb-editor-container[locked]{background:var(--treb-formula-bar-locked-background,#eef4fc);position:relative}.treb-main.treb-main .treb-formula-bar .treb-address-label[locked]:after,.treb-main.treb-main .treb-formula-bar .treb-editor-container[locked]:after{content:"";height:12px;opacity:.4;position:absolute;right:2px;top:2px;width:12px;--icon:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='currentColor' d='M416 224h-16v-80C400 65 335 0 256 0S112 65 112 144v80H96c-35 0-64 29-64 64v160c0 35 29 64 64 64h320c35 0 64-29 64-64V288c0-35-29-64-64-64m-240-80c0-44 36-80 80-80s80 36 80 80v80H176z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:12px 12px;-webkit-mask-size:12px 12px}.treb-main.treb-main .treb-annotation-textbox{background:Canvas;height:100%;left:0;overflow:hidden;padding:.5em;position:relative;top:0;width:100%}.treb-main.treb-main .treb-annotation-textbox p{margin-block-end:0;margin-block-start:0}.treb-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-tab-background:#000;--treb-tab-bar-tab-color:#fff;--treb-theme-color-1:#222;--treb-theme-color-2:#ddd;--treb-toolbar-active-button-background:#555;--treb-toolbar-button-background:#000;--treb-toolbar-hover-button-background:#444;--treb-ui-color:#fff;--treb-table-header-background:#334;--treb-table-odd-background:#122;--treb-table-header-font-weight:700;--treb-table-header-border-top:#889;--treb-table-header-border-bottom:#889;--treb-table-footer-border-bottom:#889;--treb-table-odd-border-top:#889;--treb-table-odd-border-bottom:#889;--treb-table-even-border-top:#889;--treb-table-even-border-bottom:#889;--treb-table-total-border-top:#889;--treb-table-total-border-bottom:#889;--treb-table-total-background:#334;--treb-table-total-font-weight:700;--treb-color-scheme:dark;--treb-resize-handle-color:#add8e6;--treb-resize-frame-color:#add8e6;--treb-formula-bar-locked-background:#234;--treb-grid-background:#1e1e1e;--treb-grid-header-background:#565656;--treb-grid-header-color:#ddd;--treb-tab-bar-active-tab-background:#444;--treb-tab-bar-tab-background:transparent;--treb-tab-bar-tab-border-color:#444;--treb-ui-border-color:#aaa;--treb-toolbar-button-background:#565656;--treb-toolbar-button-background:#212121;--treb-toolbar-border-color:#434343;--treb-toolbar-color:#ddd;--treb-spill-border-color:pink;--treb-spill-border-filter:drop-shadow(3px 3px 2px hsla(0,0%,100%,.95))}@media (prefers-color-scheme:dark){.treb-light-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-tab-background:#000;--treb-tab-bar-tab-color:#fff;--treb-theme-color-1:#222;--treb-theme-color-2:#ddd;--treb-toolbar-active-button-background:#555;--treb-toolbar-button-background:#000;--treb-toolbar-hover-button-background:#444;--treb-ui-color:#fff;--treb-table-header-background:#334;--treb-table-odd-background:#122;--treb-table-header-font-weight:700;--treb-table-header-border-top:#889;--treb-table-header-border-bottom:#889;--treb-table-footer-border-bottom:#889;--treb-table-odd-border-top:#889;--treb-table-odd-border-bottom:#889;--treb-table-even-border-top:#889;--treb-table-even-border-bottom:#889;--treb-table-total-border-top:#889;--treb-table-total-border-bottom:#889;--treb-table-total-background:#334;--treb-table-total-font-weight:700;--treb-color-scheme:dark;--treb-resize-handle-color:#add8e6;--treb-resize-frame-color:#add8e6;--treb-formula-bar-locked-background:#234;--treb-grid-background:#1e1e1e;--treb-grid-header-background:#565656;--treb-grid-header-color:#ddd;--treb-tab-bar-active-tab-background:#444;--treb-tab-bar-tab-background:transparent;--treb-tab-bar-tab-border-color:#444;--treb-ui-border-color:#aaa;--treb-toolbar-button-background:#565656;--treb-toolbar-button-background:#212121;--treb-toolbar-border-color:#434343;--treb-toolbar-color:#ddd;--treb-spill-border-color:pink;--treb-spill-border-filter:drop-shadow(3px 3px 2px hsla(0,0%,100%,.95))}}.treb-chart,.treb-main.treb-main .treb-chart{background:var(--treb-chart-background,#fff)}.treb-main.treb-main .treb-inherit-font .treb-chart{font-family:inherit}.treb-chart{--segment-2-offset:-20;--segment-3-offset:10;--segment-4-offset:-10;--segment-5-offset:20;--segment-6-offset:-25}.treb-chart .series-1{color:var(--treb-applied-theme-color-1)}.treb-chart .series-2{color:var(--treb-applied-theme-color-2)}.treb-chart .series-3{color:var(--treb-applied-theme-color-3)}.treb-chart .series-4{color:var(--treb-applied-theme-color-4)}.treb-chart .series-5{color:var(--treb-applied-theme-color-5)}.treb-chart .series-6{color:var(--treb-applied-theme-color-6)}.treb-chart .series-7{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-8{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-9{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-10{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-11{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-12{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-13{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-14{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-15{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-16{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-17{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-18{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-19{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-20{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-21{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-22{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-23{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-24{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-25{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-26{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-27{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-28{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-29{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-30{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-31{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-32{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-33{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-34{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-35{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-36{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-6-offset)) c h)}.treb-chart .chart-title{font-size:1.4em}.treb-chart .axis-group{font-size:.9em}.treb-chart .axis-group .series-name{font-size:1.3em}.treb-chart text{fill:var(--treb-chart-text-color,#000);stroke:none}.treb-chart .legend{font-size:1.05em}.treb-chart .legend rect{fill:currentColor}.treb-chart .legend circle{fill:currentColor;fill-opacity:.5;r:.25em;stroke:currentColor;stroke-width:2px}.treb-chart .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .chart-grid.zero,.treb-chart .chart-ticks.zero{stroke:var(--treb-chart-grid-zero-color,var(--treb-chart-grid-color,#999))}.treb-chart .label-target{fill:transparent;stroke:none}.treb-chart path.label-target{transition:fill .2s}.treb-chart path.label-target:hover{fill:rgba(0,0,0,.15)}.treb-chart .data-label{opacity:0;pointer-events:none;transition:opacity .2s ease-in-out}.treb-chart .data-label text{fill:#fff}.treb-chart .data-label path{fill:#000}.treb-chart .data-label .marker-highlight{fill:currentColor;stroke:none}.treb-chart .label-target:hover+.data-label{opacity:1}.treb-chart .chart-line{fill:none;stroke:currentColor;stroke-width:2}.treb-chart .chart-area .line{fill:none;stroke:currentColor;stroke-width:2px}.treb-chart .chart-area .fill{fill:currentColor;opacity:.5}.treb-chart .box-plot .iqr{fill:none;stroke:CanvasText;stroke-width:1px}.treb-chart .box-plot .median{fill:none;stroke:CanvasText;stroke-width:3px}.treb-chart .box-plot .outlier{r:3}.treb-chart .box-plot .outlier,.treb-chart .box-plot .whisker,.treb-chart .box-plot .whisker-extent{fill:none;stroke:CanvasText;stroke-width:1px}.treb-chart .box-plot .whisker-extent{stroke-dasharray:3 3}.treb-chart .bubble-chart{fill:color-mix(in srgb,currentColor 75%,transparent);stroke:currentColor;stroke-width:3}.treb-chart .bubble-label .label-background{fill:none;stroke:none}.treb-chart .bubble-label .label-text{transform:translate(var(--translate-offset),var(--translate-offset))}.treb-chart .scatter-plot{fill:none;stroke:currentColor;stroke-width:3}.treb-chart .scatter-plot .fill{fill:currentColor;opacity:.5;stroke:none}.treb-chart .scatter-plot .marker{fill:#fff;stroke-width:2.5px;transition:stroke-width .15s ease-in}.treb-chart .scatter-plot .marker:hover{stroke-width:5px}.treb-chart .donut path{fill:currentColor}.treb-chart .donut path.callout{fill:none;stroke:#999;stroke-dasharray:2 2}.treb-chart .donut text.callout-label{font-size:1em}.treb-chart .chart-column{fill:currentColor;stroke:none}.treb-chart .mc-correlation{stroke:currentColor;stroke-width:1}.treb-main.treb-main{--treb-icon-svg:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='153.073' height='133.742' viewBox='0.673 4.629 153.073 133.742'%3E%3ClinearGradient id='a' x1='.673' x2='153.746' y1='71.5' y2='71.5' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' style='stop-color:%235cb5ff'/%3E%3Cstop offset='1' style='stop-color:%230059b9'/%3E%3C/linearGradient%3E%3Cpath fill='url(%23a)' d='M91.656 28.313c-4.989 0-17.266 6.249-21.305 8.504-2.344-2.473-2.603-6.162-3.036-10.933-2.344 2.429-.824 9.806 0 12.496-10.238 7.635-18.83 15.531-27.597 24.471-2.992-4.729-5.031-8.593-5.726-17.183-3.038 6.509.867 15.057 3.121 19.784-9.674 12.193-19.263 25.297-27.03 37.834-35.488-74.973 72.853-119.534 143.663-88.855-43.867 29.199-55.192 121.353-132.248 96.843-5.423 7.809-9.069 18.006-13.538 27.072-3.73.263-6.334-1.646-7.288-3.12 7.506-18.181 17.183-34.192 27.075-49.984 10.718.306 21.346.478 30.198-1.04-7.681-2.038-16.877-.78-26.032-3.123C37.51 70.361 45.667 62.203 53.78 54.004c8.808.782 17.746 3.21 27.074 1.041-8.111-1.431-15.966-1.952-22.909-4.165 7.594-8.378 22.777-17.491 33.711-22.567'/%3E%3C/svg%3E")}.treb-main.treb-main .treb-icon-64{background:no-repeat 50%/100% var(--treb-icon-svg);height:64px;width:64px}.treb-main.treb-main .treb-dialog-mask{align-items:center;display:flex;height:100%;justify-content:center;left:0;opacity:0;pointer-events:none;position:absolute;top:0;transition:opacity .2s;width:100%;z-index:1000}.treb-main.treb-main .treb-embed-dialog{align-items:center;background:var(--treb-dialog-background,#fff);border:1px solid var(--treb-dialog-border-color,var(--treb-ui-border-color,#999));border-radius:3px;border-top:3px solid #999;box-shadow:0 4px 6px -4px rgba(0,0,0,.3);color:var(--treb-dialog-color,#000);display:flex;flex-direction:row;font-size:var(--treb-dialog-font-size,16px);line-height:1.6em;padding:1rem;position:relative;text-align:left}.treb-main.treb-main .treb-embed-dialog>*{display:none}.treb-main.treb-main .treb-embed-dialog>div{position:relative}.treb-main.treb-main .treb-embed-dialog>:nth-child(2){display:block;flex-grow:1;padding:2px 20px 2px 12px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box{background:transparent;border:0;padding:4px;position:absolute;right:0;top:0}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg{cursor:default;fill:#73828c;height:20px;width:20px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg:active,.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg:hover{fill:#049cfb}.treb-main.treb-main .treb-embed-dialog small{display:block;font-size:.9em}.treb-main.treb-main .treb-embed-dialog a{color:inherit;text-decoration:none}.treb-main.treb-main .treb-embed-dialog a:active,.treb-main.treb-main .treb-embed-dialog a:hover{color:#049cfb}.treb-main.treb-main .treb-embed-dialog.dialog-type-success{border-top-color:#44d926;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-about{border-top-color:#009dff;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-error{border-top-color:#f92f06;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-info{border-top-color:#009dff;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog .treb-embed-dialog-message,.treb-main.treb-main .treb-embed-dialog .treb-embed-dialog-title{white-space:pre}.treb-main.treb-main .treb-embed-dialog .treb-embed-progress-container{border:1px solid #ddd;height:6px;margin:1rem auto .5rem;position:relative;width:100%}.treb-main.treb-main .treb-embed-dialog .treb-embed-progress-bar{background:#52880b;height:100%;left:0;position:relative;top:0}.treb-main.treb-main .treb-spinner{align-items:center;background:transparent;display:flex;height:100%;justify-content:center;left:0;opacity:0;position:absolute;top:0;transition:visibility .25s,opacity .25s ease;visibility:collapse;width:100%;z-index:1000}.treb-main.treb-main .treb-spinner.visible{opacity:1;transition:visibility 0s,opacity 1s ease;visibility:visible}.treb-main.treb-main .treb-spinner>div{display:inline-block;height:80px;position:relative;width:80px}.treb-main.treb-main .treb-spinner>div div{animation:treb-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border:8px solid #fff;border-color:var(--treb-spinner-color,currentColor) transparent transparent transparent;border-radius:50%;box-sizing:border-box;display:block;height:64px;margin:8px;position:absolute;width:64px}.treb-main.treb-main .treb-spinner>div div:first-child{animation-delay:-.45s}.treb-main.treb-main .treb-spinner>div div:nth-child(2){animation-delay:-.3s}.treb-main.treb-main .treb-spinner>div div:nth-child(3){animation-delay:-.15s}@keyframes treb-spinner{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.treb-main.treb-main{--icon-x:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708"/></svg>');--icon-popout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path fill="currentColor" d="M22 14.5v5c0 2.484-2.016 4.5-4.5 4.5h-13A4.5 4.5 0 0 1 0 19.5v-13C0 4.016 2.016 2 4.5 2h11c.281 0 .5.219.5.5v1c0 .281-.219.5-.5.5h-11A2.507 2.507 0 0 0 2 6.5v13C2 20.875 3.125 22 4.5 22h13c1.375 0 2.5-1.125 2.5-2.5v-5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5M28 1v8c0 .547-.453 1-1 1a1 1 0 0 1-.703-.297l-2.75-2.75L13.36 17.14c-.094.094-.234.156-.359.156s-.266-.063-.359-.156l-1.781-1.781c-.094-.094-.156-.234-.156-.359s.063-.266.156-.359L21.048 4.454l-2.75-2.75a1 1 0 0 1-.297-.703c0-.547.453-1 1-1h8c.547 0 1 .453 1 1z"/></svg>');--icon-toolbar:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M5.5 22v2H0v-2zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm2.5-6v2H0v-2zm-10-8v2H0V6zM24 22v2H12.5v-2zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm5 2v2h-3.5v-2zm0-8v2H10.5V6z"/></svg>');--icon-export:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 28"><path fill="currentColor" d="M20 21c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m2-3.5v5a1.5 1.5 0 0 1-1.5 1.5h-23A1.5 1.5 0 0 1 0 22.5v-5A1.5 1.5 0 0 1 1.5 16h7.266l2.109 2.125c.578.562 1.328.875 2.125.875s1.547-.313 2.125-.875L17.25 16h7.25a1.5 1.5 0 0 1 1.5 1.5m-5.078-8.891a.98.98 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.98.98 0 0 1-.219-1.094C5.234 8.25 5.594 8 6 8h4V1c0-.547.453-1 1-1h4c.547 0 1 .453 1 1v7h4c.406 0 .766.25.922.609"/></svg>');--icon-reset:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M23.609 16.5c0 .031 0 .078-.016.109C22.265 22.14 17.702 26 11.937 26c-3.047 0-6-1.203-8.219-3.313l-2.016 2.016A1 1 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a1 1 0 0 1-.297.703l-2.141 2.141A7.99 7.99 0 0 0 11.998 22a7.98 7.98 0 0 0 6.813-3.813c.375-.609.562-1.203.828-1.828.078-.219.234-.359.469-.359h3c.281 0 .5.234.5.5zM24 4v7c0 .547-.453 1-1 1h-7c-.547 0-1-.453-1-1a1 1 0 0 1 .297-.703l2.156-2.156A8.04 8.04 0 0 0 12 6a7.98 7.98 0 0 0-6.813 3.813c-.375.609-.562 1.203-.828 1.828-.078.219-.234.359-.469.359H.781a.503.503 0 0 1-.5-.5v-.109C1.625 5.844 6.234 2 12 2c3.063 0 6.047 1.219 8.266 3.313l2.031-2.016A1 1 0 0 1 23 3c.547 0 1 .453 1 1"/></svg>');--icon-about:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M14 21.5v-3c0-.281-.219-.5-.5-.5h-3c-.281 0-.5.219-.5.5v3c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5M18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328a.49.49 0 0 0 .125.656l2.063 1.563a.48.48 0 0 0 .297.094.5.5 0 0 0 .391-.187c.734-.938 1.047-1.219 1.344-1.437.266-.187.781-.375 1.344-.375 1 0 1.922.641 1.922 1.328 0 .812-.422 1.219-1.375 1.656-1.109.5-2.625 1.797-2.625 3.313v.562c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5 0-.359.453-1.125 1.188-1.547 1.188-.672 2.812-1.578 2.812-3.953zm6 3c0 6.625-5.375 12-12 12S0 20.625 0 14 5.375 2 12 2s12 5.375 12 12"/></svg>');--icon-chevron-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 28"><path fill="currentColor" d="M18.297 4.703 10 13l8.297 8.297a.99.99 0 0 1 0 1.406l-2.594 2.594a.99.99 0 0 1-1.406 0L2.703 13.703a.99.99 0 0 1 0-1.406L14.297.703a.99.99 0 0 1 1.406 0l2.594 2.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-chevron-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 28"><path fill="currentColor" d="M17.297 13.703 5.703 25.297a.99.99 0 0 1-1.406 0l-2.594-2.594a.99.99 0 0 1 0-1.406L10 13 1.703 4.703a.99.99 0 0 1 0-1.406L4.297.703a.99.99 0 0 1 1.406 0l11.594 11.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-revert:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M24 14c0 6.609-5.391 12-12 12a11.97 11.97 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.6.6 0 0 1 .391-.141.5.5 0 0 1 .359.187A7.91 7.91 0 0 0 12 21.999c4.406 0 8-3.594 8-8s-3.594-8-8-8A7.95 7.95 0 0 0 6.563 8.14l2.141 2.156a.96.96 0 0 1 .219 1.078 1 1 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.96.96 0 0 1 1.078.219l2.031 2.016c2.203-2.078 5.187-3.313 8.266-3.313 6.609 0 12 5.391 12 12zM14 9.5v7c0 .281-.219.5-.5.5h-5a.494.494 0 0 1-.5-.5v-1c0-.281.219-.5.5-.5H12V9.5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5"/></svg>');--icon-text-indent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-left" viewBox="0 0 16 16"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m.646 2.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L4.293 8 2.646 6.354a.5.5 0 0 1 0-.708M7 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m-5 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-outdent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-right" viewBox="0 0 16 16"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m10.646 2.146a.5.5 0 0 1 .708.708L11.707 8l1.647 1.646a.5.5 0 0 1-.708.708l-2-2a.5.5 0 0 1 0-.708zM2 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-center:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-top:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 15a.5.5 0 0 0 .5-.5V5.707l3.146 3.146a.5.5 0 0 0 .707-.707l-4-4a.5.5 0 0 0-.706-.001l-.001.001-4 4a.5.5 0 0 0 .708.707L7.5 5.707V14.5a.5.5 0 0 0 .5.5'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M3 1.5h10'/%3E%3C/svg%3E");--icon-text-align-middle:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8m7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0m-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0z"/></svg>');--icon-text-align-bottom:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a.5.5 0 0 0-.5.5v8.793L4.354 7.146a.5.5 0 0 0-.707.707l4 4a.5.5 0 0 0 .707.001l.001-.001 4-4a.5.5 0 0 0-.708-.707L8.5 10.293V1.5A.5.5 0 0 0 8 1'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M13 14.5H3'/%3E%3C/svg%3E");--icon-file-menu:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.54 3.87.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.826a2 2 0 0 1-1.991-1.819l-.637-7a2 2 0 0 1 .342-1.31zM2.19 4a1 1 0 0 0-.996 1.09l.637 7a1 1 0 0 0 .995.91h10.348a1 1 0 0 0 .995-.91l.637-7A1 1 0 0 0 13.81 4zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139q.323-.119.684-.12h5.396z"/></svg>');--icon-wrap-text:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4 5h8a.5.5 0 0 0 0-1H4a.5.5 0 0 0 0 1M10 8H4a.5.5 0 0 0 0 1h6a1.5 1.5 0 0 1 0 3v-1.203l-2.953 1.707L10 14.203V13a2.5 2.5 0 1 0 0-5M3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5"/></svg>');--icon-unmerge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M1.5 1a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0v-4A1.5 1.5 0 0 1 1.5 0h4a.5.5 0 0 1 0 1zM10 .5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 16 1.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5M.5 10a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 0 14.5v-4a.5.5 0 0 1 .5-.5m15 0a.5.5 0 0 1 .5.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5"/></svg>');--icon-merge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M5.5 0a.5.5 0 0 1 .5.5v4A1.5 1.5 0 0 1 4.5 6h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5m5 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 10 4.5v-4a.5.5 0 0 1 .5-.5M0 10.5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 6 11.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5m10 1a1.5 1.5 0 0 1 1.5-1.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0z"/></svg>');--icon-lock:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2m3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2M5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1"/></svg>');--icon-comment:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-2.5a2 2 0 0 0-1.6.8L8 14.333 6.1 11.8a2 2 0 0 0-1.6-.8H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2.5a1 1 0 0 1 .8.4l1.9 2.533a1 1 0 0 0 1.6 0l1.9-2.533a1 1 0 0 1 .8-.4H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/></svg>');--icon-fill-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a3 3 0 0 0-.71-.515c-.217-.104-.56-.205-.882-.02-.367.213-.427.63-.43.896-.003.304.064.664.173 1.044.196.687.556 1.528 1.035 2.402L.752 8.22c-.277.277-.269.656-.218.918.055.283.187.593.36.903.348.627.92 1.361 1.626 2.068.707.707 1.441 1.278 2.068 1.626.31.173.62.305.903.36.262.05.64.059.918-.218l5.615-5.615c.118.257.092.512.05.939-.03.292-.068.665-.073 1.176v.123h.003a1 1 0 0 0 1.993 0H14v-.057a1 1 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4 4 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067S8.857 3.052 8.23 2.704c-.31-.172-.62-.304-.903-.36-.262-.05-.64-.058-.918.219l-.217.216zM4.16 1.867c.381.356.844.922 1.311 1.632l-.704.705c-.382-.727-.66-1.402-.813-1.938a3.3 3.3 0 0 1-.131-.673q.137.09.337.274m.394 3.965c.54.852 1.107 1.567 1.607 2.033a.5.5 0 1 0 .682-.732c-.453-.422-1.017-1.136-1.564-2.027l1.088-1.088q.081.181.183.365c.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626q.183.103.365.183l-4.861 4.862a1 1 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46s-1.168-1.32-1.46-1.846c-.147-.265-.225-.47-.251-.607a1 1 0 0 1-.01-.068zm2.87-1.935a2.4 2.4 0 0 1-.241-.561c.135.033.324.11.562.241.524.292 1.186.8 1.846 1.46.45.45.83.901 1.118 1.31a3.5 3.5 0 0 0-1.066.091 11 11 0 0 1-.76-.694c-.66-.66-1.167-1.322-1.458-1.847z"/></svg>');--icon-text-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" viewBox="0 0 16 16"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604zM8.418 3.604a6 6 0 0 1-.127-.387 4 4 0 0 1-.11-.501h-.035a5.5 5.5 0 0 1-.247.888L5.86 9.211h4.614z"/></svg>');--icon-border-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0z"/></svg>');--icon-border-top:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0v1h16V0zm1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0v16h1V0zm1.906 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM7.5 1.906v.938h1v-.938zm7.5 0v.938h1v-.938zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938zm7.5 0v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM7.5 9.406v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zM1.906 16h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zM16 0h-1v16h1zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zM0 11.281v.938h1v-.938zm7.5 0v.938h1v-.938zM0 13.156v.938h1v-.938zm7.5 0v.938h1v-.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938z"/></svg>');--icon-border-double-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0zm0-2h16v1H0z"/></svg>');--icon-border-all:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0h16v16H0zm1 1v6.5h6.5V1zm7.5 0v6.5H15V1zM15 8.5H8.5V15H15zM7.5 15V8.5H1V15z"/></svg>');--icon-border-outer:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M7.5 1.906v.938h1v-.938zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM7.5 9.406v.938h1v-.938zm0 1.875v.938h1v-.938zm0 1.875v.938h1v-.938z"/><path d="M0 0v16h16V0zm1 1h14v14H1z"/></svg>');--icon-border-none:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0zm2.844 1h-.938V0h.938zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1zm2.813 0h-.938V0h.938zm1.875 0h-.938V0h.938zm1.875 0h-.938V0h.938zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5zM1 1.906v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM1 3.78v.938H0V3.78zm6.5.938V3.78h1v.938zm7.5 0V3.78h1v.938zM1 5.656v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938zm1.875.031h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5zM0 10.344v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 12.22v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 14.094v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5zm2.813 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16z"/></svg>');--icon-palette:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 .5A.5.5 0 0 1 .5 0h5a.5.5 0 0 1 .5.5v5.277l4.147-4.131a.5.5 0 0 1 .707 0l3.535 3.536a.5.5 0 0 1 0 .708L10.261 10H15.5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5H3a3 3 0 0 1-2.121-.879A3 3 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0M15 15v-4H9.258l-4.015 4zM0 .5v12.495zM0 12.995V13z"/></svg>');--icon-layout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="m3 0 17 17.156v-.114z"/><path d="M3 0H0v16h1V1h1.585L19 17.455V19H4v1h16v-2.844z"/><path d="M6.886 3.922 5.343 5.465a.5.5 0 0 0 .708.707l1.539-1.54zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3M5 9v6h6zm1 2.414L8.586 14H6z"/></svg>');--icon-freeze:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 16a.5.5 0 0 1-.5-.5v-1.293l-.646.647a.5.5 0 0 1-.707-.708L7.5 12.793V8.866l-3.4 1.963-.496 1.85a.5.5 0 1 1-.966-.26l.237-.882-1.12.646a.5.5 0 0 1-.5-.866l1.12-.646-.884-.237a.5.5 0 1 1 .26-.966l1.848.495L7 8 3.6 6.037l-1.85.495a.5.5 0 0 1-.258-.966l.883-.237-1.12-.646a.5.5 0 1 1 .5-.866l1.12.646-.237-.883a.5.5 0 1 1 .966-.258l.495 1.849L7.5 7.134V3.207L6.147 1.854a.5.5 0 1 1 .707-.708l.646.647V.5a.5.5 0 1 1 1 0v1.293l.647-.647a.5.5 0 1 1 .707.708L8.5 3.207v3.927l3.4-1.963.496-1.85a.5.5 0 1 1 .966.26l-.236.882 1.12-.646a.5.5 0 0 1 .5.866l-1.12.646.883.237a.5.5 0 1 1-.26.966l-1.848-.495L9 8l3.4 1.963 1.849-.495a.5.5 0 0 1 .259.966l-.883.237 1.12.646a.5.5 0 0 1-.5.866l-1.12-.646.236.883a.5.5 0 1 1-.966.258l-.495-1.849-3.4-1.963v3.927l1.353 1.353a.5.5 0 0 1-.707.708l-.647-.647V15.5a.5.5 0 0 1-.5.5z"/></svg>');--icon-column-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M4.5 17.5a.5.5 0 0 1-1 0v-5a.5.5 0 0 1 1 0zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0z"/></svg>');--icon-donut-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.01 9.01 0 0 0 12 1.23M2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9 9 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.43 7.43 0 0 1 2.5 10M17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.45 7.45 0 0 1-3.692-.979l-1.093 1.093A8.96 8.96 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7z"/></svg>');--icon-bar-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1z"/></svg>');--icon-line-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="m1 8 3-3 7 5 8-8v2l-8 8-7-5-3 3z"/></svg>');--icon-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/><path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z"/></svg>');--icon-recalculate:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M9.478 4.022c2.402-.209 4.583 1.047 5.711 3.014l1.083-.095c-1.233-2.528-3.912-4.175-6.881-3.916-2.97.26-5.321 2.347-6.098 5.051l1.083-.095c.768-2.132 2.698-3.748 5.102-3.959M10.523 15.977c-2.403.211-4.585-1.047-5.712-3.013l-1.08.095c1.234 2.527 3.91 4.175 6.879 3.914 2.971-.259 5.32-2.347 6.095-5.05l-1.08.095c-.769 2.132-2.699 3.749-5.102 3.959"/><path d="m2.272 15.616 5.197-3-4.098-1.097zM17.728 4.384l-5.197 3 4.098 1.098z"/></svg>');--icon-check:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/></svg>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm15 2h-4v3h4zm0 4h-4v3h4zm0 4h-4v3h3a1 1 0 0 0 1-1zm-5 3v-3H6v3zm-5 0v-3H1v2a1 1 0 0 0 1 1zm-4-4h4V8H1zm0-4h4V4H1zm5-3v3h4V4zm4 4H6v3h4z"/></svg>')}.treb-main.treb-main .treb-layout-header{overflow:hidden;overflow-x:scroll;position:relative;-ms-overflow-style:none;scrollbar-width:none}.treb-main.treb-main .treb-layout-header::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-toolbar{color:var(--treb-toolbar-color,var(--treb-ui-color,#333));display:flex;flex-direction:row;font-size:var(--treb-toolbar-font-size,inherit);gap:.5rem}.treb-main.treb-main .treb-toolbar>div{display:flex;flex-direction:row}.treb-main.treb-main .treb-toolbar>div>input,.treb-main.treb-main .treb-toolbar>input{background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:32px;overflow:hidden;padding-left:.5em;padding-right:.5em;text-overflow:ellipsis}.treb-main.treb-main .treb-toolbar>.treb-menu>button{border-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu+button,.treb-main.treb-main .treb-toolbar>.group>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>button+button,.treb-main.treb-main .treb-toolbar>.group>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>input+button,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu+button,.treb-main.treb-main .treb-toolbar>[composite]>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>button+button,.treb-main.treb-main .treb-toolbar>[composite]>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>input+button{border-left-width:0}.treb-main.treb-main .treb-toolbar>.group>button:first-child,.treb-main.treb-main .treb-toolbar>.group>input:first-child,.treb-main.treb-main .treb-toolbar>[composite]>button:first-child,.treb-main.treb-main .treb-toolbar>[composite]>input:first-child{border-bottom-left-radius:3px;border-top-left-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>.group>button:last-child,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>[composite]>button:last-child{border-bottom-right-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button,.treb-main.treb-main .treb-toolbar .treb-menu>button,.treb-main.treb-main .treb-toolbar button[data-icon],.treb-main.treb-main .treb-toolbar>button,.treb-main.treb-main .treb-toolbar>div>button{align-items:center;background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));display:flex;flex-direction:column;height:32px;justify-content:center;position:relative;width:32px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown],.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown],.treb-main.treb-main .treb-toolbar button[data-icon][dropdown],.treb-main.treb-main .treb-toolbar>button[dropdown],.treb-main.treb-main .treb-toolbar>div>button[dropdown]{width:16px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown]:after,.treb-main.treb-main .treb-toolbar button[data-icon][dropdown]:after,.treb-main.treb-main .treb-toolbar>button[dropdown]:after,.treb-main.treb-main .treb-toolbar>div>button[dropdown]:after{border:5px solid transparent;border-top-color:currentcolor;box-sizing:content-box;content:"";height:0;left:50%;position:absolute;top:18px;transform:translate(-50%,-50%);width:0}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button:hover,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[active],.treb-main.treb-main .treb-toolbar .treb-menu>button:hover,.treb-main.treb-main .treb-toolbar .treb-menu>button[active],.treb-main.treb-main .treb-toolbar button[data-icon]:hover,.treb-main.treb-main .treb-toolbar button[data-icon][active],.treb-main.treb-main .treb-toolbar>button:hover,.treb-main.treb-main .treb-toolbar>button[active],.treb-main.treb-main .treb-toolbar>div>button:hover,.treb-main.treb-main .treb-toolbar>div>button[active]{background-color:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar button[data-icon][data-color-bar]:after,.treb-main.treb-main .treb-toolbar>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar>div>button[data-color-bar]:after{background:var(--treb-color-bar-color,var(--treb-default-color,unset));border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));box-sizing:border-box;content:"";display:block;height:6px;position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon]:before,.treb-main.treb-main .treb-toolbar>button[data-command]:before,.treb-main.treb-main .treb-toolbar>button[data-icon]:before,.treb-main.treb-main .treb-toolbar>div>button[data-command]:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon]:before{background:currentColor;content:"";display:block;height:20px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:var(--icon-size,16px 16px);-webkit-mask-size:var(--icon-size,16px 16px);position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>div>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon].treb-font-stack:before{display:none}.treb-main.treb-main .treb-toolbar .treb-split{display:flex;flex-direction:column;gap:0}.treb-main.treb-main .treb-toolbar .treb-split button[data-command]{font-size:10px}.treb-main.treb-main .treb-toolbar .treb-split button[data-command]:before{display:none}.treb-main.treb-main .treb-toolbar .treb-split>button{align-items:center;display:flex;height:16px;justify-content:center}.treb-main.treb-main .treb-toolbar .treb-split>button:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-split>button:last-child{border-bottom-left-radius:3px;border-bottom-right-radius:3px;border-top:0}.treb-main.treb-main .treb-toolbar .treb-font-stack{align-items:flex-start;overflow:hidden;width:8em}.treb-main.treb-main .treb-toolbar .treb-font-stack:before{display:none}.treb-main.treb-main .treb-toolbar .treb-menu{outline:none}.treb-main.treb-main .treb-toolbar .treb-menu>div{background:var(--treb-toolbar-button-background,#fff);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px;box-shadow:0 4px 6px -4px rgba(0,0,0,.4);display:none;flex-direction:column;margin-top:.5rem;position:fixed;top:48px;z-index:20}.treb-main.treb-main .treb-toolbar .treb-menu>div button{background:transparent;border:0;margin:3px 0;padding:.4rem 1rem;text-align:left;transition:background-color .125s ease;white-space:nowrap}.treb-main.treb-main .treb-toolbar .treb-menu>div button:hover{background:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-menu>div.treb-icon-buttons>.treb-menu>button,.treb-main.treb-main .treb-toolbar .treb-menu>div.treb-icon-buttons>button{padding:0}.treb-main.treb-main .treb-toolbar .treb-menu>div>[separator]{background:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:1px;margin:2px 0}.treb-main.treb-main .treb-toolbar .treb-menu.visible>div,.treb-main.treb-main .treb-toolbar .treb-menu:focus-within>div{display:flex}.treb-main.treb-main .treb-toolbar [data-icon=file-menu]{--icon:var(--icon-file-menu)}.treb-main.treb-main .treb-toolbar [data-command=justify-left]{--icon:var(--icon-text-align-left)}.treb-main.treb-main .treb-toolbar [data-command=justify-right]{--icon:var(--icon-text-align-right)}.treb-main.treb-main .treb-toolbar [data-command=justify-center]{--icon:var(--icon-text-align-center)}.treb-main.treb-main .treb-toolbar [data-command=indent]{--icon:var(--icon-text-indent)}.treb-main.treb-main .treb-toolbar [data-command=outdent]{--icon:var(--icon-text-outdent)}.treb-main.treb-main .treb-toolbar [data-command=align-top]{--icon:var(--icon-text-align-top)}.treb-main.treb-main .treb-toolbar [data-command=align-middle]{--icon:var(--icon-text-align-middle)}.treb-main.treb-main .treb-toolbar [data-command=align-bottom]{--icon:var(--icon-text-align-bottom)}.treb-main.treb-main .treb-toolbar [data-command=merge-cells]{--icon:var(--icon-merge-cells)}.treb-main.treb-main .treb-toolbar [data-command=unmerge-cells]{--icon:var(--icon-unmerge-cells)}.treb-main.treb-main .treb-toolbar [data-command=fill-color]{--icon:var(--icon-fill-color)}.treb-main.treb-main .treb-toolbar [data-command=text-color]{--icon:var(--icon-text-color)}.treb-main.treb-main .treb-toolbar [data-command=lock-cells]{--icon:var(--icon-lock)}.treb-main.treb-main .treb-toolbar [data-command=wrap-text]{--icon:var(--icon-wrap-text)}.treb-main.treb-main .treb-toolbar [data-icon=comment]{--icon:var(--icon-comment)}.treb-main.treb-main .treb-toolbar [data-icon=table]{--icon:var(--icon-table)}.treb-main.treb-main .treb-toolbar [data-icon=layout]{--icon:var(--icon-layout)}.treb-main.treb-main .treb-toolbar [data-command=freeze-panes]{--icon:var(--icon-freeze)}.treb-main.treb-main .treb-toolbar [data-command=insert-column-chart]{--icon:var(--icon-column-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-donut-chart]{--icon:var(--icon-donut-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-bar-chart]{--icon:var(--icon-bar-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-line-chart]{--icon:var(--icon-line-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-image]{--icon:var(--icon-image)}.treb-main.treb-main .treb-toolbar [data-command=border-bottom]{--icon:var(--icon-border-bottom)}.treb-main.treb-main .treb-toolbar [data-command=border-left]{--icon:var(--icon-border-left)}.treb-main.treb-main .treb-toolbar [data-command=border-right]{--icon:var(--icon-border-right)}.treb-main.treb-main .treb-toolbar [data-command=border-top]{--icon:var(--icon-border-top)}.treb-main.treb-main .treb-toolbar [data-command=border-outside]{--icon:var(--icon-border-outer)}.treb-main.treb-main .treb-toolbar [data-command=border-all]{--icon:var(--icon-border-all)}.treb-main.treb-main .treb-toolbar [data-command=border-none]{--icon:var(--icon-border-none)}.treb-main.treb-main .treb-toolbar [data-command=border-double-bottom]{--icon:var(--icon-border-double-bottom)}.treb-main.treb-main .treb-toolbar [data-icon=palette]{--icon:var(--icon-palette)}.treb-main.treb-main .treb-toolbar [data-command=recalculate]{--icon:var(--icon-recalculate);--icon-size:20px 20px}.treb-main.treb-main .treb-toolbar .treb-font-scale{width:4em}.treb-main.treb-main .treb-toolbar .treb-number-format{width:8em}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]{align-items:center;display:flex;justify-content:center;padding:0;width:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]>svg{pointer-events:none}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div{padding:.75rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div+div{padding-top:0}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child{align-items:center;display:flex;flex-direction:row;gap:.5rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child input{flex-grow:1;padding:0 .5rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child button,.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child input{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px;height:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch button,.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches button{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:2px;height:18px;margin:0;padding:0;width:18px}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch .treb-default-color:before,.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches .treb-default-color:before{background:currentColor;content:"";display:block;height:100%;mask-image:var(--icon-x);-webkit-mask-image:var(--icon-x);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:24px 24px;-webkit-mask-size:24px 24px;opacity:.7;position:relative;width:100%}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch{align-items:center;display:grid;gap:.5rem;grid-template-columns:auto 1fr}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches{display:grid;gap:.5rem;grid-template-columns:repeat(10,1fr)}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));font:inherit;height:10rem;line-height:1.5;margin:.5rem;padding:.25rem;resize:both}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea+div{align-items:center;display:flex;flex-direction:row;gap:.5rem;justify-content:center;padding:0 0 .5rem}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea+div button{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px}.treb-main.treb-main .treb-toolbar .treb-font-scale{padding-left:2em;text-align:right;width:5em}.treb-main.treb-main .treb-toolbar [composite][font-scale]{position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon{border-radius:3px;left:.5em;line-height:1;opacity:.9;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after,.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{content:"A";position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{font-size:1.2em}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after{font-size:.9em;left:-.125em}.treb-main.treb-main{--treb-font-stack-default-size:14px;--treb-font-stack-calibri-size:16px;--treb-font-stack-tscu-comic-size:16px;--treb-font-stack-helvetica-neue-size:13px;--treb-font-stack-cambria-size:16px;--treb-font-stack-sitka-text-variant:lining-nums tabular-nums}.treb-main.treb-main.treb-ua-osx{--treb-font-stack-system-ui-size:10pt}.treb-main.treb-main .treb-font-stack-default{font-family:calibri,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif"}.treb-main.treb-main .treb-font-stack-transitional{font-family:Charter,Bitstream Charter,Cambria,serif}.treb-main.treb-main .treb-font-stack-old-style{font-family:Iowan Old Style,Palatino Linotype,URW Palladio L,P052,serif}.treb-main.treb-main .treb-font-stack-handwritten{font-family:Segoe Print,Bradley Hand,Chilanka,TSCu_Comic,casual,cursive}.treb-main.treb-main .treb-font-stack-industrial{font-family:Bahnschrift,DIN Alternate,Franklin Gothic Medium,Nimbus Sans Narrow,sans-serif-condensed,sans-serif}.treb-main.treb-main .treb-font-stack-monospace{font-family:ui-monospace,Cascadia Code,Source Code Pro,Menlo,Consolas,DejaVu Sans Mono,monospace}.treb-main.treb-main .treb-font-stack-ui{font-family:system-ui,sans-serif}.treb-main.treb-main{all:revert;box-sizing:border-box;color:inherit;color-scheme:var(--treb-color-scheme,unset);display:grid;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif");font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:14px;font-style:normal;font-weight:400;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr);height:100%;line-height:normal;position:relative;text-align:start;width:100%}.treb-main.treb-main a,.treb-main.treb-main button,.treb-main.treb-main div,.treb-main.treb-main input,.treb-main.treb-main li,.treb-main.treb-main ol,.treb-main.treb-main svg,.treb-main.treb-main textarea,.treb-main.treb-main ul{all:revert;box-sizing:border-box;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif")}.treb-main.treb-main button,.treb-main.treb-main input{color:inherit;font:inherit}.treb-main.treb-main *{box-sizing:border-box}.treb-main.treb-main [contenteditable]{-webkit-user-modify:read-write;-moz-user-modify:read-write}.treb-main.treb-main[animate] .treb-layout-header{transition:height var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-header{grid-column:1/3;grid-row:1;height:1px;opacity:0}.treb-main.treb-main[toolbar] .treb-layout-header{height:42px;opacity:1}.treb-main.treb-main[dialog] .treb-layout-header,.treb-main.treb-main[dialog]>*{opacity:.6}.treb-main.treb-main[dialog] .treb-dialog-mask{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-layout-spreadsheet{display:flex;flex-direction:row;gap:1em;grid-column:1;grid-row:2;position:relative;transition:opacity .2s ease;z-index:5}.treb-main.treb-main .treb-views.treb-can-revert .treb-view .treb-revert-indicator{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-view{display:grid;flex:1 1 0px;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;position:relative}.treb-main.treb-main .treb-view .treb-spreadsheet-backdrop{box-shadow:0 4px 6px -4px rgba(0,0,0,.4);grid-column:1;grid-row:2;z-index:2}.treb-main.treb-main .treb-view .treb-spreadsheet-body{position:relative;z-index:4}.treb-main.treb-main .treb-view .treb-spreadsheet-footer{position:relative;z-index:5}.treb-main.treb-main .treb-view .treb-layout-resize-handle,.treb-main.treb-main .treb-view .treb-revert-indicator{display:none}.treb-main.treb-main .treb-view:first-of-type .treb-revert-indicator{align-self:start;border-color:orange transparent transparent orange;border-style:solid;border-width:.5em;display:block;grid-area:2/1/3/2;height:1rem;justify-self:start;opacity:0;overflow:hidden;pointer-events:none;position:relative;transition:opacity .125s ease;width:1rem;z-index:20}.treb-main.treb-main .treb-view:last-of-type .treb-layout-resize-handle{align-self:end;border-bottom:.5rem solid var(--treb-resize-handle-color,#0059b9);border-left:.5rem solid transparent;border-right:.5rem solid var(--treb-resize-handle-color,#0059b9);border-top:.5rem solid transparent;cursor:nw-resize;display:block;grid-area:2/1/3/2;height:1rem;justify-self:end;width:1rem;z-index:20}.treb-main.treb-main[animate] .treb-layout-sidebar{transition:width var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-sidebar{align-items:center;display:flex;flex-direction:column;gap:.75rem;grid-column:2;grid-row:2;justify-content:flex-start;overflow:hidden;padding-top:3rem;width:2.5rem;width:3rem}.treb-main.treb-main[collapsed] .treb-layout-sidebar{opacity:0;width:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button{background:var(--treb-toolbar-button-background,#fff);border-bottom-right-radius:0;border-color:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-right-color:var(--treb-toolbar-button-background,transparent);border-top-right-radius:0;right:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button:after{mask-image:var(--icon-chevron-left);-webkit-mask-image:var(--icon-chevron-left)}.treb-main.treb-main .treb-layout-sidebar>button,.treb-main.treb-main .treb-toggle-sidebar-button{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-layout-sidebar>button:after,.treb-main.treb-main .treb-toggle-sidebar-button:after{background:#ccc;content:"";display:block;height:24px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;transition:background-color .1s ease;width:24px}.treb-main.treb-main .treb-layout-sidebar>button[data-can-revert=false],.treb-main.treb-main .treb-toggle-sidebar-button[data-can-revert=false]{display:none}.treb-main.treb-main .treb-layout-sidebar>button:hover:after,.treb-main.treb-main .treb-toggle-sidebar-button:hover:after{background:#666}.treb-main.treb-main .treb-layout-sidebar>button[data-command=recalculate],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=recalculate]{--icon:var(--icon-reset)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=toggle-toolbar],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=toggle-toolbar]{--icon:var(--icon-toolbar)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=revert],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=revert]{--icon:var(--icon-revert)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=export-xlsx],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=export-xlsx]{--icon:var(--icon-export)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=about],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=about]{--icon:var(--icon-about)}.treb-main.treb-main .treb-toggle-sidebar-button{align-items:center;background:transparent;border:1px solid transparent;border-radius:12px;bottom:6rem;display:flex;height:24px;justify-content:center;margin:0;padding:0;position:absolute;right:.5rem;right:calc(1.5rem - 12px);width:24px;z-index:39}.treb-main.treb-main .treb-toggle-sidebar-button:after{height:12px;mask-image:var(--icon-chevron-right);-webkit-mask-image:var(--icon-chevron-right);width:12px}.treb-main.treb-main .treb-resize-rect{border:1px dotted var(--treb-resize-frame-color,blue);display:block;height:100%;left:0;position:fixed;top:0;width:100%;z-index:9998}.treb-main.treb-main .treb-resize-mask{height:100vh;left:0;position:fixed;top:0;width:100vw;z-index:9999}treb-spreadsheet{display:block;overflow:hidden;position:relative}.treb-default-size{height:550px;width:800px}`;var gn='<div class="treb-main treb-theme"><div class="treb-layout-header treb-animate"><div class="treb-toolbar"></div></div><div class="treb-dialog-mask"><div data-bind="dialog" class="treb-embed-dialog"><div data-bind="left"><a href="https://treb.app" target="_blank"><div class="treb-icon-64"></div></a></div><div data-bind="middle"><div data-bind="title" class="treb-embed-dialog-title"></div><div data-bind="message" class="treb-embed-dialog-message"></div><div data-bind="about" class="treb-embed-dialog-body"></div></div><button type="button" data-title="close_dialog" data-bind="close" class="treb-close-box"><svg viewBox="0 0 16 16"><path d="M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"/><path d="M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"/></svg></button></div></div><div class="treb-layout-spreadsheet treb-views"><template class="treb-view-template"><div class="treb-view"><div class="treb-formula-bar notranslate" hidden><div class="treb-address-label"><div></div></div><button class="treb-insert-function-button" data-title="insert_function" data-conditional="insert-function">\u{1D453}<small>(x)</small></button><div class="treb-editor-container"><div contenteditable="true"></div></div></div><div class="treb-spreadsheet-backdrop"></div><div class="treb-spreadsheet-body" role="grid"><div class="treb-grid" tabindex="-1"><div class="treb-overlay-container notranslate" translate="no"><div class="treb-overlay-inset"><div class="treb-overlay-editor" contenteditable tabindex="-1" spellcheck="true" role="gridcell"></div></div></div></div></div><div class="treb-spreadsheet-footer" hidden><button class="treb-delete-tab" data-title="delete_sheet" data-command="delete-tab" data-conditional="delete-tab"><svg tabindex="-1" viewbox="0 0 16 16"><path d="M4,4 L12,12 M12,4 L4,12"/></svg></button><div class="treb-spreadsheet-tab-container"><ol class="treb-spreadsheet-tabs" role="tablist"></ol></div><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" data-title="add_sheet">+</button><div class="treb-stats-panel"></div><div class="treb-scale-control" data-conditional="scale-control"></div></div><div class="treb-layout-resize-handle" data-conditional="resize"></div><div class="treb-revert-indicator" data-command="revert-indicator" data-title="document_modified"></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" data-title="recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" data-title="toggle_toolbar"></button> <button data-command="export-xlsx" data-conditional="export" data-title="export"></button> <button data-command="revert" data-conditional="revert" data-title="revert"></button> <button data-command="about" data-title="about"></button></div><button class="treb-toggle-sidebar-button" data-title="toggle_sidebar"></button></div>';var vn='<div class="treb-menu" title="File menu" file-menu><button data-icon="file-menu" menu-target></button><div><button data-command="reset">New document</button><div separator></div><button data-command="import-file">Open file...</button> <button data-command="save-json">Save JSON</button><div separator xlsx-support></div><button data-command="export-xlsx" xlsx-support>Export XLSX</button></div></div><div composite narrow><button data-command="justify-left" data-target="justify" title="Left-align text"></button><div class="treb-menu"><button dropdown title="Text justify options"></button><div class="treb-icon-buttons" data-replace="justify"><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div></div></div><div composite narrow><button data-command="align-top" data-target="align" title="Align to top"></button><div class="treb-menu"><button dropdown title="Text align options"></button><div class="treb-icon-buttons" data-replace="align"><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div></div></div><div class="group" wide><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div><div class="group" wide><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div><div class="group" wide indent-group><button data-command="outdent" title="Decrease indent"></button> <button data-command="indent" title="Incrase indent"></button></div><div class="group"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-inactive-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-inactive-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-inactive-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-inactive-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-inactive-title="Comment" data-active-title="Update comment"></button><div class="treb-comment-box"><textarea></textarea><div><button data-command="clear-comment">Clear</button> <button data-command="update-comment">Save</button></div></div></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown title="Border options"></button><div class="treb-icon-buttons" data-replace="border"><button data-command="border-top" title="Top border"></button> <button data-command="border-left" title="Left border"></button> <button data-command="border-right" title="Right border"></button> <button data-command="border-bottom" title="Bottom border"></button> <button data-command="border-double-bottom" title="Double bottom border"></button> <button data-command="border-outside" title="Outside borders"></button> <button data-command="border-all" title="All borders"></button> <button data-command="border-none" title="Clear borders"></button><div separator></div><div class="treb-menu treb-color-menu treb-submenu" data-color-command="border-color" data-replace-color="border" title="Border color" data-default-color-text="Default border color"><button data-icon="palette" data-color-bar="border" data-color="{}"></button></div></div></div></div><div composite><button data-command="fill-color" data-color-bar="fill" data-color="{}" title="Fill color"></button><div class="treb-menu treb-color-menu" data-color-command="fill-color" data-replace-color="fill" data-default-color-text="No fill"><button dropdown title="Color options"></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></div><div class="treb-caption">No color</div><div class="treb-default-swatch"><button class="treb-default-color" data-command="set-color" data-color="{}"></button> <span class="treb-default-color-label" data-command="set-color" data-color="{}">...</span></div><div class="treb-caption">Other colors</div><div class="treb-swatches"></div><div><input placeholder="New color" class="treb-color-input"> <button data-command="set-color" data-color=""><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg></button></div></div></div></div><div composite><button data-command="text-color" data-color-bar="text" data-color="{}" title="Text color"></button><div class="treb-menu treb-color-menu" data-color-command="text-color" data-replace-color="text" data-default-color-text="Default text color"><button dropdown title="Color options"></button></div></div><div composite font-scale><div class="treb-font-scale-icon"></div><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown title="Font scale options"></button><div><button data-command="font-scale" data-scale="0.8">0.80</button> <button data-command="font-scale" data-scale="0.9">0.90</button> <button data-command="font-scale" data-scale="1.0">1.00</button> <button data-command="font-scale" data-scale="1.1">1.10</button> <button data-command="font-scale" data-scale="1.25">1.25</button> <button data-command="font-scale" data-scale="1.5">1.50</button> <button data-command="font-scale" data-scale="2.0">2.00</button></div></div></div><div composite font-stack><button class="treb-font-stack" data-command="font-stack" data-font-stack="" title="Font stack"></button><div class="treb-menu"><button dropdown title="Font stack options"></button><div><button data-command="font-stack" data-font-stack="default"></button> <button data-command="font-stack" data-font-stack="transitional"></button> <button data-command="font-stack" data-font-stack="monospace"></button> <button data-command="font-stack" data-font-stack="handwritten"></button> <button data-command="font-stack" data-font-stack="ui"></button></div></div></div><div composite><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown title="Number formats"></button><div class="treb-number-format-menu"></div></div></div><div class="treb-split"><button data-command="decrease-precision" title="Decrease precision"></button> <button data-command="increase-precision" title="Increase precision"></button></div><div class="treb-menu"><button data-icon="layout" title="Rows & columns"></button><div><button data-command="insert-row">Insert row</button> <button data-command="insert-column">Insert column</button> <button data-command="delete-row">Delete row</button> <button data-command="delete-column">Delete column</button><div separator add-remove-sheet></div><button data-command="insert-sheet" add-remove-sheet>Add sheet</button> <button data-command="delete-sheet" add-remove-sheet>Delete sheet</button></div></div><div composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown title="Chart options"></button><div class="treb-icon-buttons" data-replace="annotation"><button data-command="insert-column-chart" title="Insert column chart"></button> <button data-command="insert-donut-chart" title="Insert donut chart"></button> <button data-command="insert-bar-chart" title="Insert bar chart"></button> <button data-command="insert-line-chart" title="Insert line chart"></button><div separator></div><button data-command="insert-image" title="Insert image"></button></div></div></div><button data-command="recalculate" title="Recalculate" recalculate-button></button>';var yn={close_dialog:"Close dialog",insert_function:"Insert function...",delete_sheet:"Delete current sheet",add_sheet:"Add sheet",document_modified:"This document has been modified from the original version.",recalculate:"Recalculate",toggle_toolbar:"Toggle toolbar",export:"Export as XLSX",revert:"Revert to original version",about:"What's this?",toggle_sidebar:"Toggle sidebar"},Ve=class{root;sheet;border_color;color_bar_elements={};replace_targets={};layout_element;views;revert_button;revert_state=!1;toolbar_controls={};swatch_lists={};DOM;constructor(e){typeof e=="string"&&(e=document.querySelector(e)),this.DOM=le.GetInstance(e?.ownerDocument),this.DOM.view&&e instanceof this.DOM.view.HTMLElement&&(this.root=e,this.DOM.doc?.head.querySelector("style[treb-stylesheet]")||this.DOM.doc?.head.prepend(this.DOM.Create("style",void 0,void 0,{text:fn,attrs:{"treb-stylesheet":""}})))}CoerceAttributeValue(e){if(e===null||e.toString().toLowerCase()==="true"||e==="")return!0;if(e.toLowerCase()==="false")return!1;{let t=Number(e);if(!isNaN(t))return t}return e||""}ParseOptionAttributes(){let e={};if(this.root){let t=this.root.getAttributeNames();for(let r of t){switch(r){case"class":case"style":case"id":continue;case"data-options":case"options":{let o=(this.root.getAttribute(r)||"").split(",");for(let i of o){let s=i.split(/=/);s.length===1?e[s[0]]=!0:e[s[0]]=this.CoerceAttributeValue(s[1])}}continue;case"data-treb":continue;case"inline-document":continue;case"src":e.document=this.root.getAttribute("src")||void 0;continue}e[r.replace(/-/g,"_")]=this.CoerceAttributeValue(this.root.getAttribute(r))}}return{...e}}AttachElement(e={}){if(e={...this.ParseOptionAttributes(),...e},this.root){if(!e.headless){let t=this.root.getBoundingClientRect();(!t.width||!t.height)&&this.root.classList.add("treb-default-size")}if(this.root.hasAttribute("inline-document")){let t=this.root.getAttribute("inline-document")||"";for(let r of Array.from(this.root.children))if(this.DOM.view&&r instanceof this.DOM.view.HTMLScriptElement&&r.type==="application/json"){let n=r.getAttribute("name")||"";if(n===t||!n&&t==="true"){let o=r.textContent;if(o)try{e.inline_document=JSON.parse(o)}catch(i){console.error(i)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=gn,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new dt(e),this.root&&this.CreateLayout(this.sheet,this.root)}CreateLayout(e,t){new ResizeObserver(()=>e.Resize()).observe(t),this.layout_element=t.querySelector(".treb-main");let n=t.querySelector(".treb-toggle-sidebar-button");if(n&&this.layout_element){let c=this.layout_element;n.addEventListener("click",()=>{let u=c.getAttribute("collapsed");typeof u=="string"&&(u===""||u==="true")?c.removeAttribute("collapsed"):c.setAttribute("collapsed","")})}(e.options.toolbar==="show"||e.options.toolbar==="show-narrow")&&this.layout_element?.setAttribute("toolbar",""),e.options.collapsed&&this.layout_element?.setAttribute("collapsed","");let o=t.querySelector("[data-command=revert-indicator]");this.DOM.view&&o instanceof this.DOM.view.HTMLElement&&(e.options.revert_indicator?o.addEventListener("click",()=>{e.HandleToolbarMessage({command:"revert-indicator"})}):o.style.display="none"),t.querySelector(".treb-layout-sidebar")?.addEventListener("click",c=>{let u=c.target;u.dataset.command&&(u.dataset.command==="toggle-toolbar"?this.ToggleToolbar():e.HandleToolbarMessage({command:u.dataset.command}))}),e.options.toolbar&&this.AttachToolbar(e,t);let s={"table-button":!!e.options.table_button,revert:!!e.options.revert_button,toolbar:!!e.options.toolbar,export:!!e.options.export,"insert-function":!!e.options.insert_function_button,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[c,u]of Object.entries(s))if(!u){let d=this.layout_element.querySelectorAll(`[data-conditional=${c}]`);for(let m of Array.from(d))m.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let c={width:0,height:0},u={x:0,y:0},d={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let m,b,p=t.querySelector(".treb-layout-resize-handle"),h=()=>y(),f=(x=>{x.buttons===0?y():(d.x=x.screenX-u.x,d.y=x.screenY-u.y,b&&(b.style.width=c.width+d.x+"px",b.style.height=c.height+d.y+"px"))}),y=()=>{if(d.x||d.y){let x=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=x.width+d.x+"px"),t.style.height=x.height+d.y+"px"}m&&(m.removeEventListener("mouseup",h),m.removeEventListener("mousemove",f),m.parentElement?.removeChild(m),m=void 0),b?.parentElement?.removeChild(b),b=void 0};p.addEventListener("mousedown",x=>{x.stopPropagation(),x.preventDefault();let v=t.querySelector(".treb-main");b=this.DOM.Div("treb-resize-rect",v),m=this.DOM.Div("treb-resize-mask",v,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:h,mousemove:f}}),u.x=x.screenX,u.y=x.screenY,d.x=0,d.y=0;let w=this.views?.querySelectorAll(".treb-spreadsheet-body"),g=Array.from(w||[]).map(C=>C.getBoundingClientRect());if(g.length){let C=JSON.parse(JSON.stringify(g.shift()));for(let L of g)C.top=Math.min(L.top,C.top),C.left=Math.min(L.left,C.left),C.right=Math.max(L.right,C.right),C.bottom=Math.max(L.bottom,C.bottom);let U=C.right-C.left,V=C.bottom-C.top;b.style.top=C.top+"px",b.style.left=C.left+"px",b.style.width=U+"px",b.style.height=V+"px",c.width=U,c.height=V}})}let l=Array.from(this.layout_element.querySelectorAll("[data-title]"));for(let c of l)if(c instanceof HTMLElement){if(c.dataset.activeTitle)continue;c.dataset.title&&yn[c.dataset.title]&&(c.title=yn[c.dataset.title])}setTimeout(()=>this.layout_element?.setAttribute("animate",""),250)}ToggleToolbar(){if(this.layout_element){let e=this.layout_element.getAttribute("toolbar");typeof e=="string"&&(e===""||e==="true")?this.layout_element.removeAttribute("toolbar"):this.layout_element.setAttribute("toolbar","")}}UpdateSelectionStyle(e,t,r){let n=e.selection_state;r.value="";for(let l of Object.values(this.toolbar_controls))l&&(l.removeAttribute("active"),l.dataset.inactiveTitle&&(l.title=l.dataset.inactiveTitle));let o=l=>{l&&(l.setAttribute("active",""),l.dataset.activeTitle&&(l.title=l.dataset.activeTitle))};if(n.comment&&(o(this.toolbar_controls.comment),r.value=n.comment),n.style?.locked&&o(this.toolbar_controls.locked),n.frozen&&o(this.toolbar_controls.freeze),n.style?.wrap&&o(this.toolbar_controls.wrap),this.toolbar_controls.table&&(n.table?(o(this.toolbar_controls.table),this.toolbar_controls.table.dataset.command="remove-table"):this.toolbar_controls.table.dataset.command="insert-table"),this.toolbar_controls.merge&&(n.merge?(o(this.toolbar_controls.merge),this.toolbar_controls.merge.dataset.command="unmerge-cells"):this.toolbar_controls.merge.dataset.command="merge-cells"),this.toolbar_controls.stack)if(n.style?.font_face)if(n.style.font_face.startsWith("stack:")){let l=n.style.font_face.substring(6);this.toolbar_controls.stack.textContent=Pe[l]||"",this.toolbar_controls.stack.dataset.fontStack=l}else this.toolbar_controls.stack.textContent="",this.toolbar_controls.stack.dataset.fontStack="";else this.toolbar_controls.stack.textContent=Pe.default||"",this.toolbar_controls.stack.dataset.fontStack="default";let i=this.toolbar_controls.format;i&&(n.style?.number_format?i.value=R.SymbolicName(n.style.number_format)||n.style.number_format:i.value="General");let s=this.toolbar_controls.scale;switch(s&&(s.value=e.FormatNumber(n.relative_font_size||1,"0.00")),n.style?.horizontal_align){case"left":o(this.toolbar_controls.left);break;case"center":o(this.toolbar_controls.center);break;case"right":o(this.toolbar_controls.right);break}switch(n.style?.vertical_align){case"top":o(this.toolbar_controls.top);break;case"middle":o(this.toolbar_controls.middle);break;case"bottom":o(this.toolbar_controls.bottom);break}}UpdateDocumentStyles(e,t){{let s=this.DOM.Fragment(),l=e.document_styles.theme_colors.length,c=["Background","Text","Background","Text","Accent"];if(l){let b=e.document_styles.theme_colors[0].length;for(let p=0;p<b;p++)for(let h=0;h<l;h++){let f=e.document_styles.theme_colors[h][p],y=`background: ${f.resolved};`,x=c[h]||c[4];er(f.color)&&f.color.tint?x+=` (${(f.color.tint>0?"+":"")+f.color.tint*100}%)`:h===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",f.resolved):h===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",f.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",f.resolved)),this.DOM.Create("button",void 0,s,{attrs:{style:y,title:x},data:{command:"set-color",color:JSON.stringify(f.color)}})}}this.swatch_lists.theme?.replaceChildren(s),s=this.DOM.Fragment();let u=["Black","White","Gray","Red","Orange","Yellow","Green","Blue","Indigo","Violet"],d=u.map(b=>b.toLowerCase()),m=e.document_styles.colors.filter(b=>!d.includes(b.toLowerCase()));for(let b of[...u,...m]){let p=`background: ${b.toLowerCase()};`;this.DOM.Create("button",void 0,s,{attrs:{style:p,title:b},data:{command:"set-color",color:JSON.stringify({text:b.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(s)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],n=["Timestamp","Long Date","Short Date"];for(let s of e.document_styles.number_formats){if(R.SymbolicName(R.Translate(s)))continue;R.Get(s).date_format?n.push(s):r.push(s)}let o=s=>this.DOM.Create("button",void 0,void 0,{text:s,data:{format:s,command:"number-format"}}),i=this.DOM.Fragment();i.append(...r.map(s=>o(s))),i.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),i.append(...n.map(s=>o(s))),t.textContent="",t.append(i)}UpdateRevertState(e){let t=e.can_revert;this.revert_state!==t&&(this.revert_state=t,(this.revert_button||e.options.revert_indicator)&&(this.revert_state?this.views?.classList.add("treb-can-revert"):this.views?.classList.remove("treb-can-revert"),this.revert_button&&(this.revert_button.dataset.canRevert=t?"true":"false",t?(this.revert_button.classList.remove("sidebar-disabled"),this.revert_button.title="Revert to original version"):(this.revert_button.classList.add("sidebar-disabled"),this.revert_button.title="This is the original version of the document"))))}ReplaceTemplate(e,t,r=!0){let n=e.querySelector(t);if(n&&n.parentElement){for(let o of Array.from(n.content.children))n.parentElement.insertBefore(o,n);r&&n.parentElement.removeChild(n)}else console.warn("template not found",t)}AttachToolbar(e,t){let r=t.querySelector(".treb-layout-header"),n=t.querySelector(".treb-toolbar");n.innerHTML=vn;let o=[];if(e.options.toolbar==="narrow"||e.options.toolbar==="show-narrow"?o.push(...Array.from(n.querySelectorAll("[wide]"))):o.push(...Array.from(n.querySelectorAll("[narrow]"))),e.options.file_menu||o.push(n.querySelector("[file-menu]")),e.options.indent_buttons||o.push(n.querySelector("[indent-group]")),e.options.font_scale||o.push(n.querySelector("[font-scale]")),!e.options.font_stack)o.push(n.querySelector("[font-stack]"));else{let v=n.querySelectorAll("[font-stack] button[data-font-stack]");for(let w of v)if(w.dataset.fontStack){let g=Pe[w.dataset.fontStack];w.textContent=g||""}}e.options.chart_menu||o.push(n.querySelector("[chart-menu]")),e.options.freeze_button||o.push(n.querySelector("[freeze-button]")),e.options.table_button||o.push(n.querySelector("[table-button]")),!e.options.add_tab&&!e.options.delete_tab&&o.push(...Array.from(n.querySelectorAll("[add-remove-sheet]"))),e.options.toolbar_recalculate_button||o.push(n.querySelector("[recalculate-button]"));for(let v of o)v&&v.parentElement?.removeChild(v);let i=n.querySelector(".treb-color-chooser"),s=n.querySelector(".treb-comment-box textarea");for(let[v,w]of Object.entries({top:"[wide] [data-command=align-top]",middle:"[wide] [data-command=align-middle]",bottom:"[wide] [data-command=align-bottom]",left:"[wide] [data-command=justify-left]",right:"[wide] [data-command=justify-right]",center:"[wide] [data-command=justify-center]",wrap:"[data-command=wrap-text]",merge:"[data-id=merge]",comment:"[data-icon=comment]",locked:"[data-command=lock-cells]",freeze:"[data-command=freeze-panes]",table:"[data-icon=table]",format:"input.treb-number-format",scale:"input.treb-font-scale",stack:"button.treb-font-stack"})){let g=n.querySelector(w);g&&(this.toolbar_controls[v]=g)}let l=i.querySelectorAll(".treb-swatches");this.swatch_lists={theme:l[0],other:l[1]};let c=t.querySelector("[data-command=increase-precision");c&&(c.textContent=this.sheet?.FormatNumber(0,"0.00")||""),c=t.querySelector("[data-command=decrease-precision"),c&&(c.textContent=this.sheet?.FormatNumber(0,"0.0")||""),c=n.querySelector("[data-command=update-comment]"),s.addEventListener("keydown",v=>{v.key==="Enter"&&(v.shiftKey||v.ctrlKey)&&c.click()});for(let v of["border","annotation","align","justify"])this.replace_targets[v]=n.querySelector(`[data-target=${v}`);for(let v of["fill","text","border"])this.color_bar_elements[v]=n.querySelector(`[data-color-bar=${v}]`);n.addEventListener("click",v=>{let w=v.target,g={format:w.dataset.format,scale:w.dataset.scale,font_stack:w.dataset.fontStack},C=w?.dataset.command;if(C){let U=w.parentElement?.dataset.replace;if(U){let V=this.replace_targets[U];V&&(V.dataset.command=C,V.title=w.title||"")}switch(/^border-/.test(C)&&(g.color=this.border_color||{}),C){case"text-color":case"fill-color":g.color={};try{g.color=JSON.parse(w.dataset.color||"{}")}catch(V){console.error(V)}break;case"set-color":C=i.dataset.colorCommand||"",g.color={};try{g.color=JSON.parse(w.dataset.color||"{}")}catch(V){console.error(V)}if(C==="border-color"&&(this.border_color=g.color),i.dataset.target){let V=this.color_bar_elements[i.dataset.target];V&&(V.style.setProperty("--treb-color-bar-color",w.style.backgroundColor),V.dataset.color=w.dataset.color||"{}")}break;case"update-comment":g.comment=s.value;break}e.HandleToolbarMessage({command:C,...g})}});let u=(v,w)=>{let g=n.querySelector(v);if(g){let C="";g.addEventListener("focusin",()=>C=g.value),g.addEventListener("keydown",U=>{switch(U.key){case"Escape":g.value=C,e.Focus();break;case"Enter":w(g.value)||(g.value=C,e.Focus());break;default:return}U.stopPropagation(),U.preventDefault()})}};u("input.treb-number-format",v=>v?(e.HandleToolbarMessage({command:"number-format",format:v}),!0):!1),u("input.treb-font-scale",v=>{let w=Number(v);return!w||isNaN(w)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:w}),!0)});let d=i.querySelector("input"),m=i.querySelector("input + button");d.addEventListener("input",v=>{if(v instanceof InputEvent&&v.isComposing)return;m.style.background=d.value||"";let w=m.style.backgroundColor||"#fff",g=nr.MeasureColor(w),C=tr.RGBToHSL(g[0],g[1],g[2]);m.style.color=C.l>.5?"#000":"#fff",m.dataset.color=JSON.stringify(m.style.backgroundColor?{text:m.style.backgroundColor}:{})}),d.addEventListener("keydown",v=>{v.key==="Enter"&&(v.stopPropagation(),v.preventDefault(),m.click())}),/firefox/i.test(navigator.userAgent)?r.addEventListener("scroll",()=>{this.DOM.view&&this.DOM.doc?.activeElement instanceof this.DOM.view.HTMLElement&&this.DOM.doc.activeElement?.blur()}):r.addEventListener("scroll",()=>e.Focus());let b=!1,p=v=>{v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),Promise.resolve().then(()=>e.Focus()))},h=v=>{if(b){if(v.relatedTarget instanceof Node&&n.contains(v.relatedTarget))return;n.removeEventListener("keydown",p),n.removeEventListener("focusout",h),b=!1}},f=v=>{let w=v.target,g=w?.parentElement;if(w?.classList.contains("treb-menu")){g=w;for(let C of Array.from(g.children))if(C.tagName==="BUTTON"){w=C;break}}else if(!g?.classList.contains("treb-menu"))return;if(w&&g){if(b||(n.addEventListener("focusout",h),n.addEventListener("keydown",p),b=!0),g.dataset.colorCommand){i.querySelector(".treb-default-color")?.setAttribute("title",g.dataset.defaultColorText||"Default color");let j=i.querySelector(".treb-default-color-label");j&&(j.textContent=g.dataset.defaultColorText||"Default color"),g.appendChild(i),i.dataset.colorCommand=g.dataset.colorCommand,i.dataset.target=g.dataset.replaceColor||""}let C=g.querySelector("div"),U=r.getBoundingClientRect(),V=w.getBoundingClientRect(),{left:L}=V,M=g.parentElement;M?.hasAttribute("composite")&&(L=M.firstElementChild.getBoundingClientRect().left);let A=C.getBoundingClientRect();g.classList.contains("treb-submenu")?(C.style.top=V.top-A.height/2+"px",L+V.width+6+A.width>U.right?C.style.left=L-6-A.width+"px":C.style.left=L+V.width+6+"px"):(C.style.top=V.bottom+"px",L+A.width>U.right-6?C.style.left=V.right-A.width+"px":C.style.left=L+"px");let G=C.querySelector("textarea");G&&requestAnimationFrame(()=>G.focus())}},y=this.root?.querySelector(".treb-number-format-menu");y&&(this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s),e.Subscribe(v=>{switch(v.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s),this.UpdateRevertState(e);break;case"theme-change":this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s);break;case"annotation-selection":case"selection":this.UpdateSelectionStyle(e,n,s);break}}));let x=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(n.addEventListener("focusin",v=>{f(v)}),x){let v=Array.from(n.querySelectorAll(".treb-menu"));for(let w of v)w.tabIndex=0;n.addEventListener("mousedown",w=>{f(w)})}}};var mt=class{version="36.1.2";CreateSpreadsheet(e){let t=e.container,r=new Ve(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},aa=new mt;if(typeof HTMLElement<"u"){class a extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new Ve(this)}connectedCallback(){this.instance.AttachElement()}}typeof customElements<"u"&&(customElements.get("treb-spreadsheet")?console.info("custom element treb-spreadsheet is already defined."):customElements.define("treb-spreadsheet",a))}export{aa as TREB,mt as TREBGlobal};
7
+ `)}SaveLocalFile(e="treb.json",t={}){this.SaveToDesktop(e,t)}SaveToDesktop(e="treb.json",t={}){let r=this.grid.model.document_name||"document",n,o,i=e.split(/\./).filter(l=>l.trim().length),s=i.length?i[i.length-1].toLowerCase():"treb";if(i.length<=1||e==="treb.json")if(e==="treb.json"&&(s=e),(s==="csv"||s==="tsv")&&this.grid.model.sheets.length>1){let l=this.grid.active_sheet.name;e=(r+"-"+l).toLowerCase().replace(/\W+/g,"-")+"."+s}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+s;switch(s){case"csv":o=this.ExportDelimited({delimiter:","});break;case"tsv":o=this.ExportDelimited({delimiter:" "});break;case"treb":case"json":case"treb.json":n=this.SerializeDocument({...t}),o=JSON.stringify(n,void 0,t.pretty?2:void 0),this.last_save_version=this.file_version;break;default:throw new Error("invalid file type")}if(o&&e){let l=new Blob([o],{type:"text/plain;charset=utf-8"});this.SaveAs(l,e)}}LoadCSV(e,t){if(this.parent_view)return this.parent_view.LoadCSV(e,t);this.grid.FromCSV(e),this.ResetInternal(),this.grid.Update(!0),this.Publish({type:"load",source:t}),this.UpdateDocumentStyles()}ScrollOffset(e){return this.grid.ScrollOffset(e)}LoadDocument(e,t={}){if(this.parent_view)return this.parent_view.LoadDocument(e,t);if(this.initial_load_source||(this.initial_load_source=t.source),t={flush:!0,recalculate:!1,...t},t.override_selection&&e.sheet_data){let r=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let n of r)if(n.id===t.override_selection.target.sheet_id){n.selection=t.override_selection;break}}if(this.ImportDocumentData(e,t.override_sheet),this.calculator.Reset(),e.rendered_values&&!t.recalculate?(this.calculator.RebuildClean(!0),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update()):this.Recalculate(),this.InflateAnnotations(),t.flush&&this.FlushUndo(),this.Publish({type:"load",source:t.source,path:t.path}),this.UpdateDocumentStyles(),this.loaded=!0,t.scroll){let r=t.scroll;Promise.resolve().then(()=>this.ScrollTo(r))}}SetNote(e,t){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}this.grid.SetNote(e,t)}SetValidation(e,t,r){if(typeof e=="string"){let n=this.model.ResolveAddress(e,this.grid.active_sheet);e=bt(n)?new z(n.start,n.end):new z(n)}if(K(e)&&(e=new z(e)),typeof t>"u"||Array.isArray(t))this.grid.SetValidation(e,t,r);else{let n=this.model.ResolveArea(t,this.grid.active_sheet);this.grid.SetValidation(e,n,r)}}RemoveFunction(e){let t=e.toUpperCase();this.model.macro_functions.delete(t),this.UpdateAC()}DefineFunction(e,t="",r="0"){if(!e.length||/^[^A-Za-z]/.test(e)||/[^\w_.]/.test(e))throw new Error("invalid function name");typeof t=="string"&&(t=t?t.split(this.parser.argument_separator).map(n=>n.trim()):[]);for(let n of t)if(!n.length||/^[^A-Za-z]/.test(n)||/[^\w_.]/.test(n))throw new Error("invalid argument name");this.RemoveFunction(e),this.grid.model.macro_functions.set(e.toUpperCase(),{name:e,function_def:r,argument_names:t,expression:this.parser.Parse(r).expression}),this.UpdateAC()}SerializeDocument(e={}){e={share_resources:!0,shrink:!0,...e};let t=this.Serialize(e),r={app:"@trebco/treb",version:"36.1.4",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:ee.decimal_separator,...t};if(e.share_resources){let n=1,o=new Map,i=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],s=c=>{let u=o.get(c);return u||(u=(n++).toString(),o.set(c,u)),`resource:${u}`};for(let c of i)if(c){c.background_image&&(c.background_image=s(c.background_image));for(let u of c.annotations||[])u.type==="image"&&u.data?.src&&(u.data.src=s(u.data.src))}let l={};for(let[c,u]of o.entries())l[u]=c;r.shared_resources=l}return e.rendered_values&&(r.rendered_values=!0),r}Recalculate(e){let t;switch(e?.type){case"data":t=e.area;break;case"composite":t=e.data_area;break}this.calculator.Calculate(t),this.calculator.grid_expanded&&!this.grid.headless&&this.grid.UpdateLayout(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0),this.UpdateAnnotations(),this.Publish({type:"data"}),this.grid.UpdateStats()}SaveLocalStorage(e=this.options.local_storage){if(!e){console.warn("not saving, no key");return}let t=JSON.stringify(this.SerializeDocument({rendered_values:!0,expand_arrays:!0}));localStorage.setItem(e,t)}Undo(){if(this.parent_view)return this.parent_view.Undo();if(this.undo_pointer<=1)return console.warn("nothing to undo"),!1;let e=this.undo_stack[--this.undo_pointer-1],t=e.selection?JSON.parse(e.selection):void 0;return this.LoadDocument(JSON.parse(e.data),{flush:!1,override_selection:t,source:"undo"}),!0}About(){this.dialog?.ShowDialog({type:"about"})}ScrollIntoView(e,t=!1){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}this.grid.ScrollIntoView(e,t)}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}t={x:!0,y:!0,smooth:!1,...t},this.grid.ScrollTo(e,t.x,t.y,t.smooth)}Resolve(e,t){let r=this.model.ResolveAddress(e,this.grid.active_sheet,t);return K(r)?r.sheet_id?r:void 0:r.start.sheet_id?r:void 0}Unresolve(e,t=!0,r=!0){if(typeof e=="string"){let n=this.Resolve(e);if(!n)throw new Error("invalid reference");e=n}return this.calculator.Unresolve(e,this.grid.active_sheet,t,r)}Evaluate(e,t={}){return this.calculator.Evaluate(e,this.grid.active_sheet,t)}GetSelection(e=!0){let t=this.grid.GetSelection();if(t.empty)return"";let r="";if(t.area.count>1?r=z.CellAddressToLabel(t.area.start)+":"+z.CellAddressToLabel(t.area.end):r=z.CellAddressToLabel(t.area.start),!e)return r;let n=t.area.start.sheet_id||this.grid.active_sheet.id,o=this.calculator.ResolveSheetName(n,!0);return o?o+"!"+r:r}ParseNumber(e){return we.TryParse(e).value}FormatNumber(e,t="General"){return X(e)?Re.FormatPartsAsText(R.Get(t).FormatComplex(e)):R.Get(t).Format(e)}SpreadsheetDate(e){return e instanceof Date&&(e=e.getTime()),ae(e,!0)}JavascriptDate(e){return fe(e).getTime()}ApplyBorders(e,t,r=1){this.grid.ApplyBorders2(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,{},r)}ApplyStyle(e,t={},r=!0){this.grid.ApplyStyle(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,r)}ClearName(e){this.grid.SetName(e)}ListNames(){return this.model.SerializeNames()}DefineName(e,t,r,n=!1){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof r=="string"){let o=this.model.sheets.ID(r);if(typeof o=="number")r=o;else throw new Error("invalid scope; use a sheet name or sheet id")}if(typeof t=="object"&&(K(t)||bt(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet),void 0,r,n);return}if(typeof t=="string"){let o=this.parser.Parse(t);if(!o.expression)throw new Error("invalid expression");switch(o.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(o.expression,this.grid.active_sheet),void 0,r,n);return}this.grid.SetName(e,void 0,t,r,n)}else this.grid.SetName(e,void 0,t.toString(),r,n)}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=K(r)?r:r.start}if(!e){let r=this.GetSelectionReference();if(r.empty)return;e=r.target}this.grid.SetLink(e,t)}Select(e){let t;e&&(t=this.model.ResolveArea(e,this.grid.active_sheet),t.start.sheet_id&&t.start.sheet_id!==this.grid.active_sheet.id&&this.grid.ActivateSheetID(t.start.sheet_id)),this.grid.SelectRange(t)}Paste(e,...t){let r=a.clipboard,n={};switch(t.length){case 1:Array.isArray(t[0])?r=t[0]:typeof t[0]=="object"&&(n=t[0]);break;case 2:t[0]&&Array.isArray(t[0])&&(r=t[0]),t[1]&&typeof t[1]=="object"&&(n=t[1]);break}if(!r)throw new Error("no clipboad data");this.grid.PasteArea(this.RangeOrSelection(e,"no range and no selection"),r,n)}Copy(e){let t=this.RangeOrSelection(e),r=t?this.grid.CopyArea(t,"copy"):[];return a.clipboard=structuredClone(r),r}Cut(e){let t=this.RangeOrSelection(e),r=t?this.grid.CopyArea(t,"cut"):[];return a.clipboard=structuredClone(r),r}GetRange(e,t={}){let r=this.RangeOrSelection(e);if(!r)return;let n=t.type;return n||(t.formatted&&(n="formatted"),t.formula&&(n="A1")),n==="formula"&&(n="A1"),this.grid.GetRange(r,n)}GetStyle(e,t=!1){let r=this.RangeOrSelection(e);if(r)return this.grid.GetRangeStyle(r,t)}SetRange(e,t=void 0,r={}){let n=this.RangeOrSelection(e);if(n){if(r.spill&&Array.isArray(t)){let o=t.length,i=Math.max(0,...t.map(l=>l.length)),s={row:n.start.row+o+1,column:n.start.column+i+1};n.ConsumeAddress(s)}return this.grid.SetRange(n,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}RangeOrSelection(e,t){if(!e){let r=this.GetSelectionReference();if(r.empty){if(t)throw t;return}else return r.area.Clone()}return this.model.ResolveArea(e,this.grid.active_sheet)}Serialize(e={}){let t=this.grid.active_sheet;t.selection=JSON.parse(JSON.stringify(this.grid.GetSelection()));let r=this.grid.ScrollOffset();r&&(t.scroll_offset=r);let n=this.model.sheets.list.map(l=>l.toJSON(e)),o;this.model.tables.size>0&&(o=Array.from(this.model.tables.values()));let i;if(this.model.macro_functions.size){i=[];for(let l of this.model.macro_functions.values())i.push({...l,expression:void 0})}let s=this.model.SerializeNames(t);return{sheet_data:n,active_sheet:t.id,named:s.length?s:void 0,macro_functions:i,tables:o}}ApplyConditionalFormats(e,t){let r=[];if(e.conditional_formats.length||e.flush_conditional_formats){for(let n of e.conditional_formats)switch(r.push(n.area),n.type){case"gradient":n.internal||(n.internal={}),n.internal.gradient||(n.internal.gradient=new sr(n.stops,this.grid.theme,n.color_space));break;case"data-bar":n.internal||(n.internal={});break}e.ApplyConditionalFormats()}t&&this.grid.Update(!0,r)}ResolveTable(e){let t;if(typeof e=="string"){let r=e.toLowerCase();this.model.tables.has(r)&&(t=this.model.tables.get(r))}if(!t){let r=this.model.ResolveAddress(e,this.grid.active_sheet);K(r)||(r=r.start),t=this.grid.GetTableReference(r)}return t}SaveAs(e,t){let r=this.DOM.Create("a");r.href=URL.createObjectURL(e),r.download=t,r.click(),URL.revokeObjectURL(r.href)}Publish(e){this.events.Publish(e)}async ImportXLSX(e,t,r){return this.parent_view?this.parent_view.ImportXLSX(e,t):(this.export_worker||(this.export_worker=await this.LoadWorker()),new Promise((n,o)=>{this.export_worker?(this.dialog?.ShowDialog({message:"Importing XLSX..."}),this.export_worker.OnMessage(i=>{if(i.data){if(i.data.type==="import-error")return o(i.data.error||"unknown error");if(i.data.type!=="import-complete")return o("unknown error (invalid message)");if(this.parser.decimal_mark!=="."){let s=this.parser.decimal_mark,l=this.parser.argument_separator;this.parser.Save(),this.parser.SetLocaleSettings(".");let c=u=>{let d=this.parser.Parse(u);if(d.expression)return"="+this.parser.Render(d.expression,{missing:"",convert_decimal:s,convert_argument_separator:l})};for(let u of i.data.results.named||[])u.expression=c(u.expression)||"";for(let u of i.data.results.sheets||[]){for(let d of u.cells||[])d.type==="formula"&&d.value&&(d.value=c(d.value));if(u.annotations)for(let d of u.annotations)d.formula&&(d.formula=c(d.formula))}this.parser.Restore()}this.grid.FromImportData(i.data.results),this.ResetInternal(),this.grid.Update(),this.UpdateAC(),this.Publish({type:"load",source:t,path:r}),this.UpdateDocumentStyles(),this.InflateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)}else return o("unknown error (missing data)");this.dialog?.HideDialog(),n()}),this.export_worker.OnError(i=>{console.error("import worker error"),console.info(i),o(i)}),this.export_worker.PostMessage({type:"import",data:e})):o("worker failed")}))}ResetInternal(){this.calculator.Reset(),this.FlushUndo(),this.file_version=this.last_save_version=0}HandleCellEvent(e){if(e.data?.type==="hyperlink"){let t="hyperlink invalid target",r=e.data.reference||"";if(typeof r=="string"){if(/^https{0,1}:\/\//i.test(r)){if(!this.options.hyperlinks){console.warn("hyperlinks are disabled");return}let n=this.DOM.Create("a");n.setAttribute("target",this.options.hyperlinks),n.setAttribute("href",r),n.setAttribute("noreferrer","true"),n.setAttribute("nofollow","true"),n.click();return}else{let n=this.parser.Parse(r);if(n.expression){if(n.expression.type==="address"){(n.expression.sheet||n.expression.sheet_id)&&this.ActivateSheet(n.expression.sheet||n.expression.sheet_id),this.Select(r);return}else if(n.expression.type==="range"){(n.expression.start.sheet||n.expression.start.sheet_id)&&this.ActivateSheet(n.expression.start.sheet||n.expression.start.sheet_id),this.Select(r);return}}}console.warn(t,2);return}}}OnSheetChange(e){for(let t of e.activate.annotations)this.InflateAnnotation(t),this.calculator.UpdateAnnotations(t,e.activate);this.UpdateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(e.activate,!0)}HandleDrag(e){if(e.dataTransfer&&e.dataTransfer.types){if(e.dataTransfer.types.some&&e.dataTransfer.types.some(t=>t==="Files"))e.preventDefault();else for(let t=0;t<e.dataTransfer.types.length;t++)if(e.dataTransfer.types[t]==="files"){e.preventDefault();return}}}HandleDrop(e){if(e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length){e.preventDefault();let t=e.dataTransfer.files[0];/^image/.test(t.type)?this.InsertImageInternal(t):this.LoadFileInternal(t,"drag-and-drop").catch(()=>{})}}SelectFile2(e,t){if(!this.file_chooser){let r=this.DOM.Create("input",void 0,void 0,{attrs:{type:"file"},events:{change:()=>{if(r.files&&r.files[0]){let n=r.files[0];switch(r.value="",this.file_chooser_operation){case 2:this.InsertImageInternal(n);break;case 1:this.LoadFileInternal(n,"local-file",!0);break;default:console.warn("file chooser: no operation");break}}}}});this.file_chooser=r}if(!this.file_chooser)throw new Error("could not create file chooser");this.file_chooser_operation=t,this.file_chooser.accept=e||"",this.file_chooser.click()}async InsertImageInternal(e){if(this.options.max_file_size&&e.size>this.options.max_file_size){this.dialog?.ShowDialog({type:"error",message:"This file exceeds the allowed image size. Please try a smaller image.",title:"Error adding image",timeout:3e3,close_box:!0});return}let t=e;await new Promise((r,n)=>{let o=new FileReader;o.onload=async()=>{try{if(o.result){let i;if(typeof o.result=="string")i=o.result;else{i="";let l=new Uint8Array(o.result);for(let c=0;c<l.byteLength;c++)i+=String.fromCharCode(l[c])}let s=this.DOM.Create("img");s.src=i,await Promise.resolve(),this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:i,original_size:{width:s.width||300,height:s.height||300}}},void 0,void 0,void 0,{top:30,left:30,width:s.width||300,height:s.height||300})}r()}catch(i){n(i)}},o.onabort=()=>{n("Aborted")},o.onerror=()=>{n("File error")},setTimeout(()=>{o.readAsDataURL(t)},100)})}LoadFileInternal(e,t,r=!0){if(!e)return Promise.resolve();let n=new FileReader;return new Promise((o,i)=>{let s=l=>{n.onload=null,n.onabort=null,n.onerror=null,l?(r&&(this.dialog?.ShowDialog({title:"Error reading file",close_box:!0,message:"Please make sure your file is a valid XLSX, CSV or TREB file.",type:"error",timeout:3e3}),console.error(l)),i(l)):o()};n.onload=()=>{try{if(n.result)if(/\.csv$/i.test(e.name))this.LoadCSV(n.result,t);else if(/\.xls[xm]$/i.test(e.name)){typeof n.result=="string"?s("Unsupported file"):this.ImportXLSX(n.result,t).then(()=>s()).catch(l=>s(l));return}else{let l=JSON.parse(n.result);this.LoadDocument(l,{source:t})}s()}catch(l){s(l?.toString())}},n.onabort=()=>{s("Aborted")},n.onerror=()=>{s("File error")},setTimeout(()=>{/\.xls[xm]$/i.test(e.name)?n.readAsArrayBuffer(e):n.readAsText(e)},100)})}UpdateAnnotations(){for(let e of this.grid.active_sheet.annotations){let t=e.temp;if(t.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;for(let n of e.view)n&&(n.dirty=!0)}let r=e.view[this.grid.view_index]||{};r.dirty&&(r.dirty=!1,r.update_callback&&r.update_callback(),this.grid.AnnotationUpdated(e))}this.UpdateConnectedElements()}UpdateConnectedElements(){for(let e of this.model.connected_elements.values()){let t=e.internal;if(t?.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;let r=e.update;r&&Promise.resolve().then(()=>r.call(0,e))}}}RebuildAllAnnotations(){for(let e of this.grid.active_sheet.annotations){this.InflateAnnotation(e);let t=e.view[this.grid.view_index]||{};t.resize_callback&&t.resize_callback(),t.update_callback&&t.update_callback()}}InflateAnnotations(){for(let e of this.grid.active_sheet.annotations)this.InflateAnnotation(e)}InflateAnnotation(e){if(this.grid.headless)return;let t=e.view[this.grid.view_index]||{};if(t.inflated){e.dirty&&(t.resize_callback&&t.resize_callback(),e.dirty=!1);return}if(t.inflated=!0,e.dirty&&(e.dirty=!1),t.content_node){if(e.data.type==="treb-chart"){let r=this.CreateChart();r.Initialize(t.content_node);let n=()=>{if(e.data.formula){let o=this.parser.Parse(e.data.formula);if(o&&o.expression&&o.expression.type==="call"){this.parser.Walk(o.expression,l=>((l.type==="address"||l.type==="range")&&this.model.ResolveSheetID(l,void 0,this.grid.active_sheet),!0));let i=o.expression.name.toLowerCase(),s=this.calculator.CalculateExpression(o.expression);r.Exec(i,s)}}r.Update()};t.resize_callback=()=>{this.grid.headless||(r.Resize(),r.Update())},t.update_callback=()=>{this.grid.headless||n()},t.node?.parentElement&&(this.grid.headless||n())}else if(e.data.type==="image"){if(typeof e.data.data?.src=="string"){let r=ar(e.data.data.src);if(r){let n=this.DOM.Create("img");n.src=r,e.data.data.scale==="fixed"?(n.style.position="relative",n.style.left="50%",n.style.top="50%",n.style.transform="translate(-50%, -50%)"):(n.style.width="100%",n.style.height="100%"),t.content_node.appendChild(n)}}}else if(e.data.type==="textbox"&&e.data.data){let r,n=document.createElement("div");n.classList.add("treb-annotation-textbox");for(let o of e.data.data.paragraphs){let i=document.createElement("p");o.style&&(o.style.horizontal_align==="right"||o.style.horizontal_align==="center")&&(i.style.textAlign=o.style.horizontal_align);for(let s of o.content){let l=document.createElement("span");if(r||(r=l),e.data.formula||(l.textContent=s.text||""),s.style?.bold&&(l.style.fontWeight="600"),s.style?.italic&&(l.style.fontStyle="italic"),i.appendChild(l),e.data.formula)break}if(n.append(i),e.data.formula)break}if(t.content_node.append(n),e.data.data.style){let o=e.data.data.style,i=()=>{if(o.fill){let s=ft(this.grid.theme,o.fill);n.style.background=s}};t.update_callback=()=>{if(this.grid.headless||i(),r&&e.data.formula){let s=this.parser.Parse(e.data.formula);if(s&&s.expression){this.parser.Walk(s.expression,d=>((d.type==="address"||d.type==="range")&&this.model.ResolveSheetID(d,void 0,this.grid.active_sheet),!0));let l=this.calculator.CalculateExpression(s.expression),c=R.Get("General"),u;switch(s.expression.type){case"address":u=s.expression;break;case"range":u=s.expression.start;break}if(u){let m=(u.sheet_id?this.model.sheets.Find(u.sheet_id):this.grid.active_sheet)?.CellStyleData(u);m?.number_format&&(c=R.Get(m.number_format))}switch(l.type){case 3:case 2:case 8:r.textContent=c.Format(l.value);break;default:r.textContent=l.value?.toString()||""}}}},t.update_callback()}}}}DocumentChange(e){Promise.resolve().then(()=>{this.file_version++,this.file_version>=65536&&(this.file_version=1);let t=JSON.stringify(this.SerializeDocument({optimize:"size",rendered_values:!0,expand_arrays:!0}));this.options.undo&&this.PushUndo(t,e,!1),this.Publish({type:"document-change"})})}ResolveStorageKey(e,t=""){if(e){if(e===!0){let r=0,n=document.location.href;for(let i=0,s=n.length;i<s;i++)r=(r<<5)-r+n.charCodeAt(i),r|=0;let o=Math.abs(r).toString(16);return t?t+"-"+o:o}return e}}PushUndo(e,t,r=!0){let n=t||this.last_selection;this.undo_stack[this.undo_pointer-1]&&(this.undo_stack[this.undo_pointer-1].selection=n),r&&(this.file_version++,this.file_version>=65536&&(this.file_version=1)),e||(e=JSON.stringify(this.SerializeDocument({optimize:"size",rendered_values:!0,expand_arrays:!0}))),this.undo_stack[this.undo_pointer++]={data:e,selection:void 0};let o=this.undo_stack.length;if(o>16){let i=o-16;this.undo_stack=this.undo_stack.slice(i),this.undo_pointer-=i}}FlushUndo(e=!0){this.undo_stack=[],this.undo_pointer=0,this.last_save_version=this.file_version,e&&this.PushUndo(void 0,void 0,!1)}UpdateSelection(e,t){this.last_selection=JSON.stringify(e);let r={type:"selection"};t==="sheet-change"&&(r.reason=t),this.Publish(r)}UpdateSelectionStyleAnnotation(e){let t={style:JSON.parse(JSON.stringify(e.data.style||{}))};t.style&&(t.style.font_face||(t.style.font_face="stack:ui"),t.style.font_size||(t.style.font_size={unit:"em",value:1})),t.relative_font_size=ht.RelativeFontSize(t.style||{},this.grid.theme.grid_cell||{}),this.selection_state=t}UpdateSelectionStyle(e){let t=this.grid.GetFreeze(),r={frozen:!!t.rows||!!t.columns};if(e||(e=this.grid.GetSelection()),e&&!e.empty){r.selection=e;let n=this.grid.active_sheet.CellData(e.target);r.table=!!n.table,r.merge=!!n.merge_area,r.merge&&n.merge_area&&(n.merge_area.start.row!==e.target.row||n.merge_area.start.column!==e.target.column)&&(n=this.grid.active_sheet.CellData(n.merge_area.start)),r.comment=n.note,r.style=n.style?{...n.style}:void 0,r.relative_font_size=ht.RelativeFontSize(r.style||{},this.grid.theme.grid_cell||{}),r.empty=typeof n.value>"u"&&!n.style?.font_face}this.grid?.edit_state&&(this.grid.edit_state.font_face=r.style?.font_face||void 0),this.selection_state=r}UpdateDocumentStyles(){let e={},t={};for(let n of this.grid.model.sheets.list)n.NumberFormatsAndColors(t,e);this.document_styles.colors=Object.keys(t),this.document_styles.number_formats=Object.keys(e),this.document_styles.theme_colors=[];let r=[.5,.25,0,-.25,-.5];for(let n=0;n<10;n++)this.document_styles.theme_colors.push(r.map(o=>{let i={theme:n,tint:o},s=ft(this.grid.theme,i);return{color:i,resolved:s}}))}ConvertLocale(e){let t=new Jt;t.flags={...this.parser.flags};let r,n;e.decimal_mark==="."?(t.SetLocaleSettings("."),r=",",n=";"):(t.SetLocaleSettings(","),r=".",n=",");let o=i=>{let s=t.Parse(i);if(s.expression)return"="+t.Render(s.expression,{missing:"",convert_decimal:r,convert_argument_separator:n})};if(e.macro_functions)for(let i of e.macro_functions){let s=o(i.function_def);s&&(i.function_def=s)}if(e.named)for(let i of e.named){let s=o(i.expression);s&&(i.expression=s)}if(e.sheet_data){let i=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let s of i){if(s.annotations){for(let l of s.annotations)if(l.formula){let c=o(l.formula);c&&(l.formula=c)}}if(s.data?.length)for(let l of s.data){let c=Yt(l)?[l]:l.cells;for(let u of c)if(u.value&&typeof u.value=="string"&&u.value[0]==="="){let d=o(u.value.slice(1));d&&(u.value=d)}}}}}CompareVersions(e="",t=""){let r=e.split(".").map(s=>Number(s)||0).concat([0,0,0]),n=t.split(".").map(s=>Number(s)||0).concat([0,0,0]),o=[0,1,2],i={match:0};for(let s=0;s<3;s++)if(r[s]!==n[s]){i.match=r[s]>n[s]?1:-1,i.level=o[s];break}return i}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],n=this.CompareVersions(e.version,"36.1.4");if(n.match>0&&(n.level===0||n.level===1)&&console.warn(`The file you are opening was created with a newer version of TREB (${e.version} vs 36.1.4).
8
+ You may encounter compatibility errors.`),e.sheet_data&&(Array.isArray(e.sheet_data)?r=e.sheet_data:r.push(e.sheet_data)),e.shared_resources){let i=e.shared_resources,s=l=>/^resource:/.test(l)?i[l.substring(9)]||"":l;for(let l of r){l.background_image&&(l.background_image=s(l.background_image));for(let c of l.annotations||[])c.type==="image"&&c.data?.src&&(c.data.src=s(c.data.src))}}e.decimal_mark&&e.decimal_mark!==ee.decimal_separator&&this.ConvertLocale(e);let o=this.grid.model;if(o.tables.clear(),e.tables)for(let i of e.tables)o.tables.set(i.name.toLowerCase(),i);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let i of this.model.tables.values())if(i.area.start.sheet_id){let s=o.sheets.Find(i.area.start.sheet_id);if(s)for(let l=i.area.start.row;l<=i.area.end.row;l++)for(let c=i.area.start.column;c<=i.area.end.column;c++){let u=s.cells.GetCell({row:l,column:c},!0);u.table=i}}if(o.document_name=e.name,o.user_data=e.user_data,o.named.Reset(),e.named)this.model.UnserializeNames(e.named,this.grid.active_sheet);else{let i=e.named_ranges;if(!i&&r[0]&&r[0].named_ranges&&(i=r[0].named_ranges),i)for(let[s,l]of Object.entries(i))o.named.SetNamedRange(s,new z(l.start,l.end));if(e.named_expressions)for(let s of e.named_expressions)this.model.UnserializeNames([{name:s.name,expression:s.expression}],this.grid.active_sheet)}if(o.macro_functions.clear(),e.macro_functions)for(let i of e.macro_functions)o.macro_functions.set(i.name.toUpperCase(),{...i,expression:this.parser.Parse(i.function_def||"").expression});this.UpdateAC()}async LoadWorker(){let e=lr(!!this.options.in_process_workers);return await e.Init("./treb-export-worker.mjs",()=>new Worker(new URL("./treb-export-worker.mjs",import.meta.url),{type:"module"})),e}HandleKeyDown(e){e.key==="z"?(Ee.is_mac&&e.metaKey||e.ctrlKey)&&(e.stopPropagation(),e.preventDefault(),this.Undo()):e.key==="F9"&&this.options.recalculate_on_f9&&(e.stopPropagation(),e.preventDefault(),this.Recalculate())}};var fn=`@charset "UTF-8";.treb-main.treb-main .treb-mouse-mask{background:transparent;bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:9999}.treb-main.treb-main .treb-mouse-mask.column-resize{cursor:col-resize}.treb-main.treb-main .treb-mouse-mask.row-resize{cursor:row-resize}.treb-main.treb-main .treb-mouse-mask.nub-select{cursor:crosshair}.treb-main.treb-main .treb-mouse-mask.move{cursor:move}.treb-main.treb-main .treb-mouse-mask.nw-resize{cursor:nw-resize}.treb-main.treb-main .treb-note{max-width:15em;min-width:15em}.treb-main.treb-main .treb-hover-title,.treb-main.treb-main .treb-note{background:var(--treb-note-background,#fff);border:1px solid var(--treb-note-border-color,var(--treb-ui-border-color,#ddd));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-note-color,#333);font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:10.5pt;left:100px;line-height:normal;opacity:0;padding:7px 10px;position:fixed;top:100px;transition:opacity .2s;white-space:pre-line;z-index:39}.treb-main.treb-main .treb-hover-title{min-width:10em;pointer-events:none}.treb-main.treb-main .treb-sort-button{background:#fff;border:1px solid #ccc;border-radius:2px;height:1em;left:100px;opacity:0;pointer-events:none;position:absolute;top:100px;transition:opacity .1s ease;width:1em;z-index:39}.treb-main.treb-main .treb-sort-button:after{box-sizing:border-box}.treb-main.treb-main .treb-sort-button.asc:after{border:.4em solid transparent;border-top-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-25%);width:.8em}.treb-main.treb-main .treb-sort-button.desc:after{border:.4em solid transparent;border-bottom-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-80%);width:.8em}.treb-main.treb-main .treb-tooltip{border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;line-height:normal;padding:2px 10px;pointer-events:none;position:fixed;z-index:39}.treb-main.treb-main .treb-tooltip.arrow-up:after{border:4px solid transparent;border-bottom-color:inherit;box-sizing:border-box;content:" ";height:8px;left:calc(50% - 4px);overflow:hidden;position:absolute;top:-8px;width:8px}.treb-main.treb-main .treb-tooltip.arrow-left:after{border:4px solid transparent;border-right-color:inherit;box-sizing:border-box;content:" ";height:8px;left:-8px;overflow:hidden;position:absolute;top:calc(50% - 4px);width:8px}.treb-main.treb-main .treb-dropdown-caret{background:var(--treb-dropdown-caret-background,#fff);border:1px solid var(--treb-dropdown-caret-border-color,#ccc);border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;height:20px;position:absolute;width:20px;z-index:39}.treb-main.treb-main .treb-dropdown-caret path{fill:none;stroke:var(--treb-dropdown-caret-color,#444);stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.treb-main.treb-main .treb-dropdown-list{background:var(--treb-dropdown-background,#fff);border:1px solid var(--treb-dropdown-border-color,unset);box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-dropdown-color,inherit);display:none;font-size:10pt;max-height:10em;outline:none;overflow-y:auto;position:absolute;text-align:left;z-index:39}.treb-main.treb-main .treb-dropdown-list div{cursor:default;padding:2px}.treb-main.treb-main .treb-dropdown-list div.selected{background:var(--treb-dropdown-selected-background,#555);color:var(--treb-dropdown-selected-color,#fff)}.treb-main.treb-main .treb-dropdown-caret.active{background:var(--treb-dropdown-caret-active-background,#eee)}.treb-main.treb-main .treb-dropdown-caret.active+.treb-dropdown-list{display:block}.treb-main.treb-main .treb-error-highlight{background:rgba(255,0,0,.25);opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in-out;z-index:40}.treb-main.treb-main .treb-autocomplete{box-sizing:border-box;font-size:inherit;font-weight:400;line-height:normal;max-height:10em;overflow-y:auto;position:fixed;text-align:left;top:-1000px;z-index:39}.treb-main.treb-main .treb-autocomplete *{box-sizing:border-box}.treb-main.treb-main .treb-autocomplete ul{list-style-type:none}.treb-main.treb-main .treb-autocomplete ul,.treb-main.treb-main .treb-autocomplete ul li{font-size:inherit;font-weight:inherit;margin:0;padding:0}.treb-main.treb-main .treb-autocomplete ul li a{color:inherit;cursor:default;display:inline-block;font-size:inherit;font-weight:inherit;padding:3px 6px;text-decoration:none;width:100%}.treb-main.treb-main .treb-autocomplete-tooltip{position:fixed;top:-1000px;white-space:pre;z-index:39}.treb-main.treb-main .treb-formula-bar{display:flex;flex-direction:row;gap:.5em;grid-area:1/1/2/2;max-width:100%;overflow-x:hidden;padding:0 2px 12px;text-align:left}.treb-main.treb-main .treb-formula-bar[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .treb-address-label{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;height:1.75em;justify-content:center;min-height:1.5em;min-width:95px;padding-left:3px;width:95px}.treb-main.treb-main .treb-formula-bar .treb-address-label>div{outline:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button{background:transparent;border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;height:1.75em;min-height:1.5em}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .expand-button{background:transparent;border:0;border-radius:2px;height:1.75em;margin-left:2px;outline:none;padding:1px}.treb-main.treb-main .treb-formula-bar .expand-button:after{border:5px solid transparent;border-top-color:#999;content:" ";display:inline-block;margin:0;padding:0;position:relative;top:-6px;transition:transform .15s ease}.treb-main.treb-main .treb-formula-bar[expanded] .expand-button:after{transform:rotate(180deg) translateY(6px)}.treb-main.treb-main .treb-formula-bar .treb-editor-container{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;flex-grow:1;height:1.75em;justify-content:center;min-width:0}.treb-main.treb-main .treb-formula-bar .treb-editor-container>.treb-editor-shadow{opacity:.4}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container{height:4.5em;transition:height .1s ease-in-out}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container>div{overflow-y:auto}.treb-main.treb-main .treb-formula-bar .treb-editor-container>div{flex-grow:1;line-height:1.35;margin:2px;min-height:1em;outline:none;overflow-x:hidden;overflow-y:hidden;white-space:pre-wrap;width:100%}.treb-main.treb-main .treb-mouse-mask .ghost-tab{position:fixed}.treb-main.treb-main .treb-spreadsheet-footer{align-items:center;grid-area:3/1/4/2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tab-container{align-self:flex-start;height:2.2em;overflow:hidden}.treb-main.treb-main .treb-spreadsheet-footer,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{color:var(--treb-ui-color,inherit);display:flex;flex-direction:row;height:2.2em;list-style-type:none;max-width:100%;padding-inline-start:0;z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{height:auto;margin-block-start:0;margin:0;overflow-x:scroll;overflow-y:hidden;scrollbar-width:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-spreadsheet-footer[hidden]{display:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{display:inline-block;margin:0;position:relative}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{align-items:center;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top-width:1px;border:1px solid var(--treb-tab-bar-tab-border-color,var(--treb-ui-border-color,#ccc));border-top:0 solid var(--treb-tab-bar-tab-border-color,var(--treb-ui-border-color,#ccc));color:var(--treb-tab-bar-tab-color,var(--treb-ui-color,#fff));cursor:default;display:inline-flex;font-size:inherit;height:100%;justify-content:center;margin-right:-2px;overflow:hidden;padding:0 .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:focus{z-index:3}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{height:2.2em;overflow:visible;overflow-x:visible}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:last-of-type{margin-right:0}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab{margin-left:-1px}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control{align-items:center;display:flex;flex-direction:row;font-size:inherit;height:2.2em;justify-content:center;position:relative;width:5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input{background:transparent;border:1px solid transparent;border-radius:2px;color:inherit;font-family:inherit;font-size:inherit;padding:initial;text-align:center;transition:border-color .25s ease,background-color .25s ease;width:4em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container{accent-color:var(--treb-scale-slider-accent-color,undefined);align-items:center;background:var(--treb-scale-slider-background,#fff);border:1px solid var(--treb-scale-slider-border-color,var(--treb-ui-border-color,#ccc));display:flex;flex-direction:row;height:4em;justify-content:center;left:.5em;opacity:0;pointer-events:none;position:absolute;top:0;transform:rotate(-90deg);transform-origin:left top;transition:opacity .25s ease;width:10em;z-index:40}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-scale-input{border-color:var(--treb-ui-border-color,#ccc)}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container>input[type=range]{width:8.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus+.treb-slider-container,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container:focus-within,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-slider-container{opacity:.85;pointer-events:auto}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab{align-items:center;background:transparent;border:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top:0;color:currentColor;cursor:default;display:inline-flex;flex-direction:row;font-size:inherit;margin-right:-2px;min-width:2.5em;padding:.25em .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab svg{height:1em;opacity:.75;pointer-events:none;transition:opacity .125s ease-in-out;width:1em}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:hover svg{opacity:.75}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab path{stroke:currentColor;stroke-linecap:round;stroke-width:1.5px}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:active,.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:focus{z-index:3}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel{flex:1 1;overflow:hidden;text-align:end;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel>*{margin-left:.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel .treb-stats-value{background:var(--treb-stats-value-background,#f8f8ff);border:1px solid var(--treb-stats-value-border-color,var(--treb-ui-border-color,#ddd));border-radius:3px;padding:0 .3em}.treb-main.treb-main .treb-grid .treb-overlay-container{margin:0;opacity:0;outline:none;padding:0;position:absolute;z-index:24}.treb-main.treb-main .treb-grid .treb-overlay-container.align-right .treb-overlay-inset{padding-right:3px;right:0;text-align:right}.treb-main.treb-main .treb-grid .treb-overlay-container.align-center .treb-overlay-inset{left:50%;text-align:center;transform:translateX(-50%)}.treb-main.treb-main .treb-grid .treb-overlay-inset{display:flex;flex-direction:column;height:100%;justify-content:flex-end;margin:0;min-width:100%;padding:0 4px;position:absolute}.treb-main.treb-main .treb-grid .treb-overlay-editor{outline:none;position:relative;white-space:nowrap;white-space:pre}.treb-main.treb-main .treb-grid .treb-overlay-editor.firefox:before{content:"\u200B"}.treb-main.treb-main .treb-spill-border{pointer-events:none;position:absolute;transform:translateZ(0)}.treb-main.treb-main .treb-spill-border rect{fill:none;filter:var(--treb-spill-border-filter,drop-shadow(3px 3px 2px rgba(0,0,0,.5)));stroke:var(--treb-spill-border-color,#5c5ce0);stroke-dasharray:var(--treb-spill-border-dasharray,0);stroke-width:var(--treb-spill-border-width,1px);z-index:35}.treb-main.treb-main .treb-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{grid-area:2/1/3/2;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{flex-grow:1;order:2;overflow:scroll;position:relative;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;grid-template-columns:100px auto;grid-template-rows:20px auto;outline:none;overscroll-behavior:none}.treb-main.treb-main .treb-grid .tile-cover.grid-cover{grid-area:2/2/3/3}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover{grid-area:1/2/2/3;position:-webkit-sticky;position:sticky;top:0}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover{grid-area:2/1/3/2;left:0;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-grid-selection{grid-area:1/1/2/2}.treb-main.treb-main .treb-grid .treb-corner{grid-area:1/1/2/2;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-left-header{display:grid;grid-area:2/1/3/2;grid-template-columns:auto;grid-template-rows:auto;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-top-header{display:grid;grid-area:1/2/2/3;grid-template-columns:auto;grid-template-rows:auto;position:-webkit-sticky;position:sticky}.treb-main.treb-main .treb-grid .treb-contents{display:grid;grid-area:2/2/3/3;grid-template-columns:auto;grid-template-rows:auto}.treb-main.treb-main .treb-grid.safari::-webkit-scrollbar{-webkit-appearance:none;height:7px;width:7px}.treb-main.treb-main .treb-grid.safari::-webkit-scrollbar-thumb{background-color:rgba(0,0,0,.25);border-radius:4px;-webkit-box-shadow:0 0 1px hsla(0,0%,100%,.5)}.treb-main.treb-main .treb-grid canvas{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-grid .nub-select{cursor:crosshair}.treb-main.treb-main .treb-grid .link-pointer{cursor:pointer}.treb-main.treb-main .treb-grid .mock-selection-node{background:red;left:-100px;position:fixed;top:-100px}.treb-main.treb-main .treb-grid .tile-cover{background:transparent;position:relative;z-index:14}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover{z-index:22}.treb-main.treb-main .treb-grid .tile-cover.column-header-cover.resize{cursor:col-resize}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover{z-index:22}.treb-main.treb-main .treb-grid .tile-cover.row-header-cover.resize{cursor:row-resize}.treb-main.treb-main .treb-grid .frozen-annotation-container,.treb-main.treb-main .treb-grid .treb-annotation-container{left:0;pointer-events:none;position:absolute;top:0;z-index:16}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation{background:hsla(0,0%,100%,.5);border:1px solid #999;overflow:hidden;pointer-events:auto;position:absolute;z-index:1}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-content,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-content{font-family:inherit;font-size:inherit;height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-move-target,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-move-target{cursor:move;height:10%;left:0;min-height:14px;position:absolute;top:0;width:100%;z-index:2}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation .annotation-resize-target,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation .annotation-resize-target{bottom:0;cursor:nwse-resize;height:10%;min-height:14px;min-width:14px;position:absolute;right:0;width:10%;z-index:3}.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation.clone-focus,.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation.retain-focus,.treb-main.treb-main .treb-grid .frozen-annotation-container .annotation:focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation.clone-focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation.retain-focus,.treb-main.treb-main .treb-grid .treb-annotation-container .annotation:focus{box-shadow:0 0 0 3px rgba(14,165,233,.33)}.treb-main.treb-main .treb-grid .frozen-annotation-container .move-buffer,.treb-main.treb-main .treb-grid .treb-annotation-container .move-buffer{border:1px solid red;cursor:move;height:10%;left:0;position:absolute;top:0;width:100%}.treb-main.treb-main .treb-grid .treb-grid-selection{background:transparent;position:absolute;transform:translateZ(0);-moz-transform:scale(1);z-index:10}.treb-main.treb-main .treb-grid .frozen-selection{overflow:hidden;pointer-events:none;position:absolute;transform:translateZ(0);-moz-transform:scale(1);transition:background .33s;z-index:12}.treb-main.treb-main .treb-grid .frozen-selection.frozen-selection-rows{border-bottom:1px solid transparent}.treb-main.treb-main .treb-grid .frozen-selection.frozen-selection-columns{border-right:1px solid transparent}.treb-main.treb-main .treb-grid .frozen-annotation-container{height:100%;left:0;overflow:hidden;position:absolute;top:0;width:100%}.treb-main.treb-main .treb-grid .treb-corner{left:0;top:0;z-index:20}.treb-main.treb-main .treb-grid .treb-corner canvas{left:0;pointer-events:none;position:absolute;top:0}.treb-main.treb-main .treb-grid .treb-left-header{left:0;pointer-events:none;z-index:18}.treb-main.treb-main .treb-grid .treb-top-header{pointer-events:none;top:0;z-index:18}.treb-main.treb-main .treb-grid .treb-contents{height:2000px;width:2000px}.treb-main.treb-main{--alternate-selection-color-1:#fbb13c;--alternate-selection-color-2:#40c040;--alternate-selection-color-3:#b66d0d;--alternate-selection-color-4:#2176ae;--alternate-selection-color-5:#fe6847;--text-reference-color-1:#e08a00;--text-reference-color-2:#3aad3a;--text-reference-color-3:#b66d0d;--text-reference-color-4:#2176ae;--text-reference-color-5:#fe2f01}.treb-main.treb-main:focus-within .treb-grid-selection .primary-selection,.treb-main.treb-main:focus-within .treb-header-overlay{color:var(--treb-selection-color,#4caaf1)}.treb-main.treb-main .theme-color-1{color:var(--treb-theme-color-1,#e7e6e6)}.treb-main.treb-main .theme-color-2{color:var(--treb-theme-color-2,#44546a)}.treb-main.treb-main .theme-color-3{color:var(--treb-theme-color-3,#4472c4)}.treb-main.treb-main .theme-color-4{color:var(--treb-theme-color-4,#ed7d31)}.treb-main.treb-main .theme-color-5{color:var(--treb-theme-color-5,#a5a5a5)}.treb-main.treb-main .theme-color-6{color:var(--treb-theme-color-6,#ffc000)}.treb-main.treb-main .theme-color-7{color:var(--treb-theme-color-7,#5b9bd5)}.treb-main.treb-main .theme-color-8{color:var(--treb-theme-color-8,#70ad47)}.treb-main.treb-main .theme-color-9{color:var(--treb-theme-color-9,#0563c1)}.treb-main.treb-main .theme-color-10{color:var(--treb-theme-color-10,#954f72)}.treb-main.treb-main .treb-offset-dark{color:#000}.treb-main.treb-main .treb-offset-light{color:#fff}.treb-main.treb-main .note-marker{background:var(--treb-note-marker-color,#6fab20)}.treb-main.treb-main .grid-headers{background:var(--treb-grid-header-background,#eeeef2);color:var(--treb-grid-header-color,var(--treb-grid-default-color,#666));font-family:var(--treb-grid-header-font-family,inherit);font-size:var(--treb-grid-header-font-size,10pt);font-style:var(--treb-grid-header-font-style,normal);font-weight:var(--treb-grid-header-font-weight,normal);stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4))}.treb-main.treb-main .grid-cells{background:var(--treb-grid-background,#fff);color:var(--treb-grid-default-color,inherit);font-family:var(--treb-grid-font-family,inherit);font-size:var(--treb-grid-font-size,14px);stroke:var(--treb-grid-grid-color,#ccccd4)}.treb-main.treb-main .frozen-selection.highlight-area{background:rgba(87,184,255,.25);border-bottom-color:#2176ae;border-left-color:#2176ae}.treb-main.treb-main .treb-autocomplete-tooltip{background:var(--treb-autocomplete-tooltip-background,#fffbb5);border:1px solid var(--treb-autocomplete-tooltip-border-color,unset);border-radius:2px;color:var(--treb-autocomplete-tooltip-color,inherit);font-size:14px;line-height:normal;margin:4px 0;padding:3px 8px}.treb-main.treb-main .treb-autocomplete-tooltip .active-argument{font-weight:700}.treb-main.treb-main .treb-autocomplete-tooltip .function-description{font-style:italic}.treb-main.treb-main .treb-autocomplete{background:var(--treb-autocomplete-background,#fff);border:1px solid var(--treb-autocomplete-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);font-size:14px}.treb-main.treb-main .treb-autocomplete li{color:var(--treb-autocomplete-entry-color,#333)}.treb-main.treb-main .treb-autocomplete li a.selected{background:var(--treb-autocomplete-selected-entry-background,#2e8dd6);color:var(--treb-autocomplete-selected-entry-color,#fff)}.treb-main.treb-main .treb-header-overlay{color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1));stroke:none}.treb-main.treb-main .treb-header-overlay .treb-overlay{fill:#000;opacity:.05;stroke:none}.treb-main.treb-main .treb-header-overlay .treb-highlight{fill:currentColor}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="1"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="1"]{color:var(--text-reference-color-1)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="2"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="2"]{color:var(--text-reference-color-2)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="3"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="3"]{color:var(--text-reference-color-3)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="4"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="4"]{color:var(--text-reference-color-4)}.treb-main.treb-main .treb-editor-container>div [data-highlight-index="5"],.treb-main.treb-main .treb-overlay-editor [data-highlight-index="5"]{color:var(--text-reference-color-5)}.treb-main.treb-main .treb-editor-container>div span.highlight-1,.treb-main.treb-main .treb-overlay-editor span.highlight-1{color:var(--text-reference-color-1)}.treb-main.treb-main .treb-editor-container>div span.highlight-2,.treb-main.treb-main .treb-overlay-editor span.highlight-2{color:var(--text-reference-color-2)}.treb-main.treb-main .treb-editor-container>div span.highlight-3,.treb-main.treb-main .treb-overlay-editor span.highlight-3{color:var(--text-reference-color-3)}.treb-main.treb-main .treb-editor-container>div span.highlight-4,.treb-main.treb-main .treb-overlay-editor span.highlight-4{color:var(--text-reference-color-4)}.treb-main.treb-main .treb-editor-container>div span.highlight-5,.treb-main.treb-main .treb-overlay-editor span.highlight-5{color:var(--text-reference-color-5)}.treb-main.treb-main .frozen-selection .selection,.treb-main.treb-main .treb-grid-selection .selection{stroke-width:var(--treb-selection-stroke-width,2px)}.treb-main.treb-main .frozen-selection .selection .treb-selection-outline,.treb-main.treb-main .treb-grid-selection .selection .treb-selection-outline{fill:none;stroke:currentColor}.treb-main.treb-main .frozen-selection .selection .treb-selection-fill,.treb-main.treb-main .treb-grid-selection .selection .treb-selection-fill{fill:currentColor;opacity:var(--treb-selection-fill-opacity,.1);stroke:none}.treb-main.treb-main .frozen-selection .alternate-selection,.treb-main.treb-main .treb-grid-selection .alternate-selection{stroke-dasharray:var(--treb-alternate-selection-dasharray,3 2)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(1n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(1n){color:var(--alternate-selection-color-1)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(2n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(2n){color:var(--alternate-selection-color-2)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(3n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(3n){color:var(--alternate-selection-color-3)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(4n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(4n){color:var(--alternate-selection-color-4)}.treb-main.treb-main .frozen-selection .alternate-selection:nth-of-type(5n),.treb-main.treb-main .treb-grid-selection .alternate-selection:nth-of-type(5n){color:var(--alternate-selection-color-5)}.treb-main.treb-main .frozen-selection .primary-selection,.treb-main.treb-main .treb-grid-selection .primary-selection{color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1))}.treb-main.treb-main .frozen-selection .primary-selection .treb-selection-nub,.treb-main.treb-main .treb-grid-selection .primary-selection .treb-selection-nub{fill:currentColor;stroke:#fff;stroke-width:1px}.treb-main.treb-main .treb-tooltip{background:var(--treb-resize-tooltip-background,rgba(0,0,0,.8));border-color:var(--treb-resize-tooltip-background,rgba(0,0,0,.8));color:var(--treb-resize-tooltip-color,#fff);font-size:11pt}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{background:var(--treb-tab-bar-tab-background,#eeeef2);color:var(--treb-tab-bar-tab-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab[selected],.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{background:var(--treb-tab-bar-active-tab-background,#fff);border-bottom-color:var(--treb-tab-bar-active-tab-border-color,currentColor);color:var(--treb-tab-bar-active-tab-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-formula-bar .treb-address-label,.treb-main.treb-main .treb-formula-bar .treb-editor-container{background:var(--treb-formula-bar-background,transparent);color:var(--treb-formula-bar-color,var(--treb-ui-color,inherit))}.treb-main.treb-main .treb-formula-bar .treb-address-label[locked],.treb-main.treb-main .treb-formula-bar .treb-editor-container[locked]{background:var(--treb-formula-bar-locked-background,#eef4fc);position:relative}.treb-main.treb-main .treb-formula-bar .treb-address-label[locked]:after,.treb-main.treb-main .treb-formula-bar .treb-editor-container[locked]:after{content:"";height:12px;opacity:.4;position:absolute;right:2px;top:2px;width:12px;--icon:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='currentColor' d='M416 224h-16v-80C400 65 335 0 256 0S112 65 112 144v80H96c-35 0-64 29-64 64v160c0 35 29 64 64 64h320c35 0 64-29 64-64V288c0-35-29-64-64-64m-240-80c0-44 36-80 80-80s80 36 80 80v80H176z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:12px 12px;-webkit-mask-size:12px 12px}.treb-main.treb-main .treb-annotation-textbox{background:Canvas;height:100%;left:0;overflow:hidden;padding:.5em;position:relative;top:0;width:100%}.treb-main.treb-main .treb-annotation-textbox p{margin-block-end:0;margin-block-start:0}.treb-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-tab-background:#000;--treb-tab-bar-tab-color:#fff;--treb-theme-color-1:#222;--treb-theme-color-2:#ddd;--treb-toolbar-active-button-background:#555;--treb-toolbar-button-background:#000;--treb-toolbar-hover-button-background:#444;--treb-ui-color:#fff;--treb-table-header-background:#334;--treb-table-odd-background:#122;--treb-table-header-font-weight:700;--treb-table-header-border-top:#889;--treb-table-header-border-bottom:#889;--treb-table-footer-border-bottom:#889;--treb-table-odd-border-top:#889;--treb-table-odd-border-bottom:#889;--treb-table-even-border-top:#889;--treb-table-even-border-bottom:#889;--treb-table-total-border-top:#889;--treb-table-total-border-bottom:#889;--treb-table-total-background:#334;--treb-table-total-font-weight:700;--treb-color-scheme:dark;--treb-resize-handle-color:#add8e6;--treb-resize-frame-color:#add8e6;--treb-formula-bar-locked-background:#234;--treb-grid-background:#1e1e1e;--treb-grid-header-background:#565656;--treb-grid-header-color:#ddd;--treb-tab-bar-active-tab-background:#444;--treb-tab-bar-tab-background:transparent;--treb-tab-bar-tab-border-color:#444;--treb-ui-border-color:#aaa;--treb-toolbar-button-background:#565656;--treb-toolbar-button-background:#212121;--treb-toolbar-border-color:#434343;--treb-toolbar-color:#ddd;--treb-spill-border-color:pink;--treb-spill-border-filter:drop-shadow(3px 3px 2px hsla(0,0%,100%,.95))}@media (prefers-color-scheme:dark){.treb-light-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-tab-background:#000;--treb-tab-bar-tab-color:#fff;--treb-theme-color-1:#222;--treb-theme-color-2:#ddd;--treb-toolbar-active-button-background:#555;--treb-toolbar-button-background:#000;--treb-toolbar-hover-button-background:#444;--treb-ui-color:#fff;--treb-table-header-background:#334;--treb-table-odd-background:#122;--treb-table-header-font-weight:700;--treb-table-header-border-top:#889;--treb-table-header-border-bottom:#889;--treb-table-footer-border-bottom:#889;--treb-table-odd-border-top:#889;--treb-table-odd-border-bottom:#889;--treb-table-even-border-top:#889;--treb-table-even-border-bottom:#889;--treb-table-total-border-top:#889;--treb-table-total-border-bottom:#889;--treb-table-total-background:#334;--treb-table-total-font-weight:700;--treb-color-scheme:dark;--treb-resize-handle-color:#add8e6;--treb-resize-frame-color:#add8e6;--treb-formula-bar-locked-background:#234;--treb-grid-background:#1e1e1e;--treb-grid-header-background:#565656;--treb-grid-header-color:#ddd;--treb-tab-bar-active-tab-background:#444;--treb-tab-bar-tab-background:transparent;--treb-tab-bar-tab-border-color:#444;--treb-ui-border-color:#aaa;--treb-toolbar-button-background:#565656;--treb-toolbar-button-background:#212121;--treb-toolbar-border-color:#434343;--treb-toolbar-color:#ddd;--treb-spill-border-color:pink;--treb-spill-border-filter:drop-shadow(3px 3px 2px hsla(0,0%,100%,.95))}}.treb-chart,.treb-main.treb-main .treb-chart{background:var(--treb-chart-background,#fff)}.treb-main.treb-main .treb-inherit-font .treb-chart{font-family:inherit}.treb-chart{--segment-2-offset:-20;--segment-3-offset:10;--segment-4-offset:-10;--segment-5-offset:20;--segment-6-offset:-25}.treb-chart .series-1{color:var(--treb-applied-theme-color-1)}.treb-chart .series-2{color:var(--treb-applied-theme-color-2)}.treb-chart .series-3{color:var(--treb-applied-theme-color-3)}.treb-chart .series-4{color:var(--treb-applied-theme-color-4)}.treb-chart .series-5{color:var(--treb-applied-theme-color-5)}.treb-chart .series-6{color:var(--treb-applied-theme-color-6)}.treb-chart .series-7{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-8{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-9{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-10{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-11{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-12{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-2-offset)) c h)}.treb-chart .series-13{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-14{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-15{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-16{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-17{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-18{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-3-offset)) c h)}.treb-chart .series-19{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-20{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-21{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-22{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-23{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-24{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-4-offset)) c h)}.treb-chart .series-25{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-26{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-27{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-28{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-29{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-30{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-5-offset)) c h)}.treb-chart .series-31{color:lch(from var(--treb-applied-theme-color-1) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-32{color:lch(from var(--treb-applied-theme-color-2) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-33{color:lch(from var(--treb-applied-theme-color-3) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-34{color:lch(from var(--treb-applied-theme-color-4) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-35{color:lch(from var(--treb-applied-theme-color-5) calc(l + var(--segment-6-offset)) c h)}.treb-chart .series-36{color:lch(from var(--treb-applied-theme-color-6) calc(l + var(--segment-6-offset)) c h)}.treb-chart .chart-title{font-size:1.4em}.treb-chart .axis-group{font-size:.9em}.treb-chart .axis-group .series-name{font-size:1.3em}.treb-chart text{fill:var(--treb-chart-text-color,#000);stroke:none}.treb-chart .legend{font-size:1.05em}.treb-chart .legend rect{fill:currentColor}.treb-chart .legend circle{fill:currentColor;fill-opacity:.5;r:.25em;stroke:currentColor;stroke-width:2px}.treb-chart .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .chart-grid.zero,.treb-chart .chart-ticks.zero{stroke:var(--treb-chart-grid-zero-color,var(--treb-chart-grid-color,#999))}.treb-chart .label-target{fill:transparent;stroke:none}.treb-chart path.label-target{transition:fill .2s}.treb-chart path.label-target:hover{fill:rgba(0,0,0,.15)}.treb-chart .data-label{opacity:0;pointer-events:none;transition:opacity .2s ease-in-out}.treb-chart .data-label text{fill:#fff}.treb-chart .data-label path{fill:#000}.treb-chart .data-label .marker-highlight{fill:currentColor;stroke:none}.treb-chart .label-target:hover+.data-label{opacity:1}.treb-chart .chart-line{fill:none;stroke:currentColor;stroke-width:2}.treb-chart .chart-area .line{fill:none;stroke:currentColor;stroke-width:2px}.treb-chart .chart-area .fill{fill:currentColor;opacity:.5}.treb-chart .box-plot .iqr{fill:none;stroke:CanvasText;stroke-width:1px}.treb-chart .box-plot .median{fill:none;stroke:CanvasText;stroke-width:3px}.treb-chart .box-plot .outlier{r:3}.treb-chart .box-plot .outlier,.treb-chart .box-plot .whisker,.treb-chart .box-plot .whisker-extent{fill:none;stroke:CanvasText;stroke-width:1px}.treb-chart .box-plot .whisker-extent{stroke-dasharray:3 3}.treb-chart .bubble-chart{fill:color-mix(in srgb,currentColor 75%,transparent);stroke:currentColor;stroke-width:3}.treb-chart .bubble-label .label-background{fill:none;stroke:none}.treb-chart .bubble-label .label-text{transform:translate(var(--translate-offset),var(--translate-offset))}.treb-chart .scatter-plot{fill:none;stroke:currentColor;stroke-width:3}.treb-chart .scatter-plot .fill{fill:currentColor;opacity:.5;stroke:none}.treb-chart .scatter-plot .marker{fill:#fff;stroke-width:2.5px;transition:stroke-width .15s ease-in}.treb-chart .scatter-plot .marker:hover{stroke-width:5px}.treb-chart .donut path{fill:currentColor}.treb-chart .donut path.callout{fill:none;stroke:#999;stroke-dasharray:2 2}.treb-chart .donut text.callout-label{font-size:1em}.treb-chart .chart-column{fill:currentColor;stroke:none}.treb-chart .mc-correlation{stroke:currentColor;stroke-width:1}.treb-main.treb-main{--treb-icon-svg:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='153.073' height='133.742' viewBox='0.673 4.629 153.073 133.742'%3E%3ClinearGradient id='a' x1='.673' x2='153.746' y1='71.5' y2='71.5' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' style='stop-color:%235cb5ff'/%3E%3Cstop offset='1' style='stop-color:%230059b9'/%3E%3C/linearGradient%3E%3Cpath fill='url(%23a)' d='M91.656 28.313c-4.989 0-17.266 6.249-21.305 8.504-2.344-2.473-2.603-6.162-3.036-10.933-2.344 2.429-.824 9.806 0 12.496-10.238 7.635-18.83 15.531-27.597 24.471-2.992-4.729-5.031-8.593-5.726-17.183-3.038 6.509.867 15.057 3.121 19.784-9.674 12.193-19.263 25.297-27.03 37.834-35.488-74.973 72.853-119.534 143.663-88.855-43.867 29.199-55.192 121.353-132.248 96.843-5.423 7.809-9.069 18.006-13.538 27.072-3.73.263-6.334-1.646-7.288-3.12 7.506-18.181 17.183-34.192 27.075-49.984 10.718.306 21.346.478 30.198-1.04-7.681-2.038-16.877-.78-26.032-3.123C37.51 70.361 45.667 62.203 53.78 54.004c8.808.782 17.746 3.21 27.074 1.041-8.111-1.431-15.966-1.952-22.909-4.165 7.594-8.378 22.777-17.491 33.711-22.567'/%3E%3C/svg%3E")}.treb-main.treb-main .treb-icon-64{background:no-repeat 50%/100% var(--treb-icon-svg);height:64px;width:64px}.treb-main.treb-main .treb-dialog-mask{align-items:center;display:flex;height:100%;justify-content:center;left:0;opacity:0;pointer-events:none;position:absolute;top:0;transition:opacity .2s;width:100%;z-index:1000}.treb-main.treb-main .treb-embed-dialog{align-items:center;background:var(--treb-dialog-background,#fff);border:1px solid var(--treb-dialog-border-color,var(--treb-ui-border-color,#999));border-radius:3px;border-top:3px solid #999;box-shadow:0 4px 6px -4px rgba(0,0,0,.3);color:var(--treb-dialog-color,#000);display:flex;flex-direction:row;font-size:var(--treb-dialog-font-size,16px);line-height:1.6em;padding:1rem;position:relative;text-align:left}.treb-main.treb-main .treb-embed-dialog>*{display:none}.treb-main.treb-main .treb-embed-dialog>div{position:relative}.treb-main.treb-main .treb-embed-dialog>:nth-child(2){display:block;flex-grow:1;padding:2px 20px 2px 12px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box{background:transparent;border:0;padding:4px;position:absolute;right:0;top:0}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg{cursor:default;fill:#73828c;height:20px;width:20px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg:active,.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg:hover{fill:#049cfb}.treb-main.treb-main .treb-embed-dialog small{display:block;font-size:.9em}.treb-main.treb-main .treb-embed-dialog a{color:inherit;text-decoration:none}.treb-main.treb-main .treb-embed-dialog a:active,.treb-main.treb-main .treb-embed-dialog a:hover{color:#049cfb}.treb-main.treb-main .treb-embed-dialog.dialog-type-success{border-top-color:#44d926;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-about{border-top-color:#009dff;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-error{border-top-color:#f92f06;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog.dialog-type-info{border-top-color:#009dff;border-top-width:3px}.treb-main.treb-main .treb-embed-dialog .treb-embed-dialog-message,.treb-main.treb-main .treb-embed-dialog .treb-embed-dialog-title{white-space:pre}.treb-main.treb-main .treb-embed-dialog .treb-embed-progress-container{border:1px solid #ddd;height:6px;margin:1rem auto .5rem;position:relative;width:100%}.treb-main.treb-main .treb-embed-dialog .treb-embed-progress-bar{background:#52880b;height:100%;left:0;position:relative;top:0}.treb-main.treb-main .treb-spinner{align-items:center;background:transparent;display:flex;height:100%;justify-content:center;left:0;opacity:0;position:absolute;top:0;transition:visibility .25s,opacity .25s ease;visibility:collapse;width:100%;z-index:1000}.treb-main.treb-main .treb-spinner.visible{opacity:1;transition:visibility 0s,opacity 1s ease;visibility:visible}.treb-main.treb-main .treb-spinner>div{display:inline-block;height:80px;position:relative;width:80px}.treb-main.treb-main .treb-spinner>div div{animation:treb-spinner 1.2s cubic-bezier(.5,0,.5,1) infinite;border:8px solid #fff;border-color:var(--treb-spinner-color,currentColor) transparent transparent transparent;border-radius:50%;box-sizing:border-box;display:block;height:64px;margin:8px;position:absolute;width:64px}.treb-main.treb-main .treb-spinner>div div:first-child{animation-delay:-.45s}.treb-main.treb-main .treb-spinner>div div:nth-child(2){animation-delay:-.3s}.treb-main.treb-main .treb-spinner>div div:nth-child(3){animation-delay:-.15s}@keyframes treb-spinner{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.treb-main.treb-main{--icon-x:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708"/></svg>');--icon-popout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path fill="currentColor" d="M22 14.5v5c0 2.484-2.016 4.5-4.5 4.5h-13A4.5 4.5 0 0 1 0 19.5v-13C0 4.016 2.016 2 4.5 2h11c.281 0 .5.219.5.5v1c0 .281-.219.5-.5.5h-11A2.507 2.507 0 0 0 2 6.5v13C2 20.875 3.125 22 4.5 22h13c1.375 0 2.5-1.125 2.5-2.5v-5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5M28 1v8c0 .547-.453 1-1 1a1 1 0 0 1-.703-.297l-2.75-2.75L13.36 17.14c-.094.094-.234.156-.359.156s-.266-.063-.359-.156l-1.781-1.781c-.094-.094-.156-.234-.156-.359s.063-.266.156-.359L21.048 4.454l-2.75-2.75a1 1 0 0 1-.297-.703c0-.547.453-1 1-1h8c.547 0 1 .453 1 1z"/></svg>');--icon-toolbar:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M5.5 22v2H0v-2zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm2.5-6v2H0v-2zm-10-8v2H0V6zM24 22v2H12.5v-2zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm5 2v2h-3.5v-2zm0-8v2H10.5V6z"/></svg>');--icon-export:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 28"><path fill="currentColor" d="M20 21c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m2-3.5v5a1.5 1.5 0 0 1-1.5 1.5h-23A1.5 1.5 0 0 1 0 22.5v-5A1.5 1.5 0 0 1 1.5 16h7.266l2.109 2.125c.578.562 1.328.875 2.125.875s1.547-.313 2.125-.875L17.25 16h7.25a1.5 1.5 0 0 1 1.5 1.5m-5.078-8.891a.98.98 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.98.98 0 0 1-.219-1.094C5.234 8.25 5.594 8 6 8h4V1c0-.547.453-1 1-1h4c.547 0 1 .453 1 1v7h4c.406 0 .766.25.922.609"/></svg>');--icon-reset:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M23.609 16.5c0 .031 0 .078-.016.109C22.265 22.14 17.702 26 11.937 26c-3.047 0-6-1.203-8.219-3.313l-2.016 2.016A1 1 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a1 1 0 0 1-.297.703l-2.141 2.141A7.99 7.99 0 0 0 11.998 22a7.98 7.98 0 0 0 6.813-3.813c.375-.609.562-1.203.828-1.828.078-.219.234-.359.469-.359h3c.281 0 .5.234.5.5zM24 4v7c0 .547-.453 1-1 1h-7c-.547 0-1-.453-1-1a1 1 0 0 1 .297-.703l2.156-2.156A8.04 8.04 0 0 0 12 6a7.98 7.98 0 0 0-6.813 3.813c-.375.609-.562 1.203-.828 1.828-.078.219-.234.359-.469.359H.781a.503.503 0 0 1-.5-.5v-.109C1.625 5.844 6.234 2 12 2c3.063 0 6.047 1.219 8.266 3.313l2.031-2.016A1 1 0 0 1 23 3c.547 0 1 .453 1 1"/></svg>');--icon-about:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M14 21.5v-3c0-.281-.219-.5-.5-.5h-3c-.281 0-.5.219-.5.5v3c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5M18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328a.49.49 0 0 0 .125.656l2.063 1.563a.48.48 0 0 0 .297.094.5.5 0 0 0 .391-.187c.734-.938 1.047-1.219 1.344-1.437.266-.187.781-.375 1.344-.375 1 0 1.922.641 1.922 1.328 0 .812-.422 1.219-1.375 1.656-1.109.5-2.625 1.797-2.625 3.313v.562c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5 0-.359.453-1.125 1.188-1.547 1.188-.672 2.812-1.578 2.812-3.953zm6 3c0 6.625-5.375 12-12 12S0 20.625 0 14 5.375 2 12 2s12 5.375 12 12"/></svg>');--icon-chevron-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 28"><path fill="currentColor" d="M18.297 4.703 10 13l8.297 8.297a.99.99 0 0 1 0 1.406l-2.594 2.594a.99.99 0 0 1-1.406 0L2.703 13.703a.99.99 0 0 1 0-1.406L14.297.703a.99.99 0 0 1 1.406 0l2.594 2.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-chevron-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 28"><path fill="currentColor" d="M17.297 13.703 5.703 25.297a.99.99 0 0 1-1.406 0l-2.594-2.594a.99.99 0 0 1 0-1.406L10 13 1.703 4.703a.99.99 0 0 1 0-1.406L4.297.703a.99.99 0 0 1 1.406 0l11.594 11.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-revert:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M24 14c0 6.609-5.391 12-12 12a11.97 11.97 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.6.6 0 0 1 .391-.141.5.5 0 0 1 .359.187A7.91 7.91 0 0 0 12 21.999c4.406 0 8-3.594 8-8s-3.594-8-8-8A7.95 7.95 0 0 0 6.563 8.14l2.141 2.156a.96.96 0 0 1 .219 1.078 1 1 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.96.96 0 0 1 1.078.219l2.031 2.016c2.203-2.078 5.187-3.313 8.266-3.313 6.609 0 12 5.391 12 12zM14 9.5v7c0 .281-.219.5-.5.5h-5a.494.494 0 0 1-.5-.5v-1c0-.281.219-.5.5-.5H12V9.5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5"/></svg>');--icon-text-indent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-left" viewBox="0 0 16 16"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m.646 2.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L4.293 8 2.646 6.354a.5.5 0 0 1 0-.708M7 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m-5 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-outdent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-right" viewBox="0 0 16 16"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m10.646 2.146a.5.5 0 0 1 .708.708L11.707 8l1.647 1.646a.5.5 0 0 1-.708.708l-2-2a.5.5 0 0 1 0-.708zM2 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-center:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-top:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 15a.5.5 0 0 0 .5-.5V5.707l3.146 3.146a.5.5 0 0 0 .707-.707l-4-4a.5.5 0 0 0-.706-.001l-.001.001-4 4a.5.5 0 0 0 .708.707L7.5 5.707V14.5a.5.5 0 0 0 .5.5'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M3 1.5h10'/%3E%3C/svg%3E");--icon-text-align-middle:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8m7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0m-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0z"/></svg>');--icon-text-align-bottom:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 1a.5.5 0 0 0-.5.5v8.793L4.354 7.146a.5.5 0 0 0-.707.707l4 4a.5.5 0 0 0 .707.001l.001-.001 4-4a.5.5 0 0 0-.708-.707L8.5 10.293V1.5A.5.5 0 0 0 8 1'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M13 14.5H3'/%3E%3C/svg%3E");--icon-file-menu:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.54 3.87.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.826a2 2 0 0 1-1.991-1.819l-.637-7a2 2 0 0 1 .342-1.31zM2.19 4a1 1 0 0 0-.996 1.09l.637 7a1 1 0 0 0 .995.91h10.348a1 1 0 0 0 .995-.91l.637-7A1 1 0 0 0 13.81 4zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139q.323-.119.684-.12h5.396z"/></svg>');--icon-wrap-text:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4 5h8a.5.5 0 0 0 0-1H4a.5.5 0 0 0 0 1M10 8H4a.5.5 0 0 0 0 1h6a1.5 1.5 0 0 1 0 3v-1.203l-2.953 1.707L10 14.203V13a2.5 2.5 0 1 0 0-5M3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5"/></svg>');--icon-unmerge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M1.5 1a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0v-4A1.5 1.5 0 0 1 1.5 0h4a.5.5 0 0 1 0 1zM10 .5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 16 1.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5M.5 10a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 0 14.5v-4a.5.5 0 0 1 .5-.5m15 0a.5.5 0 0 1 .5.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5"/></svg>');--icon-merge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M5.5 0a.5.5 0 0 1 .5.5v4A1.5 1.5 0 0 1 4.5 6h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5m5 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 10 4.5v-4a.5.5 0 0 1 .5-.5M0 10.5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 6 11.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5m10 1a1.5 1.5 0 0 1 1.5-1.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0z"/></svg>');--icon-lock:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2m3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2M5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1"/></svg>');--icon-comment:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-2.5a2 2 0 0 0-1.6.8L8 14.333 6.1 11.8a2 2 0 0 0-1.6-.8H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2.5a1 1 0 0 1 .8.4l1.9 2.533a1 1 0 0 0 1.6 0l1.9-2.533a1 1 0 0 1 .8-.4H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/></svg>');--icon-fill-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a3 3 0 0 0-.71-.515c-.217-.104-.56-.205-.882-.02-.367.213-.427.63-.43.896-.003.304.064.664.173 1.044.196.687.556 1.528 1.035 2.402L.752 8.22c-.277.277-.269.656-.218.918.055.283.187.593.36.903.348.627.92 1.361 1.626 2.068.707.707 1.441 1.278 2.068 1.626.31.173.62.305.903.36.262.05.64.059.918-.218l5.615-5.615c.118.257.092.512.05.939-.03.292-.068.665-.073 1.176v.123h.003a1 1 0 0 0 1.993 0H14v-.057a1 1 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4 4 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067S8.857 3.052 8.23 2.704c-.31-.172-.62-.304-.903-.36-.262-.05-.64-.058-.918.219l-.217.216zM4.16 1.867c.381.356.844.922 1.311 1.632l-.704.705c-.382-.727-.66-1.402-.813-1.938a3.3 3.3 0 0 1-.131-.673q.137.09.337.274m.394 3.965c.54.852 1.107 1.567 1.607 2.033a.5.5 0 1 0 .682-.732c-.453-.422-1.017-1.136-1.564-2.027l1.088-1.088q.081.181.183.365c.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626q.183.103.365.183l-4.861 4.862a1 1 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46s-1.168-1.32-1.46-1.846c-.147-.265-.225-.47-.251-.607a1 1 0 0 1-.01-.068zm2.87-1.935a2.4 2.4 0 0 1-.241-.561c.135.033.324.11.562.241.524.292 1.186.8 1.846 1.46.45.45.83.901 1.118 1.31a3.5 3.5 0 0 0-1.066.091 11 11 0 0 1-.76-.694c-.66-.66-1.167-1.322-1.458-1.847z"/></svg>');--icon-text-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" viewBox="0 0 16 16"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604zM8.418 3.604a6 6 0 0 1-.127-.387 4 4 0 0 1-.11-.501h-.035a5.5 5.5 0 0 1-.247.888L5.86 9.211h4.614z"/></svg>');--icon-border-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0z"/></svg>');--icon-border-top:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0v1h16V0zm1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0v16h1V0zm1.906 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM7.5 1.906v.938h1v-.938zm7.5 0v.938h1v-.938zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938zm7.5 0v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM7.5 9.406v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zM1.906 16h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zM16 0h-1v16h1zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zM0 11.281v.938h1v-.938zm7.5 0v.938h1v-.938zM0 13.156v.938h1v-.938zm7.5 0v.938h1v-.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938z"/></svg>');--icon-border-double-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0zm0-2h16v1H0z"/></svg>');--icon-border-all:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0h16v16H0zm1 1v6.5h6.5V1zm7.5 0v6.5H15V1zM15 8.5H8.5V15H15zM7.5 15V8.5H1V15z"/></svg>');--icon-border-outer:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M7.5 1.906v.938h1v-.938zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM7.5 9.406v.938h1v-.938zm0 1.875v.938h1v-.938zm0 1.875v.938h1v-.938z"/><path d="M0 0v16h16V0zm1 1h14v14H1z"/></svg>');--icon-border-none:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0zm2.844 1h-.938V0h.938zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1zm2.813 0h-.938V0h.938zm1.875 0h-.938V0h.938zm1.875 0h-.938V0h.938zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5zM1 1.906v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM1 3.78v.938H0V3.78zm6.5.938V3.78h1v.938zm7.5 0V3.78h1v.938zM1 5.656v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938zm1.875.031h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5zM0 10.344v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 12.22v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 14.094v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5zm2.813 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16z"/></svg>');--icon-palette:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 .5A.5.5 0 0 1 .5 0h5a.5.5 0 0 1 .5.5v5.277l4.147-4.131a.5.5 0 0 1 .707 0l3.535 3.536a.5.5 0 0 1 0 .708L10.261 10H15.5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5H3a3 3 0 0 1-2.121-.879A3 3 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0M15 15v-4H9.258l-4.015 4zM0 .5v12.495zM0 12.995V13z"/></svg>');--icon-layout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="m3 0 17 17.156v-.114z"/><path d="M3 0H0v16h1V1h1.585L19 17.455V19H4v1h16v-2.844z"/><path d="M6.886 3.922 5.343 5.465a.5.5 0 0 0 .708.707l1.539-1.54zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3M5 9v6h6zm1 2.414L8.586 14H6z"/></svg>');--icon-freeze:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M8 16a.5.5 0 0 1-.5-.5v-1.293l-.646.647a.5.5 0 0 1-.707-.708L7.5 12.793V8.866l-3.4 1.963-.496 1.85a.5.5 0 1 1-.966-.26l.237-.882-1.12.646a.5.5 0 0 1-.5-.866l1.12-.646-.884-.237a.5.5 0 1 1 .26-.966l1.848.495L7 8 3.6 6.037l-1.85.495a.5.5 0 0 1-.258-.966l.883-.237-1.12-.646a.5.5 0 1 1 .5-.866l1.12.646-.237-.883a.5.5 0 1 1 .966-.258l.495 1.849L7.5 7.134V3.207L6.147 1.854a.5.5 0 1 1 .707-.708l.646.647V.5a.5.5 0 1 1 1 0v1.293l.647-.647a.5.5 0 1 1 .707.708L8.5 3.207v3.927l3.4-1.963.496-1.85a.5.5 0 1 1 .966.26l-.236.882 1.12-.646a.5.5 0 0 1 .5.866l-1.12.646.883.237a.5.5 0 1 1-.26.966l-1.848-.495L9 8l3.4 1.963 1.849-.495a.5.5 0 0 1 .259.966l-.883.237 1.12.646a.5.5 0 0 1-.5.866l-1.12-.646.236.883a.5.5 0 1 1-.966.258l-.495-1.849-3.4-1.963v3.927l1.353 1.353a.5.5 0 0 1-.707.708l-.647-.647V15.5a.5.5 0 0 1-.5.5z"/></svg>');--icon-column-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M4.5 17.5a.5.5 0 0 1-1 0v-5a.5.5 0 0 1 1 0zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0z"/></svg>');--icon-donut-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.01 9.01 0 0 0 12 1.23M2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9 9 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.43 7.43 0 0 1 2.5 10M17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.45 7.45 0 0 1-3.692-.979l-1.093 1.093A8.96 8.96 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7z"/></svg>');--icon-bar-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1z"/></svg>');--icon-line-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="m1 8 3-3 7 5 8-8v2l-8 8-7-5-3 3z"/></svg>');--icon-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0"/><path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z"/></svg>');--icon-recalculate:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20" viewBox="0 0 20 20"><path d="M9.478 4.022c2.402-.209 4.583 1.047 5.711 3.014l1.083-.095c-1.233-2.528-3.912-4.175-6.881-3.916-2.97.26-5.321 2.347-6.098 5.051l1.083-.095c.768-2.132 2.698-3.748 5.102-3.959M10.523 15.977c-2.403.211-4.585-1.047-5.712-3.013l-1.08.095c1.234 2.527 3.91 4.175 6.879 3.914 2.971-.259 5.32-2.347 6.095-5.05l-1.08.095c-.769 2.132-2.699 3.749-5.102 3.959"/><path d="m2.272 15.616 5.197-3-4.098-1.097zM17.728 4.384l-5.197 3 4.098 1.098z"/></svg>');--icon-check:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/></svg>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm15 2h-4v3h4zm0 4h-4v3h4zm0 4h-4v3h3a1 1 0 0 0 1-1zm-5 3v-3H6v3zm-5 0v-3H1v2a1 1 0 0 0 1 1zm-4-4h4V8H1zm0-4h4V4H1zm5-3v3h4V4zm4 4H6v3h4z"/></svg>')}.treb-main.treb-main .treb-layout-header{overflow:hidden;overflow-x:scroll;position:relative;-ms-overflow-style:none;scrollbar-width:none}.treb-main.treb-main .treb-layout-header::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-toolbar{color:var(--treb-toolbar-color,var(--treb-ui-color,#333));display:flex;flex-direction:row;font-size:var(--treb-toolbar-font-size,inherit);gap:.5rem}.treb-main.treb-main .treb-toolbar>div{display:flex;flex-direction:row}.treb-main.treb-main .treb-toolbar>div>input,.treb-main.treb-main .treb-toolbar>input{background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:32px;overflow:hidden;padding-left:.5em;padding-right:.5em;text-overflow:ellipsis}.treb-main.treb-main .treb-toolbar>.treb-menu>button{border-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu+button,.treb-main.treb-main .treb-toolbar>.group>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>button+button,.treb-main.treb-main .treb-toolbar>.group>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>input+button,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu+button,.treb-main.treb-main .treb-toolbar>[composite]>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>button+button,.treb-main.treb-main .treb-toolbar>[composite]>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>input+button{border-left-width:0}.treb-main.treb-main .treb-toolbar>.group>button:first-child,.treb-main.treb-main .treb-toolbar>.group>input:first-child,.treb-main.treb-main .treb-toolbar>[composite]>button:first-child,.treb-main.treb-main .treb-toolbar>[composite]>input:first-child{border-bottom-left-radius:3px;border-top-left-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>.group>button:last-child,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>[composite]>button:last-child{border-bottom-right-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button,.treb-main.treb-main .treb-toolbar .treb-menu>button,.treb-main.treb-main .treb-toolbar button[data-icon],.treb-main.treb-main .treb-toolbar>button,.treb-main.treb-main .treb-toolbar>div>button{align-items:center;background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));display:flex;flex-direction:column;height:32px;justify-content:center;position:relative;width:32px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown],.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown],.treb-main.treb-main .treb-toolbar button[data-icon][dropdown],.treb-main.treb-main .treb-toolbar>button[dropdown],.treb-main.treb-main .treb-toolbar>div>button[dropdown]{width:16px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown]:after,.treb-main.treb-main .treb-toolbar button[data-icon][dropdown]:after,.treb-main.treb-main .treb-toolbar>button[dropdown]:after,.treb-main.treb-main .treb-toolbar>div>button[dropdown]:after{border:5px solid transparent;border-top-color:currentcolor;box-sizing:content-box;content:"";height:0;left:50%;position:absolute;top:18px;transform:translate(-50%,-50%);width:0}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button:hover,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[active],.treb-main.treb-main .treb-toolbar .treb-menu>button:hover,.treb-main.treb-main .treb-toolbar .treb-menu>button[active],.treb-main.treb-main .treb-toolbar button[data-icon]:hover,.treb-main.treb-main .treb-toolbar button[data-icon][active],.treb-main.treb-main .treb-toolbar>button:hover,.treb-main.treb-main .treb-toolbar>button[active],.treb-main.treb-main .treb-toolbar>div>button:hover,.treb-main.treb-main .treb-toolbar>div>button[active]{background-color:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar button[data-icon][data-color-bar]:after,.treb-main.treb-main .treb-toolbar>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar>div>button[data-color-bar]:after{background:var(--treb-color-bar-color,var(--treb-default-color,unset));border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));box-sizing:border-box;content:"";display:block;height:6px;position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon]:before,.treb-main.treb-main .treb-toolbar>button[data-command]:before,.treb-main.treb-main .treb-toolbar>button[data-icon]:before,.treb-main.treb-main .treb-toolbar>div>button[data-command]:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon]:before{background:currentColor;content:"";display:block;height:20px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:var(--icon-size,16px 16px);-webkit-mask-size:var(--icon-size,16px 16px);position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>button[data-icon].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>div>button[data-command].treb-font-stack:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon].treb-font-stack:before{display:none}.treb-main.treb-main .treb-toolbar .treb-split{display:flex;flex-direction:column;gap:0}.treb-main.treb-main .treb-toolbar .treb-split button[data-command]{font-size:10px}.treb-main.treb-main .treb-toolbar .treb-split button[data-command]:before{display:none}.treb-main.treb-main .treb-toolbar .treb-split>button{align-items:center;display:flex;height:16px;justify-content:center}.treb-main.treb-main .treb-toolbar .treb-split>button:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-split>button:last-child{border-bottom-left-radius:3px;border-bottom-right-radius:3px;border-top:0}.treb-main.treb-main .treb-toolbar .treb-font-stack{align-items:flex-start;overflow:hidden;width:8em}.treb-main.treb-main .treb-toolbar .treb-font-stack:before{display:none}.treb-main.treb-main .treb-toolbar .treb-menu{outline:none}.treb-main.treb-main .treb-toolbar .treb-menu>div{background:var(--treb-toolbar-button-background,#fff);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px;box-shadow:0 4px 6px -4px rgba(0,0,0,.4);display:none;flex-direction:column;margin-top:.5rem;position:fixed;top:48px;z-index:20}.treb-main.treb-main .treb-toolbar .treb-menu>div button{background:transparent;border:0;margin:3px 0;padding:.4rem 1rem;text-align:left;transition:background-color .125s ease;white-space:nowrap}.treb-main.treb-main .treb-toolbar .treb-menu>div button:hover{background:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-menu>div.treb-icon-buttons>.treb-menu>button,.treb-main.treb-main .treb-toolbar .treb-menu>div.treb-icon-buttons>button{padding:0}.treb-main.treb-main .treb-toolbar .treb-menu>div>[separator]{background:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:1px;margin:2px 0}.treb-main.treb-main .treb-toolbar .treb-menu.visible>div,.treb-main.treb-main .treb-toolbar .treb-menu:focus-within>div{display:flex}.treb-main.treb-main .treb-toolbar [data-icon=file-menu]{--icon:var(--icon-file-menu)}.treb-main.treb-main .treb-toolbar [data-command=justify-left]{--icon:var(--icon-text-align-left)}.treb-main.treb-main .treb-toolbar [data-command=justify-right]{--icon:var(--icon-text-align-right)}.treb-main.treb-main .treb-toolbar [data-command=justify-center]{--icon:var(--icon-text-align-center)}.treb-main.treb-main .treb-toolbar [data-command=indent]{--icon:var(--icon-text-indent)}.treb-main.treb-main .treb-toolbar [data-command=outdent]{--icon:var(--icon-text-outdent)}.treb-main.treb-main .treb-toolbar [data-command=align-top]{--icon:var(--icon-text-align-top)}.treb-main.treb-main .treb-toolbar [data-command=align-middle]{--icon:var(--icon-text-align-middle)}.treb-main.treb-main .treb-toolbar [data-command=align-bottom]{--icon:var(--icon-text-align-bottom)}.treb-main.treb-main .treb-toolbar [data-command=merge-cells]{--icon:var(--icon-merge-cells)}.treb-main.treb-main .treb-toolbar [data-command=unmerge-cells]{--icon:var(--icon-unmerge-cells)}.treb-main.treb-main .treb-toolbar [data-command=fill-color]{--icon:var(--icon-fill-color)}.treb-main.treb-main .treb-toolbar [data-command=text-color]{--icon:var(--icon-text-color)}.treb-main.treb-main .treb-toolbar [data-command=lock-cells]{--icon:var(--icon-lock)}.treb-main.treb-main .treb-toolbar [data-command=wrap-text]{--icon:var(--icon-wrap-text)}.treb-main.treb-main .treb-toolbar [data-icon=comment]{--icon:var(--icon-comment)}.treb-main.treb-main .treb-toolbar [data-icon=table]{--icon:var(--icon-table)}.treb-main.treb-main .treb-toolbar [data-icon=layout]{--icon:var(--icon-layout)}.treb-main.treb-main .treb-toolbar [data-command=freeze-panes]{--icon:var(--icon-freeze)}.treb-main.treb-main .treb-toolbar [data-command=insert-column-chart]{--icon:var(--icon-column-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-donut-chart]{--icon:var(--icon-donut-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-bar-chart]{--icon:var(--icon-bar-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-line-chart]{--icon:var(--icon-line-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-image]{--icon:var(--icon-image)}.treb-main.treb-main .treb-toolbar [data-command=border-bottom]{--icon:var(--icon-border-bottom)}.treb-main.treb-main .treb-toolbar [data-command=border-left]{--icon:var(--icon-border-left)}.treb-main.treb-main .treb-toolbar [data-command=border-right]{--icon:var(--icon-border-right)}.treb-main.treb-main .treb-toolbar [data-command=border-top]{--icon:var(--icon-border-top)}.treb-main.treb-main .treb-toolbar [data-command=border-outside]{--icon:var(--icon-border-outer)}.treb-main.treb-main .treb-toolbar [data-command=border-all]{--icon:var(--icon-border-all)}.treb-main.treb-main .treb-toolbar [data-command=border-none]{--icon:var(--icon-border-none)}.treb-main.treb-main .treb-toolbar [data-command=border-double-bottom]{--icon:var(--icon-border-double-bottom)}.treb-main.treb-main .treb-toolbar [data-icon=palette]{--icon:var(--icon-palette)}.treb-main.treb-main .treb-toolbar [data-command=recalculate]{--icon:var(--icon-recalculate);--icon-size:20px 20px}.treb-main.treb-main .treb-toolbar .treb-font-scale{width:4em}.treb-main.treb-main .treb-toolbar .treb-number-format{width:8em}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]{align-items:center;display:flex;justify-content:center;padding:0;width:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]>svg{pointer-events:none}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div{padding:.75rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div+div{padding-top:0}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child{align-items:center;display:flex;flex-direction:row;gap:.5rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child input{flex-grow:1;padding:0 .5rem}.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child button,.treb-main.treb-main .treb-toolbar .treb-color-chooser>div:last-child input{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px;height:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch button,.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches button{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:2px;height:18px;margin:0;padding:0;width:18px}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch .treb-default-color:before,.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches .treb-default-color:before{background:currentColor;content:"";display:block;height:100%;mask-image:var(--icon-x);-webkit-mask-image:var(--icon-x);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:24px 24px;-webkit-mask-size:24px 24px;opacity:.7;position:relative;width:100%}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-default-swatch{align-items:center;display:grid;gap:.5rem;grid-template-columns:auto 1fr}.treb-main.treb-main .treb-toolbar .treb-color-chooser .treb-swatches{display:grid;gap:.5rem;grid-template-columns:repeat(10,1fr)}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));font:inherit;height:10rem;line-height:1.5;margin:.5rem;padding:.25rem;resize:both}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea+div{align-items:center;display:flex;flex-direction:row;gap:.5rem;justify-content:center;padding:0 0 .5rem}.treb-main.treb-main .treb-toolbar .treb-comment-box textarea+div button{border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-radius:3px}.treb-main.treb-main .treb-toolbar .treb-font-scale{padding-left:2em;text-align:right;width:5em}.treb-main.treb-main .treb-toolbar [composite][font-scale]{position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon{border-radius:3px;left:.5em;line-height:1;opacity:.9;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after,.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{content:"A";position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{font-size:1.2em}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after{font-size:.9em;left:-.125em}.treb-main.treb-main{--treb-font-stack-default-size:14px;--treb-font-stack-calibri-size:16px;--treb-font-stack-tscu-comic-size:16px;--treb-font-stack-helvetica-neue-size:13px;--treb-font-stack-cambria-size:16px;--treb-font-stack-sitka-text-variant:lining-nums tabular-nums}.treb-main.treb-main.treb-ua-osx{--treb-font-stack-system-ui-size:10pt}.treb-main.treb-main .treb-font-stack-default{font-family:calibri,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif"}.treb-main.treb-main .treb-font-stack-transitional{font-family:Charter,Bitstream Charter,Cambria,serif}.treb-main.treb-main .treb-font-stack-old-style{font-family:Iowan Old Style,Palatino Linotype,URW Palladio L,P052,serif}.treb-main.treb-main .treb-font-stack-handwritten{font-family:Segoe Print,Bradley Hand,Chilanka,TSCu_Comic,casual,cursive}.treb-main.treb-main .treb-font-stack-industrial{font-family:Bahnschrift,DIN Alternate,Franklin Gothic Medium,Nimbus Sans Narrow,sans-serif-condensed,sans-serif}.treb-main.treb-main .treb-font-stack-monospace{font-family:ui-monospace,Cascadia Code,Source Code Pro,Menlo,Consolas,DejaVu Sans Mono,monospace}.treb-main.treb-main .treb-font-stack-ui{font-family:system-ui,sans-serif}.treb-main.treb-main{all:revert;box-sizing:border-box;color:inherit;color-scheme:var(--treb-color-scheme,unset);display:grid;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif");font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:14px;font-style:normal;font-weight:400;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr);height:100%;line-height:normal;position:relative;text-align:start;width:100%}.treb-main.treb-main a,.treb-main.treb-main button,.treb-main.treb-main div,.treb-main.treb-main input,.treb-main.treb-main li,.treb-main.treb-main ol,.treb-main.treb-main svg,.treb-main.treb-main textarea,.treb-main.treb-main ul{all:revert;box-sizing:border-box;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif")}.treb-main.treb-main button,.treb-main.treb-main input{color:inherit;font:inherit}.treb-main.treb-main *{box-sizing:border-box}.treb-main.treb-main [contenteditable]{-webkit-user-modify:read-write;-moz-user-modify:read-write}.treb-main.treb-main[animate] .treb-layout-header{transition:height var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-header{grid-column:1/3;grid-row:1;height:1px;opacity:0}.treb-main.treb-main[toolbar] .treb-layout-header{height:42px;opacity:1}.treb-main.treb-main[dialog] .treb-layout-header,.treb-main.treb-main[dialog]>*{opacity:.6}.treb-main.treb-main[dialog] .treb-dialog-mask{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-layout-spreadsheet{display:flex;flex-direction:row;gap:1em;grid-column:1;grid-row:2;position:relative;transition:opacity .2s ease;z-index:5}.treb-main.treb-main .treb-views.treb-can-revert .treb-view .treb-revert-indicator{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-view{display:grid;flex:1 1 0px;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;position:relative}.treb-main.treb-main .treb-view .treb-spreadsheet-backdrop{box-shadow:0 4px 6px -4px rgba(0,0,0,.4);grid-column:1;grid-row:2;z-index:2}.treb-main.treb-main .treb-view .treb-spreadsheet-body{position:relative;z-index:4}.treb-main.treb-main .treb-view .treb-spreadsheet-footer{position:relative;z-index:5}.treb-main.treb-main .treb-view .treb-layout-resize-handle,.treb-main.treb-main .treb-view .treb-revert-indicator{display:none}.treb-main.treb-main .treb-view:first-of-type .treb-revert-indicator{align-self:start;border-color:orange transparent transparent orange;border-style:solid;border-width:.5em;display:block;grid-area:2/1/3/2;height:1rem;justify-self:start;opacity:0;overflow:hidden;pointer-events:none;position:relative;transition:opacity .125s ease;width:1rem;z-index:20}.treb-main.treb-main .treb-view:last-of-type .treb-layout-resize-handle{align-self:end;border-bottom:.5rem solid var(--treb-resize-handle-color,#0059b9);border-left:.5rem solid transparent;border-right:.5rem solid var(--treb-resize-handle-color,#0059b9);border-top:.5rem solid transparent;cursor:nw-resize;display:block;grid-area:2/1/3/2;height:1rem;justify-self:end;width:1rem;z-index:20}.treb-main.treb-main[animate] .treb-layout-sidebar{transition:width var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-sidebar{align-items:center;display:flex;flex-direction:column;gap:.75rem;grid-column:2;grid-row:2;justify-content:flex-start;overflow:hidden;padding-top:3rem;width:2.5rem;width:3rem}.treb-main.treb-main[collapsed] .treb-layout-sidebar{opacity:0;width:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button{background:var(--treb-toolbar-button-background,#fff);border-bottom-right-radius:0;border-color:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-right-color:var(--treb-toolbar-button-background,transparent);border-top-right-radius:0;right:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button:after{mask-image:var(--icon-chevron-left);-webkit-mask-image:var(--icon-chevron-left)}.treb-main.treb-main .treb-layout-sidebar>button,.treb-main.treb-main .treb-toggle-sidebar-button{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-layout-sidebar>button:after,.treb-main.treb-main .treb-toggle-sidebar-button:after{background:#ccc;content:"";display:block;height:24px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;transition:background-color .1s ease;width:24px}.treb-main.treb-main .treb-layout-sidebar>button[data-can-revert=false],.treb-main.treb-main .treb-toggle-sidebar-button[data-can-revert=false]{display:none}.treb-main.treb-main .treb-layout-sidebar>button:hover:after,.treb-main.treb-main .treb-toggle-sidebar-button:hover:after{background:#666}.treb-main.treb-main .treb-layout-sidebar>button[data-command=recalculate],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=recalculate]{--icon:var(--icon-reset)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=toggle-toolbar],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=toggle-toolbar]{--icon:var(--icon-toolbar)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=revert],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=revert]{--icon:var(--icon-revert)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=export-xlsx],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=export-xlsx]{--icon:var(--icon-export)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=about],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=about]{--icon:var(--icon-about)}.treb-main.treb-main .treb-toggle-sidebar-button{align-items:center;background:transparent;border:1px solid transparent;border-radius:12px;bottom:6rem;display:flex;height:24px;justify-content:center;margin:0;padding:0;position:absolute;right:.5rem;right:calc(1.5rem - 12px);width:24px;z-index:39}.treb-main.treb-main .treb-toggle-sidebar-button:after{height:12px;mask-image:var(--icon-chevron-right);-webkit-mask-image:var(--icon-chevron-right);width:12px}.treb-main.treb-main .treb-resize-rect{border:1px dotted var(--treb-resize-frame-color,blue);display:block;height:100%;left:0;position:fixed;top:0;width:100%;z-index:9998}.treb-main.treb-main .treb-resize-mask{height:100vh;left:0;position:fixed;top:0;width:100vw;z-index:9999}treb-spreadsheet{display:block;overflow:hidden;position:relative}.treb-default-size{height:550px;width:800px}`;var gn='<div class="treb-main treb-theme"><div class="treb-layout-header treb-animate"><div class="treb-toolbar"></div></div><div class="treb-dialog-mask"><div data-bind="dialog" class="treb-embed-dialog"><div data-bind="left"><a href="https://treb.app" target="_blank"><div class="treb-icon-64"></div></a></div><div data-bind="middle"><div data-bind="title" class="treb-embed-dialog-title"></div><div data-bind="message" class="treb-embed-dialog-message"></div><div data-bind="about" class="treb-embed-dialog-body"></div></div><button type="button" data-title="close_dialog" data-bind="close" class="treb-close-box"><svg viewBox="0 0 16 16"><path d="M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"/><path d="M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"/></svg></button></div></div><div class="treb-layout-spreadsheet treb-views"><template class="treb-view-template"><div class="treb-view"><div class="treb-formula-bar notranslate" hidden><div class="treb-address-label"><div></div></div><button class="treb-insert-function-button" data-title="insert_function" data-conditional="insert-function">\u{1D453}<small>(x)</small></button><div class="treb-editor-container"><div contenteditable="true"></div></div></div><div class="treb-spreadsheet-backdrop"></div><div class="treb-spreadsheet-body" role="grid"><div class="treb-grid" tabindex="-1"><div class="treb-overlay-container notranslate" translate="no"><div class="treb-overlay-inset"><div class="treb-overlay-editor" contenteditable tabindex="-1" spellcheck="true" role="gridcell"></div></div></div></div></div><div class="treb-spreadsheet-footer" hidden><button class="treb-delete-tab" data-title="delete_sheet" data-command="delete-tab" data-conditional="delete-tab"><svg tabindex="-1" viewbox="0 0 16 16"><path d="M4,4 L12,12 M12,4 L4,12"/></svg></button><div class="treb-spreadsheet-tab-container"><ol class="treb-spreadsheet-tabs" role="tablist"></ol></div><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" data-title="add_sheet">+</button><div class="treb-stats-panel"></div><div class="treb-scale-control" data-conditional="scale-control"></div></div><div class="treb-layout-resize-handle" data-conditional="resize"></div><div class="treb-revert-indicator" data-command="revert-indicator" data-title="document_modified"></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" data-title="recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" data-title="toggle_toolbar"></button> <button data-command="export-xlsx" data-conditional="export" data-title="export"></button> <button data-command="revert" data-conditional="revert" data-title="revert"></button> <button data-command="about" data-title="about"></button></div><button class="treb-toggle-sidebar-button" data-title="toggle_sidebar"></button></div>';var vn='<div class="treb-menu" title="File menu" file-menu><button data-icon="file-menu" menu-target></button><div><button data-command="reset">New document</button><div separator></div><button data-command="import-file">Open file...</button> <button data-command="save-json">Save JSON</button><div separator xlsx-support></div><button data-command="export-xlsx" xlsx-support>Export XLSX</button></div></div><div composite narrow><button data-command="justify-left" data-target="justify" title="Left-align text"></button><div class="treb-menu"><button dropdown title="Text justify options"></button><div class="treb-icon-buttons" data-replace="justify"><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div></div></div><div composite narrow><button data-command="align-top" data-target="align" title="Align to top"></button><div class="treb-menu"><button dropdown title="Text align options"></button><div class="treb-icon-buttons" data-replace="align"><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div></div></div><div class="group" wide><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div><div class="group" wide><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div><div class="group" wide indent-group><button data-command="outdent" title="Decrease indent"></button> <button data-command="indent" title="Incrase indent"></button></div><div class="group"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-inactive-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-inactive-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-inactive-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-inactive-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-inactive-title="Comment" data-active-title="Update comment"></button><div class="treb-comment-box"><textarea></textarea><div><button data-command="clear-comment">Clear</button> <button data-command="update-comment">Save</button></div></div></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown title="Border options"></button><div class="treb-icon-buttons" data-replace="border"><button data-command="border-top" title="Top border"></button> <button data-command="border-left" title="Left border"></button> <button data-command="border-right" title="Right border"></button> <button data-command="border-bottom" title="Bottom border"></button> <button data-command="border-double-bottom" title="Double bottom border"></button> <button data-command="border-outside" title="Outside borders"></button> <button data-command="border-all" title="All borders"></button> <button data-command="border-none" title="Clear borders"></button><div separator></div><div class="treb-menu treb-color-menu treb-submenu" data-color-command="border-color" data-replace-color="border" title="Border color" data-default-color-text="Default border color"><button data-icon="palette" data-color-bar="border" data-color="{}"></button></div></div></div></div><div composite><button data-command="fill-color" data-color-bar="fill" data-color="{}" title="Fill color"></button><div class="treb-menu treb-color-menu" data-color-command="fill-color" data-replace-color="fill" data-default-color-text="No fill"><button dropdown title="Color options"></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></div><div class="treb-caption">No color</div><div class="treb-default-swatch"><button class="treb-default-color" data-command="set-color" data-color="{}"></button> <span class="treb-default-color-label" data-command="set-color" data-color="{}">...</span></div><div class="treb-caption">Other colors</div><div class="treb-swatches"></div><div><input placeholder="New color" class="treb-color-input"> <button data-command="set-color" data-color=""><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg></button></div></div></div></div><div composite><button data-command="text-color" data-color-bar="text" data-color="{}" title="Text color"></button><div class="treb-menu treb-color-menu" data-color-command="text-color" data-replace-color="text" data-default-color-text="Default text color"><button dropdown title="Color options"></button></div></div><div composite font-scale><div class="treb-font-scale-icon"></div><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown title="Font scale options"></button><div><button data-command="font-scale" data-scale="0.8">0.80</button> <button data-command="font-scale" data-scale="0.9">0.90</button> <button data-command="font-scale" data-scale="1.0">1.00</button> <button data-command="font-scale" data-scale="1.1">1.10</button> <button data-command="font-scale" data-scale="1.25">1.25</button> <button data-command="font-scale" data-scale="1.5">1.50</button> <button data-command="font-scale" data-scale="2.0">2.00</button></div></div></div><div composite font-stack><button class="treb-font-stack" data-command="font-stack" data-font-stack="" title="Font stack"></button><div class="treb-menu"><button dropdown title="Font stack options"></button><div><button data-command="font-stack" data-font-stack="default"></button> <button data-command="font-stack" data-font-stack="transitional"></button> <button data-command="font-stack" data-font-stack="monospace"></button> <button data-command="font-stack" data-font-stack="handwritten"></button> <button data-command="font-stack" data-font-stack="ui"></button></div></div></div><div composite><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown title="Number formats"></button><div class="treb-number-format-menu"></div></div></div><div class="treb-split"><button data-command="decrease-precision" title="Decrease precision"></button> <button data-command="increase-precision" title="Increase precision"></button></div><div class="treb-menu"><button data-icon="layout" title="Rows & columns"></button><div><button data-command="insert-row">Insert row</button> <button data-command="insert-column">Insert column</button> <button data-command="delete-row">Delete row</button> <button data-command="delete-column">Delete column</button><div separator add-remove-sheet></div><button data-command="insert-sheet" add-remove-sheet>Add sheet</button> <button data-command="delete-sheet" add-remove-sheet>Delete sheet</button></div></div><div composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown title="Chart options"></button><div class="treb-icon-buttons" data-replace="annotation"><button data-command="insert-column-chart" title="Insert column chart"></button> <button data-command="insert-donut-chart" title="Insert donut chart"></button> <button data-command="insert-bar-chart" title="Insert bar chart"></button> <button data-command="insert-line-chart" title="Insert line chart"></button><div separator></div><button data-command="insert-image" title="Insert image"></button></div></div></div><button data-command="recalculate" title="Recalculate" recalculate-button></button>';var yn={close_dialog:"Close dialog",insert_function:"Insert function...",delete_sheet:"Delete current sheet",add_sheet:"Add sheet",document_modified:"This document has been modified from the original version.",recalculate:"Recalculate",toggle_toolbar:"Toggle toolbar",export:"Export as XLSX",revert:"Revert to original version",about:"What's this?",toggle_sidebar:"Toggle sidebar"},Ve=class{root;sheet;border_color;color_bar_elements={};replace_targets={};layout_element;views;revert_button;revert_state=!1;toolbar_controls={};swatch_lists={};DOM;constructor(e){typeof e=="string"&&(e=document.querySelector(e)),this.DOM=le.GetInstance(e?.ownerDocument),this.DOM.view&&e instanceof this.DOM.view.HTMLElement&&(this.root=e,this.DOM.doc?.head.querySelector("style[treb-stylesheet]")||this.DOM.doc?.head.prepend(this.DOM.Create("style",void 0,void 0,{text:fn,attrs:{"treb-stylesheet":""}})))}CoerceAttributeValue(e){if(e===null||e.toString().toLowerCase()==="true"||e==="")return!0;if(e.toLowerCase()==="false")return!1;{let t=Number(e);if(!isNaN(t))return t}return e||""}ParseOptionAttributes(){let e={};if(this.root){let t=this.root.getAttributeNames();for(let r of t){switch(r){case"class":case"style":case"id":continue;case"data-options":case"options":{let o=(this.root.getAttribute(r)||"").split(",");for(let i of o){let s=i.split(/=/);s.length===1?e[s[0]]=!0:e[s[0]]=this.CoerceAttributeValue(s[1])}}continue;case"data-treb":continue;case"inline-document":continue;case"src":e.document=this.root.getAttribute("src")||void 0;continue}e[r.replace(/-/g,"_")]=this.CoerceAttributeValue(this.root.getAttribute(r))}}return{...e}}AttachElement(e={}){if(e={...this.ParseOptionAttributes(),...e},this.root){if(!e.headless){let t=this.root.getBoundingClientRect();(!t.width||!t.height)&&this.root.classList.add("treb-default-size")}if(this.root.hasAttribute("inline-document")){let t=this.root.getAttribute("inline-document")||"";for(let r of Array.from(this.root.children))if(this.DOM.view&&r instanceof this.DOM.view.HTMLScriptElement&&r.type==="application/json"){let n=r.getAttribute("name")||"";if(n===t||!n&&t==="true"){let o=r.textContent;if(o)try{e.inline_document=JSON.parse(o)}catch(i){console.error(i)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=gn,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new dt(e),this.root&&this.CreateLayout(this.sheet,this.root)}CreateLayout(e,t){new ResizeObserver(()=>e.Resize()).observe(t),this.layout_element=t.querySelector(".treb-main");let n=t.querySelector(".treb-toggle-sidebar-button");if(n&&this.layout_element){let c=this.layout_element;n.addEventListener("click",()=>{let u=c.getAttribute("collapsed");typeof u=="string"&&(u===""||u==="true")?c.removeAttribute("collapsed"):c.setAttribute("collapsed","")})}(e.options.toolbar==="show"||e.options.toolbar==="show-narrow")&&this.layout_element?.setAttribute("toolbar",""),e.options.collapsed&&this.layout_element?.setAttribute("collapsed","");let o=t.querySelector("[data-command=revert-indicator]");this.DOM.view&&o instanceof this.DOM.view.HTMLElement&&(e.options.revert_indicator?o.addEventListener("click",()=>{e.HandleToolbarMessage({command:"revert-indicator"})}):o.style.display="none"),t.querySelector(".treb-layout-sidebar")?.addEventListener("click",c=>{let u=c.target;u.dataset.command&&(u.dataset.command==="toggle-toolbar"?this.ToggleToolbar():e.HandleToolbarMessage({command:u.dataset.command}))}),e.options.toolbar&&this.AttachToolbar(e,t);let s={"table-button":!!e.options.table_button,revert:!!e.options.revert_button,toolbar:!!e.options.toolbar,export:!!e.options.export,"insert-function":!!e.options.insert_function_button,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[c,u]of Object.entries(s))if(!u){let d=this.layout_element.querySelectorAll(`[data-conditional=${c}]`);for(let m of Array.from(d))m.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let c={width:0,height:0},u={x:0,y:0},d={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let m,b,p=t.querySelector(".treb-layout-resize-handle"),h=()=>y(),f=(x=>{x.buttons===0?y():(d.x=x.screenX-u.x,d.y=x.screenY-u.y,b&&(b.style.width=c.width+d.x+"px",b.style.height=c.height+d.y+"px"))}),y=()=>{if(d.x||d.y){let x=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=x.width+d.x+"px"),t.style.height=x.height+d.y+"px"}m&&(m.removeEventListener("mouseup",h),m.removeEventListener("mousemove",f),m.parentElement?.removeChild(m),m=void 0),b?.parentElement?.removeChild(b),b=void 0};p.addEventListener("mousedown",x=>{x.stopPropagation(),x.preventDefault();let v=t.querySelector(".treb-main");b=this.DOM.Div("treb-resize-rect",v),m=this.DOM.Div("treb-resize-mask",v,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:h,mousemove:f}}),u.x=x.screenX,u.y=x.screenY,d.x=0,d.y=0;let w=this.views?.querySelectorAll(".treb-spreadsheet-body"),g=Array.from(w||[]).map(C=>C.getBoundingClientRect());if(g.length){let C=JSON.parse(JSON.stringify(g.shift()));for(let L of g)C.top=Math.min(L.top,C.top),C.left=Math.min(L.left,C.left),C.right=Math.max(L.right,C.right),C.bottom=Math.max(L.bottom,C.bottom);let U=C.right-C.left,V=C.bottom-C.top;b.style.top=C.top+"px",b.style.left=C.left+"px",b.style.width=U+"px",b.style.height=V+"px",c.width=U,c.height=V}})}let l=Array.from(this.layout_element.querySelectorAll("[data-title]"));for(let c of l)if(c instanceof HTMLElement){if(c.dataset.activeTitle)continue;c.dataset.title&&yn[c.dataset.title]&&(c.title=yn[c.dataset.title])}setTimeout(()=>this.layout_element?.setAttribute("animate",""),250)}ToggleToolbar(){if(this.layout_element){let e=this.layout_element.getAttribute("toolbar");typeof e=="string"&&(e===""||e==="true")?this.layout_element.removeAttribute("toolbar"):this.layout_element.setAttribute("toolbar","")}}UpdateSelectionStyle(e,t,r){let n=e.selection_state;r.value="";for(let l of Object.values(this.toolbar_controls))l&&(l.removeAttribute("active"),l.dataset.inactiveTitle&&(l.title=l.dataset.inactiveTitle));let o=l=>{l&&(l.setAttribute("active",""),l.dataset.activeTitle&&(l.title=l.dataset.activeTitle))};if(n.comment&&(o(this.toolbar_controls.comment),r.value=n.comment),n.style?.locked&&o(this.toolbar_controls.locked),n.frozen&&o(this.toolbar_controls.freeze),n.style?.wrap&&o(this.toolbar_controls.wrap),this.toolbar_controls.table&&(n.table?(o(this.toolbar_controls.table),this.toolbar_controls.table.dataset.command="remove-table"):this.toolbar_controls.table.dataset.command="insert-table"),this.toolbar_controls.merge&&(n.merge?(o(this.toolbar_controls.merge),this.toolbar_controls.merge.dataset.command="unmerge-cells"):this.toolbar_controls.merge.dataset.command="merge-cells"),this.toolbar_controls.stack)if(n.style?.font_face)if(n.style.font_face.startsWith("stack:")){let l=n.style.font_face.substring(6);this.toolbar_controls.stack.textContent=Pe[l]||"",this.toolbar_controls.stack.dataset.fontStack=l}else this.toolbar_controls.stack.textContent="",this.toolbar_controls.stack.dataset.fontStack="";else this.toolbar_controls.stack.textContent=Pe.default||"",this.toolbar_controls.stack.dataset.fontStack="default";let i=this.toolbar_controls.format;i&&(n.style?.number_format?i.value=R.SymbolicName(n.style.number_format)||n.style.number_format:i.value="General");let s=this.toolbar_controls.scale;switch(s&&(s.value=e.FormatNumber(n.relative_font_size||1,"0.00")),n.style?.horizontal_align){case"left":o(this.toolbar_controls.left);break;case"center":o(this.toolbar_controls.center);break;case"right":o(this.toolbar_controls.right);break}switch(n.style?.vertical_align){case"top":o(this.toolbar_controls.top);break;case"middle":o(this.toolbar_controls.middle);break;case"bottom":o(this.toolbar_controls.bottom);break}}UpdateDocumentStyles(e,t){{let s=this.DOM.Fragment(),l=e.document_styles.theme_colors.length,c=["Background","Text","Background","Text","Accent"];if(l){let b=e.document_styles.theme_colors[0].length;for(let p=0;p<b;p++)for(let h=0;h<l;h++){let f=e.document_styles.theme_colors[h][p],y=`background: ${f.resolved};`,x=c[h]||c[4];er(f.color)&&f.color.tint?x+=` (${(f.color.tint>0?"+":"")+f.color.tint*100}%)`:h===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",f.resolved):h===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",f.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",f.resolved)),this.DOM.Create("button",void 0,s,{attrs:{style:y,title:x},data:{command:"set-color",color:JSON.stringify(f.color)}})}}this.swatch_lists.theme?.replaceChildren(s),s=this.DOM.Fragment();let u=["Black","White","Gray","Red","Orange","Yellow","Green","Blue","Indigo","Violet"],d=u.map(b=>b.toLowerCase()),m=e.document_styles.colors.filter(b=>!d.includes(b.toLowerCase()));for(let b of[...u,...m]){let p=`background: ${b.toLowerCase()};`;this.DOM.Create("button",void 0,s,{attrs:{style:p,title:b},data:{command:"set-color",color:JSON.stringify({text:b.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(s)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],n=["Timestamp","Long Date","Short Date"];for(let s of e.document_styles.number_formats){if(R.SymbolicName(R.Translate(s)))continue;R.Get(s).date_format?n.push(s):r.push(s)}let o=s=>this.DOM.Create("button",void 0,void 0,{text:s,data:{format:s,command:"number-format"}}),i=this.DOM.Fragment();i.append(...r.map(s=>o(s))),i.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),i.append(...n.map(s=>o(s))),t.textContent="",t.append(i)}UpdateRevertState(e){let t=e.can_revert;this.revert_state!==t&&(this.revert_state=t,(this.revert_button||e.options.revert_indicator)&&(this.revert_state?this.views?.classList.add("treb-can-revert"):this.views?.classList.remove("treb-can-revert"),this.revert_button&&(this.revert_button.dataset.canRevert=t?"true":"false",t?(this.revert_button.classList.remove("sidebar-disabled"),this.revert_button.title="Revert to original version"):(this.revert_button.classList.add("sidebar-disabled"),this.revert_button.title="This is the original version of the document"))))}ReplaceTemplate(e,t,r=!0){let n=e.querySelector(t);if(n&&n.parentElement){for(let o of Array.from(n.content.children))n.parentElement.insertBefore(o,n);r&&n.parentElement.removeChild(n)}else console.warn("template not found",t)}AttachToolbar(e,t){let r=t.querySelector(".treb-layout-header"),n=t.querySelector(".treb-toolbar");n.innerHTML=vn;let o=[];if(e.options.toolbar==="narrow"||e.options.toolbar==="show-narrow"?o.push(...Array.from(n.querySelectorAll("[wide]"))):o.push(...Array.from(n.querySelectorAll("[narrow]"))),e.options.file_menu||o.push(n.querySelector("[file-menu]")),e.options.indent_buttons||o.push(n.querySelector("[indent-group]")),e.options.font_scale||o.push(n.querySelector("[font-scale]")),!e.options.font_stack)o.push(n.querySelector("[font-stack]"));else{let v=n.querySelectorAll("[font-stack] button[data-font-stack]");for(let w of v)if(w.dataset.fontStack){let g=Pe[w.dataset.fontStack];w.textContent=g||""}}e.options.chart_menu||o.push(n.querySelector("[chart-menu]")),e.options.freeze_button||o.push(n.querySelector("[freeze-button]")),e.options.table_button||o.push(n.querySelector("[table-button]")),!e.options.add_tab&&!e.options.delete_tab&&o.push(...Array.from(n.querySelectorAll("[add-remove-sheet]"))),e.options.toolbar_recalculate_button||o.push(n.querySelector("[recalculate-button]"));for(let v of o)v&&v.parentElement?.removeChild(v);let i=n.querySelector(".treb-color-chooser"),s=n.querySelector(".treb-comment-box textarea");for(let[v,w]of Object.entries({top:"[wide] [data-command=align-top]",middle:"[wide] [data-command=align-middle]",bottom:"[wide] [data-command=align-bottom]",left:"[wide] [data-command=justify-left]",right:"[wide] [data-command=justify-right]",center:"[wide] [data-command=justify-center]",wrap:"[data-command=wrap-text]",merge:"[data-id=merge]",comment:"[data-icon=comment]",locked:"[data-command=lock-cells]",freeze:"[data-command=freeze-panes]",table:"[data-icon=table]",format:"input.treb-number-format",scale:"input.treb-font-scale",stack:"button.treb-font-stack"})){let g=n.querySelector(w);g&&(this.toolbar_controls[v]=g)}let l=i.querySelectorAll(".treb-swatches");this.swatch_lists={theme:l[0],other:l[1]};let c=t.querySelector("[data-command=increase-precision");c&&(c.textContent=this.sheet?.FormatNumber(0,"0.00")||""),c=t.querySelector("[data-command=decrease-precision"),c&&(c.textContent=this.sheet?.FormatNumber(0,"0.0")||""),c=n.querySelector("[data-command=update-comment]"),s.addEventListener("keydown",v=>{v.key==="Enter"&&(v.shiftKey||v.ctrlKey)&&c.click()});for(let v of["border","annotation","align","justify"])this.replace_targets[v]=n.querySelector(`[data-target=${v}`);for(let v of["fill","text","border"])this.color_bar_elements[v]=n.querySelector(`[data-color-bar=${v}]`);n.addEventListener("click",v=>{let w=v.target,g={format:w.dataset.format,scale:w.dataset.scale,font_stack:w.dataset.fontStack},C=w?.dataset.command;if(C){let U=w.parentElement?.dataset.replace;if(U){let V=this.replace_targets[U];V&&(V.dataset.command=C,V.title=w.title||"")}switch(/^border-/.test(C)&&(g.color=this.border_color||{}),C){case"text-color":case"fill-color":g.color={};try{g.color=JSON.parse(w.dataset.color||"{}")}catch(V){console.error(V)}break;case"set-color":C=i.dataset.colorCommand||"",g.color={};try{g.color=JSON.parse(w.dataset.color||"{}")}catch(V){console.error(V)}if(C==="border-color"&&(this.border_color=g.color),i.dataset.target){let V=this.color_bar_elements[i.dataset.target];V&&(V.style.setProperty("--treb-color-bar-color",w.style.backgroundColor),V.dataset.color=w.dataset.color||"{}")}break;case"update-comment":g.comment=s.value;break}e.HandleToolbarMessage({command:C,...g})}});let u=(v,w)=>{let g=n.querySelector(v);if(g){let C="";g.addEventListener("focusin",()=>C=g.value),g.addEventListener("keydown",U=>{switch(U.key){case"Escape":g.value=C,e.Focus();break;case"Enter":w(g.value)||(g.value=C,e.Focus());break;default:return}U.stopPropagation(),U.preventDefault()})}};u("input.treb-number-format",v=>v?(e.HandleToolbarMessage({command:"number-format",format:v}),!0):!1),u("input.treb-font-scale",v=>{let w=Number(v);return!w||isNaN(w)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:w}),!0)});let d=i.querySelector("input"),m=i.querySelector("input + button");d.addEventListener("input",v=>{if(v instanceof InputEvent&&v.isComposing)return;m.style.background=d.value||"";let w=m.style.backgroundColor||"#fff",g=nr.MeasureColor(w),C=tr.RGBToHSL(g[0],g[1],g[2]);m.style.color=C.l>.5?"#000":"#fff",m.dataset.color=JSON.stringify(m.style.backgroundColor?{text:m.style.backgroundColor}:{})}),d.addEventListener("keydown",v=>{v.key==="Enter"&&(v.stopPropagation(),v.preventDefault(),m.click())}),/firefox/i.test(navigator.userAgent)?r.addEventListener("scroll",()=>{this.DOM.view&&this.DOM.doc?.activeElement instanceof this.DOM.view.HTMLElement&&this.DOM.doc.activeElement?.blur()}):r.addEventListener("scroll",()=>e.Focus());let b=!1,p=v=>{v.key==="Escape"&&(v.stopPropagation(),v.preventDefault(),Promise.resolve().then(()=>e.Focus()))},h=v=>{if(b){if(v.relatedTarget instanceof Node&&n.contains(v.relatedTarget))return;n.removeEventListener("keydown",p),n.removeEventListener("focusout",h),b=!1}},f=v=>{let w=v.target,g=w?.parentElement;if(w?.classList.contains("treb-menu")){g=w;for(let C of Array.from(g.children))if(C.tagName==="BUTTON"){w=C;break}}else if(!g?.classList.contains("treb-menu"))return;if(w&&g){if(b||(n.addEventListener("focusout",h),n.addEventListener("keydown",p),b=!0),g.dataset.colorCommand){i.querySelector(".treb-default-color")?.setAttribute("title",g.dataset.defaultColorText||"Default color");let j=i.querySelector(".treb-default-color-label");j&&(j.textContent=g.dataset.defaultColorText||"Default color"),g.appendChild(i),i.dataset.colorCommand=g.dataset.colorCommand,i.dataset.target=g.dataset.replaceColor||""}let C=g.querySelector("div"),U=r.getBoundingClientRect(),V=w.getBoundingClientRect(),{left:L}=V,M=g.parentElement;M?.hasAttribute("composite")&&(L=M.firstElementChild.getBoundingClientRect().left);let A=C.getBoundingClientRect();g.classList.contains("treb-submenu")?(C.style.top=V.top-A.height/2+"px",L+V.width+6+A.width>U.right?C.style.left=L-6-A.width+"px":C.style.left=L+V.width+6+"px"):(C.style.top=V.bottom+"px",L+A.width>U.right-6?C.style.left=V.right-A.width+"px":C.style.left=L+"px");let G=C.querySelector("textarea");G&&requestAnimationFrame(()=>G.focus())}},y=this.root?.querySelector(".treb-number-format-menu");y&&(this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s),e.Subscribe(v=>{switch(v.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s),this.UpdateRevertState(e);break;case"theme-change":this.UpdateDocumentStyles(e,y),this.UpdateSelectionStyle(e,n,s);break;case"annotation-selection":case"selection":this.UpdateSelectionStyle(e,n,s);break}}));let x=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(n.addEventListener("focusin",v=>{f(v)}),x){let v=Array.from(n.querySelectorAll(".treb-menu"));for(let w of v)w.tabIndex=0;n.addEventListener("mousedown",w=>{f(w)})}}};var mt=class{version="36.1.4";CreateSpreadsheet(e){let t=e.container,r=new Ve(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},aa=new mt;if(typeof HTMLElement<"u"){class a extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new Ve(this)}connectedCallback(){this.instance.AttachElement()}}typeof customElements<"u"&&(customElements.get("treb-spreadsheet")?console.info("custom element treb-spreadsheet is already defined."):customElements.define("treb-spreadsheet",a))}export{aa as TREB,mt as TREBGlobal};