@trebco/treb 28.2.3 → 28.3.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.
- package/dist/treb-spreadsheet-light.mjs +8 -8
- package/dist/treb-spreadsheet.mjs +10 -10
- package/dist/treb.d.ts +11 -5
- package/package.json +1 -1
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +3 -3
- package/treb-embed/src/custom-element/treb-global.ts +2 -2
- package/treb-embed/src/embedded-spreadsheet.ts +17 -4
- package/treb-grid/src/types/grid.ts +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/*! TREB v28.
|
|
2
|
-
var Zi=Object.defineProperty;var Bi=(c,e)=>{for(var t in e)Zi(c,t,{get:e[t],enumerable:!0})};var N=c=>c!==null&&typeof c=="object"&&"row"in c&&"column"in c,Pr=c=>c!==null&&typeof c=="object"&&"start"in c&&N(c.start)&&"end"in c&&N(c.end),y=class c{start_;end_;constructor(e,t=e,r=!1){this.end_=this.PatchNull(t),this.start_=this.PatchNull(e),r&&this.Normalize()}static FromColumn(e){return new c({row:1/0,column:e})}static FromRow(e){return new c({row:e,column:1/0})}static ColumnToLabel(e){let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}static CellAddressToLabel(e,t=!1){return(t?`${e.sheet_id||0}!`:"")+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new c(e.start,e.end);for(let i of t)i&&(r.ConsumeAddress(i.start),r.ConsumeAddress(i.end));return r}static Bleed(e,t=1){return new c({row:Math.max(0,e.start.row-t),column:Math.max(0,e.start.column-t),sheet_id:e.start.sheet_id},{row:e.end.row+t,column:e.end.column+t})}static PatchArea(e,t){let{before_column:r,column_count:i,before_row:n,row_count:a}=t,s=new c(e.start,e.end),o=e.start.sheet_id;if(i&&r<=s.end.column){if(i>0)r<=s.start.column?s.Shift(0,i):r>s.start.column&&r<=s.end.column?s.ConsumeAddress({row:s.end.row,column:s.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(s));else if(i<0)if(r-i<=s.start.column)s.Shift(0,i);else{if(r<=s.start.column&&r-i>s.end.column)return!1;if(r<=s.start.column){let l=r-i-1;s=new c({row:s.start.row,column:l+1+i,sheet_id:o},{row:s.end.row,column:s.end.column+i})}else r<=s.end.column?r-i-1>=s.end.column?s=new c({row:s.start.row,column:s.start.column,sheet_id:o},{row:s.end.row,column:r-1}):s=new c({row:s.start.row,column:s.start.column,sheet_id:o},{row:s.end.row,column:s.start.column+s.columns+i-1}):console.warn("AA X case 2",r,i,JSON.stringify(s))}}if(a&&n<=s.end.row){if(a>0)n<=s.start.row?s.Shift(a,0):n>s.start.row&&n<=s.end.row?s.ConsumeAddress({row:s.end.row+a,column:s.end.column}):console.warn("AA X case 3",n,a,JSON.stringify(s));else if(a<0)if(n-a<=s.start.row)s.Shift(a,0);else{if(n<=s.start.row&&n-a>s.end.row)return!1;if(n<=s.start.row){let l=n-a-1;s=new c({column:s.start.column,row:l+1+a,sheet_id:o},{column:s.end.column,row:s.end.row+a})}else n<=s.end.row?n-a-1>=s.end.row?s=new c({column:s.start.column,row:s.start.row,sheet_id:o},{column:s.end.column,row:n-1}):s=new c({column:s.start.column,row:s.start.row,sheet_id:o},{column:s.end.column,row:s.start.row+s.rows+a-1}):console.warn("AA X case 4",n,a,JSON.stringify(s))}}return s}get start(){return{...this.start_}}set start(e){this.start_=e}get end(){return{...this.end_}}set end(e){this.end_=e}get rows(){return this.start_.row===1/0||this.end_.row===1/0?1/0:this.end_.row-this.start_.row+1}get columns(){return this.start_.column===1/0||this.end_.column===1/0?1/0:this.end_.column-this.start_.column+1}get count(){return this.rows*this.columns}get entire_sheet(){return this.entire_row&&this.entire_column}get entire_column(){return this.start_.row===1/0}get entire_row(){return this.start_.column===1/0}PatchNull(e){let t={...e};return t.row===null&&(t.row=1/0),t.column===null&&(t.column=1/0),t}SetSheetID(e){this.start_.sheet_id=e}Normalize(){let e={...this.start_},t={...this.end_};e.row===1/0||t.row===1/0?e.row=t.row=1/0:e.row>t.row&&(e.row=this.end_.row,e.absolute_row=this.end_.absolute_row,t.row=this.start_.row,t.absolute_row=this.start_.absolute_row),e.column===1/0||t.column===1/0?e.column=t.column=1/0:e.column>t.column&&(e.column=this.end_.column,e.absolute_column=this.end_.absolute_column,t.column=this.start_.column,t.absolute_column=this.start_.absolute_column),this.start_=e,this.end_=t}TopLeft(){let e={row:0,column:0};return this.entire_row||(e.column=this.start.column),this.entire_column||(e.row=this.start.row),e}BottomRight(){let e={row:0,column:0};return this.entire_row||(e.column=this.end.column),this.entire_column||(e.row=this.end.row),e}ContainsRow(e){return this.entire_column||e>=this.start_.row&&e<=this.end_.row}ContainsColumn(e){return this.entire_row||e>=this.start_.column&&e<=this.end_.column}Contains(e){return(this.entire_column||e.row>=this.start_.row&&e.row<=this.end_.row)&&(this.entire_row||e.column>=this.start_.column&&e.column<=this.end_.column)}ContainsArea(e){return this.start.column<=e.start.column&&this.end.column>=e.end.column&&this.start.row<=e.start.row&&this.end.row>=e.end.row}Intersects(e){return!(e.start.column>this.end.column||this.start.column>e.end.column||e.start.row>this.end.row||this.start.row>e.end.row)}Equals(e){return e.start_.row===this.start_.row&&e.start_.column===this.start_.column&&e.end_.row===this.end_.row&&e.end_.column===this.end_.column}Clone(){return new c(this.start,this.end)}Array(){if(this.entire_column||this.entire_row)throw new Error("can't convert infinite area to array");let e=new Array(this.rows*this.columns),t=this.start_.sheet_id,r=0;for(let i=this.start_.row;i<=this.end_.row;i++)for(let n=this.start_.column;n<=this.end_.column;n++)e[r++]={row:i,column:n,sheet_id:t};return e}get left(){let e=new c(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new c(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new c(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new c(this.start_,this.end_);return e.start_.row=e.end_.row,e}Shift(e,t){return this.start_.row+=e,this.start_.column+=t,this.end_.row+=e,this.end_.column+=t,this}ConsumeAddress(e){this.entire_row||(e.column<this.start_.column&&(this.start_.column=e.column),e.column>this.end_.column&&(this.end_.column=e.column)),this.entire_column||(e.row<this.start_.row&&(this.start_.row=e.row),e.row>this.end_.row&&(this.end_.row=e.row))}ConsumeArea(e){this.ConsumeAddress(e.start),this.ConsumeAddress(e.end)}Resize(e,t){return this.end_.row=this.start_.row+e-1,this.end_.column=this.start_.column+t-1,this}Iterate(e){if(this.entire_column||this.entire_row){console.warn("don't iterate infinite area");return}for(let t=this.start_.column;t<=this.end_.column;t++)for(let r=this.start_.row;r<=this.end_.row;r++)e({column:t,row:r,sheet_id:this.start_.sheet_id})}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=c.ColumnToLabel(this.start_.column),e+=":"+c.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=c.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+c.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var fe=c=>typeof c=="object"&&!!c&&typeof c.real=="number"&&typeof c.imaginary=="number",Le=c=>c.real?c.imaginary?c.imaginary>0?`${c.real} + ${c.imaginary}i`:`${c.real} - ${Math.abs(c.imaginary)}i`:c.real.toString():c.imaginary?c.imaginary+"i":"0",Kt=c=>typeof c=="object"&&!!c&&typeof c.value=="number"&&typeof c.unit=="string",er=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var se=c=>{switch(typeof c){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return c===null?0:fe(c)?7:Kt(c)?9:5;case"string":return c[0]==="="?1:2;default:return 6}};var ee=class{static StringToColumn(e){let t=0;e=e.toUpperCase();for(let r=0;r<e.length;r++)t*=26,t+=e.charCodeAt(r)-64;return t-1}value;type=0;calculated;calculated_type;formatted;rendered_type;style;area;merge_area;table;renderer_data;render_clean=[];note;hyperlink;editing;render_function;click_function;validation;constructor(e,t){typeof e<"u"&&this.Set(e,t)}ValueIsNumber(){return this.type===3}ValueIsFormula(){return this.type===1}ValueIsBoolean(){return this.type===4}ValueIsComplex(){return this.type===7}FlushStyle(){this.formatted=this.rendered_type=this.style=void 0,this.render_clean=[]}FlushArray(){this.area=void 0}FlushCache(){this.calculated=this.calculated_type=this.formatted=this.rendered_type=this.render_function=this.click_function=void 0,this.render_clean=[]}Reset(){this.type=0,this.value=this.note=this.hyperlink=this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.area=this.renderer_data=this.render_function=this.click_function=void 0,this.render_clean=[]}Set(e,t=se(e)){this.value=e,this.type=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.render_function=this.click_function=this.area=void 0,this.render_clean=[]}SetCalculatedValue(e,t=se(e)){e===void 0&&(e=0,t=3),this.calculated!==e&&(this.calculated=e,this.calculated_type=t,this.formatted=this.rendered_type=void 0,this.render_clean=[])}GetValue(){return this.calculated_type?this.calculated:typeof this.value=="string"&&this.value[0]==="'"?this.value.slice(1):this.value}GetValue4(){return this.calculated_type?{type:this.calculated_type,value:this.calculated}:this.type===1?{type:3,value:0}:{type:this.type,value:typeof this.value=="string"&&this.value[0]==="'"?this.value.slice(1):this.value}}SetNote(e){this.note=e,this.render_clean=[]}SetCalculationError(e="ERR"){this.SetCalculatedValue(e,6)}SetArray(e){this.type=0,this.value=this.formatted=this.rendered_type=this.style=this.hyperlink=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}SetArrayHead(e,t){this.type=se(t),this.value=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}};var tr=c=>!c.cells,je=c=>!!c[0]&&tr(c[0]),rr=c=>!!c[0]&&c[0].row!==void 0,Wi=er.map((c,e)=>({[c]:e})).reduce((c,e)=>({...c,...e}),{}),dt=class{data=[];rows_=0;columns_=0;get rows(){return this.rows_}get columns(){return this.columns_}EnsureRow(e){this.rows_=Math.max(e+1,this.rows_)}EnsureColumn(e){this.columns_=Math.max(e+1,this.columns_)}InsertColumns(e=0,t=1){let r=JSON.parse(JSON.stringify(this.data[13]));this.data=this.data.map(i=>{if(i.length>=e){let n=i.slice(0,e),a=e+t,s=i.slice(e);for(let o=0;o<s.length;o++)n[a++]=s[o];return n}return i}),this.columns_+=t}DeleteColumns(e,t=1){this.data.forEach(r=>r.splice(e,t)),this.columns_-=t}DeleteRows(e,t=1){this.data.splice(e,t),this.rows_-=t}InsertRows(e=0,t=1){let r=[e,0,[]];for(let i=1;i<t;i++)r.push([]);Array.prototype.splice.apply(this.data,r),this.rows_+=t}GetCell(e,t){let{row:r,column:i}=e;if(!this.data[r])if(t)this.data[r]=[],this.rows_=Math.max(this.rows_,r+1);else return;return this.data[r][i]||t&&(this.data[r][i]=new ee,this.columns_=Math.max(this.columns_,i+1)),this.data[r][i]}EnsureCell(e){let{row:t,column:r}=e,i=this.data[t];i||(this.data[t]=i=[],this.rows_=Math.max(this.rows_,t+1));let n=i[r];return n||(n=i[r]=new ee,this.columns_=Math.max(this.columns_,r+1)),n}FromArray(e=[],t=!1){this.data=[];let r=0,i=0;if(t){i=e.length;for(let n=0;n<i;n++){let a=e[n];r=Math.max(r,a.length);for(let s=0;s<a.length;s++)this.data[s]||(this.data[s]=[]),this.data[s][n]=new ee(a[s])}}else{r=e.length;for(let n=0;n<r;n++){let a=[],s=e[n];i=Math.max(i,s.length);for(let o=0;o<s.length;o++)a[o]=new ee(s[o]);this.data[n]=a}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Wi[e]||void 0}ValueTypeToSerializedType(e){return e?er[e]:void 0}ImportDataValidation(e){if(typeof e.type=="number"){let t=["list","date","range","number","boolean"];if(e.type=t[e.type],!e.type)return}return e}FromJSON(e=[],t){if(this.data=[],!je(e)){let i=[];if(rr(e))for(let n of e)for(let a of n.cells)i.push({...a,row:n.row});else for(let n of e)for(let a of n.cells)i.push({...a,column:n.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let n=new ee(i.value);if(typeof i.calculated<"u"&&n.SetCalculatedValue(i.calculated,this.SerializedTypeToValueType(i.calculated_type)),t&&typeof i.style_ref<"u"&&(n.style=t[i.style_ref]),typeof i.note<"u"&&(n.note=i.note),typeof i.hyperlink<"u"&&(n.hyperlink=i.hyperlink),this.data[i.row][i.column]&&this.data[i.row][i.column].area&&(n.area=this.data[i.row][i.column].area),this.data[i.row][i.column]=n,i.area){let a=new y(i.area.start,i.area.end);for(let s=a.start.row;s<=a.end.row;s++)for(let o=a.start.column;o<=a.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ee),this.data[s][o].area=a}if(i.table&&r.push({...i.table}),i.merge_area){let a=new y(i.merge_area.start,i.merge_area.end);for(let s=a.start.row;s<=a.end.row;s++)for(let o=a.start.column;o<=a.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ee),this.data[s][o].merge_area=a}i.validation&&(n.validation=this.ImportDataValidation(i.validation))}for(let i of r)for(let n=i.area.start.row;n<=i.area.end.row;n++)for(let a=i.area.start.column;a<=i.area.end.column;a++)this.data[n]||(this.data[n]=[]),this.data[n][a]||(this.data[n][a]=new ee),this.data[n][a].table=i;this.rows_=this.data.length,this.columns_=this.data.reduce((i,n)=>Math.max(i,n.length),0)}toJSON(e={}){let t=0,r=0,i=this.data.length-1,n;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,i=e.subset.end.row);let a=[],s=-1,o=-1,l={},d={};for(let h=r;h<=i;h++)if(this.data[h]){let u=this.data[h];n=u.length-1,e.subset&&(n=e.subset.end.column);for(let m=t;m<=n;m++){let f=u[m],p=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===m,g=f&&f.area&&f.area.start.row===h&&f.area.start.column===m,b=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===m,v=f?f.type===2&&!f.value:!0;if(f&&(!v||e.preserve_empty_strings)&&(p||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||f.validation||e.decorated_cells&&f.style&&(f.style.fill||f.style.border_bottom||f.style.border_top||f.style.border_left||f.style.border_right))){let _={row:h,column:m,value:f.value};f.note&&(_.note=f.note),f.hyperlink&&(_.hyperlink=f.hyperlink),e.preserve_type&&(_.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(_.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(_.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(_.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&b&&e.tables&&(_.table=JSON.parse(JSON.stringify(f.table))),f.area&&g&&(_.area=f.area.toJSON()),f.merge_area&&(_.merge_area=f.merge_area.toJSON()),f.validation&&(_.validation=f.validation),e.cell_style_refs&&e.cell_style_refs[m]&&e.cell_style_refs[m][h]&&(_.style_ref=e.cell_style_refs[m][h],e.cell_style_refs[m][h]=0),l[h]=h,d[m]=m,s=Math.max(h,s),o=Math.max(m,o),a.push(_)}}}if(e.nested){let h=Object.keys(l),u=Object.keys(d);if(h.length<=u.length&&h.length){let m={},f=[];for(let p of a){let{row:g,...b}=p;m[p.row]||(m[p.row]=[]),m[p.row].push(b)}for(let p of h){let g=Number(p);f.push({row:g,cells:m[g]})}return{data:f,rows:s,columns:o+1}}else if(u.length){let m={},f=[];for(let p of a){let{column:g,...b}=p;m[p.column]||(m[p.column]=[]),m[p.column].push(b)}for(let p of u){let g=Number(p);f.push({column:g,cells:m[g]})}return{data:f,rows:s,columns:o+1}}}return{data:a,rows:s+1,columns:o+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize2(e,t){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),t.column===1/0&&(t={...t,column:this.columns_-1}),t.row===1/0&&(t={...t,row:this.rows_-1}),{from:e,to:t}}Normalize1(e){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),e}RawValue(e,t=e){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].value:void 0;let r=[],i=this.data.slice(e.row,t.row+1),n=e.column,a=t.column+1;for(let s of i){let o=[];for(let l=n,d=0;l<a;l++,d++){let h=s[l];o.push(h?h.value:void 0)}r.push(o)}return r}GetRange(e,t,r=!1){if(t?{from:e,to:t}=this.Normalize2(e,t):e=this.Normalize1(e),!t||e===t||e.column===t.column&&e.row===t.row)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue():void 0;let i=[];if(r)for(let n=e.column;n<=t.column;n++){let a=[];for(let s=e.row;s<=t.row;s++)this.data[s]&&this.data[s][n]?a.push(this.data[s][n].GetValue()):a.push(void 0);i.push(a)}else for(let n=e.row;n<=t.row;n++){let a=[];for(let s=e.column;s<=t.column;s++)this.data[n]&&this.data[n][s]?a.push(this.data[n][s].GetValue()):a.push(void 0);i.push(a)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue4():{value:void 0,type:0};let i=[];if(r)for(let n=e.column;n<=t.column;n++){let a=[];for(let s=e.row;s<=t.row;s++)this.data[s]&&this.data[s][n]?a.push(this.data[s][n].GetValue4()):a.push({type:0});i.push(a)}else for(let n=e.row;n<=t.row;n++){let a=[];for(let s=e.column;s<=t.column;s++)this.data[n]&&this.data[n][s]?a.push(this.data[n][s].GetValue4()):a.push({type:0});i.push(a)}return{type:8,value:i}}Apply(e,t,r=!1){if(N(e)&&(e=new y(e)),e.entire_column||e.entire_row)throw new Error("don't iterate infinite cells");let i=e.start,n=e.end;if(r)for(let a=i.row;a<=n.row;a++){this.data[a]||(this.data[a]=[]);let s=this.data[a];for(let o=i.column;o<=n.column;o++)s[o]||(s[o]=new ee),t(s[o],o,a)}else for(let a=i.row;a<=n.row;a++)if(this.data[a]){let s=this.data[a];for(let o=i.column;o<=n.column;o++)s[o]&&t(s[o],o,a)}}Apply2(e,t,r=!1){if(N(e)&&(e=new y(e)),e.entire_column||e.entire_row)throw new Error("don't iterate infinite cells");let i=e.start,n=e.end;if(r)for(let a=i.row;a<=n.row;a++){this.data[a]||(this.data[a]=[]);let s=this.data[a];for(let o=i.column;o<=n.column;o++)if(s[o]||(s[o]=new ee),!t(s[o],o,a))return}else for(let a=i.row;a<=n.row;a++)if(this.data[a]){let s=this.data[a];for(let o=i.column;o<=n.column;o++)if(s[o]&&!t(s[o],o,a))return}}SetArea(e,t){if(ArrayBuffer.isView(t))throw new Error("ABIV");if(Array.isArray(t))for(let r=e.start.row,i=0;r<=e.end.row;r++,i++){this.data[r]||(this.data[r]=[]);let n=this.data[r];if(t[i])for(let a=e.start.column,s=0;a<=e.end.column;a++,s++)n[a]||(n[a]=new ee),n[a].Set(t[i][s])}else{let r=se(t);for(let i=e.start.row;i<=e.end.row;i++){this.data[i]||(this.data[i]=[]);let n=this.data[i];for(let a=e.start.column;a<=e.end.column;a++)n[a]||(n[a]=new ee),n[a].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}IterateAll(e){for(let t of this.data)if(t)for(let r of t)r&&e(r)}FlushCellStyles(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushStyle()}FlushCachedValues(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushCache()}};var D=class{static locale="en-us";static decimal_separator=".";static argument_separator=",";static grouping_separator=",";static date_components={short_days:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],long_days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],short_months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],long_months:["January","February","March","April","May","June","July","August","September","October","November","December"]};static UpdateLocale(e){if(e)this.locale=e;else if(typeof self<"u"){let i=self?.document?.location;if(i&&i.search&&/locale=([^?&]+?)(?:\?|$|&)/.test(i.search)){let n=i.search.match(/locale=(.*?)(?:\?|$|&)/);n&&(this.locale=n[1]),console.info("override locale",this.locale)}else typeof navigator<"u"&&(navigator.languages&&navigator.languages[0]?this.locale=navigator.languages[0]:this.locale=navigator.language)}let t=new Intl.NumberFormat(this.locale,{minimumFractionDigits:1}).format(3.3).replace(/\d/g,"");this.decimal_separator=t===","?",":".",this.decimal_separator===","?(this.argument_separator=";",this.grouping_separator=" "):(this.argument_separator=",",this.grouping_separator=",");let r=new Date(2e3,0,2,12,0,0,0);this.UpdateDateComponent(0,0,r),r=new Date(2e3,1,7,12,0,0,0),this.UpdateDateComponent(1,1,r),r=new Date(2e3,2,7,12,0,0,0),this.UpdateDateComponent(2,2,r),r=new Date(2e3,3,5,12,0,0,0),this.UpdateDateComponent(3,3,r),r=new Date(2e3,4,4,12,0,0,0),this.UpdateDateComponent(4,4,r),r=new Date(2e3,5,2,12,0,0,0),this.UpdateDateComponent(5,5,r),r=new Date(2e3,6,1,12,0,0,0),this.UpdateDateComponent(6,6,r),r=new Date(2e3,7,1,12,0,0,0),this.UpdateDateComponent(7,-1,r),r=new Date(2e3,8,1,12,0,0,0),this.UpdateDateComponent(8,-1,r),r=new Date(2e3,9,1,12,0,0,0),this.UpdateDateComponent(9,-1,r),r=new Date(2e3,10,1,12,0,0,0),this.UpdateDateComponent(10,-1,r),r=new Date(2e3,11,1,12,0,0,0),this.UpdateDateComponent(11,-1,r)}static UpdateDateComponent(e,t,r){t>=0&&(this.date_components.short_days[t]=r.toLocaleString(this.locale,{weekday:"short"}),this.date_components.long_days[t]=r.toLocaleString(this.locale,{weekday:"long"})),e>=0&&(this.date_components.short_months[e]=r.toLocaleString(this.locale,{month:"short"}),this.date_components.long_months[e]=r.toLocaleString(this.locale,{month:"long"}))}};D.UpdateLocale();var H=class c{constructor(e=0,t=0,r=0,i=0){this.left=e;this.top=t;this.width=r;this.height=i}get right(){return this.left+this.width}get bottom(){return this.top+this.height}static Create(e){return new c(e.left||0,e.top||0,e.width||0,e.height||0)}static IsRectangle(e){return typeof e=="object"&&typeof e?.left=="number"&&typeof e?.top=="number"&&typeof e?.width=="number"&&typeof e?.height=="number"}Shift(e=0,t=0){return new c(this.left+e,this.top+t,this.width,this.height)}Scale(e=1,t=e){return new c(this.left*e,this.top*t,this.width*e,this.height*t)}Expand(e=0,t=0){return new c(this.left,this.top,this.width+e,this.height+t)}Combine(e){return new c(Math.min(this.left,e.left),Math.min(this.top,e.top),Math.max(this.right,e.right)-Math.min(this.left,e.left),Math.max(this.bottom,e.bottom)-Math.min(this.top,e.top))}Contains(e,t,r=0){return e>=this.left-r&&e<=this.left+this.width+r&&t>=this.top-r&&t<=this.top+this.height+r}ContextFill(e){e.fillRect(this.left,this.top,this.width,this.height)}ContextStroke(e){e.strokeRect(this.left,this.top,this.width,this.height)}Clamp(e,t){return e=Math.min(Math.max(e,this.left),this.right),t=Math.min(Math.max(t,this.top),this.bottom),{x:e,y:t}}ApplyStyle(e){e.style.top=this.top+"px",e.style.left=this.left+"px",e.style.width=this.width+"px",e.style.height=this.height+"px"}toJSON(){return{top:this.top,left:this.left,width:this.width,height:this.height}}};var ji=JSON.stringify({}),V={DefaultProperties:{horizontal_align:"",vertical_align:"",number_format:"General",nan:"NaN",font_size:{unit:"pt",value:10.5},font_face:"sans-serif",bold:!1,italic:!1,underline:!1,strike:!1,text:{theme:1},border_top:0,border_left:0,border_right:0,border_bottom:0},CompositeBorders:c=>({top:{width:c.border_top||0,color:c.border_top_fill||{}},left:{width:c.border_left||0,color:c.border_left_fill||{}},right:{width:c.border_right||0,color:c.border_right_fill||{}},bottom:{width:c.border_bottom||0,color:c.border_bottom_fill||{}}}),Merge:(c,e,t=!0)=>{let r=t?{...c,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:c=>JSON.parse(JSON.stringify(c.reduce((e,t)=>({...e,...t}),{}))),Empty:c=>JSON.stringify(c)===ji,ValidColor:c=>!!(c&&!c.none&&(c.text||c.theme||c.theme===0)),ParseFontSize:(c="",e="em")=>{let t=c.match(/(-*[\d.]+)\s*(\S*)/);if(t){let r=Number(t[1]);if(!r||isNaN(r)||r<0)return{};let i=t[2].toLowerCase()||e;if(i==="pt"||i==="em"||i==="%"||i==="px")return{font_size:{unit:i,value:r}}}return{}},RelativeFontSize:(c,e)=>{let t=12,r=12;switch(c.font_size?.unit){case"pt":if(!c.font_size.value)return 1;r=c.font_size.value;break;case"px":if(!c.font_size.value)return 1;r=Math.round(c.font_size.value*300/4)/100;break;case"em":return c.font_size.value||1;case"%":return(c.font_size.value||100)/100;default:return 1}switch(e.font_size?.unit){case"pt":if(!e.font_size.value)return 1;t=e.font_size.value;break;case"px":if(!e.font_size.value)return 1;t=Math.round(e.font_size.value*300/4)/100;break;default:return 1}return r/t},FontSize:(c,e=!0)=>{let t=c.font_size?.value;switch(c.font_size?.unit){case"pt":return(t||12)+"pt";case"px":return e?Math.round((t||16)*300/4)/100+"pt":(t||16)+"px";case"em":return(t||1)+"em";case"%":return(t||100)+"%"}return""},Font:(c,e=1)=>{let t=[];return c.bold&&t.push("bold"),c.italic&&t.push("italic"),t.push(((c.font_size?.value||0)*e).toFixed(2)+(c.font_size?.unit||"pt")),t.push(c.font_face||""),t.join(" ")}};var ir=c=>!!c&&Array.isArray(c)&&Array.isArray(c[0]),j=(c,e)=>(typeof e>"u"&&(e=se(c)),{value:c,type:e}),ce=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real};var Q={Darken:(c,e,t,r,i=!1)=>{let{h:n,s:a,l:s}=Q.RGBToHSL(c,e,t);return i?s-=s*r/100:s-=r/100,s=Math.max(0,Math.min(1,s)),Q.HSLToRGB(n,a,s)},Lighten:(c,e,t,r,i=!1)=>{let{h:n,s:a,l:s}=Q.RGBToHSL(c,e,t);return i?s+=s*r/100:s+=r/100,s=Math.max(0,Math.min(1,s)),Q.HSLToRGB(n,a,s)},RGBToHSL:(c,e,t)=>{c/=255,e/=255,t/=255;let r=Math.max(c,e,t),i=Math.min(c,e,t),n=0,a=0,s=(r+i)/2;if(r===i)n=a=0;else{let o=r-i;switch(a=s>.5?o/(2-r-i):o/(r+i),r){case c:n=(e-t)/o+(e<t?6:0);break;case e:n=(t-c)/o+2;break;case t:n=(c-e)/o+4;break}n/=6}return{h:n*360,s:a,l:s}},HSLToRGB:(c,e,t)=>{let r,i,n;if(e===0)r=i=n=t;else{c=c/360;let a=t<.5?t*(1+e):t+e-t*e,s=2*t-a;r=Q.HueToRGB(s,a,c+.3333333333333333),i=Q.HueToRGB(s,a,c),n=Q.HueToRGB(s,a,c-.3333333333333333)}return{r:Math.round(r*255),g:Math.round(i*255),b:Math.round(n*255)}},HueToRGB:(c,e,t)=>(t<0&&(t+=1),t>1&&(t-=1),t<.16666666666666666?c+(e-c)*6*t:t<.5?e:t<.6666666666666666?c+(e-c)*(.6666666666666666-t)*6:c)};var Yi="http://www.w3.org/2000/svg",F=class c{static instances=[];static GetInstance(e){for(let r of this.instances)if(r.doc===e)return r;let t=new c(e);return this.instances.push(t),t}doc;view;get HTMLElement(){return this.view?.HTMLElement}constructor(e){e&&(this.doc=e,this.view=e?.defaultView)}GetSelection(){return this.view?.getSelection()}Div(e,t,r){return this.Create("div",e,t,r)}ClassNames(e,t){e.classList.add(...(Array.isArray(t)?t:[t]).reduce((r,i)=>[...r,...i.split(/\s+/g)],[]))}SVG(e,t,r){let i=this.doc.createElementNS(Yi,e);return t&&this.ClassNames(i,t),r&&r.appendChild(i),i}Text(e){return this.doc.createTextNode(e)}Fragment(){return this.doc.createDocumentFragment()}Create(e,t,r,i){let n=this.doc.createElement(e);if(t&&this.ClassNames(n,t),i){if(i.attrs)for(let[a,s]of Object.entries(i.attrs))n.setAttribute(a,s);if(i.data)for(let[a,s]of Object.entries(i.data))n.dataset[a]=s;if(i.text&&(n.textContent=i.text),i.html&&(n.innerHTML=i.html),i.events)for(let[a,s]of Object.entries(i.events))n.addEventListener(a,s);if(i.style)for(let[a,s]of Object.entries(i.style))n.style[a]=s}return r&&r.appendChild(n),n}};var ht={grid_color:"#ccc",note_marker_color:"#d2c500",mode:"light",offset_cache:{},offset_light:"#fff",offset_dark:"#000"},pe=(c,e)=>T(c,e,0),Ji=(c,e,t)=>{c.mode==="dark"&&(t=-t),c.tint_cache||(c.tint_cache=[]),c.tint_cache[e]||(c.tint_cache[e]={});let r=c.tint_cache[e][t];if(!r){let i=(c.theme_colors_rgb?c.theme_colors_rgb[e]:[0,0,0])||[0,0,0],n;t>0?n=Q.Lighten(i[0],i[1],i[2],t*100,!0):n=Q.Darken(i[0],i[1],i[2],-t*100,!0),r=`rgb(${n.r},${n.g},${n.b})`,c.tint_cache[e][t]=r}return r},T=(c,e,t)=>{if(e?.offset){if(e.offset.offset)return console.warn("invalid offset color"),"";let r=T(c,e.offset);if(c.offset_cache&&c.offset_cache[r])return c.offset_cache[r];let i=c.offset_light;if(r){let n=r.match(/rgb\((\d+), (\d+), (\d+)\)/);n?Q.RGBToHSL(Number(n[1]),Number(n[2]),Number(n[3])).l>.65&&(i=c.offset_dark):console.warn("can't offset against color",r),c.offset_cache||(c.offset_cache={}),c.offset_cache[r]=i}else console.warn("can't resolve offset color",e.offset);return i}return e?.text?e.text==="none"?"":e.text:e?.theme||e?.theme===0?e.tint?Ji(c,e.theme,e.tint):c.theme_colors?c.theme_colors[e.theme]:"":(t||t===0)&&c.theme_colors?c.theme_colors[t]:""},Xi=c=>{let e=10,t="pt",r=c.match(/^([\d.]+)(\D.*)$/);return r&&(e=Number(r[1]),t=r[2]),{value:e,unit:t}},Gr=c=>{let{value:e,unit:t}=Xi(c.fontSize||""),r={fill:{text:c.backgroundColor},text:{text:c.color},font_size:{unit:t,value:e},font_face:c.fontFamily};return/italic/i.test(c.font)&&(r.italic=!0),c.fontWeight==="700"&&(r.bold=!0),r},Qi=(c,e)=>{let t=c.grid_cell?.text,r=c.grid_cell?.fill;e.fillStyle=t?.text||"",e.fillRect(0,0,3,3);let i=Q.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));e.fillStyle=r?.text||"",e.fillRect(0,0,3,3);let n=Q.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));return i.l>n.l?"dark":"light"},ut=(c,e=.7)=>{let t={border_top:1,border_top_fill:{theme:c},border_bottom:1,border_bottom_fill:{theme:c}};return{header:{text:{offset:{theme:c}},fill:{theme:c},bold:!0,...t},odd:{fill:{theme:c,tint:e},...t},even:{...t},total:{...t,border_top:2}}},Hr=c=>{let e=JSON.parse(JSON.stringify(ht)),t=F.GetInstance(c.ownerDocument),r=(h,u)=>t.Div(u,h),i=(h,u)=>t.view?.getComputedStyle(r(h,u)),n=r(c,""),a=i.bind(0,n),s=a("grid-cells");e.grid_cell=Gr(s),e.grid_color=s.stroke||"",s=a("grid-headers"),e.headers=Gr(s),e.headers_grid_color=s.stroke,(!e.headers_grid_color||e.headers_grid_color==="none")&&(e.headers_grid_color=e.grid_color),s=a("treb-offset-dark"),s.color&&(e.offset_dark=s.color),s=a("treb-offset-light"),s.color&&(e.offset_light=s.color),s=a("note-marker"),e.note_marker_color=s.backgroundColor,n.style.color="rgba(1,2,3,.4)",s=a("");let o=s.color;e.theme_colors=[e.grid_cell.fill?.text||"rgb(255, 255, 255)",e.grid_cell.text?.text||"rgb(51, 51, 51)"];for(let h=1;h<32&&(s=a(`theme-color-${h}`),!(!s.color||s.color===o));h++)e.theme_colors.push(s.color);let l=t.Create("canvas");l.width=3,l.height=3;let d=l.getContext("2d",{willReadFrequently:!0});return d&&(e.mode=Qi(e,d)),d&&(e.theme_colors_rgb=e.theme_colors.map(h=>{d.fillStyle=h,d.fillRect(0,0,3,3);let u=d.getImageData(1,1,1,1);return Array.from(u.data)})),e.table=ut(4),n.parentElement?.removeChild(n),e};var Or={column:0,type:"auto",asc:!0};var qi=1e3,oe=class{constructor(e=!1,t){this.verbose=e;this.log_id=t}queue=[];dispatched=!1;subscribers=[];Publish(e){this.verbose&&console.info(`es publish (${this.log_id})`,e),Array.isArray(e)?this.queue.push(...e):this.queue.push(e),this.dispatched||(this.dispatched=!0,Promise.resolve().then(()=>{let t=this.queue.slice(0);this.dispatched=!1,this.queue=[];for(let r of t)for(let i of this.subscribers)i.subscriber(r)}))}Subscribe(e){let t=qi++;return this.subscribers.push({subscriber:e,token:t}),t}Cancel(e){this.subscribers=this.subscribers.filter(t=>t.token!==e)}CancelAll(){this.subscribers=[]}};var de=class{static color_measurement_canvas;static text_measurement_node;static color_cache={};static MeasureColorARGB(e){let t=this.MeasureColor(e),r="FF";for(let i=0;i<3;i++){let n=t[i].toString(16);n.length===0?r+="00":n.length===1?r+=`0${n}`:r+=n}return r.toUpperCase()}static MeasureColor(e){let t=this.color_cache[e];if(t)return t;this.color_measurement_canvas||(this.color_measurement_canvas=document.createElement("canvas"),this.color_measurement_canvas.width=1,this.color_measurement_canvas.height=1);let r=this.color_measurement_canvas.getContext("2d",{willReadFrequently:!0});return r?(r.fillStyle="#fff",r.fillRect(0,0,1,1),r.fillStyle=e,r.fillRect(0,0,1,1),t=new Uint8ClampedArray(r.getImageData(0,0,1,1).data),this.color_cache[e]=t,t):new Uint8ClampedArray(3)}static EnsureMeasurementNode(){if(!this.text_measurement_node){let e=document.querySelector(".treb-chart-measurement-node");e?this.text_measurement_node=e:(this.text_measurement_node=document.createElement("div"),this.text_measurement_node.classList.add("treb-chart-measurement-node"),this.text_measurement_node.style.margin="0px",this.text_measurement_node.style.padding="0px",this.text_measurement_node.style.height="initial",this.text_measurement_node.style.width="initial",this.text_measurement_node.style.whiteSpace="nowrap",this.text_measurement_node.style.position="fixed",this.text_measurement_node.style.border="0px",this.text_measurement_node.style.border="1px solid red",this.text_measurement_node.style.boxSizing="content-box",this.text_measurement_node.style.top=this.text_measurement_node.style.left="-1000px",document.body.appendChild(this.text_measurement_node))}}static MeasureText(e,t,r=0){this.EnsureMeasurementNode(),this.text_measurement_node.style.font=e,/\n/.test(t)?(t=t.replace(/\n/g,"<BR/>"),this.text_measurement_node.innerHTML=t):this.text_measurement_node.textContent=t,this.text_measurement_node.style.lineHeight="1em",r?this.text_measurement_node.style.transform=`rotate(${r}deg)`:this.text_measurement_node.style.transform="";let i=this.text_measurement_node.getBoundingClientRect();return{width:i.width,height:i.height}}};var nr,Ki=(c,e,t)=>{let r={};return Array.prototype.forEach.call(e,i=>{e[i]!==t[i]&&(r[i]=e[i])}),(Object.keys(r).map(i=>`${i}: ${r[i]}`).join("; ")+"; "+(c.getAttribute("style")||"")).trim().replace(/"/g,"'")},$r=(c,e)=>{let t=c.cloneNode(!1),r=getComputedStyle(c),i=Ki(c,r,e);return t.removeAttribute("class"),t.setAttribute("style",i),Array.prototype.forEach.call(c.childNodes,n=>{switch(n.nodeType){case Node.ELEMENT_NODE:t.appendChild($r(n,r));break;case Node.TEXT_NODE:c.textContent&&t.appendChild(document.createTextNode(c.textContent));break;case Node.COMMENT_NODE:break;default:console.warn("unhandled node type in serialize",n)}}),t},Zr=c=>{if(!nr){let e={},t=document.createElement("iframe");t.style.width="10px",t.style.height="10px",t.style.position="absolute",t.style.left="-100px",document.body.appendChild(t);let r=t.contentDocument;if(r){let i=r.createElement("div");r.body.appendChild(i);let n=getComputedStyle(i);Array.prototype.forEach.call(n,a=>e[a]=n[a])}document.body.removeChild(t),nr=e}return $r(c,nr)};var en={data:!0,same_origin:!0,remote:!1},mt=(c,e={})=>{let t={...en,...e};try{let r=new URL(c,document.location.href);return r.protocol==="data:"?t.data?r.href:void 0:r.origin===document.location.origin?t.same_origin?r.href:void 0:t.remote?r.hash:void 0}catch(r){console.error(r)}};var Br=(c,e,t=6.5,r=!1,i=!1)=>{if(e===c)e++,c&&c--;else{let h=Math.round(e*1e5)/1e5;Math.abs(h-e)/(e-c)<1e-5&&(e=h)}let n=e-c,a=Math.log(n)/Math.log(10),s=Math.floor(Math.abs(a))*(a<0?-1:1)-1;i&&(s=Math.max(0,s));let o=i?[1,2,5,10,15,20,25,50,100]:[.1,.25,.5,1,2.5,5,10,25,50,100],l=-1,d=0;for(let h of o){let u=h*Math.pow(10,s),m=Math.floor(c/u)*u,p=(Math.ceil(e/u)*u-m)/u,g=Math.abs(p-t);(l<0||g<d)&&(!r||p<=t)&&(d=g,l=u)}return c=Math.floor(c/l)*l,e=Math.ceil(e/l)*l,t=Math.round((e-c)/l),{scale:s,step:l,count:t,min:c,max:e}};var ft=class{constructor(e,t,r="HSL"){this.color_space=r;this.mapped=e.map(i=>{if(i.value<0||i.value>1)throw new Error("invalid stop value");let n=de.MeasureColor(T(t,i.color)),a=[];if(r==="HSL"){let s=Q.RGBToHSL(n[0],n[1],n[2]);a=[s.h,s.s,s.l]}else a=[...n];return{...i,resolved:a}}),this.mapped.sort((i,n)=>i.value-n.value),this.mapped[0].value>0&&this.mapped.unshift({...this.mapped[0],value:0}),this.mapped[this.mapped.length-1].value<1&&this.mapped.push({...this.mapped[this.mapped.length-1],value:1})}mapped;RenderColor(e){return this.color_space==="RGB"?{text:`rgb(${e})`}:{text:`hsl(${e[0]},${e[1]*100}%,${e[2]*100}%)`}}Interpolate(e){e=Math.min(1,Math.max(0,e));for(let[t,r]of this.mapped.entries()){if(e===r.value)return this.RenderColor(r.resolved);if(e<r.value){let i=this.mapped[t-1],n=r,a=n.value-i.value,s=e-i.value,o=[0,1,2].map(l=>i.resolved[l]+(n.resolved[l]-i.resolved[l])/a*s);return this.RenderColor(o)}}return{text:""}}};var ze=/[\s-+=<>!()]/,Xr=/['*\\]/,ar=34,sr=39,tn=160,Wr=32,rn=9,nn=10,an=13,ye=48,Ye=57,or=46,lr=43,Je=45,jr=40,cr=41,Xe=44,sn=37,dr=95,pt=36,on=123,ln=125,Qe=91,Yr=93,cn=33,Jr=59,dn=35,hn=64,Pe=65,qe=97,un=69,mn=101,bt=90,gt=122,fn=105;var hr=192,ur=312,mr={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},pn=Object.keys(mr).sort((c,e)=>e.length-c.length),bn={"-":100,"+":100},Ge=class{argument_separator=",";decimal_mark=".";flags={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0};r1c1_regex=/[rR]((?:\[[-+]{0,1}\d+\]|\d+))[cC]((?:\[[-+]{0,1}\d+\]|\d+))$/;argument_separator_char=Xe;decimal_mark_char=or;imaginary_char=fn;imaginary_number="i";id_counter=0;expression="";data=[];index=0;length=0;valid=!0;error_position;error;dependencies={addresses:{},ranges:{}};address_refcount={};full_reference_list=[];Walk(e,t){switch(e.type){case"address":case"missing":case"literal":case"complex":case"identifier":case"operator":case"structured-reference":t(e);return;case"dimensioned":t(e)&&(this.Walk(e.expression,t),this.Walk(e.unit,t));return;case"range":t(e)&&(this.Walk(e.start,t),this.Walk(e.end,t));return;case"binary":t(e)&&(this.Walk(e.left,t),this.Walk(e.right,t));return;case"unary":t(e)&&this.Walk(e.operand,t);return;case"group":t(e)&&e.elements.forEach(r=>this.Walk(r,t));return;case"call":t(e)&&e.args.forEach(r=>this.Walk(r,t))}}Transpose(e){let t=e.length,r=[],i=0;for(let n=0;n<t;n++)Array.isArray(e[n])&&(i=Math.max(i,e[n].length));for(let n=0;n<i;n++){r[n]=[];for(let a=0;a<t;a++)r[n][a]=e[a][n]}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},i=t.missing??"(missing)",{convert_decimal:n,convert_argument_separator:a,convert_imaginary_number:s,long_structured_references:o,table_name:l}=t,d=this.argument_separator+" ";a===","?d=", ":a===";"&&(d="; ");let h=this.imaginary_number;s&&(h=s);let u=n===","?",":".",m=this.decimal_mark===","?/,/:/\./,f=this.decimal_mark===","?/,/g:/\./g;switch(e.type){case"address":return this.AddressLabel(e,r);case"range":return this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return i;case"array":return"{"+this.Transpose(e.values).map(p=>p.map(g=>typeof g=="string"?'"'+g+'"':g).join(", ")).join("; ")+"}";case"binary":return this.Render(e.left,t)+" "+e.operator+" "+this.Render(e.right,t);case"unary":return e.operator+this.Render(e.operand,t);case"complex":if(e.text)return n?e.text.replace(f,u):e.text;{let p=Math.abs(e.imaginary).toString();if((n===","||this.decimal_mark===",")&&(p=p.replace(/\./,",")),e.real){let g=e.real.toString();(n===","||this.decimal_mark===",")&&(g=g.replace(/\./,","));let b=Math.abs(e.imaginary);return`${g}${e.imaginary<0?" - ":" + "}${b===1?"":p}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${p}i`}break;case"literal":if(typeof e.value=="string")return'"'+e.value.replace(/"/g,'""')+'"';if(n&&typeof e.value=="number")if(e.text){let p=e.text;return n===","&&this.decimal_mark==="."&&(p=p.replace(/,/g,"")),p.replace(m,u)}else return e.value.toString().replace(/\./,u);else if(e.text)return e.text;return e.value.toString();case"identifier":return e.name;case"operator":return"["+e.operator+"]";case"group":return e.explicit?"("+e.elements.map(p=>this.Render(p,t)).join(d)+")":e.elements.map(p=>this.Render(p,t)).join(d);case"call":return e.name+"("+e.args.map(p=>this.Render(p,t)).join(d)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let p=e.column;/[^A-Za-z]/.test(p)&&(p="["+p+"]");let g=e.table;switch(!g&&o&&l&&(g=l),e.scope){case"all":return`${g}[[#all],${p}]`;case"row":return o?`${g}[[#this row],${p}]`:`${g}[@${p}]`;case"column":return`${g}[${p}]`}throw new Error("unhandled scope in structured reference")}}return"??"}Parse(e){switch(e=e.trim(),e[0]==="="&&(e=e.substr(1).trim()),this.expression=e,this.data=[],this.length=e.length,this.index=0,this.valid=!0,this.error_position=void 0,this.error=void 0,this.dependencies.addresses={},this.dependencies.ranges={},this.address_refcount={},this.full_reference_list=[],this.id_counter=0,this.argument_separator){case";":this.argument_separator_char=Jr;break;default:this.argument_separator_char=Xe;break}switch(this.decimal_mark){case",":this.decimal_mark_char=Xe;break;default:this.decimal_mark_char=or;break}for(let i=0;i<this.length;i++)this.data[i]=e.charCodeAt(i);let t=this.ParseGeneric(),r={};for(let i of Object.keys(this.dependencies.addresses))this.address_refcount[i]&&(r[i]=this.dependencies.addresses[i]);return this.dependencies.addresses=r,{expression:t||void 0,valid:this.valid,error:this.error,error_position:this.error_position,dependencies:this.dependencies,separator:this.argument_separator,decimal_mark:this.decimal_mark,full_reference_list:this.full_reference_list.slice(0)}}ColumnLabel(e){if(e===1/0)return"";let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}AddressLabel(e,t){let r=e.column;!e.absolute_column&&e.column!==1/0&&(r+=t.columns);let i=e.row;if(!e.absolute_row&&e.row!==1/0&&(i+=t.rows),i<0||r<0||i===1/0&&r===1/0)return"#REF";let n="";return e.sheet&&(n=(ze.test(e.sheet)?"'"+e.sheet+"'":e.sheet)+"!"),i===1/0?n+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?n+(e.absolute_row?"$":"")+(i+1):n+(e.absolute_column?"$":"")+this.ColumnLabel(r)+(e.absolute_row?"$":"")+(i+1)}ParseGeneric(e=[0]){let t=[];for(;this.index<this.length;){let r=this.ParseNext(t.length===0);if(typeof r=="number"){if(e.some(i=>r===i))break;if(r===jr){this.index++;let i=this.ParseGeneric([cr]);this.index++,i&&t.push({type:"group",id:this.id_counter++,elements:[i],explicit:!0})}else{let i=this.ConsumeOperator();i?t.push(i):(this.error=`unexpected character [1]: ${String.fromCharCode(r)}, 0x${r.toString(16)}`,this.valid=!1,this.index++)}}else t.push(r)}if(t.length){if(t=this.BinaryToRange2(t),this.flags.fractions){let r=[],i=a=>a.type==="literal"&&typeof a.value=="number"&&a.value%1===0,n=0;for(;n<t.length-3;n++)if(i(t[n])&&i(t[n+1])&&t[n+2].type==="operator"&&t[n+2].operator==="/"&&i(t[n+3])){let a=t[n],s=t[n+1],o=t[n+3],l=(a.value<0?-1:1)*(s.value/o.value);n+=3,r.push({id:t[n].id,type:"literal",text:this.expression.substring(a.position,o.position+1),value:a.value+l,position:a.position})}else r.push(t[n]);for(;n<t.length;n++)r.push(t[n]);t=r}if(t=t.map(r=>r.type==="identifier"&&r.name===this.imaginary_number?{type:"complex",real:0,imaginary:1,position:r.position,text:r.name,id:this.id_counter++}:r),this.flags.dimensioned_quantities){let r=[],i;for(let n=0;n<t.length;n++){let a=t[n];if(!i)i=a;else if(a.type==="identifier"&&(i.type==="literal"||i.type==="group"||i.type==="call")){let s=a;for(;t[n+1]?.type==="identifier";)s.name+=" "+t[++n].name;r.push({type:"dimensioned",expression:i,unit:a,id:this.id_counter++}),i=void 0}else r.push(i),i=a}i&&r.push(i),t=r}}return t.length===0?null:t.length===1?t[0]:this.BinaryToComplex(this.ArrangeUnits(t))}UnitToAddress(e){if(e.type==="literal"){if(typeof e.value=="number"&&e.value>0&&!/\./.test(e.text||""))return{type:"address",position:e.position,label:e.value.toString(),row:e.value-1,id:this.id_counter++,column:1/0}}else{let t,r=e.name,i=r.split("!");if(i.length>1&&(t=i.slice(0,i.length-1).join("!"),r=r.substr(t.length+1),t[0]==="'"))if(t.length>1&&t[t.length-1]==="'")t=t.substr(1,t.length-2);else return;let n=r[0]==="$";r=(n?r.substr(1):r).toUpperCase();let a=Number(r);if(isNaN(a)){if(/[A-Z]{1,3}/.test(r)){let s=-1;for(let o=0;o<r.length;o++){let l=r[o].charCodeAt(0);s=26*(1+s)+(l-Pe)}return{type:"address",position:e.position,absolute_column:n,label:e.name,column:s,id:this.id_counter++,row:1/0,sheet:t}}}else if(a>0&&a!==1/0&&!/\./.test(r))return{type:"address",position:e.position,absolute_row:n,label:e.name,row:a-1,id:this.id_counter++,column:1/0,sheet:t}}}BinaryToRange2(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],n=e[r+1],a=e[r+2],s,o="",l;if(i&&n&&a&&n.type==="operator"&&n.operator===":"){if(i.type==="address"&&a.type==="address"){let d=i.position+i.label.length,h=a.position;s={type:"range",id:this.id_counter++,position:i.position,start:i,end:a,label:i.label+this.expression.substring(d,h)+a.label},o=s.start.label+":"+s.end.label,this.address_refcount[s.start.label]--,this.address_refcount[s.end.label]--;let u=[i.position,a.position];this.full_reference_list=this.full_reference_list.filter(m=>m.position!==u[0]&&m.position!==u[1])}else if((i.type==="literal"||i.type==="identifier")&&(a.type==="literal"||a.type==="identifier")){let d=this.UnitToAddress(i);if(!d&&i.type==="literal"&&typeof i.value=="number"&&i.value<0){let u={...i,text:(i.text||"").replace(/^-/,""),position:i.position+1,value:-i.value};d=this.UnitToAddress(u),d&&(l={type:"operator",operator:"-",position:i.position,id:this.id_counter++})}let h=this.UnitToAddress(a);d&&h&&(d.column===1/0&&h.column===1/0||d.row===1/0&&h.row===1/0)&&(o=d.label+":"+h.label,s={type:"range",id:this.id_counter++,position:d.position,start:d,end:h,label:o})}}s?(l&&t.push(l),t.push(s),this.dependencies.ranges[o]=s,this.full_reference_list.push(s),r+=2):t.push(i)}return t}BinaryToComplex(e){if(e.type==="binary")if((e.operator==="+"||e.operator==="-")&&e.left.type==="literal"&&typeof e.left.value=="number"&&e.right.type==="complex"&&!e.right.composited){let t="";t=this.expression.substring(e.left.position,e.right.position+(e.right.text?.length||0));let r=e.right.imaginary;return e.operator==="-"&&(r=-r),{type:"complex",position:e.left.position,text:t,id:this.id_counter++,imaginary:r,real:e.left.value,composited:!0}}else e.left=this.BinaryToComplex(e.left),e.right=this.BinaryToComplex(e.right);else if(e.type==="unary"&&(e.operator==="-"||e.operator==="+")&&e.operand.type==="complex"&&e.operand.text===this.imaginary_number)return{...e.operand,position:e.position,text:this.expression.substring(e.position,e.operand.position+(e.operand.text||"").length),imaginary:e.operand.imaginary*(e.operator==="-"?-1:1)};return e}BinaryToRangeX(e){if(e.type==="binary"){if(e.operator===":"){let t,r="";if(e.left.type==="address"&&e.right.type==="address"){let i=e.left.position+e.left.label.length,n=e.right.position;t={type:"range",id:this.id_counter++,position:e.left.position,start:e.left,end:e.right,label:e.left.label+this.expression.substring(i,n)+e.right.label},r=t.start.label+":"+t.end.label,this.address_refcount[t.start.label]--,this.address_refcount[t.end.label]--;let a=[e.left.position,e.right.position];this.full_reference_list=this.full_reference_list.filter(s=>s.position!==a[0]&&s.position!==a[1])}else if((e.left.type==="literal"||e.left.type==="identifier")&&(e.right.type==="literal"||e.right.type==="identifier")){let i=this.UnitToAddress(e.left),n=this.UnitToAddress(e.right);i&&n&&(i.column===1/0&&n.column===1/0||i.row===1/0&&n.row===1/0)&&(r=i.label+":"+n.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:i,end:n,label:r})}if(t)return this.dependencies.ranges[r]=t,this.full_reference_list.push(t),t;this.error="unexpected character: :",this.valid=!1}e.left=this.BinaryToRangeX(e.left),e.right=this.BinaryToRangeX(e.right)}return e}ArrangeUnits(e){if(e.length===0)return{type:"missing",id:this.id_counter++};if(e.length===1)return e[0];let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(bn[i.operator]){let n=this.BinaryToComplex(this.ArrangeUnits(e.slice(r+1)));if(!this.valid)return{type:"group",id:this.id_counter++,elements:e,explicit:!1};n.type==="binary"?(n.left={type:"unary",id:this.id_counter++,operator:i.operator,operand:n.left,position:i.position},i=n):i={type:"unary",id:this.id_counter++,operator:i.operator,operand:n,position:i.position},r=e.length}else return this.error=`unexpected character [2]: ${i.operator}`,this.error_position=i.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1};else{t.push(i);continue}if(t.length<2)t.push(i);else if(t[t.length-1].type==="operator"){let n=t[t.length-2],a=t[t.length-1],s=a.operator,o={type:"binary",id:this.id_counter++,left:n,operator:s,position:a.position,right:i};n.type==="binary"&&mr[s]>mr[n.operator]&&(o.left=n.left,o.operator=n.operator,o.position=n.position,o.right={type:"binary",id:this.id_counter++,left:n.right,right:i,operator:s,position:a.position}),t.splice(-2,2,o)}else return this.error="multiple expressions",this.error_position=i.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1}}return t[0]}ParseNext(e=!0){this.ConsumeWhiteSpace();let t=this.data[this.index];if(t===ar)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ye&&t<=Ye||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===on)return this.ConsumeArray();if(e&&(t===Je||t===lr)){let r=this.data[this.index+1];if(r>=ye&&r<=Ye||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Pe&&t<=bt||t>=qe&&t<=gt||t===dr||t===dn||t===sr||t===pt||t===Qe||t>=hr&&t<=ur)return this.ConsumeToken(t);return t}ConsumeArray(){let e={type:"array",id:this.id_counter++,values:[],position:this.index};this.index++;let t=0,r=0;for(;this.index<this.length;){let i=this.ParseNext(),n=this.index;if(typeof i=="number")switch(this.index++,i){case Jr:r++,t=0;break;case Xe:t++;break;case ln:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=n,this.valid=!1);break}else switch(i.type){case"literal":e.values[t]||(e.values[t]=[]),e.values[t][r]=i.value;break;default:this.valid&&(this.error="invalid value in array literal",this.error_position=n,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of pn)if(this.expression.substr(this.index,e.length)===e){let t=this.index;return this.index+=e.length,{type:"operator",id:this.id_counter++,operator:e,position:t}}return null}ConsumeArguments(){this.index++;let e=0,t=[];for(;this.index<this.length;){let r=this.ParseGeneric([this.argument_separator_char,cr]);r!==null&&t.push(r);let i=this.data[this.index];if(i===this.argument_separator_char){this.index++,e++;for(let n=t.length;n<e;n++)t.push({type:"missing",id:this.id_counter++})}else if(i===cr)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,i=e===sr,n=0,a=!1;for(e===Qe&&(n=1,a=!0),++this.index;this.index<this.length;this.index++){let d=this.data[this.index];if(d>=Pe&&d<=bt||d>=qe&&d<=gt||d>=hr&&d<=ur||d===dr||d===pt||d===or||d===cn||i||d>=ye&&d<=Ye||d===Qe||n>0&&d===Yr||d===Je&&this.flags.r1c1&&n===1||n>0&&d===hn&&this.data[this.index-1]===Qe||n===1&&(d===Xe||d===Wr)||n>1)t.push(d),d===Qe&&(n++,a=!0),d===Yr&&n--,d===sr&&(i=!1);else break}let s=t.map(d=>String.fromCharCode(d)).join("");if(i)return this.error="unbalanced single quote",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:s,position:r};if(n)return this.error="unbalanced square bracket",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:s,position:r};if(s.toLowerCase()==="true")return{type:"literal",id:this.id_counter++,value:!0,position:r};if(s.toLowerCase()==="false")return{type:"literal",id:this.id_counter++,value:!1,position:r};if(this.ConsumeWhiteSpace(),this.data[this.index]===jr){let d=this.ConsumeArguments();return{type:"call",id:this.id_counter++,name:s,args:d,position:r}}if(this.flags.spreadsheet_semantics){let d=this.ConsumeAddress(s,r);if(d)return d;if(a){let h=this.ConsumeStructuredReference(s,r);if(h)return h}}let l={type:"identifier",id:this.id_counter++,name:s,position:r};return this.full_reference_list.push(l),l}ConsumeStructuredReference(e,t){let r=t,i=e.length,n=e,a="",s=0;for(;s<i;s++){if(e[s]==="["){e=e.substring(s);break}a+=e[s]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let o=e.split(",").map(u=>u.trim()),l="column",d="";if(o.length>2)return;o.length===2?(/\[#this row\]/i.test(o[0])?l="row":/\[#all\]/i.test(o[0])&&(l="all"),d=o[1]):(d=o[0],d[0]==="@"&&(l="row",d=d.substring(1,d.length))),d[0]==="["&&d[d.length-1]==="]"&&(d=d.substring(1,d.length-1));let h={type:"structured-reference",id:this.id_counter++,label:n,position:t,scope:l,column:d,table:a};return this.full_reference_list.push(h),h}ConsumeAddress(e,t){let r=t,i=e.length,n,a=e.split("!");if(a.length>1&&(n=a.slice(0,a.length-1).join("!"),t+=n.length+1),this.flags.r1c1){let h=a[a.length-1].match(this.r1c1_regex);if(h){let u={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:n,r1c1:!0};return h[1][0]==="["?(u.offset_row=!0,u.row=Number(h[1].substring(1,h[1].length-1))):u.row=Number(h[1])-1,h[2][0]==="["?(u.offset_column=!0,u.column=Number(h[2].substring(1,h[2].length-1))):u.column=Number(h[2])-1,u}}let s=this.ConsumeAddressColumn(t);if(!s)return null;t=s.position;let o=this.ConsumeAddressRow(t);if(!o)return null;t=o.position;let l=n?n+e.substr(n.length,t-r).toUpperCase():e.substr(0,t-r).toUpperCase();n&&n[0]==="'"&&(n=n.substr(1,n.length-2));let d={type:"address",id:this.id_counter++,label:l,row:o.row,column:s.column,absolute_row:o.absolute,absolute_column:s.absolute,position:r,sheet:n};return i!==t-r?null:(this.dependencies.addresses[d.label]=d,this.address_refcount[d.label]=(this.address_refcount[d.label]||0)+1,this.full_reference_list.push(d),d)}ConsumeAddressRow(e){let t=this.data[e]===pt;t&&e++;let r=e,i=0;for(;;e++){let n=this.data[e];if(n>=ye&&n<=Ye)i*=10,i+=n-ye;else break}return r===e?!1:{absolute:t,row:i-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,i=this.data[e]===pt;for(i&&e++;;e++,r++){if(r>=4)return!1;let n=this.data[e];if(n>=Pe&&n<=bt)t=26*(1+t)+(n-Pe);else if(n>=qe&&n<=gt)t=26*(1+t)+(n-qe);else break}return t<0?!1:{absolute:i,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,i=!1,n=0,a=0,s=0,o="integer",l=0,d=!1,h=this.index;for(;this.index<this.length;this.index++,l++){let m=this.data[this.index];if(m===this.decimal_mark_char)if(o==="integer")o="fraction";else break;else if(m===sn){n/=100,s/=100,this.index++;break}else if(m===lr||m===Je)if(l===0)m===Je&&(i=!0);else break;else if(m===un||m===mn)if(o==="integer"||o==="fraction")o="exponent",this.index<this.length-1&&(this.data[this.index+1]===lr?this.index++:this.data[this.index+1]===Je&&(this.index++,r=!0));else break;else if(m===this.imaginary_char){let f=this.data[this.index+1];if(f>=Pe&&f<=bt||f>=qe&&f<=gt||f>=hr&&f<=ur||f===dr)break;if(o==="integer"||o==="fraction"){this.index++,d=!0;break}}else if(m>=ye&&m<=Ye)switch(o){case"integer":n=n*10+(m-ye);break;case"fraction":s=s*10+(m-ye),a++;break;case"exponent":t=t*10+(m-ye);break}else break}let u=n+s/Math.pow(10,a);return o==="exponent"&&(u=u*Math.pow(10,(r?-1:1)*t)),d?{type:"complex",id:this.id_counter++,position:e,imaginary:i?-u:u,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:i?-u:u,text:this.expression.substring(h,this.index)||""}}ConsumeString(){this.index++;let e=[];for(;this.index<this.length;this.index++){let t=this.data[this.index];if(t===ar&&(this.index++,this.index>=this.length||this.data[this.index]!==ar))break;e.push(t)}return e.map(t=>String.fromCharCode(t)).join("")}ConsumeWhiteSpace(){for(;this.index<this.length;){let e=this.data[this.index];if(e===Wr||e===rn||e===nn||e===an||e===tn)this.index++;else return}}};var Qr=(c,e=",")=>{let t=0,r=[],i="",n=[],a=c.length;if(/[\r\n"]/.test(e))throw new Error("invalid delimiter");for(let s=0;s<a;s++){let o=c[s];if(!(s===0&&o.charCodeAt(0)===65279))if(t===0)switch(o){case e:r.push(i),i="";break;case"\r":break;case`
|
|
3
|
-
`:r.push(i),i="",n.push(r),r=[];break;case'"':i.length===0?t=1:i+=o;break;default:i+=o;break}else o==='"'?s+1<a&&c[s+1]==='"'?(i+='"',s++):t=0:i+=o}return(r.length||i.length)&&(r.push(i),n.push(r)),n};var
|
|
1
|
+
/*! TREB v28.3.4. Copyright 2018-2023 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
|
|
2
|
+
var Zi=Object.defineProperty;var Bi=(c,e)=>{for(var t in e)Zi(c,t,{get:e[t],enumerable:!0})};var N=c=>c!==null&&typeof c=="object"&&"row"in c&&"column"in c,Pr=c=>c!==null&&typeof c=="object"&&"start"in c&&N(c.start)&&"end"in c&&N(c.end),y=class c{start_;end_;constructor(e,t=e,r=!1){this.end_=this.PatchNull(t),this.start_=this.PatchNull(e),r&&this.Normalize()}static FromColumn(e){return new c({row:1/0,column:e})}static FromRow(e){return new c({row:e,column:1/0})}static ColumnToLabel(e){let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}static CellAddressToLabel(e,t=!1){return(t?`${e.sheet_id||0}!`:"")+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new c(e.start,e.end);for(let i of t)i&&(r.ConsumeAddress(i.start),r.ConsumeAddress(i.end));return r}static Bleed(e,t=1){return new c({row:Math.max(0,e.start.row-t),column:Math.max(0,e.start.column-t),sheet_id:e.start.sheet_id},{row:e.end.row+t,column:e.end.column+t})}static PatchArea(e,t){let{before_column:r,column_count:i,before_row:n,row_count:a}=t,s=new c(e.start,e.end),o=e.start.sheet_id;if(i&&r<=s.end.column){if(i>0)r<=s.start.column?s.Shift(0,i):r>s.start.column&&r<=s.end.column?s.ConsumeAddress({row:s.end.row,column:s.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(s));else if(i<0)if(r-i<=s.start.column)s.Shift(0,i);else{if(r<=s.start.column&&r-i>s.end.column)return!1;if(r<=s.start.column){let l=r-i-1;s=new c({row:s.start.row,column:l+1+i,sheet_id:o},{row:s.end.row,column:s.end.column+i})}else r<=s.end.column?r-i-1>=s.end.column?s=new c({row:s.start.row,column:s.start.column,sheet_id:o},{row:s.end.row,column:r-1}):s=new c({row:s.start.row,column:s.start.column,sheet_id:o},{row:s.end.row,column:s.start.column+s.columns+i-1}):console.warn("AA X case 2",r,i,JSON.stringify(s))}}if(a&&n<=s.end.row){if(a>0)n<=s.start.row?s.Shift(a,0):n>s.start.row&&n<=s.end.row?s.ConsumeAddress({row:s.end.row+a,column:s.end.column}):console.warn("AA X case 3",n,a,JSON.stringify(s));else if(a<0)if(n-a<=s.start.row)s.Shift(a,0);else{if(n<=s.start.row&&n-a>s.end.row)return!1;if(n<=s.start.row){let l=n-a-1;s=new c({column:s.start.column,row:l+1+a,sheet_id:o},{column:s.end.column,row:s.end.row+a})}else n<=s.end.row?n-a-1>=s.end.row?s=new c({column:s.start.column,row:s.start.row,sheet_id:o},{column:s.end.column,row:n-1}):s=new c({column:s.start.column,row:s.start.row,sheet_id:o},{column:s.end.column,row:s.start.row+s.rows+a-1}):console.warn("AA X case 4",n,a,JSON.stringify(s))}}return s}get start(){return{...this.start_}}set start(e){this.start_=e}get end(){return{...this.end_}}set end(e){this.end_=e}get rows(){return this.start_.row===1/0||this.end_.row===1/0?1/0:this.end_.row-this.start_.row+1}get columns(){return this.start_.column===1/0||this.end_.column===1/0?1/0:this.end_.column-this.start_.column+1}get count(){return this.rows*this.columns}get entire_sheet(){return this.entire_row&&this.entire_column}get entire_column(){return this.start_.row===1/0}get entire_row(){return this.start_.column===1/0}PatchNull(e){let t={...e};return t.row===null&&(t.row=1/0),t.column===null&&(t.column=1/0),t}SetSheetID(e){this.start_.sheet_id=e}Normalize(){let e={...this.start_},t={...this.end_};e.row===1/0||t.row===1/0?e.row=t.row=1/0:e.row>t.row&&(e.row=this.end_.row,e.absolute_row=this.end_.absolute_row,t.row=this.start_.row,t.absolute_row=this.start_.absolute_row),e.column===1/0||t.column===1/0?e.column=t.column=1/0:e.column>t.column&&(e.column=this.end_.column,e.absolute_column=this.end_.absolute_column,t.column=this.start_.column,t.absolute_column=this.start_.absolute_column),this.start_=e,this.end_=t}TopLeft(){let e={row:0,column:0};return this.entire_row||(e.column=this.start.column),this.entire_column||(e.row=this.start.row),e}BottomRight(){let e={row:0,column:0};return this.entire_row||(e.column=this.end.column),this.entire_column||(e.row=this.end.row),e}ContainsRow(e){return this.entire_column||e>=this.start_.row&&e<=this.end_.row}ContainsColumn(e){return this.entire_row||e>=this.start_.column&&e<=this.end_.column}Contains(e){return(this.entire_column||e.row>=this.start_.row&&e.row<=this.end_.row)&&(this.entire_row||e.column>=this.start_.column&&e.column<=this.end_.column)}ContainsArea(e){return this.start.column<=e.start.column&&this.end.column>=e.end.column&&this.start.row<=e.start.row&&this.end.row>=e.end.row}Intersects(e){return!(e.start.column>this.end.column||this.start.column>e.end.column||e.start.row>this.end.row||this.start.row>e.end.row)}Equals(e){return e.start_.row===this.start_.row&&e.start_.column===this.start_.column&&e.end_.row===this.end_.row&&e.end_.column===this.end_.column}Clone(){return new c(this.start,this.end)}Array(){if(this.entire_column||this.entire_row)throw new Error("can't convert infinite area to array");let e=new Array(this.rows*this.columns),t=this.start_.sheet_id,r=0;for(let i=this.start_.row;i<=this.end_.row;i++)for(let n=this.start_.column;n<=this.end_.column;n++)e[r++]={row:i,column:n,sheet_id:t};return e}get left(){let e=new c(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new c(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new c(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new c(this.start_,this.end_);return e.start_.row=e.end_.row,e}Shift(e,t){return this.start_.row+=e,this.start_.column+=t,this.end_.row+=e,this.end_.column+=t,this}ConsumeAddress(e){this.entire_row||(e.column<this.start_.column&&(this.start_.column=e.column),e.column>this.end_.column&&(this.end_.column=e.column)),this.entire_column||(e.row<this.start_.row&&(this.start_.row=e.row),e.row>this.end_.row&&(this.end_.row=e.row))}ConsumeArea(e){this.ConsumeAddress(e.start),this.ConsumeAddress(e.end)}Resize(e,t){return this.end_.row=this.start_.row+e-1,this.end_.column=this.start_.column+t-1,this}Iterate(e){if(this.entire_column||this.entire_row){console.warn("don't iterate infinite area");return}for(let t=this.start_.column;t<=this.end_.column;t++)for(let r=this.start_.row;r<=this.end_.row;r++)e({column:t,row:r,sheet_id:this.start_.sheet_id})}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=c.ColumnToLabel(this.start_.column),e+=":"+c.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=c.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+c.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var fe=c=>typeof c=="object"&&!!c&&typeof c.real=="number"&&typeof c.imaginary=="number",Le=c=>c.real?c.imaginary?c.imaginary>0?`${c.real} + ${c.imaginary}i`:`${c.real} - ${Math.abs(c.imaginary)}i`:c.real.toString():c.imaginary?c.imaginary+"i":"0",Kt=c=>typeof c=="object"&&!!c&&typeof c.value=="number"&&typeof c.unit=="string",er=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var se=c=>{switch(typeof c){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return c===null?0:fe(c)?7:Kt(c)?9:5;case"string":return c[0]==="="?1:2;default:return 6}};var ee=class{static StringToColumn(e){let t=0;e=e.toUpperCase();for(let r=0;r<e.length;r++)t*=26,t+=e.charCodeAt(r)-64;return t-1}value;type=0;calculated;calculated_type;formatted;rendered_type;style;area;merge_area;table;renderer_data;render_clean=[];note;hyperlink;editing;render_function;click_function;validation;constructor(e,t){typeof e<"u"&&this.Set(e,t)}ValueIsNumber(){return this.type===3}ValueIsFormula(){return this.type===1}ValueIsBoolean(){return this.type===4}ValueIsComplex(){return this.type===7}FlushStyle(){this.formatted=this.rendered_type=this.style=void 0,this.render_clean=[]}FlushArray(){this.area=void 0}FlushCache(){this.calculated=this.calculated_type=this.formatted=this.rendered_type=this.render_function=this.click_function=void 0,this.render_clean=[]}Reset(){this.type=0,this.value=this.note=this.hyperlink=this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.area=this.renderer_data=this.render_function=this.click_function=void 0,this.render_clean=[]}Set(e,t=se(e)){this.value=e,this.type=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.render_function=this.click_function=this.area=void 0,this.render_clean=[]}SetCalculatedValue(e,t=se(e)){e===void 0&&(e=0,t=3),this.calculated!==e&&(this.calculated=e,this.calculated_type=t,this.formatted=this.rendered_type=void 0,this.render_clean=[])}GetValue(){return this.calculated_type?this.calculated:typeof this.value=="string"&&this.value[0]==="'"?this.value.slice(1):this.value}GetValue4(){return this.calculated_type?{type:this.calculated_type,value:this.calculated}:this.type===1?{type:3,value:0}:{type:this.type,value:typeof this.value=="string"&&this.value[0]==="'"?this.value.slice(1):this.value}}SetNote(e){this.note=e,this.render_clean=[]}SetCalculationError(e="ERR"){this.SetCalculatedValue(e,6)}SetArray(e){this.type=0,this.value=this.formatted=this.rendered_type=this.style=this.hyperlink=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}SetArrayHead(e,t){this.type=se(t),this.value=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}};var tr=c=>!c.cells,je=c=>!!c[0]&&tr(c[0]),rr=c=>!!c[0]&&c[0].row!==void 0,Wi=er.map((c,e)=>({[c]:e})).reduce((c,e)=>({...c,...e}),{}),dt=class{data=[];rows_=0;columns_=0;get rows(){return this.rows_}get columns(){return this.columns_}EnsureRow(e){this.rows_=Math.max(e+1,this.rows_)}EnsureColumn(e){this.columns_=Math.max(e+1,this.columns_)}InsertColumns(e=0,t=1){let r=JSON.parse(JSON.stringify(this.data[13]));this.data=this.data.map(i=>{if(i.length>=e){let n=i.slice(0,e),a=e+t,s=i.slice(e);for(let o=0;o<s.length;o++)n[a++]=s[o];return n}return i}),this.columns_+=t}DeleteColumns(e,t=1){this.data.forEach(r=>r.splice(e,t)),this.columns_-=t}DeleteRows(e,t=1){this.data.splice(e,t),this.rows_-=t}InsertRows(e=0,t=1){let r=[e,0,[]];for(let i=1;i<t;i++)r.push([]);Array.prototype.splice.apply(this.data,r),this.rows_+=t}GetCell(e,t){let{row:r,column:i}=e;if(!this.data[r])if(t)this.data[r]=[],this.rows_=Math.max(this.rows_,r+1);else return;return this.data[r][i]||t&&(this.data[r][i]=new ee,this.columns_=Math.max(this.columns_,i+1)),this.data[r][i]}EnsureCell(e){let{row:t,column:r}=e,i=this.data[t];i||(this.data[t]=i=[],this.rows_=Math.max(this.rows_,t+1));let n=i[r];return n||(n=i[r]=new ee,this.columns_=Math.max(this.columns_,r+1)),n}FromArray(e=[],t=!1){this.data=[];let r=0,i=0;if(t){i=e.length;for(let n=0;n<i;n++){let a=e[n];r=Math.max(r,a.length);for(let s=0;s<a.length;s++)this.data[s]||(this.data[s]=[]),this.data[s][n]=new ee(a[s])}}else{r=e.length;for(let n=0;n<r;n++){let a=[],s=e[n];i=Math.max(i,s.length);for(let o=0;o<s.length;o++)a[o]=new ee(s[o]);this.data[n]=a}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Wi[e]||void 0}ValueTypeToSerializedType(e){return e?er[e]:void 0}ImportDataValidation(e){if(typeof e.type=="number"){let t=["list","date","range","number","boolean"];if(e.type=t[e.type],!e.type)return}return e}FromJSON(e=[],t){if(this.data=[],!je(e)){let i=[];if(rr(e))for(let n of e)for(let a of n.cells)i.push({...a,row:n.row});else for(let n of e)for(let a of n.cells)i.push({...a,column:n.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let n=new ee(i.value);if(typeof i.calculated<"u"&&n.SetCalculatedValue(i.calculated,this.SerializedTypeToValueType(i.calculated_type)),t&&typeof i.style_ref<"u"&&(n.style=t[i.style_ref]),typeof i.note<"u"&&(n.note=i.note),typeof i.hyperlink<"u"&&(n.hyperlink=i.hyperlink),this.data[i.row][i.column]&&this.data[i.row][i.column].area&&(n.area=this.data[i.row][i.column].area),this.data[i.row][i.column]=n,i.area){let a=new y(i.area.start,i.area.end);for(let s=a.start.row;s<=a.end.row;s++)for(let o=a.start.column;o<=a.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ee),this.data[s][o].area=a}if(i.table&&r.push({...i.table}),i.merge_area){let a=new y(i.merge_area.start,i.merge_area.end);for(let s=a.start.row;s<=a.end.row;s++)for(let o=a.start.column;o<=a.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ee),this.data[s][o].merge_area=a}i.validation&&(n.validation=this.ImportDataValidation(i.validation))}for(let i of r)for(let n=i.area.start.row;n<=i.area.end.row;n++)for(let a=i.area.start.column;a<=i.area.end.column;a++)this.data[n]||(this.data[n]=[]),this.data[n][a]||(this.data[n][a]=new ee),this.data[n][a].table=i;this.rows_=this.data.length,this.columns_=this.data.reduce((i,n)=>Math.max(i,n.length),0)}toJSON(e={}){let t=0,r=0,i=this.data.length-1,n;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,i=e.subset.end.row);let a=[],s=-1,o=-1,l={},d={};for(let h=r;h<=i;h++)if(this.data[h]){let u=this.data[h];n=u.length-1,e.subset&&(n=e.subset.end.column);for(let m=t;m<=n;m++){let f=u[m],p=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===m,g=f&&f.area&&f.area.start.row===h&&f.area.start.column===m,b=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===m,v=f?f.type===2&&!f.value:!0;if(f&&(!v||e.preserve_empty_strings)&&(p||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||f.validation||e.decorated_cells&&f.style&&(f.style.fill||f.style.border_bottom||f.style.border_top||f.style.border_left||f.style.border_right))){let _={row:h,column:m,value:f.value};f.note&&(_.note=f.note),f.hyperlink&&(_.hyperlink=f.hyperlink),e.preserve_type&&(_.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(_.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(_.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(_.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&b&&e.tables&&(_.table=JSON.parse(JSON.stringify(f.table))),f.area&&g&&(_.area=f.area.toJSON()),f.merge_area&&(_.merge_area=f.merge_area.toJSON()),f.validation&&(_.validation=f.validation),e.cell_style_refs&&e.cell_style_refs[m]&&e.cell_style_refs[m][h]&&(_.style_ref=e.cell_style_refs[m][h],e.cell_style_refs[m][h]=0),l[h]=h,d[m]=m,s=Math.max(h,s),o=Math.max(m,o),a.push(_)}}}if(e.nested){let h=Object.keys(l),u=Object.keys(d);if(h.length<=u.length&&h.length){let m={},f=[];for(let p of a){let{row:g,...b}=p;m[p.row]||(m[p.row]=[]),m[p.row].push(b)}for(let p of h){let g=Number(p);f.push({row:g,cells:m[g]})}return{data:f,rows:s,columns:o+1}}else if(u.length){let m={},f=[];for(let p of a){let{column:g,...b}=p;m[p.column]||(m[p.column]=[]),m[p.column].push(b)}for(let p of u){let g=Number(p);f.push({column:g,cells:m[g]})}return{data:f,rows:s,columns:o+1}}}return{data:a,rows:s+1,columns:o+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize2(e,t){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),t.column===1/0&&(t={...t,column:this.columns_-1}),t.row===1/0&&(t={...t,row:this.rows_-1}),{from:e,to:t}}Normalize1(e){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),e}RawValue(e,t=e){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].value:void 0;let r=[],i=this.data.slice(e.row,t.row+1),n=e.column,a=t.column+1;for(let s of i){let o=[];for(let l=n,d=0;l<a;l++,d++){let h=s[l];o.push(h?h.value:void 0)}r.push(o)}return r}GetRange(e,t,r=!1){if(t?{from:e,to:t}=this.Normalize2(e,t):e=this.Normalize1(e),!t||e===t||e.column===t.column&&e.row===t.row)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue():void 0;let i=[];if(r)for(let n=e.column;n<=t.column;n++){let a=[];for(let s=e.row;s<=t.row;s++)this.data[s]&&this.data[s][n]?a.push(this.data[s][n].GetValue()):a.push(void 0);i.push(a)}else for(let n=e.row;n<=t.row;n++){let a=[];for(let s=e.column;s<=t.column;s++)this.data[n]&&this.data[n][s]?a.push(this.data[n][s].GetValue()):a.push(void 0);i.push(a)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue4():{value:void 0,type:0};let i=[];if(r)for(let n=e.column;n<=t.column;n++){let a=[];for(let s=e.row;s<=t.row;s++)this.data[s]&&this.data[s][n]?a.push(this.data[s][n].GetValue4()):a.push({type:0});i.push(a)}else for(let n=e.row;n<=t.row;n++){let a=[];for(let s=e.column;s<=t.column;s++)this.data[n]&&this.data[n][s]?a.push(this.data[n][s].GetValue4()):a.push({type:0});i.push(a)}return{type:8,value:i}}Apply(e,t,r=!1){if(N(e)&&(e=new y(e)),e.entire_column||e.entire_row)throw new Error("don't iterate infinite cells");let i=e.start,n=e.end;if(r)for(let a=i.row;a<=n.row;a++){this.data[a]||(this.data[a]=[]);let s=this.data[a];for(let o=i.column;o<=n.column;o++)s[o]||(s[o]=new ee),t(s[o],o,a)}else for(let a=i.row;a<=n.row;a++)if(this.data[a]){let s=this.data[a];for(let o=i.column;o<=n.column;o++)s[o]&&t(s[o],o,a)}}Apply2(e,t,r=!1){if(N(e)&&(e=new y(e)),e.entire_column||e.entire_row)throw new Error("don't iterate infinite cells");let i=e.start,n=e.end;if(r)for(let a=i.row;a<=n.row;a++){this.data[a]||(this.data[a]=[]);let s=this.data[a];for(let o=i.column;o<=n.column;o++)if(s[o]||(s[o]=new ee),!t(s[o],o,a))return}else for(let a=i.row;a<=n.row;a++)if(this.data[a]){let s=this.data[a];for(let o=i.column;o<=n.column;o++)if(s[o]&&!t(s[o],o,a))return}}SetArea(e,t){if(ArrayBuffer.isView(t))throw new Error("ABIV");if(Array.isArray(t))for(let r=e.start.row,i=0;r<=e.end.row;r++,i++){this.data[r]||(this.data[r]=[]);let n=this.data[r];if(t[i])for(let a=e.start.column,s=0;a<=e.end.column;a++,s++)n[a]||(n[a]=new ee),n[a].Set(t[i][s])}else{let r=se(t);for(let i=e.start.row;i<=e.end.row;i++){this.data[i]||(this.data[i]=[]);let n=this.data[i];for(let a=e.start.column;a<=e.end.column;a++)n[a]||(n[a]=new ee),n[a].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}IterateAll(e){for(let t of this.data)if(t)for(let r of t)r&&e(r)}FlushCellStyles(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushStyle()}FlushCachedValues(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushCache()}};var D=class{static locale="en-us";static decimal_separator=".";static argument_separator=",";static grouping_separator=",";static date_components={short_days:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],long_days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],short_months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],long_months:["January","February","March","April","May","June","July","August","September","October","November","December"]};static UpdateLocale(e){if(e)this.locale=e;else if(typeof self<"u"){let i=self?.document?.location;if(i&&i.search&&/locale=([^?&]+?)(?:\?|$|&)/.test(i.search)){let n=i.search.match(/locale=(.*?)(?:\?|$|&)/);n&&(this.locale=n[1]),console.info("override locale",this.locale)}else typeof navigator<"u"&&(navigator.languages&&navigator.languages[0]?this.locale=navigator.languages[0]:this.locale=navigator.language)}let t=new Intl.NumberFormat(this.locale,{minimumFractionDigits:1}).format(3.3).replace(/\d/g,"");this.decimal_separator=t===","?",":".",this.decimal_separator===","?(this.argument_separator=";",this.grouping_separator=" "):(this.argument_separator=",",this.grouping_separator=",");let r=new Date(2e3,0,2,12,0,0,0);this.UpdateDateComponent(0,0,r),r=new Date(2e3,1,7,12,0,0,0),this.UpdateDateComponent(1,1,r),r=new Date(2e3,2,7,12,0,0,0),this.UpdateDateComponent(2,2,r),r=new Date(2e3,3,5,12,0,0,0),this.UpdateDateComponent(3,3,r),r=new Date(2e3,4,4,12,0,0,0),this.UpdateDateComponent(4,4,r),r=new Date(2e3,5,2,12,0,0,0),this.UpdateDateComponent(5,5,r),r=new Date(2e3,6,1,12,0,0,0),this.UpdateDateComponent(6,6,r),r=new Date(2e3,7,1,12,0,0,0),this.UpdateDateComponent(7,-1,r),r=new Date(2e3,8,1,12,0,0,0),this.UpdateDateComponent(8,-1,r),r=new Date(2e3,9,1,12,0,0,0),this.UpdateDateComponent(9,-1,r),r=new Date(2e3,10,1,12,0,0,0),this.UpdateDateComponent(10,-1,r),r=new Date(2e3,11,1,12,0,0,0),this.UpdateDateComponent(11,-1,r)}static UpdateDateComponent(e,t,r){t>=0&&(this.date_components.short_days[t]=r.toLocaleString(this.locale,{weekday:"short"}),this.date_components.long_days[t]=r.toLocaleString(this.locale,{weekday:"long"})),e>=0&&(this.date_components.short_months[e]=r.toLocaleString(this.locale,{month:"short"}),this.date_components.long_months[e]=r.toLocaleString(this.locale,{month:"long"}))}};D.UpdateLocale();var H=class c{constructor(e=0,t=0,r=0,i=0){this.left=e;this.top=t;this.width=r;this.height=i}get right(){return this.left+this.width}get bottom(){return this.top+this.height}static Create(e){return new c(e.left||0,e.top||0,e.width||0,e.height||0)}static IsRectangle(e){return typeof e=="object"&&typeof e?.left=="number"&&typeof e?.top=="number"&&typeof e?.width=="number"&&typeof e?.height=="number"}Shift(e=0,t=0){return new c(this.left+e,this.top+t,this.width,this.height)}Scale(e=1,t=e){return new c(this.left*e,this.top*t,this.width*e,this.height*t)}Expand(e=0,t=0){return new c(this.left,this.top,this.width+e,this.height+t)}Combine(e){return new c(Math.min(this.left,e.left),Math.min(this.top,e.top),Math.max(this.right,e.right)-Math.min(this.left,e.left),Math.max(this.bottom,e.bottom)-Math.min(this.top,e.top))}Contains(e,t,r=0){return e>=this.left-r&&e<=this.left+this.width+r&&t>=this.top-r&&t<=this.top+this.height+r}ContextFill(e){e.fillRect(this.left,this.top,this.width,this.height)}ContextStroke(e){e.strokeRect(this.left,this.top,this.width,this.height)}Clamp(e,t){return e=Math.min(Math.max(e,this.left),this.right),t=Math.min(Math.max(t,this.top),this.bottom),{x:e,y:t}}ApplyStyle(e){e.style.top=this.top+"px",e.style.left=this.left+"px",e.style.width=this.width+"px",e.style.height=this.height+"px"}toJSON(){return{top:this.top,left:this.left,width:this.width,height:this.height}}};var ji=JSON.stringify({}),U={DefaultProperties:{horizontal_align:"",vertical_align:"",number_format:"General",nan:"NaN",font_size:{unit:"pt",value:10.5},font_face:"sans-serif",bold:!1,italic:!1,underline:!1,strike:!1,text:{theme:1},border_top:0,border_left:0,border_right:0,border_bottom:0},CompositeBorders:c=>({top:{width:c.border_top||0,color:c.border_top_fill||{}},left:{width:c.border_left||0,color:c.border_left_fill||{}},right:{width:c.border_right||0,color:c.border_right_fill||{}},bottom:{width:c.border_bottom||0,color:c.border_bottom_fill||{}}}),Merge:(c,e,t=!0)=>{let r=t?{...c,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:c=>JSON.parse(JSON.stringify(c.reduce((e,t)=>({...e,...t}),{}))),Empty:c=>JSON.stringify(c)===ji,ValidColor:c=>!!(c&&!c.none&&(c.text||c.theme||c.theme===0)),ParseFontSize:(c="",e="em")=>{let t=c.match(/(-*[\d.]+)\s*(\S*)/);if(t){let r=Number(t[1]);if(!r||isNaN(r)||r<0)return{};let i=t[2].toLowerCase()||e;if(i==="pt"||i==="em"||i==="%"||i==="px")return{font_size:{unit:i,value:r}}}return{}},RelativeFontSize:(c,e)=>{let t=12,r=12;switch(c.font_size?.unit){case"pt":if(!c.font_size.value)return 1;r=c.font_size.value;break;case"px":if(!c.font_size.value)return 1;r=Math.round(c.font_size.value*300/4)/100;break;case"em":return c.font_size.value||1;case"%":return(c.font_size.value||100)/100;default:return 1}switch(e.font_size?.unit){case"pt":if(!e.font_size.value)return 1;t=e.font_size.value;break;case"px":if(!e.font_size.value)return 1;t=Math.round(e.font_size.value*300/4)/100;break;default:return 1}return r/t},FontSize:(c,e=!0)=>{let t=c.font_size?.value;switch(c.font_size?.unit){case"pt":return(t||12)+"pt";case"px":return e?Math.round((t||16)*300/4)/100+"pt":(t||16)+"px";case"em":return(t||1)+"em";case"%":return(t||100)+"%"}return""},Font:(c,e=1)=>{let t=[];return c.bold&&t.push("bold"),c.italic&&t.push("italic"),t.push(((c.font_size?.value||0)*e).toFixed(2)+(c.font_size?.unit||"pt")),t.push(c.font_face||""),t.join(" ")}};var ir=c=>!!c&&Array.isArray(c)&&Array.isArray(c[0]),j=(c,e)=>(typeof e>"u"&&(e=se(c)),{value:c,type:e}),ce=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real};var Q={Darken:(c,e,t,r,i=!1)=>{let{h:n,s:a,l:s}=Q.RGBToHSL(c,e,t);return i?s-=s*r/100:s-=r/100,s=Math.max(0,Math.min(1,s)),Q.HSLToRGB(n,a,s)},Lighten:(c,e,t,r,i=!1)=>{let{h:n,s:a,l:s}=Q.RGBToHSL(c,e,t);return i?s+=s*r/100:s+=r/100,s=Math.max(0,Math.min(1,s)),Q.HSLToRGB(n,a,s)},RGBToHSL:(c,e,t)=>{c/=255,e/=255,t/=255;let r=Math.max(c,e,t),i=Math.min(c,e,t),n=0,a=0,s=(r+i)/2;if(r===i)n=a=0;else{let o=r-i;switch(a=s>.5?o/(2-r-i):o/(r+i),r){case c:n=(e-t)/o+(e<t?6:0);break;case e:n=(t-c)/o+2;break;case t:n=(c-e)/o+4;break}n/=6}return{h:n*360,s:a,l:s}},HSLToRGB:(c,e,t)=>{let r,i,n;if(e===0)r=i=n=t;else{c=c/360;let a=t<.5?t*(1+e):t+e-t*e,s=2*t-a;r=Q.HueToRGB(s,a,c+.3333333333333333),i=Q.HueToRGB(s,a,c),n=Q.HueToRGB(s,a,c-.3333333333333333)}return{r:Math.round(r*255),g:Math.round(i*255),b:Math.round(n*255)}},HueToRGB:(c,e,t)=>(t<0&&(t+=1),t>1&&(t-=1),t<.16666666666666666?c+(e-c)*6*t:t<.5?e:t<.6666666666666666?c+(e-c)*(.6666666666666666-t)*6:c)};var Yi="http://www.w3.org/2000/svg",F=class c{static instances=[];static GetInstance(e){for(let r of this.instances)if(r.doc===e)return r;let t=new c(e);return this.instances.push(t),t}doc;view;get HTMLElement(){return this.view?.HTMLElement}constructor(e){e&&(this.doc=e,this.view=e?.defaultView)}GetSelection(){return this.view?.getSelection()}Div(e,t,r){return this.Create("div",e,t,r)}ClassNames(e,t){e.classList.add(...(Array.isArray(t)?t:[t]).reduce((r,i)=>[...r,...i.split(/\s+/g)],[]))}SVG(e,t,r){let i=this.doc.createElementNS(Yi,e);return t&&this.ClassNames(i,t),r&&r.appendChild(i),i}Text(e){return this.doc.createTextNode(e)}Fragment(){return this.doc.createDocumentFragment()}Create(e,t,r,i){let n=this.doc.createElement(e);if(t&&this.ClassNames(n,t),i){if(i.attrs)for(let[a,s]of Object.entries(i.attrs))n.setAttribute(a,s);if(i.data)for(let[a,s]of Object.entries(i.data))n.dataset[a]=s;if(i.text&&(n.textContent=i.text),i.html&&(n.innerHTML=i.html),i.events)for(let[a,s]of Object.entries(i.events))n.addEventListener(a,s);if(i.style)for(let[a,s]of Object.entries(i.style))n.style[a]=s}return r&&r.appendChild(n),n}};var ht={grid_color:"#ccc",note_marker_color:"#d2c500",mode:"light",offset_cache:{},offset_light:"#fff",offset_dark:"#000"},pe=(c,e)=>R(c,e,0),Ji=(c,e,t)=>{c.mode==="dark"&&(t=-t),c.tint_cache||(c.tint_cache=[]),c.tint_cache[e]||(c.tint_cache[e]={});let r=c.tint_cache[e][t];if(!r){let i=(c.theme_colors_rgb?c.theme_colors_rgb[e]:[0,0,0])||[0,0,0],n;t>0?n=Q.Lighten(i[0],i[1],i[2],t*100,!0):n=Q.Darken(i[0],i[1],i[2],-t*100,!0),r=`rgb(${n.r},${n.g},${n.b})`,c.tint_cache[e][t]=r}return r},R=(c,e,t)=>{if(e?.offset){if(e.offset.offset)return console.warn("invalid offset color"),"";let r=R(c,e.offset);if(c.offset_cache&&c.offset_cache[r])return c.offset_cache[r];let i=c.offset_light;if(r){let n=r.match(/rgb\((\d+), (\d+), (\d+)\)/);n?Q.RGBToHSL(Number(n[1]),Number(n[2]),Number(n[3])).l>.65&&(i=c.offset_dark):console.warn("can't offset against color",r),c.offset_cache||(c.offset_cache={}),c.offset_cache[r]=i}else console.warn("can't resolve offset color",e.offset);return i}return e?.text?e.text==="none"?"":e.text:e?.theme||e?.theme===0?e.tint?Ji(c,e.theme,e.tint):c.theme_colors?c.theme_colors[e.theme]:"":(t||t===0)&&c.theme_colors?c.theme_colors[t]:""},Xi=c=>{let e=10,t="pt",r=c.match(/^([\d.]+)(\D.*)$/);return r&&(e=Number(r[1]),t=r[2]),{value:e,unit:t}},Gr=c=>{let{value:e,unit:t}=Xi(c.fontSize||""),r={fill:{text:c.backgroundColor},text:{text:c.color},font_size:{unit:t,value:e},font_face:c.fontFamily};return/italic/i.test(c.font)&&(r.italic=!0),c.fontWeight==="700"&&(r.bold=!0),r},Qi=(c,e)=>{let t=c.grid_cell?.text,r=c.grid_cell?.fill;e.fillStyle=t?.text||"",e.fillRect(0,0,3,3);let i=Q.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));e.fillStyle=r?.text||"",e.fillRect(0,0,3,3);let n=Q.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));return i.l>n.l?"dark":"light"},ut=(c,e=.7)=>{let t={border_top:1,border_top_fill:{theme:c},border_bottom:1,border_bottom_fill:{theme:c}};return{header:{text:{offset:{theme:c}},fill:{theme:c},bold:!0,...t},odd:{fill:{theme:c,tint:e},...t},even:{...t},total:{...t,border_top:2}}},Hr=c=>{let e=JSON.parse(JSON.stringify(ht)),t=F.GetInstance(c.ownerDocument),r=(h,u)=>t.Div(u,h),i=(h,u)=>t.view?.getComputedStyle(r(h,u)),n=r(c,""),a=i.bind(0,n),s=a("grid-cells");e.grid_cell=Gr(s),e.grid_color=s.stroke||"",s=a("grid-headers"),e.headers=Gr(s),e.headers_grid_color=s.stroke,(!e.headers_grid_color||e.headers_grid_color==="none")&&(e.headers_grid_color=e.grid_color),s=a("treb-offset-dark"),s.color&&(e.offset_dark=s.color),s=a("treb-offset-light"),s.color&&(e.offset_light=s.color),s=a("note-marker"),e.note_marker_color=s.backgroundColor,n.style.color="rgba(1,2,3,.4)",s=a("");let o=s.color;e.theme_colors=[e.grid_cell.fill?.text||"rgb(255, 255, 255)",e.grid_cell.text?.text||"rgb(51, 51, 51)"];for(let h=1;h<32&&(s=a(`theme-color-${h}`),!(!s.color||s.color===o));h++)e.theme_colors.push(s.color);let l=t.Create("canvas");l.width=3,l.height=3;let d=l.getContext("2d",{willReadFrequently:!0});return d&&(e.mode=Qi(e,d)),d&&(e.theme_colors_rgb=e.theme_colors.map(h=>{d.fillStyle=h,d.fillRect(0,0,3,3);let u=d.getImageData(1,1,1,1);return Array.from(u.data)})),e.table=ut(4),n.parentElement?.removeChild(n),e};var Or={column:0,type:"auto",asc:!0};var qi=1e3,oe=class{constructor(e=!1,t){this.verbose=e;this.log_id=t}queue=[];dispatched=!1;subscribers=[];Publish(e){this.verbose&&console.info(`es publish (${this.log_id})`,e),Array.isArray(e)?this.queue.push(...e):this.queue.push(e),this.dispatched||(this.dispatched=!0,Promise.resolve().then(()=>{let t=this.queue.slice(0);this.dispatched=!1,this.queue=[];for(let r of t)for(let i of this.subscribers)i.subscriber(r)}))}Subscribe(e){let t=qi++;return this.subscribers.push({subscriber:e,token:t}),t}Cancel(e){this.subscribers=this.subscribers.filter(t=>t.token!==e)}CancelAll(){this.subscribers=[]}};var de=class{static color_measurement_canvas;static text_measurement_node;static color_cache={};static MeasureColorARGB(e){let t=this.MeasureColor(e),r="FF";for(let i=0;i<3;i++){let n=t[i].toString(16);n.length===0?r+="00":n.length===1?r+=`0${n}`:r+=n}return r.toUpperCase()}static MeasureColor(e){let t=this.color_cache[e];if(t)return t;this.color_measurement_canvas||(this.color_measurement_canvas=document.createElement("canvas"),this.color_measurement_canvas.width=1,this.color_measurement_canvas.height=1);let r=this.color_measurement_canvas.getContext("2d",{willReadFrequently:!0});return r?(r.fillStyle="#fff",r.fillRect(0,0,1,1),r.fillStyle=e,r.fillRect(0,0,1,1),t=new Uint8ClampedArray(r.getImageData(0,0,1,1).data),this.color_cache[e]=t,t):new Uint8ClampedArray(3)}static EnsureMeasurementNode(){if(!this.text_measurement_node){let e=document.querySelector(".treb-chart-measurement-node");e?this.text_measurement_node=e:(this.text_measurement_node=document.createElement("div"),this.text_measurement_node.classList.add("treb-chart-measurement-node"),this.text_measurement_node.style.margin="0px",this.text_measurement_node.style.padding="0px",this.text_measurement_node.style.height="initial",this.text_measurement_node.style.width="initial",this.text_measurement_node.style.whiteSpace="nowrap",this.text_measurement_node.style.position="fixed",this.text_measurement_node.style.border="0px",this.text_measurement_node.style.border="1px solid red",this.text_measurement_node.style.boxSizing="content-box",this.text_measurement_node.style.top=this.text_measurement_node.style.left="-1000px",document.body.appendChild(this.text_measurement_node))}}static MeasureText(e,t,r=0){this.EnsureMeasurementNode(),this.text_measurement_node.style.font=e,/\n/.test(t)?(t=t.replace(/\n/g,"<BR/>"),this.text_measurement_node.innerHTML=t):this.text_measurement_node.textContent=t,this.text_measurement_node.style.lineHeight="1em",r?this.text_measurement_node.style.transform=`rotate(${r}deg)`:this.text_measurement_node.style.transform="";let i=this.text_measurement_node.getBoundingClientRect();return{width:i.width,height:i.height}}};var nr,Ki=(c,e,t)=>{let r={};return Array.prototype.forEach.call(e,i=>{e[i]!==t[i]&&(r[i]=e[i])}),(Object.keys(r).map(i=>`${i}: ${r[i]}`).join("; ")+"; "+(c.getAttribute("style")||"")).trim().replace(/"/g,"'")},$r=(c,e)=>{let t=c.cloneNode(!1),r=getComputedStyle(c),i=Ki(c,r,e);return t.removeAttribute("class"),t.setAttribute("style",i),Array.prototype.forEach.call(c.childNodes,n=>{switch(n.nodeType){case Node.ELEMENT_NODE:t.appendChild($r(n,r));break;case Node.TEXT_NODE:c.textContent&&t.appendChild(document.createTextNode(c.textContent));break;case Node.COMMENT_NODE:break;default:console.warn("unhandled node type in serialize",n)}}),t},Zr=c=>{if(!nr){let e={},t=document.createElement("iframe");t.style.width="10px",t.style.height="10px",t.style.position="absolute",t.style.left="-100px",document.body.appendChild(t);let r=t.contentDocument;if(r){let i=r.createElement("div");r.body.appendChild(i);let n=getComputedStyle(i);Array.prototype.forEach.call(n,a=>e[a]=n[a])}document.body.removeChild(t),nr=e}return $r(c,nr)};var en={data:!0,same_origin:!0,remote:!1},mt=(c,e={})=>{let t={...en,...e};try{let r=new URL(c,document.location.href);return r.protocol==="data:"?t.data?r.href:void 0:r.origin===document.location.origin?t.same_origin?r.href:void 0:t.remote?r.hash:void 0}catch(r){console.error(r)}};var Br=(c,e,t=6.5,r=!1,i=!1)=>{if(e===c)e++,c&&c--;else{let h=Math.round(e*1e5)/1e5;Math.abs(h-e)/(e-c)<1e-5&&(e=h)}let n=e-c,a=Math.log(n)/Math.log(10),s=Math.floor(Math.abs(a))*(a<0?-1:1)-1;i&&(s=Math.max(0,s));let o=i?[1,2,5,10,15,20,25,50,100]:[.1,.25,.5,1,2.5,5,10,25,50,100],l=-1,d=0;for(let h of o){let u=h*Math.pow(10,s),m=Math.floor(c/u)*u,p=(Math.ceil(e/u)*u-m)/u,g=Math.abs(p-t);(l<0||g<d)&&(!r||p<=t)&&(d=g,l=u)}return c=Math.floor(c/l)*l,e=Math.ceil(e/l)*l,t=Math.round((e-c)/l),{scale:s,step:l,count:t,min:c,max:e}};var ft=class{constructor(e,t,r="HSL"){this.color_space=r;this.mapped=e.map(i=>{if(i.value<0||i.value>1)throw new Error("invalid stop value");let n=de.MeasureColor(R(t,i.color)),a=[];if(r==="HSL"){let s=Q.RGBToHSL(n[0],n[1],n[2]);a=[s.h,s.s,s.l]}else a=[...n];return{...i,resolved:a}}),this.mapped.sort((i,n)=>i.value-n.value),this.mapped[0].value>0&&this.mapped.unshift({...this.mapped[0],value:0}),this.mapped[this.mapped.length-1].value<1&&this.mapped.push({...this.mapped[this.mapped.length-1],value:1})}mapped;RenderColor(e){return this.color_space==="RGB"?{text:`rgb(${e})`}:{text:`hsl(${e[0]},${e[1]*100}%,${e[2]*100}%)`}}Interpolate(e){e=Math.min(1,Math.max(0,e));for(let[t,r]of this.mapped.entries()){if(e===r.value)return this.RenderColor(r.resolved);if(e<r.value){let i=this.mapped[t-1],n=r,a=n.value-i.value,s=e-i.value,o=[0,1,2].map(l=>i.resolved[l]+(n.resolved[l]-i.resolved[l])/a*s);return this.RenderColor(o)}}return{text:""}}};var ze=/[\s-+=<>!()]/,Xr=/['*\\]/,ar=34,sr=39,tn=160,Wr=32,rn=9,nn=10,an=13,ye=48,Ye=57,or=46,lr=43,Je=45,jr=40,cr=41,Xe=44,sn=37,dr=95,pt=36,on=123,ln=125,Qe=91,Yr=93,cn=33,Jr=59,dn=35,hn=64,Pe=65,qe=97,un=69,mn=101,bt=90,gt=122,fn=105;var hr=192,ur=312,mr={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},pn=Object.keys(mr).sort((c,e)=>e.length-c.length),bn={"-":100,"+":100},Ge=class{argument_separator=",";decimal_mark=".";flags={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0};r1c1_regex=/[rR]((?:\[[-+]{0,1}\d+\]|\d+))[cC]((?:\[[-+]{0,1}\d+\]|\d+))$/;argument_separator_char=Xe;decimal_mark_char=or;imaginary_char=fn;imaginary_number="i";id_counter=0;expression="";data=[];index=0;length=0;valid=!0;error_position;error;dependencies={addresses:{},ranges:{}};address_refcount={};full_reference_list=[];Walk(e,t){switch(e.type){case"address":case"missing":case"literal":case"complex":case"identifier":case"operator":case"structured-reference":t(e);return;case"dimensioned":t(e)&&(this.Walk(e.expression,t),this.Walk(e.unit,t));return;case"range":t(e)&&(this.Walk(e.start,t),this.Walk(e.end,t));return;case"binary":t(e)&&(this.Walk(e.left,t),this.Walk(e.right,t));return;case"unary":t(e)&&this.Walk(e.operand,t);return;case"group":t(e)&&e.elements.forEach(r=>this.Walk(r,t));return;case"call":t(e)&&e.args.forEach(r=>this.Walk(r,t))}}Transpose(e){let t=e.length,r=[],i=0;for(let n=0;n<t;n++)Array.isArray(e[n])&&(i=Math.max(i,e[n].length));for(let n=0;n<i;n++){r[n]=[];for(let a=0;a<t;a++)r[n][a]=e[a][n]}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},i=t.missing??"(missing)",{convert_decimal:n,convert_argument_separator:a,convert_imaginary_number:s,long_structured_references:o,table_name:l}=t,d=this.argument_separator+" ";a===","?d=", ":a===";"&&(d="; ");let h=this.imaginary_number;s&&(h=s);let u=n===","?",":".",m=this.decimal_mark===","?/,/:/\./,f=this.decimal_mark===","?/,/g:/\./g;switch(e.type){case"address":return this.AddressLabel(e,r);case"range":return this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return i;case"array":return"{"+this.Transpose(e.values).map(p=>p.map(g=>typeof g=="string"?'"'+g+'"':g).join(", ")).join("; ")+"}";case"binary":return this.Render(e.left,t)+" "+e.operator+" "+this.Render(e.right,t);case"unary":return e.operator+this.Render(e.operand,t);case"complex":if(e.text)return n?e.text.replace(f,u):e.text;{let p=Math.abs(e.imaginary).toString();if((n===","||this.decimal_mark===",")&&(p=p.replace(/\./,",")),e.real){let g=e.real.toString();(n===","||this.decimal_mark===",")&&(g=g.replace(/\./,","));let b=Math.abs(e.imaginary);return`${g}${e.imaginary<0?" - ":" + "}${b===1?"":p}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${p}i`}break;case"literal":if(typeof e.value=="string")return'"'+e.value.replace(/"/g,'""')+'"';if(n&&typeof e.value=="number")if(e.text){let p=e.text;return n===","&&this.decimal_mark==="."&&(p=p.replace(/,/g,"")),p.replace(m,u)}else return e.value.toString().replace(/\./,u);else if(e.text)return e.text;return e.value.toString();case"identifier":return e.name;case"operator":return"["+e.operator+"]";case"group":return e.explicit?"("+e.elements.map(p=>this.Render(p,t)).join(d)+")":e.elements.map(p=>this.Render(p,t)).join(d);case"call":return e.name+"("+e.args.map(p=>this.Render(p,t)).join(d)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let p=e.column;/[^A-Za-z]/.test(p)&&(p="["+p+"]");let g=e.table;switch(!g&&o&&l&&(g=l),e.scope){case"all":return`${g}[[#all],${p}]`;case"row":return o?`${g}[[#this row],${p}]`:`${g}[@${p}]`;case"column":return`${g}[${p}]`}throw new Error("unhandled scope in structured reference")}}return"??"}Parse(e){switch(e=e.trim(),e[0]==="="&&(e=e.substr(1).trim()),this.expression=e,this.data=[],this.length=e.length,this.index=0,this.valid=!0,this.error_position=void 0,this.error=void 0,this.dependencies.addresses={},this.dependencies.ranges={},this.address_refcount={},this.full_reference_list=[],this.id_counter=0,this.argument_separator){case";":this.argument_separator_char=Jr;break;default:this.argument_separator_char=Xe;break}switch(this.decimal_mark){case",":this.decimal_mark_char=Xe;break;default:this.decimal_mark_char=or;break}for(let i=0;i<this.length;i++)this.data[i]=e.charCodeAt(i);let t=this.ParseGeneric(),r={};for(let i of Object.keys(this.dependencies.addresses))this.address_refcount[i]&&(r[i]=this.dependencies.addresses[i]);return this.dependencies.addresses=r,{expression:t||void 0,valid:this.valid,error:this.error,error_position:this.error_position,dependencies:this.dependencies,separator:this.argument_separator,decimal_mark:this.decimal_mark,full_reference_list:this.full_reference_list.slice(0)}}ColumnLabel(e){if(e===1/0)return"";let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}AddressLabel(e,t){let r=e.column;!e.absolute_column&&e.column!==1/0&&(r+=t.columns);let i=e.row;if(!e.absolute_row&&e.row!==1/0&&(i+=t.rows),i<0||r<0||i===1/0&&r===1/0)return"#REF";let n="";return e.sheet&&(n=(ze.test(e.sheet)?"'"+e.sheet+"'":e.sheet)+"!"),i===1/0?n+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?n+(e.absolute_row?"$":"")+(i+1):n+(e.absolute_column?"$":"")+this.ColumnLabel(r)+(e.absolute_row?"$":"")+(i+1)}ParseGeneric(e=[0]){let t=[];for(;this.index<this.length;){let r=this.ParseNext(t.length===0);if(typeof r=="number"){if(e.some(i=>r===i))break;if(r===jr){this.index++;let i=this.ParseGeneric([cr]);this.index++,i&&t.push({type:"group",id:this.id_counter++,elements:[i],explicit:!0})}else{let i=this.ConsumeOperator();i?t.push(i):(this.error=`unexpected character [1]: ${String.fromCharCode(r)}, 0x${r.toString(16)}`,this.valid=!1,this.index++)}}else t.push(r)}if(t.length){if(t=this.BinaryToRange2(t),this.flags.fractions){let r=[],i=a=>a.type==="literal"&&typeof a.value=="number"&&a.value%1===0,n=0;for(;n<t.length-3;n++)if(i(t[n])&&i(t[n+1])&&t[n+2].type==="operator"&&t[n+2].operator==="/"&&i(t[n+3])){let a=t[n],s=t[n+1],o=t[n+3],l=(a.value<0?-1:1)*(s.value/o.value);n+=3,r.push({id:t[n].id,type:"literal",text:this.expression.substring(a.position,o.position+1),value:a.value+l,position:a.position})}else r.push(t[n]);for(;n<t.length;n++)r.push(t[n]);t=r}if(t=t.map(r=>r.type==="identifier"&&r.name===this.imaginary_number?{type:"complex",real:0,imaginary:1,position:r.position,text:r.name,id:this.id_counter++}:r),this.flags.dimensioned_quantities){let r=[],i;for(let n=0;n<t.length;n++){let a=t[n];if(!i)i=a;else if(a.type==="identifier"&&(i.type==="literal"||i.type==="group"||i.type==="call")){let s=a;for(;t[n+1]?.type==="identifier";)s.name+=" "+t[++n].name;r.push({type:"dimensioned",expression:i,unit:a,id:this.id_counter++}),i=void 0}else r.push(i),i=a}i&&r.push(i),t=r}}return t.length===0?null:t.length===1?t[0]:this.BinaryToComplex(this.ArrangeUnits(t))}UnitToAddress(e){if(e.type==="literal"){if(typeof e.value=="number"&&e.value>0&&!/\./.test(e.text||""))return{type:"address",position:e.position,label:e.value.toString(),row:e.value-1,id:this.id_counter++,column:1/0}}else{let t,r=e.name,i=r.split("!");if(i.length>1&&(t=i.slice(0,i.length-1).join("!"),r=r.substr(t.length+1),t[0]==="'"))if(t.length>1&&t[t.length-1]==="'")t=t.substr(1,t.length-2);else return;let n=r[0]==="$";r=(n?r.substr(1):r).toUpperCase();let a=Number(r);if(isNaN(a)){if(/[A-Z]{1,3}/.test(r)){let s=-1;for(let o=0;o<r.length;o++){let l=r[o].charCodeAt(0);s=26*(1+s)+(l-Pe)}return{type:"address",position:e.position,absolute_column:n,label:e.name,column:s,id:this.id_counter++,row:1/0,sheet:t}}}else if(a>0&&a!==1/0&&!/\./.test(r))return{type:"address",position:e.position,absolute_row:n,label:e.name,row:a-1,id:this.id_counter++,column:1/0,sheet:t}}}BinaryToRange2(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],n=e[r+1],a=e[r+2],s,o="",l;if(i&&n&&a&&n.type==="operator"&&n.operator===":"){if(i.type==="address"&&a.type==="address"){let d=i.position+i.label.length,h=a.position;s={type:"range",id:this.id_counter++,position:i.position,start:i,end:a,label:i.label+this.expression.substring(d,h)+a.label},o=s.start.label+":"+s.end.label,this.address_refcount[s.start.label]--,this.address_refcount[s.end.label]--;let u=[i.position,a.position];this.full_reference_list=this.full_reference_list.filter(m=>m.position!==u[0]&&m.position!==u[1])}else if((i.type==="literal"||i.type==="identifier")&&(a.type==="literal"||a.type==="identifier")){let d=this.UnitToAddress(i);if(!d&&i.type==="literal"&&typeof i.value=="number"&&i.value<0){let u={...i,text:(i.text||"").replace(/^-/,""),position:i.position+1,value:-i.value};d=this.UnitToAddress(u),d&&(l={type:"operator",operator:"-",position:i.position,id:this.id_counter++})}let h=this.UnitToAddress(a);d&&h&&(d.column===1/0&&h.column===1/0||d.row===1/0&&h.row===1/0)&&(o=d.label+":"+h.label,s={type:"range",id:this.id_counter++,position:d.position,start:d,end:h,label:o})}}s?(l&&t.push(l),t.push(s),this.dependencies.ranges[o]=s,this.full_reference_list.push(s),r+=2):t.push(i)}return t}BinaryToComplex(e){if(e.type==="binary")if((e.operator==="+"||e.operator==="-")&&e.left.type==="literal"&&typeof e.left.value=="number"&&e.right.type==="complex"&&!e.right.composited){let t="";t=this.expression.substring(e.left.position,e.right.position+(e.right.text?.length||0));let r=e.right.imaginary;return e.operator==="-"&&(r=-r),{type:"complex",position:e.left.position,text:t,id:this.id_counter++,imaginary:r,real:e.left.value,composited:!0}}else e.left=this.BinaryToComplex(e.left),e.right=this.BinaryToComplex(e.right);else if(e.type==="unary"&&(e.operator==="-"||e.operator==="+")&&e.operand.type==="complex"&&e.operand.text===this.imaginary_number)return{...e.operand,position:e.position,text:this.expression.substring(e.position,e.operand.position+(e.operand.text||"").length),imaginary:e.operand.imaginary*(e.operator==="-"?-1:1)};return e}BinaryToRangeX(e){if(e.type==="binary"){if(e.operator===":"){let t,r="";if(e.left.type==="address"&&e.right.type==="address"){let i=e.left.position+e.left.label.length,n=e.right.position;t={type:"range",id:this.id_counter++,position:e.left.position,start:e.left,end:e.right,label:e.left.label+this.expression.substring(i,n)+e.right.label},r=t.start.label+":"+t.end.label,this.address_refcount[t.start.label]--,this.address_refcount[t.end.label]--;let a=[e.left.position,e.right.position];this.full_reference_list=this.full_reference_list.filter(s=>s.position!==a[0]&&s.position!==a[1])}else if((e.left.type==="literal"||e.left.type==="identifier")&&(e.right.type==="literal"||e.right.type==="identifier")){let i=this.UnitToAddress(e.left),n=this.UnitToAddress(e.right);i&&n&&(i.column===1/0&&n.column===1/0||i.row===1/0&&n.row===1/0)&&(r=i.label+":"+n.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:i,end:n,label:r})}if(t)return this.dependencies.ranges[r]=t,this.full_reference_list.push(t),t;this.error="unexpected character: :",this.valid=!1}e.left=this.BinaryToRangeX(e.left),e.right=this.BinaryToRangeX(e.right)}return e}ArrangeUnits(e){if(e.length===0)return{type:"missing",id:this.id_counter++};if(e.length===1)return e[0];let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(bn[i.operator]){let n=this.BinaryToComplex(this.ArrangeUnits(e.slice(r+1)));if(!this.valid)return{type:"group",id:this.id_counter++,elements:e,explicit:!1};n.type==="binary"?(n.left={type:"unary",id:this.id_counter++,operator:i.operator,operand:n.left,position:i.position},i=n):i={type:"unary",id:this.id_counter++,operator:i.operator,operand:n,position:i.position},r=e.length}else return this.error=`unexpected character [2]: ${i.operator}`,this.error_position=i.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1};else{t.push(i);continue}if(t.length<2)t.push(i);else if(t[t.length-1].type==="operator"){let n=t[t.length-2],a=t[t.length-1],s=a.operator,o={type:"binary",id:this.id_counter++,left:n,operator:s,position:a.position,right:i};n.type==="binary"&&mr[s]>mr[n.operator]&&(o.left=n.left,o.operator=n.operator,o.position=n.position,o.right={type:"binary",id:this.id_counter++,left:n.right,right:i,operator:s,position:a.position}),t.splice(-2,2,o)}else return this.error="multiple expressions",this.error_position=i.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1}}return t[0]}ParseNext(e=!0){this.ConsumeWhiteSpace();let t=this.data[this.index];if(t===ar)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ye&&t<=Ye||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===on)return this.ConsumeArray();if(e&&(t===Je||t===lr)){let r=this.data[this.index+1];if(r>=ye&&r<=Ye||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Pe&&t<=bt||t>=qe&&t<=gt||t===dr||t===dn||t===sr||t===pt||t===Qe||t>=hr&&t<=ur)return this.ConsumeToken(t);return t}ConsumeArray(){let e={type:"array",id:this.id_counter++,values:[],position:this.index};this.index++;let t=0,r=0;for(;this.index<this.length;){let i=this.ParseNext(),n=this.index;if(typeof i=="number")switch(this.index++,i){case Jr:r++,t=0;break;case Xe:t++;break;case ln:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=n,this.valid=!1);break}else switch(i.type){case"literal":e.values[t]||(e.values[t]=[]),e.values[t][r]=i.value;break;default:this.valid&&(this.error="invalid value in array literal",this.error_position=n,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of pn)if(this.expression.substr(this.index,e.length)===e){let t=this.index;return this.index+=e.length,{type:"operator",id:this.id_counter++,operator:e,position:t}}return null}ConsumeArguments(){this.index++;let e=0,t=[];for(;this.index<this.length;){let r=this.ParseGeneric([this.argument_separator_char,cr]);r!==null&&t.push(r);let i=this.data[this.index];if(i===this.argument_separator_char){this.index++,e++;for(let n=t.length;n<e;n++)t.push({type:"missing",id:this.id_counter++})}else if(i===cr)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,i=e===sr,n=0,a=!1;for(e===Qe&&(n=1,a=!0),++this.index;this.index<this.length;this.index++){let d=this.data[this.index];if(d>=Pe&&d<=bt||d>=qe&&d<=gt||d>=hr&&d<=ur||d===dr||d===pt||d===or||d===cn||i||d>=ye&&d<=Ye||d===Qe||n>0&&d===Yr||d===Je&&this.flags.r1c1&&n===1||n>0&&d===hn&&this.data[this.index-1]===Qe||n===1&&(d===Xe||d===Wr)||n>1)t.push(d),d===Qe&&(n++,a=!0),d===Yr&&n--,d===sr&&(i=!1);else break}let s=t.map(d=>String.fromCharCode(d)).join("");if(i)return this.error="unbalanced single quote",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:s,position:r};if(n)return this.error="unbalanced square bracket",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:s,position:r};if(s.toLowerCase()==="true")return{type:"literal",id:this.id_counter++,value:!0,position:r};if(s.toLowerCase()==="false")return{type:"literal",id:this.id_counter++,value:!1,position:r};if(this.ConsumeWhiteSpace(),this.data[this.index]===jr){let d=this.ConsumeArguments();return{type:"call",id:this.id_counter++,name:s,args:d,position:r}}if(this.flags.spreadsheet_semantics){let d=this.ConsumeAddress(s,r);if(d)return d;if(a){let h=this.ConsumeStructuredReference(s,r);if(h)return h}}let l={type:"identifier",id:this.id_counter++,name:s,position:r};return this.full_reference_list.push(l),l}ConsumeStructuredReference(e,t){let r=t,i=e.length,n=e,a="",s=0;for(;s<i;s++){if(e[s]==="["){e=e.substring(s);break}a+=e[s]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let o=e.split(",").map(u=>u.trim()),l="column",d="";if(o.length>2)return;o.length===2?(/\[#this row\]/i.test(o[0])?l="row":/\[#all\]/i.test(o[0])&&(l="all"),d=o[1]):(d=o[0],d[0]==="@"&&(l="row",d=d.substring(1,d.length))),d[0]==="["&&d[d.length-1]==="]"&&(d=d.substring(1,d.length-1));let h={type:"structured-reference",id:this.id_counter++,label:n,position:t,scope:l,column:d,table:a};return this.full_reference_list.push(h),h}ConsumeAddress(e,t){let r=t,i=e.length,n,a=e.split("!");if(a.length>1&&(n=a.slice(0,a.length-1).join("!"),t+=n.length+1),this.flags.r1c1){let h=a[a.length-1].match(this.r1c1_regex);if(h){let u={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:n,r1c1:!0};return h[1][0]==="["?(u.offset_row=!0,u.row=Number(h[1].substring(1,h[1].length-1))):u.row=Number(h[1])-1,h[2][0]==="["?(u.offset_column=!0,u.column=Number(h[2].substring(1,h[2].length-1))):u.column=Number(h[2])-1,u}}let s=this.ConsumeAddressColumn(t);if(!s)return null;t=s.position;let o=this.ConsumeAddressRow(t);if(!o)return null;t=o.position;let l=n?n+e.substr(n.length,t-r).toUpperCase():e.substr(0,t-r).toUpperCase();n&&n[0]==="'"&&(n=n.substr(1,n.length-2));let d={type:"address",id:this.id_counter++,label:l,row:o.row,column:s.column,absolute_row:o.absolute,absolute_column:s.absolute,position:r,sheet:n};return i!==t-r?null:(this.dependencies.addresses[d.label]=d,this.address_refcount[d.label]=(this.address_refcount[d.label]||0)+1,this.full_reference_list.push(d),d)}ConsumeAddressRow(e){let t=this.data[e]===pt;t&&e++;let r=e,i=0;for(;;e++){let n=this.data[e];if(n>=ye&&n<=Ye)i*=10,i+=n-ye;else break}return r===e?!1:{absolute:t,row:i-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,i=this.data[e]===pt;for(i&&e++;;e++,r++){if(r>=4)return!1;let n=this.data[e];if(n>=Pe&&n<=bt)t=26*(1+t)+(n-Pe);else if(n>=qe&&n<=gt)t=26*(1+t)+(n-qe);else break}return t<0?!1:{absolute:i,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,i=!1,n=0,a=0,s=0,o="integer",l=0,d=!1,h=this.index;for(;this.index<this.length;this.index++,l++){let m=this.data[this.index];if(m===this.decimal_mark_char)if(o==="integer")o="fraction";else break;else if(m===sn){n/=100,s/=100,this.index++;break}else if(m===lr||m===Je)if(l===0)m===Je&&(i=!0);else break;else if(m===un||m===mn)if(o==="integer"||o==="fraction")o="exponent",this.index<this.length-1&&(this.data[this.index+1]===lr?this.index++:this.data[this.index+1]===Je&&(this.index++,r=!0));else break;else if(m===this.imaginary_char){let f=this.data[this.index+1];if(f>=Pe&&f<=bt||f>=qe&&f<=gt||f>=hr&&f<=ur||f===dr)break;if(o==="integer"||o==="fraction"){this.index++,d=!0;break}}else if(m>=ye&&m<=Ye)switch(o){case"integer":n=n*10+(m-ye);break;case"fraction":s=s*10+(m-ye),a++;break;case"exponent":t=t*10+(m-ye);break}else break}let u=n+s/Math.pow(10,a);return o==="exponent"&&(u=u*Math.pow(10,(r?-1:1)*t)),d?{type:"complex",id:this.id_counter++,position:e,imaginary:i?-u:u,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:i?-u:u,text:this.expression.substring(h,this.index)||""}}ConsumeString(){this.index++;let e=[];for(;this.index<this.length;this.index++){let t=this.data[this.index];if(t===ar&&(this.index++,this.index>=this.length||this.data[this.index]!==ar))break;e.push(t)}return e.map(t=>String.fromCharCode(t)).join("")}ConsumeWhiteSpace(){for(;this.index<this.length;){let e=this.data[this.index];if(e===Wr||e===rn||e===nn||e===an||e===tn)this.index++;else return}}};var Qr=(c,e=",")=>{let t=0,r=[],i="",n=[],a=c.length;if(/[\r\n"]/.test(e))throw new Error("invalid delimiter");for(let s=0;s<a;s++){let o=c[s];if(!(s===0&&o.charCodeAt(0)===65279))if(t===0)switch(o){case e:r.push(i),i="";break;case"\r":break;case`
|
|
3
|
+
`:r.push(i),i="",n.push(r),r=[];break;case'"':i.length===0?t=1:i+=o;break;default:i+=o;break}else o==='"'?s+1<a&&c[s+1]==='"'?(i+='"',s++):t=0:i+=o}return(r.length||i.length)&&(r.push(i),n.push(r)),n};var Re=class c{static _instance=new c;constructor(){}static get instance(){return this._instance}HTML(e){let t=[];for(let r of e){let i=[];for(let n of r)n.pre&&i.push("<pre>"),n.emphasis&&i.push("<em>"),n.strong&&i.push("<strong>"),n.strike&&i.push("<strike>"),i.push(n.text),n.strike&&i.push("</strike>"),n.strong&&i.push("</strong>"),n.emphasis&&i.push("</em>"),n.pre&&i.push("</pre>");t.push(i.join(""))}return t.join(`<br/>
|
|
4
4
|
`)}Dummy(e=""){return e.split(/\n/).map(t=>[{text:t}])}Parse(e=""){let t=this.Tokenize(e);for(let r=0;r<t.length;r++){let i=t[r];if(i.type==="delimeter"){let n=t[r-1],a=t[r+1],s=!n||n.type==="whitespace"||n.type==="newline",o=n&&n.type==="text"&&/[^\w\d]$/.test(n.text),l=!a||a.type==="whitespace"||a.type==="newline",d=a&&a.type==="text"&&/^[^\w\d]/.test(a.text);i.left_flanking=!l&&(!d||s),i.right_flanking=!s&&(!o||l||d)}}return this.ApplyFormatting(t),this.Consolidate(t)}IsWhitespace(e){return e===" "||e===" "}IsNewline(e){return e==="\r"||e===`
|
|
5
|
-
`}IsDelimeter(e){return e==="*"||e==="_"||e==="~"}Consolidate(e){let t=[],r={},i=[],n={type:"text",text:""};for(let a of e)if(a.type==="newline")n.text.length&&i.push(n),n={...r,text:"",type:"text"},t.push(i),i=[];else switch((!!r.strong!=!!a.strong||!!r.emphasis!=!!a.emphasis||!!r.strike!=!!a.strike)&&(r.strong=!!a.strong,r.emphasis=!!a.emphasis,r.strike=!!a.strike,n.text.length&&i.push(n),n={...r,text:"",type:"text"}),a.type){case"text":case"whitespace":n.text+=a.text;break;case"delimeter":for(let s=0;s<a.length;s++)n.text+=a.char;break}return n.text.length&&i.push(n),i.length&&t.push(i),t}ApplyFormatting(e,t){let r=0,i=e.length;for(r=0;r<i;r++){let n=e[r];if(n.type==="delimeter"){if(t&&n.right_flanking&&t.char===n.char&&n.length>0)return{index:r,token:n};if(n.left_flanking){let a=this.ApplyFormatting(e.slice(r+1),n);if(a.token){let s=Math.min(a.token.length,n.length),o=n.char==="~",l=!o&&!!(s%2),d=!o&&s>=2;for(let h=r+1;h<=r+a.index;h++)e[h].strong=!!e[h].strong||d,e[h].emphasis=!!e[h].emphasis||l,e[h].strike=!!e[h].strike||o;a.token.length-=s,n.length-=s,n.length>0?r--:r+=a.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,i=0,n=!1,a="";for(i=0;i<r;i++){let s=e[i];if(this.IsWhitespace(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(this.IsWhitespace(l))o+=l,i++;else break}t.push({type:"whitespace",text:o}),n=!1,a=""}else if(this.IsNewline(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(this.IsNewline(l))o+=l,i++;else break}t.push({type:"newline",text:o}),n=!1,a=""}else if(n)a+=s,n=!1;else if(this.IsDelimeter(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(l===s)o+=l,i++;else break}t.push({type:"delimeter",text:o,char:s,length:o.length}),n=!1,a=""}else s==="\\"?n=!0:a+=s}return a&&t.push({type:"text",text:a}),t}};var ve=class{date_format=!1;string_format=!1;fraction_format=!1;twelve_hour=!1;fraction_denominator=0;fraction_integer=!0;fraction_align=0;fraction_denominator_digits=0;integer_min_digits=0;decimal_min_digits=0;decimal_max_digits=0;grouping=!1;has_number_format=!1;prefix=[{text:""}];suffix=[{text:""}];scaling=0;percent=!1;exponential=!1;has_asterisk=!1};var qr=42,Kr=95,fr=63,vt=48,ei=46,pr=44,ti=37,br=34,Ke=35,ri=59,wt=92,ii=64,gn=91,_n=93,ni=69,ai=101,yn=72,vn=104,wn=77,xn=109,Cn=83,An=115,Sn=68,kn=100,Rn=89,Tn=121,En=65,Mn=97;var xt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new ve;static preserve_formatting_characters=!1;static decimal_mark=ei;static group_separator=pr;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new ve,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new ve,this.sections=[this.current_section];this.char_index<this.characters.length;)this.ConsumeChar();return this.sections}static ConsumeString(){let e="";for(this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case wt:this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index+1<this.characters.length&&(e+=this.pattern[++this.char_index]);break;case br:return this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated string")}static ConsumeFormatting(){let e="";for(++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case wt:throw new Error("invalid escape character in formatting block");case _n:return this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated format")}static ScanFractionFormat(){let e=/^([#?]+ +){0,1}([#?]+)\/([#?0-9]+)(?:$|[^#?0-9])/,r=this.pattern.substr(this.char_index).match(e);if(!r)return!1;let i=(r[1]||"").length+r[2].length+r[3].length+1;this.current_section.fraction_format=!0,this.current_section.fraction_integer=!!r[1];let n=Number(r[3]);return isNaN(n)||(this.current_section.fraction_denominator=n),this.current_section.decimal_max_digits=this.current_section.fraction_denominator_digits=r[3].length,this.char_index+=i,this.current_section.has_number_format=!0,!0}static ConsumeNumberFormat(){let e=0;for(this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case this.group_separator:{let r=!1;for(let i=this.char_index+1;!r&&i<this.characters.length;i++){let n=this.characters[i];if(n===this.decimal_mark||n===Ke||n===vt)r=!0;else if(n!==pr)break}if(r){if(e===1)throw new Error("invalid grouping in decimal part");this.current_section.grouping=!0}else this.current_section.scaling=(this.current_section.scaling||1)*1e3}break;case this.decimal_mark:if(e===1)throw new Error("too many decimal marks");e=1;break;case Ke:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case vt:e===1?(this.current_section.decimal_max_digits++,this.current_section.decimal_min_digits=this.current_section.decimal_max_digits):this.current_section.integer_min_digits++;break;default:return}}static AppendCharAsText(e=!0){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=this.pattern[this.char_index]:this.current_section.prefix[this.current_section.prefix.length-1].text+=this.pattern[this.char_index],e&&this.char_index++}static AppendString(e){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=e:this.current_section.prefix[this.current_section.prefix.length-1].text+=e}static AppendTextPart(e){this.current_section.has_number_format?(this.current_section.suffix.push(e),this.current_section.suffix.push({text:""})):(this.current_section.prefix.push(e),this.current_section.prefix.push({text:""}))}static ConsumeChar(){let e=this.characters[this.char_index];if(!((e===fr||e===Ke)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case ri:this.char_index++,this.current_section=new ve,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case ii:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case vt:case Ke:case ei:case pr:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case gn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case br:this.AppendString(this.ConsumeString());break;case fr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Kr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case qr:if(this.current_section.has_asterisk)throw new Error("we don't support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case ai:case ni:this.current_section.percent||this.current_section.exponential||this.current_section.string_format?this.AppendCharAsText():(this.current_section.exponential=!0,this.char_index++);break;case ti:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case wt:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}static ParseDatePattern(){for(this.date_pattern=!0;this.date_pattern&&this.char_index<this.pattern.length;)this.DatePatternConsumeChar();if(this.date_pattern){this.date_pattern=!1;for(let e of this.sections)for(let t of e.prefix)t.flag&&t.flag&7&&(this.date_pattern=!0)}return this.date_pattern&&(this.sections[0].date_format=!0,this.sections[0].prefix.forEach((e,t)=>{if(e.flag===3&&(e.text==="mm"||e.text==="m")){if(t)for(let r=t-1;r;r--){let i=this.sections[0].prefix[r];if(i.flag===3){/h/i.test(i.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}if(t<this.sections[0].prefix.length-1)for(let r=t+1;r<this.sections[0].prefix.length;r++){let i=this.sections[0].prefix[r];if(i.flag===3){/s/i.test(i.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}}})),this.date_pattern}static ConsumeDatePart(){let e=this.pattern[this.char_index++],t=e.toLowerCase(),r={text:e,flag:3};for(;this.pattern[this.char_index]&&this.pattern[this.char_index].toLowerCase()===t;)r.text+=this.pattern[this.char_index++];if(t==="s"&&this.pattern[this.char_index]===".")for(r.text+=this.pattern[this.char_index++];this.pattern[this.char_index]==="0";)r.text+=this.pattern[this.char_index++];return r}static ConsumeAMPM(){let e=this.pattern.substr(this.char_index,5);if(e==="am/pm"||e==="AM/PM")return this.char_index+=5,this.sections[0].twelve_hour=!0,{text:e,flag:3};if(e=this.pattern.substr(this.char_index,3),e==="a/p"||e==="A/P")return this.char_index+=3,this.sections[0].twelve_hour=!0,{text:e,flag:3}}static DatePatternConsumeChar(){switch(this.characters[this.char_index]){case ri:this.char_index=this.characters.length;break;case vt:case Ke:case ai:case ni:case ti:case ii:this.date_pattern=!1;break;case yn:case vn:case wn:case xn:case Cn:case An:case Sn:case kn:case Rn:case Tn:this.AppendTextPart(this.ConsumeDatePart());break;case En:case Mn:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case br:this.AppendString(this.ConsumeString());break;case fr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Kr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case qr:if(this.current_section.has_asterisk)throw new Error("we don't support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case wt:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}};var De=c=>(c>=60&&c--,new Date(-22090752e5+864e5*c)),He=(c,e=!0)=>{if(e){let t=new Date(c),r=new Date;r.setUTCMilliseconds(t.getUTCMilliseconds()),r.setUTCSeconds(t.getUTCSeconds()),r.setUTCMinutes(t.getUTCMinutes()),r.setUTCHours(t.getHours()),r.setUTCDate(t.getDate()),r.setUTCMonth(t.getMonth()),r.setUTCFullYear(t.getFullYear()),c=r.getTime()}return c=(c+22090752e5)/864e5,c>=60&&c++,c},te=class c{static grouping_regexp=/\d{1,3}(?=(\d{3})+(?!\d))/g;static fraction_limits=[9,99,999,9999];static imaginary_character="\u{1D456}";static minus_character="-";magic_decimal=!1;transform_value;_pattern="";sections;decimal_zero_regexp=[];cloned=[];get pattern(){return this._pattern}get date_format(){return this.sections[0]&&this.sections[0].date_format}constructor(e){if(this._pattern=e,this.sections=xt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new ve),this.sections[1]||(this.sections[1]={...this.sections[0]},this.sections[1].prefix=JSON.parse(JSON.stringify(this.sections[1].prefix)),this.sections[1].suffix=JSON.parse(JSON.stringify(this.sections[1].suffix)),this.sections[1].prefix.push({text:"-"}),this.cloned[1]=!0),this.sections[2]||(this.sections[2]={...this.sections[0]},this.cloned[2]=!0),!this.sections[3]){for(let t of this.sections[0].prefix)if(t.flag===5){this.sections[3]={...this.sections[0]},this.sections[3].string_format=!0,this.cloned[3]=!0;break}}this.decimal_zero_regexp=this.sections.map(t=>{if(t.decimal_max_digits>t.decimal_min_digits)return new RegExp(`0{1,${t.decimal_max_digits-t.decimal_min_digits}}(?:$|e)`)})}static FormatPartsAsText(e,t=0){let r=-1,i=e.map((n,a)=>{switch(n.flag){case 2:return r=a,n.text;case 1:return n.text.replace(/./g," ");case 6:return"";default:return n.text}});if(r>=0&&t){let n=i.reduce((s,o,l)=>l===r?s:s+o.length,0),a="";for(let s=0;s<t-n;s++)a+=i[r];i[r]=a}return i.join("")}SetDecimal(e){for(let t of this.sections)t.fraction_format||(t.decimal_min_digits=e,t.decimal_max_digits=e)}IncreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.min(e.fraction_denominator_digits+1,4)):(e.decimal_min_digits++,e.decimal_max_digits=e.decimal_min_digits)})}DecreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.max(e.fraction_denominator_digits-1,1)):(e.decimal_min_digits=Math.max(0,e.decimal_min_digits-1),e.decimal_max_digits=e.decimal_min_digits)})}AddGrouping(){this.sections.forEach(e=>{e.grouping=!0})}RemoveGrouping(){this.sections.forEach(e=>{e.grouping=!1})}ToggleGrouping(){let e=!this.sections[0].grouping;this.sections.forEach(t=>{t.grouping=e})}toString(){return this.sections[0].date_format?this._pattern:this.sections.filter((e,t)=>!this.cloned[t]).map(e=>{let t="",r=0;if(e.fraction_format){e.fraction_integer&&(t+="? ");let i="";for(let n=0;n<e.fraction_denominator_digits;n++)i+="#";t+=i,t+="/",e.fraction_denominator?t+=e.fraction_denominator:t+=i}else if(e.has_number_format){for(r=0;r<e.integer_min_digits;r++)t+="0";if(e.grouping&&(t.length<4&&(t=("####"+t).slice(-4)),t=t.replace(/[\d#]{1,3}(?=([\d#]{3})+(?![\d#]))/g,"$&,")),e.decimal_max_digits||e.decimal_min_digits){for(t+=".",r=0;r<e.decimal_min_digits;r++)t+="0";for(;r<e.decimal_max_digits;r++)t+="#"}if(e.scaling){let i=Math.log10(e.scaling)/3;for(r=0;r<i;r++)t+=","}e.exponential&&(t+="e")}return e.prefix.map(i=>i.flag===1?i.text==="0"?"?":"_"+i.text:i.flag===2?"*"+i.text:i.flag===6?"["+i.text+"]":i.text).join("")+t+e.suffix.map(i=>i.flag===1?i.text==="0"?"?":"_"+i.text:i.flag===2?"*"+i.text:i.text).join("")}).join(";")}FormatDimensionedQuantity(e){if(this.transform_value){let r=this.transform_value(e);if(Kt(r))e=r;else return typeof r=="string"?r:this.FormatParts(r)}let t=this.FormatParts(e.value||0);return e.unit&&t.push({text:" "},{text:e.unit}),t}FormatComplex(e){let t=[],r=[],i=!1,n=!!e.imaginary;n&&(t=this.FormatParts(e.imaginary),n=t.some(o=>/[1-9]/.test(o.text)),t.length===1&&this.sections[0].integer_min_digits<=1&&t[0].text==="1"?(t[0].text="",i=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",i=!0));let a=!!e.real;a&&(r=this.FormatParts(e.real),a=r.some(o=>/[1-9]/.test(o.text)));let s=[];if(a||!a&&!n){if(s.push(...r),n){let o=Math.abs(e.imaginary);s.push({text:e.imaginary<0?` ${c.minus_character} `:" + "});let l=i?[]:this.FormatParts(Math.abs(e.imaginary));s.push(...l,{text:c.imaginary_character})}}else n&&s.push(...t,{text:c.imaginary_character});return s}FormatParts(e){if(typeof e!="number"&&!this.sections[3])return[{text:e.toString()}];let{parts:t,section:r}=this.BaseFormat(e),i=[];if(r.date_format||r.string_format)for(let n of t)typeof n=="string"?i.push({text:n}):i.push(n);else this.magic_decimal&&t[1]===""&&t.splice(1,1),i=[...r.prefix.map(n=>({...n})),{text:r.has_number_format?t.join(D.decimal_separator):""},...r.suffix.map(n=>({...n}))];for(let n=1;n<i.length;n++)i[n].flag===i[n-1].flag&&(i[n].text=i[n-1].text+i[n].text,i[n-1].text="");return i.filter(n=>n.text)}Format(e,t=0){return c.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=De(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=12)),{parts:r.prefix.map(a=>{if(a.flag===4)return a.text==="mm"?{text:this.ZeroPad(t.getUTCMinutes().toString(),2)}:{text:this.ZeroPad(t.getUTCMinutes().toString(),1)};if(a.flag===3){switch(a.text.toLowerCase()){case"am/pm":case"a/p":{let o=a.text.split("/");return{text:t.getUTCHours()>12?o[1]:o[0]}}case"mmmmm":return{text:D.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return a.text==="MMMM"?{text:D.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:D.date_components.long_months[t.getUTCMonth()]};case"mmm":return a.text==="MMM"?{text:D.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:D.date_components.short_months[t.getUTCMonth()]};case"mm":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),2)};case"m":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),1)};case"ddddd":case"dddd":return a.text==="DDDDD"||a.text==="DDDD"?{text:D.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:D.date_components.long_days[t.getUTCDay()]};case"ddd":return a.text==="DDD"?{text:D.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:D.date_components.short_days[t.getUTCDay()]};case"dd":return{text:this.ZeroPad(t.getUTCDate().toString(),2)};case"d":return{text:this.ZeroPad(t.getUTCDate().toString(),1)};case"yyyy":case"yyy":return{text:t.getUTCFullYear().toString()};case"yy":case"y":return{text:this.ZeroPad((t.getUTCFullYear()%100).toString(),2)};case"hh":return{text:this.ZeroPad(i.toString(),2)};case"h":return{text:this.ZeroPad(i.toString(),1)};case"ss":return{text:this.ZeroPad(t.getUTCSeconds().toString(),2)};case"s":return{text:this.ZeroPad(t.getUTCSeconds().toString(),1)}}let s=a.text.match(/^(s+)\.(0+)$/);if(s)return{text:this.ZeroPad(t.getUTCSeconds().toString(),s[1].length)+D.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(s[2].length).substr(2)}}return{...a}}),section:r}}StringFormat(e,t){let r=[];for(let i of t.prefix)i.flag===5?r.push({text:e}):r.push({...i});return{parts:r,section:t}}Round2(e,t){let r=Math.pow(10,t);return Math.round(r*e)/r}FormatFraction(e,t){t.percent&&(e*=100);let r={denominator:1,numerator:Math.round(e),error:Math.abs(Math.round(e)-e)};if(t.fraction_denominator)r.denominator=t.fraction_denominator,r.numerator=Math.round(e*r.denominator);else if(r.error){let n=c.fraction_limits[t.fraction_denominator_digits-1]||c.fraction_limits[0];for(let a=2;a<=n;a++){let s=Math.round(e*a),o=Math.abs(s/a-e);if(o<r.error&&(r={numerator:s,denominator:a,error:o},!o))break}}let i=[];if(t.fraction_integer){let n=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(n||!r.numerator)&&(i.push(n.toString()),r.numerator&&i.push(" "))}else r.numerator||i.push("0");return r.numerator&&(i.push(r.numerator.toString()),i.push("/"),i.push(r.denominator.toString())),i.join("")}BaseFormat(e){if(this.sections[0].date_format)return this.DateFormat(Number(e));if(typeof e!="number")return this.StringFormat(e.toString(),this.sections[3]);let t=this.sections[0],r=this.decimal_zero_regexp[0];e<0&&(t=this.sections[1]);let i=t.percent?t.decimal_max_digits+2:t.decimal_max_digits,n=Math.pow(10,-i)/2,a=Math.abs(e);if(a<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(a/=t.scaling,a<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2])),t.string_format)return this.StringFormat(e.toString(),t);let s="";if(t.fraction_format)return{parts:[this.FormatFraction(a,t)],section:t};t.exponential?s=a.toExponential(t.decimal_max_digits):(t.percent&&(a*=100),s=this.Round2(a,t.decimal_max_digits).toFixed(t.decimal_max_digits)),r&&(s=s.replace(r,""));let o=s.split(".");for(;o[0].length<t.integer_min_digits;)o[0]=("0000000000000000"+o[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&o[0]==="0"&&(o[0]=""),t.grouping&&(o[0]=o[0].replace(c.grouping_regexp,"$&"+D.grouping_separator)),{parts:o,section:t}}};var I=class{static cache={};static complex_general;static symbolc_name_map={};static base_formats={Accounting:"_(#,##0.00_);(#,##0.00);-???",Number:"0.00",Integer:"0",Percent:"0.00%",General:"0.######",Fraction:"# ?/?",Dollar:"$* _(#,##0.00_);$* (#,##0.00);$* -???",Exponential:"0.000e","Short Date":"mm/dd/yy","Long Date":"dddd, mmm d yyyy",Timestamp:"mm-dd-yy hh:mm:ss"};static aliases={Scientific:"Exponential",Percentage:"Percent",Currency:"Dollar"};static Get(e,t=!1){if(t&&e==="General")return this.complex_general;let r=this.symbolc_name_map[e.toLowerCase()],i=this.cache[r||e];return i||(i=new te(e),this.cache[e]=i),i}static Equals(e,t){if(e===t)return!0;let r=this.Get(e),i=this.Get(t);return r.pattern===i.pattern}static Translate(e){let t=this.symbolc_name_map[e.toLowerCase()];return t?this.cache[t].toString():e}static SymbolicName(e){for(let t of Object.keys(this.base_formats))if(e===this.base_formats[t])return t;return null}static InitCache(){for(let e of Object.keys(this.base_formats))this.cache[e]=new te(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new te("0.###"),this.complex_general.magic_decimal=!0;for(let e of Object.keys(this.aliases))this.cache[e]=this.cache[this.aliases[e]],this.symbolc_name_map[e.toLowerCase()]=e}};I.InitCache();var si=new Date().getUTCFullYear(),_r=class{compare_day;compare_month;TestDate(e){let t=Date.parse(e);if(isNaN(t))return!1;let r=new Date(t),n=e.replace(/[\d\-\\/,.\s]+/g," ").toLocaleLowerCase().split(/\s+/).map(o=>o.trim()).filter(o=>!!o);if(!n.length)return t;if(!this.compare_month){this.compare_month={};for(let o=0;o<12;o++)this.compare_month[D.date_components.long_months[o].toLocaleLowerCase().replace(/\./,"")]=o,this.compare_month[D.date_components.short_months[o].toLocaleLowerCase().replace(/\./,"")]=o}if(!this.compare_day){this.compare_day={};for(let o=0;o<7;o++)this.compare_day[D.date_components.long_days[o].toLocaleLowerCase().replace(/\./,"")]=o,this.compare_day[D.date_components.short_days[o].toLocaleLowerCase().replace(/\./,"")]=o}let a=!1,s=!1;for(let o of n){let l=!1;for(let[d,h]of Object.entries(this.compare_month))if(o===d){if(a||r.getUTCMonth()!==h)return!1;l=!0,a=!0}if(!l){for(let[d,h]of Object.entries(this.compare_day))if(o===d){if(s||r.getUTCDay()!==h)return!1;l=!0,s=!0}}if(!l)return!1}return s&&!a?!1:t}TryParse(e=""){let t={};if(e[0]==="'")return{value:e,type:2};if(e==="")return{value:e,type:2};if(e==="NaN")return{value:NaN,type:3,hints:{Nan:!0}};let r=e.trim(),i=r.match(/^[$](.*?)$/);i&&(r=i[1],t.Currency=!0);let n=r.match(/^\((.*?)\)$/);n&&(r=n[1],t.Parens=!0);let a=r.match(/^(.*?)%\s*$/);a&&(r=a[1],t.Percent=!0),D.decimal_separator==="."?/,/.test(r)&&(r=r.replace(/,/g,""),t.Grouping=!0):(r=r.replace(/(\d)\s+/g,"$1"),r=r.replace(/\./g,""),r=r.replace(/,/,"."));let s=Number(r);if(s===null||isNaN(s)){let o=e.toLowerCase();if(o==="false")return{value:!1,type:4};if(o==="true")return{value:!0,type:4};let l=this.TestDate(e);if(l!==!1&&!isNaN(l)){let d=new Date(l),h=d.getUTCFullYear();if(h>=si-200&&h<=si+200)return t={Date:!0},(d.getHours()||d.getMinutes()||d.getSeconds())&&(t.Time=!0),{value:He(l),type:3,hints:t}}return{value:e,type:2}}if(n&&(s=-s),a){let o=s<0?-1:1,l=(o*s).toString().split(".");l[0]=("00"+l[0]).replace(/(\d\d)$/,".$1"),s=Number(l.join(""))*o}return/e/.test(e)&&(t.Exponential=!0),{value:s,type:3,hints:t}}},be=new _r;var Ct=class{constructor(e,t,r={x:0,y:0},i){this.theme=t;this.offset=r;let n=F.GetInstance(i.ownerDocument);this.g=n.SVG("g"),this.g.setAttribute("transform",`translate(${r.x}, ${r.y})`),this.outline=n.SVG("rect","outline"),e?(this.g.setAttribute("class","selection primary-selection"),this.fill=n.SVG("path","fill"),this.nub=n.SVG("rect","nub"),this.g.appendChild(this.fill),this.g.appendChild(this.outline),this.g.appendChild(this.nub)):(this.g.setAttribute("class","selection alternate-selection"),this.fill=n.SVG("rect","fill"),this.g.appendChild(this.fill),this.g.appendChild(this.outline))}g;outline;fill;nub;Offset(e){this.g.setAttribute("transform",`translate(${e.x}, ${e.y})`)}Show(e=!0){this.g.style.display=e?"block":"none"}SetOutline(e,t=!1){this.outline.setAttribute("x",(e.left-1).toString()),this.outline.setAttribute("y",(e.top-1).toString()),this.outline.setAttribute("width",(e.width+1).toString()),this.outline.setAttribute("height",(e.height+1).toString()),t&&this.fill&&(this.fill.setAttribute("x",e.left.toString()),this.fill.setAttribute("y",e.top.toString()),this.fill.setAttribute("width",e.width.toString()),this.fill.setAttribute("height",e.height.toString()))}SetFill(e,t){if(!this.fill)return;let r=[];r.push("M"+e.left+" "+e.top),r.push("L"+e.left+" "+e.bottom),r.push("L"+e.right+" "+e.bottom),r.push("L"+e.right+" "+e.top),r.push("Z"),r.push("M"+t.left+" "+t.top),r.push("L"+t.right+" "+t.top),r.push("L"+t.right+" "+t.bottom),r.push("L"+t.left+" "+t.bottom),r.push("Z"),this.fill.setAttribute("d",r.join(" "))}SetNub(e){this.nub&&(this.nub.setAttribute("x",(e.left+e.width-4).toString()),this.nub.setAttribute("y",(e.top+e.height-4).toString()),this.nub.setAttribute("width","7"),this.nub.setAttribute("height","7"))}};var Ne=class{constructor(e,t,r){this.theme=e;this.container=t;this.orientation=r;let i=F.GetInstance(t.ownerDocument);this.g=i.SVG("g","treb-header-overlay"),this.overlay=i.SVG("rect","treb-overlay"),this.highlight=i.SVG("rect","treb-highlight"),this.g.style.display="none",this.g.appendChild(this.highlight),this.g.appendChild(this.overlay),t.appendChild(this.g)}g;overlay;highlight;Remove(){this.container.removeChild(this.g)}Hide(){this.g.style.display="none"}Show(e,t,r,i){this.overlay.setAttribute("x",e.toString()),this.overlay.setAttribute("y",t.toString()),this.overlay.setAttribute("width",r.toString()),this.overlay.setAttribute("height",i.toString()),this.orientation===0?(this.highlight.setAttribute("x",e.toString()),this.highlight.setAttribute("y",(t+i-2).toString()),this.highlight.setAttribute("width",r.toString()),this.highlight.setAttribute("height","2")):(this.highlight.setAttribute("x",(e+r-2).toString()),this.highlight.setAttribute("y",t.toString()),this.highlight.setAttribute("width","2"),this.highlight.setAttribute("height",i.toString())),this.g.style.display="block"}};var At=class{constructor(e,t,r,i,n,a){this.theme=e;this.layout=t;this.model=r;this.view=i;this.primary_selection=n;this.additional_selections=a}nub_rectangle=new H(-1,-1,0,0);cached_additional_selections="";grid_selections=[];row_header_selections=[];column_header_selections=[];corner_selections=[];row_overlay;column_overlay;corner_row_overlay;corner_column_overlay;Initialize(){this.row_overlay=new Ne(this.theme,this.layout.row_header_selection,0),this.column_overlay=new Ne(this.theme,this.layout.column_header_selection,1),this.corner_row_overlay=new Ne(this.theme,this.layout.corner_selection,0),this.corner_column_overlay=new Ne(this.theme,this.layout.corner_selection,1)}RenderSelections(e=!0,t=!0){let r=this.primary_selection.empty;e||(this.primary_selection.empty=!0);let i=[this.primary_selection].concat(this.additional_selections);this.RenderSelectionGroup(i,this.layout.grid_selection,void 0,void 0,this.grid_selections,void 0,t);let n=new H(-1,-1,0,0);if(!this.primary_selection.empty){let o=this.view.active_sheet.RealArea(this.primary_selection.area);n=this.layout.CellAddressToRectangle(o.start).Combine(this.layout.CellAddressToRectangle(o.end))}if(!this.primary_selection.empty&&this.layout.header_offset.y>2?(this.row_overlay.Show(n.left,0,n.width,this.layout.header_offset.y),this.corner_row_overlay.Show(n.left+this.layout.header_offset.x,0,n.width,this.layout.header_offset.y)):(this.row_overlay.Hide(),this.corner_row_overlay.Hide()),!this.primary_selection.empty&&this.layout.header_offset.x>2?(this.column_overlay.Show(0,n.top,this.layout.header_offset.x,n.height),this.corner_column_overlay.Show(0,n.top+this.layout.header_offset.y,this.layout.header_offset.x,n.height)):(this.column_overlay.Hide(),this.corner_column_overlay.Hide()),!this.view.active_sheet.freeze.columns&&!this.view.active_sheet.freeze.rows){this.primary_selection.empty=r;return}let a=[],s=[];if(this.primary_selection.empty)a.push(!1),s.push(!1);else{let o=this.primary_selection.area.start;a.push(o.row<=this.view.active_sheet.freeze.rows||o.row===1/0),s.push(o.column<=this.view.active_sheet.freeze.columns||o.column===1/0)}for(let{area:o}of this.additional_selections)a.push(o.start.row<=this.view.active_sheet.freeze.rows||o.start.row===1/0),s.push(o.start.column<=this.view.active_sheet.freeze.columns||o.start.column===1/0);this.view.active_sheet.freeze.rows&&this.RenderSelectionGroup(i,this.layout.row_header_selection,a,void 0,this.row_header_selections,{x:0,y:this.layout.header_offset.y}),this.view.active_sheet.freeze.columns&&this.RenderSelectionGroup(i,this.layout.column_header_selection,s,void 0,this.column_header_selections,{x:this.layout.header_offset.x,y:0}),this.view.active_sheet.freeze.rows&&this.view.active_sheet.freeze.columns&&this.RenderSelectionGroup(i,this.layout.corner_selection,s,a,this.corner_selections,{...this.layout.header_offset}),this.primary_selection.empty=r}RenderSelectionGroup(e,t,r,i,n,a,s=!0){for(let o=0;o<e.length;o++)if((!e[o].area.start.sheet_id||e[o].area.start.sheet_id===this.view.active_sheet.id)&&!e[o].empty&&(!r||r[o])&&(!i||i[o])){if(s||!e[o].rendered){let d=this.EnsureGridSelectionBlock(t,n,o,a);this.RenderSVGSelection(e[o],d,o)}}else n[o]&&n[o].Show(!1);for(let o=e.length;o<n.length;o++)n[o]&&n[o].Show(!1)}EnsureGridSelectionBlock(e,t,r,i){let n=t[r];if(!n)if(n=new Ct(!r,this.theme,void 0,e),t[r]=n,r){let a=e.querySelector(".alternate-selections");a||(a=this.layout.DOM.SVG("g","alternate-selections"),e.appendChild(a)),a?.appendChild(n.g)}else e.appendChild(n.g);return i&&n.Offset(i),n}ClampEnd(e){return{row:Math.min(e.row,this.view.active_sheet.rows-1),column:Math.min(e.column,this.view.active_sheet.columns-1)}}RenderSVGSelection(e,t,r=0){let i=this.view.active_sheet.RealArea(e.area,!0),n=this.layout.CellAddressToRectangle(i.start);if(i.count>1)n=n.Combine(this.layout.CellAddressToRectangle(i.end));else if(r){let a=this.view.active_sheet.CellData(e.target);a.merge_area&&(n=this.layout.CellAddressToRectangle(a.merge_area.start),n=n.Combine(this.layout.CellAddressToRectangle(a.merge_area.end)))}if(r||(this.nub_rectangle=new H(n.left+n.width-6,n.top+n.height-6,11,11)),n.top===0&&this.layout.header_offset.y<=1&&(n.top=1,n.height-=1),n.left===0&&this.layout.header_offset.x<=1&&(n.left=1,n.width-=1),n.height<=0||n.height<=0){t.Show(!1);return}if(t.SetOutline(n,!!r),r)e.rendered=!0;else{let a=this.layout.CellAddressToRectangle(e.target),s=this.view.active_sheet.CellData(e.target);s.merge_area&&(a=this.layout.CellAddressToRectangle(s.merge_area.start),a=a.Combine(this.layout.CellAddressToRectangle(s.merge_area.end))),t.SetFill(a,n),t.SetNub(n)}t.Show()}};function ge(c,e=[],t,r){typeof e=="string"&&(e=[e]);let i,n=s=>{s.stopPropagation(),s.preventDefault(),i(),r&&r(s)},a=s=>{if(s.stopPropagation(),s.preventDefault(),!s.buttons){i(),r&&r(s);return}t&&t(s)};i=()=>{c.style.display="none",c.removeEventListener("mousemove",a),c.removeEventListener("mouseup",n);for(let s of e)c.classList.remove(s)};for(let s of e)c.classList.add(s);c.style.display="block",t&&c.addEventListener("mousemove",a),r&&c.addEventListener("mouseup",n)}var St=class extends oe{constructor(t){super();this.container=t;this.format=I.Get("0.0");let r=F.GetInstance(t.ownerDocument);this.input=r.Create("input","treb-scale-input",t,{events:{keypress:n=>{switch(n.key){case"ArrowUp":case"ArrowDown":n.stopPropagation(),n.preventDefault(),console.info("mark?");break}},keydown:n=>{switch(n.key){case"Enter":this.input.blur();break;case"ArrowUp":this.Tick(-1);break;case"ArrowDown":this.Tick(1);break;case"Escape":this.input.value=this.format.Format(this.scale)+"%",this.input.blur();break;default:return}n.stopPropagation(),n.preventDefault()},focusin:()=>this.input.select(),change:()=>{let n=this.input.value;n=n.replace(/%/g,"");let a=be.TryParse(n);a.type===3?this.UpdateScale(Number(a.value),!0):this.input.value=this.format.Format(this.scale)+"%"}}});let i=r.Div("treb-slider-container",t);this.slider=r.Create("input",void 0,i,{attrs:{type:"range",min:"50",max:"200",value:"100",step:"2.5"},events:{input:()=>this.UpdateScale(Number(this.slider.value),!0)}}),t.addEventListener("wheel",n=>{n.stopPropagation(),n.preventDefault(),this.Tick(n.deltaY)})}input;slider;scale=0;format;timeout=0;Tick(t){let r=Math.round(this.scale/2.5)*2.5;t>0?this.UpdateScale(r-2.5,!0,!0):t<0&&this.UpdateScale(r+2.5,!0,!0)}UpdateScale(t,r=!1,i=!1){t=Math.max(50,Math.min(200,t)),t!==this.scale&&(this.scale=t,this.input.value=this.format.Format(t)+"%",this.slider.value=t.toFixed(1),r&&(this.timeout||(this.timeout=requestAnimationFrame(()=>{this.timeout=0,this.Publish({type:"scale",value:this.scale/100,keep_focus:i})}))))}};var kt=class extends oe{constructor(t,r,i,n,a){super();this.layout=t;this.model=r;this.view=i;this.options=n;if(this.DOM=F.GetInstance(a.ownerDocument),this.container=a.querySelector(".treb-spreadsheet-footer"),!this.container)throw new Error("missing container for tab bar");if(n.tab_bar!=="auto"&&this.container.removeAttribute("hidden"),this.tab_container=this.container.querySelector(".treb-spreadsheet-tabs"),this.container.addEventListener("click",s=>{let o=s.target?.dataset.command;if(o)switch(s.stopPropagation(),s.preventDefault(),o){case"add-tab":this.Publish({type:"add-sheet"});break;case"delete-tab":this.Publish({type:"delete-sheet"});break;default:console.info("unhandled command",o)}}),this.options.stats&&(this.stats_panel=this.container.querySelector(".treb-stats-panel")),this.options.scale_control){let s=this.container.querySelector(".treb-scale-control");this.scale_control=new St(s),this.scale_control.Subscribe(o=>{this.Publish(o)}),this.UpdateScale(this.options.initial_scale||1)}}tab_container;scale_control;stats_panel;dragging=!1;double_click_data={};_visible=!1;get visible(){return this._visible}set stats_data(t){if(this.stats_panel){this.stats_panel.innerText="";for(let r of t)this.DOM.Create("span","treb-stats-label",this.stats_panel,{text:r.label}),this.DOM.Create("span","treb-stats-value",this.stats_panel,{text:r.value})}}container;DOM;IsDoubleClick(t,r=300){return this.double_click_data.index===t?(clearTimeout(this.double_click_data.timeout),this.double_click_data.index=void 0,this.double_click_data.timeout=void 0,!0):(this.double_click_data.timeout&&clearTimeout(this.double_click_data.timeout),this.double_click_data.index=t,this.double_click_data.timeout=window.setTimeout(()=>{this.double_click_data.index=void 0,this.double_click_data.timeout=void 0},r),!1)}Hide(){this.Show(!1)}Show(t=!0){this.container&&(this._visible=t,t?this.container.removeAttribute("hidden"):this.container.setAttribute("hidden",""))}SetActive(t,r){r?t.setAttribute("selected",""):t.removeAttribute("selected")}UpdateScale(t){this.scale_control?.UpdateScale(t*100)}DoubleClickTab(t,r,i){if(r.contentEditable="true",this.DOM.doc){let n=this.DOM.GetSelection();if(n){n.removeAllRanges();let a=this.DOM.doc.createRange();a.selectNodeContents(r),n.addRange(a)}}r.addEventListener("keydown",n=>{switch(n.key){case"Enter":this.Publish({type:"rename-sheet",name:r.innerText.trim(),sheet:i});break;case"Escape":r.innerText=i.name,this.Publish({type:"cancel"}),this.Update();break;default:return}n.stopPropagation(),n.preventDefault()}),r.addEventListener("focusout",()=>{let n=r.innerText.trim();n!==i.name?this.Publish({type:"rename-sheet",name:n,sheet:i}):this.Update()}),r.focus()}MouseDownTab(t,r,i,n,a){if(t.stopPropagation(),t.preventDefault(),this.IsDoubleClick(n))return;this.Publish({type:"activate-sheet",sheet:i});let s=a.map(p=>p.getBoundingClientRect()),o=n*2-1,l=s[0].left,d=s[s.length-1].right,h=s[0].top,u=s[0].bottom,m=-1,f=(s.length-1)*2+1;for(let p of a)this.SetActive(p,p===r);this.dragging=!0,ge(this.layout.mask,[],p=>{let[g,b]=[p.clientX,p.clientY];if(b>h&&b<u){let v=o;if(g<l)v=m;else if(g>d)v=f;else for(let _=0;_<s.length;_++){let w=s[_];if(g>=w.left&&g<=w.right){_!==n&&(g>=w.left+w.width/2?v=_*2+1:v=_*2-1);break}}v!==o&&(o=v,r.style.order=o.toString(),s=a.map(_=>_.getBoundingClientRect()))}},()=>{let p=n,g=(o+1)/2;this.dragging=!1;for(let b=0;b<this.model.sheets.length;b++)this.model.sheets.list[b].visible||(p>=b&&p++,g>=b&&g++);p===g||p===0&&g<=0||p===a.length-1&&g>=a.length-1||this.Publish({type:"reorder-sheet",index:p,move_before:g})})}Update(){if(this.dragging)return;if(this.options.tab_bar==="auto"){if(this.model.sheets.list.reduce((i,n)=>n.visible?i+1:i,0)<=1){this.Show(!1);return}this.Show(!0)}if(!this.tab_container)return;this.tab_container.innerText="";let t=[];for(let r of this.model.sheets.list){if(!r.visible)continue;let i=t.length,n=this.DOM.Create("li");n.setAttribute("tabindex","0"),n.style.order=(i*2).toString(),n.role="tab",this.SetActive(n,r===this.view.active_sheet);let a=o=>this.MouseDownTab(o,n,r,i,t),s=o=>{n.removeEventListener("mousedown",a),n.removeEventListener("dblclick",s),this.DoubleClickTab(o,n,r)};n.textContent=r.name,n.addEventListener("dblclick",s),n.addEventListener("mousedown",a),this.tab_container.appendChild(n),t.push(n)}}};var oi=()=>({target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0});var In=100,li={move_with_cells:!0,resize_with_cells:!0,movable:!0,resizable:!0,removable:!0,selectable:!0},Ee=class{data={...li};get key(){return this.key_}rect;scaled_rect;temp={};view=[];dirty;key_=In++;constructor(e={}){this.data={...li,...JSON.parse(JSON.stringify(e))},e.rect&&(this.rect=H.Create(e.rect))}toJSON(){return{...this.data,rect:this.rect}}};var zn=100,ci=60,Y=class c{static base_id=100;static default_sheet_name="Sheet1";default_style_properties;annotations=[];freeze={rows:0,columns:0};visible=!0;default_column_width=100;default_row_height=25;cells=new dt;selection=oi();scroll_offset={x:0,y:0};name=c.default_sheet_name;background_image;_image=void 0;flush_conditional_formats=!1;get image(){return this._image}conditional_formats=[];outline;id_;row_height_=[];column_width_=[];row_headers=[];column_headers=[];row_header_width=100;column_header_height=25;style_map=[];style_json_map=[];sheet_style={};row_styles={};column_styles={};row_pattern=[];cell_style=[];conditional_format_cache=[];conditional_format_checklist=[];get header_offset(){return{x:this.row_header_width,y:this.column_header_height}}get rows(){return this.cells.rows}get columns(){return this.cells.columns}get id(){return this.id_}set id(e){this.id_=e,this.id>=c.base_id&&(c.base_id=this.id+1)}constructor(e){this.default_style_properties=e,this.default_column_width=zn,this.row_header_width=ci,this.UpdateDefaultRowHeight(),this.id_=c.base_id++}static Reset(){this.base_id=100}static Blank(e,t,r=30,i=20){let n=new c(e);return t&&(n.name=t),r=Math.max(r,1),i=Math.max(i,1),n.cells.EnsureCell({row:r-1,column:i-1}),n}static UpdateStyle(e){if(typeof e.horizontal_align=="number"){let t=["","left","center","right"];e.horizontal_align=t[e.horizontal_align]||void 0}if(typeof e.vertical_align=="number"){let t=["","top","bottom","middle"];e.vertical_align=t[e.vertical_align]||void 0}}static FromJSON(e,t,r){let i=typeof e=="string"?JSON.parse(e):e,n=(l,d)=>{Object.keys(d).forEach(h=>{let u=Number(h)||0;l[u]=d[h]})};r||(r=new c(t)),i.default_column_width&&(r.default_column_width=i.default_column_width),i.default_row_height&&(r.default_row_height=i.default_row_height),i.conditional_formats&&(r.conditional_formats=i.conditional_formats),i.id&&(r.id=i.id),i.name&&(r.name=i.name),i.background_image&&(r.background_image=i.background_image);let a=l=>{let d=l;this.UpdateStyle(d),(d.font_size_value||d.font_size_unit)&&(d.font_size={unit:d.font_size_unit||"pt",value:d.font_size_value||10},d.font_size_unit=void 0,d.font_size_value=void 0),d.font_bold&&(d.bold=!0,d.font_bold=void 0),d.font_italic&&(d.italic=!0,d.font_italic=void 0),d.font_underline&&(d.underline=!0,d.font_underline=void 0),d.font_strike&&(d.strike=!0,d.font_strike=void 0),d.text_color&&(d.text_color!=="none"&&(d.text={text:d.text_color}),d.text_color=void 0),d.background&&(d.background!=="none"&&(d.fill={text:d.background}),d.background=void 0),d.border_top_color&&(d.border_top_color!=="none"&&(d.border_top_fill={text:d.border_top_color}),d.border_top_color=void 0),d.border_left_color&&(d.border_left_color!=="none"&&(d.border_left_fill={text:d.border_left_color}),d.border_left_color=void 0),d.border_bottom_color&&(d.border_bottom_color!=="none"&&(d.border_bottom_fill={text:d.border_bottom_color}),d.border_bottom_color=void 0),d.border_right_color&&(d.border_right_color!=="none"&&(d.border_right_fill={text:d.border_right_color}),d.border_right_color=void 0)},s=i.styles||i.cell_style_refs||[];for(let l of s)a(l);if(r.cell_style=[],s&&(i.cell_styles||[]).forEach(l=>{typeof l.ref=="number"&&(l.style=JSON.parse(JSON.stringify(s[l.ref])))}),r.cells.FromJSON(i.data),i.rows&&r.cells.EnsureRow(i.rows-1),i.columns&&r.cells.EnsureColumn(i.columns-1),i.data)if(je(i.data))for(let l of i.data)l.style_ref&&(r.cell_style[l.column]||(r.cell_style[l.column]=[]),r.cell_style[l.column][l.row]=JSON.parse(JSON.stringify(s[l.style_ref])));else if(rr(i.data))for(let l of i.data){let d=l.row;for(let h of l.cells){let u=h.column;h.style_ref&&(r.cell_style[u]||(r.cell_style[u]=[]),r.cell_style[u][d]=JSON.parse(JSON.stringify(s[h.style_ref])))}}else for(let l of i.data){let d=l.column;for(let h of l.cells){let u=h.row;h.style_ref&&(r.cell_style[d]||(r.cell_style[d]=[]),r.cell_style[d][u]=JSON.parse(JSON.stringify(s[h.style_ref])))}}r.freeze.rows=0,r.freeze.columns=0,i.freeze&&(r.freeze.rows=i.freeze.rows||0,r.freeze.columns=i.freeze.columns||0),r.scroll_offset=i.scroll?{...i.scroll}:{x:0,y:0};for(let l of i.cell_styles||[])if(l.style&&(r.cell_style[l.column]||(r.cell_style[l.column]=[]),r.cell_style[l.column][l.row]=l.style,l.rows))for(let d=1;d<l.rows;d++)r.cell_style[l.column][l.row+d]=JSON.parse(JSON.stringify(l.style));r.sheet_style=i.sheet_style||{},r.column_styles={},r.row_styles={};let o=(l,d)=>{for(let h of Object.keys(l)){let u=Number(h),m=l[u];if(typeof m=="number"){let f=s[m];f&&(d[u]=JSON.parse(JSON.stringify(f)),a(d[u]))}else m&&(d[u]=m,a(d[u]))}};o(i.row_style,r.row_styles),o(i.column_style,r.column_styles),r.row_pattern=i.row_pattern||[],a(r.sheet_style||{});for(let l of r.row_pattern)a(l);return r.row_height_=[],n(r.row_height_,i.row_height||{}),r.row_height_.length&&r.cells.EnsureRow(r.row_height_.length-1),r.column_width_=[],n(r.column_width_,i.column_width||{}),r.column_width_.length&&r.cells.EnsureColumn(r.column_width_.length-1),r.annotations=(i.annotations||[]).map(l=>new Ee(l)),i.selection&&(r.selection=JSON.parse(JSON.stringify(i.selection))),r.visible=!0,typeof i.visible<"u"&&(r.visible=!!i.visible),r}Activate(e){if(this.background_image){let t=mt(this.background_image);t&&(this._image=e.Create("img"),this._image.src=t)}}MergeCells(e){e=e.Clone(),this.cells.Apply(e,(t,r,i)=>{t.merge_area=e,t.render_clean=[],(r!==e.start.column||i!==e.start.row)&&t.Reset()},!0)}UnmergeCells(e){let t=!0;if(this.cells.Apply(e,r=>{t=t&&!!r.merge_area&&e.Equals(r.merge_area)},!1),!t){console.warn("area mismatch");return}this.cells.Apply(e,r=>{r.merge_area=void 0,r.render_clean=[]},!1)}StyleFontSize(e,t={}){let r=e.font_size?.value||0,i=0;switch(e.font_size?.unit){case"px":r*=75/100;break;case"em":i=e.font_size.value||1;break;case"%":i=(e.font_size.value||100)/100;break}return i&&(r=i*(t.font_size?.value||10),t.font_size?.unit==="px"&&(r*=75/100)),r||10}UpdateDefaultRowHeight(){let e=V.Composite([this.default_style_properties,this.sheet_style]);if(typeof window<"u"){let t=de.MeasureText(V.Font(e),"M"),r=Math.round(t.height*1.4);this.default_row_height<r&&(this.default_row_height=r)}}SetRowHeaders(e){this.row_headers=e.map(t=>t===void 0?"":t.toString()),this.row_headers&&this.cells.EnsureRow(this.row_headers.length-1)}SetColumnHeaders(e){this.column_headers=e.map(t=>t===void 0?"":t.toString()),e&&this.cells.EnsureColumn(e.length-1)}RowHeader(e){return this.row_headers?this.row_headers.length>e?this.row_headers[e]:"":e+1}ColumnHeader(e){let t="";if(this.column_headers)return this.column_headers.length>e?this.column_headers[e]:"";for(;;){let r=e%26;if(t=String.fromCharCode(65+r)+t,e=Math.floor(e/26),e)e--;else break}return t}GetRowHeight(e){let t=this.row_height_[e];return typeof t>"u"?this.default_row_height:t}SetRowHeight(e,t){return this.row_height_[e]=t,this.cells.EnsureRow(e),t}GetColumnWidth(e){let t=this.column_width_[e];return typeof t>"u"?this.default_column_width:t}SetColumnWidth(e,t){return this.column_width_[e]=t,this.cells.EnsureColumn(e),t}Delta(e,t){let r={},i=[...Object.keys(e),...Object.keys(t)];for(let n of i){let a=e[n],s=t[n];typeof a=="object"&&typeof s=="object"?JSON.stringify(a)!==JSON.stringify(s)&&(r[n]=s):a!==s&&(r[n]=s)}return r}UpdateCellStyle(e,t,r=!0){let{row:i,column:n}=e;this.cell_style[n]||(this.cell_style[n]=[]);let a=this.CompositeStyleForCell(e,!1,!1,void 0,!1),s=V.Composite([this.default_style_properties,a,V.Merge(this.cell_style[n][i]||{},t,r)]),o=this.Delta(a,s);this.cell_style[n][i]=o,this.BleedFlush({start:e,end:e})}Invalidate(e){this.cells.Apply(this.RealArea(e),t=>t.render_clean=[])}UpdateAreaStyle(e,t={},r=!0){if(e)if(e.entire_sheet)this.UpdateSheetStyle(t,r);else if(e.entire_column)for(let i=e.start.column;i<=e.end.column;i++)this.UpdateColumnStyle(i,t,r);else if(e.entire_row)for(let i=e.start.row;i<=e.end.row;i++)this.UpdateRowStyle(i,t,r);else e.Array().forEach(i=>this.UpdateCellStyle(i,t,r))}HasCellStyle(e){return!!(this.cell_style[e.column]&&this.cell_style[e.column][e.row]||this.row_styles[e.row]||this.column_styles[e.column]||this.row_pattern.length)}NextVisibleColumn(e){for(++e;this.column_width_[e]===0;e++);return e}PreviousVisibleColumn(e){for(--e;e>=0&&this.column_width_[e]===0;e--);return e}NextVisibleRow(e){for(++e;this.row_height_[e]===0;e++);return e}PreviousVisibleRow(e){for(--e;e>=0&&this.row_height_[e]===0;e--);return e}TableRow(e,t){let r={alternate:!1,header:t===e.area.start.row,last:!1,totals:e.totals_row&&t===e.area.end.row};if(r.header||r.totals)return r;if(!(e.totals_row&&this.GetRowHeight(e.area.end.row)>0)){let a=e.area.end.row;for(;a>=e.area.start.row;a--)if(this.GetRowHeight(a)){r.last=a===t;break}}let n=e.area.start.row+1;for(;n<=e.area.end.row&&!(this.GetRowHeight(n)&&(r.alternate=!r.alternate,n===t));n++);return r}SurroundingStyle(e,t){let r=[{},{},{},{},{},{},{},{},{},{}],i=e.column+1,n=e.column-1,a=e.row+1,s=e.row-1;for(;this.column_width_[i]===0;i++);for(;this.row_height_[a]===0;a++);for(;n>=0&&this.column_width_[n]===0;n--);for(;s>=0&&this.row_height_[s]===0;s--);return n>=0&&s>=0&&(r[7]=this.CellStyleData({row:s,column:n},t)||{}),n>=0&&(r[4]=this.CellStyleData({row:e.row,column:n},t)||{},r[1]=this.CellStyleData({row:a,column:n},t)||{}),s>=0&&(r[8]=this.CellStyleData({row:s,column:e.column},t)||{},r[9]=this.CellStyleData({row:s,column:i},t)||{}),r[6]=this.CellStyleData({row:e.row,column:i},t)||{},r[2]=this.CellStyleData({row:a,column:e.column},t)||{},r[3]=this.CellStyleData({row:a,column:i},t)||{},r}CellStyleData(e,t){let r=this.cells.GetCell(e);if(r){if(!r.style){let i=this.GetStyleIndex(this.CompositeStyleForCell(e));r.style=this.style_map[i]}if(r.table){let i=r.table.theme||t;if(i){let n=JSON.parse(JSON.stringify(r.style)),a=this.TableRow(r.table,e.row);return a.header?i.header&&(n=V.Composite([n,i.header])):a.totals?i.total&&(n=V.Composite([n,i.total])):a.alternate?i.odd&&(n=V.Composite([n,i.odd])):i.even&&(n=V.Composite([n,i.even])),n}}return r.style}}GetCopyStyle(e){return this.CompositeStyleForCell(e,!0,!1,void 0,!1)}CellData(e){let t=this.cells.EnsureCell(e);if(t.rendered_type)return t;let r,i;if(t.calculated_type?(i=t.calculated,r=t.calculated_type):(i=t.value,r=t.type),!t.style){let n=this.GetStyleIndex(this.CompositeStyleForCell(e));t.style=this.style_map[n]}if(!r||i===null||typeof i>"u")t.formatted="",t.rendered_type=2;else if(r===3)isNaN(i)?t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan:t.formatted=this.FormatNumber(i,t.style.number_format),t.rendered_type=3;else if(r===6)t.formatted="#"+(i||"ERR?"),t.rendered_type=6;else if(r===4)t.formatted=i.toString().toUpperCase(),t.rendered_type=4;else if(r===1&&t.calculated===void 0)t.formatted="",t.rendered_type=2;else if(r===7){let n=i;if(isNaN(n.real)||isNaN(n.imaginary))t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan;else{let a=I.Get(t.style.number_format||"",!0);t.formatted=a.FormatComplex(n)}t.rendered_type=7}else if(r===9){if(isNaN(i.value))t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan,t.formatted+=" "+i.unit;else{let n=I.Get(t.style.number_format||"",!0);t.formatted=n.FormatDimensionedQuantity(i)}t.rendered_type=9}else t.formatted=this.FormatNumber(i,t.style.number_format),t.rendered_type=2;return t}FormatNumber(e,t=""){let r=I.Get(t).FormatParts(e);return r.length?r.length===1&&!r[0].flag?r[0].text||"":r:""}SetHeaderSize(e=ci,t=this.default_row_height){this.row_header_width=e,this.column_header_height=t}AutoSizeRow(e,t={},r=!0){let i=this.default_row_height,n=9;for(let a=0;a<this.cells.columns;a++){let s=this.CellData({row:e,column:a}),o=s.style,l=s.formatted||"";if(typeof l!="string"&&(l=l.map(d=>d.text).join("")),o&&l&&l.length){let d=l.split(/\n/),h=Math.round(this.StyleFontSize(o,t)*1.5);i=Math.max(i,((h||10)+n)*d.length)}}!r&&this.GetRowHeight(e)>=i||this.SetRowHeight(e,i)}GetStyle(e){return this.style_map[e]}InsertRows(e=0,t=1){if(e)for(let o=0;o<this.cells.columns;o++){let l=this.cells.GetCell({row:e-1,column:o},!1);if(l&&l.area){let d=this.cells.GetCell({row:e,column:o},!1);if(d&&d.area&&d.area.Equals(l.area))return!1}}t<0?this.cells.DeleteRows(e,-t):this.cells.InsertRows(e,t);let r={},i={};for(let o=e;o<this.cells.rows;o++)for(let l=0;l<this.cells.columns;l++){let d=this.cells.GetCell({row:o,column:l},!1);d&&(d.area&&!i[d.area.spreadsheet_label]&&(i[d.area.spreadsheet_label]=d.area),d.merge_area&&!r[d.merge_area.spreadsheet_label]&&(r[d.merge_area.spreadsheet_label]=d.merge_area))}for(let o of Object.keys(i)){let l=i[o],d=new y({row:l.start.row+t,column:l.start.column},{row:l.end.row+t,column:l.end.column});d.Iterate(h=>{let u=this.cells.GetCell(h,!0);u.area=d})}for(let o of Object.keys(r)){let l=r[o],d={row:l.start.row,column:l.start.column};l.start.row>=e&&(d.row+=t);let h=new y(d,{row:l.end.row+t,column:l.end.column});h.Iterate(u=>{let m=this.cells.GetCell(u,!0);m.merge_area=h})}let n=Object.keys(this.row_styles),a={};n.forEach(o=>{let l=Number(o);l<e?a[l]=this.row_styles[l]:t<0&&l<e-t||(a[l+t]=this.row_styles[l])}),this.row_styles=a;let s=[];if(t<0)s=[e,-t];else{s=[e,0];for(let o=0;o<t;o++)s.push(void 0)}return this.cell_style.forEach(o=>{o&&o.length>=e&&o.splice.apply(o,s)}),this.row_height_.splice.apply(this.row_height_,s),this.FlushCellStyles(),!0}InsertColumns(e=0,t=1){if(e)for(let o=0;o<this.cells.rows;o++){let l=this.cells.GetCell({row:o,column:e-1},!1);if(l&&l.area){let d=this.cells.GetCell({row:o,column:e},!1);if(d&&d.area&&d.area.Equals(l.area))return!1}}t<0?this.cells.DeleteColumns(e,-t):this.cells.InsertColumns(e,t);let r={},i={};for(let o=e;o<this.cells.columns;o++)for(let l=0;l<this.cells.rows;l++){let d=this.cells.GetCell({row:l,column:o},!1);d&&(d.area&&!i[d.area.spreadsheet_label]&&(i[d.area.spreadsheet_label]=d.area),d.merge_area&&!r[d.merge_area.spreadsheet_label]&&(r[d.merge_area.spreadsheet_label]=d.merge_area))}for(let o of Object.keys(i)){let l=i[o],d=new y({row:l.start.row,column:l.start.column+t},{row:l.end.row,column:l.end.column+t});d.Iterate(h=>{let u=this.cells.GetCell(h,!0);u.area=d})}for(let o of Object.keys(r)){let l=r[o],d={row:l.start.row,column:l.start.column};l.start.column>=e&&(d.column+=t);let h=new y(d,{row:l.end.row,column:l.end.column+t});h.Iterate(u=>{let m=this.cells.GetCell(u,!0);m.merge_area=h})}let n=Object.keys(this.column_styles),a={};n.forEach(o=>{let l=Number(o);l<e?a[l]=this.column_styles[l]:t<0&&l<e-t||(a[l+t]=this.column_styles[l])}),this.column_styles=a;let s=[];if(t<0)s=[e,-t];else{s=[e,0];for(let o=0;o<t;o++)s.push(void 0)}return this.cell_style.splice.apply(this.cell_style,s),this.column_width_.splice.apply(this.column_width_,s),this.FlushCellStyles(),!0}ClearArea(e){e=this.RealArea(e),this.cells.Apply(e,t=>t.Reset())}SetAreaValues2(e,t){e=this.RealArea(e),this.cells.SetArea(e,t)}SetArrayValue(e,t){e=this.RealArea(e),this.cells.Apply(e,i=>i.SetArray(e),!0),this.cells.GetCell(e.start,!0).SetArrayHead(e,t)}SetCellValue(e,t){this.cells.GetCell(e,!0).Set(t)}TablesFromArea(e,t=!1){if(N(e)){let i=this.cells.GetCell(e,!1);return i?.table&&(!t||e.row===i.table.area.start.row)?[i.table]:[]}let r=new Set;for(let i=e.start.row;i<=e.end.row;i++)for(let n=e.start.column;n<=e.end.column;n++){let a=this.cells.GetCell({row:i,column:n},!1);a?.table&&!r.has(a.table)&&(!t||i===a.table.area.start.row)&&r.add(a.table)}return Array.from(r.values())}RealArea(e,t=!1){let r=e.start,i=e.end;return e.entire_row&&(r.column=0,r.absolute_column=!1,i.column=this.cells.columns-1,i.absolute_column=!1),e.entire_column&&(r.row=0,r.absolute_row=!1,i.row=this.cells.rows-1,i.absolute_row=!1),t&&(i.row>=this.rows&&(i.row=this.rows-1,i.absolute_row=!1),i.column>=this.columns&&(i.column=this.columns-1,i.absolute_column=!1)),new y(r,i)}GetCellStyle(e,t=!1){if(N(e))return this.CompositeStyleForCell(e,!0,!1,t);if(e.start.row===e.end.row&&e.start.column===e.end.column)return this.CompositeStyleForCell(e.start,!0,!1,t);let r=[];for(let i=e.start.row;i<=e.end.row;i++){let n=[];for(let a=e.start.column;a<=e.end.column;a++)n.push(this.CompositeStyleForCell({row:i,column:a},!0,!1,t));r.push(n)}return r}FormattedCellValue(e){let t=this.CellData(e);if(t)return typeof t.formatted=="string"?t.formatted:t.formatted?t.formatted.map(r=>{switch(r.flag){case 1:return" ";case 2:return" ";default:return r.text}}).join(""):t.value}GetFormattedRange(e,t=e){if(e.row===t.row&&e.column===t.column)return this.FormattedCellValue(e);let r=[];for(let i=e.row;i<=t.row;i++){let n=[];for(let a=e.column;a<=t.column;a++)n.push(this.FormattedCellValue({row:i,column:a}));r.push(n)}return r}NumberFormatsAndColors(e,t){let r=i=>{i.number_format&&(t[i.number_format]=1),i.text?.text&&i.text.text!=="none"&&(e[i.text.text]=1),i.fill?.text&&(e[i.fill.text]=1),i.border_top_fill?.text&&(e[i.border_top_fill.text]=1),i.border_left_fill?.text&&(e[i.border_left_fill.text]=1),i.border_right_fill?.text&&(e[i.border_right_fill.text]=1),i.border_bottom_fill?.text&&(e[i.border_bottom_fill.text]=1)};r(this.sheet_style);for(let i in this.row_styles)r(this.row_styles[i]);for(let i in this.column_styles)r(this.column_styles[i]);for(let i of this.row_pattern)r(i);for(let i of this.cell_style)if(i)for(let n of i)n&&r(n)}CompressCellStyles(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i)for(let n=0;n<i.length;n++){let a=i[n];if(a){let s=n+1;for(;s<i.length&&i[s]===a;s++);s>n+1?t.push({row:n,column:r,ref:a,rows:s-n}):t.push({row:n,column:r,ref:a}),n=s-1}}}return t}toJSON(e={}){let t=(A,k)=>{let S={};for(let M=0;M<A.length;M++)typeof A[M]<"u"&&A[M]!==k&&(S[M]=A[M]);if(Object.keys(S).length)return S},r=[{}],i={},n=[],a=JSON.stringify({});for(let A=0;A<this.cell_style.length;A++){let k=this.cell_style[A];if(k){n[A]=[];for(let S=0;S<k.length;S++)if(k[S]){let M=JSON.stringify(k[S]);if(M!==a){let U=i[M];typeof U!="number"&&(i[M]=U=r.length,r.push(k[S])),n[A][S]=U}}}}let s=A=>{let k=JSON.stringify(A);if(k===a)return 0;let S=i[k];return typeof S!="number"&&(i[k]=S=r.length,r.push(A)),S};r=JSON.parse(JSON.stringify(r));let o=JSON.parse(JSON.stringify(this.sheet_style)),l=JSON.parse(JSON.stringify(this.row_pattern)),d={},h={};for(let A of Object.keys(this.column_styles)){let k=Number(A),S=this.column_styles[k];if(S){let M=s(S);M&&(d[k]=M)}}for(let A of Object.keys(this.row_styles)){let k=Number(A),S=this.row_styles[k];if(S){let M=s(S);M&&(h[k]=M)}}let u=(A,k)=>{if(typeof A<"u"&&A!=="none")return A===k?void 0:de.MeasureColorARGB(A)},m=(A={},k={})=>{let S={...k,...A};if(S.text)return S.text=de.MeasureColorARGB(S.text),S;if(typeof S.theme=="number")return S};if(e.export_colors){let A=[];for(let k of[r,[o],l])if(Array.isArray(k))for(let S of k)A.push(S);else for(let S of Object.keys(k))A.push(k[S]);for(let k of A){let S=m(k.border_top_fill,V.DefaultProperties.border_top_fill);S!==void 0&&(k.border_top_fill=S),S=m(k.border_left_fill,V.DefaultProperties.border_left_fill),S!==void 0&&(k.border_left_fill=S),S=m(k.border_right_fill,V.DefaultProperties.border_right_fill),S!==void 0&&(k.border_right_fill=S),S=m(k.border_bottom_fill,V.DefaultProperties.border_bottom_fill),S!==void 0&&(k.border_bottom_fill=S),k.fill?.text&&(k.fill.text=de.MeasureColorARGB(k.fill.text)),k.text&&k.text.text&&k.text.text!=="none"&&(k.text.text=de.MeasureColorARGB(k.text.text))}}let f={calculated_value:!!e.rendered_values,preserve_type:!!e.preserve_type,expand_arrays:!!e.expand_arrays,decorated_cells:!!e.decorated_cells,nested:!0,cell_style_refs:n,tables:!!e.tables},p=this.cells.toJSON(f),g=p.data,{rows:b,columns:v}=p;e.shrink?(b+=2,v+=1):(b=this.rows,v=this.columns);for(let A of this.annotations)A.data.extent||this.CalculateAnnotationExtent(A),A.data.extent&&(b=Math.max(b,A.data.extent.row+1),v=Math.max(v,A.data.extent.column+1));let _=this.CompressCellStyles(n),w=this.conditional_formats.length?JSON.parse(JSON.stringify(this.conditional_formats.map(A=>({...A,internal:void 0})))):void 0,x={id:this.id,name:this.name,data:g,sheet_style:o,rows:b,columns:v,cell_styles:_,styles:r,row_style:h,column_style:d,conditional_formats:w,row_pattern:l.length?l:void 0,default_row_height:this.default_row_height,default_column_width:this.default_column_width,row_height:t(this.row_height_,this.default_row_height),column_width:t(this.column_width_,this.default_column_width),selection:JSON.parse(JSON.stringify(this.selection)),annotations:JSON.parse(JSON.stringify(this.annotations))};return this.visible||(x.visible=this.visible),(this.scroll_offset.x||this.scroll_offset.y)&&(x.scroll=this.scroll_offset),this.background_image&&(x.background_image=this.background_image),(this.freeze.rows||this.freeze.columns)&&(x.freeze=this.freeze),x}FlushCellStyles(){this.style_map=[],this.style_json_map=[],this.cells.FlushCellStyles()}ImportData(e){let t=e.styles;e.outline&&(this.outline=e.outline);let r=e.sheet_style;r&&this.UpdateAreaStyle(new y({row:1/0,column:1/0},{row:1/0,column:1/0}),t[r]);let i=e.column_styles;if(i)for(let a=0;a<i.length;a++)i[a]&&this.UpdateAreaStyle(new y({row:1/0,column:a},{row:1/0,column:a}),t[i[a]]);this.cells.FromJSON(e.cells),e.name&&(this.name=e.name||"");let n=this.cell_style;for(let a of e.cells)a.style_ref&&(n[a.column]||(n[a.column]=[]),n[a.column][a.row]=t[a.style_ref]);for(let a=0;a<e.column_widths.length;a++)typeof e.column_widths[a]<"u"&&this.SetColumnWidth(a,e.column_widths[a]);for(let a=0;a<e.row_heights.length;a++)typeof e.row_heights[a]<"u"&&this.SetRowHeight(a,e.row_heights[a]);for(let a of e.annotations||[])this.annotations.push(new Ee(a));for(let a of e.conditional_formats||[])this.conditional_formats.push(a);e.hidden&&(this.visible=!1)}CalculateAnnotationExtent(e){if(e.data.layout){e.data.extent={...e.data.layout.br.address};return}let t=1e3;e.data.extent={row:0,column:0};let r=e.rect?.right;if(r&&this.default_column_width){for(let n=0;r>=0&&n<t;n++)if(r-=this.GetColumnWidth(n),r<0){e.data.extent.column=n;break}}let i=e.rect?.bottom;if(i&&this.default_row_height){for(let n=0;i>=0&&n<t;n++)if(i-=this.GetRowHeight(n),i<0){e.data.extent.row=n;break}}}UpdateSheetStyle(e,t=!0){this.sheet_style=V.Merge(this.sheet_style,e,t);let r=Object.keys(e);for(let i of this.cell_style)if(i)for(let n of i)n&&r.forEach(a=>delete n[a]);for(let i of Object.keys(this.row_styles))r.forEach(n=>delete this.row_styles[i][n]);for(let i of Object.keys(this.column_styles))r.forEach(n=>delete this.column_styles[i][n]);this.FlushCellStyles()}UpdateRowStyle(e,t,r=!0){this.row_styles[e]=V.Merge(this.row_styles[e]||{},t,r);let i=Object.keys(t);for(let n of this.cell_style)n&&n[e]&&i.forEach(a=>delete n[e][a]);for(let n=0;n<this.cells.columns;n++)if(this.column_styles[n]){let a=this.column_styles[n],s=this.cell_style[n]?this.cell_style[n][e]||{}:{};for(let o of i)typeof a[o]<"u"&&(s[o]=t[o]);Object.keys(s).length&&(this.cell_style[n]||(this.cell_style[n]=[]),this.cell_style[n][e]=JSON.parse(JSON.stringify(s)))}this.cells.Apply(this.RealArea(y.FromRow(e)),n=>n.FlushStyle())}UpdateColumnStyle(e,t,r=!0){this.column_styles[e]=V.Merge(this.column_styles[e]||{},t,r);let i=Object.keys(t);if(this.cell_style[e])for(let n of this.cell_style[e])n&&i.forEach(a=>delete n[a]);this.cells.Apply(this.RealArea(y.FromColumn(e)),n=>n.FlushStyle())}BleedFlush(e){let t=[Math.max(0,e.start.row-1),e.end.row+1],r=[Math.max(0,e.start.column-1),e.end.column+1];for(let i=t[0];i<=t[1];i++)for(let n=r[0];n<=r[1];n++)this.cells.GetCell({row:i,column:n},!1)?.FlushStyle()}FlushConditionalFormats(){this.flush_conditional_formats=!0}ApplyConditionalFormats(){let e=this.flush_conditional_formats;for(let i of this.conditional_formats)if(i.internal?.vertex?.updated){e=!0;break}if(!e)return;this.flush_conditional_formats=!1;let t=[],r=[...this.conditional_format_checklist];this.conditional_format_checklist=[];for(let i of this.conditional_formats)if(i.internal?.vertex?.updated&&(i.internal.vertex.updated=!1),i.type==="gradient"){let n=JSON.parse(JSON.stringify(i.area)),a=i.internal?.vertex?.result;if(a&&i.internal?.gradient){let s=i.property??"fill";if(a.type===8)for(let o=n.start.row;o<=n.end.row;o++)for(let l=n.start.column;l<=n.end.column;l++){let d=a.value[l-n.start.column][o-n.start.row];if(d.type===3){t[o]||(t[o]=[]),t[o][l]||(t[o][l]=[]);let h=i.internal.gradient.Interpolate(d.value);t[o][l].push({[s]:h})}}else if(a.type===3){let o=i.internal.gradient.Interpolate(a.value);for(let l=n.start.row;l<=n.end.row;l++){t[l]||(t[l]=[]);for(let d=n.start.column;d<=n.end.column;d++)t[l][d]||(t[l][d]=[]),t[l][d].push({[s]:o})}}r.push(n),this.conditional_format_checklist.push(n)}}else{let n=JSON.parse(JSON.stringify(i.area)),a=i.internal?.vertex?.result;if(a){if(a.type===8)for(let s=n.start.row;s<=n.end.row;s++)for(let o=n.start.column;o<=n.end.column;o++){let l=a.value[o-n.start.column][s-n.start.row];(l.type===4||l.type===3)&&l.value&&(t[s]||(t[s]=[]),t[s][o]||(t[s][o]=[]),t[s][o].push(i.style))}else if((a.type===4||a.type===3)&&a.value)for(let s=n.start.row;s<=n.end.row;s++){t[s]||(t[s]=[]);for(let o=n.start.column;o<=n.end.column;o++)t[s][o]||(t[s][o]=[]),t[s][o].push(i.style)}r.push(n),this.conditional_format_checklist.push(n)}}for(let i of r)this.BleedFlush(i);this.conditional_format_cache=t}ConditionalFormatForCell(e){return this.conditional_format_cache[e.row]?this.conditional_format_cache[e.row][e.column]||[]:[]}CompositeStyleForCell(e,t=!0,r=!0,i=!0,n=!0){let{row:a,column:s}=e,o=[];return i&&o.push(this.default_style_properties),o.push(this.sheet_style),r&&this.row_pattern.length&&o.push(this.row_pattern[a%this.row_pattern.length]),this.row_styles[a]&&o.push(this.row_styles[a]),this.column_styles[s]&&o.push(this.column_styles[s]),t&&this.cell_style[s]&&this.cell_style[s][a]&&o.push(this.cell_style[s][a]),n&&o.push(...this.ConditionalFormatForCell(e)),V.Composite(o)}GetStyleIndex(e){let t=JSON.stringify(e);for(let i=0;i<this.style_json_map.length;i++)if(t===this.style_json_map[i])return i;let r=this.style_map.length;return this.style_map.push(JSON.parse(t)),this.style_json_map.push(t),r}};var Oe=class{constructor(e,t,r=!1,i=F.GetInstance()){this.model=e;this.view=t;this.DOM=i;if(r)return;if(!i)throw new Error("missing DOM context");this.dpr=Math.max(1,self.devicePixelRatio||1),this.mask=i.Div("treb-mouse-mask"),this.tooltip=i.Div("treb-tooltip"),this.dropdown_caret=i.SVG("svg","treb-dropdown-caret"),this.dropdown_caret.setAttribute("viewBox","0 0 24 24"),this.dropdown_caret.tabIndex=-1;let n=i.SVG("path");n.setAttribute("d","M5,7 L12,17 L19,7"),this.dropdown_caret.appendChild(n),this.dropdown_caret.addEventListener("click",a=>{a.stopPropagation(),a.preventDefault(),this.grid_cover.classList.remove("nub-select");let s=this.dropdown_caret.getAttribute("class")||"";/active/i.test(s)?this.dropdown_caret.setAttribute("class","treb-dropdown-caret"):(this.dropdown_caret.setAttribute("class","treb-dropdown-caret active"),this.dropdown_list.focus())}),this.dropdown_list=i.Div("treb-dropdown-list",void 0,{attrs:{tabindex:"-1"}}),this.dropdown_list.addEventListener("keydown",a=>{let s=0;switch(a.key){case"ArrowDown":s=1;break;case"ArrowUp":s=-1;break;case"Escape":break;case"Enter":break;default:console.info(a.key);return}if(a.stopPropagation(),a.preventDefault(),a.key==="Escape"||a.key==="Enter")this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),a.key==="Enter"&&this.dropdown_callback&&this.dropdown_selected&&this.dropdown_callback.call(0,this.dropdown_selected.dropdown_value);else if(s&&this.dropdown_selected)if(s>0&&this.dropdown_selected.nextSibling){this.dropdown_selected.nextSibling.classList.add("selected"),this.dropdown_selected.classList.remove("selected"),this.dropdown_selected=this.dropdown_selected.nextSibling;let o=this.dropdown_selected.offsetTop+this.dropdown_selected.offsetHeight;o>this.dropdown_list.offsetHeight+this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=o-this.dropdown_list.offsetHeight)}else s<0&&this.dropdown_selected.previousSibling&&(this.dropdown_selected.previousSibling.classList.add("selected"),this.dropdown_selected.classList.remove("selected"),this.dropdown_selected=this.dropdown_selected.previousSibling,this.dropdown_selected.offsetTop<this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=this.dropdown_selected.offsetTop))}),this.dropdown_list.addEventListener("mousedown",a=>{let s=a.target;a.target!==this.dropdown_list&&(a.stopPropagation(),a.preventDefault(),this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_callback&&this.dropdown_callback.call(0,s.dropdown_value))}),this.dropdown_list.addEventListener("mousemove",a=>{let s=a.target;s!==this.dropdown_selected&&(this.grid_cover.classList.remove("nub-select"),this.dropdown_selected&&this.dropdown_selected.classList.remove("selected"),s.classList.add("selected"),this.dropdown_selected=s)}),this.mock_selection=i.Div("mock-selection-node",void 0,{html:" "}),this.note_node=i.Div("treb-note"),this.title_node=i.Div("treb-hover-title"),this.sort_button=i.Create("button","treb-sort-button",void 0,{attrs:{title:"Sort table",tabindex:"-1"}}),this.HideNote()}column_header;row_header;contents;buffer_canvas;corner;corner_canvas;grid_selection;grid_cover;column_header_cover;row_header_cover;annotation_container;mask;mock_selection;container;grid_tiles=[];column_header_tiles=[];row_header_tiles=[];corner_selection;row_header_selection;column_header_selection;corner_annotations;row_header_annotations;column_header_annotations;frozen_row_tiles=[];frozen_column_tiles=[];header_size={width:0,height:0};last_column=0;total_height=0;total_width=0;default_row_height=0;default_column_width=0;header_offset={x:0,y:0};dpr=1;scale=1;scroll_reference_node;get scroll_offset(){return this.scroll_reference_node?{x:this.scroll_reference_node.scrollLeft,y:this.scroll_reference_node.scrollTop}:{x:0,y:0}}set scroll_offset(e){this.scroll_reference_node&&(this.scroll_reference_node.scrollLeft=e.x,this.scroll_reference_node.scrollTop=e.y)}dropdown_caret;trident=typeof navigator<"u"&&navigator.userAgent&&/trident/i.test(navigator.userAgent);default_tile_size={width:1200,height:800};tooltip_state;tooltip;dropdown_list;dropdown_caret_visible=!1;dropdown_callback;dropdown_selected;note_node;sort_button;title_node;row_cache=[];column_cache=[];initialized=!1;UpdateDPR(){let e=Math.max(1,self.devicePixelRatio||1);return e===this.dpr?!1:(this.dpr=e,!0)}ColumnWidth(e){return Math.round(this.view.active_sheet.GetColumnWidth(e)*this.scale)}RowHeight(e){return Math.round(this.view.active_sheet.GetRowHeight(e)*this.scale)}SetRowHeight(e,t){this.view.active_sheet.SetRowHeight(e,Math.round(t/this.scale))}SetColumnWidth(e,t){this.view.active_sheet.SetColumnWidth(e,Math.round(t/this.scale))}ShowSelections(e=!0){this.grid_selection.style.display=e?"block":"none"}HideTitle(){this.title_node.style.opacity="0"}ShowTitle(e,t){if(this.title_node.textContent=e,!this.title_node.parentElement)return;let r=this.title_node.parentElement.getBoundingClientRect(),i=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.title_node.style.left=r.left+i.left-this.scroll_reference_node.scrollLeft+0+"px",this.title_node.style.top=r.top+i.bottom-this.scroll_reference_node.scrollTop+8+"px",this.title_node.style.opacity="1"}HideNote(){this.note_node.style.opacity="0",this.note_node.style.pointerEvents="none"}HideTableSortButton(){this.sort_button.style.opacity="0",this.sort_button.style.pointerEvents="none",this.sort_button.setAttribute("tabindex","-1")}ShowTableSortButton(e,t,r){if(!this.sort_button.parentElement)return;let i=!0,n=!1;e.sort&&e.sort.column===t&&(i=!e.sort.asc,n=!0),this.sort_button.setAttribute("tabindex","0 "),this.sort_button.style.opacity="1",this.sort_button.style.pointerEvents="initial",this.sort_button.classList.remove("asc","desc"),n&&this.sort_button.classList.add(i?"asc":"desc"),this.sort_button.dataset.asc=i.toString(),this.sort_button.dataset.table=e.name,this.sort_button.dataset.column=t.toString();let a=this.OffsetCellAddressToRectangle(r).Shift(this.header_size.width,this.header_size.height),s=this.sort_button.getBoundingClientRect();this.sort_button.style.left=a.right-s.width-s.width/2+"px",this.sort_button.style.top=a.top+(a.height-s.height)/2+"px"}ShowNote(e,t,r,i){if(i?this.note_node.innerHTML=i:this.note_node.textContent=e,!this.note_node.parentElement)return;let n=this.note_node.getBoundingClientRect(),a=this.note_node.parentElement.getBoundingClientRect(),s={x:8,y:2},o=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.note_node.style.left=a.left+o.right-this.scroll_reference_node.scrollLeft+s.x+"px",this.note_node.style.top=a.top+o.top-this.scroll_reference_node.scrollTop-n.height/5-s.y+"px",this.note_node.style.opacity="1",this.note_node.style.pointerEvents="auto"}AnnotationLayoutOrder(e,t){let r=-1;for(let n=0;n<this.view.active_sheet.annotations.length;n++)if(this.view.active_sheet.annotations[n]===e){r=n;break}if(r<0)return!1;let i=Math.min(Math.max(0,r+t),this.view.active_sheet.annotations.length-1);if(i===r)return!1;this.view.active_sheet.annotations.splice(r,1),this.view.active_sheet.annotations.splice(i,0,e);for(let n=0;n<this.view.active_sheet.annotations.length;n++){let a=this.view.active_sheet.annotations[n].key,s=this.container?.querySelectorAll(`.annotation[data-key="${a}"]`);if(s)for(let o=0;o<s?.length;o++)s[o].style.zIndex=(n+1).toString()}return!0}PointToAnnotationCorner(e){let t=this.PointToAddress_Grid(e,void 0,!1),r=this.CellAddressToRectangle(t);return{address:t,offset:{x:(e.x-r.left)/r.width,y:(e.y-r.top)/r.height}}}RectToAnnotationLayout(e){return{tl:this.PointToAnnotationCorner({x:(e.left||0)+1,y:(e.top||0)+1}),br:this.PointToAnnotationCorner({x:e.right||e.left||100,y:e.bottom||e.top||100})}}AddressToAnnotationLayout(e,t){let r={tl:this.CellAddressToRectangle(e),br:this.CellAddressToRectangle(t)};return{tl:this.PointToAnnotationCorner({x:r.tl.left||0,y:r.tl.top||0}),br:this.PointToAnnotationCorner({x:r.br.right||r.tl.left||100,y:r.br.bottom||r.tl.left||100})}}AnnotationLayoutToRect(e){let t=this.CellAddressToRectangle(e.tl.address),r=this.CellAddressToRectangle(e.br.address),i=t.left+t.width*e.tl.offset.x-1,n=t.top+t.height*e.tl.offset.y-1;return new H(i,n,r.left+r.width*e.br.offset.x-i,r.top+r.height*e.br.offset.y-n)}UpdateAnnotation(e){Array.isArray(e)||(e=[e]);for(let t of e){let r=t.view[this.view.view_index]||{};if(r.node){if(r.node.dataset.scale=this.scale.toString(),r.node.style.fontSize=`${10*this.scale}pt`,t.rect&&!t.data.layout&&(t.scaled_rect=t.rect.Scale(this.scale),t.data.layout=this.RectToAnnotationLayout(t.scaled_rect)),t.data.layout){let i=this.AnnotationLayoutToRect(t.data.layout);i.ApplyStyle(r.node),t.scaled_rect=i}r.node.dataset.key=t.key.toString(),(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.CloneFrozenAnnotation(t)}}}GetFrozenAnnotations(e){return[this.row_header_annotations,this.column_header_annotations,this.corner_annotations].map(r=>r.querySelector(`.annotation[data-key="${e.key}"]`)).filter(r=>r!==null)}CloneFrozenAnnotations(){for(let e of this.view.active_sheet.annotations)e.view[this.view.view_index]?.node&&e.key&&this.CloneFrozenAnnotation(e)}ClearFrozenAnnotations(){for(let e of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let t=e.querySelectorAll(".annotation");for(let r=0;r<t.length;r++)t[r].parentElement?.removeChild(t[r])}}RemoveFrozenAnnotation(e){for(let t of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let r=t.querySelector(`.annotation[data-key="${e.key}"]`);r&&r.parentElement?.removeChild(r)}}CloneFrozenAnnotation(e){for(let t of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let r=t.querySelector(`.annotation[data-key="${e.key}"]`);r&&r.parentElement?.removeChild(r);let i=e.view[this.view.view_index];if(r=i?.node?.cloneNode(!0),r){let n=r.querySelector(".annotation-move-target"),a=r.querySelector(".annotation-resize-target");r.addEventListener("mousedown",s=>{let o=i.node;requestAnimationFrame(()=>{o?.focus()}),this.AnnotationMouseDown(e,i.node,s,n,a)}),t.appendChild(r)}}}RemoveAnnotation(e){let t=e.view[this.view.view_index]||{};t.node&&t.node.parentElement?.removeChild(t.node),this.RemoveFrozenAnnotation(e)}RemoveAnnotationNodes(){let e=Array.prototype.map.call(this.annotation_container.children,t=>t);for(let t of e)this.annotation_container.removeChild(t);(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.ClearFrozenAnnotations()}AddAnnotation(e){let t=e.view[this.view.view_index]||{};if(!t.node)throw new Error("annotation view/node missing");this.annotation_container.appendChild(t.node),this.UpdateAnnotation(e)}AnnotationMouseDown(e,t,r,i,n){let a=e.scaled_rect;return a?new Promise(s=>{let o={left:a.left,top:a.top,width:a.width,height:a.height},l=this.scroll_reference_node,d=l.getBoundingClientRect(),h=t.getBoundingClientRect();if(r.target===i||r.target!==n&&r.altKey){r.stopPropagation(),r.preventDefault(),t.focus();let u={x:h.left+r.offsetX-a.left,y:h.top+r.offsetY-a.top},m=[t,...this.GetFrozenAnnotations(e)],f=25,p=this.CellAddressToRectangle({row:0,column:0}).Combine(this.CellAddressToRectangle({row:this.view.active_sheet.rows-1,column:this.view.active_sheet.columns-1})).Expand(-1,-1);ge(this.mask,"move",g=>{if(g.offsetY-d.top<this.header_offset.y){let b=Math.min(f,l.scrollTop);l.scrollTop-=b,u.y+=b}else if(g.offsetY-d.top>=d.height&&l.scrollTop+d.height<p.height){let b=f;l.scrollTop+=b,u.y-=b}if(g.offsetX-d.left<this.header_offset.x){let b=Math.min(f,l.scrollLeft);l.scrollLeft-=b,u.x+=b}else if(g.offsetX-d.left>=d.width&&l.scrollLeft+d.width<p.width){let b=f;l.scrollLeft+=b,u.x-=b}if(a.top=g.offsetY-u.y,a.left=g.offsetX-u.x,g.shiftKey){let b=Math.abs(a.left-o.left),v=Math.abs(a.top-o.top);b<=v?a.left=o.left:a.top=o.top}if(g.ctrlKey){let b=this.ClampToGrid({x:a.left,y:a.top});a.left=b.x,a.top=b.y}for(let b of m)b.style.top=a.top+"px",b.style.left=a.left+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(a),s({type:"annotation",annotation:e,event:"move"})});return}else if(r.target===n){r.stopPropagation(),r.preventDefault(),t.focus();let u=0;e.data.type==="image"&&e.data.data&&e.data.data.original_size&&e.data.data.original_size.width&&e.data.data.original_size.height&&(u=e.data.data.original_size.width/e.data.data.original_size.height);let m=t.getBoundingClientRect(),f={x:m.left+r.offsetX-a.width+n.offsetLeft,y:m.top+r.offsetY-a.height+n.offsetTop};ge(this.mask,"nw-resize",p=>{let g=[t,...this.GetFrozenAnnotations(e)];if(a.height=p.offsetY-f.y,a.width=p.offsetX-f.x,p.shiftKey&&p.ctrlKey){if(u){let b=Math.abs(a.width-o.width),v=Math.abs(a.height-o.height);b<v?a.width=u*a.height:a.height=a.width/u}}else if(p.shiftKey){let b=Math.abs(a.height-o.height),v=Math.abs(a.width-o.width);b>v?a.width=o.width:a.height=o.height}else if(p.ctrlKey){let b=this.ClampToGrid({x:a.right,y:a.bottom});a.width=b.x-a.left+1,a.height=b.y-a.top+1}for(let b of g)b.style.height=a.height+"px",b.style.width=a.width+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(a),s({type:"annotation",annotation:e,event:"resize"})});return}else s()}):(console.info("missing scaled rect!"),Promise.reject())}Initialize(e,t,r=!0){this.mask.parentElement||e.parentElement?.parentElement?.appendChild(this.mask),this.tooltip.parentElement||e.appendChild(this.tooltip),this.dropdown_caret.parentElement||e.appendChild(this.dropdown_caret),this.dropdown_list.parentElement||e.appendChild(this.dropdown_list),this.note_node.parentElement||e.appendChild(this.note_node),this.sort_button.parentElement||(e.appendChild(this.sort_button),this.sort_button.addEventListener("click",()=>{t.sort(this.sort_button.dataset.table||"",Number(this.sort_button.dataset.column||"0")||0,/true/i.test(this.sort_button.dataset.asc||"")),this.sort_button.classList.remove("asc","desc"),this.sort_button.dataset.asc==="true"?(this.sort_button.dataset.asc="false",this.sort_button.classList.add("desc")):(this.sort_button.dataset.asc="true",this.sort_button.classList.add("asc")),t.focus()})),this.title_node.parentElement||e.appendChild(this.title_node),this.InitializeInternal(e,t.scroll),!r&&this.scroll_reference_node&&(this.scroll_reference_node.style.overflow="hidden"),this.dropdown_callback=t.dropdown,this.initialized=!0}MockSelection(){if(this.container&&!this.trident&&this.DOM.doc){let e=this.DOM.GetSelection();if(e){let t=this.DOM.doc.createRange();t.selectNodeContents(this.mock_selection),e.removeAllRanges(),e.addRange(t)}}}CreateTile(e,t,r,i,n,a,s,o=!0){let l=this.DOM.Create("canvas");return l.setAttribute("class",e),l.logical_size=t,l.width=t.width*this.dpr,l.height=t.height*this.dpr,l.style.width=`${t.width}px`,l.style.height=`${t.height}px`,l.tile_position=r,l.first_cell=i,this.UpdateTileGridPosition(l),l.last_cell={row:i.row+n.rows-1,column:i.column+n.columns-1},l.pixel_start=a,l.pixel_end={x:a.x+t.width,y:a.y+t.height},l.dirty=!!o,l.needs_full_repaint=!0,s.appendChild(l),l}ApplyTheme(e){this.row_header.style.backgroundColor=this.column_header.style.backgroundColor=this.corner.style.backgroundColor=e.headers?.fill?pe(e,e.headers.fill):"",this.corner.style.borderColor=e.grid_color||"";for(let t of this.grid_tiles)for(let r of t)r.style.backgroundColor=pe(e,e.grid_cell?.fill)||"#fff";this.dropdown_list.style.font=V.Font(e.grid_cell||{})}UpdateTotalSize(){this.total_height=0;let e=this.view.active_sheet.rows;for(let r=0;r<e;r++)this.total_height+=this.RowHeight(r);this.total_width=0;let t=this.view.active_sheet.columns;for(let r=0;r<t;r++)this.total_width+=this.ColumnWidth(r)}UpdateContentsSize(){let e=this.row_header_tiles.reduce((r,i)=>r+i.logical_size.height,0),t=this.column_header_tiles.reduce((r,i)=>r+i.logical_size.width,0);this.column_header.style.width=this.contents.style.width=`${t}px`,this.row_header.style.height=this.contents.style.height=`${e}px`}HideTooltip(){this.tooltip.style.display="none",this.tooltip_state=void 0,this.tooltip.classList.remove("arrow-up"),this.tooltip.classList.remove("arrow-left")}ShowTooltip(e={}){e.up?(this.tooltip.classList.add("arrow-up"),this.tooltip_state="up"):e.left&&(this.tooltip.classList.add("arrow-left"),this.tooltip_state="left"),this.tooltip.style.display="block",this.UpdateTooltip(e)}ShowDropdownCaret(e,t,r){let i=this.OffsetCellAddressToRectangle(e.start);e.count>1&&(i=i.Combine(this.OffsetCellAddressToRectangle(e.end))),i=i.Shift(this.header_size.width,this.header_size.height);let n=Math.round(this.scale*Math.max(8,Math.min(20,i.height)));this.dropdown_caret.style.height=`${n}px`,this.dropdown_caret.style.width=`${n}px`,this.dropdown_caret.style.left=`${i.right+1}px`,this.dropdown_caret.style.top=`${i.bottom-n}px`,this.dropdown_list.style.top=`${i.bottom+2}px`,this.dropdown_list.style.left=`${i.left+2}px`,this.dropdown_list.style.minWidth=`${i.width}px`,this.dropdown_list.textContent="";for(let a of t){let s=this.DOM.Div(void 0,this.dropdown_list);r===a&&(this.dropdown_selected=s,s.classList.add("selected")),s.dropdown_value=a,s.textContent=a?.toString()||""}this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_caret.style.display="block",this.dropdown_caret_visible=!0}HideDropdownCaret(){this.dropdown_caret_visible&&(this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_caret_visible=!1,this.dropdown_caret.style.display="none")}GetScrollOffset(){return{x:this.scroll_reference_node.scrollLeft+this.header_offset.x,y:this.scroll_reference_node.scrollTop+this.header_offset.y}}ScrollTo(e,t=!0,r=!0,i=!1){let n=this.CellAddressToRectangle(e);if(i&&this.scroll_reference_node.scrollTo){let a={left:this.scroll_reference_node.scrollLeft,top:this.scroll_reference_node.scrollTop},s={left:t?n.left:a.left,top:r?n.top:a.top,behavior:"smooth"};this.scroll_reference_node.scrollTo(s)}else r&&(this.scroll_reference_node.scrollTop=n.top),t&&(this.scroll_reference_node.scrollLeft=n.left)}ScrollIntoView(e){let t=this.CellAddressToRectangle(e),r=this.scroll_reference_node.clientWidth-this.row_header.offsetWidth,i=this.scroll_reference_node.clientHeight-this.column_header.offsetHeight,n={x:0,y:0},a={x:!1,y:!1},s=new H(this.scroll_reference_node.scrollLeft,this.scroll_reference_node.scrollTop,r,i);(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&(this.view.active_sheet.freeze.rows&&e.row>=this.view.active_sheet.freeze.rows?n.y=this.frozen_row_tiles[0].logical_size.height:this.view.active_sheet.freeze.rows&&(a.y=!0),this.view.active_sheet.freeze.columns&&e.column>=this.view.active_sheet.freeze.columns?n.x=this.frozen_column_tiles[0].logical_size.width:this.view.active_sheet.freeze.columns&&(a.x=!0)),e.row!==1/0&&(t.top<s.top+n.y&&!a.y?this.scroll_reference_node.scrollTop=t.top-n.y:t.bottom>s.bottom&&(this.scroll_reference_node.scrollTop=t.bottom-i)),e.column!==1/0&&(t.left<s.left+n.x&&!a.x?this.scroll_reference_node.scrollLeft=t.left-n.x:t.right>s.right&&(this.scroll_reference_node.scrollLeft=t.right-r))}UpdateTooltip(e={}){if(typeof e.text<"u"&&(this.tooltip.textContent=e.text),typeof e.x<"u"){let t=e.x||0;this.tooltip_state==="up"&&(t-=this.tooltip.offsetWidth/2),this.tooltip.style.left=Math.round(t)+"px"}if(typeof e.y<"u"){let t=e.y||0;this.tooltip_state==="left"&&(t-=this.tooltip.offsetHeight/2),this.tooltip.style.top=Math.round(t)+"px"}}CoordinateToRowHeader(e){let t={column:1/0,row:0};if(this.view.active_sheet.freeze.rows&&this.frozen_row_tiles[0].pixel_end.y>=e-this.scroll_reference_node.scrollTop){let r=0;e-=this.scroll_reference_node.scrollTop;for(let i=0;i<this.view.active_sheet.freeze.rows;i++)if(r+=this.RowHeight(i),r>=e)return t.row=i,t}for(let r of this.row_header_tiles)if(r.pixel_end.y>=e){let i=e-r.pixel_start.y,n=0;for(t.row=r.first_cell.row;t.row<=r.last_cell.row;t.row++,i-=n)if(n=this.RowHeight(t.row),n>i)return t;return t}return t}CoordinateToColumnHeader(e){let t={row:1/0,column:0};if(this.view.active_sheet.freeze.columns&&this.frozen_column_tiles[0].pixel_end.x>=e-this.scroll_reference_node.scrollLeft){let r=0;e-=this.scroll_reference_node.scrollLeft;for(let i=0;i<this.view.active_sheet.freeze.columns;i++)if(r+=this.ColumnWidth(i),r>=e)return t.column=i,t}for(let r of this.column_header_tiles)if(r.pixel_end.x>=e){let i=e-r.pixel_start.x,n=0;for(t.column=r.first_cell.column;t.column<=r.last_cell.column;t.column++,i-=n)if(n=this.ColumnWidth(t.column),n>i)return t;return t}return t}PointToAddress_Grid(e,t=!1,r=!0){if(r){if(this.view.active_sheet.freeze.rows){let s=this.frozen_row_tiles[0].logical_size.height;e.y-this.scroll_reference_node.scrollTop<s&&(e.y-=this.scroll_reference_node.scrollTop)}if(this.view.active_sheet.freeze.columns){let s=this.frozen_column_tiles[0].logical_size.width;e.x-this.scroll_reference_node.scrollLeft<s&&(e.x-=this.scroll_reference_node.scrollLeft)}}let i={row:0,column:0},n=this.grid_tiles[this.grid_tiles.length-1],a=n[n.length-1];if(e.y>a.pixel_end.y){let s=e.y-a.pixel_end.y;for(i.row=a.last_cell.row;s>0;)i.row++,s-=this.default_row_height}else for(let s of n)if(s.pixel_start.y<=e.y&&s.pixel_end.y>=e.y){let o=e.y-s.pixel_start.y,l=0;for(i.row=s.first_cell.row;i.row<=s.last_cell.row&&(l=this.RowHeight(i.row),!(l>o));i.row++,o-=l);break}if(e.x>a.pixel_end.x){let s=e.x-a.pixel_end.x;for(i.column=a.last_cell.column;s>0;)i.column++,s-=this.default_column_width}else for(let s of this.grid_tiles)if(s[0].pixel_start.x<=e.x&&s[0].pixel_end.x>=e.x){let o=s[0],l=e.x-o.pixel_start.x,d=0;for(i.column=o.first_cell.column;i.column<=o.last_cell.column&&(d=this.ColumnWidth(i.column),!(d>l));i.column++,l-=d);break}return i}AdjacentTile(e,t=0,r=0){if(!t&&!r)return e;let i=e.tile_position,n=e.tile_position.row+t,a=e.tile_position.column+r;if(!(n<0||a<0)){if(this.grid_tiles[i.column]&&this.grid_tiles[i.column][i.row]===e&&this.grid_tiles[a])return this.grid_tiles[a][n];if(!i.column&&this.frozen_column_tiles[i.row]===e)return this.frozen_column_tiles[n];if(!i.row&&this.frozen_row_tiles[i.column]===e)return this.frozen_row_tiles[a]}}UpdateTiles(){if(!this.container)throw new Error("invalid container");this.grid_tiles.forEach(w=>{w.forEach(x=>{x.parentElement&&x.parentElement.removeChild(x)})});for(let w of[this.column_header_tiles,this.row_header_tiles,this.frozen_row_tiles,this.frozen_column_tiles])for(let x of w)x.parentElement&&x.parentElement.removeChild(x);this.frozen_row_tiles=[],this.frozen_column_tiles=[],this.row_header_tiles=[],this.column_header_tiles=[],this.grid_tiles=[];let e=this.view.active_sheet;this.default_row_height=Math.round(e.default_row_height*this.scale),this.default_column_width=Math.round(e.default_column_width*this.scale),this.header_offset={x:Math.round(e.header_offset.x*this.scale),y:Math.round(e.header_offset.y*this.scale)},this.UpdateContainingGrid();let t=this.view.active_sheet.rows,r=this.view.active_sheet.columns;t||(t=100),r||(r=40);let i=0,n=0;for(let w=0;w<t;w++)i+=this.RowHeight(w);for(let w=0;w<r;w++)n+=this.ColumnWidth(w);if(!n||!i)throw"unexpected missing total size";if(i||(i=this.default_row_height*t),n||(n=this.default_column_width*r),this.container.clientWidth>n+this.header_size.width){let w=Math.ceil((this.container.offsetWidth-n)/this.default_column_width);n+=w*this.default_column_width,r+=w}if(this.last_column=r,this.container.clientHeight>i+this.header_size.height){let w=Math.ceil((this.container.offsetHeight-i)/this.default_row_height);i+=w*this.default_row_height,t+=w}this.column_header.style.width=this.contents.style.width=`${n}px`,this.row_header.style.height=this.contents.style.height=`${i}px`;let a=[],s=[],o=0,l=0;for(let w=0;w<r;w++){let x=this.ColumnWidth(w);o&&o+x>this.default_tile_size.width&&(a.push(o),s.push(l),l=w,o=0),o+=x}a.push(o),s.push(l);let d=[],h=[],u=0,m=0;for(let w=0;w<t;w++){let x=this.RowHeight(w);u&&u+x>this.default_tile_size.height&&(d.push(u),h.push(m),u=0,m=w),u+=x}d.push(u),h.push(m);let f=a.length,p=d.length,g=0,b=0,v=0,_=0;for(let w=0;w<this.view.active_sheet.freeze.rows;w++)v+=this.RowHeight(w);for(let w=0;w<this.view.active_sheet.freeze.columns;w++)_+=this.ColumnWidth(w);for(let w=0;w<f;w++){let x=[];g=0;let A=w===f-1?r-s[w]:s[w+1]-s[w];this.column_header_tiles.push(this.CreateTile("column-header-tile",{height:this.header_offset.y,width:a[w]},{row:0,column:w},{row:0,column:s[w]},{rows:0,columns:A},{x:b,y:0},this.column_header)),this.view.active_sheet.freeze.rows&&this.frozen_row_tiles.push(this.CreateTile("frozen-row-tile",{height:v,width:a[w]},{row:1,column:w},{row:0,column:s[w]},{rows:0,columns:A},{x:b,y:0},this.column_header));for(let k=0;k<p;k++){let S=k===p-1?t-h[k]:h[k+1]-h[k];w||(this.row_header_tiles.push(this.CreateTile("row-header-tile",{height:d[k],width:this.header_offset.x},{row:k,column:0},{row:h[k],column:0},{rows:S,columns:1},{x:0,y:g},this.row_header)),this.view.active_sheet.freeze.columns&&this.frozen_column_tiles.push(this.CreateTile("frozen-column-tile",{height:d[k],width:_},{row:k,column:1},{row:h[k],column:0},{rows:S,columns:1},{x:0,y:g},this.row_header))),x.push(this.CreateTile("grid-tile",{height:d[k],width:a[w]},{row:k,column:w},{row:h[k],column:s[w]},{rows:S,columns:A},{x:b,y:g},this.contents)),g+=d[k]}this.grid_tiles.push(x),b+=a[w]}this.total_height=i,this.total_width=n,this.ClearLayoutCaches(),this.UpdateGridTemplates(!0,!0)}ClearLayoutCaches(){this.row_cache=[],this.column_cache=[]}TileIndexForColumn(e){for(let t of this.column_header_tiles)if(t.first_cell.column<=e&&t.last_cell.column>=e)return t.tile_position.column;return-1}TileIndexForRow(e){for(let t of this.row_header_tiles)if(t.first_cell.row<=e&&t.last_cell.row>=e)return t.tile_position.row;return-1}DirtyHeaders(e){if(e){for(let t of this.column_header_tiles){if(t.dirty)continue;let r=new y({row:e.start.row,column:t.first_cell.column},{row:e.start.row,column:t.last_cell.column});(e.entire_row||r.Intersects(e))&&(t.dirty=!0)}for(let t of this.row_header_tiles){if(t.dirty)continue;let r=new y({column:e.start.column,row:t.first_cell.row},{column:e.start.column,row:t.last_cell.row});(e.entire_column||r.Intersects(e))&&(t.dirty=!0)}}}DirtyAll(){for(let e of this.grid_tiles)for(let t of e)t.dirty=!0}DirtyArea(e){if(this.initialized){Array.isArray(e)||(e=[e]);for(let t of e){let r={row:0,column:0},i={row:this.grid_tiles[0].length-1,column:this.grid_tiles.length-1};t.start.column!==1/0&&(r.column=i.column=this.TileIndexForColumn(t.start.column),t.end.column!==t.start.column&&(i.column=this.TileIndexForColumn(t.end.column))),t.start.row!==1/0&&(r.row=i.row=this.TileIndexForRow(t.start.row),t.end.row!==t.start.row&&(i.row=this.TileIndexForRow(t.end.row)));for(let n=r.column;n<=i.column;n++)for(let a=r.row;a<=i.row;a++)this.grid_tiles[n][a].dirty=!0}}}VisibleTiles(){let e=[{row:0,column:0},{row:0,column:0}];if(!this.container||!this.grid_tiles.length||!this.grid_tiles[0].length)return new y(e[0],e[1]);let t=this.scroll_reference_node.scrollLeft,r=t+this.scroll_reference_node.offsetWidth,i=this.scroll_reference_node.scrollTop,n=i+this.scroll_reference_node.offsetHeight;for(let a of this.grid_tiles){let s=a[0];if(s.pixel_start.x<=t&&s.pixel_end.x>=t){for(s of a)if(s.pixel_start.y<=i&&s.pixel_end.y>=i){e[0]=s.tile_position;break}}if(a===this.grid_tiles[this.grid_tiles.length-1]||s.pixel_start.x<=r&&s.pixel_end.x>=r){for(s of a)if(s===a[a.length-1]||s.pixel_start.y<=n&&s.pixel_end.y>=n)return e[1]=s.tile_position,new y(e[0],e[1])}}return new y(e[0],e[1])}UpdateTileHeights(e=!0,t=-1){let r=0;for(let i=0;i<this.row_header_tiles.length;i++){let n=this.row_header_tiles[i];if(t>n.last_cell.row){r+=n.logical_size.height;continue}let a=0;for(let o=n.first_cell.row;o<=n.last_cell.row;o++)a+=this.RowHeight(o);let s=n.logical_size.height===a;if(n.pixel_start.y=r,r+=a,n.pixel_end.y=r,!s){if(n.logical_size.height=a,n.style.height=`${a}px`,n.height=this.dpr*a,this.view.active_sheet.freeze.columns){let o=this.frozen_column_tiles[i];o.logical_size.height=a,o.style.height=`${a}px`,o.height=this.dpr*a}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let o of this.grid_tiles){let l=o[i];l.pixel_start.y=n.pixel_start.y,l.pixel_end.y=n.pixel_end.y,s||(l.logical_size.height=a,l.style.height=`${a}px`,l.height=this.dpr*a,e&&(l.dirty=!0,l.needs_full_repaint=!0))}}if(this.view.active_sheet.freeze.rows){let i=0;for(let n=0;n<this.view.active_sheet.freeze.rows;n++)i+=this.RowHeight(n);for(let n of this.frozen_row_tiles)n.style.height=`${i}px`,n.height=i*this.dpr;i+=this.header_offset.y,this.corner_canvas.style.height=`${i}px`,this.corner_canvas.height=i*this.dpr;for(let n of this.grid_tiles)n[0].dirty=!0}this.UpdateGridTemplates(!1,!0),this.row_header.style.height=this.contents.style.height=`${r}px`,this.ClearLayoutCaches()}UpdateTileWidths(e=!0,t=-1){let r=0;for(let i=0;i<this.column_header_tiles.length;i++){let n=this.column_header_tiles[i],a=this.grid_tiles[i];if(t>n.last_cell.column){r+=n.logical_size.width;continue}let s=0;for(let l=n.first_cell.column;l<=n.last_cell.column;l++)s+=this.ColumnWidth(l);let o=n.logical_size.width===s;if(n.pixel_start.x=r,r+=s,n.pixel_end.x=r,!o){if(n.logical_size.width=s,n.style.width=`${s}px`,n.width=this.dpr*s,this.view.active_sheet.freeze.rows){let l=this.frozen_row_tiles[i];l.logical_size.width=s,l.style.width=`${s}px`,l.width=this.dpr*s}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let l of a)l.pixel_start.x=n.pixel_start.x,l.pixel_end.x=n.pixel_end.x,o||(l.logical_size.width=s,l.style.width=`${s}px`,l.width=this.dpr*s,e&&(l.dirty=!0,l.needs_full_repaint=!0))}if(this.view.active_sheet.freeze.columns){let i=0;for(let n=0;n<this.view.active_sheet.freeze.columns;n++)i+=this.ColumnWidth(n);for(let n of this.frozen_column_tiles)n.style.width=`${i}px`,n.width=i*this.dpr;i+=this.header_offset.x,this.corner_canvas.style.width=`${i}px`,this.corner_canvas.width=i*this.dpr;for(let n of this.grid_tiles[0])n.dirty=!0}this.UpdateGridTemplates(!0,!1),this.column_header.style.width=this.contents.style.width=`${r}px`,this.ClearLayoutCaches()}ClampToGrid(e){let t=this.PointToAddress_Grid(e),r=this.OffsetCellAddressToRectangle(t);return e.x>r.left+r.width/2?e.x=r.left+r.width-1:e.x=r.left-1,e.y>r.top+r.height/2?e.y=r.top+r.height-1:e.y=r.top-1,e}OffsetCellAddressToRectangle(e){let t=this.CellAddressToRectangle(e);return e.column>=0&&e.column<this.view.active_sheet.freeze.columns&&(t=t.Shift(this.scroll_reference_node.scrollLeft,0)),e.row>=0&&e.row<this.view.active_sheet.freeze.rows&&(t=t.Shift(0,this.scroll_reference_node.scrollTop)),t}CellAddressToRectangle(e){let t=e.row===1/0||e.row<0?0:e.row,r=e.column===1/0||e.column<0?0:e.column;if(this.column_cache.length<=r+1){this.column_cache.length||(this.column_cache[0]=0);for(let a=this.column_cache.length-1;a<=r;a++)this.column_cache[a+1]=this.column_cache[a]+this.ColumnWidth(a)}if(this.row_cache.length<=t+1){this.row_cache.length||(this.row_cache[0]=0);for(let a=this.row_cache.length-1;a<=t;a++)this.row_cache[a+1]=this.row_cache[a]+this.RowHeight(a)}let i=this.column_cache[r],n=this.row_cache[t];return new H(i,n,this.column_cache[r+1]-i,this.row_cache[t+1]-n)}ResizeTileWidth(e,t,r=!0){let i=this.column_header_tiles[e],n=t-i.logical_size.width;i.logical_size.width=t,i.style.width=`${t}px`,i.width=this.dpr*t,i.pixel_end.x+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let s=e+1;s<this.column_header_tiles.length;s++){this.column_header_tiles[s].pixel_start.x+=n,this.column_header_tiles[s].pixel_end.x+=n;for(let o of this.grid_tiles[s])o.pixel_start.x+=n,o.pixel_end.x+=n}let a=this.grid_tiles[e];for(i of a)i.logical_size.width=t,i.style.width=`${t}px`,i.width=this.dpr*t,i.pixel_end.x+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);this.UpdateTotalSize(),this.UpdateGridTemplates(!0,!1),this.UpdateContentsSize()}ResizeTileHeight(e,t,r=!0){let i=this.row_header_tiles[e],n=t-i.logical_size.height;i.logical_size.height=t,i.style.height=`${t}px`,i.height=this.dpr*t,i.pixel_end.y+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let a=e+1;a<this.row_header_tiles.length;a++)i=this.row_header_tiles[a],i.pixel_start.y+=n,i.pixel_end.y+=n;for(let a of this.grid_tiles){i=a[e],i.logical_size.height=t,i.style.height=`${t}px`,i.height=this.dpr*t,i.pixel_end.y+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let s=e+1;s<a.length;s++)a[s].pixel_start.y+=n,a[s].pixel_end.y+=n}this.UpdateTotalSize(),this.UpdateGridTemplates(!1,!0),this.UpdateContentsSize()}};var Rt=class extends Oe{constructor(e,t){super(e,t,!0)}InitializeInternal(e,t){}UpdateGridTemplates(e,t){}UpdateTileGridPosition(e){}UpdateContainingGrid(){}ResizeCursor(e){}};var Tt=class extends Oe{constructor(e,t,r){super(e,t,!1,r),this.column_header=r.Div("treb-top-header"),this.row_header=r.Div("treb-left-header"),this.corner=r.Div("treb-corner"),this.corner_canvas=r.Create("canvas"),this.corner.appendChild(this.corner_canvas),this.contents=r.Div("treb-contents"),this.buffer_canvas=r.Create("canvas","treb-buffer-canvas",this.contents),this.grid_selection=r.SVG("svg","treb-grid-selection",this.contents),this.row_header_selection=r.SVG("svg",["frozen-selection","frozen-selection-rows"],this.column_header),this.row_header_annotations=r.Div("frozen-annotation-container frozen-annotation-container-rows",this.column_header),this.column_header_selection=r.SVG("svg",["frozen-selection","frozen-selection-columns"],this.row_header),this.column_header_annotations=r.Div("frozen-annotation-container frozen-annotation-container-columns",this.row_header),this.corner_selection=r.SVG("svg","frozen-selection",this.corner),this.corner_annotations=r.Div("frozen-annotation-container frozen-annotation-container-corner",this.corner),this.annotation_container=r.Div("treb-annotation-container"),this.grid_cover=r.Div("tile-cover grid-cover"),this.column_header_cover=r.Div("tile-cover column-header-cover"),this.row_header_cover=r.Div("tile-cover row-header-cover")}InitializeInternal(e,t){this.container=e,this.scroll_reference_node=this.container,e.appendChild(this.column_header),e.appendChild(this.row_header),e.appendChild(this.corner),e.appendChild(this.contents),e.appendChild(this.annotation_container),e.appendChild(this.grid_cover),e.appendChild(this.column_header_cover),e.appendChild(this.row_header_cover),e.appendChild(this.mock_selection),this.container.addEventListener("scroll",()=>t())}ResizeCursor(e){switch(e){case"row":this.row_header_cover.classList.add("resize");break;case"column":this.column_header_cover.classList.add("resize");break;default:this.row_header_cover.classList.remove("resize"),this.column_header_cover.classList.remove("resize");break}}UpdateTileGridPosition(e){e.style.gridColumn=`${e.tile_position.column+1} / ${e.tile_position.column+2}`,e.style.gridRow=`${e.tile_position.row+1} / ${e.tile_position.row+2}`}UpdateContainingGrid(){if(!this.container)throw new Error("missing container");this.header_size.width=this.header_offset.x,this.header_size.height=this.header_offset.y;let e=this.header_offset.x,t=this.header_offset.y;if(this.view.active_sheet.freeze.columns)for(let r=0;r<this.view.active_sheet.freeze.columns;r++)e+=this.ColumnWidth(r);if(this.view.active_sheet.freeze.rows)for(let r=0;r<this.view.active_sheet.freeze.rows;r++)t+=this.RowHeight(r);this.container.style.gridTemplateColumns=`${this.header_offset.x}px auto`,this.container.style.gridTemplateRows=`${this.header_offset.y}px auto`,this.corner_canvas.setAttribute("width",`${this.dpr*e}`),this.corner_canvas.setAttribute("height",`${this.dpr*t}`),this.column_header.style.height=`${t}px`,this.corner_canvas.style.width=`${e}px`,this.corner_canvas.style.height=`${t}px`}UpdateGridTemplates(e=!0,t=!0){let r=0,i=0;this.column_header.style.gridTemplateColumns=this.contents.style.gridTemplateColumns=this.column_header_tiles.map(l=>(r+=l.logical_size.width,`${l.logical_size.width}px`)).join(" "),this.column_header.style.gridTemplateRows=`${this.header_offset.y}px auto`,this.row_header.style.gridTemplateRows=this.contents.style.gridTemplateRows=this.row_header_tiles.map(l=>(i+=l.logical_size.height,`${l.logical_size.height}px`)).join(" ");let n=this.header_offset.y;if(this.view.active_sheet.freeze.rows)for(let l=0;l<this.view.active_sheet.freeze.rows;l++)n+=this.RowHeight(l);this.column_header.style.height=`${n}px`,this.row_header_selection.style.display="block",this.row_header_selection.style.width=`${r}px`,this.corner_selection.style.height=this.row_header_selection.style.height=`${n}px`,this.corner_selection.style.top=this.row_header_selection.style.top="0px",this.row_header_selection.style.left="0px";let a=this.header_offset.x;if(this.view.active_sheet.freeze.columns)for(let l=0;l<this.view.active_sheet.freeze.columns;l++)a+=this.ColumnWidth(l);this.column_header_selection.style.display="block",this.corner_selection.style.width=this.column_header_selection.style.width=`${a}px`,this.column_header_selection.style.height=`${i}px`,this.column_header_selection.style.top="0px",this.corner_selection.style.left=this.column_header_selection.style.left="0px";let s={x:this.view.active_sheet.header_offset.x*this.scale,y:this.view.active_sheet.header_offset.y*this.scale},o=this.view.active_sheet.freeze;o.rows&&o.columns?(this.row_header_annotations.style.display="block",this.column_header_annotations.style.display="block",this.corner_annotations.style.display="block"):o.rows?(this.row_header_annotations.style.display="block",this.column_header_annotations.style.display="none",this.corner_annotations.style.display="none"):o.columns?(this.row_header_annotations.style.display="none",this.column_header_annotations.style.display="block",this.corner_annotations.style.display="none"):(this.row_header_annotations.style.display="none",this.column_header_annotations.style.display="none",this.corner_annotations.style.display="none"),this.row_header_annotations.style.width=`${r}px`,this.corner_annotations.style.height=this.row_header_annotations.style.height=`${n-s.y}px`,this.corner_annotations.style.top=this.row_header_annotations.style.top=`${s.y}px`,this.column_header_annotations.style.width=this.corner_annotations.style.width=`${a-s.x}px`,this.column_header_annotations.style.height=`${i}px`,this.corner_annotations.style.left=this.column_header_annotations.style.left=`${s.x}px`,this.corner_selection.style.display="block",this.grid_selection.style.width=`${r}px`,this.grid_selection.style.height=`${i}px`,this.grid_selection.style.top=`${this.header_offset.y}px`,this.grid_selection.style.left=`${this.header_offset.x}px`,this.annotation_container.style.width=`${r}px`,this.annotation_container.style.height=`${i}px`,this.annotation_container.style.top=`${this.header_offset.y}px`,this.annotation_container.style.left=`${this.header_offset.x}px`}};var Et=class{function_names=[];argument_separator=D.argument_separator.charCodeAt(0);function_map={};RemoveFunctions(e){Array.isArray(e)||(e=[e]);let t=Object.keys(this.function_map).map(r=>this.function_map[r]);for(let r of e)t=t.filter(i=>i.name!==r.name);this.SetFunctions(t)}AddFunctions(e){Array.isArray(e)||(e=[e]);let t=Object.keys(this.function_map).map(r=>this.function_map[r]).concat(...e);this.SetFunctions(t)}SetFunctions(e){this.function_map={},this.function_names=e.map(t=>(this.function_map[t.name.toLowerCase()]=t,t.name)).sort((t,r)=>t.toLowerCase().localeCompare(r.toLowerCase()))}NormalizeIdentifier(e){let t=this.function_map[e.toLowerCase()];return t?t.name:void 0}Exec(e){if(e.text[0]!=="=")return{};let t,r={};if(e.cursor===e.text.length&&(t=e.text.match(/(?:^|[^A-Za-z_\d])([A-Za-z_][\w\d_.]*)\s*$/),t)){let n=t[1],a=new RegExp("^"+n.replace(".","\\."),"i");r={completions:this.function_names.filter(o=>a.test(o)).map(o=>this.function_map[o.toLowerCase()]),token:n,position:e.cursor-n.length}}let i=this.ParseTooltip(e.text.substr(0,e.cursor));if(i.function){let n=this.function_map[i.function.toLowerCase()];n&&(r.tooltip='<span class="notranslate">'+n.name+"</span>",r.arguments="("+(n.arguments||[]).map((a,s)=>{let o=a.name||"argument";return s===i.argument?`<span class="active-argument">${o}</span>`:o}).join(D.argument_separator+" ")+")",r.description=n.description?`<span class="function-description">${n.description}</span>`:"",r.function_position=i.position||0)}return r}ParseTooltip(e){let t=[],r=0,i="",n=!1,a=0;for(let o of e){let l=o.charCodeAt(0);if(n)l===34&&(n=!1);else switch(l){case 40:t.push({buffer:i.trim(),argument:r,position:a-i.length}),i="",r=0;break;case this.argument_separator:r++;break;case 41:r=t.pop()?.argument||0;break;case 34:i="",n=!0;break;default:l>=97&&l<=122||l>=65&&l<=90||l>=48&&l<=57||l===95||l===46?i+=o:i=""}a++}let s=t.pop();return{function:s?.buffer||void 0,position:s?.position||0,argument:r}}};var Me=class c extends oe{constructor(t,r,i){super();this.model=t;this.view=r;this.autocomplete=i;this.parser=t.parser}static FormulaChars=("$^&*(-+={[<>/~%"+D.argument_separator).split("");active_cell;autocomplete_matcher;container_node;active_editor;nodes=[];target_address;assume_formula=!1;text_formula=!1;get selecting(){if(this.assume_formula)return!0;if(!this.text_formula)return!1;if(this.active_editor&&this.active_editor.node===this.active_editor.node.ownerDocument.activeElement){let t=this.active_editor.node.ownerDocument.defaultView,r=t.getSelection();if(r?.rangeCount){let a=r?.getRangeAt(0);if((a?.endContainer instanceof t.HTMLElement?a.endContainer:a.endContainer?.parentElement)?.dataset.reference!==void 0)return!0;if(a?.startContainer instanceof t.Text){let o=(a.startContainer.textContent?.substring(0,a.startOffset)||"").trim();if(o.length&&c.FormulaChars.includes(o[o.length-1]))return!0}else console.info("mark 21",a)}let n=this.SubstringToCaret2(this.active_editor.node)[1].trim();if(n.length){let a=n[n.length-1];return c.FormulaChars.includes(a)}}return!1}composite_dependencies=[];get dependencies(){return this.composite_dependencies}parser;FocusEditor(){this.active_editor&&this.active_editor.node.focus()}RegisterListener(t,r,i){t.node.addEventListener(r,i),t.listeners||(t.listeners=new Map),t.listeners.set(r,i)}SelectAll(t){let i=t.ownerDocument.defaultView.getSelection(),n=t.ownerDocument.createRange();n.selectNode(t),i?.removeAllRanges(),i?.addRange(n)}SetCaret(t,r){let i=t.node.ownerDocument,n=i?.defaultView,a=n.getSelection(),s=i?.createRange(),o=d=>{let h=d;for(;h&&!(h instanceof n.Text)&&h.firstChild;)h=h.firstChild;return h},l=o(t.node);if(r){let d=o(r.node);a&&s&&(s.setStart(l,t.offset),s.setEnd(d,r.offset),a.removeAllRanges(),a.addRange(s))}else a&&s&&(s.setStart(l,t.offset),s.setEnd(l,t.offset),s.collapse(!0),a.removeAllRanges(),a.addRange(s))}InsertReference(t,r){if(!this.active_editor)return;let i=this.active_editor.node.ownerDocument.defaultView,n=i.getSelection();if(!n)throw new Error("error getting selection");if(n.rangeCount===0)return"";let a=n.getRangeAt(0),s=this.active_editor.node.textContent||"";if(a.startContainer instanceof i.Text)if(!a.collapsed&&a.startOffset<a.endOffset){let o=this.SubstringToCaret2(this.active_editor.node);this.active_editor.node.textContent=o[0]+t+s.substring(o[1].length),this.SetCaret({node:this.active_editor.node,offset:o[0].length},{node:this.active_editor.node,offset:o[0].length+t.length})}else{let o=a.startContainer.parentElement;if(o instanceof i.HTMLElement&&o.dataset.reference)o.textContent=t,this.SetCaret({node:o,offset:t.length});else{let l=this.SubstringToCaret2(this.active_editor.node)[1],d="",h="",u=l.trim();if(u.length){let m=u[u.length-1];c.FormulaChars.includes(m)||(l.length===u.length?d=" +":d="+")}this.active_editor.node.textContent=l+d+t+s.substring(l.length),this.SetCaret({node:this.active_editor.node,offset:l.length+t.length+d.length})}}else a.startContainer instanceof i.HTMLElement?(a.startContainer.textContent=t,this.SetCaret({node:a.startContainer,offset:t.length})):console.warn("unexpected range start container",a.startContainer);this.UpdateText(this.active_editor),this.UpdateColors(),this.active_editor.node.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}UpdateColors(t=!1){let r=new Map,i=new Map;for(let a of this.nodes)for(let s of a.references||[]){let o=this.model.AddressToLabel(s);r.has(o)||(r.set(o,s),i.set(o,i.size))}for(let a of this.nodes){for(let s of Array.from(a.node.childNodes)){let o=s.ownerDocument?.defaultView;if(o&&s instanceof o.HTMLElement&&s.dataset.reference){let l=i.get(s.dataset.reference);s.dataset.highlightIndex=typeof l=="number"?(l%5+1).toString():"?"}}a.check=a.node.innerHTML.length}let n=Array.from(r.values());!t&&JSON.stringify(this.composite_dependencies)===JSON.stringify(n)||(this.composite_dependencies=n,this.Publish({type:"update",dependencies:this.composite_dependencies}))}UpdateDependencies(t,r){let i=[];for(let o of r.full_reference_list||[])switch(o.type){case"address":case"range":{let l=o.type==="range"?o.start:o;l.sheet_id||(l.sheet?l.sheet_id=this.model.sheets.Find(l.sheet)?.id||0:l.sheet_id=this.view.active_sheet.id),i.push(o);break}case"structured-reference":if(this.target_address){let l=this.model.ResolveStructuredReference(o,this.target_address);l&&i.push(l)}else console.info("target address not set");break;case"identifier":{let l=this.model.named_ranges.Get(o.name);l&&(l.count===1?i.push({type:"address",...l.start,label:o.name,position:o.position,id:o.id}):i.push({type:"range",start:{type:"address",position:o.position,id:o.id,label:o.name,...l.start},end:{type:"address",position:o.position,label:o.name,id:o.id,...l.end},label:o.name,position:o.position,id:o.id}));break}}i.sort((o,l)=>o.position-l.position);let n=[],a=new Set,s=new Map;for(let o of i){let l=this.model.AddressToLabel(o,this.view.active_sheet),d=N(o)?new y(o):new y(o.start,o.end);a.has(l)||(n.push(d),a.add(l)),s.set(o,l)}return this.UpdateReferences(t,n),s}UpdateReferences(t,r=[]){t.node.dataset.references=JSON.stringify(r.map(i=>this.model.AddressToLabel(i))),t.references=r}UpdateText(t,r={}){let i=t.node,n=i.textContent||"",a=F.GetInstance(i.ownerDocument);if(this.text_formula=n[0]==="=",this.active_editor&&!this.assume_formula&&(this.active_editor.node.spellcheck=!this.text_formula),n===t.formatted_text)return;let[s,o]=this.SubstringToCaret2(i),l=s.length,d=o.length;if(l===0&&d===0&&(d=n.length),!n)this.UpdateReferences(t);else{let u=this.parser.Parse(n);if(u.expression){let m=this.UpdateDependencies(t,u),f=n[0]==="="?1:0,p=0,g,b,v=0,_,w=a.Fragment(),x=(A,k="text",S="",M=!1)=>{let U=a.Text(A);if((M||(l>v||l===0&&v===0)&&l<=v+A.length)&&(g={offset:l-v,node:U}),d>v&&d<=v+A.length&&(b={offset:d-v,node:U}),k!=="text"){let W=a.Create("span",k);S&&(W.dataset.reference=S),W.appendChild(U),w.appendChild(W)}else w.appendChild(U);_=U,v+=A.length};this.parser.Walk(u.expression,A=>{if(A.type==="missing"||A.type==="group"||A.type==="dimensioned")return!0;let k=A.position+f,S=n.substring(p,k),M="",U=A.type,W="";switch(A.type){case"identifier":case"call":M=n.substring(k,k+A.name.length);break;case"literal":if(typeof A.value=="string")M=n.substring(k,k+A.value.length+2),U="string";else return!1;break;case"address":case"range":case"structured-reference":W=m.get(A)||"???",M=r.rewrite_addresses?A.label:n.substring(k,k+A.label.length);break;default:return!0}return x(S),x(M,U,W),p=k+M.length,A.type!=="range"}),p<n.length&&x(n.substring(p)),g||(_?g={node:_,offset:(_.data||"").length}:x("",void 0,"",!0)),i.textContent="",i.appendChild(w),g&&!r.format_only&&i===this.active_editor?.node&&this.SetCaret(g,b)}}t.formatted_text=n;let h=this.autocomplete_matcher;h&&Promise.resolve().then(()=>{let u=h.Exec({text:n,cursor:o.length}),m=this.NodeAtIndex(u.completions?.length?u.position||0:u.function_position||0);this.Autocomplete(u,m)})}NodeAtIndex(t){let r=this.active_editor?.node.childNodes||[];for(let i=0;i<r.length;i++){let n=r[i].textContent?.length||0;if(n>t)return r[i];t-=n}}AcceptAutocomplete(t){if(!this.active_editor)return;let r=0;if(t.data&&t.data.completions){for(let d of t.data.completions)if(d.name.toLowerCase()===t.value?.toLowerCase()){r=d.type||0;break}}let i=t.data?.position||0,n=i+(t.data?.token?.length||0),a=r===1?t.value:t.value+"(",s=this.active_editor.node.textContent||"",o=s.substring(0,i)+a,l=o.length;o+=s.substring(n),this.active_editor.node.textContent=o,this.SetCaret({node:this.active_editor.node,offset:l}),this.autocomplete?.Hide(),this.UpdateText(this.active_editor),this.UpdateColors()}Autocomplete(t,r){if(!this.container_node||!this.autocomplete)return;let i;r?.nodeType===Node.ELEMENT_NODE?i=r.getBoundingClientRect():i=this.container_node.getBoundingClientRect();let n=new H(Math.round(i.left),Math.round(i.top),i.width,i.height);this.autocomplete.Show(this.AcceptAutocomplete.bind(this),t,n)}SubstringToCaret2(t){let r=["",""];if(t!==t.ownerDocument.activeElement||t!==this.active_editor?.node)return r;let n=t.ownerDocument.defaultView,a=[!1,!1],s=(l,d)=>{if(l===d.startContainer&&l===d.endContainer&&!(l instanceof n.Text)){a[0]=a[1]=!0,r[0]+=l.textContent,r[1]+=l.textContent;return}if(l===d.startContainer&&(r[0]+=(l.textContent||"").substring(0,d.startOffset),a[0]=!0),l===d.endContainer&&(r[1]+=(l.textContent||"").substring(0,d.endOffset),a[1]=!0),!(a[0]&&a[1])){if(l instanceof n.Text){let h=l.textContent||"";a[0]||(r[0]+=h),a[1]||(r[1]+=h)}else if(l.hasChildNodes()){for(let h of Array.from(l.childNodes))if(s(h,d),a[0]&&a[1])return}}},o=n.getSelection();if(o?.rangeCount??0>0){let l=o?.getRangeAt(0);l&&s(t,l)}return r}};var Nn=typeof navigator>"u"?"":navigator.appVersion,we=typeof navigator>"u"?"":navigator.userAgent,yr=class{is_edge=/Edge/.test(Nn);is_ipad=/iPad|iPhone/.test(we);is_android=/android|samsung/i.test(we);is_mobile=this.is_ipad||this.is_android;is_firefox=/firefox/i.test(we);is_safari=/safari/i.test(we)&&!/edg/i.test(we);is_mac=/macintosh/i.test(we);is_chrome=/Chrome/i.test(we);is_windows=/win64|win32|windows\s+nt/i.test(we);is_modern=!this.is_edge&&!(this.is_firefox&&this.is_android)&&/webkit|firefox/i.test(we)},Vn={is_edge:!1,is_ipad:!1,is_android:!1,is_firefox:!1,is_safari:!1,is_mac:!1,is_chrome:!1,trident:!1,is_windows:!1,is_modern:!0,is_node:!0,is_mobile:!1},re=typeof navigator>"u"?Vn:new yr;var Mt=class extends Me{constructor(t,r,i,n,a){super(i,n,a);this.container=t;this.theme=r;this.container_node=t.querySelector(".treb-overlay-container"),this.edit_node=this.container_node.querySelector(".treb-overlay-editor"),re.is_firefox&&this.edit_node.classList.add("firefox"),this.edit_node.inputMode="none";let s={node:this.edit_node};this.nodes=[s],this.active_editor=s,this.RegisterListener(s,"input",o=>{if(o instanceof InputEvent&&o.isComposing)return;if(!o.isTrusted){this.reset_selection=!0;return}this.reset_selection&&this.Publish({type:"reset-selection"});let l=this.edit_node.firstChild;l&&l.tagName==="BR"&&this.edit_node.removeChild(l),this.editing&&(this.UpdateText(s),this.UpdateColors())}),this.RegisterListener(s,"keyup",o=>{o.isComposing||!this.editing||this.autocomplete&&this.autocomplete.HandleKey("keyup",o).handled}),this.edit_inset=this.container_node.querySelector(".treb-overlay-inset"),this.ClearContents()}internal_selection={target:{row:0,column:0},area:new y({row:0,column:0})};get selection(){return this.internal_selection}set selection(t){if(t){let r=t.target||t.area.start;this.internal_selection={target:{row:r.row,column:r.column},area:new y(t.area.start,t.area.end)}}else{let r={row:0,column:0};this.internal_selection={target:r,area:new y(r)}}}reset_selection=!1;edit_node;container_node;edit_inset;scale=1;internal_editing=!1;get editing(){return this.internal_editing}set editing(t){this.internal_editing!==t&&(this.internal_editing=t,t?(this.container_node.style.opacity="1",this.container_node.style.pointerEvents="initial"):(this.container_node.style.opacity="0",this.container_node.style.pointerEvents="none"))}UpdateCaption(t=""){this.edit_node.setAttribute("aria-label",t)}Focus(t=""){this.edit_node!==this.edit_node.ownerDocument.activeElement&&(this.container_node.style.top=`${this.container.scrollTop+this.view.active_sheet.header_offset.y}px`,this.container_node.style.left=`${this.container.scrollLeft+this.view.active_sheet.header_offset.x}px`),this.edit_node.focus(),this.UpdateCaption(t)}CloseEditor(){this.editing=!1,this.reset_selection=!1,this.ClearContents(),this.edit_node.spellcheck=!0,this.autocomplete?.Hide(),this.active_cell=void 0}ClearContents(){re.is_firefox?this.edit_node.innerHTML="<span></span>":this.edit_node.textContent=""}Edit(t,r,i,n,a){this.Publish({type:"start-editing",editor:"ice"}),this.active_cell=i,this.target_address={...t.target},this.reset_selection=!1;let s=i.style||{};switch(this.edit_node.style.font=V.Font(s,this.scale),this.edit_node.style.color=T(this.theme,s.text,1),this.edit_inset.style.backgroundColor=T(this.theme,s.fill,0),s.horizontal_align){case"right":this.container_node.classList.remove("align-center","align-left"),this.container_node.classList.add("align-right");break;case"center":this.container_node.classList.remove("align-right","align-left"),this.container_node.classList.add("align-center");break;default:this.container_node.classList.remove("align-right","align-center"),this.container_node.classList.add("align-left");break}this.edit_node.style.paddingBottom=`${Math.max(0,(self.devicePixelRatio||1)-1)}px`;let o=n?.toString()||"";if(o&&o[0]==="="&&(this.edit_node.spellcheck=!1),r.ApplyStyle(this.container_node),this.autocomplete?.ResetBlock(),this.selection=t,typeof n<"u"){let l=o[0]!=="="&&o[o.length-1]==="%",d=o.length;this.edit_node.textContent=o,this.SetCaret({node:this.edit_node,offset:d-(l?1:0)})}this.editing=!0,Promise.resolve().then(()=>{this.active_editor&&(this.active_editor.formatted_text=void 0,this.UpdateText(this.active_editor),this.UpdateColors()),!a&&n!==void 0&&this.Publish({type:"update",text:n.toString(),dependencies:this.composite_dependencies})})}HandleKeyDown(t){if(this.editing){if(this.autocomplete){let r=this.autocomplete.HandleKey("keydown",t);if(r.accept&&this.AcceptAutocomplete(r),r.handled)return"handled"}switch(t.key){case"Enter":case"Tab":return"commit";case"Escape":case"Esc":return"discard";case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"Up":case"Down":case"Left":case"Right":return this.selecting?void 0:"handled"}return"handled"}}UpdateScale(t){this.scale=t}};var vr=class{canvas;cache={};constructor(){typeof document<"u"&&(this.canvas=document.createElement("canvas"))}Flush(){this.cache={}}Get(e,t=10){let r=e+";"+t,i=this.cache[r];return i||(i=this.Measure(e,t),this.cache[r]=i,i)}Measure(e,t){let r=e.match(/([\d.]+)((?:%|em))/);if(r){let u=r[1]+r[2],m=Number(r[1])*t;r[2]==="%"&&(m/=100),e=e.replace(u,m+"px")}let i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("invalid context");i.font=e;let n=i.measureText("MMM"),a=Math.ceil(n.width);if(this.canvas.setAttribute("width",a.toString()),this.canvas.setAttribute("height",a.toString()),i=this.canvas.getContext("2d",{willReadFrequently:!0}),!i)throw new Error("invalid context");i.font=e,i.textAlign="center",i.textBaseline="alphabetic",i.fillStyle="#000";let s=Math.round(a*2/3),o=Math.round(a/2);i.clearRect(0,0,a,a);for(let u=32;u<=126;u++){let m=String.fromCharCode(u);i.fillText(m,o,s)}let l=i.getImageData(0,0,this.canvas.width,this.canvas.height).data,d=Math.floor(this.GetFirstIndex(l)/a),h=Math.floor(this.GetLastIndex(l)/a);return{ascender:s-d,descender:h-s,block:h-d+1,paren:i.measureText("(").width,hash:i.measureText("##").width-i.measureText("#").width}}GetFirstIndex(e){for(let t=3,r=e.length;t<r;t+=4)if(e[t]>0)return(t-3)/4;return e.length}GetLastIndex(e){for(let t=e.length-1;t>=3;t-=4)if(e[t]>0)return t/4;return 0}},It=new vr;var wr="bottom",di=/webkit/i.test(typeof navigator>"u"?"":navigator?.userAgent||"")?1:0,zt=class{constructor(e,t,r,i,n){this.theme=e;this.layout=t;this.model=r;this.view=i;this.options=n;this.buffer_canvas=t.buffer_canvas,this.buffer_canvas.width=this.buffer_canvas_size.width,this.buffer_canvas.height=this.buffer_canvas_size.height;let a=this.buffer_canvas.getContext("2d",{alpha:!1});if(a){let s=this.layout.dpr;this.buffer_context=a,this.buffer_context.setTransform(s,0,0,s,0,0),this.buffer_context.textAlign="left",this.buffer_context.textBaseline=wr}}cell_edge_buffer=4;overflow_areas=[];buffer_canvas;buffer_context;buffer_canvas_size={width:256,height:256};FlushOverflows(){this.view.active_sheet.cells.IterateAll(t=>{t.renderer_data?.overflowed&&(t.renderer_data=void 0,t.render_clean[this.view.view_index]=!1)});for(let t of this.overflow_areas)t.tile.dirty=!0;this.overflow_areas=[]}MeasureText(e,t){let r=this.layout.grid_tiles[0][0].getContext("2d",{alpha:!1});if(!r)throw new Error("invalid context");return t&&(r.font=t),r.measureText(e)}EnsureBuffer(e=0,t=0,r=0){let i=this.layout.dpr;if(e=e*i,t=t*i,r=r*i,e>this.buffer_canvas_size.width||t>this.buffer_canvas_size.height){this.buffer_canvas_size.width=Math.max(Math.ceil(e/256)*256,this.buffer_canvas_size.width),this.buffer_canvas_size.height=Math.max(Math.ceil(t/256)*256,this.buffer_canvas_size.height),this.buffer_canvas.width=this.buffer_canvas_size.width,this.buffer_canvas.height=this.buffer_canvas_size.height;let n=this.buffer_canvas.getContext("2d",{alpha:!1});n&&(this.buffer_context=n,this.buffer_context.textAlign="left",this.buffer_context.textBaseline=wr)}this.buffer_context.setTransform(i,0,0,i,r,0)}OverflowDirty(e=!1){let t=[];for(let r of this.overflow_areas){let i=r.area.start.row,n=e;if(!n)for(let a=r.area.start.column;!n&&a<=r.area.end.column;a++){let s=this.view.active_sheet.cells.GetCell({row:i,column:a},!1);n=!!(s&&!s.render_clean[this.view.view_index])}if(n){for(let a=r.area.start.column;a<=r.area.end.column;a++){let s=this.view.active_sheet.cells.GetCell({row:i,column:a},!1);s&&(s.render_clean[this.view.view_index]=!1,s.renderer_data&&s.renderer_data.overflowed&&(s.renderer_data=void 0))}r.tile.dirty=!0}else t.push(r)}this.overflow_areas=t}RenderCorner(){let t=this.layout.corner_canvas.getContext("2d",{alpha:!1});if(!t)throw new Error("invalid context");let r=It.Get(V.Font(this.theme.headers||{},this.layout.scale)),i=this.layout.dpr,n=this.layout.header_offset,a=n.x;for(let o=0;o<this.view.active_sheet.freeze.columns;o++)a+=this.layout.ColumnWidth(o);let s=n.y;for(let o=0;o<this.view.active_sheet.freeze.rows;o++)s+=this.layout.RowHeight(o);t.setTransform(i,0,0,i,0,0),t.fillStyle=this.theme.headers?.fill?T(this.theme,this.theme.headers.fill):"",t.fillRect(0,0,a,n.y),t.fillRect(0,0,n.x,s),t.strokeStyle=this.theme.headers_grid_color||"",t.beginPath(),t.moveTo(n.x-.5,0),t.lineTo(n.x-.5,n.y),t.moveTo(0,n.y-.5),t.lineTo(n.x,n.y-.5),t.stroke(),!(!this.view.active_sheet.freeze.columns&&!this.view.active_sheet.freeze.rows)&&(t.strokeStyle=this.theme.grid_color||"",t.beginPath(),s!==n.y&&(t.moveTo(n.x-.5,n.y),t.lineTo(n.x-.5,s)),a!==n.x&&(t.moveTo(n.x,n.y-.5),t.lineTo(a,n.y-.5)),t.stroke(),t.strokeStyle=this.theme.headers_grid_color||"",t.textAlign="center",t.textBaseline="middle",t.font=V.Font(this.theme.headers||{},this.layout.scale),t.fillStyle=T(this.theme,this.theme.headers?.text),this.view.active_sheet.freeze.rows&&this.layout.header_offset.x>1&&(t.setTransform(i,0,0,i,0,0),t.translate(0,n.y),t.beginPath(),t.moveTo(0,0-.5),t.lineTo(n.x,0-.5),t.stroke(),this.RenderRowLabels(t,0,this.view.active_sheet.freeze.rows-1,r.block)),this.view.active_sheet.freeze.columns&&this.layout.header_offset.y>1&&(t.setTransform(i,0,0,i,0,0),t.translate(n.x,0),t.beginPath(),t.moveTo(0-.5,0),t.lineTo(0-.5,n.y),t.stroke(),this.RenderColumnLabels(t,0,this.view.active_sheet.freeze.columns-1)))}RenderColumnLabels(e,t,r){let i=this.layout.header_offset.y;if(!(i<=1)){for(e.fillStyle=T(this.theme,this.theme.headers?.text,0),e.beginPath();t<=r;t++){let n=this.layout.ColumnWidth(t),a=y.ColumnToLabel(t),s=e.measureText(a);n>s.width&&e.fillText(a,n/2,i/2+1),e.moveTo(n-.5,0),e.lineTo(n-.5,i),e.translate(n,0)}e.stroke()}}RenderRowLabels(e,t,r,i){let n=this.layout.header_offset.x;if(!(n<=1)){for(e.fillStyle=T(this.theme,this.theme.headers?.text,0),e.beginPath();t<=r;t++){let a=this.layout.RowHeight(t);a>=i*1.2&&e.fillText(`${t+1}`,n/2,a/2+1),e.moveTo(0,a-.5),e.lineTo(n,a-.5),e.translate(0,a)}e.stroke()}}RenderHeaders(e,t=!1){let r=this.layout.dpr,i=this.layout.header_offset,n=It.Get(V.Font(this.theme.headers||{},this.layout.scale));for(let a=e.start.column;a<=e.end.column;a++){let s=this.layout.column_header_tiles[a];if(s.dirty||t){let o=s.getContext("2d",{alpha:!1});if(!o)continue;o.setTransform(r,0,0,r,0,0),o.textAlign="center",o.textBaseline="middle",o.font=V.Font(this.theme.headers||{},this.layout.scale),o.fillStyle=this.theme.headers?.fill?T(this.theme,this.theme.headers.fill):"",o.fillRect(0,0,s.logical_size.width,this.layout.header_offset.y),o.strokeStyle=this.theme.headers_grid_color||"",o.beginPath(),o.moveTo(0,i.y-.5),o.lineTo(s.logical_size.width,i.y-.5),o.stroke(),o.strokeStyle=this.theme.headers_grid_color||"",this.RenderColumnLabels(o,s.first_cell.column,s.last_cell.column),s.dirty=!1}}for(let a=e.start.row;a<=e.end.row;a++){let s=this.layout.row_header_tiles[a];if(s.dirty||t){let o=s.getContext("2d",{alpha:!1});if(!o)continue;o.fillStyle=this.theme.headers?.fill?T(this.theme,this.theme.headers.fill):"",o.setTransform(r,0,0,r,0,0),o.textAlign="center",o.textBaseline="middle",o.font=V.Font(this.theme.headers||{},this.layout.scale),o.fillRect(0,0,this.layout.header_offset.x,s.logical_size.height),o.strokeStyle=this.theme.headers_grid_color||"",o.beginPath(),o.moveTo(i.x-.5,0),o.lineTo(i.x-.5,s.logical_size.height),o.stroke(),o.strokeStyle=this.theme.headers_grid_color||"",this.RenderRowLabels(o,s.first_cell.row,s.last_cell.row,n.block),s.dirty=!1}}(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.RenderCorner()}CopyToAdjacent(e,t,r,i,n,a,s){let o=this.layout.AdjacentTile(e,i,r);if(!o)return;let l=n,d=a;r>0?l=n-(e.pixel_end.x-e.pixel_start.x)*t:r<0&&(l=n+(o.pixel_end.x-o.pixel_start.x)*t),i>0&&(d=a-(e.pixel_end.y-e.pixel_start.y)*t);let h=o.getContext("2d",{alpha:!1});h&&(h.setTransform(t,0,0,t,l,d),h.drawImage(this.buffer_canvas,0,0,(s.width||0)*t,(s.height||0)*t,s.left||0,0,s.width||0,s.height||0))}Render(e){let t=e.getContext("2d",{alpha:!1});if(!t)return;t.textBaseline=wr;let r=this.layout.dpr;t.setTransform(r,0,0,r,0,0);let i=0,n=0;for(let o=e.first_cell.column;o<=e.last_cell.column;o++){let l=this.layout.ColumnWidth(o);if(l){n=0;for(let d=e.first_cell.row;d<=e.last_cell.row;d++){let h=this.layout.RowHeight(d);if(h){t.setTransform(r,0,0,r,i,n);let u=this.view.active_sheet.CellData({row:d,column:o});if(e.needs_full_repaint||!u.render_clean[this.view.view_index]){let m=this.RenderCell(e,u,t,{row:d,column:o},l,h,e.pixel_start.x+i,e.pixel_start.y+n);m.tile_overflow_right&&this.CopyToAdjacent(e,r,1,0,i,n,m),m.tile_overflow_left&&this.CopyToAdjacent(e,r,-1,0,i,n,m),m.tile_overflow_bottom&&this.CopyToAdjacent(e,r,0,1,i,n,m)}}n+=h*r}i+=l*r}}if(!this.view.active_sheet.freeze.rows&&!this.view.active_sheet.freeze.columns)return;let a=0,s=0;if(e.first_cell.row<=this.view.active_sheet.freeze.rows-1)for(let o=e.first_cell.row;o<this.view.active_sheet.freeze.rows&&o<=e.last_cell.row;o++)a+=this.layout.RowHeight(o);if(e.first_cell.column<=this.view.active_sheet.freeze.columns-1)for(let o=e.first_cell.column;o<this.view.active_sheet.freeze.columns&&o<=e.last_cell.column;o++)s+=this.layout.ColumnWidth(o);if(a){let o=this.layout.frozen_row_tiles[e.tile_position.column];if(!o)throw new Error("can't find matching header tile");let l=o.getContext("2d",{alpha:!0});if(!l)throw new Error("header context failed");l.setTransform(r,0,0,r,0,0),l.drawImage(e,0,0,e.logical_size.width*r,a*r,0,0,e.logical_size.width,a)}if(s){let o=this.layout.frozen_column_tiles[e.tile_position.row];if(!o)throw new Error("can't find matching header tile");let l=o.getContext("2d",{alpha:!0});if(!l)throw new Error("header context failed");l.setTransform(r,0,0,r,0,0),l.drawImage(e,0,0,s*r,e.logical_size.height*r,0,0,s,e.logical_size.height)}if(s&&a){let o=this.layout.corner_canvas.getContext("2d",{alpha:"false"});if(!o)throw new Error("corner context failed");o.setTransform(r,0,0,r,this.layout.header_offset.x*r,this.layout.header_offset.y*r),o.drawImage(e,0,0,s*r,a*r,0,0,s,a)}}PrepText(e,t,r,i){let n=[],a=r.style||{},s,o=0,l,d=r.editing?"":r.formatted;if(Array.isArray(d)){for(let h of d){if(h.flag===6){l=h.text;continue}let u=e.measureText(h.text).width,m={width:u,text:h.text,hidden:h.flag===1};n.push(m),h.flag===2?s=m:o+=u}if(s){let h=s.text,u=s.width,m=i-o-2*this.cell_edge_buffer;if(s.width=Math.max(0,m),m>0){let f=Math.floor(m/u);for(let p=1;p<f;p++)s.text+=h;o=i-2*this.cell_edge_buffer}else s.text=""}return{strings:[n],format:l,width:o}}else if(d){r.type===2&&d[0]==="'"&&(d=d.slice(1));let h;this.options.markdown?h=Te.instance.Parse(d):(h=Te.instance.Dummy(d),e.font=t.base);let u=0,m=i-2*this.cell_edge_buffer,f=[];if(a.wrap)for(let p of h){for(let b=1;b<p.length;b++){let v=p[b].text.match(/^(\s+)/);v&&(p[b-1].text+=v[1],p[b].text=p[b].text.replace(/^\s+/,""))}let g=[];for(let b of p){this.options.markdown&&(b.strong&&b.emphasis?e.font=t.strong_emphasis:b.strong?e.font=t.strong:b.emphasis?e.font=t.emphasis:e.font=t.base);let v=b.text.match(/\S+\s*/g);if(v&&v.length)for(let _ of v){let w=e.measureText(_.trim()).width,x=e.measureText(_).width;g.push({part:b,text:_,trimmed:w,width:x})}}for(;g.length;){let b=g.shift(),v=[b],_=b.trimmed;for(;_<m&&g.length;){let w=g[0],x=_-b.trimmed+b.width+w.trimmed;if(x>=m)break;b=w,v.push(w),_=x,g.shift(),u=Math.max(u,_)}b.text=b.text.trim(),b.width=b.trimmed,u=Math.max(u,b.width),f.push(v.map(w=>({...w.part,hidden:!1,width:w.width,text:w.text})))}}else for(let p of h){let g=[],b=0;for(let v of p){this.options.markdown&&(v.strong&&v.emphasis?e.font=t.strong_emphasis:v.strong?e.font=t.strong:v.emphasis?e.font=t.emphasis:e.font=t.base);let _=e.measureText(v.text).width;b+=_,g.push({...v,hidden:!1,width:_})}u=Math.max(u,b),f.push(g)}return{strings:f,width:u}}return{strings:[[{text:"",hidden:!1,width:0}]],width:0}}ResolveColors(e){let t={...e};return t.text={text:T(this.theme,e.text,1)},t}RenderCellBorders(e,t,r,i=0,n=0,a=0,s=0){let o=this.view.active_sheet.SurroundingStyle(e,this.theme.table),l=T(this.theme,o[8].fill);l&&(t.fillStyle=l,t.fillRect(i+0,n-1,a,1)),l=T(this.theme,o[4].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n,1,s)),l=T(this.theme,r.fill),l&&(t.fillStyle=l,t.fillRect(i-1,n-1,a+1,s+1)),l=T(this.theme,o[6].fill),l&&(t.fillStyle=l,t.fillRect(i+a-1,n-1,1,s+1)),l=T(this.theme,o[2].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n+s-1,a+1,1)),o[6].border_top&&!o[6].border_left&&(t.fillStyle=T(this.theme,o[6].border_top_fill,1),t.fillRect(i+a-1,n-2+o[6].border_top,1,1)),o[9].border_left&&(t.fillStyle=T(this.theme,o[9].border_left_fill,1),t.fillRect(i+a-1,n-1,1,1)),o[9].border_bottom&&(t.fillStyle=T(this.theme,o[9].border_bottom_fill,1),t.fillRect(i+a-1,n-2+o[9].border_bottom,1,1)),o[4].border_top&&!o[4].border_right&&(t.fillStyle=T(this.theme,o[4].border_right_fill,1),t.fillRect(i-1,n-2+o[4].border_top,1,1)),o[7].border_right&&(t.fillStyle=T(this.theme,o[7].border_right_fill,1),t.fillRect(i-1,n-1,1,1)),o[7].border_bottom&&(t.fillStyle=T(this.theme,o[7].border_bottom_fill,1),t.fillRect(i-1,n-2+o[7].border_bottom,1,1)),o[6].border_bottom&&!o[6].border_left&&(t.fillStyle=T(this.theme,o[6].border_bottom_fill,1),t.fillRect(i+a-1,n+s-o[6].border_bottom,1,1)),o[3].border_left&&(t.fillStyle=T(this.theme,o[3].border_left_fill,1),t.fillRect(i+a-1,n+s-1,1,1)),o[3].border_top&&(t.fillStyle=T(this.theme,o[3].border_top_fill,1),t.fillRect(i+a-1,n+s-o[3].border_top,1,1)),o[4].border_bottom&&!o[4].border_right&&(t.fillStyle=T(this.theme,o[4].border_bottom_fill,1),t.fillRect(i-1,n+s-o[4].border_bottom,1,1)),o[1].border_right&&(t.fillStyle=T(this.theme,o[1].border_right_fill,1),t.fillRect(i-1,n+s-1,1,1)),o[1].border_top&&(t.fillStyle=T(this.theme,o[1].border_top_fill,1),t.fillRect(i-1,n+s-o[1].border_top,1,1)),o[8].border_bottom&&(t.fillStyle=T(this.theme,o[8].border_bottom_fill,1),o[8].border_bottom===2&&(t.fillRect(i-1,n-2,a+1,1),t.fillRect(i-1,n-0,a+1,1),t.fillStyle=T(this.theme,o[8].fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n-1,a+1,1)),o[4].border_right&&(t.fillStyle=T(this.theme,o[4].border_right_fill,1),t.fillRect(i-1,n-1,1,s+1)),o[6].border_left&&(t.fillStyle=T(this.theme,o[4].border_left_fill,1),t.fillRect(i+a-1,n-1,1,s+1)),o[2].border_top&&(t.fillStyle=T(this.theme,o[2].border_top_fill,1),o[2].border_top===2&&(t.fillRect(i-1,n+s-2,a+1,1),t.fillRect(i-1,n+s-0,a+1,1),t.fillStyle=T(this.theme,o[2].fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n+s-1,a+1,1)),r.border_top&&(t.fillStyle=T(this.theme,r.border_top_fill,1),r.border_top===2&&(t.fillRect(i-1,n-2,a+1,1),t.fillRect(i-1,n+0,a+1,1),t.fillStyle=T(this.theme,r.fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n-1,a+1,1)),r.border_left&&(t.fillStyle=T(this.theme,r.border_left_fill,1),t.fillRect(i-1,n-1,1,s+1)),r.border_right&&(t.fillStyle=T(this.theme,r.border_right_fill,1),t.fillRect(i+a-1,n-1,1,s+1)),r.border_bottom&&(t.fillStyle=T(this.theme,r.border_bottom_fill,1),r.border_bottom===2&&(t.fillRect(i-1,n+s-2,a+1,1),t.fillRect(i-1,n+s+0,a+1,1),t.fillStyle=T(this.theme,r.fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n+s-1,a+1,1))}PaintBackgroundImage(e,t,r,i,n,a,s=0,o=0,l=0){if(!t.width||!t.height)return;let d=(this.layout.scale||1)*this.layout.dpr,h=r/d%t.width,u=i/d%t.height,m=n/d,f=a/d,p=h+m>t.width,g=u+f>t.height;p&&e.drawImage(t,h-t.width,u,m,f,s,o,n-l,a-l),g&&e.drawImage(t,h,u-t.height,m,f,s,o,n-l,a-l),p&&g&&e.drawImage(t,h-t.width,u-t.height,m,f,s,o,n-l,a-l),e.drawImage(t,h,u,m,f,s,o,n-l,a-l)}RenderCellBackground(e,t,r,i,n,a,s=0,o=0){if(r.fillStyle=this.theme.grid_color,r.fillRect(0,0,n,a),this.view.active_sheet.image)this.PaintBackgroundImage(r,this.view.active_sheet.image,s,o,n,a,0,0,1);else{let l=T(this.theme,i.fill);l?(r.fillStyle=l,r.fillRect(0,0,n-1,a-1)):(r.fillStyle=pe(this.theme,this.theme.grid_cell?.fill)||"#fff",r.fillRect(0,0,n-1,a-1))}this.RenderCellBorders(t,r,i,0,0,n,a),e&&(r.fillStyle=this.theme.note_marker_color,r.beginPath(),r.moveTo(n-2,1),r.lineTo(n-2-8,1),r.lineTo(n-2,1+8),r.lineTo(n-2,1),r.fill())}RenderCell(e,t,r,i,n,a,s=0,o=0){let l={},d=!t.render_clean[this.view.view_index];if(t.render_clean[this.view.view_index]=!0,e.needs_full_repaint&&t.renderer_data?.overflowed)return{};let h=t.style?{...t.style}:{};if(t.table&&(h=this.view.active_sheet.CellStyleData(i,t.table.theme||this.theme.table)||{}),t.merge_area)if(i.row===t.merge_area.start.row&&i.column===t.merge_area.start.column){for(let C=t.merge_area.start.column+1;C<=t.merge_area.end.column;C++)n+=this.layout.ColumnWidth(C);for(let C=t.merge_area.start.row+1;C<=t.merge_area.end.row;C++)a+=this.layout.RowHeight(C);if(t.merge_area.count>1){let C=this.view.active_sheet.CellStyleData(t.merge_area.end);C&&(h.border_bottom=C.border_bottom,h.border_right=C.border_right,h.border_bottom_fill=C.border_bottom_fill,h.border_right_fill=C.border_right_fill)}t.merge_area.end.column>e.last_cell.column&&(l.tile_overflow_right=!0),t.merge_area.end.row>e.last_cell.row&&(l.tile_overflow_bottom=!0),(l.tile_overflow_bottom||l.tile_overflow_right)&&this.overflow_areas.push({tile:e,head:{...i},area:new y(t.merge_area.start,t.merge_area.end)})}else return{};let u=!!t.hyperlink;if(t.render_function){this.RenderCellBackground(!!t.note,i,r,h,n,a),r.strokeStyle=r.fillStyle=T(this.theme,h.text,1);let C=this.ResolveColors(h);if(t.render_function.call(void 0,{width:n,height:a,context:r,cell:t,style:C,scale:this.layout.scale||1}).handled)return l}let m={base:V.Font(h,this.layout.scale),strong:V.Font({...h,bold:!0},this.layout.scale),emphasis:V.Font({...h,italic:!0},this.layout.scale),strong_emphasis:V.Font({...h,bold:!0,italic:!0},this.layout.scale)};if(r.font=m.base,d||!t.renderer_data||t.renderer_data.width!==n||t.renderer_data.height!==a){let C=this.PrepText(r,m,t,n);t.renderer_data={text_data:C,width:n,height:a}}let f=t.renderer_data.text_data,p=f.width>n-2*this.cell_edge_buffer,g=n,b=0,v=!1,_=t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7||t.type===9||t.calculated_type===9,w=h.horizontal_align;w||(w=_?"right":"left");let x=[];if(p)if(t.type!==3&&t.calculated_type!==3&&!h.wrap&&!t.merge_area){let K=f.width-n+this.cell_edge_buffer,ne=0,ae=0;w==="center"?ne=ae=K/2:w==="right"?ne=K:ae=K;let J=i.column,X=i.column;for(;ae>0&&J<this.layout.last_column;){J++;let q={row:i.row,column:J},z=this.view.active_sheet.CellData(q),Z=this.layout.ColumnWidth(J);if(ae-=Z,z&&!z.type&&!z.calculated_type)x.push({address:q,cell:z,grid:new H(g,0,Z,a),background:new H(g-1,0,Z,a-1),border:new H(g,0,Z,a)}),g+=Z,z.render_clean[this.view.view_index]=!0,z.renderer_data={overflowed:!0};else{v=!0;break}}for(J>e.last_cell.column&&(l.tile_overflow_right=!0);ne>0&&X>=1;){X--;let q={row:i.row,column:X},z=this.view.active_sheet.CellData(q),Z=this.layout.ColumnWidth(X);if(ne-=Z,z&&!z.type&&!z.calculated_type)b-=Z,x.push({address:q,cell:z,grid:new H(b,0,Z,a),background:new H(b,0,Z,a-1),border:new H(b,0,Z,a)});else{v=!0;break}}X<e.first_cell.column&&(l.tile_overflow_left=!0),this.overflow_areas.push({head:{...i},tile:e,area:new y({row:i.row,column:X},{row:i.row,column:J})})}else v=!_;let A=!1,k=r;(l.tile_overflow_bottom||l.tile_overflow_left||l.tile_overflow_right)&&(A=!0,l.width=g-b,l.height=a,l.left=b,this.EnsureBuffer(l.width+1,a+1,-b),r=this.buffer_context,r.font=m.base),this.RenderCellBackground(!!t.note,i,r,h,n,a,s,o);for(let C of x)C.cell.style?.fill&&(C.cell.style.fill.text||C.cell.style.fill.theme||C.cell.style.fill.theme===0)&&!this.options.grid_over_background?(r.fillStyle=pe(this.theme,C.cell.style.fill),r.fillRect(C.grid.left,C.grid.top,C.grid.width,C.grid.height)):(r.fillStyle=this.theme.grid_color||"",r.fillRect(C.grid.left,C.grid.top,C.grid.width,C.grid.height),this.view.active_sheet.image?this.PaintBackgroundImage(r,this.view.active_sheet.image,s+C.background.left,o+C.background.top,C.background.width,C.background.height,C.background.left,C.background.top,0):(r.fillStyle=this.theme.grid_cell?.fill?pe(this.theme,this.theme.grid_cell.fill):"",r.fillRect(C.background.left,C.background.top,C.background.width,C.background.height))),C.cell.style&&this.RenderCellBorders(C.address,r,C.cell.style,C.border.left,C.border.top,C.border.width,C.border.height);let S=It.Get(m.base,this.theme.grid_cell?.font_size?.value);r.lineWidth=1,r.strokeStyle=r.fillStyle=f.format?f.format:T(this.theme,h.text,1),r.beginPath();let M=this.cell_edge_buffer,U=1.25,W=f.strings.length,me=W*S.block*U;v=(v||me>=a)&&!A,v&&(r.save(),r.beginPath(),r.moveTo(b+1.5,0),r.lineTo(b+1.5,a),r.lineTo(g-1.5,a),r.lineTo(g-1.5,0),r.clip()),r.beginPath();let ie=Math.round(a-2-S.block*U*(W-1)+di);switch(h.vertical_align){case"top":ie=Math.round(S.block*U)+1;break;case"middle":ie=Math.round((a-me)/2+S.block*U);break}if((t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7)&&p){let C=Math.floor((n-2*this.cell_edge_buffer)/S.hash),K="";for(let ae=0;ae<C;ae++)K+="#";let ne=r.measureText(K).width;w==="center"?M=Math.round((n-ne)/2):w==="right"&&(M=n-this.cell_edge_buffer-ne),r.fillText(K,M,ie)}else{let C=ie,K=0;for(let ne of f.strings){let ae=0;for(let z of ne)ae+=z.width;w==="center"?M=Math.round((n-ae)/2):w==="right"&&(M=n-this.cell_edge_buffer-ae);let J=Math.floor(C+1.5-S.descender-di)+.5,X=Math.floor(C-S.descender-S.ascender/2)+.5,q=M;for(let z of ne)z.strong&&z.emphasis?r.font=m.strong_emphasis:z.strong?r.font=m.strong:z.emphasis?r.font=m.emphasis:r.font=m.base,z.hidden||(z.text&&r.fillText(z.text,q,C),h.underline&&(r.moveTo(q,J),r.lineTo(q+z.width,J)),(h.strike||z.strike)&&(r.moveTo(q,X),r.lineTo(q+z.width,X)),u&&(z.left=q,z.top=C-S.block,z.height=S.block)),q+=z.width;K++,C=Math.round(ie+K*S.block*U)}}if(r.stroke(),v)r.restore();else if(A){let C=this.layout.dpr;k.drawImage(this.buffer_canvas,0,0,(l.width||0)*C,a*C,b,0,l.width||0,a)}return l}};var Dt=class extends Me{constructor(t,r,i,n,a){super(r,i,a);this.options=n;let s=F.GetInstance(t.ownerDocument),o=t.querySelector(".treb-formula-bar");o.removeAttribute("hidden"),this.address_label_container=o.querySelector(".treb-address-label"),this.address_label=this.address_label_container.firstElementChild,this.InitAddressLabel(),this.options.insert_function_button&&(this.button=s.Create("button","formula-button",o),this.button.addEventListener("click",()=>{let h=this.active_editor&&this.active_editor.node.textContent||"";this.Publish({type:"formula-button",formula:h})})),this.container_node=t.querySelector(".treb-editor-container");let l=this.container_node.firstElementChild,d={node:l};this.active_editor=d,this.nodes=[d],l&&this.RegisterListener(d,"input",h=>{h.isTrusted&&(this.UpdateText(d),this.UpdateColors())}),this.active_editor.node.spellcheck=!1,this.RegisterListener(d,"focusin",()=>{if(!this.active_editor)return;let h=this.active_editor.node.textContent||"";h[0]==="{"&&h[h.length-1]==="}"&&(h=h.substring(1,h.length-1),this.active_editor.node.textContent=h,this.active_editor.formatted_text=void 0),this.autocomplete?.ResetBlock(),this.UpdateText(this.active_editor),this.UpdateColors(),this.Publish([{type:"start-editing",editor:"formula-bar"},{type:"update",text:h,cell:this.active_cell,dependencies:this.composite_dependencies}]),this.focused_=!0}),this.RegisterListener(d,"focusout",h=>{this.selecting&&console.info("focusout, but selecting..."),this.autocomplete?.Hide(),this.Publish([{type:"stop-editing"}]),this.focused_=!1,this.active_editor&&(this.active_editor.node.spellcheck=!1)}),this.RegisterListener(d,"keydown",this.FormulaKeyDown.bind(this)),this.RegisterListener(d,"keyup",this.FormulaKeyUp.bind(this)),this.options.expand_formula_button&&(this.expand_button=s.Create("button","expand-button",o,{events:{click:h=>{h.stopPropagation(),h.preventDefault(),this.active_editor&&(this.active_editor.node.scrollTop=0),o.hasAttribute("expanded")?o.removeAttribute("expanded"):o.setAttribute("expanded","")}}}))}focused_=!1;get focused(){return this.focused_}address_label_container;address_label;button;expand_button;label_update_timer=0;get formula(){return this.active_editor&&this.active_editor.node.textContent||""}set formula(t){this.active_editor&&(this.active_editor.node.textContent=t,this.active_editor.formatted_text=void 0)}get label(){return this.address_label?.textContent||""}set label(t){t.trim().length?(this.address_label.textContent=t,this.label_update_timer||(this.label_update_timer=requestAnimationFrame(()=>{this.label_update_timer=0,this.address_label.scrollWidth>this.address_label.offsetWidth?this.address_label.setAttribute("title",t):this.address_label.removeAttribute("title")}))):(this.address_label.innerHTML=" ",this.address_label.removeAttribute("title"))}set editable(t){!this.active_editor||!this.container_node||(t?(this.active_editor.node.setAttribute("contenteditable","true"),this.container_node.removeAttribute("locked")):(this.active_editor.node.removeAttribute("contenteditable"),this.container_node.setAttribute("locked","")))}IsElement(t){return t===this.active_editor?.node}InitAddressLabel(){this.address_label.contentEditable="true",this.address_label.spellcheck=!1,this.address_label.addEventListener("focusin",t=>{let r=this.address_label.ownerDocument;requestAnimationFrame(()=>{let i=r.defaultView.getSelection(),n=r.createRange();n.selectNodeContents(this.address_label),i?.removeAllRanges(),i?.addRange(n)})}),this.address_label.addEventListener("keydown",t=>{if(!t.isComposing)switch(t.key){case"Enter":t.stopPropagation(),t.preventDefault(),this.Publish({type:"address-label-event",text:this.address_label.textContent||void 0});break;case"Esc":case"Escape":t.stopPropagation(),t.preventDefault(),this.Publish({type:"address-label-event"});break}})}GetTextContent(t){let r=t.childNodes,i=[];for(let n=0;n<r.length;n++){let a=r[n];switch(a.nodeType){case Node.ELEMENT_NODE:i.push(...this.GetTextContent(a)),a instanceof Element&&a.tagName==="DIV"&&i.push(`
|
|
5
|
+
`}IsDelimeter(e){return e==="*"||e==="_"||e==="~"}Consolidate(e){let t=[],r={},i=[],n={type:"text",text:""};for(let a of e)if(a.type==="newline")n.text.length&&i.push(n),n={...r,text:"",type:"text"},t.push(i),i=[];else switch((!!r.strong!=!!a.strong||!!r.emphasis!=!!a.emphasis||!!r.strike!=!!a.strike)&&(r.strong=!!a.strong,r.emphasis=!!a.emphasis,r.strike=!!a.strike,n.text.length&&i.push(n),n={...r,text:"",type:"text"}),a.type){case"text":case"whitespace":n.text+=a.text;break;case"delimeter":for(let s=0;s<a.length;s++)n.text+=a.char;break}return n.text.length&&i.push(n),i.length&&t.push(i),t}ApplyFormatting(e,t){let r=0,i=e.length;for(r=0;r<i;r++){let n=e[r];if(n.type==="delimeter"){if(t&&n.right_flanking&&t.char===n.char&&n.length>0)return{index:r,token:n};if(n.left_flanking){let a=this.ApplyFormatting(e.slice(r+1),n);if(a.token){let s=Math.min(a.token.length,n.length),o=n.char==="~",l=!o&&!!(s%2),d=!o&&s>=2;for(let h=r+1;h<=r+a.index;h++)e[h].strong=!!e[h].strong||d,e[h].emphasis=!!e[h].emphasis||l,e[h].strike=!!e[h].strike||o;a.token.length-=s,n.length-=s,n.length>0?r--:r+=a.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,i=0,n=!1,a="";for(i=0;i<r;i++){let s=e[i];if(this.IsWhitespace(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(this.IsWhitespace(l))o+=l,i++;else break}t.push({type:"whitespace",text:o}),n=!1,a=""}else if(this.IsNewline(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(this.IsNewline(l))o+=l,i++;else break}t.push({type:"newline",text:o}),n=!1,a=""}else if(n)a+=s,n=!1;else if(this.IsDelimeter(s)){a&&t.push({type:"text",text:a});let o=s;for(;;){let l=e[i+1];if(l===s)o+=l,i++;else break}t.push({type:"delimeter",text:o,char:s,length:o.length}),n=!1,a=""}else s==="\\"?n=!0:a+=s}return a&&t.push({type:"text",text:a}),t}};var ve=class{date_format=!1;string_format=!1;fraction_format=!1;twelve_hour=!1;fraction_denominator=0;fraction_integer=!0;fraction_align=0;fraction_denominator_digits=0;integer_min_digits=0;decimal_min_digits=0;decimal_max_digits=0;grouping=!1;has_number_format=!1;prefix=[{text:""}];suffix=[{text:""}];scaling=0;percent=!1;exponential=!1;has_asterisk=!1};var qr=42,Kr=95,fr=63,vt=48,ei=46,pr=44,ti=37,br=34,Ke=35,ri=59,wt=92,ii=64,gn=91,_n=93,ni=69,ai=101,yn=72,vn=104,wn=77,xn=109,Cn=83,An=115,Sn=68,kn=100,Tn=89,Rn=121,En=65,Mn=97;var xt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new ve;static preserve_formatting_characters=!1;static decimal_mark=ei;static group_separator=pr;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new ve,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new ve,this.sections=[this.current_section];this.char_index<this.characters.length;)this.ConsumeChar();return this.sections}static ConsumeString(){let e="";for(this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case wt:this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index+1<this.characters.length&&(e+=this.pattern[++this.char_index]);break;case br:return this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated string")}static ConsumeFormatting(){let e="";for(++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case wt:throw new Error("invalid escape character in formatting block");case _n:return this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated format")}static ScanFractionFormat(){let e=/^([#?]+ +){0,1}([#?]+)\/([#?0-9]+)(?:$|[^#?0-9])/,r=this.pattern.substr(this.char_index).match(e);if(!r)return!1;let i=(r[1]||"").length+r[2].length+r[3].length+1;this.current_section.fraction_format=!0,this.current_section.fraction_integer=!!r[1];let n=Number(r[3]);return isNaN(n)||(this.current_section.fraction_denominator=n),this.current_section.decimal_max_digits=this.current_section.fraction_denominator_digits=r[3].length,this.char_index+=i,this.current_section.has_number_format=!0,!0}static ConsumeNumberFormat(){let e=0;for(this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case this.group_separator:{let r=!1;for(let i=this.char_index+1;!r&&i<this.characters.length;i++){let n=this.characters[i];if(n===this.decimal_mark||n===Ke||n===vt)r=!0;else if(n!==pr)break}if(r){if(e===1)throw new Error("invalid grouping in decimal part");this.current_section.grouping=!0}else this.current_section.scaling=(this.current_section.scaling||1)*1e3}break;case this.decimal_mark:if(e===1)throw new Error("too many decimal marks");e=1;break;case Ke:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case vt:e===1?(this.current_section.decimal_max_digits++,this.current_section.decimal_min_digits=this.current_section.decimal_max_digits):this.current_section.integer_min_digits++;break;default:return}}static AppendCharAsText(e=!0){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=this.pattern[this.char_index]:this.current_section.prefix[this.current_section.prefix.length-1].text+=this.pattern[this.char_index],e&&this.char_index++}static AppendString(e){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=e:this.current_section.prefix[this.current_section.prefix.length-1].text+=e}static AppendTextPart(e){this.current_section.has_number_format?(this.current_section.suffix.push(e),this.current_section.suffix.push({text:""})):(this.current_section.prefix.push(e),this.current_section.prefix.push({text:""}))}static ConsumeChar(){let e=this.characters[this.char_index];if(!((e===fr||e===Ke)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case ri:this.char_index++,this.current_section=new ve,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case ii:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case vt:case Ke:case ei:case pr:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case gn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case br:this.AppendString(this.ConsumeString());break;case fr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Kr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case qr:if(this.current_section.has_asterisk)throw new Error("we don't support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case ai:case ni:this.current_section.percent||this.current_section.exponential||this.current_section.string_format?this.AppendCharAsText():(this.current_section.exponential=!0,this.char_index++);break;case ti:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case wt:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}static ParseDatePattern(){for(this.date_pattern=!0;this.date_pattern&&this.char_index<this.pattern.length;)this.DatePatternConsumeChar();if(this.date_pattern){this.date_pattern=!1;for(let e of this.sections)for(let t of e.prefix)t.flag&&t.flag&7&&(this.date_pattern=!0)}return this.date_pattern&&(this.sections[0].date_format=!0,this.sections[0].prefix.forEach((e,t)=>{if(e.flag===3&&(e.text==="mm"||e.text==="m")){if(t)for(let r=t-1;r;r--){let i=this.sections[0].prefix[r];if(i.flag===3){/h/i.test(i.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}if(t<this.sections[0].prefix.length-1)for(let r=t+1;r<this.sections[0].prefix.length;r++){let i=this.sections[0].prefix[r];if(i.flag===3){/s/i.test(i.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}}})),this.date_pattern}static ConsumeDatePart(){let e=this.pattern[this.char_index++],t=e.toLowerCase(),r={text:e,flag:3};for(;this.pattern[this.char_index]&&this.pattern[this.char_index].toLowerCase()===t;)r.text+=this.pattern[this.char_index++];if(t==="s"&&this.pattern[this.char_index]===".")for(r.text+=this.pattern[this.char_index++];this.pattern[this.char_index]==="0";)r.text+=this.pattern[this.char_index++];return r}static ConsumeAMPM(){let e=this.pattern.substr(this.char_index,5);if(e==="am/pm"||e==="AM/PM")return this.char_index+=5,this.sections[0].twelve_hour=!0,{text:e,flag:3};if(e=this.pattern.substr(this.char_index,3),e==="a/p"||e==="A/P")return this.char_index+=3,this.sections[0].twelve_hour=!0,{text:e,flag:3}}static DatePatternConsumeChar(){switch(this.characters[this.char_index]){case ri:this.char_index=this.characters.length;break;case vt:case Ke:case ai:case ni:case ti:case ii:this.date_pattern=!1;break;case yn:case vn:case wn:case xn:case Cn:case An:case Sn:case kn:case Tn:case Rn:this.AppendTextPart(this.ConsumeDatePart());break;case En:case Mn:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case br:this.AppendString(this.ConsumeString());break;case fr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Kr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case qr:if(this.current_section.has_asterisk)throw new Error("we don't support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case wt:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}};var De=c=>(c>=60&&c--,new Date(-22090752e5+864e5*c)),He=(c,e=!0)=>{if(e){let t=new Date(c),r=new Date;r.setUTCMilliseconds(t.getUTCMilliseconds()),r.setUTCSeconds(t.getUTCSeconds()),r.setUTCMinutes(t.getUTCMinutes()),r.setUTCHours(t.getHours()),r.setUTCDate(t.getDate()),r.setUTCMonth(t.getMonth()),r.setUTCFullYear(t.getFullYear()),c=r.getTime()}return c=(c+22090752e5)/864e5,c>=60&&c++,c},te=class c{static grouping_regexp=/\d{1,3}(?=(\d{3})+(?!\d))/g;static fraction_limits=[9,99,999,9999];static imaginary_character="\u{1D456}";static minus_character="-";magic_decimal=!1;transform_value;_pattern="";sections;decimal_zero_regexp=[];cloned=[];get pattern(){return this._pattern}get date_format(){return this.sections[0]&&this.sections[0].date_format}constructor(e){if(this._pattern=e,this.sections=xt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new ve),this.sections[1]||(this.sections[1]={...this.sections[0]},this.sections[1].prefix=JSON.parse(JSON.stringify(this.sections[1].prefix)),this.sections[1].suffix=JSON.parse(JSON.stringify(this.sections[1].suffix)),this.sections[1].prefix.push({text:"-"}),this.cloned[1]=!0),this.sections[2]||(this.sections[2]={...this.sections[0]},this.cloned[2]=!0),!this.sections[3]){for(let t of this.sections[0].prefix)if(t.flag===5){this.sections[3]={...this.sections[0]},this.sections[3].string_format=!0,this.cloned[3]=!0;break}}this.decimal_zero_regexp=this.sections.map(t=>{if(t.decimal_max_digits>t.decimal_min_digits)return new RegExp(`0{1,${t.decimal_max_digits-t.decimal_min_digits}}(?:$|e)`)})}static FormatPartsAsText(e,t=0){let r=-1,i=e.map((n,a)=>{switch(n.flag){case 2:return r=a,n.text;case 1:return n.text.replace(/./g," ");case 6:return"";default:return n.text}});if(r>=0&&t){let n=i.reduce((s,o,l)=>l===r?s:s+o.length,0),a="";for(let s=0;s<t-n;s++)a+=i[r];i[r]=a}return i.join("")}SetDecimal(e){for(let t of this.sections)t.fraction_format||(t.decimal_min_digits=e,t.decimal_max_digits=e)}IncreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.min(e.fraction_denominator_digits+1,4)):(e.decimal_min_digits++,e.decimal_max_digits=e.decimal_min_digits)})}DecreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.max(e.fraction_denominator_digits-1,1)):(e.decimal_min_digits=Math.max(0,e.decimal_min_digits-1),e.decimal_max_digits=e.decimal_min_digits)})}AddGrouping(){this.sections.forEach(e=>{e.grouping=!0})}RemoveGrouping(){this.sections.forEach(e=>{e.grouping=!1})}ToggleGrouping(){let e=!this.sections[0].grouping;this.sections.forEach(t=>{t.grouping=e})}toString(){return this.sections[0].date_format?this._pattern:this.sections.filter((e,t)=>!this.cloned[t]).map(e=>{let t="",r=0;if(e.fraction_format){e.fraction_integer&&(t+="? ");let i="";for(let n=0;n<e.fraction_denominator_digits;n++)i+="#";t+=i,t+="/",e.fraction_denominator?t+=e.fraction_denominator:t+=i}else if(e.has_number_format){for(r=0;r<e.integer_min_digits;r++)t+="0";if(e.grouping&&(t.length<4&&(t=("####"+t).slice(-4)),t=t.replace(/[\d#]{1,3}(?=([\d#]{3})+(?![\d#]))/g,"$&,")),e.decimal_max_digits||e.decimal_min_digits){for(t+=".",r=0;r<e.decimal_min_digits;r++)t+="0";for(;r<e.decimal_max_digits;r++)t+="#"}if(e.scaling){let i=Math.log10(e.scaling)/3;for(r=0;r<i;r++)t+=","}e.exponential&&(t+="e")}return e.prefix.map(i=>i.flag===1?i.text==="0"?"?":"_"+i.text:i.flag===2?"*"+i.text:i.flag===6?"["+i.text+"]":i.text).join("")+t+e.suffix.map(i=>i.flag===1?i.text==="0"?"?":"_"+i.text:i.flag===2?"*"+i.text:i.text).join("")}).join(";")}FormatDimensionedQuantity(e){if(this.transform_value){let r=this.transform_value(e);if(Kt(r))e=r;else return typeof r=="string"?r:this.FormatParts(r)}let t=this.FormatParts(e.value||0);return e.unit&&t.push({text:" "},{text:e.unit}),t}FormatComplex(e){let t=[],r=[],i=!1,n=!!e.imaginary;n&&(t=this.FormatParts(e.imaginary),n=t.some(o=>/[1-9]/.test(o.text)),t.length===1&&this.sections[0].integer_min_digits<=1&&t[0].text==="1"?(t[0].text="",i=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",i=!0));let a=!!e.real;a&&(r=this.FormatParts(e.real),a=r.some(o=>/[1-9]/.test(o.text)));let s=[];if(a||!a&&!n){if(s.push(...r),n){let o=Math.abs(e.imaginary);s.push({text:e.imaginary<0?` ${c.minus_character} `:" + "});let l=i?[]:this.FormatParts(Math.abs(e.imaginary));s.push(...l,{text:c.imaginary_character})}}else n&&s.push(...t,{text:c.imaginary_character});return s}FormatParts(e){if(typeof e!="number"&&!this.sections[3])return[{text:e.toString()}];let{parts:t,section:r}=this.BaseFormat(e),i=[];if(r.date_format||r.string_format)for(let n of t)typeof n=="string"?i.push({text:n}):i.push(n);else this.magic_decimal&&t[1]===""&&t.splice(1,1),i=[...r.prefix.map(n=>({...n})),{text:r.has_number_format?t.join(D.decimal_separator):""},...r.suffix.map(n=>({...n}))];for(let n=1;n<i.length;n++)i[n].flag===i[n-1].flag&&(i[n].text=i[n-1].text+i[n].text,i[n-1].text="");return i.filter(n=>n.text)}Format(e,t=0){return c.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=De(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=12)),{parts:r.prefix.map(a=>{if(a.flag===4)return a.text==="mm"?{text:this.ZeroPad(t.getUTCMinutes().toString(),2)}:{text:this.ZeroPad(t.getUTCMinutes().toString(),1)};if(a.flag===3){switch(a.text.toLowerCase()){case"am/pm":case"a/p":{let o=a.text.split("/");return{text:t.getUTCHours()>12?o[1]:o[0]}}case"mmmmm":return{text:D.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return a.text==="MMMM"?{text:D.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:D.date_components.long_months[t.getUTCMonth()]};case"mmm":return a.text==="MMM"?{text:D.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:D.date_components.short_months[t.getUTCMonth()]};case"mm":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),2)};case"m":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),1)};case"ddddd":case"dddd":return a.text==="DDDDD"||a.text==="DDDD"?{text:D.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:D.date_components.long_days[t.getUTCDay()]};case"ddd":return a.text==="DDD"?{text:D.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:D.date_components.short_days[t.getUTCDay()]};case"dd":return{text:this.ZeroPad(t.getUTCDate().toString(),2)};case"d":return{text:this.ZeroPad(t.getUTCDate().toString(),1)};case"yyyy":case"yyy":return{text:t.getUTCFullYear().toString()};case"yy":case"y":return{text:this.ZeroPad((t.getUTCFullYear()%100).toString(),2)};case"hh":return{text:this.ZeroPad(i.toString(),2)};case"h":return{text:this.ZeroPad(i.toString(),1)};case"ss":return{text:this.ZeroPad(t.getUTCSeconds().toString(),2)};case"s":return{text:this.ZeroPad(t.getUTCSeconds().toString(),1)}}let s=a.text.match(/^(s+)\.(0+)$/);if(s)return{text:this.ZeroPad(t.getUTCSeconds().toString(),s[1].length)+D.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(s[2].length).substr(2)}}return{...a}}),section:r}}StringFormat(e,t){let r=[];for(let i of t.prefix)i.flag===5?r.push({text:e}):r.push({...i});return{parts:r,section:t}}Round2(e,t){let r=Math.pow(10,t);return Math.round(r*e)/r}FormatFraction(e,t){t.percent&&(e*=100);let r={denominator:1,numerator:Math.round(e),error:Math.abs(Math.round(e)-e)};if(t.fraction_denominator)r.denominator=t.fraction_denominator,r.numerator=Math.round(e*r.denominator);else if(r.error){let n=c.fraction_limits[t.fraction_denominator_digits-1]||c.fraction_limits[0];for(let a=2;a<=n;a++){let s=Math.round(e*a),o=Math.abs(s/a-e);if(o<r.error&&(r={numerator:s,denominator:a,error:o},!o))break}}let i=[];if(t.fraction_integer){let n=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(n||!r.numerator)&&(i.push(n.toString()),r.numerator&&i.push(" "))}else r.numerator||i.push("0");return r.numerator&&(i.push(r.numerator.toString()),i.push("/"),i.push(r.denominator.toString())),i.join("")}BaseFormat(e){if(this.sections[0].date_format)return this.DateFormat(Number(e));if(typeof e!="number")return this.StringFormat(e.toString(),this.sections[3]);let t=this.sections[0],r=this.decimal_zero_regexp[0];e<0&&(t=this.sections[1]);let i=t.percent?t.decimal_max_digits+2:t.decimal_max_digits,n=Math.pow(10,-i)/2,a=Math.abs(e);if(a<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(a/=t.scaling,a<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2])),t.string_format)return this.StringFormat(e.toString(),t);let s="";if(t.fraction_format)return{parts:[this.FormatFraction(a,t)],section:t};t.exponential?s=a.toExponential(t.decimal_max_digits):(t.percent&&(a*=100),s=this.Round2(a,t.decimal_max_digits).toFixed(t.decimal_max_digits)),r&&(s=s.replace(r,""));let o=s.split(".");for(;o[0].length<t.integer_min_digits;)o[0]=("0000000000000000"+o[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&o[0]==="0"&&(o[0]=""),t.grouping&&(o[0]=o[0].replace(c.grouping_regexp,"$&"+D.grouping_separator)),{parts:o,section:t}}};var I=class{static cache={};static complex_general;static symbolc_name_map={};static base_formats={Accounting:"_(#,##0.00_);(#,##0.00);-???",Number:"0.00",Integer:"0",Percent:"0.00%",General:"0.######",Fraction:"# ?/?",Dollar:"$* _(#,##0.00_);$* (#,##0.00);$* -???",Exponential:"0.000e","Short Date":"mm/dd/yy","Long Date":"dddd, mmm d yyyy",Timestamp:"mm-dd-yy hh:mm:ss"};static aliases={Scientific:"Exponential",Percentage:"Percent",Currency:"Dollar"};static Get(e,t=!1){if(t&&e==="General")return this.complex_general;let r=this.symbolc_name_map[e.toLowerCase()],i=this.cache[r||e];return i||(i=new te(e),this.cache[e]=i),i}static Equals(e,t){if(e===t)return!0;let r=this.Get(e),i=this.Get(t);return r.pattern===i.pattern}static Translate(e){let t=this.symbolc_name_map[e.toLowerCase()];return t?this.cache[t].toString():e}static SymbolicName(e){for(let t of Object.keys(this.base_formats))if(e===this.base_formats[t])return t;return null}static InitCache(){for(let e of Object.keys(this.base_formats))this.cache[e]=new te(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new te("0.###"),this.complex_general.magic_decimal=!0;for(let e of Object.keys(this.aliases))this.cache[e]=this.cache[this.aliases[e]],this.symbolc_name_map[e.toLowerCase()]=e}};I.InitCache();var si=new Date().getUTCFullYear(),_r=class{compare_day;compare_month;TestDate(e){let t=Date.parse(e);if(isNaN(t))return!1;let r=new Date(t),n=e.replace(/[\d\-\\/,.\s]+/g," ").toLocaleLowerCase().split(/\s+/).map(o=>o.trim()).filter(o=>!!o);if(!n.length)return t;if(!this.compare_month){this.compare_month={};for(let o=0;o<12;o++)this.compare_month[D.date_components.long_months[o].toLocaleLowerCase().replace(/\./,"")]=o,this.compare_month[D.date_components.short_months[o].toLocaleLowerCase().replace(/\./,"")]=o}if(!this.compare_day){this.compare_day={};for(let o=0;o<7;o++)this.compare_day[D.date_components.long_days[o].toLocaleLowerCase().replace(/\./,"")]=o,this.compare_day[D.date_components.short_days[o].toLocaleLowerCase().replace(/\./,"")]=o}let a=!1,s=!1;for(let o of n){let l=!1;for(let[d,h]of Object.entries(this.compare_month))if(o===d){if(a||r.getUTCMonth()!==h)return!1;l=!0,a=!0}if(!l){for(let[d,h]of Object.entries(this.compare_day))if(o===d){if(s||r.getUTCDay()!==h)return!1;l=!0,s=!0}}if(!l)return!1}return s&&!a?!1:t}TryParse(e=""){let t={};if(e[0]==="'")return{value:e,type:2};if(e==="")return{value:e,type:2};if(e==="NaN")return{value:NaN,type:3,hints:{Nan:!0}};let r=e.trim(),i=r.match(/^[$](.*?)$/);i&&(r=i[1],t.Currency=!0);let n=r.match(/^\((.*?)\)$/);n&&(r=n[1],t.Parens=!0);let a=r.match(/^(.*?)%\s*$/);a&&(r=a[1],t.Percent=!0),D.decimal_separator==="."?/,/.test(r)&&(r=r.replace(/,/g,""),t.Grouping=!0):(r=r.replace(/(\d)\s+/g,"$1"),r=r.replace(/\./g,""),r=r.replace(/,/,"."));let s=Number(r);if(s===null||isNaN(s)){let o=e.toLowerCase();if(o==="false")return{value:!1,type:4};if(o==="true")return{value:!0,type:4};let l=this.TestDate(e);if(l!==!1&&!isNaN(l)){let d=new Date(l),h=d.getUTCFullYear();if(h>=si-200&&h<=si+200)return t={Date:!0},(d.getHours()||d.getMinutes()||d.getSeconds())&&(t.Time=!0),{value:He(l),type:3,hints:t}}return{value:e,type:2}}if(n&&(s=-s),a){let o=s<0?-1:1,l=(o*s).toString().split(".");l[0]=("00"+l[0]).replace(/(\d\d)$/,".$1"),s=Number(l.join(""))*o}return/e/.test(e)&&(t.Exponential=!0),{value:s,type:3,hints:t}}},be=new _r;var Ct=class{constructor(e,t,r={x:0,y:0},i){this.theme=t;this.offset=r;let n=F.GetInstance(i.ownerDocument);this.g=n.SVG("g"),this.g.setAttribute("transform",`translate(${r.x}, ${r.y})`),this.outline=n.SVG("rect","outline"),e?(this.g.setAttribute("class","selection primary-selection"),this.fill=n.SVG("path","fill"),this.nub=n.SVG("rect","nub"),this.g.appendChild(this.fill),this.g.appendChild(this.outline),this.g.appendChild(this.nub)):(this.g.setAttribute("class","selection alternate-selection"),this.fill=n.SVG("rect","fill"),this.g.appendChild(this.fill),this.g.appendChild(this.outline))}g;outline;fill;nub;Offset(e){this.g.setAttribute("transform",`translate(${e.x}, ${e.y})`)}Show(e=!0){this.g.style.display=e?"block":"none"}SetOutline(e,t=!1){this.outline.setAttribute("x",(e.left-1).toString()),this.outline.setAttribute("y",(e.top-1).toString()),this.outline.setAttribute("width",(e.width+1).toString()),this.outline.setAttribute("height",(e.height+1).toString()),t&&this.fill&&(this.fill.setAttribute("x",e.left.toString()),this.fill.setAttribute("y",e.top.toString()),this.fill.setAttribute("width",e.width.toString()),this.fill.setAttribute("height",e.height.toString()))}SetFill(e,t){if(!this.fill)return;let r=[];r.push("M"+e.left+" "+e.top),r.push("L"+e.left+" "+e.bottom),r.push("L"+e.right+" "+e.bottom),r.push("L"+e.right+" "+e.top),r.push("Z"),r.push("M"+t.left+" "+t.top),r.push("L"+t.right+" "+t.top),r.push("L"+t.right+" "+t.bottom),r.push("L"+t.left+" "+t.bottom),r.push("Z"),this.fill.setAttribute("d",r.join(" "))}SetNub(e){this.nub&&(this.nub.setAttribute("x",(e.left+e.width-4).toString()),this.nub.setAttribute("y",(e.top+e.height-4).toString()),this.nub.setAttribute("width","7"),this.nub.setAttribute("height","7"))}};var Ne=class{constructor(e,t,r){this.theme=e;this.container=t;this.orientation=r;let i=F.GetInstance(t.ownerDocument);this.g=i.SVG("g","treb-header-overlay"),this.overlay=i.SVG("rect","treb-overlay"),this.highlight=i.SVG("rect","treb-highlight"),this.g.style.display="none",this.g.appendChild(this.highlight),this.g.appendChild(this.overlay),t.appendChild(this.g)}g;overlay;highlight;Remove(){this.container.removeChild(this.g)}Hide(){this.g.style.display="none"}Show(e,t,r,i){this.overlay.setAttribute("x",e.toString()),this.overlay.setAttribute("y",t.toString()),this.overlay.setAttribute("width",r.toString()),this.overlay.setAttribute("height",i.toString()),this.orientation===0?(this.highlight.setAttribute("x",e.toString()),this.highlight.setAttribute("y",(t+i-2).toString()),this.highlight.setAttribute("width",r.toString()),this.highlight.setAttribute("height","2")):(this.highlight.setAttribute("x",(e+r-2).toString()),this.highlight.setAttribute("y",t.toString()),this.highlight.setAttribute("width","2"),this.highlight.setAttribute("height",i.toString())),this.g.style.display="block"}};var At=class{constructor(e,t,r,i,n,a){this.theme=e;this.layout=t;this.model=r;this.view=i;this.primary_selection=n;this.additional_selections=a}nub_rectangle=new H(-1,-1,0,0);cached_additional_selections="";grid_selections=[];row_header_selections=[];column_header_selections=[];corner_selections=[];row_overlay;column_overlay;corner_row_overlay;corner_column_overlay;Initialize(){this.row_overlay=new Ne(this.theme,this.layout.row_header_selection,0),this.column_overlay=new Ne(this.theme,this.layout.column_header_selection,1),this.corner_row_overlay=new Ne(this.theme,this.layout.corner_selection,0),this.corner_column_overlay=new Ne(this.theme,this.layout.corner_selection,1)}RenderSelections(e=!0,t=!0){let r=this.primary_selection.empty;e||(this.primary_selection.empty=!0);let i=[this.primary_selection].concat(this.additional_selections);this.RenderSelectionGroup(i,this.layout.grid_selection,void 0,void 0,this.grid_selections,void 0,t);let n=new H(-1,-1,0,0);if(!this.primary_selection.empty){let o=this.view.active_sheet.RealArea(this.primary_selection.area);n=this.layout.CellAddressToRectangle(o.start).Combine(this.layout.CellAddressToRectangle(o.end))}if(!this.primary_selection.empty&&this.layout.header_offset.y>2?(this.row_overlay.Show(n.left,0,n.width,this.layout.header_offset.y),this.corner_row_overlay.Show(n.left+this.layout.header_offset.x,0,n.width,this.layout.header_offset.y)):(this.row_overlay.Hide(),this.corner_row_overlay.Hide()),!this.primary_selection.empty&&this.layout.header_offset.x>2?(this.column_overlay.Show(0,n.top,this.layout.header_offset.x,n.height),this.corner_column_overlay.Show(0,n.top+this.layout.header_offset.y,this.layout.header_offset.x,n.height)):(this.column_overlay.Hide(),this.corner_column_overlay.Hide()),!this.view.active_sheet.freeze.columns&&!this.view.active_sheet.freeze.rows){this.primary_selection.empty=r;return}let a=[],s=[];if(this.primary_selection.empty)a.push(!1),s.push(!1);else{let o=this.primary_selection.area.start;a.push(o.row<=this.view.active_sheet.freeze.rows||o.row===1/0),s.push(o.column<=this.view.active_sheet.freeze.columns||o.column===1/0)}for(let{area:o}of this.additional_selections)a.push(o.start.row<=this.view.active_sheet.freeze.rows||o.start.row===1/0),s.push(o.start.column<=this.view.active_sheet.freeze.columns||o.start.column===1/0);this.view.active_sheet.freeze.rows&&this.RenderSelectionGroup(i,this.layout.row_header_selection,a,void 0,this.row_header_selections,{x:0,y:this.layout.header_offset.y}),this.view.active_sheet.freeze.columns&&this.RenderSelectionGroup(i,this.layout.column_header_selection,s,void 0,this.column_header_selections,{x:this.layout.header_offset.x,y:0}),this.view.active_sheet.freeze.rows&&this.view.active_sheet.freeze.columns&&this.RenderSelectionGroup(i,this.layout.corner_selection,s,a,this.corner_selections,{...this.layout.header_offset}),this.primary_selection.empty=r}RenderSelectionGroup(e,t,r,i,n,a,s=!0){for(let o=0;o<e.length;o++)if((!e[o].area.start.sheet_id||e[o].area.start.sheet_id===this.view.active_sheet.id)&&!e[o].empty&&(!r||r[o])&&(!i||i[o])){if(s||!e[o].rendered){let d=this.EnsureGridSelectionBlock(t,n,o,a);this.RenderSVGSelection(e[o],d,o)}}else n[o]&&n[o].Show(!1);for(let o=e.length;o<n.length;o++)n[o]&&n[o].Show(!1)}EnsureGridSelectionBlock(e,t,r,i){let n=t[r];if(!n)if(n=new Ct(!r,this.theme,void 0,e),t[r]=n,r){let a=e.querySelector(".alternate-selections");a||(a=this.layout.DOM.SVG("g","alternate-selections"),e.appendChild(a)),a?.appendChild(n.g)}else e.appendChild(n.g);return i&&n.Offset(i),n}ClampEnd(e){return{row:Math.min(e.row,this.view.active_sheet.rows-1),column:Math.min(e.column,this.view.active_sheet.columns-1)}}RenderSVGSelection(e,t,r=0){let i=this.view.active_sheet.RealArea(e.area,!0),n=this.layout.CellAddressToRectangle(i.start);if(i.count>1)n=n.Combine(this.layout.CellAddressToRectangle(i.end));else if(r){let a=this.view.active_sheet.CellData(e.target);a.merge_area&&(n=this.layout.CellAddressToRectangle(a.merge_area.start),n=n.Combine(this.layout.CellAddressToRectangle(a.merge_area.end)))}if(r||(this.nub_rectangle=new H(n.left+n.width-6,n.top+n.height-6,11,11)),n.top===0&&this.layout.header_offset.y<=1&&(n.top=1,n.height-=1),n.left===0&&this.layout.header_offset.x<=1&&(n.left=1,n.width-=1),n.height<=0||n.height<=0){t.Show(!1);return}if(t.SetOutline(n,!!r),r)e.rendered=!0;else{let a=this.layout.CellAddressToRectangle(e.target),s=this.view.active_sheet.CellData(e.target);s.merge_area&&(a=this.layout.CellAddressToRectangle(s.merge_area.start),a=a.Combine(this.layout.CellAddressToRectangle(s.merge_area.end))),t.SetFill(a,n),t.SetNub(n)}t.Show()}};function ge(c,e=[],t,r){typeof e=="string"&&(e=[e]);let i,n=s=>{s.stopPropagation(),s.preventDefault(),i(),r&&r(s)},a=s=>{if(s.stopPropagation(),s.preventDefault(),!s.buttons){i(),r&&r(s);return}t&&t(s)};i=()=>{c.style.display="none",c.removeEventListener("mousemove",a),c.removeEventListener("mouseup",n);for(let s of e)c.classList.remove(s)};for(let s of e)c.classList.add(s);c.style.display="block",t&&c.addEventListener("mousemove",a),r&&c.addEventListener("mouseup",n)}var St=class extends oe{constructor(t){super();this.container=t;this.format=I.Get("0.0");let r=F.GetInstance(t.ownerDocument);this.input=r.Create("input","treb-scale-input",t,{events:{keypress:n=>{switch(n.key){case"ArrowUp":case"ArrowDown":n.stopPropagation(),n.preventDefault(),console.info("mark?");break}},keydown:n=>{switch(n.key){case"Enter":this.input.blur();break;case"ArrowUp":this.Tick(-1);break;case"ArrowDown":this.Tick(1);break;case"Escape":this.input.value=this.format.Format(this.scale)+"%",this.input.blur();break;default:return}n.stopPropagation(),n.preventDefault()},focusin:()=>this.input.select(),change:()=>{let n=this.input.value;n=n.replace(/%/g,"");let a=be.TryParse(n);a.type===3?this.UpdateScale(Number(a.value),!0):this.input.value=this.format.Format(this.scale)+"%"}}});let i=r.Div("treb-slider-container",t);this.slider=r.Create("input",void 0,i,{attrs:{type:"range",min:"50",max:"200",value:"100",step:"2.5"},events:{input:()=>this.UpdateScale(Number(this.slider.value),!0)}}),t.addEventListener("wheel",n=>{n.stopPropagation(),n.preventDefault(),this.Tick(n.deltaY)})}input;slider;scale=0;format;timeout=0;Tick(t){let r=Math.round(this.scale/2.5)*2.5;t>0?this.UpdateScale(r-2.5,!0,!0):t<0&&this.UpdateScale(r+2.5,!0,!0)}UpdateScale(t,r=!1,i=!1){t=Math.max(50,Math.min(200,t)),t!==this.scale&&(this.scale=t,this.input.value=this.format.Format(t)+"%",this.slider.value=t.toFixed(1),r&&(this.timeout||(this.timeout=requestAnimationFrame(()=>{this.timeout=0,this.Publish({type:"scale",value:this.scale/100,keep_focus:i})}))))}};var kt=class extends oe{constructor(t,r,i,n,a){super();this.layout=t;this.model=r;this.view=i;this.options=n;if(this.DOM=F.GetInstance(a.ownerDocument),this.container=a.querySelector(".treb-spreadsheet-footer"),!this.container)throw new Error("missing container for tab bar");if(n.tab_bar!=="auto"&&this.container.removeAttribute("hidden"),this.tab_container=this.container.querySelector(".treb-spreadsheet-tabs"),this.container.addEventListener("click",s=>{let o=s.target?.dataset.command;if(o)switch(s.stopPropagation(),s.preventDefault(),o){case"add-tab":this.Publish({type:"add-sheet"});break;case"delete-tab":this.Publish({type:"delete-sheet"});break;default:console.info("unhandled command",o)}}),this.options.stats&&(this.stats_panel=this.container.querySelector(".treb-stats-panel")),this.options.scale_control){let s=this.container.querySelector(".treb-scale-control");this.scale_control=new St(s),this.scale_control.Subscribe(o=>{this.Publish(o)}),this.UpdateScale(this.options.initial_scale||1)}}tab_container;scale_control;stats_panel;dragging=!1;double_click_data={};_visible=!1;get visible(){return this._visible}set stats_data(t){if(this.stats_panel){this.stats_panel.innerText="";for(let r of t)this.DOM.Create("span","treb-stats-label",this.stats_panel,{text:r.label}),this.DOM.Create("span","treb-stats-value",this.stats_panel,{text:r.value})}}container;DOM;IsDoubleClick(t,r=300){return this.double_click_data.index===t?(clearTimeout(this.double_click_data.timeout),this.double_click_data.index=void 0,this.double_click_data.timeout=void 0,!0):(this.double_click_data.timeout&&clearTimeout(this.double_click_data.timeout),this.double_click_data.index=t,this.double_click_data.timeout=window.setTimeout(()=>{this.double_click_data.index=void 0,this.double_click_data.timeout=void 0},r),!1)}Hide(){this.Show(!1)}Show(t=!0){this.container&&(this._visible=t,t?this.container.removeAttribute("hidden"):this.container.setAttribute("hidden",""))}SetActive(t,r){r?t.setAttribute("selected",""):t.removeAttribute("selected")}UpdateScale(t){this.scale_control?.UpdateScale(t*100)}DoubleClickTab(t,r,i){if(r.contentEditable="true",this.DOM.doc){let n=this.DOM.GetSelection();if(n){n.removeAllRanges();let a=this.DOM.doc.createRange();a.selectNodeContents(r),n.addRange(a)}}r.addEventListener("keydown",n=>{switch(n.key){case"Enter":this.Publish({type:"rename-sheet",name:r.innerText.trim(),sheet:i});break;case"Escape":r.innerText=i.name,this.Publish({type:"cancel"}),this.Update();break;default:return}n.stopPropagation(),n.preventDefault()}),r.addEventListener("focusout",()=>{let n=r.innerText.trim();n!==i.name?this.Publish({type:"rename-sheet",name:n,sheet:i}):this.Update()}),r.focus()}MouseDownTab(t,r,i,n,a){if(t.stopPropagation(),t.preventDefault(),this.IsDoubleClick(n))return;this.Publish({type:"activate-sheet",sheet:i});let s=a.map(p=>p.getBoundingClientRect()),o=n*2-1,l=s[0].left,d=s[s.length-1].right,h=s[0].top,u=s[0].bottom,m=-1,f=(s.length-1)*2+1;for(let p of a)this.SetActive(p,p===r);this.dragging=!0,ge(this.layout.mask,[],p=>{let[g,b]=[p.clientX,p.clientY];if(b>h&&b<u){let v=o;if(g<l)v=m;else if(g>d)v=f;else for(let _=0;_<s.length;_++){let w=s[_];if(g>=w.left&&g<=w.right){_!==n&&(g>=w.left+w.width/2?v=_*2+1:v=_*2-1);break}}v!==o&&(o=v,r.style.order=o.toString(),s=a.map(_=>_.getBoundingClientRect()))}},()=>{let p=n,g=(o+1)/2;this.dragging=!1;for(let b=0;b<this.model.sheets.length;b++)this.model.sheets.list[b].visible||(p>=b&&p++,g>=b&&g++);p===g||p===0&&g<=0||p===a.length-1&&g>=a.length-1||this.Publish({type:"reorder-sheet",index:p,move_before:g})})}Update(){if(this.dragging)return;if(this.options.tab_bar==="auto"){if(this.model.sheets.list.reduce((i,n)=>n.visible?i+1:i,0)<=1){this.Show(!1);return}this.Show(!0)}if(!this.tab_container)return;this.tab_container.innerText="";let t=[];for(let r of this.model.sheets.list){if(!r.visible)continue;let i=t.length,n=this.DOM.Create("li");n.setAttribute("tabindex","0"),n.style.order=(i*2).toString(),n.role="tab",this.SetActive(n,r===this.view.active_sheet);let a=o=>this.MouseDownTab(o,n,r,i,t),s=o=>{n.removeEventListener("mousedown",a),n.removeEventListener("dblclick",s),this.DoubleClickTab(o,n,r)};n.textContent=r.name,n.addEventListener("dblclick",s),n.addEventListener("mousedown",a),this.tab_container.appendChild(n),t.push(n)}}};var oi=()=>({target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0});var In=100,li={move_with_cells:!0,resize_with_cells:!0,movable:!0,resizable:!0,removable:!0,selectable:!0},Ee=class{data={...li};get key(){return this.key_}rect;scaled_rect;temp={};view=[];dirty;key_=In++;constructor(e={}){this.data={...li,...JSON.parse(JSON.stringify(e))},e.rect&&(this.rect=H.Create(e.rect))}toJSON(){return{...this.data,rect:this.rect}}};var zn=100,ci=60,Y=class c{static base_id=100;static default_sheet_name="Sheet1";default_style_properties;annotations=[];freeze={rows:0,columns:0};visible=!0;default_column_width=100;default_row_height=25;cells=new dt;selection=oi();scroll_offset={x:0,y:0};name=c.default_sheet_name;background_image;_image=void 0;flush_conditional_formats=!1;get image(){return this._image}conditional_formats=[];outline;id_;row_height_=[];column_width_=[];row_headers=[];column_headers=[];row_header_width=100;column_header_height=25;style_map=[];style_json_map=[];sheet_style={};row_styles={};column_styles={};row_pattern=[];cell_style=[];conditional_format_cache=[];conditional_format_checklist=[];get header_offset(){return{x:this.row_header_width,y:this.column_header_height}}get rows(){return this.cells.rows}get columns(){return this.cells.columns}get id(){return this.id_}set id(e){this.id_=e,this.id>=c.base_id&&(c.base_id=this.id+1)}constructor(e){this.default_style_properties=e,this.default_column_width=zn,this.row_header_width=ci,this.UpdateDefaultRowHeight(),this.id_=c.base_id++}static Reset(){this.base_id=100}static Blank(e,t,r=30,i=20){let n=new c(e);return t&&(n.name=t),r=Math.max(r,1),i=Math.max(i,1),n.cells.EnsureCell({row:r-1,column:i-1}),n}static UpdateStyle(e){if(typeof e.horizontal_align=="number"){let t=["","left","center","right"];e.horizontal_align=t[e.horizontal_align]||void 0}if(typeof e.vertical_align=="number"){let t=["","top","bottom","middle"];e.vertical_align=t[e.vertical_align]||void 0}}static FromJSON(e,t,r){let i=typeof e=="string"?JSON.parse(e):e,n=(l,d)=>{Object.keys(d).forEach(h=>{let u=Number(h)||0;l[u]=d[h]})};r||(r=new c(t)),i.default_column_width&&(r.default_column_width=i.default_column_width),i.default_row_height&&(r.default_row_height=i.default_row_height),i.conditional_formats&&(r.conditional_formats=i.conditional_formats),i.id&&(r.id=i.id),i.name&&(r.name=i.name),i.background_image&&(r.background_image=i.background_image);let a=l=>{let d=l;this.UpdateStyle(d),(d.font_size_value||d.font_size_unit)&&(d.font_size={unit:d.font_size_unit||"pt",value:d.font_size_value||10},d.font_size_unit=void 0,d.font_size_value=void 0),d.font_bold&&(d.bold=!0,d.font_bold=void 0),d.font_italic&&(d.italic=!0,d.font_italic=void 0),d.font_underline&&(d.underline=!0,d.font_underline=void 0),d.font_strike&&(d.strike=!0,d.font_strike=void 0),d.text_color&&(d.text_color!=="none"&&(d.text={text:d.text_color}),d.text_color=void 0),d.background&&(d.background!=="none"&&(d.fill={text:d.background}),d.background=void 0),d.border_top_color&&(d.border_top_color!=="none"&&(d.border_top_fill={text:d.border_top_color}),d.border_top_color=void 0),d.border_left_color&&(d.border_left_color!=="none"&&(d.border_left_fill={text:d.border_left_color}),d.border_left_color=void 0),d.border_bottom_color&&(d.border_bottom_color!=="none"&&(d.border_bottom_fill={text:d.border_bottom_color}),d.border_bottom_color=void 0),d.border_right_color&&(d.border_right_color!=="none"&&(d.border_right_fill={text:d.border_right_color}),d.border_right_color=void 0)},s=i.styles||i.cell_style_refs||[];for(let l of s)a(l);if(r.cell_style=[],s&&(i.cell_styles||[]).forEach(l=>{typeof l.ref=="number"&&(l.style=JSON.parse(JSON.stringify(s[l.ref])))}),r.cells.FromJSON(i.data),i.rows&&r.cells.EnsureRow(i.rows-1),i.columns&&r.cells.EnsureColumn(i.columns-1),i.data)if(je(i.data))for(let l of i.data)l.style_ref&&(r.cell_style[l.column]||(r.cell_style[l.column]=[]),r.cell_style[l.column][l.row]=JSON.parse(JSON.stringify(s[l.style_ref])));else if(rr(i.data))for(let l of i.data){let d=l.row;for(let h of l.cells){let u=h.column;h.style_ref&&(r.cell_style[u]||(r.cell_style[u]=[]),r.cell_style[u][d]=JSON.parse(JSON.stringify(s[h.style_ref])))}}else for(let l of i.data){let d=l.column;for(let h of l.cells){let u=h.row;h.style_ref&&(r.cell_style[d]||(r.cell_style[d]=[]),r.cell_style[d][u]=JSON.parse(JSON.stringify(s[h.style_ref])))}}r.freeze.rows=0,r.freeze.columns=0,i.freeze&&(r.freeze.rows=i.freeze.rows||0,r.freeze.columns=i.freeze.columns||0),r.scroll_offset=i.scroll?{...i.scroll}:{x:0,y:0};for(let l of i.cell_styles||[])if(l.style&&(r.cell_style[l.column]||(r.cell_style[l.column]=[]),r.cell_style[l.column][l.row]=l.style,l.rows))for(let d=1;d<l.rows;d++)r.cell_style[l.column][l.row+d]=JSON.parse(JSON.stringify(l.style));r.sheet_style=i.sheet_style||{},r.column_styles={},r.row_styles={};let o=(l,d)=>{for(let h of Object.keys(l)){let u=Number(h),m=l[u];if(typeof m=="number"){let f=s[m];f&&(d[u]=JSON.parse(JSON.stringify(f)),a(d[u]))}else m&&(d[u]=m,a(d[u]))}};o(i.row_style,r.row_styles),o(i.column_style,r.column_styles),r.row_pattern=i.row_pattern||[],a(r.sheet_style||{});for(let l of r.row_pattern)a(l);return r.row_height_=[],n(r.row_height_,i.row_height||{}),r.row_height_.length&&r.cells.EnsureRow(r.row_height_.length-1),r.column_width_=[],n(r.column_width_,i.column_width||{}),r.column_width_.length&&r.cells.EnsureColumn(r.column_width_.length-1),r.annotations=(i.annotations||[]).map(l=>new Ee(l)),i.selection&&(r.selection=JSON.parse(JSON.stringify(i.selection))),r.visible=!0,typeof i.visible<"u"&&(r.visible=!!i.visible),r}Activate(e){if(this.background_image){let t=mt(this.background_image);t&&(this._image=e.Create("img"),this._image.src=t)}}MergeCells(e){e=e.Clone(),this.cells.Apply(e,(t,r,i)=>{t.merge_area=e,t.render_clean=[],(r!==e.start.column||i!==e.start.row)&&t.Reset()},!0)}UnmergeCells(e){let t=!0;if(this.cells.Apply(e,r=>{t=t&&!!r.merge_area&&e.Equals(r.merge_area)},!1),!t){console.warn("area mismatch");return}this.cells.Apply(e,r=>{r.merge_area=void 0,r.render_clean=[]},!1)}StyleFontSize(e,t={}){let r=e.font_size?.value||0,i=0;switch(e.font_size?.unit){case"px":r*=75/100;break;case"em":i=e.font_size.value||1;break;case"%":i=(e.font_size.value||100)/100;break}return i&&(r=i*(t.font_size?.value||10),t.font_size?.unit==="px"&&(r*=75/100)),r||10}UpdateDefaultRowHeight(){let e=U.Composite([this.default_style_properties,this.sheet_style]);if(typeof window<"u"){let t=de.MeasureText(U.Font(e),"M"),r=Math.round(t.height*1.4);this.default_row_height<r&&(this.default_row_height=r)}}SetRowHeaders(e){this.row_headers=e.map(t=>t===void 0?"":t.toString()),this.row_headers&&this.cells.EnsureRow(this.row_headers.length-1)}SetColumnHeaders(e){this.column_headers=e.map(t=>t===void 0?"":t.toString()),e&&this.cells.EnsureColumn(e.length-1)}RowHeader(e){return this.row_headers?this.row_headers.length>e?this.row_headers[e]:"":e+1}ColumnHeader(e){let t="";if(this.column_headers)return this.column_headers.length>e?this.column_headers[e]:"";for(;;){let r=e%26;if(t=String.fromCharCode(65+r)+t,e=Math.floor(e/26),e)e--;else break}return t}GetRowHeight(e){let t=this.row_height_[e];return typeof t>"u"?this.default_row_height:t}SetRowHeight(e,t){return this.row_height_[e]=t,this.cells.EnsureRow(e),t}GetColumnWidth(e){let t=this.column_width_[e];return typeof t>"u"?this.default_column_width:t}SetColumnWidth(e,t){return this.column_width_[e]=t,this.cells.EnsureColumn(e),t}Delta(e,t){let r={},i=[...Object.keys(e),...Object.keys(t)];for(let n of i){let a=e[n],s=t[n];typeof a=="object"&&typeof s=="object"?JSON.stringify(a)!==JSON.stringify(s)&&(r[n]=s):a!==s&&(r[n]=s)}return r}UpdateCellStyle(e,t,r=!0){let{row:i,column:n}=e;this.cell_style[n]||(this.cell_style[n]=[]);let a=this.CompositeStyleForCell(e,!1,!1,void 0,!1),s=U.Composite([this.default_style_properties,a,U.Merge(this.cell_style[n][i]||{},t,r)]),o=this.Delta(a,s);this.cell_style[n][i]=o,this.BleedFlush({start:e,end:e})}Invalidate(e){this.cells.Apply(this.RealArea(e),t=>t.render_clean=[])}UpdateAreaStyle(e,t={},r=!0){if(e)if(e.entire_sheet)this.UpdateSheetStyle(t,r);else if(e.entire_column)for(let i=e.start.column;i<=e.end.column;i++)this.UpdateColumnStyle(i,t,r);else if(e.entire_row)for(let i=e.start.row;i<=e.end.row;i++)this.UpdateRowStyle(i,t,r);else e.Array().forEach(i=>this.UpdateCellStyle(i,t,r))}HasCellStyle(e){return!!(this.cell_style[e.column]&&this.cell_style[e.column][e.row]||this.row_styles[e.row]||this.column_styles[e.column]||this.row_pattern.length)}NextVisibleColumn(e){for(++e;this.column_width_[e]===0;e++);return e}PreviousVisibleColumn(e){for(--e;e>=0&&this.column_width_[e]===0;e--);return e}NextVisibleRow(e){for(++e;this.row_height_[e]===0;e++);return e}PreviousVisibleRow(e){for(--e;e>=0&&this.row_height_[e]===0;e--);return e}TableRow(e,t){let r={alternate:!1,header:t===e.area.start.row,last:!1,totals:e.totals_row&&t===e.area.end.row};if(r.header||r.totals)return r;if(!(e.totals_row&&this.GetRowHeight(e.area.end.row)>0)){let a=e.area.end.row;for(;a>=e.area.start.row;a--)if(this.GetRowHeight(a)){r.last=a===t;break}}let n=e.area.start.row+1;for(;n<=e.area.end.row&&!(this.GetRowHeight(n)&&(r.alternate=!r.alternate,n===t));n++);return r}SurroundingStyle(e,t){let r=[{},{},{},{},{},{},{},{},{},{}],i=e.column+1,n=e.column-1,a=e.row+1,s=e.row-1;for(;this.column_width_[i]===0;i++);for(;this.row_height_[a]===0;a++);for(;n>=0&&this.column_width_[n]===0;n--);for(;s>=0&&this.row_height_[s]===0;s--);return n>=0&&s>=0&&(r[7]=this.CellStyleData({row:s,column:n},t)||{}),n>=0&&(r[4]=this.CellStyleData({row:e.row,column:n},t)||{},r[1]=this.CellStyleData({row:a,column:n},t)||{}),s>=0&&(r[8]=this.CellStyleData({row:s,column:e.column},t)||{},r[9]=this.CellStyleData({row:s,column:i},t)||{}),r[6]=this.CellStyleData({row:e.row,column:i},t)||{},r[2]=this.CellStyleData({row:a,column:e.column},t)||{},r[3]=this.CellStyleData({row:a,column:i},t)||{},r}CellStyleData(e,t){let r=this.cells.GetCell(e);if(r){if(!r.style){let i=this.GetStyleIndex(this.CompositeStyleForCell(e));r.style=this.style_map[i]}if(r.table){let i=r.table.theme||t;if(i){let n=JSON.parse(JSON.stringify(r.style)),a=this.TableRow(r.table,e.row);return a.header?i.header&&(n=U.Composite([n,i.header])):a.totals?i.total&&(n=U.Composite([n,i.total])):a.alternate?i.odd&&(n=U.Composite([n,i.odd])):i.even&&(n=U.Composite([n,i.even])),n}}return r.style}}GetCopyStyle(e){return this.CompositeStyleForCell(e,!0,!1,void 0,!1)}CellData(e){let t=this.cells.EnsureCell(e);if(t.rendered_type)return t;let r,i;if(t.calculated_type?(i=t.calculated,r=t.calculated_type):(i=t.value,r=t.type),!t.style){let n=this.GetStyleIndex(this.CompositeStyleForCell(e));t.style=this.style_map[n]}if(!r||i===null||typeof i>"u")t.formatted="",t.rendered_type=2;else if(r===3)isNaN(i)?t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan:t.formatted=this.FormatNumber(i,t.style.number_format),t.rendered_type=3;else if(r===6)t.formatted="#"+(i||"ERR?"),t.rendered_type=6;else if(r===4)t.formatted=i.toString().toUpperCase(),t.rendered_type=4;else if(r===1&&t.calculated===void 0)t.formatted="",t.rendered_type=2;else if(r===7){let n=i;if(isNaN(n.real)||isNaN(n.imaginary))t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan;else{let a=I.Get(t.style.number_format||"",!0);t.formatted=a.FormatComplex(n)}t.rendered_type=7}else if(r===9){if(isNaN(i.value))t.formatted=typeof t.style.nan>"u"?"NaN":t.style.nan,t.formatted+=" "+i.unit;else{let n=I.Get(t.style.number_format||"",!0);t.formatted=n.FormatDimensionedQuantity(i)}t.rendered_type=9}else t.formatted=this.FormatNumber(i,t.style.number_format),t.rendered_type=2;return t}FormatNumber(e,t=""){let r=I.Get(t).FormatParts(e);return r.length?r.length===1&&!r[0].flag?r[0].text||"":r:""}SetHeaderSize(e=ci,t=this.default_row_height){this.row_header_width=e,this.column_header_height=t}AutoSizeRow(e,t={},r=!0){let i=this.default_row_height,n=9;for(let a=0;a<this.cells.columns;a++){let s=this.CellData({row:e,column:a}),o=s.style,l=s.formatted||"";if(typeof l!="string"&&(l=l.map(d=>d.text).join("")),o&&l&&l.length){let d=l.split(/\n/),h=Math.round(this.StyleFontSize(o,t)*1.5);i=Math.max(i,((h||10)+n)*d.length)}}!r&&this.GetRowHeight(e)>=i||this.SetRowHeight(e,i)}GetStyle(e){return this.style_map[e]}InsertRows(e=0,t=1){if(e)for(let o=0;o<this.cells.columns;o++){let l=this.cells.GetCell({row:e-1,column:o},!1);if(l&&l.area){let d=this.cells.GetCell({row:e,column:o},!1);if(d&&d.area&&d.area.Equals(l.area))return!1}}t<0?this.cells.DeleteRows(e,-t):this.cells.InsertRows(e,t);let r={},i={};for(let o=e;o<this.cells.rows;o++)for(let l=0;l<this.cells.columns;l++){let d=this.cells.GetCell({row:o,column:l},!1);d&&(d.area&&!i[d.area.spreadsheet_label]&&(i[d.area.spreadsheet_label]=d.area),d.merge_area&&!r[d.merge_area.spreadsheet_label]&&(r[d.merge_area.spreadsheet_label]=d.merge_area))}for(let o of Object.keys(i)){let l=i[o],d=new y({row:l.start.row+t,column:l.start.column},{row:l.end.row+t,column:l.end.column});d.Iterate(h=>{let u=this.cells.GetCell(h,!0);u.area=d})}for(let o of Object.keys(r)){let l=r[o],d={row:l.start.row,column:l.start.column};l.start.row>=e&&(d.row+=t);let h=new y(d,{row:l.end.row+t,column:l.end.column});h.Iterate(u=>{let m=this.cells.GetCell(u,!0);m.merge_area=h})}let n=Object.keys(this.row_styles),a={};n.forEach(o=>{let l=Number(o);l<e?a[l]=this.row_styles[l]:t<0&&l<e-t||(a[l+t]=this.row_styles[l])}),this.row_styles=a;let s=[];if(t<0)s=[e,-t];else{s=[e,0];for(let o=0;o<t;o++)s.push(void 0)}return this.cell_style.forEach(o=>{o&&o.length>=e&&o.splice.apply(o,s)}),this.row_height_.splice.apply(this.row_height_,s),this.FlushCellStyles(),!0}InsertColumns(e=0,t=1){if(e)for(let o=0;o<this.cells.rows;o++){let l=this.cells.GetCell({row:o,column:e-1},!1);if(l&&l.area){let d=this.cells.GetCell({row:o,column:e},!1);if(d&&d.area&&d.area.Equals(l.area))return!1}}t<0?this.cells.DeleteColumns(e,-t):this.cells.InsertColumns(e,t);let r={},i={};for(let o=e;o<this.cells.columns;o++)for(let l=0;l<this.cells.rows;l++){let d=this.cells.GetCell({row:l,column:o},!1);d&&(d.area&&!i[d.area.spreadsheet_label]&&(i[d.area.spreadsheet_label]=d.area),d.merge_area&&!r[d.merge_area.spreadsheet_label]&&(r[d.merge_area.spreadsheet_label]=d.merge_area))}for(let o of Object.keys(i)){let l=i[o],d=new y({row:l.start.row,column:l.start.column+t},{row:l.end.row,column:l.end.column+t});d.Iterate(h=>{let u=this.cells.GetCell(h,!0);u.area=d})}for(let o of Object.keys(r)){let l=r[o],d={row:l.start.row,column:l.start.column};l.start.column>=e&&(d.column+=t);let h=new y(d,{row:l.end.row,column:l.end.column+t});h.Iterate(u=>{let m=this.cells.GetCell(u,!0);m.merge_area=h})}let n=Object.keys(this.column_styles),a={};n.forEach(o=>{let l=Number(o);l<e?a[l]=this.column_styles[l]:t<0&&l<e-t||(a[l+t]=this.column_styles[l])}),this.column_styles=a;let s=[];if(t<0)s=[e,-t];else{s=[e,0];for(let o=0;o<t;o++)s.push(void 0)}return this.cell_style.splice.apply(this.cell_style,s),this.column_width_.splice.apply(this.column_width_,s),this.FlushCellStyles(),!0}ClearArea(e){e=this.RealArea(e),this.cells.Apply(e,t=>t.Reset())}SetAreaValues2(e,t){e=this.RealArea(e),this.cells.SetArea(e,t)}SetArrayValue(e,t){e=this.RealArea(e),this.cells.Apply(e,i=>i.SetArray(e),!0),this.cells.GetCell(e.start,!0).SetArrayHead(e,t)}SetCellValue(e,t){this.cells.GetCell(e,!0).Set(t)}TablesFromArea(e,t=!1){if(N(e)){let i=this.cells.GetCell(e,!1);return i?.table&&(!t||e.row===i.table.area.start.row)?[i.table]:[]}let r=new Set;for(let i=e.start.row;i<=e.end.row;i++)for(let n=e.start.column;n<=e.end.column;n++){let a=this.cells.GetCell({row:i,column:n},!1);a?.table&&!r.has(a.table)&&(!t||i===a.table.area.start.row)&&r.add(a.table)}return Array.from(r.values())}RealArea(e,t=!1){let r=e.start,i=e.end;return e.entire_row&&(r.column=0,r.absolute_column=!1,i.column=this.cells.columns-1,i.absolute_column=!1),e.entire_column&&(r.row=0,r.absolute_row=!1,i.row=this.cells.rows-1,i.absolute_row=!1),t&&(i.row>=this.rows&&(i.row=this.rows-1,i.absolute_row=!1),i.column>=this.columns&&(i.column=this.columns-1,i.absolute_column=!1)),new y(r,i)}GetCellStyle(e,t=!1){if(N(e))return this.CompositeStyleForCell(e,!0,!1,t);if(e.start.row===e.end.row&&e.start.column===e.end.column)return this.CompositeStyleForCell(e.start,!0,!1,t);let r=[];for(let i=e.start.row;i<=e.end.row;i++){let n=[];for(let a=e.start.column;a<=e.end.column;a++)n.push(this.CompositeStyleForCell({row:i,column:a},!0,!1,t));r.push(n)}return r}FormattedCellValue(e){let t=this.CellData(e);if(t)return typeof t.formatted=="string"?t.formatted:t.formatted?t.formatted.map(r=>{switch(r.flag){case 1:return" ";case 2:return" ";default:return r.text}}).join(""):t.value}GetFormattedRange(e,t=e){if(e.row===t.row&&e.column===t.column)return this.FormattedCellValue(e);let r=[];for(let i=e.row;i<=t.row;i++){let n=[];for(let a=e.column;a<=t.column;a++)n.push(this.FormattedCellValue({row:i,column:a}));r.push(n)}return r}NumberFormatsAndColors(e,t){let r=i=>{i.number_format&&(t[i.number_format]=1),i.text?.text&&i.text.text!=="none"&&(e[i.text.text]=1),i.fill?.text&&(e[i.fill.text]=1),i.border_top_fill?.text&&(e[i.border_top_fill.text]=1),i.border_left_fill?.text&&(e[i.border_left_fill.text]=1),i.border_right_fill?.text&&(e[i.border_right_fill.text]=1),i.border_bottom_fill?.text&&(e[i.border_bottom_fill.text]=1)};r(this.sheet_style);for(let i in this.row_styles)r(this.row_styles[i]);for(let i in this.column_styles)r(this.column_styles[i]);for(let i of this.row_pattern)r(i);for(let i of this.cell_style)if(i)for(let n of i)n&&r(n)}CompressCellStyles(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i)for(let n=0;n<i.length;n++){let a=i[n];if(a){let s=n+1;for(;s<i.length&&i[s]===a;s++);s>n+1?t.push({row:n,column:r,ref:a,rows:s-n}):t.push({row:n,column:r,ref:a}),n=s-1}}}return t}toJSON(e={}){let t=(A,k)=>{let S={};for(let M=0;M<A.length;M++)typeof A[M]<"u"&&A[M]!==k&&(S[M]=A[M]);if(Object.keys(S).length)return S},r=[{}],i={},n=[],a=JSON.stringify({});for(let A=0;A<this.cell_style.length;A++){let k=this.cell_style[A];if(k){n[A]=[];for(let S=0;S<k.length;S++)if(k[S]){let M=JSON.stringify(k[S]);if(M!==a){let V=i[M];typeof V!="number"&&(i[M]=V=r.length,r.push(k[S])),n[A][S]=V}}}}let s=A=>{let k=JSON.stringify(A);if(k===a)return 0;let S=i[k];return typeof S!="number"&&(i[k]=S=r.length,r.push(A)),S};r=JSON.parse(JSON.stringify(r));let o=JSON.parse(JSON.stringify(this.sheet_style)),l=JSON.parse(JSON.stringify(this.row_pattern)),d={},h={};for(let A of Object.keys(this.column_styles)){let k=Number(A),S=this.column_styles[k];if(S){let M=s(S);M&&(d[k]=M)}}for(let A of Object.keys(this.row_styles)){let k=Number(A),S=this.row_styles[k];if(S){let M=s(S);M&&(h[k]=M)}}let u=(A,k)=>{if(typeof A<"u"&&A!=="none")return A===k?void 0:de.MeasureColorARGB(A)},m=(A={},k={})=>{let S={...k,...A};if(S.text)return S.text=de.MeasureColorARGB(S.text),S;if(typeof S.theme=="number")return S};if(e.export_colors){let A=[];for(let k of[r,[o],l])if(Array.isArray(k))for(let S of k)A.push(S);else for(let S of Object.keys(k))A.push(k[S]);for(let k of A){let S=m(k.border_top_fill,U.DefaultProperties.border_top_fill);S!==void 0&&(k.border_top_fill=S),S=m(k.border_left_fill,U.DefaultProperties.border_left_fill),S!==void 0&&(k.border_left_fill=S),S=m(k.border_right_fill,U.DefaultProperties.border_right_fill),S!==void 0&&(k.border_right_fill=S),S=m(k.border_bottom_fill,U.DefaultProperties.border_bottom_fill),S!==void 0&&(k.border_bottom_fill=S),k.fill?.text&&(k.fill.text=de.MeasureColorARGB(k.fill.text)),k.text&&k.text.text&&k.text.text!=="none"&&(k.text.text=de.MeasureColorARGB(k.text.text))}}let f={calculated_value:!!e.rendered_values,preserve_type:!!e.preserve_type,expand_arrays:!!e.expand_arrays,decorated_cells:!!e.decorated_cells,nested:!0,cell_style_refs:n,tables:!!e.tables},p=this.cells.toJSON(f),g=p.data,{rows:b,columns:v}=p;e.shrink?(b+=2,v+=1):(b=this.rows,v=this.columns);for(let A of this.annotations)A.data.extent||this.CalculateAnnotationExtent(A),A.data.extent&&(b=Math.max(b,A.data.extent.row+1),v=Math.max(v,A.data.extent.column+1));let _=this.CompressCellStyles(n),w=this.conditional_formats.length?JSON.parse(JSON.stringify(this.conditional_formats.map(A=>({...A,internal:void 0})))):void 0,x={id:this.id,name:this.name,data:g,sheet_style:o,rows:b,columns:v,cell_styles:_,styles:r,row_style:h,column_style:d,conditional_formats:w,row_pattern:l.length?l:void 0,default_row_height:this.default_row_height,default_column_width:this.default_column_width,row_height:t(this.row_height_,this.default_row_height),column_width:t(this.column_width_,this.default_column_width),selection:JSON.parse(JSON.stringify(this.selection)),annotations:JSON.parse(JSON.stringify(this.annotations))};return this.visible||(x.visible=this.visible),(this.scroll_offset.x||this.scroll_offset.y)&&(x.scroll=this.scroll_offset),this.background_image&&(x.background_image=this.background_image),(this.freeze.rows||this.freeze.columns)&&(x.freeze=this.freeze),x}FlushCellStyles(){this.style_map=[],this.style_json_map=[],this.cells.FlushCellStyles()}ImportData(e){let t=e.styles;e.outline&&(this.outline=e.outline);let r=e.sheet_style;r&&this.UpdateAreaStyle(new y({row:1/0,column:1/0},{row:1/0,column:1/0}),t[r]);let i=e.column_styles;if(i)for(let a=0;a<i.length;a++)i[a]&&this.UpdateAreaStyle(new y({row:1/0,column:a},{row:1/0,column:a}),t[i[a]]);this.cells.FromJSON(e.cells),e.name&&(this.name=e.name||"");let n=this.cell_style;for(let a of e.cells)a.style_ref&&(n[a.column]||(n[a.column]=[]),n[a.column][a.row]=t[a.style_ref]);for(let a=0;a<e.column_widths.length;a++)typeof e.column_widths[a]<"u"&&this.SetColumnWidth(a,e.column_widths[a]);for(let a=0;a<e.row_heights.length;a++)typeof e.row_heights[a]<"u"&&this.SetRowHeight(a,e.row_heights[a]);for(let a of e.annotations||[])this.annotations.push(new Ee(a));for(let a of e.conditional_formats||[])this.conditional_formats.push(a);e.hidden&&(this.visible=!1)}CalculateAnnotationExtent(e){if(e.data.layout){e.data.extent={...e.data.layout.br.address};return}let t=1e3;e.data.extent={row:0,column:0};let r=e.rect?.right;if(r&&this.default_column_width){for(let n=0;r>=0&&n<t;n++)if(r-=this.GetColumnWidth(n),r<0){e.data.extent.column=n;break}}let i=e.rect?.bottom;if(i&&this.default_row_height){for(let n=0;i>=0&&n<t;n++)if(i-=this.GetRowHeight(n),i<0){e.data.extent.row=n;break}}}UpdateSheetStyle(e,t=!0){this.sheet_style=U.Merge(this.sheet_style,e,t);let r=Object.keys(e);for(let i of this.cell_style)if(i)for(let n of i)n&&r.forEach(a=>delete n[a]);for(let i of Object.keys(this.row_styles))r.forEach(n=>delete this.row_styles[i][n]);for(let i of Object.keys(this.column_styles))r.forEach(n=>delete this.column_styles[i][n]);this.FlushCellStyles()}UpdateRowStyle(e,t,r=!0){this.row_styles[e]=U.Merge(this.row_styles[e]||{},t,r);let i=Object.keys(t);for(let n of this.cell_style)n&&n[e]&&i.forEach(a=>delete n[e][a]);for(let n=0;n<this.cells.columns;n++)if(this.column_styles[n]){let a=this.column_styles[n],s=this.cell_style[n]?this.cell_style[n][e]||{}:{};for(let o of i)typeof a[o]<"u"&&(s[o]=t[o]);Object.keys(s).length&&(this.cell_style[n]||(this.cell_style[n]=[]),this.cell_style[n][e]=JSON.parse(JSON.stringify(s)))}this.cells.Apply(this.RealArea(y.FromRow(e)),n=>n.FlushStyle())}UpdateColumnStyle(e,t,r=!0){this.column_styles[e]=U.Merge(this.column_styles[e]||{},t,r);let i=Object.keys(t);if(this.cell_style[e])for(let n of this.cell_style[e])n&&i.forEach(a=>delete n[a]);this.cells.Apply(this.RealArea(y.FromColumn(e)),n=>n.FlushStyle())}BleedFlush(e){let t=[Math.max(0,e.start.row-1),e.end.row+1],r=[Math.max(0,e.start.column-1),e.end.column+1];for(let i=t[0];i<=t[1];i++)for(let n=r[0];n<=r[1];n++)this.cells.GetCell({row:i,column:n},!1)?.FlushStyle()}FlushConditionalFormats(){this.flush_conditional_formats=!0}ApplyConditionalFormats(){let e=this.flush_conditional_formats;for(let i of this.conditional_formats)if(i.internal?.vertex?.updated){e=!0;break}if(!e)return;this.flush_conditional_formats=!1;let t=[],r=[...this.conditional_format_checklist];this.conditional_format_checklist=[];for(let i of this.conditional_formats)if(i.internal?.vertex?.updated&&(i.internal.vertex.updated=!1),i.type==="gradient"){let n=JSON.parse(JSON.stringify(i.area)),a=i.internal?.vertex?.result;if(a&&i.internal?.gradient){let s=i.property??"fill";if(a.type===8)for(let o=n.start.row;o<=n.end.row;o++)for(let l=n.start.column;l<=n.end.column;l++){let d=a.value[l-n.start.column][o-n.start.row];if(d.type===3){t[o]||(t[o]=[]),t[o][l]||(t[o][l]=[]);let h=i.internal.gradient.Interpolate(d.value);t[o][l].push({[s]:h})}}else if(a.type===3){let o=i.internal.gradient.Interpolate(a.value);for(let l=n.start.row;l<=n.end.row;l++){t[l]||(t[l]=[]);for(let d=n.start.column;d<=n.end.column;d++)t[l][d]||(t[l][d]=[]),t[l][d].push({[s]:o})}}r.push(n),this.conditional_format_checklist.push(n)}}else{let n=JSON.parse(JSON.stringify(i.area)),a=i.internal?.vertex?.result;if(a){if(a.type===8)for(let s=n.start.row;s<=n.end.row;s++)for(let o=n.start.column;o<=n.end.column;o++){let l=a.value[o-n.start.column][s-n.start.row];(l.type===4||l.type===3)&&l.value&&(t[s]||(t[s]=[]),t[s][o]||(t[s][o]=[]),t[s][o].push(i.style))}else if((a.type===4||a.type===3)&&a.value)for(let s=n.start.row;s<=n.end.row;s++){t[s]||(t[s]=[]);for(let o=n.start.column;o<=n.end.column;o++)t[s][o]||(t[s][o]=[]),t[s][o].push(i.style)}r.push(n),this.conditional_format_checklist.push(n)}}for(let i of r)this.BleedFlush(i);this.conditional_format_cache=t}ConditionalFormatForCell(e){return this.conditional_format_cache[e.row]?this.conditional_format_cache[e.row][e.column]||[]:[]}CompositeStyleForCell(e,t=!0,r=!0,i=!0,n=!0){let{row:a,column:s}=e,o=[];return i&&o.push(this.default_style_properties),o.push(this.sheet_style),r&&this.row_pattern.length&&o.push(this.row_pattern[a%this.row_pattern.length]),this.row_styles[a]&&o.push(this.row_styles[a]),this.column_styles[s]&&o.push(this.column_styles[s]),t&&this.cell_style[s]&&this.cell_style[s][a]&&o.push(this.cell_style[s][a]),n&&o.push(...this.ConditionalFormatForCell(e)),U.Composite(o)}GetStyleIndex(e){let t=JSON.stringify(e);for(let i=0;i<this.style_json_map.length;i++)if(t===this.style_json_map[i])return i;let r=this.style_map.length;return this.style_map.push(JSON.parse(t)),this.style_json_map.push(t),r}};var Oe=class{constructor(e,t,r=!1,i=F.GetInstance()){this.model=e;this.view=t;this.DOM=i;if(r)return;if(!i)throw new Error("missing DOM context");this.dpr=Math.max(1,self.devicePixelRatio||1),this.mask=i.Div("treb-mouse-mask"),this.tooltip=i.Div("treb-tooltip"),this.dropdown_caret=i.SVG("svg","treb-dropdown-caret"),this.dropdown_caret.setAttribute("viewBox","0 0 24 24"),this.dropdown_caret.tabIndex=-1;let n=i.SVG("path");n.setAttribute("d","M5,7 L12,17 L19,7"),this.dropdown_caret.appendChild(n),this.dropdown_caret.addEventListener("click",a=>{a.stopPropagation(),a.preventDefault(),this.grid_cover.classList.remove("nub-select");let s=this.dropdown_caret.getAttribute("class")||"";/active/i.test(s)?this.dropdown_caret.setAttribute("class","treb-dropdown-caret"):(this.dropdown_caret.setAttribute("class","treb-dropdown-caret active"),this.dropdown_list.focus())}),this.dropdown_list=i.Div("treb-dropdown-list",void 0,{attrs:{tabindex:"-1"}}),this.dropdown_list.addEventListener("keydown",a=>{let s=0;switch(a.key){case"ArrowDown":s=1;break;case"ArrowUp":s=-1;break;case"Escape":break;case"Enter":break;default:console.info(a.key);return}if(a.stopPropagation(),a.preventDefault(),a.key==="Escape"||a.key==="Enter")this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),a.key==="Enter"&&this.dropdown_callback&&this.dropdown_selected&&this.dropdown_callback.call(0,this.dropdown_selected.dropdown_value);else if(s&&this.dropdown_selected)if(s>0&&this.dropdown_selected.nextSibling){this.dropdown_selected.nextSibling.classList.add("selected"),this.dropdown_selected.classList.remove("selected"),this.dropdown_selected=this.dropdown_selected.nextSibling;let o=this.dropdown_selected.offsetTop+this.dropdown_selected.offsetHeight;o>this.dropdown_list.offsetHeight+this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=o-this.dropdown_list.offsetHeight)}else s<0&&this.dropdown_selected.previousSibling&&(this.dropdown_selected.previousSibling.classList.add("selected"),this.dropdown_selected.classList.remove("selected"),this.dropdown_selected=this.dropdown_selected.previousSibling,this.dropdown_selected.offsetTop<this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=this.dropdown_selected.offsetTop))}),this.dropdown_list.addEventListener("mousedown",a=>{let s=a.target;a.target!==this.dropdown_list&&(a.stopPropagation(),a.preventDefault(),this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_callback&&this.dropdown_callback.call(0,s.dropdown_value))}),this.dropdown_list.addEventListener("mousemove",a=>{let s=a.target;s!==this.dropdown_selected&&(this.grid_cover.classList.remove("nub-select"),this.dropdown_selected&&this.dropdown_selected.classList.remove("selected"),s.classList.add("selected"),this.dropdown_selected=s)}),this.mock_selection=i.Div("mock-selection-node",void 0,{html:" "}),this.note_node=i.Div("treb-note"),this.title_node=i.Div("treb-hover-title"),this.sort_button=i.Create("button","treb-sort-button",void 0,{attrs:{title:"Sort table",tabindex:"-1"}}),this.HideNote()}column_header;row_header;contents;buffer_canvas;corner;corner_canvas;grid_selection;grid_cover;column_header_cover;row_header_cover;annotation_container;mask;mock_selection;container;grid_tiles=[];column_header_tiles=[];row_header_tiles=[];corner_selection;row_header_selection;column_header_selection;corner_annotations;row_header_annotations;column_header_annotations;frozen_row_tiles=[];frozen_column_tiles=[];header_size={width:0,height:0};last_column=0;total_height=0;total_width=0;default_row_height=0;default_column_width=0;header_offset={x:0,y:0};dpr=1;scale=1;scroll_reference_node;get scroll_offset(){return this.scroll_reference_node?{x:this.scroll_reference_node.scrollLeft,y:this.scroll_reference_node.scrollTop}:{x:0,y:0}}set scroll_offset(e){this.scroll_reference_node&&(this.scroll_reference_node.scrollLeft=e.x,this.scroll_reference_node.scrollTop=e.y)}dropdown_caret;trident=typeof navigator<"u"&&navigator.userAgent&&/trident/i.test(navigator.userAgent);default_tile_size={width:1200,height:800};tooltip_state;tooltip;dropdown_list;dropdown_caret_visible=!1;dropdown_callback;dropdown_selected;note_node;sort_button;title_node;row_cache=[];column_cache=[];initialized=!1;UpdateDPR(){let e=Math.max(1,self.devicePixelRatio||1);return e===this.dpr?!1:(this.dpr=e,!0)}ColumnWidth(e){return Math.round(this.view.active_sheet.GetColumnWidth(e)*this.scale)}RowHeight(e){return Math.round(this.view.active_sheet.GetRowHeight(e)*this.scale)}SetRowHeight(e,t){this.view.active_sheet.SetRowHeight(e,Math.round(t/this.scale))}SetColumnWidth(e,t){this.view.active_sheet.SetColumnWidth(e,Math.round(t/this.scale))}ShowSelections(e=!0){this.grid_selection.style.display=e?"block":"none"}HideTitle(){this.title_node.style.opacity="0"}ShowTitle(e,t){if(this.title_node.textContent=e,!this.title_node.parentElement)return;let r=this.title_node.parentElement.getBoundingClientRect(),i=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.title_node.style.left=r.left+i.left-this.scroll_reference_node.scrollLeft+0+"px",this.title_node.style.top=r.top+i.bottom-this.scroll_reference_node.scrollTop+8+"px",this.title_node.style.opacity="1"}HideNote(){this.note_node.style.opacity="0",this.note_node.style.pointerEvents="none"}HideTableSortButton(){this.sort_button.style.opacity="0",this.sort_button.style.pointerEvents="none",this.sort_button.setAttribute("tabindex","-1")}ShowTableSortButton(e,t,r){if(!this.sort_button.parentElement)return;let i=!0,n=!1;e.sort&&e.sort.column===t&&(i=!e.sort.asc,n=!0),this.sort_button.setAttribute("tabindex","0 "),this.sort_button.style.opacity="1",this.sort_button.style.pointerEvents="initial",this.sort_button.classList.remove("asc","desc"),n&&this.sort_button.classList.add(i?"asc":"desc"),this.sort_button.dataset.asc=i.toString(),this.sort_button.dataset.table=e.name,this.sort_button.dataset.column=t.toString();let a=this.OffsetCellAddressToRectangle(r).Shift(this.header_size.width,this.header_size.height),s=this.sort_button.getBoundingClientRect();this.sort_button.style.left=a.right-s.width-s.width/2+"px",this.sort_button.style.top=a.top+(a.height-s.height)/2+"px"}ShowNote(e,t,r,i){if(i?this.note_node.innerHTML=i:this.note_node.textContent=e,!this.note_node.parentElement)return;let n=this.note_node.getBoundingClientRect(),a=this.note_node.parentElement.getBoundingClientRect(),s={x:8,y:2},o=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.note_node.style.left=a.left+o.right-this.scroll_reference_node.scrollLeft+s.x+"px",this.note_node.style.top=a.top+o.top-this.scroll_reference_node.scrollTop-n.height/5-s.y+"px",this.note_node.style.opacity="1",this.note_node.style.pointerEvents="auto"}AnnotationLayoutOrder(e,t){let r=-1;for(let n=0;n<this.view.active_sheet.annotations.length;n++)if(this.view.active_sheet.annotations[n]===e){r=n;break}if(r<0)return!1;let i=Math.min(Math.max(0,r+t),this.view.active_sheet.annotations.length-1);if(i===r)return!1;this.view.active_sheet.annotations.splice(r,1),this.view.active_sheet.annotations.splice(i,0,e);for(let n=0;n<this.view.active_sheet.annotations.length;n++){let a=this.view.active_sheet.annotations[n].key,s=this.container?.querySelectorAll(`.annotation[data-key="${a}"]`);if(s)for(let o=0;o<s?.length;o++)s[o].style.zIndex=(n+1).toString()}return!0}PointToAnnotationCorner(e){let t=this.PointToAddress_Grid(e,void 0,!1),r=this.CellAddressToRectangle(t);return{address:t,offset:{x:(e.x-r.left)/r.width,y:(e.y-r.top)/r.height}}}RectToAnnotationLayout(e){return{tl:this.PointToAnnotationCorner({x:(e.left||0)+1,y:(e.top||0)+1}),br:this.PointToAnnotationCorner({x:e.right||e.left||100,y:e.bottom||e.top||100})}}AddressToAnnotationLayout(e,t){let r={tl:this.CellAddressToRectangle(e),br:this.CellAddressToRectangle(t)};return{tl:this.PointToAnnotationCorner({x:r.tl.left||0,y:r.tl.top||0}),br:this.PointToAnnotationCorner({x:r.br.right||r.tl.left||100,y:r.br.bottom||r.tl.left||100})}}AnnotationLayoutToRect(e){let t=this.CellAddressToRectangle(e.tl.address),r=this.CellAddressToRectangle(e.br.address),i=t.left+t.width*e.tl.offset.x-1,n=t.top+t.height*e.tl.offset.y-1;return new H(i,n,r.left+r.width*e.br.offset.x-i,r.top+r.height*e.br.offset.y-n)}UpdateAnnotation(e){Array.isArray(e)||(e=[e]);for(let t of e){let r=t.view[this.view.view_index]||{};if(r.node){if(r.node.dataset.scale=this.scale.toString(),r.node.style.fontSize=`${10*this.scale}pt`,t.rect&&!t.data.layout&&(t.scaled_rect=t.rect.Scale(this.scale),t.data.layout=this.RectToAnnotationLayout(t.scaled_rect)),t.data.layout){let i=this.AnnotationLayoutToRect(t.data.layout);i.ApplyStyle(r.node),t.scaled_rect=i}r.node.dataset.key=t.key.toString(),(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.CloneFrozenAnnotation(t)}}}GetFrozenAnnotations(e){return[this.row_header_annotations,this.column_header_annotations,this.corner_annotations].map(r=>r.querySelector(`.annotation[data-key="${e.key}"]`)).filter(r=>r!==null)}CloneFrozenAnnotations(){for(let e of this.view.active_sheet.annotations)e.view[this.view.view_index]?.node&&e.key&&this.CloneFrozenAnnotation(e)}ClearFrozenAnnotations(){for(let e of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let t=e.querySelectorAll(".annotation");for(let r=0;r<t.length;r++)t[r].parentElement?.removeChild(t[r])}}RemoveFrozenAnnotation(e){for(let t of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let r=t.querySelector(`.annotation[data-key="${e.key}"]`);r&&r.parentElement?.removeChild(r)}}CloneFrozenAnnotation(e){for(let t of[this.row_header_annotations,this.column_header_annotations,this.corner_annotations]){let r=t.querySelector(`.annotation[data-key="${e.key}"]`);r&&r.parentElement?.removeChild(r);let i=e.view[this.view.view_index];if(r=i?.node?.cloneNode(!0),r){let n=r.querySelector(".annotation-move-target"),a=r.querySelector(".annotation-resize-target");r.addEventListener("mousedown",s=>{let o=i.node;requestAnimationFrame(()=>{o?.focus()}),this.AnnotationMouseDown(e,i.node,s,n,a)}),t.appendChild(r)}}}RemoveAnnotation(e){let t=e.view[this.view.view_index]||{};t.node&&t.node.parentElement?.removeChild(t.node),this.RemoveFrozenAnnotation(e)}RemoveAnnotationNodes(){let e=Array.prototype.map.call(this.annotation_container.children,t=>t);for(let t of e)this.annotation_container.removeChild(t);(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.ClearFrozenAnnotations()}AddAnnotation(e){let t=e.view[this.view.view_index]||{};if(!t.node)throw new Error("annotation view/node missing");this.annotation_container.appendChild(t.node),this.UpdateAnnotation(e)}AnnotationMouseDown(e,t,r,i,n){let a=e.scaled_rect;return a?new Promise(s=>{let o={left:a.left,top:a.top,width:a.width,height:a.height},l=this.scroll_reference_node,d=l.getBoundingClientRect(),h=t.getBoundingClientRect();if(r.target===i||r.target!==n&&r.altKey){r.stopPropagation(),r.preventDefault(),t.focus();let u={x:h.left+r.offsetX-a.left,y:h.top+r.offsetY-a.top},m=[t,...this.GetFrozenAnnotations(e)],f=25,p=this.CellAddressToRectangle({row:0,column:0}).Combine(this.CellAddressToRectangle({row:this.view.active_sheet.rows-1,column:this.view.active_sheet.columns-1})).Expand(-1,-1);ge(this.mask,"move",g=>{if(g.offsetY-d.top<this.header_offset.y){let b=Math.min(f,l.scrollTop);l.scrollTop-=b,u.y+=b}else if(g.offsetY-d.top>=d.height&&l.scrollTop+d.height<p.height){let b=f;l.scrollTop+=b,u.y-=b}if(g.offsetX-d.left<this.header_offset.x){let b=Math.min(f,l.scrollLeft);l.scrollLeft-=b,u.x+=b}else if(g.offsetX-d.left>=d.width&&l.scrollLeft+d.width<p.width){let b=f;l.scrollLeft+=b,u.x-=b}if(a.top=g.offsetY-u.y,a.left=g.offsetX-u.x,g.shiftKey){let b=Math.abs(a.left-o.left),v=Math.abs(a.top-o.top);b<=v?a.left=o.left:a.top=o.top}if(g.ctrlKey){let b=this.ClampToGrid({x:a.left,y:a.top});a.left=b.x,a.top=b.y}for(let b of m)b.style.top=a.top+"px",b.style.left=a.left+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(a),s({type:"annotation",annotation:e,event:"move"})});return}else if(r.target===n){r.stopPropagation(),r.preventDefault(),t.focus();let u=0;e.data.type==="image"&&e.data.data&&e.data.data.original_size&&e.data.data.original_size.width&&e.data.data.original_size.height&&(u=e.data.data.original_size.width/e.data.data.original_size.height);let m=t.getBoundingClientRect(),f={x:m.left+r.offsetX-a.width+n.offsetLeft,y:m.top+r.offsetY-a.height+n.offsetTop};ge(this.mask,"nw-resize",p=>{let g=[t,...this.GetFrozenAnnotations(e)];if(a.height=p.offsetY-f.y,a.width=p.offsetX-f.x,p.shiftKey&&p.ctrlKey){if(u){let b=Math.abs(a.width-o.width),v=Math.abs(a.height-o.height);b<v?a.width=u*a.height:a.height=a.width/u}}else if(p.shiftKey){let b=Math.abs(a.height-o.height),v=Math.abs(a.width-o.width);b>v?a.width=o.width:a.height=o.height}else if(p.ctrlKey){let b=this.ClampToGrid({x:a.right,y:a.bottom});a.width=b.x-a.left+1,a.height=b.y-a.top+1}for(let b of g)b.style.height=a.height+"px",b.style.width=a.width+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(a),s({type:"annotation",annotation:e,event:"resize"})});return}else s()}):(console.info("missing scaled rect!"),Promise.reject())}Initialize(e,t,r=!0){this.mask.parentElement||e.parentElement?.parentElement?.appendChild(this.mask),this.tooltip.parentElement||e.appendChild(this.tooltip),this.dropdown_caret.parentElement||e.appendChild(this.dropdown_caret),this.dropdown_list.parentElement||e.appendChild(this.dropdown_list),this.note_node.parentElement||e.appendChild(this.note_node),this.sort_button.parentElement||(e.appendChild(this.sort_button),this.sort_button.addEventListener("click",()=>{t.sort(this.sort_button.dataset.table||"",Number(this.sort_button.dataset.column||"0")||0,/true/i.test(this.sort_button.dataset.asc||"")),this.sort_button.classList.remove("asc","desc"),this.sort_button.dataset.asc==="true"?(this.sort_button.dataset.asc="false",this.sort_button.classList.add("desc")):(this.sort_button.dataset.asc="true",this.sort_button.classList.add("asc")),t.focus()})),this.title_node.parentElement||e.appendChild(this.title_node),this.InitializeInternal(e,t.scroll),!r&&this.scroll_reference_node&&(this.scroll_reference_node.style.overflow="hidden"),this.dropdown_callback=t.dropdown,this.initialized=!0}MockSelection(){if(this.container&&!this.trident&&this.DOM.doc){let e=this.DOM.GetSelection();if(e){let t=this.DOM.doc.createRange();t.selectNodeContents(this.mock_selection),e.removeAllRanges(),e.addRange(t)}}}CreateTile(e,t,r,i,n,a,s,o=!0){let l=this.DOM.Create("canvas");return l.setAttribute("class",e),l.logical_size=t,l.width=t.width*this.dpr,l.height=t.height*this.dpr,l.style.width=`${t.width}px`,l.style.height=`${t.height}px`,l.tile_position=r,l.first_cell=i,this.UpdateTileGridPosition(l),l.last_cell={row:i.row+n.rows-1,column:i.column+n.columns-1},l.pixel_start=a,l.pixel_end={x:a.x+t.width,y:a.y+t.height},l.dirty=!!o,l.needs_full_repaint=!0,s.appendChild(l),l}ApplyTheme(e){this.row_header.style.backgroundColor=this.column_header.style.backgroundColor=this.corner.style.backgroundColor=e.headers?.fill?pe(e,e.headers.fill):"",this.corner.style.borderColor=e.grid_color||"";for(let t of this.grid_tiles)for(let r of t)r.style.backgroundColor=pe(e,e.grid_cell?.fill)||"#fff";this.dropdown_list.style.font=U.Font(e.grid_cell||{})}UpdateTotalSize(){this.total_height=0;let e=this.view.active_sheet.rows;for(let r=0;r<e;r++)this.total_height+=this.RowHeight(r);this.total_width=0;let t=this.view.active_sheet.columns;for(let r=0;r<t;r++)this.total_width+=this.ColumnWidth(r)}UpdateContentsSize(){let e=this.row_header_tiles.reduce((r,i)=>r+i.logical_size.height,0),t=this.column_header_tiles.reduce((r,i)=>r+i.logical_size.width,0);this.column_header.style.width=this.contents.style.width=`${t}px`,this.row_header.style.height=this.contents.style.height=`${e}px`}HideTooltip(){this.tooltip.style.display="none",this.tooltip_state=void 0,this.tooltip.classList.remove("arrow-up"),this.tooltip.classList.remove("arrow-left")}ShowTooltip(e={}){e.up?(this.tooltip.classList.add("arrow-up"),this.tooltip_state="up"):e.left&&(this.tooltip.classList.add("arrow-left"),this.tooltip_state="left"),this.tooltip.style.display="block",this.UpdateTooltip(e)}ShowDropdownCaret(e,t,r){let i=this.OffsetCellAddressToRectangle(e.start);e.count>1&&(i=i.Combine(this.OffsetCellAddressToRectangle(e.end))),i=i.Shift(this.header_size.width,this.header_size.height);let n=Math.round(this.scale*Math.max(8,Math.min(20,i.height)));this.dropdown_caret.style.height=`${n}px`,this.dropdown_caret.style.width=`${n}px`,this.dropdown_caret.style.left=`${i.right+1}px`,this.dropdown_caret.style.top=`${i.bottom-n}px`,this.dropdown_list.style.top=`${i.bottom+2}px`,this.dropdown_list.style.left=`${i.left+2}px`,this.dropdown_list.style.minWidth=`${i.width}px`,this.dropdown_list.textContent="";for(let a of t){let s=this.DOM.Div(void 0,this.dropdown_list);r===a&&(this.dropdown_selected=s,s.classList.add("selected")),s.dropdown_value=a,s.textContent=a?.toString()||""}this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_caret.style.display="block",this.dropdown_caret_visible=!0}HideDropdownCaret(){this.dropdown_caret_visible&&(this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_caret_visible=!1,this.dropdown_caret.style.display="none")}GetScrollOffset(){return{x:this.scroll_reference_node.scrollLeft+this.header_offset.x,y:this.scroll_reference_node.scrollTop+this.header_offset.y}}ScrollTo(e,t=!0,r=!0,i=!1){let n=this.CellAddressToRectangle(e);if(i&&this.scroll_reference_node.scrollTo){let a={left:this.scroll_reference_node.scrollLeft,top:this.scroll_reference_node.scrollTop},s={left:t?n.left:a.left,top:r?n.top:a.top,behavior:"smooth"};this.scroll_reference_node.scrollTo(s)}else r&&(this.scroll_reference_node.scrollTop=n.top),t&&(this.scroll_reference_node.scrollLeft=n.left)}ScrollIntoView(e){let t=this.CellAddressToRectangle(e),r=this.scroll_reference_node.clientWidth-this.row_header.offsetWidth,i=this.scroll_reference_node.clientHeight-this.column_header.offsetHeight,n={x:0,y:0},a={x:!1,y:!1},s=new H(this.scroll_reference_node.scrollLeft,this.scroll_reference_node.scrollTop,r,i);(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&(this.view.active_sheet.freeze.rows&&e.row>=this.view.active_sheet.freeze.rows?n.y=this.frozen_row_tiles[0].logical_size.height:this.view.active_sheet.freeze.rows&&(a.y=!0),this.view.active_sheet.freeze.columns&&e.column>=this.view.active_sheet.freeze.columns?n.x=this.frozen_column_tiles[0].logical_size.width:this.view.active_sheet.freeze.columns&&(a.x=!0)),e.row!==1/0&&(t.top<s.top+n.y&&!a.y?this.scroll_reference_node.scrollTop=t.top-n.y:t.bottom>s.bottom&&(this.scroll_reference_node.scrollTop=t.bottom-i)),e.column!==1/0&&(t.left<s.left+n.x&&!a.x?this.scroll_reference_node.scrollLeft=t.left-n.x:t.right>s.right&&(this.scroll_reference_node.scrollLeft=t.right-r))}UpdateTooltip(e={}){if(typeof e.text<"u"&&(this.tooltip.textContent=e.text),typeof e.x<"u"){let t=e.x||0;this.tooltip_state==="up"&&(t-=this.tooltip.offsetWidth/2),this.tooltip.style.left=Math.round(t)+"px"}if(typeof e.y<"u"){let t=e.y||0;this.tooltip_state==="left"&&(t-=this.tooltip.offsetHeight/2),this.tooltip.style.top=Math.round(t)+"px"}}CoordinateToRowHeader(e){let t={column:1/0,row:0};if(this.view.active_sheet.freeze.rows&&this.frozen_row_tiles[0].pixel_end.y>=e-this.scroll_reference_node.scrollTop){let r=0;e-=this.scroll_reference_node.scrollTop;for(let i=0;i<this.view.active_sheet.freeze.rows;i++)if(r+=this.RowHeight(i),r>=e)return t.row=i,t}for(let r of this.row_header_tiles)if(r.pixel_end.y>=e){let i=e-r.pixel_start.y,n=0;for(t.row=r.first_cell.row;t.row<=r.last_cell.row;t.row++,i-=n)if(n=this.RowHeight(t.row),n>i)return t;return t}return t}CoordinateToColumnHeader(e){let t={row:1/0,column:0};if(this.view.active_sheet.freeze.columns&&this.frozen_column_tiles[0].pixel_end.x>=e-this.scroll_reference_node.scrollLeft){let r=0;e-=this.scroll_reference_node.scrollLeft;for(let i=0;i<this.view.active_sheet.freeze.columns;i++)if(r+=this.ColumnWidth(i),r>=e)return t.column=i,t}for(let r of this.column_header_tiles)if(r.pixel_end.x>=e){let i=e-r.pixel_start.x,n=0;for(t.column=r.first_cell.column;t.column<=r.last_cell.column;t.column++,i-=n)if(n=this.ColumnWidth(t.column),n>i)return t;return t}return t}PointToAddress_Grid(e,t=!1,r=!0){if(r){if(this.view.active_sheet.freeze.rows){let s=this.frozen_row_tiles[0].logical_size.height;e.y-this.scroll_reference_node.scrollTop<s&&(e.y-=this.scroll_reference_node.scrollTop)}if(this.view.active_sheet.freeze.columns){let s=this.frozen_column_tiles[0].logical_size.width;e.x-this.scroll_reference_node.scrollLeft<s&&(e.x-=this.scroll_reference_node.scrollLeft)}}let i={row:0,column:0},n=this.grid_tiles[this.grid_tiles.length-1],a=n[n.length-1];if(e.y>a.pixel_end.y){let s=e.y-a.pixel_end.y;for(i.row=a.last_cell.row;s>0;)i.row++,s-=this.default_row_height}else for(let s of n)if(s.pixel_start.y<=e.y&&s.pixel_end.y>=e.y){let o=e.y-s.pixel_start.y,l=0;for(i.row=s.first_cell.row;i.row<=s.last_cell.row&&(l=this.RowHeight(i.row),!(l>o));i.row++,o-=l);break}if(e.x>a.pixel_end.x){let s=e.x-a.pixel_end.x;for(i.column=a.last_cell.column;s>0;)i.column++,s-=this.default_column_width}else for(let s of this.grid_tiles)if(s[0].pixel_start.x<=e.x&&s[0].pixel_end.x>=e.x){let o=s[0],l=e.x-o.pixel_start.x,d=0;for(i.column=o.first_cell.column;i.column<=o.last_cell.column&&(d=this.ColumnWidth(i.column),!(d>l));i.column++,l-=d);break}return i}AdjacentTile(e,t=0,r=0){if(!t&&!r)return e;let i=e.tile_position,n=e.tile_position.row+t,a=e.tile_position.column+r;if(!(n<0||a<0)){if(this.grid_tiles[i.column]&&this.grid_tiles[i.column][i.row]===e&&this.grid_tiles[a])return this.grid_tiles[a][n];if(!i.column&&this.frozen_column_tiles[i.row]===e)return this.frozen_column_tiles[n];if(!i.row&&this.frozen_row_tiles[i.column]===e)return this.frozen_row_tiles[a]}}UpdateTiles(){if(!this.container)throw new Error("invalid container");this.grid_tiles.forEach(w=>{w.forEach(x=>{x.parentElement&&x.parentElement.removeChild(x)})});for(let w of[this.column_header_tiles,this.row_header_tiles,this.frozen_row_tiles,this.frozen_column_tiles])for(let x of w)x.parentElement&&x.parentElement.removeChild(x);this.frozen_row_tiles=[],this.frozen_column_tiles=[],this.row_header_tiles=[],this.column_header_tiles=[],this.grid_tiles=[];let e=this.view.active_sheet;this.default_row_height=Math.round(e.default_row_height*this.scale),this.default_column_width=Math.round(e.default_column_width*this.scale),this.header_offset={x:Math.round(e.header_offset.x*this.scale),y:Math.round(e.header_offset.y*this.scale)},this.UpdateContainingGrid();let t=this.view.active_sheet.rows,r=this.view.active_sheet.columns;t||(t=100),r||(r=40);let i=0,n=0;for(let w=0;w<t;w++)i+=this.RowHeight(w);for(let w=0;w<r;w++)n+=this.ColumnWidth(w);if(!n||!i)throw"unexpected missing total size";if(i||(i=this.default_row_height*t),n||(n=this.default_column_width*r),this.container.clientWidth>n+this.header_size.width){let w=Math.ceil((this.container.offsetWidth-n)/this.default_column_width);n+=w*this.default_column_width,r+=w}if(this.last_column=r,this.container.clientHeight>i+this.header_size.height){let w=Math.ceil((this.container.offsetHeight-i)/this.default_row_height);i+=w*this.default_row_height,t+=w}this.column_header.style.width=this.contents.style.width=`${n}px`,this.row_header.style.height=this.contents.style.height=`${i}px`;let a=[],s=[],o=0,l=0;for(let w=0;w<r;w++){let x=this.ColumnWidth(w);o&&o+x>this.default_tile_size.width&&(a.push(o),s.push(l),l=w,o=0),o+=x}a.push(o),s.push(l);let d=[],h=[],u=0,m=0;for(let w=0;w<t;w++){let x=this.RowHeight(w);u&&u+x>this.default_tile_size.height&&(d.push(u),h.push(m),u=0,m=w),u+=x}d.push(u),h.push(m);let f=a.length,p=d.length,g=0,b=0,v=0,_=0;for(let w=0;w<this.view.active_sheet.freeze.rows;w++)v+=this.RowHeight(w);for(let w=0;w<this.view.active_sheet.freeze.columns;w++)_+=this.ColumnWidth(w);for(let w=0;w<f;w++){let x=[];g=0;let A=w===f-1?r-s[w]:s[w+1]-s[w];this.column_header_tiles.push(this.CreateTile("column-header-tile",{height:this.header_offset.y,width:a[w]},{row:0,column:w},{row:0,column:s[w]},{rows:0,columns:A},{x:b,y:0},this.column_header)),this.view.active_sheet.freeze.rows&&this.frozen_row_tiles.push(this.CreateTile("frozen-row-tile",{height:v,width:a[w]},{row:1,column:w},{row:0,column:s[w]},{rows:0,columns:A},{x:b,y:0},this.column_header));for(let k=0;k<p;k++){let S=k===p-1?t-h[k]:h[k+1]-h[k];w||(this.row_header_tiles.push(this.CreateTile("row-header-tile",{height:d[k],width:this.header_offset.x},{row:k,column:0},{row:h[k],column:0},{rows:S,columns:1},{x:0,y:g},this.row_header)),this.view.active_sheet.freeze.columns&&this.frozen_column_tiles.push(this.CreateTile("frozen-column-tile",{height:d[k],width:_},{row:k,column:1},{row:h[k],column:0},{rows:S,columns:1},{x:0,y:g},this.row_header))),x.push(this.CreateTile("grid-tile",{height:d[k],width:a[w]},{row:k,column:w},{row:h[k],column:s[w]},{rows:S,columns:A},{x:b,y:g},this.contents)),g+=d[k]}this.grid_tiles.push(x),b+=a[w]}this.total_height=i,this.total_width=n,this.ClearLayoutCaches(),this.UpdateGridTemplates(!0,!0)}ClearLayoutCaches(){this.row_cache=[],this.column_cache=[]}TileIndexForColumn(e){for(let t of this.column_header_tiles)if(t.first_cell.column<=e&&t.last_cell.column>=e)return t.tile_position.column;return-1}TileIndexForRow(e){for(let t of this.row_header_tiles)if(t.first_cell.row<=e&&t.last_cell.row>=e)return t.tile_position.row;return-1}DirtyHeaders(e){if(e){for(let t of this.column_header_tiles){if(t.dirty)continue;let r=new y({row:e.start.row,column:t.first_cell.column},{row:e.start.row,column:t.last_cell.column});(e.entire_row||r.Intersects(e))&&(t.dirty=!0)}for(let t of this.row_header_tiles){if(t.dirty)continue;let r=new y({column:e.start.column,row:t.first_cell.row},{column:e.start.column,row:t.last_cell.row});(e.entire_column||r.Intersects(e))&&(t.dirty=!0)}}}DirtyAll(){for(let e of this.grid_tiles)for(let t of e)t.dirty=!0}DirtyArea(e){if(this.initialized){Array.isArray(e)||(e=[e]);for(let t of e){let r={row:0,column:0},i={row:this.grid_tiles[0].length-1,column:this.grid_tiles.length-1};t.start.column!==1/0&&(r.column=i.column=this.TileIndexForColumn(t.start.column),t.end.column!==t.start.column&&(i.column=this.TileIndexForColumn(t.end.column))),t.start.row!==1/0&&(r.row=i.row=this.TileIndexForRow(t.start.row),t.end.row!==t.start.row&&(i.row=this.TileIndexForRow(t.end.row)));for(let n=r.column;n<=i.column;n++)for(let a=r.row;a<=i.row;a++)this.grid_tiles[n][a].dirty=!0}}}VisibleTiles(){let e=[{row:0,column:0},{row:0,column:0}];if(!this.container||!this.grid_tiles.length||!this.grid_tiles[0].length)return new y(e[0],e[1]);let t=this.scroll_reference_node.scrollLeft,r=t+this.scroll_reference_node.offsetWidth,i=this.scroll_reference_node.scrollTop,n=i+this.scroll_reference_node.offsetHeight;for(let a of this.grid_tiles){let s=a[0];if(s.pixel_start.x<=t&&s.pixel_end.x>=t){for(s of a)if(s.pixel_start.y<=i&&s.pixel_end.y>=i){e[0]=s.tile_position;break}}if(a===this.grid_tiles[this.grid_tiles.length-1]||s.pixel_start.x<=r&&s.pixel_end.x>=r){for(s of a)if(s===a[a.length-1]||s.pixel_start.y<=n&&s.pixel_end.y>=n)return e[1]=s.tile_position,new y(e[0],e[1])}}return new y(e[0],e[1])}UpdateTileHeights(e=!0,t=-1){let r=0;for(let i=0;i<this.row_header_tiles.length;i++){let n=this.row_header_tiles[i];if(t>n.last_cell.row){r+=n.logical_size.height;continue}let a=0;for(let o=n.first_cell.row;o<=n.last_cell.row;o++)a+=this.RowHeight(o);let s=n.logical_size.height===a;if(n.pixel_start.y=r,r+=a,n.pixel_end.y=r,!s){if(n.logical_size.height=a,n.style.height=`${a}px`,n.height=this.dpr*a,this.view.active_sheet.freeze.columns){let o=this.frozen_column_tiles[i];o.logical_size.height=a,o.style.height=`${a}px`,o.height=this.dpr*a}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let o of this.grid_tiles){let l=o[i];l.pixel_start.y=n.pixel_start.y,l.pixel_end.y=n.pixel_end.y,s||(l.logical_size.height=a,l.style.height=`${a}px`,l.height=this.dpr*a,e&&(l.dirty=!0,l.needs_full_repaint=!0))}}if(this.view.active_sheet.freeze.rows){let i=0;for(let n=0;n<this.view.active_sheet.freeze.rows;n++)i+=this.RowHeight(n);for(let n of this.frozen_row_tiles)n.style.height=`${i}px`,n.height=i*this.dpr;i+=this.header_offset.y,this.corner_canvas.style.height=`${i}px`,this.corner_canvas.height=i*this.dpr;for(let n of this.grid_tiles)n[0].dirty=!0}this.UpdateGridTemplates(!1,!0),this.row_header.style.height=this.contents.style.height=`${r}px`,this.ClearLayoutCaches()}UpdateTileWidths(e=!0,t=-1){let r=0;for(let i=0;i<this.column_header_tiles.length;i++){let n=this.column_header_tiles[i],a=this.grid_tiles[i];if(t>n.last_cell.column){r+=n.logical_size.width;continue}let s=0;for(let l=n.first_cell.column;l<=n.last_cell.column;l++)s+=this.ColumnWidth(l);let o=n.logical_size.width===s;if(n.pixel_start.x=r,r+=s,n.pixel_end.x=r,!o){if(n.logical_size.width=s,n.style.width=`${s}px`,n.width=this.dpr*s,this.view.active_sheet.freeze.rows){let l=this.frozen_row_tiles[i];l.logical_size.width=s,l.style.width=`${s}px`,l.width=this.dpr*s}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let l of a)l.pixel_start.x=n.pixel_start.x,l.pixel_end.x=n.pixel_end.x,o||(l.logical_size.width=s,l.style.width=`${s}px`,l.width=this.dpr*s,e&&(l.dirty=!0,l.needs_full_repaint=!0))}if(this.view.active_sheet.freeze.columns){let i=0;for(let n=0;n<this.view.active_sheet.freeze.columns;n++)i+=this.ColumnWidth(n);for(let n of this.frozen_column_tiles)n.style.width=`${i}px`,n.width=i*this.dpr;i+=this.header_offset.x,this.corner_canvas.style.width=`${i}px`,this.corner_canvas.width=i*this.dpr;for(let n of this.grid_tiles[0])n.dirty=!0}this.UpdateGridTemplates(!0,!1),this.column_header.style.width=this.contents.style.width=`${r}px`,this.ClearLayoutCaches()}ClampToGrid(e){let t=this.PointToAddress_Grid(e),r=this.OffsetCellAddressToRectangle(t);return e.x>r.left+r.width/2?e.x=r.left+r.width-1:e.x=r.left-1,e.y>r.top+r.height/2?e.y=r.top+r.height-1:e.y=r.top-1,e}OffsetCellAddressToRectangle(e){let t=this.CellAddressToRectangle(e);return e.column>=0&&e.column<this.view.active_sheet.freeze.columns&&(t=t.Shift(this.scroll_reference_node.scrollLeft,0)),e.row>=0&&e.row<this.view.active_sheet.freeze.rows&&(t=t.Shift(0,this.scroll_reference_node.scrollTop)),t}CellAddressToRectangle(e){let t=e.row===1/0||e.row<0?0:e.row,r=e.column===1/0||e.column<0?0:e.column;if(this.column_cache.length<=r+1){this.column_cache.length||(this.column_cache[0]=0);for(let a=this.column_cache.length-1;a<=r;a++)this.column_cache[a+1]=this.column_cache[a]+this.ColumnWidth(a)}if(this.row_cache.length<=t+1){this.row_cache.length||(this.row_cache[0]=0);for(let a=this.row_cache.length-1;a<=t;a++)this.row_cache[a+1]=this.row_cache[a]+this.RowHeight(a)}let i=this.column_cache[r],n=this.row_cache[t];return new H(i,n,this.column_cache[r+1]-i,this.row_cache[t+1]-n)}ResizeTileWidth(e,t,r=!0){let i=this.column_header_tiles[e],n=t-i.logical_size.width;i.logical_size.width=t,i.style.width=`${t}px`,i.width=this.dpr*t,i.pixel_end.x+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let s=e+1;s<this.column_header_tiles.length;s++){this.column_header_tiles[s].pixel_start.x+=n,this.column_header_tiles[s].pixel_end.x+=n;for(let o of this.grid_tiles[s])o.pixel_start.x+=n,o.pixel_end.x+=n}let a=this.grid_tiles[e];for(i of a)i.logical_size.width=t,i.style.width=`${t}px`,i.width=this.dpr*t,i.pixel_end.x+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);this.UpdateTotalSize(),this.UpdateGridTemplates(!0,!1),this.UpdateContentsSize()}ResizeTileHeight(e,t,r=!0){let i=this.row_header_tiles[e],n=t-i.logical_size.height;i.logical_size.height=t,i.style.height=`${t}px`,i.height=this.dpr*t,i.pixel_end.y+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let a=e+1;a<this.row_header_tiles.length;a++)i=this.row_header_tiles[a],i.pixel_start.y+=n,i.pixel_end.y+=n;for(let a of this.grid_tiles){i=a[e],i.logical_size.height=t,i.style.height=`${t}px`,i.height=this.dpr*t,i.pixel_end.y+=n,r&&(i.dirty=!0,i.needs_full_repaint=!0);for(let s=e+1;s<a.length;s++)a[s].pixel_start.y+=n,a[s].pixel_end.y+=n}this.UpdateTotalSize(),this.UpdateGridTemplates(!1,!0),this.UpdateContentsSize()}};var Tt=class extends Oe{constructor(e,t){super(e,t,!0)}InitializeInternal(e,t){}UpdateGridTemplates(e,t){}UpdateTileGridPosition(e){}UpdateContainingGrid(){}ResizeCursor(e){}};var Rt=class extends Oe{constructor(e,t,r){super(e,t,!1,r),this.column_header=r.Div("treb-top-header"),this.row_header=r.Div("treb-left-header"),this.corner=r.Div("treb-corner"),this.corner_canvas=r.Create("canvas"),this.corner.appendChild(this.corner_canvas),this.contents=r.Div("treb-contents"),this.buffer_canvas=r.Create("canvas","treb-buffer-canvas",this.contents),this.grid_selection=r.SVG("svg","treb-grid-selection",this.contents),this.row_header_selection=r.SVG("svg",["frozen-selection","frozen-selection-rows"],this.column_header),this.row_header_annotations=r.Div("frozen-annotation-container frozen-annotation-container-rows",this.column_header),this.column_header_selection=r.SVG("svg",["frozen-selection","frozen-selection-columns"],this.row_header),this.column_header_annotations=r.Div("frozen-annotation-container frozen-annotation-container-columns",this.row_header),this.corner_selection=r.SVG("svg","frozen-selection",this.corner),this.corner_annotations=r.Div("frozen-annotation-container frozen-annotation-container-corner",this.corner),this.annotation_container=r.Div("treb-annotation-container"),this.grid_cover=r.Div("tile-cover grid-cover"),this.column_header_cover=r.Div("tile-cover column-header-cover"),this.row_header_cover=r.Div("tile-cover row-header-cover")}InitializeInternal(e,t){this.container=e,this.scroll_reference_node=this.container,e.appendChild(this.column_header),e.appendChild(this.row_header),e.appendChild(this.corner),e.appendChild(this.contents),e.appendChild(this.annotation_container),e.appendChild(this.grid_cover),e.appendChild(this.column_header_cover),e.appendChild(this.row_header_cover),e.appendChild(this.mock_selection),this.container.addEventListener("scroll",()=>t())}ResizeCursor(e){switch(e){case"row":this.row_header_cover.classList.add("resize");break;case"column":this.column_header_cover.classList.add("resize");break;default:this.row_header_cover.classList.remove("resize"),this.column_header_cover.classList.remove("resize");break}}UpdateTileGridPosition(e){e.style.gridColumn=`${e.tile_position.column+1} / ${e.tile_position.column+2}`,e.style.gridRow=`${e.tile_position.row+1} / ${e.tile_position.row+2}`}UpdateContainingGrid(){if(!this.container)throw new Error("missing container");this.header_size.width=this.header_offset.x,this.header_size.height=this.header_offset.y;let e=this.header_offset.x,t=this.header_offset.y;if(this.view.active_sheet.freeze.columns)for(let r=0;r<this.view.active_sheet.freeze.columns;r++)e+=this.ColumnWidth(r);if(this.view.active_sheet.freeze.rows)for(let r=0;r<this.view.active_sheet.freeze.rows;r++)t+=this.RowHeight(r);this.container.style.gridTemplateColumns=`${this.header_offset.x}px auto`,this.container.style.gridTemplateRows=`${this.header_offset.y}px auto`,this.corner_canvas.setAttribute("width",`${this.dpr*e}`),this.corner_canvas.setAttribute("height",`${this.dpr*t}`),this.column_header.style.height=`${t}px`,this.corner_canvas.style.width=`${e}px`,this.corner_canvas.style.height=`${t}px`}UpdateGridTemplates(e=!0,t=!0){let r=0,i=0;this.column_header.style.gridTemplateColumns=this.contents.style.gridTemplateColumns=this.column_header_tiles.map(l=>(r+=l.logical_size.width,`${l.logical_size.width}px`)).join(" "),this.column_header.style.gridTemplateRows=`${this.header_offset.y}px auto`,this.row_header.style.gridTemplateRows=this.contents.style.gridTemplateRows=this.row_header_tiles.map(l=>(i+=l.logical_size.height,`${l.logical_size.height}px`)).join(" ");let n=this.header_offset.y;if(this.view.active_sheet.freeze.rows)for(let l=0;l<this.view.active_sheet.freeze.rows;l++)n+=this.RowHeight(l);this.column_header.style.height=`${n}px`,this.row_header_selection.style.display="block",this.row_header_selection.style.width=`${r}px`,this.corner_selection.style.height=this.row_header_selection.style.height=`${n}px`,this.corner_selection.style.top=this.row_header_selection.style.top="0px",this.row_header_selection.style.left="0px";let a=this.header_offset.x;if(this.view.active_sheet.freeze.columns)for(let l=0;l<this.view.active_sheet.freeze.columns;l++)a+=this.ColumnWidth(l);this.column_header_selection.style.display="block",this.corner_selection.style.width=this.column_header_selection.style.width=`${a}px`,this.column_header_selection.style.height=`${i}px`,this.column_header_selection.style.top="0px",this.corner_selection.style.left=this.column_header_selection.style.left="0px";let s={x:this.view.active_sheet.header_offset.x*this.scale,y:this.view.active_sheet.header_offset.y*this.scale},o=this.view.active_sheet.freeze;o.rows&&o.columns?(this.row_header_annotations.style.display="block",this.column_header_annotations.style.display="block",this.corner_annotations.style.display="block"):o.rows?(this.row_header_annotations.style.display="block",this.column_header_annotations.style.display="none",this.corner_annotations.style.display="none"):o.columns?(this.row_header_annotations.style.display="none",this.column_header_annotations.style.display="block",this.corner_annotations.style.display="none"):(this.row_header_annotations.style.display="none",this.column_header_annotations.style.display="none",this.corner_annotations.style.display="none"),this.row_header_annotations.style.width=`${r}px`,this.corner_annotations.style.height=this.row_header_annotations.style.height=`${n-s.y}px`,this.corner_annotations.style.top=this.row_header_annotations.style.top=`${s.y}px`,this.column_header_annotations.style.width=this.corner_annotations.style.width=`${a-s.x}px`,this.column_header_annotations.style.height=`${i}px`,this.corner_annotations.style.left=this.column_header_annotations.style.left=`${s.x}px`,this.corner_selection.style.display="block",this.grid_selection.style.width=`${r}px`,this.grid_selection.style.height=`${i}px`,this.grid_selection.style.top=`${this.header_offset.y}px`,this.grid_selection.style.left=`${this.header_offset.x}px`,this.annotation_container.style.width=`${r}px`,this.annotation_container.style.height=`${i}px`,this.annotation_container.style.top=`${this.header_offset.y}px`,this.annotation_container.style.left=`${this.header_offset.x}px`}};var Et=class{function_names=[];argument_separator=D.argument_separator.charCodeAt(0);function_map={};RemoveFunctions(e){Array.isArray(e)||(e=[e]);let t=Object.keys(this.function_map).map(r=>this.function_map[r]);for(let r of e)t=t.filter(i=>i.name!==r.name);this.SetFunctions(t)}AddFunctions(e){Array.isArray(e)||(e=[e]);let t=Object.keys(this.function_map).map(r=>this.function_map[r]).concat(...e);this.SetFunctions(t)}SetFunctions(e){this.function_map={},this.function_names=e.map(t=>(this.function_map[t.name.toLowerCase()]=t,t.name)).sort((t,r)=>t.toLowerCase().localeCompare(r.toLowerCase()))}NormalizeIdentifier(e){let t=this.function_map[e.toLowerCase()];return t?t.name:void 0}Exec(e){if(e.text[0]!=="=")return{};let t,r={};if(e.cursor===e.text.length&&(t=e.text.match(/(?:^|[^A-Za-z_\d])([A-Za-z_][\w\d_.]*)\s*$/),t)){let n=t[1],a=new RegExp("^"+n.replace(".","\\."),"i");r={completions:this.function_names.filter(o=>a.test(o)).map(o=>this.function_map[o.toLowerCase()]),token:n,position:e.cursor-n.length}}let i=this.ParseTooltip(e.text.substr(0,e.cursor));if(i.function){let n=this.function_map[i.function.toLowerCase()];n&&(r.tooltip='<span class="notranslate">'+n.name+"</span>",r.arguments="("+(n.arguments||[]).map((a,s)=>{let o=a.name||"argument";return s===i.argument?`<span class="active-argument">${o}</span>`:o}).join(D.argument_separator+" ")+")",r.description=n.description?`<span class="function-description">${n.description}</span>`:"",r.function_position=i.position||0)}return r}ParseTooltip(e){let t=[],r=0,i="",n=!1,a=0;for(let o of e){let l=o.charCodeAt(0);if(n)l===34&&(n=!1);else switch(l){case 40:t.push({buffer:i.trim(),argument:r,position:a-i.length}),i="",r=0;break;case this.argument_separator:r++;break;case 41:r=t.pop()?.argument||0;break;case 34:i="",n=!0;break;default:l>=97&&l<=122||l>=65&&l<=90||l>=48&&l<=57||l===95||l===46?i+=o:i=""}a++}let s=t.pop();return{function:s?.buffer||void 0,position:s?.position||0,argument:r}}};var Me=class c extends oe{constructor(t,r,i){super();this.model=t;this.view=r;this.autocomplete=i;this.parser=t.parser}static FormulaChars=("$^&*(-+={[<>/~%"+D.argument_separator).split("");active_cell;autocomplete_matcher;container_node;active_editor;nodes=[];target_address;assume_formula=!1;text_formula=!1;get selecting(){if(this.assume_formula)return!0;if(!this.text_formula)return!1;if(this.active_editor&&this.active_editor.node===this.active_editor.node.ownerDocument.activeElement){let t=this.active_editor.node.ownerDocument.defaultView,r=t.getSelection();if(r?.rangeCount){let a=r?.getRangeAt(0);if((a?.endContainer instanceof t.HTMLElement?a.endContainer:a.endContainer?.parentElement)?.dataset.reference!==void 0)return!0;if(a?.startContainer instanceof t.Text){let o=(a.startContainer.textContent?.substring(0,a.startOffset)||"").trim();if(o.length&&c.FormulaChars.includes(o[o.length-1]))return!0}else console.info("mark 21",a)}let n=this.SubstringToCaret2(this.active_editor.node)[1].trim();if(n.length){let a=n[n.length-1];return c.FormulaChars.includes(a)}}return!1}composite_dependencies=[];get dependencies(){return this.composite_dependencies}parser;FocusEditor(){this.active_editor&&this.active_editor.node.focus()}RegisterListener(t,r,i){t.node.addEventListener(r,i),t.listeners||(t.listeners=new Map),t.listeners.set(r,i)}SelectAll(t){let i=t.ownerDocument.defaultView.getSelection(),n=t.ownerDocument.createRange();n.selectNode(t),i?.removeAllRanges(),i?.addRange(n)}SetCaret(t,r){let i=t.node.ownerDocument,n=i?.defaultView,a=n.getSelection(),s=i?.createRange(),o=d=>{let h=d;for(;h&&!(h instanceof n.Text)&&h.firstChild;)h=h.firstChild;return h},l=o(t.node);if(r){let d=o(r.node);a&&s&&(s.setStart(l,t.offset),s.setEnd(d,r.offset),a.removeAllRanges(),a.addRange(s))}else a&&s&&(s.setStart(l,t.offset),s.setEnd(l,t.offset),s.collapse(!0),a.removeAllRanges(),a.addRange(s))}InsertReference(t,r){if(!this.active_editor)return;let i=this.active_editor.node.ownerDocument.defaultView,n=i.getSelection();if(!n)throw new Error("error getting selection");if(n.rangeCount===0)return"";let a=n.getRangeAt(0),s=this.active_editor.node.textContent||"";if(a.startContainer instanceof i.Text)if(!a.collapsed&&a.startOffset<a.endOffset){let o=this.SubstringToCaret2(this.active_editor.node);this.active_editor.node.textContent=o[0]+t+s.substring(o[1].length),this.SetCaret({node:this.active_editor.node,offset:o[0].length},{node:this.active_editor.node,offset:o[0].length+t.length})}else{let o=a.startContainer.parentElement;if(o instanceof i.HTMLElement&&o.dataset.reference)o.textContent=t,this.SetCaret({node:o,offset:t.length});else{let l=this.SubstringToCaret2(this.active_editor.node)[1],d="",h="",u=l.trim();if(u.length){let m=u[u.length-1];c.FormulaChars.includes(m)||(l.length===u.length?d=" +":d="+")}this.active_editor.node.textContent=l+d+t+s.substring(l.length),this.SetCaret({node:this.active_editor.node,offset:l.length+t.length+d.length})}}else a.startContainer instanceof i.HTMLElement?(a.startContainer.textContent=t,this.SetCaret({node:a.startContainer,offset:t.length})):console.warn("unexpected range start container",a.startContainer);this.UpdateText(this.active_editor),this.UpdateColors(),this.active_editor.node.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}UpdateColors(t=!1){let r=new Map,i=new Map;for(let a of this.nodes)for(let s of a.references||[]){let o=this.model.AddressToLabel(s);r.has(o)||(r.set(o,s),i.set(o,i.size))}for(let a of this.nodes){for(let s of Array.from(a.node.childNodes)){let o=s.ownerDocument?.defaultView;if(o&&s instanceof o.HTMLElement&&s.dataset.reference){let l=i.get(s.dataset.reference);s.dataset.highlightIndex=typeof l=="number"?(l%5+1).toString():"?"}}a.check=a.node.innerHTML.length}let n=Array.from(r.values());!t&&JSON.stringify(this.composite_dependencies)===JSON.stringify(n)||(this.composite_dependencies=n,this.Publish({type:"update",dependencies:this.composite_dependencies}))}UpdateDependencies(t,r){let i=[];for(let o of r.full_reference_list||[])switch(o.type){case"address":case"range":{let l=o.type==="range"?o.start:o;l.sheet_id||(l.sheet?l.sheet_id=this.model.sheets.Find(l.sheet)?.id||0:l.sheet_id=this.view.active_sheet.id),i.push(o);break}case"structured-reference":if(this.target_address){let l=this.model.ResolveStructuredReference(o,this.target_address);l&&i.push(l)}else console.info("target address not set");break;case"identifier":{let l=this.model.named_ranges.Get(o.name);l&&(l.count===1?i.push({type:"address",...l.start,label:o.name,position:o.position,id:o.id}):i.push({type:"range",start:{type:"address",position:o.position,id:o.id,label:o.name,...l.start},end:{type:"address",position:o.position,label:o.name,id:o.id,...l.end},label:o.name,position:o.position,id:o.id}));break}}i.sort((o,l)=>o.position-l.position);let n=[],a=new Set,s=new Map;for(let o of i){let l=this.model.AddressToLabel(o,this.view.active_sheet),d=N(o)?new y(o):new y(o.start,o.end);a.has(l)||(n.push(d),a.add(l)),s.set(o,l)}return this.UpdateReferences(t,n),s}UpdateReferences(t,r=[]){t.node.dataset.references=JSON.stringify(r.map(i=>this.model.AddressToLabel(i))),t.references=r}UpdateText(t,r={}){let i=t.node,n=i.textContent||"",a=F.GetInstance(i.ownerDocument);if(this.text_formula=n[0]==="=",this.active_editor&&!this.assume_formula&&(this.active_editor.node.spellcheck=!this.text_formula),n===t.formatted_text)return;let[s,o]=this.SubstringToCaret2(i),l=s.length,d=o.length;if(l===0&&d===0&&(d=n.length),!n)this.UpdateReferences(t);else{let u=this.parser.Parse(n);if(u.expression){let m=this.UpdateDependencies(t,u),f=n[0]==="="?1:0,p=0,g,b,v=0,_,w=a.Fragment(),x=(A,k="text",S="",M=!1)=>{let V=a.Text(A);if((M||(l>v||l===0&&v===0)&&l<=v+A.length)&&(g={offset:l-v,node:V}),d>v&&d<=v+A.length&&(b={offset:d-v,node:V}),k!=="text"){let W=a.Create("span",k);S&&(W.dataset.reference=S),W.appendChild(V),w.appendChild(W)}else w.appendChild(V);_=V,v+=A.length};this.parser.Walk(u.expression,A=>{if(A.type==="missing"||A.type==="group"||A.type==="dimensioned")return!0;let k=A.position+f,S=n.substring(p,k),M="",V=A.type,W="";switch(A.type){case"identifier":case"call":M=n.substring(k,k+A.name.length);break;case"literal":if(typeof A.value=="string")M=n.substring(k,k+A.value.length+2),V="string";else return!1;break;case"address":case"range":case"structured-reference":W=m.get(A)||"???",M=r.rewrite_addresses?A.label:n.substring(k,k+A.label.length);break;default:return!0}return x(S),x(M,V,W),p=k+M.length,A.type!=="range"}),p<n.length&&x(n.substring(p)),g||(_?g={node:_,offset:(_.data||"").length}:x("",void 0,"",!0)),i.textContent="",i.appendChild(w),g&&!r.format_only&&i===this.active_editor?.node&&this.SetCaret(g,b)}}t.formatted_text=n;let h=this.autocomplete_matcher;h&&Promise.resolve().then(()=>{let u=h.Exec({text:n,cursor:o.length}),m=this.NodeAtIndex(u.completions?.length?u.position||0:u.function_position||0);this.Autocomplete(u,m)})}NodeAtIndex(t){let r=this.active_editor?.node.childNodes||[];for(let i=0;i<r.length;i++){let n=r[i].textContent?.length||0;if(n>t)return r[i];t-=n}}AcceptAutocomplete(t){if(!this.active_editor)return;let r=0;if(t.data&&t.data.completions){for(let d of t.data.completions)if(d.name.toLowerCase()===t.value?.toLowerCase()){r=d.type||0;break}}let i=t.data?.position||0,n=i+(t.data?.token?.length||0),a=r===1?t.value:t.value+"(",s=this.active_editor.node.textContent||"",o=s.substring(0,i)+a,l=o.length;o+=s.substring(n),this.active_editor.node.textContent=o,this.SetCaret({node:this.active_editor.node,offset:l}),this.autocomplete?.Hide(),this.UpdateText(this.active_editor),this.UpdateColors()}Autocomplete(t,r){if(!this.container_node||!this.autocomplete)return;let i;r?.nodeType===Node.ELEMENT_NODE?i=r.getBoundingClientRect():i=this.container_node.getBoundingClientRect();let n=new H(Math.round(i.left),Math.round(i.top),i.width,i.height);this.autocomplete.Show(this.AcceptAutocomplete.bind(this),t,n)}SubstringToCaret2(t){let r=["",""];if(t!==t.ownerDocument.activeElement||t!==this.active_editor?.node)return r;let n=t.ownerDocument.defaultView,a=[!1,!1],s=(l,d)=>{if(l===d.startContainer&&l===d.endContainer&&!(l instanceof n.Text)){a[0]=a[1]=!0,r[0]+=l.textContent,r[1]+=l.textContent;return}if(l===d.startContainer&&(r[0]+=(l.textContent||"").substring(0,d.startOffset),a[0]=!0),l===d.endContainer&&(r[1]+=(l.textContent||"").substring(0,d.endOffset),a[1]=!0),!(a[0]&&a[1])){if(l instanceof n.Text){let h=l.textContent||"";a[0]||(r[0]+=h),a[1]||(r[1]+=h)}else if(l.hasChildNodes()){for(let h of Array.from(l.childNodes))if(s(h,d),a[0]&&a[1])return}}},o=n.getSelection();if(o?.rangeCount??0>0){let l=o?.getRangeAt(0);l&&s(t,l)}return r}};var Nn=typeof navigator>"u"?"":navigator.appVersion,we=typeof navigator>"u"?"":navigator.userAgent,yr=class{is_edge=/Edge/.test(Nn);is_ipad=/iPad|iPhone/.test(we);is_android=/android|samsung/i.test(we);is_mobile=this.is_ipad||this.is_android;is_firefox=/firefox/i.test(we);is_safari=/safari/i.test(we)&&!/edg/i.test(we);is_mac=/macintosh/i.test(we);is_chrome=/Chrome/i.test(we);is_windows=/win64|win32|windows\s+nt/i.test(we);is_modern=!this.is_edge&&!(this.is_firefox&&this.is_android)&&/webkit|firefox/i.test(we)},Un={is_edge:!1,is_ipad:!1,is_android:!1,is_firefox:!1,is_safari:!1,is_mac:!1,is_chrome:!1,trident:!1,is_windows:!1,is_modern:!0,is_node:!0,is_mobile:!1},re=typeof navigator>"u"?Un:new yr;var Mt=class extends Me{constructor(t,r,i,n,a){super(i,n,a);this.container=t;this.theme=r;this.container_node=t.querySelector(".treb-overlay-container"),this.edit_node=this.container_node.querySelector(".treb-overlay-editor"),re.is_firefox&&this.edit_node.classList.add("firefox"),this.edit_node.inputMode="none";let s={node:this.edit_node};this.nodes=[s],this.active_editor=s,this.RegisterListener(s,"input",o=>{if(o instanceof InputEvent&&o.isComposing)return;if(!o.isTrusted){this.reset_selection=!0;return}this.reset_selection&&this.Publish({type:"reset-selection"});let l=this.edit_node.firstChild;l&&l.tagName==="BR"&&this.edit_node.removeChild(l),this.editing&&(this.UpdateText(s),this.UpdateColors())}),this.RegisterListener(s,"keyup",o=>{o.isComposing||!this.editing||this.autocomplete&&this.autocomplete.HandleKey("keyup",o).handled}),this.edit_inset=this.container_node.querySelector(".treb-overlay-inset"),this.ClearContents()}internal_selection={target:{row:0,column:0},area:new y({row:0,column:0})};get selection(){return this.internal_selection}set selection(t){if(t){let r=t.target||t.area.start;this.internal_selection={target:{row:r.row,column:r.column},area:new y(t.area.start,t.area.end)}}else{let r={row:0,column:0};this.internal_selection={target:r,area:new y(r)}}}reset_selection=!1;edit_node;container_node;edit_inset;scale=1;internal_editing=!1;get editing(){return this.internal_editing}set editing(t){this.internal_editing!==t&&(this.internal_editing=t,t?(this.container_node.style.opacity="1",this.container_node.style.pointerEvents="initial"):(this.container_node.style.opacity="0",this.container_node.style.pointerEvents="none"))}UpdateCaption(t=""){this.edit_node.setAttribute("aria-label",t)}Focus(t=""){this.edit_node!==this.edit_node.ownerDocument.activeElement&&(this.container_node.style.top=`${this.container.scrollTop+this.view.active_sheet.header_offset.y}px`,this.container_node.style.left=`${this.container.scrollLeft+this.view.active_sheet.header_offset.x}px`),this.edit_node.focus(),this.UpdateCaption(t)}CloseEditor(){this.editing=!1,this.reset_selection=!1,this.ClearContents(),this.edit_node.spellcheck=!0,this.autocomplete?.Hide(),this.active_cell=void 0}ClearContents(){re.is_firefox?this.edit_node.innerHTML="<span></span>":this.edit_node.textContent=""}Edit(t,r,i,n,a){this.Publish({type:"start-editing",editor:"ice"}),this.active_cell=i,this.target_address={...t.target},this.reset_selection=!1;let s=i.style||{};switch(this.edit_node.style.font=U.Font(s,this.scale),this.edit_node.style.color=R(this.theme,s.text,1),this.edit_inset.style.backgroundColor=R(this.theme,s.fill,0),s.horizontal_align){case"right":this.container_node.classList.remove("align-center","align-left"),this.container_node.classList.add("align-right");break;case"center":this.container_node.classList.remove("align-right","align-left"),this.container_node.classList.add("align-center");break;default:this.container_node.classList.remove("align-right","align-center"),this.container_node.classList.add("align-left");break}this.edit_node.style.paddingBottom=`${Math.max(0,(self.devicePixelRatio||1)-1)}px`;let o=n?.toString()||"";if(o&&o[0]==="="&&(this.edit_node.spellcheck=!1),r.ApplyStyle(this.container_node),this.autocomplete?.ResetBlock(),this.selection=t,typeof n<"u"){let l=o[0]!=="="&&o[o.length-1]==="%",d=o.length;this.edit_node.textContent=o,this.SetCaret({node:this.edit_node,offset:d-(l?1:0)})}this.editing=!0,Promise.resolve().then(()=>{this.active_editor&&(this.active_editor.formatted_text=void 0,this.UpdateText(this.active_editor),this.UpdateColors()),!a&&n!==void 0&&this.Publish({type:"update",text:n.toString(),dependencies:this.composite_dependencies})})}HandleKeyDown(t){if(this.editing){if(this.autocomplete){let r=this.autocomplete.HandleKey("keydown",t);if(r.accept&&this.AcceptAutocomplete(r),r.handled)return"handled"}switch(t.key){case"Enter":case"Tab":return"commit";case"Escape":case"Esc":return"discard";case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"Up":case"Down":case"Left":case"Right":return this.selecting?void 0:"handled"}return"handled"}}UpdateScale(t){this.scale=t}};var vr=class{canvas;cache={};constructor(){typeof document<"u"&&(this.canvas=document.createElement("canvas"))}Flush(){this.cache={}}Get(e,t=10){let r=e+";"+t,i=this.cache[r];return i||(i=this.Measure(e,t),this.cache[r]=i,i)}Measure(e,t){let r=e.match(/([\d.]+)((?:%|em))/);if(r){let u=r[1]+r[2],m=Number(r[1])*t;r[2]==="%"&&(m/=100),e=e.replace(u,m+"px")}let i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("invalid context");i.font=e;let n=i.measureText("MMM"),a=Math.ceil(n.width);if(this.canvas.setAttribute("width",a.toString()),this.canvas.setAttribute("height",a.toString()),i=this.canvas.getContext("2d",{willReadFrequently:!0}),!i)throw new Error("invalid context");i.font=e,i.textAlign="center",i.textBaseline="alphabetic",i.fillStyle="#000";let s=Math.round(a*2/3),o=Math.round(a/2);i.clearRect(0,0,a,a);for(let u=32;u<=126;u++){let m=String.fromCharCode(u);i.fillText(m,o,s)}let l=i.getImageData(0,0,this.canvas.width,this.canvas.height).data,d=Math.floor(this.GetFirstIndex(l)/a),h=Math.floor(this.GetLastIndex(l)/a);return{ascender:s-d,descender:h-s,block:h-d+1,paren:i.measureText("(").width,hash:i.measureText("##").width-i.measureText("#").width}}GetFirstIndex(e){for(let t=3,r=e.length;t<r;t+=4)if(e[t]>0)return(t-3)/4;return e.length}GetLastIndex(e){for(let t=e.length-1;t>=3;t-=4)if(e[t]>0)return t/4;return 0}},It=new vr;var wr="bottom",di=/webkit/i.test(typeof navigator>"u"?"":navigator?.userAgent||"")?1:0,zt=class{constructor(e,t,r,i,n){this.theme=e;this.layout=t;this.model=r;this.view=i;this.options=n;this.buffer_canvas=t.buffer_canvas,this.buffer_canvas.width=this.buffer_canvas_size.width,this.buffer_canvas.height=this.buffer_canvas_size.height;let a=this.buffer_canvas.getContext("2d",{alpha:!1});if(a){let s=this.layout.dpr;this.buffer_context=a,this.buffer_context.setTransform(s,0,0,s,0,0),this.buffer_context.textAlign="left",this.buffer_context.textBaseline=wr}}cell_edge_buffer=4;overflow_areas=[];buffer_canvas;buffer_context;buffer_canvas_size={width:256,height:256};FlushOverflows(){this.view.active_sheet.cells.IterateAll(t=>{t.renderer_data?.overflowed&&(t.renderer_data=void 0,t.render_clean[this.view.view_index]=!1)});for(let t of this.overflow_areas)t.tile.dirty=!0;this.overflow_areas=[]}MeasureText(e,t){let r=this.layout.grid_tiles[0][0].getContext("2d",{alpha:!1});if(!r)throw new Error("invalid context");return t&&(r.font=t),r.measureText(e)}EnsureBuffer(e=0,t=0,r=0){let i=this.layout.dpr;if(e=e*i,t=t*i,r=r*i,e>this.buffer_canvas_size.width||t>this.buffer_canvas_size.height){this.buffer_canvas_size.width=Math.max(Math.ceil(e/256)*256,this.buffer_canvas_size.width),this.buffer_canvas_size.height=Math.max(Math.ceil(t/256)*256,this.buffer_canvas_size.height),this.buffer_canvas.width=this.buffer_canvas_size.width,this.buffer_canvas.height=this.buffer_canvas_size.height;let n=this.buffer_canvas.getContext("2d",{alpha:!1});n&&(this.buffer_context=n,this.buffer_context.textAlign="left",this.buffer_context.textBaseline=wr)}this.buffer_context.setTransform(i,0,0,i,r,0)}OverflowDirty(e=!1){let t=[];for(let r of this.overflow_areas){let i=r.area.start.row,n=e;if(!n)for(let a=r.area.start.column;!n&&a<=r.area.end.column;a++){let s=this.view.active_sheet.cells.GetCell({row:i,column:a},!1);n=!!(s&&!s.render_clean[this.view.view_index])}if(n){for(let a=r.area.start.column;a<=r.area.end.column;a++){let s=this.view.active_sheet.cells.GetCell({row:i,column:a},!1);s&&(s.render_clean[this.view.view_index]=!1,s.renderer_data&&s.renderer_data.overflowed&&(s.renderer_data=void 0))}r.tile.dirty=!0}else t.push(r)}this.overflow_areas=t}RenderCorner(){let t=this.layout.corner_canvas.getContext("2d",{alpha:!1});if(!t)throw new Error("invalid context");let r=It.Get(U.Font(this.theme.headers||{},this.layout.scale)),i=this.layout.dpr,n=this.layout.header_offset,a=n.x;for(let o=0;o<this.view.active_sheet.freeze.columns;o++)a+=this.layout.ColumnWidth(o);let s=n.y;for(let o=0;o<this.view.active_sheet.freeze.rows;o++)s+=this.layout.RowHeight(o);t.setTransform(i,0,0,i,0,0),t.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",t.fillRect(0,0,a,n.y),t.fillRect(0,0,n.x,s),t.strokeStyle=this.theme.headers_grid_color||"",t.beginPath(),t.moveTo(n.x-.5,0),t.lineTo(n.x-.5,n.y),t.moveTo(0,n.y-.5),t.lineTo(n.x,n.y-.5),t.stroke(),!(!this.view.active_sheet.freeze.columns&&!this.view.active_sheet.freeze.rows)&&(t.strokeStyle=this.theme.grid_color||"",t.beginPath(),s!==n.y&&(t.moveTo(n.x-.5,n.y),t.lineTo(n.x-.5,s)),a!==n.x&&(t.moveTo(n.x,n.y-.5),t.lineTo(a,n.y-.5)),t.stroke(),t.strokeStyle=this.theme.headers_grid_color||"",t.textAlign="center",t.textBaseline="middle",t.font=U.Font(this.theme.headers||{},this.layout.scale),t.fillStyle=R(this.theme,this.theme.headers?.text),this.view.active_sheet.freeze.rows&&this.layout.header_offset.x>1&&(t.setTransform(i,0,0,i,0,0),t.translate(0,n.y),t.beginPath(),t.moveTo(0,0-.5),t.lineTo(n.x,0-.5),t.stroke(),this.RenderRowLabels(t,0,this.view.active_sheet.freeze.rows-1,r.block)),this.view.active_sheet.freeze.columns&&this.layout.header_offset.y>1&&(t.setTransform(i,0,0,i,0,0),t.translate(n.x,0),t.beginPath(),t.moveTo(0-.5,0),t.lineTo(0-.5,n.y),t.stroke(),this.RenderColumnLabels(t,0,this.view.active_sheet.freeze.columns-1)))}RenderColumnLabels(e,t,r){let i=this.layout.header_offset.y;if(!(i<=1)){for(e.fillStyle=R(this.theme,this.theme.headers?.text,0),e.beginPath();t<=r;t++){let n=this.layout.ColumnWidth(t),a=y.ColumnToLabel(t),s=e.measureText(a);n>s.width&&e.fillText(a,n/2,i/2+1),e.moveTo(n-.5,0),e.lineTo(n-.5,i),e.translate(n,0)}e.stroke()}}RenderRowLabels(e,t,r,i){let n=this.layout.header_offset.x;if(!(n<=1)){for(e.fillStyle=R(this.theme,this.theme.headers?.text,0),e.beginPath();t<=r;t++){let a=this.layout.RowHeight(t);a>=i*1.2&&e.fillText(`${t+1}`,n/2,a/2+1),e.moveTo(0,a-.5),e.lineTo(n,a-.5),e.translate(0,a)}e.stroke()}}RenderHeaders(e,t=!1){let r=this.layout.dpr,i=this.layout.header_offset,n=It.Get(U.Font(this.theme.headers||{},this.layout.scale));for(let a=e.start.column;a<=e.end.column;a++){let s=this.layout.column_header_tiles[a];if(s.dirty||t){let o=s.getContext("2d",{alpha:!1});if(!o)continue;o.setTransform(r,0,0,r,0,0),o.textAlign="center",o.textBaseline="middle",o.font=U.Font(this.theme.headers||{},this.layout.scale),o.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",o.fillRect(0,0,s.logical_size.width,this.layout.header_offset.y),o.strokeStyle=this.theme.headers_grid_color||"",o.beginPath(),o.moveTo(0,i.y-.5),o.lineTo(s.logical_size.width,i.y-.5),o.stroke(),o.strokeStyle=this.theme.headers_grid_color||"",this.RenderColumnLabels(o,s.first_cell.column,s.last_cell.column),s.dirty=!1}}for(let a=e.start.row;a<=e.end.row;a++){let s=this.layout.row_header_tiles[a];if(s.dirty||t){let o=s.getContext("2d",{alpha:!1});if(!o)continue;o.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",o.setTransform(r,0,0,r,0,0),o.textAlign="center",o.textBaseline="middle",o.font=U.Font(this.theme.headers||{},this.layout.scale),o.fillRect(0,0,this.layout.header_offset.x,s.logical_size.height),o.strokeStyle=this.theme.headers_grid_color||"",o.beginPath(),o.moveTo(i.x-.5,0),o.lineTo(i.x-.5,s.logical_size.height),o.stroke(),o.strokeStyle=this.theme.headers_grid_color||"",this.RenderRowLabels(o,s.first_cell.row,s.last_cell.row,n.block),s.dirty=!1}}(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.RenderCorner()}CopyToAdjacent(e,t,r,i,n,a,s){let o=this.layout.AdjacentTile(e,i,r);if(!o)return;let l=n,d=a;r>0?l=n-(e.pixel_end.x-e.pixel_start.x)*t:r<0&&(l=n+(o.pixel_end.x-o.pixel_start.x)*t),i>0&&(d=a-(e.pixel_end.y-e.pixel_start.y)*t);let h=o.getContext("2d",{alpha:!1});h&&(h.setTransform(t,0,0,t,l,d),h.drawImage(this.buffer_canvas,0,0,(s.width||0)*t,(s.height||0)*t,s.left||0,0,s.width||0,s.height||0))}Render(e){let t=e.getContext("2d",{alpha:!1});if(!t)return;t.textBaseline=wr;let r=this.layout.dpr;t.setTransform(r,0,0,r,0,0);let i=0,n=0;for(let o=e.first_cell.column;o<=e.last_cell.column;o++){let l=this.layout.ColumnWidth(o);if(l){n=0;for(let d=e.first_cell.row;d<=e.last_cell.row;d++){let h=this.layout.RowHeight(d);if(h){t.setTransform(r,0,0,r,i,n);let u=this.view.active_sheet.CellData({row:d,column:o});if(e.needs_full_repaint||!u.render_clean[this.view.view_index]){let m=this.RenderCell(e,u,t,{row:d,column:o},l,h,e.pixel_start.x+i,e.pixel_start.y+n);m.tile_overflow_right&&this.CopyToAdjacent(e,r,1,0,i,n,m),m.tile_overflow_left&&this.CopyToAdjacent(e,r,-1,0,i,n,m),m.tile_overflow_bottom&&this.CopyToAdjacent(e,r,0,1,i,n,m)}}n+=h*r}i+=l*r}}if(!this.view.active_sheet.freeze.rows&&!this.view.active_sheet.freeze.columns)return;let a=0,s=0;if(e.first_cell.row<=this.view.active_sheet.freeze.rows-1)for(let o=e.first_cell.row;o<this.view.active_sheet.freeze.rows&&o<=e.last_cell.row;o++)a+=this.layout.RowHeight(o);if(e.first_cell.column<=this.view.active_sheet.freeze.columns-1)for(let o=e.first_cell.column;o<this.view.active_sheet.freeze.columns&&o<=e.last_cell.column;o++)s+=this.layout.ColumnWidth(o);if(a){let o=this.layout.frozen_row_tiles[e.tile_position.column];if(!o)throw new Error("can't find matching header tile");let l=o.getContext("2d",{alpha:!0});if(!l)throw new Error("header context failed");l.setTransform(r,0,0,r,0,0),l.drawImage(e,0,0,e.logical_size.width*r,a*r,0,0,e.logical_size.width,a)}if(s){let o=this.layout.frozen_column_tiles[e.tile_position.row];if(!o)throw new Error("can't find matching header tile");let l=o.getContext("2d",{alpha:!0});if(!l)throw new Error("header context failed");l.setTransform(r,0,0,r,0,0),l.drawImage(e,0,0,s*r,e.logical_size.height*r,0,0,s,e.logical_size.height)}if(s&&a){let o=this.layout.corner_canvas.getContext("2d",{alpha:"false"});if(!o)throw new Error("corner context failed");o.setTransform(r,0,0,r,this.layout.header_offset.x*r,this.layout.header_offset.y*r),o.drawImage(e,0,0,s*r,a*r,0,0,s,a)}}PrepText(e,t,r,i){let n=[],a=r.style||{},s,o=0,l,d=r.editing?"":r.formatted;if(Array.isArray(d)){for(let h of d){if(h.flag===6){l=h.text;continue}let u=e.measureText(h.text).width,m={width:u,text:h.text,hidden:h.flag===1};n.push(m),h.flag===2?s=m:o+=u}if(s){let h=s.text,u=s.width,m=i-o-2*this.cell_edge_buffer;if(s.width=Math.max(0,m),m>0){let f=Math.floor(m/u);for(let p=1;p<f;p++)s.text+=h;o=i-2*this.cell_edge_buffer}else s.text=""}return{strings:[n],format:l,width:o}}else if(d){r.type===2&&d[0]==="'"&&(d=d.slice(1));let h;this.options.markdown?h=Re.instance.Parse(d):(h=Re.instance.Dummy(d),e.font=t.base);let u=0,m=i-2*this.cell_edge_buffer,f=[];if(a.wrap)for(let p of h){for(let b=1;b<p.length;b++){let v=p[b].text.match(/^(\s+)/);v&&(p[b-1].text+=v[1],p[b].text=p[b].text.replace(/^\s+/,""))}let g=[];for(let b of p){this.options.markdown&&(b.strong&&b.emphasis?e.font=t.strong_emphasis:b.strong?e.font=t.strong:b.emphasis?e.font=t.emphasis:e.font=t.base);let v=b.text.match(/\S+\s*/g);if(v&&v.length)for(let _ of v){let w=e.measureText(_.trim()).width,x=e.measureText(_).width;g.push({part:b,text:_,trimmed:w,width:x})}}for(;g.length;){let b=g.shift(),v=[b],_=b.trimmed;for(;_<m&&g.length;){let w=g[0],x=_-b.trimmed+b.width+w.trimmed;if(x>=m)break;b=w,v.push(w),_=x,g.shift(),u=Math.max(u,_)}b.text=b.text.trim(),b.width=b.trimmed,u=Math.max(u,b.width),f.push(v.map(w=>({...w.part,hidden:!1,width:w.width,text:w.text})))}}else for(let p of h){let g=[],b=0;for(let v of p){this.options.markdown&&(v.strong&&v.emphasis?e.font=t.strong_emphasis:v.strong?e.font=t.strong:v.emphasis?e.font=t.emphasis:e.font=t.base);let _=e.measureText(v.text).width;b+=_,g.push({...v,hidden:!1,width:_})}u=Math.max(u,b),f.push(g)}return{strings:f,width:u}}return{strings:[[{text:"",hidden:!1,width:0}]],width:0}}ResolveColors(e){let t={...e};return t.text={text:R(this.theme,e.text,1)},t}RenderCellBorders(e,t,r,i=0,n=0,a=0,s=0){let o=this.view.active_sheet.SurroundingStyle(e,this.theme.table),l=R(this.theme,o[8].fill);l&&(t.fillStyle=l,t.fillRect(i+0,n-1,a,1)),l=R(this.theme,o[4].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n,1,s)),l=R(this.theme,r.fill),l&&(t.fillStyle=l,t.fillRect(i-1,n-1,a+1,s+1)),l=R(this.theme,o[6].fill),l&&(t.fillStyle=l,t.fillRect(i+a-1,n-1,1,s+1)),l=R(this.theme,o[2].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n+s-1,a+1,1)),o[6].border_top&&!o[6].border_left&&(t.fillStyle=R(this.theme,o[6].border_top_fill,1),t.fillRect(i+a-1,n-2+o[6].border_top,1,1)),o[9].border_left&&(t.fillStyle=R(this.theme,o[9].border_left_fill,1),t.fillRect(i+a-1,n-1,1,1)),o[9].border_bottom&&(t.fillStyle=R(this.theme,o[9].border_bottom_fill,1),t.fillRect(i+a-1,n-2+o[9].border_bottom,1,1)),o[4].border_top&&!o[4].border_right&&(t.fillStyle=R(this.theme,o[4].border_right_fill,1),t.fillRect(i-1,n-2+o[4].border_top,1,1)),o[7].border_right&&(t.fillStyle=R(this.theme,o[7].border_right_fill,1),t.fillRect(i-1,n-1,1,1)),o[7].border_bottom&&(t.fillStyle=R(this.theme,o[7].border_bottom_fill,1),t.fillRect(i-1,n-2+o[7].border_bottom,1,1)),o[6].border_bottom&&!o[6].border_left&&(t.fillStyle=R(this.theme,o[6].border_bottom_fill,1),t.fillRect(i+a-1,n+s-o[6].border_bottom,1,1)),o[3].border_left&&(t.fillStyle=R(this.theme,o[3].border_left_fill,1),t.fillRect(i+a-1,n+s-1,1,1)),o[3].border_top&&(t.fillStyle=R(this.theme,o[3].border_top_fill,1),t.fillRect(i+a-1,n+s-o[3].border_top,1,1)),o[4].border_bottom&&!o[4].border_right&&(t.fillStyle=R(this.theme,o[4].border_bottom_fill,1),t.fillRect(i-1,n+s-o[4].border_bottom,1,1)),o[1].border_right&&(t.fillStyle=R(this.theme,o[1].border_right_fill,1),t.fillRect(i-1,n+s-1,1,1)),o[1].border_top&&(t.fillStyle=R(this.theme,o[1].border_top_fill,1),t.fillRect(i-1,n+s-o[1].border_top,1,1)),o[8].border_bottom&&(t.fillStyle=R(this.theme,o[8].border_bottom_fill,1),o[8].border_bottom===2&&(t.fillRect(i-1,n-2,a+1,1),t.fillRect(i-1,n-0,a+1,1),t.fillStyle=R(this.theme,o[8].fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n-1,a+1,1)),o[4].border_right&&(t.fillStyle=R(this.theme,o[4].border_right_fill,1),t.fillRect(i-1,n-1,1,s+1)),o[6].border_left&&(t.fillStyle=R(this.theme,o[4].border_left_fill,1),t.fillRect(i+a-1,n-1,1,s+1)),o[2].border_top&&(t.fillStyle=R(this.theme,o[2].border_top_fill,1),o[2].border_top===2&&(t.fillRect(i-1,n+s-2,a+1,1),t.fillRect(i-1,n+s-0,a+1,1),t.fillStyle=R(this.theme,o[2].fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n+s-1,a+1,1)),r.border_top&&(t.fillStyle=R(this.theme,r.border_top_fill,1),r.border_top===2&&(t.fillRect(i-1,n-2,a+1,1),t.fillRect(i-1,n+0,a+1,1),t.fillStyle=R(this.theme,r.fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n-1,a+1,1)),r.border_left&&(t.fillStyle=R(this.theme,r.border_left_fill,1),t.fillRect(i-1,n-1,1,s+1)),r.border_right&&(t.fillStyle=R(this.theme,r.border_right_fill,1),t.fillRect(i+a-1,n-1,1,s+1)),r.border_bottom&&(t.fillStyle=R(this.theme,r.border_bottom_fill,1),r.border_bottom===2&&(t.fillRect(i-1,n+s-2,a+1,1),t.fillRect(i-1,n+s+0,a+1,1),t.fillStyle=R(this.theme,r.fill)||pe(this.theme,this.theme.grid_cell?.fill)||"#fff"),t.fillRect(i-1,n+s-1,a+1,1))}PaintBackgroundImage(e,t,r,i,n,a,s=0,o=0,l=0){if(!t.width||!t.height)return;let d=(this.layout.scale||1)*this.layout.dpr,h=r/d%t.width,u=i/d%t.height,m=n/d,f=a/d,p=h+m>t.width,g=u+f>t.height;p&&e.drawImage(t,h-t.width,u,m,f,s,o,n-l,a-l),g&&e.drawImage(t,h,u-t.height,m,f,s,o,n-l,a-l),p&&g&&e.drawImage(t,h-t.width,u-t.height,m,f,s,o,n-l,a-l),e.drawImage(t,h,u,m,f,s,o,n-l,a-l)}RenderCellBackground(e,t,r,i,n,a,s=0,o=0){if(r.fillStyle=this.theme.grid_color,r.fillRect(0,0,n,a),this.view.active_sheet.image)this.PaintBackgroundImage(r,this.view.active_sheet.image,s,o,n,a,0,0,1);else{let l=R(this.theme,i.fill);l?(r.fillStyle=l,r.fillRect(0,0,n-1,a-1)):(r.fillStyle=pe(this.theme,this.theme.grid_cell?.fill)||"#fff",r.fillRect(0,0,n-1,a-1))}this.RenderCellBorders(t,r,i,0,0,n,a),e&&(r.fillStyle=this.theme.note_marker_color,r.beginPath(),r.moveTo(n-2,1),r.lineTo(n-2-8,1),r.lineTo(n-2,1+8),r.lineTo(n-2,1),r.fill())}RenderCell(e,t,r,i,n,a,s=0,o=0){let l={},d=!t.render_clean[this.view.view_index];if(t.render_clean[this.view.view_index]=!0,e.needs_full_repaint&&t.renderer_data?.overflowed)return{};let h=t.style?{...t.style}:{};if(t.table&&(h=this.view.active_sheet.CellStyleData(i,t.table.theme||this.theme.table)||{}),t.merge_area)if(i.row===t.merge_area.start.row&&i.column===t.merge_area.start.column){for(let C=t.merge_area.start.column+1;C<=t.merge_area.end.column;C++)n+=this.layout.ColumnWidth(C);for(let C=t.merge_area.start.row+1;C<=t.merge_area.end.row;C++)a+=this.layout.RowHeight(C);if(t.merge_area.count>1){let C=this.view.active_sheet.CellStyleData(t.merge_area.end);C&&(h.border_bottom=C.border_bottom,h.border_right=C.border_right,h.border_bottom_fill=C.border_bottom_fill,h.border_right_fill=C.border_right_fill)}t.merge_area.end.column>e.last_cell.column&&(l.tile_overflow_right=!0),t.merge_area.end.row>e.last_cell.row&&(l.tile_overflow_bottom=!0),(l.tile_overflow_bottom||l.tile_overflow_right)&&this.overflow_areas.push({tile:e,head:{...i},area:new y(t.merge_area.start,t.merge_area.end)})}else return{};let u=!!t.hyperlink;if(t.render_function){this.RenderCellBackground(!!t.note,i,r,h,n,a),r.strokeStyle=r.fillStyle=R(this.theme,h.text,1);let C=this.ResolveColors(h);if(t.render_function.call(void 0,{width:n,height:a,context:r,cell:t,style:C,scale:this.layout.scale||1}).handled)return l}let m={base:U.Font(h,this.layout.scale),strong:U.Font({...h,bold:!0},this.layout.scale),emphasis:U.Font({...h,italic:!0},this.layout.scale),strong_emphasis:U.Font({...h,bold:!0,italic:!0},this.layout.scale)};if(r.font=m.base,d||!t.renderer_data||t.renderer_data.width!==n||t.renderer_data.height!==a){let C=this.PrepText(r,m,t,n);t.renderer_data={text_data:C,width:n,height:a}}let f=t.renderer_data.text_data,p=f.width>n-2*this.cell_edge_buffer,g=n,b=0,v=!1,_=t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7||t.type===9||t.calculated_type===9,w=h.horizontal_align;w||(w=_?"right":"left");let x=[];if(p)if(t.type!==3&&t.calculated_type!==3&&!h.wrap&&!t.merge_area){let K=f.width-n+this.cell_edge_buffer,ne=0,ae=0;w==="center"?ne=ae=K/2:w==="right"?ne=K:ae=K;let J=i.column,X=i.column;for(;ae>0&&J<this.layout.last_column;){J++;let q={row:i.row,column:J},z=this.view.active_sheet.CellData(q),Z=this.layout.ColumnWidth(J);if(ae-=Z,z&&!z.type&&!z.calculated_type)x.push({address:q,cell:z,grid:new H(g,0,Z,a),background:new H(g-1,0,Z,a-1),border:new H(g,0,Z,a)}),g+=Z,z.render_clean[this.view.view_index]=!0,z.renderer_data={overflowed:!0};else{v=!0;break}}for(J>e.last_cell.column&&(l.tile_overflow_right=!0);ne>0&&X>=1;){X--;let q={row:i.row,column:X},z=this.view.active_sheet.CellData(q),Z=this.layout.ColumnWidth(X);if(ne-=Z,z&&!z.type&&!z.calculated_type)b-=Z,x.push({address:q,cell:z,grid:new H(b,0,Z,a),background:new H(b,0,Z,a-1),border:new H(b,0,Z,a)});else{v=!0;break}}X<e.first_cell.column&&(l.tile_overflow_left=!0),this.overflow_areas.push({head:{...i},tile:e,area:new y({row:i.row,column:X},{row:i.row,column:J})})}else v=!_;let A=!1,k=r;(l.tile_overflow_bottom||l.tile_overflow_left||l.tile_overflow_right)&&(A=!0,l.width=g-b,l.height=a,l.left=b,this.EnsureBuffer(l.width+1,a+1,-b),r=this.buffer_context,r.font=m.base),this.RenderCellBackground(!!t.note,i,r,h,n,a,s,o);for(let C of x)C.cell.style?.fill&&(C.cell.style.fill.text||C.cell.style.fill.theme||C.cell.style.fill.theme===0)&&!this.options.grid_over_background?(r.fillStyle=pe(this.theme,C.cell.style.fill),r.fillRect(C.grid.left,C.grid.top,C.grid.width,C.grid.height)):(r.fillStyle=this.theme.grid_color||"",r.fillRect(C.grid.left,C.grid.top,C.grid.width,C.grid.height),this.view.active_sheet.image?this.PaintBackgroundImage(r,this.view.active_sheet.image,s+C.background.left,o+C.background.top,C.background.width,C.background.height,C.background.left,C.background.top,0):(r.fillStyle=this.theme.grid_cell?.fill?pe(this.theme,this.theme.grid_cell.fill):"",r.fillRect(C.background.left,C.background.top,C.background.width,C.background.height))),C.cell.style&&this.RenderCellBorders(C.address,r,C.cell.style,C.border.left,C.border.top,C.border.width,C.border.height);let S=It.Get(m.base,this.theme.grid_cell?.font_size?.value);r.lineWidth=1,r.strokeStyle=r.fillStyle=f.format?f.format:R(this.theme,h.text,1),r.beginPath();let M=this.cell_edge_buffer,V=1.25,W=f.strings.length,me=W*S.block*V;v=(v||me>=a)&&!A,v&&(r.save(),r.beginPath(),r.moveTo(b+1.5,0),r.lineTo(b+1.5,a),r.lineTo(g-1.5,a),r.lineTo(g-1.5,0),r.clip()),r.beginPath();let ie=Math.round(a-2-S.block*V*(W-1)+di);switch(h.vertical_align){case"top":ie=Math.round(S.block*V)+1;break;case"middle":ie=Math.round((a-me)/2+S.block*V);break}if((t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7)&&p){let C=Math.floor((n-2*this.cell_edge_buffer)/S.hash),K="";for(let ae=0;ae<C;ae++)K+="#";let ne=r.measureText(K).width;w==="center"?M=Math.round((n-ne)/2):w==="right"&&(M=n-this.cell_edge_buffer-ne),r.fillText(K,M,ie)}else{let C=ie,K=0;for(let ne of f.strings){let ae=0;for(let z of ne)ae+=z.width;w==="center"?M=Math.round((n-ae)/2):w==="right"&&(M=n-this.cell_edge_buffer-ae);let J=Math.floor(C+1.5-S.descender-di)+.5,X=Math.floor(C-S.descender-S.ascender/2)+.5,q=M;for(let z of ne)z.strong&&z.emphasis?r.font=m.strong_emphasis:z.strong?r.font=m.strong:z.emphasis?r.font=m.emphasis:r.font=m.base,z.hidden||(z.text&&r.fillText(z.text,q,C),h.underline&&(r.moveTo(q,J),r.lineTo(q+z.width,J)),(h.strike||z.strike)&&(r.moveTo(q,X),r.lineTo(q+z.width,X)),u&&(z.left=q,z.top=C-S.block,z.height=S.block)),q+=z.width;K++,C=Math.round(ie+K*S.block*V)}}if(r.stroke(),v)r.restore();else if(A){let C=this.layout.dpr;k.drawImage(this.buffer_canvas,0,0,(l.width||0)*C,a*C,b,0,l.width||0,a)}return l}};var Dt=class extends Me{constructor(t,r,i,n,a){super(r,i,a);this.options=n;let s=F.GetInstance(t.ownerDocument),o=t.querySelector(".treb-formula-bar");o.removeAttribute("hidden"),this.address_label_container=o.querySelector(".treb-address-label"),this.address_label=this.address_label_container.firstElementChild,this.InitAddressLabel(),this.options.insert_function_button&&(this.button=s.Create("button","formula-button",o),this.button.addEventListener("click",()=>{let h=this.active_editor&&this.active_editor.node.textContent||"";this.Publish({type:"formula-button",formula:h})})),this.container_node=t.querySelector(".treb-editor-container");let l=this.container_node.firstElementChild,d={node:l};this.active_editor=d,this.nodes=[d],l&&this.RegisterListener(d,"input",h=>{h.isTrusted&&(this.UpdateText(d),this.UpdateColors())}),this.active_editor.node.spellcheck=!1,this.RegisterListener(d,"focusin",()=>{if(!this.active_editor)return;let h=this.active_editor.node.textContent||"";h[0]==="{"&&h[h.length-1]==="}"&&(h=h.substring(1,h.length-1),this.active_editor.node.textContent=h,this.active_editor.formatted_text=void 0),this.autocomplete?.ResetBlock(),this.UpdateText(this.active_editor),this.UpdateColors(),this.Publish([{type:"start-editing",editor:"formula-bar"},{type:"update",text:h,cell:this.active_cell,dependencies:this.composite_dependencies}]),this.focused_=!0}),this.RegisterListener(d,"focusout",h=>{this.selecting&&console.info("focusout, but selecting..."),this.autocomplete?.Hide(),this.Publish([{type:"stop-editing"}]),this.focused_=!1,this.active_editor&&(this.active_editor.node.spellcheck=!1)}),this.RegisterListener(d,"keydown",this.FormulaKeyDown.bind(this)),this.RegisterListener(d,"keyup",this.FormulaKeyUp.bind(this)),this.options.expand_formula_button&&(this.expand_button=s.Create("button","expand-button",o,{events:{click:h=>{h.stopPropagation(),h.preventDefault(),this.active_editor&&(this.active_editor.node.scrollTop=0),o.hasAttribute("expanded")?o.removeAttribute("expanded"):o.setAttribute("expanded","")}}}))}focused_=!1;get focused(){return this.focused_}address_label_container;address_label;button;expand_button;label_update_timer=0;get formula(){return this.active_editor&&this.active_editor.node.textContent||""}set formula(t){this.active_editor&&(this.active_editor.node.textContent=t,this.active_editor.formatted_text=void 0)}get label(){return this.address_label?.textContent||""}set label(t){t.trim().length?(this.address_label.textContent=t,this.label_update_timer||(this.label_update_timer=requestAnimationFrame(()=>{this.label_update_timer=0,this.address_label.scrollWidth>this.address_label.offsetWidth?this.address_label.setAttribute("title",t):this.address_label.removeAttribute("title")}))):(this.address_label.innerHTML=" ",this.address_label.removeAttribute("title"))}set editable(t){!this.active_editor||!this.container_node||(t?(this.active_editor.node.setAttribute("contenteditable","true"),this.container_node.removeAttribute("locked")):(this.active_editor.node.removeAttribute("contenteditable"),this.container_node.setAttribute("locked","")))}IsElement(t){return t===this.active_editor?.node}InitAddressLabel(){this.address_label.contentEditable="true",this.address_label.spellcheck=!1,this.address_label.addEventListener("focusin",t=>{let r=this.address_label.ownerDocument;requestAnimationFrame(()=>{let i=r.defaultView.getSelection(),n=r.createRange();n.selectNodeContents(this.address_label),i?.removeAllRanges(),i?.addRange(n)})}),this.address_label.addEventListener("keydown",t=>{if(!t.isComposing)switch(t.key){case"Enter":t.stopPropagation(),t.preventDefault(),this.Publish({type:"address-label-event",text:this.address_label.textContent||void 0});break;case"Esc":case"Escape":t.stopPropagation(),t.preventDefault(),this.Publish({type:"address-label-event"});break}})}GetTextContent(t){let r=t.childNodes,i=[];for(let n=0;n<r.length;n++){let a=r[n];switch(a.nodeType){case Node.ELEMENT_NODE:i.push(...this.GetTextContent(a)),a instanceof Element&&a.tagName==="DIV"&&i.push(`
|
|
6
6
|
`);break;case Node.TEXT_NODE:a.nodeValue&&i.push(a.nodeValue);break}}return i}FormulaKeyUp(t){t.isComposing||this.autocomplete&&this.autocomplete.HandleKey("keyup",t).handled}FormulaKeyDown(t){if(!t.isComposing){if(this.autocomplete){let r=this.autocomplete.HandleKey("keydown",t);if(r.accept&&this.AcceptAutocomplete(r),r.handled)return}switch(t.key){case"Enter":case"Tab":{let r=t.key==="Enter"&&t.ctrlKey&&t.shiftKey,i=(this.active_editor?this.GetTextContent(this.active_editor.node).join(""):"").trim();this.Publish({type:"commit",value:i,event:t,array:r})}break;case"Escape":case"Esc":this.Publish({type:"discard"});break;default:return}t.stopPropagation(),t.preventDefault()}}};var et=class{constructor(e={}){this.options=e;if(this.DOM=F.GetInstance(e.container?.ownerDocument),!this.DOM.doc)throw new Error("invalid context");this.completion_list=this.DOM.Div("treb-cell-editor-ac-list treb-autocomplete",e.container||this.DOM.doc.body,{events:{mousedown:t=>this.ListMouseDown(t),mousemove:t=>this.ListMouseMove(t)}}),this.tooltip=this.DOM.Div("treb-cell-editor-ac-tooltip treb-autocomplete-tooltip",e.container||this.DOM.doc.body)}completion_list_visible=!1;tooltip_visible=!1;last_completion;completion_list;tooltip;selected_index=0;block=!1;autocomplete_data={};callback;active_element;DOM;Hide(){this.tooltip.style.top="-1000px",this.completion_list.style.top="-1000px",this.completion_list_visible=!1,this.tooltip_visible=!1,this.active_element=void 0}SetBlock(){this.block=!0}ResetBlock(){this.block=!1}ListMouseMove(e){let t=e.target;t.tagName==="A"&&t!==this.active_element&&this.active_element&&(this.active_element.classList.remove("selected"),this.active_element=t,this.active_element.classList.add("selected"),this.selected_index=Number(t.dataset.index||"0"),this.last_completion=t.textContent||"")}ListMouseDown(e){e.stopPropagation(),e.preventDefault();let t=e.target;for(;t;){if(t===this.completion_list)return;if(t.tagName==="A")break;t=t.parentElement}t&&(console.info(t),this.callback&&this.callback({handled:!0,accept:!0,value:t.textContent?t.textContent:void 0,data:this.autocomplete_data,click:!0}))}HandleKey(e,t){if(!this.completion_list_visible)return{handled:!1};let r=0,i=!1,n=!1;switch(t.key){case"Up":case"ArrowUp":r=-1;break;case"Down":case"ArrowDown":r=1;break;case"Tab":n=!0;break;case"Escape":case"Esc":i=!0;break;default:return{handled:!1}}if(t.stopPropagation(),t.preventDefault(),e==="keyup")return{handled:!0};if(r){let a=this.completion_list.getBoundingClientRect();this.selected_index+=r,this.selected_index=Math.max(0,this.selected_index);let s=this.completion_list.querySelectorAll("a");this.selected_index=Math.min(this.selected_index,s.length-1);for(let o=0;o<s.length;o++){let l=s[o];if(o===this.selected_index){l.classList.add("selected"),this.active_element=l;let d=l.getBoundingClientRect();d.top<a.top?this.completion_list.scrollBy(0,-d.height):d.bottom>a.bottom&&this.completion_list.scrollBy(0,d.height),this.last_completion=l.textContent||void 0}else l.classList.remove("selected")}return{handled:!0}}else{if(i)return this.block=!0,this.Hide(),{handled:!0};if(n)return{handled:!0,accept:!0,value:this.last_completion,data:this.autocomplete_data}}return{handled:!1}}Show(e,t={},r){if(this.completion_list_visible=!1,this.tooltip_visible=!1,this.autocomplete_data=t,this.callback=e,!this.block)if(t.tooltip?(this.tooltip.innerHTML=t.tooltip+t.arguments+(t.description?`
|
|
7
7
|
`+t.description:""),this.tooltip.style.left=r.left+"px",this.options.tooltip_prefer_top?this.tooltip.style.top=r.top-this.tooltip.offsetHeight-5+"px":this.tooltip.style.top=r.bottom+5+"px",this.tooltip_visible=!0):this.tooltip.style.top="-1000px",t.completions&&t.completions.length){this.tooltip.style.top="-1000px",this.selected_index=0,this.completion_list.innerHTML='<ul class="notranslate">'+t.completions.map((s,o)=>(s.name===this.last_completion&&(this.selected_index=o),`<li><a data-index="${o}">${s.name}</a></li>`)).join(`
|
|
8
|
-
`)+"<ul>";let i=this.completion_list.offsetHeight,n=!1;this.options.autocomplete_prefer_top?n=r.top>=200:this.DOM.doc?.documentElement&&Math.max(this.DOM.doc.documentElement.clientHeight,this.DOM.view?.innerHeight||0)-r.bottom<200&&(n=!0),n?this.completion_list.style.top=r.top-i-5+"px":this.completion_list.style.top=r.bottom+5+"px",this.completion_list.style.left=r.left+"px";let a=this.completion_list.querySelectorAll("a");this.active_element=a[this.selected_index],a[this.selected_index].classList.add("selected"),this.last_completion=a[this.selected_index].textContent||void 0,this.completion_list.scrollTop=this.active_element.offsetTop,this.completion_list_visible=!0}else this.completion_list.style.top="-1000px"}};var tt=(C=>(C[C.Null=0]="Null",C[C.InsertRows=1]="InsertRows",C[C.InsertColumns=2]="InsertColumns",C[C.ResizeRows=3]="ResizeRows",C[C.ResizeColumns=4]="ResizeColumns",C[C.Select=5]="Select",C[C.SetRange=6]="SetRange",C[C.UpdateStyle=7]="UpdateStyle",C[C.UpdateBorders=8]="UpdateBorders",C[C.MergeCells=9]="MergeCells",C[C.UnmergeCells=10]="UnmergeCells",C[C.Clear=11]="Clear",C[C.UpdateTheme=12]="UpdateTheme",C[C.SetNote=13]="SetNote",C[C.SetLink=14]="SetLink",C[C.Freeze=15]="Freeze",C[C.SetName=16]="SetName",C[C.ShowHeaders=17]="ShowHeaders",C[C.AddSheet=18]="AddSheet",C[C.DuplicateSheet=19]="DuplicateSheet",C[C.DeleteSheet=20]="DeleteSheet",C[C.ActivateSheet=21]="ActivateSheet",C[C.RenameSheet=22]="RenameSheet",C[C.ReorderSheet=23]="ReorderSheet",C[C.ShowSheet=24]="ShowSheet",C[C.DataValidation=25]="DataValidation",C[C.Reset=26]="Reset",C[C.SortTable=27]="SortTable",C[C.InsertTable=28]="InsertTable",C[C.RemoveTable=29]="RemoveTable",C))(tt||{});var hi={scrollbars:!0,in_cell_editor:!0,formula_bar:!0,add_tab:!1,tab_bar:"auto",insert_function_button:!1,expand_formula_button:!1,expand:!0,repaint_on_cell_change:!0,grid_over_background:!1};var rt=class{grid_events=new oe;command_log=new oe;model;view;get active_sheet(){return this.view.active_sheet}set active_sheet(e){this.view.active_sheet=e}get view_index(){return this.view.view_index}batch=!1;batch_events=[];autocomplete_matcher=new Et;flags={};options;parser;constructor(e={},t){this.model=t,this.view={active_sheet:this.model.sheets.list[0],view_index:this.model.view_count++},this.parser=t.parser,this.options={...hi,...e}}RemoveTable(e){this.ExecCommand({key:29,table:e})}InsertTable(e,t=!0,r=void 0,i){e.start.sheet_id||(e.start.sheet_id=this.active_sheet.id);let n=this.FindSheet(e);for(let a=e.start.row;a<=e.end.row;a++)for(let s=e.start.column;s<=e.end.column;s++){let o=n.cells.GetCell({row:a,column:s},!1);if(o&&(o.area||o.merge_area||o.table)){this.Error(4);return}}this.ExecCommand({key:28,area:JSON.parse(JSON.stringify(e)),totals:t,sortable:r,theme:i})}ActivateSheet(e){let t=typeof e=="number"?e:void 0,r=typeof e=="string"?e:void 0;this.ExecCommand({key:21,index:t,name:r})}ActivateSheetID(e){this.ExecCommand({key:21,id:e})}DuplicateSheet(e,t,r){let i={key:19,new_name:t,insert_before:r};typeof e>"u"?i.id=this.active_sheet.id:i.index=e,this.ExecCommand(i)}AddSheet(e){this.ExecCommand({key:18,name:e,show:!0})}DeleteSheet(e){if(typeof e>"u"&&!this.model.sheets.list.some((t,r)=>t===this.active_sheet?(e=r,!0):!1))throw new Error("invalid index");this.ExecCommand({key:20,index:e})}InsertSheet(e,t){if(typeof e>"u"&&!this.model.sheets.list.some((r,i)=>r===this.active_sheet?(e=i+1,!0):!1))throw new Error("invalid index");this.ExecCommand({key:18,insert_index:e,name:t,show:!0})}DeleteSheetID(e){this.ExecCommand({key:20,id:e})}Reset(){this.ExecCommand({key:26})}SetLink(e,t){this.ExecCommand({key:14,area:e,reference:t})}ShowAll(){let e=[];for(let t=0;t<this.model.sheets.length;t++)e.push({key:24,index:t,show:!0});this.ExecCommand(e)}ShowSheet(e=0,t=!0){let r={key:24,show:t};typeof e=="string"?r.name=e:r.index=e,this.ExecCommand(r)}SortTable(e,t={}){this.ExecCommand({key:27,table:JSON.parse(JSON.stringify(e)),...Or,...t})}GetFreeze(){return{...this.active_sheet.freeze}}InsertRows(e=0,t=1){this.ExecCommand({key:1,before_row:e,count:t})}GetTableReference(e){return this.model.sheets.Find(e.sheet_id||this.active_sheet.id)?.CellData(e).table||void 0}FromCSV(e){let t=this.parser.decimal_mark===",";t&&(this.parser.argument_separator=",",this.parser.decimal_mark=".");let i=Qr(e).map(a=>a.map(s=>{if(s){let o=this.parser.Parse(s);if(o.expression?.type==="complex")return o.expression}return be.TryParse(s).value}));t&&(this.parser.argument_separator=";",this.parser.decimal_mark=",");let n={row:Math.max(0,i.length-1),column:i.reduce((a,s)=>Math.max(a,Math.max(0,s.length-1)),0)};this.ExecCommand([{key:26},{key:6,area:{start:{row:0,column:0},end:n},value:i}])}InsertColumns(e=0,t=1){this.ExecCommand({key:2,before_column:e,count:t})}ReorderSheet(e,t){this.ExecCommand({key:23,index:e,move_before:t})}RenameSheet(e,t){this.ExecCommand({key:22,new_name:t,id:e.id})}Freeze(e=0,t=0,r=!0){this.ExecCommand({key:15,rows:e,columns:t,highlight_transition:r})}SetRowHeight(e,t,r=!0){this.ExecCommand({key:3,row:e,height:t,shrink:r})}SetColumnWidth(e,t=0){this.ExecCommand({key:4,column:e,width:t})}FilterTable(e,t,r){let i=[];if(!e.area.start.sheet_id)throw new Error("invalid table area");let n=this.model.sheets.Find(e.area.start.sheet_id);if(!n)throw new Error("invalid table sheet");let a=[],s=[],o=e.totals_row?e.area.end.row-1:e.area.end.row;t+=e.area.start.column;for(let l=e.area.start.row+1;l<=o;l++){let d=n.CellData({row:l,column:t}),h=r(d),u=n.GetRowHeight(l);h&&!u?a.push(l):!h&&u&&s.push(l)}a&&i.push({key:3,sheet_id:n.id,row:a,height:n.default_row_height}),s&&i.push({key:3,sheet_id:n.id,row:s,height:0}),i.length&&this.ExecCommand(i)}UpdateSheets(e,t=!1,r){Y.Reset();let i=e.map(n=>Y.FromJSON(n,this.model.theme_style_properties));if(i.length===0&&i.push(Y.Blank(this.model.theme_style_properties)),this.model.sheets.Assign(i),this.ResetMetadata(),this.active_sheet=i[0],r){let n=this.model.sheets.Find(r);n&&(this.active_sheet=n)}}SetAutocompleteFunctions(e){let t=[];for(let i of this.model.named_expressions.keys())t.push({name:i,type:0});let r=e.slice(0).concat(this.model.named_ranges.List().map(i=>({name:i.name,type:1})),t);this.autocomplete_matcher.SetFunctions(r)}ResetMetadata(){this.model.document_name=void 0,this.model.user_data=void 0}Serialize(e={}){let t=this.model.sheets.list.map(a=>a.toJSON(e)),r;this.model.tables.size>0&&(r=Array.from(this.model.tables.values()));let i;if(this.model.macro_functions.size){i=[];for(let a of this.model.macro_functions.values())i.push({...a,expression:void 0})}let n=[];if(this.model.named_expressions)for(let[a,s]of this.model.named_expressions){this.parser.Walk(s,l=>{if(l.type==="address"||l.type==="range"){let d=l.type==="range"?l.start:l;if(d.absolute_column=d.absolute_row=!0,!d.sheet){if(d.sheet_id){let h=this.model.sheets.Find(d.sheet_id);h&&(d.sheet=h.name)}d.sheet||(d.sheet=this.active_sheet.name)}return l.type==="range"&&(l.end.absolute_column=l.end.absolute_row=!0),!1}return!0});let o=this.parser.Render(s,{missing:""});n.push({name:a,expression:o})}return{sheet_data:t,active_sheet:this.active_sheet.id,named_ranges:this.model.named_ranges.Count()?this.model.named_ranges.Serialize():void 0,macro_functions:i,tables:r,named_expressions:n.length?n:void 0}}ResizeColumnsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.column;if(typeof r>"u"){r=[];for(let i=0;i<t.columns;i++)r.push(i)}if(typeof r=="number"&&(r=[r]),e.width)for(let i of r)t.SetColumnWidth(i,e.width);else console.error("auto size not supported")}ResizeRowsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.row;if(typeof r>"u"){r=[];for(let i=0;i<t.rows;i++)r.push(i)}if(typeof r=="number"&&(r=[r]),e.height)for(let i of r)t.SetRowHeight(i,e.height);else console.error("auto size not supported")}ResetInternal(){Y.Reset(),this.UpdateSheets([],!0),this.model.named_ranges.Reset(),this.model.named_expressions.clear(),this.model.macro_functions.clear(),this.model.tables.clear()}ValidatePasteAreas(e){for(let t of e){let r=this.active_sheet;if(t.start.sheet_id&&t.start.sheet_id!==r.id&&(r=this.model.sheets.Find(t.start.sheet_id)),!r)return!1;let i=!0;if(r.cells.Apply2(t,n=>(n.style?.locked&&(console.info("invalid: locked cells"),i=!1),n.merge_area&&(!t.Contains(n.merge_area.start)||!t.Contains(n.merge_area.end))&&(console.info("invalid: merge area"),i=!1),n.area&&(!t.Contains(n.area.start)||!t.Contains(n.area.end))&&(console.info("invalid: array"),i=!1),i)),!i)return!1}return!0}SetValidationInternal(e){let t,r=this.FindSheet(e.area);if(r&&(t=r.cells.GetCell(e.area,!0)),!t)throw new Error("invalid cell in set validation");e.range?t.validation={type:"range",area:e.range,error:!!e.error}:e.list?t.validation={type:"list",list:JSON.parse(JSON.stringify(e.list)),error:!!e.error}:t.validation=void 0}GetValidationRange(e){let t,r=this.FindSheet(e);if(r){t=[],e=r.RealArea(new y(e.start,e.end),!0);for(let i=e.start.row;i<=e.end.row;i++)for(let n=e.start.column;n<=e.end.column;n++){let a=r.CellData({row:i,column:n});a&&a.formatted&&(typeof a.formatted=="string"?t.push(a.formatted):t.push(te.FormatPartsAsText(a.formatted)))}}return t}DeleteSheetInternal(e){let t=!1,r=-1,i="",n=!1,a=e.name?e.name.toLowerCase():"",s=this.model.sheets.list.filter((o,l)=>l===e.index||o.id===e.id||o.name.toLowerCase()===a?(t=o===this.active_sheet,this.model.named_ranges.RemoveRangesForSheet(o.id),i=o.name,r=l,!1):!0);if(i&&this.RenameSheetReferences(s,i,"#REF")>0&&(n=!0),!s.length)s.push(Y.Blank(this.model.theme_style_properties)),r=0;else if(s.every(o=>!o.visible))s.unshift(Y.Blank(this.model.theme_style_properties)),r=0;else for(r>=s.length&&(r=0);!s[r].visible;)r++;return this.model.sheets.Assign(s),t&&this.ActivateSheetInternal({key:21,index:r}),n}RenameSheetInternal(e,t){if(!t||Xr.test(t))throw new Error("invalid sheet name");let r=t.toLowerCase();for(let n of this.model.sheets.list)if(n!==e&&n.name.toLowerCase()===r)throw new Error("sheet name already exists");let i=e.name;e.name=t,this.model.sheets.Assign(this.model.sheets.list),this.RenameSheetReferences(this.model.sheets.list,i,t)}SortTableInternal(e){if(!e.table.area.start.sheet_id)throw new Error("table has invalid area");let t=this.model.sheets.Find(e.table.area.start.sheet_id);if(!t)throw new Error("invalid sheet in table area");let r=[],i=[],n=e.table.area.end.row;e.table.totals_row&&n--;let a=0,s=0;for(let u=e.table.area.start.row+1;u<=n;u++){if(t.GetRowHeight(u))i.push(u);else continue;let f={row:u,number:0,text:"",type:0,data:[]};for(let p=e.table.area.start.column;p<=e.table.area.end.column;p++){let g=t.CellData({row:u,column:p});if(p===e.column+e.table.area.start.column){let b=g.calculated_type||g.type;b===2?a++:b===3&&s++;let v=g.calculated_type?g.calculated:g.value;f.text=v?.toString()||"",f.number=Number(v)||0,f.type=g.calculated_type||g.type}f.data.push({address:{row:u,column:p},data:g.value,type:g.type,style:g.style})}r.push(f)}let o=e.type;o==="auto"&&(s>a?o="numeric":o="text");let l=e.asc?1:-1;switch(o){case"numeric":r.sort((u,m)=>u.type===0?m.type===0?0:1:m.type===0?-1:(u.number-m.number)*l);break;case"text":default:r.sort((u,m)=>u.type===0?m.type===0?0:1:m.type===0?-1:u.text.localeCompare(m.text)*l);break}let d={row:e.table.area.start.row+1,column:e.table.area.start.column};for(let u=0;u<i.length;u++){d.row=i[u];let m=r[u];d.column=e.table.area.start.column;for(let f of m.data){if(f.type===1){let p=f.data,g={columns:0,rows:d.row-m.row},b=this.parser.Parse(p);b.expression&&(p="="+this.parser.Render(b.expression,{offset:g,missing:""})),t.SetCellValue(d,p)}else t.SetCellValue(d,f.data);t.UpdateCellStyle(d,f.style||{},!1),d.column++}}let h=this.model.tables.get(e.table.name.toLowerCase());h&&(h.sort={type:e.type,asc:!!e.asc,column:e.column});{let u=e.table.area.start.row;for(let m=e.table.area.start.column;m<=e.table.area.end.column;m++)t.cells.data[u][m]?.FlushStyle();if(e.table.totals_row){u=e.table.area.end.row;for(let m=e.table.area.start.column;m<=e.table.area.end.column;m++)t.cells.data[u][m]?.FlushStyle()}}return new y(e.table.area.start,e.table.area.end)}UpdateTableColumns(e){if(!e.area.start.sheet_id)throw new Error("invalid area in table");let t=this.model.sheets.Find(e.area.start.sheet_id);if(!t)throw new Error("invalid sheet in table");let r=e.columns?.slice(0)||void 0,i=[],n=e.area.start.row,a=e.area.end.column-e.area.start.column+1,s=e.area.start.column;for(let o=0;o<a;o++,s++){let l=t.CellData({row:n,column:s}),d="";l.type!==2?(typeof l.formatted<"u"?d=l.formatted.toString():typeof l.calculated<"u"?d=l.calculated.toString():typeof l.value<"u"&&(d=l.value.toString()),l.Set(d,2)):d=l.value||"",d||(d=`Column${o+1}`);let h=d,u=!1,m=1;for(;!u;){u=!0;e:for(let f of i)if(f.toLowerCase()===h.toLowerCase()){u=!1,h=`${d}${++m}`;break e}}l.Set(h,2),i.push(h.toLowerCase())}if(r&&r.length===i.length){let o=new Map;for(let l=0;l<r.length;l++){let d=r[l].toLowerCase();d!==i[l]&&o.set(d,i[l])}if(o.size){let l=e.name.toLowerCase();for(let d of this.model.sheets.list)d.cells.IterateAll(h=>{if(h.ValueIsFormula()){let u=!1,m=this.parser.Parse(h.value);m.expression&&(this.parser.Walk(m.expression,f=>{if(f.type==="structured-reference"&&(f.table.toLowerCase()===l||!f.table&&h.table===e))for(let[p,g]of o.entries())f.column.toLowerCase()===p&&(f.column=g,u=!0);return!0}),u&&(console.info("updating value"),h.value="="+this.parser.Render(m.expression,{missing:""})))}})}}return e.columns=i,{start:{...e.area.start},end:{row:e.area.start.row,column:e.area.end.column}}}SetRangeInternal(e,t={}){let r=N(e.area)?new y(e.area):new y(e.area.start,e.area.end),i=this.FindSheet(r);if(r.start.sheet_id||(r.start.sheet_id=i.id),!r.entire_row&&!r.entire_column&&(r.end.row>=i.rows||r.end.column>=i.columns)&&(i.cells.EnsureCell(r.end),i===this.active_sheet&&(t.layout=!0)),N(e.area)){let n=i.CellData(e.area);if(n.area&&(n.area.rows>1||n.area.columns>1)){this.Error(2);return}let a=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;return e.r1c1&&(a=this.TranslateR1C1(e.area,a)),e.array?i.SetArrayValue(r,a):i.SetCellValue(e.area,a),r}else{if(e.array){let n=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;e.r1c1&&(n=this.TranslateR1C1(r.start,n)),i.SetArrayValue(r,n)}else{if(e.r1c1){if(Array.isArray(e.value))for(let n=0;n<e.value.length&&n<r.rows;n++){e.value[n]||(e.value[n]=[]);let a=e.value[n];for(let s=0;s<a.length&&s<r.columns;s++){let o={...r.start,row:r.start.row+n,column:r.start.column+s};a[s]=this.TranslateR1C1(o,a[s])}}else if(typeof e.value=="string"&&e.value[0]==="="){let n=[];for(let a=0;a<r.rows;a++){let s=[];for(let o=0;o<r.columns;o++){let l={...r.start,row:r.start.row+a,column:r.start.column+o};s.push(this.TranslateR1C1(l,e.value))}n.push(s)}e.value=n}}i.SetAreaValues2(r,e.value)}return r}}ActivateSheetInternal(e){let t=this.ResolveSheet(e)||this.model.sheets.list[0];if(this.active_sheet===t&&!e.force)return;if(!t.visible)throw new Error("cannot activate hidden sheet");let r=this.active_sheet;this.active_sheet=t,this.grid_events.Publish({type:"sheet-change",deactivate:r,activate:this.active_sheet})}ShowSheetInternal(e){let t=this.ResolveSheet(e);if(t&&t.visible!==e.show){if(!e.show){let r=0;for(let i of this.model.sheets.list)(!t.visible||i===t)&&r++;if(r>=this.model.sheets.length)throw new Error("can't hide all sheets")}if(t.visible=e.show,t===this.active_sheet){let r=this.model.sheets.list;for(let i=0;i<r.length;i++)if(r[i]===this.active_sheet){for(let n=i+1;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:21,index:n});return}for(let n=0;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:21,index:n});return}throw new Error("no visible sheet")}}}}NormalizeCommands(e){Array.isArray(e)||(e=[e]);let t=this.active_sheet.id;for(let r of e)switch(r.key){case 0:case 17:case 24:case 18:case 19:case 20:case 21:case 22:case 23:case 26:break;case 27:case 29:r.table.area.start.sheet_id||(r.table.area.start.sheet_id=t);break;case 3:case 4:case 2:case 1:case 15:r.sheet_id||(r.sheet_id=t);break;case 11:case 13:case 14:case 8:case 9:case 10:case 25:case 6:case 7:case 16:case 5:case 28:r.area&&(N(r.area)?r.area.sheet_id||(r.area.sheet_id=t):r.area.start.sheet_id||(r.area.start.sheet_id=t));break}return e}AddSheetInternal(e=Y.default_sheet_name,t=-1){if(!this.options.add_tab){console.warn("add tab option not set or false");return}for(;this.model.sheets.list.some(i=>i.name===e);){let i=e.match(/^(.*?)(\d+)$/);i?e=i[1]+(Number(i[2])+1):e=e+"2"}let r=Y.Blank(this.model.theme_style_properties,e);return t>=0?this.model.sheets.Splice(t,0,r):this.model.sheets.Add(r),r.id}ResolveSheet(e){if(typeof e.index<"u")return this.model.sheets.list[e.index];if(typeof e.name<"u")return this.model.sheets.Find(e.name);if(e.id)return this.model.sheets.Find(e.id)}FindSheet(e){if(e===void 0)return this.active_sheet;let t=typeof e=="number"?e:N(e)?e.sheet_id:e.start.sheet_id;if(!t||t===this.active_sheet.id)return this.active_sheet;let r=this.model.sheets.Find(t);return r||this.active_sheet}PatchFormulasInternal(e,t,r,i,n,a,s){let o=this.parser.Parse(e||""),l=!1;if(o.expression&&(this.parser.Walk(o.expression,d=>{if(d.type==="range"||d.type==="address"){let h=[];d.type==="range"?(d.start.sheet&&d.start.sheet.toLowerCase()===a||!d.start.sheet&&s)&&h.push(d.start,d.end):d.type==="address"&&(d.sheet&&d.sheet.toLowerCase()===a||!d.sheet&&s)&&h.push(d);for(let u of h)r&&u.row>=t&&(r<0&&u.row+r<t?u.column=u.row=-1:u.row+=r,l=!0),n&&u.column>=i&&(n<0&&u.column+n<i?u.column=u.row=-1:u.column+=n,l=!0);return!1}return!0}),l))return"="+this.parser.Render(o.expression,{missing:""})}PatchExpressionSheetName(e,t,r){let i=!1,n=this.parser.Parse(e||"");if(n.expression&&(this.parser.Walk(n.expression,a=>(a.type==="address"&&a.sheet&&a.sheet.toLowerCase()===t&&(a.sheet=r,i=!0),!0)),i))return"="+this.parser.Render(n.expression,{missing:""})}RenameSheetReferences(e,t,r){let i=0;t=t.toLowerCase();for(let n of e){if(n.cells.IterateAll(a=>{if(a.ValueIsFormula()){let s=this.PatchExpressionSheetName(a.value||"",t,r);s&&(a.value=s,i++)}}),n.conditional_formats?.length)for(let a of n.conditional_formats)switch(a.type){case"cell-match":case"expression":{let s=this.PatchExpressionSheetName(a.expression,t,r);s&&(a.expression=s,i++)}break}for(let a of n.annotations)if(a.data.formula){let s=this.PatchExpressionSheetName(a.data.formula,t,r);s&&(a.data.formula=s,i++)}}return i}ApplyBordersInternal(e){let t=e.borders,r=e.borders==="none"?0:e.width,i=new y(e.area.start,e.area.end),n=this.FindSheet(i);i.start.sheet_id=n.id;let a={border_top:r},s={border_bottom:r},o={border_left:r},l={border_right:r},d={border_top:0,border_top_fill:{}},h={border_bottom:0,border_bottom_fill:{}},u={border_left:0,border_left_fill:{}},m={border_right:0,border_right_fill:{}};return e.color?(a.border_top_fill={...e.color},s.border_bottom_fill={...e.color},o.border_left_fill={...e.color},l.border_right_fill={...e.color}):(a.border_top_fill={},s.border_bottom_fill={},o.border_left_fill={},l.border_right_fill={}),(t==="none"||t==="all")&&n.UpdateAreaStyle(i,{...a,...s,...o,...l},!0),(t==="top"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.top,{...a},!0)),(t==="none"||t==="all"||t==="outside"||t==="top")&&(i.entire_column||i.start.row&&n.UpdateAreaStyle(new y({row:i.start.row-1,column:i.start.column},{row:i.start.row-1,column:i.end.column}),{...h},!0)),(t==="bottom"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.bottom,{...s},!0)),(t==="none"||t==="all"||t==="outside"||t==="bottom")&&(i.entire_column||n.UpdateAreaStyle(new y({row:i.end.row+1,column:i.start.column},{row:i.end.row+1,column:i.end.column}),{...d},!0)),(t==="left"||t==="outside")&&(i.entire_row||n.UpdateAreaStyle(i.left,{...o},!0)),(t==="none"||t==="all"||t==="outside"||t==="left")&&(i.entire_row||i.start.column&&n.UpdateAreaStyle(new y({row:i.start.row,column:i.start.column-1},{row:i.end.row,column:i.start.column-1}),{...m},!0)),(t==="right"||t==="outside")&&(i.entire_row||n.UpdateAreaStyle(i.right,{...l},!0)),(t==="none"||t==="all"||t==="outside"||t==="right")&&(i.entire_row||n.UpdateAreaStyle(new y({row:i.start.row,column:i.end.column+1},{row:i.end.row,column:i.end.column+1}),{...u},!0)),y.Bleed(i)}TranslateR1C1(e,t){let r=!1,i=this.parser.flags.r1c1;if(this.parser.flags.r1c1=!0,typeof t=="string"&&t[0]==="="){let n=this.parser.Parse(t);n.expression&&(this.parser.Walk(n.expression,a=>(a.type==="address"&&a.r1c1&&(r=!0,a.offset_column&&(a.column=a.column+e.column),a.offset_row&&(a.row=a.row+e.row)),!0)),r&&(t="="+this.parser.Render(n.expression,{missing:""})))}return this.parser.flags.r1c1=i,t}ClearAreaInternal(e){let t;if(e.start.sheet_id?t=this.model.sheets.Find(e.start.sheet_id):t=this.active_sheet,!t){console.warn("can't resolve sheet in ClearAreaInternal");return}let r=!1;e=t.RealArea(e),t.cells.Apply(e,n=>{n.area&&!e.ContainsArea(n.area)&&(r=!0)});let i=this.model.tables.keys();for(let n of i){let a=this.model.tables.get(n);if(a&&a.area.start.sheet_id===t.id){let s=new y(a.area.start,a.area.end);if(e.ContainsArea(s)){for(let o=s.start.row;o<=s.end.row;o++)for(let l=s.start.column;l<=a.area.end.column;l++){let d=t.cells.GetCell({row:o,column:l},!1);d&&(d.table=void 0)}this.model.tables.delete(n)}}}r?this.Error(2):t.ClearArea(e)}Error(e){this.grid_events.Publish({type:"error",code:e})}DuplicateSheetInternal(e){if(!this.options.add_tab){console.warn("add tab option not set or false");return}let t=this.ResolveSheet(e),r=this.model.sheets.list.reduce((o,l)=>Math.max(o,l.id),0)+1,i=-1;for(let o=0;o<this.model.sheets.length;o++)this.model.sheets.list[o]===t&&(i=o+1);if(!t||i<0)throw new Error("source sheet not found");if(typeof e.insert_before=="number")i=e.insert_before;else if(typeof e.insert_before=="string"){let o=e.insert_before.toLowerCase();for(let l=0;l<this.model.sheets.length;l++)if(this.model.sheets.list[l].name.toLowerCase()===o){i=l;break}}let n={rendered_values:!0},a=Y.FromJSON(t.toJSON(n),this.model.theme_style_properties),s=e.new_name||t.name;for(;this.model.sheets.list.some(o=>o.name===s);){let o=s.match(/^(.*?)(\d+)$/);o?s=o[1]+(Number(o[2])+1):s=s+"2"}return a.name=s,a.id=r,this.model.sheets.Splice(i,0,a),a.id}SelectInternal(e){}FreezeInternal(e){let t=this.FindSheet(e.sheet_id||this.active_sheet.id);t.freeze.rows=e.rows,t.freeze.columns=e.columns}PatchExpression(e,t){let r=0,i=this.parser.Parse(e);if(i.expression&&(this.parser.Walk(i.expression,n=>{if(n.type==="range"){if(!n.start.sheet||n.start.sheet.toLowerCase()===t.sheet.name.toLowerCase()){let a=y.PatchArea(n,t);a?(n.start.row=a.start.row,n.start.column=a.start.column,n.end.row=a.end.row,n.end.column=a.end.column):n.start.row=n.end.row=n.start.column=n.end.column=-1}return r++,!1}else if(n.type==="address"){let a=y.PatchArea({start:n,end:n},t);return a?(n.row=a.start.row,n.column=a.start.column):n.row=n.column=-1,r++,!1}return!0}),r))return this.parser.Render(i.expression,{missing:""})}PatchConditionals(e){if(e.sheet.conditional_formats?.length){let t=new Set;for(let r of e.sheet.conditional_formats){let i=y.PatchArea(r.area,e);if(i)r.area=JSON.parse(JSON.stringify(i));else{t.add(r);continue}switch(r.type){case"expression":case"cell-match":{let n=this.PatchExpression(r.expression,e);n&&(r.expression=n)}break}}t.size&&(e.sheet.conditional_formats=e.sheet.conditional_formats.filter(r=>!t.has(r)))}}InsertRowsInternal(e){let t=this.FindSheet(e.sheet_id);if(e.count===1/0?e.count=1:e.count===-1/0&&(e.count=-t.rows),!t.InsertRows(e.before_row,e.count))return this.Error(2),{error:!0};this.PatchConditionals({sheet:t,before_column:0,column_count:0,before_row:e.before_row,row_count:e.count});let r=Array.from(this.model.tables.values());for(let o of r)if(o.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_row<=o.area.start.row)o.area.start.row+=e.count,o.area.end.row+=e.count;else if(e.before_row<=o.area.end.row){o.area.end.row+=e.count;for(let l=o.area.start.row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=o}}}else if(e.before_row<=o.area.start.row)if(e.before_row-e.count<=o.area.start.row)o.area.start.row+=e.count,o.area.end.row+=e.count;else if(e.before_row-e.count>=o.area.end.row)this.model.tables.delete(o.name.toLowerCase());else{this.model.tables.delete(o.name.toLowerCase());for(let l=e.before_row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table===o&&(h.table=void 0)}}else e.before_row<=o.area.end.row&&(e.before_row-e.count>o.area.end.row&&(o.totals_row=!1),o.area.end.row=Math.max(0,o.area.end.row+e.count,e.before_row-1));this.model.named_ranges.PatchNamedRanges(t.id,0,0,e.before_row,e.count);let i=t.name.toLowerCase();for(let o of this.model.sheets.list){let l=o===t;o.cells.IterateAll(d=>{if(d.ValueIsFormula()){let h=this.PatchFormulasInternal(d.value||"",e.before_row,e.count,0,0,i,l);h&&(d.value=h)}});for(let d of o.annotations)if(d.data.formula){let h=this.PatchFormulasInternal(d.data.formula||"",e.before_row,e.count,0,0,i,l);h&&(d.data.formula=h)}}let n=[],a=[],s=[];if(e.count>0){let o=e.before_row;for(let l of t.annotations)if(l.data.layout){let[d,h,u]=[l.data.layout.tl.address.row,l.data.layout.br.address.row,l.data.layout.br.offset.y];if(o<=d)l.data.layout.tl.address.row+=e.count,l.data.layout.br.address.row+=e.count;else if(o<h||o===h&&u>0)l.data.layout.br.address.row+=e.count,a.push(l);else continue;n.push(l)}}else if(e.count<0){let o=e.before_row,l=e.before_row-e.count-1;for(let d of t.annotations)if(d.data.layout){let[h,u,m]=[d.data.layout.tl.address.row,d.data.layout.br.address.row,d.data.layout.br.offset.y];if(o<=h)if(l<h)d.data.layout.tl.address.row+=e.count,d.data.layout.br.address.row+=e.count;else if(l<u-1||l===u-1&&m>0)d.data.layout.tl.address.row=o,d.data.layout.tl.offset.y=0,d.data.layout.br.address.row+=e.count,a.push(d);else{s.push(d);continue}else if(o<u||o===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.row+=e.count,a.push(d)):(d.data.layout.br.address.row=o,d.data.layout.br.offset.y=0,a.push(d));else continue;n.push(d)}}for(let o of s)t.annotations=t.annotations.filter(l=>l!==o);return{update_annotations_list:n,resize_annotations_list:a,delete_annotations_list:s}}InsertColumnsInternal(e){let t=this.FindSheet(e.sheet_id);if(e.count===1/0?e.count=1:e.count===-1/0&&(e.count=-t.columns),!t.InsertColumns(e.before_column,e.count))return this.Error(2),{error:!0};this.PatchConditionals({sheet:t,before_column:e.before_column,column_count:e.count,before_row:0,row_count:0});let r=Array.from(this.model.tables.values());for(let o of r)if(o.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_column<=o.area.start.column)o.area.start.column+=e.count,o.area.end.column+=e.count;else if(e.before_column<=o.area.end.column){o.area.end.column+=e.count;for(let l=o.area.start.row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=o}this.UpdateTableColumns(o)}}else e.before_column<=o.area.start.column?e.before_column-e.count<=o.area.start.column?(o.area.start.column+=e.count,o.area.end.column+=e.count):e.before_column-e.count>=o.area.end.column?this.model.tables.delete(o.name.toLowerCase()):(o.area.start.column=e.before_column,o.area.end.column+=e.count,this.UpdateTableColumns(o)):e.before_column<=o.area.end.column&&(o.area.end.column=Math.max(0,o.area.end.column+e.count,e.before_column-1),this.UpdateTableColumns(o));this.model.named_ranges.PatchNamedRanges(t.id,e.before_column,e.count,0,0);let i=t.name.toLowerCase();for(let o of this.model.sheets.list){let l=o===t;o.cells.IterateAll(d=>{if(d.ValueIsFormula()){let h=this.PatchFormulasInternal(d.value||"",0,0,e.before_column,e.count,i,l);h&&(d.value=h)}});for(let d of o.annotations)if(d.data.formula){let h=this.PatchFormulasInternal(d.data.formula,0,0,e.before_column,e.count,i,l);h&&(d.data.formula=h)}}let n=[],a=[],s=[];if(e.count>0){let o=e.before_column;for(let l of t.annotations)if(l.data.layout){let[d,h,u]=[l.data.layout.tl.address.column,l.data.layout.br.address.column,l.data.layout.br.offset.x];if(o<=d)l.data.layout.tl.address.column+=e.count,l.data.layout.br.address.column+=e.count;else if(o<h||o===h&&u>0)l.data.layout.br.address.column+=e.count,a.push(l);else continue;n.push(l)}}else if(e.count<0){let o=e.before_column,l=e.before_column-e.count-1;for(let d of t.annotations)if(d.data.layout){let[h,u,m]=[d.data.layout.tl.address.column,d.data.layout.br.address.column,d.data.layout.br.offset.x];if(o<=h)if(l<h)d.data.layout.tl.address.column+=e.count,d.data.layout.br.address.column+=e.count;else if(l<u-1||l===u-1&&m>0)d.data.layout.tl.address.column=o,d.data.layout.tl.offset.x=0,d.data.layout.br.address.column+=e.count,a.push(d);else{s.push(d);continue}else if(o<u||o===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.column+=e.count,a.push(d)):(d.data.layout.br.address.column=o,d.data.layout.br.offset.x=0,a.push(d));else continue;n.push(d)}}for(let o of s)t.annotations=t.annotations.filter(l=>l!==o);return{update_annotations_list:n,resize_annotations_list:a,delete_annotations_list:s}}ExecCommand(e,t=!0){let r={pending:[]},i=[];e=this.NormalizeCommands(e),t&&this.command_log.Publish({command:e,timestamp:new Date().getTime()});for(let n of e)switch(n.key){case 26:this.ResetInternal();break;case 11:if(n.area){let a=new y(n.area.start,n.area.end);this.ClearAreaInternal(a),r.data_area=y.Join(a,r.data_area),r.formula=!0}break;case 5:this.SelectInternal(n);break;case 15:this.FreezeInternal(n),r.structure_event=!0;break;case 28:{let a=this.FindSheet(n.area),s=new y(n.area.start,n.area.end),o=!0;e:for(let l=s.start.row;l<=s.end.row;l++)for(let d=s.start.column;d<=s.end.column;d++){let h=a.cells.GetCell({row:l,column:d},!1);if(h&&(h.area||h.merge_area||h.table)){o=!1;break e}}if(o){let l=this.model.tables.size+1,d="";for(;d=`Table${l++}`,!!this.model.tables.has(d.toLowerCase()););let h={area:n.area,name:d,sortable:n.sortable,theme:n.theme};n.totals&&(h.totals_row=!0),this.model.tables.set(d.toLowerCase(),h);for(let u=s.start.row;u<=s.end.row;u++)for(let m=s.start.column;m<=s.end.column;m++){let f=a.cells.GetCell({row:u,column:m},!0);f.table=h}this.UpdateTableColumns(h),a.Invalidate(new y(h.area.start,h.area.end)),a===this.active_sheet?(r.style_area=y.Join(s,r.style_area),r.render_area=y.Join(s,r.render_area)):r.style_event=!0}}break;case 29:{let a=this.FindSheet(n.table.area),s=new y(n.table.area.start,n.table.area.end);for(let l=s.start.row;l<=s.end.row;l++)for(let d=s.start.column;d<=s.end.column;d++){let h=a.cells.GetCell({row:l,column:d},!1);h&&(h.table=void 0)}this.model.tables.delete(n.table.name.toLowerCase());let o=a.RealArea(s.Clone().Shift(-1,-1).Resize(s.rows+2,s.columns+2));a.Invalidate(o),a===this.active_sheet?(r.style_area=y.Join(s,r.style_area),r.render_area=y.Join(s,r.render_area)):r.style_event=!0}break;case 9:{let a=this.FindSheet(n.area);a.MergeCells(new y(n.area.start,n.area.end)),r.structure_event=!0,r.structure_rebuild_required=!0,a===this.active_sheet?(r.data_area=y.Join(n.area,r.data_area),r.render_area=y.Join(n.area,r.render_area)):(r.data_event=!0,r.pending||(r.pending=[]),r.pending.push(a.id))}break;case 10:{let a=this.FindSheet(n.area),s={},o=new y(n.area.start,n.area.end);a.cells.Apply(o,d=>{if(d.merge_area){let h=y.CellAddressToLabel(d.merge_area.start)+":"+y.CellAddressToLabel(d.merge_area.end);s[h]=d.merge_area}},!1);let l=Object.keys(s);for(let d=0;d<l.length;d++)a.UnmergeCells(s[l[d]]);a===this.active_sheet?(r.render_area=y.Join(n.area,r.render_area),r.data_area=y.Join(n.area,r.data_area)):(r.data_event=!0,r.pending||(r.pending=[]),r.pending.push(a.id)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 7:{let a,s=this.FindSheet(n.area);N(n.area)?(a=new y(n.area),s.UpdateCellStyle(n.area,n.style,!!n.delta)):(a=new y(n.area.start,n.area.end),s.UpdateAreaStyle(a,n.style,!!n.delta)),s===this.active_sheet?(r.style_area=y.Join(a,r.style_area),(!n.delta||n.style.fill||n.style.border_top||n.style.border_left||n.style.border_right||n.style.border_bottom)&&(a=y.Bleed(a),this.active_sheet.Invalidate(a)),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}break;case 25:this.SetValidationInternal(n),(!n.area.sheet_id||n.area.sheet_id===this.active_sheet.id)&&(r.render_area=y.Join(new y(n.area),r.render_area));break;case 16:n.area?(this.model.named_expressions.delete(n.name),this.model.named_ranges.SetName(n.name,new y(n.area.start,n.area.end)),this.autocomplete_matcher.AddFunctions({type:1,name:n.name})):n.expression?(this.model.named_ranges.ClearName(n.name),this.model.named_expressions.set(n.name,n.expression),this.autocomplete_matcher.AddFunctions({type:1,name:n.name})):(this.model.named_ranges.ClearName(n.name),this.model.named_expressions.delete(n.name),this.autocomplete_matcher.RemoveFunctions({type:1,name:n.name})),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 8:{let a=this.ApplyBordersInternal(n);a.start.sheet_id===this.active_sheet.id?(r.render_area=y.Join(a,r.render_area),r.style_area=y.Join(a,r.style_area)):r.style_event=!0}break;case 24:this.ShowSheetInternal(n),r.sheets=!0,r.structure_event=!0;break;case 23:{let a=[],s=this.model.sheets.list[n.index];for(let o=0;o<this.model.sheets.length;o++)o!==n.index&&(o===n.move_before&&a.push(s),a.push(this.model.sheets.list[o]));n.move_before>=this.model.sheets.length&&a.push(s),this.model.sheets.Assign(a),r.sheets=!0,r.structure_event=!0}break;case 22:{let a=this.ResolveSheet(n);a&&(this.RenameSheetInternal(a,n.new_name),r.sheets=!0,r.structure_event=!0)}break;case 3:{let a=this.ResizeRowsInternal(n);if(a)if(a.start.sheet_id===this.active_sheet.id){let s=this.active_sheet.RealArea(new y(a.start,a.end));r.render_area=y.Join(s,r.render_area),r.data_area=y.Join(s,r.data_area),r.data_event=!0}else r.data_event=!0,r.pending||(r.pending=[]),a.start.sheet_id&&r.pending.push(a.start.sheet_id);r.structure_event=!0}break;case 4:this.ResizeColumnsInternal(n),r.structure_event=!0;break;case 17:this.active_sheet.SetHeaderSize(n.show?void 0:1,n.show?void 0:1),this.flags.layout=!0,this.flags.repaint=!0;break;case 1:this.InsertRowsInternal(n),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 2:this.InsertColumnsInternal(n),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 14:case 13:{let a=this.FindSheet(n.area),s=a.cells.GetCell(n.area,!0);if(s){let o;s.merge_area?(o=new y(s.merge_area.start),s=a.cells.GetCell(s.merge_area.start,!0)):o=new y(n.area),n.key===13?s.SetNote(n.note):(s.hyperlink=n.reference||void 0,s.render_clean=[]),a===this.active_sheet?(r.style_area=y.Join(o,r.style_area),r.render_area=y.Join(o,r.render_area)):r.style_event=!0}}break;case 27:{let a=this.SortTableInternal(n);a&&a.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(a,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(a,r.render_area))):r.data_event=!0}break;case 6:{let a=this.SetRangeInternal(n,r);if(a){let o=this.model.sheets.Find(a.start.sheet_id||this.active_sheet.id)?.TablesFromArea(a,!0)||[];for(let l of o)this.UpdateTableColumns(l)}a&&a.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(a,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(a,r.render_area))):r.data_event=!0}break;case 20:this.DeleteSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 19:this.DuplicateSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 18:{let a=this.AddSheetInternal(n.name,n.insert_index);typeof a=="number"&&n.show&&this.ActivateSheetInternal({key:21,id:a}),r.structure_event=!0,r.sheets=!0,r.structure=!0}break;case 21:this.ActivateSheetInternal(n);break;default:console.warn(`unhandled command: ${tt[n.key]} (${n.key})`)}return r.data_area?(r.data_area.start.sheet_id||r.data_area.SetSheetID(this.active_sheet.id),i.push({type:"data",area:r.data_area})):r.data_event&&i.push({type:"data"}),r.style_area?(r.style_area.start.sheet_id||r.style_area.SetSheetID(this.active_sheet.id),i.push({type:"style",area:r.style_area})):r.style_event&&i.push({type:"style"}),r.structure_event&&i.push({type:"structure",rebuild_required:r.structure_rebuild_required}),this.batch?this.batch_events.push(...i):this.grid_events.Publish(i),r}};var Nt=class extends Me{get active(){return this.nodes.length>0}Reset(){this.AttachNodes()}AttachNodes(e=[],t=!0){this.assume_formula=t;let r=[];r=e.map(i=>{for(let n of this.nodes)if(n.node===i)return n;return{node:i}});for(let i of this.nodes)if(i.listeners){for(let[n,a]of i.listeners.entries())i.node.removeEventListener(n,a);i.listeners.clear()}this.nodes=r;for(let i of this.nodes){if(i.formatted_text===i.node.textContent){let n=i.node.innerHTML.length;i.check!==n&&(i.formatted_text=void 0)}i.node.ownerDocument.activeElement===i.node&&(this.active_editor=i),this.UpdateText(i,{toll_events:!0}),this.RegisterListener(i,"focusin",()=>{this.active_editor=i}),this.RegisterListener(i,"focusout",()=>{this.active_editor=void 0}),this.RegisterListener(i,"input",n=>{n.isTrusted&&(this.UpdateText(i),this.UpdateColors())})}this.UpdateColors(!0)}};var it=class extends rt{hide_selection=!1;headless=!1;get scale(){return this.layout.scale}set scale(e){this.layout.scale=e,this.UpdateLayout(),this.UpdateAnnotationLayout(),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.layout.ApplyTheme(this.theme),this.overlay_editor?.UpdateScale(e),this.tab_bar?.UpdateScale(e),this.grid_events.Publish({type:"scale",scale:e});for(let t of this.model.sheets.list)for(let r of t.annotations)r.dirty=!0}theme;language_map;reverse_language_map;hover_data={};editing_state=0;editing_cell={row:-1,column:-1,sheet_id:0};selected_annotation;editing_annotation;view_node;container;layout;tile_update_pending=!1;scroll_offset_pending;pending_layout_update=new Set;decimal_separator_code=46;overlay_editor;autocomplete;formula_bar;RESIZE_PIXEL_BUFFER=5;external_editor_config;external_editor;cell_resize={row:-1,column:-1};render_tiles=new y({row:0,column:0});primary_selection={target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0};active_selection={target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0};nub_select_flag=!1;additional_selections=[];double_click_data={};layout_token=0;render_token=0;tile_renderer;selection_renderer;tab_bar;DOM=F.GetInstance();constructor(e={},t,r=ht,i=!0,n){if(super(e,t),this.decimal_separator_code=D.decimal_separator.charCodeAt(0),this.theme=JSON.parse(JSON.stringify(r)),!i){this.headless=!0,this.layout=new Rt(this.model,this.view);return}this.DOM=n,this.layout=new Tt(this.model,this.view,n),e.initial_scale&&(typeof e.initial_scale=="string"&&(e.initial_scale=Number(e.initial_scale)),this.layout.scale=e.initial_scale),this.tile_renderer=new zt(this.theme,this.layout,this.model,this.view,this.options),this.selection_renderer=new At(this.theme,this.layout,this.model,this.view,this.primary_selection,this.additional_selections)}SetLanguageMap(e){if(!e)this.language_map=this.reverse_language_map=void 0;else{let t=Object.keys(e);this.language_map={};for(let r of t)this.language_map[r.toUpperCase()]=e[r];this.reverse_language_map={};for(let r of t){let i=e[r];this.reverse_language_map[i.toUpperCase()]=r}}this.primary_selection.empty||this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target)}SetNote(e,t){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.target}this.ExecCommand({key:13,area:e,note:t})}FindAnnotation(e){for(let t of this.active_sheet.annotations)if((t.view[this.view_index]||{}).node===e)return t}CreateAnnotation(e={},t=!0,r=!1,i){let n=new Ee(e);if(r)if(!n.data.layout&&n.scaled_rect&&(n.data.layout=this.layout.RectToAnnotationLayout(n.scaled_rect)),!n.data.layout)console.warn("can't offset annotation without layout");else{let a=this.layout.AnnotationLayoutToRect(n.data.layout).Shift(20,20),s=!0;for(;s;){s=!1;for(let o of this.active_sheet.annotations)if(o!==n&&o.scaled_rect&&o.scaled_rect.top===a.top&&o.scaled_rect.left===a.left){a=a.Shift(20,20),s=!0;break}}n.data.layout=this.layout.RectToAnnotationLayout(a)}return i&&(H.IsRectangle(i)?(n.data.layout=void 0,n.rect=H.Create(i)):i.start&&(n.rect=void 0,n.data.layout=this.layout.AddressToAnnotationLayout(i.start,i.end||i.start))),t&&(this.active_sheet.annotations.some(a=>a===n)||this.active_sheet.annotations.push(n),this.AddAnnotation(n)),n}UpdateAnnotationLayout(){}AddAnnotation(e,t=!1,r=!0){let i=e.view[this.view_index];if(i||(i={},e.view[this.view_index]=i),!i.node){let n=this.DOM.Div("annotation",void 0,{data:{scale:this.layout.scale.toString()},style:{fontSize:`${10*this.layout.scale}pt`},attrs:{tabindex:"-1"},events:{mousedown:o=>{o.button===0&&this.layout.AnnotationMouseDown(e,n,o,a,s).then(l=>{l&&this.grid_events.Publish(l),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)})},focusin:()=>{for(let o of this.layout.GetFrozenAnnotations(e))o.classList.add("clone-focus");this.selected_annotation=e,this.primary_selection.empty=!0,this.primary_selection.target={row:-1,column:-1,sheet_id:this.active_sheet.id},this.HideGridSelection()},focusout:o=>{for(let l of this.layout.GetFrozenAnnotations(e))l.classList.remove("clone-focus");this.formula_bar&&this.formula_bar.IsElement(o.relatedTarget)?(this.primary_selection.empty=!0,this.RenderSelections(),this.editing_annotation=e,this.layout.ShowSelections(!0)):(this.selected_annotation===e&&(this.selected_annotation=void 0),this.ShowGridSelection())}}});i.node=n,i.content_node=this.DOM.Div("annotation-content",n);let a=this.DOM.Div("annotation-move-target",n),s=this.DOM.Div("annotation-resize-target",n);n.addEventListener("keydown",o=>{let l=e.scaled_rect;if(!l){console.info("missing scaled rect!");return}let d=[n,...this.layout.GetFrozenAnnotations(e)],h={x:l.left,y:l.top};switch(o.key){case"ArrowUp":case"Up":o.ctrlKey?(this.layout.AnnotationLayoutOrder(e,1)&&this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),n.focus()):h.y--;break;case"ArrowLeft":case"Left":if(o.ctrlKey)return;h.x--;break;case"ArrowRight":case"Right":if(o.ctrlKey)return;h.x++;break;case"ArrowDown":case"Down":o.ctrlKey?(this.layout.AnnotationLayoutOrder(e,-1)&&this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),n.focus()):h.y++;break;case"Escape":case"Esc":this.Focus();break;case"Delete":case"Del":this.Focus(),this.RemoveAnnotation(e);break;default:return}if(o.stopPropagation(),o.preventDefault(),h.x=Math.max(h.x,0),h.y=Math.max(h.y,0),l.left!==h.x||l.top!==h.y){l.left=Math.round(h.x),l.top=Math.round(h.y);for(let u of d)u.style.top=l.top+"px",u.style.left=l.left+"px";e.data.extent=void 0,this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),e.data.layout=this.layout.RectToAnnotationLayout(l)}})}r&&(this.layout.AddAnnotation(e),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)),t||this.grid_events.Publish({type:"annotation",annotation:e,event:"create"})}AnnotationUpdated(e){this.layout.CloneFrozenAnnotation(e)}RemoveAnnotation(e){for(let t=0;t<this.active_sheet.annotations.length;t++)if(e===this.active_sheet.annotations[t]){this.active_sheet.annotations.splice(t,1),this.layout.RemoveAnnotation(e),this.grid_events.Publish({type:"annotation",annotation:e,event:"delete"});return}}RemoveAnnotationNodes(){this.headless||this.layout.RemoveAnnotationNodes()}Serialize(e={}){return this.active_sheet.selection=JSON.parse(JSON.stringify(this.primary_selection)),this.active_sheet.scroll_offset=this.layout.scroll_offset,super.Serialize(e)}ShowHeaders(e=!0){this.ExecCommand({key:17,show:e})}FromImportData(e,t=!1){this.RemoveAnnotationNodes();let r=e.sheets,i=r.map(()=>Y.Blank(this.model.theme_style_properties).toJSON()),n;if(typeof e.active_tab=="number")n=i[e.active_tab]?.id;else for(let s=0;s<e.sheets.length;s++)if(!e.sheets[s].hidden){n=i[s].id;break}this.UpdateSheets(i,!0,n);let a={};this.model.macro_functions.clear(),this.ClearSelection(this.primary_selection),this.model.tables.clear();for(let s=0;s<r.length;s++){let o=this.model.sheets.list[s];o.ImportData(r[s]),a[o.name]=o.id;for(let l of r[s].cells)l.table&&(l.table.area.start.sheet_id=o.id,this.model.tables.set(l.table.name.toLowerCase(),l.table));for(let l of this.model.tables.values())this.UpdateTableColumns(l)}if(this.model.sheets.UpdateIndexes(),this.model.named_ranges.Reset(),this.model.named_expressions.clear(),e.names){for(let s of Object.keys(e.names)){let o=this.model.named_ranges.ValidateNamed(s);if(!o){console.warn(`invalid name: ${s}`);continue}let l=e.names[s];if(typeof l!="number"){let d=this.parser.Parse(l);if(d.expression)if(d.expression.type==="range"){let h=a[d.expression.start.sheet||""];h&&(d.expression.start.sheet_id=h,this.model.named_ranges.SetName(o,new y(d.expression.start,d.expression.end),!1))}else if(d.expression.type==="address"){let h=a[d.expression.sheet||""];h&&(d.expression.sheet_id=h,this.model.named_ranges.SetName(o,new y(d.expression),!1))}else{let h=d.expression;this.parser.Walk(h,u=>u.type==="address"||u.type==="range"?(u.type==="range"&&(u=u.start),u.sheet_id||(u.sheet_id=a[u.sheet||""]||0),!1):!0),this.model.named_expressions.set(o,h)}}}this.model.named_ranges.RebuildList()}for(let s of this.active_sheet.annotations)this.AddAnnotation(s,!0);this.ActivateSheetTasks(),this.QueueLayoutUpdate(),this.StyleDefaultFromTheme(),t&&this.Repaint(!1,!1),this.tab_bar&&this.tab_bar.Update()}NextSheet(e=1){if(this.model.sheets.length===1)return;let t=this.model.sheets.list.map((r,i)=>({sheet:r,index:i})).filter(r=>r.sheet.visible);if(t.length!==1){for(let r=0;r<t.length;r++)if(t[r].sheet===this.active_sheet){let i=(r+e)%t.length;for(;i<0;)i+=t.length;this.ActivateSheet(t[i].index);return}}}UpdateSheets(e,t=!1,r){if(super.UpdateSheets(e,t,r),this.RemoveAnnotationNodes(),this.ClearSelection(this.primary_selection),e[0]&&e[0].primary_selection){let i=e[0].primary_selection;i.empty||this.Select(this.primary_selection,new y(i.area.start,i.area.end),i.target)}else if(!this.active_sheet.selection.empty){let i=this.active_sheet.selection;this.Select(this.primary_selection,new y(i.area.start,i.area.end),i.target)}this.layout.ClearLayoutCaches();for(let i of this.model.sheets.list)for(let n of i.annotations)this.AddAnnotation(n,!0,i===this.active_sheet);this.ActivateSheetTasks(),this.QueueLayoutUpdate(JSON.parse(JSON.stringify(this.active_sheet.scroll_offset))),this.StyleDefaultFromTheme(),t&&this.Repaint(!1,!1),this.tab_bar&&this.tab_bar.Update()}UpdateLayout(){this.layout.UpdateTiles(),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!0)}UpdateTheme(e=!1,t){if(!e)for(let i of Object.keys(this.theme))delete this.theme[i];let r=JSON.parse(JSON.stringify(ht));this.view_node&&(r={...Hr(this.view_node)}),r={...this.theme,...r,...t},Object.assign(this.theme,r),this.StyleDefaultFromTheme(),this.active_sheet.UpdateDefaultRowHeight(),this.active_sheet.FlushCellStyles(),this.layout.ApplyTheme(this.theme),e||(this.UpdateLayout(),this.overlay_editor?.UpdateScale(this.layout.scale),this.Repaint(!0,!0,!0))}Initialize(e,t=!1){if(!this.tile_renderer||!this.selection_renderer)return;this.view_node=e,this.UpdateTheme(!0);let i=e.querySelector(".treb-spreadsheet-body").querySelector("div");this.options.formula_bar&&(this.autocomplete||(this.autocomplete=new et({theme:this.theme,container:i})),this.InitFormulaBar(e,this.autocomplete)),this.options.tab_bar&&(this.tab_bar=new kt(this.layout,this.model,this.view,this.options,e),this.tab_bar.Subscribe(n=>{switch(n.type){case"cancel":break;case"scale":{let a=this.layout.scale;if(a=Math.round(n.value*1e3)/1e3,a=Math.min(2,Math.max(a,.5)),this.options.persist_scale_key&&localStorage.setItem(this.options.persist_scale_key,JSON.stringify({scale:a})),this.scale=a,n.keep_focus)return}break;case"reorder-sheet":this.ReorderSheet(n.index,n.move_before);break;case"delete-sheet":this.DeleteSheet();break;case"add-sheet":this.AddSheet();break;case"rename-sheet":this.RenameSheet(n.sheet,n.name);break;case"activate-sheet":this.ActivateSheetID(n.sheet.id);break}this.SelectingArgument()||this.Focus()})),this.container=i,this.container.classList.add("treb-grid"),re.is_mac&&re.is_safari&&this.container.classList.add("safari"),this.container.setAttribute("tabindex","-1"),this.layout.Initialize(i,{scroll:()=>this.OnScroll(),dropdown:n=>this.OnDropdownSelect(n),sort:(n,a,s)=>{let o=this.model.tables.get(n.toLowerCase());o&&this.SortTable(o,{column:a,asc:s})},focus:()=>this.Focus()},this.options.scrollbars),this.selection_renderer.Initialize(),this.layout.UpdateTiles(),this.autocomplete||(this.autocomplete=new et({theme:this.theme,container:i})),this.InitOverlayEditor(this.autocomplete),this.AttachListeners(),this.render_tiles=this.layout.VisibleTiles(),t||(this.tab_bar?.Update(),this.Repaint(!0))}MergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:9,area:e||this.primary_selection.area}))}UnmergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:10,area:e||this.primary_selection.area}))}Focus(e=""){re.is_mobile?this.container?.focus():this.overlay_editor?.Focus(e)}SetValidation(e,t,r){if(!e){if(this.primary_selection.empty)throw new Error("invalid target in set validation");e=this.primary_selection.target}let i={key:25,area:e,error:r};t&&(Array.isArray(t)?i.list=t:typeof t=="object"&&t.start&&t.end&&N(t.start)&&N(t.end)&&(i.range=t)),this.ExecCommand(i),!this.primary_selection.empty&&(!e.sheet_id||e.sheet_id===this.active_sheet.id)&&this.primary_selection.target.row===e.row&&this.primary_selection.target.column===e.column&&requestAnimationFrame(()=>this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target))}SetName(e,t,r){let i=this.model.named_ranges.ValidateNamed(e);if(!i)throw new Error("invalid name");let n=e.trim().toUpperCase();if(this.autocomplete_matcher){for(let s of Object.keys(this.autocomplete_matcher.function_map))if(n===s.toUpperCase()){if(t||r)throw new Error("name already defined");break}}e=i;let a={key:16,name:e};if(t)N(t)&&(t=new y(t)),t.start.sheet_id||(t=new y({...t.start,sheet_id:this.active_sheet.id},t.end)),a.area=new y(t.start,t.end);else if(r){let s=this.parser.Parse(r);if(s.valid&&s.expression)this.parser.Walk(s.expression,o=>{if(o.type==="address"||o.type==="range"){if(o.type==="range"&&(o=o.start),!o.sheet_id&&o.sheet){let l=this.model.sheets.Find(o.sheet);l&&(o.sheet_id=l.id)}return o.sheet_id||(o.sheet_id=this.active_sheet.id),!1}return!0}),a.expression=s.expression;else throw new Error("invalid expression")}this.ExecCommand(a)}SelectAll(){this.Select(this.primary_selection,new y({row:1/0,column:1/0}),void 0,!0),this.RenderSelections()}ExternalEditor(e){if(this.external_editor_config=e,e){let t=(e.dependencies||[]).filter(r=>!!r).map(r=>N(r)?new y(r):new y(r.start,r.end));if(e.nodes?.length){if(!this.external_editor){let r=new Nt(this.model,this.view);this.external_editor=r,r.Subscribe(i=>this.HighlightDependencies(r.dependencies))}this.external_editor.AttachNodes(e.nodes,e.assume_formula??!0)}else this.external_editor&&this.external_editor.Reset();e.dependencies&&this.HighlightDependencies(t)}else this.external_editor&&this.external_editor.Reset(),this.ClearAdditionalSelections(),this.RenderSelections(!0)}SelectRange(e){this.Select(this.primary_selection,e),this.RenderSelections()}GetRangeStyle(e,t=!1){let r=0;if(N(e)?r=e.sheet_id||this.active_sheet.id:r=e.start.sheet_id||this.active_sheet.id,r)return this.model.sheets.Find(r)?.GetCellStyle(e,t)||void 0}GetRange(e,t){if(N(e)){let i=this.model.sheets.Find(e.sheet_id||this.active_sheet.id);return i?t==="formula"?i.cells.RawValue(e):t==="formatted"?i.GetFormattedRange(e):i.cells.GetRange(e):void 0}let r=this.model.sheets.Find(e.start.sheet_id||this.active_sheet.id);if(r)return t==="formula"?r.cells.RawValue(e.start,e.end):t==="formatted"?r.GetFormattedRange(e.start,e.end):r.cells.GetRange(e.start,e.end)}SetRange(e,t,r={}){let{recycle:i,transpose:n,array:a,r1c1:s}=r;if(r.argument_separator){let o={argument_separator:this.parser.argument_separator,decimal_mark:this.parser.decimal_mark},l=!1;if(r.argument_separator===","&&this.parser.argument_separator!==","&&(this.parser.argument_separator=",",this.parser.decimal_mark=".",l=!0),r.argument_separator===";"&&this.parser.argument_separator!==";"&&(this.parser.argument_separator=";",this.parser.decimal_mark=",",l=!0),l){let d=h=>{if(typeof h=="string"&&h[0]==="="){let u=this.parser.Parse(h);u.expression&&(h="="+this.parser.Render(u.expression,{missing:"",convert_decimal:o.decimal_mark,convert_argument_separator:o.argument_separator}))}return h};Array.isArray(t)?t=t.map(h=>Array.isArray(h)?h.map(u=>d(u)):d(h)):t=d(t)}this.parser.argument_separator=o.argument_separator,this.parser.decimal_mark=o.decimal_mark}if(t=this.UntranslateData(t),!Array.isArray(t))i||a?this.ExecCommand({key:6,area:e,value:t,array:a,r1c1:s}):this.ExecCommand({key:6,area:e.start,value:t,array:a,r1c1:s});else{if(!ir(t))if(i){let o=e.entire_column?this.active_sheet.rows:e.rows,l=e.entire_row?this.active_sheet.columns:e.columns,d=o*l;if(d>t.length){let u=t.slice(0),m=Math.ceil(d/u.length);for(let f=1;f<m;f++)u=u.concat(t.slice(0));t=u}let h=[];for(let u=0,m=0;u<l;u++,m+=o)h[u]=t.slice(m,m+o);t=h}else t=[t];n&&(t=this.Transpose(t)),this.ExecCommand({key:6,area:e,value:t,array:a,r1c1:s})}!this.primary_selection.empty&&e.Contains(this.primary_selection.target)&&this.UpdateFormulaBarFormula()}ApplyStyle(e,t={},r=!0){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.area}Y.UpdateStyle(t),this.ExecCommand({key:7,area:e,style:t,delta:r}),this.UpdateFormulaBarFormula()}GetSelection(){return this.primary_selection}Update(e=!1,t){this.DelayedRender(e,t)}ApplyBorders2(e,t="none",r,i=1){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.area}t==="none"&&(i=0),this.ExecCommand({key:8,color:r,area:e,borders:t,width:i})}Batch(e,t=!0){this.batch=!0,e(),this.batch=!1;let r=this.batch_events.slice(0);return this.batch_events=[],t&&this.DelayedRender(!1),r}ScrollTo(e,t=!0,r=!0,i=!1){this.layout.ScrollTo(e,t,r,i)}ScrollIntoView(e){this.options.scrollbars&&this.layout.ScrollIntoView(e)}GetScrollOffset(){return this.layout.GetScrollOffset()}ScrollOffset(e){if(e)this.layout.scroll_offset=e;else return this.layout.scroll_offset}TranslateInternal(e,t){let r=this.parser.Parse(e);if(r.expression){let i=!1;if(this.parser.Walk(r.expression,n=>{if(n.type==="call"){let a=t[n.name.toUpperCase()];a&&(i=!0,n.name=a)}return!0}),i)return"="+this.parser.Render(r.expression,{missing:""})}return e}RenameSheetInternal(e,t){super.RenameSheetInternal(e,t),this.tab_bar?.Update()}TranslateFunction(e){return this.language_map?this.TranslateInternal(e,this.language_map):e}UntranslateFunction(e){return this.reverse_language_map?this.TranslateInternal(e,this.reverse_language_map):e}UntranslateData(e){return Array.isArray(e)?ir(e)?e.map(t=>t.map(r=>r&&typeof r=="string"&&r[0]==="="?this.UntranslateFunction(r):r)):e.map(t=>t&&typeof t=="string"&&t[0]==="="?this.UntranslateFunction(t):t):(e&&typeof e=="string"&&e[0]==="="&&(e=this.UntranslateFunction(e)),e)}StyleDefaultFromTheme(){this.model.theme_style_properties.font_face=this.theme.grid_cell?.font_face||"",this.model.theme_style_properties.font_size=this.theme.grid_cell?.font_size||{unit:"pt",value:10}}AutoSizeColumn(e,t,r=!0){if(!this.tile_renderer)return;let i=12,n=4*2;r||(i=e.GetColumnWidth(t));for(let a=0;a<e.cells.rows;a++){let s=e.CellData({row:a,column:t}),o=s.formatted||"";if(typeof o!="string"&&(o=o.map(l=>l.text).join("")),o&&o.length){let l=this.tile_renderer.MeasureText(o,V.Font(s.style||{}));i=Math.max(i,Math.ceil(l.width)+n)}}e.SetColumnWidth(t,i)}EnsureActiveSheet(e=!1){for(let t of this.model.sheets.list)if(t===this.active_sheet){e&&this.ActivateSheetInternal({key:21,id:t.id,force:!0});return}this.ActivateSheetInternal({key:21,index:0})}ActivateSheetInternal(e){let t=this.SelectingArgument(),r=this.ResolveSheet(e)||this.model.sheets.list[0];if(this.active_sheet===r&&!e.force)return;if(!r.visible)throw new Error("cannot activate hidden sheet");this.HideHoverInfo(),this.active_sheet.selection=JSON.parse(JSON.stringify(this.primary_selection)),this.active_sheet.scroll_offset=this.layout.scroll_offset;let i=this.active_sheet;this.RemoveAnnotationNodes(),this.active_sheet=r,t?this.RenderSelections():(this.ClearSelection(this.primary_selection),r.selection&&!r.selection.empty&&this.Select(this.primary_selection,new y(r.selection.area.start,r.selection.area.end),r.selection.target));let n=this.active_sheet.annotations;for(let a of n)this.AddAnnotation(a,!0);this.ActivateSheetTasks(),this.QueueLayoutUpdate(),this.pending_layout_update.has(this.active_sheet.id)?(this.Repaint(!0,!0),this.pending_layout_update.delete(this.active_sheet.id)):this.Repaint(!1,!1),this.grid_events.Publish({type:"sheet-change",deactivate:i,activate:this.active_sheet}),this.tab_bar&&this.tab_bar.Update(),this.layout.scroll_offset=this.active_sheet.scroll_offset,this.formula_bar?.selecting&&requestAnimationFrame(()=>this.formula_bar?.FocusEditor())}ActivateSheetTasks(){if(this.active_sheet.Activate(this.DOM),this.active_sheet.image&&!this.active_sheet.image.complete){let e=this.active_sheet.image,t=0,r=()=>{e.complete?this.UpdateLayout():t++<5&&setTimeout(()=>r(),10)};r()}}HighlightFreezeArea(){for(let e of[this.layout.corner_selection,this.layout.row_header_selection,this.layout.column_header_selection])e.classList.add("highlight-area"),setTimeout(()=>{e.classList.remove("highlight-area")},400)}QueueLayoutUpdate(e){this.tile_update_pending=!0,e&&(this.scroll_offset_pending=e)}HandleAddressLabelEvent(e){if(e){let t=(a="")=>{let s=a.toLowerCase();for(let o of this.model.sheets.list)if(o.name.toLowerCase()===s)return o.id;return this.active_sheet.id},r=a=>{for(let s of this.model.sheets.list)if(s.id===a)return s;return this.active_sheet},i,n=this.parser.Parse(e);if(n.expression)switch(n.expression.type){case"address":n.expression.sheet_id=t(n.expression.sheet),i=new y(n.expression);break;case"range":n.expression.start.sheet_id=t(n.expression.start.sheet),i=new y(n.expression.start,n.expression.end);break;case"identifier":i=this.model.named_ranges.Get(n.expression.name),i||this.primary_selection.empty||this.SetName(n.expression.name.toUpperCase(),this.primary_selection.area);break;default:break}if(i){let a=r(i.start.sheet_id);if(a.columns>=i.end.column&&a.rows>=i.end.row){this.ExecCommand({key:5,area:i});return}else console.warn("address out of range")}}this.UpdateAddressLabel(),this.Focus()}InitFormulaBar(e,t){this.formula_bar=new Dt(e,this.model,this.view,this.options,t),this.formula_bar.autocomplete_matcher=this.autocomplete_matcher,this.formula_bar.Subscribe(r=>{switch(r.type){case"address-label-event":this.HandleAddressLabelEvent(r.text);break;case"stop-editing":this.editing_state=0;break;case"start-editing":this.editing_state=2,this.editing_cell={...this.primary_selection.target};break;case"discard":if(this.editing_state=0,this.editing_annotation){this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection);let i=this.editing_annotation.view[this.view_index]?.node;i&&i.focus(),this.editing_annotation=void 0,this.UpdateFormulaBarFormula(),this.DelayedRender();return}this.container&&this.Focus(),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),this.UpdateFormulaBarFormula(),this.DelayedRender();break;case"commit":if(this.active_sheet.id!==this.editing_cell.sheet_id&&this.editing_cell.sheet_id&&this.ActivateSheetID(this.editing_cell.sheet_id),this.editing_state=0,this.editing_annotation){let i=this.editing_annotation;this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),i.data.formula=r.value?this.FixFormula(r.value):"";let n=this.editing_annotation.view[this.view_index]?.node;n&&n.focus(),this.grid_events.Publish({type:"annotation",event:"update",annotation:i}),this.editing_annotation=void 0,this.DelayedRender();return}this.container&&this.Focus(),this.SetInferredType(this.primary_selection,r.value,r.array),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),this.options.repaint_on_cell_change&&this.DelayedRender(!1,this.primary_selection.area),r.event&&this.OverlayKeyDown(r.event);break;case"update":r.dependencies&&this.HighlightDependencies(r.dependencies);break}})}InitOverlayEditor(e){this.container&&(this.overlay_editor=new Mt(this.container,this.theme,this.model,this.view,e),this.overlay_editor.UpdateScale(this.layout.scale),this.overlay_editor.autocomplete_matcher=this.autocomplete_matcher,this.overlay_editor.Subscribe(t=>{switch(t.type){case"stop-editing":this.editing_state=0;break;case"start-editing":this.editing_state=1,this.editing_cell={...this.primary_selection.target};break;case"update":t.dependencies&&this.HighlightDependencies(t.dependencies);break;case"end-selection":case"reset-selection":this.ClearSelection(this.active_selection),this.overlay_editor?.target_address?.sheet_id&&this.active_sheet.id!==this.overlay_editor.target_address.sheet_id&&this.ActivateSheetID(this.overlay_editor.target_address.sheet_id),this.DelayedRender();break}}))}DelayedRender(e=!1,t,r=!1){!this.tile_update_pending&&t?this.layout.DirtyArea(t):!this.tile_update_pending&&e&&this.layout.DirtyAll(),this.render_token||(this.render_token=1,Promise.resolve().then(()=>{this.render_token=0,this.Repaint(e,r)}))}Repaint(e=!1,t=!1,r=!1){if(this.headless||!this.tile_renderer)return;if(this.tile_update_pending&&(this.tile_update_pending=!1,this.layout.UpdateTiles(),this.scroll_offset_pending&&(this.layout.scroll_offset=this.scroll_offset_pending,this.scroll_offset_pending=void 0),this.render_tiles=this.layout.VisibleTiles(),this.layout.UpdateAnnotation(this.active_sheet.annotations)),this.layout_token=0,this.tile_renderer.OverflowDirty(t),e)for(let o of this.layout.grid_tiles)for(let l of o)l.dirty=!0;let i=this.render_tiles.start,n=this.render_tiles.end,a=[];for(let o=i.row;o<=n.row;o++)a.push(o);let s=[];for(let o=i.column;o<=n.column;o++)s.push(o);i.row>0&&this.active_sheet.freeze.rows&&a.push(0),i.column>0&&this.active_sheet.freeze.columns&&s.push(0);for(let o of s)for(let l of a){let d=this.layout.grid_tiles[o][l];(e||d.dirty||d.needs_full_repaint)&&(this.tile_renderer.Render(d),d.dirty=d.needs_full_repaint=!1)}this.tile_renderer.RenderHeaders(this.render_tiles,r),this.tile_renderer.RenderCorner(),this.RenderSelections()}MouseMove_RowHeader(e){let t=this.layout.CoordinateToRowHeader(e.offsetY),r=this.layout.OffsetCellAddressToRectangle({row:t.row,column:0});this.hover_data.address&&(this.hover_data.address.row!==-1||this.hover_data.address.column!==-1)&&this.HoverCell({row:-1,column:-1});let i=-1;e.offsetY-r.top<=this.RESIZE_PIXEL_BUFFER&&t.row>0?i=t.row-1:r.bottom-e.offsetY<=this.RESIZE_PIXEL_BUFFER&&(i=t.row),i>=0?this.layout.ResizeCursor("row"):this.cell_resize.row&&(this.cell_resize.row=-1,this.layout.ResizeCursor()),this.cell_resize.row=i}MouseMove_ColumnHeader(e){let t=this.layout.CoordinateToColumnHeader(e.offsetX),r=this.layout.OffsetCellAddressToRectangle({row:0,column:t.column});this.hover_data.address&&(this.hover_data.address.row!==-1||this.hover_data.address.column!==-1)&&this.HoverCell({row:-1,column:-1});let i=-1;e.offsetX-r.left<=this.RESIZE_PIXEL_BUFFER&&t.column>0?i=t.column-1:r.right-e.offsetX<=this.RESIZE_PIXEL_BUFFER&&(i=t.column),i>=0?this.layout.ResizeCursor("column"):this.cell_resize.column&&(this.cell_resize.column=-1,this.layout.ResizeCursor()),this.cell_resize.column=i}MouseDown_RowHeader(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.layout.CoordinateToRowHeader(e.offsetY),r=this.layout.row_header_cover.getBoundingClientRect(),i={x:r.left,y:r.top};if(this.cell_resize.row>=0){let n=this.cell_resize.row,a=i.y+e.offsetY;if(this.layout.HideDropdownCaret(),this.IsDoubleClick({row:n,column:-1})){let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.rows>1&&this.primary_selection.area.start.column===1/0&&this.primary_selection.area.ContainsRow(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.row;p<=f.end.row;p++)m.push(p)}this.ExecCommand({key:3,row:m});return}let s=this.layout.RowHeight(n),o=s,l=this.layout.OffsetCellAddressToRectangle({row:n,column:0}),d=i.y+l.bottom;this.layout.ShowTooltip({left:!0,text:`${o}px`,x:Math.round(r.right+10),y:d});let h=[],u=[];for(let m of this.active_sheet.annotations){let f=l.bottom-1;if(!m.scaled_rect||m.scaled_rect.bottom<f)continue;let p=[...this.layout.GetFrozenAnnotations(m)],g=m.view[this.view_index]?.node;g&&p.push(g),f<=m.scaled_rect.top&&m.data.move_with_cells?h.push({annotation:m,y:m.scaled_rect.top,nodes:p}):f>m.scaled_rect.top&&m.data.resize_with_cells&&u.push({annotation:m,height:m.scaled_rect.height,nodes:p})}ge(this.layout.mask,"row-resize",m=>{let f=Math.max(-s,Math.round(m.offsetY-a));if(f+s!==o){o=f+s,this.layout.SetRowHeight(n,o),this.layout.UpdateTooltip({text:`${o}px`,y:d+f});for(let{annotation:p,y:g}of h)p.scaled_rect&&(p.scaled_rect.top=g+f);for(let{annotation:p,height:g}of u)p.scaled_rect&&(p.scaled_rect.height=g+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:g}of u)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);for(let{annotation:p,nodes:g}of h)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);this.layout.UpdateTileHeights(!0,n),this.Repaint(!1,!0),this.layout.UpdateAnnotation(this.active_sheet.annotations)})}},()=>{this.layout.HideTooltip(),requestAnimationFrame(()=>{let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.rows>1&&this.primary_selection.area.start.column===1/0&&this.primary_selection.area.ContainsRow(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.row;p<=f.end.row;p++)m.push(p)}this.layout.SetRowHeight(n,s),this.ExecCommand({key:3,row:m,height:o/this.scale});for(let{annotation:f}of h)f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));for(let{annotation:f}of u){f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));let p=f.view[this.view_index];p&&p.resize_callback&&p.resize_callback.call(void 0)}})})}else{let n=this.SelectingArgument()?this.active_selection:this.primary_selection;if(this.SelectingArgument()||this.Focus(),e.shiftKey&&!n.empty){let a=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=a}else this.Select(n,new y(t),{column:0,row:t.row});this.RenderSelections(),ge(this.layout.mask,[],a=>{let s=this.layout.CoordinateToRowHeader(a.offsetY-i.y),o=new y(s,t,!0);(n.empty||!o.Equals(n.area))&&(this.Select(n,o,void 0,!0),this.RenderSelections())},()=>{})}}MouseDown_ColumnHeader(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.layout.CoordinateToColumnHeader(e.offsetX),r=this.layout.column_header_cover.getBoundingClientRect(),i={x:r.left,y:r.top};if(this.cell_resize.column>=0){let n=this.cell_resize.column,a=i.x+e.offsetX;if(this.layout.HideDropdownCaret(),this.IsDoubleClick({row:-1,column:n})){let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.columns>1&&this.primary_selection.area.start.row===1/0&&this.primary_selection.area.ContainsColumn(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.column;p<=f.end.column;p++)m.push(p)}this.ExecCommand({key:4,column:m});return}let s=this.layout.ColumnWidth(n),o=s,l=this.layout.OffsetCellAddressToRectangle({row:0,column:n}),d=i.x+l.right;this.layout.ShowTooltip({up:!0,text:`${o}px`,x:d,y:Math.round(r.bottom+10)});let h=[],u=[];for(let m of this.active_sheet.annotations){let f=l.right-1;if(!m.scaled_rect||m.scaled_rect.right<f)continue;let p=[...this.layout.GetFrozenAnnotations(m)],g=m.view[this.view_index]?.node;g&&p.push(g),f<=m.scaled_rect.left&&m.data.move_with_cells?h.push({annotation:m,x:m.scaled_rect.left,nodes:p}):f>m.scaled_rect.left&&m.data.resize_with_cells&&u.push({annotation:m,width:m.scaled_rect.width,nodes:p})}ge(this.layout.mask,"column-resize",m=>{let f=Math.max(-s,Math.round(m.offsetX-a));if(f+s!==o){o=f+s,this.layout.UpdateTooltip({text:`${o}px`,x:d+f}),this.layout.SetColumnWidth(n,o);for(let{annotation:p,x:g}of h)p.scaled_rect&&(p.scaled_rect.left=g+f);for(let{annotation:p,width:g}of u)p.scaled_rect&&(p.scaled_rect.width=g+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:g}of u)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);for(let{annotation:p,nodes:g}of h)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);this.layout.UpdateTileWidths(!0,n),this.Repaint(!1,!0)})}},()=>{this.layout.HideTooltip(),requestAnimationFrame(()=>{let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.columns>1&&this.primary_selection.area.start.row===1/0&&this.primary_selection.area.ContainsColumn(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);for(let p=f.start.column;p<=f.end.column;p++)m.push(p)}this.ExecCommand({key:4,column:m,width:o/this.scale});for(let{annotation:f}of h)f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));for(let{annotation:f}of u){f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));let p=f.view[this.view_index];p&&p.resize_callback&&p.resize_callback.call(void 0)}})})}else{let n=this.SelectingArgument()?this.active_selection:this.primary_selection;if(this.SelectingArgument()||this.Focus(),e.shiftKey&&!n.empty){let a=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=a}else this.Select(n,new y(t),{row:0,column:t.column});this.RenderSelections(),ge(this.layout.mask,[],a=>{let s=this.layout.CoordinateToColumnHeader(a.offsetX-i.x),o=new y(s,t,!0);(n.empty||!o.Equals(n.area))&&(this.Select(n,o,void 0,!0),this.RenderSelections())})}}HoverCell(e,t){let r=this.active_sheet.cells.GetCell(e,!1);if(r?.table&&r.table.area.start.row===e.row&&r.table.sortable!==!1?(this.hover_data.table_header=!0,this.layout.ShowTableSortButton(r.table,e.column-r.table.area.start.column,e)):(this.hover_data.table_header&&this.layout.HideTableSortButton(),this.hover_data.table_header=!1),r?.merge_area){let i=r.merge_area;e=i.start,r=this.active_sheet.cells.GetCell(e,!1),e={row:i.start.row,column:i.end.column}}if(r?.note){let i=this.options.markdown?Te.instance.HTML(Te.instance.Parse(r.note)):void 0;this.layout.ShowNote(r.note,e,t,i),this.hover_data.note=!0}else this.hover_data.note&&(this.layout.HideNote(),this.hover_data.note=!1);r?.hyperlink?(this.layout.ShowTitle("Link: "+r.hyperlink,e),this.hover_data.link=!0,this.hover_data.cell=r):this.hover_data.link&&(this.layout.HideTitle(),this.hover_data.cell=void 0),this.hover_data.address={...e}}HideHoverInfo(){this.layout.HideTitle(),this.layout.HideTooltip(),this.hover_data.note=this.hover_data.link=!1,this.hover_data.cell=void 0,this.hover_data.pointer&&this.layout.grid_cover.classList.remove("link-pointer"),this.hover_data.pointer=!1}MouseMove_Grid(e){if(e.stopPropagation(),e.preventDefault(),!this.selection_renderer)return;(this.cell_resize.row>=0||this.cell_resize.column>=0)&&this.layout.ResizeCursor();let t={x:e.offsetX,y:e.offsetY},r;if(this.overlay_editor?.editing||(r=this.layout.PointToAddress_Grid(t),(!this.hover_data.address||this.hover_data.address.row!==r.row||this.hover_data.address.column!==r.column)&&this.HoverCell(r,e)),this.hover_data.link&&r&&(this.hover_data.point=t,this.hover_data.handler||(this.hover_data.handler=requestAnimationFrame(()=>{let n=this.hover_data.address&&this.hover_data.point&&this.hover_data.cell&&this.PointInTextPart(this.hover_data.address,this.hover_data.point,this.hover_data.cell);n!==!!this.hover_data.pointer&&(this.hover_data.pointer=n,n?this.layout.grid_cover.classList.add("link-pointer"):this.layout.grid_cover.classList.remove("link-pointer")),this.hover_data.handler=void 0}))),this.primary_selection.empty||!this.selection_renderer.nub_rectangle){this.nub_select_flag&&(this.layout.grid_cover.classList.remove("nub-select"),this.nub_select_flag=!1);return}let i=this.selection_renderer.nub_rectangle.Contains(e.offsetX,e.offsetY);i!==this.nub_select_flag&&(i?this.layout.grid_cover.classList.add("nub-select"):this.layout.grid_cover.classList.remove("nub-select"),this.nub_select_flag=i)}ClearDoubleClick(){this.double_click_data.address=void 0}IsDoubleClick(e,t=300){if(this.double_click_data.address&&this.double_click_data.address.row===e.row&&this.double_click_data.address.column===e.column)return clearTimeout(this.double_click_data.timeout),this.double_click_data.address=void 0,this.double_click_data.timeout=void 0,!0;this.double_click_data.timeout&&clearTimeout(this.double_click_data.timeout),this.double_click_data.address={...e},this.double_click_data.timeout=window.setTimeout(()=>{this.double_click_data.address=void 0,this.double_click_data.timeout=void 0},t)}PointInTextPart(e,t,r){let i=this.layout.CellAddressToRectangle(e);r.merge_area&&(i=i.Combine(this.layout.CellAddressToRectangle(r.merge_area.end)));let n=t.x-i.left,a=t.y-i.top,s=r.renderer_data?.text_data?.strings||[];for(let o of s)for(let l of o)if(typeof l.left=="number"&&typeof l.top=="number"&&typeof l.width=="number"&&typeof l.height=="number"&&n>=l.left&&a>=l.top&&n<=l.left+l.width&&a<=l.top+l.height)return!0;return!1}MouseDown_Grid(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.SelectingArgument();!t&&this.additional_selections.length&&this.ClearAdditionalSelections(),(!t||!this.formula_bar?.selecting&&!this.external_editor?.selecting)&&this.Focus(),this.overlay_editor?.editing&&!this.overlay_editor?.selecting&&this.DismissEditor();let r={x:e.offsetX,y:e.offsetY},i=this.layout.PointToAddress_Grid(r),n=t?this.active_selection:this.primary_selection;if(!t&&this.IsDoubleClick(i)){re.is_mobile&&this.overlay_editor?.edit_node?.focus(),this.OverlayEditCell({target:i,area:new y(i)},!1);return}let a=this.layout.grid_cover.getBoundingClientRect(),s={x:a.left,y:a.top},o=[],l;if(e.shiftKey&&!n.empty){let h=n.target;this.Select(n,new y(i,n.target,!0),void 0,!0),i=h}else if(this.nub_select_flag)i=n.area.TopLeft(),o.push("nub-select"),l=this.active_sheet.RealArea(n.area);else{let h=i,u=this.active_sheet.CellData(h);if(u.merge_area&&(h=u.merge_area.start,u=this.active_sheet.CellData(u.merge_area.start)),u.hyperlink&&this.PointInTextPart(h,r,u)){let m=u.hyperlink;Promise.resolve().then(()=>{this.grid_events.Publish({type:"cell-event",data:{type:"hyperlink",data:m}})}),this.ClearDoubleClick();return}if(u.click_function){let m=this.layout.CellAddressToRectangle(h);u.merge_area&&(m=m.Combine(this.layout.CellAddressToRectangle(u.merge_area.end)));let f=u.click_function.call(this,{cell:u,x:r.x-m.left,y:r.y-m.top,width:m.width,height:m.height,scale:this.layout.scale});if(f.value&&this.ExecCommand({key:6,value:f.value,area:h}),f.block_selection){this.ClearDoubleClick(),!this.primary_selection.empty&&this.primary_selection.target.row===h.row&&this.primary_selection.target.column===h.column&&this.UpdateFormulaBarFormula();return}}this.Select(n,new y(i),i)}this.RenderSelections(),t&&this.UpdateSelectedArgument(n);let d=this.layout.CellAddressToRectangle({row:0,column:0}).Combine(this.layout.CellAddressToRectangle({row:this.active_sheet.rows-1,column:this.active_sheet.columns-1})).Expand(-1,-1);ge(this.layout.mask,o,h=>{let u={x:h.offsetX-s.x,y:h.offsetY-s.y},m=d.Clamp(u.x,u.y),f=this.layout.PointToAddress_Grid(m,!0),p=this.layout.scroll_reference_node,g=!1;this.container&&this.options.scrollbars&&(u.x<p.scrollLeft?(p.scrollLeft-=25,g=!0):u.x>p.scrollLeft+this.container.clientWidth&&(p.scrollLeft+=25,g=!0),u.y<p.scrollTop?(p.scrollTop-=25,g=!0):u.y>p.scrollTop+this.container.clientHeight&&(p.scrollTop+=25,g=!0),g&&(a=this.layout.grid_cover.getBoundingClientRect(),s.x=a.left+document.body.scrollLeft,s.y=a.top+document.body.scrollTop));let b=new y(f,i,!0);if(l&&(b=l.Clone(),b.ConsumeAddress(f),b.rows!==l.rows&&b.columns!==l.columns)){let v={rows:f.row>l.end.row?f.row-l.end.row:l.start.row-f.row,columns:f.column>l.end.column?f.column-l.end.column:l.start.column-f.column};v.rows>=v.columns?b=new y({row:b.start.row,column:l.start.column},{row:b.end.row,column:l.end.column}):b=new y({row:l.start.row,column:b.start.column},{row:l.end.row,column:b.end.column})}(n.empty||!b.Equals(n.area))&&(this.Select(n,b,void 0,!0),this.RenderSelections(),t?this.UpdateSelectedArgument(n):!n.empty&&!n.area.entire_sheet&&(n.area.entire_column?this.UpdateAddressLabel(void 0,n.area.columns+"C"):n.area.entire_row?this.UpdateAddressLabel(void 0,n.area.rows+"R"):n.area.count>1?this.UpdateAddressLabel(void 0,n.area.rows+"R x "+n.area.columns+"C"):this.UpdateAddressLabel(n)))},()=>{this.UpdateAddressLabel(),t?this.overlay_editor?.editing||(this.external_editor_config?(this.external_editor?.active&&this.external_editor.FocusEditor(),this.external_editor_config.update):this.formula_bar&&this.formula_bar.FocusEditor()):l&&this.RecycleNubArea(n.area,l)})}Transpose(e){let t=[],r=e.length,i=e[0].length;for(let n=0;n<i;n++){t[n]=[];for(let a=0;a<r;a++)t[n][a]=e[a][n]}return t}RecycleNubArea(e,t){if(e.Equals(t))return;let r=[];for(let h=0;h<t.rows;h++){r[h]=[];for(let u=0;u<t.columns;u++){let m={row:t.start.row+h,column:t.start.column+u};r[h][u]=this.active_sheet.CellData(m)}}if(r[0][0].area&&r[0][0].area.Equals(t)){this.ExecCommand({key:6,value:r[0][0].value,array:!0,area:e});return}if(r[0][0].table&&t.Equals(new y(r[0][0].table.area.start,r[0][0].table.area.end))){let h=r[0][0].table,u=h.sortable,m=h.totals_row,f=h.theme;this.ExecCommand([{key:29,table:h},{key:28,area:e,sortable:u,totals:m,theme:f}]);return}let i=[],n=[],a=t.columns,s=e.rows,o=!1,l=!1;e.columns===t.columns?o=e.start.row<t.start.row:(a=t.rows,s=e.columns,o=e.start.column<t.start.column,r=this.Transpose(r),l=!0);for(let h=0;h<s;h++)i[h]=[],n[h]=[];for(let h=0;h<a;h++){let u=0;if(r.length>1){u=1;let m=[],f=[];for(let p=0;p<r.length;p++){let g=r[p][h];g.ValueIsNumber()&&(f.push(p),m.push(g.value))}if(m.length>1){let p=m.slice(1).map((g,b)=>g-m[b]);p.every(g=>g===p[0])&&(u=p[0])}m.length&&(u+=m[m.length-1]-m[0])}for(let m=0;m<r.length;m++){let f,p=r[m][h];if(p.ValueIsFormula()){let x=this.parser.Parse(p.value);x.expression&&x.full_reference_list?.length&&(f=x.expression)}let g=0,b=m,v=r.length,_=0,w=u;o&&(b=s-r.length+m,v=-r.length,w=-u);for(let x=b;x>=0&&x<s;x+=v,g+=v,_+=w){if(f)i[x][h]="="+this.parser.Render(f,{offset:{rows:g,columns:0}});else{let A=r[m][h];A.ValueIsNumber()?i[x][h]=A.value+_:i[x][h]=A.value}n[x][h]=r[m][h].style||{}}}}let d=[{key:6,value:l?this.Transpose(i):i,array:!1,area:e}];l&&(n=this.Transpose(n));for(let h=0;h<n.length;h++)for(let u=0;u<n[h].length;u++)d.push({key:7,area:{row:h+e.start.row,column:u+e.start.column},style:n[h][u],delta:!1});this.ExecCommand(d)}UpdateSelectedArgument(e){let t=this.active_sheet.CellData(e.area.start),r=new y(t.merge_area?t.merge_area.start:e.target),i=this.model.named_ranges.MatchSelection(e.area,r);if(!i&&(i=e.area.spreadsheet_label,t.merge_area&&t.merge_area.Equals(e.area)&&(i=y.CellAddressToLabel(t.merge_area.start)),this.external_editor_config||this.active_sheet.id!==this.editing_cell.sheet_id)){let n=this.active_sheet.name;ze.test(n)?i=`'${n}'!${i}`:i=`${n}!${i}`}if(this.overlay_editor?.editing&&this.overlay_editor.selecting)this.overlay_editor.InsertReference(i,0);else if(this.formula_bar&&this.formula_bar.selecting)this.formula_bar.InsertReference(i,0);else if(this.external_editor_config&&(this.external_editor?.active&&(this.external_editor.FocusEditor(),this.external_editor.InsertReference(i,0)),this.external_editor_config.update)){let n=this.external_editor_config.update.call(0,i);n&&Array.isArray(n)&&this.HighlightDependencies(n.filter(a=>!!a).map(a=>N(a)?new y(a):new y(a.start,a.end)))}}SelectingArgument(){return this.overlay_editor?.editing&&this.overlay_editor?.selecting||this.formula_bar&&this.formula_bar.selecting||!!this.external_editor_config}OverlayKeyDown(e){let t=!1;if(this.overlay_editor&&this.overlay_editor.editing)switch(t=!0,this.overlay_editor.HandleKeyDown(e)){case"handled":return;case"discard":this.editing_state=0,this.DismissEditor(),this.DelayedRender();return;case"commit":if(this.active_sheet.id!==this.editing_cell.sheet_id&&this.editing_cell.sheet_id&&this.ActivateSheetID(this.editing_cell.sheet_id),this.editing_state=0,this.overlay_editor?.selection){let l=this.overlay_editor?.edit_node.textContent||void 0,d=e.key==="Enter"&&e.ctrlKey&&e.shiftKey;this.SetInferredType(this.overlay_editor.selection,l,d)}this.DismissEditor(),this.options.repaint_on_cell_change&&this.DelayedRender(!1,this.overlay_editor?.selection.area||void 0);break}let r=this.SelectingArgument();if(this.formula_bar&&this.formula_bar.focused&&!r||this.selected_annotation&&!r)return;let i=r?this.active_selection:this.primary_selection,n={rows:0,columns:0},a=!1,s=!1;if(e.ctrlKey||re.is_mac&&e.metaKey){switch(e.key){case"ArrowDown":case"Down":n.rows++;break;case"ArrowUp":case"Up":n.rows--;break;case"ArrowLeft":case"Left":n.columns--;break;case"ArrowRight":case"Right":n.columns++;break;case"Delete":case"Del":{e.stopPropagation(),e.preventDefault();for(let o=0;o<this.model.sheets.length;o++)if(this.model.sheets.list[o]===this.active_sheet){this.DeleteSheet(o);break}return}break;case"/":e.stopPropagation(),e.preventDefault(),this.SelectArrayOrTable();break;default:if(e.shiftKey)return}if(n.columns||n.rows)if(e.stopPropagation(),e.preventDefault(),!i.empty&&(n.columns||n.rows)){if(this.BlockSelection(i,!!e.shiftKey,n.columns,n.rows))return}else return;else{let o={},l=this.primary_selection.empty?{}:this.active_sheet.CellData(this.primary_selection.target).style||{};switch(e.key.toLowerCase()){case"b":o.bold=!l.bold;break;case"i":o.italic=!l.italic;break;case"u":o.underline=!l.underline;break;case"a":this.SelectAll();break;case"0":if(!e.altKey)return;this.ClearSelection(this.primary_selection),this.RenderSelections();break;default:e.key;return}Object.keys(o).length&&this.ApplyStyle(void 0,o)}}else switch(e.key){case"Tab":e.shiftKey?n.columns--:n.columns++,a=!0;break;case"Enter":e.shiftKey?n.rows--:n.rows++,a=!0;break;case"ArrowDown":case"Down":n.rows++,s=e.shiftKey;break;case"ArrowUp":case"Up":n.rows--,s=e.shiftKey;break;case"ArrowLeft":case"Left":n.columns--,s=e.shiftKey;break;case"ArrowRight":case"Right":n.columns++,s=e.shiftKey;break;case"Delete":case"Del":i.empty||this.DeleteSelection(i);break;case"PageUp":case"PageDown":if(e.shiftKey){this.NextSheet(e.key==="PageUp"?-1:1);break}return;case"Control":case"Shift":case"Alt":return;default:i.empty||e.key!=="Escape"&&this.OverlayEditCell(i,!0,e);return}e.stopPropagation(),e.preventDefault(),(n.rows||n.columns)&&this.AdvanceSelection(n,i,a,s,!t)}SelectArrayOrTable(){if(this.primary_selection.empty)return;let e=this.active_sheet.CellData(this.primary_selection.target);if(!(!e||!e.area&&!e.table)){if(e.area&&this.Select(this.primary_selection,e.area,e.area.start),e.table){let t=new y(e.table.area.start,e.table.area.end);this.Select(this.primary_selection,t,t.start)}this.RenderSelections()}}RenderSelections(e=!0){let t=this.hide_selection?!1:!this.editing_state||this.editing_cell.sheet_id===this.active_sheet.id;this.selection_renderer?.RenderSelections(t,e)}BlockSelection(e,t,r,i,n=!0){if(e.empty)return!1;let a={...e.target};i>0?a.row=Math.max(a.row,e.area.end.row):i<0&&(a.row=Math.min(a.row,e.area.start.row)),r>0?a.column=Math.max(a.column,e.area.end.column):r<0&&(a.column=Math.min(a.column,e.area.start.column));let s=this.active_sheet.cells,o=s.GetCell(e.target,!1);if(!o||o.type===0&&!o.area)return!1;let l={...a};for(;;){let d={row:l.row+i,column:l.column+r};if(d.column<0||d.row<0||d.column>=this.active_sheet.columns||d.row>=this.active_sheet.rows)break;let h=!1;if(i)for(let u=e.area.start.column;!h&&u<=e.area.end.column;u++)o=s.GetCell({row:d.row,column:u},!1),h=h||!!o&&(o.type!==0||!!o.area),!h&&o&&o.merge_area&&(o=s.GetCell(o.merge_area.start,!1),h=h||!!o&&(o.type!==0||!!o.area));else for(let u=e.area.start.row;!h&&u<=e.area.end.row;u++)o=s.GetCell({row:u,column:d.column},!1),h=h||!!o&&(o.type!==0||!!o.area),!h&&o&&o.merge_area&&(o=s.GetCell(o.merge_area.start,!1),h=h||!!o&&(o.type!==0||!!o.area));if(!h)break;l=d}if(t){i?(a.row=e.target.row,a.column=e.area.start.column,l.column=e.area.end.column):(a.column=e.target.column,a.row=e.area.start.row,l.row=e.area.end.row);let d=new y(a,l,!0);this.Select(e,d,e.target,!0)}else this.Select(e,new y(l));return this.ScrollIntoView(l),this.SelectingArgument()&&this.UpdateSelectedArgument(e),n&&this.DelayedRender(),!0}DeleteSelection(e){if(e.empty)return;let t=this.active_sheet.RealArea(e.area);this.ExecCommand({key:11,area:t})}SetInferredType(e,t,r=!1,i=!0){let n=e.target||e.area.start,a=this.active_sheet.CellData(n);if(a.area){if(!r&&a.area.count>1||!e.area||!e.area.Equals(a.area)){this.Error(2);return}}else if(r){let h=!1;if(this.active_sheet.cells.Apply(e.area,u=>{u.area&&(h=!0)},!1),h){this.Error(2);return}}if(a.validation&&a.validation.error){let h;if(a.validation.type==="list"?h=a.validation.list:a.validation.type==="range"&&(h=this.GetValidationRange(a.validation.area)),h&&h.length){let u=!1;if(t){let m=t.toUpperCase();for(let f of h)if(f&&f.toString().toUpperCase()===m){t=f.toString(),u=!0;break}}if(!u){this.Error(3);return}}}a.merge_area&&(n=a.merge_area.start);let s=typeof t=="string"&&t.trim()[0]==="=",o=[];if(s&&(t=this.FixFormula(t||""),!this.active_sheet.HasCellStyle(n))){let h=this.parser.Parse(t);if(h){if(h.expression?.type==="call"&&(!a.style||!a.style.number_format||I.Equals(a.style.number_format,"General"))){let u=h.expression.name.toLowerCase(),m;switch(u){case"today":m="Short Date";break;case"now":m="Timestamp";break}m&&o.push({key:7,area:r?e.area:n,style:{number_format:m},delta:!0})}if(h.dependencies){let u,m=h.dependencies;for(let f of Object.keys(m.addresses)){let p=m.addresses[f];if(this.active_sheet.HasCellStyle({...p})){let g=this.active_sheet.CellData({...p});if(g.style&&g.style.number_format&&(!u||/%/.test(u))&&(u=I.Translate(g.style.number_format),!/%/.test(u)))break}}if(u){let f={number_format:u};o.push({key:7,area:r?e.area:n,style:f,delta:!0})}}}}let l=this.parser.Parse(t||"").expression;l?.type==="group"&&l.elements.length===1&&l.elements[0].type==="complex"&&(l=l.elements[0]);let d=l&&l.type==="complex"?{type:7,value:{real:l.real,imaginary:l.imaginary}}:be.TryParse(t);if(!s&&d.type===3){let h="",u=d.hints||{};(!a.style||!a.style.number_format||I.Equals(a.style.number_format,"General"))&&(u.Date?h="Short Date":u.Exponential?h="Exponential":u.Percent?h="Percent":u.Currency?h="Currency":(u.Grouping||u.Parens)&&(h="Accounting")),h&&o.push({key:7,area:r?e.area:n,style:{number_format:h},delta:!0})}if(o.push({key:6,area:r?e.area:n,array:r,value:s?this.UntranslateFunction(t||""):d.value}),i)this.ExecCommand(o);else return o}FixFormula(e){if(e.trim()[0]!=="=")return e;e=e.replace(/^\s+/,"");let t=!1,r=!1,i=0,n=!1,a=e.length;for(let s=0;s<a;s++){let o=e[s];if(!n)switch(o){case'"':t?e[s+1]==='"'?s++:t=!1:r||(t=!0);break;case"'":r?r=!1:t||(r=!0);break;case"\\":n=!0;break;case"(":!t&&!r&&i++;break;case")":!t&&!r&&i--;break}}for(t?e+='"':r&&(e+="'");i>0;)e+=")",i--;return e=this.NormalizeFormula(e),e}NormalizeFormula(e){let t=this.parser.Parse(e);return t.error&&console.warn(t.error),t&&t.expression&&(this.parser.Walk(t.expression,r=>{switch(r.type){case"call":r.name=this.autocomplete_matcher.NormalizeIdentifier(r.name)||r.name;break;case"identifier":this.model.named_ranges.Get(r.name)&&(r.name=r.name.toUpperCase());break}return!0}),e="="+this.parser.Render(t.expression,{missing:""})),e}DismissEditor(){this.overlay_editor?.active_cell&&(this.overlay_editor.active_cell.editing=!1,this.overlay_editor.active_cell.render_clean=[],this.DelayedRender(void 0,this.overlay_editor.selection.area)),this.editing_state=0,this.Focus(),this.overlay_editor?.CloseEditor(),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection)}NormalizeCellValue(e){let t=e.value;if(e.ValueIsNumber()&&e.style&&e.style.number_format)if(I.Get(e.style.number_format).date_format){let i=De(e.value),n=i.getUTCHours()||i.getUTCMinutes()||i.getUTCSeconds()?"Timestamp":"Short Date";t=I.Get(n).Format(t)}else if(/(?:%|percent)/i.test(e.style.number_format)){let i=0,n=e.value.toString().match(/\.(.*?)$/);n&&n[1]&&(i=Math.max(0,n[1].length-2)),t=(e.value*100).toFixed(i)+"%",D.decimal_separator===","&&(t=t.replace(/\./,","))}else t&&D.decimal_separator===","&&(t=e.value.toString().replace(/\./,","));else{if(e.ValueIsBoolean())return e.value.toString().toUpperCase();e.ValueIsNumber()?t&&D.decimal_separator===","&&(t=e.value.toString().replace(/\./,",")):e.ValueIsComplex()?(e.value.imaginary?e.value.real?t=`${e.value.real.toString()}${e.value.imaginary<0?" - ":" + "}${e.value.imaginary===1||e.value.imaginary===-1?"":Math.abs(e.value.imaginary).toString()}i`:e.value.imaginary===1?t="i":e.value.imaginary===-1?t="-i":t=e.value.imaginary.toString()+"i":t=e.value.real.toString(),D.decimal_separator===","&&(t=t.replace(/\./,","))):e.ValueIsFormula()&&(t=this.TranslateFunction(e.value))}return t}IsNumeric(e){return e>=48&&e<=57||e===this.decimal_separator_code||e===45||e===43}OverlayEditCell(e,t=!0,r){if(!this.options.in_cell_editor)return;let i=e.target||e.area.start,n=this.active_sheet.CellData(i),a;if(this.HideHoverInfo(),n.merge_area?(a=this.layout.OffsetCellAddressToRectangle(n.merge_area.start).Combine(this.layout.OffsetCellAddressToRectangle(n.merge_area.end)),i=n.merge_area.start,n=this.active_sheet.CellData(i)):a=this.layout.OffsetCellAddressToRectangle(i),n.style?.locked){console.info("cell is locked for editing");return}a=a.Shift(this.layout.header_size.width,this.layout.header_size.height);let s=n.value;t?(n.type===3||n.rendered_type===3)&&n.style&&n.style.number_format&&/(?:%|percent)/i.test(n.style.number_format)&&(!r||this.IsNumeric(r.key.charCodeAt(0)))?s="%":s=void 0:s=this.NormalizeCellValue(n),this.overlay_editor?.Edit(e,a.Expand(-1,-1),n,s,r),n.editing=!0,n.render_clean=[],this.DelayedRender(!1,e.area)}BoundAddressArea(e,t){e.column>t.end.column?(e.row=this.StepVisibleRows(e.row,1),e.row>t.end.row&&(e.row=t.start.row),e.column=t.start.column):e.column<t.start.column?(e.row=this.StepVisibleRows(e.row,-1),e.row<t.start.row&&(e.row=t.end.row),e.column=t.end.column):e.row>t.end.row?(e.column=this.StepVisibleColumns(e.column,1),e.column>t.end.column&&(e.column=t.start.column),e.row=t.start.row):e.row<t.start.row&&(e.column=this.StepVisibleColumns(e.column,-1),e.column<t.start.column&&(e.column=t.end.column),e.row=t.end.row)}StepVisibleRows(e,t){if(t>0)for(let r=0;r<t;r++)this.layout.RowHeight(++e)||r--;else if(t<0)for(let r=0;r>t;r--)--e>=0&&!this.layout.RowHeight(e)&&r++;return e}StepVisibleColumns(e,t){if(t>0)for(let r=0;r<t;r++)this.layout.ColumnWidth(++e)||r--;else if(t<0)for(let r=0;r>t;r--)--e>=0&&!this.layout.ColumnWidth(e)&&r++;return e}EnsureAddress(e,t=8){let r=!1;if(this.options.expand){if(e.row!==1/0&&e.row>=this.active_sheet.rows){let i=this.active_sheet.rows;for(;e.row>=i;)i+=t;this.active_sheet.cells.EnsureRow(i),r=!0}if(e.column!==1/0&&e.column>=this.active_sheet.columns){let i=this.active_sheet.columns;for(;e.column>=i;)i+=t;this.active_sheet.cells.EnsureColumn(i),r=!0}r&&(this.layout.UpdateTiles(),this.layout.UpdateContentsSize(),this.Repaint(!0,!0))}return r}AdvanceSelection(e,t,r=!1,i=!1,n=!0){let a=this.SelectingArgument();if(t.empty)if(a){let s={row:Math.max(0,this.StepVisibleRows(this.primary_selection.target.row,e.rows)),column:Math.max(0,this.StepVisibleColumns(this.primary_selection.target.column,e.columns))};this.Select(t,new y(s))}else this.Select(t,new y({row:0,column:0}));else{let s=this.active_sheet.CellData(t.target);if(s.merge_area&&r&&(r=!s.merge_area.Equals(t.area)),r&&t.area.count>1){let o=this.active_sheet.RealArea(t.area),l=t.target;for(;;){l.row=this.StepVisibleRows(l.row,e.rows),l.column=this.StepVisibleColumns(l.column,e.columns),this.BoundAddressArea(l,o);let d=this.active_sheet.CellData(l);if(!d.merge_area||d.merge_area.start.row===l.row&&d.merge_area.start.column===l.column)break}this.Select(t,o,l)}else if(i&&t&&t.target){let o=t.area,l=t.target,d=o.start,h=o.end,u={row:1/0,column:1/0};if(e.columns&&(o.columns===1?e.columns>0?(h.column=this.StepVisibleColumns(h.column,1),u.column=h.column):(d.column=this.StepVisibleColumns(d.column,-1),u.column=d.column):o.end.column>l.column?(h.column=this.StepVisibleColumns(h.column,e.columns),u.column=h.column):o.start.column<l.column&&(d.column=this.StepVisibleColumns(d.column,e.columns),u.column=d.column),h.column=Math.max(0,h.column),d.column=Math.max(0,d.column)),e.rows&&(o.rows===1?e.rows>0?(h.row=this.StepVisibleRows(h.row,1),u.row=h.row):(d.row=this.StepVisibleRows(d.row,-1),u.row=d.row):o.end.row>l.row?(h.row=this.StepVisibleRows(h.row,e.rows),u.row=h.row):o.start.row<l.row&&(d.row=this.StepVisibleRows(d.row,e.rows),u.row=d.row),h.row=Math.max(0,h.row),d.row=Math.max(0,d.row)),this.options.expand){for(let m of[d,h,u])m.row!==1/0&&(m.row=Math.max(0,m.row)),m.column!==1/0&&(m.column=Math.max(0,m.column));this.EnsureAddress(h)&&(n=!0),this.ScrollIntoView(u),this.Select(t,new y(d,h),void 0,!0)}else{for(let m of[d,h,u])m.row!==1/0&&(m.row=Math.max(0,Math.min(m.row,this.active_sheet.rows-1))),m.column!==1/0&&(m.column=Math.max(0,Math.min(m.column,this.active_sheet.columns-1)));this.ScrollIntoView(u),this.Select(t,new y(d,h),void 0,!0)}}else{let o=t.target;s.merge_area?(e.columns<0?o.column=this.StepVisibleColumns(s.merge_area.start.column,-1):e.columns>0&&(o.column=this.StepVisibleColumns(s.merge_area.end.column,1)),e.rows<0?o.row=this.StepVisibleRows(s.merge_area.start.row,-1):e.rows>0&&(o.row=this.StepVisibleRows(s.merge_area.end.row,1))):(o.row=this.StepVisibleRows(o.row,e.rows),o.column=this.StepVisibleColumns(o.column,e.columns)),this.EnsureAddress(o)&&(n=!0),this.Select(t,new y({row:Math.min(Math.max(0,o.row),this.active_sheet.rows-1),column:Math.min(Math.max(0,o.column),this.active_sheet.columns-1)})),this.RenderSelections(),this.ScrollIntoView(t.target)}}this.SelectingArgument()&&this.UpdateSelectedArgument(t),n&&this.DelayedRender()}HighlightDependencies(e,t=!0){let r=0;e:for(let i of e)if((i.start.row===1/0||i.start.row<this.active_sheet.rows)&&(i.start.column===1/0||i.start.column<this.active_sheet.columns)){i=this.active_sheet.RealArea(i);let n=i.spreadsheet_label;if(this.additional_selections[r]&&this.additional_selections[r].area.spreadsheet_label===n)r++;else{for(let a=0;a<r;a++)if(this.additional_selections[a].area.spreadsheet_label===n&&this.additional_selections[a].area.start.sheet_id===i.start.sheet_id)continue e;this.additional_selections[r++]={target:i.start,area:i}}}this.additional_selections.splice(r),t&&this.RenderSelections(!1)}ClearAdditionalSelections(){this.additional_selections.splice(0,this.additional_selections.length)}ClearSelection(e){this.Select(e)}HideGridSelection(){this.UpdateAddressLabel(void 0,"");let e=this.selected_annotation&&this.selected_annotation.data.formula?this.selected_annotation.data.formula:"";this.UpdateFormulaBarFormula(e),this.layout.ShowSelections(!1)}ShowGridSelection(){this.UpdateAddressLabel(),this.UpdateFormulaBarFormula(),this.layout.ShowSelections(!0)}Select(e,t,r,i=!1){if(e.empty||i&&(r=e.target),t){let n=this.active_sheet.RealArea(t);r||(r=n.start);let a=!0;for(;a;)a=!1,this.active_sheet.cells.Apply(n,l=>{l.merge_area&&!n.ContainsArea(l.merge_area)&&(t.ConsumeArea(l.merge_area),n=this.active_sheet.RealArea(t),a=!0)});e.area=new y({...t.start,sheet_id:this.active_sheet.id},t.end),r&&(e.target={...r,sheet_id:this.active_sheet.id}),e.empty=!1;let s=this.active_sheet.CellData(e.target),o="";s.formatted&&(typeof s.formatted=="string"?o=s.formatted:o=s.formatted.map(l=>l.flag===1||l.flag===6?"":l.text).join("")),this.overlay_editor?.UpdateCaption(o)}else e.empty=!0;e===this.primary_selection&&(re.is_edge&&this.Focus(),this.grid_events.Publish({type:"selection",selection:this.primary_selection}),this.UpdateAddressLabel(),this.UpdateFormulaBarFormula(),this.formula_bar&&(this.formula_bar.target_address={...this.primary_selection.target}),this.options.stats&&this.UpdateStats())}UpdateFormulaBarFormula(e){if(this.formula_bar){if(e){this.formula_bar.formula=e;return}if(this.primary_selection.empty)this.formula_bar.formula="";else{let t=this.active_sheet.CellData(this.primary_selection.target),r=t.merge_area||t.area;r&&(r.start.column!==this.primary_selection.target.column||r.start.row!==this.primary_selection.target.row)&&(t=this.active_sheet.CellData(r.start)),this.formula_bar.editable=!t.style?.locked;let i=this.NormalizeCellValue(t);if(t.validation&&!t.style?.locked){let n;t.validation.type==="list"?n=t.validation.list:t.validation.type==="range"&&(n=this.GetValidationRange(t.validation.area)),n&&n.length&&this.layout.ShowDropdownCaret(t.merge_area||new y(this.primary_selection.target),n,t.value)}else this.layout.HideDropdownCaret();t.area?this.formula_bar.formula="{"+(i||"")+"}":this.formula_bar.formula=typeof i<"u"?i.toString():""}}}RenderStats(e){if(!Array.isArray(e))return[];let t=0,r=0,i={real:0,imaginary:0};for(let a of e)for(let s of a)typeof s=="number"?(i.real+=s,r++):fe(s)&&(i.real+=s.real,i.imaginary+=s.imaginary,r++),typeof s<"u"&&t++;let n=a=>{let s=Math.floor(Math.log10(a));return s<-6||s>10?I.Get("Exponential"):s<=-1?I.Get("General"):I.Get("Number")};if(t>1)if(r>0){let a=I.Get("General");if(i.imaginary){let s={real:i.real/r,imaginary:i.imaginary/r};return[{label:"Count",value:t.toString()},{label:"Sum",value:te.FormatPartsAsText(a.FormatComplex(i))},{label:"Average",value:te.FormatPartsAsText(a.FormatComplex(s))}]}else return[{label:"Count",value:t.toString()},{label:"Sum",value:n(i.real).Format(i.real)},{label:"Average",value:n(i.real/r).Format(i.real/r)}]}else return[{label:"Count",value:t.toString()}];return[]}UpdateStats(){if(this.tab_bar){let e=[];typeof this.options.stats=="function"?this.primary_selection.empty||(e=this.options.stats.call(void 0,this.GetRange(this.primary_selection.area))):!this.primary_selection.empty&&this.primary_selection.area.count>1&&(e=this.RenderStats(this.GetRange(this.primary_selection.area))),this.tab_bar.stats_data=e}}UpdateAddressLabel(e=this.primary_selection,t){if(this.formula_bar)if(typeof t<"u")this.formula_bar.label=t;else if(e.empty)this.formula_bar.label="";else{let r=this.active_sheet.CellData(this.primary_selection.target),i=new y(r.merge_area?r.merge_area.start:e.target);this.formula_bar.label=this.model.named_ranges.MatchSelection(e.area,i)||y.CellAddressToLabel(i.start)}}OnDropdownSelect(e){if(typeof e<"u"){let i=be.TryParse(e.toString());i.type===3&&(e=i.value)}let t=this.active_sheet.CellData(this.primary_selection.target),r=t.merge_area?t.merge_area.start:this.primary_selection.target;this.ExecCommand({key:6,area:r,value:e}),this.UpdateFormulaBarFormula()}OnScroll(){let e=this.layout.VisibleTiles();e.Equals(this.render_tiles)||(this.render_tiles=e,this.layout_token||(this.layout_token=requestAnimationFrame(()=>this.Repaint())))}AttachListeners(){if(!this.container)throw new Error("invalid container");this.container.addEventListener("copy",this.HandleCopy.bind(this)),this.container.addEventListener("cut",this.HandleCut.bind(this)),this.container.addEventListener("paste",this.HandlePaste.bind(this)),this.layout.grid_cover.addEventListener("mousedown",e=>this.MouseDown_Grid(e)),this.layout.column_header_cover.addEventListener("mousedown",e=>this.MouseDown_ColumnHeader(e)),this.layout.row_header_cover.addEventListener("mousedown",e=>this.MouseDown_RowHeader(e)),this.layout.column_header_cover.addEventListener("mousemove",e=>this.MouseMove_ColumnHeader(e)),this.layout.row_header_cover.addEventListener("mousemove",e=>this.MouseMove_RowHeader(e)),this.layout.grid_cover.addEventListener("mousemove",e=>this.MouseMove_Grid(e)),this.overlay_editor?.edit_node.addEventListener("keydown",e=>this.OverlayKeyDown(e)),this.layout.corner.addEventListener("dblclick",()=>{this.SelectAll()}),window.addEventListener("resize",()=>{this.layout.UpdateDPR()&&(this.QueueLayoutUpdate(),this.Repaint(!0,!0,!0))})}HandleCopy(e){if(e.stopPropagation(),e.preventDefault(),this.primary_selection.empty){if(e.clipboardData&&e.clipboardData.clearData(),this.selected_annotation&&e.clipboardData){let t=JSON.stringify({data:this.selected_annotation,source:this.active_sheet.id});e.clipboardData.setData("text/x-treb-annotation",t);let r=this.selected_annotation.view[this.view_index];if(r&&r.node){let i=r.node.firstChild;if(i){let n=Zr(i).outerHTML,a="text/plain";e.clipboardData.setData(a,n)}}}}else{let t=this.active_sheet.RealArea(this.primary_selection.area),r=t.columns,i=t.rows,n=[],a=[];for(let o=0;o<i;o++){let l=[];for(let d=0;d<r;d++){let h={row:t.start.row+o,column:t.start.column+d},u=this.active_sheet.CellData(h),m="";u.calculated?u.calculated_type===7?m=Le(u.calculated):m=u.calculated.toString():u.type===7?m=Le(u.value):m=u.value?.toString()||"",l.push(m);let f={address:h,data:u.value,type:u.type,style:this.active_sheet.GetCopyStyle(h)};u.area&&u.area.start.row===h.row&&u.area.start.column===h.column&&(f.array={rows:u.area.rows,columns:u.area.columns}),a.push(JSON.parse(JSON.stringify(f)))}n.push(l)}let s=n.map(o=>o.join(" ")).join(`
|
|
8
|
+
`)+"<ul>";let i=this.completion_list.offsetHeight,n=!1;this.options.autocomplete_prefer_top?n=r.top>=200:this.DOM.doc?.documentElement&&Math.max(this.DOM.doc.documentElement.clientHeight,this.DOM.view?.innerHeight||0)-r.bottom<200&&(n=!0),n?this.completion_list.style.top=r.top-i-5+"px":this.completion_list.style.top=r.bottom+5+"px",this.completion_list.style.left=r.left+"px";let a=this.completion_list.querySelectorAll("a");this.active_element=a[this.selected_index],a[this.selected_index].classList.add("selected"),this.last_completion=a[this.selected_index].textContent||void 0,this.completion_list.scrollTop=this.active_element.offsetTop,this.completion_list_visible=!0}else this.completion_list.style.top="-1000px"}};var tt=(C=>(C[C.Null=0]="Null",C[C.InsertRows=1]="InsertRows",C[C.InsertColumns=2]="InsertColumns",C[C.ResizeRows=3]="ResizeRows",C[C.ResizeColumns=4]="ResizeColumns",C[C.Select=5]="Select",C[C.SetRange=6]="SetRange",C[C.UpdateStyle=7]="UpdateStyle",C[C.UpdateBorders=8]="UpdateBorders",C[C.MergeCells=9]="MergeCells",C[C.UnmergeCells=10]="UnmergeCells",C[C.Clear=11]="Clear",C[C.UpdateTheme=12]="UpdateTheme",C[C.SetNote=13]="SetNote",C[C.SetLink=14]="SetLink",C[C.Freeze=15]="Freeze",C[C.SetName=16]="SetName",C[C.ShowHeaders=17]="ShowHeaders",C[C.AddSheet=18]="AddSheet",C[C.DuplicateSheet=19]="DuplicateSheet",C[C.DeleteSheet=20]="DeleteSheet",C[C.ActivateSheet=21]="ActivateSheet",C[C.RenameSheet=22]="RenameSheet",C[C.ReorderSheet=23]="ReorderSheet",C[C.ShowSheet=24]="ShowSheet",C[C.DataValidation=25]="DataValidation",C[C.Reset=26]="Reset",C[C.SortTable=27]="SortTable",C[C.InsertTable=28]="InsertTable",C[C.RemoveTable=29]="RemoveTable",C))(tt||{});var hi={scrollbars:!0,in_cell_editor:!0,formula_bar:!0,add_tab:!1,tab_bar:"auto",insert_function_button:!1,expand_formula_button:!1,expand:!0,repaint_on_cell_change:!0,grid_over_background:!1};var rt=class{grid_events=new oe;command_log=new oe;model;view;get active_sheet(){return this.view.active_sheet}set active_sheet(e){this.view.active_sheet=e}get view_index(){return this.view.view_index}batch=!1;batch_events=[];autocomplete_matcher=new Et;flags={};options;parser;constructor(e={},t){this.model=t,this.view={active_sheet:this.model.sheets.list[0],view_index:this.model.view_count++},this.parser=t.parser,this.options={...hi,...e}}RemoveTable(e){this.ExecCommand({key:29,table:e})}InsertTable(e,t=!0,r=void 0,i){e.start.sheet_id||(e.start.sheet_id=this.active_sheet.id);let n=this.FindSheet(e);for(let a=e.start.row;a<=e.end.row;a++)for(let s=e.start.column;s<=e.end.column;s++){let o=n.cells.GetCell({row:a,column:s},!1);if(o&&(o.area||o.merge_area||o.table)){this.Error(4);return}}this.ExecCommand({key:28,area:JSON.parse(JSON.stringify(e)),totals:t,sortable:r,theme:i})}ActivateSheet(e){let t=typeof e=="number"?e:void 0,r=typeof e=="string"?e:void 0;this.ExecCommand({key:21,index:t,name:r})}ActivateSheetID(e){this.ExecCommand({key:21,id:e})}DuplicateSheet(e,t,r){let i={key:19,new_name:t,insert_before:r};typeof e>"u"?i.id=this.active_sheet.id:i.index=e,this.ExecCommand(i)}AddSheet(e){this.ExecCommand({key:18,name:e,show:!0})}DeleteSheet(e){if(typeof e>"u"&&!this.model.sheets.list.some((t,r)=>t===this.active_sheet?(e=r,!0):!1))throw new Error("invalid index");this.ExecCommand({key:20,index:e})}InsertSheet(e,t){if(typeof e>"u"&&!this.model.sheets.list.some((r,i)=>r===this.active_sheet?(e=i+1,!0):!1))throw new Error("invalid index");this.ExecCommand({key:18,insert_index:e,name:t,show:!0})}DeleteSheetID(e){this.ExecCommand({key:20,id:e})}Reset(){this.ExecCommand({key:26})}SetLink(e,t){this.ExecCommand({key:14,area:e,reference:t})}ShowAll(){let e=[];for(let t=0;t<this.model.sheets.length;t++)e.push({key:24,index:t,show:!0});this.ExecCommand(e)}ShowSheet(e=0,t=!0){let r={key:24,show:t};typeof e=="string"?r.name=e:r.index=e,this.ExecCommand(r)}SortTable(e,t={}){this.ExecCommand({key:27,table:JSON.parse(JSON.stringify(e)),...Or,...t})}GetFreeze(){return{...this.active_sheet.freeze}}InsertRows(e=0,t=1){this.ExecCommand({key:1,before_row:e,count:t})}GetTableReference(e){return this.model.sheets.Find(e.sheet_id||this.active_sheet.id)?.CellData(e).table||void 0}FromCSV(e){let t=this.parser.decimal_mark===",";t&&(this.parser.argument_separator=",",this.parser.decimal_mark=".");let i=Qr(e).map(a=>a.map(s=>{if(s){let o=this.parser.Parse(s);if(o.expression?.type==="complex")return o.expression}return be.TryParse(s).value}));t&&(this.parser.argument_separator=";",this.parser.decimal_mark=",");let n={row:Math.max(0,i.length-1),column:i.reduce((a,s)=>Math.max(a,Math.max(0,s.length-1)),0)};this.ExecCommand([{key:26},{key:6,area:{start:{row:0,column:0},end:n},value:i}])}InsertColumns(e=0,t=1){this.ExecCommand({key:2,before_column:e,count:t})}ReorderSheet(e,t){this.ExecCommand({key:23,index:e,move_before:t})}RenameSheet(e,t){this.ExecCommand({key:22,new_name:t,id:e.id})}Freeze(e=0,t=0,r=!0){this.ExecCommand({key:15,rows:e,columns:t,highlight_transition:r})}SetRowHeight(e,t,r=!0){this.ExecCommand({key:3,row:e,height:t,shrink:r})}SetColumnWidth(e,t=0){this.ExecCommand({key:4,column:e,width:t})}FilterTable(e,t,r){let i=[];if(!e.area.start.sheet_id)throw new Error("invalid table area");let n=this.model.sheets.Find(e.area.start.sheet_id);if(!n)throw new Error("invalid table sheet");let a=[],s=[],o=e.totals_row?e.area.end.row-1:e.area.end.row;t+=e.area.start.column;for(let l=e.area.start.row+1;l<=o;l++){let d=n.CellData({row:l,column:t}),h=r(d),u=n.GetRowHeight(l);h&&!u?a.push(l):!h&&u&&s.push(l)}a&&i.push({key:3,sheet_id:n.id,row:a,height:n.default_row_height}),s&&i.push({key:3,sheet_id:n.id,row:s,height:0}),i.length&&this.ExecCommand(i)}UpdateSheets(e,t=!1,r){Y.Reset();let i=e.map(n=>Y.FromJSON(n,this.model.theme_style_properties));if(i.length===0&&i.push(Y.Blank(this.model.theme_style_properties)),this.model.sheets.Assign(i),this.ResetMetadata(),this.active_sheet=i[0],r){let n=this.model.sheets.Find(r);n&&(this.active_sheet=n)}}SetAutocompleteFunctions(e){let t=[];for(let i of this.model.named_expressions.keys())t.push({name:i,type:0});let r=e.slice(0).concat(this.model.named_ranges.List().map(i=>({name:i.name,type:1})),t);this.autocomplete_matcher.SetFunctions(r)}ResetMetadata(){this.model.document_name=void 0,this.model.user_data=void 0}Serialize(e={}){let t=this.model.sheets.list.map(a=>a.toJSON(e)),r;this.model.tables.size>0&&(r=Array.from(this.model.tables.values()));let i;if(this.model.macro_functions.size){i=[];for(let a of this.model.macro_functions.values())i.push({...a,expression:void 0})}let n=[];if(this.model.named_expressions)for(let[a,s]of this.model.named_expressions){this.parser.Walk(s,l=>{if(l.type==="address"||l.type==="range"){let d=l.type==="range"?l.start:l;if(d.absolute_column=d.absolute_row=!0,!d.sheet){if(d.sheet_id){let h=this.model.sheets.Find(d.sheet_id);h&&(d.sheet=h.name)}d.sheet||(d.sheet=this.active_sheet.name)}return l.type==="range"&&(l.end.absolute_column=l.end.absolute_row=!0),!1}return!0});let o=this.parser.Render(s,{missing:""});n.push({name:a,expression:o})}return{sheet_data:t,active_sheet:this.active_sheet.id,named_ranges:this.model.named_ranges.Count()?this.model.named_ranges.Serialize():void 0,macro_functions:i,tables:r,named_expressions:n.length?n:void 0}}ResizeColumnsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.column;if(typeof r>"u"){r=[];for(let i=0;i<t.columns;i++)r.push(i)}if(typeof r=="number"&&(r=[r]),e.width)for(let i of r)t.SetColumnWidth(i,e.width);else console.error("auto size not supported")}ResizeRowsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.row;if(typeof r>"u"){r=[];for(let i=0;i<t.rows;i++)r.push(i)}if(typeof r=="number"&&(r=[r]),e.height)for(let i of r)t.SetRowHeight(i,e.height);else console.error("auto size not supported")}ResetInternal(){Y.Reset(),this.UpdateSheets([],!0),this.model.named_ranges.Reset(),this.model.named_expressions.clear(),this.model.macro_functions.clear(),this.model.tables.clear()}ValidatePasteAreas(e){for(let t of e){let r=this.active_sheet;if(t.start.sheet_id&&t.start.sheet_id!==r.id&&(r=this.model.sheets.Find(t.start.sheet_id)),!r)return!1;let i=!0;if(r.cells.Apply2(t,n=>(n.style?.locked&&(console.info("invalid: locked cells"),i=!1),n.merge_area&&(!t.Contains(n.merge_area.start)||!t.Contains(n.merge_area.end))&&(console.info("invalid: merge area"),i=!1),n.area&&(!t.Contains(n.area.start)||!t.Contains(n.area.end))&&(console.info("invalid: array"),i=!1),i)),!i)return!1}return!0}SetValidationInternal(e){let t,r=this.FindSheet(e.area);if(r&&(t=r.cells.GetCell(e.area,!0)),!t)throw new Error("invalid cell in set validation");e.range?t.validation={type:"range",area:e.range,error:!!e.error}:e.list?t.validation={type:"list",list:JSON.parse(JSON.stringify(e.list)),error:!!e.error}:t.validation=void 0}GetValidationRange(e){let t,r=this.FindSheet(e);if(r){t=[],e=r.RealArea(new y(e.start,e.end),!0);for(let i=e.start.row;i<=e.end.row;i++)for(let n=e.start.column;n<=e.end.column;n++){let a=r.CellData({row:i,column:n});a&&a.formatted&&(typeof a.formatted=="string"?t.push(a.formatted):t.push(te.FormatPartsAsText(a.formatted)))}}return t}DeleteSheetInternal(e){let t=!1,r=-1,i="",n=!1,a=e.name?e.name.toLowerCase():"",s=this.model.sheets.list.filter((o,l)=>l===e.index||o.id===e.id||o.name.toLowerCase()===a?(t=o===this.active_sheet,this.model.named_ranges.RemoveRangesForSheet(o.id),i=o.name,r=l,!1):!0);if(i&&this.RenameSheetReferences(s,i,"#REF")>0&&(n=!0),!s.length)s.push(Y.Blank(this.model.theme_style_properties)),r=0;else if(s.every(o=>!o.visible))s.unshift(Y.Blank(this.model.theme_style_properties)),r=0;else for(r>=s.length&&(r=0);!s[r].visible;)r++;return this.model.sheets.Assign(s),t&&this.ActivateSheetInternal({key:21,index:r}),n}RenameSheetInternal(e,t){if(!t||Xr.test(t))throw new Error("invalid sheet name");let r=t.toLowerCase();for(let n of this.model.sheets.list)if(n!==e&&n.name.toLowerCase()===r)throw new Error("sheet name already exists");let i=e.name;e.name=t,this.model.sheets.Assign(this.model.sheets.list),this.RenameSheetReferences(this.model.sheets.list,i,t)}SortTableInternal(e){if(!e.table.area.start.sheet_id)throw new Error("table has invalid area");let t=this.model.sheets.Find(e.table.area.start.sheet_id);if(!t)throw new Error("invalid sheet in table area");let r=[],i=[],n=e.table.area.end.row;e.table.totals_row&&n--;let a=0,s=0;for(let u=e.table.area.start.row+1;u<=n;u++){if(t.GetRowHeight(u))i.push(u);else continue;let f={row:u,number:0,text:"",type:0,data:[]};for(let p=e.table.area.start.column;p<=e.table.area.end.column;p++){let g=t.CellData({row:u,column:p});if(p===e.column+e.table.area.start.column){let b=g.calculated_type||g.type;b===2?a++:b===3&&s++;let v=g.calculated_type?g.calculated:g.value;f.text=v?.toString()||"",f.number=Number(v)||0,f.type=g.calculated_type||g.type}f.data.push({address:{row:u,column:p},data:g.value,type:g.type,style:g.style})}r.push(f)}let o=e.type;o==="auto"&&(s>a?o="numeric":o="text");let l=e.asc?1:-1;switch(o){case"numeric":r.sort((u,m)=>u.type===0?m.type===0?0:1:m.type===0?-1:(u.number-m.number)*l);break;case"text":default:r.sort((u,m)=>u.type===0?m.type===0?0:1:m.type===0?-1:u.text.localeCompare(m.text)*l);break}let d={row:e.table.area.start.row+1,column:e.table.area.start.column};for(let u=0;u<i.length;u++){d.row=i[u];let m=r[u];d.column=e.table.area.start.column;for(let f of m.data){if(f.type===1){let p=f.data,g={columns:0,rows:d.row-m.row},b=this.parser.Parse(p);b.expression&&(p="="+this.parser.Render(b.expression,{offset:g,missing:""})),t.SetCellValue(d,p)}else t.SetCellValue(d,f.data);t.UpdateCellStyle(d,f.style||{},!1),d.column++}}let h=this.model.tables.get(e.table.name.toLowerCase());h&&(h.sort={type:e.type,asc:!!e.asc,column:e.column});{let u=e.table.area.start.row;for(let m=e.table.area.start.column;m<=e.table.area.end.column;m++)t.cells.data[u][m]?.FlushStyle();if(e.table.totals_row){u=e.table.area.end.row;for(let m=e.table.area.start.column;m<=e.table.area.end.column;m++)t.cells.data[u][m]?.FlushStyle()}}return new y(e.table.area.start,e.table.area.end)}UpdateTableColumns(e){if(!e.area.start.sheet_id)throw new Error("invalid area in table");let t=this.model.sheets.Find(e.area.start.sheet_id);if(!t)throw new Error("invalid sheet in table");let r=e.columns?.slice(0)||void 0,i=[],n=e.area.start.row,a=e.area.end.column-e.area.start.column+1,s=e.area.start.column;for(let o=0;o<a;o++,s++){let l=t.CellData({row:n,column:s}),d="";l.type!==2?(typeof l.formatted<"u"?d=l.formatted.toString():typeof l.calculated<"u"?d=l.calculated.toString():typeof l.value<"u"&&(d=l.value.toString()),l.Set(d,2)):d=l.value||"",d||(d=`Column${o+1}`);let h=d,u=!1,m=1;for(;!u;){u=!0;e:for(let f of i)if(f.toLowerCase()===h.toLowerCase()){u=!1,h=`${d}${++m}`;break e}}l.Set(h,2),i.push(h.toLowerCase())}if(r&&r.length===i.length){let o=new Map;for(let l=0;l<r.length;l++){let d=r[l].toLowerCase();d!==i[l]&&o.set(d,i[l])}if(o.size){let l=e.name.toLowerCase();for(let d of this.model.sheets.list)d.cells.IterateAll(h=>{if(h.ValueIsFormula()){let u=!1,m=this.parser.Parse(h.value);m.expression&&(this.parser.Walk(m.expression,f=>{if(f.type==="structured-reference"&&(f.table.toLowerCase()===l||!f.table&&h.table===e))for(let[p,g]of o.entries())f.column.toLowerCase()===p&&(f.column=g,u=!0);return!0}),u&&(console.info("updating value"),h.value="="+this.parser.Render(m.expression,{missing:""})))}})}}return e.columns=i,{start:{...e.area.start},end:{row:e.area.start.row,column:e.area.end.column}}}SetRangeInternal(e,t={}){let r=N(e.area)?new y(e.area):new y(e.area.start,e.area.end),i=this.FindSheet(r);if(r.start.sheet_id||(r.start.sheet_id=i.id),!r.entire_row&&!r.entire_column&&(r.end.row>=i.rows||r.end.column>=i.columns)&&(i.cells.EnsureCell(r.end),i===this.active_sheet&&(t.layout=!0)),N(e.area)){let n=i.CellData(e.area);if(n.area&&(n.area.rows>1||n.area.columns>1)){this.Error(2);return}let a=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;return e.r1c1&&(a=this.TranslateR1C1(e.area,a)),e.array?i.SetArrayValue(r,a):i.SetCellValue(e.area,a),r}else{if(e.array){let n=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;e.r1c1&&(n=this.TranslateR1C1(r.start,n)),i.SetArrayValue(r,n)}else{if(e.r1c1){if(Array.isArray(e.value))for(let n=0;n<e.value.length&&n<r.rows;n++){e.value[n]||(e.value[n]=[]);let a=e.value[n];for(let s=0;s<a.length&&s<r.columns;s++){let o={...r.start,row:r.start.row+n,column:r.start.column+s};a[s]=this.TranslateR1C1(o,a[s])}}else if(typeof e.value=="string"&&e.value[0]==="="){let n=[];for(let a=0;a<r.rows;a++){let s=[];for(let o=0;o<r.columns;o++){let l={...r.start,row:r.start.row+a,column:r.start.column+o};s.push(this.TranslateR1C1(l,e.value))}n.push(s)}e.value=n}}i.SetAreaValues2(r,e.value)}return r}}ActivateSheetInternal(e){let t=this.ResolveSheet(e)||this.model.sheets.list[0];if(this.active_sheet===t&&!e.force)return;if(!t.visible)throw new Error("cannot activate hidden sheet");let r=this.active_sheet;this.active_sheet=t,this.grid_events.Publish({type:"sheet-change",deactivate:r,activate:this.active_sheet})}ShowSheetInternal(e){let t=this.ResolveSheet(e);if(t&&t.visible!==e.show){if(!e.show){let r=0;for(let i of this.model.sheets.list)(!t.visible||i===t)&&r++;if(r>=this.model.sheets.length)throw new Error("can't hide all sheets")}if(t.visible=e.show,t===this.active_sheet){let r=this.model.sheets.list;for(let i=0;i<r.length;i++)if(r[i]===this.active_sheet){for(let n=i+1;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:21,index:n});return}for(let n=0;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:21,index:n});return}throw new Error("no visible sheet")}}}}NormalizeCommands(e){Array.isArray(e)||(e=[e]);let t=this.active_sheet.id;for(let r of e)switch(r.key){case 0:case 17:case 24:case 18:case 19:case 20:case 21:case 22:case 23:case 26:break;case 27:case 29:r.table.area.start.sheet_id||(r.table.area.start.sheet_id=t);break;case 3:case 4:case 2:case 1:case 15:r.sheet_id||(r.sheet_id=t);break;case 11:case 13:case 14:case 8:case 9:case 10:case 25:case 6:case 7:case 16:case 5:case 28:r.area&&(N(r.area)?r.area.sheet_id||(r.area.sheet_id=t):r.area.start.sheet_id||(r.area.start.sheet_id=t));break}return e}AddSheetInternal(e=Y.default_sheet_name,t=-1){if(!this.options.add_tab){console.warn("add tab option not set or false");return}for(;this.model.sheets.list.some(i=>i.name===e);){let i=e.match(/^(.*?)(\d+)$/);i?e=i[1]+(Number(i[2])+1):e=e+"2"}let r=Y.Blank(this.model.theme_style_properties,e);return t>=0?this.model.sheets.Splice(t,0,r):this.model.sheets.Add(r),r.id}ResolveSheet(e){if(typeof e.index<"u")return this.model.sheets.list[e.index];if(typeof e.name<"u")return this.model.sheets.Find(e.name);if(e.id)return this.model.sheets.Find(e.id)}FindSheet(e){if(e===void 0)return this.active_sheet;let t=typeof e=="number"?e:N(e)?e.sheet_id:e.start.sheet_id;if(!t||t===this.active_sheet.id)return this.active_sheet;let r=this.model.sheets.Find(t);return r||this.active_sheet}PatchFormulasInternal(e,t,r,i,n,a,s){let o=this.parser.Parse(e||""),l=!1;if(o.expression&&(this.parser.Walk(o.expression,d=>{if(d.type==="range"||d.type==="address"){let h=[];d.type==="range"?(d.start.sheet&&d.start.sheet.toLowerCase()===a||!d.start.sheet&&s)&&h.push(d.start,d.end):d.type==="address"&&(d.sheet&&d.sheet.toLowerCase()===a||!d.sheet&&s)&&h.push(d);for(let u of h)r&&u.row>=t&&(r<0&&u.row+r<t?u.column=u.row=-1:u.row+=r,l=!0),n&&u.column>=i&&(n<0&&u.column+n<i?u.column=u.row=-1:u.column+=n,l=!0);return!1}return!0}),l))return"="+this.parser.Render(o.expression,{missing:""})}PatchExpressionSheetName(e,t,r){let i=!1,n=this.parser.Parse(e||"");if(n.expression&&(this.parser.Walk(n.expression,a=>(a.type==="address"&&a.sheet&&a.sheet.toLowerCase()===t&&(a.sheet=r,i=!0),!0)),i))return"="+this.parser.Render(n.expression,{missing:""})}RenameSheetReferences(e,t,r){let i=0;t=t.toLowerCase();for(let n of e){if(n.cells.IterateAll(a=>{if(a.ValueIsFormula()){let s=this.PatchExpressionSheetName(a.value||"",t,r);s&&(a.value=s,i++)}}),n.conditional_formats?.length)for(let a of n.conditional_formats)switch(a.type){case"cell-match":case"expression":{let s=this.PatchExpressionSheetName(a.expression,t,r);s&&(a.expression=s,i++)}break}for(let a of n.annotations)if(a.data.formula){let s=this.PatchExpressionSheetName(a.data.formula,t,r);s&&(a.data.formula=s,i++)}}return i}ApplyBordersInternal(e){let t=e.borders,r=e.borders==="none"?0:e.width,i=new y(e.area.start,e.area.end),n=this.FindSheet(i);i.start.sheet_id=n.id;let a={border_top:r},s={border_bottom:r},o={border_left:r},l={border_right:r},d={border_top:0,border_top_fill:{}},h={border_bottom:0,border_bottom_fill:{}},u={border_left:0,border_left_fill:{}},m={border_right:0,border_right_fill:{}};return e.color?(a.border_top_fill={...e.color},s.border_bottom_fill={...e.color},o.border_left_fill={...e.color},l.border_right_fill={...e.color}):(a.border_top_fill={},s.border_bottom_fill={},o.border_left_fill={},l.border_right_fill={}),(t==="none"||t==="all")&&n.UpdateAreaStyle(i,{...a,...s,...o,...l},!0),(t==="top"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.top,{...a},!0)),(t==="none"||t==="all"||t==="outside"||t==="top")&&(i.entire_column||i.start.row&&n.UpdateAreaStyle(new y({row:i.start.row-1,column:i.start.column},{row:i.start.row-1,column:i.end.column}),{...h},!0)),(t==="bottom"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.bottom,{...s},!0)),(t==="none"||t==="all"||t==="outside"||t==="bottom")&&(i.entire_column||n.UpdateAreaStyle(new y({row:i.end.row+1,column:i.start.column},{row:i.end.row+1,column:i.end.column}),{...d},!0)),(t==="left"||t==="outside")&&(i.entire_row||n.UpdateAreaStyle(i.left,{...o},!0)),(t==="none"||t==="all"||t==="outside"||t==="left")&&(i.entire_row||i.start.column&&n.UpdateAreaStyle(new y({row:i.start.row,column:i.start.column-1},{row:i.end.row,column:i.start.column-1}),{...m},!0)),(t==="right"||t==="outside")&&(i.entire_row||n.UpdateAreaStyle(i.right,{...l},!0)),(t==="none"||t==="all"||t==="outside"||t==="right")&&(i.entire_row||n.UpdateAreaStyle(new y({row:i.start.row,column:i.end.column+1},{row:i.end.row,column:i.end.column+1}),{...u},!0)),y.Bleed(i)}TranslateR1C1(e,t){let r=!1,i=this.parser.flags.r1c1;if(this.parser.flags.r1c1=!0,typeof t=="string"&&t[0]==="="){let n=this.parser.Parse(t);n.expression&&(this.parser.Walk(n.expression,a=>(a.type==="address"&&a.r1c1&&(r=!0,a.offset_column&&(a.column=a.column+e.column),a.offset_row&&(a.row=a.row+e.row)),!0)),r&&(t="="+this.parser.Render(n.expression,{missing:""})))}return this.parser.flags.r1c1=i,t}ClearAreaInternal(e){let t;if(e.start.sheet_id?t=this.model.sheets.Find(e.start.sheet_id):t=this.active_sheet,!t){console.warn("can't resolve sheet in ClearAreaInternal");return}let r=!1;e=t.RealArea(e),t.cells.Apply(e,n=>{n.area&&!e.ContainsArea(n.area)&&(r=!0)});let i=this.model.tables.keys();for(let n of i){let a=this.model.tables.get(n);if(a&&a.area.start.sheet_id===t.id){let s=new y(a.area.start,a.area.end);if(e.ContainsArea(s)){for(let o=s.start.row;o<=s.end.row;o++)for(let l=s.start.column;l<=a.area.end.column;l++){let d=t.cells.GetCell({row:o,column:l},!1);d&&(d.table=void 0)}this.model.tables.delete(n)}}}r?this.Error(2):t.ClearArea(e)}Error(e){this.grid_events.Publish({type:"error",code:e})}DuplicateSheetInternal(e){if(!this.options.add_tab){console.warn("add tab option not set or false");return}let t=this.ResolveSheet(e),r=this.model.sheets.list.reduce((o,l)=>Math.max(o,l.id),0)+1,i=-1;for(let o=0;o<this.model.sheets.length;o++)this.model.sheets.list[o]===t&&(i=o+1);if(!t||i<0)throw new Error("source sheet not found");if(typeof e.insert_before=="number")i=e.insert_before;else if(typeof e.insert_before=="string"){let o=e.insert_before.toLowerCase();for(let l=0;l<this.model.sheets.length;l++)if(this.model.sheets.list[l].name.toLowerCase()===o){i=l;break}}let n={rendered_values:!0},a=Y.FromJSON(t.toJSON(n),this.model.theme_style_properties),s=e.new_name||t.name;for(;this.model.sheets.list.some(o=>o.name===s);){let o=s.match(/^(.*?)(\d+)$/);o?s=o[1]+(Number(o[2])+1):s=s+"2"}return a.name=s,a.id=r,this.model.sheets.Splice(i,0,a),a.id}SelectInternal(e){}FreezeInternal(e){let t=this.FindSheet(e.sheet_id||this.active_sheet.id);t.freeze.rows=e.rows,t.freeze.columns=e.columns}PatchExpression(e,t){let r=0,i=this.parser.Parse(e);if(i.expression&&(this.parser.Walk(i.expression,n=>{if(n.type==="range"){if(!n.start.sheet||n.start.sheet.toLowerCase()===t.sheet.name.toLowerCase()){let a=y.PatchArea(n,t);a?(n.start.row=a.start.row,n.start.column=a.start.column,n.end.row=a.end.row,n.end.column=a.end.column):n.start.row=n.end.row=n.start.column=n.end.column=-1}return r++,!1}else if(n.type==="address"){let a=y.PatchArea({start:n,end:n},t);return a?(n.row=a.start.row,n.column=a.start.column):n.row=n.column=-1,r++,!1}return!0}),r))return this.parser.Render(i.expression,{missing:""})}PatchConditionals(e){if(e.sheet.conditional_formats?.length){let t=new Set;for(let r of e.sheet.conditional_formats){let i=y.PatchArea(r.area,e);if(i)r.area=JSON.parse(JSON.stringify(i));else{t.add(r);continue}switch(r.type){case"expression":case"cell-match":{let n=this.PatchExpression(r.expression,e);n&&(r.expression=n)}break}}t.size&&(e.sheet.conditional_formats=e.sheet.conditional_formats.filter(r=>!t.has(r)))}}InsertRowsInternal(e){let t=this.FindSheet(e.sheet_id);if(e.count===1/0?e.count=1:e.count===-1/0&&(e.count=-t.rows),!t.InsertRows(e.before_row,e.count))return this.Error(2),{error:!0};this.PatchConditionals({sheet:t,before_column:0,column_count:0,before_row:e.before_row,row_count:e.count});let r=Array.from(this.model.tables.values());for(let o of r)if(o.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_row<=o.area.start.row)o.area.start.row+=e.count,o.area.end.row+=e.count;else if(e.before_row<=o.area.end.row){o.area.end.row+=e.count;for(let l=o.area.start.row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=o}}}else if(e.before_row<=o.area.start.row)if(e.before_row-e.count<=o.area.start.row)o.area.start.row+=e.count,o.area.end.row+=e.count;else if(e.before_row-e.count>=o.area.end.row)this.model.tables.delete(o.name.toLowerCase());else{this.model.tables.delete(o.name.toLowerCase());for(let l=e.before_row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table===o&&(h.table=void 0)}}else e.before_row<=o.area.end.row&&(e.before_row-e.count>o.area.end.row&&(o.totals_row=!1),o.area.end.row=Math.max(0,o.area.end.row+e.count,e.before_row-1));this.model.named_ranges.PatchNamedRanges(t.id,0,0,e.before_row,e.count);let i=t.name.toLowerCase();for(let o of this.model.sheets.list){let l=o===t;o.cells.IterateAll(d=>{if(d.ValueIsFormula()){let h=this.PatchFormulasInternal(d.value||"",e.before_row,e.count,0,0,i,l);h&&(d.value=h)}});for(let d of o.annotations)if(d.data.formula){let h=this.PatchFormulasInternal(d.data.formula||"",e.before_row,e.count,0,0,i,l);h&&(d.data.formula=h)}}let n=[],a=[],s=[];if(e.count>0){let o=e.before_row;for(let l of t.annotations)if(l.data.layout){let[d,h,u]=[l.data.layout.tl.address.row,l.data.layout.br.address.row,l.data.layout.br.offset.y];if(o<=d)l.data.layout.tl.address.row+=e.count,l.data.layout.br.address.row+=e.count;else if(o<h||o===h&&u>0)l.data.layout.br.address.row+=e.count,a.push(l);else continue;n.push(l)}}else if(e.count<0){let o=e.before_row,l=e.before_row-e.count-1;for(let d of t.annotations)if(d.data.layout){let[h,u,m]=[d.data.layout.tl.address.row,d.data.layout.br.address.row,d.data.layout.br.offset.y];if(o<=h)if(l<h)d.data.layout.tl.address.row+=e.count,d.data.layout.br.address.row+=e.count;else if(l<u-1||l===u-1&&m>0)d.data.layout.tl.address.row=o,d.data.layout.tl.offset.y=0,d.data.layout.br.address.row+=e.count,a.push(d);else{s.push(d);continue}else if(o<u||o===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.row+=e.count,a.push(d)):(d.data.layout.br.address.row=o,d.data.layout.br.offset.y=0,a.push(d));else continue;n.push(d)}}for(let o of s)t.annotations=t.annotations.filter(l=>l!==o);return{update_annotations_list:n,resize_annotations_list:a,delete_annotations_list:s}}InsertColumnsInternal(e){let t=this.FindSheet(e.sheet_id);if(e.count===1/0?e.count=1:e.count===-1/0&&(e.count=-t.columns),!t.InsertColumns(e.before_column,e.count))return this.Error(2),{error:!0};this.PatchConditionals({sheet:t,before_column:e.before_column,column_count:e.count,before_row:0,row_count:0});let r=Array.from(this.model.tables.values());for(let o of r)if(o.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_column<=o.area.start.column)o.area.start.column+=e.count,o.area.end.column+=e.count;else if(e.before_column<=o.area.end.column){o.area.end.column+=e.count;for(let l=o.area.start.row;l<=o.area.end.row;l++)for(let d=o.area.start.column;d<=o.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=o}this.UpdateTableColumns(o)}}else e.before_column<=o.area.start.column?e.before_column-e.count<=o.area.start.column?(o.area.start.column+=e.count,o.area.end.column+=e.count):e.before_column-e.count>=o.area.end.column?this.model.tables.delete(o.name.toLowerCase()):(o.area.start.column=e.before_column,o.area.end.column+=e.count,this.UpdateTableColumns(o)):e.before_column<=o.area.end.column&&(o.area.end.column=Math.max(0,o.area.end.column+e.count,e.before_column-1),this.UpdateTableColumns(o));this.model.named_ranges.PatchNamedRanges(t.id,e.before_column,e.count,0,0);let i=t.name.toLowerCase();for(let o of this.model.sheets.list){let l=o===t;o.cells.IterateAll(d=>{if(d.ValueIsFormula()){let h=this.PatchFormulasInternal(d.value||"",0,0,e.before_column,e.count,i,l);h&&(d.value=h)}});for(let d of o.annotations)if(d.data.formula){let h=this.PatchFormulasInternal(d.data.formula,0,0,e.before_column,e.count,i,l);h&&(d.data.formula=h)}}let n=[],a=[],s=[];if(e.count>0){let o=e.before_column;for(let l of t.annotations)if(l.data.layout){let[d,h,u]=[l.data.layout.tl.address.column,l.data.layout.br.address.column,l.data.layout.br.offset.x];if(o<=d)l.data.layout.tl.address.column+=e.count,l.data.layout.br.address.column+=e.count;else if(o<h||o===h&&u>0)l.data.layout.br.address.column+=e.count,a.push(l);else continue;n.push(l)}}else if(e.count<0){let o=e.before_column,l=e.before_column-e.count-1;for(let d of t.annotations)if(d.data.layout){let[h,u,m]=[d.data.layout.tl.address.column,d.data.layout.br.address.column,d.data.layout.br.offset.x];if(o<=h)if(l<h)d.data.layout.tl.address.column+=e.count,d.data.layout.br.address.column+=e.count;else if(l<u-1||l===u-1&&m>0)d.data.layout.tl.address.column=o,d.data.layout.tl.offset.x=0,d.data.layout.br.address.column+=e.count,a.push(d);else{s.push(d);continue}else if(o<u||o===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.column+=e.count,a.push(d)):(d.data.layout.br.address.column=o,d.data.layout.br.offset.x=0,a.push(d));else continue;n.push(d)}}for(let o of s)t.annotations=t.annotations.filter(l=>l!==o);return{update_annotations_list:n,resize_annotations_list:a,delete_annotations_list:s}}ExecCommand(e,t=!0){let r={pending:[]},i=[];e=this.NormalizeCommands(e),t&&this.command_log.Publish({command:e,timestamp:new Date().getTime()});for(let n of e)switch(n.key){case 26:this.ResetInternal();break;case 11:if(n.area){let a=new y(n.area.start,n.area.end);this.ClearAreaInternal(a),r.data_area=y.Join(a,r.data_area),r.formula=!0}break;case 5:this.SelectInternal(n);break;case 15:this.FreezeInternal(n),r.structure_event=!0;break;case 28:{let a=this.FindSheet(n.area),s=new y(n.area.start,n.area.end),o=!0;e:for(let l=s.start.row;l<=s.end.row;l++)for(let d=s.start.column;d<=s.end.column;d++){let h=a.cells.GetCell({row:l,column:d},!1);if(h&&(h.area||h.merge_area||h.table)){o=!1;break e}}if(o){let l=this.model.tables.size+1,d="";for(;d=`Table${l++}`,!!this.model.tables.has(d.toLowerCase()););let h={area:n.area,name:d,sortable:n.sortable,theme:n.theme};n.totals&&(h.totals_row=!0),this.model.tables.set(d.toLowerCase(),h);for(let u=s.start.row;u<=s.end.row;u++)for(let m=s.start.column;m<=s.end.column;m++){let f=a.cells.GetCell({row:u,column:m},!0);f.table=h}this.UpdateTableColumns(h),a.Invalidate(new y(h.area.start,h.area.end)),a===this.active_sheet?(r.style_area=y.Join(s,r.style_area),r.render_area=y.Join(s,r.render_area)):r.style_event=!0}}break;case 29:{let a=this.FindSheet(n.table.area),s=new y(n.table.area.start,n.table.area.end);for(let l=s.start.row;l<=s.end.row;l++)for(let d=s.start.column;d<=s.end.column;d++){let h=a.cells.GetCell({row:l,column:d},!1);h&&(h.table=void 0)}this.model.tables.delete(n.table.name.toLowerCase());let o=a.RealArea(s.Clone().Shift(-1,-1).Resize(s.rows+2,s.columns+2));a.Invalidate(o),a===this.active_sheet?(r.style_area=y.Join(s,r.style_area),r.render_area=y.Join(s,r.render_area)):r.style_event=!0}break;case 9:{let a=this.FindSheet(n.area);a.MergeCells(new y(n.area.start,n.area.end)),r.structure_event=!0,r.structure_rebuild_required=!0,a===this.active_sheet?(r.data_area=y.Join(n.area,r.data_area),r.render_area=y.Join(n.area,r.render_area)):(r.data_event=!0,r.pending||(r.pending=[]),r.pending.push(a.id))}break;case 10:{let a=this.FindSheet(n.area),s={},o=new y(n.area.start,n.area.end);a.cells.Apply(o,d=>{if(d.merge_area){let h=y.CellAddressToLabel(d.merge_area.start)+":"+y.CellAddressToLabel(d.merge_area.end);s[h]=d.merge_area}},!1);let l=Object.keys(s);for(let d=0;d<l.length;d++)a.UnmergeCells(s[l[d]]);a===this.active_sheet?(r.render_area=y.Join(n.area,r.render_area),r.data_area=y.Join(n.area,r.data_area)):(r.data_event=!0,r.pending||(r.pending=[]),r.pending.push(a.id)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 7:{let a,s=this.FindSheet(n.area);N(n.area)?(a=new y(n.area),s.UpdateCellStyle(n.area,n.style,!!n.delta)):(a=new y(n.area.start,n.area.end),s.UpdateAreaStyle(a,n.style,!!n.delta)),s===this.active_sheet?(r.style_area=y.Join(a,r.style_area),(!n.delta||n.style.fill||n.style.border_top||n.style.border_left||n.style.border_right||n.style.border_bottom)&&(a=y.Bleed(a),this.active_sheet.Invalidate(a)),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}break;case 25:this.SetValidationInternal(n),(!n.area.sheet_id||n.area.sheet_id===this.active_sheet.id)&&(r.render_area=y.Join(new y(n.area),r.render_area));break;case 16:n.area?(this.model.named_expressions.delete(n.name),this.model.named_ranges.SetName(n.name,new y(n.area.start,n.area.end)),this.autocomplete_matcher.AddFunctions({type:1,name:n.name})):n.expression?(this.model.named_ranges.ClearName(n.name),this.model.named_expressions.set(n.name,n.expression),this.autocomplete_matcher.AddFunctions({type:1,name:n.name})):(this.model.named_ranges.ClearName(n.name),this.model.named_expressions.delete(n.name),this.autocomplete_matcher.RemoveFunctions({type:1,name:n.name})),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 8:{let a=this.ApplyBordersInternal(n);a.start.sheet_id===this.active_sheet.id?(r.render_area=y.Join(a,r.render_area),r.style_area=y.Join(a,r.style_area)):r.style_event=!0}break;case 24:this.ShowSheetInternal(n),r.sheets=!0,r.structure_event=!0;break;case 23:{let a=[],s=this.model.sheets.list[n.index];for(let o=0;o<this.model.sheets.length;o++)o!==n.index&&(o===n.move_before&&a.push(s),a.push(this.model.sheets.list[o]));n.move_before>=this.model.sheets.length&&a.push(s),this.model.sheets.Assign(a),r.sheets=!0,r.structure_event=!0}break;case 22:{let a=this.ResolveSheet(n);a&&(this.RenameSheetInternal(a,n.new_name),r.sheets=!0,r.structure_event=!0)}break;case 3:{let a=this.ResizeRowsInternal(n);if(a)if(a.start.sheet_id===this.active_sheet.id){let s=this.active_sheet.RealArea(new y(a.start,a.end));r.render_area=y.Join(s,r.render_area),r.data_area=y.Join(s,r.data_area),r.data_event=!0}else r.data_event=!0,r.pending||(r.pending=[]),a.start.sheet_id&&r.pending.push(a.start.sheet_id);r.structure_event=!0}break;case 4:this.ResizeColumnsInternal(n),r.structure_event=!0;break;case 17:this.active_sheet.SetHeaderSize(n.show?void 0:1,n.show?void 0:1),this.flags.layout=!0,this.flags.repaint=!0;break;case 1:this.InsertRowsInternal(n),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 2:this.InsertColumnsInternal(n),r.structure_event=!0,r.structure_rebuild_required=!0;break;case 14:case 13:{let a=this.FindSheet(n.area),s=a.cells.GetCell(n.area,!0);if(s){let o;s.merge_area?(o=new y(s.merge_area.start),s=a.cells.GetCell(s.merge_area.start,!0)):o=new y(n.area),n.key===13?s.SetNote(n.note):(s.hyperlink=n.reference||void 0,s.render_clean=[]),a===this.active_sheet?(r.style_area=y.Join(o,r.style_area),r.render_area=y.Join(o,r.render_area)):r.style_event=!0}}break;case 27:{let a=this.SortTableInternal(n);a&&a.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(a,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(a,r.render_area))):r.data_event=!0}break;case 6:{let a=this.SetRangeInternal(n,r);if(a){let o=this.model.sheets.Find(a.start.sheet_id||this.active_sheet.id)?.TablesFromArea(a,!0)||[];for(let l of o)this.UpdateTableColumns(l)}a&&a.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(a,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(a,r.render_area))):r.data_event=!0}break;case 20:this.DeleteSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 19:this.DuplicateSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 18:{let a=this.AddSheetInternal(n.name,n.insert_index);typeof a=="number"&&n.show&&this.ActivateSheetInternal({key:21,id:a}),r.structure_event=!0,r.sheets=!0,r.structure=!0}break;case 21:this.ActivateSheetInternal(n);break;default:console.warn(`unhandled command: ${tt[n.key]} (${n.key})`)}return r.data_area?(r.data_area.start.sheet_id||r.data_area.SetSheetID(this.active_sheet.id),i.push({type:"data",area:r.data_area})):r.data_event&&i.push({type:"data"}),r.style_area?(r.style_area.start.sheet_id||r.style_area.SetSheetID(this.active_sheet.id),i.push({type:"style",area:r.style_area})):r.style_event&&i.push({type:"style"}),r.structure_event&&i.push({type:"structure",rebuild_required:r.structure_rebuild_required}),this.batch?this.batch_events.push(...i):this.grid_events.Publish(i),r}};var Nt=class extends Me{get active(){return this.nodes.length>0}Reset(){this.AttachNodes()}AttachNodes(e=[],t=!0){this.assume_formula=t;let r=[];r=e.map(i=>{for(let n of this.nodes)if(n.node===i)return n;return{node:i}});for(let i of this.nodes)if(i.listeners){for(let[n,a]of i.listeners.entries())i.node.removeEventListener(n,a);i.listeners.clear()}this.nodes=r;for(let i of this.nodes){if(i.formatted_text===i.node.textContent){let n=i.node.innerHTML.length;i.check!==n&&(i.formatted_text=void 0)}i.node.ownerDocument.activeElement===i.node&&(this.active_editor=i),this.UpdateText(i,{toll_events:!0}),this.RegisterListener(i,"focusin",()=>{this.active_editor=i}),this.RegisterListener(i,"focusout",()=>{this.active_editor=void 0}),this.RegisterListener(i,"input",n=>{n.isTrusted&&(this.UpdateText(i),this.UpdateColors())})}this.UpdateColors(!0)}};var it=class extends rt{hide_selection=!1;headless=!1;get scale(){return this.layout.scale}set scale(e){this.layout.scale=e,this.UpdateLayout(),this.UpdateAnnotationLayout(),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.layout.ApplyTheme(this.theme),this.overlay_editor?.UpdateScale(e),this.tab_bar?.UpdateScale(e),this.grid_events.Publish({type:"scale",scale:e});for(let t of this.model.sheets.list)for(let r of t.annotations)r.dirty=!0}theme;language_map;reverse_language_map;hover_data={};editing_state=0;editing_cell={row:-1,column:-1,sheet_id:0};selected_annotation;editing_annotation;view_node;container;layout;tile_update_pending=!1;scroll_offset_pending;pending_layout_update=new Set;decimal_separator_code=46;overlay_editor;autocomplete;formula_bar;RESIZE_PIXEL_BUFFER=5;external_editor_config;external_editor;cell_resize={row:-1,column:-1};render_tiles=new y({row:0,column:0});primary_selection={target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0};active_selection={target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0};nub_select_flag=!1;additional_selections=[];double_click_data={};layout_token=0;render_token=0;tile_renderer;selection_renderer;tab_bar;DOM=F.GetInstance();constructor(e={},t,r=ht,i=!0,n){if(super(e,t),this.decimal_separator_code=D.decimal_separator.charCodeAt(0),this.theme=JSON.parse(JSON.stringify(r)),!i){this.headless=!0,this.layout=new Tt(this.model,this.view);return}this.DOM=n,this.layout=new Rt(this.model,this.view,n),e.initial_scale&&(typeof e.initial_scale=="string"&&(e.initial_scale=Number(e.initial_scale)),this.layout.scale=e.initial_scale),this.tile_renderer=new zt(this.theme,this.layout,this.model,this.view,this.options),this.selection_renderer=new At(this.theme,this.layout,this.model,this.view,this.primary_selection,this.additional_selections)}SetLanguageMap(e){if(!e)this.language_map=this.reverse_language_map=void 0;else{let t=Object.keys(e);this.language_map={};for(let r of t)this.language_map[r.toUpperCase()]=e[r];this.reverse_language_map={};for(let r of t){let i=e[r];this.reverse_language_map[i.toUpperCase()]=r}}this.primary_selection.empty||this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target)}SetNote(e,t){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.target}this.ExecCommand({key:13,area:e,note:t})}FindAnnotation(e){for(let t of this.active_sheet.annotations)if((t.view[this.view_index]||{}).node===e)return t}CreateAnnotation(e={},t=!0,r=!1,i){let n=new Ee(e);if(r)if(!n.data.layout&&n.scaled_rect&&(n.data.layout=this.layout.RectToAnnotationLayout(n.scaled_rect)),!n.data.layout)console.warn("can't offset annotation without layout");else{let a=this.layout.AnnotationLayoutToRect(n.data.layout).Shift(20,20),s=!0;for(;s;){s=!1;for(let o of this.active_sheet.annotations)if(o!==n&&o.scaled_rect&&o.scaled_rect.top===a.top&&o.scaled_rect.left===a.left){a=a.Shift(20,20),s=!0;break}}n.data.layout=this.layout.RectToAnnotationLayout(a)}return i&&(H.IsRectangle(i)?(n.data.layout=void 0,n.rect=H.Create(i)):i.start&&(n.rect=void 0,n.data.layout=this.layout.AddressToAnnotationLayout(i.start,i.end||i.start))),t&&(this.active_sheet.annotations.some(a=>a===n)||this.active_sheet.annotations.push(n),this.AddAnnotation(n)),n}UpdateAnnotationLayout(){}AddAnnotation(e,t=!1,r=!0){let i=e.view[this.view_index];if(i||(i={},e.view[this.view_index]=i),!i.node){let n=this.DOM.Div("annotation",void 0,{data:{scale:this.layout.scale.toString()},style:{fontSize:`${10*this.layout.scale}pt`},attrs:{tabindex:"-1"},events:{mousedown:o=>{o.button===0&&this.layout.AnnotationMouseDown(e,n,o,a,s).then(l=>{l&&this.grid_events.Publish(l),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)})},focusin:()=>{for(let o of this.layout.GetFrozenAnnotations(e))o.classList.add("clone-focus");this.selected_annotation=e,this.primary_selection.empty=!0,this.primary_selection.target={row:-1,column:-1,sheet_id:this.active_sheet.id},this.HideGridSelection()},focusout:o=>{for(let l of this.layout.GetFrozenAnnotations(e))l.classList.remove("clone-focus");this.formula_bar&&this.formula_bar.IsElement(o.relatedTarget)?(this.primary_selection.empty=!0,this.RenderSelections(),this.editing_annotation=e,this.layout.ShowSelections(!0)):(this.selected_annotation===e&&(this.selected_annotation=void 0),this.ShowGridSelection())}}});i.node=n,i.content_node=this.DOM.Div("annotation-content",n);let a=this.DOM.Div("annotation-move-target",n),s=this.DOM.Div("annotation-resize-target",n);n.addEventListener("keydown",o=>{let l=e.scaled_rect;if(!l){console.info("missing scaled rect!");return}let d=[n,...this.layout.GetFrozenAnnotations(e)],h={x:l.left,y:l.top};switch(o.key){case"ArrowUp":case"Up":o.ctrlKey?(this.layout.AnnotationLayoutOrder(e,1)&&this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),n.focus()):h.y--;break;case"ArrowLeft":case"Left":if(o.ctrlKey)return;h.x--;break;case"ArrowRight":case"Right":if(o.ctrlKey)return;h.x++;break;case"ArrowDown":case"Down":o.ctrlKey?(this.layout.AnnotationLayoutOrder(e,-1)&&this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),n.focus()):h.y++;break;case"Escape":case"Esc":this.Focus();break;case"Delete":case"Del":this.Focus(),this.RemoveAnnotation(e);break;default:return}if(o.stopPropagation(),o.preventDefault(),h.x=Math.max(h.x,0),h.y=Math.max(h.y,0),l.left!==h.x||l.top!==h.y){l.left=Math.round(h.x),l.top=Math.round(h.y);for(let u of d)u.style.top=l.top+"px",u.style.left=l.left+"px";e.data.extent=void 0,this.grid_events.Publish({type:"annotation",event:"move",annotation:e}),e.data.layout=this.layout.RectToAnnotationLayout(l)}})}r&&(this.layout.AddAnnotation(e),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)),t||this.grid_events.Publish({type:"annotation",annotation:e,event:"create"})}AnnotationUpdated(e){this.layout.CloneFrozenAnnotation(e)}RemoveAnnotation(e){for(let t=0;t<this.active_sheet.annotations.length;t++)if(e===this.active_sheet.annotations[t]){this.active_sheet.annotations.splice(t,1),this.layout.RemoveAnnotation(e),this.grid_events.Publish({type:"annotation",annotation:e,event:"delete"});return}}RemoveAnnotationNodes(){this.headless||this.layout.RemoveAnnotationNodes()}Serialize(e={}){return this.active_sheet.selection=JSON.parse(JSON.stringify(this.primary_selection)),this.active_sheet.scroll_offset=this.layout.scroll_offset,super.Serialize(e)}ShowHeaders(e=!0){this.ExecCommand({key:17,show:e})}FromImportData(e,t=!1){this.RemoveAnnotationNodes();let r=e.sheets,i=r.map(()=>Y.Blank(this.model.theme_style_properties).toJSON()),n;if(typeof e.active_tab=="number")n=i[e.active_tab]?.id;else for(let s=0;s<e.sheets.length;s++)if(!e.sheets[s].hidden){n=i[s].id;break}this.UpdateSheets(i,!0,n);let a={};this.model.macro_functions.clear(),this.ClearSelection(this.primary_selection),this.model.tables.clear();for(let s=0;s<r.length;s++){let o=this.model.sheets.list[s];o.ImportData(r[s]),a[o.name]=o.id;for(let l of r[s].cells)l.table&&(l.table.area.start.sheet_id=o.id,this.model.tables.set(l.table.name.toLowerCase(),l.table));for(let l of this.model.tables.values())this.UpdateTableColumns(l)}if(this.model.sheets.UpdateIndexes(),this.model.named_ranges.Reset(),this.model.named_expressions.clear(),e.names){for(let s of Object.keys(e.names)){let o=this.model.named_ranges.ValidateNamed(s);if(!o){console.warn(`invalid name: ${s}`);continue}let l=e.names[s];if(typeof l!="number"){let d=this.parser.Parse(l);if(d.expression)if(d.expression.type==="range"){let h=a[d.expression.start.sheet||""];h&&(d.expression.start.sheet_id=h,this.model.named_ranges.SetName(o,new y(d.expression.start,d.expression.end),!1))}else if(d.expression.type==="address"){let h=a[d.expression.sheet||""];h&&(d.expression.sheet_id=h,this.model.named_ranges.SetName(o,new y(d.expression),!1))}else{let h=d.expression;this.parser.Walk(h,u=>u.type==="address"||u.type==="range"?(u.type==="range"&&(u=u.start),u.sheet_id||(u.sheet_id=a[u.sheet||""]||0),!1):!0),this.model.named_expressions.set(o,h)}}}this.model.named_ranges.RebuildList()}for(let s of this.active_sheet.annotations)this.AddAnnotation(s,!0);this.ActivateSheetTasks(),this.QueueLayoutUpdate(),this.StyleDefaultFromTheme(),t&&this.Repaint(!1,!1),this.tab_bar&&this.tab_bar.Update()}NextSheet(e=1){if(this.model.sheets.length===1)return;let t=this.model.sheets.list.map((r,i)=>({sheet:r,index:i})).filter(r=>r.sheet.visible);if(t.length!==1){for(let r=0;r<t.length;r++)if(t[r].sheet===this.active_sheet){let i=(r+e)%t.length;for(;i<0;)i+=t.length;this.ActivateSheet(t[i].index);return}}}UpdateSheets(e,t=!1,r){if(super.UpdateSheets(e,t,r),this.RemoveAnnotationNodes(),this.ClearSelection(this.primary_selection),e[0]&&e[0].primary_selection){let i=e[0].primary_selection;i.empty||this.Select(this.primary_selection,new y(i.area.start,i.area.end),i.target)}else if(!this.active_sheet.selection.empty){let i=this.active_sheet.selection;this.Select(this.primary_selection,new y(i.area.start,i.area.end),i.target)}this.layout.ClearLayoutCaches();for(let i of this.model.sheets.list)for(let n of i.annotations)this.AddAnnotation(n,!0,i===this.active_sheet);this.ActivateSheetTasks(),this.QueueLayoutUpdate(JSON.parse(JSON.stringify(this.active_sheet.scroll_offset))),this.StyleDefaultFromTheme(),t&&this.Repaint(!1,!1),this.tab_bar&&this.tab_bar.Update()}UpdateLayout(){this.layout.UpdateTiles(),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!0)}UpdateTheme(e=!1,t){if(!e)for(let i of Object.keys(this.theme))delete this.theme[i];let r=JSON.parse(JSON.stringify(ht));this.view_node&&(r={...Hr(this.view_node)}),r={...this.theme,...r,...t},Object.assign(this.theme,r),this.StyleDefaultFromTheme(),this.active_sheet.UpdateDefaultRowHeight(),this.active_sheet.FlushCellStyles(),this.layout.ApplyTheme(this.theme),e||(this.UpdateLayout(),this.overlay_editor?.UpdateScale(this.layout.scale),this.Repaint(!0,!0,!0))}Initialize(e,t=!1){if(!this.tile_renderer||!this.selection_renderer)return;this.view_node=e,this.UpdateTheme(!0);let i=e.querySelector(".treb-spreadsheet-body").querySelector("div");this.options.formula_bar&&(this.autocomplete||(this.autocomplete=new et({theme:this.theme,container:i})),this.InitFormulaBar(e,this.autocomplete)),this.options.tab_bar&&(this.tab_bar=new kt(this.layout,this.model,this.view,this.options,e),this.tab_bar.Subscribe(n=>{switch(n.type){case"cancel":break;case"scale":{let a=this.layout.scale;if(a=Math.round(n.value*1e3)/1e3,a=Math.min(2,Math.max(a,.5)),this.options.persist_scale_key&&localStorage.setItem(this.options.persist_scale_key,JSON.stringify({scale:a})),this.scale=a,n.keep_focus)return}break;case"reorder-sheet":this.ReorderSheet(n.index,n.move_before);break;case"delete-sheet":this.DeleteSheet();break;case"add-sheet":this.AddSheet();break;case"rename-sheet":this.RenameSheet(n.sheet,n.name);break;case"activate-sheet":this.ActivateSheetID(n.sheet.id);break}this.SelectingArgument()||this.Focus()})),this.container=i,this.container.classList.add("treb-grid"),re.is_mac&&re.is_safari&&this.container.classList.add("safari"),this.container.setAttribute("tabindex","-1"),this.layout.Initialize(i,{scroll:()=>this.OnScroll(),dropdown:n=>this.OnDropdownSelect(n),sort:(n,a,s)=>{let o=this.model.tables.get(n.toLowerCase());o&&this.SortTable(o,{column:a,asc:s})},focus:()=>this.Focus()},this.options.scrollbars),this.selection_renderer.Initialize(),this.layout.UpdateTiles(),this.autocomplete||(this.autocomplete=new et({theme:this.theme,container:i})),this.InitOverlayEditor(this.autocomplete),this.AttachListeners(),this.render_tiles=this.layout.VisibleTiles(),t||(this.tab_bar?.Update(),this.Repaint(!0))}MergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:9,area:e||this.primary_selection.area}))}UnmergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:10,area:e||this.primary_selection.area}))}Focus(e=""){re.is_mobile?this.container?.focus():this.overlay_editor?.Focus(e)}SetValidation(e,t,r){if(!e){if(this.primary_selection.empty)throw new Error("invalid target in set validation");e=this.primary_selection.target}let i={key:25,area:e,error:r};t&&(Array.isArray(t)?i.list=t:typeof t=="object"&&t.start&&t.end&&N(t.start)&&N(t.end)&&(i.range=t)),this.ExecCommand(i),!this.primary_selection.empty&&(!e.sheet_id||e.sheet_id===this.active_sheet.id)&&this.primary_selection.target.row===e.row&&this.primary_selection.target.column===e.column&&requestAnimationFrame(()=>this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target))}SetName(e,t,r){let i=this.model.named_ranges.ValidateNamed(e);if(!i)throw new Error("invalid name");let n=e.trim().toUpperCase();if(this.autocomplete_matcher){for(let s of Object.keys(this.autocomplete_matcher.function_map))if(n===s.toUpperCase()){if(t||r)throw new Error("name already defined");break}}e=i;let a={key:16,name:e};if(t)N(t)&&(t=new y(t)),t.start.sheet_id||(t=new y({...t.start,sheet_id:this.active_sheet.id},t.end)),a.area=new y(t.start,t.end);else if(r){let s=this.parser.Parse(r);if(s.valid&&s.expression)this.parser.Walk(s.expression,o=>{if(o.type==="address"||o.type==="range"){if(o.type==="range"&&(o=o.start),!o.sheet_id&&o.sheet){let l=this.model.sheets.Find(o.sheet);l&&(o.sheet_id=l.id)}return o.sheet_id||(o.sheet_id=this.active_sheet.id),!1}return!0}),a.expression=s.expression;else throw new Error("invalid expression")}this.ExecCommand(a)}SelectAll(){this.Select(this.primary_selection,new y({row:1/0,column:1/0}),void 0,!0),this.RenderSelections()}ExternalEditor(e){if(this.external_editor_config=e,e){let t=(e.dependencies||[]).filter(r=>!!r).map(r=>N(r)?new y(r):new y(r.start,r.end));if(e.nodes?.length){if(!this.external_editor){let r=new Nt(this.model,this.view);this.external_editor=r,r.Subscribe(i=>this.HighlightDependencies(r.dependencies))}this.external_editor.AttachNodes(e.nodes,e.assume_formula??!0)}else this.external_editor&&this.external_editor.Reset();e.dependencies&&this.HighlightDependencies(t)}else this.external_editor&&this.external_editor.Reset(),this.ClearAdditionalSelections(),this.RenderSelections(!0)}SelectRange(e){this.Select(this.primary_selection,e),this.RenderSelections()}GetRangeStyle(e,t=!1){let r=0;if(N(e)?r=e.sheet_id||this.active_sheet.id:r=e.start.sheet_id||this.active_sheet.id,r)return this.model.sheets.Find(r)?.GetCellStyle(e,t)||void 0}GetRange(e,t){if(N(e)){let i=this.model.sheets.Find(e.sheet_id||this.active_sheet.id);return i?t==="formula"?i.cells.RawValue(e):t==="formatted"?i.GetFormattedRange(e):i.cells.GetRange(e):void 0}let r=this.model.sheets.Find(e.start.sheet_id||this.active_sheet.id);if(r)return t==="formula"?r.cells.RawValue(e.start,e.end):t==="formatted"?r.GetFormattedRange(e.start,e.end):r.cells.GetRange(e.start,e.end)}SetRange(e,t,r={}){let{recycle:i,transpose:n,array:a,r1c1:s}=r;if(r.argument_separator){let o={argument_separator:this.parser.argument_separator,decimal_mark:this.parser.decimal_mark},l=!1;if(r.argument_separator===","&&this.parser.argument_separator!==","&&(this.parser.argument_separator=",",this.parser.decimal_mark=".",l=!0),r.argument_separator===";"&&this.parser.argument_separator!==";"&&(this.parser.argument_separator=";",this.parser.decimal_mark=",",l=!0),l){let d=h=>{if(typeof h=="string"&&h[0]==="="){let u=this.parser.Parse(h);u.expression&&(h="="+this.parser.Render(u.expression,{missing:"",convert_decimal:o.decimal_mark,convert_argument_separator:o.argument_separator}))}return h};Array.isArray(t)?t=t.map(h=>Array.isArray(h)?h.map(u=>d(u)):d(h)):t=d(t)}this.parser.argument_separator=o.argument_separator,this.parser.decimal_mark=o.decimal_mark}if(t=this.UntranslateData(t),!Array.isArray(t))i||a?this.ExecCommand({key:6,area:e,value:t,array:a,r1c1:s}):this.ExecCommand({key:6,area:e.start,value:t,array:a,r1c1:s});else{if(!ir(t))if(i){let o=e.entire_column?this.active_sheet.rows:e.rows,l=e.entire_row?this.active_sheet.columns:e.columns,d=o*l;if(d>t.length){let u=t.slice(0),m=Math.ceil(d/u.length);for(let f=1;f<m;f++)u=u.concat(t.slice(0));t=u}let h=[];for(let u=0,m=0;u<l;u++,m+=o)h[u]=t.slice(m,m+o);t=h}else t=[t];n&&(t=this.Transpose(t)),this.ExecCommand({key:6,area:e,value:t,array:a,r1c1:s})}!this.primary_selection.empty&&e.Contains(this.primary_selection.target)&&this.UpdateFormulaBarFormula()}ApplyStyle(e,t={},r=!0){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.area}Y.UpdateStyle(t),this.ExecCommand({key:7,area:e,style:t,delta:r}),this.UpdateFormulaBarFormula()}GetSelection(){return this.primary_selection}Update(e=!1,t){this.DelayedRender(e,t)}ApplyBorders2(e,t="none",r,i=1){if(!e){if(this.primary_selection.empty)return;e=this.primary_selection.area}t==="none"&&(i=0),this.ExecCommand({key:8,color:r,area:e,borders:t,width:i})}Batch(e,t=!0){this.batch=!0,e(),this.batch=!1;let r=this.batch_events.slice(0);return this.batch_events=[],t&&this.DelayedRender(!1),r}ScrollTo(e,t=!0,r=!0,i=!1){this.layout.ScrollTo(e,t,r,i)}ScrollIntoView(e){this.options.scrollbars&&this.layout.ScrollIntoView(e)}GetScrollOffset(){return this.layout.GetScrollOffset()}ScrollOffset(e){if(e)this.layout.scroll_offset=e;else return this.layout.scroll_offset}TranslateInternal(e,t){let r=this.parser.Parse(e);if(r.expression){let i=!1;if(this.parser.Walk(r.expression,n=>{if(n.type==="call"){let a=t[n.name.toUpperCase()];a&&(i=!0,n.name=a)}return!0}),i)return"="+this.parser.Render(r.expression,{missing:""})}return e}RenameSheetInternal(e,t){super.RenameSheetInternal(e,t),this.tab_bar?.Update()}TranslateFunction(e){return this.language_map?this.TranslateInternal(e,this.language_map):e}UntranslateFunction(e){return this.reverse_language_map?this.TranslateInternal(e,this.reverse_language_map):e}UntranslateData(e){return Array.isArray(e)?ir(e)?e.map(t=>t.map(r=>r&&typeof r=="string"&&r[0]==="="?this.UntranslateFunction(r):r)):e.map(t=>t&&typeof t=="string"&&t[0]==="="?this.UntranslateFunction(t):t):(e&&typeof e=="string"&&e[0]==="="&&(e=this.UntranslateFunction(e)),e)}StyleDefaultFromTheme(){this.model.theme_style_properties.font_face=this.theme.grid_cell?.font_face||"",this.model.theme_style_properties.font_size=this.theme.grid_cell?.font_size||{unit:"pt",value:10}}AutoSizeColumn(e,t,r=!0){if(!this.tile_renderer)return;let i=12,n=4*2;r||(i=e.GetColumnWidth(t));for(let a=0;a<e.cells.rows;a++){let s=e.CellData({row:a,column:t}),o=s.formatted||"";if(typeof o!="string"&&(o=o.map(l=>l.text).join("")),o&&o.length){let l=this.tile_renderer.MeasureText(o,U.Font(s.style||{}));i=Math.max(i,Math.ceil(l.width)+n)}}e.SetColumnWidth(t,i)}EnsureActiveSheet(e=!1){for(let t of this.model.sheets.list)if(t===this.active_sheet){e&&this.ActivateSheetInternal({key:21,id:t.id,force:!0});return}this.ActivateSheetInternal({key:21,index:0})}ActivateSheetInternal(e){let t=this.SelectingArgument(),r=this.ResolveSheet(e)||this.model.sheets.list[0];if(this.active_sheet===r&&!e.force)return;if(!r.visible)throw new Error("cannot activate hidden sheet");this.HideHoverInfo(),this.active_sheet.selection=JSON.parse(JSON.stringify(this.primary_selection)),this.active_sheet.scroll_offset=this.layout.scroll_offset;let i=this.active_sheet;this.RemoveAnnotationNodes(),this.active_sheet=r,t?this.RenderSelections():(this.ClearSelection(this.primary_selection),r.selection&&!r.selection.empty&&this.Select(this.primary_selection,new y(r.selection.area.start,r.selection.area.end),r.selection.target));let n=this.active_sheet.annotations;for(let a of n)this.AddAnnotation(a,!0);this.ActivateSheetTasks(),this.QueueLayoutUpdate(),this.pending_layout_update.has(this.active_sheet.id)?(this.Repaint(!0,!0),this.pending_layout_update.delete(this.active_sheet.id)):this.Repaint(!1,!1),this.grid_events.Publish({type:"sheet-change",deactivate:i,activate:this.active_sheet}),this.tab_bar&&this.tab_bar.Update(),this.layout.scroll_offset=this.active_sheet.scroll_offset,this.formula_bar?.selecting&&requestAnimationFrame(()=>this.formula_bar?.FocusEditor())}ActivateSheetTasks(){if(this.active_sheet.Activate(this.DOM),this.active_sheet.image&&!this.active_sheet.image.complete){let e=this.active_sheet.image,t=0,r=()=>{e.complete?this.UpdateLayout():t++<5&&setTimeout(()=>r(),10)};r()}}HighlightFreezeArea(){for(let e of[this.layout.corner_selection,this.layout.row_header_selection,this.layout.column_header_selection])e.classList.add("highlight-area"),setTimeout(()=>{e.classList.remove("highlight-area")},400)}QueueLayoutUpdate(e){this.tile_update_pending=!0,e&&(this.scroll_offset_pending=e)}HandleAddressLabelEvent(e){if(e){let t=(a="")=>{let s=a.toLowerCase();for(let o of this.model.sheets.list)if(o.name.toLowerCase()===s)return o.id;return this.active_sheet.id},r=a=>{for(let s of this.model.sheets.list)if(s.id===a)return s;return this.active_sheet},i,n=this.parser.Parse(e);if(n.expression)switch(n.expression.type){case"address":n.expression.sheet_id=t(n.expression.sheet),i=new y(n.expression);break;case"range":n.expression.start.sheet_id=t(n.expression.start.sheet),i=new y(n.expression.start,n.expression.end);break;case"identifier":i=this.model.named_ranges.Get(n.expression.name),i||this.primary_selection.empty||this.SetName(n.expression.name.toUpperCase(),this.primary_selection.area);break;default:break}if(i){let a=r(i.start.sheet_id);if(a.columns>=i.end.column&&a.rows>=i.end.row){this.ExecCommand({key:5,area:i});return}else console.warn("address out of range")}}this.UpdateAddressLabel(),this.Focus()}InitFormulaBar(e,t){this.formula_bar=new Dt(e,this.model,this.view,this.options,t),this.formula_bar.autocomplete_matcher=this.autocomplete_matcher,this.formula_bar.Subscribe(r=>{switch(r.type){case"address-label-event":this.HandleAddressLabelEvent(r.text);break;case"stop-editing":this.editing_state=0;break;case"start-editing":this.editing_state=2,this.editing_cell={...this.primary_selection.target};break;case"discard":if(this.editing_state=0,this.editing_annotation){this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection);let i=this.editing_annotation.view[this.view_index]?.node;i&&i.focus(),this.editing_annotation=void 0,this.UpdateFormulaBarFormula(),this.DelayedRender();return}this.container&&this.Focus(),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),this.UpdateFormulaBarFormula(),this.DelayedRender();break;case"commit":if(this.active_sheet.id!==this.editing_cell.sheet_id&&this.editing_cell.sheet_id&&this.ActivateSheetID(this.editing_cell.sheet_id),this.editing_state=0,this.editing_annotation){let i=this.editing_annotation;this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),i.data.formula=r.value?this.FixFormula(r.value):"";let n=this.editing_annotation.view[this.view_index]?.node;n&&n.focus(),this.grid_events.Publish({type:"annotation",event:"update",annotation:i}),this.editing_annotation=void 0,this.DelayedRender();return}this.container&&this.Focus(),this.SetInferredType(this.primary_selection,r.value,r.array),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection),this.options.repaint_on_cell_change&&this.DelayedRender(!1,this.primary_selection.area),r.event&&this.OverlayKeyDown(r.event);break;case"update":r.dependencies&&this.HighlightDependencies(r.dependencies);break}})}InitOverlayEditor(e){this.container&&(this.overlay_editor=new Mt(this.container,this.theme,this.model,this.view,e),this.overlay_editor.UpdateScale(this.layout.scale),this.overlay_editor.autocomplete_matcher=this.autocomplete_matcher,this.overlay_editor.Subscribe(t=>{switch(t.type){case"stop-editing":this.editing_state=0;break;case"start-editing":this.editing_state=1,this.editing_cell={...this.primary_selection.target};break;case"update":t.dependencies&&this.HighlightDependencies(t.dependencies);break;case"end-selection":case"reset-selection":this.ClearSelection(this.active_selection),this.overlay_editor?.target_address?.sheet_id&&this.active_sheet.id!==this.overlay_editor.target_address.sheet_id&&this.ActivateSheetID(this.overlay_editor.target_address.sheet_id),this.DelayedRender();break}}))}DelayedRender(e=!1,t,r=!1){!this.tile_update_pending&&t?this.layout.DirtyArea(t):!this.tile_update_pending&&e&&this.layout.DirtyAll(),this.render_token||(this.render_token=1,Promise.resolve().then(()=>{this.render_token=0,this.Repaint(e,r)}))}Repaint(e=!1,t=!1,r=!1){if(this.headless||!this.tile_renderer)return;if(this.tile_update_pending&&(this.tile_update_pending=!1,this.layout.UpdateTiles(),this.scroll_offset_pending&&(this.layout.scroll_offset=this.scroll_offset_pending,this.scroll_offset_pending=void 0),this.render_tiles=this.layout.VisibleTiles(),this.layout.UpdateAnnotation(this.active_sheet.annotations)),this.layout_token=0,this.tile_renderer.OverflowDirty(t),e)for(let o of this.layout.grid_tiles)for(let l of o)l.dirty=!0;let i=this.render_tiles.start,n=this.render_tiles.end,a=[];for(let o=i.row;o<=n.row;o++)a.push(o);let s=[];for(let o=i.column;o<=n.column;o++)s.push(o);i.row>0&&this.active_sheet.freeze.rows&&a.push(0),i.column>0&&this.active_sheet.freeze.columns&&s.push(0);for(let o of s)for(let l of a){let d=this.layout.grid_tiles[o][l];(e||d.dirty||d.needs_full_repaint)&&(this.tile_renderer.Render(d),d.dirty=d.needs_full_repaint=!1)}this.tile_renderer.RenderHeaders(this.render_tiles,r),this.tile_renderer.RenderCorner(),this.RenderSelections()}MouseMove_RowHeader(e){let t=this.layout.CoordinateToRowHeader(e.offsetY),r=this.layout.OffsetCellAddressToRectangle({row:t.row,column:0});this.hover_data.address&&(this.hover_data.address.row!==-1||this.hover_data.address.column!==-1)&&this.HoverCell({row:-1,column:-1});let i=-1;e.offsetY-r.top<=this.RESIZE_PIXEL_BUFFER&&t.row>0?i=t.row-1:r.bottom-e.offsetY<=this.RESIZE_PIXEL_BUFFER&&(i=t.row),i>=0?this.layout.ResizeCursor("row"):this.cell_resize.row&&(this.cell_resize.row=-1,this.layout.ResizeCursor()),this.cell_resize.row=i}MouseMove_ColumnHeader(e){let t=this.layout.CoordinateToColumnHeader(e.offsetX),r=this.layout.OffsetCellAddressToRectangle({row:0,column:t.column});this.hover_data.address&&(this.hover_data.address.row!==-1||this.hover_data.address.column!==-1)&&this.HoverCell({row:-1,column:-1});let i=-1;e.offsetX-r.left<=this.RESIZE_PIXEL_BUFFER&&t.column>0?i=t.column-1:r.right-e.offsetX<=this.RESIZE_PIXEL_BUFFER&&(i=t.column),i>=0?this.layout.ResizeCursor("column"):this.cell_resize.column&&(this.cell_resize.column=-1,this.layout.ResizeCursor()),this.cell_resize.column=i}MouseDown_RowHeader(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.layout.CoordinateToRowHeader(e.offsetY),r=this.layout.row_header_cover.getBoundingClientRect(),i={x:r.left,y:r.top};if(this.cell_resize.row>=0){let n=this.cell_resize.row,a=i.y+e.offsetY;if(this.layout.HideDropdownCaret(),this.IsDoubleClick({row:n,column:-1})){let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.rows>1&&this.primary_selection.area.start.column===1/0&&this.primary_selection.area.ContainsRow(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.row;p<=f.end.row;p++)m.push(p)}this.ExecCommand({key:3,row:m});return}let s=this.layout.RowHeight(n),o=s,l=this.layout.OffsetCellAddressToRectangle({row:n,column:0}),d=i.y+l.bottom;this.layout.ShowTooltip({left:!0,text:`${o}px`,x:Math.round(r.right+10),y:d});let h=[],u=[];for(let m of this.active_sheet.annotations){let f=l.bottom-1;if(!m.scaled_rect||m.scaled_rect.bottom<f)continue;let p=[...this.layout.GetFrozenAnnotations(m)],g=m.view[this.view_index]?.node;g&&p.push(g),f<=m.scaled_rect.top&&m.data.move_with_cells?h.push({annotation:m,y:m.scaled_rect.top,nodes:p}):f>m.scaled_rect.top&&m.data.resize_with_cells&&u.push({annotation:m,height:m.scaled_rect.height,nodes:p})}ge(this.layout.mask,"row-resize",m=>{let f=Math.max(-s,Math.round(m.offsetY-a));if(f+s!==o){o=f+s,this.layout.SetRowHeight(n,o),this.layout.UpdateTooltip({text:`${o}px`,y:d+f});for(let{annotation:p,y:g}of h)p.scaled_rect&&(p.scaled_rect.top=g+f);for(let{annotation:p,height:g}of u)p.scaled_rect&&(p.scaled_rect.height=g+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:g}of u)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);for(let{annotation:p,nodes:g}of h)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);this.layout.UpdateTileHeights(!0,n),this.Repaint(!1,!0),this.layout.UpdateAnnotation(this.active_sheet.annotations)})}},()=>{this.layout.HideTooltip(),requestAnimationFrame(()=>{let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.rows>1&&this.primary_selection.area.start.column===1/0&&this.primary_selection.area.ContainsRow(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.row;p<=f.end.row;p++)m.push(p)}this.layout.SetRowHeight(n,s),this.ExecCommand({key:3,row:m,height:o/this.scale});for(let{annotation:f}of h)f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));for(let{annotation:f}of u){f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));let p=f.view[this.view_index];p&&p.resize_callback&&p.resize_callback.call(void 0)}})})}else{let n=this.SelectingArgument()?this.active_selection:this.primary_selection;if(this.SelectingArgument()||this.Focus(),e.shiftKey&&!n.empty){let a=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=a}else this.Select(n,new y(t),{column:0,row:t.row});this.RenderSelections(),ge(this.layout.mask,[],a=>{let s=this.layout.CoordinateToRowHeader(a.offsetY-i.y),o=new y(s,t,!0);(n.empty||!o.Equals(n.area))&&(this.Select(n,o,void 0,!0),this.RenderSelections())},()=>{})}}MouseDown_ColumnHeader(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.layout.CoordinateToColumnHeader(e.offsetX),r=this.layout.column_header_cover.getBoundingClientRect(),i={x:r.left,y:r.top};if(this.cell_resize.column>=0){let n=this.cell_resize.column,a=i.x+e.offsetX;if(this.layout.HideDropdownCaret(),this.IsDoubleClick({row:-1,column:n})){let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.columns>1&&this.primary_selection.area.start.row===1/0&&this.primary_selection.area.ContainsColumn(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);m=[];for(let p=f.start.column;p<=f.end.column;p++)m.push(p)}this.ExecCommand({key:4,column:m});return}let s=this.layout.ColumnWidth(n),o=s,l=this.layout.OffsetCellAddressToRectangle({row:0,column:n}),d=i.x+l.right;this.layout.ShowTooltip({up:!0,text:`${o}px`,x:d,y:Math.round(r.bottom+10)});let h=[],u=[];for(let m of this.active_sheet.annotations){let f=l.right-1;if(!m.scaled_rect||m.scaled_rect.right<f)continue;let p=[...this.layout.GetFrozenAnnotations(m)],g=m.view[this.view_index]?.node;g&&p.push(g),f<=m.scaled_rect.left&&m.data.move_with_cells?h.push({annotation:m,x:m.scaled_rect.left,nodes:p}):f>m.scaled_rect.left&&m.data.resize_with_cells&&u.push({annotation:m,width:m.scaled_rect.width,nodes:p})}ge(this.layout.mask,"column-resize",m=>{let f=Math.max(-s,Math.round(m.offsetX-a));if(f+s!==o){o=f+s,this.layout.UpdateTooltip({text:`${o}px`,x:d+f}),this.layout.SetColumnWidth(n,o);for(let{annotation:p,x:g}of h)p.scaled_rect&&(p.scaled_rect.left=g+f);for(let{annotation:p,width:g}of u)p.scaled_rect&&(p.scaled_rect.width=g+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:g}of u)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);for(let{annotation:p,nodes:g}of h)if(p.scaled_rect)for(let b of g)p.scaled_rect.ApplyStyle(b);this.layout.UpdateTileWidths(!0,n),this.Repaint(!1,!0)})}},()=>{this.layout.HideTooltip(),requestAnimationFrame(()=>{let m=[n];if(!this.primary_selection.empty&&this.primary_selection.area.columns>1&&this.primary_selection.area.start.row===1/0&&this.primary_selection.area.ContainsColumn(n)){let f=this.active_sheet.RealArea(this.primary_selection.area);for(let p=f.start.column;p<=f.end.column;p++)m.push(p)}this.ExecCommand({key:4,column:m,width:o/this.scale});for(let{annotation:f}of h)f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));for(let{annotation:f}of u){f.scaled_rect&&(f.data.layout=this.layout.RectToAnnotationLayout(f.scaled_rect));let p=f.view[this.view_index];p&&p.resize_callback&&p.resize_callback.call(void 0)}})})}else{let n=this.SelectingArgument()?this.active_selection:this.primary_selection;if(this.SelectingArgument()||this.Focus(),e.shiftKey&&!n.empty){let a=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=a}else this.Select(n,new y(t),{row:0,column:t.column});this.RenderSelections(),ge(this.layout.mask,[],a=>{let s=this.layout.CoordinateToColumnHeader(a.offsetX-i.x),o=new y(s,t,!0);(n.empty||!o.Equals(n.area))&&(this.Select(n,o,void 0,!0),this.RenderSelections())})}}HoverCell(e,t){let r=this.active_sheet.cells.GetCell(e,!1);if(r?.table&&r.table.area.start.row===e.row&&r.table.sortable!==!1?(this.hover_data.table_header=!0,this.layout.ShowTableSortButton(r.table,e.column-r.table.area.start.column,e)):(this.hover_data.table_header&&this.layout.HideTableSortButton(),this.hover_data.table_header=!1),r?.merge_area){let i=r.merge_area;e=i.start,r=this.active_sheet.cells.GetCell(e,!1),e={row:i.start.row,column:i.end.column}}if(r?.note){let i=this.options.markdown?Re.instance.HTML(Re.instance.Parse(r.note)):void 0;this.layout.ShowNote(r.note,e,t,i),this.hover_data.note=!0}else this.hover_data.note&&(this.layout.HideNote(),this.hover_data.note=!1);r?.hyperlink?(this.layout.ShowTitle("Link: "+r.hyperlink,e),this.hover_data.link=!0,this.hover_data.cell=r):this.hover_data.link&&(this.layout.HideTitle(),this.hover_data.cell=void 0),this.hover_data.address={...e}}HideHoverInfo(){this.layout.HideTitle(),this.layout.HideTooltip(),this.hover_data.note=this.hover_data.link=!1,this.hover_data.cell=void 0,this.hover_data.pointer&&this.layout.grid_cover.classList.remove("link-pointer"),this.hover_data.pointer=!1}MouseMove_Grid(e){if(e.stopPropagation(),e.preventDefault(),!this.selection_renderer)return;(this.cell_resize.row>=0||this.cell_resize.column>=0)&&this.layout.ResizeCursor();let t={x:e.offsetX,y:e.offsetY},r;if(this.overlay_editor?.editing||(r=this.layout.PointToAddress_Grid(t),(!this.hover_data.address||this.hover_data.address.row!==r.row||this.hover_data.address.column!==r.column)&&this.HoverCell(r,e)),this.hover_data.link&&r&&(this.hover_data.point=t,this.hover_data.handler||(this.hover_data.handler=requestAnimationFrame(()=>{let n=this.hover_data.address&&this.hover_data.point&&this.hover_data.cell&&this.PointInTextPart(this.hover_data.address,this.hover_data.point,this.hover_data.cell);n!==!!this.hover_data.pointer&&(this.hover_data.pointer=n,n?this.layout.grid_cover.classList.add("link-pointer"):this.layout.grid_cover.classList.remove("link-pointer")),this.hover_data.handler=void 0}))),this.primary_selection.empty||!this.selection_renderer.nub_rectangle){this.nub_select_flag&&(this.layout.grid_cover.classList.remove("nub-select"),this.nub_select_flag=!1);return}let i=this.selection_renderer.nub_rectangle.Contains(e.offsetX,e.offsetY);i!==this.nub_select_flag&&(i?this.layout.grid_cover.classList.add("nub-select"):this.layout.grid_cover.classList.remove("nub-select"),this.nub_select_flag=i)}ClearDoubleClick(){this.double_click_data.address=void 0}IsDoubleClick(e,t=300){if(this.double_click_data.address&&this.double_click_data.address.row===e.row&&this.double_click_data.address.column===e.column)return clearTimeout(this.double_click_data.timeout),this.double_click_data.address=void 0,this.double_click_data.timeout=void 0,!0;this.double_click_data.timeout&&clearTimeout(this.double_click_data.timeout),this.double_click_data.address={...e},this.double_click_data.timeout=window.setTimeout(()=>{this.double_click_data.address=void 0,this.double_click_data.timeout=void 0},t)}PointInTextPart(e,t,r){let i=this.layout.CellAddressToRectangle(e);r.merge_area&&(i=i.Combine(this.layout.CellAddressToRectangle(r.merge_area.end)));let n=t.x-i.left,a=t.y-i.top,s=r.renderer_data?.text_data?.strings||[];for(let o of s)for(let l of o)if(typeof l.left=="number"&&typeof l.top=="number"&&typeof l.width=="number"&&typeof l.height=="number"&&n>=l.left&&a>=l.top&&n<=l.left+l.width&&a<=l.top+l.height)return!0;return!1}MouseDown_Grid(e){if(e.button!==0)return;e.stopPropagation(),e.preventDefault();let t=this.SelectingArgument();!t&&this.additional_selections.length&&this.ClearAdditionalSelections(),(!t||!this.formula_bar?.selecting&&!this.external_editor?.selecting)&&this.Focus(),this.overlay_editor?.editing&&!this.overlay_editor?.selecting&&this.DismissEditor();let r={x:e.offsetX,y:e.offsetY},i=this.layout.PointToAddress_Grid(r),n=t?this.active_selection:this.primary_selection;if(!t&&this.IsDoubleClick(i)){re.is_mobile&&this.overlay_editor?.edit_node?.focus(),this.OverlayEditCell({target:i,area:new y(i)},!1);return}let a=this.layout.grid_cover.getBoundingClientRect(),s={x:a.left,y:a.top},o=[],l;if(e.shiftKey&&!n.empty){let h=n.target;this.Select(n,new y(i,n.target,!0),void 0,!0),i=h}else if(this.nub_select_flag)i=n.area.TopLeft(),o.push("nub-select"),l=this.active_sheet.RealArea(n.area);else{let h=i,u=this.active_sheet.CellData(h);if(u.merge_area&&(h=u.merge_area.start,u=this.active_sheet.CellData(u.merge_area.start)),u.hyperlink&&this.PointInTextPart(h,r,u)){let m=u.hyperlink;Promise.resolve().then(()=>{this.grid_events.Publish({type:"cell-event",data:{type:"hyperlink",data:m}})}),this.ClearDoubleClick();return}if(u.click_function){let m=this.layout.CellAddressToRectangle(h);u.merge_area&&(m=m.Combine(this.layout.CellAddressToRectangle(u.merge_area.end)));let f=u.click_function.call(this,{cell:u,x:r.x-m.left,y:r.y-m.top,width:m.width,height:m.height,scale:this.layout.scale});if(f.value&&this.ExecCommand({key:6,value:f.value,area:h}),f.block_selection){this.ClearDoubleClick(),!this.primary_selection.empty&&this.primary_selection.target.row===h.row&&this.primary_selection.target.column===h.column&&this.UpdateFormulaBarFormula();return}}this.Select(n,new y(i),i)}this.RenderSelections(),t&&this.UpdateSelectedArgument(n);let d=this.layout.CellAddressToRectangle({row:0,column:0}).Combine(this.layout.CellAddressToRectangle({row:this.active_sheet.rows-1,column:this.active_sheet.columns-1})).Expand(-1,-1);ge(this.layout.mask,o,h=>{let u={x:h.offsetX-s.x,y:h.offsetY-s.y},m=d.Clamp(u.x,u.y),f=this.layout.PointToAddress_Grid(m,!0),p=this.layout.scroll_reference_node,g=!1;this.container&&this.options.scrollbars&&(u.x<p.scrollLeft?(p.scrollLeft-=25,g=!0):u.x>p.scrollLeft+this.container.clientWidth&&(p.scrollLeft+=25,g=!0),u.y<p.scrollTop?(p.scrollTop-=25,g=!0):u.y>p.scrollTop+this.container.clientHeight&&(p.scrollTop+=25,g=!0),g&&(a=this.layout.grid_cover.getBoundingClientRect(),s.x=a.left+document.body.scrollLeft,s.y=a.top+document.body.scrollTop));let b=new y(f,i,!0);if(l&&(b=l.Clone(),b.ConsumeAddress(f),b.rows!==l.rows&&b.columns!==l.columns)){let v={rows:f.row>l.end.row?f.row-l.end.row:l.start.row-f.row,columns:f.column>l.end.column?f.column-l.end.column:l.start.column-f.column};v.rows>=v.columns?b=new y({row:b.start.row,column:l.start.column},{row:b.end.row,column:l.end.column}):b=new y({row:l.start.row,column:b.start.column},{row:l.end.row,column:b.end.column})}(n.empty||!b.Equals(n.area))&&(this.Select(n,b,void 0,!0),this.RenderSelections(),t?this.UpdateSelectedArgument(n):!n.empty&&!n.area.entire_sheet&&(n.area.entire_column?this.UpdateAddressLabel(void 0,n.area.columns+"C"):n.area.entire_row?this.UpdateAddressLabel(void 0,n.area.rows+"R"):n.area.count>1?this.UpdateAddressLabel(void 0,n.area.rows+"R x "+n.area.columns+"C"):this.UpdateAddressLabel(n)))},()=>{this.UpdateAddressLabel(),t?this.overlay_editor?.editing||(this.external_editor_config?(this.external_editor?.active&&this.external_editor.FocusEditor(),this.external_editor_config.update):this.formula_bar&&this.formula_bar.FocusEditor()):l&&this.RecycleNubArea(n.area,l)})}Transpose(e){let t=[],r=e.length,i=e[0].length;for(let n=0;n<i;n++){t[n]=[];for(let a=0;a<r;a++)t[n][a]=e[a][n]}return t}RecycleNubArea(e,t){if(e.Equals(t))return;let r=[];for(let h=0;h<t.rows;h++){r[h]=[];for(let u=0;u<t.columns;u++){let m={row:t.start.row+h,column:t.start.column+u};r[h][u]=this.active_sheet.CellData(m)}}if(r[0][0].area&&r[0][0].area.Equals(t)){this.ExecCommand({key:6,value:r[0][0].value,array:!0,area:e});return}if(r[0][0].table&&t.Equals(new y(r[0][0].table.area.start,r[0][0].table.area.end))){let h=r[0][0].table,u=h.sortable,m=h.totals_row,f=h.theme;this.ExecCommand([{key:29,table:h},{key:28,area:e,sortable:u,totals:m,theme:f}]);return}let i=[],n=[],a=t.columns,s=e.rows,o=!1,l=!1;e.columns===t.columns?o=e.start.row<t.start.row:(a=t.rows,s=e.columns,o=e.start.column<t.start.column,r=this.Transpose(r),l=!0);for(let h=0;h<s;h++)i[h]=[],n[h]=[];for(let h=0;h<a;h++){let u=0;if(r.length>1){u=1;let m=[],f=[];for(let p=0;p<r.length;p++){let g=r[p][h];g.ValueIsNumber()&&(f.push(p),m.push(g.value))}if(m.length>1){let p=m.slice(1).map((g,b)=>g-m[b]);p.every(g=>g===p[0])&&(u=p[0])}m.length&&(u+=m[m.length-1]-m[0])}for(let m=0;m<r.length;m++){let f,p=r[m][h];if(p.ValueIsFormula()){let x=this.parser.Parse(p.value);x.expression&&x.full_reference_list?.length&&(f=x.expression)}let g=0,b=m,v=r.length,_=0,w=u;o&&(b=s-r.length+m,v=-r.length,w=-u);for(let x=b;x>=0&&x<s;x+=v,g+=v,_+=w){if(f)i[x][h]="="+this.parser.Render(f,{offset:{rows:g,columns:0}});else{let A=r[m][h];A.ValueIsNumber()?i[x][h]=A.value+_:i[x][h]=A.value}n[x][h]=r[m][h].style||{}}}}let d=[{key:6,value:l?this.Transpose(i):i,array:!1,area:e}];l&&(n=this.Transpose(n));for(let h=0;h<n.length;h++)for(let u=0;u<n[h].length;u++)d.push({key:7,area:{row:h+e.start.row,column:u+e.start.column},style:n[h][u],delta:!1});this.ExecCommand(d)}UpdateSelectedArgument(e){let t=this.active_sheet.CellData(e.area.start),r=new y(t.merge_area?t.merge_area.start:e.target),i=this.model.named_ranges.MatchSelection(e.area,r);if(!i&&(i=e.area.spreadsheet_label,t.merge_area&&t.merge_area.Equals(e.area)&&(i=y.CellAddressToLabel(t.merge_area.start)),this.external_editor_config||this.active_sheet.id!==this.editing_cell.sheet_id)){let n=this.active_sheet.name;ze.test(n)?i=`'${n}'!${i}`:i=`${n}!${i}`}if(this.overlay_editor?.editing&&this.overlay_editor.selecting)this.overlay_editor.InsertReference(i,0);else if(this.formula_bar&&this.formula_bar.selecting)this.formula_bar.InsertReference(i,0);else if(this.external_editor_config&&(this.external_editor?.active&&(this.external_editor.FocusEditor(),this.external_editor.InsertReference(i,0)),this.external_editor_config.update)){let n=this.external_editor_config.update.call(0,i);n&&Array.isArray(n)&&this.HighlightDependencies(n.filter(a=>!!a).map(a=>N(a)?new y(a):new y(a.start,a.end)))}}SelectingArgument(){return this.overlay_editor?.editing&&this.overlay_editor?.selecting||this.formula_bar&&this.formula_bar.selecting||!!this.external_editor_config}OverlayKeyDown(e){let t=!1;if(this.overlay_editor&&this.overlay_editor.editing)switch(t=!0,this.overlay_editor.HandleKeyDown(e)){case"handled":return;case"discard":this.editing_state=0,this.DismissEditor(),this.DelayedRender();return;case"commit":if(this.active_sheet.id!==this.editing_cell.sheet_id&&this.editing_cell.sheet_id&&this.ActivateSheetID(this.editing_cell.sheet_id),this.editing_state=0,this.overlay_editor?.selection){let l=this.overlay_editor?.edit_node.textContent||void 0,d=e.key==="Enter"&&e.ctrlKey&&e.shiftKey;this.SetInferredType(this.overlay_editor.selection,l,d)}this.DismissEditor(),this.options.repaint_on_cell_change&&this.DelayedRender(!1,this.overlay_editor?.selection.area||void 0);break}let r=this.SelectingArgument();if(this.formula_bar&&this.formula_bar.focused&&!r||this.selected_annotation&&!r)return;let i=r?this.active_selection:this.primary_selection,n={rows:0,columns:0},a=!1,s=!1;if(e.ctrlKey||re.is_mac&&e.metaKey){switch(e.key){case"ArrowDown":case"Down":n.rows++;break;case"ArrowUp":case"Up":n.rows--;break;case"ArrowLeft":case"Left":n.columns--;break;case"ArrowRight":case"Right":n.columns++;break;case"Delete":case"Del":{e.stopPropagation(),e.preventDefault();for(let o=0;o<this.model.sheets.length;o++)if(this.model.sheets.list[o]===this.active_sheet){this.DeleteSheet(o);break}return}break;case"/":e.stopPropagation(),e.preventDefault(),this.SelectArrayOrTable();break;default:if(e.shiftKey)return}if(n.columns||n.rows)if(e.stopPropagation(),e.preventDefault(),!i.empty&&(n.columns||n.rows)){if(this.BlockSelection(i,!!e.shiftKey,n.columns,n.rows))return}else return;else{let o={},l=this.primary_selection.empty?{}:this.active_sheet.CellData(this.primary_selection.target).style||{};switch(e.key.toLowerCase()){case"b":o.bold=!l.bold;break;case"i":o.italic=!l.italic;break;case"u":o.underline=!l.underline;break;case"a":this.SelectAll();break;case"0":if(!e.altKey)return;this.ClearSelection(this.primary_selection),this.RenderSelections();break;default:e.key;return}Object.keys(o).length&&this.ApplyStyle(void 0,o)}}else switch(e.key){case"Tab":e.shiftKey?n.columns--:n.columns++,a=!0;break;case"Enter":e.shiftKey?n.rows--:n.rows++,a=!0;break;case"ArrowDown":case"Down":n.rows++,s=e.shiftKey;break;case"ArrowUp":case"Up":n.rows--,s=e.shiftKey;break;case"ArrowLeft":case"Left":n.columns--,s=e.shiftKey;break;case"ArrowRight":case"Right":n.columns++,s=e.shiftKey;break;case"Delete":case"Del":i.empty||this.DeleteSelection(i);break;case"PageUp":case"PageDown":if(e.shiftKey){this.NextSheet(e.key==="PageUp"?-1:1);break}return;case"Control":case"Shift":case"Alt":return;default:i.empty||e.key!=="Escape"&&this.OverlayEditCell(i,!0,e);return}e.stopPropagation(),e.preventDefault(),(n.rows||n.columns)&&this.AdvanceSelection(n,i,a,s,!t)}SelectArrayOrTable(){if(this.primary_selection.empty)return;let e=this.active_sheet.CellData(this.primary_selection.target);if(!(!e||!e.area&&!e.table)){if(e.area&&this.Select(this.primary_selection,e.area,e.area.start),e.table){let t=new y(e.table.area.start,e.table.area.end);this.Select(this.primary_selection,t,t.start)}this.RenderSelections()}}RenderSelections(e=!0){let t=this.hide_selection?!1:!this.editing_state||this.editing_cell.sheet_id===this.active_sheet.id;this.selection_renderer?.RenderSelections(t,e)}BlockSelection(e,t,r,i,n=!0){if(e.empty)return!1;let a={...e.target};i>0?a.row=Math.max(a.row,e.area.end.row):i<0&&(a.row=Math.min(a.row,e.area.start.row)),r>0?a.column=Math.max(a.column,e.area.end.column):r<0&&(a.column=Math.min(a.column,e.area.start.column));let s=this.active_sheet.cells,o=s.GetCell(e.target,!1);if(!o||o.type===0&&!o.area)return!1;let l={...a};for(;;){let d={row:l.row+i,column:l.column+r};if(d.column<0||d.row<0||d.column>=this.active_sheet.columns||d.row>=this.active_sheet.rows)break;let h=!1;if(i)for(let u=e.area.start.column;!h&&u<=e.area.end.column;u++)o=s.GetCell({row:d.row,column:u},!1),h=h||!!o&&(o.type!==0||!!o.area),!h&&o&&o.merge_area&&(o=s.GetCell(o.merge_area.start,!1),h=h||!!o&&(o.type!==0||!!o.area));else for(let u=e.area.start.row;!h&&u<=e.area.end.row;u++)o=s.GetCell({row:u,column:d.column},!1),h=h||!!o&&(o.type!==0||!!o.area),!h&&o&&o.merge_area&&(o=s.GetCell(o.merge_area.start,!1),h=h||!!o&&(o.type!==0||!!o.area));if(!h)break;l=d}if(t){i?(a.row=e.target.row,a.column=e.area.start.column,l.column=e.area.end.column):(a.column=e.target.column,a.row=e.area.start.row,l.row=e.area.end.row);let d=new y(a,l,!0);this.Select(e,d,e.target,!0)}else this.Select(e,new y(l));return this.ScrollIntoView(l),this.SelectingArgument()&&this.UpdateSelectedArgument(e),n&&this.DelayedRender(),!0}DeleteSelection(e){if(e.empty)return;let t=this.active_sheet.RealArea(e.area);this.ExecCommand({key:11,area:t})}SetInferredType(e,t,r=!1,i=!0){let n=e.target||e.area.start,a=this.active_sheet.CellData(n);if(a.area){if(!r&&a.area.count>1||!e.area||!e.area.Equals(a.area)){this.Error(2);return}}else if(r){let h=!1;if(this.active_sheet.cells.Apply(e.area,u=>{u.area&&(h=!0)},!1),h){this.Error(2);return}}if(a.validation&&a.validation.error){let h;if(a.validation.type==="list"?h=a.validation.list:a.validation.type==="range"&&(h=this.GetValidationRange(a.validation.area)),h&&h.length){let u=!1;if(t){let m=t.toUpperCase();for(let f of h)if(f&&f.toString().toUpperCase()===m){t=f.toString(),u=!0;break}}if(!u){this.Error(3);return}}}a.merge_area&&(n=a.merge_area.start);let s=typeof t=="string"&&t.trim()[0]==="=",o=[];if(s&&(t=this.FixFormula(t||""),!this.active_sheet.HasCellStyle(n))){let h=this.parser.Parse(t);if(h){if(h.expression?.type==="call"&&(!a.style||!a.style.number_format||I.Equals(a.style.number_format,"General"))){let u=h.expression.name.toLowerCase(),m;switch(u){case"today":m="Short Date";break;case"now":m="Timestamp";break}m&&o.push({key:7,area:r?e.area:n,style:{number_format:m},delta:!0})}if(h.dependencies){let u,m=h.dependencies;for(let f of Object.keys(m.addresses)){let p=m.addresses[f];if(this.active_sheet.HasCellStyle({...p})){let g=this.active_sheet.CellData({...p});if(g.style&&g.style.number_format&&(!u||/%/.test(u))&&(u=I.Translate(g.style.number_format),!/%/.test(u)))break}}if(u){let f={number_format:I.SymbolicName(u)||u};o.push({key:7,area:r?e.area:n,style:f,delta:!0})}}}}let l=this.parser.Parse(t||"").expression;l?.type==="group"&&l.elements.length===1&&l.elements[0].type==="complex"&&(l=l.elements[0]);let d=l&&l.type==="complex"?{type:7,value:{real:l.real,imaginary:l.imaginary}}:be.TryParse(t);if(!s&&d.type===3){let h="",u=d.hints||{};(!a.style||!a.style.number_format||I.Equals(a.style.number_format,"General"))&&(u.Date?h="Short Date":u.Exponential?h="Exponential":u.Percent?h="Percent":u.Currency?h="Currency":(u.Grouping||u.Parens)&&(h="Accounting")),h&&o.push({key:7,area:r?e.area:n,style:{number_format:h},delta:!0})}if(o.push({key:6,area:r?e.area:n,array:r,value:s?this.UntranslateFunction(t||""):d.value}),i)this.ExecCommand(o);else return o}FixFormula(e){if(e.trim()[0]!=="=")return e;e=e.replace(/^\s+/,"");let t=!1,r=!1,i=0,n=!1,a=e.length;for(let s=0;s<a;s++){let o=e[s];if(!n)switch(o){case'"':t?e[s+1]==='"'?s++:t=!1:r||(t=!0);break;case"'":r?r=!1:t||(r=!0);break;case"\\":n=!0;break;case"(":!t&&!r&&i++;break;case")":!t&&!r&&i--;break}}for(t?e+='"':r&&(e+="'");i>0;)e+=")",i--;return e=this.NormalizeFormula(e),e}NormalizeFormula(e){let t=this.parser.Parse(e);return t.error&&console.warn(t.error),t&&t.expression&&(this.parser.Walk(t.expression,r=>{switch(r.type){case"call":r.name=this.autocomplete_matcher.NormalizeIdentifier(r.name)||r.name;break;case"identifier":this.model.named_ranges.Get(r.name)&&(r.name=r.name.toUpperCase());break}return!0}),e="="+this.parser.Render(t.expression,{missing:""})),e}DismissEditor(){this.overlay_editor?.active_cell&&(this.overlay_editor.active_cell.editing=!1,this.overlay_editor.active_cell.render_clean=[],this.DelayedRender(void 0,this.overlay_editor.selection.area)),this.editing_state=0,this.Focus(),this.overlay_editor?.CloseEditor(),this.ClearAdditionalSelections(),this.ClearSelection(this.active_selection)}NormalizeCellValue(e){let t=e.value;if(e.ValueIsNumber()&&e.style&&e.style.number_format)if(I.Get(e.style.number_format).date_format){let i=De(e.value),n=i.getUTCHours()||i.getUTCMinutes()||i.getUTCSeconds()?"Timestamp":"Short Date";t=I.Get(n).Format(t)}else if(/(?:%|percent)/i.test(e.style.number_format)){let i=0,n=e.value.toString().match(/\.(.*?)$/);n&&n[1]&&(i=Math.max(0,n[1].length-2)),t=(e.value*100).toFixed(i)+"%",D.decimal_separator===","&&(t=t.replace(/\./,","))}else t&&D.decimal_separator===","&&(t=e.value.toString().replace(/\./,","));else{if(e.ValueIsBoolean())return e.value.toString().toUpperCase();e.ValueIsNumber()?t&&D.decimal_separator===","&&(t=e.value.toString().replace(/\./,",")):e.ValueIsComplex()?(e.value.imaginary?e.value.real?t=`${e.value.real.toString()}${e.value.imaginary<0?" - ":" + "}${e.value.imaginary===1||e.value.imaginary===-1?"":Math.abs(e.value.imaginary).toString()}i`:e.value.imaginary===1?t="i":e.value.imaginary===-1?t="-i":t=e.value.imaginary.toString()+"i":t=e.value.real.toString(),D.decimal_separator===","&&(t=t.replace(/\./,","))):e.ValueIsFormula()&&(t=this.TranslateFunction(e.value))}return t}IsNumeric(e){return e>=48&&e<=57||e===this.decimal_separator_code||e===45||e===43}OverlayEditCell(e,t=!0,r){if(!this.options.in_cell_editor)return;let i=e.target||e.area.start,n=this.active_sheet.CellData(i),a;if(this.HideHoverInfo(),n.merge_area?(a=this.layout.OffsetCellAddressToRectangle(n.merge_area.start).Combine(this.layout.OffsetCellAddressToRectangle(n.merge_area.end)),i=n.merge_area.start,n=this.active_sheet.CellData(i)):a=this.layout.OffsetCellAddressToRectangle(i),n.style?.locked){console.info("cell is locked for editing");return}a=a.Shift(this.layout.header_size.width,this.layout.header_size.height);let s=n.value;t?(n.type===3||n.rendered_type===3)&&n.style&&n.style.number_format&&/(?:%|percent)/i.test(n.style.number_format)&&(!r||this.IsNumeric(r.key.charCodeAt(0)))?s="%":s=void 0:s=this.NormalizeCellValue(n),this.overlay_editor?.Edit(e,a.Expand(-1,-1),n,s,r),n.editing=!0,n.render_clean=[],this.DelayedRender(!1,e.area)}BoundAddressArea(e,t){e.column>t.end.column?(e.row=this.StepVisibleRows(e.row,1),e.row>t.end.row&&(e.row=t.start.row),e.column=t.start.column):e.column<t.start.column?(e.row=this.StepVisibleRows(e.row,-1),e.row<t.start.row&&(e.row=t.end.row),e.column=t.end.column):e.row>t.end.row?(e.column=this.StepVisibleColumns(e.column,1),e.column>t.end.column&&(e.column=t.start.column),e.row=t.start.row):e.row<t.start.row&&(e.column=this.StepVisibleColumns(e.column,-1),e.column<t.start.column&&(e.column=t.end.column),e.row=t.end.row)}StepVisibleRows(e,t){if(t>0)for(let r=0;r<t;r++)this.layout.RowHeight(++e)||r--;else if(t<0)for(let r=0;r>t;r--)--e>=0&&!this.layout.RowHeight(e)&&r++;return e}StepVisibleColumns(e,t){if(t>0)for(let r=0;r<t;r++)this.layout.ColumnWidth(++e)||r--;else if(t<0)for(let r=0;r>t;r--)--e>=0&&!this.layout.ColumnWidth(e)&&r++;return e}EnsureAddress(e,t=8){let r=!1;if(this.options.expand){if(e.row!==1/0&&e.row>=this.active_sheet.rows){let i=this.active_sheet.rows;for(;e.row>=i;)i+=t;this.active_sheet.cells.EnsureRow(i),r=!0}if(e.column!==1/0&&e.column>=this.active_sheet.columns){let i=this.active_sheet.columns;for(;e.column>=i;)i+=t;this.active_sheet.cells.EnsureColumn(i),r=!0}r&&(this.layout.UpdateTiles(),this.layout.UpdateContentsSize(),this.Repaint(!0,!0))}return r}AdvanceSelection(e,t,r=!1,i=!1,n=!0){let a=this.SelectingArgument();if(t.empty)if(a){let s={row:Math.max(0,this.StepVisibleRows(this.primary_selection.target.row,e.rows)),column:Math.max(0,this.StepVisibleColumns(this.primary_selection.target.column,e.columns))};this.Select(t,new y(s))}else this.Select(t,new y({row:0,column:0}));else{let s=this.active_sheet.CellData(t.target);if(s.merge_area&&r&&(r=!s.merge_area.Equals(t.area)),r&&t.area.count>1){let o=this.active_sheet.RealArea(t.area),l=t.target;for(;;){l.row=this.StepVisibleRows(l.row,e.rows),l.column=this.StepVisibleColumns(l.column,e.columns),this.BoundAddressArea(l,o);let d=this.active_sheet.CellData(l);if(!d.merge_area||d.merge_area.start.row===l.row&&d.merge_area.start.column===l.column)break}this.Select(t,o,l)}else if(i&&t&&t.target){let o=t.area,l=t.target,d=o.start,h=o.end,u={row:1/0,column:1/0};if(e.columns&&(o.columns===1?e.columns>0?(h.column=this.StepVisibleColumns(h.column,1),u.column=h.column):(d.column=this.StepVisibleColumns(d.column,-1),u.column=d.column):o.end.column>l.column?(h.column=this.StepVisibleColumns(h.column,e.columns),u.column=h.column):o.start.column<l.column&&(d.column=this.StepVisibleColumns(d.column,e.columns),u.column=d.column),h.column=Math.max(0,h.column),d.column=Math.max(0,d.column)),e.rows&&(o.rows===1?e.rows>0?(h.row=this.StepVisibleRows(h.row,1),u.row=h.row):(d.row=this.StepVisibleRows(d.row,-1),u.row=d.row):o.end.row>l.row?(h.row=this.StepVisibleRows(h.row,e.rows),u.row=h.row):o.start.row<l.row&&(d.row=this.StepVisibleRows(d.row,e.rows),u.row=d.row),h.row=Math.max(0,h.row),d.row=Math.max(0,d.row)),this.options.expand){for(let m of[d,h,u])m.row!==1/0&&(m.row=Math.max(0,m.row)),m.column!==1/0&&(m.column=Math.max(0,m.column));this.EnsureAddress(h)&&(n=!0),this.ScrollIntoView(u),this.Select(t,new y(d,h),void 0,!0)}else{for(let m of[d,h,u])m.row!==1/0&&(m.row=Math.max(0,Math.min(m.row,this.active_sheet.rows-1))),m.column!==1/0&&(m.column=Math.max(0,Math.min(m.column,this.active_sheet.columns-1)));this.ScrollIntoView(u),this.Select(t,new y(d,h),void 0,!0)}}else{let o=t.target;s.merge_area?(e.columns<0?o.column=this.StepVisibleColumns(s.merge_area.start.column,-1):e.columns>0&&(o.column=this.StepVisibleColumns(s.merge_area.end.column,1)),e.rows<0?o.row=this.StepVisibleRows(s.merge_area.start.row,-1):e.rows>0&&(o.row=this.StepVisibleRows(s.merge_area.end.row,1))):(o.row=this.StepVisibleRows(o.row,e.rows),o.column=this.StepVisibleColumns(o.column,e.columns)),this.EnsureAddress(o)&&(n=!0),this.Select(t,new y({row:Math.min(Math.max(0,o.row),this.active_sheet.rows-1),column:Math.min(Math.max(0,o.column),this.active_sheet.columns-1)})),this.RenderSelections(),this.ScrollIntoView(t.target)}}this.SelectingArgument()&&this.UpdateSelectedArgument(t),n&&this.DelayedRender()}HighlightDependencies(e,t=!0){let r=0;e:for(let i of e)if((i.start.row===1/0||i.start.row<this.active_sheet.rows)&&(i.start.column===1/0||i.start.column<this.active_sheet.columns)){i=this.active_sheet.RealArea(i);let n=i.spreadsheet_label;if(this.additional_selections[r]&&this.additional_selections[r].area.spreadsheet_label===n)r++;else{for(let a=0;a<r;a++)if(this.additional_selections[a].area.spreadsheet_label===n&&this.additional_selections[a].area.start.sheet_id===i.start.sheet_id)continue e;this.additional_selections[r++]={target:i.start,area:i}}}this.additional_selections.splice(r),t&&this.RenderSelections(!1)}ClearAdditionalSelections(){this.additional_selections.splice(0,this.additional_selections.length)}ClearSelection(e){this.Select(e)}HideGridSelection(){this.UpdateAddressLabel(void 0,"");let e=this.selected_annotation&&this.selected_annotation.data.formula?this.selected_annotation.data.formula:"";this.UpdateFormulaBarFormula(e),this.layout.ShowSelections(!1)}ShowGridSelection(){this.UpdateAddressLabel(),this.UpdateFormulaBarFormula(),this.layout.ShowSelections(!0)}Select(e,t,r,i=!1){if(e.empty||i&&(r=e.target),t){let n=this.active_sheet.RealArea(t);r||(r=n.start);let a=!0;for(;a;)a=!1,this.active_sheet.cells.Apply(n,l=>{l.merge_area&&!n.ContainsArea(l.merge_area)&&(t.ConsumeArea(l.merge_area),n=this.active_sheet.RealArea(t),a=!0)});e.area=new y({...t.start,sheet_id:this.active_sheet.id},t.end),r&&(e.target={...r,sheet_id:this.active_sheet.id}),e.empty=!1;let s=this.active_sheet.CellData(e.target),o="";s.formatted&&(typeof s.formatted=="string"?o=s.formatted:o=s.formatted.map(l=>l.flag===1||l.flag===6?"":l.text).join("")),this.overlay_editor?.UpdateCaption(o)}else e.empty=!0;e===this.primary_selection&&(re.is_edge&&this.Focus(),this.grid_events.Publish({type:"selection",selection:this.primary_selection}),this.UpdateAddressLabel(),this.UpdateFormulaBarFormula(),this.formula_bar&&(this.formula_bar.target_address={...this.primary_selection.target}),this.options.stats&&this.UpdateStats())}UpdateFormulaBarFormula(e){if(this.formula_bar){if(e){this.formula_bar.formula=e;return}if(this.primary_selection.empty)this.formula_bar.formula="";else{let t=this.active_sheet.CellData(this.primary_selection.target),r=t.merge_area||t.area;r&&(r.start.column!==this.primary_selection.target.column||r.start.row!==this.primary_selection.target.row)&&(t=this.active_sheet.CellData(r.start)),this.formula_bar.editable=!t.style?.locked;let i=this.NormalizeCellValue(t);if(t.validation&&!t.style?.locked){let n;t.validation.type==="list"?n=t.validation.list:t.validation.type==="range"&&(n=this.GetValidationRange(t.validation.area)),n&&n.length&&this.layout.ShowDropdownCaret(t.merge_area||new y(this.primary_selection.target),n,t.value)}else this.layout.HideDropdownCaret();t.area?this.formula_bar.formula="{"+(i||"")+"}":this.formula_bar.formula=typeof i<"u"?i.toString():""}}}RenderStats(e){if(!Array.isArray(e))return[];let t=0,r=0,i={real:0,imaginary:0};for(let a of e)for(let s of a)typeof s=="number"?(i.real+=s,r++):fe(s)&&(i.real+=s.real,i.imaginary+=s.imaginary,r++),typeof s<"u"&&t++;let n=a=>{let s=Math.floor(Math.log10(a));return s<-6||s>10?I.Get("Exponential"):s<=-1?I.Get("General"):I.Get("Number")};if(t>1)if(r>0){let a=I.Get("General");if(i.imaginary){let s={real:i.real/r,imaginary:i.imaginary/r};return[{label:"Count",value:t.toString()},{label:"Sum",value:te.FormatPartsAsText(a.FormatComplex(i))},{label:"Average",value:te.FormatPartsAsText(a.FormatComplex(s))}]}else return[{label:"Count",value:t.toString()},{label:"Sum",value:n(i.real).Format(i.real)},{label:"Average",value:n(i.real/r).Format(i.real/r)}]}else return[{label:"Count",value:t.toString()}];return[]}UpdateStats(){if(this.tab_bar){let e=[];typeof this.options.stats=="function"?this.primary_selection.empty||(e=this.options.stats.call(void 0,this.GetRange(this.primary_selection.area))):!this.primary_selection.empty&&this.primary_selection.area.count>1&&(e=this.RenderStats(this.GetRange(this.primary_selection.area))),this.tab_bar.stats_data=e}}UpdateAddressLabel(e=this.primary_selection,t){if(this.formula_bar)if(typeof t<"u")this.formula_bar.label=t;else if(e.empty)this.formula_bar.label="";else{let r=this.active_sheet.CellData(this.primary_selection.target),i=new y(r.merge_area?r.merge_area.start:e.target);this.formula_bar.label=this.model.named_ranges.MatchSelection(e.area,i)||y.CellAddressToLabel(i.start)}}OnDropdownSelect(e){if(typeof e<"u"){let i=be.TryParse(e.toString());i.type===3&&(e=i.value)}let t=this.active_sheet.CellData(this.primary_selection.target),r=t.merge_area?t.merge_area.start:this.primary_selection.target;this.ExecCommand({key:6,area:r,value:e}),this.UpdateFormulaBarFormula()}OnScroll(){let e=this.layout.VisibleTiles();e.Equals(this.render_tiles)||(this.render_tiles=e,this.layout_token||(this.layout_token=requestAnimationFrame(()=>this.Repaint())))}AttachListeners(){if(!this.container)throw new Error("invalid container");this.container.addEventListener("copy",this.HandleCopy.bind(this)),this.container.addEventListener("cut",this.HandleCut.bind(this)),this.container.addEventListener("paste",this.HandlePaste.bind(this)),this.layout.grid_cover.addEventListener("mousedown",e=>this.MouseDown_Grid(e)),this.layout.column_header_cover.addEventListener("mousedown",e=>this.MouseDown_ColumnHeader(e)),this.layout.row_header_cover.addEventListener("mousedown",e=>this.MouseDown_RowHeader(e)),this.layout.column_header_cover.addEventListener("mousemove",e=>this.MouseMove_ColumnHeader(e)),this.layout.row_header_cover.addEventListener("mousemove",e=>this.MouseMove_RowHeader(e)),this.layout.grid_cover.addEventListener("mousemove",e=>this.MouseMove_Grid(e)),this.overlay_editor?.edit_node.addEventListener("keydown",e=>this.OverlayKeyDown(e)),this.layout.corner.addEventListener("dblclick",()=>{this.SelectAll()}),window.addEventListener("resize",()=>{this.layout.UpdateDPR()&&(this.QueueLayoutUpdate(),this.Repaint(!0,!0,!0))})}HandleCopy(e){if(e.stopPropagation(),e.preventDefault(),this.primary_selection.empty){if(e.clipboardData&&e.clipboardData.clearData(),this.selected_annotation&&e.clipboardData){let t=JSON.stringify({data:this.selected_annotation,source:this.active_sheet.id});e.clipboardData.setData("text/x-treb-annotation",t);let r=this.selected_annotation.view[this.view_index];if(r&&r.node){let i=r.node.firstChild;if(i){let n=Zr(i).outerHTML,a="text/plain";e.clipboardData.setData(a,n)}}}}else{let t=this.active_sheet.RealArea(this.primary_selection.area),r=t.columns,i=t.rows,n=[],a=[];for(let o=0;o<i;o++){let l=[];for(let d=0;d<r;d++){let h={row:t.start.row+o,column:t.start.column+d},u=this.active_sheet.CellData(h),m="";u.calculated?u.calculated_type===7?m=Le(u.calculated):m=u.calculated.toString():u.type===7?m=Le(u.value):m=u.value?.toString()||"",l.push(m);let f={address:h,data:u.value,type:u.type,style:this.active_sheet.GetCopyStyle(h)};u.area&&u.area.start.row===h.row&&u.area.start.column===h.column&&(f.array={rows:u.area.rows,columns:u.area.columns}),a.push(JSON.parse(JSON.stringify(f)))}n.push(l)}let s=n.map(o=>o.join(" ")).join(`
|
|
9
9
|
`);e.clipboardData&&(e.clipboardData.clearData(),e.clipboardData.setData("text/plain",s),e.clipboardData.setData("text/x-treb",JSON.stringify({source:t,data:a})))}}HandleCut(e){if(e.stopPropagation(),e.preventDefault(),this.HandleCopy(e),this.primary_selection.empty)this.selected_annotation&&this.RemoveAnnotation(this.selected_annotation);else{let t=this.active_sheet.RealArea(this.primary_selection.area);this.ExecCommand({key:11,area:t})}}RecyclePasteAreas(e,t){let r=[];if(e.count===1)for(let i=t.start.row;i<=t.end.row;i++)for(let n=t.start.column;n<=t.end.column;n++)r.push(new y({row:i,column:n}));else if(e.columns===t.columns&&t.rows>=e.rows&&t.rows%e.rows===0)for(let i=t.start.row;i<=t.end.row;i+=e.rows)r.push(new y({row:i,column:t.start.column},{row:i+e.rows-1,column:t.end.column}));else if(e.rows===t.rows&&t.columns>=e.columns&&t.columns%e.columns===0)for(let i=t.start.column;i<=t.end.column;i+=e.columns)r.push(new y({column:i,row:t.start.row},{column:i+e.columns-1,row:t.end.row}));else r.push(t.Clone().Resize(e.rows,e.columns));return r}HandlePaste(e){if(this.overlay_editor?.editing||(e.stopPropagation(),e.preventDefault(),!e.clipboardData))return;let t=e.clipboardData.getData("text/x-treb-annotation");if(t){try{let a=JSON.parse(t);if(a.source&&a.source!==this.active_sheet.id&&a.data&&a.data.formula){let l="",d=this.model.sheets.Find(a.source);if(d&&(l=d.name),l){let h=this.parser.Parse(a.data.formula);h.expression&&(this.parser.Walk(h.expression,u=>u.type==="range"?(!u.start.sheet_id&&!u.start.sheet&&(u.start.sheet=l),!1):(u.type==="address"&&!u.sheet_id&&!u.sheet&&(u.sheet=l),!0)),a.data.formula="="+this.parser.Render(h.expression,{missing:""}))}}let o=this.CreateAnnotation(a.data,!0,!0).view[this.view_index];if(o&&o.node){let l=o.node;setTimeout(()=>{l.focus()},1)}}catch(a){console.error(a)}return}if(this.primary_selection.empty)return;let r=this.active_sheet.RealArea(this.primary_selection.area),i=[],n=e.clipboardData.getData("text/x-treb");if(n)try{let a=JSON.parse(n),s=new y(a.source.start,a.source.end),o=this.RecyclePasteAreas(s,r);if(o.length===1&&r.Resize(o[0].rows,o[0].columns),!this.ValidatePasteAreas(o)){this.Error(5);return}let l=[];for(let d of o){this.active_sheet.cells.EnsureCell(d.end),i.push({key:11,area:d});let h={rows:d.start.row-s.start.row,columns:d.start.column-s.start.column};a.data.forEach(u=>{let m=u.data,f={row:u.address.row-s.start.row+d.start.row,column:u.address.column-s.start.column+d.start.column};if(u.type===1){let p=this.parser.Parse(m);p.expression&&(m="="+this.parser.Render(p.expression,{offset:h,missing:""}))}if(u.array){let p={start:{...f},end:{row:f.row+u.array.rows-1,column:f.column+u.array.columns-1}},g={key:6,value:m,array:!0,area:p};l.push(new y(p.start,p.end)),i.push(g)}else{let p=!1;for(let g of l)if(g.Contains(f)){p=!0;break}p||i.push({key:6,value:m,area:f})}i.push({key:7,style:u.style||{},area:f})})}}catch(a){console.error("invalid treb data on clipboard"),console.info(a);return}else{let a=e.clipboardData.getData("text/plain");if(!a)return!0;let o=a.trim().split(`
|
|
10
|
-
`).map(d=>d.split(" ").map(h=>h.trim())),l=this.RecyclePasteAreas(new y({row:0,column:0},{row:o.length-1,column:o[0].length-1}),r);if(l.length===1&&(r.Resize(o.length,o[0].length),r.Resize(l[0].rows,l[0].columns)),!this.ValidatePasteAreas(l)){this.Error(5);return}for(let d of l)for(let h=0;h<o.length;h++)for(let u=0;u<o[0].length;u++){let m=new y({row:h+d.start.row,column:u+d.start.column});if(this.active_sheet.cells.EnsureCell(m.end),o[h][u]){let f=this.SetInferredType({area:m,target:m.start,empty:!1},o[h][u],!1,!1);if(f)for(let p of f)i.push(p)}else{let f=this.active_sheet.cells.GetCell(m.start,!1);f&&f.type!==0&&i.push({key:11,area:m.Clone()})}}}this.ExecCommand(i),this.Select(this.primary_selection,r)}AllSelections(e=!1){let t=[this.primary_selection,this.active_selection].concat(this.additional_selections);return e?t:t.filter(r=>!r.empty)}InsertRowsInternal(e){let t=super.InsertRowsInternal(e);if(t.error)return t;let r=this.FindSheet(e.sheet_id);if(r===this.active_sheet){if(e.count<0)for(let i of this.AllSelections())i.empty=!0;else for(let i of this.AllSelections())i.target.row>=e.before_row&&(i.target.row+=e.count),i.area.entire_column||(i.area.start.row>=e.before_row?i.area.Shift(e.count,0):i.area.end.row>=e.before_row&&i.area.ConsumeAddress({row:i.area.end.row+e.count,column:i.area.end.column}));for(let i of t.delete_annotations_list||[])this.layout.RemoveAnnotation(i);if(this.QueueLayoutUpdate(),this.Repaint(),t.update_annotations_list?.length){this.layout.UpdateAnnotation(t.update_annotations_list);for(let i of t.resize_annotations_list||[]){let n=i.view[this.view_index];n?.resize_callback&&n.resize_callback.call(void 0)}}}else this.pending_layout_update.add(r.id);return t}InsertColumnsInternal(e){let t=super.InsertColumnsInternal(e);if(t.error)return t;let r=this.FindSheet(e.sheet_id);if(r===this.active_sheet){if(e.count<0)for(let i of this.AllSelections())i.empty=!0;else for(let i of this.AllSelections())i.target.column>=e.before_column&&(i.target.column+=e.count),i.area.entire_row||(i.area.start.column>=e.before_column?i.area.Shift(0,e.count):i.area.end.column>=e.before_column&&i.area.ConsumeAddress({row:i.area.end.row,column:i.area.end.column+e.count}));for(let i of t.delete_annotations_list||[])this.layout.RemoveAnnotation(i);if(this.tile_renderer?.FlushOverflows(),this.QueueLayoutUpdate(),this.DelayedRender(!0,void 0,!0),t.update_annotations_list?.length){this.layout.UpdateAnnotation(t.update_annotations_list);for(let i of t.resize_annotations_list||[]){let n=i.view[this.view_index];n?.resize_callback&&n.resize_callback.call(void 0)}}}else this.pending_layout_update.add(r.id);return t}ResetInternal(){super.ResetInternal(),this.RemoveAnnotationNodes(),this.ClearSelection(this.primary_selection),this.ScrollIntoView({row:0,column:0}),this.QueueLayoutUpdate(),this.layout.HideNote()}ResizeColumnsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.column;if(typeof r>"u"){r=[];for(let a=0;a<t.columns;a++)r.push(a)}typeof r=="number"&&(r=[r]);let i=typeof e.width!="number",n=Math.round(e.width||0/this.scale);if(i)for(let a of r)this.AutoSizeColumn(t,a,!1);else for(let a of r)t.SetColumnWidth(a,n);t===this.active_sheet?(this.layout.UpdateTotalSize(),this.layout.container&&this.layout.container.offsetWidth&&this.layout.container.offsetWidth>this.layout.total_width?this.UpdateLayout():(this.layout.UpdateTileWidths(!0),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!1,!0)),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.RenderSelections()):this.pending_layout_update.add(t.id)}ResizeRowsInternal(e){let t,r=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,i=e.row;if(typeof i>"u"){i=[];for(let o=0;o<r.rows;o++)i.push(o)}typeof i=="number"&&(i=[i]);let n=typeof e.shrink=="boolean"?e.shrink:!0,a=typeof e.height!="number",s=Math.round(e.height||0/this.scale);if(a)for(let o of i)r.GetRowHeight(o)||(t?t.ConsumeAddress({row:o,column:1}):t=new y({row:o,column:1/0,sheet_id:r.id})),r.AutoSizeRow(o,this.theme.grid_cell,n);else for(let o of i){let l=r.GetRowHeight(o);(!l&&s||l&&!s)&&(t?t.ConsumeAddress({row:o,column:1}):t=new y({row:o,column:1/0,sheet_id:r.id})),r.SetRowHeight(o,s)}return r===this.active_sheet?(this.layout.UpdateTotalSize(),this.layout.container&&this.layout.container.offsetHeight&&this.layout.container.offsetHeight>this.layout.total_height?this.UpdateLayout():(this.layout.UpdateTileHeights(!0),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!1,!0)),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.RenderSelections()):this.pending_layout_update.add(r.id),t?{start:t.start,end:t.end}:void 0}SelectInternal(e){e.area?(e.area.start.sheet_id&&e.area.start.sheet_id!==this.active_sheet.id&&this.ActivateSheetInternal({key:21,id:e.area.start.sheet_id}),this.Select(this.primary_selection,new y(e.area.start,e.area.end)),this.RenderSelections()):this.ClearSelection(this.primary_selection)}FreezeInternal(e){let t=this.FindSheet(e.sheet_id||this.active_sheet.id),r=(typeof e.highlight_transition=="boolean"?e.highlight_transition:!0)&&t===this.active_sheet;if(e.rows===t.freeze.rows&&e.columns===t.freeze.columns){r&&this.HighlightFreezeArea();return}t.freeze.rows=e.rows,t.freeze.columns=e.columns,t===this.active_sheet?(this.QueueLayoutUpdate(),this.Repaint(),r&&this.HighlightFreezeArea(),e.rows||e.columns?this.layout.CloneFrozenAnnotations():this.layout.ClearFrozenAnnotations()):this.pending_layout_update.add(t.id)}ExecCommand(e,t=!0){let r=super.ExecCommand(e,t);this.batch||r.render_area&&this.DelayedRender(!1,r.render_area),r.repaint&&this.Repaint();for(let i of r.pending||[])this.pending_layout_update.add(i);return r.layout&&this.QueueLayoutUpdate(),r.sheets&&this.tab_bar&&this.tab_bar.Update(),r.formula&&this.UpdateFormulaBarFormula(),r}};var nt=class{forward={};backward=[];Count(){return this.backward.length}Serialize(){return JSON.parse(JSON.stringify(this.Map()))}Deserialize(e){if(this.Reset(),e){for(let t of Object.keys(e))this.SetName(t,new y(e[t].start,e[t].end),!1);this.RebuildList()}}MatchSelection(e,t){if(!e.start.sheet_id)throw new Error("match selection without sheet id");let r;for(let i of this.List())if(i.range.start.sheet_id===e.start.sheet_id&&(i.range.Equals(e)&&(r=i.name),t?.Equals(i.range)))return i.name;return r}SetName(e,t,r=!0){let i=this.ValidateNamed(e);return i?t.entire_column||t.entire_row?(console.warn("invalid range"),!1):(this.forward[i]=t,r&&this.RebuildList(),!0):(console.warn("invalid name"),!1)}SetNames(e){for(let t of Object.keys(e)){let r=e[t];this.SetName(t,new y(r.start,r.end),!1)}this.RebuildList()}ClearName(e,t=!0){delete this.forward[e],t&&this.RebuildList()}RemoveRangesForSheet(e,t=!0){let r={},i=this.List();for(let n of i)n.range.start.sheet_id!==e&&(r[n.name]=n.range);this.forward=r,t&&this.RebuildList()}Reset(){this.forward={},this.backward=[]}Get(e){return this.forward[e.toUpperCase()]}Map(){return this.forward}List(){return this.backward}ValidateNamed(e){return e=e.trim(),!e.length||/^[A-Za-z]{1,3}\d+$/.test(e)||/[^A-Za-z\d_.]/.test(e)||/^[^A-Za-z_]/.test(e)?!1:e.toUpperCase()}PatchNamedRanges(e,t,r,i,n){let a=this.List().slice(0);for(let s of a){let o=s.name,l=s.range;if(l.start.sheet_id!==e){console.info("skipping name",o);continue}if(r&&t<=l.end.column){if(r>0)t<=l.start.column?l.Shift(0,r):t>l.start.column&&t<=l.end.column?l.ConsumeAddress({row:l.end.row,column:l.end.column+r}):console.warn("PNR X case 1",t,r,JSON.stringify(l));else if(r<0)if(t-r<=l.start.column)l.Shift(0,r);else if(t<=l.start.column&&t-r>l.end.column)this.ClearName(o,!1);else if(t<=l.start.column){let d=t-r-1;this.SetName(o,new y({row:l.start.row,column:d+1+r,sheet_id:e},{row:l.end.row,column:l.end.column+r}),!1)}else t<=l.end.column?t-r-1>=l.end.column?this.SetName(o,new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:t-1}),!1):this.SetName(o,new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:l.start.column+l.columns+r-1}),!1):console.warn("PNR X case 2",t,r,JSON.stringify(l))}if(n&&i<=l.end.row){if(n>0)i<=l.start.row?l.Shift(n,0):i>l.start.row&&i<=l.end.row?l.ConsumeAddress({row:l.end.row+n,column:l.end.column}):console.warn("PNR X case 3",i,n,JSON.stringify(l));else if(n<0)if(i-n<=l.start.row)l.Shift(n,0);else if(i<=l.start.row&&i-n>l.end.row)this.ClearName(o,!1);else if(i<=l.start.row){let d=i-n-1;this.SetName(o,new y({column:l.start.column,row:d+1+n,sheet_id:e},{column:l.end.column,row:l.end.row+n}),!1)}else i<=l.end.row?i-n-1>=l.end.row?this.SetName(o,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:i-1}),!1):this.SetName(o,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:l.start.row+l.rows+n-1}),!1):console.warn("PNR X case 4",i,n,JSON.stringify(l))}}this.RebuildList()}RebuildList(){this.backward=[];for(let e of Object.keys(this.forward))this.backward.push({name:e,range:this.forward[e]})}};var Cr=class{get list(){return this.sheets_.slice(0)}get length(){return this.sheets_.length}names=new Map;ids=new Map;sheets_=[];Assign(e){this.sheets_=[...e],this.UpdateIndexes()}Add(e){this.sheets_.push(e),this.UpdateIndexes()}Splice(e,t,...r){this.sheets_.splice(e,t,...r),this.UpdateIndexes()}Find(e){return typeof e=="string"?this.names.get(e.toLocaleUpperCase()):this.ids.get(e)}Name(e){return this.ids.get(e)?.name||void 0}ID(e){return this.names.get(e.toLocaleUpperCase())?.id||void 0}UpdateIndexes(){this.names.clear(),this.ids.clear();for(let e of this.sheets_){let t=e.name.toLocaleUpperCase();this.names.set(t,e),this.ids.set(e.id,e)}}},at=class{parser=new Ge;document_name;user_data;sheets=new Cr;named_ranges=new nt;macro_functions=new Map;named_expressions=new Map;view_count=0;theme_style_properties=JSON.parse(JSON.stringify(V.DefaultProperties));tables=new Map;ResolveStructuredReference(e,t){let r;if(e.table?r=this.tables.get(e.table.toLowerCase()):t.sheet_id&&(r=this.sheets.Find(t.sheet_id)?.CellData(t)?.table),!r)return;let i=e.column.toLowerCase(),n=-1;if(r.columns){for(let a=0;a<r.columns.length;a++)if(i===r.columns[a]){n=r.area.start.column+a;break}}if(!(n<0))if(e.scope==="row"){let a=t.row;return a<r.area.start.row||a>r.area.end.row?void 0:{label:e.label,type:"address",row:a,column:n,sheet_id:r.area.start.sheet_id,id:e.id,position:e.position}}else{let a=r.area.start.row,s=r.area.end.row;return e.scope==="column"&&(a++,r.totals_row&&s--),{label:e.label,type:"range",position:e.position,id:e.id,start:{type:"address",row:a,column:n,sheet_id:r.area.start.sheet_id,label:e.label,position:e.position,id:0},end:{type:"address",row:s,column:n,label:e.label,position:e.position,id:0}}}}AddressToLabel(e,t){let r=N(e)?e:e.start,i=N(e)?[y.CellAddressToLabel(e)]:[y.CellAddressToLabel(e.start),y.CellAddressToLabel(e.end)],n=this.sheets.Find(r.sheet_id||0),a=n?.name?ze.test(n.name)?`'${n.name}'`:n.name:"";return a+(a?"!":"")+(i[0]===i[1]?i[0]:i.join(":"))}ResolveSheetID(e,t,r){let i=e.type==="address"?e:e.start;if(i.sheet_id)return!0;if(i.sheet){let n=this.sheets.Find(i.sheet);if(n)return i.sheet_id=n.id,!0}else{if(t?.sheet_id)return i.sheet_id=t.sheet_id,!0;if(r?.id)return i.sheet_id=r.id,!0}return!1}ResolveArea(e,t){let r=this.ResolveAddress(e,t);return N(r)?new y(r):new y(r.start,r.end)}ResolveAddress(e,t){if(typeof e=="string"){let r=this.parser.Parse(e);if(r.expression&&r.expression.type==="address")return this.ResolveSheetID(r.expression,void 0,t),{row:r.expression.row,column:r.expression.column,sheet_id:r.expression.sheet_id};if(r.expression&&r.expression.type==="range")return this.ResolveSheetID(r.expression,void 0,t),{start:{row:r.expression.start.row,column:r.expression.start.column,sheet_id:r.expression.start.sheet_id},end:{row:r.expression.end.row,column:r.expression.end.column}};if(r.expression&&r.expression.type==="identifier"){let i=this.named_ranges.Get(r.expression.name);if(i)return i}return{row:0,column:0}}return e}};var mi={"red-green":{color_space:"RGB",stops:[{value:0,color:{theme:5,tint:.5}},{value:1,color:{theme:9,tint:.5}}]},"red-yellow-green":{color_space:"RGB",stops:[{value:0,color:{theme:5,tint:.5}},{value:.5,color:{theme:7,tint:.5}},{value:1,color:{theme:9,tint:.5}}]},"green-red":{color_space:"RGB",stops:[{value:0,color:{theme:9,tint:.5}},{value:1,color:{theme:5,tint:.5}}]},"green-yellow-red":{color_space:"RGB",stops:[{value:0,color:{theme:9,tint:.5}},{value:.5,color:{theme:7,tint:.5}},{value:1,color:{theme:5,tint:.5}}]}};var Vt=class c{static type="vertex";type=c.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 i of t.edges_out){if(i.color===1)return this.color=0,!0;i.color===0&&i.edges_out.size&&(e.push(i),r=!1)}}r&&(t.color=2,e.pop())}return this.color=2,!1}};var $e=class extends Vt{dirty=!1};var fi={error:"NOTIMPL"},xe=()=>({type:6,value:"N/A"}),Ce=()=>({type:6,value:"EXPR"});var he=()=>({type:6,value:"DIV/0"}),L=()=>({type:6,value:"ARG"}),E=()=>({type:6,value:"VALUE"}),B=()=>({type:6,value:"REF"}),Ar=()=>({type:6,value:"NAME"}),Ut=()=>({type:6,value:"UNK"});var Ae=class c extends $e{static type="spreadsheet-vertex";reference;error=0;address;result={type:0};expression={type:"missing",id:-1};expression_error=!1;short_circuit=!1;type=c.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=j(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){let t=this.result.type===8?this.result.value[0][0]:this.result;this.reference.SetCalculatedValue(t.value,t.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 Ve=class c extends $e{static type="array-vertex";static list=[];type=c.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 c(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(),c.list.push(this)}RemoveDependent(e){super.RemoveDependent(e),this.edges_out.size||(this.Reset(),c.list=c.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 Lt=class{vertices=[[]];volatile_list=[];calculation_list=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===Ae.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),Ve.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 i=r[e.column];if(i&&i.area){let n={row:i.area.start.row,column:i.area.start.column,sheet_id:e.sheet_id};return console.info("array head",e,n),n}}return e}GetVertex(e,t){if(!e.sheet_id)throw console.info({address:e,create:t}),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 n=this.vertices[e.sheet_id][e.column][e.row];if(n)return n;if(!t)return}else{if(!t)return;this.vertices[e.sheet_id][e.column]=[]}let i=new Ae;return i.address={row:e.row,column:e.column,absolute_row:e.absolute_row,absolute_column:e.absolute_column,sheet_id:e.sheet_id},i.reference=r.EnsureCell(e),this.vertices[e.sheet_id][e.column][e.row]=i,Ve.CreateImplicitEdges(i,e),i}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,i=!1){this.RIBcount++;let n=this.GetVertex(e,r);if(!n){if(t){let s=Ve.GetContainingArrays(e);for(let o of s)this.SetVertexDirty(o)}return}let a=[];if(i&&(a=Array.from(n.edges_in)),n.ClearDependencies(),t&&this.SetVertexDirty(n),i){n.has_outbound_edges||this.RemoveVertex(e);for(let s of a)if(!s.has_inbound_edges&&!s.has_outbound_edges){let o=s;o.address&&this.RemoveVertex(o.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 i of this.vertices)if(i){for(let n of i)if(n)for(let a of n)a&&(a.color=a.edges_out.size?0:2,t.push(a))}let r=[];for(let i of t)if(i.color===0){for(i.color=1,r.push(i);r.length;){let n=r[r.length-1],a=!0;if(n.color!==2)for(let s of n.edges_out){if(s.color===1)return this.loop_hint=this.RenderAddress(i.address),console.info("loop detected @",this.loop_hint),!0;s.color===0&&(r.push(s),a=!1)}a&&(r.pop(),n.color=2)}i.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 i=this.model.sheets.Find(e.sheet_id);i&&(t=i.name+"!")}let r=new y(e);return t+r.spreadsheet_label}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0),[i,n]=Ve.GetVertex(e);if(r.DependsOn(i),this.loop_check_required=!0,!n)return;let a=this.vertices[e.start.sheet_id];if(a)if(e.entire_row){for(let s=0;s<a.length;s++)if(a[s])for(let o=e.start.row;o<=e.end.row;o++){let l=a[s][o];l&&i.DependsOn(l)}}else if(e.entire_column){for(let s=e.start.column;s<=e.end.column;s++)if(a[s])for(let o of a[s])o?.address&&i.DependsOn(o)}else for(let s=e.start.row;s<=e.end.row;s++)for(let o=e.start.column;o<=e.end.column;o++){let l=a[o][s];l&&i.DependsOn(l)}}AddEdge(e,t,r){let i=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(i),i.reference&&i.reference.area&&!i.array_head&&this.AddEdge({...e,row:i.reference.area.start.row,column:i.reference.area.start.column},t,"implicit"),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),i=this.GetVertex(t,!1);!r||!i||(r.RemoveDependent(i),i.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 i=e.start.row;i<=e.end.row;i++){let n={row:i,column:r,sheet_id:t};this.GetVertex(n,!1)&&this.SetDirty(n)}}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.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 Fn=c=>{let e={m:c,n:c,array:[]};for(let t=0;t<c;t++){let r=[];for(let i=0;i<c;i++)r.push({real:0,imaginary:0});e.array.push(r)}return e};var Ln=c=>{let{r:e,theta:t}=c,r=e*Math.cos(t),i=e*Math.sin(t);return{real:r,imaginary:i}},Pt=c=>{let e=Math.sqrt(c.real*c.real+c.imaginary*c.imaginary),t=Math.atan2(c.imaginary,c.real);return{r:e,theta:t}},le=(c,e)=>({real:c.real*e.real-c.imaginary*e.imaginary,imaginary:c.real*e.imaginary+c.imaginary*e.real}),Pn=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<c.n;n++)i.push(c.array[r][n]+e.array[r][n]);t.push(i)}return{m:c.m,n:c.n,array:t}},Sr=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let a=0;for(let s=0;s<c.n;s++)a+=c.array[r][s]*e.array[s][n];i.push(a)}t.push(i)}return{array:t,m:c.m,n:e.n}},bi=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let a={real:0,imaginary:0};for(let s=0;s<c.n;s++)a.real+=c.array[r][s].real*e.array[s][n].real-c.array[r][s].imaginary*e.array[s][n].imaginary,a.imaginary+=c.array[r][s].real*e.array[s][n].imaginary+c.array[r][s].imaginary*e.array[s][n].real;i.push(a)}t.push(i)}return t},Gt=c=>{let e={real:0,imaginary:0},t=c.n;if(t==2){let i=le(c.array[0][0],c.array[1][1]),n=le(c.array[1][0],c.array[0][1]);return{real:i.real-n.real,imaginary:i.imaginary-n.imaginary}}let r=Fn(c.n);for(let i=0;i<t;i++){let n=0;for(let o=1;o<t;o++){let l=0;for(let d=0;d<t;d++)d!=i&&(r.array[n][l]={...c.array[o][d]},l++);n++}r.m=r.n=t-1;let a=Math.pow(-1,i),s=le({real:c.array[0][i].real*a,imaginary:c.array[0][i].imaginary*a},Gt(r));e.real+=s.real,e.imaginary+=s.imaginary}return e};var Gn=c=>{let e={real_values:!1,imaginary_values:!1,square:c.m===c.n,unit_diagonal:!0},t={m:c.m,n:c.n,array:[]},r={m:c.m,n:c.n,array:[]};for(let i=0;i<c.m;i++){let n=c.array[i],a=[],s=[];for(let o=0;o<c.n;o++)n[o].real&&(e.real_values=!0),n[o].imaginary&&(e.imaginary_values=!0),o===i&&e.unit_diagonal&&(n[o].real!==1||n[o].imaginary!==0)&&(e.unit_diagonal=!1),a.push(n[o].real),s.push(n[o].imaginary);t.array.push(a),r.array.push(s)}return{real:t,imaginary:r,flags:e}},Hn=c=>{let e=c.array.map(t=>t.slice(0));return{m:c.m,n:c.n,array:e}},pi=c=>{if(c.m!==c.n)return;let e=Hn(c),t=e.array,r=0,i=0,n=0,a=0,s=c.m;for(i=1;i<s;i++)t[0][i]/=t[0][0];for(i=1;i<s;i++){for(n=i;n<s;n++){for(r=0,a=0;a<i;a++)r+=t[n][a]*t[a][i];t[n][i]-=r}if(i!=s-1)for(n=i+1;n<s;n++){for(r=0,a=0;a<i;a++)r+=t[i][a]*t[a][n];t[i][n]=(t[i][n]-r)/t[i][i]}}for(i=0;i<s;i++)for(n=i;n<s;n++){let o=1;if(i!=n)for(o=0,a=i;a<n;a++)o-=t[n][a]*t[a][i];t[n][i]=o/t[n][n]}for(i=0;i<s;i++)for(n=i;n<s;n++)if(i!=n){for(r=0,a=i;a<n;a++)r+=t[a][n]*(i==a?1:t[i][a]);t[i][n]=-r}for(i=0;i<s;i++)for(n=0;n<s;n++){for(r=0,a=i>n?i:n;a<s;a++)r+=(n==a?1:t[n][a])*t[a][i];t[n][i]=r}return e},gi=c=>{let e=[];if(c.m!==c.n)return;let{real:t,imaginary:r,flags:i}=Gn(c),n=pi(t);if(!n)return;if(!i.imaginary_values){for(let h=0;h<c.m;h++){let u=[];for(let m=0;m<c.n;m++)u.push({real:n.array[h][m],imaginary:0});e.push(u)}return e}let a=Sr(n,r),s=Sr(r,a),o=Pn(t,s),l=pi(o);if(!l)return;let d=Sr(a,l);for(let h=0;h<c.m;h++){let u=[];for(let m=0;m<c.n;m++)u.push({real:l.array[h][m],imaginary:-d.array[h][m]});e.push(u)}return e},_i=(c,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=le(c,t),i=le(e,t);return{real:r.real/i.real,imaginary:r.imaginary/i.real}},kr=c=>{let e=c.real||0,t=c.imaginary||0;return le({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},On=c=>{let e=Pt(c);return{real:Math.log(e.r),imaginary:e.theta}},ue=(c,e)=>{if(e.imaginary)return kr(le(e,On(c)));{let t=Pt(c);return Ln({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var yi=(c,e=0)=>c&&c.type===7?c:{type:7,value:{real:e,imaginary:0}},Ue=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real},Fe=(c,e)=>{if(c.type===6)return[0,0,c];if(e.type===6)return[0,0,e];let t=[0,0];switch(c.type){case 3:t[0]=c.value;break;case 4:t[0]=c.value?1:0;break;case 0:break;case 7:t[3]=c;break;default:return[0,0,E()]}switch(e.type){case 3:t[1]=e.value;break;case 4:t[1]=e.value?1:0;break;case 0:break;case 7:t[4]=e;break;default:return[0,0,E()]}return(t[3]||t[4])&&(t[3]=yi(t[3],t[0]),t[4]=yi(t[4],t[1])),t},$n=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ue({real:n.value.real+a.value.real,imaginary:n.value.imaginary+a.value.imaginary}):{value:t+r,type:3})},Mr=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ue({real:n.value.real-a.value.real,imaginary:n.value.imaginary-a.value.imaginary}):{value:t-r,type:3})},Zn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);if(i)return i;if(n&&a)return Ue(ue(n.value,a.value));let s=Math.pow(t,r);return isNaN(s)?E():{type:3,value:s}},Bn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);if(i)return i;if(n&&a)return Ue(ue(n.value,a.value));if(t<0&&r!==0&&Math.abs(r)<1)return Ue(ue({real:t,imaginary:0},{real:r,imaginary:0}));let s=Math.pow(t,r);return isNaN(s)?E():{type:3,value:s}},Tr=Zn,Wn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ue(le(n.value,a.value)):{value:t*r,type:3})},jn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?a.value.real===0&&a.value.imaginary===0?he():Ue(_i(n.value,a.value)):r===0?he():{value:t/r,type:3})},Yn=(c,e)=>{let[t,r,i]=Fe(c,e);return i||(r===0?he():{value:t%r,type:3})},Jn=(c,e)=>c.type===6?c:e.type===6?e:{type:2,value:`${c.type===0?"":c.value}${e.type===0?"":e.value}`},Er=(c,e)=>{if(c.type===6)return c;if(e.type===6)return e;if(c.type===0&&(e.value===""||e.value===0||e.type===7&&e.value.real===0&&e.value.imaginary===0)||e.type===0&&(c.value===""||c.value===0||c.type===7&&c.value.real===0&&c.value.imaginary===0))return{type:4,value:!0};if(c.type===7||e.type===7){let t=!1;return c.type===e.type?t=c.value.real==e.value.real&&c.value.imaginary==e.value.imaginary:c.type===3?t=e.value.real==c.value&&!e.value.imaginary:e.type===3&&(t=c.value.real==e.value&&!c.value.imaginary),{type:4,value:t}}return{type:4,value:c.value==e.value}},vi=(c,e)=>{let t=Er(c,e);return t.type===6?t:{type:4,value:!t.value}},Xn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:(c.value||0)>(e.value||0)},Qn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value>=e.value},qn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value<e.value},Kn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value<=e.value},wi=()=>{Tr=Bn},xi=c=>{switch(c){case"&":return Jn;case"+":return $n;case"-":return Mr;case"*":return Wn;case"/":return jn;case"^":return Tr;case"**":return Tr;case"%":return Yn;case"=":return Er;case"==":return Er;case"!=":return vi;case"<>":return vi;case">":return Xn;case">=":return Qn;case"<":return qn;case"<=":return Kn}};var Ai=c=>!Array.isArray(c)&&c.type===5&&!!c.value.type,st=c=>c.type===5&&c.key==="metadata",Ht=class{constructor(e,t){this.library=e;this.parser=t}context={address:{row:-1,column:-1},volatile:!1,call_index:0};call_index=0;named_range_map={};data_model;SetModel(e){this.data_model=e,this.named_range_map=e.named_ranges.Map(),this.context.model=e}Calculate(e,t,r=!1){return r||(this.context.address=t,this.context.volatile=!1,this.context.call_index=0,this.call_index=0),{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()=>B();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>B();let r=t.GetCell(e);return r?()=>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)||B():B()}GetMetadata(e,t){let r,i;switch(e.type){case"address":r=e;break;case"range":i=e;break;case"structured-reference":{let n=this.data_model.ResolveStructuredReference(e,this.context.address);n&&(n.type==="address"?r=n:n.type==="range"&&(i=n))}break;case"identifier":{let n=this.named_range_map[e.name.toUpperCase()];n&&(n.count===1?r=n.start:i=n)}break;case"call":{let n=this.CalculateExpression(e,!0);if(Ai(n))if(n.value.type==="address")r=n.value;else if(n.value.type==="range")i=n.value;else return n;else return n}break;default:return this.CalculateExpression(e)}if(r){let n;if(r.sheet_id&&(n=this.data_model.sheets.Find(r.sheet_id)),!n)return console.error("missing sheet [ac8]"),B();let a=n.CellData(r),s=a.calculated_type?a.calculated:a.value,o={type:"metadata",address:{...r},value:s,format:a.style?a.style.number_format:void 0,...t(a,r)};return{type:5,value:o,key:"metadata"}}else if(i){if(i.start.row===1/0||i.start.column===1/0)return B();let n;if(i.start.sheet_id&&(n=this.data_model.sheets.Find(i.start.sheet_id)),!n)throw new Error("missing sheet [ac9]");let a=[];for(let s=i.start.column;s<=i.end.column;s++){let o=[];for(let l=i.start.row;l<=i.end.row;l++){let d=n.CellData({row:l,column:s});r={...i.start,row:l,column:s};let h=d.calculated_type?d.calculated:d.value,u={type:"metadata",address:r,value:h,format:d.style?d.style.number_format:void 0,...t(d,r)};o.push({type:5,value:u,key:"metadata"})}a.push(o)}return{type:8,value:a}}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(i=>this.RewriteMacro(i,t));break;case"call":e.args=e.args.map(i=>this.RewriteMacro(i,t));break}return e}CallMacro(e,t){if(!t.expression)return()=>Ce();let r=JSON.stringify(t.expression),i={},n=t.argument_names?.map(a=>a.toUpperCase())||[];return a=>{let s=JSON.parse(r);for(let o=0;o<n.length;o++)i[n[o]]=a.args[o]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(s,i))}}CallExpression(e,t=!1){let r=this.library.Get(e.name);return r?i=>{let n=this.call_index++;this.context.volatile=this.context.volatile||!!r.volatile;let a=e.name.toLowerCase()==="if",s=-1,o,l=r.arguments||[],d=i.args.map((h,u)=>{if(o)return;let m=l[Math.min(u,l.length-1)]||{};if(u===s)return m.boxed?{type:0}:void 0;if(typeof h>"u")return a&&u===0&&(s=1),m.boxed?{type:0}:void 0;if(m.address)return m.boxed?{type:2,value:this.parser.Render(h).replace(/\$/g,"")}:this.parser.Render(h).replace(/\$/g,"");if(m.metadata)return this.GetMetadata(h,()=>({}));{let f=this.CalculateExpression(h);if(f.type===6){if(m.allow_error)return f;o=f;return}if(a&&u===0&&f.type!==8){let p=!1;if(f.type===2){let g=f.value.toLowerCase().trim();p=g!=="false"&&g!=="f"}else p=!!f.value;s=p?2:1}return m.boxed?f:f.type===8?f.value.map(p=>p.map(g=>g.value)):f.value}});if(o)return o;if(this.context.call_index=n,r.return_type===1){let h=r.fn.apply(null,d);if(t)return h;if(Ai(h)){if(h.value.type==="address")return this.CellFunction2(h.value)();if(h.value.type==="range")return this.CellFunction4(h.value.start,h.value.end)}return h}return r.fn.apply(null,d)}:()=>Ar()}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()=>B()}ResolveDimensionedQuantity(){return e=>{let t=this.CalculateExpression(e.expression);return{type:9,value:{value:t.value,unit:e.unit.name}}}}UnaryExpression(e){switch(e.operator){case"+":return t=>this.CalculateExpression(t.operand);case"-":{let t=Mr,r={type:3,value:0};return i=>{let n=this.CalculateExpression(i.operand);return n.type===8?{type:8,value:n.value.map(a=>a.map(s=>t(r,s)))}:t(r,n)}}default:return()=>(console.warn("unexpected unary operator:",e.operator),Ce())}}RecycleArray(e,t,r){if(e[0].length<r){let i=e[0].length;for(let n of e)for(let a=i;a<r;a++)n[a]=n[a%i]}if(e.length<t){let i=e.length;for(let n=i;n<t;n++)e[n]=e[n%i].slice(0)}return e}ElementwiseBinaryExpression(e,t,r){let i=Math.max(t.value.length,r.value.length),n=Math.max(t.value[0].length,r.value[0].length),a=this.RecycleArray(t.value,i,n),s=this.RecycleArray(r.value,i,n),o=[];for(let l=0;l<i;l++){let d=[];for(let h=0;h<n;h++)d[h]=e(a[l][h],s[l][h]);o.push(d)}return{type:8,value:o}}BinaryExpression(e){let t=xi(e.operator);return t?r=>{let i=this.CalculateExpression(r.left),n=this.CalculateExpression(r.right);return i.type===8?n.type===8?this.ElementwiseBinaryExpression(t,i,n):this.ElementwiseBinaryExpression(t,i,{type:8,value:[[n]]}):n.type===8?this.ElementwiseBinaryExpression(t,{type:8,value:[[i]]},n):t(i,n)}:()=>(console.info(`(unexpected binary operator: ${e.operator})`),Ce())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>B();let r=t.toUpperCase();switch(r){case"FALSE":case"F":return()=>({value:!1,type:4});case"TRUE":case"T":return()=>({value:!0,type:4});case"UNDEFINED":return()=>({value:void 0,type:0})}return()=>{let i=this.named_range_map[r];if(i)return i.count===1?this.CellFunction4(i.start,i.start):this.CellFunction4(i.start,i.end);let n=this.data_model.named_expressions.get(r);return n?this.CalculateExpression(n):Ar()}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>Ce()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.user_data)return e.user_data(e);switch(e.type){case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.user_data=this.CallMacro(e,r))(e):(e.user_data=this.CallExpression(e,t))(e)}case"address":return(e.user_data=this.CellFunction2(e))();case"range":return(e.user_data=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.user_data=this.BinaryExpression(e))(e);case"unary":return(e.user_data=this.UnaryExpression(e))(e);case"identifier":return(e.user_data=this.Identifier(e))();case"missing":return(e.user_data=()=>({value:void 0,type:0}))();case"dimensioned":return(e.user_data=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:se(e.value)};return(e.user_data=()=>r)()}case"group":return(e.user_data=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:7};return(e.user_data=()=>r)()}case"structured-reference":return(e.user_data=this.ResolveStructuredReference(e))();case"array":return(e.user_data=()=>({type:8,value:e.values.map(r=>(Array.isArray(r)?r:[r]).map(i=>({type:se(i),value:i})))}))();default:return console.warn("Unhandled parse expr:",e),Ut()}}};var Gc=1e3*60*60*24;var Ot=c=>{let e=[],t=c.length,r=c[0].length;for(let i=0;i<r;i++){e[i]=[];for(let n=0;n<t;n++)e[i][n]=c[n][i]}return e};var _e=c=>{let e=[];for(let t of c)if(t.type===8)for(let r of t.value)e=e.concat(_e(r));else e.push(t);return e},P=c=>Array.isArray(c)?c.reduce((e,t)=>typeof t>"u"?e:Array.isArray(t)?e.concat(P(t)):t instanceof Float32Array||t instanceof Float64Array?e.concat(Array.from(t)):e.concat([t]),[]):[c];var G=c=>(e,...t)=>Array.isArray(e)?{type:8,value:e.map(r=>r.map(i=>c(i,...t)))}:typeof e=="object"&&e&&e.type===8?{type:8,value:e.value.map(r=>r.map(i=>c(i,...t)))}:c(e,...t),Se=c=>(e,t,...r)=>{let i=!1,n=!1;return e&&typeof e=="object"&&e.type===8?(e=e.value,i=!0):i=Array.isArray(e),t&&typeof t=="object"&&t.type===8?(t=t.value,n=!0):n=Array.isArray(t),i?n?{type:8,value:e.map((a,s)=>a.map((o,l)=>c(o,t[s][l],...r)))}:{type:8,value:e.map(a=>a.map(s=>c(s,t,...r)))}:n?{type:8,value:t.map(a=>a.map(s=>c(e,s,...r)))}:c(e,t,...r)};var $t=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 i=r.toLowerCase();if(this.functions[i])throw new Error(`function name (${i}) is already in use`);let n=t[r];n.canonical_name=r,this.functions[i]=n}}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 ot=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,i)=>r.concat(this.UnpackValues(i)),[]):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 i=[];for(let n=0;n<r;n++)i[n]=e[n.toString()];return i}}}return[]}static SparklineCommon(e,t){let r=[],i=t.text?.text||this.default_color,n=[i,i];return Array.isArray(e.calculated)&&(r=this.UnpackValues(e.calculated[0]),typeof e.calculated[1]=="string"&&(n[0]=e.calculated[1]),typeof e.calculated[2]=="string"&&(n[1]=e.calculated[2])),{values:r,colors:n}}static RenderLine(e,t,r,i,n){let{values:a,colors:s}=this.SparklineCommon(i,n),o=.05,l=.1,d=1;Array.isArray(i.calculated)&&typeof i.calculated[2]=="number"&&(d=i.calculated[2]);let h=0,u=0,m=-1;for(let f=0;f<a.length;f++){let p=a[f];typeof p=="number"&&(m>=0?(h=Math.min(h,p),u=Math.max(u,p)):(m=f,h=u=p))}if(h!==u){let f=e*(1-2*o)/(a.length-1),p=u-h,g=t*(1-2*l),b=t*l;r.strokeStyle=s[0],r.lineWidth=d,r.lineCap="round",r.lineJoin="round",r.beginPath();let v=0;for(let _=m;_<a.length;_++){let w=a[_];if(typeof w=="number"){let x=e*o+f*_,A=t-(w-h)*g/p-b;v===0?(r.moveTo(x,A),v=1):r.lineTo(x,A)}else v=0}r.stroke()}}static RenderColumn(e,t,r,i,n){let{values:a,colors:s}=this.SparklineCommon(i,n),o=3,l=2.5,d=0,h=0,u=!1;for(let m of a)typeof m=="number"&&(u?(d=Math.min(d,m),h=Math.max(h,m)):(u=!0,d=h=m));if(a.length){let m=(e-2*o-2)/(a.length-0),f=t-2*l,p=l;if(d!==h)if(d<0&&h>0){let g=h-d,b=p+h/g*f;for(let v=0;v<a.length;v++){let _=a[v];if(typeof _=="number"){let w=o+v*m,x=Math.abs(_)/g*f;if(_>=0){r.fillStyle=s[0];let A=b-x;r.fillRect(w+2,A,m-2,x)}else{r.fillStyle=s[1];let A=b;r.fillRect(w+2,A,m-2,x)}}}}else if(h>0){r.fillStyle=s[0];let g=h-d;for(let b=0;b<a.length;b++){let v=a[b];if(typeof v=="number"){let _=o+b*m,w=Math.max(1,(v-d)/g*f),x=t-p-w;r.fillRect(_+2,x,m-2,w)}}}else{r.fillStyle=s[1];let g=h-d;for(let b=0;b<a.length;b++){let v=a[b];if(typeof v=="number"){let _=o+b*m,w=Math.max(1,Math.abs(h-v)/g*f),x=p;r.fillRect(_+2,x,m-2,w)}}}}}};var Si=c=>{let{x:e,y:t,width:r,height:i,cell:n}=c,a={},s=3,o=Math.round(16*(c.scale||1));if(n&&r&&i&&e&&t){let l={x:s,y:i-s-o};if(n.style){switch(n.style.vertical_align){case"top":l.y=s;break;case"middle":l.y=Math.round((i-o)/2);break}switch(n.style.horizontal_align){case"right":l.x=Math.round(r-s-o);break;case"center":l.x=Math.round((r-o)/2);break}}e>=l.x&&e<=l.x+o&&t>=l.y&&t<=l.y+o&&(a.value=`=Checkbox(${n.calculated?"FALSE":"TRUE"})`,a.block_selection=!0)}return a},ki=c=>{let{context:e,width:t,height:r,cell:i}=c,n=c.scale||1;e.lineJoin="round",e.lineCap="round";let a=3*n,s=16*n,o=a,l=r-a-s;if(i.style){switch(i.style.vertical_align){case"top":l=a;break;case"middle":l=(r-s)/2;break}switch(i.style.horizontal_align){case"right":o=t-a-s;break;case"center":o=(t-s)/2;break}}o=Math.floor(o)+.5,l=Math.floor(l)+.5;let d=Math.floor(o+s)+.5,h=Math.floor(l+s)+.5;if(i&&i.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(o,l),e.lineTo(o+16*n,l),e.lineTo(o+16*n,l+16*n),e.lineTo(o,l+16*n),e.closePath(),e.moveTo(o+15*n,l+4*n);for(let u of[[13.59,2.58],[6,10.17],[2.41,6.59],[1,8],[6,13]])e.lineTo(o+u[0]*n,l+u[1]*n);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(o,l),e.lineTo(d,l),e.lineTo(d,h),e.lineTo(o,h),e.closePath(),e.stroke();return{handled:!0}};var Ri=c=>{let e=.254829592,t=-.284496736,r=1.421413741,i=-1.453152027,n=1.061405429,a=.3275911;c=Math.abs(c);let s=1/(1+a*c);return 1-((((n*s+i)*s+r)*s+t)*s+e)*s*Math.exp(-1*c*c)},ta=Math.sqrt(2*Math.PI),Ti=c=>{if(c===.5)return 0;let e=c<1&&c>.5?1-c:c,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 c>.5?r:-r},Ir={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=ue(c.value,{real:.5,imaginary:0});return ce(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3&&c.value<0){let e=ue({real:c.value,imaginary:0},{real:.5,imaginary:0});return{type:7,value:e}}else{let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}}})},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0},{name:"exponent",boxed:!0}],fn:Se((c,e)=>{if(c.type===3&&e.type===3&&(c.value>=0||e.value===0||Math.abs(e.value)>=1)){let n=Math.pow(c.value,e.value);return isNaN(n)?E():{type:3,value:n}}let t=c.type===7?c.value:{real:c.value||0,imaginary:0},r=e.type===7?e.value:{real:e.value||0,imaginary:0},i=ue(t,r);return ce(i)})}},Be={Int:{fn:c=>({type:3,value:Math.floor(c)})},Rand:{volatile:!0,fn:()=>({type:3,value:Math.random()})},RandBetween:{arguments:[{name:"min"},{name:"max"}],volatile:!0,fn:(c=0,e=1)=>{if(c>e){let t=c;c=e,e=t}return{type:3,value:Math.floor(Math.random()*(e+1-c)+c)}}},Sum:{description:"Adds arguments and ranges",arguments:[{boxed:!0,name:"values or ranges"}],fn:(...c)=>{let e={real:0,imaginary:0},t=_e(c);for(let r of t)switch(r.type){case 3:e.real+=r.value;break;case 4:e.real+=r.value?1:0;break;case 7:e.real+=r.value.real,e.imaginary+=r.value.imaginary;break;case 6:return r}return ce(e)}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:He(new Date().getTime())})},Date:{description:"Constructs a Lotus date from parts",arguments:[{name:"year"},{name:"month"},{name:"day"}],fn:(c,e,t)=>{let r=new Date;return r.setMilliseconds(0),r.setSeconds(0),r.setMinutes(0),r.setHours(0),c<0||c>1e4?L():(c<1899&&(c+=1900),r.setFullYear(c),e<1||e>12?L():(r.setMonth(e-1),t<1||t>31?L():(r.setDate(t),{type:3,value:He(r.getTime())})))}},Today:{description:"Returns current day",volatile:!0,fn:()=>{let c=new Date;return c.setMilliseconds(0),c.setSeconds(0),c.setMinutes(0),c.setHours(12),{type:3,value:He(c.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:(c,e=0)=>c&&c.type===6?{value:e,type:se(e)}:c},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=_e(c);for(let t of e)if(t.type===6)return{type:4,value:!0};return{type:4,value:!1}}},Cell:{description:"Returns data about a cell",arguments:[{name:"type",description:"Type of data to return"},{name:"reference",description:"Cell reference",metadata:!0}],fn:Se((c,e)=>{if(!st(e))return B();if(c)switch(c.toString().toLowerCase()){case"format":return e.value.format?{type:2,value:e.value.format}:B();case"address":return{type:2,value:e.value.address.label.replace(/\$/g,"")}}return{type:6,value:fi.error}})},Year:{description:"Returns year from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees"}],fn:G(c=>j(c*Math.PI/180))},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians"}],fn:G(c=>j(c/Math.PI*180))},CountA:{description:"Counts cells that are not empty",fn:(...c)=>j(P(c).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...c)=>j(P(c).reduce((e,t)=>typeof t=="number"||fe(t)?e+1:e,0))},Or:{fn:(...c)=>{let e=!1;c=P(c);for(let t of c)e=e||!!t;return j(e)}},And:{fn:(...c)=>{let e=!0;c=P(c);for(let t of c)e=e&&!!t;return j(e)}},Not:{fn:G((...c)=>c.length===0?L():c.length===1?j(!c[0]):j(!0))},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:(c,e={type:4,value:!0},t={type:4,value:!1})=>{let r=e.type===8,i=t.type===8;return c.type===8?{type:8,value:c.value.map((a,s)=>a.map((o,l)=>(o.type===2?o.value.toLowerCase()!=="false"&&o.value.toLowerCase()!=="f":!!o.value)?r?e.value[s][l]:e:i?t.value[s][l]:t))}:(c.type===2?c.value.toLowerCase()!=="false"&&c.value.toLowerCase()!=="f":!!c.value)?e:t}},Fact:{description:"Returns the factorial of a number",arguments:[{name:"number"}],fn:G(c=>{c=Math.floor(c);let e=1;for(;c>1;)e*=c,c--;return{type:3,value:e}})},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0},{name:"exponent",boxed:!0}],fn:Se((c,e)=>{if(c.type===7||e.type===7){let t=c.type===7?c.value:{real:c.value||0,imaginary:0},r=e.type===7?e.value:{real:e.value||0,imaginary:0},i=ue(t,r);return ce(i)}else{let t=Math.pow(c.value,e.value);return isNaN(t)?E():{type:3,value:t}}})},Mod:{fn:Se((c,e)=>e?j(c%e):he())},Sort:{arguments:[{name:"values"}],fn:(...c)=>(c=P(c),c.every(e=>typeof e=="number")?c.sort((e,t)=>e-t):c.sort(),{type:8,value:[c.map(e=>j(e))]})},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>c.type===8?{type:8,value:Ot(c.value)}:c},Max:{fn:(...c)=>({type:3,value:Math.max.apply(0,P(c).filter(e=>typeof e=="number"))})},Min:{fn:(...c)=>({type:3,value:Math.min.apply(0,P(c).filter(e=>typeof e=="number"))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...c)=>{let e=c.map(i=>P(i)),t=Math.max.apply(0,e.map(i=>i.length)),r=0;for(let i=0;i<t;i++)r+=e.reduce((n,a)=>n*(a[i]||0),1);return{type:3,value:r}}},VLookup:{fn:(c,e,t,r=!0)=>{if(t=Math.max(0,t-1),r){let i=Math.abs(c-e[0][0]),n=e[t][0];for(let a=1;a<e[0].length;a++){let s=Math.abs(e[0][a]-c);s<i&&(i=s,n=e[t][a])}return j(n)}else{for(let i=1;i<e[0].length;i++)if(e[0][i]==c)return e[t][i];return xe()}}},Product:{arguments:[{boxed:!0}],fn:(...c)=>{let e={real:1,imaginary:0};c=_e(c);for(let t of c)t.type===7?e=le(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return ce(e)}},Log:{fn:Se((c,e=10)=>({type:3,value:Math.log(c)/Math.log(e)}))},Log10:{fn:G(c=>({type:3,value:Math.log(c)/Math.log(10)}))},Ln:{fn:G(c=>({type:3,value:Math.log(c)}))},Round:{fn:Se((c,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*c)/t}})},RoundDown:{fn:Se((c,e=0)=>{let t=Math.pow(10,e),r=c>=0;return{type:3,value:r?Math.floor(t*c)/t:Math.ceil(t*c)/t}})},Reverse:{arguments:[{boxed:!0}],fn:c=>c.type===8?(c.value.length===1?c.value[0].reverse():c.value.reverse(),c):{type:2,value:c.value.toString().split("").reverse().join("")}},Exp:{arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=kr(c.value);return ce(e)}return{type:3,value:Math.exp(c.value||0)}})},Abs:{arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:Math.sqrt(c.value.real*c.value.real+c.value.imaginary*c.value.imaginary)}:{type:3,value:Math.abs(c.value||0)})},Simplify:{arguments:[{name:"value"},{name:"significant digits"}],fn:Se((c,e=2)=>{if(e=e||2,c===0)return{type:3,value:c};let t=c<0?-1:1;c*=t;let r=Math.pow(10,Math.floor(Math.log10(c))+1-e);return{type:3,value:Math.round(c/r)*r*t}})},Erf:{fn:c=>({type:3,value:Ri(c)})},NormsInv:{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"}],fn:c=>({type:3,value:Ti(c)})},"Norm.Inv":{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"},{name:"mean",default:0},{name:"standard deviation",default:1}],xlfn:!0,fn:(c,e=0,t=1)=>({type:3,value:Ti(c)*t+e})},"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:(c,e=0,t=1,r=!0)=>{let i=0;return r?i=.5*(1+(c<e?-1:1)*Ri(Math.abs(c-e)/(t*Math.sqrt(2)))):i=Math.exp(-1/2*Math.pow((c-e)/t,2))/(t*ta),{type:3,value:i}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=ue(c.value,{real:.5,imaginary:0});return ce(e)}else{if(c.type===0||!c.value)return{type:3,value:0};{let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}}})},HexToDec:{arguments:[{description:"hexadecimal string"}],fn:c=>({type:3,value:parseInt(c,16)})},DecToHex:{arguments:[{description:"number"}],fn:c=>({type:2,value:c.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Si,render:ki,fn:c=>({value:!!c,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:c=>(ot.RenderColumn(c.width,c.height,c.context,c.cell,c.style),{handled:!0}),fn:(...c)=>({type:5,value:c,key:"sparkline-data"})},"Sparkline.Line":{arguments:[{name:"data"},{name:"color"},{name:"line width"}],render:c=>(ot.RenderLine(c.width,c.height,c.context,c.cell,c.style),{handled:!0}),fn:(...c)=>({type:5,value:c,key:"sparkline-data"})},UniqueValues:{arguments:[{name:"range",boxed:!0}],visibility:"internal",fn:c=>{if(c.type===8){let e=c.value.length,t=c.value[0]?.length,r=s=>{if(s)switch(s.type){case 2:case 3:case 4:return s.value;case 0:return"";default:return console.info("check",s,s.value),s.value?.toString()||""}else return""},i=new Set,n=new Set;for(let s of c.value)for(let o of s){let l=r(o);i.has(l)?n.add(l):i.add(l)}let a=[];for(let s of c.value){let o=[];for(let l of s){let d=r(l);o.push({type:4,value:!n.has(d)})}a.push(o)}return{type:8,value:a}}return{type:4,value:!0}}},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(c,e,t)=>{let r=_e([c]),i=0,n=0,a=0,s=0;for(let h of r){if(h.type===6)return h;h.type===3&&(n===0?(a=h.value,s=h.value):(a=Math.min(a,h.value),s=Math.max(s,h.value)),n++)}typeof t=="number"&&(s=t),typeof e=="number"&&(a=e);let o=s-a,l=1,d=1;if(c.type===8){l=c.value.length,d=c.value[0]?.length||0;let h=[];for(let u=0;u<l;u++){let m=[];for(let f=0;f<d;f++){let p=c.value[u][f];if(p.type===3){let g=0;o>0&&(g=(p.value-a)/o),m.push({type:3,value:g})}else m.push({type:0})}h.push(m)}return{type:8,value:h}}else return L()}}},Ei={};for(let c of Object.keys(Be))Ei[c.toLowerCase()]=c;var ra=["pow"],Mi={};for(let c of ra)Mi[c.toLowerCase()]=c;for(let c of Object.getOwnPropertyNames(Math)){let e=c.toLowerCase();if(Ei[e]||Mi[e])continue;let t=Object.getOwnPropertyDescriptor(Math,c);if(!t)continue;let r=t.value,i=typeof r;switch(i){case"number":Be[c]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":Be[c]={fn:(...n)=>j(r(...n)),category:["Math Functions"]};break;default:console.info("unexpected type:",i,c);break}}Math.log10||(Math.log10=c=>Math.log(c)/Math.log(10));var lt=(c,e,t=0,r=0,i=0)=>i?-(t*(c/(1-Math.pow(1+c,-e))))/(1+c)-r*(1/((1+c)*((Math.pow(1+c,e)-1)/c))):-(t*c*Math.pow(1+c,e)+r*c)/(Math.pow(1+c,e)-1),zi=(c,e,t,r=0,i=0)=>i?(1+c)*-t/c*(Math.pow(1+c,e)-1)-r*Math.pow(1+c,e):-t/c*(Math.pow(1+c,e)-1)-r*Math.pow(1+c,e),zr=(c,e,t,r=0,i=0,n=0)=>{if(e<1)return NaN;if(e===1&&n)return 0;let a=lt(c,t,r,i,n),s=zi(c,e-1,a,r,n)*c;return n?s/(1+c):s},Ii=(c,e,t,r=0,i=0,n=0)=>lt(c,t,r,i,n)-zr(c,e,t,r,i,n),Di={NPV:{description:"Returns the present value of a series of future cashflows",arguments:[{name:"Rate"},{name:"Cashflow"}],fn:(c=0,...e)=>{let t=0,r=P(e);for(let i=0;i<r.length;i++){let n=r[i];typeof n=="number"&&(t+=Math.pow(1+c,-(i+1))*n)}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:(c,e,t)=>{if(typeof c!="number")return L();if(e=P(e),t=P(t),e.length!==t.length)return L();let r=[];for(let a of e){if(typeof a!="number")return L();r.push(a)}let i=[];for(let a of t){if(typeof a!="number")return L();i.push(Math.floor(a))}let n=0;for(let a=0;a<r.length;a++)n+=(r[a]||0)/Math.pow(1+c,(i[a]-i[0])/365);return{type:3,value:n}}},XIRR:{description:"returns the internal rate of return of a nonperiodic stream of payments",arguments:[{name:"Values"},{name:"Dates"},{name:"Guess",default:.1}],fn:(c,e,t=.1)=>{if(c=P(c),e=P(e),c.length!==e.length)return L();let r=0,i=0,n=[];for(let h of c){if(typeof h!="number")return L();h>0&&r++,h<0&&i++,n.push(h)}if(r<=0||i<=0)return L();let a=[];for(let h of e){if(typeof h!="number")return L();a.push(Math.floor(h))}let s=a[0];for(let h of a)if(h<s)return L();let o=.1,l=[{found:!1,value:0},{found:!1,value:0}],d=n.length;for(let h=0;h<100;h++){let u=0;for(let m=0;m<d;m++)u+=(n[m]||0)/Math.pow(1+t,(a[m]-a[0])/365);if(Math.abs(u)<=1e-6)return{type:3,value:t};if(u>0){if(l[0].value=l[0].found?Math.max(l[0].value,t):t,l[0].found=!0,!l[1].found){t+=o;continue}}else if(l[1].value=l[1].found?Math.min(l[1].value,t):t,l[1].found=!0,!l[0].found){t-=o;continue}t=l[0].value+(l[1].value-l[0].value)/2}return E()}},IRR:{description:"Calculates the internal rate of return of a series of cashflows",arguments:[{name:"Cashflows"},{name:"Guess",default:.1}],fn:(c,e=.1)=>{let t=P(c).map(n=>typeof n=="number"?n:0),r=.1,i=[{found:!1,value:0},{found:!1,value:0}];for(let n=0;n<50;n++){let a=0;for(let s=0;s<t.length;s++)a+=Math.pow(1+e,-(s+1))*t[s];if(Math.abs(a)<=.00125)return{type:3,value:e};if(a>0){if(i[0].value=i[0].found?Math.max(i[0].value,e):e,i[0].found=!0,!i[1].found){e+=r;continue}}else if(i[1].value=i[1].found?Math.min(i[1].value,e):e,i[1].found=!0,!i[0].found){e-=r;continue}e=i[0].value+(i[1].value-i[0].value)/2}return{type:6,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:(c,e,t,r,i,n=0)=>{let a=0;for(let s=r;s<=i;s++)a+=Ii(c,s,e,t,0,n);return{type:3,value:a}}},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:(c,e,t,r,i,n=0)=>{let a=0;for(let s=r;s<=i;s++)a+=zr(c,s,e,t,0,n);return{type:3,value:a}}},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:(c,e,t,r=0,i=0,n=0)=>({type:3,value:zr(c,e,t,r,i,n)})},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:(c,e,t,r=0,i=0,n=0)=>({type:3,value:Ii(c,e,t,r,i,n)})},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:(c,e,t=0,r=0,i=0)=>{let n=.25,a=[-1,1],s=32,o=1e-6;for(let l=0;l<s;l++){let d=lt(n,c,t,r,i);if(Math.abs(d-e)<=o)return{type:3,value:n};let h=lt(a[1],c,t,r,i);e>=d&&e<=h||e>=h&&e<=d?a[0]=n:a[1]=n,n=a[0]+(a[1]-a[0])/2}return{type:3,value:n}}},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:(c,e,t,r=0,i=0)=>({type:3,value:zi(c,e,t,r,i)})},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:(c,e,t,r=0,i=0)=>i?(t+=r*(1/((1+c)*((Math.pow(1+c,e)-1)/c))),{type:3,value:-(t+t/c*(1-Math.pow(1+c,-(e-1))))}):{type:3,value:-(r+t/c*(Math.pow(1+c,e)-1))/Math.pow(1+c,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:(c,e,t=0,r=0,i=0)=>i?{type:3,value:1+(-Math.log(1+c*(1-t/-e))+Math.log(1+r*c/(-e*(1+c))))/Math.log(1+c)}:{type:3,value:(Math.log(Math.pow(1-t*c/-e,-1))+Math.log(1+r*c/-e))/Math.log(1+c)}},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:(c,e,t,r=0,i=0)=>({type:3,value:lt(c,e,t,r,i)})}};var ia=c=>{let e=[],t=c.length,r="[\\^$.|?*+()";for(let i=0;i<t;i++){let n=c[i];switch(n){case"*":e.push(".","*");break;case"?":e.push(".");break;case"~":n=c[++i]||"";default:for(let a=0;a<r.length;a++)if(n===r[a]){e.push("\\");break}e.push(n);break}}return e.join("")},Ni={Char:{arguments:[{name:"number"}],fn:c=>({type:2,value:String.fromCodePoint(c||32)}),category:["text"]},Code:{arguments:[{name:"string"}],fn:c=>({type:3,value:c.codePointAt(0)||0}),category:["text"]},Value:{arguments:[{name:"text"}],fn:c=>{let e=be.TryParse(c);return e.type===3?{type:3,value:e.value}:L()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(c,e="0.00####")=>({type:2,value:I.Get(e).Format(c||0)}),category:["text"]},Left:{arguments:[{name:"string"},{name:"count"}],fn:(c,e=1)=>({type:2,value:c.substr(0,e)}),category:["text"]},Right:{arguments:[{name:"string"},{name:"count"}],fn:(c,e=1)=>({type:2,value:c.slice(-e)}),category:["text"]},Mid:{arguments:[{name:"string"},{name:"left"},{name:"count"}],fn:(c,e=0,t=1)=>({type:2,value:c.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:(c,e,t=1)=>{if(t>=1){if(!c)return{type:3,value:t};let r=ia(c),i=new RegExp(r,"i").exec(e.substr(t-1));if(i)return{type:3,value:i.index+t}}return E()}},Find:{description:"Find a string (needle) in another string (haystack). Case-sensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(c,e,t=1)=>{if(t>=1){if(!c)return{type:3,value:t};let r=new RegExp(c).exec(e.substr(t-1));if(r)return{type:3,value:r.index+t}}return E()}},Concat:{description:"Pastes strings together",fn:(...c)=>{let t=P(c).map(r=>{let i=r?.toString()||"";return typeof r=="number"&&D.decimal_separator===","?i.replace(/\./,","):i}).join("");return{type:2,value:t}}}},Dr={Concatenate:"Concat"};var Vi={IsBlank:{description:"Returns true if the reference is blank",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:!c?.value||typeof c.value.value>"u"}))},IsNumber:{description:"Returns true if the reference is a number",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="number"}))},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="boolean"}))},IsText:{description:"Returns true if the reference is text",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="string"}))}};var ke=(c,e=!1)=>{let t=c.length,r=0,i=0;for(let n=0;n<t;n++)r+=c[n];r/=t;for(let n=0;n<t;n++){let a=c[n]-r;i+=a*a}return e?i/(t-1):i/t},Ui={"StDev.P":{description:"Returns the standard deviation of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:Math.sqrt(ke(P(c),!1))})},"StDev.S":{description:"Returns the standard deviation of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:Math.sqrt(ke(P(c),!0))})},"Var.P":{description:"Returns the variance of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:ke(P(c),!1)})},"Var.S":{description:"Returns the variance of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:ke(P(c),!0)})},Covar:{description:"Returns the covariance between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(c,e)=>{if(!Array.isArray(c)||!Array.isArray(e))return E();if(!Array.isArray(c[0])||!Array.isArray(e[0]))return E();if(c.length!==e.length)return L();let t=0,r=0,i={x:0,y:0},n={x:[],y:[]};for(let a=0;a<c.length;a++){if(!c[a]||!e[a])continue;if(c[a].length!==e[a].length)return L();let s=c[a].length;r+=s;for(let o=0;o<s;o++)i.x+=c[a][o]||0,i.y+=e[a][o]||0,n.x.push(c[a][o]||0),n.y.push(e[a][o]||0)}if(r===0)return xe();i.x/=r,i.y/=r;for(let a=0;a<r;a++)t+=(n.x[a]-i.x)*(n.y[a]-i.y);return{type:3,value:t/r}}},Correl:{description:"Returns the correlation between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(c,e)=>{if(!Array.isArray(c)||!Array.isArray(e))return E();if(!Array.isArray(c[0])||!Array.isArray(e[0]))return E();let t=0,r=0,i=0,n=0,a=0,s=0,o=0;for(let l=0;l<c.length;l++){if(!c[l]||!e[l])continue;let d=c[l].length;for(let h=0;h<d;h++){let u=Number(c[l][h]),m=Number(e[l][h]);isNaN(u)||isNaN(m)||(r+=u*m,i+=u,n+=m,a+=u*u,s+=m*m,o++)}}return t=o*r-i*n,t&&(t/=Math.sqrt((o*a-i*i)*(o*s-n*n))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=_e(c);let e=0,t={real:1,imaginary:0},r=!1,i=!1;for(let n of c)n.type===7?(r=!0,t=le(t,n.value),e++):n.type===3&&(n.value<0&&(i=!0),e++,t.real*=n.value,t.imaginary*=n.value);if(r){let n=ue(t,{real:1/e,imaginary:0});return n.imaginary?{type:7,value:n}:{type:3,value:n.real}}else return i?E():{type:3,value:Math.pow(t.real,1/e)}}},Average:{description:"Returns the arithmetic mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=_e(c);let e={real:0,imaginary:0},t=0;for(let r of c){if(r.type===6)return r;r.type===3&&(e.real+=r.value,t++),r.type===7&&(e.real+=r.value.real,e.imaginary+=r.value.imaginary,t++)}return e.real/=t,e.imaginary/=t,e.imaginary?{type:7,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:(c,e)=>{let t=P(c).filter(o=>typeof o=="number");t.sort((o,l)=>o-l);let r=t.length,i=Math.pow(10,8),n=Math.round((1+(r-1)*e)*i)/i,a=Math.floor(n),s=Math.ceil(n);return{type:3,value:(t[a-1]+t[s-1])/2}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...c)=>{let e=P(c).filter(a=>typeof a=="number");e.sort((a,s)=>a-s);let r=1+(e.length-1)*.5,i=Math.floor(r),n=Math.ceil(r);return{type:3,value:(e[i-1]+e[n-1])/2}}}},Nr={Mean:"Average",StDev:"StDev.S",Var:"Var.S"};var Fi={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&fe(c.value.value)}))},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===3?{...c}:c.type===7?{type:3,value:c.value.real||0}:c.type===0||c.type===2&&c.value===""?{type:3,value:0}:E())},Imaginary:{description:"Returns the imaginary part of a complex number (as real)",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:c.value.imaginary||0}:c.type===3||c.type===0||c.type===2&&c.value===""?{type:3,value:0}:E())},Conjugate:{description:"Returns the conjugate of a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:7,value:{real:c.value.real,imaginary:-c.value.imaginary}}:c.type===3||c.type===0||!c.value?{type:3,value:c.value||0}:E())},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:Math.atan2(c.value.imaginary,c.value.real)}:c.type===3||c.type===0||c.type===2&&c.value===""?{type:3,value:Math.atan2(0,c.value||0)}:E())},Rectangular:{description:"Converts a complex number in polar form to rectangular form",arguments:[{name:"r"},{name:"\u03B8 in radians"}],fn:(c=0,e=0)=>({type:7,value:{real:c*Math.cos(e),imaginary:c*Math.sin(e)}})},Complex:{description:"Ensures that the given value will be treated as a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===7?c:c.type===3||c.type===0||!c.value?{type:7,value:{imaginary:0,real:c.value||0}}:E())},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===3){if(!c.value)return E();c={type:7,value:{real:c.value,imaginary:0}}}else if(c.type===0||c.type===2&&c.value==="")return E();if(c.type===7){let e=Pt(c.value),t={real:Math.log(e.r),imaginary:e.theta};return t.imaginary?{type:7,value:t}:{type:3,value:t.real}}return E()})}};var Zt=c=>{let e=[];c.type===8?e=c.value:e=[[c.value]];let t=e.length,r=t?e[0].length:0,i=[];if(!t||!r)return{m:t,n:r,array:i};for(let n=0;n<t;n++){let a=[];for(let s=0;s<r;s++){let o=e[n][s];if(o.type===7)a.push({...o.value});else if(o.type===3)a.push({real:o.value,imaginary:0});else if(o.type===0||o.value==="")a.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}i.push(a)}return{m:t,n:r,array:i}},Li={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=Zt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Gt(e);return t?ce(t):E()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=Zt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Gt(e);if(t&&t.real===0&&t?.imaginary===0)return E();let r=gi(e);return r?{type:8,value:r.map(i=>i.map(n=>ce(n)))}:E()}},MMult:{description:"Returns the dot product of A and B",arguments:[{name:"A",boxed:!0},{name:"B",boxed:!0}],fn:(c,e)=>{let t=Zt(c),r=Zt(e);if(!t.array||t.error||!r.array||r.error)return E();if(t.m!==r.n)return E();let i=bi(r,t);return{type:8,value:i.map(n=>n.map(a=>ce(a)))}}}};var Bt=class c extends Ae{static type="state-leaf-vertex";state_id=0;type=c.type;color=2;state_representation="";UpdateState(){let e=JSON.stringify(Array.from(this.edges_in).map(t=>t.result));e!==this.state_representation&&(this.state_representation=e,this.state_id++)}Calculate(e){if(this.dirty){for(let t of this.edges_in)if(t.dirty)return;this.UpdateState(),this.dirty=!1}}AddDependent(e){throw new Error("leaf vertex cannot have dependents")}};var Wt=class c extends Ae{static type="calculation-leaf-vertex";type=c.type;address={row:-1,column:-1};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(e){throw new Error("leaf vertex cannot have dependents")}};var na=c=>{if(typeof c=="string")switch(c=c.toUpperCase(),c){case"AVERAGE":case"MEAN":c=101;break;case"COUNT":c=102;break;case"COUNTA":c=103;break;case"MAX":c=104;break;case"MIN":c=105;break;case"PRODUCT":c=106;break;case"STDEV":c=107;break;case"STDEVP":c=108;break;case"SUM":c=109;break;case"VAR":c=110;break;case"VARP":c=111;break;default:c=0;break}return c},aa={complex_numbers:"off"},jt=class extends Lt{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Ht(this.library,this.parser),{...aa,...r}.complex_numbers==="on"){for(let n of Object.keys(Ir))Be[n]=Ir[n];wi()}this.UpdateLocale(),this.library.Register(Be,Ni,Ui,Di,Vi,Fi,Li);for(let n of Object.keys(Nr))this.library.Alias(n,Nr[n]);for(let n of Object.keys(Dr))this.library.Alias(n,Dr[n]);this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(n,...a)=>{if(n=na(n),n>100&&(n-=100),n<1||n>11)return L();let s=_e(a),o=[],l=0,d=0,h;for(let m of s){let f=m.value?.address;if(!f)return B();if(!h||h.id!==f.sheet_id){if(!f.sheet_id)return console.warn("invalid reference in metadata"),B();if(h=this.model.sheets.Find(f.sheet_id),!h)return console.warn("invalid sheet in metadata"),B()}if(!h.GetRowHeight(f.row))continue;let g=m.value?.value;typeof g>"u"||(l++,typeof g=="number"&&(d+=g,o.push(g)))}let u=0;switch(n){case 1:if(o.length===0)return he();u=d/o.length;break;case 2:u=o.length;break;case 3:u=l;break;case 4:if(o.length===0)return E();u=Math.max.apply(0,o);break;case 5:if(o.length===0)return E();u=Math.min.apply(0,o);break;case 6:if(o.length===0)return E();u=1;for(let m of o)u*=m;break;case 7:if(o.length<2)return he();u=Math.sqrt(ke(o,!0));break;case 8:if(o.length===0)return he();u=Math.sqrt(ke(o,!1));break;case 9:u=d;break;case 10:if(o.length<2)return he();u=ke(o,!0);break;case 11:if(o.length===0)return he();u=ke(o,!1);break}return{type:3,value:u}}},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(n,a)=>{let s=P(n);typeof a!="string"?a="="+(a||0).toString():(a=a.trim(),/^[=<>]/.test(a)||(a="="+a));let o=this.parser.Parse("{}"+a),l=o.expression;if(o.error||!l)return Ce();if(l.type!=="binary")return Ce();if(l.left.type!=="array")return Ce();l.left.values=[s];let d=this.CalculateExpression(l);if(d.type===8){let h=0;for(let u of d.value)for(let m of u)m.value&&h++;return{type:3,value:h}}return d}},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:1,volatile:!0,fn:((n,a=0,s=0,o,l)=>{if(!n)return L();if(n.type===8){let h=typeof o=="number"?a+o:void 0,u=typeof l=="number"?s+l:void 0;return{type:8,value:n.value.slice(a,h).map(f=>f.slice(s,u))}}if(!st(n))return console.info("e2",{reference:n}),B();let d=this.DynamicDependencies(n.value.address,this.expression_calculator.context.address,!0,a,s,l,o);if(!d)return console.info("e1",{check_result:d}),B();if(d.dirty){let h=this.GetVertex(this.expression_calculator.context.address,!0);return h.short_circuit=!0,{type:0,value:void 0}}if(d.area){let h={type:"address",...d.area.start,label:"",position:0,id:0},u={type:"address",...d.area.end,label:"",position:0,id:0},m=d.area.count===1?h:{type:"range",start:h,end:u,label:"",position:0,id:0};return{type:5,value:m}}return E()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:1,volatile:!0,fn:(n=>{if(!n||typeof n!="string")return L();let a=this.parser.Parse(n);if(a.error||!a.expression||a.expression.type!=="address"&&a.expression.type!=="range")return B();let s=this.DynamicDependencies(a.expression,this.expression_calculator.context.address);if(!s)return B();if(s.dirty){let o=this.GetVertex(this.expression_calculator.context.address,!0);return o.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:a.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(n,a,s=0)=>{if(s)return console.warn("inexact match not supported",{value:n,range:a,type:s}),xe();if(a.type===8){if(a.value.length===1){let o=a.value[0];for(let l=0;l<o.length;l++)if(n.type==o[l].type&&n.value===o[l].value)return{type:3,value:l+1}}else for(let o=0;o<a.value.length;o++){let l=a.value[o];if(l.length!==1)return xe();if(n.type==l[0].type&&n.value===l[0].value)return{type:3,value:o+1}}return xe()}else return n.type===a.type&&n.value===a.value?{type:3,value:1}:xe();return L()}},Index:{arguments:[{name:"range",boxed:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(n,a,s)=>{if(n&&n.type!==8&&(n={type:8,value:[[n]]}),a&&s){let o=n.value[s-1];if(o){let l=o[a-1];if(l)return l}}else if(a){let o=[];for(let l of n.value){if(!l[a-1])return L();o.push([l[a-1]])}return{type:8,value:o}}else if(s){let o=n.value[s-1];if(o)return{type:8,value:[o]}}return L()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:n=>{if(!n)return L();if(Array.isArray(n)){let a=n[0];return Array.isArray(a)?{type:3,value:a.length}:E()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:n=>n?Array.isArray(n)?{type:3,value:n.length}:{type:3,value:1}:L()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0}],fn:G(n=>{if(!st(n))return B();let a=this.model.sheets.Find(n.value?.address?.sheet_id||0);if(a){let s=a.cells.GetCell(n.value.address,!1);return{type:2,value:s?.value?.toString()||""}}return B()})},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",metadata:!0}],fn:G(n=>{let a=this.model.sheets.Find(n?.value?.address?.sheet_id||0);if(a){let s=a.cells.GetCell(n.value.address,!1);return{type:4,value:s?.type===1}}return{type:4,value:!1}})}})}get parser(){return this.model.parser}library=new $t;registered_libraries={};expression_calculator;full_rebuild_required=!1;ExportCalculatedValues(){let t={};for(let r of this.model.sheets.list){let i=r.cells.toJSON({calculated_value:!0}).data;t[r.id]=i.filter(n=>n.calculated!==void 0)}return t}ApplyCalculatedValues(t){for(let r of this.model.sheets.list){let i=t[r.id];if(!i)console.info("mismatch",r.id);else for(let n of i)r.cells.data[n.row][n.column].SetCalculatedValue(n.calculated)}}SpreadCallback(t,r){if(!t.address||!t.address.sheet_id)throw new Error("spread callback called without sheet id");let i=this.model.sheets.Find(t.address.sheet_id)?.cells;if(!i)throw new Error("spread callback called without cells");if(!t||!t.reference)return;let n=t.reference.area;if(n){let a=n.rows,s=n.columns;if(r.type===8){let o=Ot(r.value);for(let l=0;l<a;l++)if(o[l]){let d=0;for(;d<s&&d<o[l].length;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(o[l][d].value,o[l][d].type);for(;d<s;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let d=0;d<s;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let o=0;o<a;o++)for(let l=0;l<s;l++)i.data[o+n.start.row][l+n.start.column].SetCalculatedValue(r.value,r.type)}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:Ut()}:this.expression_calculator.Calculate(t.expression,t.address)}DynamicDependencies(t,r,i=!1,n=0,a=0,s=1,o=1){let l=this.ResolveExpressionAddress(t,r);if(!l)return;let d=!1,h;if(t.type==="address"||t.type==="range"){let m=t.type==="range"?t.start:t;m.sheet_id?h=this.model.sheets.Find(m.sheet_id):m.sheet&&(h=this.model.sheets.Find(m.sheet))}if(!h&&r?.sheet_id&&(h=this.model.sheets.Find(r.sheet_id)),!h)throw new Error("missing sheet in dynamic dependencies [b21]");l=h.RealArea(l);let u=l.start.sheet_id;i&&(l=new y({column:l.start.column+a,row:l.start.row+n,sheet_id:l.start.sheet_id},{column:l.start.column+a+s-1,row:l.start.row+n+o-1,sheet_id:l.end.sheet_id}));for(let m=l.start.row;m<=l.end.row;m++)for(let f=l.start.column;f<=l.end.column;f++){let p=this.GetVertex({row:m,column:f,sheet_id:u},!1);p&&p.dirty&&(this.AddEdge({row:m,column:f,sheet_id:u},this.expression_calculator.context.address),d=!0)}return{dirty:d,area:l}}UpdateLocale(){D.decimal_separator===","?(this.parser.decimal_mark=",",this.parser.argument_separator=";"):(this.parser.decimal_mark=".",this.parser.argument_separator=",")}SupportedFunctions(){let t=this.library.List(),r=Object.keys(t).map(i=>{let n=t[i].canonical_name;return n||(n=i.replace(/_/g,".")),{name:n,description:t[i].description,arguments:(t[i].arguments||[]).map(a=>({name:a.name||""}))}});for(let i of this.model.macro_functions.values())r.push({name:i.name,description:i.description,arguments:(i.argument_names||[]).map(n=>({name:n}))});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 i=t[r],n=i.fn;i.fn=(...a)=>n.apply({address:{...this.expression_calculator.context.address}},a),this.library.Register({[r]:i})}}AttachModel(){this.expression_calculator.SetModel(this.model)}Calculate(t){if(this.AttachModel(),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.full_rebuild_required=!1),this.RebuildGraph(t);try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.AttachModel(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let i of Object.keys(r)){let n=r[i];n.xlfn?t[i]="_xlfn":n.extension&&(t[i]="_xll")}return t}Evaluate(t,r,i={},n=!1){let a=this.parser.argument_separator,s=this.parser.flags.r1c1;i.argument_separator&&(i.argument_separator===","?(this.parser.argument_separator=",",this.parser.decimal_mark="."):(this.parser.argument_separator=";",this.parser.decimal_mark=",")),i.r1c1&&(this.parser.flags.r1c1=i.r1c1);let o=this.parser.Parse(t);if(this.parser.argument_separator=a,this.parser.decimal_mark=a===","?".":",",this.parser.flags.r1c1=s,o&&o.expression){this.parser.Walk(o.expression,d=>{if(d.type==="address"||d.type==="range"){if(d.type==="address"){if(d.offset_column||d.offset_row)throw new Error("Evaluate does not support offset references")}else if(d.start.offset_column||d.start.offset_row||d.end.offset_column||d.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(d,void 0,r)}return!0});let l=this.CalculateExpression(o.expression);return n?l:l.type===8?l.value.map(d=>d.map(h=>h.value)):l.value}throw o.error?new Error(o.error):new Error("invalid expression")}CalculateExpression(t,r={row:-1,column:-1},i=!1){return this.expression_calculator.Calculate(t,r,i).value}RebuildClean(t=!1){this.full_rebuild_required=!1,this.AttachModel(),this.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},i=[];for(let n of t){let a={column:n.column,row:n.row,sheet_id:n.sheet_id},s=y.CellAddressToLabel(a,!0);r[s]||(r[s]=s,i.push(a))}return i}Unresolve(t,r,i=!0,n=!0){let a="",s=N(t)?new y(t):new y(t.start,t.end);if(n){let d=this.model.named_ranges.MatchSelection(s);if(d)return d}if(s.count>1?a=y.CellAddressToLabel(s.start)+":"+y.CellAddressToLabel(s.end):a=y.CellAddressToLabel(s.start),!i)return a;let o=s.start.sheet_id||r?.id,l=this.ResolveSheetName(o,!0);return l?l+"!"+a:a}ResolveSheetName(t,r=!1){let i=this.model.sheets.Find(t);if(i)return r&&ze.test(i.name)?`'${i.name}'`:i.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}UpdateConditionals(t,r){if(!t){for(let i of this.model.sheets.list)i.conditional_formats?.length&&this.UpdateConditionals(i.conditional_formats,i);return}if(!r)throw new Error("invalid call to update conditionals without context");t&&!Array.isArray(t)&&(t=[t]);for(let i of t){let n="";switch(i.type){case"cell-match":n=this.Unresolve(i.area,r,!0,!1)+" "+i.expression;break;case"expression":n=i.expression;break;case"duplicate-values":n=`UniqueValues(${this.Unresolve(i.area,r,!0,!1)})`,i.unique||(n=`NOT(${n})`);break;case"gradient":n=`=Gradient(${[this.Unresolve(i.area,r,!0,!1),i.min??"",i.max??""].join(this.parser.argument_separator)})`;break;default:continue}if(!n)continue;if(i.internal||(i.internal={}),!i.internal.vertex){i.internal.vertex=new Wt;let s;i.type!=="gradient"&&i.type!=="duplicate-values"&&(s=i.options);let o=this.Evaluate(n,r,s,!0);i.internal.vertex.result=o,i.internal.vertex.updated=!0}let a=i.internal.vertex;this.AddLeafVertex(a),this.UpdateLeafVertex(a,n,r)}}RemoveAnnotation(t){let r=t.temp.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}UpdateAnnotations(t,r){if(!t){for(let i of this.model.sheets.list)this.UpdateAnnotations(i.annotations,i);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 i of t)if(i.data.formula){i.temp.vertex||(i.temp.vertex=new Bt);let n=i.temp.vertex;this.AddLeafVertex(n),this.UpdateLeafVertex(n,i.data.formula,r)}}ResolveExpressionAddress(t,r){switch(t.type){case"address":if(this.model.ResolveSheetID(t,r))return new y(t);break;case"range":if(this.model.ResolveSheetID(t,r))return new y(t.start,t.end);break;case"identifier":{let i=this.model.named_ranges.Get(t.name.toUpperCase());if(i)return new y(i.start,i.end)}break}}NamedRangeToAddressUnit(t){let r=t.name.toUpperCase(),i=this.model.named_ranges.Get(r);if(i)return i.count===1?this.ConstructAddressUnit(i.start,r,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(i.start,r,t.id,t.position),end:this.ConstructAddressUnit(i.end,r,t.id,t.position),label:r,id:t.id,position:t.position}}ConstructAddressUnit(t,r,i,n){return{type:"address",row:t.row,column:t.column,sheet_id:t.sheet_id,label:r,id:i,position:n}}RebuildDependencies(t,r,i,n={addresses:{},ranges:{}},a){if(!i){let s=this.model.sheets.Find(r);s&&(i=s.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let s=t.name.toUpperCase();if(this.model.named_expressions.has(s)){let o=this.model.named_expressions.get(s);o&&this.RebuildDependencies(o,r,i,n,a)}else{let o=this.NamedRangeToAddressUnit(t);o&&(o.type==="address"?n.addresses[o.label]=o:n.ranges[o.label]=o)}}break;case"structured-reference":{let s=this.model.ResolveStructuredReference(t,a);s&&(s.type==="address"?n.addresses[s.sheet_id+"!"+s.label]=s:n.ranges[s.label]=s);let o=this.model.tables.get(t.table.toLowerCase());if(o){let l=a.row;if(l<o.area.start.row||l>o.area.end.row)break;let d=t.column.toLowerCase(),h=-1;if(o.columns){for(let u=0;u<o.columns.length;u++)if(d===o.columns[u]){h=o.area.start.column+u;break}}if(h>=0){let u={label:t.label,type:"address",row:l,column:h,sheet_id:o.area.start.sheet_id,id:t.id,position:t.position};n.addresses[u.sheet_id+"!"+u.label]=u}}}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=i;t.sheet_id?n.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=i;t.start.sheet_id?n.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,i,n,a);break;case"binary":this.RebuildDependencies(t.left,r,i,n,a),this.RebuildDependencies(t.right,r,i,n,a);break;case"group":t.elements.forEach(s=>this.RebuildDependencies(s,r,i,n,a));break;case"call":{let s=t.args.slice(0),o=this.library.Get(t.name);o&&o.arguments&&o.arguments.forEach((l,d)=>{l&&l.address&&(this.RebuildDependencies(s[d],r,i,void 0,a),s[d]={type:"missing",id:-1})}),s.forEach(l=>this.RebuildDependencies(l,r,i,n,a))}break}return n}UpdateLeafVertex(t,r,i){t.Reset();let n=this.parser.Parse(r);if(n.expression){let a=this.RebuildDependencies(n.expression,i.id,i.name,void 0,{row:0,column:0});for(let s of Object.keys(a.ranges)){let o=a.ranges[s];new y(o.start,o.end).Iterate(d=>{this.AddLeafVertexEdge(d,t)})}for(let s of Object.keys(a.addresses)){let o=a.addresses[s];this.AddLeafVertexEdge(o,t)}}t.expression=n.expression||{type:"missing",id:-1},t.expression_error=!n.valid}RebuildGraphCell(t,r){if(t.area&&t.area.start.column===r.column&&t.area.start.row===r.row){let{start:i,end:n}=t.area,a=i.sheet_id||r.sheet_id;i.sheet_id||(i.sheet_id=a);for(let s=i.column;s<=n.column;s++)for(let o=i.row;o<=n.row;o++)this.ResetInbound({column:s,row:o,sheet_id:a},!0,!1);this.SetDirty(r);for(let s=i.column;s<=n.column;s++)for(let o=i.row;o<=n.row;o++)o===i.row&&s===i.column||this.AddEdge(i,{...i,row:o,column:s})}if(t.type===1){this.ResetInbound(r,!0);let i=this.parser.Parse(t.value);if(i.expression){if(i.expression.type==="call"){let s=this.library.Get(i.expression.name);s&&(s.render||s.click)&&(t.render_function=s.render,t.click_function=s.click)}let a=this.RebuildDependencies(i.expression,r.sheet_id,"",void 0,r);for(let s of Object.keys(a.ranges)){let o=a.ranges[s],l=new y(o.start,o.end);l.entire_row||l.entire_column?this.AddArrayEdge(l,r):l.Iterate(d=>this.AddEdge(d,r))}for(let s of Object.keys(a.addresses)){let o=a.addresses[s];this.AddEdge(o,r)}}let n=this.GetVertex(r,!0);n&&(n.expression=i.expression||{type:"missing",id:-1},n.expression_error=!i.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 i=t.start.row;i<=t.end.row;i++){let n=r.data[i];if(n)for(let a=t.start.column;a<=t.end.column;a++){let s=n[a];s&&this.RebuildGraphCell(s,{row:i,column:a,sheet_id:t.start.sheet_id})}}}else for(let r of this.model.sheets.list||[]){let i=r.cells.data.length;for(let n=0;n<i;n++){let a=r.cells.data[n];if(a){let s=a.length;for(let o=0;o<s;o++){let l=a[o];l&&this.RebuildGraphCell(l,{row:n,column:o,sheet_id:r.id})}}}}}IsNativeOrTypedArray(t){return Array.isArray(t)||t instanceof Float64Array||t instanceof Float32Array}CheckVolatile(t){if(!t.expression||t.expression_error)return!1;let r=!1;return this.parser.Walk(t.expression,i=>{if(i.type==="call"){let n=this.library.Get(i.name);n&&n.volatile&&(r=!0)}return!r}),r}};var Yt=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 i of Array.from(r)){let n=i.dataset.bind;n&&(this.model[n]=i)}}if(this.model.about){let r=["<div>TREB version 28.2.3"];r.push("<small><a target=_blank href='https://treb.app'>http://treb.app</a></small>"),this.model.about.innerHTML=r.join(`
|
|
11
|
-
`)}this.model.close?.addEventListener("click",r=>{r.stopPropagation(),r.preventDefault(),this.HideDialog()})}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 Jt=class{constructor(e){this.container=e;let t=F.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 Pi={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"};var Re=class{constructor(e=0,t=0,r=100,i=100){this.left=e;this.top=t;this.right=r;this.bottom=i}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 ca="http://www.w3.org/2000/svg",R=(c,e={},t)=>{let r=document.createElementNS(ca,c);for(let i of Object.keys(e))if(e[i]!==void 0){let n=e[i];r.setAttribute(i,Array.isArray(n)?n.join(" "):n.toString())}return t&&(r.textContent=t),r},Xt=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=R("g"),this.group=R("g"),this.axis_group=R("g",{class:"axis-group"}),this.label_group=R("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=R("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=R("g");this.group.appendChild(t);let r=R("text");t.appendChild(r),t.setAttribute("class","legend");let i=[[]],n=10,a=e.area.width,s=0,o=0,l=e.area.width,d=e.style===1?14:26,h=e.labels.map((g,b)=>{r.textContent=g.label;let v=r.getBoundingClientRect(),_={width:v.width,height:v.height},w=_.width+d+n;return o=Math.max(o,_.height),e.layout===1?i[b]=[b]:w>a?i[s].length===0?(i[s].push(b),s++,i[s]=[],a=l):(s++,i[s]=[b],a=l-w):(i[s].push(b),a-=w),_});t.removeChild(r);let u=o,m=e.layout||0;m===0&&i.every(g=>g.length<=1)&&(m=0);for(let g=0;g<i.length;g++){let b=i[g].reduce((w,x)=>w+h[x].width+d,(i[g].length-1)*n),v=0,_=m===0?Math.round((l-b)/2):Math.round(n/2);for(let w=0;w<i[g].length;w++){let x=i[g][w],A=h[x],k=e.labels[x],S=u-1,M=!1;typeof navigator<"u"&&(M=/trident/i.test(navigator?.userAgent||""));let U=typeof k.index=="number"?k.index:x+1;t.appendChild(R("text",{"dominant-baseline":"middle",x:_+d,y:u,dy:M?".3em":void 0},k.label)),e.style===1?t.appendChild(R("rect",{class:`series-${U}`,x:_,y:S-4,width:8,height:8})):t.appendChild(R("rect",{class:`series-${U}`,x:_,y:S-1,width:d-3,height:2})),v=Math.max(v,A.height),_+=A.width+d+n}u=Math.round(u+v*1.1)}let f=t.getBoundingClientRect(),p={width:f.width,height:f.height+o};switch(e.position){case 1:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.bottom-p.height})`);break;case 2:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`);break;case 3:t.setAttribute("transform",`translate(${e.area.right-p.width}, ${e.area.top})`);break;case 0:default:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`)}e.position===0?e.area.top+=p.height||0:e.position===3?e.area.right-=(p.width||0)+8:e.position===2?e.area.left+=(p.width||0)+8:e.area.bottom-=p.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.parent.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,i){let n=R("text",{class:"chart-title",x:Math.round(t.width/2)},e);n.style.textAnchor="middle",this.group.appendChild(n);let a=n.getBoundingClientRect();switch(i){case"bottom":n.setAttribute("y",Math.round(t.bottom-a.height).toString()),t.bottom-=a.height+r;break;default:n.setAttribute("y",Math.round(t.top+r+a.height).toString()),t.top+=a.height+r;break}}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=R("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 i=this.text_measurement_node.getBoundingClientRect(),n={width:i.width,height:i.height,y_offset:i.height-(this.bounds.top-i.top-100)};return r&&(n.width=Math.ceil(n.width),n.height=Math.ceil(n.height),n.y_offset=Math.ceil(n.y_offset)),n}RenderTicks(e,t,r,i,n){let a=[],s=e.width/i;for(let o=0;o<i;o++){let l=Math.round(e.left+s/2+s*o)-.5;a.push(`M${l} ${t} L${l} ${r}`)}this.group.appendChild(R("path",{d:a,class:n}))}RenderXAxisBar(e,t,r,i,n){let a=r.length;if(!a)return;let s=4,o=t?e.width/a:e.width/(a-1),l=t?o/2:0,d=1,h=!0;for(;h;){h=!1;let u=0;for(let m=0;m<a;m+=d){let f=Math.round(e.left+l+o*m),p=f-i[m].width/2;if(u&&p<=u){d++,h=!0;break}u=f+i[m].width/2+s}}for(let u=0;u<a;u+=d){let m=Math.round(e.left+l+o*u);this.RenderText(this.axis_group,r[u],"center",{x:m,y:e.bottom},n)}}RenderXAxisTicks(e,t,r){let i=t?e.width/r:e.width/(r-1),n=t?i/2:0,a=[];for(let s=0;s<r;s++){let o=Math.round(e.left+n+i*s)+.5;a.push(`M${o},${e.bottom+.5} v6`)}this.axis_group.appendChild(R("path",{d:a.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,i,n){let a=r.length;if(!a)return;let s=4,o=t?e.width/a:e.width/(a-1),l=t?o/2:0,d=1,h=!0,u=(r.length-1)%2===0,m=(r.length-1)%3===0;for(;h;){h=!1;let f=0;for(let p=0;p<a;p+=d){let g=Math.round(e.left+l+o*p),b=g-i[p].width/2;if(f&&b<=f){d++,h=!0;break}f=g+i[p].width/2+s}}d===3&&!m&&u&&d++;for(let f=0;f<a;f+=d){let p=Math.round(e.left+l+o*f);this.RenderText(this.axis_group,r[f],"center",{x:p,y:e.bottom},n)}}RenderYAxisBar(e,t,r,i){r=r.slice(0),r.reverse();let n=r.length;if(!n)return;let a=e.height/n,s=1,o=!0;for(;o;){o=!1;let l=0;for(let d=0;d<n;d+=s){let h=r[d],u=Math.round(e.bottom-a*(d+.5)+h.metrics.height/4);if(l&&u>=l){s++,o=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=s){let d=r[l],h=Math.round(e.bottom-a*(l+.5)+d.metrics.height/4);this.RenderText(this.axis_group,d.label,"right",{x:t,y:h},i)}}RenderYAxis(e,t,r,i){let n=r.length;if(!n)return;let a=e.height/(n-1),s=1,o=!0;for(;o;){o=!1;let l=0;for(let d=0;d<n;d+=s){let h=r[d],u=Math.round(e.bottom-a*d+h.metrics.height/4);if(l&&u>=l){s++,o=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=s){let d=r[l],h=Math.round(e.bottom-a*l+d.metrics.height/4);this.RenderText(this.axis_group,d.label,"right",{x:t,y:h},i)}}LineProperties(e,t){let r=t.x-e.x,i=t.y-e.y;return{length:Math.sqrt(r*r+i*i),angle:Math.atan2(i,r)}}RenderSmoothLine(e,t,r=!1,i,n){let a=R("g"),s=[],o=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=t.map((g,b)=>{if(!(typeof g>"u"))return{x:Math.round(e.left+e.width/d*b),y:e.bottom-g}}),f=[],p=()=>{if(f.length<2)return;let g="",b=f[0],v=f[f.length-1];f.length===2?g=`${f[0].x},${f[0].y} L${f[1].x},${f[1].y}`:f.length>2&&(g=""+this.CatmullRomChain(f).map(w=>`${w.x},${w.y}`).join(" L")),g&&(s.push("M"+g),r&&(o.push(`M ${b.x},${e.bottom} L ${b.x},${b.y}`),o.push("L"+g),o.push(`L ${v.x},${e.bottom}`)))};for(let g of m)g?f.push(g):(p(),f=[]);if(f.length&&p(),r&&a.appendChild(R("path",{class:"fill",d:o})),a.appendChild(R("path",{class:"line",d:s})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),a.setAttribute("class",n.join(" "))),this.group.appendChild(a),i&&u.length){let g=R("g");for(let b of u){let v=R("circle",{cx:b.x,cy:b.y,r:h});v.addEventListener("mouseenter",_=>{this.parent.setAttribute("title",i[b.i]||"")}),v.addEventListener("mouseleave",_=>{this.parent.setAttribute("title","")}),g.appendChild(v)}g.setAttribute("class","mouse-layer"),this.group.appendChild(g)}}RenderLine(e,t,r=!1,i,n){let a=R("g"),s=[],o=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=0,f=!0,p;for(;m<l;m++){let g=t[m];if(typeof g>"u"){f=!0,r&&typeof p<"u"&&o.push(`L${p} ${e.bottom}Z`),p=void 0;continue}let b=Math.round(+e.left+e.width/d*m);f?(r&&o.push(`M${b} ${e.bottom} L${b} ${e.bottom-g}`),s.push(`M${b} ${e.bottom-g}`)):(s.push(`L${b} ${e.bottom-g}`),o.push(`L${b} ${e.bottom-g}`)),u.push({x:b,y:e.bottom-g,i:m}),p=b,f=!1}if(r&&typeof p<"u"&&o.push(`L${p} ${e.bottom}Z`),r&&a.appendChild(R("path",{class:"fill",d:o})),a.appendChild(R("path",{class:"line",d:s})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),a.setAttribute("class",n.join(" "))),this.group.appendChild(a),i&&u.length){let g=R("g");for(let b of u){let v=R("circle",{cx:b.x,cy:b.y,r:h});v.addEventListener("mouseenter",_=>{this.parent.setAttribute("title",i[b.i]||"")}),v.addEventListener("mouseleave",_=>{this.parent.setAttribute("title","")}),g.appendChild(v)}g.setAttribute("class","mouse-layer"),this.group.appendChild(g)}}RenderBarGrid(e,t,r){let i=[],n=e.width/t;for(let a=0;a<=t;a++){let s=Math.round(e.left+n*a)-.5;i.push(`M${s} ${e.top} L${s} ${e.bottom}`)}this.group.appendChild(R("path",{d:i,class:r}))}RenderGrid(e,t,r=0,i){let n=[],a=e.height/t;for(let s=0;s<=t;s++){let o=Math.round(e.top+a*s)-.5;n.push(`M${e.left} ${o} L${e.right} ${o}`)}a=e.width/(r-1);for(let s=0;s<r;s++){let o=Math.round(e.left+a*s)-.5;n.push(`M${o} ${e.top} L${o} ${e.bottom}`)}this.group.appendChild(R("path",{d:n,class:i}))}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 i=(h,u,m)=>{let{x:f,y:p}=u,{x:g,y:b}=m;return((g-f)**2+(b-p)**2)**r+h},n=0,a=i(n,e[0],e[1]),s=i(a,e[1],e[2]),o=i(s,e[2],e[3]),l=(s-a)/t,d=[];for(let h=0;h<t;h++){let u=a+l*h,m=this.AddPoints(this.MultiplyPoint(e[0],(a-u)/(a-n)),this.MultiplyPoint(e[1],(u-n)/(a-n))),f=this.AddPoints(this.MultiplyPoint(e[1],(s-u)/(s-a)),this.MultiplyPoint(e[2],(u-a)/(s-a))),p=this.AddPoints(this.MultiplyPoint(e[2],(o-u)/(o-s)),this.MultiplyPoint(e[3],(u-s)/(o-s))),g=this.AddPoints(this.MultiplyPoint(m,(s-u)/(s-n)),this.MultiplyPoint(f,(u-n)/(s-n))),b=this.AddPoints(this.MultiplyPoint(f,(o-u)/(o-a)),this.MultiplyPoint(p,(u-a)/(o-a))),v=this.AddPoints(this.MultiplyPoint(g,(s-u)/(s-a)),this.MultiplyPoint(b,(u-a)/(s-a)));d.push(v)}return d}CatmullRomChain(e,t=30){let r=e.slice(0),i=[],n=r.length;if(n){let a=r[n-1].x-r[n-2].x,s=r[n-1].y-r[n-2].y;r.push({x:r[n-1].x+a,y:r[n-1].y+s}),r.push({x:r[n-1].x+a,y:r[n-1].y+s}),a=r[1].x-r[0].x,s=r[1].y-r[0].y,r.unshift({x:r[0].x-a,y:r[0].y-s});for(let o=0;o<r.length-4;o++){let l=r.slice(o,o+4),d=this.CatmullRomSpline(l,t);i.push(...d)}}return i}RenderDataLabels(e,t,r,i,n,a,s){let o=Math.max(t.length,r.length),l=i.max-i.min||1,d=n.max-n.min||1;for(let h=0;h<o;h++){let u=t[h],m=r[h];if(u!==void 0&&m!==void 0){let f={x:e.left+(u-i.min)/l*e.width,y:e.bottom-(m-n.min)/d*e.height},p=a[h];if(p){this.label_group.appendChild(R("circle",{class:"label-target",cx:f.x,cy:f.y,r:10}));let g=R("g",{class:"data-label",transform:`translate(${f.x+10},${f.y})`});this.label_group.appendChild(g);let b=R("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${s}`});g.appendChild(b);let v=R("text",{x:4,y:0},p);g.appendChild(v);let _=v.getBoundingClientRect(),w=_.height,x=_.width+8;x+15+f.x>=e.right&&(g.setAttribute("transform",`translate(${f.x-x-15},${f.y})`),b.setAttribute("cx",(x+15).toString()));let A=R("path",{d:`M0,5 h${x} v-${w} h-${x} Z`});g.insertBefore(A,v)}}}}RenderScatterSeries(e,t,r,i,n,a=!0,s=!1,o=!1,l=!1,d=!1,h){let u=Math.max(t.length,r.length),m=i.max-i.min||1,f=n.max-n.min||1,p=[],g=[],b=[],v=R("g",{class:h});this.group.appendChild(v);for(let _=0;_<u;_++){let w=t[_],x=r[_];typeof w>"u"||typeof x>"u"?p.push(void 0):p.push({x:e.left+(w-i.min)/m*e.width,y:e.bottom-(x-n.min)/f*e.height})}if(a){let _=[],w=d?()=>_.length===2?`${_[0].x},${_[0].y} L${_[1].x},${_[1].y}`:_.length>2?this.CatmullRomChain(_).map(A=>`${A.x},${A.y}`).join(" L"):"":()=>_.map(x=>`${x.x},${x.y}`).join(" L");for(let x of p)if(x)_.push(x);else{if(_.length>=2){let A=w();g.push("M"+A),b.push(`M${_[0].x},${e.bottom}L`+A+`L${_[_.length-1].x},${e.bottom}Z`)}_=[]}if(_.length>=2){let x=w();g.push("M"+x),b.push(`M${_[0].x},${e.bottom}L`+x+`L${_[_.length-1].x},${e.bottom}Z`)}}if(o&&v.appendChild(R("path",{d:b,class:"fill"})),a&&v.appendChild(R("path",{d:g,class:"line"})),s)for(let _ of p)_&&v.appendChild(R("circle",{cx:_.x,cy:_.y,r:1,class:"point"}));if(l)for(let _ of p)_&&v.appendChild(R("circle",{cx:_.x,cy:_.y,r:3,class:"marker"}))}RenderPoints(e,t,r,i){let n=[];for(let a=0;a<t.length;a++){let s=t[a]*e.width+e.left,o=e.bottom-r[a]*e.height;n.push(`M${s-1},${o-1} L${s+1},${o+1}`),n.push(`M${s-1},${o+1} L${s+1},${o-1}`)}this.group.appendChild(R("path",{d:n,class:i}))}RenderPoint(e,t,r){this.group.appendChild(R("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=R("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(R("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,i,n,a){let s="";if(t)if(t[0]&&t[0]===t[1]&&t[0]>=e.height){let l=t[0],d=t[0]-e.height,h=Math.sqrt(l*l-d*d);s=`M${e.left+e.width/2-h},${e.bottom} a${l},${l} 0 0 1 ${h*2},0 z`}else if(t[1]&&t[1]===t[2]&&t[1]>=e.width){let l=t[1],d=t[1]-e.width,h=Math.sqrt(l*l-d*d);s=`M${e.left},${e.top+e.height/2-h} a${l},${l} 0 0 1 0,${h*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 o=R("path",{d:s,class:r});if(i&&(o.addEventListener("mouseenter",l=>{this.parent.setAttribute("title",i)}),o.addEventListener("mouseleave",l=>{this.parent.setAttribute("title","")})),this.group.appendChild(o),n){this.label_group.appendChild(R("path",{class:"label-target",d:s}));let l=a||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},d=R("g",{class:"data-label",transform:`translate(${l.x},${l.y})`});this.label_group.appendChild(d);let h=R("text",{x:0,y:0},n);d.appendChild(h);let u=h.getBoundingClientRect(),m=u.height,f=u.width+8;l.y-u.height<4&&(l.y-=l.y-u.height-4,d.setAttribute("transform",`translate(${l.x},${l.y})`)),h.setAttribute("x",Math.floor(-u.width/2).toString());let p=Math.ceil(m*.125),g=R("rect",{rx:3,x:-f/2,y:Math.round(-m+p*2/3),width:f,height:m+p});d.insertBefore(g,h)}}RenderText(e,t,r,i,n){let a=R("text",{x:i.x,y:i.y,class:n},t);switch(r){case"right":a.style.textAnchor="end";break;case"center":a.style.textAnchor="middle";break;default:a.style.textAnchor="start";break}(e||this.group).appendChild(a)}RenderDonut(e,t,r,i,n,a,s){let o=-Math.PI/2,l=0;a&&(r*=.8,i*=.7);let d=(h,u,m)=>[Math.cos(m)*u+h.x,Math.sin(m)*u+h.y];for(let h of e){let u=h.title||"",m=h.percent,f=h.index,p=[],g=0,b=d.bind(0,t,r),v=d.bind(0,t,i);if(m>.5){g=o+m/2*Math.PI*2,l=o+m*Math.PI*2;let x=g-o,A=l-g;p.push(`M${b(o)}`,`A${r},${r},${x},0,1,${b(g)}`,`A${r},${r},${A},0,1,${b(l)}`,`L${v(l)}`,`A${i},${i},${A},0,0,${v(g)}`,`A${i},${i},${x},0,0,${v(o)}`,"Z")}else{l=o+m*Math.PI*2,g=(l-o)/2+o;let x=l-o;p.push(`M${b(o)}`,`A${r},${r},${x},0,1,${b(l)}`,`L${v(l)}`,`A${i},${i},${x},0,0,${v(o)}`,"Z")}let _=R("path",{d:p,class:typeof f>"u"?void 0:`series-${f}`});typeof f<"u"&&_.setAttribute("data-index",f.toString());let w=R("g",{class:s});if(w.appendChild(_),this.group.appendChild(w),m>=.05&&u){let x=r-i;p=[];let A=d(t,i+(r-i)/2+x,g);p.push(`M${d(t,i+(r-i)/2,g)}`),p.push(`L${A}`),w.appendChild(R("path",{d:p,class:"callout"}));let k=[],S=R("text",{class:"callout-label"});w.appendChild(S);let M=g+Math.PI/2,U=u;S.textContent=U;let W=S.getBoundingClientRect(),me={width:W.width,height:W.height},[ie,C]=A;ie+=me.height/2*Math.cos(g),C+=me.height/4+me.height/2*Math.sin(g);let K=!1;M>Math.PI?ie-me.width<=n.left&&(K=!0):ie+me.width>n.right&&(K=!0);let ne=/[\s-]/;if(K&&ne.test(U)){let J=-1,X=1,q=[];for(let z=0;z<U.length;z++)if(ne.test(U[z])){let Z=Math.abs(.5-z/U.length);Z<X&&(X=Z,J=z)}J>0&&(k.push(U.substr(0,J+1).trim()),k.push(U.substr(J+1).trim()))}if(k.length){let J=0,X=0,q=k.map(z=>{S.textContent=z,W=S.getBoundingClientRect();let Z={width:W.width,height:W.height};return X=Math.max(X,Z.width),{text:z,metrics:Z}});S.textContent="";for(let z of q){let Z=R("tspan");Z.textContent=z.text;let $i=M>Math.PI?ie-(X-z.metrics.width)/2:ie+(X-z.metrics.width)/2;Z.setAttribute("x",$i.toString()),Z.setAttribute("dy",J.toString()),S.appendChild(Z),J=z.metrics.height}}let ae=M>Math.PI?"end":"start";S.setAttribute("text-anchor",ae),S.setAttribute("x",ie.toString()),S.setAttribute("y",C.toString()),typeof f<"u"&&S.setAttribute("data-index",f.toString())}o=l}}};var O=class{static Scale(e,t,r=6.5,i,n){return Br(e,t,r,i,n)}static Range(e){let t,r;for(let n of e)typeof n>"u"||((typeof t>"u"||t>n)&&(t=n),(typeof r>"u"||r<n)&&(r=n));let i=typeof t>"u"||typeof r>"u"?0:r-t;return{min:t,max:r,range:i}}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 Vr="#,##0.00",ct=class{constructor(e=new Xt){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};margin={top:.025,left:.05,bottom:.025,right:.075};Initialize(e){this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.CreateColumnChart(r,"column");break;case"bar.chart":this.CreateColumnChart(r,"bar");break;case"line.chart":this.CreateLineChart(r,"line");break;case"area.chart":this.CreateLineChart(r,"area");break;case"donut.chart":case"pie.chart":this.CreateDonut(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.CreateScatterChart(r,"plot");break;case"scatter.line":this.CreateScatterChart(r,"line");break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}CreateColumnChart(e,t){let r=this.TransformSeriesData(e[0]),i=this.CommonData(r),n;if(e[1]){n=(e[1].type===8?O.Flatten(e[1].value):O.Flatten(e[1])).map(d=>d?d.type===5&&d.value.type==="metadata"?typeof d.value.value=="number"?I.Get(d.value.format||Vr).Format(d.value.value):d.value.value:typeof d.value=="number"?I.Get(d.format||Vr).Format(d.value):d.value:"");let l=r.reduce((d,h)=>Math.max(d,h.y.data.length),0);for(l<n.length&&(n=n.slice(0,l));l>n.length;)n.push("")}let a=e[2]?.toString()||void 0,s=e[3]?.toString()||void 0;if(this.chart_data={type:t,legend:i.legend,legend_style:1,series2:r,scale:i.y.scale,title:a,y_labels:t==="bar"?n:i.y.labels,x_labels:t==="bar"?i.y.labels:n},s){this.chart_data.round=/round/i.test(s),this.chart_data.data_labels=/labels/i.test(s);let o=s.match(/labels="(.*?)"/);o&&r?this.ApplyLabels(r,o[1],n):(o=s.match(/labels=([^\s\r\n,]+)(?:\W|$)/),o&&r&&this.ApplyLabels(r,o[1],n)),o=s.match(/class=([\w_-]+)(?:\W|$)/),o&&(this.chart_data.class_name=o[1])}}ReadSeries(e){let t={x:{data:[]},y:{data:[]}};if(e[3]&&typeof e[3]=="number"&&(t.index=e[3]),e[4]&&(t.subtype=e[4].toString()),e[0]){let r=O.Flatten(e[0]);typeof r[0]=="object"?t.label=r[0]?.value?.toString()||"":t.label=r[0].toString()}if(e[2]&&typeof e[2]=="object"&&e[2].type===8){let r=O.Flatten(e[2].value);if(t.y.data=r.map(i=>typeof i.value.value=="number"?i.value.value:void 0),r[0].value?.format){t.y.format=r[0].value?.format;let i=I.Get(t.y.format);t.y.labels=t.y.data.map(n=>n===void 0?void 0:i.Format(n))}}if(e[1]&&typeof e[1]=="object"&&e[1].type===8){let r=O.Flatten(e[1].value);t.x.data=r.map(i=>typeof i.value.value=="number"?i.value.value:void 0),r[0].value.format&&(t.x.format=r[0].value.format)}for(let r of[t.x,t.y])if(r.data.length){let i=r.data.filter(n=>n||n===0);r.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)}}return t}ArrayToSeries(e){let t={x:{data:[]},y:{data:[]}},r=O.Flatten(e.value);if(t.y.data=r.map((n,a)=>typeof n.value=="number"?n.value:typeof n.value.value?.real=="number"?(t.x.data[a]=n.value.value.real,n.value.value.imaginary):typeof n.value.value=="number"?n.value.value:void 0),r[0].value.format){t.y.format=r[0].value.format||"";let n=I.Get(t.y.format||"");t.y.labels=t.y.data.map(a=>a===void 0?void 0:n.Format(a))}let i=t.y.data.filter(n=>n||n===0);if(t.y.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)},t.x.data.length){let n=t.x.data.filter(a=>typeof a=="number");if(t.x.range={min:Math.min.apply(0,n),max:Math.max.apply(0,n)},r[0].value.format){t.x.format=r[0].value.format||"";let a=I.Get(t.x.format||"");t.x.labels=t.x.data.map(s=>s===void 0?void 0:a.Format(s))}}return t}TransformSeriesData(e,t){if(!e)return[];let r=[];if(e.type===5){if(e.key==="group"){if(Array.isArray(e.value)){for(let a of e.value)if(a&&typeof a=="object")if(a.key==="series"){let s=this.ReadSeries(a.value);r.push(s)}else a.type===8&&r.push(this.ArrayToSeries(a))}}else if(e.key==="series"){let a=this.ReadSeries(e.value);r.push(a)}}else e.type===8&&r.push(this.ArrayToSeries(e));let i,n=0;if(t?.type===8){let a=O.Flatten(t.value),s="0.00###";a[0]&&a[0].type===5&&(s=a[0].value.format);let o=a.map(d=>{if(d.type===3)return d.value;if(d.type===5)return d.value.value}),l=o.filter(d=>typeof d=="number");i={data:o,format:s,range:{min:Math.min.apply(0,l),max:Math.max.apply(0,l)}}}for(let a of r)n=Math.max(n,a.y.data.length),a.x.data.length&&(i||(i=a.x));if(!i){i={data:[],range:{min:0,max:Math.max(0,n-1)}};for(let a=0;a<n;a++)i.data.push(a)}for(let a of r)a.x.data.length||(a.x=i);return r}CommonData(e,t,r){let i="",n="";for(let b of e)b.y.format&&!n&&(n=b.y.format),b.x.format&&!i&&(i=b.x.format);let a;e.some(b=>b.label&&b.label.length>0)&&(a=e.map((b,v)=>({label:b.label||`Series ${v+1}`,index:typeof b.index=="number"?b.index:v+1})));let s=e.filter(b=>b.x.range),o=Math.min.apply(0,s.map(b=>b.x.range?.min||0)),l=Math.max.apply(0,s.map(b=>b.x.range?.max||0)),d=e.filter(b=>b.y.range),h=Math.min.apply(0,s.map(b=>b.y.range?.min||0)),u=Math.max.apply(0,s.map(b=>b.y.range?.max||0));typeof t<"u"&&(h=Math.min(h,t)),typeof r<"u"&&(u=Math.max(u,r));let m=O.Scale(o,l,7),f=O.Scale(h,u,7),p,g;if(i){p=[];let b=I.Get(i);for(let v=0;v<=m.count;v++)p.push(b.Format(m.min+v*m.step))}if(n){g=[];let b=I.Get(n);for(let v=0;v<=f.count;v++)g.push(b.Format(f.min+v*f.step))}return{x:{format:i,scale:m,labels:p},y:{format:n,scale:f,labels:g},legend:a}}CreateScatterChart(e,t="plot"){let r=this.TransformSeriesData(e[0]),i=this.CommonData(r),n=e[1]?.toString()||void 0,a=e[2]?.toString()||void 0;if(this.chart_data={legend:i.legend,style:t,type:"scatter2",series:r,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels,lines:t==="line",points:t==="plot"},a){this.chart_data.markers=/marker/i.test(a),this.chart_data.smooth=/smooth/i.test(a),this.chart_data.data_labels=/labels/i.test(a);let s=a.match(/labels="(.*?)"/);s&&this.chart_data.series?this.ApplyLabels(this.chart_data.series,s[1]):(s=a.match(/labels=([^\s\r\n,]+)(?:\W|$)/),s&&this.chart_data.series&&this.ApplyLabels(this.chart_data.series,s[1])),s=a.match(/class=([\w_-]+)(?:\W|$)/),s&&(this.chart_data.class_name=s[1])}}ApplyLabels(e,t,r){for(let i of e){let n={x:I.Get(i.x.format||""),y:I.Get(i.y.format||"")};i.y.labels=[];for(let a=0;a<i.y.data.length;a++){let s=r?r[a]:typeof i.x.data[a]=="number"?n.x.Format(i.x.data[a]):"",o=typeof i.y.data[a]=="number"?n.y.Format(i.y.data[a]):"";i.y.labels[a]=t.replace(/\bx\b/g,s).replace(/\by\b/g,o)}}}CreateLineChart(e,t){let r=this.TransformSeriesData(e[0],e[1]),i=this.CommonData(r,0,0),n=e[2]?.toString()||void 0,a=e[3]?.toString()||void 0;if(this.chart_data={legend:i.legend,type:"scatter2",series:r,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels,lines:!0,filled:t==="area"},a){this.chart_data.smooth=/smooth/i.test(a);let s=a.match(/class=([\w_-]+)(?:\W|$)/);s&&(this.chart_data.class_name=s[1])}}CreateDonut(e,t=!1){let r=e[0]?.type===8?e[0].value:e[0],i=O.Flatten(r),n=i.map(b=>typeof b.value.value=="number"?b.value.value:void 0),a=e[1]?.type===8?e[1].value:e[1],s=O.Flatten(a).map(b=>{if(b&&typeof b=="object"){let v=b.value?.value;return typeof v=="number"&&b.value?.format?I.Get(b.value?.format).Format(v):v?v.toString():""}else return b?b.toString():""});n=n.map(b=>b<0?(console.warn("pie/donut chart does not support negative values (omitted)"),0):b);let o=e[2]||"",l=0,d=n.map((b,v)=>(typeof b<"u"&&(l+=b),{value:b,label:s[v]||"",index:v+1,percent:0}));if(l)for(let b of d)b.percent=(b.value||0)/l;let h=i.length&&i[0].value?.format?i[0].value.format:"",u=I.Get(h||Vr),m=I.Get("percent");typeof e[4]>"u"&&e[1]&&(e[4]="label");let f=e[4]||"";if(f)for(let b of d){let v=u.Format(b.value||0),_=m.Format(b.percent);b.title=f.replace(/value%/ig,m.Format(b.value||0)).replace(/value/ig,v).replace(/percent/ig,_).replace(/label/ig,b.label||"").trim()}let p=(e[3]||"").toString().trim(),g=p.toUpperCase();if(g==="ASC"||g==="ASCENDING"||g==="INC")d.sort((b,v)=>(b.value||0)-(v.value||0));else if(g==="DESC"||g==="DESCENDING"||g==="DEC")d.sort((b,v)=>(v.value||0)-(b.value||0));else{let b=p.match(/sort=([\w]+)(?:\W|$)/i);b&&(g=b[1],/^(asc|inc)/i.test(g)?d.sort((v,_)=>(v.value||0)-(_.value||0)):/^(desc|dec)/i.test(g)&&d.sort((v,_)=>(_.value||0)-(v.value||0)))}if(this.chart_data={type:t?"pie":"donut",slices:d,title:o},p){let b=p.match(/class=([_-\w]+)(?:\W|$)/);b&&(this.chart_data.class_name=b[1])}}Resize(){this.renderer.Resize()}Update(){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(this.chart_data.class_name);let e=new Re(0,0,this.renderer.size.width,this.renderer.size.height),t={top:Math.round(e.height)*this.margin.top,bottom:Math.round(e.height)*this.margin.bottom,left:Math.round(e.width)*this.margin.left,right:Math.round(e.width)*this.margin.right},r=this.chart_data.title;if(r&&this.renderer.RenderTitle(r,e,t.top,this.chart_data.title_layout||"top"),e.top+=t.top,e.left+=t.left,e.bottom-=t.bottom,e.right-=t.right,this.chart_data.legend&&this.chart_data.legend.length){let i=0;this.chart_data.title&&(!this.chart_data.title_layout||this.chart_data.title_layout==="top")&&(i=1);let n=this.chart_data.legend_position||i;this.renderer.Legend({labels:this.chart_data.legend,position:n,style:this.chart_data.legend_style,layout:n===0||n===1?0:1,area:e})}if(this.chart_data.type==="histogram"||this.chart_data.type==="line"||this.chart_data.type==="area"||this.chart_data.type==="column"||this.chart_data.type==="histogram2"||this.chart_data.type==="bar"||this.chart_data.type==="scatter2"){let i=[],n=0;if(this.chart_data.x_labels&&this.chart_data.x_labels.length&&(i=this.chart_data.x_labels.map(a=>{let s=this.renderer.MeasureText(a,["axis-label","x-axis-label"],!0);return n=Math.max(n,s.height),s})),this.chart_data.y_labels&&this.chart_data.y_labels.length){let a=[],s=0,o=0,l=this.chart_data.type==="scatter2"?this.chart_data.y_scale:this.chart_data.scale,d=this.chart_data.type==="bar"?this.chart_data.y_labels.length:l.count+1;for(let h=0;h<d;h++){let u=this.renderer.MeasureText(this.chart_data.y_labels[h],["axis-label","y-axis-label"]);a.push({label:this.chart_data.y_labels[h],metrics:u}),s=Math.max(s,u.width),o=Math.max(o,u.height)}e.bottom=Math.round(e.bottom-o/2),e.top=Math.round(e.top+o/2),i.length&&(e.bottom-=n+t.bottom),this.chart_data.type==="bar"?this.renderer.RenderYAxisBar(e,e.left+s,a,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(e,e.left+s,a,["axis-label","y-axis-label"]),e.left+=s+t.left}if(i.length&&this.chart_data.x_labels&&this.chart_data.x_labels.length){let a=this.chart_data.type==="histogram2",s=this.chart_data.type!=="line"&&this.chart_data.type!=="area"&&this.chart_data.type!=="bar"&&this.chart_data.type!=="scatter2"&&this.chart_data.type!=="histogram2";a&&this.renderer.RenderXAxisTicks(e,s,this.chart_data.x_labels.length),this.chart_data.y_labels&&(e.bottom+=n+t.bottom),this.renderer.RenderXAxis(e,s,this.chart_data.x_labels,i,["axis-label","x-axis-label"]),e.bottom-=n+t.bottom}}switch(this.chart_data.type){case"scatter":this.renderer.RenderPoints(e,this.chart_data.x,this.chart_data.y,"mc mc-correlation series-1");break;case"scatter2":if(this.renderer.RenderGrid(e,this.chart_data.y_scale.count,this.chart_data.x_scale.count+1,"chart-grid"),this.chart_data.series){for(let i=0;i<this.chart_data.series.length;i++){let n=this.chart_data.series[i],a=!!this.chart_data.lines,s=!!this.chart_data.points;n.subtype==="plot"?(s=!0,a=!1):n.subtype==="line"&&(s=!1,a=!0);let o=typeof n.index=="number"?n.index:i+1;this.renderer.RenderScatterSeries(e,n.x.data,n.y.data,this.chart_data.x_scale,this.chart_data.y_scale,a,s,!!this.chart_data.filled,!!this.chart_data.markers,!!this.chart_data.smooth,`scatter-plot series-${o}`)}if(this.chart_data.data_labels)for(let i=0;i<this.chart_data.series.length;i++){let n=this.chart_data.series[i];n.y.labels&&this.renderer.RenderDataLabels(e,n.x.data,n.y.data,this.chart_data.x_scale,this.chart_data.y_scale,n.y.labels,i+1)}}break;case"pie":case"donut":{let i=Math.min(e.height,e.width)/2*.9,n=this.chart_data.type==="pie"?0:i*.8;this.renderer.RenderDonut(this.chart_data.slices,e.center,i,n,e,!0,"donut")}break;case"line":case"area":{let i=this.chart_data.scale;if(this.chart_data.series){let n=this.chart_data.x_scale?this.chart_data.x_scale.max:Math.max.apply(0,this.chart_data.series.map(o=>o.length)),a=this.chart_data.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(e,this.chart_data.scale.count,this.chart_data.x_scale?this.chart_data.x_scale.count+1:n,"chart-grid");let s=0;for(let o of this.chart_data.series){let l=o.map(h=>{if(!(typeof h>"u"))return O.ApplyScale(h,e.height,i)});if(l.length<n)for(let h=l.length;h<n;h++)l.push(void 0);let d=[this.chart_data.type==="area"?"chart-area":"chart-line",`series-${s+1}`];a.call(this.renderer,e,l,this.chart_data.type==="area",this.chart_data.titles,d),s++}}}break;case"bar":{let i;if(this.renderer.RenderBarGrid(e,this.chart_data.scale.count,"chart-grid"),this.chart_data.series2){let n=0,a=this.chart_data.series2.length;for(let u of this.chart_data.series2)n=Math.max(n,u.y.data.length);let s=e.height/n,o=.7;typeof this.chart_data.space=="number"&&(o=Math.max(0,Math.min(1,1-this.chart_data.space)));let l=s*(1-o)/2,d=(s-l*2)/a,h=0;if(this.chart_data.scale.min<0&&(h=O.ApplyScale(0,e.width,this.chart_data.scale)),this.chart_data.round){let u=Math.floor(d/2);i=[0,u,u,0]}for(let u=0;u<a;u++){let m=this.chart_data.series2[u],f=typeof m.index=="number"?m.index:u+1;for(let p=0;p<m.y.data.length;p++){let g=m.y.data[p];if(typeof g=="number"){let b=Math.round(e.top+p*s+l)+u*d,v=0,_=0,w=!1;h?g>0?(_=O.ApplyScale(g+this.chart_data.scale.min,e.width,this.chart_data.scale),v=e.left+h):(_=O.ApplyScale(this.chart_data.scale.min-g,e.width,this.chart_data.scale),v=e.left+h-_,w=!0):(_=O.ApplyScale(g,e.width,this.chart_data.scale),v=e.left);let x=void 0;_&&this.renderer.RenderRectangle(new Re(v,b,v+_,b+d),i,["chart-column",`series-${f}`],x||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(e,this.chart_data.scale.count,0,"chart-grid"),this.chart_data.series2){let i=0,n=this.chart_data.series2.length;for(let u of this.chart_data.series2)i=Math.max(i,u.y.data.length);let a=e.width/i,s=.7;typeof this.chart_data.space=="number"&&(s=Math.max(0,Math.min(1,1-this.chart_data.space)));let o=a*(1-s)/2,l=(a-o*2)/n,d=0;if(this.chart_data.scale.min<0&&(d=O.ApplyScale(0,e.height,this.chart_data.scale)),this.chart_data.callouts&&this.chart_data.x_scale){let u=this.chart_data.x_scale,m=this.chart_data.callouts.map((f,p)=>{let g=Math.round(e.left+O.ApplyScale(f.value,e.width,u))+.5;return{x1:g,y1:e.bottom-e.height,x2:g,y2:e.bottom,classes:`callout-${p+1}`}});this.renderer.RenderCalloutLines(m)}let h;if(this.chart_data.round){let u=Math.floor(l/2);h=[u,u,0,0]}for(let u=0;u<n;u++){let m=this.chart_data.series2[u],f=typeof m.index=="number"?m.index:u+1;for(let p=0;p<m.y.data.length;p++){let g=m.y.data[p];if(typeof g=="number"){let b=e.left+p*a+o+u*l,v=0,_=0,w=!1;d?g>0?(v=O.ApplyScale(g+this.chart_data.scale.min,e.height,this.chart_data.scale),_=e.bottom-v-d):(v=O.ApplyScale(this.chart_data.scale.min-g,e.height,this.chart_data.scale),_=e.bottom-d,w=!0):(v=O.ApplyScale(g,e.height,this.chart_data.scale),_=e.bottom-v);let x=void 0;if(v){let A=this.chart_data.data_labels&&m.y.labels?m.y.labels[p]:"",k={x:Math.round(b+l/2),y:Math.round(_-10)};this.renderer.RenderRectangle(new Re(b,_,b+l,_+v),h,["chart-column",`series-${f}`],x||void 0,A,k)}}}}}break;case"histogram":{this.renderer.RenderGrid(e,this.chart_data.scale.count,0,"chart-grid");let i=e.width/this.chart_data.count,n=this.chart_data.column_width,a=i*(1-n)/2;for(let s=0;s<this.chart_data.count;s++){let o=Math.round(e.left+s*i+a),l=i-a*2,d=O.ApplyScale(this.chart_data.bins[s],e.height,this.chart_data.scale),h=e.bottom-d,u=this.chart_data.titles?this.chart_data.titles[s]:void 0;this.renderer.RenderRectangle(new Re(o,h,o+l,h+d),void 0,"chart-column series-1",u||void 0)}}break}}IsCellData(e){return typeof e=="object"&&typeof e.address=="object"&&typeof e.address.row=="number"&&typeof e.address.column=="number"}};var Ie=(...c)=>({type:5,value:c,key:"arguments"}),Ur={Group:{arguments:[{name:"Array...",metadata:!0}],fn:(...c)=>({type:5,value:c,key:"group"})},Series:{arguments:[{name:"Label"},{name:"X",metadata:!0},{name:"Y",metadata:!0},{name:"index"},{name:"subtype"}],fn:(...c)=>({type:5,value:c,key:"series"})},"Bar.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Line.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Area.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Pie.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels"},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:Ie},"Donut.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels",metadata:!0},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:Ie},"Scatter.Line":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Scatter.Plot":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Column.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"Chart Title"}],fn:Ie}};var Fr={};Bi(Fr,{default:()=>Lr});var Lr='var hi=Object.create;var Kt=Object.defineProperty;var ui=Object.getOwnPropertyDescriptor;var fi=Object.getOwnPropertyNames;var mi=Object.getPrototypeOf,pi=Object.prototype.hasOwnProperty;var re=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var bi=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of fi(e))!pi.call(i,n)&&n!==t&&Kt(i,n,{get:()=>e[n],enumerable:!(r=ui(e,n))||r.enumerable});return i};var Ae=(i,e,t)=>(t=i!=null?hi(mi(i)):{},bi(e||!i||!i.__esModule?Kt(t,"default",{value:i,enumerable:!0}):t,i));var De=re(je=>{"use strict";je.byteLength=yi;je.toByteArray=_i;je.fromByteArray=vi;var ce=[],se=[],gi=typeof Uint8Array<"u"?Uint8Array:Array,yt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(xe=0,er=yt.length;xe<er;++xe)ce[xe]=yt[xe],se[yt.charCodeAt(xe)]=xe;var xe,er;se["-".charCodeAt(0)]=62;se["_".charCodeAt(0)]=63;function tr(i){var e=i.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=i.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function yi(i){var e=tr(i),t=e[0],r=e[1];return(t+r)*3/4-r}function xi(i,e,t){return(e+t)*3/4-t}function _i(i){var e,t=tr(i),r=t[0],n=t[1],s=new gi(xi(i,r,n)),o=0,a=n>0?r-4:r,l;for(l=0;l<a;l+=4)e=se[i.charCodeAt(l)]<<18|se[i.charCodeAt(l+1)]<<12|se[i.charCodeAt(l+2)]<<6|se[i.charCodeAt(l+3)],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=e&255;return n===2&&(e=se[i.charCodeAt(l)]<<2|se[i.charCodeAt(l+1)]>>4,s[o++]=e&255),n===1&&(e=se[i.charCodeAt(l)]<<10|se[i.charCodeAt(l+1)]<<4|se[i.charCodeAt(l+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function wi(i){return ce[i>>18&63]+ce[i>>12&63]+ce[i>>6&63]+ce[i&63]}function Ai(i,e,t){for(var r,n=[],s=e;s<t;s+=3)r=(i[s]<<16&16711680)+(i[s+1]<<8&65280)+(i[s+2]&255),n.push(wi(r));return n.join("")}function vi(i){for(var e,t=i.length,r=t%3,n=[],s=16383,o=0,a=t-r;o<a;o+=s)n.push(Ai(i,o,o+s>a?a:o+s));return r===1?(e=i[t-1],n.push(ce[e>>2]+ce[e<<4&63]+"==")):r===2&&(e=(i[t-2]<<8)+i[t-1],n.push(ce[e>>10]+ce[e>>4&63]+ce[e<<2&63]+"=")),n.join("")}});var Xe=re(de=>{"use strict";var ir=":A-Za-z_\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD",Fi=ir+"\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040",nr="["+ir+"]["+Fi+"]*",Ei=new RegExp("^"+nr+"$"),ki=function(i,e){let t=[],r=e.exec(i);for(;r;){let n=[];n.startIndex=e.lastIndex-r[0].length;let s=r.length;for(let o=0;o<s;o++)n.push(r[o]);t.push(n),r=e.exec(i)}return t},Wi=function(i){let e=Ei.exec(i);return!(e===null||typeof e>"u")};de.isExist=function(i){return typeof i<"u"};de.isEmptyObject=function(i){return Object.keys(i).length===0};de.merge=function(i,e,t){if(e){let r=Object.keys(e),n=r.length;for(let s=0;s<n;s++)t==="strict"?i[r[s]]=[e[r[s]]]:i[r[s]]=e[r[s]]}};de.getValue=function(i){return de.isExist(i)?i:""};de.isName=Wi;de.getAllMatches=ki;de.nameRegexp=nr});var Ct=re(cr=>{"use strict";var vt=Xe(),Ri={allowBooleanAttributes:!1,unpairedTags:[]};cr.validate=function(i,e){e=Object.assign({},Ri,e);let t=[],r=!1,n=!1;i[0]==="\\uFEFF"&&(i=i.substr(1));for(let s=0;s<i.length;s++)if(i[s]==="<"&&i[s+1]==="?"){if(s+=2,s=ar(i,s),s.err)return s}else if(i[s]==="<"){let o=s;if(s++,i[s]==="!"){s=or(i,s);continue}else{let a=!1;i[s]==="/"&&(a=!0,s++);let l="";for(;s<i.length&&i[s]!==">"&&i[s]!==" "&&i[s]!==" "&&i[s]!==`\n`&&i[s]!=="\\r";s++)l+=i[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!Li(l)){let h;return l.trim().length===0?h="Invalid space after \'<\'.":h="Tag \'"+l+"\' is an invalid name.",O("InvalidTag",h,ie(i,s))}let d=$i(i,s);if(d===!1)return O("InvalidAttr","Attributes for \'"+l+"\' have open quote.",ie(i,s));let c=d.value;if(s=d.index,c[c.length-1]==="/"){let h=s-c.length;c=c.substring(0,c.length-1);let u=lr(c,e);if(u===!0)r=!0;else return O(u.err.code,u.err.msg,ie(i,h+u.err.line))}else if(a)if(d.tagClosed){if(c.trim().length>0)return O("InvalidTag","Closing tag \'"+l+"\' can\'t have attributes or invalid starting.",ie(i,o));{let h=t.pop();if(l!==h.tagName){let u=ie(i,h.tagStartPos);return O("InvalidTag","Expected closing tag \'"+h.tagName+"\' (opened in line "+u.line+", col "+u.col+") instead of closing tag \'"+l+"\'.",ie(i,o))}t.length==0&&(n=!0)}}else return O("InvalidTag","Closing tag \'"+l+"\' doesn\'t have proper closing.",ie(i,s));else{let h=lr(c,e);if(h!==!0)return O(h.err.code,h.err.msg,ie(i,s-c.length+h.err.line));if(n===!0)return O("InvalidXml","Multiple possible root nodes found.",ie(i,s));e.unpairedTags.indexOf(l)!==-1||t.push({tagName:l,tagStartPos:o}),r=!0}for(s++;s<i.length;s++)if(i[s]==="<")if(i[s+1]==="!"){s++,s=or(i,s);continue}else if(i[s+1]==="?"){if(s=ar(i,++s),s.err)return s}else break;else if(i[s]==="&"){let h=zi(i,s);if(h==-1)return O("InvalidChar","char \'&\' is not expected.",ie(i,s));s=h}else if(n===!0&&!sr(i[s]))return O("InvalidXml","Extra text at the end",ie(i,s));i[s]==="<"&&s--}}else{if(sr(i[s]))continue;return O("InvalidChar","char \'"+i[s]+"\' is not expected.",ie(i,s))}if(r){if(t.length==1)return O("InvalidTag","Unclosed tag \'"+t[0].tagName+"\'.",ie(i,t[0].tagStartPos));if(t.length>0)return O("InvalidXml","Invalid \'"+JSON.stringify(t.map(s=>s.tagName),null,4).replace(/\\r?\\n/g,"")+"\' found.",{line:1,col:1})}else return O("InvalidXml","Start tag expected.",1);return!0};function sr(i){return i===" "||i===" "||i===`\n`||i==="\\r"}function ar(i,e){let t=e;for(;e<i.length;e++)if(i[e]=="?"||i[e]==" "){let r=i.substr(t,e-t);if(e>5&&r==="xml")return O("InvalidXml","XML declaration allowed only at the start of the document.",ie(i,e));if(i[e]=="?"&&i[e+1]==">"){e++;break}else continue}return e}function or(i,e){if(i.length>e+5&&i[e+1]==="-"&&i[e+2]==="-"){for(e+=3;e<i.length;e++)if(i[e]==="-"&&i[e+1]==="-"&&i[e+2]===">"){e+=2;break}}else if(i.length>e+8&&i[e+1]==="D"&&i[e+2]==="O"&&i[e+3]==="C"&&i[e+4]==="T"&&i[e+5]==="Y"&&i[e+6]==="P"&&i[e+7]==="E"){let t=1;for(e+=8;e<i.length;e++)if(i[e]==="<")t++;else if(i[e]===">"&&(t--,t===0))break}else if(i.length>e+9&&i[e+1]==="["&&i[e+2]==="C"&&i[e+3]==="D"&&i[e+4]==="A"&&i[e+5]==="T"&&i[e+6]==="A"&&i[e+7]==="["){for(e+=8;e<i.length;e++)if(i[e]==="]"&&i[e+1]==="]"&&i[e+2]===">"){e+=2;break}}return e}var Gi=\'"\',Mi="\'";function $i(i,e){let t="",r="",n=!1;for(;e<i.length;e++){if(i[e]===Gi||i[e]===Mi)r===""?r=i[e]:r!==i[e]||(r="");else if(i[e]===">"&&r===""){n=!0;break}t+=i[e]}return r!==""?!1:{value:t,index:e,tagClosed:n}}var Ui=new RegExp(`(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*([\'"])(([\\\\s\\\\S])*?)\\\\5)?`,"g");function lr(i,e){let t=vt.getAllMatches(i,Ui),r={};for(let n=0;n<t.length;n++){if(t[n][1].length===0)return O("InvalidAttr","Attribute \'"+t[n][2]+"\' has no space in starting.",Ee(t[n]));if(t[n][3]!==void 0&&t[n][4]===void 0)return O("InvalidAttr","Attribute \'"+t[n][2]+"\' is without value.",Ee(t[n]));if(t[n][3]===void 0&&!e.allowBooleanAttributes)return O("InvalidAttr","boolean attribute \'"+t[n][2]+"\' is not allowed.",Ee(t[n]));let s=t[n][2];if(!Bi(s))return O("InvalidAttr","Attribute \'"+s+"\' is an invalid name.",Ee(t[n]));if(!r.hasOwnProperty(s))r[s]=1;else return O("InvalidAttr","Attribute \'"+s+"\' is repeated.",Ee(t[n]))}return!0}function Vi(i,e){let t=/\\d/;for(i[e]==="x"&&(e++,t=/[\\da-fA-F]/);e<i.length;e++){if(i[e]===";")return e;if(!i[e].match(t))break}return-1}function zi(i,e){if(e++,i[e]===";")return-1;if(i[e]==="#")return e++,Vi(i,e);let t=0;for(;e<i.length;e++,t++)if(!(i[e].match(/\\w/)&&t<20)){if(i[e]===";")break;return-1}return e}function O(i,e,t){return{err:{code:i,msg:e,line:t.line||t,col:t.col}}}function Bi(i){return vt.isName(i)}function Li(i){return vt.isName(i)}function ie(i,e){let t=i.substring(0,e).split(/\\r?\\n/);return{line:t.length,col:t[t.length-1].length+1}}function Ee(i){return i.startIndex+i[1].length}});var hr=re(It=>{var dr={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(i,e){return e},attributeValueProcessor:function(i,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(i,e,t){return i}},Yi=function(i){return Object.assign({},dr,i)};It.buildOptions=Yi;It.defaultOptions=dr});var fr=re(($a,ur)=>{"use strict";var Nt=class{constructor(e){this.tagname=e,this.child=[],this[":@"]={}}add(e,t){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:t})}addChild(e){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child})}};ur.exports=Nt});var pr=re((Ua,mr)=>{var ji=Xe();function Di(i,e){let t={};if(i[e+3]==="O"&&i[e+4]==="C"&&i[e+5]==="T"&&i[e+6]==="Y"&&i[e+7]==="P"&&i[e+8]==="E"){e=e+9;let r=1,n=!1,s=!1,o="";for(;e<i.length;e++)if(i[e]==="<"&&!s){if(n&&Ji(i,e))e+=7,[entityName,val,e]=Hi(i,e+1),val.indexOf("&")===-1&&(t[Ki(entityName)]={regx:RegExp(`&${entityName};`,"g"),val});else if(n&&Xi(i,e))e+=8;else if(n&&Qi(i,e))e+=8;else if(n&&qi(i,e))e+=9;else if(Oi)s=!0;else throw new Error("Invalid DOCTYPE");r++,o=""}else if(i[e]===">"){if(s?i[e-1]==="-"&&i[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else i[e]==="["?n=!0:o+=i[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:t,i:e}}function Hi(i,e){let t="";for(;e<i.length&&i[e]!=="\'"&&i[e]!==\'"\';e++)t+=i[e];if(t=t.trim(),t.indexOf(" ")!==-1)throw new Error("External entites are not supported");let r=i[e++],n="";for(;e<i.length&&i[e]!==r;e++)n+=i[e];return[t,n,e]}function Oi(i,e){return i[e+1]==="!"&&i[e+2]==="-"&&i[e+3]==="-"}function Ji(i,e){return i[e+1]==="!"&&i[e+2]==="E"&&i[e+3]==="N"&&i[e+4]==="T"&&i[e+5]==="I"&&i[e+6]==="T"&&i[e+7]==="Y"}function Xi(i,e){return i[e+1]==="!"&&i[e+2]==="E"&&i[e+3]==="L"&&i[e+4]==="E"&&i[e+5]==="M"&&i[e+6]==="E"&&i[e+7]==="N"&&i[e+8]==="T"}function Qi(i,e){return i[e+1]==="!"&&i[e+2]==="A"&&i[e+3]==="T"&&i[e+4]==="T"&&i[e+5]==="L"&&i[e+6]==="I"&&i[e+7]==="S"&&i[e+8]==="T"}function qi(i,e){return i[e+1]==="!"&&i[e+2]==="N"&&i[e+3]==="O"&&i[e+4]==="T"&&i[e+5]==="A"&&i[e+6]==="T"&&i[e+7]==="I"&&i[e+8]==="O"&&i[e+9]==="N"}function Ki(i){if(ji.isName(i))return i;throw new Error(`Invalid entity name ${i}`)}mr.exports=Di});var gr=re((Va,br)=>{var en=/^[-+]?0x[a-fA-F0-9]+$/,tn=/^([\\-\\+])?(0*)(\\.[0-9]+([eE]\\-?[0-9]+)?|[0-9]+(\\.[0-9]+([eE]\\-?[0-9]+)?)?)$/;!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);var rn={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function nn(i,e={}){if(e=Object.assign({},rn,e),!i||typeof i!="string")return i;let t=i.trim();if(e.skipLike!==void 0&&e.skipLike.test(t))return i;if(e.hex&&en.test(t))return Number.parseInt(t,16);{let r=tn.exec(t);if(r){let n=r[1],s=r[2],o=sn(r[3]),a=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&n&&t[2]!==".")return i;if(!e.leadingZeros&&s.length>0&&!n&&t[1]!==".")return i;{let l=Number(t),d=""+l;return d.search(/[eE]/)!==-1||a?e.eNotation?l:i:t.indexOf(".")!==-1?d==="0"&&o===""||d===o||n&&d==="-"+o?l:i:s?o===d||n+o===d?l:i:t===d||t===n+d?l:i}}else return i}}function sn(i){return i&&i.indexOf(".")!==-1&&(i=i.replace(/0+$/,""),i==="."?i="0":i[0]==="."?i="0"+i:i[i.length-1]==="."&&(i=i.substr(0,i.length-1))),i}br.exports=nn});var xr=re((Ba,yr)=>{"use strict";var Pt=Xe(),ke=fr(),an=pr(),on=gr(),za="<((!\\\\[CDATA\\\\[([\\\\s\\\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\\\/)(NAME)\\\\s*>))([^<]*)".replace(/NAME/g,Pt.nameRegexp),St=class{constructor(e){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"\'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:\'"\'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"\\xA2"},pound:{regex:/&(pound|#163);/g,val:"\\xA3"},yen:{regex:/&(yen|#165);/g,val:"\\xA5"},euro:{regex:/&(euro|#8364);/g,val:"\\u20AC"},copyright:{regex:/&(copy|#169);/g,val:"\\xA9"},reg:{regex:/&(reg|#174);/g,val:"\\xAE"},inr:{regex:/&(inr|#8377);/g,val:"\\u20B9"}},this.addExternalEntities=ln,this.parseXml=fn,this.parseTextData=cn,this.resolveNameSpace=dn,this.buildAttributesMap=un,this.isItStopNode=gn,this.replaceEntitiesValue=pn,this.readStopNodeData=xn,this.saveTextToParentTag=bn,this.addChild=mn}};function ln(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:i[r]}}}function cn(i,e,t,r,n,s,o){if(i!==void 0&&(this.options.trimValues&&!r&&(i=i.trim()),i.length>0)){o||(i=this.replaceEntitiesValue(i));let a=this.options.tagValueProcessor(e,i,t,n,s);return a==null?i:typeof a!=typeof i||a!==i?a:this.options.trimValues?Zt(i,this.options.parseTagValue,this.options.numberParseOptions):i.trim()===i?Zt(i,this.options.parseTagValue,this.options.numberParseOptions):i}}function dn(i){if(this.options.removeNSPrefix){let e=i.split(":"),t=i.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(i=t+e[1])}return i}var hn=new RegExp(`([^\\\\s=]+)\\\\s*(=\\\\s*([\'"])([\\\\s\\\\S]*?)\\\\3)?`,"gm");function un(i,e,t){if(!this.options.ignoreAttributes&&typeof i=="string"){let r=Pt.getAllMatches(i,hn),n=r.length,s={};for(let o=0;o<n;o++){let a=this.resolveNameSpace(r[o][1]),l=r[o][4],d=this.options.attributeNamePrefix+a;if(a.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),d==="__proto__"&&(d="#__proto__"),l!==void 0){this.options.trimValues&&(l=l.trim()),l=this.replaceEntitiesValue(l);let c=this.options.attributeValueProcessor(a,l,e);c==null?s[d]=l:typeof c!=typeof l||c!==l?s[d]=c:s[d]=Zt(l,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[d]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){let o={};return o[this.options.attributesGroupName]=s,o}return s}}var fn=function(i){i=i.replace(/\\r\\n?/g,`\n`);let e=new ke("!xml"),t=e,r="",n="";for(let s=0;s<i.length;s++)if(i[s]==="<")if(i[s+1]==="/"){let a=we(i,">",s,"Closing Tag is not closed."),l=i.substring(s+2,a).trim();if(this.options.removeNSPrefix){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1))}this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&(r=this.saveTextToParentTag(r,t,n));let d=n.substring(n.lastIndexOf(".")+1);if(l&&this.options.unpairedTags.indexOf(l)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${l}>`);let c=0;d&&this.options.unpairedTags.indexOf(d)!==-1?(c=n.lastIndexOf(".",n.lastIndexOf(".")-1),this.tagsNodeStack.pop()):c=n.lastIndexOf("."),n=n.substring(0,c),t=this.tagsNodeStack.pop(),r="",s=a}else if(i[s+1]==="?"){let a=Tt(i,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,t,n),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){let l=new ke(a.tagName);l.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(l[":@"]=this.buildAttributesMap(a.tagExp,n,a.tagName)),this.addChild(t,l,n)}s=a.closeIndex+1}else if(i.substr(s+1,3)==="!--"){let a=we(i,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){let l=i.substring(s+4,a-2);r=this.saveTextToParentTag(r,t,n),t.add(this.options.commentPropName,[{[this.options.textNodeName]:l}])}s=a}else if(i.substr(s+1,2)==="!D"){let a=an(i,s);this.docTypeEntities=a.entities,s=a.i}else if(i.substr(s+1,2)==="!["){let a=we(i,"]]>",s,"CDATA is not closed.")-2,l=i.substring(s+9,a);if(r=this.saveTextToParentTag(r,t,n),this.options.cdataPropName)t.add(this.options.cdataPropName,[{[this.options.textNodeName]:l}]);else{let d=this.parseTextData(l,t.tagname,n,!0,!1,!0);d==null&&(d=""),t.add(this.options.textNodeName,d)}s=a+2}else{let a=Tt(i,s,this.options.removeNSPrefix),l=a.tagName,d=a.rawTagName,c=a.tagExp,h=a.attrExpPresent,u=a.closeIndex;this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&r&&t.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,t,n,!1));let p=t;if(p&&this.options.unpairedTags.indexOf(p.tagname)!==-1&&(t=this.tagsNodeStack.pop(),n=n.substring(0,n.lastIndexOf("."))),l!==e.tagname&&(n+=n?"."+l:l),this.isItStopNode(this.options.stopNodes,n,l)){let f="";if(c.length>0&&c.lastIndexOf("/")===c.length-1)s=a.closeIndex;else if(this.options.unpairedTags.indexOf(l)!==-1)s=a.closeIndex;else{let y=this.readStopNodeData(i,d,u+1);if(!y)throw new Error(`Unexpected end of ${d}`);s=y.i,f=y.tagContent}let g=new ke(l);l!==c&&h&&(g[":@"]=this.buildAttributesMap(c,n,l)),f&&(f=this.parseTextData(f,l,n,!0,h,!0,!0)),n=n.substr(0,n.lastIndexOf(".")),g.add(this.options.textNodeName,f),this.addChild(t,g,n)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){l[l.length-1]==="/"?(l=l.substr(0,l.length-1),n=n.substr(0,n.length-1),c=l):c=c.substr(0,c.length-1),this.options.transformTagName&&(l=this.options.transformTagName(l));let f=new ke(l);l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,n,l)),this.addChild(t,f,n),n=n.substr(0,n.lastIndexOf("."))}else{let f=new ke(l);this.tagsNodeStack.push(t),l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,n,l)),this.addChild(t,f,n),t=f}r="",s=u}}else r+=i[s];return e.child};function mn(i,e,t){let r=this.options.updateTag(e.tagname,t,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),i.addChild(e))}var pn=function(i){if(this.options.processEntities){for(let e in this.docTypeEntities){let t=this.docTypeEntities[e];i=i.replace(t.regx,t.val)}for(let e in this.lastEntities){let t=this.lastEntities[e];i=i.replace(t.regex,t.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){let t=this.htmlEntities[e];i=i.replace(t.regex,t.val)}i=i.replace(this.ampEntity.regex,this.ampEntity.val)}return i};function bn(i,e,t,r){return i&&(r===void 0&&(r=Object.keys(e.child).length===0),i=this.parseTextData(i,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),i!==void 0&&i!==""&&e.add(this.options.textNodeName,i),i=""),i}function gn(i,e,t){let r="*."+t;for(let n in i){let s=i[n];if(r===s||e===s)return!0}return!1}function yn(i,e,t=">"){let r,n="";for(let s=e;s<i.length;s++){let o=i[s];if(r)o===r&&(r="");else if(o===\'"\'||o==="\'")r=o;else if(o===t[0])if(t[1]){if(i[s+1]===t[1])return{data:n,index:s}}else return{data:n,index:s};else o===" "&&(o=" ");n+=o}}function we(i,e,t,r){let n=i.indexOf(e,t);if(n===-1)throw new Error(r);return n+e.length-1}function Tt(i,e,t,r=">"){let n=yn(i,e+1,r);if(!n)return;let s=n.data,o=n.index,a=s.search(/\\s/),l=s,d=!0;a!==-1&&(l=s.substr(0,a).replace(/\\s\\s*$/,""),s=s.substr(a+1));let c=l;if(t){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1),d=l!==n.data.substr(h+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:d,rawTagName:c}}function xn(i,e,t){let r=t,n=1;for(;t<i.length;t++)if(i[t]==="<")if(i[t+1]==="/"){let s=we(i,">",t,`${e} is not closed`);if(i.substring(t+2,s).trim()===e&&(n--,n===0))return{tagContent:i.substring(r,t),i:s};t=s}else if(i[t+1]==="?")t=we(i,"?>",t+1,"StopNode is not closed.");else if(i.substr(t+1,3)==="!--")t=we(i,"-->",t+3,"StopNode is not closed.");else if(i.substr(t+1,2)==="![")t=we(i,"]]>",t,"StopNode is not closed.")-2;else{let s=Tt(i,t,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&n++,t=s.closeIndex)}}function Zt(i,e,t){if(e&&typeof i=="string"){let r=i.trim();return r==="true"?!0:r==="false"?!1:on(i,t)}else return Pt.isExist(i)?i:""}yr.exports=St});var Ar=re(wr=>{"use strict";function _n(i,e){return _r(i,e)}function _r(i,e,t){let r,n={};for(let s=0;s<i.length;s++){let o=i[s],a=wn(o),l="";if(t===void 0?l=a:l=t+"."+a,a===e.textNodeName)r===void 0?r=o[a]:r+=""+o[a];else{if(a===void 0)continue;if(o[a]){let d=_r(o[a],e,l),c=vn(d,e);o[":@"]?An(d,o[":@"],l,e):Object.keys(d).length===1&&d[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?d=d[e.textNodeName]:Object.keys(d).length===0&&(e.alwaysCreateTextNode?d[e.textNodeName]="":d=""),n[a]!==void 0&&n.hasOwnProperty(a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(d)):e.isArray(a,l,c)?n[a]=[d]:n[a]=d}}}return typeof r=="string"?r.length>0&&(n[e.textNodeName]=r):r!==void 0&&(n[e.textNodeName]=r),n}function wn(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];if(r!==":@")return r}}function An(i,e,t,r){if(e){let n=Object.keys(e),s=n.length;for(let o=0;o<s;o++){let a=n[o];r.isArray(a,t+"."+a,!0,!0)?i[a]=[e[a]]:i[a]=e[a]}}}function vn(i,e){let{textNodeName:t}=e,r=Object.keys(i).length;return!!(r===0||r===1&&(i[t]||typeof i[t]=="boolean"||i[t]===0))}wr.prettify=_n});var Cr=re((Ya,vr)=>{var{buildOptions:Cn}=hr(),In=xr(),{prettify:Nn}=Ar(),Sn=Ct(),Ft=class{constructor(e){this.externalEntities={},this.options=Cn(e)}parse(e,t){if(typeof e!="string")if(e.toString)e=e.toString();else throw new Error("XML data is accepted in String or Bytes[] form.");if(t){t===!0&&(t={});let s=Sn.validate(e,t);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}let r=new In(this.options);r.addExternalEntities(this.externalEntities);let n=r.parseXml(e);return this.options.preserveOrder||n===void 0?n:Nn(n,this.options)}addEntity(e,t){if(t.indexOf("&")!==-1)throw new Error("Entity value can\'t have \'&\'");if(e.indexOf("&")!==-1||e.indexOf(";")!==-1)throw new Error("An entity must be set without \'&\' and \';\'. Eg. use \'#xD\' for \'
\'");if(t==="&")throw new Error("An entity with value \'&\' is not permitted");this.externalEntities[e]=t}};vr.exports=Ft});var Zr=re((ja,Tr)=>{var Tn=`\n`;function Zn(i,e){let t="";return e.format&&e.indentBy.length>0&&(t=Tn),Nr(i,e,"",t)}function Nr(i,e,t,r){let n="",s=!1;for(let o=0;o<i.length;o++){let a=i[o],l=Pn(a);if(l===void 0)continue;let d="";if(t.length===0?d=l:d=`${t}.${l}`,l===e.textNodeName){let f=a[l];Fn(d,e)||(f=e.tagValueProcessor(l,f),f=Sr(f,e)),s&&(n+=r),n+=f,s=!1;continue}else if(l===e.cdataPropName){s&&(n+=r),n+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,s=!1;continue}else if(l===e.commentPropName){n+=r+`<!--${a[l][0][e.textNodeName]}-->`,s=!0;continue}else if(l[0]==="?"){let f=Ir(a[":@"],e),g=l==="?xml"?"":r,y=a[l][0][e.textNodeName];y=y.length!==0?" "+y:"",n+=g+`<${l}${y}${f}?>`,s=!0;continue}let c=r;c!==""&&(c+=e.indentBy);let h=Ir(a[":@"],e),u=r+`<${l}${h}`,p=Nr(a[l],e,d,c);e.unpairedTags.indexOf(l)!==-1?e.suppressUnpairedNode?n+=u+">":n+=u+"/>":(!p||p.length===0)&&e.suppressEmptyNode?n+=u+"/>":p&&p.endsWith(">")?n+=u+`>${p}${r}</${l}>`:(n+=u+">",p&&r!==""&&(p.includes("/>")||p.includes("</"))?n+=r+e.indentBy+p+r:n+=p,n+=`</${l}>`),s=!0}return n}function Pn(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];if(i.hasOwnProperty(r)&&r!==":@")return r}}function Ir(i,e){let t="";if(i&&!e.ignoreAttributes)for(let r in i){if(!i.hasOwnProperty(r))continue;let n=e.attributeValueProcessor(r,i[r]);n=Sr(n,e),n===!0&&e.suppressBooleanAttributes?t+=` ${r.substr(e.attributeNamePrefix.length)}`:t+=` ${r.substr(e.attributeNamePrefix.length)}="${n}"`}return t}function Fn(i,e){i=i.substr(0,i.length-e.textNodeName.length-1);let t=i.substr(i.lastIndexOf(".")+1);for(let r in e.stopNodes)if(e.stopNodes[r]===i||e.stopNodes[r]==="*."+t)return!0;return!1}function Sr(i,e){if(i&&i.length>0&&e.processEntities)for(let t=0;t<e.entities.length;t++){let r=e.entities[t];i=i.replace(r.regex,r.val)}return i}Tr.exports=Zn});var Fr=re((Da,Pr)=>{"use strict";var En=Zr(),kn={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(i,e){return e},attributeValueProcessor:function(i,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("\'","g"),val:"'"},{regex:new RegExp(\'"\',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function pe(i){this.options=Object.assign({},kn,i),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Gn),this.processTextOrObjNode=Wn,this.options.format?(this.indentate=Rn,this.tagEndChar=`>\n`,this.newLine=`\n`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}pe.prototype.build=function(i){return this.options.preserveOrder?En(i,this.options):(Array.isArray(i)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(i={[this.options.arrayNodeName]:i}),this.j2x(i,0).val)};pe.prototype.j2x=function(i,e){let t="",r="";for(let n in i)if(Object.prototype.hasOwnProperty.call(i,n))if(typeof i[n]>"u")this.isAttribute(n)&&(r+="");else if(i[n]===null)this.isAttribute(n)?r+="":n[0]==="?"?r+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+n+"/"+this.tagEndChar;else if(i[n]instanceof Date)r+=this.buildTextValNode(i[n],n,"",e);else if(typeof i[n]!="object"){let s=this.isAttribute(n);if(s)t+=this.buildAttrPairStr(s,""+i[n]);else if(n===this.options.textNodeName){let o=this.options.tagValueProcessor(n,""+i[n]);r+=this.replaceEntitiesValue(o)}else r+=this.buildTextValNode(i[n],n,"",e)}else if(Array.isArray(i[n])){let s=i[n].length,o="";for(let a=0;a<s;a++){let l=i[n][a];typeof l>"u"||(l===null?n[0]==="?"?r+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+n+"/"+this.tagEndChar:typeof l=="object"?this.options.oneListGroup?o+=this.j2x(l,e+1).val:o+=this.processTextOrObjNode(l,n,e):o+=this.buildTextValNode(l,n,"",e))}this.options.oneListGroup&&(o=this.buildObjectNode(o,n,"",e)),r+=o}else if(this.options.attributesGroupName&&n===this.options.attributesGroupName){let s=Object.keys(i[n]),o=s.length;for(let a=0;a<o;a++)t+=this.buildAttrPairStr(s[a],""+i[n][s[a]])}else r+=this.processTextOrObjNode(i[n],n,e);return{attrStr:t,val:r}};pe.prototype.buildAttrPairStr=function(i,e){return e=this.options.attributeValueProcessor(i,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+i:" "+i+\'="\'+e+\'"\'};function Wn(i,e,t){let r=this.j2x(i,t+1);return i[this.options.textNodeName]!==void 0&&Object.keys(i).length===1?this.buildTextValNode(i[this.options.textNodeName],e,r.attrStr,t):this.buildObjectNode(r.val,e,r.attrStr,t)}pe.prototype.buildObjectNode=function(i,e,t,r){if(i==="")return e[0]==="?"?this.indentate(r)+"<"+e+t+"?"+this.tagEndChar:this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",n=""),(t||t==="")&&i.indexOf("<")===-1?this.indentate(r)+"<"+e+t+s+">"+i+n:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${i}-->`+this.newLine:this.indentate(r)+"<"+e+t+s+this.tagEndChar+i+this.indentate(r)+n}};pe.prototype.closeTag=function(i){let e="";return this.options.unpairedTags.indexOf(i)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${i}`,e};pe.prototype.buildTextValNode=function(i,e,t,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${i}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${i}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+t+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,i);return n=this.replaceEntitiesValue(n),n===""?this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+t+">"+n+"</"+e+this.tagEndChar}};pe.prototype.replaceEntitiesValue=function(i){if(i&&i.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){let t=this.options.entities[e];i=i.replace(t.regex,t.val)}return i};function Rn(i){return this.options.indentBy.repeat(i)}function Gn(i){return i.startsWith(this.options.attributeNamePrefix)&&i!==this.options.textNodeName?i.substr(this.attrPrefixLen):!1}Pr.exports=pe});var Et=re((Ha,Er)=>{"use strict";var Mn=Ct(),$n=Cr(),Un=Fr();Er.exports={XMLParser:$n,XMLValidator:Mn,XMLBuilder:Un}});var ni=re((cl,Xt)=>{var m={};typeof Xt=="object"&&(Xt.exports=m);m.parse=function(i,e){for(var t=m.bin.readUshort,r=m.bin.readUint,a=0,n={},s=new Uint8Array(i),o=s.length-4;r(s,o)!=101010256;)o--;var a=o;a+=4,a+=4;var l=t(s,a);a+=2;var d=t(s,a);a+=2;var c=r(s,a);a+=4;var h=r(s,a);a+=4,a=h;for(var u=0;u<l;u++){var p=r(s,a);a+=4,a+=4,a+=4,a+=4;var f=r(s,a);a+=4;var c=r(s,a);a+=4;var g=r(s,a);a+=4;var y=t(s,a),N=t(s,a+2),w=t(s,a+4);a+=6,a+=8;var x=r(s,a);a+=4,a+=y+N+w,m._readLocal(s,x,n,c,g,e)}return n};m._readLocal=function(i,e,t,r,n,s){var o=m.bin.readUshort,a=m.bin.readUint,l=a(i,e);e+=4;var d=o(i,e);e+=2;var c=o(i,e);e+=2;var h=o(i,e);e+=2;var u=a(i,e);e+=4;var p=a(i,e);e+=4,e+=8;var f=o(i,e);e+=2;var g=o(i,e);e+=2;var y=m.bin.readUTF8(i,e,f);if(e+=f,e+=g,s){t[y]={size:n,csize:r};return}var N=new Uint8Array(i.buffer,e);if(h==0)t[y]=new Uint8Array(N.buffer.slice(e,e+r));else if(h==8){var w=new Uint8Array(n);m.inflateRaw(N,w),t[y]=w}else throw"unknown compression method: "+h};m.inflateRaw=function(i,e){return m.F.inflate(i,e)};m.inflate=function(i,e){var t=i[0],r=i[1],n=t&15,s=t>>>4;return m.inflateRaw(new Uint8Array(i.buffer,i.byteOffset+2,i.length-6),e)};m.deflate=function(i,e){e==null&&(e={level:6});var t=0,r=new Uint8Array(50+Math.floor(i.length*1.1));r[t]=120,r[t+1]=156,t+=2,t=m.F.deflateRaw(i,r,t,e.level);var n=m.adler(i,0,i.length);return r[t+0]=n>>>24&255,r[t+1]=n>>>16&255,r[t+2]=n>>>8&255,r[t+3]=n>>>0&255,new Uint8Array(r.buffer,0,t+4)};m.deflateRaw=function(i,e){e==null&&(e={level:6});var t=new Uint8Array(50+Math.floor(i.length*1.1)),r=m.F.deflateRaw(i,t,r,e.level);return new Uint8Array(t.buffer,0,r)};m.encode=function(i,e){e==null&&(e=!1);var t=0,r=m.bin.writeUint,n=m.bin.writeUshort,s={};for(var o in i){var a=!m._noNeed(o)&&!e,l=i[o],d=m.crc.crc(l,0,l.length);s[o]={cpr:a,usize:l.length,crc:d,file:a?m.deflateRaw(l):l}}for(var o in s)t+=s[o].file.length+30+46+2*m.bin.sizeUTF8(o);t+=22;var c=new Uint8Array(t),h=0,u=[];for(var o in s){var p=s[o];u.push(h),h=m._writeHeader(c,h,o,p,0)}var f=0,g=h;for(var o in s){var p=s[o];u.push(h),h=m._writeHeader(c,h,o,p,1,u[f++])}var y=h-g;return r(c,h,101010256),h+=4,h+=4,n(c,h,f),h+=2,n(c,h,f),h+=2,r(c,h,y),h+=4,r(c,h,g),h+=4,h+=2,c.buffer};m._noNeed=function(i){var e=i.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(e)!=-1};m._writeHeader=function(i,e,t,r,n,s){var o=m.bin.writeUint,a=m.bin.writeUshort,l=r.file;o(i,e,n==0?67324752:33639248),e+=4,n==1&&(e+=2),a(i,e,20),e+=2,a(i,e,0),e+=2,a(i,e,r.cpr?8:0),e+=2,o(i,e,0),e+=4,o(i,e,r.crc),e+=4,o(i,e,l.length),e+=4,o(i,e,r.usize),e+=4,a(i,e,m.bin.sizeUTF8(t)),e+=2,a(i,e,0),e+=2,n==1&&(e+=2,e+=2,e+=6,o(i,e,s),e+=4);var d=m.bin.writeUTF8(i,e,t);return e+=d,n==0&&(i.set(l,e),e+=l.length),e};m.crc={table:function(){for(var i=new Uint32Array(256),e=0;e<256;e++){for(var t=e,r=0;r<8;r++)t&1?t=3988292384^t>>>1:t=t>>>1;i[e]=t}return i}(),update:function(i,e,t,r){for(var n=0;n<r;n++)i=m.crc.table[(i^e[t+n])&255]^i>>>8;return i},crc:function(i,e,t){return m.crc.update(4294967295,i,e,t)^4294967295}};m.adler=function(i,e,t){for(var r=1,n=0,s=e,o=e+t;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=i[s++],n+=r;r=r%65521,n=n%65521}return n<<16|r};m.bin={readUshort:function(i,e){return i[e]|i[e+1]<<8},writeUshort:function(i,e,t){i[e]=t&255,i[e+1]=t>>8&255},readUint:function(i,e){return i[e+3]*(256*256*256)+(i[e+2]<<16|i[e+1]<<8|i[e])},writeUint:function(i,e,t){i[e]=t&255,i[e+1]=t>>8&255,i[e+2]=t>>16&255,i[e+3]=t>>24&255},readASCII:function(i,e,t){for(var r="",n=0;n<t;n++)r+=String.fromCharCode(i[e+n]);return r},writeASCII:function(i,e,t){for(var r=0;r<t.length;r++)i[e+r]=t.charCodeAt(r)},pad:function(i){return i.length<2?"0"+i:i},readUTF8:function(i,e,t){for(var r="",n,s=0;s<t;s++)r+="%"+m.bin.pad(i[e+s].toString(16));try{n=decodeURIComponent(r)}catch{return m.bin.readASCII(i,e,t)}return n},writeUTF8:function(i,e,t){for(var r=t.length,n=0,s=0;s<r;s++){var o=t.charCodeAt(s);if(!(o&4294967295-128+1))i[e+n]=o,n++;else if(!(o&4294967295-2048+1))i[e+n]=192|o>>6,i[e+n+1]=128|o>>0&63,n+=2;else if(!(o&4294967295-65536+1))i[e+n]=224|o>>12,i[e+n+1]=128|o>>6&63,i[e+n+2]=128|o>>0&63,n+=3;else if(!(o&4294967295-(1<<21)+1))i[e+n]=240|o>>18,i[e+n+1]=128|o>>12&63,i[e+n+2]=128|o>>6&63,i[e+n+3]=128|o>>0&63,n+=4;else throw"e"}return n},sizeUTF8:function(i){for(var e=i.length,t=0,r=0;r<e;r++){var n=i.charCodeAt(r);if(!(n&4294967295-128+1))t++;else if(!(n&4294967295-2048+1))t+=2;else if(!(n&4294967295-65536+1))t+=3;else if(!(n&4294967295-(1<<21)+1))t+=4;else throw"e"}return t}};m.F={};m.F.deflateRaw=function(i,e,t,r){var n=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]],s=n[r],o=m.F.U,a=m.F._goodIndex,l=m.F._hash,d=m.F._putsE,c=0,h=t<<3,u=0,p=i.length;if(r==0){for(;c<p;){var f=Math.min(65535,p-c);d(e,h,c+f==p?1:0),h=m.F._copyExact(i,c,f,e,h+8),c+=f}return h>>>3}var g=o.lits,y=o.strt,N=o.prev,w=0,x=0,I=0,G=0,Y=0,k=0;p>2&&(k=m.F._hash(i,0),y[k]=0);var M=0,V=0;for(c=0;c<p;c++){if(Y=k,c+1<p-2){k=m.F._hash(i,c+1);var z=c+1&32767;N[z]=y[k],y[k]=z}if(u<=c){(w>14e3||x>26697)&&p-c>100&&(u<c&&(g[w]=c-u,w+=2,u=c),h=m.F._writeBlock(c==p-1||u==p?1:0,g,w,G,i,I,c-I,e,h),w=x=G=0,I=c);var U=0;c<p-2&&(U=m.F._bestMatch(i,c,N,Y,Math.min(s[2],p-c),s[3]));var f=U>>>16,X=U&65535;if(U!=0){var f=U>>>16,X=U&65535,J=a(f,o.of0);o.lhst[257+J]++;var B=a(X,o.df0);o.dhst[B]++,G+=o.exb[J]+o.dxb[B],g[w]=f<<23|c-u,g[w+1]=X<<16|J<<8|B,w+=2,u=c+f}else o.lhst[i[c]]++;x++}}for((I!=c||i.length==0)&&(u<c&&(g[w]=c-u,w+=2,u=c),h=m.F._writeBlock(1,g,w,G,i,I,c-I,e,h),w=0,x=0,w=x=G=0,I=c);h&7;)h++;return h>>>3};m.F._bestMatch=function(i,e,t,r,n,s){var o=e&32767,a=t[o],l=o-a+32768&32767;if(a==o||r!=m.F._hash(i,e-l))return 0;for(var d=0,c=0,h=Math.min(32767,e);l<=h&&--s!=0&&a!=o;){if(d==0||i[e+d]==i[e+d-l]){var u=m.F._howLong(i,e,l);if(u>d){if(d=u,c=l,d>=n)break;l+2<u&&(u=l+2);for(var p=0,f=0;f<u-2;f++){var g=e-l+f+32768&32767,y=t[g],N=g-y+32768&32767;N>p&&(p=N,a=g)}}}o=a,a=t[o],l+=o-a+32768&32767}return d<<16|c};m.F._howLong=function(i,e,t){if(i[e]!=i[e-t]||i[e+1]!=i[e+1-t]||i[e+2]!=i[e+2-t])return 0;var r=e,n=Math.min(i.length,e+258);for(e+=3;e<n&&i[e]==i[e-t];)e++;return e-r};m.F._hash=function(i,e){return(i[e]<<8|i[e+1])+(i[e+2]<<4)&65535};m.saved=0;m.F._writeBlock=function(i,e,t,r,n,s,o,a,l){var d=m.F.U,c=m.F._putsF,h=m.F._putsE,u,p,f,g,y,N,w,x,I;d.lhst[256]++,u=m.F.getTrees(),p=u[0],f=u[1],g=u[2],y=u[3],N=u[4],w=u[5],x=u[6],I=u[7];var G=(l+3&7?8-(l+3&7):0)+32+(o<<3),Y=r+m.F.contSize(d.fltree,d.lhst)+m.F.contSize(d.fdtree,d.dhst),k=r+m.F.contSize(d.ltree,d.lhst)+m.F.contSize(d.dtree,d.dhst);k+=14+3*w+m.F.contSize(d.itree,d.ihst)+(d.ihst[16]*2+d.ihst[17]*3+d.ihst[18]*7);for(var M=0;M<286;M++)d.lhst[M]=0;for(var M=0;M<30;M++)d.dhst[M]=0;for(var M=0;M<19;M++)d.ihst[M]=0;var V=G<Y&&G<k?0:Y<k?1:2;c(a,l,i),c(a,l+1,V),l+=3;var z=l;if(V==0){for(;l&7;)l++;l=m.F._copyExact(n,s,o,a,l)}else{var U,X;if(V==1&&(U=d.fltree,X=d.fdtree),V==2){m.F.makeCodes(d.ltree,p),m.F.revCodes(d.ltree,p),m.F.makeCodes(d.dtree,f),m.F.revCodes(d.dtree,f),m.F.makeCodes(d.itree,g),m.F.revCodes(d.itree,g),U=d.ltree,X=d.dtree,h(a,l,y-257),l+=5,h(a,l,N-1),l+=5,h(a,l,w-4),l+=4;for(var J=0;J<w;J++)h(a,l+J*3,d.itree[(d.ordr[J]<<1)+1]);l+=3*w,l=m.F._codeTiny(x,d.itree,a,l),l=m.F._codeTiny(I,d.itree,a,l)}for(var B=s,K=0;K<t;K+=2){for(var j=e[K],_=j>>>23,T=B+(j&(1<<23)-1);B<T;)l=m.F._writeLit(n[B++],U,a,l);if(_!=0){var Z=e[K+1],P=Z>>16,C=Z>>8&255,F=Z&255;l=m.F._writeLit(257+C,U,a,l),h(a,l,_-d.of0[C]),l+=d.exb[C],l=m.F._writeLit(F,X,a,l),c(a,l,P-d.df0[F]),l+=d.dxb[F],B+=_}}l=m.F._writeLit(256,U,a,l)}return l};m.F._copyExact=function(i,e,t,r,n){var s=n>>>3;return r[s]=t,r[s+1]=t>>>8,r[s+2]=255-r[s],r[s+3]=255-r[s+1],s+=4,r.set(new Uint8Array(i.buffer,e,t),s),n+(t+4<<3)};m.F.getTrees=function(){for(var i=m.F.U,e=m.F._hufTree(i.lhst,i.ltree,15),t=m.F._hufTree(i.dhst,i.dtree,15),r=[],n=m.F._lenCodes(i.ltree,r),s=[],o=m.F._lenCodes(i.dtree,s),a=0;a<r.length;a+=2)i.ihst[r[a]]++;for(var a=0;a<s.length;a+=2)i.ihst[s[a]]++;for(var l=m.F._hufTree(i.ihst,i.itree,7),d=19;d>4&&i.itree[(i.ordr[d-1]<<1)+1]==0;)d--;return[e,t,l,n,o,d,r,s]};m.F.getSecond=function(i){for(var e=[],t=0;t<i.length;t+=2)e.push(i[t+1]);return e};m.F.nonZero=function(i){for(var e="",t=0;t<i.length;t+=2)i[t+1]!=0&&(e+=(t>>1)+",");return e};m.F.contSize=function(i,e){for(var t=0,r=0;r<e.length;r++)t+=e[r]*i[(r<<1)+1];return t};m.F._codeTiny=function(i,e,t,r){for(var n=0;n<i.length;n+=2){var s=i[n],o=i[n+1];r=m.F._writeLit(s,e,t,r);var a=s==16?2:s==17?3:7;s>15&&(m.F._putsE(t,r,o,a),r+=a)}return r};m.F._lenCodes=function(i,e){for(var t=i.length;t!=2&&i[t-1]==0;)t-=2;for(var r=0;r<t;r+=2){var n=i[r+1],s=r+3<t?i[r+3]:-1,o=r+5<t?i[r+5]:-1,a=r==0?-1:i[r-1];if(n==0&&s==n&&o==n){for(var l=r+5;l+2<t&&i[l+2]==n;)l+=2;var d=Math.min(l+1-r>>>1,138);d<11?e.push(17,d-3):e.push(18,d-11),r+=d*2-2}else if(n==a&&s==n&&o==n){for(var l=r+5;l+2<t&&i[l+2]==n;)l+=2;var d=Math.min(l+1-r>>>1,6);e.push(16,d-3),r+=d*2-2}else e.push(n,0)}return t>>>1};m.F._hufTree=function(i,e,t){var r=[],n=i.length,s=e.length,o=0;for(o=0;o<s;o+=2)e[o]=0,e[o+1]=0;for(o=0;o<n;o++)i[o]!=0&&r.push({lit:o,f:i[o]});var a=r.length,l=r.slice(0);if(a==0)return 0;if(a==1){var d=r[0].lit,l=d==0?1:0;return e[(d<<1)+1]=1,e[(l<<1)+1]=1,1}r.sort(function(y,N){return y.f-N.f});var c=r[0],h=r[1],u=0,p=1,f=2;for(r[0]={lit:-1,f:c.f+h.f,l:c,r:h,d:0};p!=a-1;)u!=p&&(f==a||r[u].f<r[f].f)?c=r[u++]:c=r[f++],u!=p&&(f==a||r[u].f<r[f].f)?h=r[u++]:h=r[f++],r[p++]={lit:-1,f:c.f+h.f,l:c,r:h};var g=m.F.setDepth(r[p-1],0);for(g>t&&(m.F.restrictDepth(l,t,g),g=t),o=0;o<a;o++)e[(l[o].lit<<1)+1]=l[o].d;return g};m.F.setDepth=function(i,e){return i.lit!=-1?(i.d=e,e):Math.max(m.F.setDepth(i.l,e+1),m.F.setDepth(i.r,e+1))};m.F.restrictDepth=function(i,e,t){var r=0,n=1<<t-e,s=0;for(i.sort(function(a,l){return l.d==a.d?a.f-l.f:l.d-a.d}),r=0;r<i.length&&i[r].d>e;r++){var o=i[r].d;i[r].d=e,s+=n-(1<<t-o)}for(s=s>>>t-e;s>0;){var o=i[r].d;o<e?(i[r].d++,s-=1<<e-o-1):r++}for(;r>=0;r--)i[r].d==e&&s<0&&(i[r].d--,s++);s!=0&&console.log("debt left")};m.F._goodIndex=function(i,e){var t=0;return e[t|16]<=i&&(t|=16),e[t|8]<=i&&(t|=8),e[t|4]<=i&&(t|=4),e[t|2]<=i&&(t|=2),e[t|1]<=i&&(t|=1),t};m.F._writeLit=function(i,e,t,r){return m.F._putsF(t,r,e[i<<1]),r+e[(i<<1)+1]};m.F.inflate=function(i,e){var t=Uint8Array;if(i[0]==3&&i[1]==0)return e||new t(0);var r=m.F,n=r._bitsF,s=r._bitsE,o=r._decodeTiny,a=r.makeCodes,l=r.codes2map,d=r._get17,c=r.U,h=e==null;h&&(e=new t(i.length>>>2<<3));for(var u=0,p=0,f=0,g=0,y=0,N=0,w=0,x=0,I=0,G,Y;u==0;){if(u=n(i,I,1),p=n(i,I+1,2),I+=3,p==0){I&7&&(I+=8-(I&7));var k=(I>>>3)+4,M=i[k-4]|i[k-3]<<8;h&&(e=m.F._check(e,x+M)),e.set(new t(i.buffer,i.byteOffset+k,M),x),I=k+M<<3,x+=M;continue}if(h&&(e=m.F._check(e,x+(1<<17))),p==1&&(G=c.flmap,Y=c.fdmap,N=512-1,w=32-1),p==2){f=s(i,I,5)+257,g=s(i,I+5,5)+1,y=s(i,I+10,4)+4,I+=14;for(var V=I,z=0;z<38;z+=2)c.itree[z]=0,c.itree[z+1]=0;for(var U=1,z=0;z<y;z++){var X=s(i,I+z*3,3);c.itree[(c.ordr[z]<<1)+1]=X,X>U&&(U=X)}I+=3*y,a(c.itree,U),l(c.itree,U,c.imap),G=c.lmap,Y=c.dmap,I=o(c.imap,(1<<U)-1,f+g,i,I,c.ttree);var J=r._copyOut(c.ttree,0,f,c.ltree);N=(1<<J)-1;var B=r._copyOut(c.ttree,f,g,c.dtree);w=(1<<B)-1,a(c.ltree,J),l(c.ltree,J,G),a(c.dtree,B),l(c.dtree,B,Y)}for(;;){var K=G[d(i,I)&N];I+=K&15;var j=K>>>4;if(!(j>>>8))e[x++]=j;else{if(j==256)break;var _=x+j-254;if(j>264){var T=c.ldef[j-257];_=x+(T>>>3)+s(i,I,T&7),I+=T&7}var Z=Y[d(i,I)&w];I+=Z&15;var P=Z>>>4,C=c.ddef[P],F=(C>>>4)+n(i,I,C&15);for(I+=C&15,h&&(e=m.F._check(e,x+(1<<17)));x<_;)e[x]=e[x++-F],e[x]=e[x++-F],e[x]=e[x++-F],e[x]=e[x++-F];x=_}}}return e.length==x?e:e.slice(0,x)};m.F._check=function(i,e){var t=i.length;if(e<=t)return i;var r=new Uint8Array(Math.max(t<<1,e));return r.set(i,0),r};m.F._decodeTiny=function(i,e,t,r,n,s){for(var o=m.F._bitsE,a=m.F._get17,l=0;l<t;){var d=i[a(r,n)&e];n+=d&15;var c=d>>>4;if(c<=15)s[l]=c,l++;else{var h=0,u=0;c==16?(u=3+o(r,n,2),n+=2,h=s[l-1]):c==17?(u=3+o(r,n,3),n+=3):c==18&&(u=11+o(r,n,7),n+=7);for(var p=l+u;l<p;)s[l]=h,l++}}return n};m.F._copyOut=function(i,e,t,r){for(var n=0,s=0,o=r.length>>>1;s<t;){var a=i[s+e];r[s<<1]=0,r[(s<<1)+1]=a,a>n&&(n=a),s++}for(;s<o;)r[s<<1]=0,r[(s<<1)+1]=0,s++;return n};m.F.makeCodes=function(i,e){for(var t=m.F.U,r=i.length,n,s,o,a,l,d=t.bl_count,a=0;a<=e;a++)d[a]=0;for(a=1;a<r;a+=2)d[i[a]]++;var c=t.next_code;for(n=0,d[0]=0,s=1;s<=e;s++)n=n+d[s-1]<<1,c[s]=n;for(o=0;o<r;o+=2)l=i[o+1],l!=0&&(i[o]=c[l],c[l]++)};m.F.codes2map=function(i,e,t){for(var r=i.length,n=m.F.U,s=n.rev15,o=0;o<r;o+=2)if(i[o+1]!=0)for(var a=o>>1,l=i[o+1],d=a<<4|l,c=e-l,h=i[o]<<c,u=h+(1<<c);h!=u;){var p=s[h]>>>15-e;t[p]=d,h++}};m.F.revCodes=function(i,e){for(var t=m.F.U.rev15,r=15-e,n=0;n<i.length;n+=2){var s=i[n]<<e-i[n+1];i[n]=t[s]>>>r}};m.F._putsE=function(i,e,t){t=t<<(e&7);var r=e>>>3;i[r]|=t,i[r+1]|=t>>>8};m.F._putsF=function(i,e,t){t=t<<(e&7);var r=e>>>3;i[r]|=t,i[r+1]|=t>>>8,i[r+2]|=t>>>16};m.F._bitsE=function(i,e,t){return(i[e>>>3]|i[(e>>>3)+1]<<8)>>>(e&7)&(1<<t)-1};m.F._bitsF=function(i,e,t){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16)>>>(e&7)&(1<<t)-1};m.F._get17=function(i,e){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16)>>>(e&7)};m.F._get25=function(i,e){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16|i[(e>>>3)+3]<<24)>>>(e&7)};m.F.U=function(){var i=Uint16Array,e=Uint32Array;return{next_code:new i(16),bl_count:new i(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new i(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new i(512),fltree:[],fdmap:new i(32),fdtree:[],lmap:new i(32768),ltree:[],ttree:[],dmap:new i(32768),dtree:[],imap:new i(512),itree:[],rev15:new i(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new i(65536),prev:new i(32768)}}();(function(){for(var i=m.F.U,e=32768,t=0;t<e;t++){var r=t;r=(r&2863311530)>>>1|(r&1431655765)<<1,r=(r&3435973836)>>>2|(r&858993459)<<2,r=(r&4042322160)>>>4|(r&252645135)<<4,r=(r&4278255360)>>>8|(r&16711935)<<8,i.rev15[t]=(r>>>16|r<<16)>>>17}function n(s,o,a){for(;o--!=0;)s.push(0,a)}for(var t=0;t<32;t++)i.ldef[t]=i.of0[t]<<3|i.exb[t],i.ddef[t]=i.df0[t]<<4|i.dxb[t];n(i.fltree,144,8),n(i.fltree,255-143,9),n(i.fltree,279-255,7),n(i.fltree,287-279,8),m.F.makeCodes(i.fltree,9),m.F.codes2map(i.fltree,9,i.flmap),m.F.revCodes(i.fltree,9),n(i.fdtree,32,5),m.F.makeCodes(i.fdtree,5),m.F.codes2map(i.fdtree,5,i.fdmap),m.F.revCodes(i.fdtree,5),n(i.itree,19,0),n(i.ltree,286,0),n(i.dtree,30,0),n(i.ttree,320,0)})()});var ai=Ae(De());var He=i=>{let e=Math.floor((i-5)/7*100+.5)/100;return Math.floor((e*7+5)/7*256)/256},xt=i=>Math.floor((256*i+Math.floor(18.285714285714285))/256*7);var rr="UEsDBAoAAAAAAAAAIQBi7p1okAQAAJAEAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbDw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxUeXBlcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9jb250ZW50LXR5cGVzIj48RGVmYXVsdCBFeHRlbnNpb249InJlbHMiIENvbnRlbnRUeXBlPSJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtcGFja2FnZS5yZWxhdGlvbnNoaXBzK3htbCIvPjxEZWZhdWx0IEV4dGVuc2lvbj0ieG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24veG1sIi8+PE92ZXJyaWRlIFBhcnROYW1lPSIveGwvd29ya2Jvb2sueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc2hlZXQubWFpbit4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii94bC93b3Jrc2hlZXRzL3NoZWV0MS54bWwiIENvbnRlbnRUeXBlPSJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtb2ZmaWNlZG9jdW1lbnQuc3ByZWFkc2hlZXRtbC53b3Jrc2hlZXQreG1sIi8+PE92ZXJyaWRlIFBhcnROYW1lPSIveGwvdGhlbWUvdGhlbWUxLnhtbCIgQ29udGVudFR5cGU9ImFwcGxpY2F0aW9uL3ZuZC5vcGVueG1sZm9ybWF0cy1vZmZpY2Vkb2N1bWVudC50aGVtZSt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii94bC9zdHlsZXMueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc3R5bGVzK3htbCIvPjxPdmVycmlkZSBQYXJ0TmFtZT0iL3hsL3NoYXJlZFN0cmluZ3MueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc2hhcmVkU3RyaW5ncyt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii9kb2NQcm9wcy9jb3JlLnhtbCIgQ29udGVudFR5cGU9ImFwcGxpY2F0aW9uL3ZuZC5vcGVueG1sZm9ybWF0cy1wYWNrYWdlLmNvcmUtcHJvcGVydGllcyt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii9kb2NQcm9wcy9hcHAueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LmV4dGVuZGVkLXByb3BlcnRpZXMreG1sIi8+PC9UeXBlcz5QSwMECgAAAAAAAAAhALVVMCNMAgAATAIAAAsAAABfcmVscy8ucmVsczw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxSZWxhdGlvbnNoaXBzIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvcGFja2FnZS8yMDA2L3JlbGF0aW9uc2hpcHMiPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDMiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvZXh0ZW5kZWQtcHJvcGVydGllcyIgVGFyZ2V0PSJkb2NQcm9wcy9hcHAueG1sIi8+PFJlbGF0aW9uc2hpcCBJZD0icklkMiIgVHlwZT0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzL21ldGFkYXRhL2NvcmUtcHJvcGVydGllcyIgVGFyZ2V0PSJkb2NQcm9wcy9jb3JlLnhtbCIvPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDEiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvb2ZmaWNlRG9jdW1lbnQiIFRhcmdldD0ieGwvd29ya2Jvb2sueG1sIi8+PC9SZWxhdGlvbnNoaXBzPlBLAwQKAAAAAAAAACEAunCeZsoGAADKBgAADwAAAHhsL3dvcmtib29rLnhtbDw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjx3b3JrYm9vayB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIiB4bWxuczpyPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzIiB4bWxuczptYz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL21hcmt1cC1jb21wYXRpYmlsaXR5LzIwMDYiIG1jOklnbm9yYWJsZT0ieDE1IHhyIHhyNiB4cjEwIHhyMiIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiIgeG1sbnM6eHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNC9yZXZpc2lvbiIgeG1sbnM6eHI2PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTYvcmV2aXNpb242IiB4bWxuczp4cjEwPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTYvcmV2aXNpb24xMCIgeG1sbnM6eHIyPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTUvcmV2aXNpb24yIj48ZmlsZVZlcnNpb24gYXBwTmFtZT0ieGwiIGxhc3RFZGl0ZWQ9IjciIGxvd2VzdEVkaXRlZD0iNyIgcnVwQnVpbGQ9IjIxMTI2Ii8+PHdvcmtib29rUHIgZGVmYXVsdFRoZW1lVmVyc2lvbj0iMTY2OTI1Ii8+PG1jOkFsdGVybmF0ZUNvbnRlbnQgeG1sbnM6bWM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9tYXJrdXAtY29tcGF0aWJpbGl0eS8yMDA2Ij48bWM6Q2hvaWNlIFJlcXVpcmVzPSJ4MTUiPjx4MTVhYzphYnNQYXRoIHVybD0iSDpcVFJFQlx0cmViLWV4cG9ydFx0ZW1wbGF0ZVwiIHhtbG5zOngxNWFjPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvYWMiLz48L21jOkNob2ljZT48L21jOkFsdGVybmF0ZUNvbnRlbnQ+PHhyOnJldmlzaW9uUHRyIHJldklETGFzdFNhdmU9IjAiIGRvY3VtZW50SWQ9Ijhfe0Q4NThGOUY3LTBEOTItNEFFNC04QTQyLTQ4MENCMzU5QjYyRH0iIHhyNjpjb2F1dGhWZXJzaW9uTGFzdD0iNDAiIHhyNjpjb2F1dGhWZXJzaW9uTWF4PSI0MCIgeHIxMDp1aWRMYXN0U2F2ZT0iezAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMH0iLz48Ym9va1ZpZXdzPjx3b3JrYm9va1ZpZXcgeFdpbmRvdz0iMCIgeVdpbmRvdz0iMCIgd2luZG93V2lkdGg9IjI0NTcwIiB3aW5kb3dIZWlnaHQ9IjExMTMwIiB4cjI6dWlkPSJ7REU0RTdEMzUtNDkyRC00MEQ3LTk5MjUtNDY0N0Y1ODdFMURFfSIvPjwvYm9va1ZpZXdzPjxzaGVldHM+PHNoZWV0IG5hbWU9IlNoZWV0MSIgc2hlZXRJZD0iMSIgcjppZD0icklkMSIvPjwvc2hlZXRzPjxjYWxjUHIgY2FsY0lkPSIxOTEwMjkiLz48ZXh0THN0PjxleHQgdXJpPSJ7MTQwQTcwOTQtMEUzNS00ODkyLTg0MzItQzREMkU1N0VERUI1fSIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiI+PHgxNTp3b3JrYm9va1ByIGNoYXJ0VHJhY2tpbmdSZWZCYXNlPSIxIi8+PC9leHQ+PC9leHRMc3Q+PC93b3JrYm9vaz5QSwMECgAAAAAAAAAhAIE+lJe6AgAAugIAABoAAAB4bC9fcmVscy93b3JrYm9vay54bWwucmVsczw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxSZWxhdGlvbnNoaXBzIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvcGFja2FnZS8yMDA2L3JlbGF0aW9uc2hpcHMiPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDMiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvc3R5bGVzIiBUYXJnZXQ9InN0eWxlcy54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQyIiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3RoZW1lIiBUYXJnZXQ9InRoZW1lL3RoZW1lMS54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQxIiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3dvcmtzaGVldCIgVGFyZ2V0PSJ3b3Jrc2hlZXRzL3NoZWV0MS54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQ0IiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3NoYXJlZFN0cmluZ3MiIFRhcmdldD0ic2hhcmVkU3RyaW5ncy54bWwiLz48L1JlbGF0aW9uc2hpcHM+UEsDBAoAAAAAAAAAIQACrURzpAMAAKQDAAAYAAAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHdvcmtzaGVldCB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIiB4bWxuczpyPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzIiB4bWxuczptYz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL21hcmt1cC1jb21wYXRpYmlsaXR5LzIwMDYiIG1jOklnbm9yYWJsZT0ieDE0YWMgeHIgeHIyIHhyMyIgeG1sbnM6eDE0YWM9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAwOS85L2FjIiB4bWxuczp4cj0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDE0L3JldmlzaW9uIiB4bWxuczp4cjI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNS9yZXZpc2lvbjIiIHhtbG5zOnhyMz0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDE2L3JldmlzaW9uMyIgeHI6dWlkPSJ7MEQ4RTVDQTItNUM5RS00RDRCLTk0QzUtRjM1QzA0MUYzOUJEfSI+PGRpbWVuc2lvbiByZWY9IkExIi8+PHNoZWV0Vmlld3M+PHNoZWV0VmlldyB0YWJTZWxlY3RlZD0iMSIgd29ya2Jvb2tWaWV3SWQ9IjAiLz48L3NoZWV0Vmlld3M+PHNoZWV0Rm9ybWF0UHIgZGVmYXVsdFJvd0hlaWdodD0iMTUiIHgxNGFjOmR5RGVzY2VudD0iMC4yNSIvPjxzaGVldERhdGEvPjxwYWdlTWFyZ2lucyBsZWZ0PSIwLjciIHJpZ2h0PSIwLjciIHRvcD0iMC43NSIgYm90dG9tPSIwLjc1IiBoZWFkZXI9IjAuMyIgZm9vdGVyPSIwLjMiLz48L3dvcmtzaGVldD5QSwMECgAAAAAAAAAhAMEXEL7GIAAAxiAAABMAAAB4bC90aGVtZS90aGVtZTEueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPGE6dGhlbWUgeG1sbnM6YT0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL2RyYXdpbmdtbC8yMDA2L21haW4iIG5hbWU9Ik9mZmljZSBUaGVtZSI+PGE6dGhlbWVFbGVtZW50cz48YTpjbHJTY2hlbWUgbmFtZT0iT2ZmaWNlIj48YTpkazE+PGE6c3lzQ2xyIHZhbD0id2luZG93VGV4dCIgbGFzdENscj0iMDAwMDAwIi8+PC9hOmRrMT48YTpsdDE+PGE6c3lzQ2xyIHZhbD0id2luZG93IiBsYXN0Q2xyPSJGRkZGRkYiLz48L2E6bHQxPjxhOmRrMj48YTpzcmdiQ2xyIHZhbD0iNDQ1NDZBIi8+PC9hOmRrMj48YTpsdDI+PGE6c3JnYkNsciB2YWw9IkU3RTZFNiIvPjwvYTpsdDI+PGE6YWNjZW50MT48YTpzcmdiQ2xyIHZhbD0iNDQ3MkM0Ii8+PC9hOmFjY2VudDE+PGE6YWNjZW50Mj48YTpzcmdiQ2xyIHZhbD0iRUQ3RDMxIi8+PC9hOmFjY2VudDI+PGE6YWNjZW50Mz48YTpzcmdiQ2xyIHZhbD0iQTVBNUE1Ii8+PC9hOmFjY2VudDM+PGE6YWNjZW50ND48YTpzcmdiQ2xyIHZhbD0iRkZDMDAwIi8+PC9hOmFjY2VudDQ+PGE6YWNjZW50NT48YTpzcmdiQ2xyIHZhbD0iNUI5QkQ1Ii8+PC9hOmFjY2VudDU+PGE6YWNjZW50Nj48YTpzcmdiQ2xyIHZhbD0iNzBBRDQ3Ii8+PC9hOmFjY2VudDY+PGE6aGxpbms+PGE6c3JnYkNsciB2YWw9IjA1NjNDMSIvPjwvYTpobGluaz48YTpmb2xIbGluaz48YTpzcmdiQ2xyIHZhbD0iOTU0RjcyIi8+PC9hOmZvbEhsaW5rPjwvYTpjbHJTY2hlbWU+PGE6Zm9udFNjaGVtZSBuYW1lPSJPZmZpY2UiPjxhOm1ham9yRm9udD48YTpsYXRpbiB0eXBlZmFjZT0iQ2FsaWJyaSBMaWdodCIgcGFub3NlPSIwMjBGMDMwMjAyMDIwNDAzMDIwNCIvPjxhOmVhIHR5cGVmYWNlPSIiLz48YTpjcyB0eXBlZmFjZT0iIi8+PGE6Zm9udCBzY3JpcHQ9IkpwYW4iIHR5cGVmYWNlPSLmuLjjgrTjgrfjg4Pjgq8gTGlnaHQiLz48YTpmb250IHNjcmlwdD0iSGFuZyIgdHlwZWZhY2U9IuunkeydgCDqs6DrlJUiLz48YTpmb250IHNjcmlwdD0iSGFucyIgdHlwZWZhY2U9Iuetiee6vyBMaWdodCIvPjxhOmZvbnQgc2NyaXB0PSJIYW50IiB0eXBlZmFjZT0i5paw57Sw5piO6auUIi8+PGE6Zm9udCBzY3JpcHQ9IkFyYWIiIHR5cGVmYWNlPSJUaW1lcyBOZXcgUm9tYW4iLz48YTpmb250IHNjcmlwdD0iSGViciIgdHlwZWZhY2U9IlRpbWVzIE5ldyBSb21hbiIvPjxhOmZvbnQgc2NyaXB0PSJUaGFpIiB0eXBlZmFjZT0iVGFob21hIi8+PGE6Zm9udCBzY3JpcHQ9IkV0aGkiIHR5cGVmYWNlPSJOeWFsYSIvPjxhOmZvbnQgc2NyaXB0PSJCZW5nIiB0eXBlZmFjZT0iVnJpbmRhIi8+PGE6Zm9udCBzY3JpcHQ9Ikd1anIiIHR5cGVmYWNlPSJTaHJ1dGkiLz48YTpmb250IHNjcmlwdD0iS2htciIgdHlwZWZhY2U9Ik1vb2xCb3JhbiIvPjxhOmZvbnQgc2NyaXB0PSJLbmRhIiB0eXBlZmFjZT0iVHVuZ2EiLz48YTpmb250IHNjcmlwdD0iR3VydSIgdHlwZWZhY2U9IlJhYXZpIi8+PGE6Zm9udCBzY3JpcHQ9IkNhbnMiIHR5cGVmYWNlPSJFdXBoZW1pYSIvPjxhOmZvbnQgc2NyaXB0PSJDaGVyIiB0eXBlZmFjZT0iUGxhbnRhZ2VuZXQgQ2hlcm9rZWUiLz48YTpmb250IHNjcmlwdD0iWWlpaSIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBZaSBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJUaWJ0IiB0eXBlZmFjZT0iTWljcm9zb2Z0IEhpbWFsYXlhIi8+PGE6Zm9udCBzY3JpcHQ9IlRoYWEiIHR5cGVmYWNlPSJNViBCb2xpIi8+PGE6Zm9udCBzY3JpcHQ9IkRldmEiIHR5cGVmYWNlPSJNYW5nYWwiLz48YTpmb250IHNjcmlwdD0iVGVsdSIgdHlwZWZhY2U9IkdhdXRhbWkiLz48YTpmb250IHNjcmlwdD0iVGFtbCIgdHlwZWZhY2U9IkxhdGhhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmMiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJPcnlhIiB0eXBlZmFjZT0iS2FsaW5nYSIvPjxhOmZvbnQgc2NyaXB0PSJNbHltIiB0eXBlZmFjZT0iS2FydGlrYSIvPjxhOmZvbnQgc2NyaXB0PSJMYW9vIiB0eXBlZmFjZT0iRG9rQ2hhbXBhIi8+PGE6Zm9udCBzY3JpcHQ9IlNpbmgiIHR5cGVmYWNlPSJJc2tvb2xhIFBvdGEiLz48YTpmb250IHNjcmlwdD0iTW9uZyIgdHlwZWZhY2U9Ik1vbmdvbGlhbiBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJWaWV0IiB0eXBlZmFjZT0iVGltZXMgTmV3IFJvbWFuIi8+PGE6Zm9udCBzY3JpcHQ9IlVpZ2giIHR5cGVmYWNlPSJNaWNyb3NvZnQgVWlnaHVyIi8+PGE6Zm9udCBzY3JpcHQ9Ikdlb3IiIHR5cGVmYWNlPSJTeWxmYWVuIi8+PGE6Zm9udCBzY3JpcHQ9IkFybW4iIHR5cGVmYWNlPSJBcmlhbCIvPjxhOmZvbnQgc2NyaXB0PSJCdWdpIiB0eXBlZmFjZT0iTGVlbGF3YWRlZSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJCb3BvIiB0eXBlZmFjZT0iTWljcm9zb2Z0IEpoZW5nSGVpIi8+PGE6Zm9udCBzY3JpcHQ9IkphdmEiIHR5cGVmYWNlPSJKYXZhbmVzZSBUZXh0Ii8+PGE6Zm9udCBzY3JpcHQ9Ikxpc3UiIHR5cGVmYWNlPSJTZWdvZSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJNeW1yIiB0eXBlZmFjZT0iTXlhbm1hciBUZXh0Ii8+PGE6Zm9udCBzY3JpcHQ9Ik5rb28iIHR5cGVmYWNlPSJFYnJpbWEiLz48YTpmb250IHNjcmlwdD0iT2xjayIgdHlwZWZhY2U9Ik5pcm1hbGEgVUkiLz48YTpmb250IHNjcmlwdD0iT3NtYSIgdHlwZWZhY2U9IkVicmltYSIvPjxhOmZvbnQgc2NyaXB0PSJQaGFnIiB0eXBlZmFjZT0iUGhhZ3NwYSIvPjxhOmZvbnQgc2NyaXB0PSJTeXJuIiB0eXBlZmFjZT0iRXN0cmFuZ2VsbyBFZGVzc2EiLz48YTpmb250IHNjcmlwdD0iU3lyaiIgdHlwZWZhY2U9IkVzdHJhbmdlbG8gRWRlc3NhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmUiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJTb3JhIiB0eXBlZmFjZT0iTmlybWFsYSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJUYWxlIiB0eXBlZmFjZT0iTWljcm9zb2Z0IFRhaSBMZSIvPjxhOmZvbnQgc2NyaXB0PSJUYWx1IiB0eXBlZmFjZT0iTWljcm9zb2Z0IE5ldyBUYWkgTHVlIi8+PGE6Zm9udCBzY3JpcHQ9IlRmbmciIHR5cGVmYWNlPSJFYnJpbWEiLz48L2E6bWFqb3JGb250PjxhOm1pbm9yRm9udD48YTpsYXRpbiB0eXBlZmFjZT0iQ2FsaWJyaSIgcGFub3NlPSIwMjBGMDUwMjAyMDIwNDAzMDIwNCIvPjxhOmVhIHR5cGVmYWNlPSIiLz48YTpjcyB0eXBlZmFjZT0iIi8+PGE6Zm9udCBzY3JpcHQ9IkpwYW4iIHR5cGVmYWNlPSLmuLjjgrTjgrfjg4Pjgq8iLz48YTpmb250IHNjcmlwdD0iSGFuZyIgdHlwZWZhY2U9IuunkeydgCDqs6DrlJUiLz48YTpmb250IHNjcmlwdD0iSGFucyIgdHlwZWZhY2U9Iuetiee6vyIvPjxhOmZvbnQgc2NyaXB0PSJIYW50IiB0eXBlZmFjZT0i5paw57Sw5piO6auUIi8+PGE6Zm9udCBzY3JpcHQ9IkFyYWIiIHR5cGVmYWNlPSJBcmlhbCIvPjxhOmZvbnQgc2NyaXB0PSJIZWJyIiB0eXBlZmFjZT0iQXJpYWwiLz48YTpmb250IHNjcmlwdD0iVGhhaSIgdHlwZWZhY2U9IlRhaG9tYSIvPjxhOmZvbnQgc2NyaXB0PSJFdGhpIiB0eXBlZmFjZT0iTnlhbGEiLz48YTpmb250IHNjcmlwdD0iQmVuZyIgdHlwZWZhY2U9IlZyaW5kYSIvPjxhOmZvbnQgc2NyaXB0PSJHdWpyIiB0eXBlZmFjZT0iU2hydXRpIi8+PGE6Zm9udCBzY3JpcHQ9IktobXIiIHR5cGVmYWNlPSJEYXVuUGVuaCIvPjxhOmZvbnQgc2NyaXB0PSJLbmRhIiB0eXBlZmFjZT0iVHVuZ2EiLz48YTpmb250IHNjcmlwdD0iR3VydSIgdHlwZWZhY2U9IlJhYXZpIi8+PGE6Zm9udCBzY3JpcHQ9IkNhbnMiIHR5cGVmYWNlPSJFdXBoZW1pYSIvPjxhOmZvbnQgc2NyaXB0PSJDaGVyIiB0eXBlZmFjZT0iUGxhbnRhZ2VuZXQgQ2hlcm9rZWUiLz48YTpmb250IHNjcmlwdD0iWWlpaSIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBZaSBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJUaWJ0IiB0eXBlZmFjZT0iTWljcm9zb2Z0IEhpbWFsYXlhIi8+PGE6Zm9udCBzY3JpcHQ9IlRoYWEiIHR5cGVmYWNlPSJNViBCb2xpIi8+PGE6Zm9udCBzY3JpcHQ9IkRldmEiIHR5cGVmYWNlPSJNYW5nYWwiLz48YTpmb250IHNjcmlwdD0iVGVsdSIgdHlwZWZhY2U9IkdhdXRhbWkiLz48YTpmb250IHNjcmlwdD0iVGFtbCIgdHlwZWZhY2U9IkxhdGhhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmMiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJPcnlhIiB0eXBlZmFjZT0iS2FsaW5nYSIvPjxhOmZvbnQgc2NyaXB0PSJNbHltIiB0eXBlZmFjZT0iS2FydGlrYSIvPjxhOmZvbnQgc2NyaXB0PSJMYW9vIiB0eXBlZmFjZT0iRG9rQ2hhbXBhIi8+PGE6Zm9udCBzY3JpcHQ9IlNpbmgiIHR5cGVmYWNlPSJJc2tvb2xhIFBvdGEiLz48YTpmb250IHNjcmlwdD0iTW9uZyIgdHlwZWZhY2U9Ik1vbmdvbGlhbiBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJWaWV0IiB0eXBlZmFjZT0iQXJpYWwiLz48YTpmb250IHNjcmlwdD0iVWlnaCIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBVaWdodXIiLz48YTpmb250IHNjcmlwdD0iR2VvciIgdHlwZWZhY2U9IlN5bGZhZW4iLz48YTpmb250IHNjcmlwdD0iQXJtbiIgdHlwZWZhY2U9IkFyaWFsIi8+PGE6Zm9udCBzY3JpcHQ9IkJ1Z2kiIHR5cGVmYWNlPSJMZWVsYXdhZGVlIFVJIi8+PGE6Zm9udCBzY3JpcHQ9IkJvcG8iIHR5cGVmYWNlPSJNaWNyb3NvZnQgSmhlbmdIZWkiLz48YTpmb250IHNjcmlwdD0iSmF2YSIgdHlwZWZhY2U9IkphdmFuZXNlIFRleHQiLz48YTpmb250IHNjcmlwdD0iTGlzdSIgdHlwZWZhY2U9IlNlZ29lIFVJIi8+PGE6Zm9udCBzY3JpcHQ9Ik15bXIiIHR5cGVmYWNlPSJNeWFubWFyIFRleHQiLz48YTpmb250IHNjcmlwdD0iTmtvbyIgdHlwZWZhY2U9IkVicmltYSIvPjxhOmZvbnQgc2NyaXB0PSJPbGNrIiB0eXBlZmFjZT0iTmlybWFsYSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJPc21hIiB0eXBlZmFjZT0iRWJyaW1hIi8+PGE6Zm9udCBzY3JpcHQ9IlBoYWciIHR5cGVmYWNlPSJQaGFnc3BhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cm4iIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJTeXJqIiB0eXBlZmFjZT0iRXN0cmFuZ2VsbyBFZGVzc2EiLz48YTpmb250IHNjcmlwdD0iU3lyZSIgdHlwZWZhY2U9IkVzdHJhbmdlbG8gRWRlc3NhIi8+PGE6Zm9udCBzY3JpcHQ9IlNvcmEiIHR5cGVmYWNlPSJOaXJtYWxhIFVJIi8+PGE6Zm9udCBzY3JpcHQ9IlRhbGUiIHR5cGVmYWNlPSJNaWNyb3NvZnQgVGFpIExlIi8+PGE6Zm9udCBzY3JpcHQ9IlRhbHUiIHR5cGVmYWNlPSJNaWNyb3NvZnQgTmV3IFRhaSBMdWUiLz48YTpmb250IHNjcmlwdD0iVGZuZyIgdHlwZWZhY2U9IkVicmltYSIvPjwvYTptaW5vckZvbnQ+PC9hOmZvbnRTY2hlbWU+PGE6Zm10U2NoZW1lIG5hbWU9Ik9mZmljZSI+PGE6ZmlsbFN0eWxlTHN0PjxhOnNvbGlkRmlsbD48YTpzY2hlbWVDbHIgdmFsPSJwaENsciIvPjwvYTpzb2xpZEZpbGw+PGE6Z3JhZEZpbGwgcm90V2l0aFNoYXBlPSIxIj48YTpnc0xzdD48YTpncyBwb3M9IjAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSIxMTAwMDAiLz48YTpzYXRNb2QgdmFsPSIxMDUwMDAiLz48YTp0aW50IHZhbD0iNjcwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48YTpncyBwb3M9IjUwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6bHVtTW9kIHZhbD0iMTA1MDAwIi8+PGE6c2F0TW9kIHZhbD0iMTAzMDAwIi8+PGE6dGludCB2YWw9IjczMDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSIxMDAwMDAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSIxMDUwMDAiLz48YTpzYXRNb2QgdmFsPSIxMDkwMDAiLz48YTp0aW50IHZhbD0iODEwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48L2E6Z3NMc3Q+PGE6bGluIGFuZz0iNTQwMDAwMCIgc2NhbGVkPSIwIi8+PC9hOmdyYWRGaWxsPjxhOmdyYWRGaWxsIHJvdFdpdGhTaGFwZT0iMSI+PGE6Z3NMc3Q+PGE6Z3MgcG9zPSIwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6c2F0TW9kIHZhbD0iMTAzMDAwIi8+PGE6bHVtTW9kIHZhbD0iMTAyMDAwIi8+PGE6dGludCB2YWw9Ijk0MDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSI1MDAwMCI+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnNhdE1vZCB2YWw9IjExMDAwMCIvPjxhOmx1bU1vZCB2YWw9IjEwMDAwMCIvPjxhOnNoYWRlIHZhbD0iMTAwMDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSIxMDAwMDAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSI5OTAwMCIvPjxhOnNhdE1vZCB2YWw9IjEyMDAwMCIvPjxhOnNoYWRlIHZhbD0iNzgwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48L2E6Z3NMc3Q+PGE6bGluIGFuZz0iNTQwMDAwMCIgc2NhbGVkPSIwIi8+PC9hOmdyYWRGaWxsPjwvYTpmaWxsU3R5bGVMc3Q+PGE6bG5TdHlsZUxzdD48YTpsbiB3PSI2MzUwIiBjYXA9ImZsYXQiIGNtcGQ9InNuZyIgYWxnbj0iY3RyIj48YTpzb2xpZEZpbGw+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiLz48L2E6c29saWRGaWxsPjxhOnByc3REYXNoIHZhbD0ic29saWQiLz48YTptaXRlciBsaW09IjgwMDAwMCIvPjwvYTpsbj48YTpsbiB3PSIxMjcwMCIgY2FwPSJmbGF0IiBjbXBkPSJzbmciIGFsZ249ImN0ciI+PGE6c29saWRGaWxsPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIi8+PC9hOnNvbGlkRmlsbD48YTpwcnN0RGFzaCB2YWw9InNvbGlkIi8+PGE6bWl0ZXIgbGltPSI4MDAwMDAiLz48L2E6bG4+PGE6bG4gdz0iMTkwNTAiIGNhcD0iZmxhdCIgY21wZD0ic25nIiBhbGduPSJjdHIiPjxhOnNvbGlkRmlsbD48YTpzY2hlbWVDbHIgdmFsPSJwaENsciIvPjwvYTpzb2xpZEZpbGw+PGE6cHJzdERhc2ggdmFsPSJzb2xpZCIvPjxhOm1pdGVyIGxpbT0iODAwMDAwIi8+PC9hOmxuPjwvYTpsblN0eWxlTHN0PjxhOmVmZmVjdFN0eWxlTHN0PjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdC8+PC9hOmVmZmVjdFN0eWxlPjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdC8+PC9hOmVmZmVjdFN0eWxlPjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdD48YTpvdXRlclNoZHcgYmx1clJhZD0iNTcxNTAiIGRpc3Q9IjE5MDUwIiBkaXI9IjU0MDAwMDAiIGFsZ249ImN0ciIgcm90V2l0aFNoYXBlPSIwIj48YTpzcmdiQ2xyIHZhbD0iMDAwMDAwIj48YTphbHBoYSB2YWw9IjYzMDAwIi8+PC9hOnNyZ2JDbHI+PC9hOm91dGVyU2hkdz48L2E6ZWZmZWN0THN0PjwvYTplZmZlY3RTdHlsZT48L2E6ZWZmZWN0U3R5bGVMc3Q+PGE6YmdGaWxsU3R5bGVMc3Q+PGE6c29saWRGaWxsPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIi8+PC9hOnNvbGlkRmlsbD48YTpzb2xpZEZpbGw+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnRpbnQgdmFsPSI5NTAwMCIvPjxhOnNhdE1vZCB2YWw9IjE3MDAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOnNvbGlkRmlsbD48YTpncmFkRmlsbCByb3RXaXRoU2hhcGU9IjEiPjxhOmdzTHN0PjxhOmdzIHBvcz0iMCI+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnRpbnQgdmFsPSI5MzAwMCIvPjxhOnNhdE1vZCB2YWw9IjE1MDAwMCIvPjxhOnNoYWRlIHZhbD0iOTgwMDAiLz48YTpsdW1Nb2QgdmFsPSIxMDIwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48YTpncyBwb3M9IjUwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6dGludCB2YWw9Ijk4MDAwIi8+PGE6c2F0TW9kIHZhbD0iMTMwMDAwIi8+PGE6c2hhZGUgdmFsPSI5MDAwMCIvPjxhOmx1bU1vZCB2YWw9IjEwMzAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOmdzPjxhOmdzIHBvcz0iMTAwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6c2hhZGUgdmFsPSI2MzAwMCIvPjxhOnNhdE1vZCB2YWw9IjEyMDAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOmdzPjwvYTpnc0xzdD48YTpsaW4gYW5nPSI1NDAwMDAwIiBzY2FsZWQ9IjAiLz48L2E6Z3JhZEZpbGw+PC9hOmJnRmlsbFN0eWxlTHN0PjwvYTpmbXRTY2hlbWU+PC9hOnRoZW1lRWxlbWVudHM+PGE6b2JqZWN0RGVmYXVsdHMvPjxhOmV4dHJhQ2xyU2NoZW1lTHN0Lz48YTpleHRMc3Q+PGE6ZXh0IHVyaT0iezA1QTRDMjVDLTA4NUUtNDM0MC04NUEzLUE1NTMxRTUxMERCMn0iPjx0aG0xNTp0aGVtZUZhbWlseSB4bWxuczp0aG0xNT0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2UvdGhlbWVtbC8yMDEyL21haW4iIG5hbWU9Ik9mZmljZSBUaGVtZSIgaWQ9Ins2MkY5MzlCNi05M0FGLTREQjgtOUM2Qi1ENkM3REZEQzU4OUZ9IiB2aWQ9Ins0QTNDNDZFOC02MUNDLTQ2MDMtQTU4OS03NDIyQTQ3QThFNEF9Ii8+PC9hOmV4dD48L2E6ZXh0THN0PjwvYTp0aGVtZT5QSwMECgAAAAAAAAAhAHmhgGxSBgAAUgYAAA0AAAB4bC9zdHlsZXMueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHN0eWxlU2hlZXQgeG1sbnM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9zcHJlYWRzaGVldG1sLzIwMDYvbWFpbiIgeG1sbnM6bWM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9tYXJrdXAtY29tcGF0aWJpbGl0eS8yMDA2IiBtYzpJZ25vcmFibGU9IngxNGFjIHgxNnIyIHhyIiB4bWxuczp4MTRhYz0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDA5LzkvYWMiIHhtbG5zOngxNnIyPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTUvMDIvbWFpbiIgeG1sbnM6eHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNC9yZXZpc2lvbiI+PGZvbnRzIGNvdW50PSIxIiB4MTRhYzprbm93bkZvbnRzPSIxIj48Zm9udD48c3ogdmFsPSIxMSIvPjxjb2xvciB0aGVtZT0iMSIvPjxuYW1lIHZhbD0iQ2FsaWJyaSIvPjxmYW1pbHkgdmFsPSIyIi8+PHNjaGVtZSB2YWw9Im1pbm9yIi8+PC9mb250PjwvZm9udHM+PGZpbGxzIGNvdW50PSIyIj48ZmlsbD48cGF0dGVybkZpbGwgcGF0dGVyblR5cGU9Im5vbmUiLz48L2ZpbGw+PGZpbGw+PHBhdHRlcm5GaWxsIHBhdHRlcm5UeXBlPSJncmF5MTI1Ii8+PC9maWxsPjwvZmlsbHM+PGJvcmRlcnMgY291bnQ9IjEiPjxib3JkZXI+PGxlZnQvPjxyaWdodC8+PHRvcC8+PGJvdHRvbS8+PGRpYWdvbmFsLz48L2JvcmRlcj48L2JvcmRlcnM+PGNlbGxTdHlsZVhmcyBjb3VudD0iMSI+PHhmIG51bUZtdElkPSIwIiBmb250SWQ9IjAiIGZpbGxJZD0iMCIgYm9yZGVySWQ9IjAiLz48L2NlbGxTdHlsZVhmcz48Y2VsbFhmcyBjb3VudD0iMSI+PHhmIG51bUZtdElkPSIwIiBmb250SWQ9IjAiIGZpbGxJZD0iMCIgYm9yZGVySWQ9IjAiIHhmSWQ9IjAiLz48L2NlbGxYZnM+PGNlbGxTdHlsZXMgY291bnQ9IjEiPjxjZWxsU3R5bGUgbmFtZT0iTm9ybWFsIiB4ZklkPSIwIiBidWlsdGluSWQ9IjAiLz48L2NlbGxTdHlsZXM+PGR4ZnMgY291bnQ9IjAiLz48dGFibGVTdHlsZXMgY291bnQ9IjAiIGRlZmF1bHRUYWJsZVN0eWxlPSJUYWJsZVN0eWxlTWVkaXVtMiIgZGVmYXVsdFBpdm90U3R5bGU9IlBpdm90U3R5bGVMaWdodDE2Ii8+PGV4dExzdD48ZXh0IHVyaT0ie0VCNzlERUYyLTgwQjgtNDNlNS05NUJELTU0Q0JEREY5MDIwQ30iIHhtbG5zOngxND0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDA5LzkvbWFpbiI+PHgxNDpzbGljZXJTdHlsZXMgZGVmYXVsdFNsaWNlclN0eWxlPSJTbGljZXJTdHlsZUxpZ2h0MSIvPjwvZXh0PjxleHQgdXJpPSJ7OTI2MEE1MTAtRjMwMS00NmE4LTg2MzUtRjUxMkQ2NEJFNUY1fSIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiI+PHgxNTp0aW1lbGluZVN0eWxlcyBkZWZhdWx0VGltZWxpbmVTdHlsZT0iVGltZVNsaWNlclN0eWxlTGlnaHQxIi8+PC9leHQ+PC9leHRMc3Q+PC9zdHlsZVNoZWV0PlBLAwQKAAAAAAAAACEA0IywC4EAAACBAAAAFAAAAHhsL3NoYXJlZFN0cmluZ3MueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHNzdCB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIi8+UEsDBAoAAAAAAAAAIQDcCx83XQIAAF0CAAARAAAAZG9jUHJvcHMvY29yZS54bWw8P3htbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJVVEYtOCIgc3RhbmRhbG9uZT0ieWVzIj8+DQo8Y3A6Y29yZVByb3BlcnRpZXMgeG1sbnM6Y3A9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9wYWNrYWdlLzIwMDYvbWV0YWRhdGEvY29yZS1wcm9wZXJ0aWVzIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOmRjdGVybXM9Imh0dHA6Ly9wdXJsLm9yZy9kYy90ZXJtcy8iIHhtbG5zOmRjbWl0eXBlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIj48ZGM6Y3JlYXRvcj5kdW5jYW48L2RjOmNyZWF0b3I+PGNwOmxhc3RNb2RpZmllZEJ5PmR1bmNhbjwvY3A6bGFzdE1vZGlmaWVkQnk+PGRjdGVybXM6Y3JlYXRlZCB4c2k6dHlwZT0iZGN0ZXJtczpXM0NEVEYiPjIwMTktMDEtMzFUMTY6NDg6MDNaPC9kY3Rlcm1zOmNyZWF0ZWQ+PGRjdGVybXM6bW9kaWZpZWQgeHNpOnR5cGU9ImRjdGVybXM6VzNDRFRGIj4yMDE5LTAxLTMxVDE2OjQ4OjI4WjwvZGN0ZXJtczptb2RpZmllZD48L2NwOmNvcmVQcm9wZXJ0aWVzPlBLAwQKAAAAAAAAACEAYUkJEBEDAAARAwAAEAAAAGRvY1Byb3BzL2FwcC54bWw8P3htbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJVVEYtOCIgc3RhbmRhbG9uZT0ieWVzIj8+DQo8UHJvcGVydGllcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL29mZmljZURvY3VtZW50LzIwMDYvZXh0ZW5kZWQtcHJvcGVydGllcyIgeG1sbnM6dnQ9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L2RvY1Byb3BzVlR5cGVzIj48QXBwbGljYXRpb24+TWljcm9zb2Z0IEV4Y2VsPC9BcHBsaWNhdGlvbj48RG9jU2VjdXJpdHk+MDwvRG9jU2VjdXJpdHk+PFNjYWxlQ3JvcD5mYWxzZTwvU2NhbGVDcm9wPjxIZWFkaW5nUGFpcnM+PHZ0OnZlY3RvciBzaXplPSIyIiBiYXNlVHlwZT0idmFyaWFudCI+PHZ0OnZhcmlhbnQ+PHZ0Omxwc3RyPldvcmtzaGVldHM8L3Z0Omxwc3RyPjwvdnQ6dmFyaWFudD48dnQ6dmFyaWFudD48dnQ6aTQ+MTwvdnQ6aTQ+PC92dDp2YXJpYW50PjwvdnQ6dmVjdG9yPjwvSGVhZGluZ1BhaXJzPjxUaXRsZXNPZlBhcnRzPjx2dDp2ZWN0b3Igc2l6ZT0iMSIgYmFzZVR5cGU9Imxwc3RyIj48dnQ6bHBzdHI+U2hlZXQxPC92dDpscHN0cj48L3Z0OnZlY3Rvcj48L1RpdGxlc09mUGFydHM+PENvbXBhbnk+PC9Db21wYW55PjxMaW5rc1VwVG9EYXRlPmZhbHNlPC9MaW5rc1VwVG9EYXRlPjxTaGFyZWREb2M+ZmFsc2U8L1NoYXJlZERvYz48SHlwZXJsaW5rc0NoYW5nZWQ+ZmFsc2U8L0h5cGVybGlua3NDaGFuZ2VkPjxBcHBWZXJzaW9uPjE2LjAzMDA8L0FwcFZlcnNpb24+PC9Qcm9wZXJ0aWVzPlBLAQIUAAoAAAAAAAAAIQBi7p1okAQAAJAEAAATAAAAAAAAAAAAAAAAAAAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAhQACgAAAAAAAAAhALVVMCNMAgAATAIAAAsAAAAAAAAAAAAAAAAAwQQAAF9yZWxzLy5yZWxzUEsBAhQACgAAAAAAAAAhALpwnmbKBgAAygYAAA8AAAAAAAAAAAAAAAAANgcAAHhsL3dvcmtib29rLnhtbFBLAQIUAAoAAAAAAAAAIQCBPpSXugIAALoCAAAaAAAAAAAAAAAAAAAAAC0OAAB4bC9fcmVscy93b3JrYm9vay54bWwucmVsc1BLAQIUAAoAAAAAAAAAIQACrURzpAMAAKQDAAAYAAAAAAAAAAAAAAAAAB8RAAB4bC93b3Jrc2hlZXRzL3NoZWV0MS54bWxQSwECFAAKAAAAAAAAACEAwRcQvsYgAADGIAAAEwAAAAAAAAAAAAAAAAD5FAAAeGwvdGhlbWUvdGhlbWUxLnhtbFBLAQIUAAoAAAAAAAAAIQB5oYBsUgYAAFIGAAANAAAAAAAAAAAAAAAAAPA1AAB4bC9zdHlsZXMueG1sUEsBAhQACgAAAAAAAAAhANCMsAuBAAAAgQAAABQAAAAAAAAAAAAAAAAAbTwAAHhsL3NoYXJlZFN0cmluZ3MueG1sUEsBAhQACgAAAAAAAAAhANwLHzddAgAAXQIAABEAAAAAAAAAAAAAAAAAID0AAGRvY1Byb3BzL2NvcmUueG1sUEsBAhQACgAAAAAAAAAhAGFJCRARAwAAEQMAABAAAAAAAAAAAAAAAAAArD8AAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAAAoACgCAAgAA60IAAAAA";var _t=i=>i!==null&&typeof i=="object"&&"row"in i&&"column"in i;var L=class i{start_;end_;constructor(e,t=e,r=!1){this.end_=this.PatchNull(t),this.start_=this.PatchNull(e),r&&this.Normalize()}static FromColumn(e){return new i({row:1/0,column:e})}static FromRow(e){return new i({row:e,column:1/0})}static ColumnToLabel(e){let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}static CellAddressToLabel(e,t=!1){return(t?`${e.sheet_id||0}!`:"")+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new i(e.start,e.end);for(let n of t)n&&(r.ConsumeAddress(n.start),r.ConsumeAddress(n.end));return r}static Bleed(e,t=1){return new i({row:Math.max(0,e.start.row-t),column:Math.max(0,e.start.column-t),sheet_id:e.start.sheet_id},{row:e.end.row+t,column:e.end.column+t})}static PatchArea(e,t){let{before_column:r,column_count:n,before_row:s,row_count:o}=t,a=new i(e.start,e.end),l=e.start.sheet_id;if(n&&r<=a.end.column){if(n>0)r<=a.start.column?a.Shift(0,n):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+n}):console.warn("AA X case 1",r,n,JSON.stringify(a));else if(n<0)if(r-n<=a.start.column)a.Shift(0,n);else{if(r<=a.start.column&&r-n>a.end.column)return!1;if(r<=a.start.column){let d=r-n-1;a=new i({row:a.start.row,column:d+1+n,sheet_id:l},{row:a.end.row,column:a.end.column+n})}else r<=a.end.column?r-n-1>=a.end.column?a=new i({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:r-1}):a=new i({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:a.start.column+a.columns+n-1}):console.warn("AA X case 2",r,n,JSON.stringify(a))}}if(o&&s<=a.end.row){if(o>0)s<=a.start.row?a.Shift(o,0):s>a.start.row&&s<=a.end.row?a.ConsumeAddress({row:a.end.row+o,column:a.end.column}):console.warn("AA X case 3",s,o,JSON.stringify(a));else if(o<0)if(s-o<=a.start.row)a.Shift(o,0);else{if(s<=a.start.row&&s-o>a.end.row)return!1;if(s<=a.start.row){let d=s-o-1;a=new i({column:a.start.column,row:d+1+o,sheet_id:l},{column:a.end.column,row:a.end.row+o})}else s<=a.end.row?s-o-1>=a.end.row?a=new i({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:s-1}):a=new i({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:a.start.row+a.rows+o-1}):console.warn("AA X case 4",s,o,JSON.stringify(a))}}return a}get start(){return{...this.start_}}set start(e){this.start_=e}get end(){return{...this.end_}}set end(e){this.end_=e}get rows(){return this.start_.row===1/0||this.end_.row===1/0?1/0:this.end_.row-this.start_.row+1}get columns(){return this.start_.column===1/0||this.end_.column===1/0?1/0:this.end_.column-this.start_.column+1}get count(){return this.rows*this.columns}get entire_sheet(){return this.entire_row&&this.entire_column}get entire_column(){return this.start_.row===1/0}get entire_row(){return this.start_.column===1/0}PatchNull(e){let t={...e};return t.row===null&&(t.row=1/0),t.column===null&&(t.column=1/0),t}SetSheetID(e){this.start_.sheet_id=e}Normalize(){let e={...this.start_},t={...this.end_};e.row===1/0||t.row===1/0?e.row=t.row=1/0:e.row>t.row&&(e.row=this.end_.row,e.absolute_row=this.end_.absolute_row,t.row=this.start_.row,t.absolute_row=this.start_.absolute_row),e.column===1/0||t.column===1/0?e.column=t.column=1/0:e.column>t.column&&(e.column=this.end_.column,e.absolute_column=this.end_.absolute_column,t.column=this.start_.column,t.absolute_column=this.start_.absolute_column),this.start_=e,this.end_=t}TopLeft(){let e={row:0,column:0};return this.entire_row||(e.column=this.start.column),this.entire_column||(e.row=this.start.row),e}BottomRight(){let e={row:0,column:0};return this.entire_row||(e.column=this.end.column),this.entire_column||(e.row=this.end.row),e}ContainsRow(e){return this.entire_column||e>=this.start_.row&&e<=this.end_.row}ContainsColumn(e){return this.entire_row||e>=this.start_.column&&e<=this.end_.column}Contains(e){return(this.entire_column||e.row>=this.start_.row&&e.row<=this.end_.row)&&(this.entire_row||e.column>=this.start_.column&&e.column<=this.end_.column)}ContainsArea(e){return this.start.column<=e.start.column&&this.end.column>=e.end.column&&this.start.row<=e.start.row&&this.end.row>=e.end.row}Intersects(e){return!(e.start.column>this.end.column||this.start.column>e.end.column||e.start.row>this.end.row||this.start.row>e.end.row)}Equals(e){return e.start_.row===this.start_.row&&e.start_.column===this.start_.column&&e.end_.row===this.end_.row&&e.end_.column===this.end_.column}Clone(){return new i(this.start,this.end)}Array(){if(this.entire_column||this.entire_row)throw new Error("can\'t convert infinite area to array");let e=new Array(this.rows*this.columns),t=this.start_.sheet_id,r=0;for(let n=this.start_.row;n<=this.end_.row;n++)for(let s=this.start_.column;s<=this.end_.column;s++)e[r++]={row:n,column:s,sheet_id:t};return e}get left(){let e=new i(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new i(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new i(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new i(this.start_,this.end_);return e.start_.row=e.end_.row,e}Shift(e,t){return this.start_.row+=e,this.start_.column+=t,this.end_.row+=e,this.end_.column+=t,this}ConsumeAddress(e){this.entire_row||(e.column<this.start_.column&&(this.start_.column=e.column),e.column>this.end_.column&&(this.end_.column=e.column)),this.entire_column||(e.row<this.start_.row&&(this.start_.row=e.row),e.row>this.end_.row&&(this.end_.row=e.row))}ConsumeArea(e){this.ConsumeAddress(e.start),this.ConsumeAddress(e.end)}Resize(e,t){return this.end_.row=this.start_.row+e-1,this.end_.column=this.start_.column+t-1,this}Iterate(e){if(this.entire_column||this.entire_row){console.warn("don\'t iterate infinite area");return}for(let t=this.start_.column;t<=this.end_.column;t++)for(let r=this.start_.row;r<=this.end_.row;r++)e({column:t,row:r,sheet_id:this.start_.sheet_id})}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=i.ColumnToLabel(this.start_.column),e+=":"+i.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=i.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+i.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var Ci=i=>typeof i=="object"&&!!i&&typeof i.real=="number"&&typeof i.imaginary=="number";var wt=i=>typeof i=="object"&&!!i&&typeof i.value=="number"&&typeof i.unit=="string",At=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var _e=i=>{switch(typeof i){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return i===null?0:Ci(i)?7:wt(i)?9:5;case"string":return i[0]==="="?1:2;default:return 6}};var te=class{static StringToColumn(e){let t=0;e=e.toUpperCase();for(let r=0;r<e.length;r++)t*=26,t+=e.charCodeAt(r)-64;return t-1}value;type=0;calculated;calculated_type;formatted;rendered_type;style;area;merge_area;table;renderer_data;render_clean=[];note;hyperlink;editing;render_function;click_function;validation;constructor(e,t){typeof e<"u"&&this.Set(e,t)}ValueIsNumber(){return this.type===3}ValueIsFormula(){return this.type===1}ValueIsBoolean(){return this.type===4}ValueIsComplex(){return this.type===7}FlushStyle(){this.formatted=this.rendered_type=this.style=void 0,this.render_clean=[]}FlushArray(){this.area=void 0}FlushCache(){this.calculated=this.calculated_type=this.formatted=this.rendered_type=this.render_function=this.click_function=void 0,this.render_clean=[]}Reset(){this.type=0,this.value=this.note=this.hyperlink=this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.area=this.renderer_data=this.render_function=this.click_function=void 0,this.render_clean=[]}Set(e,t=_e(e)){this.value=e,this.type=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.render_function=this.click_function=this.area=void 0,this.render_clean=[]}SetCalculatedValue(e,t=_e(e)){e===void 0&&(e=0,t=3),this.calculated!==e&&(this.calculated=e,this.calculated_type=t,this.formatted=this.rendered_type=void 0,this.render_clean=[])}GetValue(){return this.calculated_type?this.calculated:typeof this.value=="string"&&this.value[0]==="\'"?this.value.slice(1):this.value}GetValue4(){return this.calculated_type?{type:this.calculated_type,value:this.calculated}:this.type===1?{type:3,value:0}:{type:this.type,value:typeof this.value=="string"&&this.value[0]==="\'"?this.value.slice(1):this.value}}SetNote(e){this.note=e,this.render_clean=[]}SetCalculationError(e="ERR"){this.SetCalculatedValue(e,6)}SetArray(e){this.type=0,this.value=this.formatted=this.rendered_type=this.style=this.hyperlink=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}SetArrayHead(e,t){this.type=_e(t),this.value=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}};var Ii=i=>!i.cells,Ni=i=>!!i[0]&&Ii(i[0]),Si=i=>!!i[0]&&i[0].row!==void 0,Ti=At.map((i,e)=>({[i]:e})).reduce((i,e)=>({...i,...e}),{}),Je=class{data=[];rows_=0;columns_=0;get rows(){return this.rows_}get columns(){return this.columns_}EnsureRow(e){this.rows_=Math.max(e+1,this.rows_)}EnsureColumn(e){this.columns_=Math.max(e+1,this.columns_)}InsertColumns(e=0,t=1){let r=JSON.parse(JSON.stringify(this.data[13]));this.data=this.data.map(n=>{if(n.length>=e){let s=n.slice(0,e),o=e+t,a=n.slice(e);for(let l=0;l<a.length;l++)s[o++]=a[l];return s}return n}),this.columns_+=t}DeleteColumns(e,t=1){this.data.forEach(r=>r.splice(e,t)),this.columns_-=t}DeleteRows(e,t=1){this.data.splice(e,t),this.rows_-=t}InsertRows(e=0,t=1){let r=[e,0,[]];for(let n=1;n<t;n++)r.push([]);Array.prototype.splice.apply(this.data,r),this.rows_+=t}GetCell(e,t){let{row:r,column:n}=e;if(!this.data[r])if(t)this.data[r]=[],this.rows_=Math.max(this.rows_,r+1);else return;return this.data[r][n]||t&&(this.data[r][n]=new te,this.columns_=Math.max(this.columns_,n+1)),this.data[r][n]}EnsureCell(e){let{row:t,column:r}=e,n=this.data[t];n||(this.data[t]=n=[],this.rows_=Math.max(this.rows_,t+1));let s=n[r];return s||(s=n[r]=new te,this.columns_=Math.max(this.columns_,r+1)),s}FromArray(e=[],t=!1){this.data=[];let r=0,n=0;if(t){n=e.length;for(let s=0;s<n;s++){let o=e[s];r=Math.max(r,o.length);for(let a=0;a<o.length;a++)this.data[a]||(this.data[a]=[]),this.data[a][s]=new te(o[a])}}else{r=e.length;for(let s=0;s<r;s++){let o=[],a=e[s];n=Math.max(n,a.length);for(let l=0;l<a.length;l++)o[l]=new te(a[l]);this.data[s]=o}}this.rows_=r,this.columns_=n}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Ti[e]||void 0}ValueTypeToSerializedType(e){return e?At[e]:void 0}ImportDataValidation(e){if(typeof e.type=="number"){let t=["list","date","range","number","boolean"];if(e.type=t[e.type],!e.type)return}return e}FromJSON(e=[],t){if(this.data=[],!Ni(e)){let n=[];if(Si(e))for(let s of e)for(let o of s.cells)n.push({...o,row:s.row});else for(let s of e)for(let o of s.cells)n.push({...o,column:s.column});e=n}let r=[];for(let n of e){this.data[n.row]||(this.data[n.row]=[]);let s=new te(n.value);if(typeof n.calculated<"u"&&s.SetCalculatedValue(n.calculated,this.SerializedTypeToValueType(n.calculated_type)),t&&typeof n.style_ref<"u"&&(s.style=t[n.style_ref]),typeof n.note<"u"&&(s.note=n.note),typeof n.hyperlink<"u"&&(s.hyperlink=n.hyperlink),this.data[n.row][n.column]&&this.data[n.row][n.column].area&&(s.area=this.data[n.row][n.column].area),this.data[n.row][n.column]=s,n.area){let o=new L(n.area.start,n.area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let l=o.start.column;l<=o.end.column;l++)this.data[a]||(this.data[a]=[]),this.data[a][l]||(this.data[a][l]=new te),this.data[a][l].area=o}if(n.table&&r.push({...n.table}),n.merge_area){let o=new L(n.merge_area.start,n.merge_area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let l=o.start.column;l<=o.end.column;l++)this.data[a]||(this.data[a]=[]),this.data[a][l]||(this.data[a][l]=new te),this.data[a][l].merge_area=o}n.validation&&(s.validation=this.ImportDataValidation(n.validation))}for(let n of r)for(let s=n.area.start.row;s<=n.area.end.row;s++)for(let o=n.area.start.column;o<=n.area.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new te),this.data[s][o].table=n;this.rows_=this.data.length,this.columns_=this.data.reduce((n,s)=>Math.max(n,s.length),0)}toJSON(e={}){let t=0,r=0,n=this.data.length-1,s;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,n=e.subset.end.row);let o=[],a=-1,l=-1,d={},c={};for(let h=r;h<=n;h++)if(this.data[h]){let u=this.data[h];s=u.length-1,e.subset&&(s=e.subset.end.column);for(let p=t;p<=s;p++){let f=u[p],g=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===p,y=f&&f.area&&f.area.start.row===h&&f.area.start.column===p,N=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===p,w=f?f.type===2&&!f.value:!0;if(f&&(!w||e.preserve_empty_strings)&&(g||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||f.validation||e.decorated_cells&&f.style&&(f.style.fill||f.style.border_bottom||f.style.border_top||f.style.border_left||f.style.border_right))){let x={row:h,column:p,value:f.value};f.note&&(x.note=f.note),f.hyperlink&&(x.hyperlink=f.hyperlink),e.preserve_type&&(x.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(x.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(x.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(x.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&N&&e.tables&&(x.table=JSON.parse(JSON.stringify(f.table))),f.area&&y&&(x.area=f.area.toJSON()),f.merge_area&&(x.merge_area=f.merge_area.toJSON()),f.validation&&(x.validation=f.validation),e.cell_style_refs&&e.cell_style_refs[p]&&e.cell_style_refs[p][h]&&(x.style_ref=e.cell_style_refs[p][h],e.cell_style_refs[p][h]=0),d[h]=h,c[p]=p,a=Math.max(h,a),l=Math.max(p,l),o.push(x)}}}if(e.nested){let h=Object.keys(d),u=Object.keys(c);if(h.length<=u.length&&h.length){let p={},f=[];for(let g of o){let{row:y,...N}=g;p[g.row]||(p[g.row]=[]),p[g.row].push(N)}for(let g of h){let y=Number(g);f.push({row:y,cells:p[y]})}return{data:f,rows:a,columns:l+1}}else if(u.length){let p={},f=[];for(let g of o){let{column:y,...N}=g;p[g.column]||(p[g.column]=[]),p[g.column].push(N)}for(let g of u){let y=Number(g);f.push({column:y,cells:p[y]})}return{data:f,rows:a,columns:l+1}}}return{data:o,rows:a+1,columns:l+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize2(e,t){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),t.column===1/0&&(t={...t,column:this.columns_-1}),t.row===1/0&&(t={...t,row:this.rows_-1}),{from:e,to:t}}Normalize1(e){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),e}RawValue(e,t=e){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].value:void 0;let r=[],n=this.data.slice(e.row,t.row+1),s=e.column,o=t.column+1;for(let a of n){let l=[];for(let d=s,c=0;d<o;d++,c++){let h=a[d];l.push(h?h.value:void 0)}r.push(l)}return r}GetRange(e,t,r=!1){if(t?{from:e,to:t}=this.Normalize2(e,t):e=this.Normalize1(e),!t||e===t||e.column===t.column&&e.row===t.row)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue():void 0;let n=[];if(r)for(let s=e.column;s<=t.column;s++){let o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][s]?o.push(this.data[a][s].GetValue()):o.push(void 0);n.push(o)}else for(let s=e.row;s<=t.row;s++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[s]&&this.data[s][a]?o.push(this.data[s][a].GetValue()):o.push(void 0);n.push(o)}return n}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue4():{value:void 0,type:0};let n=[];if(r)for(let s=e.column;s<=t.column;s++){let o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][s]?o.push(this.data[a][s].GetValue4()):o.push({type:0});n.push(o)}else for(let s=e.row;s<=t.row;s++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[s]&&this.data[s][a]?o.push(this.data[s][a].GetValue4()):o.push({type:0});n.push(o)}return{type:8,value:n}}Apply(e,t,r=!1){if(_t(e)&&(e=new L(e)),e.entire_column||e.entire_row)throw new Error("don\'t iterate infinite cells");let n=e.start,s=e.end;if(r)for(let o=n.row;o<=s.row;o++){this.data[o]||(this.data[o]=[]);let a=this.data[o];for(let l=n.column;l<=s.column;l++)a[l]||(a[l]=new te),t(a[l],l,o)}else for(let o=n.row;o<=s.row;o++)if(this.data[o]){let a=this.data[o];for(let l=n.column;l<=s.column;l++)a[l]&&t(a[l],l,o)}}Apply2(e,t,r=!1){if(_t(e)&&(e=new L(e)),e.entire_column||e.entire_row)throw new Error("don\'t iterate infinite cells");let n=e.start,s=e.end;if(r)for(let o=n.row;o<=s.row;o++){this.data[o]||(this.data[o]=[]);let a=this.data[o];for(let l=n.column;l<=s.column;l++)if(a[l]||(a[l]=new te),!t(a[l],l,o))return}else for(let o=n.row;o<=s.row;o++)if(this.data[o]){let a=this.data[o];for(let l=n.column;l<=s.column;l++)if(a[l]&&!t(a[l],l,o))return}}SetArea(e,t){if(ArrayBuffer.isView(t))throw new Error("ABIV");if(Array.isArray(t))for(let r=e.start.row,n=0;r<=e.end.row;r++,n++){this.data[r]||(this.data[r]=[]);let s=this.data[r];if(t[n])for(let o=e.start.column,a=0;o<=e.end.column;o++,a++)s[o]||(s[o]=new te),s[o].Set(t[n][a])}else{let r=_e(t);for(let n=e.start.row;n<=e.end.row;n++){this.data[n]||(this.data[n]=[]);let s=this.data[n];for(let o=e.start.column;o<=e.end.column;o++)s[o]||(s[o]=new te),s[o].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}IterateAll(e){for(let t of this.data)if(t)for(let r of t)r&&e(r)}FlushCellStyles(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushStyle()}FlushCachedValues(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushCache()}};var $=class{static locale="en-us";static decimal_separator=".";static argument_separator=",";static grouping_separator=",";static date_components={short_days:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],long_days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],short_months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],long_months:["January","February","March","April","May","June","July","August","September","October","November","December"]};static UpdateLocale(e){if(e)this.locale=e;else if(typeof self<"u"){let n=self?.document?.location;if(n&&n.search&&/locale=([^?&]+?)(?:\\?|$|&)/.test(n.search)){let s=n.search.match(/locale=(.*?)(?:\\?|$|&)/);s&&(this.locale=s[1]),console.info("override locale",this.locale)}else typeof navigator<"u"&&(navigator.languages&&navigator.languages[0]?this.locale=navigator.languages[0]:this.locale=navigator.language)}let t=new Intl.NumberFormat(this.locale,{minimumFractionDigits:1}).format(3.3).replace(/\\d/g,"");this.decimal_separator=t===","?",":".",this.decimal_separator===","?(this.argument_separator=";",this.grouping_separator=" "):(this.argument_separator=",",this.grouping_separator=",");let r=new Date(2e3,0,2,12,0,0,0);this.UpdateDateComponent(0,0,r),r=new Date(2e3,1,7,12,0,0,0),this.UpdateDateComponent(1,1,r),r=new Date(2e3,2,7,12,0,0,0),this.UpdateDateComponent(2,2,r),r=new Date(2e3,3,5,12,0,0,0),this.UpdateDateComponent(3,3,r),r=new Date(2e3,4,4,12,0,0,0),this.UpdateDateComponent(4,4,r),r=new Date(2e3,5,2,12,0,0,0),this.UpdateDateComponent(5,5,r),r=new Date(2e3,6,1,12,0,0,0),this.UpdateDateComponent(6,6,r),r=new Date(2e3,7,1,12,0,0,0),this.UpdateDateComponent(7,-1,r),r=new Date(2e3,8,1,12,0,0,0),this.UpdateDateComponent(8,-1,r),r=new Date(2e3,9,1,12,0,0,0),this.UpdateDateComponent(9,-1,r),r=new Date(2e3,10,1,12,0,0,0),this.UpdateDateComponent(10,-1,r),r=new Date(2e3,11,1,12,0,0,0),this.UpdateDateComponent(11,-1,r)}static UpdateDateComponent(e,t,r){t>=0&&(this.date_components.short_days[t]=r.toLocaleString(this.locale,{weekday:"short"}),this.date_components.long_days[t]=r.toLocaleString(this.locale,{weekday:"long"})),e>=0&&(this.date_components.short_months[e]=r.toLocaleString(this.locale,{month:"short"}),this.date_components.long_months[e]=r.toLocaleString(this.locale,{month:"long"}))}};$.UpdateLocale();var Zi=JSON.stringify({}),ve={DefaultProperties:{horizontal_align:"",vertical_align:"",number_format:"General",nan:"NaN",font_size:{unit:"pt",value:10.5},font_face:"sans-serif",bold:!1,italic:!1,underline:!1,strike:!1,text:{theme:1},border_top:0,border_left:0,border_right:0,border_bottom:0},CompositeBorders:i=>({top:{width:i.border_top||0,color:i.border_top_fill||{}},left:{width:i.border_left||0,color:i.border_left_fill||{}},right:{width:i.border_right||0,color:i.border_right_fill||{}},bottom:{width:i.border_bottom||0,color:i.border_bottom_fill||{}}}),Merge:(i,e,t=!0)=>{let r=t?{...i,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:i=>JSON.parse(JSON.stringify(i.reduce((e,t)=>({...e,...t}),{}))),Empty:i=>JSON.stringify(i)===Zi,ValidColor:i=>!!(i&&!i.none&&(i.text||i.theme||i.theme===0)),ParseFontSize:(i="",e="em")=>{let t=i.match(/(-*[\\d.]+)\\s*(\\S*)/);if(t){let r=Number(t[1]);if(!r||isNaN(r)||r<0)return{};let n=t[2].toLowerCase()||e;if(n==="pt"||n==="em"||n==="%"||n==="px")return{font_size:{unit:n,value:r}}}return{}},RelativeFontSize:(i,e)=>{let t=12,r=12;switch(i.font_size?.unit){case"pt":if(!i.font_size.value)return 1;r=i.font_size.value;break;case"px":if(!i.font_size.value)return 1;r=Math.round(i.font_size.value*300/4)/100;break;case"em":return i.font_size.value||1;case"%":return(i.font_size.value||100)/100;default:return 1}switch(e.font_size?.unit){case"pt":if(!e.font_size.value)return 1;t=e.font_size.value;break;case"px":if(!e.font_size.value)return 1;t=Math.round(e.font_size.value*300/4)/100;break;default:return 1}return r/t},FontSize:(i,e=!0)=>{let t=i.font_size?.value;switch(i.font_size?.unit){case"pt":return(t||12)+"pt";case"px":return e?Math.round((t||16)*300/4)/100+"pt":(t||16)+"px";case"em":return(t||1)+"em";case"%":return(t||100)+"%"}return""},Font:(i,e=1)=>{let t=[];return i.bold&&t.push("bold"),i.italic&&t.push("italic"),t.push(((i.font_size?.value||0)*e).toFixed(2)+(i.font_size?.unit||"pt")),t.push(i.font_face||""),t.join(" ")}};var ut=Ae(Et());var Vn={"<":"<",">":">","&":"&",""":\'"\',"'":"\'"},zn=/&\\w+;/g,Bn=i=>i.replace(zn,e=>Vn[e]||e);var Qe=Bn;var kr=(i,e)=>Qe(e),Wr={ignoreAttributes:!1,attributeNamePrefix:"__",trimValues:!1,textNodeName:"text__",tagValueProcessor:kr,ignoreDeclaration:!0},qe={ignoreAttributes:!1,attributesGroupName:"a$",attributeNamePrefix:"",textNodeName:"t$",trimValues:!1,ignoreDeclaration:!0,isArray:(i,e,t,r)=>/Relationship$/.test(i),tagValueProcessor:kr},R=class{static FindChild(e={},t){let r=t.split("/");for(let n of r)if(e=e[n],!e)return;return e}static FindAll(e={},t){let r=t.split("/");if(r[0]==="."&&r.shift(),r[0]==="..")throw new Error("invalid path (no access to parent)");if(r[0]==="")throw new Error("invalid path (no access to root)");if(r[0]==="**")throw new Error("ENOTIMPL");return this.FindAllTail(e,r)}static FindAllTail(e,t){if(Array.isArray(e))return e.reduce((r,n)=>r.concat(this.FindAllTail(n,t)),[]);for(let r=0;r<t.length;r++){let n=t[r];if(n==="*"?e=Object.keys(e).filter(s=>s!=="a$"&&s!=="t$").map(s=>e[s]):e=e[n],!e)return[];if(Array.isArray(e)){if(r===t.length-1||e.length===0)return e;let s=t.slice(1);return e.reduce((o,a)=>o.concat(this.FindAllTail(a,s)),[])}}return[e]}};var Ce=class{strings=[];reverse={};FromXML(e){this.strings=[],this.reverse={};let t=0;for(let r of R.FindAll(e,"sst/si")){if(r.t){let n="";typeof r.t=="string"?n=r.t:r.t.t$&&(n=r.t.t$),this.strings[t]=n,this.reverse[n]=t}else if(r.r){let s=R.FindAll(r.r,"t").map(o=>typeof o=="string"?o:o.t$||"").join("");this.strings[t]=s,this.reverse[s]=t}else console.warn(` ** unexpected shared string @ ${t}`),console.info(r);t++}}Get(e){return this.strings[e]}Ensure(e){e[0]==="\'"&&(e=e.substring(1));let t=this.reverse[e];return typeof t=="number"||(t=this.strings.length,this.strings.push(e),this.reverse[e]=t),t}};var be=class i{static color_map=["lt1","dk1","lt2","dk2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"];colors={};FromXML(e){let t=Object.keys(e)[0],r="",n=t.toString().match(/^(.*?):/);if(n&&(r=n[1]+":"),e[t]&&e[t][`${r}themeElements`]){let s=e[t][`${r}themeElements`][`${r}clrScheme`];for(let o of i.color_map){let a=s[`${r}${o}`],l,d="rgb";a[`${r}srgbClr`]?(d="rgb",l=a[`${r}srgbClr`].a$.val||""):a[`${r}sysClr`]&&(d="system",l=a[`${r}sysClr`].a$.lastClr||""),this.colors[o]={name:o,value:l,type:d}}}}};var he=class{date_format=!1;string_format=!1;fraction_format=!1;twelve_hour=!1;fraction_denominator=0;fraction_integer=!0;fraction_align=0;fraction_denominator_digits=0;integer_min_digits=0;decimal_min_digits=0;decimal_max_digits=0;grouping=!1;has_number_format=!1;prefix=[{text:""}];suffix=[{text:""}];scaling=0;percent=!1;exponential=!1;has_asterisk=!1};var Rr=42,Gr=95,kt=63,Ke=48,Mr=46,Wt=44,$r=37,Rt=34,We=35,Ur=59,et=92,Vr=64,Yn=91,jn=93,zr=69,Br=101,Dn=72,Hn=104,On=77,Jn=109,Xn=83,Qn=115,qn=68,Kn=100,es=89,ts=121,rs=65,is=97;var tt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new he;static preserve_formatting_characters=!1;static decimal_mark=Mr;static group_separator=Wt;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new he,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new he,this.sections=[this.current_section];this.char_index<this.characters.length;)this.ConsumeChar();return this.sections}static ConsumeString(){let e="";for(this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case et:this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index+1<this.characters.length&&(e+=this.pattern[++this.char_index]);break;case Rt:return this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated string")}static ConsumeFormatting(){let e="";for(++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case et:throw new Error("invalid escape character in formatting block");case jn:return this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated format")}static ScanFractionFormat(){let e=/^([#?]+ +){0,1}([#?]+)\\/([#?0-9]+)(?:$|[^#?0-9])/,r=this.pattern.substr(this.char_index).match(e);if(!r)return!1;let n=(r[1]||"").length+r[2].length+r[3].length+1;this.current_section.fraction_format=!0,this.current_section.fraction_integer=!!r[1];let s=Number(r[3]);return isNaN(s)||(this.current_section.fraction_denominator=s),this.current_section.decimal_max_digits=this.current_section.fraction_denominator_digits=r[3].length,this.char_index+=n,this.current_section.has_number_format=!0,!0}static ConsumeNumberFormat(){let e=0;for(this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case this.group_separator:{let r=!1;for(let n=this.char_index+1;!r&&n<this.characters.length;n++){let s=this.characters[n];if(s===this.decimal_mark||s===We||s===Ke)r=!0;else if(s!==Wt)break}if(r){if(e===1)throw new Error("invalid grouping in decimal part");this.current_section.grouping=!0}else this.current_section.scaling=(this.current_section.scaling||1)*1e3}break;case this.decimal_mark:if(e===1)throw new Error("too many decimal marks");e=1;break;case We:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case Ke:e===1?(this.current_section.decimal_max_digits++,this.current_section.decimal_min_digits=this.current_section.decimal_max_digits):this.current_section.integer_min_digits++;break;default:return}}static AppendCharAsText(e=!0){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=this.pattern[this.char_index]:this.current_section.prefix[this.current_section.prefix.length-1].text+=this.pattern[this.char_index],e&&this.char_index++}static AppendString(e){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=e:this.current_section.prefix[this.current_section.prefix.length-1].text+=e}static AppendTextPart(e){this.current_section.has_number_format?(this.current_section.suffix.push(e),this.current_section.suffix.push({text:""})):(this.current_section.prefix.push(e),this.current_section.prefix.push({text:""}))}static ConsumeChar(){let e=this.characters[this.char_index];if(!((e===kt||e===We)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case Ur:this.char_index++,this.current_section=new he,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case Vr:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case Ke:case We:case Mr:case Wt:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case Yn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Rt:this.AppendString(this.ConsumeString());break;case kt:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Gr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case Rr:if(this.current_section.has_asterisk)throw new Error("we don\'t support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case Br:case zr:this.current_section.percent||this.current_section.exponential||this.current_section.string_format?this.AppendCharAsText():(this.current_section.exponential=!0,this.char_index++);break;case $r:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case et:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}static ParseDatePattern(){for(this.date_pattern=!0;this.date_pattern&&this.char_index<this.pattern.length;)this.DatePatternConsumeChar();if(this.date_pattern){this.date_pattern=!1;for(let e of this.sections)for(let t of e.prefix)t.flag&&t.flag&7&&(this.date_pattern=!0)}return this.date_pattern&&(this.sections[0].date_format=!0,this.sections[0].prefix.forEach((e,t)=>{if(e.flag===3&&(e.text==="mm"||e.text==="m")){if(t)for(let r=t-1;r;r--){let n=this.sections[0].prefix[r];if(n.flag===3){/h/i.test(n.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}if(t<this.sections[0].prefix.length-1)for(let r=t+1;r<this.sections[0].prefix.length;r++){let n=this.sections[0].prefix[r];if(n.flag===3){/s/i.test(n.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}}})),this.date_pattern}static ConsumeDatePart(){let e=this.pattern[this.char_index++],t=e.toLowerCase(),r={text:e,flag:3};for(;this.pattern[this.char_index]&&this.pattern[this.char_index].toLowerCase()===t;)r.text+=this.pattern[this.char_index++];if(t==="s"&&this.pattern[this.char_index]===".")for(r.text+=this.pattern[this.char_index++];this.pattern[this.char_index]==="0";)r.text+=this.pattern[this.char_index++];return r}static ConsumeAMPM(){let e=this.pattern.substr(this.char_index,5);if(e==="am/pm"||e==="AM/PM")return this.char_index+=5,this.sections[0].twelve_hour=!0,{text:e,flag:3};if(e=this.pattern.substr(this.char_index,3),e==="a/p"||e==="A/P")return this.char_index+=3,this.sections[0].twelve_hour=!0,{text:e,flag:3}}static DatePatternConsumeChar(){switch(this.characters[this.char_index]){case Ur:this.char_index=this.characters.length;break;case Ke:case We:case Br:case zr:case $r:case Vr:this.date_pattern=!1;break;case Dn:case Hn:case On:case Jn:case Xn:case Qn:case qn:case Kn:case es:case ts:this.AppendTextPart(this.ConsumeDatePart());break;case rs:case is:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Rt:this.AppendString(this.ConsumeString());break;case kt:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Gr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case Rr:if(this.current_section.has_asterisk)throw new Error("we don\'t support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case et:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}};var ns=i=>(i>=60&&i--,new Date(-22090752e5+864e5*i)),Lr=(i,e=!0)=>{if(e){let t=new Date(i),r=new Date;r.setUTCMilliseconds(t.getUTCMilliseconds()),r.setUTCSeconds(t.getUTCSeconds()),r.setUTCMinutes(t.getUTCMinutes()),r.setUTCHours(t.getHours()),r.setUTCDate(t.getDate()),r.setUTCMonth(t.getMonth()),r.setUTCFullYear(t.getFullYear()),i=r.getTime()}return i=(i+22090752e5)/864e5,i>=60&&i++,i},Ie=class i{static grouping_regexp=/\\d{1,3}(?=(\\d{3})+(?!\\d))/g;static fraction_limits=[9,99,999,9999];static imaginary_character="\\u{1D456}";static minus_character="-";magic_decimal=!1;transform_value;_pattern="";sections;decimal_zero_regexp=[];cloned=[];get pattern(){return this._pattern}get date_format(){return this.sections[0]&&this.sections[0].date_format}constructor(e){if(this._pattern=e,this.sections=tt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new he),this.sections[1]||(this.sections[1]={...this.sections[0]},this.sections[1].prefix=JSON.parse(JSON.stringify(this.sections[1].prefix)),this.sections[1].suffix=JSON.parse(JSON.stringify(this.sections[1].suffix)),this.sections[1].prefix.push({text:"-"}),this.cloned[1]=!0),this.sections[2]||(this.sections[2]={...this.sections[0]},this.cloned[2]=!0),!this.sections[3]){for(let t of this.sections[0].prefix)if(t.flag===5){this.sections[3]={...this.sections[0]},this.sections[3].string_format=!0,this.cloned[3]=!0;break}}this.decimal_zero_regexp=this.sections.map(t=>{if(t.decimal_max_digits>t.decimal_min_digits)return new RegExp(`0{1,${t.decimal_max_digits-t.decimal_min_digits}}(?:$|e)`)})}static FormatPartsAsText(e,t=0){let r=-1,n=e.map((s,o)=>{switch(s.flag){case 2:return r=o,s.text;case 1:return s.text.replace(/./g," ");case 6:return"";default:return s.text}});if(r>=0&&t){let s=n.reduce((a,l,d)=>d===r?a:a+l.length,0),o="";for(let a=0;a<t-s;a++)o+=n[r];n[r]=o}return n.join("")}SetDecimal(e){for(let t of this.sections)t.fraction_format||(t.decimal_min_digits=e,t.decimal_max_digits=e)}IncreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.min(e.fraction_denominator_digits+1,4)):(e.decimal_min_digits++,e.decimal_max_digits=e.decimal_min_digits)})}DecreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.max(e.fraction_denominator_digits-1,1)):(e.decimal_min_digits=Math.max(0,e.decimal_min_digits-1),e.decimal_max_digits=e.decimal_min_digits)})}AddGrouping(){this.sections.forEach(e=>{e.grouping=!0})}RemoveGrouping(){this.sections.forEach(e=>{e.grouping=!1})}ToggleGrouping(){let e=!this.sections[0].grouping;this.sections.forEach(t=>{t.grouping=e})}toString(){return this.sections[0].date_format?this._pattern:this.sections.filter((e,t)=>!this.cloned[t]).map(e=>{let t="",r=0;if(e.fraction_format){e.fraction_integer&&(t+="? ");let n="";for(let s=0;s<e.fraction_denominator_digits;s++)n+="#";t+=n,t+="/",e.fraction_denominator?t+=e.fraction_denominator:t+=n}else if(e.has_number_format){for(r=0;r<e.integer_min_digits;r++)t+="0";if(e.grouping&&(t.length<4&&(t=("####"+t).slice(-4)),t=t.replace(/[\\d#]{1,3}(?=([\\d#]{3})+(?![\\d#]))/g,"$&,")),e.decimal_max_digits||e.decimal_min_digits){for(t+=".",r=0;r<e.decimal_min_digits;r++)t+="0";for(;r<e.decimal_max_digits;r++)t+="#"}if(e.scaling){let n=Math.log10(e.scaling)/3;for(r=0;r<n;r++)t+=","}e.exponential&&(t+="e")}return e.prefix.map(n=>n.flag===1?n.text==="0"?"?":"_"+n.text:n.flag===2?"*"+n.text:n.flag===6?"["+n.text+"]":n.text).join("")+t+e.suffix.map(n=>n.flag===1?n.text==="0"?"?":"_"+n.text:n.flag===2?"*"+n.text:n.text).join("")}).join(";")}FormatDimensionedQuantity(e){if(this.transform_value){let r=this.transform_value(e);if(wt(r))e=r;else return typeof r=="string"?r:this.FormatParts(r)}let t=this.FormatParts(e.value||0);return e.unit&&t.push({text:" "},{text:e.unit}),t}FormatComplex(e){let t=[],r=[],n=!1,s=!!e.imaginary;s&&(t=this.FormatParts(e.imaginary),s=t.some(l=>/[1-9]/.test(l.text)),t.length===1&&this.sections[0].integer_min_digits<=1&&t[0].text==="1"?(t[0].text="",n=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",n=!0));let o=!!e.real;o&&(r=this.FormatParts(e.real),o=r.some(l=>/[1-9]/.test(l.text)));let a=[];if(o||!o&&!s){if(a.push(...r),s){let l=Math.abs(e.imaginary);a.push({text:e.imaginary<0?` ${i.minus_character} `:" + "});let d=n?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...d,{text:i.imaginary_character})}}else s&&a.push(...t,{text:i.imaginary_character});return a}FormatParts(e){if(typeof e!="number"&&!this.sections[3])return[{text:e.toString()}];let{parts:t,section:r}=this.BaseFormat(e),n=[];if(r.date_format||r.string_format)for(let s of t)typeof s=="string"?n.push({text:s}):n.push(s);else this.magic_decimal&&t[1]===""&&t.splice(1,1),n=[...r.prefix.map(s=>({...s})),{text:r.has_number_format?t.join($.decimal_separator):""},...r.suffix.map(s=>({...s}))];for(let s=1;s<n.length;s++)n[s].flag===n[s-1].flag&&(n[s].text=n[s-1].text+n[s].text,n[s-1].text="");return n.filter(s=>s.text)}Format(e,t=0){return i.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=ns(e),r=this.sections[0],n=t.getUTCHours();return r.twelve_hour&&(n>12&&(n-=12),n===0&&(n=12)),{parts:r.prefix.map(o=>{if(o.flag===4)return o.text==="mm"?{text:this.ZeroPad(t.getUTCMinutes().toString(),2)}:{text:this.ZeroPad(t.getUTCMinutes().toString(),1)};if(o.flag===3){switch(o.text.toLowerCase()){case"am/pm":case"a/p":{let l=o.text.split("/");return{text:t.getUTCHours()>12?l[1]:l[0]}}case"mmmmm":return{text:$.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:$.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:$.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:$.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:$.date_components.short_months[t.getUTCMonth()]};case"mm":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),2)};case"m":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),1)};case"ddddd":case"dddd":return o.text==="DDDDD"||o.text==="DDDD"?{text:$.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:$.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:$.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:$.date_components.short_days[t.getUTCDay()]};case"dd":return{text:this.ZeroPad(t.getUTCDate().toString(),2)};case"d":return{text:this.ZeroPad(t.getUTCDate().toString(),1)};case"yyyy":case"yyy":return{text:t.getUTCFullYear().toString()};case"yy":case"y":return{text:this.ZeroPad((t.getUTCFullYear()%100).toString(),2)};case"hh":return{text:this.ZeroPad(n.toString(),2)};case"h":return{text:this.ZeroPad(n.toString(),1)};case"ss":return{text:this.ZeroPad(t.getUTCSeconds().toString(),2)};case"s":return{text:this.ZeroPad(t.getUTCSeconds().toString(),1)}}let a=o.text.match(/^(s+)\\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+$.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),section:r}}StringFormat(e,t){let r=[];for(let n of t.prefix)n.flag===5?r.push({text:e}):r.push({...n});return{parts:r,section:t}}Round2(e,t){let r=Math.pow(10,t);return Math.round(r*e)/r}FormatFraction(e,t){t.percent&&(e*=100);let r={denominator:1,numerator:Math.round(e),error:Math.abs(Math.round(e)-e)};if(t.fraction_denominator)r.denominator=t.fraction_denominator,r.numerator=Math.round(e*r.denominator);else if(r.error){let s=i.fraction_limits[t.fraction_denominator_digits-1]||i.fraction_limits[0];for(let o=2;o<=s;o++){let a=Math.round(e*o),l=Math.abs(a/o-e);if(l<r.error&&(r={numerator:a,denominator:o,error:l},!l))break}}let n=[];if(t.fraction_integer){let s=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(s||!r.numerator)&&(n.push(s.toString()),r.numerator&&n.push(" "))}else r.numerator||n.push("0");return r.numerator&&(n.push(r.numerator.toString()),n.push("/"),n.push(r.denominator.toString())),n.join("")}BaseFormat(e){if(this.sections[0].date_format)return this.DateFormat(Number(e));if(typeof e!="number")return this.StringFormat(e.toString(),this.sections[3]);let t=this.sections[0],r=this.decimal_zero_regexp[0];e<0&&(t=this.sections[1]);let n=t.percent?t.decimal_max_digits+2:t.decimal_max_digits,s=Math.pow(10,-n)/2,o=Math.abs(e);if(o<s&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(o/=t.scaling,o<s&&(t=this.sections[2],r=this.decimal_zero_regexp[2])),t.string_format)return this.StringFormat(e.toString(),t);let a="";if(t.fraction_format)return{parts:[this.FormatFraction(o,t)],section:t};t.exponential?a=o.toExponential(t.decimal_max_digits):(t.percent&&(o*=100),a=this.Round2(o,t.decimal_max_digits).toFixed(t.decimal_max_digits)),r&&(a=a.replace(r,""));let l=a.split(".");for(;l[0].length<t.integer_min_digits;)l[0]=("0000000000000000"+l[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&l[0]==="0"&&(l[0]=""),t.grouping&&(l[0]=l[0].replace(i.grouping_regexp,"$&"+$.grouping_separator)),{parts:l,section:t}}};var Re=class{static cache={};static complex_general;static symbolc_name_map={};static base_formats={Accounting:"_(#,##0.00_);(#,##0.00);-???",Number:"0.00",Integer:"0",Percent:"0.00%",General:"0.######",Fraction:"# ?/?",Dollar:"$* _(#,##0.00_);$* (#,##0.00);$* -???",Exponential:"0.000e","Short Date":"mm/dd/yy","Long Date":"dddd, mmm d yyyy",Timestamp:"mm-dd-yy hh:mm:ss"};static aliases={Scientific:"Exponential",Percentage:"Percent",Currency:"Dollar"};static Get(e,t=!1){if(t&&e==="General")return this.complex_general;let r=this.symbolc_name_map[e.toLowerCase()],n=this.cache[r||e];return n||(n=new Ie(e),this.cache[e]=n),n}static Equals(e,t){if(e===t)return!0;let r=this.Get(e),n=this.Get(t);return r.pattern===n.pattern}static Translate(e){let t=this.symbolc_name_map[e.toLowerCase()];return t?this.cache[t].toString():e}static SymbolicName(e){for(let t of Object.keys(this.base_formats))if(e===this.base_formats[t])return t;return null}static InitCache(){for(let e of Object.keys(this.base_formats))this.cache[e]=new Ie(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new Ie("0.###"),this.complex_general.magic_decimal=!0;for(let e of Object.keys(this.aliases))this.cache[e]=this.cache[this.aliases[e]],this.symbolc_name_map[e.toLowerCase()]=e}};Re.InitCache();var Yr=new Date().getUTCFullYear(),Gt=class{compare_day;compare_month;TestDate(e){let t=Date.parse(e);if(isNaN(t))return!1;let r=new Date(t),s=e.replace(/[\\d\\-\\\\/,.\\s]+/g," ").toLocaleLowerCase().split(/\\s+/).map(l=>l.trim()).filter(l=>!!l);if(!s.length)return t;if(!this.compare_month){this.compare_month={};for(let l=0;l<12;l++)this.compare_month[$.date_components.long_months[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_month[$.date_components.short_months[l].toLocaleLowerCase().replace(/\\./,"")]=l}if(!this.compare_day){this.compare_day={};for(let l=0;l<7;l++)this.compare_day[$.date_components.long_days[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_day[$.date_components.short_days[l].toLocaleLowerCase().replace(/\\./,"")]=l}let o=!1,a=!1;for(let l of s){let d=!1;for(let[c,h]of Object.entries(this.compare_month))if(l===c){if(o||r.getUTCMonth()!==h)return!1;d=!0,o=!0}if(!d){for(let[c,h]of Object.entries(this.compare_day))if(l===c){if(a||r.getUTCDay()!==h)return!1;d=!0,a=!0}}if(!d)return!1}return a&&!o?!1:t}TryParse(e=""){let t={};if(e[0]==="\'")return{value:e,type:2};if(e==="")return{value:e,type:2};if(e==="NaN")return{value:NaN,type:3,hints:{Nan:!0}};let r=e.trim(),n=r.match(/^[$](.*?)$/);n&&(r=n[1],t.Currency=!0);let s=r.match(/^\\((.*?)\\)$/);s&&(r=s[1],t.Parens=!0);let o=r.match(/^(.*?)%\\s*$/);o&&(r=o[1],t.Percent=!0),$.decimal_separator==="."?/,/.test(r)&&(r=r.replace(/,/g,""),t.Grouping=!0):(r=r.replace(/(\\d)\\s+/g,"$1"),r=r.replace(/\\./g,""),r=r.replace(/,/,"."));let a=Number(r);if(a===null||isNaN(a)){let l=e.toLowerCase();if(l==="false")return{value:!1,type:4};if(l==="true")return{value:!0,type:4};let d=this.TestDate(e);if(d!==!1&&!isNaN(d)){let c=new Date(d),h=c.getUTCFullYear();if(h>=Yr-200&&h<=Yr+200)return t={Date:!0},(c.getHours()||c.getMinutes()||c.getSeconds())&&(t.Time=!0),{value:Lr(d),type:3,hints:t}}return{value:e,type:2}}if(s&&(a=-a),o){let l=a<0?-1:1,d=(l*a).toString().split(".");d[0]=("00"+d[0]).replace(/(\\d\\d)$/,".$1"),a=Number(d.join(""))*l}return/e/.test(e)&&(t.Exponential=!0),{value:a,type:3,hints:t}}},fo=new Gt;var Mt={top:{},left:{},bottom:{},right:{},diagonal:{}},Ne=class i{static default_styles={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"mm-dd-yy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yy h:mm",37:"#,##0 ;(#,##0)",38:"#,##0 ;[Red](#,##0)",39:"#,##0.00;(#,##0.00)",40:"#,##0.00;[Red](#,##0.00)",45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@"};theme=new be;cell_xfs=[];fonts=[];borders=[];fills=[];number_formats=[];base_number_format_id=200;dxf_styles=[];modified=!1;Clamp(e,t,r){return Math.max(t,Math.min(e,r))}TintColor(e,t){let r=parseInt(e.substr(0,2),16),n=parseInt(e.substr(2,2),16),s=parseInt(e.substr(4,2),16);return t<0?(r=Math.round(r*t+r),n=Math.round(n*t+n),s=Math.round(s*t+s)):(r=Math.round((255-r)*t+r),n=Math.round((255-n)*t+n),s=Math.round((255-s)*t+s)),[r,n,s].map(o=>{let a=this.Clamp(o,0,255).toString(16);return a.length<2?"0"+a:a}).join("")}StyleOptionsFromProperties(e){let t=JSON.parse(JSON.stringify(e));for(let d of Object.keys(t))t[d]==="none"&&delete t[d];let r={},n={pattern_type:"none"},s=JSON.parse(JSON.stringify(Mt)),o={font:r,border:s};t.number_format&&(o.number_format={format:Re.Translate(t.number_format),symbolic_name:t.number_format}),t.font_size?.unit&&t.font_size.value&&(t.font_size.unit!=="pt"?console.warn("can\'t handle non-point font (FIXME)"):r.size=t.font_size.value),t.bold&&(r.bold=!0),t.italic&&(r.italic=!0),t.underline&&(r.underline=!0),t.text&&(t.text.text?r.color_argb=t.text.text:typeof t.text.theme=="number"&&(r.color_theme=t.text.theme,t.text.tint&&(r.color_tint=t.text.tint)));let a=(d,c)=>{d.width&&(c.style="thin",d.color.text?c.rgba=d.color.text:typeof d.color.theme=="number"?(c.theme=d.color.theme,d.color.tint&&(c.tint=d.color.tint)):c.color=64)},l=ve.CompositeBorders(t);switch(a(l.top,s.top),a(l.left,s.left),a(l.right,s.right),a(l.bottom,s.bottom),t.vertical_align){case"top":o.vertical_alignment="top";break;case"middle":o.vertical_alignment="center";break}switch(t.horizontal_align){case"center":o.horizontal_alignment="center";break;case"left":o.horizontal_alignment="left";break;case"right":o.horizontal_alignment="right";break}return t.fill&&(n.pattern_type="solid",t.fill.text?(n.fg_color={argb:t.fill.text},o.fill=n):typeof t.fill.theme=="number"&&(n.fg_color={theme:t.fill.theme},t.fill.tint&&(n.fg_color.tint=t.fill.tint),o.fill=n)),t.wrap&&(o.wrap=!0),o}CellXfToStyle(e){let t={},r=i.default_styles[e.number_format];if(!r){for(let l of this.number_formats)if(l.id===e.number_format&&l.format){r=l.format;break}}if(r){let l=/\\[\\$(.)-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(l,"$1");let d=/\\[\\$-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(d,""),t.number_format=r}let n=this.fonts[0],s=this.fonts[e.font||0];s&&(s.bold&&(t.bold=!0),s.italic&&(t.italic=!0),s.underline&&(t.underline=!0),s.strike&&(t.strike=!0),n&&n.size&&s.size&&n.size!==s.size&&(t.font_size={value:100*s.size/n.size,unit:"%"}),s.color_argb?t.text={text:"#"+(s.color_argb.length>6?s.color_argb.substr(s.color_argb.length-6):s.color_argb)}:typeof s.color_theme=="number"&&(t.text={theme:s.color_theme}));let o=this.fills[e.fill||0];if(o&&o.pattern_type!=="none"){if(o.pattern_type==="gray"){let l=Math.round((o.pattern_gray||0)/1e3*255);t.fill={text:`rgb(${l}, ${l}, ${l})`}}o.pattern_type==="solid"&&o.fg_color&&(o.fg_color.argb?t.fill={text:"#"+(o.fg_color.argb.length>6?o.fg_color.argb.substr(o.fg_color.argb.length-6):o.fg_color.argb)}:typeof o.fg_color.theme=="number"&&(t.fill={theme:o.fg_color.theme},o.fg_color.tint&&(t.fill.tint=Math.round(o.fg_color.tint*1e3)/1e3)))}switch(e.horizontal_alignment){case"center":t.horizontal_align="center";break;case"right":t.horizontal_align="right";break;case"left":t.horizontal_align="left";break}switch(e.vertical_alignment){case"center":t.vertical_align="middle";break;case"top":t.vertical_align="top";break;case"bottom":t.vertical_align="bottom";break}e.wrap_text&&(t.wrap=!0);let a=this.borders[e.border||0];return a&&(a.bottom.style&&(a.bottom.style==="double"?t.border_bottom=2:t.border_bottom=1),a.left.style&&(t.border_left=1),a.top.style&&(t.border_top=1),a.right.style&&(t.border_right=1)),t}CellXfToStyles(){return this.cell_xfs.map(e=>this.CellXfToStyle(e))}EnsureNumberFormat(e){if(typeof e.format>"u"||e.symbolic_name&&/^general$/i.test(e.symbolic_name))return 0;for(let r=0;r<100;r++){let n=i.default_styles[r];if(n&&n===e.format)return r}for(let r of this.number_formats)if(r.format===e.format)return r.id||0;this.modified=!0;let t={id:this.base_number_format_id++,format:e.format};return this.number_formats.push(t),t.id}CompareBorderEdge(e,t){return e.color===t.color&&e.rgba===t.rgba&&e.style===t.style&&e.theme===t.theme&&e.tint===t.tint}CompareBorder(e,t){return this.CompareBorderEdge(e.top,t.top)&&this.CompareBorderEdge(e.left,t.left)&&this.CompareBorderEdge(e.bottom,t.bottom)&&this.CompareBorderEdge(e.right,t.right)&&this.CompareBorderEdge(e.diagonal,t.diagonal)}EnsureBorder(e){for(let r=0;r<this.borders.length;r++){let n=this.borders[r];if(this.CompareBorder(n,e))return r}this.modified=!0;let t=JSON.parse(JSON.stringify(e));return this.borders.push(t),this.borders.length-1}MatchColor(e,t){return!e&&!t?!0:!e||!t?!1:e.argb===t.argb&&e.indexed===t.indexed&&e.theme===t.theme&&e.tint===t.tint}EnsureFill(e){for(let r=0;r<this.fills.length;r++){let n=this.fills[r];if(this.MatchColor(e.bg_color,n.bg_color)&&this.MatchColor(e.fg_color,n.fg_color)&&e.pattern_gray===n.pattern_gray&&e.pattern_type===n.pattern_type)return r}this.modified=!0;let t={...e};return this.fills.push(t),this.fills.length-1}EnsureFont(e){let t={...this.fonts[0],...e};for(let r=0;r<this.fonts.length;r++){let n=this.fonts[r];if(n.bold===t.bold&&n.italic===t.italic&&n.underline===t.underline&&n.size===t.size&&n.strike===t.strike&&n.color_argb===t.color_argb&&n.color_theme===t.color_theme&&n.color_tint===t.color_tint&&n.family===t.family)return r}return this.modified=!0,this.fonts.push(t),this.fonts.length-1}EnsureStyle(e){let t=this.EnsureFont(e.font||{}),r=this.EnsureBorder(e.border||Mt),n=this.EnsureNumberFormat(e.number_format||{}),s=this.EnsureFill(e.fill||{pattern_type:"none"});for(let a=0;a<this.cell_xfs.length;a++){let l=this.cell_xfs[a];if(l.font===t&&l.fill===s&&l.border===r&&l.number_format===n&&!!l.wrap_text==!!e.wrap&&(!e.horizontal_alignment&&!l.horizontal_alignment||e.horizontal_alignment===l.horizontal_alignment)&&(!e.vertical_alignment&&!l.vertical_alignment||e.vertical_alignment===l.vertical_alignment))return a}this.modified=!0;let o={font:t,fill:s,border:r,number_format:n};return e.horizontal_alignment&&(o.horizontal_alignment=e.horizontal_alignment),e.vertical_alignment&&(o.vertical_alignment=e.vertical_alignment),e.wrap&&(o.wrap_text=!0),this.cell_xfs.push(o),this.cell_xfs.length-1}FromXML(e,t){let r=R.FindAll.bind(R,e);this.theme=t;let n=r("styleSheet/numFmts/numFmt");this.number_formats=n.map(d=>({id:Number(d.a$?.numFmtId||0),format:Qe(d.a$?.formatCode||"")})),n=r("styleSheet/borders/border"),this.borders=n.map(d=>{let c=JSON.parse(JSON.stringify(Mt));return d.left&&(c.left.style=d.left.a$.style,c.left.color=Number(d.left.color?.a$?.indexed)),d.right&&(c.right.style=d.right.a$.style,c.right.color=Number(d.right.color?.a$?.indexed)),d.top&&(c.top.style=d.top.a$.style,c.top.color=Number(d.top.color?.a$?.indexed)),d.bottom&&(c.bottom.style=d.bottom.a$.style,c.bottom.color=Number(d.bottom.color?.a$?.indexed)),c}),n=r("styleSheet/cellXfs/xf"),this.cell_xfs=n.map(d=>{let c={number_format:Number(d.a$.numFmtId),font:Number(d.a$.fontId),fill:Number(d.a$.fillId),border:Number(d.a$.borderId),xfid:Number(d.a$.xfId)};return d.alignment&&(c.horizontal_alignment=d.alignment.a$.horizontal,c.vertical_alignment=d.alignment.a$.vertical,c.wrap_text=!!d.alignment.a$.wrapText),c});let s=d=>{let c={pattern_type:"none"};if(d.patternFill){let h=d.patternFill.a$?.patternType;switch(h){case"none":case void 0:break;case"solid":c.pattern_type="solid",d.patternFill.fgColor&&(c.fg_color={theme:d.patternFill.fgColor.a$?.theme?Number(d.patternFill.fgColor.a$.theme):void 0,indexed:d.patternFill.fgColor.a$?.indexed?Number(d.patternFill.fgColor.a$.indexed):void 0,tint:d.patternFill.fgColor.a$?.tint?Number(d.patternFill.fgColor.a$.tint):void 0,argb:d.patternFill.fgColor.a$?.rgb});break;default:{let u=h?.match(/^gray(\\d+)$/);if(u){c.pattern_type="gray",c.pattern_gray=Number(u[1]);break}}}}return c};n=r("styleSheet/fills/fill"),this.fills=n.map(s);let o=d=>{let c={};return c.italic=typeof d.i<"u",c.bold=typeof d.b<"u",c.underline=typeof d.u<"u",c.strike=typeof d.strike<"u",d.sz&&(c.size=Number(d.sz.a$.val)),d.scheme&&(c.scheme=d.scheme.a$.val),d.name&&(c.name=d.name.a$.val),d.family&&(c.family=Number(d.family.a$.val)),d.color&&(d.color.a$?.theme&&(c.color_theme=Number(d.color.a$.theme)),d.color.a$?.tint&&(c.color_tint=Number(d.color.a$.tint)),d.color.a$?.rgb&&(c.color_argb=d.color.a$.rgb)),c};n=r("styleSheet/fonts/font"),this.fonts=n.map(o);let a=d=>{let c={};return d.a$.rgb?c.text="#"+d.a$.rgb.substring(2):d.a$.theme&&(c.theme=Number(d.a$.theme)||0,d.a$.tint&&(c.tint=Math.round(d.a$.tint*1e3)/1e3)),c},l=r("styleSheet/dxfs/dxf");this.dxf_styles=l.map(d=>{let c={};return d.font&&(c.bold=!!d.font.b,c.italic=!!d.font.i&&d.font.i.a$.val!=="0"),d.font?.color?.a$&&(c.text=a(d.font.color)),d.fill?.patternFill?.bgColor?.a$&&(c.fill=a(d.fill.patternFill.bgColor)),c})}};var ae=(i,e,t,r)=>{let s=`rId${Object.keys(i).length+1}`;return i[s]={id:s,type:e,target:t,mode:r},s};var Ht=/[\\s-+=<>!()]/;var $t=34,Ut=39,ss=160,jr=32,as=9,os=10,ls=13,ue=48,Ge=57,Vt=46,zt=43,Me=45,Dr=40,Bt=41,$e=44,cs=37,Lt=95,rt=36,ds=123,hs=125,Ue=91,Hr=93,us=33,Or=59,fs=35,ms=64,Se=65,Ve=97,ps=69,bs=101,it=90,nt=122,gs=105;var Yt=192,jt=312,Dt={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},ys=Object.keys(Dt).sort((i,e)=>e.length-i.length),xs={"-":100,"+":100},Te=class{argument_separator=",";decimal_mark=".";flags={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0};r1c1_regex=/[rR]((?:\\[[-+]{0,1}\\d+\\]|\\d+))[cC]((?:\\[[-+]{0,1}\\d+\\]|\\d+))$/;argument_separator_char=$e;decimal_mark_char=Vt;imaginary_char=gs;imaginary_number="i";id_counter=0;expression="";data=[];index=0;length=0;valid=!0;error_position;error;dependencies={addresses:{},ranges:{}};address_refcount={};full_reference_list=[];Walk(e,t){switch(e.type){case"address":case"missing":case"literal":case"complex":case"identifier":case"operator":case"structured-reference":t(e);return;case"dimensioned":t(e)&&(this.Walk(e.expression,t),this.Walk(e.unit,t));return;case"range":t(e)&&(this.Walk(e.start,t),this.Walk(e.end,t));return;case"binary":t(e)&&(this.Walk(e.left,t),this.Walk(e.right,t));return;case"unary":t(e)&&this.Walk(e.operand,t);return;case"group":t(e)&&e.elements.forEach(r=>this.Walk(r,t));return;case"call":t(e)&&e.args.forEach(r=>this.Walk(r,t))}}Transpose(e){let t=e.length,r=[],n=0;for(let s=0;s<t;s++)Array.isArray(e[s])&&(n=Math.max(n,e[s].length));for(let s=0;s<n;s++){r[s]=[];for(let o=0;o<t;o++)r[s][o]=e[o][s]}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},n=t.missing??"(missing)",{convert_decimal:s,convert_argument_separator:o,convert_imaginary_number:a,long_structured_references:l,table_name:d}=t,c=this.argument_separator+" ";o===","?c=", ":o===";"&&(c="; ");let h=this.imaginary_number;a&&(h=a);let u=s===","?",":".",p=this.decimal_mark===","?/,/:/\\./,f=this.decimal_mark===","?/,/g:/\\./g;switch(e.type){case"address":return this.AddressLabel(e,r);case"range":return this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return n;case"array":return"{"+this.Transpose(e.values).map(g=>g.map(y=>typeof y=="string"?\'"\'+y+\'"\':y).join(", ")).join("; ")+"}";case"binary":return this.Render(e.left,t)+" "+e.operator+" "+this.Render(e.right,t);case"unary":return e.operator+this.Render(e.operand,t);case"complex":if(e.text)return s?e.text.replace(f,u):e.text;{let g=Math.abs(e.imaginary).toString();if((s===","||this.decimal_mark===",")&&(g=g.replace(/\\./,",")),e.real){let y=e.real.toString();(s===","||this.decimal_mark===",")&&(y=y.replace(/\\./,","));let N=Math.abs(e.imaginary);return`${y}${e.imaginary<0?" - ":" + "}${N===1?"":g}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${g}i`}break;case"literal":if(typeof e.value=="string")return\'"\'+e.value.replace(/"/g,\'""\')+\'"\';if(s&&typeof e.value=="number")if(e.text){let g=e.text;return s===","&&this.decimal_mark==="."&&(g=g.replace(/,/g,"")),g.replace(p,u)}else return e.value.toString().replace(/\\./,u);else if(e.text)return e.text;return e.value.toString();case"identifier":return e.name;case"operator":return"["+e.operator+"]";case"group":return e.explicit?"("+e.elements.map(g=>this.Render(g,t)).join(c)+")":e.elements.map(g=>this.Render(g,t)).join(c);case"call":return e.name+"("+e.args.map(g=>this.Render(g,t)).join(c)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let g=e.column;/[^A-Za-z]/.test(g)&&(g="["+g+"]");let y=e.table;switch(!y&&l&&d&&(y=d),e.scope){case"all":return`${y}[[#all],${g}]`;case"row":return l?`${y}[[#this row],${g}]`:`${y}[@${g}]`;case"column":return`${y}[${g}]`}throw new Error("unhandled scope in structured reference")}}return"??"}Parse(e){switch(e=e.trim(),e[0]==="="&&(e=e.substr(1).trim()),this.expression=e,this.data=[],this.length=e.length,this.index=0,this.valid=!0,this.error_position=void 0,this.error=void 0,this.dependencies.addresses={},this.dependencies.ranges={},this.address_refcount={},this.full_reference_list=[],this.id_counter=0,this.argument_separator){case";":this.argument_separator_char=Or;break;default:this.argument_separator_char=$e;break}switch(this.decimal_mark){case",":this.decimal_mark_char=$e;break;default:this.decimal_mark_char=Vt;break}for(let n=0;n<this.length;n++)this.data[n]=e.charCodeAt(n);let t=this.ParseGeneric(),r={};for(let n of Object.keys(this.dependencies.addresses))this.address_refcount[n]&&(r[n]=this.dependencies.addresses[n]);return this.dependencies.addresses=r,{expression:t||void 0,valid:this.valid,error:this.error,error_position:this.error_position,dependencies:this.dependencies,separator:this.argument_separator,decimal_mark:this.decimal_mark,full_reference_list:this.full_reference_list.slice(0)}}ColumnLabel(e){if(e===1/0)return"";let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}AddressLabel(e,t){let r=e.column;!e.absolute_column&&e.column!==1/0&&(r+=t.columns);let n=e.row;if(!e.absolute_row&&e.row!==1/0&&(n+=t.rows),n<0||r<0||n===1/0&&r===1/0)return"#REF";let s="";return e.sheet&&(s=(Ht.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!"),n===1/0?s+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?s+(e.absolute_row?"$":"")+(n+1):s+(e.absolute_column?"$":"")+this.ColumnLabel(r)+(e.absolute_row?"$":"")+(n+1)}ParseGeneric(e=[0]){let t=[];for(;this.index<this.length;){let r=this.ParseNext(t.length===0);if(typeof r=="number"){if(e.some(n=>r===n))break;if(r===Dr){this.index++;let n=this.ParseGeneric([Bt]);this.index++,n&&t.push({type:"group",id:this.id_counter++,elements:[n],explicit:!0})}else{let n=this.ConsumeOperator();n?t.push(n):(this.error=`unexpected character [1]: ${String.fromCharCode(r)}, 0x${r.toString(16)}`,this.valid=!1,this.index++)}}else t.push(r)}if(t.length){if(t=this.BinaryToRange2(t),this.flags.fractions){let r=[],n=o=>o.type==="literal"&&typeof o.value=="number"&&o.value%1===0,s=0;for(;s<t.length-3;s++)if(n(t[s])&&n(t[s+1])&&t[s+2].type==="operator"&&t[s+2].operator==="/"&&n(t[s+3])){let o=t[s],a=t[s+1],l=t[s+3],d=(o.value<0?-1:1)*(a.value/l.value);s+=3,r.push({id:t[s].id,type:"literal",text:this.expression.substring(o.position,l.position+1),value:o.value+d,position:o.position})}else r.push(t[s]);for(;s<t.length;s++)r.push(t[s]);t=r}if(t=t.map(r=>r.type==="identifier"&&r.name===this.imaginary_number?{type:"complex",real:0,imaginary:1,position:r.position,text:r.name,id:this.id_counter++}:r),this.flags.dimensioned_quantities){let r=[],n;for(let s=0;s<t.length;s++){let o=t[s];if(!n)n=o;else if(o.type==="identifier"&&(n.type==="literal"||n.type==="group"||n.type==="call")){let a=o;for(;t[s+1]?.type==="identifier";)a.name+=" "+t[++s].name;r.push({type:"dimensioned",expression:n,unit:o,id:this.id_counter++}),n=void 0}else r.push(n),n=o}n&&r.push(n),t=r}}return t.length===0?null:t.length===1?t[0]:this.BinaryToComplex(this.ArrangeUnits(t))}UnitToAddress(e){if(e.type==="literal"){if(typeof e.value=="number"&&e.value>0&&!/\\./.test(e.text||""))return{type:"address",position:e.position,label:e.value.toString(),row:e.value-1,id:this.id_counter++,column:1/0}}else{let t,r=e.name,n=r.split("!");if(n.length>1&&(t=n.slice(0,n.length-1).join("!"),r=r.substr(t.length+1),t[0]==="\'"))if(t.length>1&&t[t.length-1]==="\'")t=t.substr(1,t.length-2);else return;let s=r[0]==="$";r=(s?r.substr(1):r).toUpperCase();let o=Number(r);if(isNaN(o)){if(/[A-Z]{1,3}/.test(r)){let a=-1;for(let l=0;l<r.length;l++){let d=r[l].charCodeAt(0);a=26*(1+a)+(d-Se)}return{type:"address",position:e.position,absolute_column:s,label:e.name,column:a,id:this.id_counter++,row:1/0,sheet:t}}}else if(o>0&&o!==1/0&&!/\\./.test(r))return{type:"address",position:e.position,absolute_row:s,label:e.name,row:o-1,id:this.id_counter++,column:1/0,sheet:t}}}BinaryToRange2(e){let t=[];for(let r=0;r<e.length;r++){let n=e[r],s=e[r+1],o=e[r+2],a,l="",d;if(n&&s&&o&&s.type==="operator"&&s.operator===":"){if(n.type==="address"&&o.type==="address"){let c=n.position+n.label.length,h=o.position;a={type:"range",id:this.id_counter++,position:n.position,start:n,end:o,label:n.label+this.expression.substring(c,h)+o.label},l=a.start.label+":"+a.end.label,this.address_refcount[a.start.label]--,this.address_refcount[a.end.label]--;let u=[n.position,o.position];this.full_reference_list=this.full_reference_list.filter(p=>p.position!==u[0]&&p.position!==u[1])}else if((n.type==="literal"||n.type==="identifier")&&(o.type==="literal"||o.type==="identifier")){let c=this.UnitToAddress(n);if(!c&&n.type==="literal"&&typeof n.value=="number"&&n.value<0){let u={...n,text:(n.text||"").replace(/^-/,""),position:n.position+1,value:-n.value};c=this.UnitToAddress(u),c&&(d={type:"operator",operator:"-",position:n.position,id:this.id_counter++})}let h=this.UnitToAddress(o);c&&h&&(c.column===1/0&&h.column===1/0||c.row===1/0&&h.row===1/0)&&(l=c.label+":"+h.label,a={type:"range",id:this.id_counter++,position:c.position,start:c,end:h,label:l})}}a?(d&&t.push(d),t.push(a),this.dependencies.ranges[l]=a,this.full_reference_list.push(a),r+=2):t.push(n)}return t}BinaryToComplex(e){if(e.type==="binary")if((e.operator==="+"||e.operator==="-")&&e.left.type==="literal"&&typeof e.left.value=="number"&&e.right.type==="complex"&&!e.right.composited){let t="";t=this.expression.substring(e.left.position,e.right.position+(e.right.text?.length||0));let r=e.right.imaginary;return e.operator==="-"&&(r=-r),{type:"complex",position:e.left.position,text:t,id:this.id_counter++,imaginary:r,real:e.left.value,composited:!0}}else e.left=this.BinaryToComplex(e.left),e.right=this.BinaryToComplex(e.right);else if(e.type==="unary"&&(e.operator==="-"||e.operator==="+")&&e.operand.type==="complex"&&e.operand.text===this.imaginary_number)return{...e.operand,position:e.position,text:this.expression.substring(e.position,e.operand.position+(e.operand.text||"").length),imaginary:e.operand.imaginary*(e.operator==="-"?-1:1)};return e}BinaryToRangeX(e){if(e.type==="binary"){if(e.operator===":"){let t,r="";if(e.left.type==="address"&&e.right.type==="address"){let n=e.left.position+e.left.label.length,s=e.right.position;t={type:"range",id:this.id_counter++,position:e.left.position,start:e.left,end:e.right,label:e.left.label+this.expression.substring(n,s)+e.right.label},r=t.start.label+":"+t.end.label,this.address_refcount[t.start.label]--,this.address_refcount[t.end.label]--;let o=[e.left.position,e.right.position];this.full_reference_list=this.full_reference_list.filter(a=>a.position!==o[0]&&a.position!==o[1])}else if((e.left.type==="literal"||e.left.type==="identifier")&&(e.right.type==="literal"||e.right.type==="identifier")){let n=this.UnitToAddress(e.left),s=this.UnitToAddress(e.right);n&&s&&(n.column===1/0&&s.column===1/0||n.row===1/0&&s.row===1/0)&&(r=n.label+":"+s.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:n,end:s,label:r})}if(t)return this.dependencies.ranges[r]=t,this.full_reference_list.push(t),t;this.error="unexpected character: :",this.valid=!1}e.left=this.BinaryToRangeX(e.left),e.right=this.BinaryToRangeX(e.right)}return e}ArrangeUnits(e){if(e.length===0)return{type:"missing",id:this.id_counter++};if(e.length===1)return e[0];let t=[];for(let r=0;r<e.length;r++){let n=e[r];if(n.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(xs[n.operator]){let s=this.BinaryToComplex(this.ArrangeUnits(e.slice(r+1)));if(!this.valid)return{type:"group",id:this.id_counter++,elements:e,explicit:!1};s.type==="binary"?(s.left={type:"unary",id:this.id_counter++,operator:n.operator,operand:s.left,position:n.position},n=s):n={type:"unary",id:this.id_counter++,operator:n.operator,operand:s,position:n.position},r=e.length}else return this.error=`unexpected character [2]: ${n.operator}`,this.error_position=n.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1};else{t.push(n);continue}if(t.length<2)t.push(n);else if(t[t.length-1].type==="operator"){let s=t[t.length-2],o=t[t.length-1],a=o.operator,l={type:"binary",id:this.id_counter++,left:s,operator:a,position:o.position,right:n};s.type==="binary"&&Dt[a]>Dt[s.operator]&&(l.left=s.left,l.operator=s.operator,l.position=s.position,l.right={type:"binary",id:this.id_counter++,left:s.right,right:n,operator:a,position:o.position}),t.splice(-2,2,l)}else return this.error="multiple expressions",this.error_position=n.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1}}return t[0]}ParseNext(e=!0){this.ConsumeWhiteSpace();let t=this.data[this.index];if(t===$t)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ue&&t<=Ge||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===ds)return this.ConsumeArray();if(e&&(t===Me||t===zt)){let r=this.data[this.index+1];if(r>=ue&&r<=Ge||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Se&&t<=it||t>=Ve&&t<=nt||t===Lt||t===fs||t===Ut||t===rt||t===Ue||t>=Yt&&t<=jt)return this.ConsumeToken(t);return t}ConsumeArray(){let e={type:"array",id:this.id_counter++,values:[],position:this.index};this.index++;let t=0,r=0;for(;this.index<this.length;){let n=this.ParseNext(),s=this.index;if(typeof n=="number")switch(this.index++,n){case Or:r++,t=0;break;case $e:t++;break;case hs:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=s,this.valid=!1);break}else switch(n.type){case"literal":e.values[t]||(e.values[t]=[]),e.values[t][r]=n.value;break;default:this.valid&&(this.error="invalid value in array literal",this.error_position=s,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of ys)if(this.expression.substr(this.index,e.length)===e){let t=this.index;return this.index+=e.length,{type:"operator",id:this.id_counter++,operator:e,position:t}}return null}ConsumeArguments(){this.index++;let e=0,t=[];for(;this.index<this.length;){let r=this.ParseGeneric([this.argument_separator_char,Bt]);r!==null&&t.push(r);let n=this.data[this.index];if(n===this.argument_separator_char){this.index++,e++;for(let s=t.length;s<e;s++)t.push({type:"missing",id:this.id_counter++})}else if(n===Bt)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,n=e===Ut,s=0,o=!1;for(e===Ue&&(s=1,o=!0),++this.index;this.index<this.length;this.index++){let c=this.data[this.index];if(c>=Se&&c<=it||c>=Ve&&c<=nt||c>=Yt&&c<=jt||c===Lt||c===rt||c===Vt||c===us||n||c>=ue&&c<=Ge||c===Ue||s>0&&c===Hr||c===Me&&this.flags.r1c1&&s===1||s>0&&c===ms&&this.data[this.index-1]===Ue||s===1&&(c===$e||c===jr)||s>1)t.push(c),c===Ue&&(s++,o=!0),c===Hr&&s--,c===Ut&&(n=!1);else break}let a=t.map(c=>String.fromCharCode(c)).join("");if(n)return this.error="unbalanced single quote",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:a,position:r};if(s)return this.error="unbalanced square bracket",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:a,position:r};if(a.toLowerCase()==="true")return{type:"literal",id:this.id_counter++,value:!0,position:r};if(a.toLowerCase()==="false")return{type:"literal",id:this.id_counter++,value:!1,position:r};if(this.ConsumeWhiteSpace(),this.data[this.index]===Dr){let c=this.ConsumeArguments();return{type:"call",id:this.id_counter++,name:a,args:c,position:r}}if(this.flags.spreadsheet_semantics){let c=this.ConsumeAddress(a,r);if(c)return c;if(o){let h=this.ConsumeStructuredReference(a,r);if(h)return h}}let d={type:"identifier",id:this.id_counter++,name:a,position:r};return this.full_reference_list.push(d),d}ConsumeStructuredReference(e,t){let r=t,n=e.length,s=e,o="",a=0;for(;a<n;a++){if(e[a]==="["){e=e.substring(a);break}o+=e[a]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let l=e.split(",").map(u=>u.trim()),d="column",c="";if(l.length>2)return;l.length===2?(/\\[#this row\\]/i.test(l[0])?d="row":/\\[#all\\]/i.test(l[0])&&(d="all"),c=l[1]):(c=l[0],c[0]==="@"&&(d="row",c=c.substring(1,c.length))),c[0]==="["&&c[c.length-1]==="]"&&(c=c.substring(1,c.length-1));let h={type:"structured-reference",id:this.id_counter++,label:s,position:t,scope:d,column:c,table:o};return this.full_reference_list.push(h),h}ConsumeAddress(e,t){let r=t,n=e.length,s,o=e.split("!");if(o.length>1&&(s=o.slice(0,o.length-1).join("!"),t+=s.length+1),this.flags.r1c1){let h=o[o.length-1].match(this.r1c1_regex);if(h){let u={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:s,r1c1:!0};return h[1][0]==="["?(u.offset_row=!0,u.row=Number(h[1].substring(1,h[1].length-1))):u.row=Number(h[1])-1,h[2][0]==="["?(u.offset_column=!0,u.column=Number(h[2].substring(1,h[2].length-1))):u.column=Number(h[2])-1,u}}let a=this.ConsumeAddressColumn(t);if(!a)return null;t=a.position;let l=this.ConsumeAddressRow(t);if(!l)return null;t=l.position;let d=s?s+e.substr(s.length,t-r).toUpperCase():e.substr(0,t-r).toUpperCase();s&&s[0]==="\'"&&(s=s.substr(1,s.length-2));let c={type:"address",id:this.id_counter++,label:d,row:l.row,column:a.column,absolute_row:l.absolute,absolute_column:a.absolute,position:r,sheet:s};return n!==t-r?null:(this.dependencies.addresses[c.label]=c,this.address_refcount[c.label]=(this.address_refcount[c.label]||0)+1,this.full_reference_list.push(c),c)}ConsumeAddressRow(e){let t=this.data[e]===rt;t&&e++;let r=e,n=0;for(;;e++){let s=this.data[e];if(s>=ue&&s<=Ge)n*=10,n+=s-ue;else break}return r===e?!1:{absolute:t,row:n-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,n=this.data[e]===rt;for(n&&e++;;e++,r++){if(r>=4)return!1;let s=this.data[e];if(s>=Se&&s<=it)t=26*(1+t)+(s-Se);else if(s>=Ve&&s<=nt)t=26*(1+t)+(s-Ve);else break}return t<0?!1:{absolute:n,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,n=!1,s=0,o=0,a=0,l="integer",d=0,c=!1,h=this.index;for(;this.index<this.length;this.index++,d++){let p=this.data[this.index];if(p===this.decimal_mark_char)if(l==="integer")l="fraction";else break;else if(p===cs){s/=100,a/=100,this.index++;break}else if(p===zt||p===Me)if(d===0)p===Me&&(n=!0);else break;else if(p===ps||p===bs)if(l==="integer"||l==="fraction")l="exponent",this.index<this.length-1&&(this.data[this.index+1]===zt?this.index++:this.data[this.index+1]===Me&&(this.index++,r=!0));else break;else if(p===this.imaginary_char){let f=this.data[this.index+1];if(f>=Se&&f<=it||f>=Ve&&f<=nt||f>=Yt&&f<=jt||f===Lt)break;if(l==="integer"||l==="fraction"){this.index++,c=!0;break}}else if(p>=ue&&p<=Ge)switch(l){case"integer":s=s*10+(p-ue);break;case"fraction":a=a*10+(p-ue),o++;break;case"exponent":t=t*10+(p-ue);break}else break}let u=s+a/Math.pow(10,o);return l==="exponent"&&(u=u*Math.pow(10,(r?-1:1)*t)),c?{type:"complex",id:this.id_counter++,position:e,imaginary:n?-u:u,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:n?-u:u,text:this.expression.substring(h,this.index)||""}}ConsumeString(){this.index++;let e=[];for(;this.index<this.length;this.index++){let t=this.data[this.index];if(t===$t&&(this.index++,this.index>=this.length||this.data[this.index]!==$t))break;e.push(t)}return e.map(t=>String.fromCharCode(t)).join("")}ConsumeWhiteSpace(){for(;this.index<this.length;){let e=this.data[this.index];if(e===jr||e===as||e===os||e===ls||e===ss)this.index++;else return}}};var Jr=class i{static _instance=new i;constructor(){}static get instance(){return this._instance}HTML(e){let t=[];for(let r of e){let n=[];for(let s of r)s.pre&&n.push("<pre>"),s.emphasis&&n.push("<em>"),s.strong&&n.push("<strong>"),s.strike&&n.push("<strike>"),n.push(s.text),s.strike&&n.push("</strike>"),s.strong&&n.push("</strong>"),s.emphasis&&n.push("</em>"),s.pre&&n.push("</pre>");t.push(n.join(""))}return t.join(`<br/>\n`)}Dummy(e=""){return e.split(/\\n/).map(t=>[{text:t}])}Parse(e=""){let t=this.Tokenize(e);for(let r=0;r<t.length;r++){let n=t[r];if(n.type==="delimeter"){let s=t[r-1],o=t[r+1],a=!s||s.type==="whitespace"||s.type==="newline",l=s&&s.type==="text"&&/[^\\w\\d]$/.test(s.text),d=!o||o.type==="whitespace"||o.type==="newline",c=o&&o.type==="text"&&/^[^\\w\\d]/.test(o.text);n.left_flanking=!d&&(!c||a),n.right_flanking=!a&&(!l||d||c)}}return this.ApplyFormatting(t),this.Consolidate(t)}IsWhitespace(e){return e===" "||e===" "}IsNewline(e){return e==="\\r"||e===`\n`}IsDelimeter(e){return e==="*"||e==="_"||e==="~"}Consolidate(e){let t=[],r={},n=[],s={type:"text",text:""};for(let o of e)if(o.type==="newline")s.text.length&&n.push(s),s={...r,text:"",type:"text"},t.push(n),n=[];else switch((!!r.strong!=!!o.strong||!!r.emphasis!=!!o.emphasis||!!r.strike!=!!o.strike)&&(r.strong=!!o.strong,r.emphasis=!!o.emphasis,r.strike=!!o.strike,s.text.length&&n.push(s),s={...r,text:"",type:"text"}),o.type){case"text":case"whitespace":s.text+=o.text;break;case"delimeter":for(let a=0;a<o.length;a++)s.text+=o.char;break}return s.text.length&&n.push(s),n.length&&t.push(n),t}ApplyFormatting(e,t){let r=0,n=e.length;for(r=0;r<n;r++){let s=e[r];if(s.type==="delimeter"){if(t&&s.right_flanking&&t.char===s.char&&s.length>0)return{index:r,token:s};if(s.left_flanking){let o=this.ApplyFormatting(e.slice(r+1),s);if(o.token){let a=Math.min(o.token.length,s.length),l=s.char==="~",d=!l&&!!(a%2),c=!l&&a>=2;for(let h=r+1;h<=r+o.index;h++)e[h].strong=!!e[h].strong||c,e[h].emphasis=!!e[h].emphasis||d,e[h].strike=!!e[h].strike||l;o.token.length-=a,s.length-=a,s.length>0?r--:r+=o.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,n=0,s=!1,o="";for(n=0;n<r;n++){let a=e[n];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(this.IsWhitespace(d))l+=d,n++;else break}t.push({type:"whitespace",text:l}),s=!1,o=""}else if(this.IsNewline(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(this.IsNewline(d))l+=d,n++;else break}t.push({type:"newline",text:l}),s=!1,o=""}else if(s)o+=a,s=!1;else if(this.IsDelimeter(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(d===a)l+=d,n++;else break}t.push({type:"delimeter",text:l,char:a,length:l.length}),s=!1,o=""}else a==="\\\\"?s=!0:o+=a}return o&&t.push({type:"text",text:o}),t}};var Xr={"c:tx":{"c:strRef":{"c:f":"","c:strCache":{"c:ptCount":{a$:{val:"1"}},"c:pt":{a$:{idx:"0"},"c:v":""}}}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},Qr={"c:tx":{"c:rich":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:r":{"a:rPr":{a$:{lang:""}},"a:t":""}}}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},st={"c:chartSpace":{a$:{"xmlns:c":"http://schemas.openxmlformats.org/drawingml/2006/chart","xmlns:a":"http://schemas.openxmlformats.org/drawingml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:c16r2":"http://schemas.microsoft.com/office/drawing/2015/06/chart"},"c:date1904":{a$:{val:"0"}},"c:lang":{a$:{val:"en-US"}},"c:roundedCorners":{a$:{val:"0"}},"mc:AlternateContent":{a$:{"xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006"},"mc:Choice":{a$:{Requires:"c14","xmlns:c14":"http://schemas.microsoft.com/office/drawing/2007/8/2/chart"},"c14:style":{a$:{val:"102"}}},"mc:Fallback":{"c:style":{a$:{val:"2"}}}},"c:chart":{},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"bg1"}}},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:printSettings":{"c:headerFooter":{},"c:pageMargins":{a$:{b:"0.75",l:"0.7",r:"0.7",t:"0.75",header:"0.3",footer:"0.3"}},"c:pageSetup":{}}}};var qr={"c:idx":{a$:{val:"0"}},"c:order":{a$:{val:"0"}},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"}}},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:invertIfNegative":{a$:{val:"0"}},"c:val":{"c:numRef":{"c:f":""}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-F52E-47BC-822F-A046A80610BE}"}}}}},Kr={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:barChart":{"c:barDir":{a$:{val:"col"}},"c:grouping":{a$:{val:"clustered"}},"c:varyColors":{a$:{val:"0"}},"c:ser":[],"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}}},"c:gapWidth":{a$:{val:"219"}},"c:overlap":{a$:{val:"-27"}},"c:axId":[{a$:{val:"47003664"}},{a$:{val:"1789284464"}}]},"c:catAx":{"c:axId":{a$:{val:"47003664"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"b"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"1789284464"}},"c:crosses":{a$:{val:"autoZero"}},"c:auto":{a$:{val:"1"}},"c:lblAlgn":{a$:{val:"ctr"}},"c:lblOffset":{a$:{val:"100"}},"c:noMultiLvlLbl":{a$:{val:"0"}}},"c:valAx":{"c:axId":{a$:{val:"1789284464"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"l"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:numFmt":{a$:{formatCode:"General",sourceLinked:"1"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"47003664"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"between"}}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}};var ei={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:doughnutChart":{"c:varyColors":{a$:{val:"1"}},"c:ser":{"c:idx":{a$:{val:"0"}},"c:order":{a$:{val:"0"}},"c:dPt":{"c:idx":{a$:{val:"3"}},"c:bubble3D":{a$:{val:"0"}},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent4"}}},"a:ln":{a$:{w:"19050"},"a:solidFill":{"a:schemeClr":{a$:{val:"lt1"}}}},"a:effectLst":{}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000007-E886-49A6-AE6D-C67D8A27530F}"}}}}},"c:cat":{"c:strRef":{"c:f":""}},"c:val":{"c:numRef":{"c:f":""}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-3689-4BB4-A84F-05B9F3BBE577}"}}}}},"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}},"c:showLeaderLines":{a$:{val:"1"}}},"c:firstSliceAng":{a$:{val:"0"}},"c:holeSize":{a$:{val:"75"}}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:legend":{"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{a$:{rtl:"0"},"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}};var ti={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:scatterChart":{"c:scatterStyle":{a$:{val:"lineMarker"}},"c:varyColors":{a$:{val:"0"}},"c:ser":[],"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}}},"c:axId":[{a$:{val:"2028657983"}},{a$:{val:"2023395087"}}]},"c:valAx":[{"c:axId":{a$:{val:"2028657983"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"b"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"25000"}},"a:lumOff":{a$:{val:"75000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"2023395087"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"midCat"}}},{"c:axId":{a$:{val:"2023395087"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"l"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:numFmt":{a$:{formatCode:"0.00",sourceLinked:"1"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"25000"}},"a:lumOff":{a$:{val:"75000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"2028657983"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"midCat"}}}],"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}},ri={"c:spPr":{"a:ln":{a$:{w:"19050",cap:"rnd"},"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"}}},"a:round":{}},"a:effectLst":{}},"c:marker":{"c:symbol":{a$:{val:"none"}}},"c:xVal":{"c:numRef":{"c:f":""}},"c:yVal":{"c:numRef":{"c:f":""}},"c:smooth":{a$:{val:"0"}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-1F6C-44A9-AA4F-6706F20CC72E}"}}}}};var Ze=class i{constructor(e,t=i.next_chart_index++){this.options=e;this.index=t}static next_chart_index=1;relationships={};UpdateChartTitle(e){let t=this.options.title||{type:"literal",value:""};if(t&&t.type==="literal"){let r=JSON.parse(JSON.stringify(Qr)),n=r["c:tx"]["c:rich"]["a:p"];n["a:r"]={"a:rPr":{a$:{lang:$.locale}},"a:t":t.value},e["c:title"]=r}else if(t){let r=JSON.parse(JSON.stringify(Xr));r["c:tx"]["c:strRef"]["c:f"]=t.label,e["c:title"]=r}}toJSON(){switch(this.options.type){case"column":case"bar":return this.CreateBarChart();case"scatter":case"scatter2":return this.CreateScatterChart();case"donut":return this.CreateDonutChart();default:console.info("unhandled chart type",this.options.type)}return this.CreateBarChart()}CreateScatterChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(ti));this.options.smooth&&(r["c:plotArea"]["c:scatterChart"]["c:scatterStyle"].a$.val="smoothMarker"),t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=t["c:chart"]["c:plotArea"]["c:scatterChart"]["c:ser"],s=!1;for(let o=0;o<this.options.data.length;o++){let a=JSON.parse(JSON.stringify(ri));if(a["c:idx"]={a$:{val:o.toString()}},a["c:order"]={a$:{val:o.toString()}},this.options.names&&this.options.names[o]){let l=this.options.names[o];switch(l.type){case"literal":a["c:tx"]={"c:v":l.value.toString()},s=!0;break;case"range":case"address":a["c:tx"]={"c:strRef":{"c:f":l.label}},s=!0;break}}o<6&&(a["c:spPr"]["a:ln"]["a:solidFill"]["a:schemeClr"].a$.val=`accent${o+1}`),a["c:yVal"]["c:numRef"]["c:f"]=this.options.data[o]?.label,this.options.labels2&&this.options.labels2[o]&&(a["c:xVal"]["c:numRef"]["c:f"]=this.options.labels2[o]?.label),this.options.smooth&&(a["c:smooth"]={a$:{val:1}}),n.push(a)}return s&&(t["c:chart"]["c:legend"]={"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}}}),e}CreateDonutChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(ei));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=r["c:plotArea"]["c:doughnutChart"];return n&&(n["c:ser"]["c:cat"]["c:strRef"]["c:f"]=this.options.labels?.label||"",n["c:ser"]["c:val"]["c:numRef"]["c:f"]=this.options.data[0]?.label||""),e}CreateBarChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(Kr));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=r["c:plotArea"]["c:barChart"];if(n){let s=n["c:barDir"];s&&(s.a$.val=this.options.type==="bar"?"bar":"col");let o=n["c:ser"];for(let a=0;a<this.options.data.length;a++){let l=JSON.parse(JSON.stringify(qr));l["c:idx"]={a$:{val:a.toString()}},l["c:order"]={a$:{val:a.toString()}},a<6&&(l["c:spPr"]["a:solidFill"]["a:schemeClr"].a$.val=`accent${a+1}`),!a&&this.options.labels&&(l["c:cat"]={"c:strRef":{"c:f":this.options.labels.label}}),l["c:val"]["c:numRef"]["c:f"]=this.options.data[a]?.label,o.push(l)}}return e}};var at=class i{constructor(e,t=i.next_image_index++){this.options=e;this.index=t;switch(e.mimetype){case"svg+xml":this.extension="svg";break;case"image/png":this.extension="png";break;case"jpg":this.extension="jpeg";break;case"svg":case"png":case"jpeg":case"gif":this.extension=e.mimetype;break;default:console.warn("unhandled mime type",e.mimetype);break}}static next_image_index=1;extension=""};var ii=9525,ze=class i{constructor(e=i.next_drawing_index++){this.index=e}static next_drawing_index=1;sheet_drawing_relationship=0;charts=[];images=[];relationships={};AddImage(e,t){let r=new at(e);if(r.extension){let n=ae(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",`../media/image${r.index}.${r.extension}`);this.images.push({image:r,relationship:n,anchor:t})}}AddChart(e,t){let r=new Ze(e),n=ae(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",`../charts/chart${r.index}.xml`);this.charts.push({chart:r,anchor:t,relationship:n})}CornerToJSON(e){return{"xdr:col":e.column,"xdr:colOff":(e.column_offset||0)*ii,"xdr:row":e.row,"xdr:rowOff":(e.row_offset||0)*ii}}AnchorToJSON(e){return{"xdr:from":{...this.CornerToJSON(e.from)},"xdr:to":{...this.CornerToJSON(e.to)}}}toJSON(){let e=this.images.map(n=>({a$:{editAs:"oneCell"},...this.AnchorToJSON(n.anchor),"xdr:pic":{"xdr:nvPicPr":{"xdr:cNvPr":{a$:{id:n.image.index+1,name:"Image "+n.image.index}},"xdr:cNvPicPr":{"a:picLocks":{a$:{noChangeAspect:1}}}},"xdr:blipFill":{"a:blip":{a$:n.image.extension==="svg"?{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships"}:{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:embed":n.relationship},"a:extLst":{"a:ext":[{a$:{uri:"{28A0092B-C50C-407E-A947-70E740481C1C}"},"a14:useLocalDpi":{a$:{"xmlns:a14":"http://schemas.microsoft.com/office/drawing/2010/main",val:0}}},n.image.extension==="svg"?{a$:{uri:"{96DAC541-7B7A-43D3-8B79-37D633B846F1}"},"asvg:svgBlip":{a$:{"xmlns:asvg":"http://schemas.microsoft.com/office/drawing/2016/SVG/main","r:embed":n.relationship}}}:void 0]}},"a:stretch":{"a:fillRect":{}}},"xdr:spPr":{"a:xfrm":{"a:off":{a$:{x:0,y:0}},"a:ext":{a$:{cx:4057650,cy:6172200}}},"a:prstGeom":{a$:{prst:"rect"},"a:avLst":{}}}},"xdr:clientData":{}})),t=this.charts.map(n=>({...this.AnchorToJSON(n.anchor),"xdr:graphicFrame":{a$:{macro:""},"xdr:nvGraphicFramePr":{"xdr:cNvPr":{a$:{id:n.chart.index+1,name:`Chart ${n.chart.index}`}},"xdr:cNvGraphicFramePr":{}},"xdr:xfrm":{"a:off":{a$:{x:0,y:0}},"a:ext":{a$:{cx:0,cy:0}}},"a:graphic":{"a:graphicData":{a$:{uri:"http://schemas.openxmlformats.org/drawingml/2006/chart"},"c:chart":{a$:{"xmlns:c":"http://schemas.openxmlformats.org/drawingml/2006/chart","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:id":n.relationship}}}}},"xdr:clientData":{}}));return{"xdr:wsDr":{a$:{"xmlns:xdr":"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing","xmlns:a":"http://schemas.openxmlformats.org/drawingml/2006/main"},"xdr:twoCellAnchor":[...t,...e]}}}};var Jt=Ae(Et());var Pe=i=>"row"in i&&"col"in i,ge=i=>"from"in i&&"to"in i&&Pe(i.from)&&Pe(i.to),ot=(i,e)=>e.sheet===i.sheet&&e.row>=i.from.row&&e.row<=i.to.row&&e.col>=i.from.col&&e.col<=i.to.col,Ot=(i,e=0,t=0)=>({from:{row:i.from.row+e,col:i.from.col+t,sheet:i.from.sheet},to:{row:i.to.row+e,col:i.to.col+t,sheet:i.to.sheet}});var lt=class{constructor(e={}){this.options=e}path;rels_path;rels={};sheet_data={};shared_strings;extent;visible_state;tab_selected=!1;default_width=0;drawings=[];TranslateAddress(e){e=e.toUpperCase();let t=e.match(/([A-Z]+\\d+):([A-Z]+\\d+)/);if(t)return{from:this.TranslateAddress(t[1]),to:this.TranslateAddress(t[2])};let r=0,n=0;if(t=e.match(/^([A-Z]+)(\\d+)$/),t){r=Number(t[2]),n=0;let s=t[1].length;for(let o=0;o<s;o++){let a=t[1].charCodeAt(o)-64;n=n*26+a}}return{row:r,col:n}}Address(e,t=!1){if(ge(e))return this.Address(e.from,t)+":"+this.Address(e.to,t);let r="",n=e.col;for(;n>0;){let o=(n-1)%26+1;r=String.fromCharCode(64+o)+r,n=(n-o)/26}let s=e.sheet?`\'${e.sheet}\'!`:"";return t?`${s}$${r}$${e.row}`:s+r+e.row}NormalizeAddress(e){let t,r;return typeof e=="string"?(t=e.toUpperCase(),r=this.TranslateAddress(t)):(r=e,t=this.Address(r)),{a:t,rc:r}}Parse(){let e=this.sheet_data.worksheet?.dimension?.a$?.ref,t=this.TranslateAddress(e||"");ge(t)?this.extent=JSON.parse(JSON.stringify(t)):this.extent={from:JSON.parse(JSON.stringify(t)),to:JSON.parse(JSON.stringify(t))}}};var ws=new Jt.XMLParser(Wr),ye=new Jt.XMLParser(qe),dt={greaterThan:">",greaterThanOrEquals:">=",lessThan:"<",lessThanOrEquals:"<=",equal:"=",notEqual:"<>"};var ct=class{constructor(e){this.zip=e}xml={};shared_strings=new Ce;style_cache=new Ne;theme=new be;defined_names={};rels={};sheets=[];active_tab=0;get sheet_count(){return this.sheets.length}ReadRels(e){let t={},r=this.zip.Has(e)?this.zip.Get(e):"",n=ye.parse(r||"");for(let s of n.Relationships?.Relationship||[]){let o=s.a$.Id;t[o]={id:o,type:s.a$.Type,target:s.a$.Target}}return t}Init(){this.rels=this.ReadRels("xl/_rels/workbook.xml.rels");let e=this.zip.Has("xl/sharedStrings.xml")?this.zip.Get("xl/sharedStrings.xml"):"",t=ye.parse(e||"");this.shared_strings.FromXML(t),e=this.zip.Get("xl/theme/theme1.xml"),t=ye.parse(e),this.theme.FromXML(t),e=this.zip.Get("xl/styles.xml"),t=ye.parse(e),this.style_cache.FromXML(t,this.theme),e=this.zip.Get("xl/workbook.xml"),t=ye.parse(e),this.defined_names={};let r=R.FindAll(t,"workbook/definedNames/definedName");for(let o of r){let a=o.a$?.name,l=o.t$||"";a&&l&&(this.defined_names[a]=l)}let n=R.FindAll(t,"workbook/bookViews/workbookView");n[0]?.a$?.activeTab&&(this.active_tab=Number(n[0].a$.activeTab)||0);let s=R.FindAll(t,"workbook/sheets/sheet");for(let o of s){let a=o.a$?.name;if(a){let l=o.a$.state,d=o.a$["r:id"],c=new lt({name:a,rid:d,id:Number(o.a$.sheetId)});l==="hidden"?c.visible_state=1:l==="veryHidden"&&(c.visible_state=2),c.shared_strings=this.shared_strings,c.path=`xl/${this.rels[d].target}`,c.rels_path=c.path.replace("worksheets","worksheets/_rels")+".rels",e=this.zip.Get(c.path),c.sheet_data=ye.parse(e||""),c.rels=this.ReadRels(c.rels_path),c.Parse(),this.sheets.push(c)}}}ReadTable(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ye.parse(t),n=r.table?.a$?.name||"";return{name:n,display_name:r.table?.a$?.displayName||n,ref:r.table?.a$.ref||"",totals_row_shown:Number(r.table?.a$.totalsRowShown||"0")||0,totals_row_count:Number(r.table?.a$.totalsRowCount||"0")||0}}ReadDrawing(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ye.parse(t),n=this.ReadRels(e.replace(/^..\\/drawings/,"xl/drawings/_rels")+".rels"),s=[],o=R.FindAll(r,"xdr:wsDr/xdr:twoCellAnchor"),a=(l={})=>({column:l["xdr:col"]||0,column_offset:l["xdr:colOff"]||0,row:l["xdr:row"]||0,row_offset:l["xdr:rowOff"]||0});for(let l of o){let d={from:a(l["xdr:from"]),to:a(l["xdr:to"])},c=R.FindAll(l,"xdr:graphicFrame/a:graphic/a:graphicData/c:chart")[0];if(c&&c.a$&&c.a$["r:id"]){let h={type:"chart",anchor:d},u=n[c.a$["r:id"]];u&&u.target&&(h.chart=this.ReadChart(u.target)),s.push(h)}else{let h=R.FindAll(l,"xdr:pic/xdr:blipFill/a:blip")[0];if(h&&h.a$["r:embed"]){let u=n[h.a$["r:embed"]];if(u&&u.target&&/(?:jpg|jpeg|png|gif)$/i.test(u.target)){let p=u.target.replace(/^\\.\\./,"xl"),f=p.replace(/^.*\\//,""),g={type:"image",anchor:d,image:this.zip.GetBinary(p),filename:f};s.push(g)}}}}return s}ReadChart(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ws.parse(t),n={type:0},s=R.FindChild(r,"c:chartSpace/c:chart/c:title");if(s){let l=R.FindChild(s,"c:tx/c:strRef/c:f");if(l)typeof l=="string"?n.title=l:l.text__&&(n.title=l.text__);else{let d=R.FindAll(s,"c:tx/c:rich/a:p/a:r/a:t");n.title=\'"\'+d.join("")+\'"\'}}let o=(l,d=!1)=>{let c=[],h=l["c:ser"]||[];Array.isArray(h)||(h=[h]);for(let u of h){let p=c.length,f=u["c:order"];f&&(p=Number(f.__val||0)||0);let g={},y=R.FindChild(u,"c:tx/c:v");if(y){let N=y;N&&(g.title=`"${N}"`)}else y=R.FindChild(u,"c:tx/c:strRef/c:f"),y&&(g.title=y);if(d){let N=R.FindChild(u,"c:xVal/c:numRef/c:f");N&&(g.categories=N);let w=R.FindChild(u,"c:yVal/c:numRef/c:f");w&&(g.values=w)}else{let N=R.FindChild(u,"c:val/c:numRef/c:f");N&&(g.values=N);let w=R.FindChild(u,"c:cat/c:strRef/c:f");w||(w=R.FindChild(u,"c:cat/c:numRef/c:f")),w&&(g.categories=w)}c[p]=g}return c},a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:barChart");return a&&(n.type=2,a["c:barDir"]&&a["c:barDir"].__val==="col"&&(n.type=1),n.series=o(a)),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:lineChart"),a&&(n.type=3,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:doughnutChart"),a&&(n.type=5,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:pieChart"),a&&(n.type=6,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:scatterChart"),a&&(n.type=4,n.series=o(a,!0))),n}GetNamedRanges(){return this.defined_names}};var Qt=Ae(ni()),si=Ae(De()),Fe=class{records;text=new Map;constructor(e){this.records=Qt.default.parse(e)}Has(e){return this.text.has(e)||!!this.records?.[e]}ArrayBuffer(){let e={};if(this.records)for(let[r,n]of Object.entries(this.records))e[r]=new Uint8Array(n);let t=new TextEncoder;for(let[r,n]of this.text.entries())e[r]=t.encode(n);return Qt.default.encode(e)}SetBinary(e,t,r){if(r==="base64"){let n=si.default.toByteArray(t);this.records[e]=n}else throw new Error("unsupported encoding: "+r)}Set(e,t){this.text.set(e,t),this.records[e]&&delete this.records[e]}GetBinary(e){let t=this.records[e];if(t)return new Uint8Array(t);throw new Error("path not in records: "+e)}Get(e){let t=this.text.get(e);if(t)return t;let r=this.records[e];if(r)return t=new TextDecoder().decode(r),this.text.set(e,t),delete this.records[e],t;throw console.info(this),new Error("path not in zip file: "+e)}};var fe=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n`,ht=class{zip;xmloptions={format:!0,attributesGroupName:"a$",textNodeName:"t$",ignoreAttributes:!1,suppressEmptyNode:!0};xmlbuilder1=new ut.XMLBuilder(this.xmloptions);xmlparser2=new ut.XMLParser(qe);parser=new Te;decorated_functions={};Init(e={}){for(let r of Object.keys(e))this.decorated_functions[r.toLowerCase()]=e[r];let t=ai.toByteArray(rr);this.zip=new Fe(t)}WriteRels(e,t,r=!1){if(!this.zip)throw new Error("missing zip");let n=Object.keys(e),s={Relationships:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/relationships"},Relationship:n.map(a=>{let l=e[a],d={Id:l.id,Target:l.target,Type:l.type};return l.mode&&(d.TargetMode=l.mode),{a$:d}})}},o=fe+this.xmlbuilder1.build(s);r&&console.info(o),this.zip.Set(t,o)}WriteStyleCache(e){if(!this.zip)throw new Error("missing zip");let t=c=>{let h={};return c.indexed!==void 0&&(h.indexed=c.indexed),c.theme!==void 0&&(h.theme=c.theme),c.tint!==void 0&&(h.tint=c.tint),c.argb!==void 0&&(h.rgb=c.argb),h},r=e.cell_xfs.map(c=>{let h={a$:{numFmtId:c.number_format,fontId:c.font,fillId:c.fill,borderId:c.border}};return(c.horizontal_alignment||c.vertical_alignment||c.wrap_text)&&(h.alignment={a$:{}},c.horizontal_alignment&&(h.alignment.a$.horizontal=c.horizontal_alignment),c.vertical_alignment&&(h.alignment.a$.vertical=c.vertical_alignment),c.wrap_text&&(h.alignment.a$.wrapText=1)),h}),n=c=>{if(c.color)return{indexed:c.color};if(c.rgba)return{rgb:c.rgba};if(c.theme){let h={theme:c.theme};return c.tint&&(h.tint=c.tint),h}},s=e.borders.map(c=>{let h={left:{},right:{},top:{},bottom:{},diagonal:{}};if(c.top.style){h.top.a$={style:c.top.style};let u=n(c.top);u&&(h.top.color={a$:u})}if(c.left.style){h.left.a$={style:c.left.style};let u=n(c.left);u&&(h.left.color={a$:u})}if(c.bottom.style){h.bottom.a$={style:c.bottom.style};let u=n(c.bottom);u&&(h.bottom.color={a$:u})}if(c.right.style){h.right.a$={style:c.right.style};let u=n(c.right);u&&(h.right.color={a$:u})}if(c.diagonal.style){h.diagonal.a$={style:c.diagonal.style};let u=n(c.diagonal);u&&(h.diagonal.color={a$:u})}return h}),o=e.fills.map(c=>{let h={a$:{patternType:c.pattern_type}};return c.pattern_gray!==void 0&&(h.a$.patternType=`gray${c.pattern_gray}`),c.bg_color&&(h.bgColor={a$:t(c.bg_color)}),c.fg_color&&(h.fgColor={a$:t(c.fg_color)}),{patternFill:h}}),a=e.fonts.map(c=>{let h={};return c.bold&&(h.b=""),c.italic&&(h.i=""),c.underline&&(h.u=""),c.strike&&(h.strike=""),c.size!==void 0&&(h.sz={a$:{val:c.size}}),c.family!==void 0&&(h.family={a$:{val:c.family}}),c.name!==void 0&&(h.name={a$:{val:c.name}}),c.scheme!==void 0&&(h.scheme={a$:{val:c.scheme}}),c.color_argb!==void 0?h.color={a$:{rgb:c.color_argb}}:c.color_theme!==void 0&&(h.color={a$:{theme:c.color_theme}},c.color_tint&&(h.color.a$.tint=c.color_tint)),h}),l={styleSheet:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x14ac x16r2 xr","xmlns:x14ac":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac","xmlns:x16r2":"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision"}}};if(e.number_formats.length&&(l.styleSheet.numFmts={a$:{count:e.number_formats.length},numFmt:e.number_formats.map(c=>({a$:{numFmtId:c.id,formatCode:c.format}}))}),a.length&&(l.styleSheet.fonts={a$:{count:a.length},font:a}),o.length&&(l.styleSheet.fills={a$:{count:o.length},fill:o}),s.length&&(l.styleSheet.borders={a$:{count:s.length},border:s}),r.length&&(l.styleSheet.cellXfs={a$:{count:r.length},xf:r}),e.dxf_styles.length){let c=[];for(let h of e.dxf_styles){let u={};if(h.text||h.bold||h.italic||h.underline){let p={};h.text&&(p.color={a$:{}},h.text.text?p.color.a$.rgb="FF"+h.text.text.substring(1):h.text.theme&&(p.color.a$.theme=h.text.theme,h.text.tint&&(p.color.a$.tint=h.text.tint))),h.bold&&(p.b={}),h.italic&&(p.i={}),h.underline&&(p.u={}),h.strike&&(p.strike={}),u.font=p}if(h.fill){let p={a$:{}};h.fill.text?p.a$.rgb="FF"+h.fill.text.substring(1):h.fill.theme&&(p.a$.theme=h.fill.theme,h.fill.tint&&(p.a$.tint=h.fill.tint)),u.fill={patternFill:{bgColor:p}}}c.push(u)}c.length&&(l.styleSheet.dxfs={a$:{count:c.length},dxf:c})}let d=fe+this.xmlbuilder1.build(l);this.zip?.Set("xl/styles.xml",d)}WriteSharedStrings(e){if(!this.zip)throw new Error("missing zip");let t={sst:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",count:e.strings.length,uniqueCount:e.strings.length},si:[...e.strings.map(n=>({t:n}))]}},r=fe+this.xmlbuilder1.build(t);this.zip.Set("xl/sharedStrings.xml",r)}SheetStyle(e,t){if(!e.sheet_style)return 0;let r=t.StyleOptionsFromProperties(e.sheet_style);return t.EnsureStyle(r)}RowStyle(e,t,r){let n=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.row_style){let a=e.row_style[r];typeof a=="number"&&(a=n[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(ve.Composite(s));return t.EnsureStyle(o)}ColumnStyle(e,t,r){let n=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.column_style){let a=e.column_style[r];typeof a=="number"&&(a=n[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(ve.Composite(s));return t.EnsureStyle(o)}StyleFromCell(e,t,r,n,s={}){let o=e.styles||e.cell_style_refs||[],a=[e.sheet_style];if(e.row_pattern&&e.row_pattern.length&&a.push(e.row_pattern[r%e.row_pattern.length]),e.row_style){let d=e.row_style[r];typeof d=="number"&&(d=o[d]),d&&a.push(d)}if(e.column_style){let d=e.column_style[n];typeof d=="number"&&(d=o[d]),d&&a.push(d)}a.push(s);let l=t.StyleOptionsFromProperties(ve.Composite(a));return t.EnsureStyle(l)}NormalizeAddress(e,t){let r=e.type==="address"?[e]:[e.start,e.end];for(let n of r)n.absolute_row=!0,n.absolute_column=!0,n.sheet||(n.sheet=t.name);return e.type==="range"&&(e.end.sheet=void 0),e.label=this.parser.Render(e),e}AnnotationLayoutToAnchor(e,t){let r=n=>{let s=t.column_width&&t.column_width[n.address.column]?t.column_width[n.address.column]:t.default_column_width||100,o=t.row_height&&t.row_height[n.address.row]?t.row_height[n.address.row]:t.default_row_height||20;return{...n.address,row_offset:Math.round(n.offset.y*o),column_offset:Math.round(n.offset.x*s)}};return{from:r(e.tl),to:r(e.br)}}AnnotationRectToAnchor(e,t){let r={from:{row:-1,column:-1},to:{row:-1,column:-1}},n={top:0,left:0,width:301,height:301,...e},s={...n,right:n.left+n.width,bottom:n.top+n.height};for(let o=0,a=0;a<1e3;a++){let l=t.column_width&&t.column_width[a]?t.column_width[a]:t.default_column_width||100;if(r.from.column<0&&s.left<=o+l&&(r.from.column=a,r.from.column_offset=s.left-o),r.to.column<0&&s.right<=o+l){r.to.column=a,r.to.column_offset=s.right-o;break}o+=l}for(let o=0,a=0;a<1e3;a++){let l=t.row_height&&t.row_height[a]?t.row_height[a]:t.default_row_height||20;if(r.from.row<0&&s.top<=o+l&&(r.from.row=a,r.from.row_offset=s.top-o),r.to.row<0&&s.bottom<=o+l){r.to.row=a,r.to.row_offset=s.bottom-o;break}o+=l}return r}ParseImages(e){let t=[];for(let r of e.annotations||[])if(r.type==="image"&&r.data?.src){let n=r.data.src,s=n.match(/^data:image\\/([^;]*?);base64,/);if(s){let o=n.substr(s[0].length),a=s[1],l={data:o,mimetype:a,encoding:"base64"};switch(a){case"svg+xml":case"webp":case"jpeg":case"jpg":case"image/png":case"png":case"gif":r.layout?t.push({anchor:this.AnnotationLayoutToAnchor(r.layout,e),options:l}):r.rect?t.push({anchor:this.AnnotationRectToAnchor(r.rect,e),options:l}):console.warn("annotation missing layout");break;default:console.info("unhandled image type",a);break}}}return t}ParseCharts(e){let t=[],r=(n,s,o)=>{if(n.type==="range")s.data.push(this.NormalizeAddress(n,e));else if(n.type==="call"){if(/group/i.test(n.name))for(let a of n.args||[])r(a,s,o?o+" (recurse)":void 0);else if(/series/i.test(n.name)){let[a,l,d]=n.args;d&&d.type==="range"?(s.data.push(this.NormalizeAddress(d,e)),a&&(s.names||(s.names=[]),a.type==="address"&&this.NormalizeAddress(a,e),a.type==="range"?(this.NormalizeAddress(a.start,e),s.names[s.data.length-1]=a.start):s.names[s.data.length-1]=a),s.labels2||(s.labels2=[]),l&&l.type==="range"&&(s.labels2[s.data.length-1]=this.NormalizeAddress(l,e))):console.info("invalid series missing Y",{y:d,arg:n,ref:o})}}};for(let n of e.annotations||[]){let s=this.parser.Parse(n.formula||"");if(s.expression&&s.expression.type==="call"){let o="";switch(s.expression.name.toLowerCase()){case"line.chart":o="scatter";break;case"scatter.line":o="scatter2";break;case"donut.chart":o="donut";break;case"bar.chart":o="bar";break;case"column.chart":o="column";break}if(o==="column"||o==="donut"||o==="bar"||o==="scatter"||o==="scatter2"){let a={type:o,data:[]},l=o==="scatter2"?1:2,d=s.expression.args[l];if(d&&d.type==="literal"?a.title=d:d&&d.type==="address"&&(a.title=this.NormalizeAddress(d,e)),s.expression.args[0]){let h=s.expression.args[0];if(o==="scatter2"||o==="bar"||o==="column"||o==="scatter")r(h,a,e.name);else if(h.type==="range")a.data.push(this.NormalizeAddress(h,e));else if(h.type==="call"&&/group/i.test(h.name))for(let u of h.args)u.type==="range"?a.data.push(this.NormalizeAddress(u,e)):u.type==="call"&&/series/i.test(u.name)&&u.args[2]&&u.args[2].type==="range"&&a.data.push(this.NormalizeAddress(u.args[2],e));else h.type==="call"&&/series/i.test(h.name)&&h.args[2]&&h.args[2].type==="range"&&a.data.push(this.NormalizeAddress(h.args[2],e))}o!=="scatter2"&&s.expression.args[1]&&s.expression.args[1].type==="range"&&(a.labels=this.NormalizeAddress(s.expression.args[1],e)),(o==="scatter"&&s.expression.args[4]&&s.expression.args[4].type==="literal"&&s.expression.args[4].value.toString().toLowerCase()==="smooth"||o==="scatter2"&&s.expression.args[2]&&s.expression.args[2].type==="literal"&&/smooth/i.test(s.expression.args[2].value.toString()))&&(a.smooth=!0);let c=n.rect;n.layout?t.push({anchor:this.AnnotationLayoutToAnchor(n.layout,e),options:a}):c?t.push({anchor:this.AnnotationRectToAnchor(c,e),options:a}):console.warn("annotation missing layout")}}}return t}FormulaText(e,t){if(e[0]!=="=")return e;let r=this.parser.Parse(e);if(r.expression){this.parser.Walk(r.expression,s=>{if(s.type==="call"){let o=s.name.toLowerCase();this.decorated_functions[o]&&(s.name=this.decorated_functions[o]+"."+s.name)}return!0});let n=t.table?.name||"";return this.parser.Render(r.expression,{missing:"",long_structured_references:!0,table_name:n})}else return console.warn("parsing function failed"),console.warn(e),e.substring(1)}Export(e){let t=0,r=[];for(let w=0;w<e.sheet_data.length;w++){let x=e.sheet_data[w],I=x.id||0;I&&(r[I]=x.name||""),I===e.active_sheet&&(t=w)}let n=new Ce,s=new Ne,o=new be,a=this.zip?.Get("xl/theme/theme1.xml");o.FromXML(this.xmlparser2.parse(a||"")),a=this.zip?.Get("xl/styles.xml"),s.FromXML(this.xmlparser2.parse(a||""),o),ze.next_drawing_index=1,Ze.next_chart_index=1;let l=[],d=[];for(let w=0;w<e.sheet_data.length;w++){let x=e.sheet_data[w],I={},G={xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x14ac xr xr2 xr3","xmlns:x14ac":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr2":"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2","xmlns:xr3":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3","xr:uid":"{D37933E2-499F-4789-8D13-194E11B743FC}"},Y=x.default_row_height?x.default_row_height/20*15:15,k={worksheet:{a$:{...G},dimension:{a$:{ref:"A1"}},sheetViews:{sheetView:{a$:{workbookViewId:0}}},sheetFormatPr:{a$:Y===15?{"x14ac:dyDescent":.25}:{defaultRowHeight:Y,customHeight:1,"x14ac:dyDescent":.25}},cols:{},sheetData:{},mergeCells:{a$:{count:0}},dataValidations:{},hyperlinks:{},conditionalFormatting:{},pageMargins:{a$:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3}},drawing:{},tableParts:{a$:{count:0}},extLst:{ext:{a$:{uri:"{05C60535-1F16-4fd2-B633-F4F36F0B64E0}","xmlns:x14":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"}}}}},M=x.styles||x.cell_style_refs||[],V=new Je;V.FromJSON(x.data,M);for(let b of x.cell_styles){let S=V.EnsureCell(b);S.style||(S.style=M[b.ref])}let z={start:{row:V.rows+1,column:V.columns+1},end:{row:V.rows+1,column:V.columns+1}},U={row:[]},X=[],J=[],B=[],K=[],j=[],_=[],T=this.SheetStyle(x,s);for(let b=0;b<V.data.length;b++){let S=this.RowStyle(x,s,b);if(V.data[b]&&V.data[b].length){b<z.start.row&&(z.start.row=b);let W={start:-1,end:-1},E=[];for(let A=0;A<V.data[b].length;A++){_[A]||(_[A]=this.ColumnStyle(x,s,A));let v=V.data[b][A];if(v){if(v.table&&v.table.area.start.row===b&&v.table.area.start.column===A){let le=new L(v.table.area.start,v.table.area.end),Be=d.length+1,li=`../tables/table${Be}.xml`,pt=[];for(let ne=0;ne<le.columns;ne++){let Q=V.data[b][A+ne],me="";Q.type!==2?(typeof Q.calculated<"u"?me=Q.calculated.toString():typeof Q.value<"u"&&(me=Q.value.toString()),Q.type=2,Q.value=me):me=Q.value||"",me||(me=`Column${ne+1}`);let Ye=me,gt=!1,ci=1;for(;!gt;){gt=!0;e:for(let di of pt)if(di.toLowerCase()===Ye.toLowerCase()){gt=!1,Ye=`${me}${++ci}`;break e}}Q.value=Ye,pt.push(Ye)}let Le;if(v.table.totals_row){Le=[];for(let ne=0;ne<le.columns;ne++){let Q=V.data[le.end.row][le.start.column+ne];Q.type&&(Q.type===1?Le[ne]={type:"formula",value:(Q.value||"").toString().substring(1)}:(Q.type!==2&&(Q.type=2,Q.value=Q.value?.toString()||""),Le[ne]={type:"label",value:Q.value}))}}let bt={rel:ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",li),index:Be,ref:le.spreadsheet_label,name:`Table${Be}`,display_name:`Table${Be}`,totals_row_shown:0,totals_row_count:v.table?.totals_row?1:0,columns:pt,footers:Le};if(v.table.totals_row){let ne=new L(le.start,{row:le.end.row-1,column:le.end.column});bt.filterRef=ne.spreadsheet_label}K.push(bt),d.push(bt)}if(v.merge_area&&v.merge_area.start.row===b&&v.merge_area.start.column===A&&B.push(new L(v.merge_area.start,v.merge_area.end)),v.hyperlink){let le=ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",v.hyperlink,"External");X.push({rel:le,target:v.hyperlink,address:{row:b,column:A}})}if(v.validation&&(v.validation.type==="list"||v.validation.type==="range")&&j.push({address:{row:b,column:A},validation:v.validation}),v.type===1&&/^=?sparkline\\./i.test(v.value)){J.push({address:{row:b,column:A},formula:v.value,style:v.style});continue}A<z.start.column&&(z.start.column=A),W.start<0&&(W.start=A),W.end=A;let D=this.StyleFromCell(x,s,b,A,v.style);if(v.type===0&&(S&&D===S||!S&&_[A]&&D===_[A]))continue;let H,q,ee;switch(v.type){case 1:switch(ee=this.FormulaText(v.value,v),v.calculated_type){case 2:H=v.calculated,q="str";break;case 3:H=v.calculated;break;case 4:H=v.calculated?1:0,q="b";break}break;case 2:H=n.Ensure(v.value),q="s";break;case 3:H=v.value;break;case 4:H=v.value?1:0,q="b";break}v.area&&v.area.start.row===b&&v.area.start.column===A&&typeof ee=="string"&&(ee={t$:ee,a$:{t:"array",ref:v.area.spreadsheet_label}});let oe={a$:{r:L.CellAddressToLabel({row:b,column:A})}};q!==void 0&&(oe.a$.t=q),D!==void 0&&(oe.a$.s=D),ee!==void 0&&(oe.f=ee),H!==void 0&&(oe.v=H),E.push(oe)}}if(E.length||S&&S!==T){let A={a$:{r:b+1,spans:`${W.start+1}:${W.end+1}`},c:E};x.row_height&&typeof x.row_height[b]=="number"&&x.row_height[b]!==x.default_row_height&&(A.a$.customHeight=1,A.a$.ht=x.row_height[b]*3/4),S&&S!==T&&(A.a$.s=S,A.a$.customFormat=1),U.row.push(A)}}}let Z=[];x.default_column_width&&(k.worksheet.sheetFormatPr.a$.defaultColWidth=He(x.default_column_width));for(let b=0;b<x.columns;b++){let S={index:b};x.column_width&&x.default_column_width&&typeof x.column_width[b]=="number"&&x.column_width[b]!==x.default_column_width&&(S.width=He(x.column_width[b]));let W=_[b];W&&W!==T&&(S.style=W),(S.style!==void 0||S.width!==void 0)&&(Z[b]=S)}if(Z.length||T){let b=[],S=He(x.default_column_width||90);{let W=0;for(let E of Z){if(!E)continue;T&&E.index>W+1&&b.push({a$:{min:W+1,max:E.index,style:T,width:S}});let A={min:E.index+1,max:E.index+1};E.style===void 0?A.style=T:A.style=E.style,E.width!==void 0?(A.width=E.width,A.customWidth=1):A.width=S,b.push({a$:A}),W=E.index}T&&W<16384&&b.push({a$:{min:W+1,max:16384,style:T,width:S}}),k.worksheet.cols.col=b}}else delete k.worksheet.cols;j.length?k.worksheet.dataValidations={a$:{count:j.length},dataValidation:j.map(b=>{let S={a$:{type:"list",allowBlank:1,showInputMessage:1,showErrorMessage:1,sqref:new L(b.address).spreadsheet_label}};if(b.validation.type==="range"){let W={id:0,type:"range",label:"",position:0,start:{...b.validation.area.start,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"},end:{...b.validation.area.end,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"}};typeof b.validation.area.start.sheet_id<"u"&&(W.start.sheet=r[b.validation.area.start.sheet_id]),S.formula1=this.parser.Render(W)}else b.validation.type==="list"&&(S.formula1=`"${b.validation.list.join(",")}"`);return S})}:delete k.worksheet.dataValidations,K.length?(k.worksheet.tableParts.a$.count=K.length,k.worksheet.tableParts.tablePart=K.map(b=>({a$:{"r:id":b.rel||""}}))):delete k.worksheet.tableParts;for(let b of K){let S={};b.totals_row_count&&(S.totalsRowCount=1);let W={a$:{count:(b.columns||[]).length},tableColumn:[]};if(b.columns)for(let v=0;v<b.columns.length;v++){let D=b.columns[v],H=(b.footers||[])[v],q={a$:{id:v+1,name:D||`Column${v+1}`}};H&&(H.type==="label"?q.a$.totalsRowLabel=H.value:H.type==="formula"&&(q.a$.totalsRowFunction="custom",q.totalsRowFormula=H.value)),W.tableColumn.push(q)}let E={table:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"xr xr3","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr3":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",id:b.index||0,name:b.name,displayName:b.display_name,...S,ref:b.ref},autoFilter:{a$:{ref:b.filterRef||b.ref}},tableColumns:W,tableStyleInfo:{a$:{name:"TableStyleMedium2",showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}}}},A=fe+this.xmlbuilder1.build(E);this.zip?.Set(`xl/tables/table${b.index}.xml`,A)}if(x.conditional_formats?.length){let b=[],S=1,W={},E=Object.entries(dt).map(A=>(W[A[1]]=A[0],A[1]));E.sort((A,v)=>v.length-A.length);for(let A of x.conditional_formats){let v=0;switch(A.type!=="gradient"&&(v=s.dxf_styles.length,s.dxf_styles.push(A.style)),A.type){case"cell-match":{let D="",H="";for(let q of E)if(new RegExp("^"+q+"\\\\s").test(A.expression)){D=W[q],H=A.expression.substring(q.length).trim();break}D&&b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"cellIs",dxfId:v,operator:D,priority:S++},formula:H}})}break;case"expression":b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"expression",dxfId:v,priority:S++},formula:A.expression}});break;case"duplicate-values":b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:A.unique?"uniqueValues":"duplicateValues",dxfId:v,priority:S++}}});break;case"gradient":{let D=[],H=[];for(let ee of A.stops){ee.value===0?D.push({a$:{type:"min"}}):ee.value===1?D.push({a$:{type:"max"}}):D.push({a$:{type:"percentile",val:ee.value*100}});let oe={a$:{}};ee.color.text?oe.a$.rgb="FF"+ee.color.text.substring(1):ee.color.theme&&(oe.a$.theme=ee.color.theme,oe.a$.tint=ee.color.tint||void 0),H.push(oe)}let q={a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"colorScale",priority:S++},colorScale:{cfvo:D,color:H}}};b.push(q)}break}}b.length?k.worksheet.conditionalFormatting=b.length>1?b:b[0]:delete k.worksheet.conditionalFormatting}else delete k.worksheet.conditionalFormatting;B.length?(k.worksheet.mergeCells.a$.count=B.length,k.worksheet.mergeCells.mergeCell=B.map(b=>({a$:{ref:b.spreadsheet_label}}))):delete k.worksheet.mergeCells,X.length?k.worksheet.hyperlinks.hyperlink=X.map(b=>({a$:{"r:id":b.rel,ref:new L(b.address).spreadsheet_label,"xr:uid":"{0C6B7792-7EA0-4932-BF15-D49C453C565D}"}})):delete k.worksheet.hyperlinks,J.length?k.worksheet.extLst.ext["x14:sparklineGroups"]={a$:{"xmlns:xm":"http://schemas.microsoft.com/office/excel/2006/main"},"x14:sparklineGroup":J.map(b=>{let S=this.parser.Parse(b.formula),W="";if(S.expression&&S.expression.type==="call"&&S.expression.args.length>0){let A=S.expression.args[0];if(A.type==="range"||A.type==="address"){let v=A.type==="range"?A.start:A;v.sheet||(typeof v.sheet_id<"u"?v.sheet=r[v.sheet_id]:v.sheet=x.name),W=this.parser.Render(A)}}let E={displayEmptyCellsAs:"gap"};return/column/i.test(b.formula)&&(E.type="column"),{a$:E,"x14:colorSeries":{a$:{rgb:"FF376092"}},"x14:sparklines":{"x14:sparkline":{"xm:f":W,"xm:sqref":new L(b.address).spreadsheet_label}}}})}:delete k.worksheet.extLst,k.worksheet.sheetData=U;let P=this.ParseCharts(x),C=this.ParseImages(x);if(P.length||C.length){let b=new ze;for(let E of P)b.AddChart(E.options,E.anchor);for(let E of C)b.AddImage(E.options,E.anchor);for(let{image:E}of b.images)E.options.data&&this.zip?.SetBinary(`xl/media/image${E.index}.${E.extension}`,E.options.data,E.options.encoding);for(let{chart:E}of b.charts){let A=E.toJSON(),v=fe+this.xmlbuilder1.build(A);this.zip?.Set(`xl/charts/chart${E.index}.xml`,v),this.WriteRels(E.relationships,`xl/charts/_rels/chart${E.index}.xml.rels`)}this.WriteRels(b.relationships,`xl/drawings/_rels/drawing${b.index}.xml.rels`);let S=fe+this.xmlbuilder1.build(b.toJSON());this.zip?.Set(`xl/drawings/drawing${b.index}.xml`,S),l.push(b);let W=ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",`../drawings/drawing${b.index}.xml`);k.worksheet.drawing={a$:{"r:id":W}}}else delete k.worksheet.drawing;k.worksheet.dimension.a$.ref=new L(z.start,z.end).spreadsheet_label;let F=fe+this.xmlbuilder1.build(k);this.zip?.Set(`xl/worksheets/sheet${w+1}.xml`,F),Object.keys(I).length&&this.WriteRels(I,`xl/worksheets/_rels/sheet${w+1}.xml.rels`)}this.WriteSharedStrings(n),this.WriteStyleCache(s);let c={};ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles","styles.xml"),ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme","theme/theme1.xml"),ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings","sharedStrings.xml");let h=e.sheet_data.map((w,x)=>ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",`worksheets/sheet${x+1}.xml`));this.WriteRels(c,"xl/_rels/workbook.xml.rels");let u={definedName:[]};if(e.named_ranges){let w=Object.keys(e.named_ranges);for(let x of w){let I="",G=new L(e.named_ranges[x].start,e.named_ranges[x].end);if(G.start.absolute_column=G.start.absolute_row=!0,G.end.absolute_column=G.end.absolute_row=!0,G.start.sheet_id){for(let Y of e.sheet_data)if(Y.id===G.start.sheet_id){I=Y.name||"";break}}I&&(Ht.test(I)&&(I=`\'${I}\'`),I+="!"),u.definedName.push({a$:{name:x},t$:I+G.spreadsheet_label})}}if(e.named_expressions)for(let w of e.named_expressions)u.definedName.push({a$:{name:w.name},t$:w.expression});u.definedName.length||(u=void 0);let p={workbook:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x15 xr xr6 xr10 xr2","xmlns:x15":"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr6":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision6","xmlns:xr10":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10","xmlns:xr2":"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"},workbookPr:{a$:{defaultThemeVersion:"166925"}},bookViews:{workbookView:{a$:{activeTab:t||0}}},sheets:{sheet:e.sheet_data.map((w,x)=>{let I={name:w.name||`Sheet${x+1}`,sheetId:x+1,"r:id":h[x]};return w.visible===!1&&(I.state="hidden"),{a$:I}})},definedNames:u}},f=fe+this.xmlbuilder1.build(p);this.zip?.Set("xl/workbook.xml",f);let g={};for(let w of l)for(let x of w.images)switch(x.image.extension){case"gif":case"png":case"jpeg":g[x.image.extension]="image/"+x.image.extension;break;case"svg":g.svg="image/svg+xml";break}let y={Types:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/content-types"},Default:[{a$:{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}},{a$:{Extension:"xml",ContentType:"application/xml"}},...Object.keys(g).map(w=>({a$:{Extension:w,ContentType:g[w]}}))],Override:[{a$:{PartName:"/xl/workbook.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"}},...e.sheet_data.map((w,x)=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",PartName:`/xl/worksheets/sheet${x+1}.xml`}})),...l.reduce((w,x)=>w.concat([...x.charts.map(I=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",PartName:`/xl/charts/chart${I.chart.index}.xml`}})),{a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawing+xml",PartName:`/xl/drawings/drawing${x.index}.xml`}}]),[]),{a$:{PartName:"/xl/theme/theme1.xml",ContentType:"application/vnd.openxmlformats-officedocument.theme+xml"}},{a$:{PartName:"/xl/styles.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"}},{a$:{PartName:"/xl/sharedStrings.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"}},...d.map(w=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",PartName:`/xl/tables/table${w.index||0}.xml`}})),{a$:{PartName:"/docProps/core.xml",ContentType:"application/vnd.openxmlformats-package.core-properties+xml"}},{a$:{PartName:"/docProps/app.xml",ContentType:"application/vnd.openxmlformats-officedocument.extended-properties+xml"}}]}},N=fe+this.xmlbuilder1.build(y);this.zip?.Set("[Content_Types].xml",N)}ArrayBuffer(){if(!this.zip)throw new Error("missing zip");return this.zip.ArrayBuffer()}Blob(){if(!this.zip)throw new Error("missing zip");let e=this.zip.ArrayBuffer();return new Blob([e],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}};var oi=Ae(De());var ft=class{parser=new Te;workbook;zip;Init(e){this.zip=new Fe(e),this.workbook=new ct(this.zip),this.workbook.Init()}SheetCount(){return this.workbook?.sheet_count||0}ParseCell(e,t,r,n,s,o,a){let l=t.a$?.r;if(!l){console.warn("cell missing address");return}let d=e.TranslateAddress(l);if(ge(d)){console.warn("cell has range address");return}let c,h="undefined",u,p="undefined";if(t.a$?.t&&t.a$.t==="s"){if(h="string",typeof t.v!==void 0){let y=Number(t.v);!isNaN(y)&&e.shared_strings&&(c=e.shared_strings.Get(y)||"",c[0]==="="&&(c="\'"+c))}}else if(typeof t.f<"u"){h="formula";let y=(typeof t.f=="string"?t.f:t.f.t$)||"";if(y){c="="+y.replace(/^_xll\\./g,"");let N=this.parser.Parse(y);N.expression&&(this.parser.Walk(N.expression,w=>(w.type==="call"&&/^_xll\\./.test(w.name)&&(w.name=w.name.substr(5)),!0)),c="="+this.parser.Render(N.expression,{missing:""})),typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si&&(r[t.f.a$.si]={row:d.row-1,column:d.col-1,formula:c,parse_result:this.parser.Parse(c)})}else if(typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si){let N=r[t.f.a$.si];N&&(N.parse_result.expression?c="="+this.parser.Render(N.parse_result.expression,{offset:{rows:d.row-1-N.row,columns:d.col-1-N.column},missing:""}):c=N.formula)}if(typeof t.f!="string"&&t.f.a$?.t==="array"){let N=e.TranslateAddress(t.f.a$.ref||"");ge(N)&&n.push(Ot(N,-1,-1))}if(typeof t.v<"u"){let N=Number(t.v.toString());isNaN(N)?(p="string",u=t.v.toString()):(p="number",u=N)}}else if(typeof t.v<"u"){let y=Number(t.v.toString());isNaN(y)?(h="string",c=t.v.toString()):(h="number",c=y)}let f={row:d.row-1,col:d.col-1};for(let y of n)ot(y,f)&&(f.row!==y.from.row||f.col!==y.from.col)&&(p=h,u=c,c=void 0,h="undefined");let g={row:f.row,column:f.col,value:c,type:h};typeof u<"u"&&(g.calculated_type=p,g.calculated=u),t.a$?.s&&(g.style_ref=Number(t.a$.s));for(let y of o)y.address.row===d.row&&y.address.col===d.col&&(g.hyperlink=y.reference);for(let y of a)if(y.address.row===f.row&&y.address.column===f.col){g.validation=y.validation;break}for(let y of s)ot(y,f)&&(g.merge_area={start:{row:y.from.row,column:y.from.col},end:{row:y.to.row,column:y.to.col}});for(let y of n)ot(y,f)&&(g.area={start:{row:y.from.row,column:y.from.col},end:{row:y.to.row,column:y.to.col}});return g}AddressToArea(e){return Pe(e)?{start:{row:e.row-1,column:e.col-1},end:{row:e.row-1,column:e.col-1}}:{start:{row:e.from.row-1,column:e.from.col-1},end:{row:e.to.row-1,column:e.to.col-1}}}ParseConditionalFormat(e,t){let r=this.AddressToArea(e),n=dt;switch(t.a$.type){case"duplicateValues":case"uniqueValues":let s={};if(t.a$.dxfId){let o=Number(t.a$.dxfId);isNaN(o)||(s=this.workbook?.style_cache.dxf_styles[o]||{})}return{type:"duplicate-values",area:r,style:s,unique:t.a$.type==="uniqueValues"};case"cellIs":if(t.a$.operator&&t.formula){let o={};if(t.a$.dxfId){let l=Number(t.a$.dxfId);isNaN(l)||(o=this.workbook?.style_cache.dxf_styles[l]||{})}let a=n[t.a$.operator||""];if(!a)console.info("unhandled cellIs operator:",t.a$.operator);else return{type:"cell-match",expression:a+" "+t.formula,area:r,style:o}}break;case"expression":if(t.formula){let o={};if(t.a$.dxfId){let a=Number(t.a$.dxfId);isNaN(a)||(o=this.workbook?.style_cache.dxf_styles[a]||{})}return{type:"expression",expression:t.formula,area:r,style:o}}break;case"colorScale":if(t.colorScale&&Array.isArray(t.colorScale.cfvo)&&Array.isArray(t.colorScale.color)){let o=[];for(let[a,l]of t.colorScale.cfvo.entries()){let d=0,c={},h=t.colorScale.color[a];switch(h.a$.rgb?c.text="#"+h.a$.rgb.substring(2):h.a$.theme&&(c.theme=Number(h.a$.theme)||0,h.a$.tint&&(c.tint=Math.round(h.a$.tint*1e3)/1e3)),l.a$.type){case"min":d=0;break;case"max":d=1;break;case"percentile":d=(Number(l.a$.val)||0)/100;break}o.push({color:c,value:d})}return{type:"gradient",stops:o,color_space:"RGB",area:r}}else console.info("unexpected colorScale",{rule:t});break;default:console.info("unhandled cf type:",{rule:t})}}GetSheet(e=0){if(!this.workbook)throw new Error("missing workbook");let t=this.workbook.sheets[e],r=[],n={},s=[],o=[],a=[],l=[],d=[],c=[],h=R.FindAll.bind(R,t.sheet_data),u=h("worksheet/conditionalFormatting");for(let _ of u)if(_.a$?.sqref){let T=t.TranslateAddress(_.a$.sqref);if(_.cfRule){let Z=Array.isArray(_.cfRule)?_.cfRule:[_.cfRule];for(let P of Z){let C=this.ParseConditionalFormat(T,P);C&&a.push(C)}}}let p=h("worksheet/mergeCells/mergeCell");for(let _ of p)if(_.a$.ref){let T=t.TranslateAddress(_.a$.ref);ge(T)&&o.push(Ot(T,-1,-1))}let f=h("worksheet/dataValidations/dataValidation");for(let _ of f){let T=_.a$?.type,Z=_.a$?.sqref,P=_.formula1;if(Z&&P&&T==="list"){let C,F,b=this.parser.Parse(Z);b.expression&&(b.expression.type==="address"?C=b.expression:b.expression.type==="range"&&(C=b.expression.start)),b=this.parser.Parse(P),b.expression&&(b.expression.type==="range"?F={type:"range",area:b.expression}:b.expression.type==="literal"&&(F={type:"list",list:b.expression.value.toString().split(/,/).map(S=>{let W=this.parser.Parse(S);if(W.expression?.type==="group"&&/\\s/.test(S))return S;if(W.expression?.type==="literal")return W.expression.value;if(W.expression?.type==="identifier")return W.expression.name})})),C&&F&&d.push({address:C,validation:F})}}let g=h("worksheet/hyperlinks/hyperlink");for(let _ of g){let T=t.TranslateAddress(_.a$?.ref||"");ge(T)&&(T=T.from);let Z="",P="";if(_.a$&&_.a$["r:id"]){Z="remote link";let C=t.rels[_.a$["r:id"]];C&&(P=C.target||"")}else P=_.__location||"",Z=_.__display||"";l.push({address:T,reference:P,text:Z})}let y=21,N=100,w=t.sheet_data.worksheet?.sheetFormatPr;if(w){if(w.a$?.defaultColWidth){let _=Number(w.a$.defaultColWidth);isNaN(_)||(N=xt(_))}if(w.a$?.defaultRowHeight){let _=Number(w.a$.defaultRowHeight);isNaN(_)||(y=Math.round(_*4/3))}}let x=[],I=[],G=h("worksheet/sheetData/row");for(let _ of G){let T=_.a$?.r?Number(_.a$.r):1,Z=y;if(_.a$?.ht){let C=Number(_.a$.ht);isNaN(C)||(Z=Math.round(C*4/3))}if(_.a$?.outlineLevel){let C=Number(_.a$.outlineLevel);isNaN(C)||(I[T-1]=C)}Z!==y&&(x[T-1]=Z);let P=_.c||[];Array.isArray(P)||(P=[P]);for(let C of P){let F=this.ParseCell(t,C,n,s,o,l,d);F&&r.push(F)}}let Y=[],k=-1,M=[],V=h("worksheet/cols/col");for(let _ of V){let T=Number(_.a$?.min),Z=Number(_.a$?.max);if(_.a$?.style){let P=Number(_.a$.style);if(!isNaN(T)&&!isNaN(Z)&&!isNaN(P))if(t.extent&&Z>=t.extent.to.col||Z-T>100)k=P;else for(let C=T;C<=Z;C++)Y[C]=P}if(_.a$?.customWidth){let P=Number(_.a$.width);if(!isNaN(T)&&!isNaN(Z)&&!isNaN(P)&&Z!==16384){P=xt(P);for(let C=T;C<=Z;C++)M[C-1]=P}}}let z=h("worksheet/tableParts/tablePart");for(let _ of z){let T=_.a$?_.a$["r:id"]:void 0;if(T){let Z="",P=t.rels[T];if(P){Z=P.target||"";let C=this.workbook.ReadTable(Z);if(C){let F=t.TranslateAddress(C.ref),b=Pe(F)?{start:{row:F.row-1,column:F.col-1},end:{row:F.row-1,column:F.col-1}}:{start:{row:F.from.row-1,column:F.from.col-1},end:{row:F.to.row-1,column:F.to.col-1}};for(let S of r)if(S.row===b.start.row&&S.column===b.start.column){S.table={area:b,name:C.name,totals_row:!!C.totals_row_count};break}}}}}let U=h("worksheet/drawing"),X=[],J=[];for(let _ of U){let T=_.a$?_.a$["r:id"]:void 0;if(T){let Z="",P=t.rels[T];if(P&&(Z=P.target||""),Z){let C=this.workbook.ReadDrawing(Z);if(C&&C.length)for(let F of C)switch(F.type){case"chart":X.push(F);break;case"image":J.push(F);break}}}}let B=_=>{let T={address:{row:_.row,column:_.column},offset:{x:0,y:0}};if(_.row_offset){let Z=x[_.row];Z===void 0&&(Z=y),T.offset.y=_.row_offset/9525/Z}if(_.column_offset){let Z=M[_.column];Z===void 0&&(Z=N),T.offset.x=_.column_offset/9525/Z}return T};for(let _ of J)if(_&&_.image){let T={tl:B(_.anchor.from),br:B(_.anchor.to)},Z="image",P=oi.default.fromByteArray(_.image),C="";if(_.filename&&(/jpe*g$/i.test(_.filename)?C="jpeg":/png$/i.test(_.filename)?C="png":/gif$/i.test(_.filename)&&(C="gif")),C&&P){let F="data:image/"+C+";base64,"+P;c.push({layout:T,type:Z,data:{src:F}})}}for(let _ of X)if(_&&_.chart){let T={tl:B(_.anchor.from),br:B(_.anchor.to)},Z,P=[],C="",F=_.chart?.series;switch(_.chart.type){case 4:Z="treb-chart",C="Scatter.Line",F&&F.length&&(P[0]=`Group(${F.map(S=>`Series(${S.title||""},${S.categories||""},${S.values||""})`||"").join(", ")})`),P[1]=_.chart.title;break;case 5:case 6:C=_.chart.type===5?"Donut.Chart":"Pie.Chart",Z="treb-chart",F&&F[0]&&(P[0]=F[0].values,P[1]=F[0]?.categories||""),P[2]=_.chart.title;break;case 2:case 1:case 3:switch(P[2]=_.chart.title,Z="treb-chart",_.chart.type){case 2:C="Bar.Chart";break;case 1:C="Column.Chart";break;default:C="Line.Chart"}F&&(F.length>1?P[0]=`Group(${F.map(S=>`Series(${S.title||""},,${S.values||""})`||"").join(", ")})`:F.length===1&&(F[0].title?P[0]=`Series(${F[0].title||""},,${F[0].values||""})`:P[0]=F[0].values),P[1]=F[0]?.categories||"");break}let b=`=${C}(${P.join(", ")})`;Z&&b&&c.push({layout:T,type:Z,formula:b})}let K=h("worksheet/extLst/ext");for(let _ of K){let T="";for(let P of Object.keys(_?.a$||{})){let C=P.match(/^xmlns:(.*)$/);if(C){T=C[1];break}}let Z=R.FindAll(_,`${T}:sparklineGroups/${T}:sparklineGroup`);for(let P of Z){let C="Sparkline.line",F="",b="";P.a$?.type==="column"&&(C="Sparkline.column");let S=R.FindAll(P,`${T}:sparklines/${T}:sparkline`);for(let W of S)for(let E of Object.keys(W))/:f$/.test(E)?b=W[E]:/:sqref$/.test(E)&&(F=W[E]);if(b&&F){let W=`=${C}(${b})`,E=t.TranslateAddress(F);if(Pe(E)){let A={row:E.row-1,column:E.col-1,value:W,type:"formula"},v=!1;for(let D of r)if(D.row===A.row&&D.column===A.column){v=!0,D.type="formula",D.value=W;break}v||r.push(A)}}}}let j={name:t.options.name,cells:r,default_column_width:N,column_widths:M,row_heights:x,annotations:c,conditional_formats:a,styles:this.workbook?.style_cache?.CellXfToStyles()||[]};return I.length&&(j.outline=I),(t.visible_state===1||t.visible_state===2)&&(j.hidden=!0),k>=0&&(j.sheet_style=k),Y.length&&(j.column_styles=Y),j}};var mt=self,qt=new ht,vs=i=>{i.sheet&&(qt.Init(i.decorated||[]),qt.Export(i.sheet),mt.postMessage({status:"complete",blob:qt.Blob()}))},Cs=i=>{let e=new ft;try{e.Init(i.data);let t=e.SheetCount(),r={sheets:[],names:e.workbook?.GetNamedRanges(),active_tab:e.workbook?.active_tab};for(let n=0;n<t;n++){let s=e.GetSheet(n);s&&r.sheets.push(s)}mt.postMessage({status:"complete",results:r})}catch(t){console.warn("error importing xlsx file"),console.info(t),mt.postMessage({status:"error",data:t})}};mt.addEventListener("message",i=>{i.data&&i.data.command==="export"?vs(i.data):i.data&&i.data.command==="import"&&Cs(i.data)});\n';var Qt=class c{static treb_base_path="";static treb_embedded_script_path="";static one_time_warnings={};DOM=F.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return D}language_model;events=new oe;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;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;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}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={...Pi,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(te.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,i;this.options.local_storage&&!this.options.toll_initial_load&&!e.model&&(r=localStorage.getItem(this.options.local_storage)||void 0,r&&(i="local-storage")),!r&&!this.options.toll_initial_load&&!e.model&&e.inline_document&&(r=e.inline_document,i="inline-document"),this.options.local_storage&&!e.model&&window.addEventListener("visibilitychange",s=>{document.visibilityState==="hidden"&&this.options.local_storage&&this.dirty&&this.SaveLocalStorage(this.options.local_storage)});let n;typeof this.options.container=="string"?n=document.querySelector(this.options.container):this.options.container&&(n=this.options.container);let a={insert_function_button:!1,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};if(this.options.scale&&(a.initial_scale=this.options.scale),this.options.stats&&(a.stats=this.options.stats,a.tab_bar=!0),this.options.scale_control&&(a.scale_control=!0,a.tab_bar=!0,this.options.persist_scale&&(a.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),a.persist_scale_key))){let s=localStorage.getItem(a.persist_scale_key);if(s)try{let o=JSON.parse(s);a.initial_scale=o.scale||1}catch{console.warn("parsing persisted scale failed")}}if(e.model?(this.model=e.model.model,this.calculator=e.model.calculator,this.DOM=e.model.DOM):(this.model=new at,this.model.sheets.Add(Y.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,e)),n&&(this.DOM=F.GetInstance(n.ownerDocument)),this.grid=new it(a,this.model,void 0,!!n,this.DOM),this.options.headless&&(this.grid.headless=!0),n){this.DOM=F.GetInstance(n.ownerDocument),this.parent_view||(re.is_windows?n.parentElement?.classList.add("treb-ua-windows"):re.is_mac&&n.parentElement?.classList.add("treb-ua-osx"));let s=n.querySelector(".treb-view-template");this.view=s.content.firstElementChild?.cloneNode(!0),n.prepend(this.view),this.view.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=l=>this.HandleKeyDown(l),n.addEventListener("keydown",this.key_listener);let o=!!(r||this.options.document);this.grid.Initialize(this.view,o),this.options.dnd&&(this.view.addEventListener("dragenter",l=>this.HandleDrag(l)),this.view.addEventListener("dragover",l=>this.HandleDrag(l)),this.view.addEventListener("drop",l=>this.HandleDrop(l))),this.grid.grid_events.Subscribe(l=>{switch(l.type){case"error":this.dialog?.ShowDialog({type:"error",...this.TranslateGridError(l.code),timeout:3e3,close_box:!0});break;case"selection":this.UpdateSelection(l.selection),this.UpdateSelectionStyle(l.selection);break;case"sheet-change":this.OnSheetChange(l),this.UpdateSelectionStyle();break;case"data":{let d=this.last_selection;(this.calculation===0?this.Recalculate(l):Promise.resolve()).then(()=>{this.DocumentChange(d)})}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(!1),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.events.Publish({type:"view-change"});break;case"annotation":if(l.annotation){let d=l.annotation.view[this.grid.view_index]||{};switch(this.DocumentChange(),l.event){case"create":this.InflateAnnotation(l.annotation),this.calculator.UpdateAnnotations(l.annotation,this.grid.active_sheet),this.grid.AnnotationUpdated(l.annotation);break;case"delete":this.calculator.RemoveAnnotation(l.annotation);break;case"update":d.update_callback?(d.update_callback(),this.grid.AnnotationUpdated(l.annotation)):console.info("annotation update event without update callback"),this.calculator.UpdateAnnotations(l.annotation,this.grid.active_sheet);break;case"resize":d.resize_callback&&(d.resize_callback(),this.grid.AnnotationUpdated(l.annotation));break}}else console.info("annotation event without annotation");break;case"structure":{let d=this.last_selection;l.rebuild_required?(this.calculator.Reset(),(this.calculation===0?this.Recalculate(l):Promise.resolve()).then(()=>{this.DocumentChange(d)})):this.DocumentChange(d)}this.UpdateSelectionStyle();break;case"cell-event":this.HandleCellEvent(l);break}}),this.options.prompt_save&&window.addEventListener("beforeunload",l=>{this.last_save_version!==this.file_version&&(l.preventDefault(),l.returnValue="")})}else c.one_time_warnings.headless||(c.one_time_warnings.headless=!0,console.info("not initializing layout; don't call UI functions"));if(r?(typeof r=="string"&&(r=JSON.parse(r)),r?this.LoadDocument(r,{recalculate:!!this.options.recalculate,source:i}):this.UpdateDocumentStyles()):t||(this.calculator.RebuildClean(!0),this.UpdateDocumentStyles()),this.FlushUndo(),this.grid.ShowHeaders(this.options.headers),this.options.scroll&&!this.options.document){let s=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(s)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),n&&this.options.spinner&&(this.spinner=new Jt(n)),t&&!e.model&&!r&&this.LoadNetworkDocument(t,this.options),n&&(this.dialog=new Yt(n))}UpdateAC(){let e=this.calculator.SupportedFunctions();if(this.language_model){let t={};for(let r of this.language_model.functions||[])t[r.base.toUpperCase()]=r;e=e.map(r=>t[r.name.toUpperCase()]||r)}this.grid.SetAutocompleteFunctions(e)}CreateCalculator(e,t){return new jt(e,{complex_numbers:t.complex})}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 c({...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?.parentElement&&(t.key_listener&&t.view.parentElement.removeEventListener("keydown",t.key_listener),t.view.parentElement.removeChild(t.view)),this.view?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view?.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.tab_bar?.Update())}),e.Subscribe(r=>{switch(r.type){case"selection":break;default:e.UpdateAnnotations(),this.grid.Update(!0)}}),this.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(e.grid.EnsureActiveSheet(),e.grid.UpdateLayout(),e.grid.tab_bar?.Update())});let t=this.Subscribe(r=>{switch(r.type){case"selection":break;case"load":case"reset":e.grid.EnsureActiveSheet(!0),e.UpdateAnnotations(),e.grid.Update(!0);break;default:e.UpdateAnnotations(),e.grid.Update(!0)}});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){if(e===void 0){let r=this.GetSelectionReference();if(r.empty)throw new Error("invalid range (no selection)");e=r.area}return this.AddConditionalFormat({type:"duplicate-values",area:this.model.ResolveArea(e,this.grid.active_sheet),...t})}ConditionalFormatGradient(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let r=this.model.ResolveArea(e,this.grid.active_sheet),i=typeof t=="object"?{type:"gradient",area:r,...t}:{type:"gradient",area:r,...mi[t]};return this.AddConditionalFormat(i),i}ConditionalFormatCellMatch(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let i={type:"cell-match",area:this.model.ResolveArea(e,this.grid.active_sheet),...t};return this.AddConditionalFormat(i),i}ConditionalFormatExpression(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let i={type:"expression",area:this.model.ResolveArea(e,this.grid.active_sheet),...t};return this.AddConditionalFormat(i),i}AddConditionalFormat(e){let t=this.model.sheets.Find(e.area.start.sheet_id||0);if(!t)throw new Error("invalid reference in format");return t.conditional_formats.push(e),this.calculator.UpdateConditionals(e,t),this.ApplyConditionalFormats(t,t===this.grid.active_sheet),this.PushUndo(),e}RemoveConditionalFormat(e){let t=e.area,r=t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):this.grid.active_sheet;if(!r)throw new Error("invalid reference in format");let i=0;r.conditional_formats=r.conditional_formats.filter(n=>n===e?(i++,this.calculator.RemoveConditional(n),!1):!0),i&&r.FlushConditionalFormats(),this.ApplyConditionalFormats(r,!1),r===this.grid.active_sheet&&this.grid.Update(!0),i&&this.PushUndo()}RemoveConditionalFormats(e){if(e===void 0){let i=this.GetSelectionReference();if(i.empty)throw new Error("invalid range (no selection)");e=i.area}let t=this.model.ResolveArea(e,this.grid.active_sheet),r=t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):this.grid.active_sheet;if(r){let i=0;r.conditional_formats=r.conditional_formats.filter(n=>new y(n.area.start,n.area.end).Intersects(t)?(i++,this.calculator.RemoveConditional(n),!1):!0),i&&(r.FlushConditionalFormats(),this.ApplyConditionalFormats(r,!1),r===this.grid.active_sheet&&this.grid.Update(!0),this.PushUndo())}}HandleToolbarMessage(e){if(this.focus_target!==this){this.focus_target.HandleToolbarMessage(e);return}let t={},r=i=>{let n=this.grid.GetSelection();if(n&&!n.empty){let a=n.area.spreadsheet_label;this.InsertAnnotation(`=${i}(${a},,"${a}")`,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(i){console.error(i)}else{let i=1,n=e.command.substring(7);e.command==="border-double-bottom"&&(n="bottom",i=2),this.grid.ApplyBorders2(void 0,n,e.color||{},i)}else switch(e.command){case"about":this.About();break;case"number-format":t.number_format=e.format||"General";break;case"font-scale":{let i=this.grid.GetSelection(),n=this.grid.active_sheet.RealArea(i.area),a=Number(e.scale||1);if(a&&!isNaN(a)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:a}},!0);let s=[];for(let o=n.start.row;o<=n.end.row;o++)s.push(o);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 i=e.color||{};e.command==="text-color"?t.text=i:e.command==="fill-color"&&(t.fill=i)}catch(i){console.error(i)}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 i=this.grid.GetFreeze();i.rows||i.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"increase-precision":case"decrease-precision":if(this.selection_state?.style){let i=I.Get(this.selection_state.style.number_format||"General");if(i.date_format)break;let n=new te(i.pattern);if(i.magic_decimal){let a=0,s=this.GetRange();Array.isArray(s)||(s=[[s]]);e:for(let o=0;o<s.length;o++)for(let l=0;l<s[o].length;l++){let d=s[o][l];if(typeof d<"u"&&fe(d)){let h=I.Get(this.selection_state.style.number_format||"General",!0),u=h.BaseFormat(d.real),m=h.BaseFormat(d.imaginary);u.parts&&typeof u.parts[1]=="string"&&(a=u.parts[1].length),m.parts&&typeof m.parts[1]=="string"&&(a=Math.max(a,m.parts[1].length));break e}else if(typeof d=="number"){let h=i.BaseFormat(d);h.parts&&typeof h.parts[1]=="string"&&(a=h.parts[1].length);break e}}e.command==="increase-precision"?n.SetDecimal(a+1):n.SetDecimal(Math.max(0,a-1))}else e.command==="increase-precision"?n.IncreaseDecimal():n.DecreaseDecimal();t.number_format=n.toString()}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.
|
|
10
|
+
`).map(d=>d.split(" ").map(h=>h.trim())),l=this.RecyclePasteAreas(new y({row:0,column:0},{row:o.length-1,column:o[0].length-1}),r);if(l.length===1&&(r.Resize(o.length,o[0].length),r.Resize(l[0].rows,l[0].columns)),!this.ValidatePasteAreas(l)){this.Error(5);return}for(let d of l)for(let h=0;h<o.length;h++)for(let u=0;u<o[0].length;u++){let m=new y({row:h+d.start.row,column:u+d.start.column});if(this.active_sheet.cells.EnsureCell(m.end),o[h][u]){let f=this.SetInferredType({area:m,target:m.start,empty:!1},o[h][u],!1,!1);if(f)for(let p of f)i.push(p)}else{let f=this.active_sheet.cells.GetCell(m.start,!1);f&&f.type!==0&&i.push({key:11,area:m.Clone()})}}}this.ExecCommand(i),this.Select(this.primary_selection,r)}AllSelections(e=!1){let t=[this.primary_selection,this.active_selection].concat(this.additional_selections);return e?t:t.filter(r=>!r.empty)}InsertRowsInternal(e){let t=super.InsertRowsInternal(e);if(t.error)return t;let r=this.FindSheet(e.sheet_id);if(r===this.active_sheet){if(e.count<0)for(let i of this.AllSelections())i.empty=!0;else for(let i of this.AllSelections())i.target.row>=e.before_row&&(i.target.row+=e.count),i.area.entire_column||(i.area.start.row>=e.before_row?i.area.Shift(e.count,0):i.area.end.row>=e.before_row&&i.area.ConsumeAddress({row:i.area.end.row+e.count,column:i.area.end.column}));for(let i of t.delete_annotations_list||[])this.layout.RemoveAnnotation(i);if(this.QueueLayoutUpdate(),this.Repaint(),t.update_annotations_list?.length){this.layout.UpdateAnnotation(t.update_annotations_list);for(let i of t.resize_annotations_list||[]){let n=i.view[this.view_index];n?.resize_callback&&n.resize_callback.call(void 0)}}}else this.pending_layout_update.add(r.id);return t}InsertColumnsInternal(e){let t=super.InsertColumnsInternal(e);if(t.error)return t;let r=this.FindSheet(e.sheet_id);if(r===this.active_sheet){if(e.count<0)for(let i of this.AllSelections())i.empty=!0;else for(let i of this.AllSelections())i.target.column>=e.before_column&&(i.target.column+=e.count),i.area.entire_row||(i.area.start.column>=e.before_column?i.area.Shift(0,e.count):i.area.end.column>=e.before_column&&i.area.ConsumeAddress({row:i.area.end.row,column:i.area.end.column+e.count}));for(let i of t.delete_annotations_list||[])this.layout.RemoveAnnotation(i);if(this.tile_renderer?.FlushOverflows(),this.QueueLayoutUpdate(),this.DelayedRender(!0,void 0,!0),t.update_annotations_list?.length){this.layout.UpdateAnnotation(t.update_annotations_list);for(let i of t.resize_annotations_list||[]){let n=i.view[this.view_index];n?.resize_callback&&n.resize_callback.call(void 0)}}}else this.pending_layout_update.add(r.id);return t}ResetInternal(){super.ResetInternal(),this.RemoveAnnotationNodes(),this.ClearSelection(this.primary_selection),this.ScrollIntoView({row:0,column:0}),this.QueueLayoutUpdate(),this.layout.HideNote()}ResizeColumnsInternal(e){let t=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,r=e.column;if(typeof r>"u"){r=[];for(let a=0;a<t.columns;a++)r.push(a)}typeof r=="number"&&(r=[r]);let i=typeof e.width!="number",n=Math.round(e.width||0/this.scale);if(i)for(let a of r)this.AutoSizeColumn(t,a,!1);else for(let a of r)t.SetColumnWidth(a,n);t===this.active_sheet?(this.layout.UpdateTotalSize(),this.layout.container&&this.layout.container.offsetWidth&&this.layout.container.offsetWidth>this.layout.total_width?this.UpdateLayout():(this.layout.UpdateTileWidths(!0),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!1,!0)),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.RenderSelections()):this.pending_layout_update.add(t.id)}ResizeRowsInternal(e){let t,r=e.sheet_id?this.FindSheet(e.sheet_id):this.active_sheet,i=e.row;if(typeof i>"u"){i=[];for(let o=0;o<r.rows;o++)i.push(o)}typeof i=="number"&&(i=[i]);let n=typeof e.shrink=="boolean"?e.shrink:!0,a=typeof e.height!="number",s=Math.round(e.height||0/this.scale);if(a)for(let o of i)r.GetRowHeight(o)||(t?t.ConsumeAddress({row:o,column:1}):t=new y({row:o,column:1/0,sheet_id:r.id})),r.AutoSizeRow(o,this.theme.grid_cell,n);else for(let o of i){let l=r.GetRowHeight(o);(!l&&s||l&&!s)&&(t?t.ConsumeAddress({row:o,column:1}):t=new y({row:o,column:1/0,sheet_id:r.id})),r.SetRowHeight(o,s)}return r===this.active_sheet?(this.layout.UpdateTotalSize(),this.layout.container&&this.layout.container.offsetHeight&&this.layout.container.offsetHeight>this.layout.total_height?this.UpdateLayout():(this.layout.UpdateTileHeights(!0),this.render_tiles=this.layout.VisibleTiles(),this.Repaint(!1,!0)),this.layout.UpdateAnnotation(this.active_sheet.annotations),this.RenderSelections()):this.pending_layout_update.add(r.id),t?{start:t.start,end:t.end}:void 0}SelectInternal(e){e.area?(e.area.start.sheet_id&&e.area.start.sheet_id!==this.active_sheet.id&&this.ActivateSheetInternal({key:21,id:e.area.start.sheet_id}),this.Select(this.primary_selection,new y(e.area.start,e.area.end)),this.RenderSelections()):this.ClearSelection(this.primary_selection)}FreezeInternal(e){let t=this.FindSheet(e.sheet_id||this.active_sheet.id),r=(typeof e.highlight_transition=="boolean"?e.highlight_transition:!0)&&t===this.active_sheet;if(e.rows===t.freeze.rows&&e.columns===t.freeze.columns){r&&this.HighlightFreezeArea();return}t.freeze.rows=e.rows,t.freeze.columns=e.columns,t===this.active_sheet?(this.QueueLayoutUpdate(),this.Repaint(),r&&this.HighlightFreezeArea(),e.rows||e.columns?this.layout.CloneFrozenAnnotations():this.layout.ClearFrozenAnnotations()):this.pending_layout_update.add(t.id)}ExecCommand(e,t=!0){let r=super.ExecCommand(e,t);this.batch||r.render_area&&this.DelayedRender(!1,r.render_area),r.repaint&&this.Repaint();for(let i of r.pending||[])this.pending_layout_update.add(i);return r.layout&&this.QueueLayoutUpdate(),r.sheets&&this.tab_bar&&this.tab_bar.Update(),r.formula&&this.UpdateFormulaBarFormula(),r}};var nt=class{forward={};backward=[];Count(){return this.backward.length}Serialize(){return JSON.parse(JSON.stringify(this.Map()))}Deserialize(e){if(this.Reset(),e){for(let t of Object.keys(e))this.SetName(t,new y(e[t].start,e[t].end),!1);this.RebuildList()}}MatchSelection(e,t){if(!e.start.sheet_id)throw new Error("match selection without sheet id");let r;for(let i of this.List())if(i.range.start.sheet_id===e.start.sheet_id&&(i.range.Equals(e)&&(r=i.name),t?.Equals(i.range)))return i.name;return r}SetName(e,t,r=!0){let i=this.ValidateNamed(e);return i?t.entire_column||t.entire_row?(console.warn("invalid range"),!1):(this.forward[i]=t,r&&this.RebuildList(),!0):(console.warn("invalid name"),!1)}SetNames(e){for(let t of Object.keys(e)){let r=e[t];this.SetName(t,new y(r.start,r.end),!1)}this.RebuildList()}ClearName(e,t=!0){delete this.forward[e],t&&this.RebuildList()}RemoveRangesForSheet(e,t=!0){let r={},i=this.List();for(let n of i)n.range.start.sheet_id!==e&&(r[n.name]=n.range);this.forward=r,t&&this.RebuildList()}Reset(){this.forward={},this.backward=[]}Get(e){return this.forward[e.toUpperCase()]}Map(){return this.forward}List(){return this.backward}ValidateNamed(e){return e=e.trim(),!e.length||/^[A-Za-z]{1,3}\d+$/.test(e)||/[^A-Za-z\d_.]/.test(e)||/^[^A-Za-z_]/.test(e)?!1:e.toUpperCase()}PatchNamedRanges(e,t,r,i,n){let a=this.List().slice(0);for(let s of a){let o=s.name,l=s.range;if(l.start.sheet_id!==e){console.info("skipping name",o);continue}if(r&&t<=l.end.column){if(r>0)t<=l.start.column?l.Shift(0,r):t>l.start.column&&t<=l.end.column?l.ConsumeAddress({row:l.end.row,column:l.end.column+r}):console.warn("PNR X case 1",t,r,JSON.stringify(l));else if(r<0)if(t-r<=l.start.column)l.Shift(0,r);else if(t<=l.start.column&&t-r>l.end.column)this.ClearName(o,!1);else if(t<=l.start.column){let d=t-r-1;this.SetName(o,new y({row:l.start.row,column:d+1+r,sheet_id:e},{row:l.end.row,column:l.end.column+r}),!1)}else t<=l.end.column?t-r-1>=l.end.column?this.SetName(o,new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:t-1}),!1):this.SetName(o,new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:l.start.column+l.columns+r-1}),!1):console.warn("PNR X case 2",t,r,JSON.stringify(l))}if(n&&i<=l.end.row){if(n>0)i<=l.start.row?l.Shift(n,0):i>l.start.row&&i<=l.end.row?l.ConsumeAddress({row:l.end.row+n,column:l.end.column}):console.warn("PNR X case 3",i,n,JSON.stringify(l));else if(n<0)if(i-n<=l.start.row)l.Shift(n,0);else if(i<=l.start.row&&i-n>l.end.row)this.ClearName(o,!1);else if(i<=l.start.row){let d=i-n-1;this.SetName(o,new y({column:l.start.column,row:d+1+n,sheet_id:e},{column:l.end.column,row:l.end.row+n}),!1)}else i<=l.end.row?i-n-1>=l.end.row?this.SetName(o,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:i-1}),!1):this.SetName(o,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:l.start.row+l.rows+n-1}),!1):console.warn("PNR X case 4",i,n,JSON.stringify(l))}}this.RebuildList()}RebuildList(){this.backward=[];for(let e of Object.keys(this.forward))this.backward.push({name:e,range:this.forward[e]})}};var Cr=class{get list(){return this.sheets_.slice(0)}get length(){return this.sheets_.length}names=new Map;ids=new Map;sheets_=[];Assign(e){this.sheets_=[...e],this.UpdateIndexes()}Add(e){this.sheets_.push(e),this.UpdateIndexes()}Splice(e,t,...r){this.sheets_.splice(e,t,...r),this.UpdateIndexes()}Find(e){return typeof e=="string"?this.names.get(e.toLocaleUpperCase()):this.ids.get(e)}Name(e){return this.ids.get(e)?.name||void 0}ID(e){return this.names.get(e.toLocaleUpperCase())?.id||void 0}UpdateIndexes(){this.names.clear(),this.ids.clear();for(let e of this.sheets_){let t=e.name.toLocaleUpperCase();this.names.set(t,e),this.ids.set(e.id,e)}}},at=class{parser=new Ge;document_name;user_data;sheets=new Cr;named_ranges=new nt;macro_functions=new Map;named_expressions=new Map;view_count=0;theme_style_properties=JSON.parse(JSON.stringify(U.DefaultProperties));tables=new Map;ResolveStructuredReference(e,t){let r;if(e.table?r=this.tables.get(e.table.toLowerCase()):t.sheet_id&&(r=this.sheets.Find(t.sheet_id)?.CellData(t)?.table),!r)return;let i=e.column.toLowerCase(),n=-1;if(r.columns){for(let a=0;a<r.columns.length;a++)if(i===r.columns[a]){n=r.area.start.column+a;break}}if(!(n<0))if(e.scope==="row"){let a=t.row;return a<r.area.start.row||a>r.area.end.row?void 0:{label:e.label,type:"address",row:a,column:n,sheet_id:r.area.start.sheet_id,id:e.id,position:e.position}}else{let a=r.area.start.row,s=r.area.end.row;return e.scope==="column"&&(a++,r.totals_row&&s--),{label:e.label,type:"range",position:e.position,id:e.id,start:{type:"address",row:a,column:n,sheet_id:r.area.start.sheet_id,label:e.label,position:e.position,id:0},end:{type:"address",row:s,column:n,label:e.label,position:e.position,id:0}}}}AddressToLabel(e,t){let r=N(e)?e:e.start,i=N(e)?[y.CellAddressToLabel(e)]:[y.CellAddressToLabel(e.start),y.CellAddressToLabel(e.end)],n=this.sheets.Find(r.sheet_id||0),a=n?.name?ze.test(n.name)?`'${n.name}'`:n.name:"";return a+(a?"!":"")+(i[0]===i[1]?i[0]:i.join(":"))}ResolveSheetID(e,t,r){let i=e.type==="address"?e:e.start;if(i.sheet_id)return!0;if(i.sheet){let n=this.sheets.Find(i.sheet);if(n)return i.sheet_id=n.id,!0}else{if(t?.sheet_id)return i.sheet_id=t.sheet_id,!0;if(r?.id)return i.sheet_id=r.id,!0}return!1}ResolveArea(e,t){let r=this.ResolveAddress(e,t);return N(r)?new y(r):new y(r.start,r.end)}ResolveAddress(e,t){if(typeof e=="string"){let r=this.parser.Parse(e);if(r.expression&&r.expression.type==="address")return this.ResolveSheetID(r.expression,void 0,t),{row:r.expression.row,column:r.expression.column,sheet_id:r.expression.sheet_id};if(r.expression&&r.expression.type==="range")return this.ResolveSheetID(r.expression,void 0,t),{start:{row:r.expression.start.row,column:r.expression.start.column,sheet_id:r.expression.start.sheet_id},end:{row:r.expression.end.row,column:r.expression.end.column}};if(r.expression&&r.expression.type==="identifier"){let i=this.named_ranges.Get(r.expression.name);if(i)return i}return{row:0,column:0}}return e}};var mi={"red-green":{color_space:"RGB",stops:[{value:0,color:{theme:5,tint:.5}},{value:1,color:{theme:9,tint:.5}}]},"red-yellow-green":{color_space:"RGB",stops:[{value:0,color:{theme:5,tint:.5}},{value:.5,color:{theme:7,tint:.5}},{value:1,color:{theme:9,tint:.5}}]},"green-red":{color_space:"RGB",stops:[{value:0,color:{theme:9,tint:.5}},{value:1,color:{theme:5,tint:.5}}]},"green-yellow-red":{color_space:"RGB",stops:[{value:0,color:{theme:9,tint:.5}},{value:.5,color:{theme:7,tint:.5}},{value:1,color:{theme:5,tint:.5}}]}};var Ut=class c{static type="vertex";type=c.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 i of t.edges_out){if(i.color===1)return this.color=0,!0;i.color===0&&i.edges_out.size&&(e.push(i),r=!1)}}r&&(t.color=2,e.pop())}return this.color=2,!1}};var $e=class extends Ut{dirty=!1};var fi={error:"NOTIMPL"},xe=()=>({type:6,value:"N/A"}),Ce=()=>({type:6,value:"EXPR"});var he=()=>({type:6,value:"DIV/0"}),L=()=>({type:6,value:"ARG"}),E=()=>({type:6,value:"VALUE"}),B=()=>({type:6,value:"REF"}),Ar=()=>({type:6,value:"NAME"}),Vt=()=>({type:6,value:"UNK"});var Ae=class c extends $e{static type="spreadsheet-vertex";reference;error=0;address;result={type:0};expression={type:"missing",id:-1};expression_error=!1;short_circuit=!1;type=c.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=j(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){let t=this.result.type===8?this.result.value[0][0]:this.result;this.reference.SetCalculatedValue(t.value,t.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 Ue=class c extends $e{static type="array-vertex";static list=[];type=c.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 c(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(),c.list.push(this)}RemoveDependent(e){super.RemoveDependent(e),this.edges_out.size||(this.Reset(),c.list=c.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 Lt=class{vertices=[[]];volatile_list=[];calculation_list=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===Ae.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),Ue.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 i=r[e.column];if(i&&i.area){let n={row:i.area.start.row,column:i.area.start.column,sheet_id:e.sheet_id};return console.info("array head",e,n),n}}return e}GetVertex(e,t){if(!e.sheet_id)throw console.info({address:e,create:t}),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 n=this.vertices[e.sheet_id][e.column][e.row];if(n)return n;if(!t)return}else{if(!t)return;this.vertices[e.sheet_id][e.column]=[]}let i=new Ae;return i.address={row:e.row,column:e.column,absolute_row:e.absolute_row,absolute_column:e.absolute_column,sheet_id:e.sheet_id},i.reference=r.EnsureCell(e),this.vertices[e.sheet_id][e.column][e.row]=i,Ue.CreateImplicitEdges(i,e),i}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,i=!1){this.RIBcount++;let n=this.GetVertex(e,r);if(!n){if(t){let s=Ue.GetContainingArrays(e);for(let o of s)this.SetVertexDirty(o)}return}let a=[];if(i&&(a=Array.from(n.edges_in)),n.ClearDependencies(),t&&this.SetVertexDirty(n),i){n.has_outbound_edges||this.RemoveVertex(e);for(let s of a)if(!s.has_inbound_edges&&!s.has_outbound_edges){let o=s;o.address&&this.RemoveVertex(o.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 i of this.vertices)if(i){for(let n of i)if(n)for(let a of n)a&&(a.color=a.edges_out.size?0:2,t.push(a))}let r=[];for(let i of t)if(i.color===0){for(i.color=1,r.push(i);r.length;){let n=r[r.length-1],a=!0;if(n.color!==2)for(let s of n.edges_out){if(s.color===1)return this.loop_hint=this.RenderAddress(i.address),console.info("loop detected @",this.loop_hint),!0;s.color===0&&(r.push(s),a=!1)}a&&(r.pop(),n.color=2)}i.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 i=this.model.sheets.Find(e.sheet_id);i&&(t=i.name+"!")}let r=new y(e);return t+r.spreadsheet_label}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0),[i,n]=Ue.GetVertex(e);if(r.DependsOn(i),this.loop_check_required=!0,!n)return;let a=this.vertices[e.start.sheet_id];if(a)if(e.entire_row){for(let s=0;s<a.length;s++)if(a[s])for(let o=e.start.row;o<=e.end.row;o++){let l=a[s][o];l&&i.DependsOn(l)}}else if(e.entire_column){for(let s=e.start.column;s<=e.end.column;s++)if(a[s])for(let o of a[s])o?.address&&i.DependsOn(o)}else for(let s=e.start.row;s<=e.end.row;s++)for(let o=e.start.column;o<=e.end.column;o++){let l=a[o][s];l&&i.DependsOn(l)}}AddEdge(e,t,r){let i=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(i),i.reference&&i.reference.area&&!i.array_head&&this.AddEdge({...e,row:i.reference.area.start.row,column:i.reference.area.start.column},t,"implicit"),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),i=this.GetVertex(t,!1);!r||!i||(r.RemoveDependent(i),i.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 i=e.start.row;i<=e.end.row;i++){let n={row:i,column:r,sheet_id:t};this.GetVertex(n,!1)&&this.SetDirty(n)}}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.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 Fn=c=>{let e={m:c,n:c,array:[]};for(let t=0;t<c;t++){let r=[];for(let i=0;i<c;i++)r.push({real:0,imaginary:0});e.array.push(r)}return e};var Ln=c=>{let{r:e,theta:t}=c,r=e*Math.cos(t),i=e*Math.sin(t);return{real:r,imaginary:i}},Pt=c=>{let e=Math.sqrt(c.real*c.real+c.imaginary*c.imaginary),t=Math.atan2(c.imaginary,c.real);return{r:e,theta:t}},le=(c,e)=>({real:c.real*e.real-c.imaginary*e.imaginary,imaginary:c.real*e.imaginary+c.imaginary*e.real}),Pn=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<c.n;n++)i.push(c.array[r][n]+e.array[r][n]);t.push(i)}return{m:c.m,n:c.n,array:t}},Sr=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let a=0;for(let s=0;s<c.n;s++)a+=c.array[r][s]*e.array[s][n];i.push(a)}t.push(i)}return{array:t,m:c.m,n:e.n}},bi=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let a={real:0,imaginary:0};for(let s=0;s<c.n;s++)a.real+=c.array[r][s].real*e.array[s][n].real-c.array[r][s].imaginary*e.array[s][n].imaginary,a.imaginary+=c.array[r][s].real*e.array[s][n].imaginary+c.array[r][s].imaginary*e.array[s][n].real;i.push(a)}t.push(i)}return t},Gt=c=>{let e={real:0,imaginary:0},t=c.n;if(t==2){let i=le(c.array[0][0],c.array[1][1]),n=le(c.array[1][0],c.array[0][1]);return{real:i.real-n.real,imaginary:i.imaginary-n.imaginary}}let r=Fn(c.n);for(let i=0;i<t;i++){let n=0;for(let o=1;o<t;o++){let l=0;for(let d=0;d<t;d++)d!=i&&(r.array[n][l]={...c.array[o][d]},l++);n++}r.m=r.n=t-1;let a=Math.pow(-1,i),s=le({real:c.array[0][i].real*a,imaginary:c.array[0][i].imaginary*a},Gt(r));e.real+=s.real,e.imaginary+=s.imaginary}return e};var Gn=c=>{let e={real_values:!1,imaginary_values:!1,square:c.m===c.n,unit_diagonal:!0},t={m:c.m,n:c.n,array:[]},r={m:c.m,n:c.n,array:[]};for(let i=0;i<c.m;i++){let n=c.array[i],a=[],s=[];for(let o=0;o<c.n;o++)n[o].real&&(e.real_values=!0),n[o].imaginary&&(e.imaginary_values=!0),o===i&&e.unit_diagonal&&(n[o].real!==1||n[o].imaginary!==0)&&(e.unit_diagonal=!1),a.push(n[o].real),s.push(n[o].imaginary);t.array.push(a),r.array.push(s)}return{real:t,imaginary:r,flags:e}},Hn=c=>{let e=c.array.map(t=>t.slice(0));return{m:c.m,n:c.n,array:e}},pi=c=>{if(c.m!==c.n)return;let e=Hn(c),t=e.array,r=0,i=0,n=0,a=0,s=c.m;for(i=1;i<s;i++)t[0][i]/=t[0][0];for(i=1;i<s;i++){for(n=i;n<s;n++){for(r=0,a=0;a<i;a++)r+=t[n][a]*t[a][i];t[n][i]-=r}if(i!=s-1)for(n=i+1;n<s;n++){for(r=0,a=0;a<i;a++)r+=t[i][a]*t[a][n];t[i][n]=(t[i][n]-r)/t[i][i]}}for(i=0;i<s;i++)for(n=i;n<s;n++){let o=1;if(i!=n)for(o=0,a=i;a<n;a++)o-=t[n][a]*t[a][i];t[n][i]=o/t[n][n]}for(i=0;i<s;i++)for(n=i;n<s;n++)if(i!=n){for(r=0,a=i;a<n;a++)r+=t[a][n]*(i==a?1:t[i][a]);t[i][n]=-r}for(i=0;i<s;i++)for(n=0;n<s;n++){for(r=0,a=i>n?i:n;a<s;a++)r+=(n==a?1:t[n][a])*t[a][i];t[n][i]=r}return e},gi=c=>{let e=[];if(c.m!==c.n)return;let{real:t,imaginary:r,flags:i}=Gn(c),n=pi(t);if(!n)return;if(!i.imaginary_values){for(let h=0;h<c.m;h++){let u=[];for(let m=0;m<c.n;m++)u.push({real:n.array[h][m],imaginary:0});e.push(u)}return e}let a=Sr(n,r),s=Sr(r,a),o=Pn(t,s),l=pi(o);if(!l)return;let d=Sr(a,l);for(let h=0;h<c.m;h++){let u=[];for(let m=0;m<c.n;m++)u.push({real:l.array[h][m],imaginary:-d.array[h][m]});e.push(u)}return e},_i=(c,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=le(c,t),i=le(e,t);return{real:r.real/i.real,imaginary:r.imaginary/i.real}},kr=c=>{let e=c.real||0,t=c.imaginary||0;return le({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},On=c=>{let e=Pt(c);return{real:Math.log(e.r),imaginary:e.theta}},ue=(c,e)=>{if(e.imaginary)return kr(le(e,On(c)));{let t=Pt(c);return Ln({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var yi=(c,e=0)=>c&&c.type===7?c:{type:7,value:{real:e,imaginary:0}},Ve=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real},Fe=(c,e)=>{if(c.type===6)return[0,0,c];if(e.type===6)return[0,0,e];let t=[0,0];switch(c.type){case 3:t[0]=c.value;break;case 4:t[0]=c.value?1:0;break;case 0:break;case 7:t[3]=c;break;default:return[0,0,E()]}switch(e.type){case 3:t[1]=e.value;break;case 4:t[1]=e.value?1:0;break;case 0:break;case 7:t[4]=e;break;default:return[0,0,E()]}return(t[3]||t[4])&&(t[3]=yi(t[3],t[0]),t[4]=yi(t[4],t[1])),t},$n=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ve({real:n.value.real+a.value.real,imaginary:n.value.imaginary+a.value.imaginary}):{value:t+r,type:3})},Mr=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ve({real:n.value.real-a.value.real,imaginary:n.value.imaginary-a.value.imaginary}):{value:t-r,type:3})},Zn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);if(i)return i;if(n&&a)return Ve(ue(n.value,a.value));let s=Math.pow(t,r);return isNaN(s)?E():{type:3,value:s}},Bn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);if(i)return i;if(n&&a)return Ve(ue(n.value,a.value));if(t<0&&r!==0&&Math.abs(r)<1)return Ve(ue({real:t,imaginary:0},{real:r,imaginary:0}));let s=Math.pow(t,r);return isNaN(s)?E():{type:3,value:s}},Rr=Zn,Wn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?Ve(le(n.value,a.value)):{value:t*r,type:3})},jn=(c,e)=>{let[t,r,i,n,a]=Fe(c,e);return i||(n&&a?a.value.real===0&&a.value.imaginary===0?he():Ve(_i(n.value,a.value)):r===0?he():{value:t/r,type:3})},Yn=(c,e)=>{let[t,r,i]=Fe(c,e);return i||(r===0?he():{value:t%r,type:3})},Jn=(c,e)=>c.type===6?c:e.type===6?e:{type:2,value:`${c.type===0?"":c.value}${e.type===0?"":e.value}`},Er=(c,e)=>{if(c.type===6)return c;if(e.type===6)return e;if(c.type===0&&(e.value===""||e.value===0||e.type===7&&e.value.real===0&&e.value.imaginary===0)||e.type===0&&(c.value===""||c.value===0||c.type===7&&c.value.real===0&&c.value.imaginary===0))return{type:4,value:!0};if(c.type===7||e.type===7){let t=!1;return c.type===e.type?t=c.value.real==e.value.real&&c.value.imaginary==e.value.imaginary:c.type===3?t=e.value.real==c.value&&!e.value.imaginary:e.type===3&&(t=c.value.real==e.value&&!c.value.imaginary),{type:4,value:t}}return{type:4,value:c.value==e.value}},vi=(c,e)=>{let t=Er(c,e);return t.type===6?t:{type:4,value:!t.value}},Xn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:(c.value||0)>(e.value||0)},Qn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value>=e.value},qn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value<e.value},Kn=(c,e)=>c.type===6?c:e.type===6?e:c.type===7||e.type===7?E():{type:4,value:c.value<=e.value},wi=()=>{Rr=Bn},xi=c=>{switch(c){case"&":return Jn;case"+":return $n;case"-":return Mr;case"*":return Wn;case"/":return jn;case"^":return Rr;case"**":return Rr;case"%":return Yn;case"=":return Er;case"==":return Er;case"!=":return vi;case"<>":return vi;case">":return Xn;case">=":return Qn;case"<":return qn;case"<=":return Kn}};var Ai=c=>!Array.isArray(c)&&c.type===5&&!!c.value.type,st=c=>c.type===5&&c.key==="metadata",Ht=class{constructor(e,t){this.library=e;this.parser=t}context={address:{row:-1,column:-1},volatile:!1,call_index:0};call_index=0;named_range_map={};data_model;SetModel(e){this.data_model=e,this.named_range_map=e.named_ranges.Map(),this.context.model=e}Calculate(e,t,r=!1){return r||(this.context.address=t,this.context.volatile=!1,this.context.call_index=0,this.call_index=0),{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()=>B();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>B();let r=t.GetCell(e);return r?()=>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)||B():B()}GetMetadata(e,t){let r,i;switch(e.type){case"address":r=e;break;case"range":i=e;break;case"structured-reference":{let n=this.data_model.ResolveStructuredReference(e,this.context.address);n&&(n.type==="address"?r=n:n.type==="range"&&(i=n))}break;case"identifier":{let n=this.named_range_map[e.name.toUpperCase()];n&&(n.count===1?r=n.start:i=n)}break;case"call":{let n=this.CalculateExpression(e,!0);if(Ai(n))if(n.value.type==="address")r=n.value;else if(n.value.type==="range")i=n.value;else return n;else return n}break;default:return this.CalculateExpression(e)}if(r){let n;if(r.sheet_id&&(n=this.data_model.sheets.Find(r.sheet_id)),!n)return console.error("missing sheet [ac8]"),B();let a=n.CellData(r),s=a.calculated_type?a.calculated:a.value,o={type:"metadata",address:{...r},value:s,format:a.style?a.style.number_format:void 0,...t(a,r)};return{type:5,value:o,key:"metadata"}}else if(i){if(i.start.row===1/0||i.start.column===1/0)return B();let n;if(i.start.sheet_id&&(n=this.data_model.sheets.Find(i.start.sheet_id)),!n)throw new Error("missing sheet [ac9]");let a=[];for(let s=i.start.column;s<=i.end.column;s++){let o=[];for(let l=i.start.row;l<=i.end.row;l++){let d=n.CellData({row:l,column:s});r={...i.start,row:l,column:s};let h=d.calculated_type?d.calculated:d.value,u={type:"metadata",address:r,value:h,format:d.style?d.style.number_format:void 0,...t(d,r)};o.push({type:5,value:u,key:"metadata"})}a.push(o)}return{type:8,value:a}}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(i=>this.RewriteMacro(i,t));break;case"call":e.args=e.args.map(i=>this.RewriteMacro(i,t));break}return e}CallMacro(e,t){if(!t.expression)return()=>Ce();let r=JSON.stringify(t.expression),i={},n=t.argument_names?.map(a=>a.toUpperCase())||[];return a=>{let s=JSON.parse(r);for(let o=0;o<n.length;o++)i[n[o]]=a.args[o]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(s,i))}}CallExpression(e,t=!1){let r=this.library.Get(e.name);return r?i=>{let n=this.call_index++;this.context.volatile=this.context.volatile||!!r.volatile;let a=e.name.toLowerCase()==="if",s=-1,o,l=r.arguments||[],d=i.args.map((h,u)=>{if(o)return;let m=l[Math.min(u,l.length-1)]||{};if(u===s)return m.boxed?{type:0}:void 0;if(typeof h>"u")return a&&u===0&&(s=1),m.boxed?{type:0}:void 0;if(m.address)return m.boxed?{type:2,value:this.parser.Render(h).replace(/\$/g,"")}:this.parser.Render(h).replace(/\$/g,"");if(m.metadata)return this.GetMetadata(h,()=>({}));{let f=this.CalculateExpression(h);if(f.type===6){if(m.allow_error)return f;o=f;return}if(a&&u===0&&f.type!==8){let p=!1;if(f.type===2){let g=f.value.toLowerCase().trim();p=g!=="false"&&g!=="f"}else p=!!f.value;s=p?2:1}return m.boxed?f:f.type===8?f.value.map(p=>p.map(g=>g.value)):f.value}});if(o)return o;if(this.context.call_index=n,r.return_type===1){let h=r.fn.apply(null,d);if(t)return h;if(Ai(h)){if(h.value.type==="address")return this.CellFunction2(h.value)();if(h.value.type==="range")return this.CellFunction4(h.value.start,h.value.end)}return h}return r.fn.apply(null,d)}:()=>Ar()}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()=>B()}ResolveDimensionedQuantity(){return e=>{let t=this.CalculateExpression(e.expression);return{type:9,value:{value:t.value,unit:e.unit.name}}}}UnaryExpression(e){switch(e.operator){case"+":return t=>this.CalculateExpression(t.operand);case"-":{let t=Mr,r={type:3,value:0};return i=>{let n=this.CalculateExpression(i.operand);return n.type===8?{type:8,value:n.value.map(a=>a.map(s=>t(r,s)))}:t(r,n)}}default:return()=>(console.warn("unexpected unary operator:",e.operator),Ce())}}RecycleArray(e,t,r){if(e[0].length<r){let i=e[0].length;for(let n of e)for(let a=i;a<r;a++)n[a]=n[a%i]}if(e.length<t){let i=e.length;for(let n=i;n<t;n++)e[n]=e[n%i].slice(0)}return e}ElementwiseBinaryExpression(e,t,r){let i=Math.max(t.value.length,r.value.length),n=Math.max(t.value[0].length,r.value[0].length),a=this.RecycleArray(t.value,i,n),s=this.RecycleArray(r.value,i,n),o=[];for(let l=0;l<i;l++){let d=[];for(let h=0;h<n;h++)d[h]=e(a[l][h],s[l][h]);o.push(d)}return{type:8,value:o}}BinaryExpression(e){let t=xi(e.operator);return t?r=>{let i=this.CalculateExpression(r.left),n=this.CalculateExpression(r.right);return i.type===8?n.type===8?this.ElementwiseBinaryExpression(t,i,n):this.ElementwiseBinaryExpression(t,i,{type:8,value:[[n]]}):n.type===8?this.ElementwiseBinaryExpression(t,{type:8,value:[[i]]},n):t(i,n)}:()=>(console.info(`(unexpected binary operator: ${e.operator})`),Ce())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>B();let r=t.toUpperCase();switch(r){case"FALSE":case"F":return()=>({value:!1,type:4});case"TRUE":case"T":return()=>({value:!0,type:4});case"UNDEFINED":return()=>({value:void 0,type:0})}return()=>{let i=this.named_range_map[r];if(i)return i.count===1?this.CellFunction4(i.start,i.start):this.CellFunction4(i.start,i.end);let n=this.data_model.named_expressions.get(r);return n?this.CalculateExpression(n):Ar()}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>Ce()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.user_data)return e.user_data(e);switch(e.type){case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.user_data=this.CallMacro(e,r))(e):(e.user_data=this.CallExpression(e,t))(e)}case"address":return(e.user_data=this.CellFunction2(e))();case"range":return(e.user_data=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.user_data=this.BinaryExpression(e))(e);case"unary":return(e.user_data=this.UnaryExpression(e))(e);case"identifier":return(e.user_data=this.Identifier(e))();case"missing":return(e.user_data=()=>({value:void 0,type:0}))();case"dimensioned":return(e.user_data=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:se(e.value)};return(e.user_data=()=>r)()}case"group":return(e.user_data=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:7};return(e.user_data=()=>r)()}case"structured-reference":return(e.user_data=this.ResolveStructuredReference(e))();case"array":return(e.user_data=()=>({type:8,value:e.values.map(r=>(Array.isArray(r)?r:[r]).map(i=>({type:se(i),value:i})))}))();default:return console.warn("Unhandled parse expr:",e),Vt()}}};var Gc=1e3*60*60*24;var Ot=c=>{let e=[],t=c.length,r=c[0].length;for(let i=0;i<r;i++){e[i]=[];for(let n=0;n<t;n++)e[i][n]=c[n][i]}return e};var _e=c=>{let e=[];for(let t of c)if(t.type===8)for(let r of t.value)e=e.concat(_e(r));else e.push(t);return e},P=c=>Array.isArray(c)?c.reduce((e,t)=>typeof t>"u"?e:Array.isArray(t)?e.concat(P(t)):t instanceof Float32Array||t instanceof Float64Array?e.concat(Array.from(t)):e.concat([t]),[]):[c];var G=c=>(e,...t)=>Array.isArray(e)?{type:8,value:e.map(r=>r.map(i=>c(i,...t)))}:typeof e=="object"&&e&&e.type===8?{type:8,value:e.value.map(r=>r.map(i=>c(i,...t)))}:c(e,...t),Se=c=>(e,t,...r)=>{let i=!1,n=!1;return e&&typeof e=="object"&&e.type===8?(e=e.value,i=!0):i=Array.isArray(e),t&&typeof t=="object"&&t.type===8?(t=t.value,n=!0):n=Array.isArray(t),i?n?{type:8,value:e.map((a,s)=>a.map((o,l)=>c(o,t[s][l],...r)))}:{type:8,value:e.map(a=>a.map(s=>c(s,t,...r)))}:n?{type:8,value:t.map(a=>a.map(s=>c(e,s,...r)))}:c(e,t,...r)};var $t=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 i=r.toLowerCase();if(this.functions[i])throw new Error(`function name (${i}) is already in use`);let n=t[r];n.canonical_name=r,this.functions[i]=n}}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 ot=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,i)=>r.concat(this.UnpackValues(i)),[]):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 i=[];for(let n=0;n<r;n++)i[n]=e[n.toString()];return i}}}return[]}static SparklineCommon(e,t){let r=[],i=t.text?.text||this.default_color,n=[i,i];return Array.isArray(e.calculated)&&(r=this.UnpackValues(e.calculated[0]),typeof e.calculated[1]=="string"&&(n[0]=e.calculated[1]),typeof e.calculated[2]=="string"&&(n[1]=e.calculated[2])),{values:r,colors:n}}static RenderLine(e,t,r,i,n){let{values:a,colors:s}=this.SparklineCommon(i,n),o=.05,l=.1,d=1;Array.isArray(i.calculated)&&typeof i.calculated[2]=="number"&&(d=i.calculated[2]);let h=0,u=0,m=-1;for(let f=0;f<a.length;f++){let p=a[f];typeof p=="number"&&(m>=0?(h=Math.min(h,p),u=Math.max(u,p)):(m=f,h=u=p))}if(h!==u){let f=e*(1-2*o)/(a.length-1),p=u-h,g=t*(1-2*l),b=t*l;r.strokeStyle=s[0],r.lineWidth=d,r.lineCap="round",r.lineJoin="round",r.beginPath();let v=0;for(let _=m;_<a.length;_++){let w=a[_];if(typeof w=="number"){let x=e*o+f*_,A=t-(w-h)*g/p-b;v===0?(r.moveTo(x,A),v=1):r.lineTo(x,A)}else v=0}r.stroke()}}static RenderColumn(e,t,r,i,n){let{values:a,colors:s}=this.SparklineCommon(i,n),o=3,l=2.5,d=0,h=0,u=!1;for(let m of a)typeof m=="number"&&(u?(d=Math.min(d,m),h=Math.max(h,m)):(u=!0,d=h=m));if(a.length){let m=(e-2*o-2)/(a.length-0),f=t-2*l,p=l;if(d!==h)if(d<0&&h>0){let g=h-d,b=p+h/g*f;for(let v=0;v<a.length;v++){let _=a[v];if(typeof _=="number"){let w=o+v*m,x=Math.abs(_)/g*f;if(_>=0){r.fillStyle=s[0];let A=b-x;r.fillRect(w+2,A,m-2,x)}else{r.fillStyle=s[1];let A=b;r.fillRect(w+2,A,m-2,x)}}}}else if(h>0){r.fillStyle=s[0];let g=h-d;for(let b=0;b<a.length;b++){let v=a[b];if(typeof v=="number"){let _=o+b*m,w=Math.max(1,(v-d)/g*f),x=t-p-w;r.fillRect(_+2,x,m-2,w)}}}else{r.fillStyle=s[1];let g=h-d;for(let b=0;b<a.length;b++){let v=a[b];if(typeof v=="number"){let _=o+b*m,w=Math.max(1,Math.abs(h-v)/g*f),x=p;r.fillRect(_+2,x,m-2,w)}}}}}};var Si=c=>{let{x:e,y:t,width:r,height:i,cell:n}=c,a={},s=3,o=Math.round(16*(c.scale||1));if(n&&r&&i&&e&&t){let l={x:s,y:i-s-o};if(n.style){switch(n.style.vertical_align){case"top":l.y=s;break;case"middle":l.y=Math.round((i-o)/2);break}switch(n.style.horizontal_align){case"right":l.x=Math.round(r-s-o);break;case"center":l.x=Math.round((r-o)/2);break}}e>=l.x&&e<=l.x+o&&t>=l.y&&t<=l.y+o&&(a.value=`=Checkbox(${n.calculated?"FALSE":"TRUE"})`,a.block_selection=!0)}return a},ki=c=>{let{context:e,width:t,height:r,cell:i}=c,n=c.scale||1;e.lineJoin="round",e.lineCap="round";let a=3*n,s=16*n,o=a,l=r-a-s;if(i.style){switch(i.style.vertical_align){case"top":l=a;break;case"middle":l=(r-s)/2;break}switch(i.style.horizontal_align){case"right":o=t-a-s;break;case"center":o=(t-s)/2;break}}o=Math.floor(o)+.5,l=Math.floor(l)+.5;let d=Math.floor(o+s)+.5,h=Math.floor(l+s)+.5;if(i&&i.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(o,l),e.lineTo(o+16*n,l),e.lineTo(o+16*n,l+16*n),e.lineTo(o,l+16*n),e.closePath(),e.moveTo(o+15*n,l+4*n);for(let u of[[13.59,2.58],[6,10.17],[2.41,6.59],[1,8],[6,13]])e.lineTo(o+u[0]*n,l+u[1]*n);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(o,l),e.lineTo(d,l),e.lineTo(d,h),e.lineTo(o,h),e.closePath(),e.stroke();return{handled:!0}};var Ti=c=>{let e=.254829592,t=-.284496736,r=1.421413741,i=-1.453152027,n=1.061405429,a=.3275911;c=Math.abs(c);let s=1/(1+a*c);return 1-((((n*s+i)*s+r)*s+t)*s+e)*s*Math.exp(-1*c*c)},ta=Math.sqrt(2*Math.PI),Ri=c=>{if(c===.5)return 0;let e=c<1&&c>.5?1-c:c,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 c>.5?r:-r},Ir={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=ue(c.value,{real:.5,imaginary:0});return ce(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3&&c.value<0){let e=ue({real:c.value,imaginary:0},{real:.5,imaginary:0});return{type:7,value:e}}else{let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}}})},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0},{name:"exponent",boxed:!0}],fn:Se((c,e)=>{if(c.type===3&&e.type===3&&(c.value>=0||e.value===0||Math.abs(e.value)>=1)){let n=Math.pow(c.value,e.value);return isNaN(n)?E():{type:3,value:n}}let t=c.type===7?c.value:{real:c.value||0,imaginary:0},r=e.type===7?e.value:{real:e.value||0,imaginary:0},i=ue(t,r);return ce(i)})}},Be={Int:{fn:c=>({type:3,value:Math.floor(c)})},Rand:{volatile:!0,fn:()=>({type:3,value:Math.random()})},RandBetween:{arguments:[{name:"min"},{name:"max"}],volatile:!0,fn:(c=0,e=1)=>{if(c>e){let t=c;c=e,e=t}return{type:3,value:Math.floor(Math.random()*(e+1-c)+c)}}},Sum:{description:"Adds arguments and ranges",arguments:[{boxed:!0,name:"values or ranges"}],fn:(...c)=>{let e={real:0,imaginary:0},t=_e(c);for(let r of t)switch(r.type){case 3:e.real+=r.value;break;case 4:e.real+=r.value?1:0;break;case 7:e.real+=r.value.real,e.imaginary+=r.value.imaginary;break;case 6:return r}return ce(e)}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:He(new Date().getTime())})},Date:{description:"Constructs a Lotus date from parts",arguments:[{name:"year"},{name:"month"},{name:"day"}],fn:(c,e,t)=>{let r=new Date;return r.setMilliseconds(0),r.setSeconds(0),r.setMinutes(0),r.setHours(0),c<0||c>1e4?L():(c<1899&&(c+=1900),r.setFullYear(c),e<1||e>12?L():(r.setMonth(e-1),t<1||t>31?L():(r.setDate(t),{type:3,value:He(r.getTime())})))}},Today:{description:"Returns current day",volatile:!0,fn:()=>{let c=new Date;return c.setMilliseconds(0),c.setSeconds(0),c.setMinutes(0),c.setHours(12),{type:3,value:He(c.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:(c,e=0)=>c&&c.type===6?{value:e,type:se(e)}:c},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=_e(c);for(let t of e)if(t.type===6)return{type:4,value:!0};return{type:4,value:!1}}},Cell:{description:"Returns data about a cell",arguments:[{name:"type",description:"Type of data to return"},{name:"reference",description:"Cell reference",metadata:!0}],fn:Se((c,e)=>{if(!st(e))return B();if(c)switch(c.toString().toLowerCase()){case"format":return e.value.format?{type:2,value:e.value.format}:B();case"address":return{type:2,value:e.value.address.label.replace(/\$/g,"")}}return{type:6,value:fi.error}})},Year:{description:"Returns year from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date"}],fn:c=>j(new Date(De(c)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees"}],fn:G(c=>j(c*Math.PI/180))},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians"}],fn:G(c=>j(c/Math.PI*180))},CountA:{description:"Counts cells that are not empty",fn:(...c)=>j(P(c).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...c)=>j(P(c).reduce((e,t)=>typeof t=="number"||fe(t)?e+1:e,0))},Or:{fn:(...c)=>{let e=!1;c=P(c);for(let t of c)e=e||!!t;return j(e)}},And:{fn:(...c)=>{let e=!0;c=P(c);for(let t of c)e=e&&!!t;return j(e)}},Not:{fn:G((...c)=>c.length===0?L():c.length===1?j(!c[0]):j(!0))},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:(c,e={type:4,value:!0},t={type:4,value:!1})=>{let r=e.type===8,i=t.type===8;return c.type===8?{type:8,value:c.value.map((a,s)=>a.map((o,l)=>(o.type===2?o.value.toLowerCase()!=="false"&&o.value.toLowerCase()!=="f":!!o.value)?r?e.value[s][l]:e:i?t.value[s][l]:t))}:(c.type===2?c.value.toLowerCase()!=="false"&&c.value.toLowerCase()!=="f":!!c.value)?e:t}},Fact:{description:"Returns the factorial of a number",arguments:[{name:"number"}],fn:G(c=>{c=Math.floor(c);let e=1;for(;c>1;)e*=c,c--;return{type:3,value:e}})},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0},{name:"exponent",boxed:!0}],fn:Se((c,e)=>{if(c.type===7||e.type===7){let t=c.type===7?c.value:{real:c.value||0,imaginary:0},r=e.type===7?e.value:{real:e.value||0,imaginary:0},i=ue(t,r);return ce(i)}else{let t=Math.pow(c.value,e.value);return isNaN(t)?E():{type:3,value:t}}})},Mod:{fn:Se((c,e)=>e?j(c%e):he())},Sort:{arguments:[{name:"values"}],fn:(...c)=>(c=P(c),c.every(e=>typeof e=="number")?c.sort((e,t)=>e-t):c.sort(),{type:8,value:[c.map(e=>j(e))]})},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>c.type===8?{type:8,value:Ot(c.value)}:c},Max:{fn:(...c)=>({type:3,value:Math.max.apply(0,P(c).filter(e=>typeof e=="number"))})},Min:{fn:(...c)=>({type:3,value:Math.min.apply(0,P(c).filter(e=>typeof e=="number"))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...c)=>{let e=c.map(i=>P(i)),t=Math.max.apply(0,e.map(i=>i.length)),r=0;for(let i=0;i<t;i++)r+=e.reduce((n,a)=>n*(a[i]||0),1);return{type:3,value:r}}},VLookup:{fn:(c,e,t,r=!0)=>{if(t=Math.max(0,t-1),r){let i=Math.abs(c-e[0][0]),n=e[t][0];for(let a=1;a<e[0].length;a++){let s=Math.abs(e[0][a]-c);s<i&&(i=s,n=e[t][a])}return j(n)}else{for(let i=1;i<e[0].length;i++)if(e[0][i]==c)return e[t][i];return xe()}}},Product:{arguments:[{boxed:!0}],fn:(...c)=>{let e={real:1,imaginary:0};c=_e(c);for(let t of c)t.type===7?e=le(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return ce(e)}},Log:{fn:Se((c,e=10)=>({type:3,value:Math.log(c)/Math.log(e)}))},Log10:{fn:G(c=>({type:3,value:Math.log(c)/Math.log(10)}))},Ln:{fn:G(c=>({type:3,value:Math.log(c)}))},Round:{fn:Se((c,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*c)/t}})},RoundDown:{fn:Se((c,e=0)=>{let t=Math.pow(10,e),r=c>=0;return{type:3,value:r?Math.floor(t*c)/t:Math.ceil(t*c)/t}})},Reverse:{arguments:[{boxed:!0}],fn:c=>c.type===8?(c.value.length===1?c.value[0].reverse():c.value.reverse(),c):{type:2,value:c.value.toString().split("").reverse().join("")}},Exp:{arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=kr(c.value);return ce(e)}return{type:3,value:Math.exp(c.value||0)}})},Abs:{arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:Math.sqrt(c.value.real*c.value.real+c.value.imaginary*c.value.imaginary)}:{type:3,value:Math.abs(c.value||0)})},Simplify:{arguments:[{name:"value"},{name:"significant digits"}],fn:Se((c,e=2)=>{if(e=e||2,c===0)return{type:3,value:c};let t=c<0?-1:1;c*=t;let r=Math.pow(10,Math.floor(Math.log10(c))+1-e);return{type:3,value:Math.round(c/r)*r*t}})},Erf:{fn:c=>({type:3,value:Ti(c)})},NormsInv:{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"}],fn:c=>({type:3,value:Ri(c)})},"Norm.Inv":{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"},{name:"mean",default:0},{name:"standard deviation",default:1}],xlfn:!0,fn:(c,e=0,t=1)=>({type:3,value:Ri(c)*t+e})},"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:(c,e=0,t=1,r=!0)=>{let i=0;return r?i=.5*(1+(c<e?-1:1)*Ti(Math.abs(c-e)/(t*Math.sqrt(2)))):i=Math.exp(-1/2*Math.pow((c-e)/t,2))/(t*ta),{type:3,value:i}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===7){let e=ue(c.value,{real:.5,imaginary:0});return ce(e)}else{if(c.type===0||!c.value)return{type:3,value:0};{let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}}})},HexToDec:{arguments:[{description:"hexadecimal string"}],fn:c=>({type:3,value:parseInt(c,16)})},DecToHex:{arguments:[{description:"number"}],fn:c=>({type:2,value:c.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Si,render:ki,fn:c=>({value:!!c,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:c=>(ot.RenderColumn(c.width,c.height,c.context,c.cell,c.style),{handled:!0}),fn:(...c)=>({type:5,value:c,key:"sparkline-data"})},"Sparkline.Line":{arguments:[{name:"data"},{name:"color"},{name:"line width"}],render:c=>(ot.RenderLine(c.width,c.height,c.context,c.cell,c.style),{handled:!0}),fn:(...c)=>({type:5,value:c,key:"sparkline-data"})},UniqueValues:{arguments:[{name:"range",boxed:!0}],visibility:"internal",fn:c=>{if(c.type===8){let e=c.value.length,t=c.value[0]?.length,r=s=>{if(s)switch(s.type){case 2:case 3:case 4:return s.value;case 0:return"";default:return console.info("check",s,s.value),s.value?.toString()||""}else return""},i=new Set,n=new Set;for(let s of c.value)for(let o of s){let l=r(o);i.has(l)?n.add(l):i.add(l)}let a=[];for(let s of c.value){let o=[];for(let l of s){let d=r(l);o.push({type:4,value:!n.has(d)})}a.push(o)}return{type:8,value:a}}return{type:4,value:!0}}},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(c,e,t)=>{let r=_e([c]),i=0,n=0,a=0,s=0;for(let h of r){if(h.type===6)return h;h.type===3&&(n===0?(a=h.value,s=h.value):(a=Math.min(a,h.value),s=Math.max(s,h.value)),n++)}typeof t=="number"&&(s=t),typeof e=="number"&&(a=e);let o=s-a,l=1,d=1;if(c.type===8){l=c.value.length,d=c.value[0]?.length||0;let h=[];for(let u=0;u<l;u++){let m=[];for(let f=0;f<d;f++){let p=c.value[u][f];if(p.type===3){let g=0;o>0&&(g=(p.value-a)/o),m.push({type:3,value:g})}else m.push({type:0})}h.push(m)}return{type:8,value:h}}else return L()}}},Ei={};for(let c of Object.keys(Be))Ei[c.toLowerCase()]=c;var ra=["pow"],Mi={};for(let c of ra)Mi[c.toLowerCase()]=c;for(let c of Object.getOwnPropertyNames(Math)){let e=c.toLowerCase();if(Ei[e]||Mi[e])continue;let t=Object.getOwnPropertyDescriptor(Math,c);if(!t)continue;let r=t.value,i=typeof r;switch(i){case"number":Be[c]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":Be[c]={fn:(...n)=>j(r(...n)),category:["Math Functions"]};break;default:console.info("unexpected type:",i,c);break}}Math.log10||(Math.log10=c=>Math.log(c)/Math.log(10));var lt=(c,e,t=0,r=0,i=0)=>i?-(t*(c/(1-Math.pow(1+c,-e))))/(1+c)-r*(1/((1+c)*((Math.pow(1+c,e)-1)/c))):-(t*c*Math.pow(1+c,e)+r*c)/(Math.pow(1+c,e)-1),zi=(c,e,t,r=0,i=0)=>i?(1+c)*-t/c*(Math.pow(1+c,e)-1)-r*Math.pow(1+c,e):-t/c*(Math.pow(1+c,e)-1)-r*Math.pow(1+c,e),zr=(c,e,t,r=0,i=0,n=0)=>{if(e<1)return NaN;if(e===1&&n)return 0;let a=lt(c,t,r,i,n),s=zi(c,e-1,a,r,n)*c;return n?s/(1+c):s},Ii=(c,e,t,r=0,i=0,n=0)=>lt(c,t,r,i,n)-zr(c,e,t,r,i,n),Di={NPV:{description:"Returns the present value of a series of future cashflows",arguments:[{name:"Rate"},{name:"Cashflow"}],fn:(c=0,...e)=>{let t=0,r=P(e);for(let i=0;i<r.length;i++){let n=r[i];typeof n=="number"&&(t+=Math.pow(1+c,-(i+1))*n)}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:(c,e,t)=>{if(typeof c!="number")return L();if(e=P(e),t=P(t),e.length!==t.length)return L();let r=[];for(let a of e){if(typeof a!="number")return L();r.push(a)}let i=[];for(let a of t){if(typeof a!="number")return L();i.push(Math.floor(a))}let n=0;for(let a=0;a<r.length;a++)n+=(r[a]||0)/Math.pow(1+c,(i[a]-i[0])/365);return{type:3,value:n}}},XIRR:{description:"returns the internal rate of return of a nonperiodic stream of payments",arguments:[{name:"Values"},{name:"Dates"},{name:"Guess",default:.1}],fn:(c,e,t=.1)=>{if(c=P(c),e=P(e),c.length!==e.length)return L();let r=0,i=0,n=[];for(let h of c){if(typeof h!="number")return L();h>0&&r++,h<0&&i++,n.push(h)}if(r<=0||i<=0)return L();let a=[];for(let h of e){if(typeof h!="number")return L();a.push(Math.floor(h))}let s=a[0];for(let h of a)if(h<s)return L();let o=.1,l=[{found:!1,value:0},{found:!1,value:0}],d=n.length;for(let h=0;h<100;h++){let u=0;for(let m=0;m<d;m++)u+=(n[m]||0)/Math.pow(1+t,(a[m]-a[0])/365);if(Math.abs(u)<=1e-6)return{type:3,value:t};if(u>0){if(l[0].value=l[0].found?Math.max(l[0].value,t):t,l[0].found=!0,!l[1].found){t+=o;continue}}else if(l[1].value=l[1].found?Math.min(l[1].value,t):t,l[1].found=!0,!l[0].found){t-=o;continue}t=l[0].value+(l[1].value-l[0].value)/2}return E()}},IRR:{description:"Calculates the internal rate of return of a series of cashflows",arguments:[{name:"Cashflows"},{name:"Guess",default:.1}],fn:(c,e=.1)=>{let t=P(c).map(n=>typeof n=="number"?n:0),r=.1,i=[{found:!1,value:0},{found:!1,value:0}];for(let n=0;n<50;n++){let a=0;for(let s=0;s<t.length;s++)a+=Math.pow(1+e,-(s+1))*t[s];if(Math.abs(a)<=.00125)return{type:3,value:e};if(a>0){if(i[0].value=i[0].found?Math.max(i[0].value,e):e,i[0].found=!0,!i[1].found){e+=r;continue}}else if(i[1].value=i[1].found?Math.min(i[1].value,e):e,i[1].found=!0,!i[0].found){e-=r;continue}e=i[0].value+(i[1].value-i[0].value)/2}return{type:6,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:(c,e,t,r,i,n=0)=>{let a=0;for(let s=r;s<=i;s++)a+=Ii(c,s,e,t,0,n);return{type:3,value:a}}},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:(c,e,t,r,i,n=0)=>{let a=0;for(let s=r;s<=i;s++)a+=zr(c,s,e,t,0,n);return{type:3,value:a}}},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:(c,e,t,r=0,i=0,n=0)=>({type:3,value:zr(c,e,t,r,i,n)})},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:(c,e,t,r=0,i=0,n=0)=>({type:3,value:Ii(c,e,t,r,i,n)})},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:(c,e,t=0,r=0,i=0)=>{let n=.25,a=[-1,1],s=32,o=1e-6;for(let l=0;l<s;l++){let d=lt(n,c,t,r,i);if(Math.abs(d-e)<=o)return{type:3,value:n};let h=lt(a[1],c,t,r,i);e>=d&&e<=h||e>=h&&e<=d?a[0]=n:a[1]=n,n=a[0]+(a[1]-a[0])/2}return{type:3,value:n}}},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:(c,e,t,r=0,i=0)=>({type:3,value:zi(c,e,t,r,i)})},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:(c,e,t,r=0,i=0)=>i?(t+=r*(1/((1+c)*((Math.pow(1+c,e)-1)/c))),{type:3,value:-(t+t/c*(1-Math.pow(1+c,-(e-1))))}):{type:3,value:-(r+t/c*(Math.pow(1+c,e)-1))/Math.pow(1+c,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:(c,e,t=0,r=0,i=0)=>i?{type:3,value:1+(-Math.log(1+c*(1-t/-e))+Math.log(1+r*c/(-e*(1+c))))/Math.log(1+c)}:{type:3,value:(Math.log(Math.pow(1-t*c/-e,-1))+Math.log(1+r*c/-e))/Math.log(1+c)}},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:(c,e,t,r=0,i=0)=>({type:3,value:lt(c,e,t,r,i)})}};var ia=c=>{let e=[],t=c.length,r="[\\^$.|?*+()";for(let i=0;i<t;i++){let n=c[i];switch(n){case"*":e.push(".","*");break;case"?":e.push(".");break;case"~":n=c[++i]||"";default:for(let a=0;a<r.length;a++)if(n===r[a]){e.push("\\");break}e.push(n);break}}return e.join("")},Ni={Char:{arguments:[{name:"number"}],fn:c=>({type:2,value:String.fromCodePoint(c||32)}),category:["text"]},Code:{arguments:[{name:"string"}],fn:c=>({type:3,value:c.codePointAt(0)||0}),category:["text"]},Value:{arguments:[{name:"text"}],fn:c=>{let e=be.TryParse(c);return e.type===3?{type:3,value:e.value}:L()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(c,e="0.00####")=>({type:2,value:I.Get(e).Format(c||0)}),category:["text"]},Left:{arguments:[{name:"string"},{name:"count"}],fn:(c,e=1)=>({type:2,value:c.substr(0,e)}),category:["text"]},Right:{arguments:[{name:"string"},{name:"count"}],fn:(c,e=1)=>({type:2,value:c.slice(-e)}),category:["text"]},Mid:{arguments:[{name:"string"},{name:"left"},{name:"count"}],fn:(c,e=0,t=1)=>({type:2,value:c.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:(c,e,t=1)=>{if(t>=1){if(!c)return{type:3,value:t};let r=ia(c),i=new RegExp(r,"i").exec(e.substr(t-1));if(i)return{type:3,value:i.index+t}}return E()}},Find:{description:"Find a string (needle) in another string (haystack). Case-sensitive.",arguments:[{name:"Needle"},{name:"Haystack"},{name:"Start",default:1}],fn:(c,e,t=1)=>{if(t>=1){if(!c)return{type:3,value:t};let r=new RegExp(c).exec(e.substr(t-1));if(r)return{type:3,value:r.index+t}}return E()}},Concat:{description:"Pastes strings together",fn:(...c)=>{let t=P(c).map(r=>{let i=r?.toString()||"";return typeof r=="number"&&D.decimal_separator===","?i.replace(/\./,","):i}).join("");return{type:2,value:t}}}},Dr={Concatenate:"Concat"};var Ui={IsBlank:{description:"Returns true if the reference is blank",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:!c?.value||typeof c.value.value>"u"}))},IsNumber:{description:"Returns true if the reference is a number",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="number"}))},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="boolean"}))},IsText:{description:"Returns true if the reference is text",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&typeof c.value.value=="string"}))}};var ke=(c,e=!1)=>{let t=c.length,r=0,i=0;for(let n=0;n<t;n++)r+=c[n];r/=t;for(let n=0;n<t;n++){let a=c[n]-r;i+=a*a}return e?i/(t-1):i/t},Vi={"StDev.P":{description:"Returns the standard deviation of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:Math.sqrt(ke(P(c),!1))})},"StDev.S":{description:"Returns the standard deviation of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:Math.sqrt(ke(P(c),!0))})},"Var.P":{description:"Returns the variance of a set of values, corresponding to a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:ke(P(c),!1)})},"Var.S":{description:"Returns the variance of a set of values, corresponding to a sample of a population",arguments:[{name:"data"}],fn:(...c)=>({type:3,value:ke(P(c),!0)})},Covar:{description:"Returns the covariance between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(c,e)=>{if(!Array.isArray(c)||!Array.isArray(e))return E();if(!Array.isArray(c[0])||!Array.isArray(e[0]))return E();if(c.length!==e.length)return L();let t=0,r=0,i={x:0,y:0},n={x:[],y:[]};for(let a=0;a<c.length;a++){if(!c[a]||!e[a])continue;if(c[a].length!==e[a].length)return L();let s=c[a].length;r+=s;for(let o=0;o<s;o++)i.x+=c[a][o]||0,i.y+=e[a][o]||0,n.x.push(c[a][o]||0),n.y.push(e[a][o]||0)}if(r===0)return xe();i.x/=r,i.y/=r;for(let a=0;a<r;a++)t+=(n.x[a]-i.x)*(n.y[a]-i.y);return{type:3,value:t/r}}},Correl:{description:"Returns the correlation between two ranges of values",arguments:[{name:"A"},{name:"B"}],fn:(c,e)=>{if(!Array.isArray(c)||!Array.isArray(e))return E();if(!Array.isArray(c[0])||!Array.isArray(e[0]))return E();let t=0,r=0,i=0,n=0,a=0,s=0,o=0;for(let l=0;l<c.length;l++){if(!c[l]||!e[l])continue;let d=c[l].length;for(let h=0;h<d;h++){let u=Number(c[l][h]),m=Number(e[l][h]);isNaN(u)||isNaN(m)||(r+=u*m,i+=u,n+=m,a+=u*u,s+=m*m,o++)}}return t=o*r-i*n,t&&(t/=Math.sqrt((o*a-i*i)*(o*s-n*n))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=_e(c);let e=0,t={real:1,imaginary:0},r=!1,i=!1;for(let n of c)n.type===7?(r=!0,t=le(t,n.value),e++):n.type===3&&(n.value<0&&(i=!0),e++,t.real*=n.value,t.imaginary*=n.value);if(r){let n=ue(t,{real:1/e,imaginary:0});return n.imaginary?{type:7,value:n}:{type:3,value:n.real}}else return i?E():{type:3,value:Math.pow(t.real,1/e)}}},Average:{description:"Returns the arithmetic mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=_e(c);let e={real:0,imaginary:0},t=0;for(let r of c){if(r.type===6)return r;r.type===3&&(e.real+=r.value,t++),r.type===7&&(e.real+=r.value.real,e.imaginary+=r.value.imaginary,t++)}return e.real/=t,e.imaginary/=t,e.imaginary?{type:7,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:(c,e)=>{let t=P(c).filter(o=>typeof o=="number");t.sort((o,l)=>o-l);let r=t.length,i=Math.pow(10,8),n=Math.round((1+(r-1)*e)*i)/i,a=Math.floor(n),s=Math.ceil(n);return{type:3,value:(t[a-1]+t[s-1])/2}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...c)=>{let e=P(c).filter(a=>typeof a=="number");e.sort((a,s)=>a-s);let r=1+(e.length-1)*.5,i=Math.floor(r),n=Math.ceil(r);return{type:3,value:(e[i-1]+e[n-1])/2}}}},Nr={Mean:"Average",StDev:"StDev.S",Var:"Var.S"};var Fi={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0}],fn:G(c=>({type:4,value:c?.value&&fe(c.value.value)}))},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===3?{...c}:c.type===7?{type:3,value:c.value.real||0}:c.type===0||c.type===2&&c.value===""?{type:3,value:0}:E())},Imaginary:{description:"Returns the imaginary part of a complex number (as real)",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:c.value.imaginary||0}:c.type===3||c.type===0||c.type===2&&c.value===""?{type:3,value:0}:E())},Conjugate:{description:"Returns the conjugate of a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:7,value:{real:c.value.real,imaginary:-c.value.imaginary}}:c.type===3||c.type===0||!c.value?{type:3,value:c.value||0}:E())},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0}],fn:G(c=>c.type===7?{type:3,value:Math.atan2(c.value.imaginary,c.value.real)}:c.type===3||c.type===0||c.type===2&&c.value===""?{type:3,value:Math.atan2(0,c.value||0)}:E())},Rectangular:{description:"Converts a complex number in polar form to rectangular form",arguments:[{name:"r"},{name:"\u03B8 in radians"}],fn:(c=0,e=0)=>({type:7,value:{real:c*Math.cos(e),imaginary:c*Math.sin(e)}})},Complex:{description:"Ensures that the given value will be treated as a complex number",arguments:[{boxed:!0}],fn:G(c=>c.type===7?c:c.type===3||c.type===0||!c.value?{type:7,value:{imaginary:0,real:c.value||0}}:E())},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0}],fn:G(c=>{if(c.type===3){if(!c.value)return E();c={type:7,value:{real:c.value,imaginary:0}}}else if(c.type===0||c.type===2&&c.value==="")return E();if(c.type===7){let e=Pt(c.value),t={real:Math.log(e.r),imaginary:e.theta};return t.imaginary?{type:7,value:t}:{type:3,value:t.real}}return E()})}};var Zt=c=>{let e=[];c.type===8?e=c.value:e=[[c.value]];let t=e.length,r=t?e[0].length:0,i=[];if(!t||!r)return{m:t,n:r,array:i};for(let n=0;n<t;n++){let a=[];for(let s=0;s<r;s++){let o=e[n][s];if(o.type===7)a.push({...o.value});else if(o.type===3)a.push({real:o.value,imaginary:0});else if(o.type===0||o.value==="")a.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}i.push(a)}return{m:t,n:r,array:i}},Li={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=Zt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Gt(e);return t?ce(t):E()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=Zt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Gt(e);if(t&&t.real===0&&t?.imaginary===0)return E();let r=gi(e);return r?{type:8,value:r.map(i=>i.map(n=>ce(n)))}:E()}},MMult:{description:"Returns the dot product of A and B",arguments:[{name:"A",boxed:!0},{name:"B",boxed:!0}],fn:(c,e)=>{let t=Zt(c),r=Zt(e);if(!t.array||t.error||!r.array||r.error)return E();if(t.m!==r.n)return E();let i=bi(r,t);return{type:8,value:i.map(n=>n.map(a=>ce(a)))}}}};var Bt=class c extends Ae{static type="state-leaf-vertex";state_id=0;type=c.type;color=2;state_representation="";UpdateState(){let e=JSON.stringify(Array.from(this.edges_in).map(t=>t.result));e!==this.state_representation&&(this.state_representation=e,this.state_id++)}Calculate(e){if(this.dirty){for(let t of this.edges_in)if(t.dirty)return;this.UpdateState(),this.dirty=!1}}AddDependent(e){throw new Error("leaf vertex cannot have dependents")}};var Wt=class c extends Ae{static type="calculation-leaf-vertex";type=c.type;address={row:-1,column:-1};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(e){throw new Error("leaf vertex cannot have dependents")}};var na=c=>{if(typeof c=="string")switch(c=c.toUpperCase(),c){case"AVERAGE":case"MEAN":c=101;break;case"COUNT":c=102;break;case"COUNTA":c=103;break;case"MAX":c=104;break;case"MIN":c=105;break;case"PRODUCT":c=106;break;case"STDEV":c=107;break;case"STDEVP":c=108;break;case"SUM":c=109;break;case"VAR":c=110;break;case"VARP":c=111;break;default:c=0;break}return c},aa={complex_numbers:"off"},jt=class extends Lt{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Ht(this.library,this.parser),{...aa,...r}.complex_numbers==="on"){for(let n of Object.keys(Ir))Be[n]=Ir[n];wi()}this.UpdateLocale(),this.library.Register(Be,Ni,Vi,Di,Ui,Fi,Li);for(let n of Object.keys(Nr))this.library.Alias(n,Nr[n]);for(let n of Object.keys(Dr))this.library.Alias(n,Dr[n]);this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(n,...a)=>{if(n=na(n),n>100&&(n-=100),n<1||n>11)return L();let s=_e(a),o=[],l=0,d=0,h;for(let m of s){let f=m.value?.address;if(!f)return B();if(!h||h.id!==f.sheet_id){if(!f.sheet_id)return console.warn("invalid reference in metadata"),B();if(h=this.model.sheets.Find(f.sheet_id),!h)return console.warn("invalid sheet in metadata"),B()}if(!h.GetRowHeight(f.row))continue;let g=m.value?.value;typeof g>"u"||(l++,typeof g=="number"&&(d+=g,o.push(g)))}let u=0;switch(n){case 1:if(o.length===0)return he();u=d/o.length;break;case 2:u=o.length;break;case 3:u=l;break;case 4:if(o.length===0)return E();u=Math.max.apply(0,o);break;case 5:if(o.length===0)return E();u=Math.min.apply(0,o);break;case 6:if(o.length===0)return E();u=1;for(let m of o)u*=m;break;case 7:if(o.length<2)return he();u=Math.sqrt(ke(o,!0));break;case 8:if(o.length===0)return he();u=Math.sqrt(ke(o,!1));break;case 9:u=d;break;case 10:if(o.length<2)return he();u=ke(o,!0);break;case 11:if(o.length===0)return he();u=ke(o,!1);break}return{type:3,value:u}}},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(n,a)=>{let s=P(n);typeof a!="string"?a="="+(a||0).toString():(a=a.trim(),/^[=<>]/.test(a)||(a="="+a));let o=this.parser.Parse("{}"+a),l=o.expression;if(o.error||!l)return Ce();if(l.type!=="binary")return Ce();if(l.left.type!=="array")return Ce();l.left.values=[s];let d=this.CalculateExpression(l);if(d.type===8){let h=0;for(let u of d.value)for(let m of u)m.value&&h++;return{type:3,value:h}}return d}},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:1,volatile:!0,fn:((n,a=0,s=0,o,l)=>{if(!n)return L();if(n.type===8){let h=typeof o=="number"?a+o:void 0,u=typeof l=="number"?s+l:void 0;return{type:8,value:n.value.slice(a,h).map(f=>f.slice(s,u))}}if(!st(n))return console.info("e2",{reference:n}),B();let d=this.DynamicDependencies(n.value.address,this.expression_calculator.context.address,!0,a,s,l,o);if(!d)return console.info("e1",{check_result:d}),B();if(d.dirty){let h=this.GetVertex(this.expression_calculator.context.address,!0);return h.short_circuit=!0,{type:0,value:void 0}}if(d.area){let h={type:"address",...d.area.start,label:"",position:0,id:0},u={type:"address",...d.area.end,label:"",position:0,id:0},m=d.area.count===1?h:{type:"range",start:h,end:u,label:"",position:0,id:0};return{type:5,value:m}}return E()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:1,volatile:!0,fn:(n=>{if(!n||typeof n!="string")return L();let a=this.parser.Parse(n);if(a.error||!a.expression||a.expression.type!=="address"&&a.expression.type!=="range")return B();let s=this.DynamicDependencies(a.expression,this.expression_calculator.context.address);if(!s)return B();if(s.dirty){let o=this.GetVertex(this.expression_calculator.context.address,!0);return o.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:a.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(n,a,s=0)=>{if(s)return console.warn("inexact match not supported",{value:n,range:a,type:s}),xe();if(a.type===8){if(a.value.length===1){let o=a.value[0];for(let l=0;l<o.length;l++)if(n.type==o[l].type&&n.value===o[l].value)return{type:3,value:l+1}}else for(let o=0;o<a.value.length;o++){let l=a.value[o];if(l.length!==1)return xe();if(n.type==l[0].type&&n.value===l[0].value)return{type:3,value:o+1}}return xe()}else return n.type===a.type&&n.value===a.value?{type:3,value:1}:xe();return L()}},Index:{arguments:[{name:"range",boxed:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(n,a,s)=>{if(n&&n.type!==8&&(n={type:8,value:[[n]]}),a&&s){let o=n.value[s-1];if(o){let l=o[a-1];if(l)return l}}else if(a){let o=[];for(let l of n.value){if(!l[a-1])return L();o.push([l[a-1]])}return{type:8,value:o}}else if(s){let o=n.value[s-1];if(o)return{type:8,value:[o]}}return L()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:n=>{if(!n)return L();if(Array.isArray(n)){let a=n[0];return Array.isArray(a)?{type:3,value:a.length}:E()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:n=>n?Array.isArray(n)?{type:3,value:n.length}:{type:3,value:1}:L()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0}],fn:G(n=>{if(!st(n))return B();let a=this.model.sheets.Find(n.value?.address?.sheet_id||0);if(a){let s=a.cells.GetCell(n.value.address,!1);return{type:2,value:s?.value?.toString()||""}}return B()})},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",metadata:!0}],fn:G(n=>{let a=this.model.sheets.Find(n?.value?.address?.sheet_id||0);if(a){let s=a.cells.GetCell(n.value.address,!1);return{type:4,value:s?.type===1}}return{type:4,value:!1}})}})}get parser(){return this.model.parser}library=new $t;registered_libraries={};expression_calculator;full_rebuild_required=!1;ExportCalculatedValues(){let t={};for(let r of this.model.sheets.list){let i=r.cells.toJSON({calculated_value:!0}).data;t[r.id]=i.filter(n=>n.calculated!==void 0)}return t}ApplyCalculatedValues(t){for(let r of this.model.sheets.list){let i=t[r.id];if(!i)console.info("mismatch",r.id);else for(let n of i)r.cells.data[n.row][n.column].SetCalculatedValue(n.calculated)}}SpreadCallback(t,r){if(!t.address||!t.address.sheet_id)throw new Error("spread callback called without sheet id");let i=this.model.sheets.Find(t.address.sheet_id)?.cells;if(!i)throw new Error("spread callback called without cells");if(!t||!t.reference)return;let n=t.reference.area;if(n){let a=n.rows,s=n.columns;if(r.type===8){let o=Ot(r.value);for(let l=0;l<a;l++)if(o[l]){let d=0;for(;d<s&&d<o[l].length;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(o[l][d].value,o[l][d].type);for(;d<s;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let d=0;d<s;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let o=0;o<a;o++)for(let l=0;l<s;l++)i.data[o+n.start.row][l+n.start.column].SetCalculatedValue(r.value,r.type)}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:Vt()}:this.expression_calculator.Calculate(t.expression,t.address)}DynamicDependencies(t,r,i=!1,n=0,a=0,s=1,o=1){let l=this.ResolveExpressionAddress(t,r);if(!l)return;let d=!1,h;if(t.type==="address"||t.type==="range"){let m=t.type==="range"?t.start:t;m.sheet_id?h=this.model.sheets.Find(m.sheet_id):m.sheet&&(h=this.model.sheets.Find(m.sheet))}if(!h&&r?.sheet_id&&(h=this.model.sheets.Find(r.sheet_id)),!h)throw new Error("missing sheet in dynamic dependencies [b21]");l=h.RealArea(l);let u=l.start.sheet_id;i&&(l=new y({column:l.start.column+a,row:l.start.row+n,sheet_id:l.start.sheet_id},{column:l.start.column+a+s-1,row:l.start.row+n+o-1,sheet_id:l.end.sheet_id}));for(let m=l.start.row;m<=l.end.row;m++)for(let f=l.start.column;f<=l.end.column;f++){let p=this.GetVertex({row:m,column:f,sheet_id:u},!1);p&&p.dirty&&(this.AddEdge({row:m,column:f,sheet_id:u},this.expression_calculator.context.address),d=!0)}return{dirty:d,area:l}}UpdateLocale(){D.decimal_separator===","?(this.parser.decimal_mark=",",this.parser.argument_separator=";"):(this.parser.decimal_mark=".",this.parser.argument_separator=",")}SupportedFunctions(){let t=this.library.List(),r=Object.keys(t).map(i=>{let n=t[i].canonical_name;return n||(n=i.replace(/_/g,".")),{name:n,description:t[i].description,arguments:(t[i].arguments||[]).map(a=>({name:a.name||""}))}});for(let i of this.model.macro_functions.values())r.push({name:i.name,description:i.description,arguments:(i.argument_names||[]).map(n=>({name:n}))});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 i=t[r],n=i.fn;i.fn=(...a)=>n.apply({address:{...this.expression_calculator.context.address}},a),this.library.Register({[r]:i})}}AttachModel(){this.expression_calculator.SetModel(this.model)}Calculate(t){if(this.AttachModel(),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.full_rebuild_required=!1),this.RebuildGraph(t);try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.AttachModel(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let i of Object.keys(r)){let n=r[i];n.xlfn?t[i]="_xlfn":n.extension&&(t[i]="_xll")}return t}Evaluate(t,r,i={},n=!1){let a=this.parser.argument_separator,s=this.parser.flags.r1c1;i.argument_separator&&(i.argument_separator===","?(this.parser.argument_separator=",",this.parser.decimal_mark="."):(this.parser.argument_separator=";",this.parser.decimal_mark=",")),i.r1c1&&(this.parser.flags.r1c1=i.r1c1);let o=this.parser.Parse(t);if(this.parser.argument_separator=a,this.parser.decimal_mark=a===","?".":",",this.parser.flags.r1c1=s,o&&o.expression){this.parser.Walk(o.expression,d=>{if(d.type==="address"||d.type==="range"){if(d.type==="address"){if(d.offset_column||d.offset_row)throw new Error("Evaluate does not support offset references")}else if(d.start.offset_column||d.start.offset_row||d.end.offset_column||d.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(d,void 0,r)}return!0});let l=this.CalculateExpression(o.expression);return n?l:l.type===8?l.value.map(d=>d.map(h=>h.value)):l.value}throw o.error?new Error(o.error):new Error("invalid expression")}CalculateExpression(t,r={row:-1,column:-1},i=!1){return this.expression_calculator.Calculate(t,r,i).value}RebuildClean(t=!1){this.full_rebuild_required=!1,this.AttachModel(),this.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},i=[];for(let n of t){let a={column:n.column,row:n.row,sheet_id:n.sheet_id},s=y.CellAddressToLabel(a,!0);r[s]||(r[s]=s,i.push(a))}return i}Unresolve(t,r,i=!0,n=!0){let a="",s=N(t)?new y(t):new y(t.start,t.end);if(n){let d=this.model.named_ranges.MatchSelection(s);if(d)return d}if(s.count>1?a=y.CellAddressToLabel(s.start)+":"+y.CellAddressToLabel(s.end):a=y.CellAddressToLabel(s.start),!i)return a;let o=s.start.sheet_id||r?.id,l=this.ResolveSheetName(o,!0);return l?l+"!"+a:a}ResolveSheetName(t,r=!1){let i=this.model.sheets.Find(t);if(i)return r&&ze.test(i.name)?`'${i.name}'`:i.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}UpdateConditionals(t,r){if(!t){for(let i of this.model.sheets.list)i.conditional_formats?.length&&this.UpdateConditionals(i.conditional_formats,i);return}if(!r)throw new Error("invalid call to update conditionals without context");t&&!Array.isArray(t)&&(t=[t]);for(let i of t){let n="";switch(i.type){case"cell-match":n=this.Unresolve(i.area,r,!0,!1)+" "+i.expression;break;case"expression":n=i.expression;break;case"duplicate-values":n=`UniqueValues(${this.Unresolve(i.area,r,!0,!1)})`,i.unique||(n=`NOT(${n})`);break;case"gradient":n=`=Gradient(${[this.Unresolve(i.area,r,!0,!1),i.min??"",i.max??""].join(this.parser.argument_separator)})`;break;default:continue}if(!n)continue;if(i.internal||(i.internal={}),!i.internal.vertex){i.internal.vertex=new Wt;let s;i.type!=="gradient"&&i.type!=="duplicate-values"&&(s=i.options);let o=this.Evaluate(n,r,s,!0);i.internal.vertex.result=o,i.internal.vertex.updated=!0}let a=i.internal.vertex;this.AddLeafVertex(a),this.UpdateLeafVertex(a,n,r)}}RemoveAnnotation(t){let r=t.temp.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}UpdateAnnotations(t,r){if(!t){for(let i of this.model.sheets.list)this.UpdateAnnotations(i.annotations,i);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 i of t)if(i.data.formula){i.temp.vertex||(i.temp.vertex=new Bt);let n=i.temp.vertex;this.AddLeafVertex(n),this.UpdateLeafVertex(n,i.data.formula,r)}}ResolveExpressionAddress(t,r){switch(t.type){case"address":if(this.model.ResolveSheetID(t,r))return new y(t);break;case"range":if(this.model.ResolveSheetID(t,r))return new y(t.start,t.end);break;case"identifier":{let i=this.model.named_ranges.Get(t.name.toUpperCase());if(i)return new y(i.start,i.end)}break}}NamedRangeToAddressUnit(t){let r=t.name.toUpperCase(),i=this.model.named_ranges.Get(r);if(i)return i.count===1?this.ConstructAddressUnit(i.start,r,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(i.start,r,t.id,t.position),end:this.ConstructAddressUnit(i.end,r,t.id,t.position),label:r,id:t.id,position:t.position}}ConstructAddressUnit(t,r,i,n){return{type:"address",row:t.row,column:t.column,sheet_id:t.sheet_id,label:r,id:i,position:n}}RebuildDependencies(t,r,i,n={addresses:{},ranges:{}},a){if(!i){let s=this.model.sheets.Find(r);s&&(i=s.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let s=t.name.toUpperCase();if(this.model.named_expressions.has(s)){let o=this.model.named_expressions.get(s);o&&this.RebuildDependencies(o,r,i,n,a)}else{let o=this.NamedRangeToAddressUnit(t);o&&(o.type==="address"?n.addresses[o.label]=o:n.ranges[o.label]=o)}}break;case"structured-reference":{let s=this.model.ResolveStructuredReference(t,a);s&&(s.type==="address"?n.addresses[s.sheet_id+"!"+s.label]=s:n.ranges[s.label]=s);let o=this.model.tables.get(t.table.toLowerCase());if(o){let l=a.row;if(l<o.area.start.row||l>o.area.end.row)break;let d=t.column.toLowerCase(),h=-1;if(o.columns){for(let u=0;u<o.columns.length;u++)if(d===o.columns[u]){h=o.area.start.column+u;break}}if(h>=0){let u={label:t.label,type:"address",row:l,column:h,sheet_id:o.area.start.sheet_id,id:t.id,position:t.position};n.addresses[u.sheet_id+"!"+u.label]=u}}}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=i;t.sheet_id?n.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=i;t.start.sheet_id?n.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,i,n,a);break;case"binary":this.RebuildDependencies(t.left,r,i,n,a),this.RebuildDependencies(t.right,r,i,n,a);break;case"group":t.elements.forEach(s=>this.RebuildDependencies(s,r,i,n,a));break;case"call":{let s=t.args.slice(0),o=this.library.Get(t.name);o&&o.arguments&&o.arguments.forEach((l,d)=>{l&&l.address&&(this.RebuildDependencies(s[d],r,i,void 0,a),s[d]={type:"missing",id:-1})}),s.forEach(l=>this.RebuildDependencies(l,r,i,n,a))}break}return n}UpdateLeafVertex(t,r,i){t.Reset();let n=this.parser.Parse(r);if(n.expression){let a=this.RebuildDependencies(n.expression,i.id,i.name,void 0,{row:0,column:0});for(let s of Object.keys(a.ranges)){let o=a.ranges[s];new y(o.start,o.end).Iterate(d=>{this.AddLeafVertexEdge(d,t)})}for(let s of Object.keys(a.addresses)){let o=a.addresses[s];this.AddLeafVertexEdge(o,t)}}t.expression=n.expression||{type:"missing",id:-1},t.expression_error=!n.valid}RebuildGraphCell(t,r){if(t.area&&t.area.start.column===r.column&&t.area.start.row===r.row){let{start:i,end:n}=t.area,a=i.sheet_id||r.sheet_id;i.sheet_id||(i.sheet_id=a);for(let s=i.column;s<=n.column;s++)for(let o=i.row;o<=n.row;o++)this.ResetInbound({column:s,row:o,sheet_id:a},!0,!1);this.SetDirty(r);for(let s=i.column;s<=n.column;s++)for(let o=i.row;o<=n.row;o++)o===i.row&&s===i.column||this.AddEdge(i,{...i,row:o,column:s})}if(t.type===1){this.ResetInbound(r,!0);let i=this.parser.Parse(t.value);if(i.expression){if(i.expression.type==="call"){let s=this.library.Get(i.expression.name);s&&(s.render||s.click)&&(t.render_function=s.render,t.click_function=s.click)}let a=this.RebuildDependencies(i.expression,r.sheet_id,"",void 0,r);for(let s of Object.keys(a.ranges)){let o=a.ranges[s],l=new y(o.start,o.end);l.entire_row||l.entire_column?this.AddArrayEdge(l,r):l.Iterate(d=>this.AddEdge(d,r))}for(let s of Object.keys(a.addresses)){let o=a.addresses[s];this.AddEdge(o,r)}}let n=this.GetVertex(r,!0);n&&(n.expression=i.expression||{type:"missing",id:-1},n.expression_error=!i.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 i=t.start.row;i<=t.end.row;i++){let n=r.data[i];if(n)for(let a=t.start.column;a<=t.end.column;a++){let s=n[a];s&&this.RebuildGraphCell(s,{row:i,column:a,sheet_id:t.start.sheet_id})}}}else for(let r of this.model.sheets.list||[]){let i=r.cells.data.length;for(let n=0;n<i;n++){let a=r.cells.data[n];if(a){let s=a.length;for(let o=0;o<s;o++){let l=a[o];l&&this.RebuildGraphCell(l,{row:n,column:o,sheet_id:r.id})}}}}}IsNativeOrTypedArray(t){return Array.isArray(t)||t instanceof Float64Array||t instanceof Float32Array}CheckVolatile(t){if(!t.expression||t.expression_error)return!1;let r=!1;return this.parser.Walk(t.expression,i=>{if(i.type==="call"){let n=this.library.Get(i.name);n&&n.volatile&&(r=!0)}return!r}),r}};var Yt=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 i of Array.from(r)){let n=i.dataset.bind;n&&(this.model[n]=i)}}if(this.model.about){let r=["<div>TREB version 28.3.4"];r.push("<small><a target=_blank href='https://treb.app'>http://treb.app</a></small>"),this.model.about.innerHTML=r.join(`
|
|
11
|
+
`)}this.model.close?.addEventListener("click",r=>{r.stopPropagation(),r.preventDefault(),this.HideDialog()})}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 Jt=class{constructor(e){this.container=e;let t=F.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 Pi={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"};var Te=class{constructor(e=0,t=0,r=100,i=100){this.left=e;this.top=t;this.right=r;this.bottom=i}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 ca="http://www.w3.org/2000/svg",T=(c,e={},t)=>{let r=document.createElementNS(ca,c);for(let i of Object.keys(e))if(e[i]!==void 0){let n=e[i];r.setAttribute(i,Array.isArray(n)?n.join(" "):n.toString())}return t&&(r.textContent=t),r},Xt=class{parent;svg_node;text_measurement_node;container_group;group;axis_group;label_group;size={width:0,height:0};bounds=new Te;constructor(){this.container_group=T("g"),this.group=T("g"),this.axis_group=T("g",{class:"axis-group"}),this.label_group=T("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=T("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=T("g");this.group.appendChild(t);let r=T("text");t.appendChild(r),t.setAttribute("class","legend");let i=[[]],n=10,a=e.area.width,s=0,o=0,l=e.area.width,d=e.style===1?14:26,h=e.labels.map((g,b)=>{r.textContent=g.label;let v=r.getBoundingClientRect(),_={width:v.width,height:v.height},w=_.width+d+n;return o=Math.max(o,_.height),e.layout===1?i[b]=[b]:w>a?i[s].length===0?(i[s].push(b),s++,i[s]=[],a=l):(s++,i[s]=[b],a=l-w):(i[s].push(b),a-=w),_});t.removeChild(r);let u=o,m=e.layout||0;m===0&&i.every(g=>g.length<=1)&&(m=0);for(let g=0;g<i.length;g++){let b=i[g].reduce((w,x)=>w+h[x].width+d,(i[g].length-1)*n),v=0,_=m===0?Math.round((l-b)/2):Math.round(n/2);for(let w=0;w<i[g].length;w++){let x=i[g][w],A=h[x],k=e.labels[x],S=u-1,M=!1;typeof navigator<"u"&&(M=/trident/i.test(navigator?.userAgent||""));let V=typeof k.index=="number"?k.index:x+1;t.appendChild(T("text",{"dominant-baseline":"middle",x:_+d,y:u,dy:M?".3em":void 0},k.label)),e.style===1?t.appendChild(T("rect",{class:`series-${V}`,x:_,y:S-4,width:8,height:8})):t.appendChild(T("rect",{class:`series-${V}`,x:_,y:S-1,width:d-3,height:2})),v=Math.max(v,A.height),_+=A.width+d+n}u=Math.round(u+v*1.1)}let f=t.getBoundingClientRect(),p={width:f.width,height:f.height+o};switch(e.position){case 1:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.bottom-p.height})`);break;case 2:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`);break;case 3:t.setAttribute("transform",`translate(${e.area.right-p.width}, ${e.area.top})`);break;case 0:default:t.setAttribute("transform",`translate(${e.area.left}, ${e.area.top})`)}e.position===0?e.area.top+=p.height||0:e.position===3?e.area.right-=(p.width||0)+8:e.position===2?e.area.left+=(p.width||0)+8:e.area.bottom-=p.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.parent.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,i){let n=T("text",{class:"chart-title",x:Math.round(t.width/2)},e);n.style.textAnchor="middle",this.group.appendChild(n);let a=n.getBoundingClientRect();switch(i){case"bottom":n.setAttribute("y",Math.round(t.bottom-a.height).toString()),t.bottom-=a.height+r;break;default:n.setAttribute("y",Math.round(t.top+r+a.height).toString()),t.top+=a.height+r;break}}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=T("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 i=this.text_measurement_node.getBoundingClientRect(),n={width:i.width,height:i.height,y_offset:i.height-(this.bounds.top-i.top-100)};return r&&(n.width=Math.ceil(n.width),n.height=Math.ceil(n.height),n.y_offset=Math.ceil(n.y_offset)),n}RenderTicks(e,t,r,i,n){let a=[],s=e.width/i;for(let o=0;o<i;o++){let l=Math.round(e.left+s/2+s*o)-.5;a.push(`M${l} ${t} L${l} ${r}`)}this.group.appendChild(T("path",{d:a,class:n}))}RenderXAxisBar(e,t,r,i,n){let a=r.length;if(!a)return;let s=4,o=t?e.width/a:e.width/(a-1),l=t?o/2:0,d=1,h=!0;for(;h;){h=!1;let u=0;for(let m=0;m<a;m+=d){let f=Math.round(e.left+l+o*m),p=f-i[m].width/2;if(u&&p<=u){d++,h=!0;break}u=f+i[m].width/2+s}}for(let u=0;u<a;u+=d){let m=Math.round(e.left+l+o*u);this.RenderText(this.axis_group,r[u],"center",{x:m,y:e.bottom},n)}}RenderXAxisTicks(e,t,r){let i=t?e.width/r:e.width/(r-1),n=t?i/2:0,a=[];for(let s=0;s<r;s++){let o=Math.round(e.left+n+i*s)+.5;a.push(`M${o},${e.bottom+.5} v6`)}this.axis_group.appendChild(T("path",{d:a.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,i,n){let a=r.length;if(!a)return;let s=4,o=t?e.width/a:e.width/(a-1),l=t?o/2:0,d=1,h=!0,u=(r.length-1)%2===0,m=(r.length-1)%3===0;for(;h;){h=!1;let f=0;for(let p=0;p<a;p+=d){let g=Math.round(e.left+l+o*p),b=g-i[p].width/2;if(f&&b<=f){d++,h=!0;break}f=g+i[p].width/2+s}}d===3&&!m&&u&&d++;for(let f=0;f<a;f+=d){let p=Math.round(e.left+l+o*f);this.RenderText(this.axis_group,r[f],"center",{x:p,y:e.bottom},n)}}RenderYAxisBar(e,t,r,i){r=r.slice(0),r.reverse();let n=r.length;if(!n)return;let a=e.height/n,s=1,o=!0;for(;o;){o=!1;let l=0;for(let d=0;d<n;d+=s){let h=r[d],u=Math.round(e.bottom-a*(d+.5)+h.metrics.height/4);if(l&&u>=l){s++,o=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=s){let d=r[l],h=Math.round(e.bottom-a*(l+.5)+d.metrics.height/4);this.RenderText(this.axis_group,d.label,"right",{x:t,y:h},i)}}RenderYAxis(e,t,r,i){let n=r.length;if(!n)return;let a=e.height/(n-1),s=1,o=!0;for(;o;){o=!1;let l=0;for(let d=0;d<n;d+=s){let h=r[d],u=Math.round(e.bottom-a*d+h.metrics.height/4);if(l&&u>=l){s++,o=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=s){let d=r[l],h=Math.round(e.bottom-a*l+d.metrics.height/4);this.RenderText(this.axis_group,d.label,"right",{x:t,y:h},i)}}LineProperties(e,t){let r=t.x-e.x,i=t.y-e.y;return{length:Math.sqrt(r*r+i*i),angle:Math.atan2(i,r)}}RenderSmoothLine(e,t,r=!1,i,n){let a=T("g"),s=[],o=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=t.map((g,b)=>{if(!(typeof g>"u"))return{x:Math.round(e.left+e.width/d*b),y:e.bottom-g}}),f=[],p=()=>{if(f.length<2)return;let g="",b=f[0],v=f[f.length-1];f.length===2?g=`${f[0].x},${f[0].y} L${f[1].x},${f[1].y}`:f.length>2&&(g=""+this.CatmullRomChain(f).map(w=>`${w.x},${w.y}`).join(" L")),g&&(s.push("M"+g),r&&(o.push(`M ${b.x},${e.bottom} L ${b.x},${b.y}`),o.push("L"+g),o.push(`L ${v.x},${e.bottom}`)))};for(let g of m)g?f.push(g):(p(),f=[]);if(f.length&&p(),r&&a.appendChild(T("path",{class:"fill",d:o})),a.appendChild(T("path",{class:"line",d:s})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),a.setAttribute("class",n.join(" "))),this.group.appendChild(a),i&&u.length){let g=T("g");for(let b of u){let v=T("circle",{cx:b.x,cy:b.y,r:h});v.addEventListener("mouseenter",_=>{this.parent.setAttribute("title",i[b.i]||"")}),v.addEventListener("mouseleave",_=>{this.parent.setAttribute("title","")}),g.appendChild(v)}g.setAttribute("class","mouse-layer"),this.group.appendChild(g)}}RenderLine(e,t,r=!1,i,n){let a=T("g"),s=[],o=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=0,f=!0,p;for(;m<l;m++){let g=t[m];if(typeof g>"u"){f=!0,r&&typeof p<"u"&&o.push(`L${p} ${e.bottom}Z`),p=void 0;continue}let b=Math.round(+e.left+e.width/d*m);f?(r&&o.push(`M${b} ${e.bottom} L${b} ${e.bottom-g}`),s.push(`M${b} ${e.bottom-g}`)):(s.push(`L${b} ${e.bottom-g}`),o.push(`L${b} ${e.bottom-g}`)),u.push({x:b,y:e.bottom-g,i:m}),p=b,f=!1}if(r&&typeof p<"u"&&o.push(`L${p} ${e.bottom}Z`),r&&a.appendChild(T("path",{class:"fill",d:o})),a.appendChild(T("path",{class:"line",d:s})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),a.setAttribute("class",n.join(" "))),this.group.appendChild(a),i&&u.length){let g=T("g");for(let b of u){let v=T("circle",{cx:b.x,cy:b.y,r:h});v.addEventListener("mouseenter",_=>{this.parent.setAttribute("title",i[b.i]||"")}),v.addEventListener("mouseleave",_=>{this.parent.setAttribute("title","")}),g.appendChild(v)}g.setAttribute("class","mouse-layer"),this.group.appendChild(g)}}RenderBarGrid(e,t,r){let i=[],n=e.width/t;for(let a=0;a<=t;a++){let s=Math.round(e.left+n*a)-.5;i.push(`M${s} ${e.top} L${s} ${e.bottom}`)}this.group.appendChild(T("path",{d:i,class:r}))}RenderGrid(e,t,r=0,i){let n=[],a=e.height/t;for(let s=0;s<=t;s++){let o=Math.round(e.top+a*s)-.5;n.push(`M${e.left} ${o} L${e.right} ${o}`)}a=e.width/(r-1);for(let s=0;s<r;s++){let o=Math.round(e.left+a*s)-.5;n.push(`M${o} ${e.top} L${o} ${e.bottom}`)}this.group.appendChild(T("path",{d:n,class:i}))}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 i=(h,u,m)=>{let{x:f,y:p}=u,{x:g,y:b}=m;return((g-f)**2+(b-p)**2)**r+h},n=0,a=i(n,e[0],e[1]),s=i(a,e[1],e[2]),o=i(s,e[2],e[3]),l=(s-a)/t,d=[];for(let h=0;h<t;h++){let u=a+l*h,m=this.AddPoints(this.MultiplyPoint(e[0],(a-u)/(a-n)),this.MultiplyPoint(e[1],(u-n)/(a-n))),f=this.AddPoints(this.MultiplyPoint(e[1],(s-u)/(s-a)),this.MultiplyPoint(e[2],(u-a)/(s-a))),p=this.AddPoints(this.MultiplyPoint(e[2],(o-u)/(o-s)),this.MultiplyPoint(e[3],(u-s)/(o-s))),g=this.AddPoints(this.MultiplyPoint(m,(s-u)/(s-n)),this.MultiplyPoint(f,(u-n)/(s-n))),b=this.AddPoints(this.MultiplyPoint(f,(o-u)/(o-a)),this.MultiplyPoint(p,(u-a)/(o-a))),v=this.AddPoints(this.MultiplyPoint(g,(s-u)/(s-a)),this.MultiplyPoint(b,(u-a)/(s-a)));d.push(v)}return d}CatmullRomChain(e,t=30){let r=e.slice(0),i=[],n=r.length;if(n){let a=r[n-1].x-r[n-2].x,s=r[n-1].y-r[n-2].y;r.push({x:r[n-1].x+a,y:r[n-1].y+s}),r.push({x:r[n-1].x+a,y:r[n-1].y+s}),a=r[1].x-r[0].x,s=r[1].y-r[0].y,r.unshift({x:r[0].x-a,y:r[0].y-s});for(let o=0;o<r.length-4;o++){let l=r.slice(o,o+4),d=this.CatmullRomSpline(l,t);i.push(...d)}}return i}RenderDataLabels(e,t,r,i,n,a,s){let o=Math.max(t.length,r.length),l=i.max-i.min||1,d=n.max-n.min||1;for(let h=0;h<o;h++){let u=t[h],m=r[h];if(u!==void 0&&m!==void 0){let f={x:e.left+(u-i.min)/l*e.width,y:e.bottom-(m-n.min)/d*e.height},p=a[h];if(p){this.label_group.appendChild(T("circle",{class:"label-target",cx:f.x,cy:f.y,r:10}));let g=T("g",{class:"data-label",transform:`translate(${f.x+10},${f.y})`});this.label_group.appendChild(g);let b=T("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${s}`});g.appendChild(b);let v=T("text",{x:4,y:0},p);g.appendChild(v);let _=v.getBoundingClientRect(),w=_.height,x=_.width+8;x+15+f.x>=e.right&&(g.setAttribute("transform",`translate(${f.x-x-15},${f.y})`),b.setAttribute("cx",(x+15).toString()));let A=T("path",{d:`M0,5 h${x} v-${w} h-${x} Z`});g.insertBefore(A,v)}}}}RenderScatterSeries(e,t,r,i,n,a=!0,s=!1,o=!1,l=!1,d=!1,h){let u=Math.max(t.length,r.length),m=i.max-i.min||1,f=n.max-n.min||1,p=[],g=[],b=[],v=T("g",{class:h});this.group.appendChild(v);for(let _=0;_<u;_++){let w=t[_],x=r[_];typeof w>"u"||typeof x>"u"?p.push(void 0):p.push({x:e.left+(w-i.min)/m*e.width,y:e.bottom-(x-n.min)/f*e.height})}if(a){let _=[],w=d?()=>_.length===2?`${_[0].x},${_[0].y} L${_[1].x},${_[1].y}`:_.length>2?this.CatmullRomChain(_).map(A=>`${A.x},${A.y}`).join(" L"):"":()=>_.map(x=>`${x.x},${x.y}`).join(" L");for(let x of p)if(x)_.push(x);else{if(_.length>=2){let A=w();g.push("M"+A),b.push(`M${_[0].x},${e.bottom}L`+A+`L${_[_.length-1].x},${e.bottom}Z`)}_=[]}if(_.length>=2){let x=w();g.push("M"+x),b.push(`M${_[0].x},${e.bottom}L`+x+`L${_[_.length-1].x},${e.bottom}Z`)}}if(o&&v.appendChild(T("path",{d:b,class:"fill"})),a&&v.appendChild(T("path",{d:g,class:"line"})),s)for(let _ of p)_&&v.appendChild(T("circle",{cx:_.x,cy:_.y,r:1,class:"point"}));if(l)for(let _ of p)_&&v.appendChild(T("circle",{cx:_.x,cy:_.y,r:3,class:"marker"}))}RenderPoints(e,t,r,i){let n=[];for(let a=0;a<t.length;a++){let s=t[a]*e.width+e.left,o=e.bottom-r[a]*e.height;n.push(`M${s-1},${o-1} L${s+1},${o+1}`),n.push(`M${s-1},${o+1} L${s+1},${o-1}`)}this.group.appendChild(T("path",{d:n,class:i}))}RenderPoint(e,t,r){this.group.appendChild(T("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=T("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(T("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,i,n,a){let s="";if(t)if(t[0]&&t[0]===t[1]&&t[0]>=e.height){let l=t[0],d=t[0]-e.height,h=Math.sqrt(l*l-d*d);s=`M${e.left+e.width/2-h},${e.bottom} a${l},${l} 0 0 1 ${h*2},0 z`}else if(t[1]&&t[1]===t[2]&&t[1]>=e.width){let l=t[1],d=t[1]-e.width,h=Math.sqrt(l*l-d*d);s=`M${e.left},${e.top+e.height/2-h} a${l},${l} 0 0 1 0,${h*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 o=T("path",{d:s,class:r});if(i&&(o.addEventListener("mouseenter",l=>{this.parent.setAttribute("title",i)}),o.addEventListener("mouseleave",l=>{this.parent.setAttribute("title","")})),this.group.appendChild(o),n){this.label_group.appendChild(T("path",{class:"label-target",d:s}));let l=a||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},d=T("g",{class:"data-label",transform:`translate(${l.x},${l.y})`});this.label_group.appendChild(d);let h=T("text",{x:0,y:0},n);d.appendChild(h);let u=h.getBoundingClientRect(),m=u.height,f=u.width+8;l.y-u.height<4&&(l.y-=l.y-u.height-4,d.setAttribute("transform",`translate(${l.x},${l.y})`)),h.setAttribute("x",Math.floor(-u.width/2).toString());let p=Math.ceil(m*.125),g=T("rect",{rx:3,x:-f/2,y:Math.round(-m+p*2/3),width:f,height:m+p});d.insertBefore(g,h)}}RenderText(e,t,r,i,n){let a=T("text",{x:i.x,y:i.y,class:n},t);switch(r){case"right":a.style.textAnchor="end";break;case"center":a.style.textAnchor="middle";break;default:a.style.textAnchor="start";break}(e||this.group).appendChild(a)}RenderDonut(e,t,r,i,n,a,s){let o=-Math.PI/2,l=0;a&&(r*=.8,i*=.7);let d=(h,u,m)=>[Math.cos(m)*u+h.x,Math.sin(m)*u+h.y];for(let h of e){let u=h.title||"",m=h.percent,f=h.index,p=[],g=0,b=d.bind(0,t,r),v=d.bind(0,t,i);if(m>.5){g=o+m/2*Math.PI*2,l=o+m*Math.PI*2;let x=g-o,A=l-g;p.push(`M${b(o)}`,`A${r},${r},${x},0,1,${b(g)}`,`A${r},${r},${A},0,1,${b(l)}`,`L${v(l)}`,`A${i},${i},${A},0,0,${v(g)}`,`A${i},${i},${x},0,0,${v(o)}`,"Z")}else{l=o+m*Math.PI*2,g=(l-o)/2+o;let x=l-o;p.push(`M${b(o)}`,`A${r},${r},${x},0,1,${b(l)}`,`L${v(l)}`,`A${i},${i},${x},0,0,${v(o)}`,"Z")}let _=T("path",{d:p,class:typeof f>"u"?void 0:`series-${f}`});typeof f<"u"&&_.setAttribute("data-index",f.toString());let w=T("g",{class:s});if(w.appendChild(_),this.group.appendChild(w),m>=.05&&u){let x=r-i;p=[];let A=d(t,i+(r-i)/2+x,g);p.push(`M${d(t,i+(r-i)/2,g)}`),p.push(`L${A}`),w.appendChild(T("path",{d:p,class:"callout"}));let k=[],S=T("text",{class:"callout-label"});w.appendChild(S);let M=g+Math.PI/2,V=u;S.textContent=V;let W=S.getBoundingClientRect(),me={width:W.width,height:W.height},[ie,C]=A;ie+=me.height/2*Math.cos(g),C+=me.height/4+me.height/2*Math.sin(g);let K=!1;M>Math.PI?ie-me.width<=n.left&&(K=!0):ie+me.width>n.right&&(K=!0);let ne=/[\s-]/;if(K&&ne.test(V)){let J=-1,X=1,q=[];for(let z=0;z<V.length;z++)if(ne.test(V[z])){let Z=Math.abs(.5-z/V.length);Z<X&&(X=Z,J=z)}J>0&&(k.push(V.substr(0,J+1).trim()),k.push(V.substr(J+1).trim()))}if(k.length){let J=0,X=0,q=k.map(z=>{S.textContent=z,W=S.getBoundingClientRect();let Z={width:W.width,height:W.height};return X=Math.max(X,Z.width),{text:z,metrics:Z}});S.textContent="";for(let z of q){let Z=T("tspan");Z.textContent=z.text;let $i=M>Math.PI?ie-(X-z.metrics.width)/2:ie+(X-z.metrics.width)/2;Z.setAttribute("x",$i.toString()),Z.setAttribute("dy",J.toString()),S.appendChild(Z),J=z.metrics.height}}let ae=M>Math.PI?"end":"start";S.setAttribute("text-anchor",ae),S.setAttribute("x",ie.toString()),S.setAttribute("y",C.toString()),typeof f<"u"&&S.setAttribute("data-index",f.toString())}o=l}}};var O=class{static Scale(e,t,r=6.5,i,n){return Br(e,t,r,i,n)}static Range(e){let t,r;for(let n of e)typeof n>"u"||((typeof t>"u"||t>n)&&(t=n),(typeof r>"u"||r<n)&&(r=n));let i=typeof t>"u"||typeof r>"u"?0:r-t;return{min:t,max:r,range:i}}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 Ur="#,##0.00",ct=class{constructor(e=new Xt){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};margin={top:.025,left:.05,bottom:.025,right:.075};Initialize(e){this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.CreateColumnChart(r,"column");break;case"bar.chart":this.CreateColumnChart(r,"bar");break;case"line.chart":this.CreateLineChart(r,"line");break;case"area.chart":this.CreateLineChart(r,"area");break;case"donut.chart":case"pie.chart":this.CreateDonut(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.CreateScatterChart(r,"plot");break;case"scatter.line":this.CreateScatterChart(r,"line");break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}CreateColumnChart(e,t){let r=this.TransformSeriesData(e[0]),i=this.CommonData(r),n;if(e[1]){n=(e[1].type===8?O.Flatten(e[1].value):O.Flatten(e[1])).map(d=>d?d.type===5&&d.value.type==="metadata"?typeof d.value.value=="number"?I.Get(d.value.format||Ur).Format(d.value.value):d.value.value:typeof d.value=="number"?I.Get(d.format||Ur).Format(d.value):d.value:"");let l=r.reduce((d,h)=>Math.max(d,h.y.data.length),0);for(l<n.length&&(n=n.slice(0,l));l>n.length;)n.push("")}let a=e[2]?.toString()||void 0,s=e[3]?.toString()||void 0;if(this.chart_data={type:t,legend:i.legend,legend_style:1,series2:r,scale:i.y.scale,title:a,y_labels:t==="bar"?n:i.y.labels,x_labels:t==="bar"?i.y.labels:n},s){this.chart_data.round=/round/i.test(s),this.chart_data.data_labels=/labels/i.test(s);let o=s.match(/labels="(.*?)"/);o&&r?this.ApplyLabels(r,o[1],n):(o=s.match(/labels=([^\s\r\n,]+)(?:\W|$)/),o&&r&&this.ApplyLabels(r,o[1],n)),o=s.match(/class=([\w_-]+)(?:\W|$)/),o&&(this.chart_data.class_name=o[1])}}ReadSeries(e){let t={x:{data:[]},y:{data:[]}};if(e[3]&&typeof e[3]=="number"&&(t.index=e[3]),e[4]&&(t.subtype=e[4].toString()),e[0]){let r=O.Flatten(e[0]);typeof r[0]=="object"?t.label=r[0]?.value?.toString()||"":t.label=r[0].toString()}if(e[2]&&typeof e[2]=="object"&&e[2].type===8){let r=O.Flatten(e[2].value);if(t.y.data=r.map(i=>typeof i.value.value=="number"?i.value.value:void 0),r[0].value?.format){t.y.format=r[0].value?.format;let i=I.Get(t.y.format);t.y.labels=t.y.data.map(n=>n===void 0?void 0:i.Format(n))}}if(e[1]&&typeof e[1]=="object"&&e[1].type===8){let r=O.Flatten(e[1].value);t.x.data=r.map(i=>typeof i.value.value=="number"?i.value.value:void 0),r[0].value.format&&(t.x.format=r[0].value.format)}for(let r of[t.x,t.y])if(r.data.length){let i=r.data.filter(n=>n||n===0);r.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)}}return t}ArrayToSeries(e){let t={x:{data:[]},y:{data:[]}},r=O.Flatten(e.value);if(t.y.data=r.map((n,a)=>typeof n.value=="number"?n.value:typeof n.value.value?.real=="number"?(t.x.data[a]=n.value.value.real,n.value.value.imaginary):typeof n.value.value=="number"?n.value.value:void 0),r[0].value.format){t.y.format=r[0].value.format||"";let n=I.Get(t.y.format||"");t.y.labels=t.y.data.map(a=>a===void 0?void 0:n.Format(a))}let i=t.y.data.filter(n=>n||n===0);if(t.y.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)},t.x.data.length){let n=t.x.data.filter(a=>typeof a=="number");if(t.x.range={min:Math.min.apply(0,n),max:Math.max.apply(0,n)},r[0].value.format){t.x.format=r[0].value.format||"";let a=I.Get(t.x.format||"");t.x.labels=t.x.data.map(s=>s===void 0?void 0:a.Format(s))}}return t}TransformSeriesData(e,t){if(!e)return[];let r=[];if(e.type===5){if(e.key==="group"){if(Array.isArray(e.value)){for(let a of e.value)if(a&&typeof a=="object")if(a.key==="series"){let s=this.ReadSeries(a.value);r.push(s)}else a.type===8&&r.push(this.ArrayToSeries(a))}}else if(e.key==="series"){let a=this.ReadSeries(e.value);r.push(a)}}else e.type===8&&r.push(this.ArrayToSeries(e));let i,n=0;if(t?.type===8){let a=O.Flatten(t.value),s="0.00###";a[0]&&a[0].type===5&&(s=a[0].value.format);let o=a.map(d=>{if(d.type===3)return d.value;if(d.type===5)return d.value.value}),l=o.filter(d=>typeof d=="number");i={data:o,format:s,range:{min:Math.min.apply(0,l),max:Math.max.apply(0,l)}}}for(let a of r)n=Math.max(n,a.y.data.length),a.x.data.length&&(i||(i=a.x));if(!i){i={data:[],range:{min:0,max:Math.max(0,n-1)}};for(let a=0;a<n;a++)i.data.push(a)}for(let a of r)a.x.data.length||(a.x=i);return r}CommonData(e,t,r){let i="",n="";for(let b of e)b.y.format&&!n&&(n=b.y.format),b.x.format&&!i&&(i=b.x.format);let a;e.some(b=>b.label&&b.label.length>0)&&(a=e.map((b,v)=>({label:b.label||`Series ${v+1}`,index:typeof b.index=="number"?b.index:v+1})));let s=e.filter(b=>b.x.range),o=Math.min.apply(0,s.map(b=>b.x.range?.min||0)),l=Math.max.apply(0,s.map(b=>b.x.range?.max||0)),d=e.filter(b=>b.y.range),h=Math.min.apply(0,s.map(b=>b.y.range?.min||0)),u=Math.max.apply(0,s.map(b=>b.y.range?.max||0));typeof t<"u"&&(h=Math.min(h,t)),typeof r<"u"&&(u=Math.max(u,r));let m=O.Scale(o,l,7),f=O.Scale(h,u,7),p,g;if(i){p=[];let b=I.Get(i);for(let v=0;v<=m.count;v++)p.push(b.Format(m.min+v*m.step))}if(n){g=[];let b=I.Get(n);for(let v=0;v<=f.count;v++)g.push(b.Format(f.min+v*f.step))}return{x:{format:i,scale:m,labels:p},y:{format:n,scale:f,labels:g},legend:a}}CreateScatterChart(e,t="plot"){let r=this.TransformSeriesData(e[0]),i=this.CommonData(r),n=e[1]?.toString()||void 0,a=e[2]?.toString()||void 0;if(this.chart_data={legend:i.legend,style:t,type:"scatter2",series:r,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels,lines:t==="line",points:t==="plot"},a){this.chart_data.markers=/marker/i.test(a),this.chart_data.smooth=/smooth/i.test(a),this.chart_data.data_labels=/labels/i.test(a);let s=a.match(/labels="(.*?)"/);s&&this.chart_data.series?this.ApplyLabels(this.chart_data.series,s[1]):(s=a.match(/labels=([^\s\r\n,]+)(?:\W|$)/),s&&this.chart_data.series&&this.ApplyLabels(this.chart_data.series,s[1])),s=a.match(/class=([\w_-]+)(?:\W|$)/),s&&(this.chart_data.class_name=s[1])}}ApplyLabels(e,t,r){for(let i of e){let n={x:I.Get(i.x.format||""),y:I.Get(i.y.format||"")};i.y.labels=[];for(let a=0;a<i.y.data.length;a++){let s=r?r[a]:typeof i.x.data[a]=="number"?n.x.Format(i.x.data[a]):"",o=typeof i.y.data[a]=="number"?n.y.Format(i.y.data[a]):"";i.y.labels[a]=t.replace(/\bx\b/g,s).replace(/\by\b/g,o)}}}CreateLineChart(e,t){let r=this.TransformSeriesData(e[0],e[1]),i=this.CommonData(r,0,0),n=e[2]?.toString()||void 0,a=e[3]?.toString()||void 0;if(this.chart_data={legend:i.legend,type:"scatter2",series:r,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels,lines:!0,filled:t==="area"},a){this.chart_data.smooth=/smooth/i.test(a);let s=a.match(/class=([\w_-]+)(?:\W|$)/);s&&(this.chart_data.class_name=s[1])}}CreateDonut(e,t=!1){let r=e[0]?.type===8?e[0].value:e[0],i=O.Flatten(r),n=i.map(b=>typeof b.value.value=="number"?b.value.value:void 0),a=e[1]?.type===8?e[1].value:e[1],s=O.Flatten(a).map(b=>{if(b&&typeof b=="object"){let v=b.value?.value;return typeof v=="number"&&b.value?.format?I.Get(b.value?.format).Format(v):v?v.toString():""}else return b?b.toString():""});n=n.map(b=>b<0?(console.warn("pie/donut chart does not support negative values (omitted)"),0):b);let o=e[2]||"",l=0,d=n.map((b,v)=>(typeof b<"u"&&(l+=b),{value:b,label:s[v]||"",index:v+1,percent:0}));if(l)for(let b of d)b.percent=(b.value||0)/l;let h=i.length&&i[0].value?.format?i[0].value.format:"",u=I.Get(h||Ur),m=I.Get("percent");typeof e[4]>"u"&&e[1]&&(e[4]="label");let f=e[4]||"";if(f)for(let b of d){let v=u.Format(b.value||0),_=m.Format(b.percent);b.title=f.replace(/value%/ig,m.Format(b.value||0)).replace(/value/ig,v).replace(/percent/ig,_).replace(/label/ig,b.label||"").trim()}let p=(e[3]||"").toString().trim(),g=p.toUpperCase();if(g==="ASC"||g==="ASCENDING"||g==="INC")d.sort((b,v)=>(b.value||0)-(v.value||0));else if(g==="DESC"||g==="DESCENDING"||g==="DEC")d.sort((b,v)=>(v.value||0)-(b.value||0));else{let b=p.match(/sort=([\w]+)(?:\W|$)/i);b&&(g=b[1],/^(asc|inc)/i.test(g)?d.sort((v,_)=>(v.value||0)-(_.value||0)):/^(desc|dec)/i.test(g)&&d.sort((v,_)=>(_.value||0)-(v.value||0)))}if(this.chart_data={type:t?"pie":"donut",slices:d,title:o},p){let b=p.match(/class=([_-\w]+)(?:\W|$)/);b&&(this.chart_data.class_name=b[1])}}Resize(){this.renderer.Resize()}Update(){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(this.chart_data.class_name);let e=new Te(0,0,this.renderer.size.width,this.renderer.size.height),t={top:Math.round(e.height)*this.margin.top,bottom:Math.round(e.height)*this.margin.bottom,left:Math.round(e.width)*this.margin.left,right:Math.round(e.width)*this.margin.right},r=this.chart_data.title;if(r&&this.renderer.RenderTitle(r,e,t.top,this.chart_data.title_layout||"top"),e.top+=t.top,e.left+=t.left,e.bottom-=t.bottom,e.right-=t.right,this.chart_data.legend&&this.chart_data.legend.length){let i=0;this.chart_data.title&&(!this.chart_data.title_layout||this.chart_data.title_layout==="top")&&(i=1);let n=this.chart_data.legend_position||i;this.renderer.Legend({labels:this.chart_data.legend,position:n,style:this.chart_data.legend_style,layout:n===0||n===1?0:1,area:e})}if(this.chart_data.type==="histogram"||this.chart_data.type==="line"||this.chart_data.type==="area"||this.chart_data.type==="column"||this.chart_data.type==="histogram2"||this.chart_data.type==="bar"||this.chart_data.type==="scatter2"){let i=[],n=0;if(this.chart_data.x_labels&&this.chart_data.x_labels.length&&(i=this.chart_data.x_labels.map(a=>{let s=this.renderer.MeasureText(a,["axis-label","x-axis-label"],!0);return n=Math.max(n,s.height),s})),this.chart_data.y_labels&&this.chart_data.y_labels.length){let a=[],s=0,o=0,l=this.chart_data.type==="scatter2"?this.chart_data.y_scale:this.chart_data.scale,d=this.chart_data.type==="bar"?this.chart_data.y_labels.length:l.count+1;for(let h=0;h<d;h++){let u=this.renderer.MeasureText(this.chart_data.y_labels[h],["axis-label","y-axis-label"]);a.push({label:this.chart_data.y_labels[h],metrics:u}),s=Math.max(s,u.width),o=Math.max(o,u.height)}e.bottom=Math.round(e.bottom-o/2),e.top=Math.round(e.top+o/2),i.length&&(e.bottom-=n+t.bottom),this.chart_data.type==="bar"?this.renderer.RenderYAxisBar(e,e.left+s,a,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(e,e.left+s,a,["axis-label","y-axis-label"]),e.left+=s+t.left}if(i.length&&this.chart_data.x_labels&&this.chart_data.x_labels.length){let a=this.chart_data.type==="histogram2",s=this.chart_data.type!=="line"&&this.chart_data.type!=="area"&&this.chart_data.type!=="bar"&&this.chart_data.type!=="scatter2"&&this.chart_data.type!=="histogram2";a&&this.renderer.RenderXAxisTicks(e,s,this.chart_data.x_labels.length),this.chart_data.y_labels&&(e.bottom+=n+t.bottom),this.renderer.RenderXAxis(e,s,this.chart_data.x_labels,i,["axis-label","x-axis-label"]),e.bottom-=n+t.bottom}}switch(this.chart_data.type){case"scatter":this.renderer.RenderPoints(e,this.chart_data.x,this.chart_data.y,"mc mc-correlation series-1");break;case"scatter2":if(this.renderer.RenderGrid(e,this.chart_data.y_scale.count,this.chart_data.x_scale.count+1,"chart-grid"),this.chart_data.series){for(let i=0;i<this.chart_data.series.length;i++){let n=this.chart_data.series[i],a=!!this.chart_data.lines,s=!!this.chart_data.points;n.subtype==="plot"?(s=!0,a=!1):n.subtype==="line"&&(s=!1,a=!0);let o=typeof n.index=="number"?n.index:i+1;this.renderer.RenderScatterSeries(e,n.x.data,n.y.data,this.chart_data.x_scale,this.chart_data.y_scale,a,s,!!this.chart_data.filled,!!this.chart_data.markers,!!this.chart_data.smooth,`scatter-plot series-${o}`)}if(this.chart_data.data_labels)for(let i=0;i<this.chart_data.series.length;i++){let n=this.chart_data.series[i];n.y.labels&&this.renderer.RenderDataLabels(e,n.x.data,n.y.data,this.chart_data.x_scale,this.chart_data.y_scale,n.y.labels,i+1)}}break;case"pie":case"donut":{let i=Math.min(e.height,e.width)/2*.9,n=this.chart_data.type==="pie"?0:i*.8;this.renderer.RenderDonut(this.chart_data.slices,e.center,i,n,e,!0,"donut")}break;case"line":case"area":{let i=this.chart_data.scale;if(this.chart_data.series){let n=this.chart_data.x_scale?this.chart_data.x_scale.max:Math.max.apply(0,this.chart_data.series.map(o=>o.length)),a=this.chart_data.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(e,this.chart_data.scale.count,this.chart_data.x_scale?this.chart_data.x_scale.count+1:n,"chart-grid");let s=0;for(let o of this.chart_data.series){let l=o.map(h=>{if(!(typeof h>"u"))return O.ApplyScale(h,e.height,i)});if(l.length<n)for(let h=l.length;h<n;h++)l.push(void 0);let d=[this.chart_data.type==="area"?"chart-area":"chart-line",`series-${s+1}`];a.call(this.renderer,e,l,this.chart_data.type==="area",this.chart_data.titles,d),s++}}}break;case"bar":{let i;if(this.renderer.RenderBarGrid(e,this.chart_data.scale.count,"chart-grid"),this.chart_data.series2){let n=0,a=this.chart_data.series2.length;for(let u of this.chart_data.series2)n=Math.max(n,u.y.data.length);let s=e.height/n,o=.7;typeof this.chart_data.space=="number"&&(o=Math.max(0,Math.min(1,1-this.chart_data.space)));let l=s*(1-o)/2,d=(s-l*2)/a,h=0;if(this.chart_data.scale.min<0&&(h=O.ApplyScale(0,e.width,this.chart_data.scale)),this.chart_data.round){let u=Math.floor(d/2);i=[0,u,u,0]}for(let u=0;u<a;u++){let m=this.chart_data.series2[u],f=typeof m.index=="number"?m.index:u+1;for(let p=0;p<m.y.data.length;p++){let g=m.y.data[p];if(typeof g=="number"){let b=Math.round(e.top+p*s+l)+u*d,v=0,_=0,w=!1;h?g>0?(_=O.ApplyScale(g+this.chart_data.scale.min,e.width,this.chart_data.scale),v=e.left+h):(_=O.ApplyScale(this.chart_data.scale.min-g,e.width,this.chart_data.scale),v=e.left+h-_,w=!0):(_=O.ApplyScale(g,e.width,this.chart_data.scale),v=e.left);let x=void 0;_&&this.renderer.RenderRectangle(new Te(v,b,v+_,b+d),i,["chart-column",`series-${f}`],x||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(e,this.chart_data.scale.count,0,"chart-grid"),this.chart_data.series2){let i=0,n=this.chart_data.series2.length;for(let u of this.chart_data.series2)i=Math.max(i,u.y.data.length);let a=e.width/i,s=.7;typeof this.chart_data.space=="number"&&(s=Math.max(0,Math.min(1,1-this.chart_data.space)));let o=a*(1-s)/2,l=(a-o*2)/n,d=0;if(this.chart_data.scale.min<0&&(d=O.ApplyScale(0,e.height,this.chart_data.scale)),this.chart_data.callouts&&this.chart_data.x_scale){let u=this.chart_data.x_scale,m=this.chart_data.callouts.map((f,p)=>{let g=Math.round(e.left+O.ApplyScale(f.value,e.width,u))+.5;return{x1:g,y1:e.bottom-e.height,x2:g,y2:e.bottom,classes:`callout-${p+1}`}});this.renderer.RenderCalloutLines(m)}let h;if(this.chart_data.round){let u=Math.floor(l/2);h=[u,u,0,0]}for(let u=0;u<n;u++){let m=this.chart_data.series2[u],f=typeof m.index=="number"?m.index:u+1;for(let p=0;p<m.y.data.length;p++){let g=m.y.data[p];if(typeof g=="number"){let b=e.left+p*a+o+u*l,v=0,_=0,w=!1;d?g>0?(v=O.ApplyScale(g+this.chart_data.scale.min,e.height,this.chart_data.scale),_=e.bottom-v-d):(v=O.ApplyScale(this.chart_data.scale.min-g,e.height,this.chart_data.scale),_=e.bottom-d,w=!0):(v=O.ApplyScale(g,e.height,this.chart_data.scale),_=e.bottom-v);let x=void 0;if(v){let A=this.chart_data.data_labels&&m.y.labels?m.y.labels[p]:"",k={x:Math.round(b+l/2),y:Math.round(_-10)};this.renderer.RenderRectangle(new Te(b,_,b+l,_+v),h,["chart-column",`series-${f}`],x||void 0,A,k)}}}}}break;case"histogram":{this.renderer.RenderGrid(e,this.chart_data.scale.count,0,"chart-grid");let i=e.width/this.chart_data.count,n=this.chart_data.column_width,a=i*(1-n)/2;for(let s=0;s<this.chart_data.count;s++){let o=Math.round(e.left+s*i+a),l=i-a*2,d=O.ApplyScale(this.chart_data.bins[s],e.height,this.chart_data.scale),h=e.bottom-d,u=this.chart_data.titles?this.chart_data.titles[s]:void 0;this.renderer.RenderRectangle(new Te(o,h,o+l,h+d),void 0,"chart-column series-1",u||void 0)}}break}}IsCellData(e){return typeof e=="object"&&typeof e.address=="object"&&typeof e.address.row=="number"&&typeof e.address.column=="number"}};var Ie=(...c)=>({type:5,value:c,key:"arguments"}),Vr={Group:{arguments:[{name:"Array...",metadata:!0}],fn:(...c)=>({type:5,value:c,key:"group"})},Series:{arguments:[{name:"Label"},{name:"X",metadata:!0},{name:"Y",metadata:!0},{name:"index"},{name:"subtype"}],fn:(...c)=>({type:5,value:c,key:"series"})},"Bar.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Line.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Area.Chart":{arguments:[{name:"y",metadata:!0},{name:"x",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Pie.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels"},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:Ie},"Donut.Chart":{arguments:[{name:"Values",metadata:!0},{name:"Labels",metadata:!0},{name:"Title"},{name:"Sort"},{name:"Label"}],fn:Ie},"Scatter.Line":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Scatter.Plot":{arguments:[{name:"Data",metadata:!0},{name:"ChartTitle"}],fn:Ie},"Column.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Categories",metadata:!0},{name:"Chart Title"}],fn:Ie}};var Fr={};Bi(Fr,{default:()=>Lr});var Lr='var hi=Object.create;var Kt=Object.defineProperty;var ui=Object.getOwnPropertyDescriptor;var fi=Object.getOwnPropertyNames;var mi=Object.getPrototypeOf,pi=Object.prototype.hasOwnProperty;var re=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var bi=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of fi(e))!pi.call(i,n)&&n!==t&&Kt(i,n,{get:()=>e[n],enumerable:!(r=ui(e,n))||r.enumerable});return i};var Ae=(i,e,t)=>(t=i!=null?hi(mi(i)):{},bi(e||!i||!i.__esModule?Kt(t,"default",{value:i,enumerable:!0}):t,i));var De=re(je=>{"use strict";je.byteLength=yi;je.toByteArray=_i;je.fromByteArray=vi;var ce=[],se=[],gi=typeof Uint8Array<"u"?Uint8Array:Array,yt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(xe=0,er=yt.length;xe<er;++xe)ce[xe]=yt[xe],se[yt.charCodeAt(xe)]=xe;var xe,er;se["-".charCodeAt(0)]=62;se["_".charCodeAt(0)]=63;function tr(i){var e=i.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=i.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function yi(i){var e=tr(i),t=e[0],r=e[1];return(t+r)*3/4-r}function xi(i,e,t){return(e+t)*3/4-t}function _i(i){var e,t=tr(i),r=t[0],n=t[1],s=new gi(xi(i,r,n)),o=0,a=n>0?r-4:r,l;for(l=0;l<a;l+=4)e=se[i.charCodeAt(l)]<<18|se[i.charCodeAt(l+1)]<<12|se[i.charCodeAt(l+2)]<<6|se[i.charCodeAt(l+3)],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=e&255;return n===2&&(e=se[i.charCodeAt(l)]<<2|se[i.charCodeAt(l+1)]>>4,s[o++]=e&255),n===1&&(e=se[i.charCodeAt(l)]<<10|se[i.charCodeAt(l+1)]<<4|se[i.charCodeAt(l+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function wi(i){return ce[i>>18&63]+ce[i>>12&63]+ce[i>>6&63]+ce[i&63]}function Ai(i,e,t){for(var r,n=[],s=e;s<t;s+=3)r=(i[s]<<16&16711680)+(i[s+1]<<8&65280)+(i[s+2]&255),n.push(wi(r));return n.join("")}function vi(i){for(var e,t=i.length,r=t%3,n=[],s=16383,o=0,a=t-r;o<a;o+=s)n.push(Ai(i,o,o+s>a?a:o+s));return r===1?(e=i[t-1],n.push(ce[e>>2]+ce[e<<4&63]+"==")):r===2&&(e=(i[t-2]<<8)+i[t-1],n.push(ce[e>>10]+ce[e>>4&63]+ce[e<<2&63]+"=")),n.join("")}});var Xe=re(de=>{"use strict";var ir=":A-Za-z_\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD",Fi=ir+"\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040",nr="["+ir+"]["+Fi+"]*",Ei=new RegExp("^"+nr+"$"),ki=function(i,e){let t=[],r=e.exec(i);for(;r;){let n=[];n.startIndex=e.lastIndex-r[0].length;let s=r.length;for(let o=0;o<s;o++)n.push(r[o]);t.push(n),r=e.exec(i)}return t},Wi=function(i){let e=Ei.exec(i);return!(e===null||typeof e>"u")};de.isExist=function(i){return typeof i<"u"};de.isEmptyObject=function(i){return Object.keys(i).length===0};de.merge=function(i,e,t){if(e){let r=Object.keys(e),n=r.length;for(let s=0;s<n;s++)t==="strict"?i[r[s]]=[e[r[s]]]:i[r[s]]=e[r[s]]}};de.getValue=function(i){return de.isExist(i)?i:""};de.isName=Wi;de.getAllMatches=ki;de.nameRegexp=nr});var Ct=re(cr=>{"use strict";var vt=Xe(),Ri={allowBooleanAttributes:!1,unpairedTags:[]};cr.validate=function(i,e){e=Object.assign({},Ri,e);let t=[],r=!1,n=!1;i[0]==="\\uFEFF"&&(i=i.substr(1));for(let s=0;s<i.length;s++)if(i[s]==="<"&&i[s+1]==="?"){if(s+=2,s=ar(i,s),s.err)return s}else if(i[s]==="<"){let o=s;if(s++,i[s]==="!"){s=or(i,s);continue}else{let a=!1;i[s]==="/"&&(a=!0,s++);let l="";for(;s<i.length&&i[s]!==">"&&i[s]!==" "&&i[s]!==" "&&i[s]!==`\n`&&i[s]!=="\\r";s++)l+=i[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!Li(l)){let h;return l.trim().length===0?h="Invalid space after \'<\'.":h="Tag \'"+l+"\' is an invalid name.",O("InvalidTag",h,ie(i,s))}let d=$i(i,s);if(d===!1)return O("InvalidAttr","Attributes for \'"+l+"\' have open quote.",ie(i,s));let c=d.value;if(s=d.index,c[c.length-1]==="/"){let h=s-c.length;c=c.substring(0,c.length-1);let u=lr(c,e);if(u===!0)r=!0;else return O(u.err.code,u.err.msg,ie(i,h+u.err.line))}else if(a)if(d.tagClosed){if(c.trim().length>0)return O("InvalidTag","Closing tag \'"+l+"\' can\'t have attributes or invalid starting.",ie(i,o));{let h=t.pop();if(l!==h.tagName){let u=ie(i,h.tagStartPos);return O("InvalidTag","Expected closing tag \'"+h.tagName+"\' (opened in line "+u.line+", col "+u.col+") instead of closing tag \'"+l+"\'.",ie(i,o))}t.length==0&&(n=!0)}}else return O("InvalidTag","Closing tag \'"+l+"\' doesn\'t have proper closing.",ie(i,s));else{let h=lr(c,e);if(h!==!0)return O(h.err.code,h.err.msg,ie(i,s-c.length+h.err.line));if(n===!0)return O("InvalidXml","Multiple possible root nodes found.",ie(i,s));e.unpairedTags.indexOf(l)!==-1||t.push({tagName:l,tagStartPos:o}),r=!0}for(s++;s<i.length;s++)if(i[s]==="<")if(i[s+1]==="!"){s++,s=or(i,s);continue}else if(i[s+1]==="?"){if(s=ar(i,++s),s.err)return s}else break;else if(i[s]==="&"){let h=zi(i,s);if(h==-1)return O("InvalidChar","char \'&\' is not expected.",ie(i,s));s=h}else if(n===!0&&!sr(i[s]))return O("InvalidXml","Extra text at the end",ie(i,s));i[s]==="<"&&s--}}else{if(sr(i[s]))continue;return O("InvalidChar","char \'"+i[s]+"\' is not expected.",ie(i,s))}if(r){if(t.length==1)return O("InvalidTag","Unclosed tag \'"+t[0].tagName+"\'.",ie(i,t[0].tagStartPos));if(t.length>0)return O("InvalidXml","Invalid \'"+JSON.stringify(t.map(s=>s.tagName),null,4).replace(/\\r?\\n/g,"")+"\' found.",{line:1,col:1})}else return O("InvalidXml","Start tag expected.",1);return!0};function sr(i){return i===" "||i===" "||i===`\n`||i==="\\r"}function ar(i,e){let t=e;for(;e<i.length;e++)if(i[e]=="?"||i[e]==" "){let r=i.substr(t,e-t);if(e>5&&r==="xml")return O("InvalidXml","XML declaration allowed only at the start of the document.",ie(i,e));if(i[e]=="?"&&i[e+1]==">"){e++;break}else continue}return e}function or(i,e){if(i.length>e+5&&i[e+1]==="-"&&i[e+2]==="-"){for(e+=3;e<i.length;e++)if(i[e]==="-"&&i[e+1]==="-"&&i[e+2]===">"){e+=2;break}}else if(i.length>e+8&&i[e+1]==="D"&&i[e+2]==="O"&&i[e+3]==="C"&&i[e+4]==="T"&&i[e+5]==="Y"&&i[e+6]==="P"&&i[e+7]==="E"){let t=1;for(e+=8;e<i.length;e++)if(i[e]==="<")t++;else if(i[e]===">"&&(t--,t===0))break}else if(i.length>e+9&&i[e+1]==="["&&i[e+2]==="C"&&i[e+3]==="D"&&i[e+4]==="A"&&i[e+5]==="T"&&i[e+6]==="A"&&i[e+7]==="["){for(e+=8;e<i.length;e++)if(i[e]==="]"&&i[e+1]==="]"&&i[e+2]===">"){e+=2;break}}return e}var Gi=\'"\',Mi="\'";function $i(i,e){let t="",r="",n=!1;for(;e<i.length;e++){if(i[e]===Gi||i[e]===Mi)r===""?r=i[e]:r!==i[e]||(r="");else if(i[e]===">"&&r===""){n=!0;break}t+=i[e]}return r!==""?!1:{value:t,index:e,tagClosed:n}}var Ui=new RegExp(`(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*([\'"])(([\\\\s\\\\S])*?)\\\\5)?`,"g");function lr(i,e){let t=vt.getAllMatches(i,Ui),r={};for(let n=0;n<t.length;n++){if(t[n][1].length===0)return O("InvalidAttr","Attribute \'"+t[n][2]+"\' has no space in starting.",Ee(t[n]));if(t[n][3]!==void 0&&t[n][4]===void 0)return O("InvalidAttr","Attribute \'"+t[n][2]+"\' is without value.",Ee(t[n]));if(t[n][3]===void 0&&!e.allowBooleanAttributes)return O("InvalidAttr","boolean attribute \'"+t[n][2]+"\' is not allowed.",Ee(t[n]));let s=t[n][2];if(!Bi(s))return O("InvalidAttr","Attribute \'"+s+"\' is an invalid name.",Ee(t[n]));if(!r.hasOwnProperty(s))r[s]=1;else return O("InvalidAttr","Attribute \'"+s+"\' is repeated.",Ee(t[n]))}return!0}function Vi(i,e){let t=/\\d/;for(i[e]==="x"&&(e++,t=/[\\da-fA-F]/);e<i.length;e++){if(i[e]===";")return e;if(!i[e].match(t))break}return-1}function zi(i,e){if(e++,i[e]===";")return-1;if(i[e]==="#")return e++,Vi(i,e);let t=0;for(;e<i.length;e++,t++)if(!(i[e].match(/\\w/)&&t<20)){if(i[e]===";")break;return-1}return e}function O(i,e,t){return{err:{code:i,msg:e,line:t.line||t,col:t.col}}}function Bi(i){return vt.isName(i)}function Li(i){return vt.isName(i)}function ie(i,e){let t=i.substring(0,e).split(/\\r?\\n/);return{line:t.length,col:t[t.length-1].length+1}}function Ee(i){return i.startIndex+i[1].length}});var hr=re(It=>{var dr={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(i,e){return e},attributeValueProcessor:function(i,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(i,e,t){return i}},Yi=function(i){return Object.assign({},dr,i)};It.buildOptions=Yi;It.defaultOptions=dr});var fr=re(($a,ur)=>{"use strict";var Nt=class{constructor(e){this.tagname=e,this.child=[],this[":@"]={}}add(e,t){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:t})}addChild(e){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child})}};ur.exports=Nt});var pr=re((Ua,mr)=>{var ji=Xe();function Di(i,e){let t={};if(i[e+3]==="O"&&i[e+4]==="C"&&i[e+5]==="T"&&i[e+6]==="Y"&&i[e+7]==="P"&&i[e+8]==="E"){e=e+9;let r=1,n=!1,s=!1,o="";for(;e<i.length;e++)if(i[e]==="<"&&!s){if(n&&Ji(i,e))e+=7,[entityName,val,e]=Hi(i,e+1),val.indexOf("&")===-1&&(t[Ki(entityName)]={regx:RegExp(`&${entityName};`,"g"),val});else if(n&&Xi(i,e))e+=8;else if(n&&Qi(i,e))e+=8;else if(n&&qi(i,e))e+=9;else if(Oi)s=!0;else throw new Error("Invalid DOCTYPE");r++,o=""}else if(i[e]===">"){if(s?i[e-1]==="-"&&i[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else i[e]==="["?n=!0:o+=i[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:t,i:e}}function Hi(i,e){let t="";for(;e<i.length&&i[e]!=="\'"&&i[e]!==\'"\';e++)t+=i[e];if(t=t.trim(),t.indexOf(" ")!==-1)throw new Error("External entites are not supported");let r=i[e++],n="";for(;e<i.length&&i[e]!==r;e++)n+=i[e];return[t,n,e]}function Oi(i,e){return i[e+1]==="!"&&i[e+2]==="-"&&i[e+3]==="-"}function Ji(i,e){return i[e+1]==="!"&&i[e+2]==="E"&&i[e+3]==="N"&&i[e+4]==="T"&&i[e+5]==="I"&&i[e+6]==="T"&&i[e+7]==="Y"}function Xi(i,e){return i[e+1]==="!"&&i[e+2]==="E"&&i[e+3]==="L"&&i[e+4]==="E"&&i[e+5]==="M"&&i[e+6]==="E"&&i[e+7]==="N"&&i[e+8]==="T"}function Qi(i,e){return i[e+1]==="!"&&i[e+2]==="A"&&i[e+3]==="T"&&i[e+4]==="T"&&i[e+5]==="L"&&i[e+6]==="I"&&i[e+7]==="S"&&i[e+8]==="T"}function qi(i,e){return i[e+1]==="!"&&i[e+2]==="N"&&i[e+3]==="O"&&i[e+4]==="T"&&i[e+5]==="A"&&i[e+6]==="T"&&i[e+7]==="I"&&i[e+8]==="O"&&i[e+9]==="N"}function Ki(i){if(ji.isName(i))return i;throw new Error(`Invalid entity name ${i}`)}mr.exports=Di});var gr=re((Va,br)=>{var en=/^[-+]?0x[a-fA-F0-9]+$/,tn=/^([\\-\\+])?(0*)(\\.[0-9]+([eE]\\-?[0-9]+)?|[0-9]+(\\.[0-9]+([eE]\\-?[0-9]+)?)?)$/;!Number.parseInt&&window.parseInt&&(Number.parseInt=window.parseInt);!Number.parseFloat&&window.parseFloat&&(Number.parseFloat=window.parseFloat);var rn={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function nn(i,e={}){if(e=Object.assign({},rn,e),!i||typeof i!="string")return i;let t=i.trim();if(e.skipLike!==void 0&&e.skipLike.test(t))return i;if(e.hex&&en.test(t))return Number.parseInt(t,16);{let r=tn.exec(t);if(r){let n=r[1],s=r[2],o=sn(r[3]),a=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&n&&t[2]!==".")return i;if(!e.leadingZeros&&s.length>0&&!n&&t[1]!==".")return i;{let l=Number(t),d=""+l;return d.search(/[eE]/)!==-1||a?e.eNotation?l:i:t.indexOf(".")!==-1?d==="0"&&o===""||d===o||n&&d==="-"+o?l:i:s?o===d||n+o===d?l:i:t===d||t===n+d?l:i}}else return i}}function sn(i){return i&&i.indexOf(".")!==-1&&(i=i.replace(/0+$/,""),i==="."?i="0":i[0]==="."?i="0"+i:i[i.length-1]==="."&&(i=i.substr(0,i.length-1))),i}br.exports=nn});var xr=re((Ba,yr)=>{"use strict";var Pt=Xe(),ke=fr(),an=pr(),on=gr(),za="<((!\\\\[CDATA\\\\[([\\\\s\\\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\\\/)(NAME)\\\\s*>))([^<]*)".replace(/NAME/g,Pt.nameRegexp),St=class{constructor(e){this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"\'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:\'"\'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"\\xA2"},pound:{regex:/&(pound|#163);/g,val:"\\xA3"},yen:{regex:/&(yen|#165);/g,val:"\\xA5"},euro:{regex:/&(euro|#8364);/g,val:"\\u20AC"},copyright:{regex:/&(copy|#169);/g,val:"\\xA9"},reg:{regex:/&(reg|#174);/g,val:"\\xAE"},inr:{regex:/&(inr|#8377);/g,val:"\\u20B9"}},this.addExternalEntities=ln,this.parseXml=fn,this.parseTextData=cn,this.resolveNameSpace=dn,this.buildAttributesMap=un,this.isItStopNode=gn,this.replaceEntitiesValue=pn,this.readStopNodeData=xn,this.saveTextToParentTag=bn,this.addChild=mn}};function ln(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:i[r]}}}function cn(i,e,t,r,n,s,o){if(i!==void 0&&(this.options.trimValues&&!r&&(i=i.trim()),i.length>0)){o||(i=this.replaceEntitiesValue(i));let a=this.options.tagValueProcessor(e,i,t,n,s);return a==null?i:typeof a!=typeof i||a!==i?a:this.options.trimValues?Zt(i,this.options.parseTagValue,this.options.numberParseOptions):i.trim()===i?Zt(i,this.options.parseTagValue,this.options.numberParseOptions):i}}function dn(i){if(this.options.removeNSPrefix){let e=i.split(":"),t=i.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(i=t+e[1])}return i}var hn=new RegExp(`([^\\\\s=]+)\\\\s*(=\\\\s*([\'"])([\\\\s\\\\S]*?)\\\\3)?`,"gm");function un(i,e,t){if(!this.options.ignoreAttributes&&typeof i=="string"){let r=Pt.getAllMatches(i,hn),n=r.length,s={};for(let o=0;o<n;o++){let a=this.resolveNameSpace(r[o][1]),l=r[o][4],d=this.options.attributeNamePrefix+a;if(a.length)if(this.options.transformAttributeName&&(d=this.options.transformAttributeName(d)),d==="__proto__"&&(d="#__proto__"),l!==void 0){this.options.trimValues&&(l=l.trim()),l=this.replaceEntitiesValue(l);let c=this.options.attributeValueProcessor(a,l,e);c==null?s[d]=l:typeof c!=typeof l||c!==l?s[d]=c:s[d]=Zt(l,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[d]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){let o={};return o[this.options.attributesGroupName]=s,o}return s}}var fn=function(i){i=i.replace(/\\r\\n?/g,`\n`);let e=new ke("!xml"),t=e,r="",n="";for(let s=0;s<i.length;s++)if(i[s]==="<")if(i[s+1]==="/"){let a=we(i,">",s,"Closing Tag is not closed."),l=i.substring(s+2,a).trim();if(this.options.removeNSPrefix){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1))}this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&(r=this.saveTextToParentTag(r,t,n));let d=n.substring(n.lastIndexOf(".")+1);if(l&&this.options.unpairedTags.indexOf(l)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${l}>`);let c=0;d&&this.options.unpairedTags.indexOf(d)!==-1?(c=n.lastIndexOf(".",n.lastIndexOf(".")-1),this.tagsNodeStack.pop()):c=n.lastIndexOf("."),n=n.substring(0,c),t=this.tagsNodeStack.pop(),r="",s=a}else if(i[s+1]==="?"){let a=Tt(i,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,t,n),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){let l=new ke(a.tagName);l.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(l[":@"]=this.buildAttributesMap(a.tagExp,n,a.tagName)),this.addChild(t,l,n)}s=a.closeIndex+1}else if(i.substr(s+1,3)==="!--"){let a=we(i,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){let l=i.substring(s+4,a-2);r=this.saveTextToParentTag(r,t,n),t.add(this.options.commentPropName,[{[this.options.textNodeName]:l}])}s=a}else if(i.substr(s+1,2)==="!D"){let a=an(i,s);this.docTypeEntities=a.entities,s=a.i}else if(i.substr(s+1,2)==="!["){let a=we(i,"]]>",s,"CDATA is not closed.")-2,l=i.substring(s+9,a);if(r=this.saveTextToParentTag(r,t,n),this.options.cdataPropName)t.add(this.options.cdataPropName,[{[this.options.textNodeName]:l}]);else{let d=this.parseTextData(l,t.tagname,n,!0,!1,!0);d==null&&(d=""),t.add(this.options.textNodeName,d)}s=a+2}else{let a=Tt(i,s,this.options.removeNSPrefix),l=a.tagName,d=a.rawTagName,c=a.tagExp,h=a.attrExpPresent,u=a.closeIndex;this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&r&&t.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,t,n,!1));let p=t;if(p&&this.options.unpairedTags.indexOf(p.tagname)!==-1&&(t=this.tagsNodeStack.pop(),n=n.substring(0,n.lastIndexOf("."))),l!==e.tagname&&(n+=n?"."+l:l),this.isItStopNode(this.options.stopNodes,n,l)){let f="";if(c.length>0&&c.lastIndexOf("/")===c.length-1)s=a.closeIndex;else if(this.options.unpairedTags.indexOf(l)!==-1)s=a.closeIndex;else{let y=this.readStopNodeData(i,d,u+1);if(!y)throw new Error(`Unexpected end of ${d}`);s=y.i,f=y.tagContent}let g=new ke(l);l!==c&&h&&(g[":@"]=this.buildAttributesMap(c,n,l)),f&&(f=this.parseTextData(f,l,n,!0,h,!0,!0)),n=n.substr(0,n.lastIndexOf(".")),g.add(this.options.textNodeName,f),this.addChild(t,g,n)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){l[l.length-1]==="/"?(l=l.substr(0,l.length-1),n=n.substr(0,n.length-1),c=l):c=c.substr(0,c.length-1),this.options.transformTagName&&(l=this.options.transformTagName(l));let f=new ke(l);l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,n,l)),this.addChild(t,f,n),n=n.substr(0,n.lastIndexOf("."))}else{let f=new ke(l);this.tagsNodeStack.push(t),l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,n,l)),this.addChild(t,f,n),t=f}r="",s=u}}else r+=i[s];return e.child};function mn(i,e,t){let r=this.options.updateTag(e.tagname,t,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),i.addChild(e))}var pn=function(i){if(this.options.processEntities){for(let e in this.docTypeEntities){let t=this.docTypeEntities[e];i=i.replace(t.regx,t.val)}for(let e in this.lastEntities){let t=this.lastEntities[e];i=i.replace(t.regex,t.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){let t=this.htmlEntities[e];i=i.replace(t.regex,t.val)}i=i.replace(this.ampEntity.regex,this.ampEntity.val)}return i};function bn(i,e,t,r){return i&&(r===void 0&&(r=Object.keys(e.child).length===0),i=this.parseTextData(i,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),i!==void 0&&i!==""&&e.add(this.options.textNodeName,i),i=""),i}function gn(i,e,t){let r="*."+t;for(let n in i){let s=i[n];if(r===s||e===s)return!0}return!1}function yn(i,e,t=">"){let r,n="";for(let s=e;s<i.length;s++){let o=i[s];if(r)o===r&&(r="");else if(o===\'"\'||o==="\'")r=o;else if(o===t[0])if(t[1]){if(i[s+1]===t[1])return{data:n,index:s}}else return{data:n,index:s};else o===" "&&(o=" ");n+=o}}function we(i,e,t,r){let n=i.indexOf(e,t);if(n===-1)throw new Error(r);return n+e.length-1}function Tt(i,e,t,r=">"){let n=yn(i,e+1,r);if(!n)return;let s=n.data,o=n.index,a=s.search(/\\s/),l=s,d=!0;a!==-1&&(l=s.substr(0,a).replace(/\\s\\s*$/,""),s=s.substr(a+1));let c=l;if(t){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1),d=l!==n.data.substr(h+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:d,rawTagName:c}}function xn(i,e,t){let r=t,n=1;for(;t<i.length;t++)if(i[t]==="<")if(i[t+1]==="/"){let s=we(i,">",t,`${e} is not closed`);if(i.substring(t+2,s).trim()===e&&(n--,n===0))return{tagContent:i.substring(r,t),i:s};t=s}else if(i[t+1]==="?")t=we(i,"?>",t+1,"StopNode is not closed.");else if(i.substr(t+1,3)==="!--")t=we(i,"-->",t+3,"StopNode is not closed.");else if(i.substr(t+1,2)==="![")t=we(i,"]]>",t,"StopNode is not closed.")-2;else{let s=Tt(i,t,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&n++,t=s.closeIndex)}}function Zt(i,e,t){if(e&&typeof i=="string"){let r=i.trim();return r==="true"?!0:r==="false"?!1:on(i,t)}else return Pt.isExist(i)?i:""}yr.exports=St});var Ar=re(wr=>{"use strict";function _n(i,e){return _r(i,e)}function _r(i,e,t){let r,n={};for(let s=0;s<i.length;s++){let o=i[s],a=wn(o),l="";if(t===void 0?l=a:l=t+"."+a,a===e.textNodeName)r===void 0?r=o[a]:r+=""+o[a];else{if(a===void 0)continue;if(o[a]){let d=_r(o[a],e,l),c=vn(d,e);o[":@"]?An(d,o[":@"],l,e):Object.keys(d).length===1&&d[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?d=d[e.textNodeName]:Object.keys(d).length===0&&(e.alwaysCreateTextNode?d[e.textNodeName]="":d=""),n[a]!==void 0&&n.hasOwnProperty(a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(d)):e.isArray(a,l,c)?n[a]=[d]:n[a]=d}}}return typeof r=="string"?r.length>0&&(n[e.textNodeName]=r):r!==void 0&&(n[e.textNodeName]=r),n}function wn(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];if(r!==":@")return r}}function An(i,e,t,r){if(e){let n=Object.keys(e),s=n.length;for(let o=0;o<s;o++){let a=n[o];r.isArray(a,t+"."+a,!0,!0)?i[a]=[e[a]]:i[a]=e[a]}}}function vn(i,e){let{textNodeName:t}=e,r=Object.keys(i).length;return!!(r===0||r===1&&(i[t]||typeof i[t]=="boolean"||i[t]===0))}wr.prettify=_n});var Cr=re((Ya,vr)=>{var{buildOptions:Cn}=hr(),In=xr(),{prettify:Nn}=Ar(),Sn=Ct(),Ft=class{constructor(e){this.externalEntities={},this.options=Cn(e)}parse(e,t){if(typeof e!="string")if(e.toString)e=e.toString();else throw new Error("XML data is accepted in String or Bytes[] form.");if(t){t===!0&&(t={});let s=Sn.validate(e,t);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}let r=new In(this.options);r.addExternalEntities(this.externalEntities);let n=r.parseXml(e);return this.options.preserveOrder||n===void 0?n:Nn(n,this.options)}addEntity(e,t){if(t.indexOf("&")!==-1)throw new Error("Entity value can\'t have \'&\'");if(e.indexOf("&")!==-1||e.indexOf(";")!==-1)throw new Error("An entity must be set without \'&\' and \';\'. Eg. use \'#xD\' for \'
\'");if(t==="&")throw new Error("An entity with value \'&\' is not permitted");this.externalEntities[e]=t}};vr.exports=Ft});var Zr=re((ja,Tr)=>{var Tn=`\n`;function Zn(i,e){let t="";return e.format&&e.indentBy.length>0&&(t=Tn),Nr(i,e,"",t)}function Nr(i,e,t,r){let n="",s=!1;for(let o=0;o<i.length;o++){let a=i[o],l=Pn(a);if(l===void 0)continue;let d="";if(t.length===0?d=l:d=`${t}.${l}`,l===e.textNodeName){let f=a[l];Fn(d,e)||(f=e.tagValueProcessor(l,f),f=Sr(f,e)),s&&(n+=r),n+=f,s=!1;continue}else if(l===e.cdataPropName){s&&(n+=r),n+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,s=!1;continue}else if(l===e.commentPropName){n+=r+`<!--${a[l][0][e.textNodeName]}-->`,s=!0;continue}else if(l[0]==="?"){let f=Ir(a[":@"],e),g=l==="?xml"?"":r,y=a[l][0][e.textNodeName];y=y.length!==0?" "+y:"",n+=g+`<${l}${y}${f}?>`,s=!0;continue}let c=r;c!==""&&(c+=e.indentBy);let h=Ir(a[":@"],e),u=r+`<${l}${h}`,p=Nr(a[l],e,d,c);e.unpairedTags.indexOf(l)!==-1?e.suppressUnpairedNode?n+=u+">":n+=u+"/>":(!p||p.length===0)&&e.suppressEmptyNode?n+=u+"/>":p&&p.endsWith(">")?n+=u+`>${p}${r}</${l}>`:(n+=u+">",p&&r!==""&&(p.includes("/>")||p.includes("</"))?n+=r+e.indentBy+p+r:n+=p,n+=`</${l}>`),s=!0}return n}function Pn(i){let e=Object.keys(i);for(let t=0;t<e.length;t++){let r=e[t];if(i.hasOwnProperty(r)&&r!==":@")return r}}function Ir(i,e){let t="";if(i&&!e.ignoreAttributes)for(let r in i){if(!i.hasOwnProperty(r))continue;let n=e.attributeValueProcessor(r,i[r]);n=Sr(n,e),n===!0&&e.suppressBooleanAttributes?t+=` ${r.substr(e.attributeNamePrefix.length)}`:t+=` ${r.substr(e.attributeNamePrefix.length)}="${n}"`}return t}function Fn(i,e){i=i.substr(0,i.length-e.textNodeName.length-1);let t=i.substr(i.lastIndexOf(".")+1);for(let r in e.stopNodes)if(e.stopNodes[r]===i||e.stopNodes[r]==="*."+t)return!0;return!1}function Sr(i,e){if(i&&i.length>0&&e.processEntities)for(let t=0;t<e.entities.length;t++){let r=e.entities[t];i=i.replace(r.regex,r.val)}return i}Tr.exports=Zn});var Fr=re((Da,Pr)=>{"use strict";var En=Zr(),kn={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(i,e){return e},attributeValueProcessor:function(i,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&"},{regex:new RegExp(">","g"),val:">"},{regex:new RegExp("<","g"),val:"<"},{regex:new RegExp("\'","g"),val:"'"},{regex:new RegExp(\'"\',"g"),val:"""}],processEntities:!0,stopNodes:[],oneListGroup:!1};function pe(i){this.options=Object.assign({},kn,i),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Gn),this.processTextOrObjNode=Wn,this.options.format?(this.indentate=Rn,this.tagEndChar=`>\n`,this.newLine=`\n`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}pe.prototype.build=function(i){return this.options.preserveOrder?En(i,this.options):(Array.isArray(i)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(i={[this.options.arrayNodeName]:i}),this.j2x(i,0).val)};pe.prototype.j2x=function(i,e){let t="",r="";for(let n in i)if(Object.prototype.hasOwnProperty.call(i,n))if(typeof i[n]>"u")this.isAttribute(n)&&(r+="");else if(i[n]===null)this.isAttribute(n)?r+="":n[0]==="?"?r+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+n+"/"+this.tagEndChar;else if(i[n]instanceof Date)r+=this.buildTextValNode(i[n],n,"",e);else if(typeof i[n]!="object"){let s=this.isAttribute(n);if(s)t+=this.buildAttrPairStr(s,""+i[n]);else if(n===this.options.textNodeName){let o=this.options.tagValueProcessor(n,""+i[n]);r+=this.replaceEntitiesValue(o)}else r+=this.buildTextValNode(i[n],n,"",e)}else if(Array.isArray(i[n])){let s=i[n].length,o="";for(let a=0;a<s;a++){let l=i[n][a];typeof l>"u"||(l===null?n[0]==="?"?r+=this.indentate(e)+"<"+n+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+n+"/"+this.tagEndChar:typeof l=="object"?this.options.oneListGroup?o+=this.j2x(l,e+1).val:o+=this.processTextOrObjNode(l,n,e):o+=this.buildTextValNode(l,n,"",e))}this.options.oneListGroup&&(o=this.buildObjectNode(o,n,"",e)),r+=o}else if(this.options.attributesGroupName&&n===this.options.attributesGroupName){let s=Object.keys(i[n]),o=s.length;for(let a=0;a<o;a++)t+=this.buildAttrPairStr(s[a],""+i[n][s[a]])}else r+=this.processTextOrObjNode(i[n],n,e);return{attrStr:t,val:r}};pe.prototype.buildAttrPairStr=function(i,e){return e=this.options.attributeValueProcessor(i,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+i:" "+i+\'="\'+e+\'"\'};function Wn(i,e,t){let r=this.j2x(i,t+1);return i[this.options.textNodeName]!==void 0&&Object.keys(i).length===1?this.buildTextValNode(i[this.options.textNodeName],e,r.attrStr,t):this.buildObjectNode(r.val,e,r.attrStr,t)}pe.prototype.buildObjectNode=function(i,e,t,r){if(i==="")return e[0]==="?"?this.indentate(r)+"<"+e+t+"?"+this.tagEndChar:this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar;{let n="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",n=""),(t||t==="")&&i.indexOf("<")===-1?this.indentate(r)+"<"+e+t+s+">"+i+n:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${i}-->`+this.newLine:this.indentate(r)+"<"+e+t+s+this.tagEndChar+i+this.indentate(r)+n}};pe.prototype.closeTag=function(i){let e="";return this.options.unpairedTags.indexOf(i)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${i}`,e};pe.prototype.buildTextValNode=function(i,e,t,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${i}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${i}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+t+"?"+this.tagEndChar;{let n=this.options.tagValueProcessor(e,i);return n=this.replaceEntitiesValue(n),n===""?this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+t+">"+n+"</"+e+this.tagEndChar}};pe.prototype.replaceEntitiesValue=function(i){if(i&&i.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){let t=this.options.entities[e];i=i.replace(t.regex,t.val)}return i};function Rn(i){return this.options.indentBy.repeat(i)}function Gn(i){return i.startsWith(this.options.attributeNamePrefix)&&i!==this.options.textNodeName?i.substr(this.attrPrefixLen):!1}Pr.exports=pe});var Et=re((Ha,Er)=>{"use strict";var Mn=Ct(),$n=Cr(),Un=Fr();Er.exports={XMLParser:$n,XMLValidator:Mn,XMLBuilder:Un}});var ni=re((cl,Xt)=>{var m={};typeof Xt=="object"&&(Xt.exports=m);m.parse=function(i,e){for(var t=m.bin.readUshort,r=m.bin.readUint,a=0,n={},s=new Uint8Array(i),o=s.length-4;r(s,o)!=101010256;)o--;var a=o;a+=4,a+=4;var l=t(s,a);a+=2;var d=t(s,a);a+=2;var c=r(s,a);a+=4;var h=r(s,a);a+=4,a=h;for(var u=0;u<l;u++){var p=r(s,a);a+=4,a+=4,a+=4,a+=4;var f=r(s,a);a+=4;var c=r(s,a);a+=4;var g=r(s,a);a+=4;var y=t(s,a),N=t(s,a+2),w=t(s,a+4);a+=6,a+=8;var x=r(s,a);a+=4,a+=y+N+w,m._readLocal(s,x,n,c,g,e)}return n};m._readLocal=function(i,e,t,r,n,s){var o=m.bin.readUshort,a=m.bin.readUint,l=a(i,e);e+=4;var d=o(i,e);e+=2;var c=o(i,e);e+=2;var h=o(i,e);e+=2;var u=a(i,e);e+=4;var p=a(i,e);e+=4,e+=8;var f=o(i,e);e+=2;var g=o(i,e);e+=2;var y=m.bin.readUTF8(i,e,f);if(e+=f,e+=g,s){t[y]={size:n,csize:r};return}var N=new Uint8Array(i.buffer,e);if(h==0)t[y]=new Uint8Array(N.buffer.slice(e,e+r));else if(h==8){var w=new Uint8Array(n);m.inflateRaw(N,w),t[y]=w}else throw"unknown compression method: "+h};m.inflateRaw=function(i,e){return m.F.inflate(i,e)};m.inflate=function(i,e){var t=i[0],r=i[1],n=t&15,s=t>>>4;return m.inflateRaw(new Uint8Array(i.buffer,i.byteOffset+2,i.length-6),e)};m.deflate=function(i,e){e==null&&(e={level:6});var t=0,r=new Uint8Array(50+Math.floor(i.length*1.1));r[t]=120,r[t+1]=156,t+=2,t=m.F.deflateRaw(i,r,t,e.level);var n=m.adler(i,0,i.length);return r[t+0]=n>>>24&255,r[t+1]=n>>>16&255,r[t+2]=n>>>8&255,r[t+3]=n>>>0&255,new Uint8Array(r.buffer,0,t+4)};m.deflateRaw=function(i,e){e==null&&(e={level:6});var t=new Uint8Array(50+Math.floor(i.length*1.1)),r=m.F.deflateRaw(i,t,r,e.level);return new Uint8Array(t.buffer,0,r)};m.encode=function(i,e){e==null&&(e=!1);var t=0,r=m.bin.writeUint,n=m.bin.writeUshort,s={};for(var o in i){var a=!m._noNeed(o)&&!e,l=i[o],d=m.crc.crc(l,0,l.length);s[o]={cpr:a,usize:l.length,crc:d,file:a?m.deflateRaw(l):l}}for(var o in s)t+=s[o].file.length+30+46+2*m.bin.sizeUTF8(o);t+=22;var c=new Uint8Array(t),h=0,u=[];for(var o in s){var p=s[o];u.push(h),h=m._writeHeader(c,h,o,p,0)}var f=0,g=h;for(var o in s){var p=s[o];u.push(h),h=m._writeHeader(c,h,o,p,1,u[f++])}var y=h-g;return r(c,h,101010256),h+=4,h+=4,n(c,h,f),h+=2,n(c,h,f),h+=2,r(c,h,y),h+=4,r(c,h,g),h+=4,h+=2,c.buffer};m._noNeed=function(i){var e=i.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(e)!=-1};m._writeHeader=function(i,e,t,r,n,s){var o=m.bin.writeUint,a=m.bin.writeUshort,l=r.file;o(i,e,n==0?67324752:33639248),e+=4,n==1&&(e+=2),a(i,e,20),e+=2,a(i,e,0),e+=2,a(i,e,r.cpr?8:0),e+=2,o(i,e,0),e+=4,o(i,e,r.crc),e+=4,o(i,e,l.length),e+=4,o(i,e,r.usize),e+=4,a(i,e,m.bin.sizeUTF8(t)),e+=2,a(i,e,0),e+=2,n==1&&(e+=2,e+=2,e+=6,o(i,e,s),e+=4);var d=m.bin.writeUTF8(i,e,t);return e+=d,n==0&&(i.set(l,e),e+=l.length),e};m.crc={table:function(){for(var i=new Uint32Array(256),e=0;e<256;e++){for(var t=e,r=0;r<8;r++)t&1?t=3988292384^t>>>1:t=t>>>1;i[e]=t}return i}(),update:function(i,e,t,r){for(var n=0;n<r;n++)i=m.crc.table[(i^e[t+n])&255]^i>>>8;return i},crc:function(i,e,t){return m.crc.update(4294967295,i,e,t)^4294967295}};m.adler=function(i,e,t){for(var r=1,n=0,s=e,o=e+t;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=i[s++],n+=r;r=r%65521,n=n%65521}return n<<16|r};m.bin={readUshort:function(i,e){return i[e]|i[e+1]<<8},writeUshort:function(i,e,t){i[e]=t&255,i[e+1]=t>>8&255},readUint:function(i,e){return i[e+3]*(256*256*256)+(i[e+2]<<16|i[e+1]<<8|i[e])},writeUint:function(i,e,t){i[e]=t&255,i[e+1]=t>>8&255,i[e+2]=t>>16&255,i[e+3]=t>>24&255},readASCII:function(i,e,t){for(var r="",n=0;n<t;n++)r+=String.fromCharCode(i[e+n]);return r},writeASCII:function(i,e,t){for(var r=0;r<t.length;r++)i[e+r]=t.charCodeAt(r)},pad:function(i){return i.length<2?"0"+i:i},readUTF8:function(i,e,t){for(var r="",n,s=0;s<t;s++)r+="%"+m.bin.pad(i[e+s].toString(16));try{n=decodeURIComponent(r)}catch{return m.bin.readASCII(i,e,t)}return n},writeUTF8:function(i,e,t){for(var r=t.length,n=0,s=0;s<r;s++){var o=t.charCodeAt(s);if(!(o&4294967295-128+1))i[e+n]=o,n++;else if(!(o&4294967295-2048+1))i[e+n]=192|o>>6,i[e+n+1]=128|o>>0&63,n+=2;else if(!(o&4294967295-65536+1))i[e+n]=224|o>>12,i[e+n+1]=128|o>>6&63,i[e+n+2]=128|o>>0&63,n+=3;else if(!(o&4294967295-(1<<21)+1))i[e+n]=240|o>>18,i[e+n+1]=128|o>>12&63,i[e+n+2]=128|o>>6&63,i[e+n+3]=128|o>>0&63,n+=4;else throw"e"}return n},sizeUTF8:function(i){for(var e=i.length,t=0,r=0;r<e;r++){var n=i.charCodeAt(r);if(!(n&4294967295-128+1))t++;else if(!(n&4294967295-2048+1))t+=2;else if(!(n&4294967295-65536+1))t+=3;else if(!(n&4294967295-(1<<21)+1))t+=4;else throw"e"}return t}};m.F={};m.F.deflateRaw=function(i,e,t,r){var n=[[0,0,0,0,0],[4,4,8,4,0],[4,5,16,8,0],[4,6,16,16,0],[4,10,16,32,0],[8,16,32,32,0],[8,16,128,128,0],[8,32,128,256,0],[32,128,258,1024,1],[32,258,258,4096,1]],s=n[r],o=m.F.U,a=m.F._goodIndex,l=m.F._hash,d=m.F._putsE,c=0,h=t<<3,u=0,p=i.length;if(r==0){for(;c<p;){var f=Math.min(65535,p-c);d(e,h,c+f==p?1:0),h=m.F._copyExact(i,c,f,e,h+8),c+=f}return h>>>3}var g=o.lits,y=o.strt,N=o.prev,w=0,x=0,I=0,G=0,Y=0,k=0;p>2&&(k=m.F._hash(i,0),y[k]=0);var M=0,V=0;for(c=0;c<p;c++){if(Y=k,c+1<p-2){k=m.F._hash(i,c+1);var z=c+1&32767;N[z]=y[k],y[k]=z}if(u<=c){(w>14e3||x>26697)&&p-c>100&&(u<c&&(g[w]=c-u,w+=2,u=c),h=m.F._writeBlock(c==p-1||u==p?1:0,g,w,G,i,I,c-I,e,h),w=x=G=0,I=c);var U=0;c<p-2&&(U=m.F._bestMatch(i,c,N,Y,Math.min(s[2],p-c),s[3]));var f=U>>>16,X=U&65535;if(U!=0){var f=U>>>16,X=U&65535,J=a(f,o.of0);o.lhst[257+J]++;var B=a(X,o.df0);o.dhst[B]++,G+=o.exb[J]+o.dxb[B],g[w]=f<<23|c-u,g[w+1]=X<<16|J<<8|B,w+=2,u=c+f}else o.lhst[i[c]]++;x++}}for((I!=c||i.length==0)&&(u<c&&(g[w]=c-u,w+=2,u=c),h=m.F._writeBlock(1,g,w,G,i,I,c-I,e,h),w=0,x=0,w=x=G=0,I=c);h&7;)h++;return h>>>3};m.F._bestMatch=function(i,e,t,r,n,s){var o=e&32767,a=t[o],l=o-a+32768&32767;if(a==o||r!=m.F._hash(i,e-l))return 0;for(var d=0,c=0,h=Math.min(32767,e);l<=h&&--s!=0&&a!=o;){if(d==0||i[e+d]==i[e+d-l]){var u=m.F._howLong(i,e,l);if(u>d){if(d=u,c=l,d>=n)break;l+2<u&&(u=l+2);for(var p=0,f=0;f<u-2;f++){var g=e-l+f+32768&32767,y=t[g],N=g-y+32768&32767;N>p&&(p=N,a=g)}}}o=a,a=t[o],l+=o-a+32768&32767}return d<<16|c};m.F._howLong=function(i,e,t){if(i[e]!=i[e-t]||i[e+1]!=i[e+1-t]||i[e+2]!=i[e+2-t])return 0;var r=e,n=Math.min(i.length,e+258);for(e+=3;e<n&&i[e]==i[e-t];)e++;return e-r};m.F._hash=function(i,e){return(i[e]<<8|i[e+1])+(i[e+2]<<4)&65535};m.saved=0;m.F._writeBlock=function(i,e,t,r,n,s,o,a,l){var d=m.F.U,c=m.F._putsF,h=m.F._putsE,u,p,f,g,y,N,w,x,I;d.lhst[256]++,u=m.F.getTrees(),p=u[0],f=u[1],g=u[2],y=u[3],N=u[4],w=u[5],x=u[6],I=u[7];var G=(l+3&7?8-(l+3&7):0)+32+(o<<3),Y=r+m.F.contSize(d.fltree,d.lhst)+m.F.contSize(d.fdtree,d.dhst),k=r+m.F.contSize(d.ltree,d.lhst)+m.F.contSize(d.dtree,d.dhst);k+=14+3*w+m.F.contSize(d.itree,d.ihst)+(d.ihst[16]*2+d.ihst[17]*3+d.ihst[18]*7);for(var M=0;M<286;M++)d.lhst[M]=0;for(var M=0;M<30;M++)d.dhst[M]=0;for(var M=0;M<19;M++)d.ihst[M]=0;var V=G<Y&&G<k?0:Y<k?1:2;c(a,l,i),c(a,l+1,V),l+=3;var z=l;if(V==0){for(;l&7;)l++;l=m.F._copyExact(n,s,o,a,l)}else{var U,X;if(V==1&&(U=d.fltree,X=d.fdtree),V==2){m.F.makeCodes(d.ltree,p),m.F.revCodes(d.ltree,p),m.F.makeCodes(d.dtree,f),m.F.revCodes(d.dtree,f),m.F.makeCodes(d.itree,g),m.F.revCodes(d.itree,g),U=d.ltree,X=d.dtree,h(a,l,y-257),l+=5,h(a,l,N-1),l+=5,h(a,l,w-4),l+=4;for(var J=0;J<w;J++)h(a,l+J*3,d.itree[(d.ordr[J]<<1)+1]);l+=3*w,l=m.F._codeTiny(x,d.itree,a,l),l=m.F._codeTiny(I,d.itree,a,l)}for(var B=s,K=0;K<t;K+=2){for(var j=e[K],_=j>>>23,T=B+(j&(1<<23)-1);B<T;)l=m.F._writeLit(n[B++],U,a,l);if(_!=0){var Z=e[K+1],P=Z>>16,C=Z>>8&255,F=Z&255;l=m.F._writeLit(257+C,U,a,l),h(a,l,_-d.of0[C]),l+=d.exb[C],l=m.F._writeLit(F,X,a,l),c(a,l,P-d.df0[F]),l+=d.dxb[F],B+=_}}l=m.F._writeLit(256,U,a,l)}return l};m.F._copyExact=function(i,e,t,r,n){var s=n>>>3;return r[s]=t,r[s+1]=t>>>8,r[s+2]=255-r[s],r[s+3]=255-r[s+1],s+=4,r.set(new Uint8Array(i.buffer,e,t),s),n+(t+4<<3)};m.F.getTrees=function(){for(var i=m.F.U,e=m.F._hufTree(i.lhst,i.ltree,15),t=m.F._hufTree(i.dhst,i.dtree,15),r=[],n=m.F._lenCodes(i.ltree,r),s=[],o=m.F._lenCodes(i.dtree,s),a=0;a<r.length;a+=2)i.ihst[r[a]]++;for(var a=0;a<s.length;a+=2)i.ihst[s[a]]++;for(var l=m.F._hufTree(i.ihst,i.itree,7),d=19;d>4&&i.itree[(i.ordr[d-1]<<1)+1]==0;)d--;return[e,t,l,n,o,d,r,s]};m.F.getSecond=function(i){for(var e=[],t=0;t<i.length;t+=2)e.push(i[t+1]);return e};m.F.nonZero=function(i){for(var e="",t=0;t<i.length;t+=2)i[t+1]!=0&&(e+=(t>>1)+",");return e};m.F.contSize=function(i,e){for(var t=0,r=0;r<e.length;r++)t+=e[r]*i[(r<<1)+1];return t};m.F._codeTiny=function(i,e,t,r){for(var n=0;n<i.length;n+=2){var s=i[n],o=i[n+1];r=m.F._writeLit(s,e,t,r);var a=s==16?2:s==17?3:7;s>15&&(m.F._putsE(t,r,o,a),r+=a)}return r};m.F._lenCodes=function(i,e){for(var t=i.length;t!=2&&i[t-1]==0;)t-=2;for(var r=0;r<t;r+=2){var n=i[r+1],s=r+3<t?i[r+3]:-1,o=r+5<t?i[r+5]:-1,a=r==0?-1:i[r-1];if(n==0&&s==n&&o==n){for(var l=r+5;l+2<t&&i[l+2]==n;)l+=2;var d=Math.min(l+1-r>>>1,138);d<11?e.push(17,d-3):e.push(18,d-11),r+=d*2-2}else if(n==a&&s==n&&o==n){for(var l=r+5;l+2<t&&i[l+2]==n;)l+=2;var d=Math.min(l+1-r>>>1,6);e.push(16,d-3),r+=d*2-2}else e.push(n,0)}return t>>>1};m.F._hufTree=function(i,e,t){var r=[],n=i.length,s=e.length,o=0;for(o=0;o<s;o+=2)e[o]=0,e[o+1]=0;for(o=0;o<n;o++)i[o]!=0&&r.push({lit:o,f:i[o]});var a=r.length,l=r.slice(0);if(a==0)return 0;if(a==1){var d=r[0].lit,l=d==0?1:0;return e[(d<<1)+1]=1,e[(l<<1)+1]=1,1}r.sort(function(y,N){return y.f-N.f});var c=r[0],h=r[1],u=0,p=1,f=2;for(r[0]={lit:-1,f:c.f+h.f,l:c,r:h,d:0};p!=a-1;)u!=p&&(f==a||r[u].f<r[f].f)?c=r[u++]:c=r[f++],u!=p&&(f==a||r[u].f<r[f].f)?h=r[u++]:h=r[f++],r[p++]={lit:-1,f:c.f+h.f,l:c,r:h};var g=m.F.setDepth(r[p-1],0);for(g>t&&(m.F.restrictDepth(l,t,g),g=t),o=0;o<a;o++)e[(l[o].lit<<1)+1]=l[o].d;return g};m.F.setDepth=function(i,e){return i.lit!=-1?(i.d=e,e):Math.max(m.F.setDepth(i.l,e+1),m.F.setDepth(i.r,e+1))};m.F.restrictDepth=function(i,e,t){var r=0,n=1<<t-e,s=0;for(i.sort(function(a,l){return l.d==a.d?a.f-l.f:l.d-a.d}),r=0;r<i.length&&i[r].d>e;r++){var o=i[r].d;i[r].d=e,s+=n-(1<<t-o)}for(s=s>>>t-e;s>0;){var o=i[r].d;o<e?(i[r].d++,s-=1<<e-o-1):r++}for(;r>=0;r--)i[r].d==e&&s<0&&(i[r].d--,s++);s!=0&&console.log("debt left")};m.F._goodIndex=function(i,e){var t=0;return e[t|16]<=i&&(t|=16),e[t|8]<=i&&(t|=8),e[t|4]<=i&&(t|=4),e[t|2]<=i&&(t|=2),e[t|1]<=i&&(t|=1),t};m.F._writeLit=function(i,e,t,r){return m.F._putsF(t,r,e[i<<1]),r+e[(i<<1)+1]};m.F.inflate=function(i,e){var t=Uint8Array;if(i[0]==3&&i[1]==0)return e||new t(0);var r=m.F,n=r._bitsF,s=r._bitsE,o=r._decodeTiny,a=r.makeCodes,l=r.codes2map,d=r._get17,c=r.U,h=e==null;h&&(e=new t(i.length>>>2<<3));for(var u=0,p=0,f=0,g=0,y=0,N=0,w=0,x=0,I=0,G,Y;u==0;){if(u=n(i,I,1),p=n(i,I+1,2),I+=3,p==0){I&7&&(I+=8-(I&7));var k=(I>>>3)+4,M=i[k-4]|i[k-3]<<8;h&&(e=m.F._check(e,x+M)),e.set(new t(i.buffer,i.byteOffset+k,M),x),I=k+M<<3,x+=M;continue}if(h&&(e=m.F._check(e,x+(1<<17))),p==1&&(G=c.flmap,Y=c.fdmap,N=512-1,w=32-1),p==2){f=s(i,I,5)+257,g=s(i,I+5,5)+1,y=s(i,I+10,4)+4,I+=14;for(var V=I,z=0;z<38;z+=2)c.itree[z]=0,c.itree[z+1]=0;for(var U=1,z=0;z<y;z++){var X=s(i,I+z*3,3);c.itree[(c.ordr[z]<<1)+1]=X,X>U&&(U=X)}I+=3*y,a(c.itree,U),l(c.itree,U,c.imap),G=c.lmap,Y=c.dmap,I=o(c.imap,(1<<U)-1,f+g,i,I,c.ttree);var J=r._copyOut(c.ttree,0,f,c.ltree);N=(1<<J)-1;var B=r._copyOut(c.ttree,f,g,c.dtree);w=(1<<B)-1,a(c.ltree,J),l(c.ltree,J,G),a(c.dtree,B),l(c.dtree,B,Y)}for(;;){var K=G[d(i,I)&N];I+=K&15;var j=K>>>4;if(!(j>>>8))e[x++]=j;else{if(j==256)break;var _=x+j-254;if(j>264){var T=c.ldef[j-257];_=x+(T>>>3)+s(i,I,T&7),I+=T&7}var Z=Y[d(i,I)&w];I+=Z&15;var P=Z>>>4,C=c.ddef[P],F=(C>>>4)+n(i,I,C&15);for(I+=C&15,h&&(e=m.F._check(e,x+(1<<17)));x<_;)e[x]=e[x++-F],e[x]=e[x++-F],e[x]=e[x++-F],e[x]=e[x++-F];x=_}}}return e.length==x?e:e.slice(0,x)};m.F._check=function(i,e){var t=i.length;if(e<=t)return i;var r=new Uint8Array(Math.max(t<<1,e));return r.set(i,0),r};m.F._decodeTiny=function(i,e,t,r,n,s){for(var o=m.F._bitsE,a=m.F._get17,l=0;l<t;){var d=i[a(r,n)&e];n+=d&15;var c=d>>>4;if(c<=15)s[l]=c,l++;else{var h=0,u=0;c==16?(u=3+o(r,n,2),n+=2,h=s[l-1]):c==17?(u=3+o(r,n,3),n+=3):c==18&&(u=11+o(r,n,7),n+=7);for(var p=l+u;l<p;)s[l]=h,l++}}return n};m.F._copyOut=function(i,e,t,r){for(var n=0,s=0,o=r.length>>>1;s<t;){var a=i[s+e];r[s<<1]=0,r[(s<<1)+1]=a,a>n&&(n=a),s++}for(;s<o;)r[s<<1]=0,r[(s<<1)+1]=0,s++;return n};m.F.makeCodes=function(i,e){for(var t=m.F.U,r=i.length,n,s,o,a,l,d=t.bl_count,a=0;a<=e;a++)d[a]=0;for(a=1;a<r;a+=2)d[i[a]]++;var c=t.next_code;for(n=0,d[0]=0,s=1;s<=e;s++)n=n+d[s-1]<<1,c[s]=n;for(o=0;o<r;o+=2)l=i[o+1],l!=0&&(i[o]=c[l],c[l]++)};m.F.codes2map=function(i,e,t){for(var r=i.length,n=m.F.U,s=n.rev15,o=0;o<r;o+=2)if(i[o+1]!=0)for(var a=o>>1,l=i[o+1],d=a<<4|l,c=e-l,h=i[o]<<c,u=h+(1<<c);h!=u;){var p=s[h]>>>15-e;t[p]=d,h++}};m.F.revCodes=function(i,e){for(var t=m.F.U.rev15,r=15-e,n=0;n<i.length;n+=2){var s=i[n]<<e-i[n+1];i[n]=t[s]>>>r}};m.F._putsE=function(i,e,t){t=t<<(e&7);var r=e>>>3;i[r]|=t,i[r+1]|=t>>>8};m.F._putsF=function(i,e,t){t=t<<(e&7);var r=e>>>3;i[r]|=t,i[r+1]|=t>>>8,i[r+2]|=t>>>16};m.F._bitsE=function(i,e,t){return(i[e>>>3]|i[(e>>>3)+1]<<8)>>>(e&7)&(1<<t)-1};m.F._bitsF=function(i,e,t){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16)>>>(e&7)&(1<<t)-1};m.F._get17=function(i,e){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16)>>>(e&7)};m.F._get25=function(i,e){return(i[e>>>3]|i[(e>>>3)+1]<<8|i[(e>>>3)+2]<<16|i[(e>>>3)+3]<<24)>>>(e&7)};m.F.U=function(){var i=Uint16Array,e=Uint32Array;return{next_code:new i(16),bl_count:new i(16),ordr:[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],of0:[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999],exb:[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0],ldef:new i(32),df0:[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,65535,65535],dxb:[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0],ddef:new e(32),flmap:new i(512),fltree:[],fdmap:new i(32),fdtree:[],lmap:new i(32768),ltree:[],ttree:[],dmap:new i(32768),dtree:[],imap:new i(512),itree:[],rev15:new i(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new i(65536),prev:new i(32768)}}();(function(){for(var i=m.F.U,e=32768,t=0;t<e;t++){var r=t;r=(r&2863311530)>>>1|(r&1431655765)<<1,r=(r&3435973836)>>>2|(r&858993459)<<2,r=(r&4042322160)>>>4|(r&252645135)<<4,r=(r&4278255360)>>>8|(r&16711935)<<8,i.rev15[t]=(r>>>16|r<<16)>>>17}function n(s,o,a){for(;o--!=0;)s.push(0,a)}for(var t=0;t<32;t++)i.ldef[t]=i.of0[t]<<3|i.exb[t],i.ddef[t]=i.df0[t]<<4|i.dxb[t];n(i.fltree,144,8),n(i.fltree,255-143,9),n(i.fltree,279-255,7),n(i.fltree,287-279,8),m.F.makeCodes(i.fltree,9),m.F.codes2map(i.fltree,9,i.flmap),m.F.revCodes(i.fltree,9),n(i.fdtree,32,5),m.F.makeCodes(i.fdtree,5),m.F.codes2map(i.fdtree,5,i.fdmap),m.F.revCodes(i.fdtree,5),n(i.itree,19,0),n(i.ltree,286,0),n(i.dtree,30,0),n(i.ttree,320,0)})()});var ai=Ae(De());var He=i=>{let e=Math.floor((i-5)/7*100+.5)/100;return Math.floor((e*7+5)/7*256)/256},xt=i=>Math.floor((256*i+Math.floor(18.285714285714285))/256*7);var rr="UEsDBAoAAAAAAAAAIQBi7p1okAQAAJAEAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbDw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxUeXBlcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9jb250ZW50LXR5cGVzIj48RGVmYXVsdCBFeHRlbnNpb249InJlbHMiIENvbnRlbnRUeXBlPSJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtcGFja2FnZS5yZWxhdGlvbnNoaXBzK3htbCIvPjxEZWZhdWx0IEV4dGVuc2lvbj0ieG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24veG1sIi8+PE92ZXJyaWRlIFBhcnROYW1lPSIveGwvd29ya2Jvb2sueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc2hlZXQubWFpbit4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii94bC93b3Jrc2hlZXRzL3NoZWV0MS54bWwiIENvbnRlbnRUeXBlPSJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtb2ZmaWNlZG9jdW1lbnQuc3ByZWFkc2hlZXRtbC53b3Jrc2hlZXQreG1sIi8+PE92ZXJyaWRlIFBhcnROYW1lPSIveGwvdGhlbWUvdGhlbWUxLnhtbCIgQ29udGVudFR5cGU9ImFwcGxpY2F0aW9uL3ZuZC5vcGVueG1sZm9ybWF0cy1vZmZpY2Vkb2N1bWVudC50aGVtZSt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii94bC9zdHlsZXMueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc3R5bGVzK3htbCIvPjxPdmVycmlkZSBQYXJ0TmFtZT0iL3hsL3NoYXJlZFN0cmluZ3MueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LnNwcmVhZHNoZWV0bWwuc2hhcmVkU3RyaW5ncyt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii9kb2NQcm9wcy9jb3JlLnhtbCIgQ29udGVudFR5cGU9ImFwcGxpY2F0aW9uL3ZuZC5vcGVueG1sZm9ybWF0cy1wYWNrYWdlLmNvcmUtcHJvcGVydGllcyt4bWwiLz48T3ZlcnJpZGUgUGFydE5hbWU9Ii9kb2NQcm9wcy9hcHAueG1sIiBDb250ZW50VHlwZT0iYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LmV4dGVuZGVkLXByb3BlcnRpZXMreG1sIi8+PC9UeXBlcz5QSwMECgAAAAAAAAAhALVVMCNMAgAATAIAAAsAAABfcmVscy8ucmVsczw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxSZWxhdGlvbnNoaXBzIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvcGFja2FnZS8yMDA2L3JlbGF0aW9uc2hpcHMiPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDMiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvZXh0ZW5kZWQtcHJvcGVydGllcyIgVGFyZ2V0PSJkb2NQcm9wcy9hcHAueG1sIi8+PFJlbGF0aW9uc2hpcCBJZD0icklkMiIgVHlwZT0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzL21ldGFkYXRhL2NvcmUtcHJvcGVydGllcyIgVGFyZ2V0PSJkb2NQcm9wcy9jb3JlLnhtbCIvPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDEiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvb2ZmaWNlRG9jdW1lbnQiIFRhcmdldD0ieGwvd29ya2Jvb2sueG1sIi8+PC9SZWxhdGlvbnNoaXBzPlBLAwQKAAAAAAAAACEAunCeZsoGAADKBgAADwAAAHhsL3dvcmtib29rLnhtbDw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjx3b3JrYm9vayB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIiB4bWxuczpyPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzIiB4bWxuczptYz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL21hcmt1cC1jb21wYXRpYmlsaXR5LzIwMDYiIG1jOklnbm9yYWJsZT0ieDE1IHhyIHhyNiB4cjEwIHhyMiIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiIgeG1sbnM6eHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNC9yZXZpc2lvbiIgeG1sbnM6eHI2PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTYvcmV2aXNpb242IiB4bWxuczp4cjEwPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTYvcmV2aXNpb24xMCIgeG1sbnM6eHIyPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTUvcmV2aXNpb24yIj48ZmlsZVZlcnNpb24gYXBwTmFtZT0ieGwiIGxhc3RFZGl0ZWQ9IjciIGxvd2VzdEVkaXRlZD0iNyIgcnVwQnVpbGQ9IjIxMTI2Ii8+PHdvcmtib29rUHIgZGVmYXVsdFRoZW1lVmVyc2lvbj0iMTY2OTI1Ii8+PG1jOkFsdGVybmF0ZUNvbnRlbnQgeG1sbnM6bWM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9tYXJrdXAtY29tcGF0aWJpbGl0eS8yMDA2Ij48bWM6Q2hvaWNlIFJlcXVpcmVzPSJ4MTUiPjx4MTVhYzphYnNQYXRoIHVybD0iSDpcVFJFQlx0cmViLWV4cG9ydFx0ZW1wbGF0ZVwiIHhtbG5zOngxNWFjPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvYWMiLz48L21jOkNob2ljZT48L21jOkFsdGVybmF0ZUNvbnRlbnQ+PHhyOnJldmlzaW9uUHRyIHJldklETGFzdFNhdmU9IjAiIGRvY3VtZW50SWQ9Ijhfe0Q4NThGOUY3LTBEOTItNEFFNC04QTQyLTQ4MENCMzU5QjYyRH0iIHhyNjpjb2F1dGhWZXJzaW9uTGFzdD0iNDAiIHhyNjpjb2F1dGhWZXJzaW9uTWF4PSI0MCIgeHIxMDp1aWRMYXN0U2F2ZT0iezAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMH0iLz48Ym9va1ZpZXdzPjx3b3JrYm9va1ZpZXcgeFdpbmRvdz0iMCIgeVdpbmRvdz0iMCIgd2luZG93V2lkdGg9IjI0NTcwIiB3aW5kb3dIZWlnaHQ9IjExMTMwIiB4cjI6dWlkPSJ7REU0RTdEMzUtNDkyRC00MEQ3LTk5MjUtNDY0N0Y1ODdFMURFfSIvPjwvYm9va1ZpZXdzPjxzaGVldHM+PHNoZWV0IG5hbWU9IlNoZWV0MSIgc2hlZXRJZD0iMSIgcjppZD0icklkMSIvPjwvc2hlZXRzPjxjYWxjUHIgY2FsY0lkPSIxOTEwMjkiLz48ZXh0THN0PjxleHQgdXJpPSJ7MTQwQTcwOTQtMEUzNS00ODkyLTg0MzItQzREMkU1N0VERUI1fSIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiI+PHgxNTp3b3JrYm9va1ByIGNoYXJ0VHJhY2tpbmdSZWZCYXNlPSIxIi8+PC9leHQ+PC9leHRMc3Q+PC93b3JrYm9vaz5QSwMECgAAAAAAAAAhAIE+lJe6AgAAugIAABoAAAB4bC9fcmVscy93b3JrYm9vay54bWwucmVsczw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04IiBzdGFuZGFsb25lPSJ5ZXMiPz4NCjxSZWxhdGlvbnNoaXBzIHhtbG5zPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvcGFja2FnZS8yMDA2L3JlbGF0aW9uc2hpcHMiPjxSZWxhdGlvbnNoaXAgSWQ9InJJZDMiIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvc3R5bGVzIiBUYXJnZXQ9InN0eWxlcy54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQyIiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3RoZW1lIiBUYXJnZXQ9InRoZW1lL3RoZW1lMS54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQxIiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3dvcmtzaGVldCIgVGFyZ2V0PSJ3b3Jrc2hlZXRzL3NoZWV0MS54bWwiLz48UmVsYXRpb25zaGlwIElkPSJySWQ0IiBUeXBlPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzL3NoYXJlZFN0cmluZ3MiIFRhcmdldD0ic2hhcmVkU3RyaW5ncy54bWwiLz48L1JlbGF0aW9uc2hpcHM+UEsDBAoAAAAAAAAAIQACrURzpAMAAKQDAAAYAAAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHdvcmtzaGVldCB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIiB4bWxuczpyPSJodHRwOi8vc2NoZW1hcy5vcGVueG1sZm9ybWF0cy5vcmcvb2ZmaWNlRG9jdW1lbnQvMjAwNi9yZWxhdGlvbnNoaXBzIiB4bWxuczptYz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL21hcmt1cC1jb21wYXRpYmlsaXR5LzIwMDYiIG1jOklnbm9yYWJsZT0ieDE0YWMgeHIgeHIyIHhyMyIgeG1sbnM6eDE0YWM9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAwOS85L2FjIiB4bWxuczp4cj0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDE0L3JldmlzaW9uIiB4bWxuczp4cjI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNS9yZXZpc2lvbjIiIHhtbG5zOnhyMz0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDE2L3JldmlzaW9uMyIgeHI6dWlkPSJ7MEQ4RTVDQTItNUM5RS00RDRCLTk0QzUtRjM1QzA0MUYzOUJEfSI+PGRpbWVuc2lvbiByZWY9IkExIi8+PHNoZWV0Vmlld3M+PHNoZWV0VmlldyB0YWJTZWxlY3RlZD0iMSIgd29ya2Jvb2tWaWV3SWQ9IjAiLz48L3NoZWV0Vmlld3M+PHNoZWV0Rm9ybWF0UHIgZGVmYXVsdFJvd0hlaWdodD0iMTUiIHgxNGFjOmR5RGVzY2VudD0iMC4yNSIvPjxzaGVldERhdGEvPjxwYWdlTWFyZ2lucyBsZWZ0PSIwLjciIHJpZ2h0PSIwLjciIHRvcD0iMC43NSIgYm90dG9tPSIwLjc1IiBoZWFkZXI9IjAuMyIgZm9vdGVyPSIwLjMiLz48L3dvcmtzaGVldD5QSwMECgAAAAAAAAAhAMEXEL7GIAAAxiAAABMAAAB4bC90aGVtZS90aGVtZTEueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPGE6dGhlbWUgeG1sbnM6YT0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL2RyYXdpbmdtbC8yMDA2L21haW4iIG5hbWU9Ik9mZmljZSBUaGVtZSI+PGE6dGhlbWVFbGVtZW50cz48YTpjbHJTY2hlbWUgbmFtZT0iT2ZmaWNlIj48YTpkazE+PGE6c3lzQ2xyIHZhbD0id2luZG93VGV4dCIgbGFzdENscj0iMDAwMDAwIi8+PC9hOmRrMT48YTpsdDE+PGE6c3lzQ2xyIHZhbD0id2luZG93IiBsYXN0Q2xyPSJGRkZGRkYiLz48L2E6bHQxPjxhOmRrMj48YTpzcmdiQ2xyIHZhbD0iNDQ1NDZBIi8+PC9hOmRrMj48YTpsdDI+PGE6c3JnYkNsciB2YWw9IkU3RTZFNiIvPjwvYTpsdDI+PGE6YWNjZW50MT48YTpzcmdiQ2xyIHZhbD0iNDQ3MkM0Ii8+PC9hOmFjY2VudDE+PGE6YWNjZW50Mj48YTpzcmdiQ2xyIHZhbD0iRUQ3RDMxIi8+PC9hOmFjY2VudDI+PGE6YWNjZW50Mz48YTpzcmdiQ2xyIHZhbD0iQTVBNUE1Ii8+PC9hOmFjY2VudDM+PGE6YWNjZW50ND48YTpzcmdiQ2xyIHZhbD0iRkZDMDAwIi8+PC9hOmFjY2VudDQ+PGE6YWNjZW50NT48YTpzcmdiQ2xyIHZhbD0iNUI5QkQ1Ii8+PC9hOmFjY2VudDU+PGE6YWNjZW50Nj48YTpzcmdiQ2xyIHZhbD0iNzBBRDQ3Ii8+PC9hOmFjY2VudDY+PGE6aGxpbms+PGE6c3JnYkNsciB2YWw9IjA1NjNDMSIvPjwvYTpobGluaz48YTpmb2xIbGluaz48YTpzcmdiQ2xyIHZhbD0iOTU0RjcyIi8+PC9hOmZvbEhsaW5rPjwvYTpjbHJTY2hlbWU+PGE6Zm9udFNjaGVtZSBuYW1lPSJPZmZpY2UiPjxhOm1ham9yRm9udD48YTpsYXRpbiB0eXBlZmFjZT0iQ2FsaWJyaSBMaWdodCIgcGFub3NlPSIwMjBGMDMwMjAyMDIwNDAzMDIwNCIvPjxhOmVhIHR5cGVmYWNlPSIiLz48YTpjcyB0eXBlZmFjZT0iIi8+PGE6Zm9udCBzY3JpcHQ9IkpwYW4iIHR5cGVmYWNlPSLmuLjjgrTjgrfjg4Pjgq8gTGlnaHQiLz48YTpmb250IHNjcmlwdD0iSGFuZyIgdHlwZWZhY2U9IuunkeydgCDqs6DrlJUiLz48YTpmb250IHNjcmlwdD0iSGFucyIgdHlwZWZhY2U9Iuetiee6vyBMaWdodCIvPjxhOmZvbnQgc2NyaXB0PSJIYW50IiB0eXBlZmFjZT0i5paw57Sw5piO6auUIi8+PGE6Zm9udCBzY3JpcHQ9IkFyYWIiIHR5cGVmYWNlPSJUaW1lcyBOZXcgUm9tYW4iLz48YTpmb250IHNjcmlwdD0iSGViciIgdHlwZWZhY2U9IlRpbWVzIE5ldyBSb21hbiIvPjxhOmZvbnQgc2NyaXB0PSJUaGFpIiB0eXBlZmFjZT0iVGFob21hIi8+PGE6Zm9udCBzY3JpcHQ9IkV0aGkiIHR5cGVmYWNlPSJOeWFsYSIvPjxhOmZvbnQgc2NyaXB0PSJCZW5nIiB0eXBlZmFjZT0iVnJpbmRhIi8+PGE6Zm9udCBzY3JpcHQ9Ikd1anIiIHR5cGVmYWNlPSJTaHJ1dGkiLz48YTpmb250IHNjcmlwdD0iS2htciIgdHlwZWZhY2U9Ik1vb2xCb3JhbiIvPjxhOmZvbnQgc2NyaXB0PSJLbmRhIiB0eXBlZmFjZT0iVHVuZ2EiLz48YTpmb250IHNjcmlwdD0iR3VydSIgdHlwZWZhY2U9IlJhYXZpIi8+PGE6Zm9udCBzY3JpcHQ9IkNhbnMiIHR5cGVmYWNlPSJFdXBoZW1pYSIvPjxhOmZvbnQgc2NyaXB0PSJDaGVyIiB0eXBlZmFjZT0iUGxhbnRhZ2VuZXQgQ2hlcm9rZWUiLz48YTpmb250IHNjcmlwdD0iWWlpaSIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBZaSBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJUaWJ0IiB0eXBlZmFjZT0iTWljcm9zb2Z0IEhpbWFsYXlhIi8+PGE6Zm9udCBzY3JpcHQ9IlRoYWEiIHR5cGVmYWNlPSJNViBCb2xpIi8+PGE6Zm9udCBzY3JpcHQ9IkRldmEiIHR5cGVmYWNlPSJNYW5nYWwiLz48YTpmb250IHNjcmlwdD0iVGVsdSIgdHlwZWZhY2U9IkdhdXRhbWkiLz48YTpmb250IHNjcmlwdD0iVGFtbCIgdHlwZWZhY2U9IkxhdGhhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmMiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJPcnlhIiB0eXBlZmFjZT0iS2FsaW5nYSIvPjxhOmZvbnQgc2NyaXB0PSJNbHltIiB0eXBlZmFjZT0iS2FydGlrYSIvPjxhOmZvbnQgc2NyaXB0PSJMYW9vIiB0eXBlZmFjZT0iRG9rQ2hhbXBhIi8+PGE6Zm9udCBzY3JpcHQ9IlNpbmgiIHR5cGVmYWNlPSJJc2tvb2xhIFBvdGEiLz48YTpmb250IHNjcmlwdD0iTW9uZyIgdHlwZWZhY2U9Ik1vbmdvbGlhbiBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJWaWV0IiB0eXBlZmFjZT0iVGltZXMgTmV3IFJvbWFuIi8+PGE6Zm9udCBzY3JpcHQ9IlVpZ2giIHR5cGVmYWNlPSJNaWNyb3NvZnQgVWlnaHVyIi8+PGE6Zm9udCBzY3JpcHQ9Ikdlb3IiIHR5cGVmYWNlPSJTeWxmYWVuIi8+PGE6Zm9udCBzY3JpcHQ9IkFybW4iIHR5cGVmYWNlPSJBcmlhbCIvPjxhOmZvbnQgc2NyaXB0PSJCdWdpIiB0eXBlZmFjZT0iTGVlbGF3YWRlZSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJCb3BvIiB0eXBlZmFjZT0iTWljcm9zb2Z0IEpoZW5nSGVpIi8+PGE6Zm9udCBzY3JpcHQ9IkphdmEiIHR5cGVmYWNlPSJKYXZhbmVzZSBUZXh0Ii8+PGE6Zm9udCBzY3JpcHQ9Ikxpc3UiIHR5cGVmYWNlPSJTZWdvZSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJNeW1yIiB0eXBlZmFjZT0iTXlhbm1hciBUZXh0Ii8+PGE6Zm9udCBzY3JpcHQ9Ik5rb28iIHR5cGVmYWNlPSJFYnJpbWEiLz48YTpmb250IHNjcmlwdD0iT2xjayIgdHlwZWZhY2U9Ik5pcm1hbGEgVUkiLz48YTpmb250IHNjcmlwdD0iT3NtYSIgdHlwZWZhY2U9IkVicmltYSIvPjxhOmZvbnQgc2NyaXB0PSJQaGFnIiB0eXBlZmFjZT0iUGhhZ3NwYSIvPjxhOmZvbnQgc2NyaXB0PSJTeXJuIiB0eXBlZmFjZT0iRXN0cmFuZ2VsbyBFZGVzc2EiLz48YTpmb250IHNjcmlwdD0iU3lyaiIgdHlwZWZhY2U9IkVzdHJhbmdlbG8gRWRlc3NhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmUiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJTb3JhIiB0eXBlZmFjZT0iTmlybWFsYSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJUYWxlIiB0eXBlZmFjZT0iTWljcm9zb2Z0IFRhaSBMZSIvPjxhOmZvbnQgc2NyaXB0PSJUYWx1IiB0eXBlZmFjZT0iTWljcm9zb2Z0IE5ldyBUYWkgTHVlIi8+PGE6Zm9udCBzY3JpcHQ9IlRmbmciIHR5cGVmYWNlPSJFYnJpbWEiLz48L2E6bWFqb3JGb250PjxhOm1pbm9yRm9udD48YTpsYXRpbiB0eXBlZmFjZT0iQ2FsaWJyaSIgcGFub3NlPSIwMjBGMDUwMjAyMDIwNDAzMDIwNCIvPjxhOmVhIHR5cGVmYWNlPSIiLz48YTpjcyB0eXBlZmFjZT0iIi8+PGE6Zm9udCBzY3JpcHQ9IkpwYW4iIHR5cGVmYWNlPSLmuLjjgrTjgrfjg4Pjgq8iLz48YTpmb250IHNjcmlwdD0iSGFuZyIgdHlwZWZhY2U9IuunkeydgCDqs6DrlJUiLz48YTpmb250IHNjcmlwdD0iSGFucyIgdHlwZWZhY2U9Iuetiee6vyIvPjxhOmZvbnQgc2NyaXB0PSJIYW50IiB0eXBlZmFjZT0i5paw57Sw5piO6auUIi8+PGE6Zm9udCBzY3JpcHQ9IkFyYWIiIHR5cGVmYWNlPSJBcmlhbCIvPjxhOmZvbnQgc2NyaXB0PSJIZWJyIiB0eXBlZmFjZT0iQXJpYWwiLz48YTpmb250IHNjcmlwdD0iVGhhaSIgdHlwZWZhY2U9IlRhaG9tYSIvPjxhOmZvbnQgc2NyaXB0PSJFdGhpIiB0eXBlZmFjZT0iTnlhbGEiLz48YTpmb250IHNjcmlwdD0iQmVuZyIgdHlwZWZhY2U9IlZyaW5kYSIvPjxhOmZvbnQgc2NyaXB0PSJHdWpyIiB0eXBlZmFjZT0iU2hydXRpIi8+PGE6Zm9udCBzY3JpcHQ9IktobXIiIHR5cGVmYWNlPSJEYXVuUGVuaCIvPjxhOmZvbnQgc2NyaXB0PSJLbmRhIiB0eXBlZmFjZT0iVHVuZ2EiLz48YTpmb250IHNjcmlwdD0iR3VydSIgdHlwZWZhY2U9IlJhYXZpIi8+PGE6Zm9udCBzY3JpcHQ9IkNhbnMiIHR5cGVmYWNlPSJFdXBoZW1pYSIvPjxhOmZvbnQgc2NyaXB0PSJDaGVyIiB0eXBlZmFjZT0iUGxhbnRhZ2VuZXQgQ2hlcm9rZWUiLz48YTpmb250IHNjcmlwdD0iWWlpaSIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBZaSBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJUaWJ0IiB0eXBlZmFjZT0iTWljcm9zb2Z0IEhpbWFsYXlhIi8+PGE6Zm9udCBzY3JpcHQ9IlRoYWEiIHR5cGVmYWNlPSJNViBCb2xpIi8+PGE6Zm9udCBzY3JpcHQ9IkRldmEiIHR5cGVmYWNlPSJNYW5nYWwiLz48YTpmb250IHNjcmlwdD0iVGVsdSIgdHlwZWZhY2U9IkdhdXRhbWkiLz48YTpmb250IHNjcmlwdD0iVGFtbCIgdHlwZWZhY2U9IkxhdGhhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cmMiIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJPcnlhIiB0eXBlZmFjZT0iS2FsaW5nYSIvPjxhOmZvbnQgc2NyaXB0PSJNbHltIiB0eXBlZmFjZT0iS2FydGlrYSIvPjxhOmZvbnQgc2NyaXB0PSJMYW9vIiB0eXBlZmFjZT0iRG9rQ2hhbXBhIi8+PGE6Zm9udCBzY3JpcHQ9IlNpbmgiIHR5cGVmYWNlPSJJc2tvb2xhIFBvdGEiLz48YTpmb250IHNjcmlwdD0iTW9uZyIgdHlwZWZhY2U9Ik1vbmdvbGlhbiBCYWl0aSIvPjxhOmZvbnQgc2NyaXB0PSJWaWV0IiB0eXBlZmFjZT0iQXJpYWwiLz48YTpmb250IHNjcmlwdD0iVWlnaCIgdHlwZWZhY2U9Ik1pY3Jvc29mdCBVaWdodXIiLz48YTpmb250IHNjcmlwdD0iR2VvciIgdHlwZWZhY2U9IlN5bGZhZW4iLz48YTpmb250IHNjcmlwdD0iQXJtbiIgdHlwZWZhY2U9IkFyaWFsIi8+PGE6Zm9udCBzY3JpcHQ9IkJ1Z2kiIHR5cGVmYWNlPSJMZWVsYXdhZGVlIFVJIi8+PGE6Zm9udCBzY3JpcHQ9IkJvcG8iIHR5cGVmYWNlPSJNaWNyb3NvZnQgSmhlbmdIZWkiLz48YTpmb250IHNjcmlwdD0iSmF2YSIgdHlwZWZhY2U9IkphdmFuZXNlIFRleHQiLz48YTpmb250IHNjcmlwdD0iTGlzdSIgdHlwZWZhY2U9IlNlZ29lIFVJIi8+PGE6Zm9udCBzY3JpcHQ9Ik15bXIiIHR5cGVmYWNlPSJNeWFubWFyIFRleHQiLz48YTpmb250IHNjcmlwdD0iTmtvbyIgdHlwZWZhY2U9IkVicmltYSIvPjxhOmZvbnQgc2NyaXB0PSJPbGNrIiB0eXBlZmFjZT0iTmlybWFsYSBVSSIvPjxhOmZvbnQgc2NyaXB0PSJPc21hIiB0eXBlZmFjZT0iRWJyaW1hIi8+PGE6Zm9udCBzY3JpcHQ9IlBoYWciIHR5cGVmYWNlPSJQaGFnc3BhIi8+PGE6Zm9udCBzY3JpcHQ9IlN5cm4iIHR5cGVmYWNlPSJFc3RyYW5nZWxvIEVkZXNzYSIvPjxhOmZvbnQgc2NyaXB0PSJTeXJqIiB0eXBlZmFjZT0iRXN0cmFuZ2VsbyBFZGVzc2EiLz48YTpmb250IHNjcmlwdD0iU3lyZSIgdHlwZWZhY2U9IkVzdHJhbmdlbG8gRWRlc3NhIi8+PGE6Zm9udCBzY3JpcHQ9IlNvcmEiIHR5cGVmYWNlPSJOaXJtYWxhIFVJIi8+PGE6Zm9udCBzY3JpcHQ9IlRhbGUiIHR5cGVmYWNlPSJNaWNyb3NvZnQgVGFpIExlIi8+PGE6Zm9udCBzY3JpcHQ9IlRhbHUiIHR5cGVmYWNlPSJNaWNyb3NvZnQgTmV3IFRhaSBMdWUiLz48YTpmb250IHNjcmlwdD0iVGZuZyIgdHlwZWZhY2U9IkVicmltYSIvPjwvYTptaW5vckZvbnQ+PC9hOmZvbnRTY2hlbWU+PGE6Zm10U2NoZW1lIG5hbWU9Ik9mZmljZSI+PGE6ZmlsbFN0eWxlTHN0PjxhOnNvbGlkRmlsbD48YTpzY2hlbWVDbHIgdmFsPSJwaENsciIvPjwvYTpzb2xpZEZpbGw+PGE6Z3JhZEZpbGwgcm90V2l0aFNoYXBlPSIxIj48YTpnc0xzdD48YTpncyBwb3M9IjAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSIxMTAwMDAiLz48YTpzYXRNb2QgdmFsPSIxMDUwMDAiLz48YTp0aW50IHZhbD0iNjcwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48YTpncyBwb3M9IjUwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6bHVtTW9kIHZhbD0iMTA1MDAwIi8+PGE6c2F0TW9kIHZhbD0iMTAzMDAwIi8+PGE6dGludCB2YWw9IjczMDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSIxMDAwMDAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSIxMDUwMDAiLz48YTpzYXRNb2QgdmFsPSIxMDkwMDAiLz48YTp0aW50IHZhbD0iODEwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48L2E6Z3NMc3Q+PGE6bGluIGFuZz0iNTQwMDAwMCIgc2NhbGVkPSIwIi8+PC9hOmdyYWRGaWxsPjxhOmdyYWRGaWxsIHJvdFdpdGhTaGFwZT0iMSI+PGE6Z3NMc3Q+PGE6Z3MgcG9zPSIwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6c2F0TW9kIHZhbD0iMTAzMDAwIi8+PGE6bHVtTW9kIHZhbD0iMTAyMDAwIi8+PGE6dGludCB2YWw9Ijk0MDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSI1MDAwMCI+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnNhdE1vZCB2YWw9IjExMDAwMCIvPjxhOmx1bU1vZCB2YWw9IjEwMDAwMCIvPjxhOnNoYWRlIHZhbD0iMTAwMDAwIi8+PC9hOnNjaGVtZUNscj48L2E6Z3M+PGE6Z3MgcG9zPSIxMDAwMDAiPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIj48YTpsdW1Nb2QgdmFsPSI5OTAwMCIvPjxhOnNhdE1vZCB2YWw9IjEyMDAwMCIvPjxhOnNoYWRlIHZhbD0iNzgwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48L2E6Z3NMc3Q+PGE6bGluIGFuZz0iNTQwMDAwMCIgc2NhbGVkPSIwIi8+PC9hOmdyYWRGaWxsPjwvYTpmaWxsU3R5bGVMc3Q+PGE6bG5TdHlsZUxzdD48YTpsbiB3PSI2MzUwIiBjYXA9ImZsYXQiIGNtcGQ9InNuZyIgYWxnbj0iY3RyIj48YTpzb2xpZEZpbGw+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiLz48L2E6c29saWRGaWxsPjxhOnByc3REYXNoIHZhbD0ic29saWQiLz48YTptaXRlciBsaW09IjgwMDAwMCIvPjwvYTpsbj48YTpsbiB3PSIxMjcwMCIgY2FwPSJmbGF0IiBjbXBkPSJzbmciIGFsZ249ImN0ciI+PGE6c29saWRGaWxsPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIi8+PC9hOnNvbGlkRmlsbD48YTpwcnN0RGFzaCB2YWw9InNvbGlkIi8+PGE6bWl0ZXIgbGltPSI4MDAwMDAiLz48L2E6bG4+PGE6bG4gdz0iMTkwNTAiIGNhcD0iZmxhdCIgY21wZD0ic25nIiBhbGduPSJjdHIiPjxhOnNvbGlkRmlsbD48YTpzY2hlbWVDbHIgdmFsPSJwaENsciIvPjwvYTpzb2xpZEZpbGw+PGE6cHJzdERhc2ggdmFsPSJzb2xpZCIvPjxhOm1pdGVyIGxpbT0iODAwMDAwIi8+PC9hOmxuPjwvYTpsblN0eWxlTHN0PjxhOmVmZmVjdFN0eWxlTHN0PjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdC8+PC9hOmVmZmVjdFN0eWxlPjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdC8+PC9hOmVmZmVjdFN0eWxlPjxhOmVmZmVjdFN0eWxlPjxhOmVmZmVjdExzdD48YTpvdXRlclNoZHcgYmx1clJhZD0iNTcxNTAiIGRpc3Q9IjE5MDUwIiBkaXI9IjU0MDAwMDAiIGFsZ249ImN0ciIgcm90V2l0aFNoYXBlPSIwIj48YTpzcmdiQ2xyIHZhbD0iMDAwMDAwIj48YTphbHBoYSB2YWw9IjYzMDAwIi8+PC9hOnNyZ2JDbHI+PC9hOm91dGVyU2hkdz48L2E6ZWZmZWN0THN0PjwvYTplZmZlY3RTdHlsZT48L2E6ZWZmZWN0U3R5bGVMc3Q+PGE6YmdGaWxsU3R5bGVMc3Q+PGE6c29saWRGaWxsPjxhOnNjaGVtZUNsciB2YWw9InBoQ2xyIi8+PC9hOnNvbGlkRmlsbD48YTpzb2xpZEZpbGw+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnRpbnQgdmFsPSI5NTAwMCIvPjxhOnNhdE1vZCB2YWw9IjE3MDAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOnNvbGlkRmlsbD48YTpncmFkRmlsbCByb3RXaXRoU2hhcGU9IjEiPjxhOmdzTHN0PjxhOmdzIHBvcz0iMCI+PGE6c2NoZW1lQ2xyIHZhbD0icGhDbHIiPjxhOnRpbnQgdmFsPSI5MzAwMCIvPjxhOnNhdE1vZCB2YWw9IjE1MDAwMCIvPjxhOnNoYWRlIHZhbD0iOTgwMDAiLz48YTpsdW1Nb2QgdmFsPSIxMDIwMDAiLz48L2E6c2NoZW1lQ2xyPjwvYTpncz48YTpncyBwb3M9IjUwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6dGludCB2YWw9Ijk4MDAwIi8+PGE6c2F0TW9kIHZhbD0iMTMwMDAwIi8+PGE6c2hhZGUgdmFsPSI5MDAwMCIvPjxhOmx1bU1vZCB2YWw9IjEwMzAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOmdzPjxhOmdzIHBvcz0iMTAwMDAwIj48YTpzY2hlbWVDbHIgdmFsPSJwaENsciI+PGE6c2hhZGUgdmFsPSI2MzAwMCIvPjxhOnNhdE1vZCB2YWw9IjEyMDAwMCIvPjwvYTpzY2hlbWVDbHI+PC9hOmdzPjwvYTpnc0xzdD48YTpsaW4gYW5nPSI1NDAwMDAwIiBzY2FsZWQ9IjAiLz48L2E6Z3JhZEZpbGw+PC9hOmJnRmlsbFN0eWxlTHN0PjwvYTpmbXRTY2hlbWU+PC9hOnRoZW1lRWxlbWVudHM+PGE6b2JqZWN0RGVmYXVsdHMvPjxhOmV4dHJhQ2xyU2NoZW1lTHN0Lz48YTpleHRMc3Q+PGE6ZXh0IHVyaT0iezA1QTRDMjVDLTA4NUUtNDM0MC04NUEzLUE1NTMxRTUxMERCMn0iPjx0aG0xNTp0aGVtZUZhbWlseSB4bWxuczp0aG0xNT0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2UvdGhlbWVtbC8yMDEyL21haW4iIG5hbWU9Ik9mZmljZSBUaGVtZSIgaWQ9Ins2MkY5MzlCNi05M0FGLTREQjgtOUM2Qi1ENkM3REZEQzU4OUZ9IiB2aWQ9Ins0QTNDNDZFOC02MUNDLTQ2MDMtQTU4OS03NDIyQTQ3QThFNEF9Ii8+PC9hOmV4dD48L2E6ZXh0THN0PjwvYTp0aGVtZT5QSwMECgAAAAAAAAAhAHmhgGxSBgAAUgYAAA0AAAB4bC9zdHlsZXMueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHN0eWxlU2hlZXQgeG1sbnM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9zcHJlYWRzaGVldG1sLzIwMDYvbWFpbiIgeG1sbnM6bWM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9tYXJrdXAtY29tcGF0aWJpbGl0eS8yMDA2IiBtYzpJZ25vcmFibGU9IngxNGFjIHgxNnIyIHhyIiB4bWxuczp4MTRhYz0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDA5LzkvYWMiIHhtbG5zOngxNnIyPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTUvMDIvbWFpbiIgeG1sbnM6eHI9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vb2ZmaWNlL3NwcmVhZHNoZWV0bWwvMjAxNC9yZXZpc2lvbiI+PGZvbnRzIGNvdW50PSIxIiB4MTRhYzprbm93bkZvbnRzPSIxIj48Zm9udD48c3ogdmFsPSIxMSIvPjxjb2xvciB0aGVtZT0iMSIvPjxuYW1lIHZhbD0iQ2FsaWJyaSIvPjxmYW1pbHkgdmFsPSIyIi8+PHNjaGVtZSB2YWw9Im1pbm9yIi8+PC9mb250PjwvZm9udHM+PGZpbGxzIGNvdW50PSIyIj48ZmlsbD48cGF0dGVybkZpbGwgcGF0dGVyblR5cGU9Im5vbmUiLz48L2ZpbGw+PGZpbGw+PHBhdHRlcm5GaWxsIHBhdHRlcm5UeXBlPSJncmF5MTI1Ii8+PC9maWxsPjwvZmlsbHM+PGJvcmRlcnMgY291bnQ9IjEiPjxib3JkZXI+PGxlZnQvPjxyaWdodC8+PHRvcC8+PGJvdHRvbS8+PGRpYWdvbmFsLz48L2JvcmRlcj48L2JvcmRlcnM+PGNlbGxTdHlsZVhmcyBjb3VudD0iMSI+PHhmIG51bUZtdElkPSIwIiBmb250SWQ9IjAiIGZpbGxJZD0iMCIgYm9yZGVySWQ9IjAiLz48L2NlbGxTdHlsZVhmcz48Y2VsbFhmcyBjb3VudD0iMSI+PHhmIG51bUZtdElkPSIwIiBmb250SWQ9IjAiIGZpbGxJZD0iMCIgYm9yZGVySWQ9IjAiIHhmSWQ9IjAiLz48L2NlbGxYZnM+PGNlbGxTdHlsZXMgY291bnQ9IjEiPjxjZWxsU3R5bGUgbmFtZT0iTm9ybWFsIiB4ZklkPSIwIiBidWlsdGluSWQ9IjAiLz48L2NlbGxTdHlsZXM+PGR4ZnMgY291bnQ9IjAiLz48dGFibGVTdHlsZXMgY291bnQ9IjAiIGRlZmF1bHRUYWJsZVN0eWxlPSJUYWJsZVN0eWxlTWVkaXVtMiIgZGVmYXVsdFBpdm90U3R5bGU9IlBpdm90U3R5bGVMaWdodDE2Ii8+PGV4dExzdD48ZXh0IHVyaT0ie0VCNzlERUYyLTgwQjgtNDNlNS05NUJELTU0Q0JEREY5MDIwQ30iIHhtbG5zOngxND0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2Uvc3ByZWFkc2hlZXRtbC8yMDA5LzkvbWFpbiI+PHgxNDpzbGljZXJTdHlsZXMgZGVmYXVsdFNsaWNlclN0eWxlPSJTbGljZXJTdHlsZUxpZ2h0MSIvPjwvZXh0PjxleHQgdXJpPSJ7OTI2MEE1MTAtRjMwMS00NmE4LTg2MzUtRjUxMkQ2NEJFNUY1fSIgeG1sbnM6eDE1PSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS9zcHJlYWRzaGVldG1sLzIwMTAvMTEvbWFpbiI+PHgxNTp0aW1lbGluZVN0eWxlcyBkZWZhdWx0VGltZWxpbmVTdHlsZT0iVGltZVNsaWNlclN0eWxlTGlnaHQxIi8+PC9leHQ+PC9leHRMc3Q+PC9zdHlsZVNoZWV0PlBLAwQKAAAAAAAAACEA0IywC4EAAACBAAAAFAAAAHhsL3NoYXJlZFN0cmluZ3MueG1sPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pg0KPHNzdCB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3NwcmVhZHNoZWV0bWwvMjAwNi9tYWluIi8+UEsDBAoAAAAAAAAAIQDcCx83XQIAAF0CAAARAAAAZG9jUHJvcHMvY29yZS54bWw8P3htbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJVVEYtOCIgc3RhbmRhbG9uZT0ieWVzIj8+DQo8Y3A6Y29yZVByb3BlcnRpZXMgeG1sbnM6Y3A9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9wYWNrYWdlLzIwMDYvbWV0YWRhdGEvY29yZS1wcm9wZXJ0aWVzIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOmRjdGVybXM9Imh0dHA6Ly9wdXJsLm9yZy9kYy90ZXJtcy8iIHhtbG5zOmRjbWl0eXBlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvIiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIj48ZGM6Y3JlYXRvcj5kdW5jYW48L2RjOmNyZWF0b3I+PGNwOmxhc3RNb2RpZmllZEJ5PmR1bmNhbjwvY3A6bGFzdE1vZGlmaWVkQnk+PGRjdGVybXM6Y3JlYXRlZCB4c2k6dHlwZT0iZGN0ZXJtczpXM0NEVEYiPjIwMTktMDEtMzFUMTY6NDg6MDNaPC9kY3Rlcm1zOmNyZWF0ZWQ+PGRjdGVybXM6bW9kaWZpZWQgeHNpOnR5cGU9ImRjdGVybXM6VzNDRFRGIj4yMDE5LTAxLTMxVDE2OjQ4OjI4WjwvZGN0ZXJtczptb2RpZmllZD48L2NwOmNvcmVQcm9wZXJ0aWVzPlBLAwQKAAAAAAAAACEAYUkJEBEDAAARAwAAEAAAAGRvY1Byb3BzL2FwcC54bWw8P3htbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJVVEYtOCIgc3RhbmRhbG9uZT0ieWVzIj8+DQo8UHJvcGVydGllcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL29mZmljZURvY3VtZW50LzIwMDYvZXh0ZW5kZWQtcHJvcGVydGllcyIgeG1sbnM6dnQ9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L2RvY1Byb3BzVlR5cGVzIj48QXBwbGljYXRpb24+TWljcm9zb2Z0IEV4Y2VsPC9BcHBsaWNhdGlvbj48RG9jU2VjdXJpdHk+MDwvRG9jU2VjdXJpdHk+PFNjYWxlQ3JvcD5mYWxzZTwvU2NhbGVDcm9wPjxIZWFkaW5nUGFpcnM+PHZ0OnZlY3RvciBzaXplPSIyIiBiYXNlVHlwZT0idmFyaWFudCI+PHZ0OnZhcmlhbnQ+PHZ0Omxwc3RyPldvcmtzaGVldHM8L3Z0Omxwc3RyPjwvdnQ6dmFyaWFudD48dnQ6dmFyaWFudD48dnQ6aTQ+MTwvdnQ6aTQ+PC92dDp2YXJpYW50PjwvdnQ6dmVjdG9yPjwvSGVhZGluZ1BhaXJzPjxUaXRsZXNPZlBhcnRzPjx2dDp2ZWN0b3Igc2l6ZT0iMSIgYmFzZVR5cGU9Imxwc3RyIj48dnQ6bHBzdHI+U2hlZXQxPC92dDpscHN0cj48L3Z0OnZlY3Rvcj48L1RpdGxlc09mUGFydHM+PENvbXBhbnk+PC9Db21wYW55PjxMaW5rc1VwVG9EYXRlPmZhbHNlPC9MaW5rc1VwVG9EYXRlPjxTaGFyZWREb2M+ZmFsc2U8L1NoYXJlZERvYz48SHlwZXJsaW5rc0NoYW5nZWQ+ZmFsc2U8L0h5cGVybGlua3NDaGFuZ2VkPjxBcHBWZXJzaW9uPjE2LjAzMDA8L0FwcFZlcnNpb24+PC9Qcm9wZXJ0aWVzPlBLAQIUAAoAAAAAAAAAIQBi7p1okAQAAJAEAAATAAAAAAAAAAAAAAAAAAAAAABbQ29udGVudF9UeXBlc10ueG1sUEsBAhQACgAAAAAAAAAhALVVMCNMAgAATAIAAAsAAAAAAAAAAAAAAAAAwQQAAF9yZWxzLy5yZWxzUEsBAhQACgAAAAAAAAAhALpwnmbKBgAAygYAAA8AAAAAAAAAAAAAAAAANgcAAHhsL3dvcmtib29rLnhtbFBLAQIUAAoAAAAAAAAAIQCBPpSXugIAALoCAAAaAAAAAAAAAAAAAAAAAC0OAAB4bC9fcmVscy93b3JrYm9vay54bWwucmVsc1BLAQIUAAoAAAAAAAAAIQACrURzpAMAAKQDAAAYAAAAAAAAAAAAAAAAAB8RAAB4bC93b3Jrc2hlZXRzL3NoZWV0MS54bWxQSwECFAAKAAAAAAAAACEAwRcQvsYgAADGIAAAEwAAAAAAAAAAAAAAAAD5FAAAeGwvdGhlbWUvdGhlbWUxLnhtbFBLAQIUAAoAAAAAAAAAIQB5oYBsUgYAAFIGAAANAAAAAAAAAAAAAAAAAPA1AAB4bC9zdHlsZXMueG1sUEsBAhQACgAAAAAAAAAhANCMsAuBAAAAgQAAABQAAAAAAAAAAAAAAAAAbTwAAHhsL3NoYXJlZFN0cmluZ3MueG1sUEsBAhQACgAAAAAAAAAhANwLHzddAgAAXQIAABEAAAAAAAAAAAAAAAAAID0AAGRvY1Byb3BzL2NvcmUueG1sUEsBAhQACgAAAAAAAAAhAGFJCRARAwAAEQMAABAAAAAAAAAAAAAAAAAArD8AAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAAAoACgCAAgAA60IAAAAA";var _t=i=>i!==null&&typeof i=="object"&&"row"in i&&"column"in i;var L=class i{start_;end_;constructor(e,t=e,r=!1){this.end_=this.PatchNull(t),this.start_=this.PatchNull(e),r&&this.Normalize()}static FromColumn(e){return new i({row:1/0,column:e})}static FromRow(e){return new i({row:e,column:1/0})}static ColumnToLabel(e){let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}static CellAddressToLabel(e,t=!1){return(t?`${e.sheet_id||0}!`:"")+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new i(e.start,e.end);for(let n of t)n&&(r.ConsumeAddress(n.start),r.ConsumeAddress(n.end));return r}static Bleed(e,t=1){return new i({row:Math.max(0,e.start.row-t),column:Math.max(0,e.start.column-t),sheet_id:e.start.sheet_id},{row:e.end.row+t,column:e.end.column+t})}static PatchArea(e,t){let{before_column:r,column_count:n,before_row:s,row_count:o}=t,a=new i(e.start,e.end),l=e.start.sheet_id;if(n&&r<=a.end.column){if(n>0)r<=a.start.column?a.Shift(0,n):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+n}):console.warn("AA X case 1",r,n,JSON.stringify(a));else if(n<0)if(r-n<=a.start.column)a.Shift(0,n);else{if(r<=a.start.column&&r-n>a.end.column)return!1;if(r<=a.start.column){let d=r-n-1;a=new i({row:a.start.row,column:d+1+n,sheet_id:l},{row:a.end.row,column:a.end.column+n})}else r<=a.end.column?r-n-1>=a.end.column?a=new i({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:r-1}):a=new i({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:a.start.column+a.columns+n-1}):console.warn("AA X case 2",r,n,JSON.stringify(a))}}if(o&&s<=a.end.row){if(o>0)s<=a.start.row?a.Shift(o,0):s>a.start.row&&s<=a.end.row?a.ConsumeAddress({row:a.end.row+o,column:a.end.column}):console.warn("AA X case 3",s,o,JSON.stringify(a));else if(o<0)if(s-o<=a.start.row)a.Shift(o,0);else{if(s<=a.start.row&&s-o>a.end.row)return!1;if(s<=a.start.row){let d=s-o-1;a=new i({column:a.start.column,row:d+1+o,sheet_id:l},{column:a.end.column,row:a.end.row+o})}else s<=a.end.row?s-o-1>=a.end.row?a=new i({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:s-1}):a=new i({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:a.start.row+a.rows+o-1}):console.warn("AA X case 4",s,o,JSON.stringify(a))}}return a}get start(){return{...this.start_}}set start(e){this.start_=e}get end(){return{...this.end_}}set end(e){this.end_=e}get rows(){return this.start_.row===1/0||this.end_.row===1/0?1/0:this.end_.row-this.start_.row+1}get columns(){return this.start_.column===1/0||this.end_.column===1/0?1/0:this.end_.column-this.start_.column+1}get count(){return this.rows*this.columns}get entire_sheet(){return this.entire_row&&this.entire_column}get entire_column(){return this.start_.row===1/0}get entire_row(){return this.start_.column===1/0}PatchNull(e){let t={...e};return t.row===null&&(t.row=1/0),t.column===null&&(t.column=1/0),t}SetSheetID(e){this.start_.sheet_id=e}Normalize(){let e={...this.start_},t={...this.end_};e.row===1/0||t.row===1/0?e.row=t.row=1/0:e.row>t.row&&(e.row=this.end_.row,e.absolute_row=this.end_.absolute_row,t.row=this.start_.row,t.absolute_row=this.start_.absolute_row),e.column===1/0||t.column===1/0?e.column=t.column=1/0:e.column>t.column&&(e.column=this.end_.column,e.absolute_column=this.end_.absolute_column,t.column=this.start_.column,t.absolute_column=this.start_.absolute_column),this.start_=e,this.end_=t}TopLeft(){let e={row:0,column:0};return this.entire_row||(e.column=this.start.column),this.entire_column||(e.row=this.start.row),e}BottomRight(){let e={row:0,column:0};return this.entire_row||(e.column=this.end.column),this.entire_column||(e.row=this.end.row),e}ContainsRow(e){return this.entire_column||e>=this.start_.row&&e<=this.end_.row}ContainsColumn(e){return this.entire_row||e>=this.start_.column&&e<=this.end_.column}Contains(e){return(this.entire_column||e.row>=this.start_.row&&e.row<=this.end_.row)&&(this.entire_row||e.column>=this.start_.column&&e.column<=this.end_.column)}ContainsArea(e){return this.start.column<=e.start.column&&this.end.column>=e.end.column&&this.start.row<=e.start.row&&this.end.row>=e.end.row}Intersects(e){return!(e.start.column>this.end.column||this.start.column>e.end.column||e.start.row>this.end.row||this.start.row>e.end.row)}Equals(e){return e.start_.row===this.start_.row&&e.start_.column===this.start_.column&&e.end_.row===this.end_.row&&e.end_.column===this.end_.column}Clone(){return new i(this.start,this.end)}Array(){if(this.entire_column||this.entire_row)throw new Error("can\'t convert infinite area to array");let e=new Array(this.rows*this.columns),t=this.start_.sheet_id,r=0;for(let n=this.start_.row;n<=this.end_.row;n++)for(let s=this.start_.column;s<=this.end_.column;s++)e[r++]={row:n,column:s,sheet_id:t};return e}get left(){let e=new i(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new i(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new i(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new i(this.start_,this.end_);return e.start_.row=e.end_.row,e}Shift(e,t){return this.start_.row+=e,this.start_.column+=t,this.end_.row+=e,this.end_.column+=t,this}ConsumeAddress(e){this.entire_row||(e.column<this.start_.column&&(this.start_.column=e.column),e.column>this.end_.column&&(this.end_.column=e.column)),this.entire_column||(e.row<this.start_.row&&(this.start_.row=e.row),e.row>this.end_.row&&(this.end_.row=e.row))}ConsumeArea(e){this.ConsumeAddress(e.start),this.ConsumeAddress(e.end)}Resize(e,t){return this.end_.row=this.start_.row+e-1,this.end_.column=this.start_.column+t-1,this}Iterate(e){if(this.entire_column||this.entire_row){console.warn("don\'t iterate infinite area");return}for(let t=this.start_.column;t<=this.end_.column;t++)for(let r=this.start_.row;r<=this.end_.row;r++)e({column:t,row:r,sheet_id:this.start_.sheet_id})}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=i.ColumnToLabel(this.start_.column),e+=":"+i.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=i.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+i.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var Ci=i=>typeof i=="object"&&!!i&&typeof i.real=="number"&&typeof i.imaginary=="number";var wt=i=>typeof i=="object"&&!!i&&typeof i.value=="number"&&typeof i.unit=="string",At=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var _e=i=>{switch(typeof i){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return i===null?0:Ci(i)?7:wt(i)?9:5;case"string":return i[0]==="="?1:2;default:return 6}};var te=class{static StringToColumn(e){let t=0;e=e.toUpperCase();for(let r=0;r<e.length;r++)t*=26,t+=e.charCodeAt(r)-64;return t-1}value;type=0;calculated;calculated_type;formatted;rendered_type;style;area;merge_area;table;renderer_data;render_clean=[];note;hyperlink;editing;render_function;click_function;validation;constructor(e,t){typeof e<"u"&&this.Set(e,t)}ValueIsNumber(){return this.type===3}ValueIsFormula(){return this.type===1}ValueIsBoolean(){return this.type===4}ValueIsComplex(){return this.type===7}FlushStyle(){this.formatted=this.rendered_type=this.style=void 0,this.render_clean=[]}FlushArray(){this.area=void 0}FlushCache(){this.calculated=this.calculated_type=this.formatted=this.rendered_type=this.render_function=this.click_function=void 0,this.render_clean=[]}Reset(){this.type=0,this.value=this.note=this.hyperlink=this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.area=this.renderer_data=this.render_function=this.click_function=void 0,this.render_clean=[]}Set(e,t=_e(e)){this.value=e,this.type=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=this.render_function=this.click_function=this.area=void 0,this.render_clean=[]}SetCalculatedValue(e,t=_e(e)){e===void 0&&(e=0,t=3),this.calculated!==e&&(this.calculated=e,this.calculated_type=t,this.formatted=this.rendered_type=void 0,this.render_clean=[])}GetValue(){return this.calculated_type?this.calculated:typeof this.value=="string"&&this.value[0]==="\'"?this.value.slice(1):this.value}GetValue4(){return this.calculated_type?{type:this.calculated_type,value:this.calculated}:this.type===1?{type:3,value:0}:{type:this.type,value:typeof this.value=="string"&&this.value[0]==="\'"?this.value.slice(1):this.value}}SetNote(e){this.note=e,this.render_clean=[]}SetCalculationError(e="ERR"){this.SetCalculatedValue(e,6)}SetArray(e){this.type=0,this.value=this.formatted=this.rendered_type=this.style=this.hyperlink=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}SetArrayHead(e,t){this.type=_e(t),this.value=t,this.formatted=this.rendered_type=this.style=this.calculated=this.calculated_type=void 0,this.area=e,this.render_clean=[]}};var Ii=i=>!i.cells,Ni=i=>!!i[0]&&Ii(i[0]),Si=i=>!!i[0]&&i[0].row!==void 0,Ti=At.map((i,e)=>({[i]:e})).reduce((i,e)=>({...i,...e}),{}),Je=class{data=[];rows_=0;columns_=0;get rows(){return this.rows_}get columns(){return this.columns_}EnsureRow(e){this.rows_=Math.max(e+1,this.rows_)}EnsureColumn(e){this.columns_=Math.max(e+1,this.columns_)}InsertColumns(e=0,t=1){let r=JSON.parse(JSON.stringify(this.data[13]));this.data=this.data.map(n=>{if(n.length>=e){let s=n.slice(0,e),o=e+t,a=n.slice(e);for(let l=0;l<a.length;l++)s[o++]=a[l];return s}return n}),this.columns_+=t}DeleteColumns(e,t=1){this.data.forEach(r=>r.splice(e,t)),this.columns_-=t}DeleteRows(e,t=1){this.data.splice(e,t),this.rows_-=t}InsertRows(e=0,t=1){let r=[e,0,[]];for(let n=1;n<t;n++)r.push([]);Array.prototype.splice.apply(this.data,r),this.rows_+=t}GetCell(e,t){let{row:r,column:n}=e;if(!this.data[r])if(t)this.data[r]=[],this.rows_=Math.max(this.rows_,r+1);else return;return this.data[r][n]||t&&(this.data[r][n]=new te,this.columns_=Math.max(this.columns_,n+1)),this.data[r][n]}EnsureCell(e){let{row:t,column:r}=e,n=this.data[t];n||(this.data[t]=n=[],this.rows_=Math.max(this.rows_,t+1));let s=n[r];return s||(s=n[r]=new te,this.columns_=Math.max(this.columns_,r+1)),s}FromArray(e=[],t=!1){this.data=[];let r=0,n=0;if(t){n=e.length;for(let s=0;s<n;s++){let o=e[s];r=Math.max(r,o.length);for(let a=0;a<o.length;a++)this.data[a]||(this.data[a]=[]),this.data[a][s]=new te(o[a])}}else{r=e.length;for(let s=0;s<r;s++){let o=[],a=e[s];n=Math.max(n,a.length);for(let l=0;l<a.length;l++)o[l]=new te(a[l]);this.data[s]=o}}this.rows_=r,this.columns_=n}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Ti[e]||void 0}ValueTypeToSerializedType(e){return e?At[e]:void 0}ImportDataValidation(e){if(typeof e.type=="number"){let t=["list","date","range","number","boolean"];if(e.type=t[e.type],!e.type)return}return e}FromJSON(e=[],t){if(this.data=[],!Ni(e)){let n=[];if(Si(e))for(let s of e)for(let o of s.cells)n.push({...o,row:s.row});else for(let s of e)for(let o of s.cells)n.push({...o,column:s.column});e=n}let r=[];for(let n of e){this.data[n.row]||(this.data[n.row]=[]);let s=new te(n.value);if(typeof n.calculated<"u"&&s.SetCalculatedValue(n.calculated,this.SerializedTypeToValueType(n.calculated_type)),t&&typeof n.style_ref<"u"&&(s.style=t[n.style_ref]),typeof n.note<"u"&&(s.note=n.note),typeof n.hyperlink<"u"&&(s.hyperlink=n.hyperlink),this.data[n.row][n.column]&&this.data[n.row][n.column].area&&(s.area=this.data[n.row][n.column].area),this.data[n.row][n.column]=s,n.area){let o=new L(n.area.start,n.area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let l=o.start.column;l<=o.end.column;l++)this.data[a]||(this.data[a]=[]),this.data[a][l]||(this.data[a][l]=new te),this.data[a][l].area=o}if(n.table&&r.push({...n.table}),n.merge_area){let o=new L(n.merge_area.start,n.merge_area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let l=o.start.column;l<=o.end.column;l++)this.data[a]||(this.data[a]=[]),this.data[a][l]||(this.data[a][l]=new te),this.data[a][l].merge_area=o}n.validation&&(s.validation=this.ImportDataValidation(n.validation))}for(let n of r)for(let s=n.area.start.row;s<=n.area.end.row;s++)for(let o=n.area.start.column;o<=n.area.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new te),this.data[s][o].table=n;this.rows_=this.data.length,this.columns_=this.data.reduce((n,s)=>Math.max(n,s.length),0)}toJSON(e={}){let t=0,r=0,n=this.data.length-1,s;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,n=e.subset.end.row);let o=[],a=-1,l=-1,d={},c={};for(let h=r;h<=n;h++)if(this.data[h]){let u=this.data[h];s=u.length-1,e.subset&&(s=e.subset.end.column);for(let p=t;p<=s;p++){let f=u[p],g=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===p,y=f&&f.area&&f.area.start.row===h&&f.area.start.column===p,N=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===p,w=f?f.type===2&&!f.value:!0;if(f&&(!w||e.preserve_empty_strings)&&(g||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||f.validation||e.decorated_cells&&f.style&&(f.style.fill||f.style.border_bottom||f.style.border_top||f.style.border_left||f.style.border_right))){let x={row:h,column:p,value:f.value};f.note&&(x.note=f.note),f.hyperlink&&(x.hyperlink=f.hyperlink),e.preserve_type&&(x.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(x.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(x.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(x.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&N&&e.tables&&(x.table=JSON.parse(JSON.stringify(f.table))),f.area&&y&&(x.area=f.area.toJSON()),f.merge_area&&(x.merge_area=f.merge_area.toJSON()),f.validation&&(x.validation=f.validation),e.cell_style_refs&&e.cell_style_refs[p]&&e.cell_style_refs[p][h]&&(x.style_ref=e.cell_style_refs[p][h],e.cell_style_refs[p][h]=0),d[h]=h,c[p]=p,a=Math.max(h,a),l=Math.max(p,l),o.push(x)}}}if(e.nested){let h=Object.keys(d),u=Object.keys(c);if(h.length<=u.length&&h.length){let p={},f=[];for(let g of o){let{row:y,...N}=g;p[g.row]||(p[g.row]=[]),p[g.row].push(N)}for(let g of h){let y=Number(g);f.push({row:y,cells:p[y]})}return{data:f,rows:a,columns:l+1}}else if(u.length){let p={},f=[];for(let g of o){let{column:y,...N}=g;p[g.column]||(p[g.column]=[]),p[g.column].push(N)}for(let g of u){let y=Number(g);f.push({column:y,cells:p[y]})}return{data:f,rows:a,columns:l+1}}}return{data:o,rows:a+1,columns:l+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize2(e,t){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),t.column===1/0&&(t={...t,column:this.columns_-1}),t.row===1/0&&(t={...t,row:this.rows_-1}),{from:e,to:t}}Normalize1(e){return e.column===1/0&&(e={...e,column:0}),e.row===1/0&&(e={...e,row:0}),e}RawValue(e,t=e){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].value:void 0;let r=[],n=this.data.slice(e.row,t.row+1),s=e.column,o=t.column+1;for(let a of n){let l=[];for(let d=s,c=0;d<o;d++,c++){let h=a[d];l.push(h?h.value:void 0)}r.push(l)}return r}GetRange(e,t,r=!1){if(t?{from:e,to:t}=this.Normalize2(e,t):e=this.Normalize1(e),!t||e===t||e.column===t.column&&e.row===t.row)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue():void 0;let n=[];if(r)for(let s=e.column;s<=t.column;s++){let o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][s]?o.push(this.data[a][s].GetValue()):o.push(void 0);n.push(o)}else for(let s=e.row;s<=t.row;s++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[s]&&this.data[s][a]?o.push(this.data[s][a].GetValue()):o.push(void 0);n.push(o)}return n}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize2(e,t),e.row===t.row&&e.column===t.column)return this.data[e.row]&&this.data[e.row][e.column]?this.data[e.row][e.column].GetValue4():{value:void 0,type:0};let n=[];if(r)for(let s=e.column;s<=t.column;s++){let o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][s]?o.push(this.data[a][s].GetValue4()):o.push({type:0});n.push(o)}else for(let s=e.row;s<=t.row;s++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[s]&&this.data[s][a]?o.push(this.data[s][a].GetValue4()):o.push({type:0});n.push(o)}return{type:8,value:n}}Apply(e,t,r=!1){if(_t(e)&&(e=new L(e)),e.entire_column||e.entire_row)throw new Error("don\'t iterate infinite cells");let n=e.start,s=e.end;if(r)for(let o=n.row;o<=s.row;o++){this.data[o]||(this.data[o]=[]);let a=this.data[o];for(let l=n.column;l<=s.column;l++)a[l]||(a[l]=new te),t(a[l],l,o)}else for(let o=n.row;o<=s.row;o++)if(this.data[o]){let a=this.data[o];for(let l=n.column;l<=s.column;l++)a[l]&&t(a[l],l,o)}}Apply2(e,t,r=!1){if(_t(e)&&(e=new L(e)),e.entire_column||e.entire_row)throw new Error("don\'t iterate infinite cells");let n=e.start,s=e.end;if(r)for(let o=n.row;o<=s.row;o++){this.data[o]||(this.data[o]=[]);let a=this.data[o];for(let l=n.column;l<=s.column;l++)if(a[l]||(a[l]=new te),!t(a[l],l,o))return}else for(let o=n.row;o<=s.row;o++)if(this.data[o]){let a=this.data[o];for(let l=n.column;l<=s.column;l++)if(a[l]&&!t(a[l],l,o))return}}SetArea(e,t){if(ArrayBuffer.isView(t))throw new Error("ABIV");if(Array.isArray(t))for(let r=e.start.row,n=0;r<=e.end.row;r++,n++){this.data[r]||(this.data[r]=[]);let s=this.data[r];if(t[n])for(let o=e.start.column,a=0;o<=e.end.column;o++,a++)s[o]||(s[o]=new te),s[o].Set(t[n][a])}else{let r=_e(t);for(let n=e.start.row;n<=e.end.row;n++){this.data[n]||(this.data[n]=[]);let s=this.data[n];for(let o=e.start.column;o<=e.end.column;o++)s[o]||(s[o]=new te),s[o].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}IterateAll(e){for(let t of this.data)if(t)for(let r of t)r&&e(r)}FlushCellStyles(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushStyle()}FlushCachedValues(){for(let e of this.data)if(e)for(let t of e)t&&t.FlushCache()}};var $=class{static locale="en-us";static decimal_separator=".";static argument_separator=",";static grouping_separator=",";static date_components={short_days:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],long_days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],short_months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],long_months:["January","February","March","April","May","June","July","August","September","October","November","December"]};static UpdateLocale(e){if(e)this.locale=e;else if(typeof self<"u"){let n=self?.document?.location;if(n&&n.search&&/locale=([^?&]+?)(?:\\?|$|&)/.test(n.search)){let s=n.search.match(/locale=(.*?)(?:\\?|$|&)/);s&&(this.locale=s[1]),console.info("override locale",this.locale)}else typeof navigator<"u"&&(navigator.languages&&navigator.languages[0]?this.locale=navigator.languages[0]:this.locale=navigator.language)}let t=new Intl.NumberFormat(this.locale,{minimumFractionDigits:1}).format(3.3).replace(/\\d/g,"");this.decimal_separator=t===","?",":".",this.decimal_separator===","?(this.argument_separator=";",this.grouping_separator=" "):(this.argument_separator=",",this.grouping_separator=",");let r=new Date(2e3,0,2,12,0,0,0);this.UpdateDateComponent(0,0,r),r=new Date(2e3,1,7,12,0,0,0),this.UpdateDateComponent(1,1,r),r=new Date(2e3,2,7,12,0,0,0),this.UpdateDateComponent(2,2,r),r=new Date(2e3,3,5,12,0,0,0),this.UpdateDateComponent(3,3,r),r=new Date(2e3,4,4,12,0,0,0),this.UpdateDateComponent(4,4,r),r=new Date(2e3,5,2,12,0,0,0),this.UpdateDateComponent(5,5,r),r=new Date(2e3,6,1,12,0,0,0),this.UpdateDateComponent(6,6,r),r=new Date(2e3,7,1,12,0,0,0),this.UpdateDateComponent(7,-1,r),r=new Date(2e3,8,1,12,0,0,0),this.UpdateDateComponent(8,-1,r),r=new Date(2e3,9,1,12,0,0,0),this.UpdateDateComponent(9,-1,r),r=new Date(2e3,10,1,12,0,0,0),this.UpdateDateComponent(10,-1,r),r=new Date(2e3,11,1,12,0,0,0),this.UpdateDateComponent(11,-1,r)}static UpdateDateComponent(e,t,r){t>=0&&(this.date_components.short_days[t]=r.toLocaleString(this.locale,{weekday:"short"}),this.date_components.long_days[t]=r.toLocaleString(this.locale,{weekday:"long"})),e>=0&&(this.date_components.short_months[e]=r.toLocaleString(this.locale,{month:"short"}),this.date_components.long_months[e]=r.toLocaleString(this.locale,{month:"long"}))}};$.UpdateLocale();var Zi=JSON.stringify({}),ve={DefaultProperties:{horizontal_align:"",vertical_align:"",number_format:"General",nan:"NaN",font_size:{unit:"pt",value:10.5},font_face:"sans-serif",bold:!1,italic:!1,underline:!1,strike:!1,text:{theme:1},border_top:0,border_left:0,border_right:0,border_bottom:0},CompositeBorders:i=>({top:{width:i.border_top||0,color:i.border_top_fill||{}},left:{width:i.border_left||0,color:i.border_left_fill||{}},right:{width:i.border_right||0,color:i.border_right_fill||{}},bottom:{width:i.border_bottom||0,color:i.border_bottom_fill||{}}}),Merge:(i,e,t=!0)=>{let r=t?{...i,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:i=>JSON.parse(JSON.stringify(i.reduce((e,t)=>({...e,...t}),{}))),Empty:i=>JSON.stringify(i)===Zi,ValidColor:i=>!!(i&&!i.none&&(i.text||i.theme||i.theme===0)),ParseFontSize:(i="",e="em")=>{let t=i.match(/(-*[\\d.]+)\\s*(\\S*)/);if(t){let r=Number(t[1]);if(!r||isNaN(r)||r<0)return{};let n=t[2].toLowerCase()||e;if(n==="pt"||n==="em"||n==="%"||n==="px")return{font_size:{unit:n,value:r}}}return{}},RelativeFontSize:(i,e)=>{let t=12,r=12;switch(i.font_size?.unit){case"pt":if(!i.font_size.value)return 1;r=i.font_size.value;break;case"px":if(!i.font_size.value)return 1;r=Math.round(i.font_size.value*300/4)/100;break;case"em":return i.font_size.value||1;case"%":return(i.font_size.value||100)/100;default:return 1}switch(e.font_size?.unit){case"pt":if(!e.font_size.value)return 1;t=e.font_size.value;break;case"px":if(!e.font_size.value)return 1;t=Math.round(e.font_size.value*300/4)/100;break;default:return 1}return r/t},FontSize:(i,e=!0)=>{let t=i.font_size?.value;switch(i.font_size?.unit){case"pt":return(t||12)+"pt";case"px":return e?Math.round((t||16)*300/4)/100+"pt":(t||16)+"px";case"em":return(t||1)+"em";case"%":return(t||100)+"%"}return""},Font:(i,e=1)=>{let t=[];return i.bold&&t.push("bold"),i.italic&&t.push("italic"),t.push(((i.font_size?.value||0)*e).toFixed(2)+(i.font_size?.unit||"pt")),t.push(i.font_face||""),t.join(" ")}};var ut=Ae(Et());var Vn={"<":"<",">":">","&":"&",""":\'"\',"'":"\'"},zn=/&\\w+;/g,Bn=i=>i.replace(zn,e=>Vn[e]||e);var Qe=Bn;var kr=(i,e)=>Qe(e),Wr={ignoreAttributes:!1,attributeNamePrefix:"__",trimValues:!1,textNodeName:"text__",tagValueProcessor:kr,ignoreDeclaration:!0},qe={ignoreAttributes:!1,attributesGroupName:"a$",attributeNamePrefix:"",textNodeName:"t$",trimValues:!1,ignoreDeclaration:!0,isArray:(i,e,t,r)=>/Relationship$/.test(i),tagValueProcessor:kr},R=class{static FindChild(e={},t){let r=t.split("/");for(let n of r)if(e=e[n],!e)return;return e}static FindAll(e={},t){let r=t.split("/");if(r[0]==="."&&r.shift(),r[0]==="..")throw new Error("invalid path (no access to parent)");if(r[0]==="")throw new Error("invalid path (no access to root)");if(r[0]==="**")throw new Error("ENOTIMPL");return this.FindAllTail(e,r)}static FindAllTail(e,t){if(Array.isArray(e))return e.reduce((r,n)=>r.concat(this.FindAllTail(n,t)),[]);for(let r=0;r<t.length;r++){let n=t[r];if(n==="*"?e=Object.keys(e).filter(s=>s!=="a$"&&s!=="t$").map(s=>e[s]):e=e[n],!e)return[];if(Array.isArray(e)){if(r===t.length-1||e.length===0)return e;let s=t.slice(1);return e.reduce((o,a)=>o.concat(this.FindAllTail(a,s)),[])}}return[e]}};var Ce=class{strings=[];reverse={};FromXML(e){this.strings=[],this.reverse={};let t=0;for(let r of R.FindAll(e,"sst/si")){if(r.t){let n="";typeof r.t=="string"?n=r.t:r.t.t$&&(n=r.t.t$),this.strings[t]=n,this.reverse[n]=t}else if(r.r){let s=R.FindAll(r.r,"t").map(o=>typeof o=="string"?o:o.t$||"").join("");this.strings[t]=s,this.reverse[s]=t}else console.warn(` ** unexpected shared string @ ${t}`),console.info(r);t++}}Get(e){return this.strings[e]}Ensure(e){e[0]==="\'"&&(e=e.substring(1));let t=this.reverse[e];return typeof t=="number"||(t=this.strings.length,this.strings.push(e),this.reverse[e]=t),t}};var be=class i{static color_map=["lt1","dk1","lt2","dk2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"];colors={};FromXML(e){let t=Object.keys(e)[0],r="",n=t.toString().match(/^(.*?):/);if(n&&(r=n[1]+":"),e[t]&&e[t][`${r}themeElements`]){let s=e[t][`${r}themeElements`][`${r}clrScheme`];for(let o of i.color_map){let a=s[`${r}${o}`],l,d="rgb";a[`${r}srgbClr`]?(d="rgb",l=a[`${r}srgbClr`].a$.val||""):a[`${r}sysClr`]&&(d="system",l=a[`${r}sysClr`].a$.lastClr||""),this.colors[o]={name:o,value:l,type:d}}}}};var he=class{date_format=!1;string_format=!1;fraction_format=!1;twelve_hour=!1;fraction_denominator=0;fraction_integer=!0;fraction_align=0;fraction_denominator_digits=0;integer_min_digits=0;decimal_min_digits=0;decimal_max_digits=0;grouping=!1;has_number_format=!1;prefix=[{text:""}];suffix=[{text:""}];scaling=0;percent=!1;exponential=!1;has_asterisk=!1};var Rr=42,Gr=95,kt=63,Ke=48,Mr=46,Wt=44,$r=37,Rt=34,We=35,Ur=59,et=92,Vr=64,Yn=91,jn=93,zr=69,Br=101,Dn=72,Hn=104,On=77,Jn=109,Xn=83,Qn=115,qn=68,Kn=100,es=89,ts=121,rs=65,is=97;var tt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new he;static preserve_formatting_characters=!1;static decimal_mark=Mr;static group_separator=Wt;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new he,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new he,this.sections=[this.current_section];this.char_index<this.characters.length;)this.ConsumeChar();return this.sections}static ConsumeString(){let e="";for(this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case et:this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index+1<this.characters.length&&(e+=this.pattern[++this.char_index]);break;case Rt:return this.preserve_formatting_characters&&(e+=this.pattern[this.char_index]),this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated string")}static ConsumeFormatting(){let e="";for(++this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case et:throw new Error("invalid escape character in formatting block");case jn:return this.char_index++,e;default:e+=this.pattern[this.char_index];break}throw new Error("unterminated format")}static ScanFractionFormat(){let e=/^([#?]+ +){0,1}([#?]+)\\/([#?0-9]+)(?:$|[^#?0-9])/,r=this.pattern.substr(this.char_index).match(e);if(!r)return!1;let n=(r[1]||"").length+r[2].length+r[3].length+1;this.current_section.fraction_format=!0,this.current_section.fraction_integer=!!r[1];let s=Number(r[3]);return isNaN(s)||(this.current_section.fraction_denominator=s),this.current_section.decimal_max_digits=this.current_section.fraction_denominator_digits=r[3].length,this.char_index+=n,this.current_section.has_number_format=!0,!0}static ConsumeNumberFormat(){let e=0;for(this.char_index;this.char_index<this.characters.length;this.char_index++)switch(this.characters[this.char_index]){case this.group_separator:{let r=!1;for(let n=this.char_index+1;!r&&n<this.characters.length;n++){let s=this.characters[n];if(s===this.decimal_mark||s===We||s===Ke)r=!0;else if(s!==Wt)break}if(r){if(e===1)throw new Error("invalid grouping in decimal part");this.current_section.grouping=!0}else this.current_section.scaling=(this.current_section.scaling||1)*1e3}break;case this.decimal_mark:if(e===1)throw new Error("too many decimal marks");e=1;break;case We:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case Ke:e===1?(this.current_section.decimal_max_digits++,this.current_section.decimal_min_digits=this.current_section.decimal_max_digits):this.current_section.integer_min_digits++;break;default:return}}static AppendCharAsText(e=!0){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=this.pattern[this.char_index]:this.current_section.prefix[this.current_section.prefix.length-1].text+=this.pattern[this.char_index],e&&this.char_index++}static AppendString(e){this.current_section.has_number_format?this.current_section.suffix[this.current_section.suffix.length-1].text+=e:this.current_section.prefix[this.current_section.prefix.length-1].text+=e}static AppendTextPart(e){this.current_section.has_number_format?(this.current_section.suffix.push(e),this.current_section.suffix.push({text:""})):(this.current_section.prefix.push(e),this.current_section.prefix.push({text:""}))}static ConsumeChar(){let e=this.characters[this.char_index];if(!((e===kt||e===We)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case Ur:this.char_index++,this.current_section=new he,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case Vr:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case Ke:case We:case Mr:case Wt:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case Yn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Rt:this.AppendString(this.ConsumeString());break;case kt:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Gr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case Rr:if(this.current_section.has_asterisk)throw new Error("we don\'t support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case Br:case zr:this.current_section.percent||this.current_section.exponential||this.current_section.string_format?this.AppendCharAsText():(this.current_section.exponential=!0,this.char_index++);break;case $r:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case et:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}static ParseDatePattern(){for(this.date_pattern=!0;this.date_pattern&&this.char_index<this.pattern.length;)this.DatePatternConsumeChar();if(this.date_pattern){this.date_pattern=!1;for(let e of this.sections)for(let t of e.prefix)t.flag&&t.flag&7&&(this.date_pattern=!0)}return this.date_pattern&&(this.sections[0].date_format=!0,this.sections[0].prefix.forEach((e,t)=>{if(e.flag===3&&(e.text==="mm"||e.text==="m")){if(t)for(let r=t-1;r;r--){let n=this.sections[0].prefix[r];if(n.flag===3){/h/i.test(n.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}if(t<this.sections[0].prefix.length-1)for(let r=t+1;r<this.sections[0].prefix.length;r++){let n=this.sections[0].prefix[r];if(n.flag===3){/s/i.test(n.text)&&(e.flag=4,e.text=e.text.toLowerCase());break}}}})),this.date_pattern}static ConsumeDatePart(){let e=this.pattern[this.char_index++],t=e.toLowerCase(),r={text:e,flag:3};for(;this.pattern[this.char_index]&&this.pattern[this.char_index].toLowerCase()===t;)r.text+=this.pattern[this.char_index++];if(t==="s"&&this.pattern[this.char_index]===".")for(r.text+=this.pattern[this.char_index++];this.pattern[this.char_index]==="0";)r.text+=this.pattern[this.char_index++];return r}static ConsumeAMPM(){let e=this.pattern.substr(this.char_index,5);if(e==="am/pm"||e==="AM/PM")return this.char_index+=5,this.sections[0].twelve_hour=!0,{text:e,flag:3};if(e=this.pattern.substr(this.char_index,3),e==="a/p"||e==="A/P")return this.char_index+=3,this.sections[0].twelve_hour=!0,{text:e,flag:3}}static DatePatternConsumeChar(){switch(this.characters[this.char_index]){case Ur:this.char_index=this.characters.length;break;case Ke:case We:case Br:case zr:case $r:case Vr:this.date_pattern=!1;break;case Dn:case Hn:case On:case Jn:case Xn:case Qn:case qn:case Kn:case es:case ts:this.AppendTextPart(this.ConsumeDatePart());break;case rs:case is:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Rt:this.AppendString(this.ConsumeString());break;case kt:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Gr:if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:1})}break;case Rr:if(this.current_section.has_asterisk)throw new Error("we don\'t support multiple asterisks");if(this.preserve_formatting_characters)this.AppendCharAsText();else{if(++this.char_index>=this.characters.length)throw new Error("invalid pad character at end");this.AppendTextPart({text:this.pattern[this.char_index++],flag:2}),this.current_section.has_asterisk=!0}break;case et:if(this.preserve_formatting_characters&&this.AppendCharAsText(!1),++this.char_index>=this.characters.length)throw new Error("invalid escape character at end");this.AppendCharAsText();break;default:this.AppendCharAsText()}}};var ns=i=>(i>=60&&i--,new Date(-22090752e5+864e5*i)),Lr=(i,e=!0)=>{if(e){let t=new Date(i),r=new Date;r.setUTCMilliseconds(t.getUTCMilliseconds()),r.setUTCSeconds(t.getUTCSeconds()),r.setUTCMinutes(t.getUTCMinutes()),r.setUTCHours(t.getHours()),r.setUTCDate(t.getDate()),r.setUTCMonth(t.getMonth()),r.setUTCFullYear(t.getFullYear()),i=r.getTime()}return i=(i+22090752e5)/864e5,i>=60&&i++,i},Ie=class i{static grouping_regexp=/\\d{1,3}(?=(\\d{3})+(?!\\d))/g;static fraction_limits=[9,99,999,9999];static imaginary_character="\\u{1D456}";static minus_character="-";magic_decimal=!1;transform_value;_pattern="";sections;decimal_zero_regexp=[];cloned=[];get pattern(){return this._pattern}get date_format(){return this.sections[0]&&this.sections[0].date_format}constructor(e){if(this._pattern=e,this.sections=tt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new he),this.sections[1]||(this.sections[1]={...this.sections[0]},this.sections[1].prefix=JSON.parse(JSON.stringify(this.sections[1].prefix)),this.sections[1].suffix=JSON.parse(JSON.stringify(this.sections[1].suffix)),this.sections[1].prefix.push({text:"-"}),this.cloned[1]=!0),this.sections[2]||(this.sections[2]={...this.sections[0]},this.cloned[2]=!0),!this.sections[3]){for(let t of this.sections[0].prefix)if(t.flag===5){this.sections[3]={...this.sections[0]},this.sections[3].string_format=!0,this.cloned[3]=!0;break}}this.decimal_zero_regexp=this.sections.map(t=>{if(t.decimal_max_digits>t.decimal_min_digits)return new RegExp(`0{1,${t.decimal_max_digits-t.decimal_min_digits}}(?:$|e)`)})}static FormatPartsAsText(e,t=0){let r=-1,n=e.map((s,o)=>{switch(s.flag){case 2:return r=o,s.text;case 1:return s.text.replace(/./g," ");case 6:return"";default:return s.text}});if(r>=0&&t){let s=n.reduce((a,l,d)=>d===r?a:a+l.length,0),o="";for(let a=0;a<t-s;a++)o+=n[r];n[r]=o}return n.join("")}SetDecimal(e){for(let t of this.sections)t.fraction_format||(t.decimal_min_digits=e,t.decimal_max_digits=e)}IncreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.min(e.fraction_denominator_digits+1,4)):(e.decimal_min_digits++,e.decimal_max_digits=e.decimal_min_digits)})}DecreaseDecimal(){this.sections.forEach(e=>{e.fraction_format?e.fraction_denominator||(e.fraction_denominator_digits=Math.max(e.fraction_denominator_digits-1,1)):(e.decimal_min_digits=Math.max(0,e.decimal_min_digits-1),e.decimal_max_digits=e.decimal_min_digits)})}AddGrouping(){this.sections.forEach(e=>{e.grouping=!0})}RemoveGrouping(){this.sections.forEach(e=>{e.grouping=!1})}ToggleGrouping(){let e=!this.sections[0].grouping;this.sections.forEach(t=>{t.grouping=e})}toString(){return this.sections[0].date_format?this._pattern:this.sections.filter((e,t)=>!this.cloned[t]).map(e=>{let t="",r=0;if(e.fraction_format){e.fraction_integer&&(t+="? ");let n="";for(let s=0;s<e.fraction_denominator_digits;s++)n+="#";t+=n,t+="/",e.fraction_denominator?t+=e.fraction_denominator:t+=n}else if(e.has_number_format){for(r=0;r<e.integer_min_digits;r++)t+="0";if(e.grouping&&(t.length<4&&(t=("####"+t).slice(-4)),t=t.replace(/[\\d#]{1,3}(?=([\\d#]{3})+(?![\\d#]))/g,"$&,")),e.decimal_max_digits||e.decimal_min_digits){for(t+=".",r=0;r<e.decimal_min_digits;r++)t+="0";for(;r<e.decimal_max_digits;r++)t+="#"}if(e.scaling){let n=Math.log10(e.scaling)/3;for(r=0;r<n;r++)t+=","}e.exponential&&(t+="e")}return e.prefix.map(n=>n.flag===1?n.text==="0"?"?":"_"+n.text:n.flag===2?"*"+n.text:n.flag===6?"["+n.text+"]":n.text).join("")+t+e.suffix.map(n=>n.flag===1?n.text==="0"?"?":"_"+n.text:n.flag===2?"*"+n.text:n.text).join("")}).join(";")}FormatDimensionedQuantity(e){if(this.transform_value){let r=this.transform_value(e);if(wt(r))e=r;else return typeof r=="string"?r:this.FormatParts(r)}let t=this.FormatParts(e.value||0);return e.unit&&t.push({text:" "},{text:e.unit}),t}FormatComplex(e){let t=[],r=[],n=!1,s=!!e.imaginary;s&&(t=this.FormatParts(e.imaginary),s=t.some(l=>/[1-9]/.test(l.text)),t.length===1&&this.sections[0].integer_min_digits<=1&&t[0].text==="1"?(t[0].text="",n=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",n=!0));let o=!!e.real;o&&(r=this.FormatParts(e.real),o=r.some(l=>/[1-9]/.test(l.text)));let a=[];if(o||!o&&!s){if(a.push(...r),s){let l=Math.abs(e.imaginary);a.push({text:e.imaginary<0?` ${i.minus_character} `:" + "});let d=n?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...d,{text:i.imaginary_character})}}else s&&a.push(...t,{text:i.imaginary_character});return a}FormatParts(e){if(typeof e!="number"&&!this.sections[3])return[{text:e.toString()}];let{parts:t,section:r}=this.BaseFormat(e),n=[];if(r.date_format||r.string_format)for(let s of t)typeof s=="string"?n.push({text:s}):n.push(s);else this.magic_decimal&&t[1]===""&&t.splice(1,1),n=[...r.prefix.map(s=>({...s})),{text:r.has_number_format?t.join($.decimal_separator):""},...r.suffix.map(s=>({...s}))];for(let s=1;s<n.length;s++)n[s].flag===n[s-1].flag&&(n[s].text=n[s-1].text+n[s].text,n[s-1].text="");return n.filter(s=>s.text)}Format(e,t=0){return i.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=ns(e),r=this.sections[0],n=t.getUTCHours();return r.twelve_hour&&(n>12&&(n-=12),n===0&&(n=12)),{parts:r.prefix.map(o=>{if(o.flag===4)return o.text==="mm"?{text:this.ZeroPad(t.getUTCMinutes().toString(),2)}:{text:this.ZeroPad(t.getUTCMinutes().toString(),1)};if(o.flag===3){switch(o.text.toLowerCase()){case"am/pm":case"a/p":{let l=o.text.split("/");return{text:t.getUTCHours()>12?l[1]:l[0]}}case"mmmmm":return{text:$.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:$.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:$.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:$.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:$.date_components.short_months[t.getUTCMonth()]};case"mm":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),2)};case"m":return{text:this.ZeroPad((t.getUTCMonth()+1).toString(),1)};case"ddddd":case"dddd":return o.text==="DDDDD"||o.text==="DDDD"?{text:$.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:$.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:$.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:$.date_components.short_days[t.getUTCDay()]};case"dd":return{text:this.ZeroPad(t.getUTCDate().toString(),2)};case"d":return{text:this.ZeroPad(t.getUTCDate().toString(),1)};case"yyyy":case"yyy":return{text:t.getUTCFullYear().toString()};case"yy":case"y":return{text:this.ZeroPad((t.getUTCFullYear()%100).toString(),2)};case"hh":return{text:this.ZeroPad(n.toString(),2)};case"h":return{text:this.ZeroPad(n.toString(),1)};case"ss":return{text:this.ZeroPad(t.getUTCSeconds().toString(),2)};case"s":return{text:this.ZeroPad(t.getUTCSeconds().toString(),1)}}let a=o.text.match(/^(s+)\\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+$.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),section:r}}StringFormat(e,t){let r=[];for(let n of t.prefix)n.flag===5?r.push({text:e}):r.push({...n});return{parts:r,section:t}}Round2(e,t){let r=Math.pow(10,t);return Math.round(r*e)/r}FormatFraction(e,t){t.percent&&(e*=100);let r={denominator:1,numerator:Math.round(e),error:Math.abs(Math.round(e)-e)};if(t.fraction_denominator)r.denominator=t.fraction_denominator,r.numerator=Math.round(e*r.denominator);else if(r.error){let s=i.fraction_limits[t.fraction_denominator_digits-1]||i.fraction_limits[0];for(let o=2;o<=s;o++){let a=Math.round(e*o),l=Math.abs(a/o-e);if(l<r.error&&(r={numerator:a,denominator:o,error:l},!l))break}}let n=[];if(t.fraction_integer){let s=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(s||!r.numerator)&&(n.push(s.toString()),r.numerator&&n.push(" "))}else r.numerator||n.push("0");return r.numerator&&(n.push(r.numerator.toString()),n.push("/"),n.push(r.denominator.toString())),n.join("")}BaseFormat(e){if(this.sections[0].date_format)return this.DateFormat(Number(e));if(typeof e!="number")return this.StringFormat(e.toString(),this.sections[3]);let t=this.sections[0],r=this.decimal_zero_regexp[0];e<0&&(t=this.sections[1]);let n=t.percent?t.decimal_max_digits+2:t.decimal_max_digits,s=Math.pow(10,-n)/2,o=Math.abs(e);if(o<s&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(o/=t.scaling,o<s&&(t=this.sections[2],r=this.decimal_zero_regexp[2])),t.string_format)return this.StringFormat(e.toString(),t);let a="";if(t.fraction_format)return{parts:[this.FormatFraction(o,t)],section:t};t.exponential?a=o.toExponential(t.decimal_max_digits):(t.percent&&(o*=100),a=this.Round2(o,t.decimal_max_digits).toFixed(t.decimal_max_digits)),r&&(a=a.replace(r,""));let l=a.split(".");for(;l[0].length<t.integer_min_digits;)l[0]=("0000000000000000"+l[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&l[0]==="0"&&(l[0]=""),t.grouping&&(l[0]=l[0].replace(i.grouping_regexp,"$&"+$.grouping_separator)),{parts:l,section:t}}};var Re=class{static cache={};static complex_general;static symbolc_name_map={};static base_formats={Accounting:"_(#,##0.00_);(#,##0.00);-???",Number:"0.00",Integer:"0",Percent:"0.00%",General:"0.######",Fraction:"# ?/?",Dollar:"$* _(#,##0.00_);$* (#,##0.00);$* -???",Exponential:"0.000e","Short Date":"mm/dd/yy","Long Date":"dddd, mmm d yyyy",Timestamp:"mm-dd-yy hh:mm:ss"};static aliases={Scientific:"Exponential",Percentage:"Percent",Currency:"Dollar"};static Get(e,t=!1){if(t&&e==="General")return this.complex_general;let r=this.symbolc_name_map[e.toLowerCase()],n=this.cache[r||e];return n||(n=new Ie(e),this.cache[e]=n),n}static Equals(e,t){if(e===t)return!0;let r=this.Get(e),n=this.Get(t);return r.pattern===n.pattern}static Translate(e){let t=this.symbolc_name_map[e.toLowerCase()];return t?this.cache[t].toString():e}static SymbolicName(e){for(let t of Object.keys(this.base_formats))if(e===this.base_formats[t])return t;return null}static InitCache(){for(let e of Object.keys(this.base_formats))this.cache[e]=new Ie(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new Ie("0.###"),this.complex_general.magic_decimal=!0;for(let e of Object.keys(this.aliases))this.cache[e]=this.cache[this.aliases[e]],this.symbolc_name_map[e.toLowerCase()]=e}};Re.InitCache();var Yr=new Date().getUTCFullYear(),Gt=class{compare_day;compare_month;TestDate(e){let t=Date.parse(e);if(isNaN(t))return!1;let r=new Date(t),s=e.replace(/[\\d\\-\\\\/,.\\s]+/g," ").toLocaleLowerCase().split(/\\s+/).map(l=>l.trim()).filter(l=>!!l);if(!s.length)return t;if(!this.compare_month){this.compare_month={};for(let l=0;l<12;l++)this.compare_month[$.date_components.long_months[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_month[$.date_components.short_months[l].toLocaleLowerCase().replace(/\\./,"")]=l}if(!this.compare_day){this.compare_day={};for(let l=0;l<7;l++)this.compare_day[$.date_components.long_days[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_day[$.date_components.short_days[l].toLocaleLowerCase().replace(/\\./,"")]=l}let o=!1,a=!1;for(let l of s){let d=!1;for(let[c,h]of Object.entries(this.compare_month))if(l===c){if(o||r.getUTCMonth()!==h)return!1;d=!0,o=!0}if(!d){for(let[c,h]of Object.entries(this.compare_day))if(l===c){if(a||r.getUTCDay()!==h)return!1;d=!0,a=!0}}if(!d)return!1}return a&&!o?!1:t}TryParse(e=""){let t={};if(e[0]==="\'")return{value:e,type:2};if(e==="")return{value:e,type:2};if(e==="NaN")return{value:NaN,type:3,hints:{Nan:!0}};let r=e.trim(),n=r.match(/^[$](.*?)$/);n&&(r=n[1],t.Currency=!0);let s=r.match(/^\\((.*?)\\)$/);s&&(r=s[1],t.Parens=!0);let o=r.match(/^(.*?)%\\s*$/);o&&(r=o[1],t.Percent=!0),$.decimal_separator==="."?/,/.test(r)&&(r=r.replace(/,/g,""),t.Grouping=!0):(r=r.replace(/(\\d)\\s+/g,"$1"),r=r.replace(/\\./g,""),r=r.replace(/,/,"."));let a=Number(r);if(a===null||isNaN(a)){let l=e.toLowerCase();if(l==="false")return{value:!1,type:4};if(l==="true")return{value:!0,type:4};let d=this.TestDate(e);if(d!==!1&&!isNaN(d)){let c=new Date(d),h=c.getUTCFullYear();if(h>=Yr-200&&h<=Yr+200)return t={Date:!0},(c.getHours()||c.getMinutes()||c.getSeconds())&&(t.Time=!0),{value:Lr(d),type:3,hints:t}}return{value:e,type:2}}if(s&&(a=-a),o){let l=a<0?-1:1,d=(l*a).toString().split(".");d[0]=("00"+d[0]).replace(/(\\d\\d)$/,".$1"),a=Number(d.join(""))*l}return/e/.test(e)&&(t.Exponential=!0),{value:a,type:3,hints:t}}},fo=new Gt;var Mt={top:{},left:{},bottom:{},right:{},diagonal:{}},Ne=class i{static default_styles={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"mm-dd-yy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yy h:mm",37:"#,##0 ;(#,##0)",38:"#,##0 ;[Red](#,##0)",39:"#,##0.00;(#,##0.00)",40:"#,##0.00;[Red](#,##0.00)",45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@"};theme=new be;cell_xfs=[];fonts=[];borders=[];fills=[];number_formats=[];base_number_format_id=200;dxf_styles=[];modified=!1;Clamp(e,t,r){return Math.max(t,Math.min(e,r))}TintColor(e,t){let r=parseInt(e.substr(0,2),16),n=parseInt(e.substr(2,2),16),s=parseInt(e.substr(4,2),16);return t<0?(r=Math.round(r*t+r),n=Math.round(n*t+n),s=Math.round(s*t+s)):(r=Math.round((255-r)*t+r),n=Math.round((255-n)*t+n),s=Math.round((255-s)*t+s)),[r,n,s].map(o=>{let a=this.Clamp(o,0,255).toString(16);return a.length<2?"0"+a:a}).join("")}StyleOptionsFromProperties(e){let t=JSON.parse(JSON.stringify(e));for(let d of Object.keys(t))t[d]==="none"&&delete t[d];let r={},n={pattern_type:"none"},s=JSON.parse(JSON.stringify(Mt)),o={font:r,border:s};t.number_format&&(o.number_format={format:Re.Translate(t.number_format),symbolic_name:t.number_format}),t.font_size?.unit&&t.font_size.value&&(t.font_size.unit!=="pt"?console.warn("can\'t handle non-point font (FIXME)"):r.size=t.font_size.value),t.bold&&(r.bold=!0),t.italic&&(r.italic=!0),t.underline&&(r.underline=!0),t.text&&(t.text.text?r.color_argb=t.text.text:typeof t.text.theme=="number"&&(r.color_theme=t.text.theme,t.text.tint&&(r.color_tint=t.text.tint)));let a=(d,c)=>{d.width&&(c.style="thin",d.color.text?c.rgba=d.color.text:typeof d.color.theme=="number"?(c.theme=d.color.theme,d.color.tint&&(c.tint=d.color.tint)):c.color=64)},l=ve.CompositeBorders(t);switch(a(l.top,s.top),a(l.left,s.left),a(l.right,s.right),a(l.bottom,s.bottom),t.vertical_align){case"top":o.vertical_alignment="top";break;case"middle":o.vertical_alignment="center";break}switch(t.horizontal_align){case"center":o.horizontal_alignment="center";break;case"left":o.horizontal_alignment="left";break;case"right":o.horizontal_alignment="right";break}return t.fill&&(n.pattern_type="solid",t.fill.text?(n.fg_color={argb:t.fill.text},o.fill=n):typeof t.fill.theme=="number"&&(n.fg_color={theme:t.fill.theme},t.fill.tint&&(n.fg_color.tint=t.fill.tint),o.fill=n)),t.wrap&&(o.wrap=!0),o}CellXfToStyle(e){let t={},r=i.default_styles[e.number_format];if(!r){for(let l of this.number_formats)if(l.id===e.number_format&&l.format){r=l.format;break}}if(r){let l=/\\[\\$(.)-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(l,"$1");let d=/\\[\\$-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(d,""),t.number_format=r}let n=this.fonts[0],s=this.fonts[e.font||0];s&&(s.bold&&(t.bold=!0),s.italic&&(t.italic=!0),s.underline&&(t.underline=!0),s.strike&&(t.strike=!0),n&&n.size&&s.size&&n.size!==s.size&&(t.font_size={value:100*s.size/n.size,unit:"%"}),s.color_argb?t.text={text:"#"+(s.color_argb.length>6?s.color_argb.substr(s.color_argb.length-6):s.color_argb)}:typeof s.color_theme=="number"&&(t.text={theme:s.color_theme}));let o=this.fills[e.fill||0];if(o&&o.pattern_type!=="none"){if(o.pattern_type==="gray"){let l=Math.round((o.pattern_gray||0)/1e3*255);t.fill={text:`rgb(${l}, ${l}, ${l})`}}o.pattern_type==="solid"&&o.fg_color&&(o.fg_color.argb?t.fill={text:"#"+(o.fg_color.argb.length>6?o.fg_color.argb.substr(o.fg_color.argb.length-6):o.fg_color.argb)}:typeof o.fg_color.theme=="number"&&(t.fill={theme:o.fg_color.theme},o.fg_color.tint&&(t.fill.tint=Math.round(o.fg_color.tint*1e3)/1e3)))}switch(e.horizontal_alignment){case"center":t.horizontal_align="center";break;case"right":t.horizontal_align="right";break;case"left":t.horizontal_align="left";break}switch(e.vertical_alignment){case"center":t.vertical_align="middle";break;case"top":t.vertical_align="top";break;case"bottom":t.vertical_align="bottom";break}e.wrap_text&&(t.wrap=!0);let a=this.borders[e.border||0];return a&&(a.bottom.style&&(a.bottom.style==="double"?t.border_bottom=2:t.border_bottom=1),a.left.style&&(t.border_left=1),a.top.style&&(t.border_top=1),a.right.style&&(t.border_right=1)),t}CellXfToStyles(){return this.cell_xfs.map(e=>this.CellXfToStyle(e))}EnsureNumberFormat(e){if(typeof e.format>"u"||e.symbolic_name&&/^general$/i.test(e.symbolic_name))return 0;for(let r=0;r<100;r++){let n=i.default_styles[r];if(n&&n===e.format)return r}for(let r of this.number_formats)if(r.format===e.format)return r.id||0;this.modified=!0;let t={id:this.base_number_format_id++,format:e.format};return this.number_formats.push(t),t.id}CompareBorderEdge(e,t){return e.color===t.color&&e.rgba===t.rgba&&e.style===t.style&&e.theme===t.theme&&e.tint===t.tint}CompareBorder(e,t){return this.CompareBorderEdge(e.top,t.top)&&this.CompareBorderEdge(e.left,t.left)&&this.CompareBorderEdge(e.bottom,t.bottom)&&this.CompareBorderEdge(e.right,t.right)&&this.CompareBorderEdge(e.diagonal,t.diagonal)}EnsureBorder(e){for(let r=0;r<this.borders.length;r++){let n=this.borders[r];if(this.CompareBorder(n,e))return r}this.modified=!0;let t=JSON.parse(JSON.stringify(e));return this.borders.push(t),this.borders.length-1}MatchColor(e,t){return!e&&!t?!0:!e||!t?!1:e.argb===t.argb&&e.indexed===t.indexed&&e.theme===t.theme&&e.tint===t.tint}EnsureFill(e){for(let r=0;r<this.fills.length;r++){let n=this.fills[r];if(this.MatchColor(e.bg_color,n.bg_color)&&this.MatchColor(e.fg_color,n.fg_color)&&e.pattern_gray===n.pattern_gray&&e.pattern_type===n.pattern_type)return r}this.modified=!0;let t={...e};return this.fills.push(t),this.fills.length-1}EnsureFont(e){let t={...this.fonts[0],...e};for(let r=0;r<this.fonts.length;r++){let n=this.fonts[r];if(n.bold===t.bold&&n.italic===t.italic&&n.underline===t.underline&&n.size===t.size&&n.strike===t.strike&&n.color_argb===t.color_argb&&n.color_theme===t.color_theme&&n.color_tint===t.color_tint&&n.family===t.family)return r}return this.modified=!0,this.fonts.push(t),this.fonts.length-1}EnsureStyle(e){let t=this.EnsureFont(e.font||{}),r=this.EnsureBorder(e.border||Mt),n=this.EnsureNumberFormat(e.number_format||{}),s=this.EnsureFill(e.fill||{pattern_type:"none"});for(let a=0;a<this.cell_xfs.length;a++){let l=this.cell_xfs[a];if(l.font===t&&l.fill===s&&l.border===r&&l.number_format===n&&!!l.wrap_text==!!e.wrap&&(!e.horizontal_alignment&&!l.horizontal_alignment||e.horizontal_alignment===l.horizontal_alignment)&&(!e.vertical_alignment&&!l.vertical_alignment||e.vertical_alignment===l.vertical_alignment))return a}this.modified=!0;let o={font:t,fill:s,border:r,number_format:n};return e.horizontal_alignment&&(o.horizontal_alignment=e.horizontal_alignment),e.vertical_alignment&&(o.vertical_alignment=e.vertical_alignment),e.wrap&&(o.wrap_text=!0),this.cell_xfs.push(o),this.cell_xfs.length-1}FromXML(e,t){let r=R.FindAll.bind(R,e);this.theme=t;let n=r("styleSheet/numFmts/numFmt");this.number_formats=n.map(d=>({id:Number(d.a$?.numFmtId||0),format:Qe(d.a$?.formatCode||"")})),n=r("styleSheet/borders/border"),this.borders=n.map(d=>{let c=JSON.parse(JSON.stringify(Mt));return d.left&&(c.left.style=d.left.a$.style,c.left.color=Number(d.left.color?.a$?.indexed)),d.right&&(c.right.style=d.right.a$.style,c.right.color=Number(d.right.color?.a$?.indexed)),d.top&&(c.top.style=d.top.a$.style,c.top.color=Number(d.top.color?.a$?.indexed)),d.bottom&&(c.bottom.style=d.bottom.a$.style,c.bottom.color=Number(d.bottom.color?.a$?.indexed)),c}),n=r("styleSheet/cellXfs/xf"),this.cell_xfs=n.map(d=>{let c={number_format:Number(d.a$.numFmtId),font:Number(d.a$.fontId),fill:Number(d.a$.fillId),border:Number(d.a$.borderId),xfid:Number(d.a$.xfId)};return d.alignment&&(c.horizontal_alignment=d.alignment.a$.horizontal,c.vertical_alignment=d.alignment.a$.vertical,c.wrap_text=!!d.alignment.a$.wrapText),c});let s=d=>{let c={pattern_type:"none"};if(d.patternFill){let h=d.patternFill.a$?.patternType;switch(h){case"none":case void 0:break;case"solid":c.pattern_type="solid",d.patternFill.fgColor&&(c.fg_color={theme:d.patternFill.fgColor.a$?.theme?Number(d.patternFill.fgColor.a$.theme):void 0,indexed:d.patternFill.fgColor.a$?.indexed?Number(d.patternFill.fgColor.a$.indexed):void 0,tint:d.patternFill.fgColor.a$?.tint?Number(d.patternFill.fgColor.a$.tint):void 0,argb:d.patternFill.fgColor.a$?.rgb});break;default:{let u=h?.match(/^gray(\\d+)$/);if(u){c.pattern_type="gray",c.pattern_gray=Number(u[1]);break}}}}return c};n=r("styleSheet/fills/fill"),this.fills=n.map(s);let o=d=>{let c={};return c.italic=typeof d.i<"u",c.bold=typeof d.b<"u",c.underline=typeof d.u<"u",c.strike=typeof d.strike<"u",d.sz&&(c.size=Number(d.sz.a$.val)),d.scheme&&(c.scheme=d.scheme.a$.val),d.name&&(c.name=d.name.a$.val),d.family&&(c.family=Number(d.family.a$.val)),d.color&&(d.color.a$?.theme&&(c.color_theme=Number(d.color.a$.theme)),d.color.a$?.tint&&(c.color_tint=Number(d.color.a$.tint)),d.color.a$?.rgb&&(c.color_argb=d.color.a$.rgb)),c};n=r("styleSheet/fonts/font"),this.fonts=n.map(o);let a=d=>{let c={};return d.a$.rgb?c.text="#"+d.a$.rgb.substring(2):d.a$.theme&&(c.theme=Number(d.a$.theme)||0,d.a$.tint&&(c.tint=Math.round(d.a$.tint*1e3)/1e3)),c},l=r("styleSheet/dxfs/dxf");this.dxf_styles=l.map(d=>{let c={};return d.font&&(c.bold=!!d.font.b,c.italic=!!d.font.i&&d.font.i.a$.val!=="0"),d.font?.color?.a$&&(c.text=a(d.font.color)),d.fill?.patternFill?.bgColor?.a$&&(c.fill=a(d.fill.patternFill.bgColor)),c})}};var ae=(i,e,t,r)=>{let s=`rId${Object.keys(i).length+1}`;return i[s]={id:s,type:e,target:t,mode:r},s};var Ht=/[\\s-+=<>!()]/;var $t=34,Ut=39,ss=160,jr=32,as=9,os=10,ls=13,ue=48,Ge=57,Vt=46,zt=43,Me=45,Dr=40,Bt=41,$e=44,cs=37,Lt=95,rt=36,ds=123,hs=125,Ue=91,Hr=93,us=33,Or=59,fs=35,ms=64,Se=65,Ve=97,ps=69,bs=101,it=90,nt=122,gs=105;var Yt=192,jt=312,Dt={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},ys=Object.keys(Dt).sort((i,e)=>e.length-i.length),xs={"-":100,"+":100},Te=class{argument_separator=",";decimal_mark=".";flags={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0};r1c1_regex=/[rR]((?:\\[[-+]{0,1}\\d+\\]|\\d+))[cC]((?:\\[[-+]{0,1}\\d+\\]|\\d+))$/;argument_separator_char=$e;decimal_mark_char=Vt;imaginary_char=gs;imaginary_number="i";id_counter=0;expression="";data=[];index=0;length=0;valid=!0;error_position;error;dependencies={addresses:{},ranges:{}};address_refcount={};full_reference_list=[];Walk(e,t){switch(e.type){case"address":case"missing":case"literal":case"complex":case"identifier":case"operator":case"structured-reference":t(e);return;case"dimensioned":t(e)&&(this.Walk(e.expression,t),this.Walk(e.unit,t));return;case"range":t(e)&&(this.Walk(e.start,t),this.Walk(e.end,t));return;case"binary":t(e)&&(this.Walk(e.left,t),this.Walk(e.right,t));return;case"unary":t(e)&&this.Walk(e.operand,t);return;case"group":t(e)&&e.elements.forEach(r=>this.Walk(r,t));return;case"call":t(e)&&e.args.forEach(r=>this.Walk(r,t))}}Transpose(e){let t=e.length,r=[],n=0;for(let s=0;s<t;s++)Array.isArray(e[s])&&(n=Math.max(n,e[s].length));for(let s=0;s<n;s++){r[s]=[];for(let o=0;o<t;o++)r[s][o]=e[o][s]}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},n=t.missing??"(missing)",{convert_decimal:s,convert_argument_separator:o,convert_imaginary_number:a,long_structured_references:l,table_name:d}=t,c=this.argument_separator+" ";o===","?c=", ":o===";"&&(c="; ");let h=this.imaginary_number;a&&(h=a);let u=s===","?",":".",p=this.decimal_mark===","?/,/:/\\./,f=this.decimal_mark===","?/,/g:/\\./g;switch(e.type){case"address":return this.AddressLabel(e,r);case"range":return this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return n;case"array":return"{"+this.Transpose(e.values).map(g=>g.map(y=>typeof y=="string"?\'"\'+y+\'"\':y).join(", ")).join("; ")+"}";case"binary":return this.Render(e.left,t)+" "+e.operator+" "+this.Render(e.right,t);case"unary":return e.operator+this.Render(e.operand,t);case"complex":if(e.text)return s?e.text.replace(f,u):e.text;{let g=Math.abs(e.imaginary).toString();if((s===","||this.decimal_mark===",")&&(g=g.replace(/\\./,",")),e.real){let y=e.real.toString();(s===","||this.decimal_mark===",")&&(y=y.replace(/\\./,","));let N=Math.abs(e.imaginary);return`${y}${e.imaginary<0?" - ":" + "}${N===1?"":g}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${g}i`}break;case"literal":if(typeof e.value=="string")return\'"\'+e.value.replace(/"/g,\'""\')+\'"\';if(s&&typeof e.value=="number")if(e.text){let g=e.text;return s===","&&this.decimal_mark==="."&&(g=g.replace(/,/g,"")),g.replace(p,u)}else return e.value.toString().replace(/\\./,u);else if(e.text)return e.text;return e.value.toString();case"identifier":return e.name;case"operator":return"["+e.operator+"]";case"group":return e.explicit?"("+e.elements.map(g=>this.Render(g,t)).join(c)+")":e.elements.map(g=>this.Render(g,t)).join(c);case"call":return e.name+"("+e.args.map(g=>this.Render(g,t)).join(c)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let g=e.column;/[^A-Za-z]/.test(g)&&(g="["+g+"]");let y=e.table;switch(!y&&l&&d&&(y=d),e.scope){case"all":return`${y}[[#all],${g}]`;case"row":return l?`${y}[[#this row],${g}]`:`${y}[@${g}]`;case"column":return`${y}[${g}]`}throw new Error("unhandled scope in structured reference")}}return"??"}Parse(e){switch(e=e.trim(),e[0]==="="&&(e=e.substr(1).trim()),this.expression=e,this.data=[],this.length=e.length,this.index=0,this.valid=!0,this.error_position=void 0,this.error=void 0,this.dependencies.addresses={},this.dependencies.ranges={},this.address_refcount={},this.full_reference_list=[],this.id_counter=0,this.argument_separator){case";":this.argument_separator_char=Or;break;default:this.argument_separator_char=$e;break}switch(this.decimal_mark){case",":this.decimal_mark_char=$e;break;default:this.decimal_mark_char=Vt;break}for(let n=0;n<this.length;n++)this.data[n]=e.charCodeAt(n);let t=this.ParseGeneric(),r={};for(let n of Object.keys(this.dependencies.addresses))this.address_refcount[n]&&(r[n]=this.dependencies.addresses[n]);return this.dependencies.addresses=r,{expression:t||void 0,valid:this.valid,error:this.error,error_position:this.error_position,dependencies:this.dependencies,separator:this.argument_separator,decimal_mark:this.decimal_mark,full_reference_list:this.full_reference_list.slice(0)}}ColumnLabel(e){if(e===1/0)return"";let t=String.fromCharCode(65+e%26);for(;e>25;)e=Math.floor(e/26)-1,t=String.fromCharCode(65+e%26)+t;return t}AddressLabel(e,t){let r=e.column;!e.absolute_column&&e.column!==1/0&&(r+=t.columns);let n=e.row;if(!e.absolute_row&&e.row!==1/0&&(n+=t.rows),n<0||r<0||n===1/0&&r===1/0)return"#REF";let s="";return e.sheet&&(s=(Ht.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!"),n===1/0?s+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?s+(e.absolute_row?"$":"")+(n+1):s+(e.absolute_column?"$":"")+this.ColumnLabel(r)+(e.absolute_row?"$":"")+(n+1)}ParseGeneric(e=[0]){let t=[];for(;this.index<this.length;){let r=this.ParseNext(t.length===0);if(typeof r=="number"){if(e.some(n=>r===n))break;if(r===Dr){this.index++;let n=this.ParseGeneric([Bt]);this.index++,n&&t.push({type:"group",id:this.id_counter++,elements:[n],explicit:!0})}else{let n=this.ConsumeOperator();n?t.push(n):(this.error=`unexpected character [1]: ${String.fromCharCode(r)}, 0x${r.toString(16)}`,this.valid=!1,this.index++)}}else t.push(r)}if(t.length){if(t=this.BinaryToRange2(t),this.flags.fractions){let r=[],n=o=>o.type==="literal"&&typeof o.value=="number"&&o.value%1===0,s=0;for(;s<t.length-3;s++)if(n(t[s])&&n(t[s+1])&&t[s+2].type==="operator"&&t[s+2].operator==="/"&&n(t[s+3])){let o=t[s],a=t[s+1],l=t[s+3],d=(o.value<0?-1:1)*(a.value/l.value);s+=3,r.push({id:t[s].id,type:"literal",text:this.expression.substring(o.position,l.position+1),value:o.value+d,position:o.position})}else r.push(t[s]);for(;s<t.length;s++)r.push(t[s]);t=r}if(t=t.map(r=>r.type==="identifier"&&r.name===this.imaginary_number?{type:"complex",real:0,imaginary:1,position:r.position,text:r.name,id:this.id_counter++}:r),this.flags.dimensioned_quantities){let r=[],n;for(let s=0;s<t.length;s++){let o=t[s];if(!n)n=o;else if(o.type==="identifier"&&(n.type==="literal"||n.type==="group"||n.type==="call")){let a=o;for(;t[s+1]?.type==="identifier";)a.name+=" "+t[++s].name;r.push({type:"dimensioned",expression:n,unit:o,id:this.id_counter++}),n=void 0}else r.push(n),n=o}n&&r.push(n),t=r}}return t.length===0?null:t.length===1?t[0]:this.BinaryToComplex(this.ArrangeUnits(t))}UnitToAddress(e){if(e.type==="literal"){if(typeof e.value=="number"&&e.value>0&&!/\\./.test(e.text||""))return{type:"address",position:e.position,label:e.value.toString(),row:e.value-1,id:this.id_counter++,column:1/0}}else{let t,r=e.name,n=r.split("!");if(n.length>1&&(t=n.slice(0,n.length-1).join("!"),r=r.substr(t.length+1),t[0]==="\'"))if(t.length>1&&t[t.length-1]==="\'")t=t.substr(1,t.length-2);else return;let s=r[0]==="$";r=(s?r.substr(1):r).toUpperCase();let o=Number(r);if(isNaN(o)){if(/[A-Z]{1,3}/.test(r)){let a=-1;for(let l=0;l<r.length;l++){let d=r[l].charCodeAt(0);a=26*(1+a)+(d-Se)}return{type:"address",position:e.position,absolute_column:s,label:e.name,column:a,id:this.id_counter++,row:1/0,sheet:t}}}else if(o>0&&o!==1/0&&!/\\./.test(r))return{type:"address",position:e.position,absolute_row:s,label:e.name,row:o-1,id:this.id_counter++,column:1/0,sheet:t}}}BinaryToRange2(e){let t=[];for(let r=0;r<e.length;r++){let n=e[r],s=e[r+1],o=e[r+2],a,l="",d;if(n&&s&&o&&s.type==="operator"&&s.operator===":"){if(n.type==="address"&&o.type==="address"){let c=n.position+n.label.length,h=o.position;a={type:"range",id:this.id_counter++,position:n.position,start:n,end:o,label:n.label+this.expression.substring(c,h)+o.label},l=a.start.label+":"+a.end.label,this.address_refcount[a.start.label]--,this.address_refcount[a.end.label]--;let u=[n.position,o.position];this.full_reference_list=this.full_reference_list.filter(p=>p.position!==u[0]&&p.position!==u[1])}else if((n.type==="literal"||n.type==="identifier")&&(o.type==="literal"||o.type==="identifier")){let c=this.UnitToAddress(n);if(!c&&n.type==="literal"&&typeof n.value=="number"&&n.value<0){let u={...n,text:(n.text||"").replace(/^-/,""),position:n.position+1,value:-n.value};c=this.UnitToAddress(u),c&&(d={type:"operator",operator:"-",position:n.position,id:this.id_counter++})}let h=this.UnitToAddress(o);c&&h&&(c.column===1/0&&h.column===1/0||c.row===1/0&&h.row===1/0)&&(l=c.label+":"+h.label,a={type:"range",id:this.id_counter++,position:c.position,start:c,end:h,label:l})}}a?(d&&t.push(d),t.push(a),this.dependencies.ranges[l]=a,this.full_reference_list.push(a),r+=2):t.push(n)}return t}BinaryToComplex(e){if(e.type==="binary")if((e.operator==="+"||e.operator==="-")&&e.left.type==="literal"&&typeof e.left.value=="number"&&e.right.type==="complex"&&!e.right.composited){let t="";t=this.expression.substring(e.left.position,e.right.position+(e.right.text?.length||0));let r=e.right.imaginary;return e.operator==="-"&&(r=-r),{type:"complex",position:e.left.position,text:t,id:this.id_counter++,imaginary:r,real:e.left.value,composited:!0}}else e.left=this.BinaryToComplex(e.left),e.right=this.BinaryToComplex(e.right);else if(e.type==="unary"&&(e.operator==="-"||e.operator==="+")&&e.operand.type==="complex"&&e.operand.text===this.imaginary_number)return{...e.operand,position:e.position,text:this.expression.substring(e.position,e.operand.position+(e.operand.text||"").length),imaginary:e.operand.imaginary*(e.operator==="-"?-1:1)};return e}BinaryToRangeX(e){if(e.type==="binary"){if(e.operator===":"){let t,r="";if(e.left.type==="address"&&e.right.type==="address"){let n=e.left.position+e.left.label.length,s=e.right.position;t={type:"range",id:this.id_counter++,position:e.left.position,start:e.left,end:e.right,label:e.left.label+this.expression.substring(n,s)+e.right.label},r=t.start.label+":"+t.end.label,this.address_refcount[t.start.label]--,this.address_refcount[t.end.label]--;let o=[e.left.position,e.right.position];this.full_reference_list=this.full_reference_list.filter(a=>a.position!==o[0]&&a.position!==o[1])}else if((e.left.type==="literal"||e.left.type==="identifier")&&(e.right.type==="literal"||e.right.type==="identifier")){let n=this.UnitToAddress(e.left),s=this.UnitToAddress(e.right);n&&s&&(n.column===1/0&&s.column===1/0||n.row===1/0&&s.row===1/0)&&(r=n.label+":"+s.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:n,end:s,label:r})}if(t)return this.dependencies.ranges[r]=t,this.full_reference_list.push(t),t;this.error="unexpected character: :",this.valid=!1}e.left=this.BinaryToRangeX(e.left),e.right=this.BinaryToRangeX(e.right)}return e}ArrangeUnits(e){if(e.length===0)return{type:"missing",id:this.id_counter++};if(e.length===1)return e[0];let t=[];for(let r=0;r<e.length;r++){let n=e[r];if(n.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(xs[n.operator]){let s=this.BinaryToComplex(this.ArrangeUnits(e.slice(r+1)));if(!this.valid)return{type:"group",id:this.id_counter++,elements:e,explicit:!1};s.type==="binary"?(s.left={type:"unary",id:this.id_counter++,operator:n.operator,operand:s.left,position:n.position},n=s):n={type:"unary",id:this.id_counter++,operator:n.operator,operand:s,position:n.position},r=e.length}else return this.error=`unexpected character [2]: ${n.operator}`,this.error_position=n.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1};else{t.push(n);continue}if(t.length<2)t.push(n);else if(t[t.length-1].type==="operator"){let s=t[t.length-2],o=t[t.length-1],a=o.operator,l={type:"binary",id:this.id_counter++,left:s,operator:a,position:o.position,right:n};s.type==="binary"&&Dt[a]>Dt[s.operator]&&(l.left=s.left,l.operator=s.operator,l.position=s.position,l.right={type:"binary",id:this.id_counter++,left:s.right,right:n,operator:a,position:o.position}),t.splice(-2,2,l)}else return this.error="multiple expressions",this.error_position=n.position,this.valid=!1,{type:"group",id:this.id_counter++,elements:e,explicit:!1}}return t[0]}ParseNext(e=!0){this.ConsumeWhiteSpace();let t=this.data[this.index];if(t===$t)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ue&&t<=Ge||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===ds)return this.ConsumeArray();if(e&&(t===Me||t===zt)){let r=this.data[this.index+1];if(r>=ue&&r<=Ge||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Se&&t<=it||t>=Ve&&t<=nt||t===Lt||t===fs||t===Ut||t===rt||t===Ue||t>=Yt&&t<=jt)return this.ConsumeToken(t);return t}ConsumeArray(){let e={type:"array",id:this.id_counter++,values:[],position:this.index};this.index++;let t=0,r=0;for(;this.index<this.length;){let n=this.ParseNext(),s=this.index;if(typeof n=="number")switch(this.index++,n){case Or:r++,t=0;break;case $e:t++;break;case hs:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=s,this.valid=!1);break}else switch(n.type){case"literal":e.values[t]||(e.values[t]=[]),e.values[t][r]=n.value;break;default:this.valid&&(this.error="invalid value in array literal",this.error_position=s,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of ys)if(this.expression.substr(this.index,e.length)===e){let t=this.index;return this.index+=e.length,{type:"operator",id:this.id_counter++,operator:e,position:t}}return null}ConsumeArguments(){this.index++;let e=0,t=[];for(;this.index<this.length;){let r=this.ParseGeneric([this.argument_separator_char,Bt]);r!==null&&t.push(r);let n=this.data[this.index];if(n===this.argument_separator_char){this.index++,e++;for(let s=t.length;s<e;s++)t.push({type:"missing",id:this.id_counter++})}else if(n===Bt)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,n=e===Ut,s=0,o=!1;for(e===Ue&&(s=1,o=!0),++this.index;this.index<this.length;this.index++){let c=this.data[this.index];if(c>=Se&&c<=it||c>=Ve&&c<=nt||c>=Yt&&c<=jt||c===Lt||c===rt||c===Vt||c===us||n||c>=ue&&c<=Ge||c===Ue||s>0&&c===Hr||c===Me&&this.flags.r1c1&&s===1||s>0&&c===ms&&this.data[this.index-1]===Ue||s===1&&(c===$e||c===jr)||s>1)t.push(c),c===Ue&&(s++,o=!0),c===Hr&&s--,c===Ut&&(n=!1);else break}let a=t.map(c=>String.fromCharCode(c)).join("");if(n)return this.error="unbalanced single quote",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:a,position:r};if(s)return this.error="unbalanced square bracket",this.error_position=r,this.valid=!1,{type:"identifier",id:this.id_counter++,name:a,position:r};if(a.toLowerCase()==="true")return{type:"literal",id:this.id_counter++,value:!0,position:r};if(a.toLowerCase()==="false")return{type:"literal",id:this.id_counter++,value:!1,position:r};if(this.ConsumeWhiteSpace(),this.data[this.index]===Dr){let c=this.ConsumeArguments();return{type:"call",id:this.id_counter++,name:a,args:c,position:r}}if(this.flags.spreadsheet_semantics){let c=this.ConsumeAddress(a,r);if(c)return c;if(o){let h=this.ConsumeStructuredReference(a,r);if(h)return h}}let d={type:"identifier",id:this.id_counter++,name:a,position:r};return this.full_reference_list.push(d),d}ConsumeStructuredReference(e,t){let r=t,n=e.length,s=e,o="",a=0;for(;a<n;a++){if(e[a]==="["){e=e.substring(a);break}o+=e[a]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let l=e.split(",").map(u=>u.trim()),d="column",c="";if(l.length>2)return;l.length===2?(/\\[#this row\\]/i.test(l[0])?d="row":/\\[#all\\]/i.test(l[0])&&(d="all"),c=l[1]):(c=l[0],c[0]==="@"&&(d="row",c=c.substring(1,c.length))),c[0]==="["&&c[c.length-1]==="]"&&(c=c.substring(1,c.length-1));let h={type:"structured-reference",id:this.id_counter++,label:s,position:t,scope:d,column:c,table:o};return this.full_reference_list.push(h),h}ConsumeAddress(e,t){let r=t,n=e.length,s,o=e.split("!");if(o.length>1&&(s=o.slice(0,o.length-1).join("!"),t+=s.length+1),this.flags.r1c1){let h=o[o.length-1].match(this.r1c1_regex);if(h){let u={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:s,r1c1:!0};return h[1][0]==="["?(u.offset_row=!0,u.row=Number(h[1].substring(1,h[1].length-1))):u.row=Number(h[1])-1,h[2][0]==="["?(u.offset_column=!0,u.column=Number(h[2].substring(1,h[2].length-1))):u.column=Number(h[2])-1,u}}let a=this.ConsumeAddressColumn(t);if(!a)return null;t=a.position;let l=this.ConsumeAddressRow(t);if(!l)return null;t=l.position;let d=s?s+e.substr(s.length,t-r).toUpperCase():e.substr(0,t-r).toUpperCase();s&&s[0]==="\'"&&(s=s.substr(1,s.length-2));let c={type:"address",id:this.id_counter++,label:d,row:l.row,column:a.column,absolute_row:l.absolute,absolute_column:a.absolute,position:r,sheet:s};return n!==t-r?null:(this.dependencies.addresses[c.label]=c,this.address_refcount[c.label]=(this.address_refcount[c.label]||0)+1,this.full_reference_list.push(c),c)}ConsumeAddressRow(e){let t=this.data[e]===rt;t&&e++;let r=e,n=0;for(;;e++){let s=this.data[e];if(s>=ue&&s<=Ge)n*=10,n+=s-ue;else break}return r===e?!1:{absolute:t,row:n-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,n=this.data[e]===rt;for(n&&e++;;e++,r++){if(r>=4)return!1;let s=this.data[e];if(s>=Se&&s<=it)t=26*(1+t)+(s-Se);else if(s>=Ve&&s<=nt)t=26*(1+t)+(s-Ve);else break}return t<0?!1:{absolute:n,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,n=!1,s=0,o=0,a=0,l="integer",d=0,c=!1,h=this.index;for(;this.index<this.length;this.index++,d++){let p=this.data[this.index];if(p===this.decimal_mark_char)if(l==="integer")l="fraction";else break;else if(p===cs){s/=100,a/=100,this.index++;break}else if(p===zt||p===Me)if(d===0)p===Me&&(n=!0);else break;else if(p===ps||p===bs)if(l==="integer"||l==="fraction")l="exponent",this.index<this.length-1&&(this.data[this.index+1]===zt?this.index++:this.data[this.index+1]===Me&&(this.index++,r=!0));else break;else if(p===this.imaginary_char){let f=this.data[this.index+1];if(f>=Se&&f<=it||f>=Ve&&f<=nt||f>=Yt&&f<=jt||f===Lt)break;if(l==="integer"||l==="fraction"){this.index++,c=!0;break}}else if(p>=ue&&p<=Ge)switch(l){case"integer":s=s*10+(p-ue);break;case"fraction":a=a*10+(p-ue),o++;break;case"exponent":t=t*10+(p-ue);break}else break}let u=s+a/Math.pow(10,o);return l==="exponent"&&(u=u*Math.pow(10,(r?-1:1)*t)),c?{type:"complex",id:this.id_counter++,position:e,imaginary:n?-u:u,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:n?-u:u,text:this.expression.substring(h,this.index)||""}}ConsumeString(){this.index++;let e=[];for(;this.index<this.length;this.index++){let t=this.data[this.index];if(t===$t&&(this.index++,this.index>=this.length||this.data[this.index]!==$t))break;e.push(t)}return e.map(t=>String.fromCharCode(t)).join("")}ConsumeWhiteSpace(){for(;this.index<this.length;){let e=this.data[this.index];if(e===jr||e===as||e===os||e===ls||e===ss)this.index++;else return}}};var Jr=class i{static _instance=new i;constructor(){}static get instance(){return this._instance}HTML(e){let t=[];for(let r of e){let n=[];for(let s of r)s.pre&&n.push("<pre>"),s.emphasis&&n.push("<em>"),s.strong&&n.push("<strong>"),s.strike&&n.push("<strike>"),n.push(s.text),s.strike&&n.push("</strike>"),s.strong&&n.push("</strong>"),s.emphasis&&n.push("</em>"),s.pre&&n.push("</pre>");t.push(n.join(""))}return t.join(`<br/>\n`)}Dummy(e=""){return e.split(/\\n/).map(t=>[{text:t}])}Parse(e=""){let t=this.Tokenize(e);for(let r=0;r<t.length;r++){let n=t[r];if(n.type==="delimeter"){let s=t[r-1],o=t[r+1],a=!s||s.type==="whitespace"||s.type==="newline",l=s&&s.type==="text"&&/[^\\w\\d]$/.test(s.text),d=!o||o.type==="whitespace"||o.type==="newline",c=o&&o.type==="text"&&/^[^\\w\\d]/.test(o.text);n.left_flanking=!d&&(!c||a),n.right_flanking=!a&&(!l||d||c)}}return this.ApplyFormatting(t),this.Consolidate(t)}IsWhitespace(e){return e===" "||e===" "}IsNewline(e){return e==="\\r"||e===`\n`}IsDelimeter(e){return e==="*"||e==="_"||e==="~"}Consolidate(e){let t=[],r={},n=[],s={type:"text",text:""};for(let o of e)if(o.type==="newline")s.text.length&&n.push(s),s={...r,text:"",type:"text"},t.push(n),n=[];else switch((!!r.strong!=!!o.strong||!!r.emphasis!=!!o.emphasis||!!r.strike!=!!o.strike)&&(r.strong=!!o.strong,r.emphasis=!!o.emphasis,r.strike=!!o.strike,s.text.length&&n.push(s),s={...r,text:"",type:"text"}),o.type){case"text":case"whitespace":s.text+=o.text;break;case"delimeter":for(let a=0;a<o.length;a++)s.text+=o.char;break}return s.text.length&&n.push(s),n.length&&t.push(n),t}ApplyFormatting(e,t){let r=0,n=e.length;for(r=0;r<n;r++){let s=e[r];if(s.type==="delimeter"){if(t&&s.right_flanking&&t.char===s.char&&s.length>0)return{index:r,token:s};if(s.left_flanking){let o=this.ApplyFormatting(e.slice(r+1),s);if(o.token){let a=Math.min(o.token.length,s.length),l=s.char==="~",d=!l&&!!(a%2),c=!l&&a>=2;for(let h=r+1;h<=r+o.index;h++)e[h].strong=!!e[h].strong||c,e[h].emphasis=!!e[h].emphasis||d,e[h].strike=!!e[h].strike||l;o.token.length-=a,s.length-=a,s.length>0?r--:r+=o.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,n=0,s=!1,o="";for(n=0;n<r;n++){let a=e[n];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(this.IsWhitespace(d))l+=d,n++;else break}t.push({type:"whitespace",text:l}),s=!1,o=""}else if(this.IsNewline(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(this.IsNewline(d))l+=d,n++;else break}t.push({type:"newline",text:l}),s=!1,o=""}else if(s)o+=a,s=!1;else if(this.IsDelimeter(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[n+1];if(d===a)l+=d,n++;else break}t.push({type:"delimeter",text:l,char:a,length:l.length}),s=!1,o=""}else a==="\\\\"?s=!0:o+=a}return o&&t.push({type:"text",text:o}),t}};var Xr={"c:tx":{"c:strRef":{"c:f":"","c:strCache":{"c:ptCount":{a$:{val:"1"}},"c:pt":{a$:{idx:"0"},"c:v":""}}}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},Qr={"c:tx":{"c:rich":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:r":{"a:rPr":{a$:{lang:""}},"a:t":""}}}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"1400",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",spc:"0",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},st={"c:chartSpace":{a$:{"xmlns:c":"http://schemas.openxmlformats.org/drawingml/2006/chart","xmlns:a":"http://schemas.openxmlformats.org/drawingml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:c16r2":"http://schemas.microsoft.com/office/drawing/2015/06/chart"},"c:date1904":{a$:{val:"0"}},"c:lang":{a$:{val:"en-US"}},"c:roundedCorners":{a$:{val:"0"}},"mc:AlternateContent":{a$:{"xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006"},"mc:Choice":{a$:{Requires:"c14","xmlns:c14":"http://schemas.microsoft.com/office/drawing/2007/8/2/chart"},"c14:style":{a$:{val:"102"}}},"mc:Fallback":{"c:style":{a$:{val:"2"}}}},"c:chart":{},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"bg1"}}},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:printSettings":{"c:headerFooter":{},"c:pageMargins":{a$:{b:"0.75",l:"0.7",r:"0.7",t:"0.75",header:"0.3",footer:"0.3"}},"c:pageSetup":{}}}};var qr={"c:idx":{a$:{val:"0"}},"c:order":{a$:{val:"0"}},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"}}},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:invertIfNegative":{a$:{val:"0"}},"c:val":{"c:numRef":{"c:f":""}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-F52E-47BC-822F-A046A80610BE}"}}}}},Kr={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:barChart":{"c:barDir":{a$:{val:"col"}},"c:grouping":{a$:{val:"clustered"}},"c:varyColors":{a$:{val:"0"}},"c:ser":[],"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}}},"c:gapWidth":{a$:{val:"219"}},"c:overlap":{a$:{val:"-27"}},"c:axId":[{a$:{val:"47003664"}},{a$:{val:"1789284464"}}]},"c:catAx":{"c:axId":{a$:{val:"47003664"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"b"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"1789284464"}},"c:crosses":{a$:{val:"autoZero"}},"c:auto":{a$:{val:"1"}},"c:lblAlgn":{a$:{val:"ctr"}},"c:lblOffset":{a$:{val:"100"}},"c:noMultiLvlLbl":{a$:{val:"0"}}},"c:valAx":{"c:axId":{a$:{val:"1789284464"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"l"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:numFmt":{a$:{formatCode:"General",sourceLinked:"1"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"47003664"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"between"}}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}};var ei={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:doughnutChart":{"c:varyColors":{a$:{val:"1"}},"c:ser":{"c:idx":{a$:{val:"0"}},"c:order":{a$:{val:"0"}},"c:dPt":{"c:idx":{a$:{val:"3"}},"c:bubble3D":{a$:{val:"0"}},"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent4"}}},"a:ln":{a$:{w:"19050"},"a:solidFill":{"a:schemeClr":{a$:{val:"lt1"}}}},"a:effectLst":{}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000007-E886-49A6-AE6D-C67D8A27530F}"}}}}},"c:cat":{"c:strRef":{"c:f":""}},"c:val":{"c:numRef":{"c:f":""}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-3689-4BB4-A84F-05B9F3BBE577}"}}}}},"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}},"c:showLeaderLines":{a$:{val:"1"}}},"c:firstSliceAng":{a$:{val:"0"}},"c:holeSize":{a$:{val:"75"}}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:legend":{"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}},"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"0",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{a$:{rtl:"0"},"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}};var ti={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:scatterChart":{"c:scatterStyle":{a$:{val:"lineMarker"}},"c:varyColors":{a$:{val:"0"}},"c:ser":[],"c:dLbls":{"c:showLegendKey":{a$:{val:"0"}},"c:showVal":{a$:{val:"0"}},"c:showCatName":{a$:{val:"0"}},"c:showSerName":{a$:{val:"0"}},"c:showPercent":{a$:{val:"0"}},"c:showBubbleSize":{a$:{val:"0"}}},"c:axId":[{a$:{val:"2028657983"}},{a$:{val:"2023395087"}}]},"c:valAx":[{"c:axId":{a$:{val:"2028657983"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"b"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"25000"}},"a:lumOff":{a$:{val:"75000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"2023395087"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"midCat"}}},{"c:axId":{a$:{val:"2023395087"}},"c:scaling":{"c:orientation":{a$:{val:"minMax"}}},"c:delete":{a$:{val:"0"}},"c:axPos":{a$:{val:"l"}},"c:majorGridlines":{"c:spPr":{"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"15000"}},"a:lumOff":{a$:{val:"85000"}}}},"a:round":{}},"a:effectLst":{}}},"c:numFmt":{a$:{formatCode:"0.00",sourceLinked:"1"}},"c:majorTickMark":{a$:{val:"none"}},"c:minorTickMark":{a$:{val:"none"}},"c:tickLblPos":{a$:{val:"nextTo"}},"c:spPr":{"a:noFill":{},"a:ln":{a$:{w:"9525",cap:"flat",cmpd:"sng",algn:"ctr"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"25000"}},"a:lumOff":{a$:{val:"75000"}}}},"a:round":{}},"a:effectLst":{}},"c:txPr":{"a:bodyPr":{a$:{rot:"-60000000",spcFirstLastPara:"1",vertOverflow:"ellipsis",vert:"horz",wrap:"square",anchor:"ctr",anchorCtr:"1"}},"a:lstStyle":{},"a:p":{"a:pPr":{"a:defRPr":{a$:{sz:"900",b:"0",i:"0",u:"none",strike:"noStrike",kern:"1200",baseline:"0"},"a:solidFill":{"a:schemeClr":{a$:{val:"tx1"},"a:lumMod":{a$:{val:"65000"}},"a:lumOff":{a$:{val:"35000"}}}},"a:latin":{a$:{typeface:"+mn-lt"}},"a:ea":{a$:{typeface:"+mn-ea"}},"a:cs":{a$:{typeface:"+mn-cs"}}}},"a:endParaRPr":{a$:{lang:"en-US"}}}},"c:crossAx":{a$:{val:"2028657983"}},"c:crosses":{a$:{val:"autoZero"}},"c:crossBetween":{a$:{val:"midCat"}}}],"c:spPr":{"a:noFill":{},"a:ln":{"a:noFill":{}},"a:effectLst":{}}},"c:plotVisOnly":{a$:{val:"1"}},"c:dispBlanksAs":{a$:{val:"gap"}},"c:extLst":{"c:ext":{a$:{uri:"{56B9EC1D-385E-4148-901F-78D8002777C0}","xmlns:c16r3":"http://schemas.microsoft.com/office/drawing/2017/03/chart"},"c16r3:dataDisplayOptions16":{"c16r3:dispNaAsBlank":{a$:{val:"1"}}}}},"c:showDLblsOverMax":{a$:{val:"0"}}},ri={"c:spPr":{"a:ln":{a$:{w:"19050",cap:"rnd"},"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"}}},"a:round":{}},"a:effectLst":{}},"c:marker":{"c:symbol":{a$:{val:"none"}}},"c:xVal":{"c:numRef":{"c:f":""}},"c:yVal":{"c:numRef":{"c:f":""}},"c:smooth":{a$:{val:"0"}},"c:extLst":{"c:ext":{a$:{uri:"{C3380CC4-5D6E-409C-BE32-E72D297353CC}","xmlns:c16":"http://schemas.microsoft.com/office/drawing/2014/chart"},"c16:uniqueId":{a$:{val:"{00000000-1F6C-44A9-AA4F-6706F20CC72E}"}}}}};var Ze=class i{constructor(e,t=i.next_chart_index++){this.options=e;this.index=t}static next_chart_index=1;relationships={};UpdateChartTitle(e){let t=this.options.title||{type:"literal",value:""};if(t&&t.type==="literal"){let r=JSON.parse(JSON.stringify(Qr)),n=r["c:tx"]["c:rich"]["a:p"];n["a:r"]={"a:rPr":{a$:{lang:$.locale}},"a:t":t.value},e["c:title"]=r}else if(t){let r=JSON.parse(JSON.stringify(Xr));r["c:tx"]["c:strRef"]["c:f"]=t.label,e["c:title"]=r}}toJSON(){switch(this.options.type){case"column":case"bar":return this.CreateBarChart();case"scatter":case"scatter2":return this.CreateScatterChart();case"donut":return this.CreateDonutChart();default:console.info("unhandled chart type",this.options.type)}return this.CreateBarChart()}CreateScatterChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(ti));this.options.smooth&&(r["c:plotArea"]["c:scatterChart"]["c:scatterStyle"].a$.val="smoothMarker"),t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=t["c:chart"]["c:plotArea"]["c:scatterChart"]["c:ser"],s=!1;for(let o=0;o<this.options.data.length;o++){let a=JSON.parse(JSON.stringify(ri));if(a["c:idx"]={a$:{val:o.toString()}},a["c:order"]={a$:{val:o.toString()}},this.options.names&&this.options.names[o]){let l=this.options.names[o];switch(l.type){case"literal":a["c:tx"]={"c:v":l.value.toString()},s=!0;break;case"range":case"address":a["c:tx"]={"c:strRef":{"c:f":l.label}},s=!0;break}}o<6&&(a["c:spPr"]["a:ln"]["a:solidFill"]["a:schemeClr"].a$.val=`accent${o+1}`),a["c:yVal"]["c:numRef"]["c:f"]=this.options.data[o]?.label,this.options.labels2&&this.options.labels2[o]&&(a["c:xVal"]["c:numRef"]["c:f"]=this.options.labels2[o]?.label),this.options.smooth&&(a["c:smooth"]={a$:{val:1}}),n.push(a)}return s&&(t["c:chart"]["c:legend"]={"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}}}),e}CreateDonutChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(ei));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=r["c:plotArea"]["c:doughnutChart"];return n&&(n["c:ser"]["c:cat"]["c:strRef"]["c:f"]=this.options.labels?.label||"",n["c:ser"]["c:val"]["c:numRef"]["c:f"]=this.options.data[0]?.label||""),e}CreateBarChart(){let e=JSON.parse(JSON.stringify(st)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(Kr));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let n=r["c:plotArea"]["c:barChart"];if(n){let s=n["c:barDir"];s&&(s.a$.val=this.options.type==="bar"?"bar":"col");let o=n["c:ser"];for(let a=0;a<this.options.data.length;a++){let l=JSON.parse(JSON.stringify(qr));l["c:idx"]={a$:{val:a.toString()}},l["c:order"]={a$:{val:a.toString()}},a<6&&(l["c:spPr"]["a:solidFill"]["a:schemeClr"].a$.val=`accent${a+1}`),!a&&this.options.labels&&(l["c:cat"]={"c:strRef":{"c:f":this.options.labels.label}}),l["c:val"]["c:numRef"]["c:f"]=this.options.data[a]?.label,o.push(l)}}return e}};var at=class i{constructor(e,t=i.next_image_index++){this.options=e;this.index=t;switch(e.mimetype){case"svg+xml":this.extension="svg";break;case"image/png":this.extension="png";break;case"jpg":this.extension="jpeg";break;case"svg":case"png":case"jpeg":case"gif":this.extension=e.mimetype;break;default:console.warn("unhandled mime type",e.mimetype);break}}static next_image_index=1;extension=""};var ii=9525,ze=class i{constructor(e=i.next_drawing_index++){this.index=e}static next_drawing_index=1;sheet_drawing_relationship=0;charts=[];images=[];relationships={};AddImage(e,t){let r=new at(e);if(r.extension){let n=ae(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",`../media/image${r.index}.${r.extension}`);this.images.push({image:r,relationship:n,anchor:t})}}AddChart(e,t){let r=new Ze(e),n=ae(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",`../charts/chart${r.index}.xml`);this.charts.push({chart:r,anchor:t,relationship:n})}CornerToJSON(e){return{"xdr:col":e.column,"xdr:colOff":(e.column_offset||0)*ii,"xdr:row":e.row,"xdr:rowOff":(e.row_offset||0)*ii}}AnchorToJSON(e){return{"xdr:from":{...this.CornerToJSON(e.from)},"xdr:to":{...this.CornerToJSON(e.to)}}}toJSON(){let e=this.images.map(n=>({a$:{editAs:"oneCell"},...this.AnchorToJSON(n.anchor),"xdr:pic":{"xdr:nvPicPr":{"xdr:cNvPr":{a$:{id:n.image.index+1,name:"Image "+n.image.index}},"xdr:cNvPicPr":{"a:picLocks":{a$:{noChangeAspect:1}}}},"xdr:blipFill":{"a:blip":{a$:n.image.extension==="svg"?{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships"}:{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:embed":n.relationship},"a:extLst":{"a:ext":[{a$:{uri:"{28A0092B-C50C-407E-A947-70E740481C1C}"},"a14:useLocalDpi":{a$:{"xmlns:a14":"http://schemas.microsoft.com/office/drawing/2010/main",val:0}}},n.image.extension==="svg"?{a$:{uri:"{96DAC541-7B7A-43D3-8B79-37D633B846F1}"},"asvg:svgBlip":{a$:{"xmlns:asvg":"http://schemas.microsoft.com/office/drawing/2016/SVG/main","r:embed":n.relationship}}}:void 0]}},"a:stretch":{"a:fillRect":{}}},"xdr:spPr":{"a:xfrm":{"a:off":{a$:{x:0,y:0}},"a:ext":{a$:{cx:4057650,cy:6172200}}},"a:prstGeom":{a$:{prst:"rect"},"a:avLst":{}}}},"xdr:clientData":{}})),t=this.charts.map(n=>({...this.AnchorToJSON(n.anchor),"xdr:graphicFrame":{a$:{macro:""},"xdr:nvGraphicFramePr":{"xdr:cNvPr":{a$:{id:n.chart.index+1,name:`Chart ${n.chart.index}`}},"xdr:cNvGraphicFramePr":{}},"xdr:xfrm":{"a:off":{a$:{x:0,y:0}},"a:ext":{a$:{cx:0,cy:0}}},"a:graphic":{"a:graphicData":{a$:{uri:"http://schemas.openxmlformats.org/drawingml/2006/chart"},"c:chart":{a$:{"xmlns:c":"http://schemas.openxmlformats.org/drawingml/2006/chart","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:id":n.relationship}}}}},"xdr:clientData":{}}));return{"xdr:wsDr":{a$:{"xmlns:xdr":"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing","xmlns:a":"http://schemas.openxmlformats.org/drawingml/2006/main"},"xdr:twoCellAnchor":[...t,...e]}}}};var Jt=Ae(Et());var Pe=i=>"row"in i&&"col"in i,ge=i=>"from"in i&&"to"in i&&Pe(i.from)&&Pe(i.to),ot=(i,e)=>e.sheet===i.sheet&&e.row>=i.from.row&&e.row<=i.to.row&&e.col>=i.from.col&&e.col<=i.to.col,Ot=(i,e=0,t=0)=>({from:{row:i.from.row+e,col:i.from.col+t,sheet:i.from.sheet},to:{row:i.to.row+e,col:i.to.col+t,sheet:i.to.sheet}});var lt=class{constructor(e={}){this.options=e}path;rels_path;rels={};sheet_data={};shared_strings;extent;visible_state;tab_selected=!1;default_width=0;drawings=[];TranslateAddress(e){e=e.toUpperCase();let t=e.match(/([A-Z]+\\d+):([A-Z]+\\d+)/);if(t)return{from:this.TranslateAddress(t[1]),to:this.TranslateAddress(t[2])};let r=0,n=0;if(t=e.match(/^([A-Z]+)(\\d+)$/),t){r=Number(t[2]),n=0;let s=t[1].length;for(let o=0;o<s;o++){let a=t[1].charCodeAt(o)-64;n=n*26+a}}return{row:r,col:n}}Address(e,t=!1){if(ge(e))return this.Address(e.from,t)+":"+this.Address(e.to,t);let r="",n=e.col;for(;n>0;){let o=(n-1)%26+1;r=String.fromCharCode(64+o)+r,n=(n-o)/26}let s=e.sheet?`\'${e.sheet}\'!`:"";return t?`${s}$${r}$${e.row}`:s+r+e.row}NormalizeAddress(e){let t,r;return typeof e=="string"?(t=e.toUpperCase(),r=this.TranslateAddress(t)):(r=e,t=this.Address(r)),{a:t,rc:r}}Parse(){let e=this.sheet_data.worksheet?.dimension?.a$?.ref,t=this.TranslateAddress(e||"");ge(t)?this.extent=JSON.parse(JSON.stringify(t)):this.extent={from:JSON.parse(JSON.stringify(t)),to:JSON.parse(JSON.stringify(t))}}};var ws=new Jt.XMLParser(Wr),ye=new Jt.XMLParser(qe),dt={greaterThan:">",greaterThanOrEquals:">=",lessThan:"<",lessThanOrEquals:"<=",equal:"=",notEqual:"<>"};var ct=class{constructor(e){this.zip=e}xml={};shared_strings=new Ce;style_cache=new Ne;theme=new be;defined_names={};rels={};sheets=[];active_tab=0;get sheet_count(){return this.sheets.length}ReadRels(e){let t={},r=this.zip.Has(e)?this.zip.Get(e):"",n=ye.parse(r||"");for(let s of n.Relationships?.Relationship||[]){let o=s.a$.Id;t[o]={id:o,type:s.a$.Type,target:s.a$.Target}}return t}Init(){this.rels=this.ReadRels("xl/_rels/workbook.xml.rels");let e=this.zip.Has("xl/sharedStrings.xml")?this.zip.Get("xl/sharedStrings.xml"):"",t=ye.parse(e||"");this.shared_strings.FromXML(t),e=this.zip.Get("xl/theme/theme1.xml"),t=ye.parse(e),this.theme.FromXML(t),e=this.zip.Get("xl/styles.xml"),t=ye.parse(e),this.style_cache.FromXML(t,this.theme),e=this.zip.Get("xl/workbook.xml"),t=ye.parse(e),this.defined_names={};let r=R.FindAll(t,"workbook/definedNames/definedName");for(let o of r){let a=o.a$?.name,l=o.t$||"";a&&l&&(this.defined_names[a]=l)}let n=R.FindAll(t,"workbook/bookViews/workbookView");n[0]?.a$?.activeTab&&(this.active_tab=Number(n[0].a$.activeTab)||0);let s=R.FindAll(t,"workbook/sheets/sheet");for(let o of s){let a=o.a$?.name;if(a){let l=o.a$.state,d=o.a$["r:id"],c=new lt({name:a,rid:d,id:Number(o.a$.sheetId)});l==="hidden"?c.visible_state=1:l==="veryHidden"&&(c.visible_state=2),c.shared_strings=this.shared_strings,c.path=`xl/${this.rels[d].target}`,c.rels_path=c.path.replace("worksheets","worksheets/_rels")+".rels",e=this.zip.Get(c.path),c.sheet_data=ye.parse(e||""),c.rels=this.ReadRels(c.rels_path),c.Parse(),this.sheets.push(c)}}}ReadTable(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ye.parse(t),n=r.table?.a$?.name||"";return{name:n,display_name:r.table?.a$?.displayName||n,ref:r.table?.a$.ref||"",totals_row_shown:Number(r.table?.a$.totalsRowShown||"0")||0,totals_row_count:Number(r.table?.a$.totalsRowCount||"0")||0}}ReadDrawing(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ye.parse(t),n=this.ReadRels(e.replace(/^..\\/drawings/,"xl/drawings/_rels")+".rels"),s=[],o=R.FindAll(r,"xdr:wsDr/xdr:twoCellAnchor"),a=(l={})=>({column:l["xdr:col"]||0,column_offset:l["xdr:colOff"]||0,row:l["xdr:row"]||0,row_offset:l["xdr:rowOff"]||0});for(let l of o){let d={from:a(l["xdr:from"]),to:a(l["xdr:to"])},c=R.FindAll(l,"xdr:graphicFrame/a:graphic/a:graphicData/c:chart")[0];if(c&&c.a$&&c.a$["r:id"]){let h={type:"chart",anchor:d},u=n[c.a$["r:id"]];u&&u.target&&(h.chart=this.ReadChart(u.target)),s.push(h)}else{let h=R.FindAll(l,"xdr:pic/xdr:blipFill/a:blip")[0];if(h&&h.a$["r:embed"]){let u=n[h.a$["r:embed"]];if(u&&u.target&&/(?:jpg|jpeg|png|gif)$/i.test(u.target)){let p=u.target.replace(/^\\.\\./,"xl"),f=p.replace(/^.*\\//,""),g={type:"image",anchor:d,image:this.zip.GetBinary(p),filename:f};s.push(g)}}}}return s}ReadChart(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=ws.parse(t),n={type:0},s=R.FindChild(r,"c:chartSpace/c:chart/c:title");if(s){let l=R.FindChild(s,"c:tx/c:strRef/c:f");if(l)typeof l=="string"?n.title=l:l.text__&&(n.title=l.text__);else{let d=R.FindAll(s,"c:tx/c:rich/a:p/a:r/a:t");n.title=\'"\'+d.join("")+\'"\'}}let o=(l,d=!1)=>{let c=[],h=l["c:ser"]||[];Array.isArray(h)||(h=[h]);for(let u of h){let p=c.length,f=u["c:order"];f&&(p=Number(f.__val||0)||0);let g={},y=R.FindChild(u,"c:tx/c:v");if(y){let N=y;N&&(g.title=`"${N}"`)}else y=R.FindChild(u,"c:tx/c:strRef/c:f"),y&&(g.title=y);if(d){let N=R.FindChild(u,"c:xVal/c:numRef/c:f");N&&(g.categories=N);let w=R.FindChild(u,"c:yVal/c:numRef/c:f");w&&(g.values=w)}else{let N=R.FindChild(u,"c:val/c:numRef/c:f");N&&(g.values=N);let w=R.FindChild(u,"c:cat/c:strRef/c:f");w||(w=R.FindChild(u,"c:cat/c:numRef/c:f")),w&&(g.categories=w)}c[p]=g}return c},a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:barChart");return a&&(n.type=2,a["c:barDir"]&&a["c:barDir"].__val==="col"&&(n.type=1),n.series=o(a)),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:lineChart"),a&&(n.type=3,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:doughnutChart"),a&&(n.type=5,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:pieChart"),a&&(n.type=6,n.series=o(a))),a||(a=R.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:scatterChart"),a&&(n.type=4,n.series=o(a,!0))),n}GetNamedRanges(){return this.defined_names}};var Qt=Ae(ni()),si=Ae(De()),Fe=class{records;text=new Map;constructor(e){this.records=Qt.default.parse(e)}Has(e){return this.text.has(e)||!!this.records?.[e]}ArrayBuffer(){let e={};if(this.records)for(let[r,n]of Object.entries(this.records))e[r]=new Uint8Array(n);let t=new TextEncoder;for(let[r,n]of this.text.entries())e[r]=t.encode(n);return Qt.default.encode(e)}SetBinary(e,t,r){if(r==="base64"){let n=si.default.toByteArray(t);this.records[e]=n}else throw new Error("unsupported encoding: "+r)}Set(e,t){this.text.set(e,t),this.records[e]&&delete this.records[e]}GetBinary(e){let t=this.records[e];if(t)return new Uint8Array(t);throw new Error("path not in records: "+e)}Get(e){let t=this.text.get(e);if(t)return t;let r=this.records[e];if(r)return t=new TextDecoder().decode(r),this.text.set(e,t),delete this.records[e],t;throw console.info(this),new Error("path not in zip file: "+e)}};var fe=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n`,ht=class{zip;xmloptions={format:!0,attributesGroupName:"a$",textNodeName:"t$",ignoreAttributes:!1,suppressEmptyNode:!0};xmlbuilder1=new ut.XMLBuilder(this.xmloptions);xmlparser2=new ut.XMLParser(qe);parser=new Te;decorated_functions={};Init(e={}){for(let r of Object.keys(e))this.decorated_functions[r.toLowerCase()]=e[r];let t=ai.toByteArray(rr);this.zip=new Fe(t)}WriteRels(e,t,r=!1){if(!this.zip)throw new Error("missing zip");let n=Object.keys(e),s={Relationships:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/relationships"},Relationship:n.map(a=>{let l=e[a],d={Id:l.id,Target:l.target,Type:l.type};return l.mode&&(d.TargetMode=l.mode),{a$:d}})}},o=fe+this.xmlbuilder1.build(s);r&&console.info(o),this.zip.Set(t,o)}WriteStyleCache(e){if(!this.zip)throw new Error("missing zip");let t=c=>{let h={};return c.indexed!==void 0&&(h.indexed=c.indexed),c.theme!==void 0&&(h.theme=c.theme),c.tint!==void 0&&(h.tint=c.tint),c.argb!==void 0&&(h.rgb=c.argb),h},r=e.cell_xfs.map(c=>{let h={a$:{numFmtId:c.number_format,fontId:c.font,fillId:c.fill,borderId:c.border}};return(c.horizontal_alignment||c.vertical_alignment||c.wrap_text)&&(h.alignment={a$:{}},c.horizontal_alignment&&(h.alignment.a$.horizontal=c.horizontal_alignment),c.vertical_alignment&&(h.alignment.a$.vertical=c.vertical_alignment),c.wrap_text&&(h.alignment.a$.wrapText=1)),h}),n=c=>{if(c.color)return{indexed:c.color};if(c.rgba)return{rgb:c.rgba};if(c.theme){let h={theme:c.theme};return c.tint&&(h.tint=c.tint),h}},s=e.borders.map(c=>{let h={left:{},right:{},top:{},bottom:{},diagonal:{}};if(c.top.style){h.top.a$={style:c.top.style};let u=n(c.top);u&&(h.top.color={a$:u})}if(c.left.style){h.left.a$={style:c.left.style};let u=n(c.left);u&&(h.left.color={a$:u})}if(c.bottom.style){h.bottom.a$={style:c.bottom.style};let u=n(c.bottom);u&&(h.bottom.color={a$:u})}if(c.right.style){h.right.a$={style:c.right.style};let u=n(c.right);u&&(h.right.color={a$:u})}if(c.diagonal.style){h.diagonal.a$={style:c.diagonal.style};let u=n(c.diagonal);u&&(h.diagonal.color={a$:u})}return h}),o=e.fills.map(c=>{let h={a$:{patternType:c.pattern_type}};return c.pattern_gray!==void 0&&(h.a$.patternType=`gray${c.pattern_gray}`),c.bg_color&&(h.bgColor={a$:t(c.bg_color)}),c.fg_color&&(h.fgColor={a$:t(c.fg_color)}),{patternFill:h}}),a=e.fonts.map(c=>{let h={};return c.bold&&(h.b=""),c.italic&&(h.i=""),c.underline&&(h.u=""),c.strike&&(h.strike=""),c.size!==void 0&&(h.sz={a$:{val:c.size}}),c.family!==void 0&&(h.family={a$:{val:c.family}}),c.name!==void 0&&(h.name={a$:{val:c.name}}),c.scheme!==void 0&&(h.scheme={a$:{val:c.scheme}}),c.color_argb!==void 0?h.color={a$:{rgb:c.color_argb}}:c.color_theme!==void 0&&(h.color={a$:{theme:c.color_theme}},c.color_tint&&(h.color.a$.tint=c.color_tint)),h}),l={styleSheet:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x14ac x16r2 xr","xmlns:x14ac":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac","xmlns:x16r2":"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision"}}};if(e.number_formats.length&&(l.styleSheet.numFmts={a$:{count:e.number_formats.length},numFmt:e.number_formats.map(c=>({a$:{numFmtId:c.id,formatCode:c.format}}))}),a.length&&(l.styleSheet.fonts={a$:{count:a.length},font:a}),o.length&&(l.styleSheet.fills={a$:{count:o.length},fill:o}),s.length&&(l.styleSheet.borders={a$:{count:s.length},border:s}),r.length&&(l.styleSheet.cellXfs={a$:{count:r.length},xf:r}),e.dxf_styles.length){let c=[];for(let h of e.dxf_styles){let u={};if(h.text||h.bold||h.italic||h.underline){let p={};h.text&&(p.color={a$:{}},h.text.text?p.color.a$.rgb="FF"+h.text.text.substring(1):h.text.theme&&(p.color.a$.theme=h.text.theme,h.text.tint&&(p.color.a$.tint=h.text.tint))),h.bold&&(p.b={}),h.italic&&(p.i={}),h.underline&&(p.u={}),h.strike&&(p.strike={}),u.font=p}if(h.fill){let p={a$:{}};h.fill.text?p.a$.rgb="FF"+h.fill.text.substring(1):h.fill.theme&&(p.a$.theme=h.fill.theme,h.fill.tint&&(p.a$.tint=h.fill.tint)),u.fill={patternFill:{bgColor:p}}}c.push(u)}c.length&&(l.styleSheet.dxfs={a$:{count:c.length},dxf:c})}let d=fe+this.xmlbuilder1.build(l);this.zip?.Set("xl/styles.xml",d)}WriteSharedStrings(e){if(!this.zip)throw new Error("missing zip");let t={sst:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",count:e.strings.length,uniqueCount:e.strings.length},si:[...e.strings.map(n=>({t:n}))]}},r=fe+this.xmlbuilder1.build(t);this.zip.Set("xl/sharedStrings.xml",r)}SheetStyle(e,t){if(!e.sheet_style)return 0;let r=t.StyleOptionsFromProperties(e.sheet_style);return t.EnsureStyle(r)}RowStyle(e,t,r){let n=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.row_style){let a=e.row_style[r];typeof a=="number"&&(a=n[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(ve.Composite(s));return t.EnsureStyle(o)}ColumnStyle(e,t,r){let n=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.column_style){let a=e.column_style[r];typeof a=="number"&&(a=n[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(ve.Composite(s));return t.EnsureStyle(o)}StyleFromCell(e,t,r,n,s={}){let o=e.styles||e.cell_style_refs||[],a=[e.sheet_style];if(e.row_pattern&&e.row_pattern.length&&a.push(e.row_pattern[r%e.row_pattern.length]),e.row_style){let d=e.row_style[r];typeof d=="number"&&(d=o[d]),d&&a.push(d)}if(e.column_style){let d=e.column_style[n];typeof d=="number"&&(d=o[d]),d&&a.push(d)}a.push(s);let l=t.StyleOptionsFromProperties(ve.Composite(a));return t.EnsureStyle(l)}NormalizeAddress(e,t){let r=e.type==="address"?[e]:[e.start,e.end];for(let n of r)n.absolute_row=!0,n.absolute_column=!0,n.sheet||(n.sheet=t.name);return e.type==="range"&&(e.end.sheet=void 0),e.label=this.parser.Render(e),e}AnnotationLayoutToAnchor(e,t){let r=n=>{let s=t.column_width&&t.column_width[n.address.column]?t.column_width[n.address.column]:t.default_column_width||100,o=t.row_height&&t.row_height[n.address.row]?t.row_height[n.address.row]:t.default_row_height||20;return{...n.address,row_offset:Math.round(n.offset.y*o),column_offset:Math.round(n.offset.x*s)}};return{from:r(e.tl),to:r(e.br)}}AnnotationRectToAnchor(e,t){let r={from:{row:-1,column:-1},to:{row:-1,column:-1}},n={top:0,left:0,width:301,height:301,...e},s={...n,right:n.left+n.width,bottom:n.top+n.height};for(let o=0,a=0;a<1e3;a++){let l=t.column_width&&t.column_width[a]?t.column_width[a]:t.default_column_width||100;if(r.from.column<0&&s.left<=o+l&&(r.from.column=a,r.from.column_offset=s.left-o),r.to.column<0&&s.right<=o+l){r.to.column=a,r.to.column_offset=s.right-o;break}o+=l}for(let o=0,a=0;a<1e3;a++){let l=t.row_height&&t.row_height[a]?t.row_height[a]:t.default_row_height||20;if(r.from.row<0&&s.top<=o+l&&(r.from.row=a,r.from.row_offset=s.top-o),r.to.row<0&&s.bottom<=o+l){r.to.row=a,r.to.row_offset=s.bottom-o;break}o+=l}return r}ParseImages(e){let t=[];for(let r of e.annotations||[])if(r.type==="image"&&r.data?.src){let n=r.data.src,s=n.match(/^data:image\\/([^;]*?);base64,/);if(s){let o=n.substr(s[0].length),a=s[1],l={data:o,mimetype:a,encoding:"base64"};switch(a){case"svg+xml":case"webp":case"jpeg":case"jpg":case"image/png":case"png":case"gif":r.layout?t.push({anchor:this.AnnotationLayoutToAnchor(r.layout,e),options:l}):r.rect?t.push({anchor:this.AnnotationRectToAnchor(r.rect,e),options:l}):console.warn("annotation missing layout");break;default:console.info("unhandled image type",a);break}}}return t}ParseCharts(e){let t=[],r=(n,s,o)=>{if(n.type==="range")s.data.push(this.NormalizeAddress(n,e));else if(n.type==="call"){if(/group/i.test(n.name))for(let a of n.args||[])r(a,s,o?o+" (recurse)":void 0);else if(/series/i.test(n.name)){let[a,l,d]=n.args;d&&d.type==="range"?(s.data.push(this.NormalizeAddress(d,e)),a&&(s.names||(s.names=[]),a.type==="address"&&this.NormalizeAddress(a,e),a.type==="range"?(this.NormalizeAddress(a.start,e),s.names[s.data.length-1]=a.start):s.names[s.data.length-1]=a),s.labels2||(s.labels2=[]),l&&l.type==="range"&&(s.labels2[s.data.length-1]=this.NormalizeAddress(l,e))):console.info("invalid series missing Y",{y:d,arg:n,ref:o})}}};for(let n of e.annotations||[]){let s=this.parser.Parse(n.formula||"");if(s.expression&&s.expression.type==="call"){let o="";switch(s.expression.name.toLowerCase()){case"line.chart":o="scatter";break;case"scatter.line":o="scatter2";break;case"donut.chart":o="donut";break;case"bar.chart":o="bar";break;case"column.chart":o="column";break}if(o==="column"||o==="donut"||o==="bar"||o==="scatter"||o==="scatter2"){let a={type:o,data:[]},l=o==="scatter2"?1:2,d=s.expression.args[l];if(d&&d.type==="literal"?a.title=d:d&&d.type==="address"&&(a.title=this.NormalizeAddress(d,e)),s.expression.args[0]){let h=s.expression.args[0];if(o==="scatter2"||o==="bar"||o==="column"||o==="scatter")r(h,a,e.name);else if(h.type==="range")a.data.push(this.NormalizeAddress(h,e));else if(h.type==="call"&&/group/i.test(h.name))for(let u of h.args)u.type==="range"?a.data.push(this.NormalizeAddress(u,e)):u.type==="call"&&/series/i.test(u.name)&&u.args[2]&&u.args[2].type==="range"&&a.data.push(this.NormalizeAddress(u.args[2],e));else h.type==="call"&&/series/i.test(h.name)&&h.args[2]&&h.args[2].type==="range"&&a.data.push(this.NormalizeAddress(h.args[2],e))}o!=="scatter2"&&s.expression.args[1]&&s.expression.args[1].type==="range"&&(a.labels=this.NormalizeAddress(s.expression.args[1],e)),(o==="scatter"&&s.expression.args[4]&&s.expression.args[4].type==="literal"&&s.expression.args[4].value.toString().toLowerCase()==="smooth"||o==="scatter2"&&s.expression.args[2]&&s.expression.args[2].type==="literal"&&/smooth/i.test(s.expression.args[2].value.toString()))&&(a.smooth=!0);let c=n.rect;n.layout?t.push({anchor:this.AnnotationLayoutToAnchor(n.layout,e),options:a}):c?t.push({anchor:this.AnnotationRectToAnchor(c,e),options:a}):console.warn("annotation missing layout")}}}return t}FormulaText(e,t){if(e[0]!=="=")return e;let r=this.parser.Parse(e);if(r.expression){this.parser.Walk(r.expression,s=>{if(s.type==="call"){let o=s.name.toLowerCase();this.decorated_functions[o]&&(s.name=this.decorated_functions[o]+"."+s.name)}return!0});let n=t.table?.name||"";return this.parser.Render(r.expression,{missing:"",long_structured_references:!0,table_name:n})}else return console.warn("parsing function failed"),console.warn(e),e.substring(1)}Export(e){let t=0,r=[];for(let w=0;w<e.sheet_data.length;w++){let x=e.sheet_data[w],I=x.id||0;I&&(r[I]=x.name||""),I===e.active_sheet&&(t=w)}let n=new Ce,s=new Ne,o=new be,a=this.zip?.Get("xl/theme/theme1.xml");o.FromXML(this.xmlparser2.parse(a||"")),a=this.zip?.Get("xl/styles.xml"),s.FromXML(this.xmlparser2.parse(a||""),o),ze.next_drawing_index=1,Ze.next_chart_index=1;let l=[],d=[];for(let w=0;w<e.sheet_data.length;w++){let x=e.sheet_data[w],I={},G={xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x14ac xr xr2 xr3","xmlns:x14ac":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr2":"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2","xmlns:xr3":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3","xr:uid":"{D37933E2-499F-4789-8D13-194E11B743FC}"},Y=x.default_row_height?x.default_row_height/20*15:15,k={worksheet:{a$:{...G},dimension:{a$:{ref:"A1"}},sheetViews:{sheetView:{a$:{workbookViewId:0}}},sheetFormatPr:{a$:Y===15?{"x14ac:dyDescent":.25}:{defaultRowHeight:Y,customHeight:1,"x14ac:dyDescent":.25}},cols:{},sheetData:{},mergeCells:{a$:{count:0}},dataValidations:{},hyperlinks:{},conditionalFormatting:{},pageMargins:{a$:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3}},drawing:{},tableParts:{a$:{count:0}},extLst:{ext:{a$:{uri:"{05C60535-1F16-4fd2-B633-F4F36F0B64E0}","xmlns:x14":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"}}}}},M=x.styles||x.cell_style_refs||[],V=new Je;V.FromJSON(x.data,M);for(let b of x.cell_styles){let S=V.EnsureCell(b);S.style||(S.style=M[b.ref])}let z={start:{row:V.rows+1,column:V.columns+1},end:{row:V.rows+1,column:V.columns+1}},U={row:[]},X=[],J=[],B=[],K=[],j=[],_=[],T=this.SheetStyle(x,s);for(let b=0;b<V.data.length;b++){let S=this.RowStyle(x,s,b);if(V.data[b]&&V.data[b].length){b<z.start.row&&(z.start.row=b);let W={start:-1,end:-1},E=[];for(let A=0;A<V.data[b].length;A++){_[A]||(_[A]=this.ColumnStyle(x,s,A));let v=V.data[b][A];if(v){if(v.table&&v.table.area.start.row===b&&v.table.area.start.column===A){let le=new L(v.table.area.start,v.table.area.end),Be=d.length+1,li=`../tables/table${Be}.xml`,pt=[];for(let ne=0;ne<le.columns;ne++){let Q=V.data[b][A+ne],me="";Q.type!==2?(typeof Q.calculated<"u"?me=Q.calculated.toString():typeof Q.value<"u"&&(me=Q.value.toString()),Q.type=2,Q.value=me):me=Q.value||"",me||(me=`Column${ne+1}`);let Ye=me,gt=!1,ci=1;for(;!gt;){gt=!0;e:for(let di of pt)if(di.toLowerCase()===Ye.toLowerCase()){gt=!1,Ye=`${me}${++ci}`;break e}}Q.value=Ye,pt.push(Ye)}let Le;if(v.table.totals_row){Le=[];for(let ne=0;ne<le.columns;ne++){let Q=V.data[le.end.row][le.start.column+ne];Q.type&&(Q.type===1?Le[ne]={type:"formula",value:(Q.value||"").toString().substring(1)}:(Q.type!==2&&(Q.type=2,Q.value=Q.value?.toString()||""),Le[ne]={type:"label",value:Q.value}))}}let bt={rel:ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",li),index:Be,ref:le.spreadsheet_label,name:`Table${Be}`,display_name:`Table${Be}`,totals_row_shown:0,totals_row_count:v.table?.totals_row?1:0,columns:pt,footers:Le};if(v.table.totals_row){let ne=new L(le.start,{row:le.end.row-1,column:le.end.column});bt.filterRef=ne.spreadsheet_label}K.push(bt),d.push(bt)}if(v.merge_area&&v.merge_area.start.row===b&&v.merge_area.start.column===A&&B.push(new L(v.merge_area.start,v.merge_area.end)),v.hyperlink){let le=ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",v.hyperlink,"External");X.push({rel:le,target:v.hyperlink,address:{row:b,column:A}})}if(v.validation&&(v.validation.type==="list"||v.validation.type==="range")&&j.push({address:{row:b,column:A},validation:v.validation}),v.type===1&&/^=?sparkline\\./i.test(v.value)){J.push({address:{row:b,column:A},formula:v.value,style:v.style});continue}A<z.start.column&&(z.start.column=A),W.start<0&&(W.start=A),W.end=A;let D=this.StyleFromCell(x,s,b,A,v.style);if(v.type===0&&(S&&D===S||!S&&_[A]&&D===_[A]))continue;let H,q,ee;switch(v.type){case 1:switch(ee=this.FormulaText(v.value,v),v.calculated_type){case 2:H=v.calculated,q="str";break;case 3:H=v.calculated;break;case 4:H=v.calculated?1:0,q="b";break}break;case 2:H=n.Ensure(v.value),q="s";break;case 3:H=v.value;break;case 4:H=v.value?1:0,q="b";break}v.area&&v.area.start.row===b&&v.area.start.column===A&&typeof ee=="string"&&(ee={t$:ee,a$:{t:"array",ref:v.area.spreadsheet_label}});let oe={a$:{r:L.CellAddressToLabel({row:b,column:A})}};q!==void 0&&(oe.a$.t=q),D!==void 0&&(oe.a$.s=D),ee!==void 0&&(oe.f=ee),H!==void 0&&(oe.v=H),E.push(oe)}}if(E.length||S&&S!==T){let A={a$:{r:b+1,spans:`${W.start+1}:${W.end+1}`},c:E};x.row_height&&typeof x.row_height[b]=="number"&&x.row_height[b]!==x.default_row_height&&(A.a$.customHeight=1,A.a$.ht=x.row_height[b]*3/4),S&&S!==T&&(A.a$.s=S,A.a$.customFormat=1),U.row.push(A)}}}let Z=[];x.default_column_width&&(k.worksheet.sheetFormatPr.a$.defaultColWidth=He(x.default_column_width));for(let b=0;b<x.columns;b++){let S={index:b};x.column_width&&x.default_column_width&&typeof x.column_width[b]=="number"&&x.column_width[b]!==x.default_column_width&&(S.width=He(x.column_width[b]));let W=_[b];W&&W!==T&&(S.style=W),(S.style!==void 0||S.width!==void 0)&&(Z[b]=S)}if(Z.length||T){let b=[],S=He(x.default_column_width||90);{let W=0;for(let E of Z){if(!E)continue;T&&E.index>W+1&&b.push({a$:{min:W+1,max:E.index,style:T,width:S}});let A={min:E.index+1,max:E.index+1};E.style===void 0?A.style=T:A.style=E.style,E.width!==void 0?(A.width=E.width,A.customWidth=1):A.width=S,b.push({a$:A}),W=E.index}T&&W<16384&&b.push({a$:{min:W+1,max:16384,style:T,width:S}}),k.worksheet.cols.col=b}}else delete k.worksheet.cols;j.length?k.worksheet.dataValidations={a$:{count:j.length},dataValidation:j.map(b=>{let S={a$:{type:"list",allowBlank:1,showInputMessage:1,showErrorMessage:1,sqref:new L(b.address).spreadsheet_label}};if(b.validation.type==="range"){let W={id:0,type:"range",label:"",position:0,start:{...b.validation.area.start,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"},end:{...b.validation.area.end,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"}};typeof b.validation.area.start.sheet_id<"u"&&(W.start.sheet=r[b.validation.area.start.sheet_id]),S.formula1=this.parser.Render(W)}else b.validation.type==="list"&&(S.formula1=`"${b.validation.list.join(",")}"`);return S})}:delete k.worksheet.dataValidations,K.length?(k.worksheet.tableParts.a$.count=K.length,k.worksheet.tableParts.tablePart=K.map(b=>({a$:{"r:id":b.rel||""}}))):delete k.worksheet.tableParts;for(let b of K){let S={};b.totals_row_count&&(S.totalsRowCount=1);let W={a$:{count:(b.columns||[]).length},tableColumn:[]};if(b.columns)for(let v=0;v<b.columns.length;v++){let D=b.columns[v],H=(b.footers||[])[v],q={a$:{id:v+1,name:D||`Column${v+1}`}};H&&(H.type==="label"?q.a$.totalsRowLabel=H.value:H.type==="formula"&&(q.a$.totalsRowFunction="custom",q.totalsRowFormula=H.value)),W.tableColumn.push(q)}let E={table:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"xr xr3","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr3":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",id:b.index||0,name:b.name,displayName:b.display_name,...S,ref:b.ref},autoFilter:{a$:{ref:b.filterRef||b.ref}},tableColumns:W,tableStyleInfo:{a$:{name:"TableStyleMedium2",showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}}}},A=fe+this.xmlbuilder1.build(E);this.zip?.Set(`xl/tables/table${b.index}.xml`,A)}if(x.conditional_formats?.length){let b=[],S=1,W={},E=Object.entries(dt).map(A=>(W[A[1]]=A[0],A[1]));E.sort((A,v)=>v.length-A.length);for(let A of x.conditional_formats){let v=0;switch(A.type!=="gradient"&&(v=s.dxf_styles.length,s.dxf_styles.push(A.style)),A.type){case"cell-match":{let D="",H="";for(let q of E)if(new RegExp("^"+q+"\\\\s").test(A.expression)){D=W[q],H=A.expression.substring(q.length).trim();break}D&&b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"cellIs",dxfId:v,operator:D,priority:S++},formula:H}})}break;case"expression":b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"expression",dxfId:v,priority:S++},formula:A.expression}});break;case"duplicate-values":b.push({a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:A.unique?"uniqueValues":"duplicateValues",dxfId:v,priority:S++}}});break;case"gradient":{let D=[],H=[];for(let ee of A.stops){ee.value===0?D.push({a$:{type:"min"}}):ee.value===1?D.push({a$:{type:"max"}}):D.push({a$:{type:"percentile",val:ee.value*100}});let oe={a$:{}};ee.color.text?oe.a$.rgb="FF"+ee.color.text.substring(1):ee.color.theme&&(oe.a$.theme=ee.color.theme,oe.a$.tint=ee.color.tint||void 0),H.push(oe)}let q={a$:{sqref:new L(A.area.start,A.area.end).spreadsheet_label},cfRule:{a$:{type:"colorScale",priority:S++},colorScale:{cfvo:D,color:H}}};b.push(q)}break}}b.length?k.worksheet.conditionalFormatting=b.length>1?b:b[0]:delete k.worksheet.conditionalFormatting}else delete k.worksheet.conditionalFormatting;B.length?(k.worksheet.mergeCells.a$.count=B.length,k.worksheet.mergeCells.mergeCell=B.map(b=>({a$:{ref:b.spreadsheet_label}}))):delete k.worksheet.mergeCells,X.length?k.worksheet.hyperlinks.hyperlink=X.map(b=>({a$:{"r:id":b.rel,ref:new L(b.address).spreadsheet_label,"xr:uid":"{0C6B7792-7EA0-4932-BF15-D49C453C565D}"}})):delete k.worksheet.hyperlinks,J.length?k.worksheet.extLst.ext["x14:sparklineGroups"]={a$:{"xmlns:xm":"http://schemas.microsoft.com/office/excel/2006/main"},"x14:sparklineGroup":J.map(b=>{let S=this.parser.Parse(b.formula),W="";if(S.expression&&S.expression.type==="call"&&S.expression.args.length>0){let A=S.expression.args[0];if(A.type==="range"||A.type==="address"){let v=A.type==="range"?A.start:A;v.sheet||(typeof v.sheet_id<"u"?v.sheet=r[v.sheet_id]:v.sheet=x.name),W=this.parser.Render(A)}}let E={displayEmptyCellsAs:"gap"};return/column/i.test(b.formula)&&(E.type="column"),{a$:E,"x14:colorSeries":{a$:{rgb:"FF376092"}},"x14:sparklines":{"x14:sparkline":{"xm:f":W,"xm:sqref":new L(b.address).spreadsheet_label}}}})}:delete k.worksheet.extLst,k.worksheet.sheetData=U;let P=this.ParseCharts(x),C=this.ParseImages(x);if(P.length||C.length){let b=new ze;for(let E of P)b.AddChart(E.options,E.anchor);for(let E of C)b.AddImage(E.options,E.anchor);for(let{image:E}of b.images)E.options.data&&this.zip?.SetBinary(`xl/media/image${E.index}.${E.extension}`,E.options.data,E.options.encoding);for(let{chart:E}of b.charts){let A=E.toJSON(),v=fe+this.xmlbuilder1.build(A);this.zip?.Set(`xl/charts/chart${E.index}.xml`,v),this.WriteRels(E.relationships,`xl/charts/_rels/chart${E.index}.xml.rels`)}this.WriteRels(b.relationships,`xl/drawings/_rels/drawing${b.index}.xml.rels`);let S=fe+this.xmlbuilder1.build(b.toJSON());this.zip?.Set(`xl/drawings/drawing${b.index}.xml`,S),l.push(b);let W=ae(I,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",`../drawings/drawing${b.index}.xml`);k.worksheet.drawing={a$:{"r:id":W}}}else delete k.worksheet.drawing;k.worksheet.dimension.a$.ref=new L(z.start,z.end).spreadsheet_label;let F=fe+this.xmlbuilder1.build(k);this.zip?.Set(`xl/worksheets/sheet${w+1}.xml`,F),Object.keys(I).length&&this.WriteRels(I,`xl/worksheets/_rels/sheet${w+1}.xml.rels`)}this.WriteSharedStrings(n),this.WriteStyleCache(s);let c={};ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles","styles.xml"),ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme","theme/theme1.xml"),ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings","sharedStrings.xml");let h=e.sheet_data.map((w,x)=>ae(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",`worksheets/sheet${x+1}.xml`));this.WriteRels(c,"xl/_rels/workbook.xml.rels");let u={definedName:[]};if(e.named_ranges){let w=Object.keys(e.named_ranges);for(let x of w){let I="",G=new L(e.named_ranges[x].start,e.named_ranges[x].end);if(G.start.absolute_column=G.start.absolute_row=!0,G.end.absolute_column=G.end.absolute_row=!0,G.start.sheet_id){for(let Y of e.sheet_data)if(Y.id===G.start.sheet_id){I=Y.name||"";break}}I&&(Ht.test(I)&&(I=`\'${I}\'`),I+="!"),u.definedName.push({a$:{name:x},t$:I+G.spreadsheet_label})}}if(e.named_expressions)for(let w of e.named_expressions)u.definedName.push({a$:{name:w.name},t$:w.expression});u.definedName.length||(u=void 0);let p={workbook:{a$:{xmlns:"http://schemas.openxmlformats.org/spreadsheetml/2006/main","xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","xmlns:mc":"http://schemas.openxmlformats.org/markup-compatibility/2006","mc:Ignorable":"x15 xr xr6 xr10 xr2","xmlns:x15":"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main","xmlns:xr":"http://schemas.microsoft.com/office/spreadsheetml/2014/revision","xmlns:xr6":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision6","xmlns:xr10":"http://schemas.microsoft.com/office/spreadsheetml/2016/revision10","xmlns:xr2":"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"},workbookPr:{a$:{defaultThemeVersion:"166925"}},bookViews:{workbookView:{a$:{activeTab:t||0}}},sheets:{sheet:e.sheet_data.map((w,x)=>{let I={name:w.name||`Sheet${x+1}`,sheetId:x+1,"r:id":h[x]};return w.visible===!1&&(I.state="hidden"),{a$:I}})},definedNames:u}},f=fe+this.xmlbuilder1.build(p);this.zip?.Set("xl/workbook.xml",f);let g={};for(let w of l)for(let x of w.images)switch(x.image.extension){case"gif":case"png":case"jpeg":g[x.image.extension]="image/"+x.image.extension;break;case"svg":g.svg="image/svg+xml";break}let y={Types:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/content-types"},Default:[{a$:{Extension:"rels",ContentType:"application/vnd.openxmlformats-package.relationships+xml"}},{a$:{Extension:"xml",ContentType:"application/xml"}},...Object.keys(g).map(w=>({a$:{Extension:w,ContentType:g[w]}}))],Override:[{a$:{PartName:"/xl/workbook.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"}},...e.sheet_data.map((w,x)=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",PartName:`/xl/worksheets/sheet${x+1}.xml`}})),...l.reduce((w,x)=>w.concat([...x.charts.map(I=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",PartName:`/xl/charts/chart${I.chart.index}.xml`}})),{a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawing+xml",PartName:`/xl/drawings/drawing${x.index}.xml`}}]),[]),{a$:{PartName:"/xl/theme/theme1.xml",ContentType:"application/vnd.openxmlformats-officedocument.theme+xml"}},{a$:{PartName:"/xl/styles.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"}},{a$:{PartName:"/xl/sharedStrings.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"}},...d.map(w=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",PartName:`/xl/tables/table${w.index||0}.xml`}})),{a$:{PartName:"/docProps/core.xml",ContentType:"application/vnd.openxmlformats-package.core-properties+xml"}},{a$:{PartName:"/docProps/app.xml",ContentType:"application/vnd.openxmlformats-officedocument.extended-properties+xml"}}]}},N=fe+this.xmlbuilder1.build(y);this.zip?.Set("[Content_Types].xml",N)}ArrayBuffer(){if(!this.zip)throw new Error("missing zip");return this.zip.ArrayBuffer()}Blob(){if(!this.zip)throw new Error("missing zip");let e=this.zip.ArrayBuffer();return new Blob([e],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}};var oi=Ae(De());var ft=class{parser=new Te;workbook;zip;Init(e){this.zip=new Fe(e),this.workbook=new ct(this.zip),this.workbook.Init()}SheetCount(){return this.workbook?.sheet_count||0}ParseCell(e,t,r,n,s,o,a){let l=t.a$?.r;if(!l){console.warn("cell missing address");return}let d=e.TranslateAddress(l);if(ge(d)){console.warn("cell has range address");return}let c,h="undefined",u,p="undefined";if(t.a$?.t&&t.a$.t==="s"){if(h="string",typeof t.v!==void 0){let y=Number(t.v);!isNaN(y)&&e.shared_strings&&(c=e.shared_strings.Get(y)||"",c[0]==="="&&(c="\'"+c))}}else if(typeof t.f<"u"){h="formula";let y=(typeof t.f=="string"?t.f:t.f.t$)||"";if(y){c="="+y.replace(/^_xll\\./g,"");let N=this.parser.Parse(y);N.expression&&(this.parser.Walk(N.expression,w=>(w.type==="call"&&/^_xll\\./.test(w.name)&&(w.name=w.name.substr(5)),!0)),c="="+this.parser.Render(N.expression,{missing:""})),typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si&&(r[t.f.a$.si]={row:d.row-1,column:d.col-1,formula:c,parse_result:this.parser.Parse(c)})}else if(typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si){let N=r[t.f.a$.si];N&&(N.parse_result.expression?c="="+this.parser.Render(N.parse_result.expression,{offset:{rows:d.row-1-N.row,columns:d.col-1-N.column},missing:""}):c=N.formula)}if(typeof t.f!="string"&&t.f.a$?.t==="array"){let N=e.TranslateAddress(t.f.a$.ref||"");ge(N)&&n.push(Ot(N,-1,-1))}if(typeof t.v<"u"){let N=Number(t.v.toString());isNaN(N)?(p="string",u=t.v.toString()):(p="number",u=N)}}else if(typeof t.v<"u"){let y=Number(t.v.toString());isNaN(y)?(h="string",c=t.v.toString()):(h="number",c=y)}let f={row:d.row-1,col:d.col-1};for(let y of n)ot(y,f)&&(f.row!==y.from.row||f.col!==y.from.col)&&(p=h,u=c,c=void 0,h="undefined");let g={row:f.row,column:f.col,value:c,type:h};typeof u<"u"&&(g.calculated_type=p,g.calculated=u),t.a$?.s&&(g.style_ref=Number(t.a$.s));for(let y of o)y.address.row===d.row&&y.address.col===d.col&&(g.hyperlink=y.reference);for(let y of a)if(y.address.row===f.row&&y.address.column===f.col){g.validation=y.validation;break}for(let y of s)ot(y,f)&&(g.merge_area={start:{row:y.from.row,column:y.from.col},end:{row:y.to.row,column:y.to.col}});for(let y of n)ot(y,f)&&(g.area={start:{row:y.from.row,column:y.from.col},end:{row:y.to.row,column:y.to.col}});return g}AddressToArea(e){return Pe(e)?{start:{row:e.row-1,column:e.col-1},end:{row:e.row-1,column:e.col-1}}:{start:{row:e.from.row-1,column:e.from.col-1},end:{row:e.to.row-1,column:e.to.col-1}}}ParseConditionalFormat(e,t){let r=this.AddressToArea(e),n=dt;switch(t.a$.type){case"duplicateValues":case"uniqueValues":let s={};if(t.a$.dxfId){let o=Number(t.a$.dxfId);isNaN(o)||(s=this.workbook?.style_cache.dxf_styles[o]||{})}return{type:"duplicate-values",area:r,style:s,unique:t.a$.type==="uniqueValues"};case"cellIs":if(t.a$.operator&&t.formula){let o={};if(t.a$.dxfId){let l=Number(t.a$.dxfId);isNaN(l)||(o=this.workbook?.style_cache.dxf_styles[l]||{})}let a=n[t.a$.operator||""];if(!a)console.info("unhandled cellIs operator:",t.a$.operator);else return{type:"cell-match",expression:a+" "+t.formula,area:r,style:o}}break;case"expression":if(t.formula){let o={};if(t.a$.dxfId){let a=Number(t.a$.dxfId);isNaN(a)||(o=this.workbook?.style_cache.dxf_styles[a]||{})}return{type:"expression",expression:t.formula,area:r,style:o}}break;case"colorScale":if(t.colorScale&&Array.isArray(t.colorScale.cfvo)&&Array.isArray(t.colorScale.color)){let o=[];for(let[a,l]of t.colorScale.cfvo.entries()){let d=0,c={},h=t.colorScale.color[a];switch(h.a$.rgb?c.text="#"+h.a$.rgb.substring(2):h.a$.theme&&(c.theme=Number(h.a$.theme)||0,h.a$.tint&&(c.tint=Math.round(h.a$.tint*1e3)/1e3)),l.a$.type){case"min":d=0;break;case"max":d=1;break;case"percentile":d=(Number(l.a$.val)||0)/100;break}o.push({color:c,value:d})}return{type:"gradient",stops:o,color_space:"RGB",area:r}}else console.info("unexpected colorScale",{rule:t});break;default:console.info("unhandled cf type:",{rule:t})}}GetSheet(e=0){if(!this.workbook)throw new Error("missing workbook");let t=this.workbook.sheets[e],r=[],n={},s=[],o=[],a=[],l=[],d=[],c=[],h=R.FindAll.bind(R,t.sheet_data),u=h("worksheet/conditionalFormatting");for(let _ of u)if(_.a$?.sqref){let T=t.TranslateAddress(_.a$.sqref);if(_.cfRule){let Z=Array.isArray(_.cfRule)?_.cfRule:[_.cfRule];for(let P of Z){let C=this.ParseConditionalFormat(T,P);C&&a.push(C)}}}let p=h("worksheet/mergeCells/mergeCell");for(let _ of p)if(_.a$.ref){let T=t.TranslateAddress(_.a$.ref);ge(T)&&o.push(Ot(T,-1,-1))}let f=h("worksheet/dataValidations/dataValidation");for(let _ of f){let T=_.a$?.type,Z=_.a$?.sqref,P=_.formula1;if(Z&&P&&T==="list"){let C,F,b=this.parser.Parse(Z);b.expression&&(b.expression.type==="address"?C=b.expression:b.expression.type==="range"&&(C=b.expression.start)),b=this.parser.Parse(P),b.expression&&(b.expression.type==="range"?F={type:"range",area:b.expression}:b.expression.type==="literal"&&(F={type:"list",list:b.expression.value.toString().split(/,/).map(S=>{let W=this.parser.Parse(S);if(W.expression?.type==="group"&&/\\s/.test(S))return S;if(W.expression?.type==="literal")return W.expression.value;if(W.expression?.type==="identifier")return W.expression.name})})),C&&F&&d.push({address:C,validation:F})}}let g=h("worksheet/hyperlinks/hyperlink");for(let _ of g){let T=t.TranslateAddress(_.a$?.ref||"");ge(T)&&(T=T.from);let Z="",P="";if(_.a$&&_.a$["r:id"]){Z="remote link";let C=t.rels[_.a$["r:id"]];C&&(P=C.target||"")}else P=_.__location||"",Z=_.__display||"";l.push({address:T,reference:P,text:Z})}let y=21,N=100,w=t.sheet_data.worksheet?.sheetFormatPr;if(w){if(w.a$?.defaultColWidth){let _=Number(w.a$.defaultColWidth);isNaN(_)||(N=xt(_))}if(w.a$?.defaultRowHeight){let _=Number(w.a$.defaultRowHeight);isNaN(_)||(y=Math.round(_*4/3))}}let x=[],I=[],G=h("worksheet/sheetData/row");for(let _ of G){let T=_.a$?.r?Number(_.a$.r):1,Z=y;if(_.a$?.ht){let C=Number(_.a$.ht);isNaN(C)||(Z=Math.round(C*4/3))}if(_.a$?.outlineLevel){let C=Number(_.a$.outlineLevel);isNaN(C)||(I[T-1]=C)}Z!==y&&(x[T-1]=Z);let P=_.c||[];Array.isArray(P)||(P=[P]);for(let C of P){let F=this.ParseCell(t,C,n,s,o,l,d);F&&r.push(F)}}let Y=[],k=-1,M=[],V=h("worksheet/cols/col");for(let _ of V){let T=Number(_.a$?.min),Z=Number(_.a$?.max);if(_.a$?.style){let P=Number(_.a$.style);if(!isNaN(T)&&!isNaN(Z)&&!isNaN(P))if(t.extent&&Z>=t.extent.to.col||Z-T>100)k=P;else for(let C=T;C<=Z;C++)Y[C]=P}if(_.a$?.customWidth){let P=Number(_.a$.width);if(!isNaN(T)&&!isNaN(Z)&&!isNaN(P)&&Z!==16384){P=xt(P);for(let C=T;C<=Z;C++)M[C-1]=P}}}let z=h("worksheet/tableParts/tablePart");for(let _ of z){let T=_.a$?_.a$["r:id"]:void 0;if(T){let Z="",P=t.rels[T];if(P){Z=P.target||"";let C=this.workbook.ReadTable(Z);if(C){let F=t.TranslateAddress(C.ref),b=Pe(F)?{start:{row:F.row-1,column:F.col-1},end:{row:F.row-1,column:F.col-1}}:{start:{row:F.from.row-1,column:F.from.col-1},end:{row:F.to.row-1,column:F.to.col-1}};for(let S of r)if(S.row===b.start.row&&S.column===b.start.column){S.table={area:b,name:C.name,totals_row:!!C.totals_row_count};break}}}}}let U=h("worksheet/drawing"),X=[],J=[];for(let _ of U){let T=_.a$?_.a$["r:id"]:void 0;if(T){let Z="",P=t.rels[T];if(P&&(Z=P.target||""),Z){let C=this.workbook.ReadDrawing(Z);if(C&&C.length)for(let F of C)switch(F.type){case"chart":X.push(F);break;case"image":J.push(F);break}}}}let B=_=>{let T={address:{row:_.row,column:_.column},offset:{x:0,y:0}};if(_.row_offset){let Z=x[_.row];Z===void 0&&(Z=y),T.offset.y=_.row_offset/9525/Z}if(_.column_offset){let Z=M[_.column];Z===void 0&&(Z=N),T.offset.x=_.column_offset/9525/Z}return T};for(let _ of J)if(_&&_.image){let T={tl:B(_.anchor.from),br:B(_.anchor.to)},Z="image",P=oi.default.fromByteArray(_.image),C="";if(_.filename&&(/jpe*g$/i.test(_.filename)?C="jpeg":/png$/i.test(_.filename)?C="png":/gif$/i.test(_.filename)&&(C="gif")),C&&P){let F="data:image/"+C+";base64,"+P;c.push({layout:T,type:Z,data:{src:F}})}}for(let _ of X)if(_&&_.chart){let T={tl:B(_.anchor.from),br:B(_.anchor.to)},Z,P=[],C="",F=_.chart?.series;switch(_.chart.type){case 4:Z="treb-chart",C="Scatter.Line",F&&F.length&&(P[0]=`Group(${F.map(S=>`Series(${S.title||""},${S.categories||""},${S.values||""})`||"").join(", ")})`),P[1]=_.chart.title;break;case 5:case 6:C=_.chart.type===5?"Donut.Chart":"Pie.Chart",Z="treb-chart",F&&F[0]&&(P[0]=F[0].values,P[1]=F[0]?.categories||""),P[2]=_.chart.title;break;case 2:case 1:case 3:switch(P[2]=_.chart.title,Z="treb-chart",_.chart.type){case 2:C="Bar.Chart";break;case 1:C="Column.Chart";break;default:C="Line.Chart"}F&&(F.length>1?P[0]=`Group(${F.map(S=>`Series(${S.title||""},,${S.values||""})`||"").join(", ")})`:F.length===1&&(F[0].title?P[0]=`Series(${F[0].title||""},,${F[0].values||""})`:P[0]=F[0].values),P[1]=F[0]?.categories||"");break}let b=`=${C}(${P.join(", ")})`;Z&&b&&c.push({layout:T,type:Z,formula:b})}let K=h("worksheet/extLst/ext");for(let _ of K){let T="";for(let P of Object.keys(_?.a$||{})){let C=P.match(/^xmlns:(.*)$/);if(C){T=C[1];break}}let Z=R.FindAll(_,`${T}:sparklineGroups/${T}:sparklineGroup`);for(let P of Z){let C="Sparkline.line",F="",b="";P.a$?.type==="column"&&(C="Sparkline.column");let S=R.FindAll(P,`${T}:sparklines/${T}:sparkline`);for(let W of S)for(let E of Object.keys(W))/:f$/.test(E)?b=W[E]:/:sqref$/.test(E)&&(F=W[E]);if(b&&F){let W=`=${C}(${b})`,E=t.TranslateAddress(F);if(Pe(E)){let A={row:E.row-1,column:E.col-1,value:W,type:"formula"},v=!1;for(let D of r)if(D.row===A.row&&D.column===A.column){v=!0,D.type="formula",D.value=W;break}v||r.push(A)}}}}let j={name:t.options.name,cells:r,default_column_width:N,column_widths:M,row_heights:x,annotations:c,conditional_formats:a,styles:this.workbook?.style_cache?.CellXfToStyles()||[]};return I.length&&(j.outline=I),(t.visible_state===1||t.visible_state===2)&&(j.hidden=!0),k>=0&&(j.sheet_style=k),Y.length&&(j.column_styles=Y),j}};var mt=self,qt=new ht,vs=i=>{i.sheet&&(qt.Init(i.decorated||[]),qt.Export(i.sheet),mt.postMessage({status:"complete",blob:qt.Blob()}))},Cs=i=>{let e=new ft;try{e.Init(i.data);let t=e.SheetCount(),r={sheets:[],names:e.workbook?.GetNamedRanges(),active_tab:e.workbook?.active_tab};for(let n=0;n<t;n++){let s=e.GetSheet(n);s&&r.sheets.push(s)}mt.postMessage({status:"complete",results:r})}catch(t){console.warn("error importing xlsx file"),console.info(t),mt.postMessage({status:"error",data:t})}};mt.addEventListener("message",i=>{i.data&&i.data.command==="export"?vs(i.data):i.data&&i.data.command==="import"&&Cs(i.data)});\n';var Qt=class c{static treb_base_path="";static treb_embedded_script_path="";static one_time_warnings={};DOM=F.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return D}language_model;events=new oe;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;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;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={...Pi,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(te.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,i;this.options.local_storage&&!this.options.toll_initial_load&&!e.model&&(r=localStorage.getItem(this.options.local_storage)||void 0,r&&(i="local-storage")),!r&&!this.options.toll_initial_load&&!e.model&&e.inline_document&&(r=e.inline_document,i="inline-document"),this.options.local_storage&&!e.model&&window.addEventListener("visibilitychange",s=>{document.visibilityState==="hidden"&&this.options.local_storage&&this.dirty&&this.SaveLocalStorage(this.options.local_storage)});let n;typeof this.options.container=="string"?n=document.querySelector(this.options.container):this.options.container&&(n=this.options.container);let a={insert_function_button:!1,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};if(this.options.scale&&(a.initial_scale=this.options.scale),this.options.stats&&(a.stats=this.options.stats,a.tab_bar=!0),this.options.scale_control&&(a.scale_control=!0,a.tab_bar=!0,this.options.persist_scale&&(a.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),a.persist_scale_key))){let s=localStorage.getItem(a.persist_scale_key);if(s)try{let o=JSON.parse(s);a.initial_scale=o.scale||1}catch{console.warn("parsing persisted scale failed")}}if(e.model?(this.model=e.model.model,this.calculator=e.model.calculator,this.DOM=e.model.DOM):(this.model=new at,this.model.sheets.Add(Y.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,e)),n&&(this.DOM=F.GetInstance(n.ownerDocument)),this.grid=new it(a,this.model,void 0,!!n,this.DOM),this.options.headless&&(this.grid.headless=!0),n){this.DOM=F.GetInstance(n.ownerDocument),this.parent_view||(re.is_windows?n.parentElement?.classList.add("treb-ua-windows"):re.is_mac&&n.parentElement?.classList.add("treb-ua-osx"));let s=n.querySelector(".treb-view-template");this.view=s.content.firstElementChild?.cloneNode(!0),n.prepend(this.view),this.view.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=l=>this.HandleKeyDown(l),n.addEventListener("keydown",this.key_listener);let o=!!(r||this.options.document);this.grid.Initialize(this.view,o),this.options.dnd&&(this.view.addEventListener("dragenter",l=>this.HandleDrag(l)),this.view.addEventListener("dragover",l=>this.HandleDrag(l)),this.view.addEventListener("drop",l=>this.HandleDrop(l))),this.grid.grid_events.Subscribe(l=>{switch(l.type){case"error":this.dialog?.ShowDialog({type:"error",...this.TranslateGridError(l.code),timeout:3e3,close_box:!0});break;case"selection":this.UpdateSelection(l.selection),this.UpdateSelectionStyle(l.selection);break;case"sheet-change":this.OnSheetChange(l),this.UpdateSelectionStyle();break;case"data":{let d=this.last_selection;(this.calculation===0?this.Recalculate(l):Promise.resolve()).then(()=>{this.DocumentChange(d)})}break;case"style":this.DocumentChange(),this.UpdateDocumentStyles(!1),this.UpdateSelectionStyle();break;case"scale":this.RebuildAllAnnotations(),this.events.Publish({type:"view-change"});break;case"annotation":if(l.annotation){let d=l.annotation.view[this.grid.view_index]||{};switch(this.DocumentChange(),l.event){case"create":this.InflateAnnotation(l.annotation),this.calculator.UpdateAnnotations(l.annotation,this.grid.active_sheet),this.grid.AnnotationUpdated(l.annotation);break;case"delete":this.calculator.RemoveAnnotation(l.annotation);break;case"update":d.update_callback?(d.update_callback(),this.grid.AnnotationUpdated(l.annotation)):console.info("annotation update event without update callback"),this.calculator.UpdateAnnotations(l.annotation,this.grid.active_sheet);break;case"resize":d.resize_callback&&(d.resize_callback(),this.grid.AnnotationUpdated(l.annotation));break}}else console.info("annotation event without annotation");break;case"structure":{let d=this.last_selection;l.rebuild_required?(this.calculator.Reset(),(this.calculation===0?this.Recalculate(l):Promise.resolve()).then(()=>{this.DocumentChange(d)})):this.DocumentChange(d)}this.UpdateSelectionStyle();break;case"cell-event":this.HandleCellEvent(l);break}}),this.options.prompt_save&&window.addEventListener("beforeunload",l=>{this.last_save_version!==this.file_version&&(l.preventDefault(),l.returnValue="")})}else c.one_time_warnings.headless||(c.one_time_warnings.headless=!0,console.info("not initializing layout; don't call UI functions"));if(r?(typeof r=="string"&&(r=JSON.parse(r)),r?this.LoadDocument(r,{recalculate:!!this.options.recalculate,source:i}):this.UpdateDocumentStyles()):t||(this.calculator.RebuildClean(!0),this.UpdateDocumentStyles()),this.FlushUndo(),this.grid.ShowHeaders(this.options.headers),this.options.scroll&&!this.options.document){let s=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(s)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),n&&this.options.spinner&&(this.spinner=new Jt(n)),t&&!e.model&&!r&&this.LoadNetworkDocument(t,this.options),n&&(this.dialog=new Yt(n))}UpdateAC(){let e=this.calculator.SupportedFunctions();if(this.language_model){let t={};for(let r of this.language_model.functions||[])t[r.base.toUpperCase()]=r;e=e.map(r=>t[r.name.toUpperCase()]||r)}this.grid.SetAutocompleteFunctions(e)}CreateCalculator(e,t){return new jt(e,{complex_numbers:t.complex})}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 c({...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?.parentElement&&(t.key_listener&&t.view.parentElement.removeEventListener("keydown",t.key_listener),t.view.parentElement.removeChild(t.view)),this.view?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view?.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.tab_bar?.Update())}),e.Subscribe(r=>{switch(r.type){case"selection":break;default:e.UpdateAnnotations(),this.grid.Update(!0)}}),this.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(e.grid.EnsureActiveSheet(),e.grid.UpdateLayout(),e.grid.tab_bar?.Update())});let t=this.Subscribe(r=>{switch(r.type){case"selection":break;case"load":case"reset":e.grid.EnsureActiveSheet(!0),e.UpdateAnnotations(),e.grid.Update(!0);break;default:e.UpdateAnnotations(),e.grid.Update(!0)}});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){if(e===void 0){let r=this.GetSelectionReference();if(r.empty)throw new Error("invalid range (no selection)");e=r.area}return this.AddConditionalFormat({type:"duplicate-values",area:this.model.ResolveArea(e,this.grid.active_sheet),...t})}ConditionalFormatGradient(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let r=this.model.ResolveArea(e,this.grid.active_sheet),i=typeof t=="object"?{type:"gradient",area:r,...t}:{type:"gradient",area:r,...mi[t]};return this.AddConditionalFormat(i),i}ConditionalFormatCellMatch(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let i={type:"cell-match",area:this.model.ResolveArea(e,this.grid.active_sheet),...t};return this.AddConditionalFormat(i),i}ConditionalFormatExpression(e,t){if(e===void 0){let n=this.GetSelectionReference();if(n.empty)throw new Error("invalid range (no selection)");e=n.area}let i={type:"expression",area:this.model.ResolveArea(e,this.grid.active_sheet),...t};return this.AddConditionalFormat(i),i}AddConditionalFormat(e){let t=this.model.sheets.Find(e.area.start.sheet_id||0);if(!t)throw new Error("invalid reference in format");return t.conditional_formats.push(e),this.calculator.UpdateConditionals(e,t),this.ApplyConditionalFormats(t,t===this.grid.active_sheet),this.PushUndo(),e}RemoveConditionalFormat(e){let t=e.area,r=t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):this.grid.active_sheet;if(!r)throw new Error("invalid reference in format");let i=0;r.conditional_formats=r.conditional_formats.filter(n=>n===e?(i++,this.calculator.RemoveConditional(n),!1):!0),i&&r.FlushConditionalFormats(),this.ApplyConditionalFormats(r,!1),r===this.grid.active_sheet&&this.grid.Update(!0),i&&this.PushUndo()}RemoveConditionalFormats(e){if(e===void 0){let i=this.GetSelectionReference();if(i.empty)throw new Error("invalid range (no selection)");e=i.area}let t=this.model.ResolveArea(e,this.grid.active_sheet),r=t.start.sheet_id?this.model.sheets.Find(t.start.sheet_id):this.grid.active_sheet;if(r){let i=0;r.conditional_formats=r.conditional_formats.filter(n=>new y(n.area.start,n.area.end).Intersects(t)?(i++,this.calculator.RemoveConditional(n),!1):!0),i&&(r.FlushConditionalFormats(),this.ApplyConditionalFormats(r,!1),r===this.grid.active_sheet&&this.grid.Update(!0),this.PushUndo())}}HandleToolbarMessage(e){if(this.focus_target!==this){this.focus_target.HandleToolbarMessage(e);return}let t={},r=i=>{let n=this.grid.GetSelection();if(n&&!n.empty){let a=n.area.spreadsheet_label;this.InsertAnnotation(`=${i}(${a},,"${a}")`,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(i){console.error(i)}else{let i=1,n=e.command.substring(7);e.command==="border-double-bottom"&&(n="bottom",i=2),this.grid.ApplyBorders2(void 0,n,e.color||{},i)}else switch(e.command){case"about":this.About();break;case"number-format":t.number_format=e.format||"General";break;case"font-scale":{let i=this.grid.GetSelection(),n=this.grid.active_sheet.RealArea(i.area),a=Number(e.scale||1);if(a&&!isNaN(a)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:a}},!0);let s=[];for(let o=n.start.row;o<=n.end.row;o++)s.push(o);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 i=e.color||{};e.command==="text-color"?t.text=i:e.command==="fill-color"&&(t.fill=i)}catch(i){console.error(i)}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 i=this.grid.GetFreeze();i.rows||i.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"increase-precision":case"decrease-precision":if(this.selection_state?.style){let i=I.Get(this.selection_state.style.number_format||"General");if(i.date_format)break;let n=new te(i.pattern);if(i.magic_decimal){let a=0,s=this.GetRange();Array.isArray(s)||(s=[[s]]);e:for(let o=0;o<s.length;o++)for(let l=0;l<s[o].length;l++){let d=s[o][l];if(typeof d<"u"&&fe(d)){let h=I.Get(this.selection_state.style.number_format||"General",!0),u=h.BaseFormat(d.real),m=h.BaseFormat(d.imaginary);u.parts&&typeof u.parts[1]=="string"&&(a=u.parts[1].length),m.parts&&typeof m.parts[1]=="string"&&(a=Math.max(a,m.parts[1].length));break e}else if(typeof d=="number"){let h=i.BaseFormat(d);h.parts&&typeof h.parts[1]=="string"&&(a=h.parts[1].length);break e}}e.command==="increase-precision"?n.SetDecimal(a+1):n.SetDecimal(Math.max(0,a-1))}else e.command==="increase-precision"?n.IncreaseDecimal():n.DecreaseDecimal();t.number_format=n.toString()}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.
|
|
12
12
|
You can revert to the original or save your
|
|
13
|
-
changes in the sidebar.`,close_box:!0,timeout:5e3,type:"info"});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",
|
|
13
|
+
changes in the sidebar.`,close_box:!0,timeout:5e3,type:"info"});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",Vr)&&this.UpdateAC(),new ct}SetLanguage(e){if(this.language_model=e,!e)this.grid.SetLanguageMap();else{let t={};for(let r of e.functions||[])t[r.base]=r.name;this.grid.SetLanguageMap(t)}this.UpdateAC()}async Batch(e,t=!1){let r=this.last_selection,i=this.grid.Batch(e,t),n=!1,a=!1;for(let s of i)s.type==="data"?n=!0:s.type==="structure"&&s.rebuild_required&&(a=!0);a&&this.calculator.Reset(),(n||a)&&(await 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;this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0)}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,i=t.theme;typeof i=="number"&&(i=ut(i)),this.grid.InsertTable(r,t.totals_row,t.sortable,i)}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=ut(t)),r.theme=t,this.grid.active_sheet.FlushCellStyles(),this.grid.Update(!0),this.PushUndo())}AddSheet(e){this.grid.AddSheet(e);let t=this.model.sheets.list[this.model.sheets.list.length-1];return this.calculator.Reset(),t.id}InsertAnnotation(e,t="treb-chart",r,i){let n,a,s=!1;if(typeof i=="object"?(a=i.argument_separator,s=!!i.r1c1):(i===","||i===";")&&(a=i),r&&(n=H.IsRectangle(r)?r:this.model.ResolveArea(r,this.grid.active_sheet)),a&&a!==this.parser.argument_separator||s){let u={argument_separator:this.parser.argument_separator,decimal_mark:this.parser.decimal_mark};a===","?(this.parser.argument_separator=",",this.parser.decimal_mark="."):(this.parser.argument_separator=";",this.parser.decimal_mark=",");let m=this.parser.flags.r1c1;s&&(this.parser.flags.r1c1=s);let f=this.parser.Parse(e);this.parser.argument_separator=u.argument_separator,this.parser.decimal_mark=u.decimal_mark,this.parser.flags.r1c1=m,f.expression&&(e="="+this.parser.Render(f.expression,{missing:""}))}let{x:o,y:l}=this.grid.GetScrollOffset(),d=this.grid.scale||1,h={width:301,height:301};this.grid.CreateAnnotation({type:t,formula:e},void 0,void 0,n||{top:l/d+30,left:o/d+30,...h})}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)}ShowSheet(e=0,t=!0){this.grid.ShowSheet(e,t)}ActivateSheet(e){this.grid.ActivateSheet(e)}SetColumnWidth(e,t){this.grid.SetColumnWidth(e,t)}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 i=r.area;e=i.entire_column?0:i.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 i=r.area;e=i.entire_row?0:i.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 i=r.area;e=i.entire_column?0:i.start.row,t=i.rows}this.grid.InsertRows(e,-t)}DeleteColumns(e,t=1){if(typeof e>"u"){let r=this.grid.GetSelection();if(r.empty)return;let i=r.area;e=i.entire_row?0:i.start.column,t=i.columns}this.grid.InsertColumns(e,-t)}FilterTable(e,t=0,r){let i=this.ResolveTable(e);if(!i)throw new Error("invalid table reference");r?this.grid.FilterTable(i,t,n=>r.call(0,n.value,n.calculated||void 0,JSON.parse(JSON.stringify(n.style||{})))):this.grid.FilterTable(i,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(){return this.export_worker||(this.export_worker=await this.LoadWorker("export")),new Promise((e,t)=>{if(this.export_worker){this.export_worker.onmessage=i=>{e(i.data?i.data.blob:void 0)},this.export_worker.onerror=i=>{console.error("export worker error"),console.info(i),t(i)};let r=this.grid.Serialize({rendered_values:!0,expand_arrays:!0,export_colors:!0,decorated_cells:!0,tables:!0,share_resources:!1});r.decimal_mark=D.decimal_separator,this.export_worker.postMessage({command:"export",sheet:r,decorated:this.calculator.DecoratedFunctionList()})}else t("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.calculator.AttachModel(),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,i=t?!!t.recalculate:!1,n=t?t.sheet:void 0,a=/csv(?:$|\?|&)/i.test(e),s=/tsv(?:$|\?|&)/i.test(e);try{this.spinner?.Show();let o=await fetch(e);if(this.spinner?.Hide(),!o.ok)throw new Error("network error");let l=await o.text();if(typeof l=="string")if(a)this.LoadCSV(l,"network-file");else{if(s)throw new Error("tsv not supported (TODO)");{l.substr(0,11)==="&&&START&&&"?l=l.substr(11):l.substr(0,8)==="for(;;);"&&(l=l.substr(8));let d=JSON.parse(l);this.LoadDocument(d,{scroll:r,recalculate:i,override_sheet:n,source:"network-file"})}}}catch(o){console.info("error loading network document",e),console.error(o),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}),i=[];for(let s=0;s<r.columns;s++)i.push("");let n=[];for(let s=0;s<r.rows;s++)n.push(i.slice(0));let a=new RegExp(`[
|
|
14
14
|
\r"${e.delimiter}]`);if(je(r.data))for(let s of r.data){let o="";!e.formulas&&typeof s.calculated<"u"?o=fe(s.calculated)?Le(s.calculated):s.calculated.toString():typeof s.value=="string"&&s.value[0]==="'"?o=s.value.substr(1):typeof s.value<"u"&&(o=fe(s.value)?Le(s.value):s.value.toString()),a.test(o)&&(o=o.replace(/"/g,'""'),o='"'+o+'"'),n[s.row][s.column]=o}return n.map(s=>s.join(e.delimiter)).join(`\r
|
|
15
|
-
`)}SaveLocalFile(e="treb.json",t={}){this.SaveToDesktop(e,t)}SaveToDesktop(e="treb.json",t={}){let r=this.grid.model.document_name||"document",i,n,a=e.split(/\./).filter(o=>o.trim().length),s=a.length?a[a.length-1].toLowerCase():"treb";if(a.length<=1||e==="treb.json")if(e==="treb.json"&&(s=e),(s==="csv"||s==="tsv")&&this.grid.model.sheets.length>1){let o=this.grid.active_sheet.name;e=(r+"-"+o).toLowerCase().replace(/\W+/g,"-")+"."+s}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+s;switch(s){case"csv":n=this.ExportDelimited({delimiter:","});break;case"tsv":n=this.ExportDelimited({delimiter:" "});break;case"treb":case"json":case"treb.json":i=this.SerializeDocument({...t}),n=JSON.stringify(i,void 0,t.pretty?2:void 0),this.last_save_version=this.file_version;break;default:throw new Error("invalid file type")}if(n&&e){let o=new Blob([n],{type:"text/plain;charset=utf-8"});this.SaveAs(o,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 i of r)if(i.id===t.override_selection.target.sheet_id){i.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=N(r)?r:r.start}this.grid.SetNote(e,t)}SetValidation(e,t,r){if(typeof e=="string"){let i=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(i)?i:i.start}if(typeof t>"u"||Array.isArray(t))this.grid.SetValidation(e,t,r);else{let i=this.model.ResolveArea(t,this.grid.active_sheet);this.grid.SetValidation(e,i,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(i=>i.trim()):[]);for(let i of t)if(!i.length||/^[^A-Za-z]/.test(i)||/[^\w_.]/.test(i))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.grid.Serialize(e),r={app:"@trebco/treb",version:"28.2.3",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:D.decimal_separator,...t};if(e.share_resources){let i=1,n=new Map,a=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],s=l=>{let d=n.get(l);return d||(d=(i++).toString(),n.set(l,d)),`resource:${d}`};for(let l of a)if(l){l.background_image&&(l.background_image=s(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=s(d.data.src))}let o={};for(let[l,d]of n.entries())o[d]=l;r.shared_resources=o}return e.rendered_values&&(r.rendered_values=!0),r}async Recalculate(e){let t;e&&e.type==="data"&&e.area&&(t=e.area),this.calculator.Calculate(t),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"})}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(r)?r:r.start}t={x:!0,y:!0,smooth:!1,...t},this.grid.ScrollTo(e,t.x,t.y,t.smooth)}Resolve(e){let t=this.model.ResolveAddress(e,this.grid.active_sheet);return N(t)?t.sheet_id?t:void 0:t.start.sheet_id?t:void 0}Unresolve(e,t=!0,r=!0){if(typeof e=="string"){let i=this.Resolve(e);if(!i)throw new Error("invalid reference");e=i}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=y.CellAddressToLabel(t.area.start)+":"+y.CellAddressToLabel(t.area.end):r=y.CellAddressToLabel(t.area.start),!e)return r;let i=t.area.start.sheet_id||this.grid.active_sheet.id,n=this.calculator.ResolveSheetName(i,!0);return n?n+"!"+r:r}ParseNumber(e){return be.TryParse(e).value}FormatNumber(e,t="General"){return I.Get(t).Format(e)}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)}DefineName(e,t){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof t=="object"&&(N(t)||Pr(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet));return}if(typeof t=="string"){let r=this.parser.Parse(t);if(!r.expression)throw new Error("invalid expression");switch(r.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(r.expression,this.grid.active_sheet));return}this.grid.SetName(e,void 0,t)}else this.grid.SetName(e,void 0,t.toString())}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(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)}GetRange(e,t={}){if(!e){let r=this.GetSelectionReference();r.empty||(e=r.area)}if(e)return t.type||(t.formatted&&(t.type="formatted"),t.formula&&(t.type="formula")),this.grid.GetRange(this.model.ResolveAddress(e,this.grid.active_sheet),t.type)}GetStyle(e,t=!1){if(!e){let r=this.GetSelectionReference();r.empty||(e=r.area)}if(e)return this.grid.GetRangeStyle(this.model.ResolveAddress(e,this.grid.active_sheet),t)}SetRange(e,t=void 0,r={}){if(!e){let i=this.GetSelectionReference();i.empty||(e=i.area)}if(e){let i=this.model.ResolveArea(e,this.grid.active_sheet);if(r.spill&&Array.isArray(t)){let n=t.length,a=Math.max(0,...t.map(o=>o.length)),s={row:i.start.row+n+1,column:i.start.column+a+1};i.ConsumeAddress(s)}return this.grid.SetRange(i,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}ApplyConditionalFormats(e,t){let r=[];if(e.conditional_formats.length||e.flush_conditional_formats){for(let i of e.conditional_formats)r.push(i.area),i.type==="gradient"&&(i.internal||(i.internal={}),i.internal.gradient||(i.internal.gradient=new ft(i.stops,this.grid.theme,i.color_space)));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);N(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){return this.parent_view?this.parent_view.ImportXLSX(e,t):(this.export_worker||(this.export_worker=await this.LoadWorker("export")),new Promise((r,i)=>{this.export_worker?(this.dialog?.ShowDialog({message:"Importing XLSX..."}),this.export_worker.onmessage=n=>{if(n.data){if(n.data.status==="error")return i(n.data.error||"unknown error");this.grid.FromImportData(n.data.results),this.ResetInternal(),this.grid.Update(),this.UpdateAC(),this.calculator.AttachModel(),this.Publish({type:"load",source:t}),this.UpdateDocumentStyles(),this.InflateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)}else return i("unknown error (missing data)");this.dialog?.HideDialog(),r()},this.export_worker.onerror=n=>{console.error("import worker error"),console.info(n),i(n)},this.export_worker.postMessage({command:"import",data:e})):i("worker failed")}))}ResetInternal(){this.calculator.Reset(),this.FlushUndo(),this.file_version=this.last_save_version=0}HandleCellEvent(e){if(e.data?.type==="hyperlink"){let r="hyperlink invalid target",i=e.data.data||"";if(typeof i=="string"){if(/^https{0,1}:\/\//i.test(i)){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",i),n.setAttribute("noreferrer","true"),n.setAttribute("nofollow","true"),n.click();return}else{let n=this.parser.Parse(i);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(i);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(i);return}}}console.warn(r,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 i=r.files[0];switch(r.value="",this.file_chooser_operation){case 2:this.InsertImageInternal(i);break;case 1:this.LoadFileInternal(i,"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,i)=>{let n=new FileReader;n.onload=async()=>{try{if(n.result){let a;if(typeof n.result=="string")a=n.result;else{a="";let l=new Uint8Array(n.result);for(let d=0;d<l.byteLength;d++)a+=String.fromCharCode(l[d])}let s=this.DOM.Create("img");s.src=a,await Promise.resolve();let o=this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:a,original_size:{width:s.width||300,height:s.height||300}}},void 0,void 0,{top:30,left:30,width:s.width||300,height:s.height||300})}r()}catch(a){i(a)}},n.onabort=()=>{i("Aborted")},n.onerror=()=>{i("File error")},setTimeout(()=>{n.readAsDataURL(t)},100)})}LoadFileInternal(e,t,r=!0){if(!e)return Promise.resolve();let i=new FileReader;return new Promise((n,a)=>{let s=o=>{i.onload=null,i.onabort=null,i.onerror=null,o?(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(o)),a(o)):n()};i.onload=()=>{try{if(i.result)if(/\.csv$/i.test(e.name))this.LoadCSV(i.result,t);else if(/\.xls[xm]$/i.test(e.name)){typeof i.result=="string"?s("Unsupported file"):this.ImportXLSX(i.result,t).then(()=>s()).catch(o=>s(o));return}else{let o=JSON.parse(i.result);this.LoadDocument(o,{source:t})}s()}catch(o){s(o?.toString())}},i.onabort=()=>{s("Aborted")},i.onerror=()=>{s("File error")},setTimeout(()=>{/\.xls[xm]$/i.test(e.name)?i.readAsArrayBuffer(e):i.readAsText(e)},100)})}UpdateAnnotations(){for(let e of this.grid.active_sheet.annotations){if(e.temp.vertex){let r=e.temp.vertex;if(r.state_id!==e.temp.state){e.temp.state=r.state_id;for(let i of e.view)i.dirty=!0}}let t=e.view[this.grid.view_index]||{};t.dirty&&(t.update_callback&&t.update_callback(),this.grid.AnnotationUpdated(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 i=()=>{if(e.data.formula){let n=this.parser.Parse(e.data.formula);if(n&&n.expression&&n.expression.type==="call"){this.parser.Walk(n.expression,o=>((o.type==="address"||o.type==="range")&&this.model.ResolveSheetID(o,void 0,this.grid.active_sheet),!0));let a=n.expression.name.toLowerCase(),s=this.calculator.CalculateExpression(n.expression);r.Exec(a,s)}}r.Update()};t.resize_callback=()=>{this.grid.headless||(r.Resize(),r.Update())},t.update_callback=()=>{this.grid.headless||i()},t.node?.parentElement&&(this.grid.headless||i())}else if(e.data.type==="image"&&typeof e.data.data?.src=="string"){let r=mt(e.data.data.src);if(r){let i=this.DOM.Create("img");i.src=r,e.data.data.scale==="fixed"?(i.style.position="relative",i.style.left="50%",i.style.top="50%",i.style.transform="translate(-50%, -50%)"):(i.style.width="100%",i.style.height="100%"),t.content_node.appendChild(i)}}}}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,i=document.location.href;for(let a=0,s=i.length;a<s;a++)r=(r<<5)-r+i.charCodeAt(a),r|=0;let n=Math.abs(r).toString(16);return t?t+"-"+n:n}return e}}PushUndo(e,t,r=!0){let i=t||this.last_selection;this.undo_stack[this.undo_pointer-1]&&(this.undo_stack[this.undo_pointer-1].selection=i),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 n=this.undo_stack.length;if(n>16){let a=n-16;this.undo_stack=this.undo_stack.slice(a),this.undo_pointer-=a}}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){this.last_selection=JSON.stringify(e),this.Publish({type:"selection"})}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 i=this.grid.active_sheet.CellData(e.target);r.table=!!i.table,r.merge=!!i.merge_area,r.merge&&i.merge_area&&(i.merge_area.start.row!==e.target.row||i.merge_area.start.column!==e.target.column)&&(i=this.grid.active_sheet.CellData(i.merge_area.start)),r.comment=i.note,r.style=i.style?{...i.style}:void 0,r.relative_font_size=V.RelativeFontSize(r.style||{},this.grid.theme.grid_cell||{})}this.selection_state=r}UpdateDocumentStyles(e=!0){let t={},r={};for(let n of this.grid.model.sheets.list)n.NumberFormatsAndColors(r,t);this.document_styles.colors=Object.keys(r),this.document_styles.number_formats=Object.keys(t),this.document_styles.theme_colors=[];let i=[.5,.25,0,-.25,-.5];for(let n=0;n<10;n++)this.document_styles.theme_colors.push(i.map(a=>{let s={theme:n,tint:a},o=T(this.grid.theme,s);return{color:s,resolved:o}}))}ConvertLocale(e){let t=new Ge;t.flags={...this.parser.flags};let r,i;e.decimal_mark==="."?(t.decimal_mark=".",t.argument_separator=",",r=",",i=";"):(t.decimal_mark=",",t.argument_separator=";",r=".",i=",");let n=a=>{let s=t.Parse(a);if(s.expression)return"="+t.Render(s.expression,{missing:"",convert_decimal:r,convert_argument_separator:i})};if(e.macro_functions)for(let a of e.macro_functions){let s=n(a.function_def);s&&(a.function_def=s)}if(e.sheet_data){let a=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let s of a){if(s.annotations){for(let o of s.annotations)if(o.formula){let l=n(o.formula);l&&(o.formula=l)}}if(s.data?.length)for(let o of s.data){let l=tr(o)?[o]:o.cells;for(let d of l)if(d.value&&typeof d.value=="string"&&d.value[0]==="="){let h=n(d.value.slice(1));h&&(d.value=h)}}}}}CompareVersions(e="",t=""){let r=e.split(".").map(s=>Number(s)||0).concat([0,0,0]),i=t.split(".").map(s=>Number(s)||0).concat([0,0,0]),n=[0,1,2],a={match:0};for(let s=0;s<3;s++)if(r[s]!==i[s]){a.match=r[s]>i[s]?1:-1,a.level=n[s];break}return a}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],i=this.CompareVersions(e.version,"28.2.3");if(i.match>0&&(i.level===0||i.level===1)&&console.warn(`The file you are opening was created with a newer version of TREB (${e.version} vs 28.2.3).
|
|
16
|
-
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 s=e.shared_resources,o=l=>/^resource:/.test(l)?s[l.substring(9)]||"":l;for(let l of r){l.background_image&&(l.background_image=o(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=o(d.data.src))}}e.decimal_mark&&e.decimal_mark!==D.decimal_separator&&this.ConvertLocale(e);let n=this.grid.model;if(n.tables.clear(),e.tables)for(let s of e.tables)n.tables.set(s.name.toLowerCase(),s);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let[s,o]of this.model.tables.entries())if(o.area.start.sheet_id){let l=n.sheets.Find(o.area.start.sheet_id);if(l)for(let d=o.area.start.row;d<=o.area.end.row;d++)for(let h=o.area.start.column;h<=o.area.end.column;h++){let u=l.cells.GetCell({row:d,column:h},!0);u.table=o}}n.document_name=e.name,n.user_data=e.user_data,n.named_ranges.Reset();let a=e.named_ranges;if(!a&&r[0]&&r[0].named_ranges&&(a=r[0].named_ranges),a&&n.named_ranges.Deserialize(a),n.named_expressions.clear(),e.named_expressions)for(let s of e.named_expressions){let o=this.parser.Parse(s.expression);o.valid&&o.expression&&(this.parser.Walk(o.expression,l=>{if(l.type==="address"||l.type==="range"){if(l.type==="range"&&(l=l.start),!l.sheet_id&&l.sheet){let d=this.model.sheets.Find(l.sheet);d&&(l.sheet_id=d.id)}return l.sheet_id||(l.sheet_id=this.grid.active_sheet.id),!1}return!0}),n.named_expressions.set(s.name.toUpperCase(),o.expression))}if(n.macro_functions.clear(),e.macro_functions)for(let s of e.macro_functions)n.macro_functions.set(s.name.toUpperCase(),{...s,expression:this.parser.Parse(s.function_def||"").expression});this.UpdateAC()}async LoadWorker(e){if(Fr)try{return new Worker(URL.createObjectURL(new Blob([Lr],{type:"application/javascript"})))}catch(t){console.info("embedded worker failed"),console.error(t)}throw new Error("creating worker failed")}HandleKeyDown(e){e.ctrlKey&&(e.code==="KeyZ"||e.key==="z")&&(e.stopPropagation(),e.preventDefault(),this.Undo())}};var Gi=`@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;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;margin-right:6px;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 .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[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-formula-bar .formula-button{border:1px solid #ccc;border-radius:2px;height:1.75em;margin-left:6px;overflow:hidden;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .formula-button .text-1{font-style:italic;padding-right:.1em}.treb-main.treb-main .treb-formula-bar .formula-button .text-1:after{content:"f"}.treb-main.treb-main .treb-formula-bar .formula-button .text-2{font-size:.7em}.treb-main.treb-main .treb-formula-bar .formula-button .text-2:after{content:"(x)"}.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-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[hidden]{display:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{display:inline-block;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{overflow-x:hidden;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;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-width:1.5px;stroke-linecap:round}.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{margin-left:auto;overflow:hidden;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-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;grid-area:2/1/3/2;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;flex-grow:1;grid-template-columns:100px auto;grid-template-rows:20px auto;order:2;outline:none;overflow:scroll;position:relative}.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;-moz-transform:scale(1);z-index:10}.treb-main.treb-main .treb-grid .frozen-selection{overflow:hidden;pointer-events:none;position:absolute;-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{stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4));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)}.treb-main.treb-main .grid-cells{stroke:var(--treb-grid-grid-color,#ccccd4);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)}.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{stroke:none;color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1))}.treb-main.treb-main .treb-header-overlay .treb-overlay{fill:#000;stroke:none;opacity:.05}.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 .outline,.treb-main.treb-main .treb-grid-selection .selection .outline{stroke:currentColor;fill:none}.treb-main.treb-main .frozen-selection .selection .fill,.treb-main.treb-main .treb-grid-selection .selection .fill{stroke:none;fill:currentColor;opacity:var(--treb-selection-fill-opacity,.1)}.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 .nub,.treb-main.treb-main .treb-grid-selection .primary-selection .nub{stroke:#fff;fill:currentColor;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);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{--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-64Zm-240-80c0-44 36-80 80-80s80 36 80 80v80H176v-80Z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);content:"";height:12px;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;opacity:.4;position:absolute;right:2px;top:2px;width:12px}.treb-main.treb-main.treb-ua-windows .grid-cells{font-family:var(--treb-grid-font-family-windows,var(--treb-grid-font-family,"Calibri","BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif"));font-size:var(--treb-grid-font-size-windows,var(--treb-grid-font-size,12pt))}.treb-main.treb-main.treb-ua-osx .grid-cells{font-family:var(--treb-grid-font-family-osx,var(--treb-grid-font-family,inherit));font-size:var(--treb-grid-font-size-osx,var(--treb-grid-font-size,10pt))}.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-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-active-tab-background:#444;--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:field;--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}@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-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-active-tab-background:#444;--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:field;--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-chart,.treb-main.treb-main .treb-chart{background:var(--treb-chart-background,#fff)}.treb-chart .series-1{color:var(--treb-chart-color-series-1,#80b1d3)}.treb-chart .series-2{color:var(--treb-chart-color-series-2,#8dd3c7)}.treb-chart .series-3{color:var(--treb-chart-color-series-3,#bebada)}.treb-chart .series-4{color:var(--treb-chart-color-series-4,#fb8072)}.treb-chart .series-5{color:var(--treb-chart-color-series-5,#fdb462)}.treb-chart .series-6{color:var(--treb-chart-color-series-6,#b3de69)}.treb-chart .series-7{color:var(--treb-chart-color-series-7,#fccde5)}.treb-chart .series-8{color:var(--treb-chart-color-series-8,#d9d9d9)}.treb-chart .series-9{color:var(--treb-chart-color-series-9,#bc80bd)}.treb-chart .series-10{color:var(--treb-chart-color-series-10,#ccebc5)}.treb-chart .series-11{color:var(--treb-chart-color-series-11,#ffed6f)}.treb-chart .series-12{color:var(--treb-chart-color-series-12,#ffffb3)}.treb-chart .chart-title{font-size:1.4em}.treb-chart .axis-group{font-size:.9em}.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 .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .label-target{stroke:none;fill:transparent}.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{stroke:currentColor;fill:none;stroke-width:2}.treb-chart .chart-area .line{stroke:currentColor;stroke-width:2px;fill:none}.treb-chart .chart-area .fill{fill:currentColor;opacity:.5}.treb-chart .scatter-plot{stroke-width:3;fill:none;stroke:currentColor}.treb-chart .scatter-plot .fill{fill:currentColor;stroke:none;opacity:.5}.treb-chart .scatter-plot .marker{stroke-width:2.5px;fill:#fff;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.567z'/%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{fill:#73828c;cursor:default;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"><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-.708z"/></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.502 4.502 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.5zM28 1v8c0 .547-.453 1-1 1a.99.99 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.75a.996.996 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-2h5.5zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1h4zm2.5-6v2H0v-2h13.5zm-10-8v2H0V6h3.5zM24 22v2H12.5v-2H24zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1h4zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1h4zm5 2v2h-3.5v-2H24zm0-8v2H10.5V6H24z"/></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-1zm4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1zm2-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.5zm-5.078-8.891a.984.984 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.984.984 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.609z"/></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.016A.996.996 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a.99.99 0 0 1-.297.703l-2.141 2.141A7.985 7.985 0 0 0 11.998 22a7.976 7.976 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-1a.99.99 0 0 1 .297-.703l2.156-2.156A8.036 8.036 0 0 0 12 6a7.976 7.976 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.016A.996.996 0 0 1 23 3c.547 0 1 .453 1 1z"/></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-.5zM18 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.477.477 0 0 0 .297.094.498.498 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 12z"/></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.406z"/></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.406z"/></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.972 11.972 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.599.599 0 0 1 .391-.141.51.51 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.952 7.952 0 0 0 6.563 8.14l2.141 2.156a.964.964 0 0 1 .219 1.078 1.002 1.002 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.964.964 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.5z"/></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"><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-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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"><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-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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"><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-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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'%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.5z'/%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"><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 8zm7-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 0zm-.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 0v-3.793z"/></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'%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 1z'/%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"><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-7a1.99 1.99 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 4H2.19zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139C1.72 3.042 1.95 3 2.19 3h5.396l-.707-.707z"/></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 1zM10 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-5zM3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5z"/></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"><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 1h-4zM10 .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-.5zM.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-.5zm15 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-.5z"/></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"><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-.5zm5 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-.5zM0 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-.5zm10 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 0v-4z"/></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"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 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-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/></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"><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-1h12zM2 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-2H2z"/></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"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a2.972 2.972 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.01 1.01 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4.322 4.322 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067-.707-.707-1.441-1.279-2.068-1.627-.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.283 3.283 0 0 1-.131-.673c.091.061.204.15.337.274zm.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.088c.054.12.115.243.183.365.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626.122.068.244.13.365.183l-4.861 4.862a.571.571 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46-.66-.66-1.168-1.32-1.46-1.846-.147-.265-.225-.47-.251-.607a.573.573 0 0 1-.01-.068l3.048-3.047zm2.87-1.935a2.44 2.44 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.497 3.497 0 0 0-1.066.091 11.27 11.27 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"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604h-1.3zM8.418 3.604a5.908 5.908 0 0 1-.127-.387 3.618 3.618 0 0 1-.11-.501h-.035a5.492 5.492 0 0 1-.247.888L5.86 9.211h4.614L8.418 3.604z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 15h16v1H0v-1z"/></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"><path d="M0 0v1h16V0H0zm1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0V16zm1.906 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469h.031z"/></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"><path d="M0 0v16h1V0H0zm1.906 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM7.5 1.906v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1.906 8.5h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM7.5 9.406v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-8.5.937v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-8.5.937v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM1.906 16h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469h.031z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zM16 0h-1v16h1V0zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 11.281v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 13.156v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0V16zm1.906 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1h.001zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938l1 .001zm6.5-.938v.938h1V3.78h-1v.001zm7.5 0v.938h1V3.78h-1v.001zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1h.001zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 15h16v1H0v-1zm0-2h16v1H0v-1z"/></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"><path d="M0 0h16v16H0V0zm1 1v6.5h6.5V1H1zm7.5 0v6.5H15V1H8.5zM15 8.5H8.5V15H15V8.5zM7.5 15V8.5H1V15h6.5z"/></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"><path d="M7.5 1.906v.938h1v-.938h-1zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938h-1zM1.906 8.5h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zM7.5 9.406v.938h1v-.938h-1zm0 1.875v.938h1v-.938h-1zm0 1.875v.938h1v-.938h-1z"/><path d="M0 0v16h16V0H0zm1 1h14v14H1V1z"/></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"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0V0zm2.844 1h-.938V0h.938v1zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938v1zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1H7.53zm2.813 0h-.938V0h.938v1zm1.875 0h-.938V0h.938v1zm1.875 0h-.938V0h.938v1zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5V1zM1 1.906v.938H0v-.938h1zm6.5.938v-.938h1v.938h-1zm7.5 0v-.938h1v.938h-1zM1 3.78v.938H0V3.78h1zm6.5.938V3.78h1v.938h-1zm7.5 0V3.78h1v.938h-1zM1 5.656v.938H0v-.938h1zm6.5.938v-.938h1v.938h-1zm7.5 0v-.938h1v.938h-1zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969V8.5zm1.875 0h-.938v-1h.938v1zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938h-.031zm1.875.031h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5V8.5zM0 10.344v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM0 12.22v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM0 14.094v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969v.5zm1.875 0h-.938v-1h.938v1zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938v1zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5H7.53zm2.813 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16h-.969z"/></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"><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.5H3a2.99 2.99 0 0 1-2.121-.879A2.99 2.99 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188v5.647zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0zM15 15v-4H9.258l-4.015 4H15zM0 .5v12.495V.5z"/><path d="M0 12.995V13a3.07 3.07 0 0 0 0-.005z"/></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"><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.54-.704-.71zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526-.703-.711zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514-.704-.71zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5-.704-.711zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3zM5 9v6h6L5 9zm1 2.414L8.586 14H6v-2.586z"/></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"><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"><path d="M4.5 17.5a.5.5 0 0 1-1 0v-5a.5.5 0 0 1 1 0v5zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0v9zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0v13zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0v14z"/></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"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.006 9.006 0 0 0 12 1.23zM2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9.001 9.001 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.432 7.432 0 0 1 2.5 10zM17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.448 7.448 0 0 1-3.692-.979l-1.093 1.093A8.956 8.956 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7h-1.549z"/></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"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1h-5zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1h-9zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1h-13zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1h-14z"/></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"><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"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/><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-2h-12zm12 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-1h12z"/></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"><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.959zM10.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.959z"/><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"><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>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><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-2V2zm15 2h-4v3h4V4zm0 4h-4v3h4V8zm0 4h-4v3h3a1 1 0 0 0 1-1v-2zm-5 3v-3H6v3h4zm-5 0v-3H1v2a1 1 0 0 0 1 1h3zm-4-4h4V8H1v3zm0-4h4V4H1v3zm5-3v3h4V4H6zm4 4H6v3h4V8z"/></svg>')}.treb-main.treb-main .treb-layout-header{-ms-overflow-style:none;overflow:hidden;overflow-x:scroll;position:relative;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-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-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=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>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-swatches{display:grid;gap:.5rem;grid-template-columns:repeat(10,1fr)}.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-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-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{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%;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 Hi=`<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" 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><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" title="Delete current 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><ol class="treb-spreadsheet-tabs" role="tablist"></ol><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" 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" title="This document has been modified from the original version."></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" title="Recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" title="Toggle toolbar"></button> <button data-command="export-xlsx" data-conditional="export" title="Export as XLSX"></button> <button data-command="revert" data-conditional="revert" title="Revert to original version"></button> <button data-command="about" title="What's this?"></button></div><button class="treb-toggle-sidebar-button" title="Toggle sidebar"></button></div>`;var Oi='<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></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></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"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-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="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></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></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></button></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown></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 font-scale><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown></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.2">1.20</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 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><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown></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 composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown></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 We=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=F.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:Gi,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 n=(this.root.getAttribute(r)||"").split(",");for(let a of n){let s=a.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}r=r.replace(/-/g,"_"),e[r]=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 i=r.getAttribute("name")||"";if(i===t||!i&&t==="true"){let n=r.textContent;if(n)try{e.inline_document=JSON.parse(n)}catch(a){console.error(a)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=Hi,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new Qt(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 i=t.querySelector(".treb-toggle-sidebar-button");if(i&&this.layout_element){let o=this.layout_element;i.addEventListener("click",()=>{let l=o.getAttribute("collapsed");typeof l=="string"&&(l===""||l==="true")?o.removeAttribute("collapsed"):o.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 n=t.querySelector("[data-command=revert-indicator]");this.DOM.view&&n instanceof this.DOM.view.HTMLElement&&(e.options.revert_indicator?n.addEventListener("click",()=>{e.HandleToolbarMessage({command:"revert-indicator"})}):n.style.display="none"),t.querySelector(".treb-layout-sidebar")?.addEventListener("click",o=>{let l=o.target;if(l.dataset.command)switch(l.dataset.command){case"toggle-toolbar":this.ToggleToolbar();break;default:e.HandleToolbarMessage({command:l.dataset.command});break}}),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,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[o,l]of Object.entries(s))if(!l){let d=this.layout_element.querySelectorAll(`[data-conditional=${o}]`);for(let h of Array.from(d))h.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let o={width:0,height:0},l={x:0,y:0},d={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let h,u,m=t.querySelector(".treb-layout-resize-handle"),f=()=>g(),p=b=>{b.buttons===0?g():(d.x=b.screenX-l.x,d.y=b.screenY-l.y,u&&(u.style.width=o.width+d.x+"px",u.style.height=o.height+d.y+"px"))},g=()=>{if(d.x||d.y){let b=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=b.width+d.x+"px"),t.style.height=b.height+d.y+"px"}h&&(h.removeEventListener("mouseup",f),h.removeEventListener("mousemove",p),h.parentElement?.removeChild(h),h=void 0),u?.parentElement?.removeChild(u),u=void 0};m.addEventListener("mousedown",b=>{b.stopPropagation(),b.preventDefault();let v=t.querySelector(".treb-main");u=this.DOM.Div("treb-resize-rect",v),h=this.DOM.Div("treb-resize-mask",v,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:f,mousemove:p}}),l.x=b.screenX,l.y=b.screenY,d.x=0,d.y=0;let _=this.views?.querySelectorAll(".treb-spreadsheet-body"),w=Array.from(_||[]).map(x=>x.getBoundingClientRect());if(w.length){let x=JSON.parse(JSON.stringify(w.shift()));for(let S of w)x.top=Math.min(S.top,x.top),x.left=Math.min(S.left,x.left),x.right=Math.max(S.right,x.right),x.bottom=Math.max(S.bottom,x.bottom);let A=x.right-x.left,k=x.bottom-x.top;u.style.top=x.top+"px",u.style.left=x.left+"px",u.style.width=A+"px",u.style.height=k+"px",o.width=A,o.height=k}})}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 i=e.selection_state;r.value="";for(let[o,l]of Object.entries(this.toolbar_controls))l&&(l.removeAttribute("active"),l.dataset.title&&(l.title=l.dataset.title));let n=o=>{o&&(o.setAttribute("active",""),o.dataset.activeTitle&&(o.title=o.dataset.activeTitle))};i.comment&&(n(this.toolbar_controls.comment),r.value=i.comment),i.style?.locked&&n(this.toolbar_controls.locked),i.frozen&&n(this.toolbar_controls.freeze),i.style?.wrap&&n(this.toolbar_controls.wrap),this.toolbar_controls.table&&(i.table?(n(this.toolbar_controls.table),this.toolbar_controls.table.dataset.command="remove-table"):this.toolbar_controls.table.dataset.command="insert-table"),this.toolbar_controls.merge&&(i.merge?(n(this.toolbar_controls.merge),this.toolbar_controls.merge.dataset.command="unmerge-cells"):this.toolbar_controls.merge.dataset.command="merge-cells");let a=this.toolbar_controls.format;a&&(i.style?.number_format?a.value=I.SymbolicName(i.style.number_format)||i.style.number_format:a.value="General");let s=this.toolbar_controls.scale;switch(s&&(s.value=e.FormatNumber(i.relative_font_size||1,"0.00")),i.style?.horizontal_align){case"left":n(this.toolbar_controls.left);break;case"center":n(this.toolbar_controls.center);break;case"right":n(this.toolbar_controls.right);break}switch(i.style?.vertical_align){case"top":n(this.toolbar_controls.top);break;case"middle":n(this.toolbar_controls.middle);break;case"bottom":n(this.toolbar_controls.bottom);break}}UpdateDocumentStyles(e,t){{let s=this.DOM.Fragment(),o=e.document_styles.theme_colors.length,l=["Background","Text","Background","Text","Accent"];if(o){let m=e.document_styles.theme_colors[0].length;for(let f=0;f<m;f++)for(let p=0;p<o;p++){let g=e.document_styles.theme_colors[p][f],b=`background: ${g.resolved};`,v=l[p]||l[4];g.color.tint?v+=` (${(g.color.tint>0?"+":"")+g.color.tint*100}%)`:p===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",g.resolved):p===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",g.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",g.resolved)),this.DOM.Create("button",void 0,s,{attrs:{style:b,title:v},data:{command:"set-color",color:JSON.stringify(g.color)}})}}this.swatch_lists.theme?.replaceChildren(s),s=this.DOM.Fragment(),this.DOM.Create("button","treb-default-color",s,{attrs:{title:"Default color"},data:{command:"set-color",color:JSON.stringify({})}});let d=["Black","White","Gray","Red","Orange","Yellow","Green","Blue","Violet"],h=d.map(m=>m.toLowerCase()),u=e.document_styles.colors.filter(m=>!h.includes(m.toLowerCase()));for(let m of[...d,...u]){let f=`background: ${m.toLowerCase()};`;this.DOM.Create("button",void 0,s,{attrs:{style:f,title:m},data:{command:"set-color",color:JSON.stringify({text:m.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(s)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],i=["Timestamp","Long Date","Short Date"];for(let s of e.document_styles.number_formats){if(I.SymbolicName(I.Translate(s)))continue;I.Get(s).date_format?i.push(s):r.push(s)}let n=s=>this.DOM.Create("button",void 0,void 0,{text:s,data:{format:s,command:"number-format"}}),a=this.DOM.Fragment();a.append(...r.map(s=>n(s))),a.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),a.append(...i.map(s=>n(s))),t.textContent="",t.append(a)}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 i=e.querySelector(t);if(i&&i.parentElement){for(let n of Array.from(i.content.children))i.parentElement.insertBefore(n,i);r&&i.parentElement.removeChild(i)}else console.warn("template not found",t)}AttachToolbar(e,t){let r=t.querySelector(".treb-layout-header"),i=t.querySelector(".treb-toolbar");i.innerHTML=Oi;let n=[];e.options.toolbar==="narrow"||e.options.toolbar==="show-narrow"?n.push(...Array.from(i.querySelectorAll("[wide]"))):n.push(...Array.from(i.querySelectorAll("[narrow]"))),e.options.file_menu||n.push(i.querySelector("[file-menu]")),e.options.font_scale||n.push(i.querySelector("[font-scale]")),e.options.chart_menu||n.push(i.querySelector("[chart-menu]")),e.options.freeze_button||n.push(i.querySelector("[freeze-button]")),e.options.table_button||n.push(i.querySelector("[table-button]")),!e.options.add_tab&&!e.options.delete_tab&&n.push(...Array.from(i.querySelectorAll("[add-remove-sheet]"))),e.options.toolbar_recalculate_button||n.push(i.querySelector("[recalculate-button]"));for(let _ of n)_&&_.parentElement?.removeChild(_);let a=i.querySelector(".treb-color-chooser"),s=i.querySelector(".treb-comment-box textarea");for(let[_,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"})){let x=i.querySelector(w);x&&(this.toolbar_controls[_]=x)}let o=a.querySelectorAll(".treb-swatches");this.swatch_lists={theme:o[0],other:o[1]};let l=t.querySelector("[data-command=increase-precision");l&&(l.textContent=this.sheet?.FormatNumber(0,"0.00")||""),l=t.querySelector("[data-command=decrease-precision"),l&&(l.textContent=this.sheet?.FormatNumber(0,"0.0")||""),l=i.querySelector("[data-command=update-comment]"),s.addEventListener("keydown",_=>{_.key==="Enter"&&(_.shiftKey||_.ctrlKey)&&l.click()});for(let _ of["border","annotation","align","justify"])this.replace_targets[_]=i.querySelector(`[data-target=${_}`);for(let _ of["fill","text","border"])this.color_bar_elements[_]=i.querySelector(`[data-color-bar=${_}]`);i.addEventListener("click",_=>{let w=_.target,x={format:w.dataset.format,scale:w.dataset.scale},A=w?.dataset.command;if(A){let k=w.parentElement?.dataset.replace;if(k){let S=this.replace_targets[k];S&&(S.dataset.command=A,S.title=w.title||"")}switch(/^border-/.test(A)&&(x.color=this.border_color||{}),A){case"text-color":case"fill-color":x.color={};try{x.color=JSON.parse(w.dataset.color||"{}")}catch(S){console.error(S)}break;case"set-color":A=a.dataset.colorCommand||"",x.color={};try{x.color=JSON.parse(w.dataset.color||"{}")}catch(S){console.error(S)}if(A==="border-color"&&(this.border_color=x.color),a.dataset.target){let S=this.color_bar_elements[a.dataset.target];S&&(S.style.setProperty("--treb-color-bar-color",w.style.backgroundColor),S.dataset.color=w.dataset.color||"{}")}break;case"update-comment":x.comment=s.value;break}e.HandleToolbarMessage({command:A,...x})}});let d=(_,w)=>{let x=i.querySelector(_);if(x){let A="";x.addEventListener("focusin",()=>A=x.value),x.addEventListener("keydown",k=>{switch(k.key){case"Escape":x.value=A,e.Focus();break;case"Enter":w(x.value)||(x.value=A,e.Focus());break;default:return}k.stopPropagation(),k.preventDefault()})}};d("input.treb-number-format",_=>_?(e.HandleToolbarMessage({command:"number-format",format:_}),!0):!1),d("input.treb-font-scale",_=>{let w=Number(_);return!w||isNaN(w)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:w}),!0)});let h=a.querySelector("input"),u=a.querySelector("input + button");h.addEventListener("input",_=>{if(_ instanceof InputEvent&&_.isComposing)return;u.style.background=h.value||"";let w=u.style.backgroundColor||"#fff",x=de.MeasureColor(w),A=Q.RGBToHSL(x[0],x[1],x[2]);u.style.color=A.l>.5?"#000":"#fff",u.dataset.color=JSON.stringify(u.style.backgroundColor?{text:u.style.backgroundColor}:{})}),h.addEventListener("keydown",_=>{_.key==="Enter"&&(_.stopPropagation(),_.preventDefault(),u.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 m=!1,f=_=>{_.key==="Escape"&&(_.stopPropagation(),_.preventDefault(),Promise.resolve().then(()=>e.Focus()))},p=_=>{if(m){if(_.relatedTarget instanceof Node&&i.contains(_.relatedTarget))return;i.removeEventListener("keydown",f),i.removeEventListener("focusout",p),m=!1}},g=_=>{let w=_.target,x=w?.parentElement;if(w?.classList.contains("treb-menu")){x=w;for(let A of Array.from(x.children))if(A.tagName==="BUTTON"){w=A;break}}else if(!x?.classList.contains("treb-menu"))return;if(w&&x){m||(i.addEventListener("focusout",p),i.addEventListener("keydown",f),m=!0),x.dataset.colorCommand&&(a.querySelector(".treb-default-color")?.setAttribute("title",x.dataset.defaultColorText||"Default color"),x.appendChild(a),a.dataset.colorCommand=x.dataset.colorCommand,a.dataset.target=x.dataset.replaceColor||"");let A=x.querySelector("div"),k=r.getBoundingClientRect(),S=w.getBoundingClientRect(),{left:M}=S,U=x.parentElement;U?.hasAttribute("composite")&&(M=U.firstElementChild.getBoundingClientRect().left);let W=A.getBoundingClientRect();x.classList.contains("treb-submenu")?(A.style.top=S.top-W.height/2+"px",M+S.width+6+W.width>k.right?A.style.left=M-6-W.width+"px":A.style.left=M+S.width+6+"px"):(A.style.top=S.bottom+"px",M+W.width>k.right-6?A.style.left=S.right-W.width+"px":A.style.left=M+"px");let me=A.querySelector("textarea");me&&requestAnimationFrame(()=>me.focus())}},b=this.root?.querySelector(".treb-number-format-menu");b&&(this.UpdateDocumentStyles(e,b),this.UpdateSelectionStyle(e,i,s),e.Subscribe(_=>{switch(_.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,b),this.UpdateSelectionStyle(e,i,s),this.UpdateRevertState(e);break;case"selection":this.UpdateSelectionStyle(e,i,s);break}}));let v=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i.addEventListener("focusin",_=>{g(_)}),v){let _=Array.from(i.querySelectorAll(".treb-menu"));for(let w of _)w.tabIndex=0;i.addEventListener("mousedown",w=>{g(w)})}}};var qt=class{version="28.2.3";CreateSpreadsheet(e){let t=e.container,r=new We(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},fa=new qt;if(typeof HTMLElement<"u"){class c extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new We(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",c))}export{fa as TREB,qt as TREBGlobal};
|
|
15
|
+
`)}SaveLocalFile(e="treb.json",t={}){this.SaveToDesktop(e,t)}SaveToDesktop(e="treb.json",t={}){let r=this.grid.model.document_name||"document",i,n,a=e.split(/\./).filter(o=>o.trim().length),s=a.length?a[a.length-1].toLowerCase():"treb";if(a.length<=1||e==="treb.json")if(e==="treb.json"&&(s=e),(s==="csv"||s==="tsv")&&this.grid.model.sheets.length>1){let o=this.grid.active_sheet.name;e=(r+"-"+o).toLowerCase().replace(/\W+/g,"-")+"."+s}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+s;switch(s){case"csv":n=this.ExportDelimited({delimiter:","});break;case"tsv":n=this.ExportDelimited({delimiter:" "});break;case"treb":case"json":case"treb.json":i=this.SerializeDocument({...t}),n=JSON.stringify(i,void 0,t.pretty?2:void 0),this.last_save_version=this.file_version;break;default:throw new Error("invalid file type")}if(n&&e){let o=new Blob([n],{type:"text/plain;charset=utf-8"});this.SaveAs(o,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 i of r)if(i.id===t.override_selection.target.sheet_id){i.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=N(r)?r:r.start}this.grid.SetNote(e,t)}SetValidation(e,t,r){if(typeof e=="string"){let i=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(i)?i:i.start}if(typeof t>"u"||Array.isArray(t))this.grid.SetValidation(e,t,r);else{let i=this.model.ResolveArea(t,this.grid.active_sheet);this.grid.SetValidation(e,i,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(i=>i.trim()):[]);for(let i of t)if(!i.length||/^[^A-Za-z]/.test(i)||/[^\w_.]/.test(i))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.grid.Serialize(e),r={app:"@trebco/treb",version:"28.3.4",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:D.decimal_separator,...t};if(e.share_resources){let i=1,n=new Map,a=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],s=l=>{let d=n.get(l);return d||(d=(i++).toString(),n.set(l,d)),`resource:${d}`};for(let l of a)if(l){l.background_image&&(l.background_image=s(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=s(d.data.src))}let o={};for(let[l,d]of n.entries())o[d]=l;r.shared_resources=o}return e.rendered_values&&(r.rendered_values=!0),r}async Recalculate(e){let t;e&&e.type==="data"&&e.area&&(t=e.area),this.calculator.Calculate(t),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"})}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(r)?r:r.start}t={x:!0,y:!0,smooth:!1,...t},this.grid.ScrollTo(e,t.x,t.y,t.smooth)}Resolve(e){let t=this.model.ResolveAddress(e,this.grid.active_sheet);return N(t)?t.sheet_id?t:void 0:t.start.sheet_id?t:void 0}Unresolve(e,t=!0,r=!0){if(typeof e=="string"){let i=this.Resolve(e);if(!i)throw new Error("invalid reference");e=i}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=y.CellAddressToLabel(t.area.start)+":"+y.CellAddressToLabel(t.area.end):r=y.CellAddressToLabel(t.area.start),!e)return r;let i=t.area.start.sheet_id||this.grid.active_sheet.id,n=this.calculator.ResolveSheetName(i,!0);return n?n+"!"+r:r}ParseNumber(e){return be.TryParse(e).value}FormatNumber(e,t="General"){return I.Get(t).Format(e)}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)}DefineName(e,t){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof t=="object"&&(N(t)||Pr(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet));return}if(typeof t=="string"){let r=this.parser.Parse(t);if(!r.expression)throw new Error("invalid expression");switch(r.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(r.expression,this.grid.active_sheet));return}this.grid.SetName(e,void 0,t)}else this.grid.SetName(e,void 0,t.toString())}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=N(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)}GetRange(e,t={}){if(!e){let r=this.GetSelectionReference();r.empty||(e=r.area)}if(e)return t.type||(t.formatted&&(t.type="formatted"),t.formula&&(t.type="formula")),this.grid.GetRange(this.model.ResolveAddress(e,this.grid.active_sheet),t.type)}GetStyle(e,t=!1){if(!e){let r=this.GetSelectionReference();r.empty||(e=r.area)}if(e)return this.grid.GetRangeStyle(this.model.ResolveAddress(e,this.grid.active_sheet),t)}SetRange(e,t=void 0,r={}){if(!e){let i=this.GetSelectionReference();i.empty||(e=i.area)}if(e){let i=this.model.ResolveArea(e,this.grid.active_sheet);if(r.spill&&Array.isArray(t)){let n=t.length,a=Math.max(0,...t.map(o=>o.length)),s={row:i.start.row+n+1,column:i.start.column+a+1};i.ConsumeAddress(s)}return this.grid.SetRange(i,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}ApplyConditionalFormats(e,t){let r=[];if(e.conditional_formats.length||e.flush_conditional_formats){for(let i of e.conditional_formats)r.push(i.area),i.type==="gradient"&&(i.internal||(i.internal={}),i.internal.gradient||(i.internal.gradient=new ft(i.stops,this.grid.theme,i.color_space)));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);N(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){return this.parent_view?this.parent_view.ImportXLSX(e,t):(this.export_worker||(this.export_worker=await this.LoadWorker("export")),new Promise((r,i)=>{this.export_worker?(this.dialog?.ShowDialog({message:"Importing XLSX..."}),this.export_worker.onmessage=n=>{if(n.data){if(n.data.status==="error")return i(n.data.error||"unknown error");this.grid.FromImportData(n.data.results),this.ResetInternal(),this.grid.Update(),this.UpdateAC(),this.calculator.AttachModel(),this.Publish({type:"load",source:t}),this.UpdateDocumentStyles(),this.InflateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)}else return i("unknown error (missing data)");this.dialog?.HideDialog(),r()},this.export_worker.onerror=n=>{console.error("import worker error"),console.info(n),i(n)},this.export_worker.postMessage({command:"import",data:e})):i("worker failed")}))}ResetInternal(){this.calculator.Reset(),this.FlushUndo(),this.file_version=this.last_save_version=0}HandleCellEvent(e){if(e.data?.type==="hyperlink"){let r="hyperlink invalid target",i=e.data.data||"";if(typeof i=="string"){if(/^https{0,1}:\/\//i.test(i)){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",i),n.setAttribute("noreferrer","true"),n.setAttribute("nofollow","true"),n.click();return}else{let n=this.parser.Parse(i);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(i);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(i);return}}}console.warn(r,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 i=r.files[0];switch(r.value="",this.file_chooser_operation){case 2:this.InsertImageInternal(i);break;case 1:this.LoadFileInternal(i,"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,i)=>{let n=new FileReader;n.onload=async()=>{try{if(n.result){let a;if(typeof n.result=="string")a=n.result;else{a="";let l=new Uint8Array(n.result);for(let d=0;d<l.byteLength;d++)a+=String.fromCharCode(l[d])}let s=this.DOM.Create("img");s.src=a,await Promise.resolve();let o=this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:a,original_size:{width:s.width||300,height:s.height||300}}},void 0,void 0,{top:30,left:30,width:s.width||300,height:s.height||300})}r()}catch(a){i(a)}},n.onabort=()=>{i("Aborted")},n.onerror=()=>{i("File error")},setTimeout(()=>{n.readAsDataURL(t)},100)})}LoadFileInternal(e,t,r=!0){if(!e)return Promise.resolve();let i=new FileReader;return new Promise((n,a)=>{let s=o=>{i.onload=null,i.onabort=null,i.onerror=null,o?(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(o)),a(o)):n()};i.onload=()=>{try{if(i.result)if(/\.csv$/i.test(e.name))this.LoadCSV(i.result,t);else if(/\.xls[xm]$/i.test(e.name)){typeof i.result=="string"?s("Unsupported file"):this.ImportXLSX(i.result,t).then(()=>s()).catch(o=>s(o));return}else{let o=JSON.parse(i.result);this.LoadDocument(o,{source:t})}s()}catch(o){s(o?.toString())}},i.onabort=()=>{s("Aborted")},i.onerror=()=>{s("File error")},setTimeout(()=>{/\.xls[xm]$/i.test(e.name)?i.readAsArrayBuffer(e):i.readAsText(e)},100)})}UpdateAnnotations(){for(let e of this.grid.active_sheet.annotations){if(e.temp.vertex){let r=e.temp.vertex;if(r.state_id!==e.temp.state){e.temp.state=r.state_id;for(let i of e.view)i.dirty=!0}}let t=e.view[this.grid.view_index]||{};t.dirty&&(t.update_callback&&t.update_callback(),this.grid.AnnotationUpdated(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 i=()=>{if(e.data.formula){let n=this.parser.Parse(e.data.formula);if(n&&n.expression&&n.expression.type==="call"){this.parser.Walk(n.expression,o=>((o.type==="address"||o.type==="range")&&this.model.ResolveSheetID(o,void 0,this.grid.active_sheet),!0));let a=n.expression.name.toLowerCase(),s=this.calculator.CalculateExpression(n.expression);r.Exec(a,s)}}r.Update()};t.resize_callback=()=>{this.grid.headless||(r.Resize(),r.Update())},t.update_callback=()=>{this.grid.headless||i()},t.node?.parentElement&&(this.grid.headless||i())}else if(e.data.type==="image"&&typeof e.data.data?.src=="string"){let r=mt(e.data.data.src);if(r){let i=this.DOM.Create("img");i.src=r,e.data.data.scale==="fixed"?(i.style.position="relative",i.style.left="50%",i.style.top="50%",i.style.transform="translate(-50%, -50%)"):(i.style.width="100%",i.style.height="100%"),t.content_node.appendChild(i)}}}}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,i=document.location.href;for(let a=0,s=i.length;a<s;a++)r=(r<<5)-r+i.charCodeAt(a),r|=0;let n=Math.abs(r).toString(16);return t?t+"-"+n:n}return e}}PushUndo(e,t,r=!0){let i=t||this.last_selection;this.undo_stack[this.undo_pointer-1]&&(this.undo_stack[this.undo_pointer-1].selection=i),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 n=this.undo_stack.length;if(n>16){let a=n-16;this.undo_stack=this.undo_stack.slice(a),this.undo_pointer-=a}}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){this.last_selection=JSON.stringify(e),this.Publish({type:"selection"})}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 i=this.grid.active_sheet.CellData(e.target);r.table=!!i.table,r.merge=!!i.merge_area,r.merge&&i.merge_area&&(i.merge_area.start.row!==e.target.row||i.merge_area.start.column!==e.target.column)&&(i=this.grid.active_sheet.CellData(i.merge_area.start)),r.comment=i.note,r.style=i.style?{...i.style}:void 0,r.relative_font_size=U.RelativeFontSize(r.style||{},this.grid.theme.grid_cell||{})}this.selection_state=r}UpdateDocumentStyles(e=!0){let t={},r={};for(let n of this.grid.model.sheets.list)n.NumberFormatsAndColors(r,t);this.document_styles.colors=Object.keys(r),this.document_styles.number_formats=Object.keys(t),this.document_styles.theme_colors=[];let i=[.5,.25,0,-.25,-.5];for(let n=0;n<10;n++)this.document_styles.theme_colors.push(i.map(a=>{let s={theme:n,tint:a},o=R(this.grid.theme,s);return{color:s,resolved:o}}))}ConvertLocale(e){let t=new Ge;t.flags={...this.parser.flags};let r,i;e.decimal_mark==="."?(t.decimal_mark=".",t.argument_separator=",",r=",",i=";"):(t.decimal_mark=",",t.argument_separator=";",r=".",i=",");let n=a=>{let s=t.Parse(a);if(s.expression)return"="+t.Render(s.expression,{missing:"",convert_decimal:r,convert_argument_separator:i})};if(e.macro_functions)for(let a of e.macro_functions){let s=n(a.function_def);s&&(a.function_def=s)}if(e.sheet_data){let a=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let s of a){if(s.annotations){for(let o of s.annotations)if(o.formula){let l=n(o.formula);l&&(o.formula=l)}}if(s.data?.length)for(let o of s.data){let l=tr(o)?[o]:o.cells;for(let d of l)if(d.value&&typeof d.value=="string"&&d.value[0]==="="){let h=n(d.value.slice(1));h&&(d.value=h)}}}}}CompareVersions(e="",t=""){let r=e.split(".").map(s=>Number(s)||0).concat([0,0,0]),i=t.split(".").map(s=>Number(s)||0).concat([0,0,0]),n=[0,1,2],a={match:0};for(let s=0;s<3;s++)if(r[s]!==i[s]){a.match=r[s]>i[s]?1:-1,a.level=n[s];break}return a}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],i=this.CompareVersions(e.version,"28.3.4");if(i.match>0&&(i.level===0||i.level===1)&&console.warn(`The file you are opening was created with a newer version of TREB (${e.version} vs 28.3.4).
|
|
16
|
+
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 s=e.shared_resources,o=l=>/^resource:/.test(l)?s[l.substring(9)]||"":l;for(let l of r){l.background_image&&(l.background_image=o(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=o(d.data.src))}}e.decimal_mark&&e.decimal_mark!==D.decimal_separator&&this.ConvertLocale(e);let n=this.grid.model;if(n.tables.clear(),e.tables)for(let s of e.tables)n.tables.set(s.name.toLowerCase(),s);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let[s,o]of this.model.tables.entries())if(o.area.start.sheet_id){let l=n.sheets.Find(o.area.start.sheet_id);if(l)for(let d=o.area.start.row;d<=o.area.end.row;d++)for(let h=o.area.start.column;h<=o.area.end.column;h++){let u=l.cells.GetCell({row:d,column:h},!0);u.table=o}}n.document_name=e.name,n.user_data=e.user_data,n.named_ranges.Reset();let a=e.named_ranges;if(!a&&r[0]&&r[0].named_ranges&&(a=r[0].named_ranges),a&&n.named_ranges.Deserialize(a),n.named_expressions.clear(),e.named_expressions)for(let s of e.named_expressions){let o=this.parser.Parse(s.expression);o.valid&&o.expression&&(this.parser.Walk(o.expression,l=>{if(l.type==="address"||l.type==="range"){if(l.type==="range"&&(l=l.start),!l.sheet_id&&l.sheet){let d=this.model.sheets.Find(l.sheet);d&&(l.sheet_id=d.id)}return l.sheet_id||(l.sheet_id=this.grid.active_sheet.id),!1}return!0}),n.named_expressions.set(s.name.toUpperCase(),o.expression))}if(n.macro_functions.clear(),e.macro_functions)for(let s of e.macro_functions)n.macro_functions.set(s.name.toUpperCase(),{...s,expression:this.parser.Parse(s.function_def||"").expression});this.UpdateAC()}async LoadWorker(e){if(Fr)try{return new Worker(URL.createObjectURL(new Blob([Lr],{type:"application/javascript"})))}catch(t){console.info("embedded worker failed"),console.error(t)}throw new Error("creating worker failed")}HandleKeyDown(e){e.ctrlKey&&(e.code==="KeyZ"||e.key==="z")&&(e.stopPropagation(),e.preventDefault(),this.Undo())}};var Gi=`@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;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;margin-right:6px;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 .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[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-formula-bar .formula-button{border:1px solid #ccc;border-radius:2px;height:1.75em;margin-left:6px;overflow:hidden;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .formula-button .text-1{font-style:italic;padding-right:.1em}.treb-main.treb-main .treb-formula-bar .formula-button .text-1:after{content:"f"}.treb-main.treb-main .treb-formula-bar .formula-button .text-2{font-size:.7em}.treb-main.treb-main .treb-formula-bar .formula-button .text-2:after{content:"(x)"}.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-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[hidden]{display:none}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{display:inline-block;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{overflow-x:hidden;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;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-width:1.5px;stroke-linecap:round}.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{margin-left:auto;overflow:hidden;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-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;grid-area:2/1/3/2;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;flex-grow:1;grid-template-columns:100px auto;grid-template-rows:20px auto;order:2;outline:none;overflow:scroll;position:relative}.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;-moz-transform:scale(1);z-index:10}.treb-main.treb-main .treb-grid .frozen-selection{overflow:hidden;pointer-events:none;position:absolute;-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{stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4));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)}.treb-main.treb-main .grid-cells{stroke:var(--treb-grid-grid-color,#ccccd4);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)}.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{stroke:none;color:var(--treb-selection-color-unfocused,var(--treb-selection-color,#4caaf1))}.treb-main.treb-main .treb-header-overlay .treb-overlay{fill:#000;stroke:none;opacity:.05}.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 .outline,.treb-main.treb-main .treb-grid-selection .selection .outline{stroke:currentColor;fill:none}.treb-main.treb-main .frozen-selection .selection .fill,.treb-main.treb-main .treb-grid-selection .selection .fill{stroke:none;fill:currentColor;opacity:var(--treb-selection-fill-opacity,.1)}.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 .nub,.treb-main.treb-main .treb-grid-selection .primary-selection .nub{stroke:#fff;fill:currentColor;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);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{--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-64Zm-240-80c0-44 36-80 80-80s80 36 80 80v80H176v-80Z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);content:"";height:12px;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;opacity:.4;position:absolute;right:2px;top:2px;width:12px}.treb-main.treb-main.treb-ua-windows .grid-cells{font-family:var(--treb-grid-font-family-windows,var(--treb-grid-font-family,"Calibri","BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif"));font-size:var(--treb-grid-font-size-windows,var(--treb-grid-font-size,12pt))}.treb-main.treb-main.treb-ua-osx .grid-cells{font-family:var(--treb-grid-font-family-osx,var(--treb-grid-font-family,inherit));font-size:var(--treb-grid-font-size-osx,var(--treb-grid-font-size,10pt))}.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-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-active-tab-background:#444;--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:field;--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}@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-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-active-tab-background:#444;--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:field;--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-chart,.treb-main.treb-main .treb-chart{background:var(--treb-chart-background,#fff)}.treb-chart .series-1{color:var(--treb-chart-color-series-1,#80b1d3)}.treb-chart .series-2{color:var(--treb-chart-color-series-2,#8dd3c7)}.treb-chart .series-3{color:var(--treb-chart-color-series-3,#bebada)}.treb-chart .series-4{color:var(--treb-chart-color-series-4,#fb8072)}.treb-chart .series-5{color:var(--treb-chart-color-series-5,#fdb462)}.treb-chart .series-6{color:var(--treb-chart-color-series-6,#b3de69)}.treb-chart .series-7{color:var(--treb-chart-color-series-7,#fccde5)}.treb-chart .series-8{color:var(--treb-chart-color-series-8,#d9d9d9)}.treb-chart .series-9{color:var(--treb-chart-color-series-9,#bc80bd)}.treb-chart .series-10{color:var(--treb-chart-color-series-10,#ccebc5)}.treb-chart .series-11{color:var(--treb-chart-color-series-11,#ffed6f)}.treb-chart .series-12{color:var(--treb-chart-color-series-12,#ffffb3)}.treb-chart .chart-title{font-size:1.4em}.treb-chart .axis-group{font-size:.9em}.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 .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .label-target{stroke:none;fill:transparent}.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{stroke:currentColor;fill:none;stroke-width:2}.treb-chart .chart-area .line{stroke:currentColor;stroke-width:2px;fill:none}.treb-chart .chart-area .fill{fill:currentColor;opacity:.5}.treb-chart .scatter-plot{stroke-width:3;fill:none;stroke:currentColor}.treb-chart .scatter-plot .fill{fill:currentColor;stroke:none;opacity:.5}.treb-chart .scatter-plot .marker{stroke-width:2.5px;fill:#fff;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.567z'/%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{fill:#73828c;cursor:default;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"><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-.708z"/></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.502 4.502 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.5zM28 1v8c0 .547-.453 1-1 1a.99.99 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.75a.996.996 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-2h5.5zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1h4zm2.5-6v2H0v-2h13.5zm-10-8v2H0V6h3.5zM24 22v2H12.5v-2H24zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1h4zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1h4zm5 2v2h-3.5v-2H24zm0-8v2H10.5V6H24z"/></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-1zm4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1zm2-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.5zm-5.078-8.891a.984.984 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.984.984 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.609z"/></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.016A.996.996 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a.99.99 0 0 1-.297.703l-2.141 2.141A7.985 7.985 0 0 0 11.998 22a7.976 7.976 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-1a.99.99 0 0 1 .297-.703l2.156-2.156A8.036 8.036 0 0 0 12 6a7.976 7.976 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.016A.996.996 0 0 1 23 3c.547 0 1 .453 1 1z"/></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-.5zM18 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.477.477 0 0 0 .297.094.498.498 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 12z"/></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.406z"/></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.406z"/></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.972 11.972 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.599.599 0 0 1 .391-.141.51.51 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.952 7.952 0 0 0 6.563 8.14l2.141 2.156a.964.964 0 0 1 .219 1.078 1.002 1.002 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.964.964 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.5z"/></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"><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-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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"><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-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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"><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-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></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'%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.5z'/%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"><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 8zm7-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 0zm-.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 0v-3.793z"/></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'%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 1z'/%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"><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-7a1.99 1.99 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 4H2.19zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139C1.72 3.042 1.95 3 2.19 3h5.396l-.707-.707z"/></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 1zM10 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-5zM3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5z"/></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"><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 1h-4zM10 .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-.5zM.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-.5zm15 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-.5z"/></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"><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-.5zm5 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-.5zM0 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-.5zm10 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 0v-4z"/></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"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 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-2zM5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/></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"><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-1h12zM2 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-2H2z"/></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"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a2.972 2.972 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.01 1.01 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4.322 4.322 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067-.707-.707-1.441-1.279-2.068-1.627-.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.283 3.283 0 0 1-.131-.673c.091.061.204.15.337.274zm.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.088c.054.12.115.243.183.365.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626.122.068.244.13.365.183l-4.861 4.862a.571.571 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46-.66-.66-1.168-1.32-1.46-1.846-.147-.265-.225-.47-.251-.607a.573.573 0 0 1-.01-.068l3.048-3.047zm2.87-1.935a2.44 2.44 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.497 3.497 0 0 0-1.066.091 11.27 11.27 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"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604h-1.3zM8.418 3.604a5.908 5.908 0 0 1-.127-.387 3.618 3.618 0 0 1-.11-.501h-.035a5.492 5.492 0 0 1-.247.888L5.86 9.211h4.614L8.418 3.604z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 15h16v1H0v-1z"/></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"><path d="M0 0v1h16V0H0zm1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0V16zm1.906 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469h.031z"/></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"><path d="M0 0v16h1V0H0zm1.906 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM7.5 1.906v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1.906 8.5h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM7.5 9.406v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-8.5.937v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-8.5.937v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM1.906 16h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469h.031z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zM16 0h-1v16h1V0zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 11.281v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 13.156v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0V16zm1.906 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469h.031zm1.875.5h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1z"/></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"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969V0zm.937 1h.938V0h-.938v1zm1.875 0h.938V0H3.78v1h.001zm1.875 0h.938V0h-.938v1zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469h.031zM9.406 1h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.938V0h-.938v1zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031V1zM1 2.844v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM1 4.719V3.78H0v.938l1 .001zm6.5-.938v.938h1V3.78h-1v.001zm7.5 0v.938h1V3.78h-1v.001zM1 6.594v-.938H0v.938h1zm6.5-.938v.938h1v-.938h-1zm7.5 0v.938h1v-.938h-1zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5V8.5zm1.406 0h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1h.001zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031V8.5zM0 9.406v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zm-16 .937v.938h1v-.938H0zm7.5 0v.938h1v-.938h-1zm8.5.938v-.938h-1v.938h1zM0 15h16v1H0v-1zm0-2h16v1H0v-1z"/></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"><path d="M0 0h16v16H0V0zm1 1v6.5h6.5V1H1zm7.5 0v6.5H15V1H8.5zM15 8.5H8.5V15H15V8.5zM7.5 15V8.5H1V15h6.5z"/></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"><path d="M7.5 1.906v.938h1v-.938h-1zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938h-1zM1.906 8.5h.938v-1h-.938v1zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938v1zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5h.938zm.937 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zm1.875 0h.938v-1h-.938v1zM7.5 9.406v.938h1v-.938h-1zm0 1.875v.938h1v-.938h-1zm0 1.875v.938h1v-.938h-1z"/><path d="M0 0v16h16V0H0zm1 1h14v14H1V1z"/></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"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0V0zm2.844 1h-.938V0h.938v1zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938v1zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1H7.53zm2.813 0h-.938V0h.938v1zm1.875 0h-.938V0h.938v1zm1.875 0h-.938V0h.938v1zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5V1zM1 1.906v.938H0v-.938h1zm6.5.938v-.938h1v.938h-1zm7.5 0v-.938h1v.938h-1zM1 3.78v.938H0V3.78h1zm6.5.938V3.78h1v.938h-1zm7.5 0V3.78h1v.938h-1zM1 5.656v.938H0v-.938h1zm6.5.938v-.938h1v.938h-1zm7.5 0v-.938h1v.938h-1zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969V8.5zm1.875 0h-.938v-1h.938v1zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938h-.031zm1.875.031h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5V8.5zM0 10.344v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM0 12.22v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM0 14.094v-.938h1v.938H0zm7.5 0v-.938h1v.938h-1zm8.5-.938v.938h-1v-.938h1zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969v.5zm1.875 0h-.938v-1h.938v1zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938v1zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5H7.53zm2.813 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm1.875 0h-.938v-1h.938v1zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16h-.969z"/></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"><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.5H3a2.99 2.99 0 0 1-2.121-.879A2.99 2.99 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188v5.647zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0zM15 15v-4H9.258l-4.015 4H15zM0 .5v12.495V.5z"/><path d="M0 12.995V13a3.07 3.07 0 0 0 0-.005z"/></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"><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.54-.704-.71zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526-.703-.711zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514-.704-.71zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5-.704-.711zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3zM5 9v6h6L5 9zm1 2.414L8.586 14H6v-2.586z"/></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"><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"><path d="M4.5 17.5a.5.5 0 0 1-1 0v-5a.5.5 0 0 1 1 0v5zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0v9zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0v13zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0v14z"/></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"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.006 9.006 0 0 0 12 1.23zM2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9.001 9.001 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.432 7.432 0 0 1 2.5 10zM17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.448 7.448 0 0 1-3.692-.979l-1.093 1.093A8.956 8.956 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7h-1.549z"/></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"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1h-5zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1h-9zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1h-13zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1h-14z"/></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"><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"><path d="M6.002 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0z"/><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-2h-12zm12 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-1h12z"/></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"><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.959zM10.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.959z"/><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"><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>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><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-2V2zm15 2h-4v3h4V4zm0 4h-4v3h4V8zm0 4h-4v3h3a1 1 0 0 0 1-1v-2zm-5 3v-3H6v3h4zm-5 0v-3H1v2a1 1 0 0 0 1 1h3zm-4-4h4V8H1v3zm0-4h4V4H1v3zm5-3v3h4V4H6zm4 4H6v3h4V8z"/></svg>')}.treb-main.treb-main .treb-layout-header{-ms-overflow-style:none;overflow:hidden;overflow-x:scroll;position:relative;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-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-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=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>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-swatches{display:grid;gap:.5rem;grid-template-columns:repeat(10,1fr)}.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-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-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{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%;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 Hi=`<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" 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><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" title="Delete current 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><ol class="treb-spreadsheet-tabs" role="tablist"></ol><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" 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" title="This document has been modified from the original version."></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" title="Recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" title="Toggle toolbar"></button> <button data-command="export-xlsx" data-conditional="export" title="Export as XLSX"></button> <button data-command="revert" data-conditional="revert" title="Revert to original version"></button> <button data-command="about" title="What's this?"></button></div><button class="treb-toggle-sidebar-button" title="Toggle sidebar"></button></div>`;var Oi='<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></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></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"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-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="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></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></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></button></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown></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 font-scale><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown></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.2">1.20</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 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><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown></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 composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown></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 We=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=F.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:Gi,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 n=(this.root.getAttribute(r)||"").split(",");for(let a of n){let s=a.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}r=r.replace(/-/g,"_"),e[r]=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 i=r.getAttribute("name")||"";if(i===t||!i&&t==="true"){let n=r.textContent;if(n)try{e.inline_document=JSON.parse(n)}catch(a){console.error(a)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=Hi,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new Qt(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 i=t.querySelector(".treb-toggle-sidebar-button");if(i&&this.layout_element){let o=this.layout_element;i.addEventListener("click",()=>{let l=o.getAttribute("collapsed");typeof l=="string"&&(l===""||l==="true")?o.removeAttribute("collapsed"):o.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 n=t.querySelector("[data-command=revert-indicator]");this.DOM.view&&n instanceof this.DOM.view.HTMLElement&&(e.options.revert_indicator?n.addEventListener("click",()=>{e.HandleToolbarMessage({command:"revert-indicator"})}):n.style.display="none"),t.querySelector(".treb-layout-sidebar")?.addEventListener("click",o=>{let l=o.target;if(l.dataset.command)switch(l.dataset.command){case"toggle-toolbar":this.ToggleToolbar();break;default:e.HandleToolbarMessage({command:l.dataset.command});break}}),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,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[o,l]of Object.entries(s))if(!l){let d=this.layout_element.querySelectorAll(`[data-conditional=${o}]`);for(let h of Array.from(d))h.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let o={width:0,height:0},l={x:0,y:0},d={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let h,u,m=t.querySelector(".treb-layout-resize-handle"),f=()=>g(),p=b=>{b.buttons===0?g():(d.x=b.screenX-l.x,d.y=b.screenY-l.y,u&&(u.style.width=o.width+d.x+"px",u.style.height=o.height+d.y+"px"))},g=()=>{if(d.x||d.y){let b=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=b.width+d.x+"px"),t.style.height=b.height+d.y+"px"}h&&(h.removeEventListener("mouseup",f),h.removeEventListener("mousemove",p),h.parentElement?.removeChild(h),h=void 0),u?.parentElement?.removeChild(u),u=void 0};m.addEventListener("mousedown",b=>{b.stopPropagation(),b.preventDefault();let v=t.querySelector(".treb-main");u=this.DOM.Div("treb-resize-rect",v),h=this.DOM.Div("treb-resize-mask",v,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:f,mousemove:p}}),l.x=b.screenX,l.y=b.screenY,d.x=0,d.y=0;let _=this.views?.querySelectorAll(".treb-spreadsheet-body"),w=Array.from(_||[]).map(x=>x.getBoundingClientRect());if(w.length){let x=JSON.parse(JSON.stringify(w.shift()));for(let S of w)x.top=Math.min(S.top,x.top),x.left=Math.min(S.left,x.left),x.right=Math.max(S.right,x.right),x.bottom=Math.max(S.bottom,x.bottom);let A=x.right-x.left,k=x.bottom-x.top;u.style.top=x.top+"px",u.style.left=x.left+"px",u.style.width=A+"px",u.style.height=k+"px",o.width=A,o.height=k}})}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 i=e.selection_state;r.value="";for(let[o,l]of Object.entries(this.toolbar_controls))l&&(l.removeAttribute("active"),l.dataset.title&&(l.title=l.dataset.title));let n=o=>{o&&(o.setAttribute("active",""),o.dataset.activeTitle&&(o.title=o.dataset.activeTitle))};i.comment&&(n(this.toolbar_controls.comment),r.value=i.comment),i.style?.locked&&n(this.toolbar_controls.locked),i.frozen&&n(this.toolbar_controls.freeze),i.style?.wrap&&n(this.toolbar_controls.wrap),this.toolbar_controls.table&&(i.table?(n(this.toolbar_controls.table),this.toolbar_controls.table.dataset.command="remove-table"):this.toolbar_controls.table.dataset.command="insert-table"),this.toolbar_controls.merge&&(i.merge?(n(this.toolbar_controls.merge),this.toolbar_controls.merge.dataset.command="unmerge-cells"):this.toolbar_controls.merge.dataset.command="merge-cells");let a=this.toolbar_controls.format;a&&(i.style?.number_format?a.value=I.SymbolicName(i.style.number_format)||i.style.number_format:a.value="General");let s=this.toolbar_controls.scale;switch(s&&(s.value=e.FormatNumber(i.relative_font_size||1,"0.00")),i.style?.horizontal_align){case"left":n(this.toolbar_controls.left);break;case"center":n(this.toolbar_controls.center);break;case"right":n(this.toolbar_controls.right);break}switch(i.style?.vertical_align){case"top":n(this.toolbar_controls.top);break;case"middle":n(this.toolbar_controls.middle);break;case"bottom":n(this.toolbar_controls.bottom);break}}UpdateDocumentStyles(e,t){{let s=this.DOM.Fragment(),o=e.document_styles.theme_colors.length,l=["Background","Text","Background","Text","Accent"];if(o){let m=e.document_styles.theme_colors[0].length;for(let f=0;f<m;f++)for(let p=0;p<o;p++){let g=e.document_styles.theme_colors[p][f],b=`background: ${g.resolved};`,v=l[p]||l[4];g.color.tint?v+=` (${(g.color.tint>0?"+":"")+g.color.tint*100}%)`:p===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",g.resolved):p===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",g.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",g.resolved)),this.DOM.Create("button",void 0,s,{attrs:{style:b,title:v},data:{command:"set-color",color:JSON.stringify(g.color)}})}}this.swatch_lists.theme?.replaceChildren(s),s=this.DOM.Fragment(),this.DOM.Create("button","treb-default-color",s,{attrs:{title:"Default color"},data:{command:"set-color",color:JSON.stringify({})}});let d=["Black","White","Gray","Red","Orange","Yellow","Green","Blue","Violet"],h=d.map(m=>m.toLowerCase()),u=e.document_styles.colors.filter(m=>!h.includes(m.toLowerCase()));for(let m of[...d,...u]){let f=`background: ${m.toLowerCase()};`;this.DOM.Create("button",void 0,s,{attrs:{style:f,title:m},data:{command:"set-color",color:JSON.stringify({text:m.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(s)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],i=["Timestamp","Long Date","Short Date"];for(let s of e.document_styles.number_formats){if(I.SymbolicName(I.Translate(s)))continue;I.Get(s).date_format?i.push(s):r.push(s)}let n=s=>this.DOM.Create("button",void 0,void 0,{text:s,data:{format:s,command:"number-format"}}),a=this.DOM.Fragment();a.append(...r.map(s=>n(s))),a.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),a.append(...i.map(s=>n(s))),t.textContent="",t.append(a)}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 i=e.querySelector(t);if(i&&i.parentElement){for(let n of Array.from(i.content.children))i.parentElement.insertBefore(n,i);r&&i.parentElement.removeChild(i)}else console.warn("template not found",t)}AttachToolbar(e,t){let r=t.querySelector(".treb-layout-header"),i=t.querySelector(".treb-toolbar");i.innerHTML=Oi;let n=[];e.options.toolbar==="narrow"||e.options.toolbar==="show-narrow"?n.push(...Array.from(i.querySelectorAll("[wide]"))):n.push(...Array.from(i.querySelectorAll("[narrow]"))),e.options.file_menu||n.push(i.querySelector("[file-menu]")),e.options.font_scale||n.push(i.querySelector("[font-scale]")),e.options.chart_menu||n.push(i.querySelector("[chart-menu]")),e.options.freeze_button||n.push(i.querySelector("[freeze-button]")),e.options.table_button||n.push(i.querySelector("[table-button]")),!e.options.add_tab&&!e.options.delete_tab&&n.push(...Array.from(i.querySelectorAll("[add-remove-sheet]"))),e.options.toolbar_recalculate_button||n.push(i.querySelector("[recalculate-button]"));for(let _ of n)_&&_.parentElement?.removeChild(_);let a=i.querySelector(".treb-color-chooser"),s=i.querySelector(".treb-comment-box textarea");for(let[_,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"})){let x=i.querySelector(w);x&&(this.toolbar_controls[_]=x)}let o=a.querySelectorAll(".treb-swatches");this.swatch_lists={theme:o[0],other:o[1]};let l=t.querySelector("[data-command=increase-precision");l&&(l.textContent=this.sheet?.FormatNumber(0,"0.00")||""),l=t.querySelector("[data-command=decrease-precision"),l&&(l.textContent=this.sheet?.FormatNumber(0,"0.0")||""),l=i.querySelector("[data-command=update-comment]"),s.addEventListener("keydown",_=>{_.key==="Enter"&&(_.shiftKey||_.ctrlKey)&&l.click()});for(let _ of["border","annotation","align","justify"])this.replace_targets[_]=i.querySelector(`[data-target=${_}`);for(let _ of["fill","text","border"])this.color_bar_elements[_]=i.querySelector(`[data-color-bar=${_}]`);i.addEventListener("click",_=>{let w=_.target,x={format:w.dataset.format,scale:w.dataset.scale},A=w?.dataset.command;if(A){let k=w.parentElement?.dataset.replace;if(k){let S=this.replace_targets[k];S&&(S.dataset.command=A,S.title=w.title||"")}switch(/^border-/.test(A)&&(x.color=this.border_color||{}),A){case"text-color":case"fill-color":x.color={};try{x.color=JSON.parse(w.dataset.color||"{}")}catch(S){console.error(S)}break;case"set-color":A=a.dataset.colorCommand||"",x.color={};try{x.color=JSON.parse(w.dataset.color||"{}")}catch(S){console.error(S)}if(A==="border-color"&&(this.border_color=x.color),a.dataset.target){let S=this.color_bar_elements[a.dataset.target];S&&(S.style.setProperty("--treb-color-bar-color",w.style.backgroundColor),S.dataset.color=w.dataset.color||"{}")}break;case"update-comment":x.comment=s.value;break}e.HandleToolbarMessage({command:A,...x})}});let d=(_,w)=>{let x=i.querySelector(_);if(x){let A="";x.addEventListener("focusin",()=>A=x.value),x.addEventListener("keydown",k=>{switch(k.key){case"Escape":x.value=A,e.Focus();break;case"Enter":w(x.value)||(x.value=A,e.Focus());break;default:return}k.stopPropagation(),k.preventDefault()})}};d("input.treb-number-format",_=>_?(e.HandleToolbarMessage({command:"number-format",format:_}),!0):!1),d("input.treb-font-scale",_=>{let w=Number(_);return!w||isNaN(w)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:w}),!0)});let h=a.querySelector("input"),u=a.querySelector("input + button");h.addEventListener("input",_=>{if(_ instanceof InputEvent&&_.isComposing)return;u.style.background=h.value||"";let w=u.style.backgroundColor||"#fff",x=de.MeasureColor(w),A=Q.RGBToHSL(x[0],x[1],x[2]);u.style.color=A.l>.5?"#000":"#fff",u.dataset.color=JSON.stringify(u.style.backgroundColor?{text:u.style.backgroundColor}:{})}),h.addEventListener("keydown",_=>{_.key==="Enter"&&(_.stopPropagation(),_.preventDefault(),u.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 m=!1,f=_=>{_.key==="Escape"&&(_.stopPropagation(),_.preventDefault(),Promise.resolve().then(()=>e.Focus()))},p=_=>{if(m){if(_.relatedTarget instanceof Node&&i.contains(_.relatedTarget))return;i.removeEventListener("keydown",f),i.removeEventListener("focusout",p),m=!1}},g=_=>{let w=_.target,x=w?.parentElement;if(w?.classList.contains("treb-menu")){x=w;for(let A of Array.from(x.children))if(A.tagName==="BUTTON"){w=A;break}}else if(!x?.classList.contains("treb-menu"))return;if(w&&x){m||(i.addEventListener("focusout",p),i.addEventListener("keydown",f),m=!0),x.dataset.colorCommand&&(a.querySelector(".treb-default-color")?.setAttribute("title",x.dataset.defaultColorText||"Default color"),x.appendChild(a),a.dataset.colorCommand=x.dataset.colorCommand,a.dataset.target=x.dataset.replaceColor||"");let A=x.querySelector("div"),k=r.getBoundingClientRect(),S=w.getBoundingClientRect(),{left:M}=S,V=x.parentElement;V?.hasAttribute("composite")&&(M=V.firstElementChild.getBoundingClientRect().left);let W=A.getBoundingClientRect();x.classList.contains("treb-submenu")?(A.style.top=S.top-W.height/2+"px",M+S.width+6+W.width>k.right?A.style.left=M-6-W.width+"px":A.style.left=M+S.width+6+"px"):(A.style.top=S.bottom+"px",M+W.width>k.right-6?A.style.left=S.right-W.width+"px":A.style.left=M+"px");let me=A.querySelector("textarea");me&&requestAnimationFrame(()=>me.focus())}},b=this.root?.querySelector(".treb-number-format-menu");b&&(this.UpdateDocumentStyles(e,b),this.UpdateSelectionStyle(e,i,s),e.Subscribe(_=>{switch(_.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,b),this.UpdateSelectionStyle(e,i,s),this.UpdateRevertState(e);break;case"selection":this.UpdateSelectionStyle(e,i,s);break}}));let v=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i.addEventListener("focusin",_=>{g(_)}),v){let _=Array.from(i.querySelectorAll(".treb-menu"));for(let w of _)w.tabIndex=0;i.addEventListener("mousedown",w=>{g(w)})}}};var qt=class{version="28.3.4";CreateSpreadsheet(e){let t=e.container,r=new We(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},fa=new qt;if(typeof HTMLElement<"u"){class c extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new We(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",c))}export{fa as TREB,qt as TREBGlobal};
|