@trebco/treb 29.5.1 → 29.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,16 @@
1
- /*! TREB v29.5.1. Copyright 2018-2024 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
1
+ /*! TREB v29.5.4. Copyright 2018-2024 trebco, llc. All rights reserved. LGPL: https://treb.app/license */
2
2
  var xn=Object.defineProperty;var wn=(c,e)=>{for(var t in e)xn(c,t,{get:e[t],enumerable:!0})};var pt=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)}}};var ii={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0,decimal_mark:".",argument_separator:","};var xe=/[\s-+=<>!()]/,li=/['*\\]/,dr=34,hr=39,Cn=160,ni=32,Sn=9,An=10,kn=13,Ae=48,Je=57,ur=46,mr=43,Xe=45,oi=40,fr=41,Qe=44,Tn=37,pr=95,bt=36,Rn=123,En=125,qe=91,ai=93,Mn=63,In=33,si=59,zn=35,Nn=64,$e=65,Ke=97,Dn=69,Vn=101,gt=90,_t=122,Un=105,br=192,gr=312,_r={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},Fn=Object.keys(_r).sort((c,e)=>e.length-c.length),Ln={"-":100,"+":100},He=class{get argument_separator(){return this.flags.argument_separator}get decimal_mark(){return this.flags.decimal_mark}flags={...ii};r1c1_regex=/[rR]((?:\[[-+]{0,1}\d+\]|\d+))[cC]((?:\[[-+]{0,1}\d+\]|\d+))$/;argument_separator_char=Qe;decimal_mark_char=ur;imaginary_char=Un;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=[];parser_state_cache=[];SetLocaleSettings(e,t){if(typeof t>"u"&&(t=e===","?";":","),t===e)throw new Error("invalid locale setting");this.flags.argument_separator=t,this.flags.decimal_mark=e}Save(){this.parser_state_cache.push(JSON.stringify(this.flags))}Restore(){let e=this.parser_state_cache.shift();if(e)try{this.flags=JSON.parse(e)}catch(t){console.error(t)}else console.warn("No parser state to restore")}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 o=0;o<t;o++)r[n][o]=e[o]?e[o][n]:void 0}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},i=t.missing??"(missing)",{convert_decimal:n,convert_argument_separator:o,long_structured_references:a,table_name:s}=t,l=this.flags.argument_separator+" ";o===","?l=", ":o===";"&&(l="; ");let d=n===","?",":".",h=this.flags.decimal_mark===","?/,/:/\./,u=this.flags.decimal_mark===","?/,/g:/\./g;switch(e.type){case"address":return t.r1c1?this.R1C1Label(e,t.r1c1_base):this.AddressLabel(e,r);case"range":return t.r1c1?this.R1C1Label(e.start,t.r1c1_base)+":"+this.R1C1Label(e.end,t.r1c1_base):this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return i;case"array":return"{"+this.Transpose(e.values).map(m=>m.map(f=>typeof f=="string"?'"'+f+'"':f).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(u,d):e.text;{let m=Math.abs(e.imaginary).toString();if((n===","||this.flags.decimal_mark===",")&&(m=m.replace(/\./,",")),e.real){let f=e.real.toString();(n===","||this.flags.decimal_mark===",")&&(f=f.replace(/\./,","));let p=Math.abs(e.imaginary);return`${f}${e.imaginary<0?" - ":" + "}${p===1?"":m}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${m}i`}break;case"literal":if(typeof e.value=="string")return'"'+e.value.replace(/"/g,'""')+'"';if(n&&typeof e.value=="number")if(e.text){let m=e.text;return n===","&&this.flags.decimal_mark==="."&&(m=m.replace(/,/g,"")),m.replace(h,d)}else return e.value.toString().replace(/\./,d);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(m=>this.Render(m,t)).join(l)+")":e.elements.map(m=>this.Render(m,t)).join(l);case"call":return e.name+"("+e.args.map(m=>this.Render(m,t)).join(l)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let m=e.column;/[^A-Za-z]/.test(m)&&(m="["+m+"]");let f=e.table;switch(!f&&a&&s&&(f=s),e.scope){case"all":return`${f}[[#all],${m}]`;case"row":return a?`${f}[[#this row],${m}]`:`${f}[@${m}]`;case"column":return`${f}[${m}]`}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.flags.argument_separator){case";":this.argument_separator_char=si;break;default:this.argument_separator_char=Qe;break}switch(this.flags.decimal_mark){case",":this.decimal_mark_char=Qe;break;default:this.decimal_mark_char=ur;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.flags.argument_separator,decimal_mark:this.flags.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}R1C1Label(e,t){let r="";e.sheet&&(r=(xe.test(e.sheet)?"'"+e.sheet+"'":e.sheet)+"!");let i=e.absolute_row||!t?(e.row+1).toString():`[${e.row-t.row}]`,n=e.absolute_column||!t?(e.column+1).toString():`[${e.column-t.column}]`;return r+=`R${i}C${n}`,r}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=(xe.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===oi){this.index++;let i=this.ParseGeneric([fr]);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=o=>o.type==="literal"&&typeof o.value=="number"&&o.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 o=t[n],a=t[n+1],s=t[n+3],l=(o.value<0?-1:1)*(a.value/s.value);n+=3,r.push({id:t[n].id,type:"literal",text:this.expression.substring(o.position,s.position+1),value:o.value+l,position:o.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 o=t[n];if(!i)i=o;else if(o.type==="identifier"&&(i.type==="literal"||i.type==="group"||i.type==="call")){let a=o;for(;t[n+1]?.type==="identifier";)a.name+=" "+t[++n].name;r.push({type:"dimensioned",expression:i,unit:o,id:this.id_counter++}),i=void 0}else r.push(i),i=o}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 o=Number(r);if(isNaN(o)){if(/[A-Z]{1,3}/.test(r)){let a=-1;for(let s=0;s<r.length;s++){let l=r[s].charCodeAt(0);a=26*(1+a)+(l-$e)}return{type:"address",position:e.position,absolute_column:n,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:n,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 i=e[r],n=e[r+1],o=e[r+2],a,s="",l;if(i&&n&&o&&n.type==="operator"&&n.operator===":"){if(i.type==="address"&&o.type==="address"){let d=i.position+i.label.length,h=o.position;a={type:"range",id:this.id_counter++,position:i.position,start:i,end:o,label:i.label+this.expression.substring(d,h)+o.label},s=a.start.label+":"+a.end.label,this.address_refcount[a.start.label]--,this.address_refcount[a.end.label]--;let u=[i.position,o.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")&&(o.type==="literal"||o.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(o);d&&h&&(d.column===1/0&&h.column===1/0||d.row===1/0&&h.row===1/0)&&(s=d.label+":"+h.label,a={type:"range",id:this.id_counter++,position:d.position,start:d,end:h,label:s})}}a?(l&&t.push(l),t.push(a),this.dependencies.ranges[s]=a,this.full_reference_list.push(a),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 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 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(Ln[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],o=t[t.length-1],a=o.operator,s={type:"binary",id:this.id_counter++,left:n,operator:a,position:o.position,right:i};n.type==="binary"&&_r[a]>_r[n.operator]&&(s.left=n.left,s.operator=n.operator,s.position=n.position,s.right={type:"binary",id:this.id_counter++,left:n.right,right:i,operator:a,position:o.position}),t.splice(-2,2,s)}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===dr)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=Ae&&t<=Je||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===Rn)return this.ConsumeArray();if(e&&(t===Xe||t===mr)){let r=this.data[this.index+1];if(r>=Ae&&r<=Je||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=$e&&t<=gt||t>=Ke&&t<=_t||t===pr||t===zn||t===hr||t===bt||t===qe||t>=br&&t<=gr)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 si:r++,t=0;break;case Qe:t++;break;case En: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 Fn)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,fr]);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===fr)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,i=e===hr,n=0,o=!1;for(e===qe&&(n=1,o=!0),++this.index;this.index<this.length;this.index++){let d=this.data[this.index];if(d>=$e&&d<=gt||d>=Ke&&d<=_t||d>=br&&d<=gr||d===pr||d===bt||d===ur||d===In||i||d>=Ae&&d<=Je||d===qe||n>0&&d===ai||d===Xe&&this.flags.r1c1&&n===1||n>0&&d===Nn&&this.data[this.index-1]===qe||n===1&&(d===Qe||d===ni)||n>1||d===Mn&&n===0)t.push(d),d===qe&&(n++,o=!0),d===ai&&n--,d===hr&&(i=!1);else break}let a=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:a,position:r};if(n)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]===oi){let d=this.ConsumeArguments();return{type:"call",id:this.id_counter++,name:a,args:d,position:r}}if(this.flags.spreadsheet_semantics){let d=this.ConsumeAddress(a,r);if(d)return d;if(o){let h=this.ConsumeStructuredReference(a,r);if(h)return h}}let l={type:"identifier",id:this.id_counter++,name:a,position:r};return this.full_reference_list.push(l),l}ConsumeStructuredReference(e,t){let r=e.length,i=e,n="",o=0;for(;o<r;o++){if(e[o]==="["){e=e.substring(o);break}n+=e[o]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let a=e.split(",").map(h=>h.trim()),s="column",l="";if(a.length>2)return;a.length===2?(/\[#this row\]/i.test(a[0])?s="row":/\[#all\]/i.test(a[0])&&(s="all"),l=a[1]):(l=a[0],l[0]==="@"&&(s="row",l=l.substring(1,l.length))),l[0]==="["&&l[l.length-1]==="]"&&(l=l.substring(1,l.length-1));let d={type:"structured-reference",id:this.id_counter++,label:i,position:t,scope:s,column:l,table:n};return this.full_reference_list.push(d),d}ConsumeAddress(e,t){let r=t,i=e.length,n,o=e.split("!");if(o.length>1&&(n=o.slice(0,o.length-1).join("!"),t+=n.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: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 a=this.ConsumeAddressColumn(t);if(!a)return null;t=a.position;let s=this.ConsumeAddressRow(t);if(!s)return null;t=s.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:s.row,column:a.column,absolute_row:s.absolute,absolute_column:a.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]===bt;t&&e++;let r=e,i=0;for(;;e++){let n=this.data[e];if(n>=Ae&&n<=Je)i*=10,i+=n-Ae;else break}return r===e||i===0?!1:{absolute:t,row:i-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,i=this.data[e]===bt;for(i&&e++;;e++,r++){if(r>=4)return!1;let n=this.data[e];if(n>=$e&&n<=gt)t=26*(1+t)+(n-$e);else if(n>=Ke&&n<=_t)t=26*(1+t)+(n-Ke);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,o=0,a=0,s="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(s==="integer")s="fraction";else break;else if(m===Tn){n/=100,a/=100,this.index++;break}else if(m===mr||m===Xe)if(l===0)m===Xe&&(i=!0);else break;else if(m===Dn||m===Vn)if(s==="integer"||s==="fraction")s="exponent",this.index<this.length-1&&(this.data[this.index+1]===mr?this.index++:this.data[this.index+1]===Xe&&(this.index++,r=!0));else break;else if(m===this.imaginary_char){let f=this.data[this.index+1];if(f>=$e&&f<=gt||f>=Ke&&f<=_t||f>=br&&f<=gr||f===pr)break;if(s==="integer"||s==="fraction"){this.index++,d=!0;break}}else if(m>=Ae&&m<=Je)switch(s){case"integer":n=n*10+(m-Ae);break;case"fraction":a=a*10+(m-Ae),o++;break;case"exponent":t=t*10+(m-Ae);break}else break}let u=n+a/Math.pow(10,o);return s==="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===dr&&(this.index++,this.index>=this.length||this.data[this.index]!==dr))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===ni||e===Sn||e===An||e===kn||e===Cn)this.index++;else return}}};var ci=(c,e=",")=>{let t=0,r=[],i="",n=[],o=c.length;if(/[\r\n"]/.test(e))throw new Error("invalid delimiter");for(let a=0;a<o;a++){let s=c[a];if(!(a===0&&s.charCodeAt(0)===65279))if(t===0)switch(s){case e:r.push(i),i="";break;case"\r":break;case`
3
3
  `:r.push(i),i="",n.push(r),r=[];break;case'"':i.length===0?t=1:i+=s;break;default:i+=s;break}else s==='"'?a+1<o&&c[a+1]==='"'?(i+='"',a++):t=0:i+=s}return(r.length||i.length)&&(r.push(i),n.push(r)),n};var ze=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],o=t[r+1],a=!n||n.type==="whitespace"||n.type==="newline",s=n&&n.type==="text"&&/[^\w\d]$/.test(n.text),l=!o||o.type==="whitespace"||o.type==="newline",d=o&&o.type==="text"&&/^[^\w\d]/.test(o.text);i.left_flanking=!l&&(!d||a),i.right_flanking=!a&&(!s||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 o of e)if(o.type==="newline")n.text.length&&i.push(n),n={...r,text:"",type:"text"},t.push(i),i=[];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,n.text.length&&i.push(n),n={...r,text:"",type:"text"}),o.type){case"text":case"whitespace":n.text+=o.text;break;case"delimeter":for(let a=0;a<o.length;a++)n.text+=o.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 o=this.ApplyFormatting(e.slice(r+1),n);if(o.token){let a=Math.min(o.token.length,n.length),s=n.char==="~",l=!s&&!!(a%2),d=!s&&a>=2;for(let h=r+1;h<=r+o.index;h++)e[h].strong=!!e[h].strong||d,e[h].emphasis=!!e[h].emphasis||l,e[h].strike=!!e[h].strike||s;o.token.length-=a,n.length-=a,n.length>0?r--:r+=o.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,i=0,n=!1,o="";for(i=0;i<r;i++){let a=e[i];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(this.IsWhitespace(l))s+=l,i++;else break}t.push({type:"whitespace",text:s}),n=!1,o=""}else if(this.IsNewline(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(this.IsNewline(l))s+=l,i++;else break}t.push({type:"newline",text:s}),n=!1,o=""}else if(n)o+=a,n=!1;else if(this.IsDelimeter(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(l===a)s+=l,i++;else break}t.push({type:"delimeter",text:s,char:a,length:s.length}),n=!1,o=""}else a==="\\"?n=!0:o+=a}return o&&t.push({type:"text",text:o}),t}};var V=c=>c!==null&&typeof c=="object"&&"row"in c&&"column"in c,tt=c=>c!==null&&typeof c=="object"&&"start"in c&&V(c.start)&&"end"in c&&V(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){if(e.row===1/0&&e.column===1/0)throw new Error("this is going to break something");let r=t?`${e.sheet_id||0}!`:"";return e.row===1/0?r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column):e.column===1/0?r+(e.absolute_row?"$":"")+(e.row+1):r+(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:o}=t,a=new c(e.start,e.end),s=e.start.sheet_id;if(i&&r<=a.end.column){if(i>0)r<=a.start.column?a.Shift(0,i):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(a));else if(i<0)if(r-i<=a.start.column)a.Shift(0,i);else{if(r<=a.start.column&&r-i>a.end.column)return!1;if(r<=a.start.column){let l=r-i-1;a=new c({row:a.start.row,column:l+1+i,sheet_id:s},{row:a.end.row,column:a.end.column+i})}else r<=a.end.column?r-i-1>=a.end.column?a=new c({row:a.start.row,column:a.start.column,sheet_id:s},{row:a.end.row,column:r-1}):a=new c({row:a.start.row,column:a.start.column,sheet_id:s},{row:a.end.row,column:a.start.column+a.columns+i-1}):console.warn("AA X case 2",r,i,JSON.stringify(a))}}if(o&&n<=a.end.row){if(o>0)n<=a.start.row?a.Shift(o,0):n>a.start.row&&n<=a.end.row?a.ConsumeAddress({row:a.end.row+o,column:a.end.column}):console.warn("AA X case 3",n,o,JSON.stringify(a));else if(o<0)if(n-o<=a.start.row)a.Shift(o,0);else{if(n<=a.start.row&&n-o>a.end.row)return!1;if(n<=a.start.row){let l=n-o-1;a=new c({column:a.start.column,row:l+1+o,sheet_id:s},{column:a.end.column,row:a.end.row+o})}else n<=a.end.row?n-o-1>=a.end.row?a=new c({column:a.start.column,row:a.start.row,sheet_id:s},{column:a.end.column,row:n-1}):a=new c({column:a.start.column,row:a.start.row,sheet_id:s},{column:a.end.column,row:a.start.row+a.rows+o-1}):console.warn("AA X case 4",n,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}Equals2(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)}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}[Symbol.iterator](){if(this.entire_row||this.entire_column)throw new Error("don't iterate infinite area");let e=this.start_.row,t=this.start_.column;return{next:()=>{let r={column:t,row:e,sheet_id:this.start_.sheet_id};return t>this.end_.column?{done:!0,value:void 0}:(++e>this.end_.row&&(e=this.start_.row,t++),{value:r})}}}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 ae=c=>typeof c=="object"&&!!c&&typeof c.real=="number"&&typeof c.imaginary=="number",Oe=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",vr=c=>typeof c=="object"&&!!c&&typeof c.value=="number"&&typeof c.unit=="string",xr=["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:ae(c)?7:vr(c)?9:5;case"string":return c[0]==="="?1:2;default:return 6}};var re=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;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 wr=c=>!c.cells,rt=c=>!!c[0]&&wr(c[0]),Cr=c=>!!c[0]&&c[0].row!==void 0,Pn=xr.map((c,e)=>({[c]:e})).reduce((c,e)=>({...c,...e}),{}),yt=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){this.data=this.data.map(r=>{if(r.length>=e){let i=r.slice(0,e),n=e+t,o=r.slice(e);for(let a=0;a<o.length;a++)i[n++]=o[a];return i}return r}),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 re,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 re,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 o=e[n];r=Math.max(r,o.length);for(let a=0;a<o.length;a++)this.data[a]||(this.data[a]=[]),this.data[a][n]=new re(o[a])}}else{r=e.length;for(let n=0;n<r;n++){let o=[],a=e[n];i=Math.max(i,a.length);for(let s=0;s<a.length;s++)o[s]=new re(a[s]);this.data[n]=o}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Pn[e]||void 0}ValueTypeToSerializedType(e){return e?xr[e]:void 0}FromJSON(e=[],t){if(this.data=[],!rt(e)){let i=[];if(Cr(e))for(let n of e)for(let o of n.cells)i.push({...o,row:n.row});else for(let n of e)for(let o of n.cells)i.push({...o,column:n.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let n=new re(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 o=new y(i.area.start,i.area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=o.end.column;s++)this.data[a]||(this.data[a]=[]),this.data[a][s]||(this.data[a][s]=new re),this.data[a][s].area=o}if(i.table&&r.push({...i.table}),i.merge_area){let o=new y(i.merge_area.start,i.merge_area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=o.end.column;s++)this.data[a]||(this.data[a]=[]),this.data[a][s]||(this.data[a][s]=new re),this.data[a][s].merge_area=o}}for(let i of r)for(let n=i.area.start.row;n<=i.area.end.row;n++)for(let o=i.area.start.column;o<=i.area.end.column;o++)this.data[n]||(this.data[n]=[]),this.data[n][o]||(this.data[n][o]=new re),this.data[n][o].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 o=[],a=-1,s=-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,b=f&&f.area&&f.area.start.row===h&&f.area.start.column===m,g=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===m,C=f?f.type===2&&!f.value:!0;if(f&&(!C||e.preserve_empty_strings)&&(p||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||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:m,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&&g&&e.tables&&(x.table=JSON.parse(JSON.stringify(f.table))),f.area&&b&&(x.area=f.area.toJSON()),f.merge_area&&(x.merge_area=f.merge_area.toJSON()),e.cell_style_refs&&e.cell_style_refs[m]&&e.cell_style_refs[m][h]&&(x.style_ref=e.cell_style_refs[m][h],e.cell_style_refs[m][h]=0),l[h]=h,d[m]=m,a=Math.max(h,a),s=Math.max(m,s),o.push(x)}}}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 o){let{row:b,...g}=p;m[p.row]||(m[p.row]=[]),m[p.row].push(g)}for(let p of h){let b=Number(p);f.push({row:b,cells:m[b]})}return{data:f,rows:a,columns:s+1}}else if(u.length){let m={},f=[];for(let p of o){let{column:b,...g}=p;m[p.column]||(m[p.column]=[]),m[p.column].push(g)}for(let p of u){let b=Number(p);f.push({column:b,cells:m[b]})}return{data:f,rows:a,columns:s+1}}}return{data:o,rows:a+1,columns:s+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize(e,t){return e={...e,row:e.row==1/0?0:e.row,column:e.column==1/0?0:e.column},t&&(t={...t,row:t.row==1/0?this.rows_-1:t.row,column:t.column==1/0?this.columns_-1:t.column}),{from:e,to:t}}RawValue(e,t=e){if({from:e,to:t}=this.Normalize(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,o=t.column+1;for(let a of i){let s=[];for(let l=n,d=0;l<o;l++,d++){let h=a[l];s.push(h?h.value:void 0)}r.push(s)}return r}GetRange(e,t,r=!1){if({from:e,to:t}=this.Normalize(e,t),!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 o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][n]?o.push(this.data[a][n].GetValue()):o.push(void 0);i.push(o)}else for(let n=e.row;n<=t.row;n++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[n]&&this.data[n][a]?o.push(this.data[n][a].GetValue()):o.push(void 0);i.push(o)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize(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 o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][n]?o.push(this.data[a][n].GetValue4()):o.push({type:0});i.push(o)}else for(let n=e.row;n<=t.row;n++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[n]&&this.data[n][a]?o.push(this.data[n][a].GetValue4()):o.push({type:0});i.push(o)}return{type:8,value:i}}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 o=e.start.column,a=0;o<=e.end.column;o++,a++)n[o]||(n[o]=new re),n[o].Set(t[i][a])}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 o=e.start.column;o<=e.end.column;o++)n[o]||(n[o]=new re),n[o].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}*Iterate(e,t=!1){if(!e&&t&&(e=new y({row:0,column:0},{row:this.rows_-1,column:this.columns-1})),e){V(e)&&(e=new y(e)),(e.entire_column||e.entire_row)&&(e=new y(e.start,e.end),e.start.column===1/0&&(e.start.column=0,e.end.column=this.columns_-1),e.start.row===1/0&&(e.start.row=0,e.end.row=this.rows_-1));let r=e.start,i=e.end;if(t)for(let n=r.row;n<=i.row;n++){this.data[n]||(this.data[n]=[]);let o=this.data[n];for(let a=r.column;a<=i.column;a++)o[a]||(o[a]=new re),yield o[a]}else for(let n=r.row;n<=i.row;n++)if(this.data[n]){let o=this.data[n];for(let a=r.column;a<=i.column;a++)o[a]&&(yield o[a])}}else for(let r of this.data)if(r)for(let i of r)i&&(yield i)}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 N=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)}this.locale==="C"&&(console.warn("Locale not set, defaulting to en-us"),this.locale="en-us");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"}))}};N.UpdateLocale();var G=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!!e&&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 Gn=JSON.stringify({}),$n={Background:0,Text:1,Background2:2,Text2:3,Accent:4,Accent2:5,Accent3:6,Accent4:7,Accent5:8,Accent6:9},Sr=c=>typeof c.theme=="number"?c.theme:$n[c.theme]||0,J=c=>!!c&&typeof c.text=="string",Ze=c=>!!c&&typeof c.theme<"u",di=c=>!!c&&(typeof c.text=="string"||typeof c.theme<"u"),F={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)===Gn,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 Ar=c=>!!c&&Array.isArray(c)&&Array.isArray(c[0]),W=(c,e)=>(typeof e>"u"&&(e=se(c)),{value:c,type:e}),me=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real};var K={Darken:(c,e,t,r,i=!1)=>{let{h:n,s:o,l:a}=K.RGBToHSL(c,e,t);return i?a-=a*r/100:a-=r/100,a=Math.max(0,Math.min(1,a)),K.HSLToRGB(n,o,a)},Lighten:(c,e,t,r,i=!1)=>{let{h:n,s:o,l:a}=K.RGBToHSL(c,e,t);return i?a+=a*r/100:a+=r/100,a=Math.max(0,Math.min(1,a)),K.HSLToRGB(n,o,a)},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,o=0,a=(r+i)/2;if(r===i)n=o=0;else{let s=r-i;switch(o=a>.5?s/(2-r-i):s/(r+i),r){case c:n=(e-t)/s+(e<t?6:0);break;case e:n=(t-c)/s+2;break;case t:n=(c-e)/s+4;break}n/=6}return{h:n*360,s:o,l:a}},HSLToRGB:(c,e,t)=>{let r,i,n;if(e===0)r=i=n=t;else{c=c/360;let o=t<.5?t*(1+e):t+e-t*e,a=2*t-o;r=K.HueToRGB(a,o,c+.3333333333333333),i=K.HueToRGB(a,o,c),n=K.HueToRGB(a,o,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 Hn="http://www.w3.org/2000/svg",P=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(Hn,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[o,a]of Object.entries(i.attrs))n.setAttribute(o,a);if(i.data)for(let[o,a]of Object.entries(i.data))n.dataset[o]=a;if(i.text&&(n.textContent=i.text),i.html&&(n.innerHTML=i.html),i.events)for(let[o,a]of Object.entries(i.events))n.addEventListener(o,a);if(i.style)for(let[o,a]of Object.entries(i.style))n.style[o]=a}return r&&r.appendChild(n),n}};var vt={grid_color:"#ccc",note_marker_color:"#d2c500",mode:"light",offset_cache:{},offset_light:"#fff",offset_dark:"#000"},On=(c,e)=>{let t=Sr(e),r=e.tint||0;c.mode==="dark"&&(r=-r),c.tint_cache||(c.tint_cache=[]),c.tint_cache[t]||(c.tint_cache[t]={});let i=c.tint_cache[t][r];if(!i){let n=(c.theme_colors_rgb?c.theme_colors_rgb[t]:[0,0,0])||[0,0,0],o;r>0?o=K.Lighten(n[0],n[1],n[2],r*100,!0):o=K.Darken(n[0],n[1],n[2],-r*100,!0),i=`rgb(${o.r},${o.g},${o.b})`,c.tint_cache[t][r]=i}return i},R=(c,e,t)=>{if(e&&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?K.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 J(e)?e.text==="none"?"":e.text:Ze(e)?e.tint?On(c,e):c.theme_colors?c.theme_colors[Sr(e)]:"":(t||t===0)&&c.theme_colors?c.theme_colors[t]:""},Zn=c=>{let e=10,t="pt",r=c.match(/^([\d.]+)(\D.*)$/);return r&&(e=Number(r[1]),t=r[2]),{value:e,unit:t}},hi=c=>{let{value:e,unit:t}=Zn(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},Bn=(c,e)=>{let t=c.grid_cell?.text,r=c.grid_cell?.fill;e.fillStyle=J(t)?t.text:"",e.fillRect(0,0,3,3);let i=K.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));e.fillStyle=J(r)?r.text:"",e.fillRect(0,0,3,3);let n=K.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));return i.l>n.l?"dark":"light"},xt=(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}}},ui=c=>{let e=JSON.parse(JSON.stringify(vt)),t=P.GetInstance(c.ownerDocument),r=(h,u)=>t.Div(u,h),i=(h,u)=>t.view?.getComputedStyle(r(h,u)),n=r(c,""),o=i.bind(0,n),a=o("grid-cells");e.grid_cell=hi(a),e.grid_color=a.stroke||"",a=o("grid-headers"),e.headers=hi(a),e.headers_grid_color=a.stroke,(!e.headers_grid_color||e.headers_grid_color==="none")&&(e.headers_grid_color=e.grid_color),a=o("treb-offset-dark"),a.color&&(e.offset_dark=a.color),a=o("treb-offset-light"),a.color&&(e.offset_light=a.color),a=o("note-marker"),e.note_marker_color=a.backgroundColor,n.style.color="rgba(1,2,3,.4)",a=o("");let s=a.color;e.theme_colors=[J(e.grid_cell.fill)?e.grid_cell.fill.text:"rgb(255, 255, 255)",J(e.grid_cell.text)?e.grid_cell.text.text:"rgb(51, 51, 51)"];for(let h=1;h<32&&(a=o(`theme-color-${h}`),!(!a.color||a.color===s));h++)e.theme_colors.push(a.color);let l=t.Create("canvas");l.width=3,l.height=3;let d=l.getContext("2d",{willReadFrequently:!0});return d&&(e.mode=Bn(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=xt(4),n.parentElement?.removeChild(n),e};var mi={column:0,type:"auto",asc:!0};var Wn=1e3,le=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=Wn++;return this.subscribers.push({subscriber:e,token:t}),t}Cancel(e){this.subscribers=this.subscribers.filter(t=>t.token!==e)}CancelAll(){this.subscribers=[]}};var ye=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 kr,fi=c=>{let e={};for(let t=0;t<c.length;t++){let r=c[t];e[r]=c.getPropertyValue(r)}return e},jn=(c,e,t)=>{let r={},i=fi(e);for(let n of Object.keys(i))i[n]!==t[n]&&(r[n]=t[n]);return(Object.keys(r).map(n=>`${n}: ${r[n]}`).join("; ")+"; "+(c.getAttribute("style")||"")).trim().replace(/"/g,"'")},pi=(c,e)=>{let t=c.cloneNode(!1),r=getComputedStyle(c),i=jn(c,r,e);t.removeAttribute("class"),t.setAttribute("style",i);let n;return Array.prototype.forEach.call(c.childNodes,o=>{switch(o.nodeType){case Node.ELEMENT_NODE:n||(n=fi(r)),t.appendChild(pi(o,n));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",o)}}),t},bi=c=>{if(!kr){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,o=>e[o]=n[o])}document.body.removeChild(t),kr=e}return pi(c,kr)};var Yn={data:!0,same_origin:!0,remote:!1},wt=(c,e={})=>{let t={...Yn,...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 gi=(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,o=Math.log(n)/Math.log(10),a=Math.floor(Math.abs(o))*(o<0?-1:1)-1;i&&(a=Math.max(0,a));let s=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 s){let u=h*Math.pow(10,a),m=Math.floor(c/u)*u,p=(Math.ceil(e/u)*u-m)/u,b=Math.abs(p-t);(l<0||b<d)&&(!r||p<=t)&&(d=b,l=u)}return c=Math.floor(c/l)*l,e=Math.ceil(e/l)*l,t=Math.round((e-c)/l),{scale:a,step:l,count:t,min:c,max:e}};var Ct=class{constructor(e,t,r="RGB"){this.color_space=r;this.mapped=e.map(i=>{if(i.value<0||i.value>1)throw new Error("invalid stop value");let n=ye.MeasureColor(R(t,i.color)),o=[];if(r==="HSL"){let a=K.RGBToHSL(n[0],n[1],n[2]);o=[a.h,a.s,a.l]}else o=[...n];return{...i,resolved:o}}),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,o=n.value-i.value,a=e-i.value,s=[0,1,2].map(l=>i.resolved[l]+(n.resolved[l]-i.resolved[l])/o*a);return this.RenderColor(s)}}return{text:""}}};var St=class{constructor(e){this.parser=e}named=new Map;get list(){return this.named.values()}SetNamedExpression(e,t,r){return this.SetName({type:"expression",name:e,expression:t,scope:r})}SetNamedRange(e,t,r){return this.SetName({type:"range",name:e,area:new y(t.start,t.end),scope:r})}SetName(e){let t=e.name;return this.ValidateNamed(t)?(this.named.set(this.ScopedName(t,e.scope),e),!0):(console.warn("invalid name",{name:t}),!1)}ScopedName(e,t){return typeof t=="number"?t+":"+e.toLowerCase():e.toLowerCase()}ClearName(e,t){typeof t=="number"?this.named.delete(this.ScopedName(e,t)):this.named.delete(e.toLowerCase())}RemoveRangesForSheet(e){let t=[];for(let[r,i]of this.named)(i.type==="range"&&i.area.start.sheet_id===e||i.scope===e)&&t.push(r);for(let r of t)this.named.delete(r)}Reset(){this.named.clear()}Get_(e,t,r=!1){return r?this.named.get(this.ScopedName(e,t)):this.named.get(this.ScopedName(e,t))||this.named.get(e.toLowerCase())}ValidateNamed(e){return e=e.trim().toUpperCase(),!e.length||/[^A-Z\d_.?]/.test(e)||/^[^A-Z_]/.test(e)||e==="R"||e==="C"||/^[A-Z]{1,3}[1-9]\d*$/.test(e)||/^R[[\]\d]+C/.test(e)?!1:e}MatchSelection(e,t){if(!e.start.sheet_id)throw new Error("match selection without sheet id");let r;for(let i of this.named.values())if(i.type==="range"&&i.area.start.sheet_id===e.start.sheet_id&&(e.Equals(i.area)&&(r=i.name),t?.Equals(i.area)))return i.name;return r}PatchNamedRanges(e,t,r,i,n){let o=[...this.list];for(let a of o){if(a.type==="expression")continue;let s=a.name,l=a.area;if(l.start.sheet_id!==e){console.info("skipping name",s);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(s);else if(t<=l.start.column){let d=t-r-1;this.SetName({type:"range",area:new y({row:l.start.row,column:d+1+r,sheet_id:e},{row:l.end.row,column:l.end.column+r}),name:s})}else t<=l.end.column?t-r-1>=l.end.column?this.SetName({type:"range",area:new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:t-1}),name:s}):this.SetName({type:"range",name:s,area: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})}):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(s);else if(i<=l.start.row){let d=i-n-1;this.SetNamedRange(s,new y({column:l.start.column,row:d+1+n,sheet_id:e},{column:l.end.column,row:l.end.row+n}))}else i<=l.end.row?i-n-1>=l.end.row?this.SetNamedRange(s,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:i-1})):this.SetNamedRange(s,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})):console.warn("PNR X case 4",i,n,JSON.stringify(l))}}}};var it=class{parser=new He;document_name;user_data;sheets=new pt;named=new St(this.parser);macro_functions=new Map;view_count=0;theme_style_properties=JSON.parse(JSON.stringify(F.DefaultProperties));tables=new Map;GetName(e,t){let r=e.split(/!/);if(r.length===1)return this.named.Get_(e,t);let i=r[0];/^'.*?'$/.test(i)&&(i=i.substring(1,i.length-1));let n=this.sheets.ID(i);return this.named.Get_(r[1],n||0,!0)}UnserializeNames(e,t){this.parser.Save(),this.parser.SetLocaleSettings(".",",");for(let r of e){if(!r.expression)continue;let i=this.parser.Parse(r.expression);if(i.expression){let n=typeof r.scope=="string"?this.sheets.ID(r.scope):void 0;if(i.expression.type==="address"||i.expression.type==="range"){let[o,a]=i.expression.type==="range"?[i.expression.start,i.expression.end]:[i.expression,i.expression];if(o.sheet)if(/^\[\d+\]/.test(o.sheet))console.warn("named range refers to an external file");else{let s=new y({...o,sheet_id:this.sheets.ID(o.sheet)},a);s.start.sheet_id?this.named.SetNamedRange(r.name,s,n):console.warn("missing sheet ID?",o)}else console.warn("missing sheet name?",o)}else this.parser.Walk(i.expression,o=>o.type==="address"||o.type==="range"?(o.type==="range"&&(o=o.start),o.sheet_id||o.sheet&&(o.sheet_id=this.sheets.ID(o.sheet)),o.sheet_id||(o.sheet_id=t?.id),!1):!0),this.named.SetNamedExpression(r.name,i.expression,n)}}this.parser.Restore()}SerializeNames(e){let t=[];for(let r of this.named.list){let i={name:r.name,expression:""};if(r.scope&&(i.scope=this.sheets.Name(r.scope)),r.type==="expression")this.parser.Walk(r.expression,n=>{if(n.type==="address"||n.type==="range"){let o=n.type==="range"?n.start:n;return o.absolute_column=o.absolute_row=!0,o.sheet||(o.sheet_id&&(o.sheet=this.sheets.Name(o.sheet_id)),o.sheet||(o.sheet=e?.name)),n.type==="range"&&(n.end.absolute_column=n.end.absolute_row=!0),!1}return!0}),i.expression=this.parser.Render(r.expression,{missing:""});else{let n={start:{...r.area.start,absolute_column:!0,absolute_row:!0},end:{...r.area.end,absolute_column:!0,absolute_row:!0}};i.expression=this.AddressToLabel(n)}t.push(i)}return t}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 o=0;o<r.columns.length;o++)if(i===r.columns[o]){n=r.area.start.column+o;break}}if(!(n<0))if(e.scope==="row"){let o=t.row;return o<r.area.start.row||o>r.area.end.row?void 0:{label:e.label,type:"address",row:o,column:n,sheet_id:r.area.start.sheet_id,id:e.id,position:e.position}}else{let o=r.area.start.row,a=r.area.end.row;return e.scope==="column"&&(o++,r.totals_row&&a--),{label:e.label,type:"range",position:e.position,id:e.id,start:{type:"address",row:o,column:n,sheet_id:r.area.start.sheet_id,label:e.label,position:e.position,id:0},end:{type:"address",row:a,column:n,label:e.label,position:e.position,id:0}}}}AddressToLabel(e){let t=V(e)?e:e.start,r=V(e)?[y.CellAddressToLabel(e)]:[y.CellAddressToLabel(e.start),y.CellAddressToLabel(e.end)],i=this.sheets.Find(t.sheet_id||0),n=i?.name?xe.test(i.name)?`'${i.name}'`:i.name:"";return n+(n?"!":"")+(r[0]===r[1]?r[0]:r.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 V(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.GetName(r.expression.name,t.id);if(i?.type==="range")return i.area}return{row:0,column:0}}return e}AddConnectedElement(e){let t=this.connected_element_id++;return this.connected_elements.set(t,e),t}RemoveConnectedElement(e){let t=this.connected_elements.get(e);return this.connected_elements.delete(e),t}connected_element_id=100;connected_elements=new Map};var ke=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 _i=42,yi=95,Tr=63,At=48,vi=46,Rr=44,xi=37,Er=34,nt=35,wi=59,kt=92,Ci=64,Jn=91,Xn=93,Si=69,Ai=101,Qn=72,qn=104,Kn=77,eo=109,to=83,ro=115,io=68,no=100,oo=89,ao=121,so=65,lo=97;var Tt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new ke;static preserve_formatting_characters=!1;static decimal_mark=vi;static group_separator=Rr;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new ke,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new ke,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 kt: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 Er: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 kt:throw new Error("invalid escape character in formatting block");case Xn: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===nt||n===At)r=!0;else if(n!==Rr)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 nt:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case At: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===Tr||e===nt)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case wi:this.char_index++,this.current_section=new ke,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case Ci:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case At:case nt:case vi:case Rr:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case Jn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Er:this.AppendString(this.ConsumeString());break;case Tr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case yi: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 _i: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 Si: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 xi:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case kt: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 wi:this.char_index=this.characters.length;break;case At:case nt:case Ai:case Si:case xi:case Ci:this.date_pattern=!1;break;case Qn:case qn:case Kn:case eo:case to:case ro:case io:case no:case oo:case ao:this.AppendTextPart(this.ConsumeDatePart());break;case so:case lo:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Er:this.AppendString(this.ConsumeString());break;case Tr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case yi: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 _i: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 kt: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 we=c=>(c>=60&&c--,new Date(-22090752e5+864e5*c)),Ce=(c,e=!0)=>{if(e){let t=new Date(c);c=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()).getTime()}return c=(c+22090752e5)/864e5,c>=60&&c++,c},ie=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=Tt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new ke),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,o)=>{switch(n.flag){case 2:return r=o,n.text;case 1:return n.text.replace(/./g," ");case 6:return"";default:return n.text}});if(r>=0&&t){let n=i.reduce((a,s,l)=>l===r?a:a+s.length,0),o="";for(let a=0;a<t-n;a++)o+=i[r];i[r]=o}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(vr(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(s=>/[1-9]/.test(s.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 o=!!e.real;o&&(r=this.FormatParts(e.real),o=r.some(s=>/[1-9]/.test(s.text)));let a=[];if(o||!o&&!n){if(a.push(...r),n){a.push({text:e.imaginary<0?` ${c.minus_character} `:" + "});let s=i?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...s,{text:c.imaginary_character})}}else n&&a.push(...t,{text:c.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),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(N.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=we(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=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 s=o.text.split("/");return{text:t.getUTCHours()>12?s[1]:s[0]}}case"mmmmm":return{text:N.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:N.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:N.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:N.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:N.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:N.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:N.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:N.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:N.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 a=o.text.match(/^(s+)\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+N.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),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 o=2;o<=n;o++){let a=Math.round(e*o),s=Math.abs(a/o-e);if(s<r.error&&(r={numerator:a,denominator:o,error:s},!s))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,o=Math.abs(e);if(o<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(o/=t.scaling,o<n&&(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 s=a.split(".");for(;s[0].length<t.integer_min_digits;)s[0]=("0000000000000000"+s[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&s[0]==="0"&&(s[0]=""),t.grouping&&(s[0]=s[0].replace(c.grouping_regexp,"$&"+N.grouping_separator)),{parts:s,section:t}}};var z=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 ie(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 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}};z.InitCache();var ki=new Date().getUTCFullYear(),Ir=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(s=>s.trim()).filter(s=>!!s);if(!n.length)return t;if(!this.compare_month){this.compare_month={};for(let s=0;s<12;s++)this.compare_month[N.date_components.long_months[s].toLocaleLowerCase().replace(/\./,"")]=s,this.compare_month[N.date_components.short_months[s].toLocaleLowerCase().replace(/\./,"")]=s}if(!this.compare_day){this.compare_day={};for(let s=0;s<7;s++)this.compare_day[N.date_components.long_days[s].toLocaleLowerCase().replace(/\./,"")]=s,this.compare_day[N.date_components.short_days[s].toLocaleLowerCase().replace(/\./,"")]=s}let o=!1,a=!1;for(let s of n){let l=!1;for(let[d,h]of Object.entries(this.compare_month))if(s===d){if(o||r.getUTCMonth()!==h)return!1;l=!0,o=!0}if(!l){for(let[d,h]of Object.entries(this.compare_day))if(s===d){if(a||r.getUTCDay()!==h)return!1;l=!0,a=!0}}if(!l)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(),i=r.match(/^[$](.*?)$/);i&&(r=i[1],t.Currency=!0);let n=r.match(/^\((.*?)\)$/);n&&(r=n[1],t.Parens=!0);let o=r.match(/^(.*?)%\s*$/);o&&(r=o[1],t.Percent=!0),N.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 s=e.toLowerCase();if(s==="false")return{value:!1,type:4};if(s==="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>=ki-200&&h<=ki+200)return t={Date:!0},(d.getHours()||d.getMinutes()||d.getSeconds())&&(t.Time=!0),{value:Ce(l,!0),type:3,hints:t}}return{value:e,type:2}}if(n&&(a=-a),o){let s=a<0?-1:1,l=(s*a).toString().split(".");l[0]=("00"+l[0]).replace(/(\d\d)$/,".$1"),a=Number(l.join(""))*s}return/e/.test(e)&&(t.Exponential=!0),{value:a,type:3,hints:t}}},ce=new Ir;var Ti=()=>({target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0});var co=100,Ri={move_with_cells:!0,resize_with_cells:!0,movable:!0,resizable:!0,removable:!0,selectable:!0},Ne=class{data={...Ri};get key(){return this.key_}rect;scaled_rect;temp={};view=[];dirty;key_=co++;constructor(e={}){this.data={...Ri,...JSON.parse(JSON.stringify(e))},e.rect&&(this.rect=G.Create(e.rect))}toJSON(){return{...this.data,rect:this.rect}}};var ho=100,Ei=60,X=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 yt;selection=Ti();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=[];data_validation=[];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=ho,this.row_header_width=Ei,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),r.data_validation=(i.data_validations||[]).map(l=>({...l,target:(l.target||[]).map(d=>new y(d.start,d.end))})),i.id&&(r.id=i.id),i.name&&(r.name=i.name),i.background_image&&(r.background_image=i.background_image);let o=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)},a=i.styles||i.cell_style_refs||[];for(let l of a)o(l);if(r.cell_style=[],a&&(i.cell_styles||[]).forEach(l=>{typeof l.ref=="number"&&(l.style=JSON.parse(JSON.stringify(a[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(rt(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(a[l.style_ref])));else if(Cr(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(a[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(a[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 s=(l,d)=>{for(let h of Object.keys(l)){let u=Number(h),m=l[u];if(typeof m=="number"){let f=a[m];f&&(d[u]=JSON.parse(JSON.stringify(f)),o(d[u]))}else m&&(d[u]=m,o(d[u]))}};s(i.row_style,r.row_styles),s(i.column_style,r.column_styles),r.row_pattern=i.row_pattern||[],o(r.sheet_style||{});for(let l of r.row_pattern)o(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 Ne(l)),i.selection&&(r.selection=JSON.parse(JSON.stringify(i.selection))),r.visible=!0,typeof i.visible<"u"&&(r.visible=!!i.visible),r}AddValidation(e){this.data_validation.push({...e,target:(e.target||[]).map(t=>new y(t.start,t.end))})}RemoveValidations(e){let t=new y(e.start,e.end);this.data_validation=this.data_validation.filter(r=>(r.target=r.target.filter(i=>!t.Equals2(i)),r.target.length>0))}GetValidation(e){let t=[];for(let r of this.data_validation)for(let i of r.target)if(i.Contains(e)){t.push(r);break}return t}Activate(e){if(this.background_image){let t=wt(this.background_image);t&&(this._image=e.Create("img"),this._image.src=t)}}MergeCells(e){e=e.Clone();let t=[...this.cells.Iterate(e,!0)];for(let[r,i]of t.entries())i.merge_area=e,i.render_clean=[],r&&i.Reset()}UnmergeCells(e){for(let t of this.cells.Iterate(e,!1))if(!t.merge_area||!e.Equals(t.merge_area)){console.warn("area mismatch");return}for(let t of this.cells.Iterate(e,!1))t.merge_area=void 0,t.render_clean=[]}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=F.Composite([this.default_style_properties,this.sheet_style]);if(typeof window<"u"){let t=ye.MeasureText(F.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 o=e[n],a=t[n];typeof o=="object"&&typeof a=="object"?JSON.stringify(o)!==JSON.stringify(a)&&(r[n]=a):o!==a&&(r[n]=a)}return r}UpdateCellStyle(e,t,r=!0){let{row:i,column:n}=e;this.cell_style[n]||(this.cell_style[n]=[]);let o=this.CompositeStyleForCell(e,!1,!1,void 0,!1),a=F.Composite([this.default_style_properties,o,F.Merge(this.cell_style[n][i]||{},t,r)]),s=this.Delta(o,a);this.cell_style[n][i]=s,this.BleedFlush({start:e,end:e})}Invalidate(e){for(let t of this.cells.Iterate(this.RealArea(e),!1))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 for(let i of e)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 o=e.area.end.row;for(;o>=e.area.start.row;o--)if(this.GetRowHeight(o)){r.last=o===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,o=e.row+1,a=e.row-1;for(;this.column_width_[i]===0;i++);for(;this.row_height_[o]===0;o++);for(;n>=0&&this.column_width_[n]===0;n--);for(;a>=0&&this.row_height_[a]===0;a--);return n>=0&&a>=0&&(r[7]=this.CellStyleData({row:a,column:n},t)||{}),n>=0&&(r[4]=this.CellStyleData({row:e.row,column:n},t)||{},r[1]=this.CellStyleData({row:o,column:n},t)||{}),a>=0&&(r[8]=this.CellStyleData({row:a,column:e.column},t)||{},r[9]=this.CellStyleData({row:a,column:i},t)||{}),r[6]=this.CellStyleData({row:e.row,column:i},t)||{},r[2]=this.CellStyleData({row:o,column:e.column},t)||{},r[3]=this.CellStyleData({row:o,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)),o=this.TableRow(r.table,e.row);return o.header?i.header&&(n=F.Composite([n,i.header])):o.totals?i.total&&(n=F.Composite([n,i.total])):o.alternate?i.odd&&(n=F.Composite([n,i.odd])):i.even&&(n=F.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 o=z.Get(t.style.number_format||"",!0);t.formatted=o.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=z.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=z.Get(t).FormatParts(e);return r.length?r.length===1&&!r[0].flag?r[0].text||"":r:""}SetHeaderSize(e=Ei,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 o=0;o<this.cells.columns;o++){let a=this.CellData({row:e,column:o}),s=a.style,l=a.formatted||"";if(typeof l!="string"&&(l=l.map(d=>d.text).join("")),s&&l&&l.length){let d=l.split(/\n/),h=Math.round(this.StyleFontSize(s,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 s=0;s<this.cells.columns;s++){let l=this.cells.GetCell({row:e-1,column:s},!1);if(l&&l.area){let d=this.cells.GetCell({row:e,column:s},!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 s=e;s<this.cells.rows;s++)for(let l=0;l<this.cells.columns;l++){let d=this.cells.GetCell({row:s,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 s of Object.keys(i)){let l=i[s],d=new y({row:l.start.row+t,column:l.start.column},{row:l.end.row+t,column:l.end.column});for(let h of d){let u=this.cells.GetCell(h,!0);u.area=d}}for(let s of Object.keys(r)){let l=r[s],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});for(let u of h){let m=this.cells.GetCell(u,!0);m.merge_area=h}}let n=Object.keys(this.row_styles),o={};n.forEach(s=>{let l=Number(s);l<e?o[l]=this.row_styles[l]:t<0&&l<e-t||(o[l+t]=this.row_styles[l])}),this.row_styles=o;let a=[];if(t<0)a=[e,-t];else{a=[e,0];for(let s=0;s<t;s++)a.push(void 0)}return this.cell_style.forEach(s=>{s&&s.length>=e&&s.splice.apply(s,a)}),this.row_height_.splice.apply(this.row_height_,a),this.FlushCellStyles(),!0}InsertColumns(e=0,t=1){if(e)for(let s=0;s<this.cells.rows;s++){let l=this.cells.GetCell({row:s,column:e-1},!1);if(l&&l.area){let d=this.cells.GetCell({row:s,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 s=e;s<this.cells.columns;s++)for(let l=0;l<this.cells.rows;l++){let d=this.cells.GetCell({row:l,column:s},!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 s of Object.keys(i)){let l=i[s],d=new y({row:l.start.row,column:l.start.column+t},{row:l.end.row,column:l.end.column+t});for(let h of d){let u=this.cells.GetCell(h,!0);u.area=d}}for(let s of Object.keys(r)){let l=r[s],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});for(let u of h){let m=this.cells.GetCell(u,!0);m.merge_area=h}}let n=Object.keys(this.column_styles),o={};n.forEach(s=>{let l=Number(s);l<e?o[l]=this.column_styles[l]:t<0&&l<e-t||(o[l+t]=this.column_styles[l])}),this.column_styles=o;let a=[];if(t<0)a=[e,-t];else{a=[e,0];for(let s=0;s<t;s++)a.push(void 0)}return this.cell_style.splice.apply(this.cell_style,a),this.column_width_.splice.apply(this.column_width_,a),this.FlushCellStyles(),!0}ClearArea(e){for(let t of this.cells.Iterate(this.RealArea(e),!1))t.Reset()}SetAreaValues2(e,t){e=this.RealArea(e),this.cells.SetArea(e,t)}SetArrayValue(e,t){e=this.RealArea(e);for(let i of this.cells.Iterate(e,!0))i.SetArray(e);this.cells.GetCell(e.start,!0).SetArrayHead(e,t)}SetCellValue(e,t){this.cells.GetCell(e,!0).Set(t)}TablesFromArea(e,t=!1){if(V(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 o=this.cells.GetCell({row:i,column:n},!1);o?.table&&!r.has(o.table)&&(!t||i===o.table.area.start.row)&&r.add(o.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(V(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 o=e.start.column;o<=e.end.column;o++)n.push(this.CompositeStyleForCell({row:i,column:o},!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 o=e.column;o<=t.column;o++)n.push(this.FormattedCellValue({row:i,column:o}));r.push(n)}return r}NumberFormatsAndColors(e,t){let r=i=>{i.number_format&&(t[i.number_format]=1),J(i.text)&&(e[i.text.text]=1),J(i.fill)&&(e[i.fill.text]=1),J(i.border_top_fill)&&(e[i.border_top_fill.text]=1),J(i.border_left_fill)&&(e[i.border_left_fill.text]=1),J(i.border_right_fill)&&(e[i.border_right_fill.text]=1),J(i.border_bottom_fill)&&(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 o=i[n];if(o){let a=n+1;for(;a<i.length&&i[a]===o;a++);a>n+1?t.push({row:n,column:r,ref:o,rows:a-n}):t.push({row:n,column:r,ref:o}),n=a-1}}}return t}toJSON(e={}){let t=(w,A)=>{let S={};for(let I=0;I<w.length;I++)typeof w[I]<"u"&&w[I]!==A&&(S[I]=w[I]);if(Object.keys(S).length)return S},r=[{}],i={},n=[],o=JSON.stringify({});for(let w=0;w<this.cell_style.length;w++){let A=this.cell_style[w];if(A){n[w]=[];for(let S=0;S<A.length;S++)if(A[S]){let I=JSON.stringify(A[S]);if(I!==o){let L=i[I];typeof L!="number"&&(i[I]=L=r.length,r.push(A[S])),n[w][S]=L}}}}let a=w=>{let A=JSON.stringify(w);if(A===o)return 0;let S=i[A];return typeof S!="number"&&(i[A]=S=r.length,r.push(w)),S};r=JSON.parse(JSON.stringify(r));let s=JSON.parse(JSON.stringify(this.sheet_style)),l=JSON.parse(JSON.stringify(this.row_pattern)),d={},h={};for(let w of Object.keys(this.column_styles)){let A=Number(w),S=this.column_styles[A];if(S){let I=a(S);I&&(d[A]=I)}}for(let w of Object.keys(this.row_styles)){let A=Number(w),S=this.row_styles[A];if(S){let I=a(S);I&&(h[A]=I)}}let u=(w={},A={})=>{let S={...A,...w};if(J(S))return S.text=ye.MeasureColorARGB(S.text),S;if(Ze(S))return S};if(e.export_colors){let w=[];for(let A of[r,[s],l])if(Array.isArray(A))for(let S of A)w.push(S);else for(let S of Object.keys(A))w.push(A[S]);for(let A of w){let S=u(A.border_top_fill,F.DefaultProperties.border_top_fill);S!==void 0&&(A.border_top_fill=S),S=u(A.border_left_fill,F.DefaultProperties.border_left_fill),S!==void 0&&(A.border_left_fill=S),S=u(A.border_right_fill,F.DefaultProperties.border_right_fill),S!==void 0&&(A.border_right_fill=S),S=u(A.border_bottom_fill,F.DefaultProperties.border_bottom_fill),S!==void 0&&(A.border_bottom_fill=S),J(A.fill)&&(A.fill.text=ye.MeasureColorARGB(A.fill.text)),J(A.text)&&(A.text.text=ye.MeasureColorARGB(A.text.text))}}let m={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},f=this.cells.toJSON(m),p=f.data,{rows:b,columns:g}=f;e.shrink?(b+=2,g+=1):(b=this.rows,g=this.columns);for(let w of this.annotations)w.data.extent||this.CalculateAnnotationExtent(w),w.data.extent&&(b=Math.max(b,w.data.extent.row+1),g=Math.max(g,w.data.extent.column+1));let C=this.CompressCellStyles(n),x=this.conditional_formats.length?JSON.parse(JSON.stringify(this.conditional_formats.map(w=>({...w,internal:void 0})))):void 0,v=this.data_validation.length?JSON.parse(JSON.stringify(this.data_validation)):void 0,_={id:this.id,name:this.name,data:p,sheet_style:s,rows:b,columns:g,cell_styles:C,styles:r,row_style:h,column_style:d,conditional_formats:x,data_validations:v,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||(_.visible=this.visible),(this.scroll_offset.x||this.scroll_offset.y)&&(_.scroll=this.scroll_offset),this.background_image&&(_.background_image=this.background_image),(this.freeze.rows||this.freeze.columns)&&(_.freeze=this.freeze),_}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 o=0;o<i.length;o++)i[o]&&this.UpdateAreaStyle(new y({row:1/0,column:o},{row:1/0,column:o}),t[i[o]]);if(e.row_styles)for(let[o,a]of e.row_styles.entries())a&&this.UpdateAreaStyle(new y({row:o,column:1/0}),t[a]);this.cells.FromJSON(e.cells),e.name&&(this.name=e.name||"");let n=this.cell_style;for(let o of e.cells)o.style_ref&&(n[o.column]||(n[o.column]=[]),n[o.column][o.row]=t[o.style_ref]);for(let o=0;o<e.column_widths.length;o++)typeof e.column_widths[o]<"u"&&this.SetColumnWidth(o,e.column_widths[o]);for(let o=0;o<e.row_heights.length;o++)typeof e.row_heights[o]<"u"&&this.SetRowHeight(o,e.row_heights[o]);for(let o of e.annotations||[])this.annotations.push(new Ne(o));for(let o of e.conditional_formats||[])this.conditional_formats.push(o);for(let o of e.data_validations||[])this.AddValidation(o);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=F.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(o=>delete n[o]);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]=F.Merge(this.row_styles[e]||{},t,r);let i=Object.keys(t);for(let n of this.cell_style)n&&n[e]&&i.forEach(o=>delete n[e][o]);for(let n=0;n<this.cells.columns;n++)if(this.column_styles[n]){let o=this.column_styles[n],a=this.cell_style[n]?this.cell_style[n][e]||{}:{};for(let s of i)typeof o[s]<"u"&&(a[s]=t[s]);Object.keys(a).length&&(this.cell_style[n]||(this.cell_style[n]=[]),this.cell_style[n][e]=JSON.parse(JSON.stringify(a)))}for(let n of this.cells.Iterate(this.RealArea(y.FromRow(e))))n.FlushStyle()}UpdateColumnStyle(e,t,r=!0){this.column_styles[e]=F.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(o=>delete n[o]);for(let n of this.cells.Iterate(this.RealArea(y.FromColumn(e))))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){i.internal?.vertex?.updated&&(i.internal.vertex.updated=!1);let n=JSON.parse(JSON.stringify(i.area));(n.start.row===null||n.end.row===null)&&(n.start.row=0,n.end.row=this.cells.rows-1),(n.start.column===null||n.end.column===null)&&(n.start.column=0,n.end.column=this.cells.columns-1);let o=i.internal?.vertex?.result;if(i.type==="gradient"){if(o&&i.internal?.gradient){let a=i.property??"fill";if(o.type===8)for(let s=n.start.row;s<=n.end.row;s++)for(let l=n.start.column;l<=n.end.column;l++){let d=o.value[l-n.start.column][s-n.start.row];if(d.type===3){t[s]||(t[s]=[]),t[s][l]||(t[s][l]=[]);let h=i.internal.gradient.Interpolate(d.value);t[s][l].push({[a]:h})}}else if(o.type===3){let s=i.internal.gradient.Interpolate(o.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({[a]:s})}}r.push(n),this.conditional_format_checklist.push(n)}}else if(o){if(o.type===8)for(let a=n.start.row;a<=n.end.row;a++)for(let s=n.start.column;s<=n.end.column;s++){let l=o.value[s-n.start.column][a-n.start.row];l&&(l.type===4||l.type===3)&&l.value&&(t[a]||(t[a]=[]),t[a][s]||(t[a][s]=[]),t[a][s].push(i.style))}else if((o.type===4||o.type===3)&&o.value)for(let a=n.start.row;a<=n.end.row;a++){t[a]||(t[a]=[]);for(let s=n.start.column;s<=n.end.column;s++)t[a][s]||(t[a][s]=[]),t[a][s].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:o,column:a}=e,s=[];return i&&s.push(this.default_style_properties),s.push(this.sheet_style),r&&this.row_pattern.length&&s.push(this.row_pattern[o%this.row_pattern.length]),this.row_styles[o]&&s.push(this.row_styles[o]),this.column_styles[a]&&s.push(this.column_styles[a]),t&&this.cell_style[a]&&this.cell_style[a][o]&&s.push(this.cell_style[a][o]),n&&s.push(...this.ConditionalFormatForCell(e)),F.Composite(s)}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 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 Rt=class{constructor(e,t,r={x:0,y:0},i){this.theme=t;this.offset=r;let n=P.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 Ue=class{constructor(e,t,r){this.theme=e;this.container=t;this.orientation=r;let i=P.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 Et=class{constructor(e,t,r,i,n,o){this.theme=e;this.layout=t;this.model=r;this.view=i;this.primary_selection=n;this.additional_selections=o}nub_rectangle=new G(-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 Ue(this.theme,this.layout.row_header_selection,0),this.column_overlay=new Ue(this.theme,this.layout.column_header_selection,1),this.corner_row_overlay=new Ue(this.theme,this.layout.corner_selection,0),this.corner_column_overlay=new Ue(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 G(-1,-1,0,0);if(!this.primary_selection.empty){let s=this.view.active_sheet.RealArea(this.primary_selection.area);n=this.layout.CellAddressToRectangle(s.start).Combine(this.layout.CellAddressToRectangle(s.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 o=[],a=[];if(this.primary_selection.empty)o.push(!1),a.push(!1);else{let s=this.primary_selection.area.start;o.push(s.row<=this.view.active_sheet.freeze.rows||s.row===1/0),a.push(s.column<=this.view.active_sheet.freeze.columns||s.column===1/0)}for(let{area:s}of this.additional_selections)o.push(s.start.row<=this.view.active_sheet.freeze.rows||s.start.row===1/0),a.push(s.start.column<=this.view.active_sheet.freeze.columns||s.start.column===1/0);this.view.active_sheet.freeze.rows&&this.RenderSelectionGroup(i,this.layout.row_header_selection,o,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,a,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,a,o,this.corner_selections,{...this.layout.header_offset}),this.primary_selection.empty=r}RenderSelectionGroup(e,t,r,i,n,o,a=!0){for(let s=0;s<e.length;s++)if((!e[s].area.start.sheet_id||e[s].area.start.sheet_id===this.view.active_sheet.id)&&!e[s].empty&&(!r||r[s])&&(!i||i[s])){if(a||!e[s].rendered){let d=this.EnsureGridSelectionBlock(t,n,s,o);this.RenderSVGSelection(e[s],d,s)}}else n[s]&&n[s].Show(!1);for(let s=e.length;s<n.length;s++)n[s]&&n[s].Show(!1)}EnsureGridSelectionBlock(e,t,r,i){let n=t[r];if(!n)if(n=new Rt(!r,this.theme,void 0,e),t[r]=n,r){let o=e.querySelector(".alternate-selections");o||(o=this.layout.DOM.SVG("g","alternate-selections"),e.appendChild(o)),o?.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 o=this.view.active_sheet.CellData(e.target);o.merge_area&&(n=this.layout.CellAddressToRectangle(o.merge_area.start),n=n.Combine(this.layout.CellAddressToRectangle(o.merge_area.end)))}if(r||(this.nub_rectangle=new G(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 o=this.layout.CellAddressToRectangle(e.target),a=this.view.active_sheet.CellData(e.target);a.merge_area&&(o=this.layout.CellAddressToRectangle(a.merge_area.start),o=o.Combine(this.layout.CellAddressToRectangle(a.merge_area.end))),t.SetFill(o,n),t.SetNub(n)}t.Show()}};function ve(c,e=[],t,r){typeof e=="string"&&(e=[e]);let i,n=a=>{a.stopPropagation(),a.preventDefault(),i(),r&&r(a)},o=a=>{if(a.stopPropagation(),a.preventDefault(),!a.buttons){i(),r&&r(a);return}t&&t(a)};i=()=>{c.style.display="none",c.removeEventListener("mousemove",o),c.removeEventListener("mouseup",n);for(let a of e)c.classList.remove(a)};for(let a of e)c.classList.add(a);c.style.display="block",t&&c.addEventListener("mousemove",o),r&&c.addEventListener("mouseup",n)}var Mt=class extends le{constructor(t){super();this.container=t;this.format=z.Get("0.0");let r=P.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 o=ce.TryParse(n);o.type===3?this.UpdateScale(Number(o.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 It=class extends le{constructor(t,r,i,n,o){super();this.layout=t;this.model=r;this.view=i;this.options=n;if(this.DOM=P.GetInstance(o.ownerDocument),this.container=o.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",a=>{let s=a.target?.dataset.command;if(s)switch(a.stopPropagation(),a.preventDefault(),s){case"add-tab":this.Publish({type:"add-sheet"});break;case"delete-tab":this.Publish({type:"delete-sheet"});break;default:console.info("unhandled command",s)}}),this.options.stats&&(this.stats_panel=this.container.querySelector(".treb-stats-panel")),this.options.scale_control){let a=this.container.querySelector(".treb-scale-control");this.scale_control=new Mt(a),this.scale_control.Subscribe(s=>{this.Publish(s)}),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 o=this.DOM.doc.createRange();o.selectNodeContents(r),n.addRange(o)}}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,o){if(t.stopPropagation(),t.preventDefault(),this.IsDoubleClick(n))return;this.Publish({type:"activate-sheet",sheet:i});let a=o.map(p=>p.getBoundingClientRect()),s=n*2-1,l=a[0].left,d=a[a.length-1].right,h=a[0].top,u=a[0].bottom,m=-1,f=(a.length-1)*2+1;for(let p of o)this.SetActive(p,p===r);this.dragging=!0,ve(this.layout.mask,[],p=>{let[b,g]=[p.clientX,p.clientY];if(g>h&&g<u){let C=s;if(b<l)C=m;else if(b>d)C=f;else for(let x=0;x<a.length;x++){let v=a[x];if(b>=v.left&&b<=v.right){x!==n&&(b>=v.left+v.width/2?C=x*2+1:C=x*2-1);break}}C!==s&&(s=C,r.style.order=s.toString(),a=o.map(x=>x.getBoundingClientRect()))}},()=>{let p=n,b=(s+1)/2;this.dragging=!1;for(let g=0;g<this.model.sheets.length;g++)this.model.sheets.list[g].visible||(p>=g&&p++,b>=g&&b++);p===b||p===0&&b<=0||p===o.length-1&&b>=o.length-1||this.Publish({type:"reorder-sheet",index:p,move_before:b})})}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 o=s=>this.MouseDownTab(s,n,r,i,t),a=s=>{n.removeEventListener("mousedown",o),n.removeEventListener("dblclick",a),this.DoubleClickTab(s,n,r)};n.textContent=r.name,n.addEventListener("dblclick",a),n.addEventListener("mousedown",o),this.tab_container.appendChild(n),t.push(n)}}};var Be=class{constructor(e,t,r=!1,i=P.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",o=>{o.stopPropagation(),o.preventDefault(),this.grid_cover.classList.remove("nub-select");let a=this.dropdown_caret.getAttribute("class")||"";/active/i.test(a)?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",o=>{let a=0;switch(o.key){case"ArrowDown":a=1;break;case"ArrowUp":a=-1;break;case"Escape":break;case"Enter":break;default:console.info(o.key);return}if(o.stopPropagation(),o.preventDefault(),o.key==="Escape"||o.key==="Enter"){if(this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),o.key==="Enter"&&this.dropdown_callback&&this.dropdown_selected){let s=this.dropdown_selected.dataset.dropdown_value;this.dropdown_callback.call(0,s?JSON.parse(s):void 0)}}else if(a&&this.dropdown_selected)if(a>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 s=this.dropdown_selected.offsetTop+this.dropdown_selected.offsetHeight;s>this.dropdown_list.offsetHeight+this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=s-this.dropdown_list.offsetHeight)}else a<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",o=>{let a=o.target;if(o.target!==this.dropdown_list&&(o.stopPropagation(),o.preventDefault(),this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_callback)){let s=a.dataset.dropdown_value;this.dropdown_callback.call(0,s?JSON.parse(s):void 0)}}),this.dropdown_list.addEventListener("mousemove",o=>{let a=o.target;a!==this.dropdown_selected&&(this.grid_cover.classList.remove("nub-select"),this.dropdown_selected&&this.dropdown_selected.classList.remove("selected"),a.classList.add("selected"),this.dropdown_selected=a)}),this.mock_selection=i.Div("mock-selection-node",void 0,{html:"&nbsp;"}),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 o=this.OffsetCellAddressToRectangle(r).Shift(this.header_size.width,this.header_size.height),a=this.sort_button.getBoundingClientRect();this.sort_button.style.left=o.right-a.width-a.width/2+"px",this.sort_button.style.top=o.top+(o.height-a.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(),o=this.note_node.parentElement.getBoundingClientRect(),a={x:8,y:2},s=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.note_node.style.left=o.left+s.right-this.scroll_reference_node.scrollLeft+a.x+"px",this.note_node.style.top=o.top+s.top-this.scroll_reference_node.scrollTop-n.height/5-a.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 o=this.view.active_sheet.annotations[n].key,a=this.container?.querySelectorAll(`.annotation[data-key="${o}"]`);if(a)for(let s=0;s<a?.length;s++)a[s].style.zIndex=(n+1).toString()}return!0}PointToAnnotationCorner(e){let t=this.PointToAddress_Grid(e,!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 G(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"),o=r.querySelector(".annotation-resize-target");r.addEventListener("mousedown",a=>{let s=i.node;requestAnimationFrame(()=>{s?.focus()}),this.AnnotationMouseDown(e,i.node,a,n,o)}),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 o=e.scaled_rect;return o?new Promise(a=>{let s={left:o.left,top:o.top,width:o.width,height:o.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-o.left,y:h.top+r.offsetY-o.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);ve(this.mask,"move",b=>{if(b.offsetY-d.top<this.header_offset.y){let g=Math.min(f,l.scrollTop);l.scrollTop-=g,u.y+=g}else if(b.offsetY-d.top>=d.height&&l.scrollTop+d.height<p.height){let g=f;l.scrollTop+=g,u.y-=g}if(b.offsetX-d.left<this.header_offset.x){let g=Math.min(f,l.scrollLeft);l.scrollLeft-=g,u.x+=g}else if(b.offsetX-d.left>=d.width&&l.scrollLeft+d.width<p.width){let g=f;l.scrollLeft+=g,u.x-=g}if(o.top=b.offsetY-u.y,o.left=b.offsetX-u.x,b.shiftKey){let g=Math.abs(o.left-s.left),C=Math.abs(o.top-s.top);g<=C?o.left=s.left:o.top=s.top}if(b.ctrlKey){let g=this.ClampToGrid({x:o.left,y:o.top});o.left=g.x,o.top=g.y}for(let g of m)g.style.top=o.top+"px",g.style.left=o.left+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(o),a({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-o.width+n.offsetLeft,y:m.top+r.offsetY-o.height+n.offsetTop};ve(this.mask,"nw-resize",p=>{let b=[t,...this.GetFrozenAnnotations(e)];if(o.height=p.offsetY-f.y,o.width=p.offsetX-f.x,p.shiftKey&&p.ctrlKey){if(u){let g=Math.abs(o.width-s.width),C=Math.abs(o.height-s.height);g<C?o.width=u*o.height:o.height=o.width/u}}else if(p.shiftKey){let g=Math.abs(o.height-s.height),C=Math.abs(o.width-s.width);g>C?o.width=s.width:o.height=s.height}else if(p.ctrlKey){let g=this.ClampToGrid({x:o.right,y:o.bottom});o.width=g.x-o.left+1,o.height=g.y-o.top+1}for(let g of b)g.style.height=o.height+"px",g.style.width=o.width+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(o),a({type:"annotation",annotation:e,event:"resize"})});return}else a()}):(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,o,a,s=!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=o,l.pixel_end={x:o.x+t.width,y:o.y+t.height},l.dirty=!!s,l.needs_full_repaint=!0,a.appendChild(l),l}ApplyTheme(e){this.row_header.style.backgroundColor=this.column_header.style.backgroundColor=this.corner.style.backgroundColor=e.headers?.fill?R(e,e.headers.fill,0):"",this.corner.style.borderColor=e.grid_color||"";for(let t of this.grid_tiles)for(let r of t)r.style.backgroundColor=R(e,e.grid_cell?.fill,0)||"#fff";this.dropdown_list.style.font=F.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.style.fontSize=this.scale.toFixed(2)+"em",this.dropdown_list.textContent="";for(let o of t){let a=this.DOM.Div(void 0,this.dropdown_list);r===o&&(this.dropdown_selected=a,a.classList.add("selected")),a.dataset.dropdown_value=JSON.stringify(o),a.textContent=o?.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 o={left:this.scroll_reference_node.scrollLeft,top:this.scroll_reference_node.scrollTop},a={left:t?n.left:o.left,top:r?n.top:o.top,behavior:"smooth"};this.scroll_reference_node.scrollTo(a)}else r&&(this.scroll_reference_node.scrollTop=n.top),t&&(this.scroll_reference_node.scrollLeft=n.left)}ScrollIntoView(e,t=!1){let r=this.CellAddressToRectangle(e),i=this.scroll_reference_node.clientWidth-this.row_header.offsetWidth,n=this.scroll_reference_node.clientHeight-this.column_header.offsetHeight,o={x:0,y:0},a={x:!1,y:!1},s=new G(this.scroll_reference_node.scrollLeft,this.scroll_reference_node.scrollTop,i,n);(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?o.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?o.x=this.frozen_column_tiles[0].logical_size.width:this.view.active_sheet.freeze.columns&&(a.x=!0));let l={behavior:t?"smooth":"auto"};e.row!==1/0&&(r.top<s.top+o.y&&!a.y?l.top=r.top-o.y:r.bottom>s.bottom&&(l.top=r.bottom-n)),e.column!==1/0&&(r.left<s.left+o.x&&!a.x?l.left=r.left-o.x:r.right>s.right&&(l.left=r.right-i)),this.scroll_reference_node.scrollTo(l)}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=!0){if(t){if(this.view.active_sheet.freeze.rows){let o=this.frozen_row_tiles[0].logical_size.height;e.y-this.scroll_reference_node.scrollTop<o&&(e.y-=this.scroll_reference_node.scrollTop)}if(this.view.active_sheet.freeze.columns){let o=this.frozen_column_tiles[0].logical_size.width;e.x-this.scroll_reference_node.scrollLeft<o&&(e.x-=this.scroll_reference_node.scrollLeft)}}let r={row:0,column:0},i=this.grid_tiles[this.grid_tiles.length-1],n=i[i.length-1];if(e.y>n.pixel_end.y){let o=e.y-n.pixel_end.y;for(r.row=n.last_cell.row;o>0;)r.row++,o-=this.default_row_height}else for(let o of i)if(o.pixel_start.y<=e.y&&o.pixel_end.y>=e.y){let a=e.y-o.pixel_start.y,s=0;for(r.row=o.first_cell.row;r.row<=o.last_cell.row&&(s=this.RowHeight(r.row),!(s>a));r.row++,a-=s);break}if(e.x>n.pixel_end.x){let o=e.x-n.pixel_end.x;for(r.column=n.last_cell.column;o>0;)r.column++,o-=this.default_column_width}else for(let o of this.grid_tiles)if(o[0].pixel_start.x<=e.x&&o[0].pixel_end.x>=e.x){let a=o[0],s=e.x-a.pixel_start.x,l=0;for(r.column=a.first_cell.column;r.column<=a.last_cell.column&&(l=this.ColumnWidth(r.column),!(l>s));r.column++,s-=l);break}return r}AdjacentTile(e,t=0,r=0){if(!t&&!r)return e;let i=e.tile_position,n=e.tile_position.row+t,o=e.tile_position.column+r;if(!(n<0||o<0)){if(this.grid_tiles[i.column]&&this.grid_tiles[i.column][i.row]===e&&this.grid_tiles[o])return this.grid_tiles[o][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[o]}}UpdateTiles(){if(!this.container)throw new Error("invalid container");this.grid_tiles.forEach(v=>{v.forEach(_=>{_.parentElement&&_.parentElement.removeChild(_)})});for(let v of[this.column_header_tiles,this.row_header_tiles,this.frozen_row_tiles,this.frozen_column_tiles])for(let _ of v)_.parentElement&&_.parentElement.removeChild(_);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 v=0;v<t;v++)i+=this.RowHeight(v);for(let v=0;v<r;v++)n+=this.ColumnWidth(v);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 v=Math.ceil((this.container.offsetWidth-n)/this.default_column_width);n+=v*this.default_column_width,r+=v}if(this.last_column=r,this.container.clientHeight>i+this.header_size.height){let v=Math.ceil((this.container.offsetHeight-i)/this.default_row_height);i+=v*this.default_row_height,t+=v}this.column_header.style.width=this.contents.style.width=`${n}px`,this.row_header.style.height=this.contents.style.height=`${i}px`;let o=[],a=[],s=0,l=0;for(let v=0;v<r;v++){let _=this.ColumnWidth(v);s&&s+_>this.default_tile_size.width&&(o.push(s),a.push(l),l=v,s=0),s+=_}o.push(s),a.push(l);let d=[],h=[],u=0,m=0;for(let v=0;v<t;v++){let _=this.RowHeight(v);u&&u+_>this.default_tile_size.height&&(d.push(u),h.push(m),u=0,m=v),u+=_}d.push(u),h.push(m);let f=o.length,p=d.length,b=0,g=0,C=0,x=0;for(let v=0;v<this.view.active_sheet.freeze.rows;v++)C+=this.RowHeight(v);for(let v=0;v<this.view.active_sheet.freeze.columns;v++)x+=this.ColumnWidth(v);for(let v=0;v<f;v++){let _=[];b=0;let w=v===f-1?r-a[v]:a[v+1]-a[v];this.column_header_tiles.push(this.CreateTile("column-header-tile",{height:this.header_offset.y,width:o[v]},{row:0,column:v},{row:0,column:a[v]},{rows:0,columns:w},{x:g,y:0},this.column_header)),this.view.active_sheet.freeze.rows&&this.frozen_row_tiles.push(this.CreateTile("frozen-row-tile",{height:C,width:o[v]},{row:1,column:v},{row:0,column:a[v]},{rows:0,columns:w},{x:g,y:0},this.column_header));for(let A=0;A<p;A++){let S=A===p-1?t-h[A]:h[A+1]-h[A];v||(this.row_header_tiles.push(this.CreateTile("row-header-tile",{height:d[A],width:this.header_offset.x},{row:A,column:0},{row:h[A],column:0},{rows:S,columns:1},{x:0,y:b},this.row_header)),this.view.active_sheet.freeze.columns&&this.frozen_column_tiles.push(this.CreateTile("frozen-column-tile",{height:d[A],width:x},{row:A,column:1},{row:h[A],column:0},{rows:S,columns:1},{x:0,y:b},this.row_header))),_.push(this.CreateTile("grid-tile",{height:d[A],width:o[v]},{row:A,column:v},{row:h[A],column:a[v]},{rows:S,columns:w},{x:g,y:b},this.contents)),b+=d[A]}this.grid_tiles.push(_),g+=o[v]}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 o=r.row;o<=i.row;o++)this.grid_tiles[n][o].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 o of this.grid_tiles){let a=o[0];if(a.pixel_start.x<=t&&a.pixel_end.x>=t){for(a of o)if(a.pixel_start.y<=i&&a.pixel_end.y>=i){e[0]=a.tile_position;break}}if(o===this.grid_tiles[this.grid_tiles.length-1]||a.pixel_start.x<=r&&a.pixel_end.x>=r){for(a of o)if(a===o[o.length-1]||a.pixel_start.y<=n&&a.pixel_end.y>=n)return e[1]=a.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 o=0;for(let s=n.first_cell.row;s<=n.last_cell.row;s++)o+=this.RowHeight(s);let a=n.logical_size.height===o;if(n.pixel_start.y=r,r+=o,n.pixel_end.y=r,!a){if(n.logical_size.height=o,n.style.height=`${o}px`,n.height=this.dpr*o,this.view.active_sheet.freeze.columns){let s=this.frozen_column_tiles[i];s.logical_size.height=o,s.style.height=`${o}px`,s.height=this.dpr*o}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let s of this.grid_tiles){let l=s[i];l.pixel_start.y=n.pixel_start.y,l.pixel_end.y=n.pixel_end.y,a||(l.logical_size.height=o,l.style.height=`${o}px`,l.height=this.dpr*o,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],o=this.grid_tiles[i];if(t>n.last_cell.column){r+=n.logical_size.width;continue}let a=0;for(let l=n.first_cell.column;l<=n.last_cell.column;l++)a+=this.ColumnWidth(l);let s=n.logical_size.width===a;if(n.pixel_start.x=r,r+=a,n.pixel_end.x=r,!s){if(n.logical_size.width=a,n.style.width=`${a}px`,n.width=this.dpr*a,this.view.active_sheet.freeze.rows){let l=this.frozen_row_tiles[i];l.logical_size.width=a,l.style.width=`${a}px`,l.width=this.dpr*a}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let l of o)l.pixel_start.x=n.pixel_start.x,l.pixel_end.x=n.pixel_end.x,s||(l.logical_size.width=a,l.style.width=`${a}px`,l.width=this.dpr*a,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 o=this.column_cache.length-1;o<=r;o++)this.column_cache[o+1]=this.column_cache[o]+this.ColumnWidth(o)}if(this.row_cache.length<=t+1){this.row_cache.length||(this.row_cache[0]=0);for(let o=this.row_cache.length-1;o<=t;o++)this.row_cache[o+1]=this.row_cache[o]+this.RowHeight(o)}let i=this.column_cache[r],n=this.row_cache[t];return new G(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 a=e+1;a<this.column_header_tiles.length;a++){this.column_header_tiles[a].pixel_start.x+=n,this.column_header_tiles[a].pixel_end.x+=n;for(let s of this.grid_tiles[a])s.pixel_start.x+=n,s.pixel_end.x+=n}let o=this.grid_tiles[e];for(i of o)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 o=e+1;o<this.row_header_tiles.length;o++)i=this.row_header_tiles[o],i.pixel_start.y+=n,i.pixel_end.y+=n;for(let o of this.grid_tiles){i=o[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 a=e+1;a<o.length;a++)o[a].pixel_start.y+=n,o[a].pixel_end.y+=n}this.UpdateTotalSize(),this.UpdateGridTemplates(!1,!0),this.UpdateContentsSize()}};var zt=class extends Be{constructor(e,t){super(e,t,!0)}InitializeInternal(){}UpdateGridTemplates(){}UpdateTileGridPosition(){}UpdateContainingGrid(){}ResizeCursor(){}};var Nt=class extends Be{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(){let e=0,t=0;this.column_header.style.gridTemplateColumns=this.contents.style.gridTemplateColumns=this.column_header_tiles.map(a=>(e+=a.logical_size.width,`${a.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(a=>(t+=a.logical_size.height,`${a.logical_size.height}px`)).join(" ");let r=this.header_offset.y;if(this.view.active_sheet.freeze.rows)for(let a=0;a<this.view.active_sheet.freeze.rows;a++)r+=this.RowHeight(a);this.column_header.style.height=`${r}px`,this.row_header_selection.style.display="block",this.row_header_selection.style.width=`${e}px`,this.corner_selection.style.height=this.row_header_selection.style.height=`${r}px`,this.corner_selection.style.top=this.row_header_selection.style.top="0px",this.row_header_selection.style.left="0px";let i=this.header_offset.x;if(this.view.active_sheet.freeze.columns)for(let a=0;a<this.view.active_sheet.freeze.columns;a++)i+=this.ColumnWidth(a);this.column_header_selection.style.display="block",this.corner_selection.style.width=this.column_header_selection.style.width=`${i}px`,this.column_header_selection.style.height=`${t}px`,this.column_header_selection.style.top="0px",this.corner_selection.style.left=this.column_header_selection.style.left="0px";let n={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=`${e}px`,this.corner_annotations.style.height=this.row_header_annotations.style.height=`${r-n.y}px`,this.corner_annotations.style.top=this.row_header_annotations.style.top=`${n.y}px`,this.column_header_annotations.style.width=this.corner_annotations.style.width=`${i-n.x}px`,this.column_header_annotations.style.height=`${t}px`,this.corner_annotations.style.left=this.column_header_annotations.style.left=`${n.x}px`,this.corner_selection.style.display="block",this.grid_selection.style.width=`${e}px`,this.grid_selection.style.height=`${t}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=`${e}px`,this.annotation_container.style.height=`${t}px`,this.annotation_container.style.top=`${this.header_offset.y}px`,this.annotation_container.style.left=`${this.header_offset.x}px`}};var De=class c extends le{constructor(t,r,i){super();this.model=t;this.view=r;this.autocomplete=i;this.parser=t.parser}static FormulaChars=("$^&*(-+={[<>/~%"+N.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 o=r?.getRangeAt(0);if((o?.endContainer instanceof t.HTMLElement?o.endContainer:o.endContainer?.parentElement)?.dataset.reference!==void 0)return!0;if(o?.startContainer instanceof t.Text){let s=(o.startContainer.textContent?.substring(0,o.startOffset)||"").trim();if(s.length&&c.FormulaChars.includes(s[s.length-1]))return!0}else console.info("mark 21",o)}let n=this.SubstringToCaret2(this.active_editor.node)[1].trim();if(n.length){let o=n[n.length-1];return c.FormulaChars.includes(o)}}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,o=n.getSelection(),a=i?.createRange(),s=d=>{let h=d;for(;h&&!(h instanceof n.Text)&&h.firstChild;)h=h.firstChild;return h},l=s(t.node);if(r){let d=s(r.node);o&&a&&(a.setStart(l,t.offset),a.setEnd(d,r.offset),o.removeAllRanges(),o.addRange(a))}else o&&a&&(a.setStart(l,t.offset),a.setEnd(l,t.offset),a.collapse(!0),o.removeAllRanges(),o.addRange(a))}InsertReference(t){if(!this.active_editor)return;let r=this.active_editor.node.ownerDocument.defaultView,i=r.getSelection();if(!i)throw new Error("error getting selection");if(i.rangeCount===0)return"";let n=i.getRangeAt(0),o=this.active_editor.node.textContent||"";if(n.startContainer instanceof r.Text)if(!n.collapsed&&n.startOffset<n.endOffset){let a=this.SubstringToCaret2(this.active_editor.node);this.active_editor.node.textContent=a[0]+t+o.substring(a[1].length),this.SetCaret({node:this.active_editor.node,offset:a[0].length},{node:this.active_editor.node,offset:a[0].length+t.length})}else{let a=n.startContainer.parentElement;if(a instanceof r.HTMLElement&&a.dataset.reference)a.textContent=t,this.SetCaret({node:a,offset:t.length});else{let s=this.SubstringToCaret2(this.active_editor.node)[1],l="",d=s.trim();if(d.length){let h=d[d.length-1];c.FormulaChars.includes(h)||(s.length===d.length?l=" +":l="+")}this.active_editor.node.textContent=s+l+t+o.substring(s.length),this.SetCaret({node:this.active_editor.node,offset:s.length+t.length+l.length})}}else n.startContainer instanceof r.HTMLElement?(n.startContainer.textContent=t,this.SetCaret({node:n.startContainer,offset:t.length})):console.warn("unexpected range start container",n.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 o of this.nodes)for(let a of o.references||[]){let s=this.model.AddressToLabel(a);r.has(s)||(r.set(s,a),i.set(s,i.size))}for(let o of this.nodes){for(let a of Array.from(o.node.childNodes)){let s=a.ownerDocument?.defaultView;if(s&&a instanceof s.HTMLElement&&a.dataset.reference){let l=i.get(a.dataset.reference);a.dataset.highlightIndex=typeof l=="number"?(l%5+1).toString():"?"}}o.check=o.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 s of r.full_reference_list||[])switch(s.type){case"address":case"range":{let l=s.type==="range"?s.start:s;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(s);break}case"structured-reference":if(this.target_address){let l=this.model.ResolveStructuredReference(s,this.target_address);l&&i.push(l)}else console.info("target address not set");break;case"identifier":{let l=this.model.GetName(s.name,this.view.active_sheet.id);l?.type==="range"&&(l.area.count===1?i.push({type:"address",...l.area.start,label:s.name,position:s.position,id:s.id}):i.push({type:"range",start:{type:"address",position:s.position,id:s.id,label:s.name,...l.area.start},end:{type:"address",position:s.position,label:s.name,id:s.id,...l.area.end},label:s.name,position:s.position,id:s.id}));break}}i.sort((s,l)=>s.position-l.position);let n=[],o=new Set,a=new Map;for(let s of i){let l=this.model.AddressToLabel(s),d=V(s)?new y(s):new y(s.start,s.end);o.has(l)||(n.push(d),o.add(l)),a.set(s,l)}return this.UpdateReferences(t,n),a}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||"",o=P.GetInstance(i.ownerDocument);if(this.text_formula=n[0]==="=",this.active_editor&&!this.assume_formula&&(this.active_editor.node.spellcheck=!this.text_formula,!this.text_formula)||n===t.formatted_text)return;let[a,s]=this.SubstringToCaret2(i),l=a.length,d=s.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,b,g,C=0,x,v=o.Fragment(),_=(w,A="text",S="",I=!1)=>{let L=o.Text(w);if((I||(l>C||l===0&&C===0)&&l<=C+w.length)&&(b={offset:l-C,node:L}),d>C&&d<=C+w.length&&(g={offset:d-C,node:L}),A!=="text"){let Z=o.Create("span",A);S&&(Z.dataset.reference=S),Z.appendChild(L),v.appendChild(Z)}else v.appendChild(L);x=L,C+=w.length};this.parser.Walk(u.expression,w=>{if(w.type==="missing"||w.type==="group"||w.type==="dimensioned")return!0;let A=w.position+f,S=n.substring(p,A),I="",L=w.type,Z="";switch(w.type){case"identifier":case"call":I=n.substring(A,A+w.name.length);break;case"literal":if(typeof w.value=="string")I=n.substring(A,A+w.value.length+2),L="string";else return!1;break;case"address":case"range":case"structured-reference":Z=m.get(w)||"???",I=r.rewrite_addresses?w.label:n.substring(A,A+w.label.length);break;default:return!0}return _(S),_(I,L,Z),p=A+I.length,w.type!=="range"}),p<n.length&&_(n.substring(p)),b||(x?b={node:x,offset:(x.data||"").length}:_("",void 0,"",!0)),i.textContent="",i.appendChild(v),b&&!r.format_only&&i===this.active_editor?.node&&this.SetCaret(b,g)}}t.formatted_text=n;let h=this.autocomplete_matcher;h&&Promise.resolve().then(()=>{let u=h.Exec({text:n,cursor:s.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;if(t.data&&t.data.completions){for(let d of t.data.completions)if(d.name.toLowerCase()===t.value?.toLowerCase()){r=d.type;break}}let i=t.data?.position||0,n=i+(t.data?.token?.length||0),o=r==="token"?t.value:t.value+"(",a=this.active_editor.node.textContent||"",s=a.substring(0,i)+o,l=s.length;s+=a.substring(n),this.active_editor.node.textContent=s,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 G(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,o=[!1,!1],a=(l,d)=>{if(l===d.startContainer&&l===d.endContainer&&!(l instanceof n.Text)){o[0]=o[1]=!0,r[0]+=l.textContent,r[1]+=l.textContent;return}if(l===d.startContainer&&(r[0]+=(l.textContent||"").substring(0,d.startOffset),o[0]=!0),l===d.endContainer&&(r[1]+=(l.textContent||"").substring(0,d.endOffset),o[1]=!0),!(o[0]&&o[1])){if(l instanceof n.Text){let h=l.textContent||"";o[0]||(r[0]+=h),o[1]||(r[1]+=h)}else if(l.hasChildNodes()){for(let h of Array.from(l.childNodes))if(a(h,d),o[0]&&o[1])return}}},s=n.getSelection();if(s?.rangeCount??!1){let l=s?.getRangeAt(0);l&&a(t,l)}return r}};var uo=typeof navigator>"u"?"":navigator.appVersion,Te=typeof navigator>"u"?"":navigator.userAgent,zr=class{is_edge=/Edge/.test(uo);is_ipad=/iPad|iPhone/.test(Te);is_android=/android|samsung/i.test(Te);is_mobile=this.is_ipad||this.is_android;is_firefox=/firefox/i.test(Te);is_safari=/safari/i.test(Te)&&!/edg/i.test(Te);is_mac=/macintosh/i.test(Te);is_chrome=/Chrome/i.test(Te);is_windows=/win64|win32|windows\s+nt/i.test(Te);is_modern=!this.is_edge&&!(this.is_firefox&&this.is_android)&&/webkit|firefox/i.test(Te)},mo={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},ee=typeof navigator>"u"?mo:new zr;var Dt=class extends De{constructor(t,r,i,n,o){super(i,n,o);this.container=t;this.theme=r;this.container_node=t.querySelector(".treb-overlay-container"),this.edit_node=this.container_node.querySelector(".treb-overlay-editor"),ee.is_firefox&&this.edit_node.classList.add("firefox"),this.edit_node.inputMode="none";let a={node:this.edit_node};this.nodes=[a],this.active_editor=a,this.RegisterListener(a,"input",s=>{if(s instanceof InputEvent&&s.isComposing)return;if(!s.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(a),this.UpdateColors())}),this.RegisterListener(a,"keyup",s=>{s.isComposing||!this.editing||this.autocomplete&&this.autocomplete.HandleKey("keyup",s).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(){ee.is_firefox?this.edit_node.innerHTML="<span></span>":this.edit_node.textContent=""}Edit(t,r,i,n,o){this.Publish({type:"start-editing",editor:"ice"}),this.active_cell=i,this.target_address={...t.target},this.reset_selection=!1;let a=i.style||{};switch(this.edit_node.style.font=F.Font(a,this.scale),this.edit_node.style.color=R(this.theme,a.text,1),this.edit_inset.style.backgroundColor=R(this.theme,a.fill,0),a.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 s=n?.toString()||"";if(s&&s[0]==="="&&(this.edit_node.spellcheck=!1),r.ApplyStyle(this.container_node),this.autocomplete?.ResetBlock(),this.selection=t,typeof n<"u"){let l=s[0]!=="="&&s[s.length-1]==="%",d=s.length;this.edit_node.textContent=s,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()),!o&&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 Nr=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"),o=Math.ceil(n.width);if(this.canvas.setAttribute("width",o.toString()),this.canvas.setAttribute("height",o.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 a=Math.round(o*2/3),s=Math.round(o/2);i.clearRect(0,0,o,o);for(let u=32;u<=126;u++){let m=String.fromCharCode(u);i.fillText(m,s,a)}let l=i.getImageData(0,0,this.canvas.width,this.canvas.height).data,d=Math.floor(this.GetFirstIndex(l)/o),h=Math.floor(this.GetLastIndex(l)/o);return{ascender:a-d,descender:h-a,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}},Vt=new Nr;var fo=" ",Dr="bottom",Ii=/webkit/i.test(typeof navigator>"u"?"":navigator?.userAgent||"")?1:0,Ut=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 o=this.buffer_canvas.getContext("2d",{alpha:!1});if(o){let a=this.layout.dpr;this.buffer_context=o,this.buffer_context.setTransform(a,0,0,a,0,0),this.buffer_context.textAlign="left",this.buffer_context.textBaseline=Dr}}cell_edge_buffer=4;overflow_areas=[];buffer_canvas;buffer_context;buffer_canvas_size={width:256,height:256};FlushOverflows(){let e=this.view.active_sheet.cells;for(let t of e.Iterate())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=Dr)}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 o=r.area.start.column;!n&&o<=r.area.end.column;o++){let a=this.view.active_sheet.cells.GetCell({row:i,column:o},!1);n=!!(a&&!a.render_clean[this.view.view_index])}if(n){for(let o=r.area.start.column;o<=r.area.end.column;o++){let a=this.view.active_sheet.cells.GetCell({row:i,column:o},!1);a&&(a.render_clean[this.view.view_index]=!1,a.renderer_data&&a.renderer_data.overflowed&&(a.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=Vt.Get(F.Font(this.theme.headers||{},this.layout.scale)),i=this.layout.dpr,n=this.layout.header_offset,o=n.x;for(let s=0;s<this.view.active_sheet.freeze.columns;s++)o+=this.layout.ColumnWidth(s);let a=n.y;for(let s=0;s<this.view.active_sheet.freeze.rows;s++)a+=this.layout.RowHeight(s);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,o,n.y),t.fillRect(0,0,n.x,a),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(),a!==n.y&&(t.moveTo(n.x-.5,n.y),t.lineTo(n.x-.5,a)),o!==n.x&&(t.moveTo(n.x,n.y-.5),t.lineTo(o,n.y-.5)),t.stroke(),t.strokeStyle=this.theme.headers_grid_color||"",t.textAlign="center",t.textBaseline="middle",t.font=F.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),o=y.ColumnToLabel(t),a=e.measureText(o);n>a.width&&e.fillText(o,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 o=this.layout.RowHeight(t);o>=i*1.2&&e.fillText(`${t+1}`,n/2,o/2+1),e.moveTo(0,o-.5),e.lineTo(n,o-.5),e.translate(0,o)}e.stroke()}}RenderHeaders(e,t=!1){let r=this.layout.dpr,i=this.layout.header_offset,n=Vt.Get(F.Font(this.theme.headers||{},this.layout.scale));for(let o=e.start.column;o<=e.end.column;o++){let a=this.layout.column_header_tiles[o];if(a.dirty||t){let s=a.getContext("2d",{alpha:!1});if(!s)continue;s.setTransform(r,0,0,r,0,0),s.textAlign="center",s.textBaseline="middle",s.font=F.Font(this.theme.headers||{},this.layout.scale),s.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",s.fillRect(0,0,a.logical_size.width,this.layout.header_offset.y),s.strokeStyle=this.theme.headers_grid_color||"",s.beginPath(),s.moveTo(0,i.y-.5),s.lineTo(a.logical_size.width,i.y-.5),s.stroke(),s.strokeStyle=this.theme.headers_grid_color||"",this.RenderColumnLabels(s,a.first_cell.column,a.last_cell.column),a.dirty=!1}}for(let o=e.start.row;o<=e.end.row;o++){let a=this.layout.row_header_tiles[o];if(a.dirty||t){let s=a.getContext("2d",{alpha:!1});if(!s)continue;s.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",s.setTransform(r,0,0,r,0,0),s.textAlign="center",s.textBaseline="middle",s.font=F.Font(this.theme.headers||{},this.layout.scale),s.fillRect(0,0,this.layout.header_offset.x,a.logical_size.height),s.strokeStyle=this.theme.headers_grid_color||"",s.beginPath(),s.moveTo(i.x-.5,0),s.lineTo(i.x-.5,a.logical_size.height),s.stroke(),s.strokeStyle=this.theme.headers_grid_color||"",this.RenderRowLabels(s,a.first_cell.row,a.last_cell.row,n.block),a.dirty=!1}}(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.RenderCorner()}CopyToAdjacent(e,t,r,i,n,o,a){let s=this.layout.AdjacentTile(e,i,r);if(!s)return;let l=n,d=o;r>0?l=n-(e.pixel_end.x-e.pixel_start.x)*t:r<0&&(l=n+(s.pixel_end.x-s.pixel_start.x)*t),i>0&&(d=o-(e.pixel_end.y-e.pixel_start.y)*t);let h=s.getContext("2d",{alpha:!1});h&&(h.setTransform(t,0,0,t,l,d),h.drawImage(this.buffer_canvas,0,0,(a.width||0)*t,(a.height||0)*t,a.left||0,0,a.width||0,a.height||0))}Render(e){let t=e.getContext("2d",{alpha:!1});if(!t)return;t.textBaseline=Dr;let r=this.layout.dpr;t.setTransform(r,0,0,r,0,0);let i=0,n=0;for(let s=e.first_cell.column;s<=e.last_cell.column;s++){let l=this.layout.ColumnWidth(s);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:s});if(e.needs_full_repaint||!u.render_clean[this.view.view_index]){let m=this.RenderCell(e,u,t,{row:d,column:s},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 o=0,a=0;if(e.first_cell.row<=this.view.active_sheet.freeze.rows-1)for(let s=e.first_cell.row;s<this.view.active_sheet.freeze.rows&&s<=e.last_cell.row;s++)o+=this.layout.RowHeight(s);if(e.first_cell.column<=this.view.active_sheet.freeze.columns-1)for(let s=e.first_cell.column;s<this.view.active_sheet.freeze.columns&&s<=e.last_cell.column;s++)a+=this.layout.ColumnWidth(s);if(o){let s=this.layout.frozen_row_tiles[e.tile_position.column];if(!s)throw new Error("can't find matching header tile");let l=s.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,o*r,0,0,e.logical_size.width,o)}if(a){let s=this.layout.frozen_column_tiles[e.tile_position.row];if(!s)throw new Error("can't find matching header tile");let l=s.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,a*r,e.logical_size.height*r,0,0,a,e.logical_size.height)}if(a&&o){let s=this.layout.corner_canvas.getContext("2d",{alpha:"false"});if(!s)throw new Error("corner context failed");s.setTransform(r,0,0,r,this.layout.header_offset.x*r,this.layout.header_offset.y*r),s.drawImage(e,0,0,a*r,o*r,0,0,a,o)}}PrepText(e,t,r,i){let n=[],o=r.style||{},a,s=0,l,d=r.editing?"":r.formatted;Array.isArray(d)&&(d=d.filter(m=>m.flag!==8));let h="",u;if(o.indent){for(let m=0;m<o.indent;m++)h+=fo;u=o.horizontal_align,u||(u=r.type===3||r.calculated_type===3||r.type===7||r.calculated_type===7?"right":"left")}if(Array.isArray(d)){h&&(u==="right"?d.push({text:h,flag:8}):(u==="left"||typeof u>"u")&&d.unshift({text:h,flag:8}));for(let m of d){if(m.flag===6){l=m.text;continue}let f=e.measureText(m.text).width,p={width:f,text:m.text,hidden:m.flag===1};n.push(p),m.flag===2?a=p:s+=f}if(a){let m=a.text,f=a.width,p=i-s-2*this.cell_edge_buffer;if(a.width=Math.max(0,p),p>0){let b=Math.floor(p/f);for(let g=1;g<b;g++)a.text+=m;s=i-2*this.cell_edge_buffer}else a.text=""}return{strings:[n],format:l,width:s}}else if(d){r.type===2&&d[0]==="'"&&(d=d.slice(1));let m;this.options.markdown?m=ze.instance.Parse(d):(m=ze.instance.Dummy(d),e.font=t.base);let f=0,p=i-2*this.cell_edge_buffer,b=[];if(o.wrap){let g=h&&o.horizontal_align!=="center"?e.measureText(h).width:0;p-=g;for(let C of m){for(let v=1;v<C.length;v++){let _=C[v].text.match(/^(\s+)/);_&&(C[v-1].text+=_[1],C[v].text=C[v].text.replace(/^\s+/,""))}let x=[];for(let v of C){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 _=v.text.match(/\S+\s*/g);if(_&&_.length)for(let w of _){let A=e.measureText(w.trim()).width,S=e.measureText(w).width;x.push({part:v,text:w,trimmed:A,width:S})}}for(;x.length;){let v=x.shift(),_=[v],w=v.trimmed;for(;w<p&&x.length;){let S=x[0],I=w-v.trimmed+v.width+S.trimmed;if(I>=p)break;v=S,_.push(S),w=I,x.shift(),f=Math.max(f,w)}v.text=v.text.trim(),v.width=v.trimmed,f=Math.max(f,v.width);let A=_.map(S=>({...S.part,hidden:!1,width:S.width,text:S.text}));o.indent&&(u==="right"?A.push({text:h,hidden:!1,width:g}):u==="left"&&A.unshift({text:h,hidden:!1,width:g})),b.push(A)}}}else for(let g of m){let C=[];o.indent&&(u==="right"?g.push({text:h}):u==="left"&&g.unshift({text:h}));let x=0;for(let v of g){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;x+=_,C.push({...v,hidden:!1,width:_})}f=Math.max(f,x),b.push(C)}return{strings:b,width:f}}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,o=0,a=0){let s=this.view.active_sheet.SurroundingStyle(e,this.theme.table),l=R(this.theme,s[8].fill);l&&(t.fillStyle=l,t.fillRect(i+0,n-1,o,1)),l=R(this.theme,s[4].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n,1,a)),l=R(this.theme,r.fill),l&&(t.fillStyle=l,t.fillRect(i-1,n-1,o+1,a+1)),l=R(this.theme,s[6].fill),l&&(t.fillStyle=l,t.fillRect(i+o-1,n-1,1,a+1)),l=R(this.theme,s[2].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n+a-1,o+1,1)),s[6].border_top&&!s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_top_fill,1),t.fillRect(i+o-1,n-2+s[6].border_top,1,1)),s[9].border_left&&(t.fillStyle=R(this.theme,s[9].border_left_fill,1),t.fillRect(i+o-1,n-1,1,1)),s[9].border_bottom&&(t.fillStyle=R(this.theme,s[9].border_bottom_fill,1),t.fillRect(i+o-1,n-2+s[9].border_bottom,1,1)),s[4].border_top&&!s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_right_fill,1),t.fillRect(i-1,n-2+s[4].border_top,1,1)),s[7].border_right&&(t.fillStyle=R(this.theme,s[7].border_right_fill,1),t.fillRect(i-1,n-1,1,1)),s[7].border_bottom&&(t.fillStyle=R(this.theme,s[7].border_bottom_fill,1),t.fillRect(i-1,n-2+s[7].border_bottom,1,1)),s[6].border_bottom&&!s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_bottom_fill,1),t.fillRect(i+o-1,n+a-s[6].border_bottom,1,1)),s[3].border_left&&(t.fillStyle=R(this.theme,s[3].border_left_fill,1),t.fillRect(i+o-1,n+a-1,1,1)),s[3].border_top&&(t.fillStyle=R(this.theme,s[3].border_top_fill,1),t.fillRect(i+o-1,n+a-s[3].border_top,1,1)),s[4].border_bottom&&!s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_bottom_fill,1),t.fillRect(i-1,n+a-s[4].border_bottom,1,1)),s[1].border_right&&(t.fillStyle=R(this.theme,s[1].border_right_fill,1),t.fillRect(i-1,n+a-1,1,1)),s[1].border_top&&(t.fillStyle=R(this.theme,s[1].border_top_fill,1),t.fillRect(i-1,n+a-s[1].border_top,1,1)),s[8].border_bottom&&(t.fillStyle=R(this.theme,s[8].border_bottom_fill,1),s[8].border_bottom===2&&(t.fillRect(i-1,n-2,o+1,1),t.fillRect(i-1,n-0,o+1,1),t.fillStyle=R(this.theme,s[8].fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n-1,o+1,1)),s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_right_fill,1),t.fillRect(i-1,n-1,1,a+1)),s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_left_fill,1),t.fillRect(i+o-1,n-1,1,a+1)),s[2].border_top&&(t.fillStyle=R(this.theme,s[2].border_top_fill,1),s[2].border_top===2&&(t.fillRect(i-1,n+a-2,o+1,1),t.fillRect(i-1,n+a-0,o+1,1),t.fillStyle=R(this.theme,s[2].fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n+a-1,o+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,o+1,1),t.fillRect(i-1,n+0,o+1,1),t.fillStyle=R(this.theme,r.fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n-1,o+1,1)),r.border_left&&(t.fillStyle=R(this.theme,r.border_left_fill,1),t.fillRect(i-1,n-1,1,a+1)),r.border_right&&(t.fillStyle=R(this.theme,r.border_right_fill,1),t.fillRect(i+o-1,n-1,1,a+1)),r.border_bottom&&(t.fillStyle=R(this.theme,r.border_bottom_fill,1),r.border_bottom===2&&(t.fillRect(i-1,n+a-2,o+1,1),t.fillRect(i-1,n+a+0,o+1,1),t.fillStyle=R(this.theme,r.fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n+a-1,o+1,1))}PaintBackgroundImage(e,t,r,i,n,o,a=0,s=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=o/d,p=h+m>t.width,b=u+f>t.height;p&&e.drawImage(t,h-t.width,u,m,f,a,s,n-l,o-l),b&&e.drawImage(t,h,u-t.height,m,f,a,s,n-l,o-l),p&&b&&e.drawImage(t,h-t.width,u-t.height,m,f,a,s,n-l,o-l),e.drawImage(t,h,u,m,f,a,s,n-l,o-l)}RenderCellBackground(e,t,r,i,n,o,a=0,s=0){if(r.fillStyle=this.theme.grid_color,r.fillRect(0,0,n,o),this.view.active_sheet.image)this.PaintBackgroundImage(r,this.view.active_sheet.image,a,s,n,o,0,0,1);else{let l=R(this.theme,i.fill);l?(r.fillStyle=l,r.fillRect(0,0,n-1,o-1)):(r.fillStyle=R(this.theme,this.theme.grid_cell?.fill,0)||"#fff",r.fillRect(0,0,n-1,o-1))}this.RenderCellBorders(t,r,i,0,0,n,o),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,9),r.lineTo(n-2,1),r.fill())}RenderCell(e,t,r,i,n,o,a=0,s=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 T=t.merge_area.start.column+1;T<=t.merge_area.end.column;T++)n+=this.layout.ColumnWidth(T);for(let T=t.merge_area.start.row+1;T<=t.merge_area.end.row;T++)o+=this.layout.RowHeight(T);if(t.merge_area.count>1){let T=this.view.active_sheet.CellStyleData(t.merge_area.end);T&&(h.border_bottom=T.border_bottom,h.border_right=T.border_right,h.border_bottom_fill=T.border_bottom_fill,h.border_right_fill=T.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,o),r.strokeStyle=r.fillStyle=R(this.theme,h.text,1);let T=this.ResolveColors(h);if(t.render_function.call(void 0,{width:n,height:o,context:r,cell:t,style:T,scale:this.layout.scale||1}).handled)return l}let m={base:F.Font(h,this.layout.scale),strong:F.Font({...h,bold:!0},this.layout.scale),emphasis:F.Font({...h,italic:!0},this.layout.scale),strong_emphasis:F.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!==o){let T=this.PrepText(r,m,t,n);t.renderer_data={text_data:T,width:n,height:o}}let f=t.renderer_data.text_data,p=f.width>n-2*this.cell_edge_buffer,b=n,g=0,C=!1,x=t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7||t.type===9||t.calculated_type===9,v=h.horizontal_align;v||(v=x?"right":"left");let _=[];if(p)if(t.type!==3&&t.calculated_type!==3&&!h.wrap&&!t.merge_area){let te=f.width-n+this.cell_edge_buffer,oe=0,k=0;v==="center"?oe=k=te/2:v==="right"?oe=te:k=te;let Q=i.column,q=i.column;for(;k>0&&Q<this.layout.last_column;){Q++;let B={row:i.row,column:Q},D=this.view.active_sheet.CellData(B),Y=this.layout.ColumnWidth(Q);if(k-=Y,D&&!D.type&&!D.calculated_type)_.push({address:B,cell:D,grid:new G(b,0,Y,o),background:new G(b-1,0,Y,o-1),border:new G(b,0,Y,o)}),b+=Y,D.render_clean[this.view.view_index]=!0,D.renderer_data={overflowed:!0};else{C=!0;break}}for(Q>e.last_cell.column&&(l.tile_overflow_right=!0);oe>0&&q>=1;){q--;let B={row:i.row,column:q},D=this.view.active_sheet.CellData(B),Y=this.layout.ColumnWidth(q);if(oe-=Y,D&&!D.type&&!D.calculated_type)g-=Y,_.push({address:B,cell:D,grid:new G(g,0,Y,o),background:new G(g,0,Y,o-1),border:new G(g,0,Y,o)});else{C=!0;break}}q<e.first_cell.column&&(l.tile_overflow_left=!0),this.overflow_areas.push({head:{...i},tile:e,area:new y({row:i.row,column:q},{row:i.row,column:Q})})}else C=!x;let w=!1,A=r;(l.tile_overflow_bottom||l.tile_overflow_left||l.tile_overflow_right)&&(w=!0,l.width=b-g,l.height=o,l.left=g,this.EnsureBuffer(l.width+1,o+1,-g),r=this.buffer_context,r.font=m.base),this.RenderCellBackground(!!t.note,i,r,h,n,o,a,s);for(let T of _)T.cell.style?.fill&&di(T.cell.style.fill)&&!this.options.grid_over_background?(r.fillStyle=R(this.theme,T.cell.style.fill,0),r.fillRect(T.grid.left,T.grid.top,T.grid.width,T.grid.height)):(r.fillStyle=this.theme.grid_color||"",r.fillRect(T.grid.left,T.grid.top,T.grid.width,T.grid.height),this.view.active_sheet.image?this.PaintBackgroundImage(r,this.view.active_sheet.image,a+T.background.left,s+T.background.top,T.background.width,T.background.height,T.background.left,T.background.top,0):(r.fillStyle=this.theme.grid_cell?.fill?R(this.theme,this.theme.grid_cell.fill,0):"",r.fillRect(T.background.left,T.background.top,T.background.width,T.background.height))),T.cell.style&&this.RenderCellBorders(T.address,r,T.cell.style,T.border.left,T.border.top,T.border.width,T.border.height);let S=Vt.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 I=this.cell_edge_buffer,L=1.25,Z=f.strings.length,_e=Z*S.block*L;C=(C||_e>=o)&&!w,C&&(r.save(),r.beginPath(),r.moveTo(g+1.5,0),r.lineTo(g+1.5,o),r.lineTo(b-1.5,o),r.lineTo(b-1.5,0),r.clip()),r.beginPath();let ne=Math.round(o-2-S.block*L*(Z-1)+Ii);switch(h.vertical_align){case"top":ne=Math.round(S.block*L)+1;break;case"middle":ne=Math.round((o-_e)/2+S.block*L);break}if((t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7)&&p){let T=Math.floor((n-2*this.cell_edge_buffer)/S.hash),te="";for(let k=0;k<T;k++)te+="#";let oe=r.measureText(te).width;v==="center"?I=Math.round((n-oe)/2):v==="right"&&(I=n-this.cell_edge_buffer-oe),r.fillText(te,I,ne)}else{let T=ne,te=0;for(let oe of f.strings){let k=0;for(let D of oe)k+=D.width;v==="center"?I=Math.round((n-k)/2):v==="right"&&(I=n-this.cell_edge_buffer-k);let Q=Math.floor(T+1.5-S.descender-Ii)+.5,q=Math.floor(T-S.descender-S.ascender/2)+.5,B=I;for(let D of oe)D.strong&&D.emphasis?r.font=m.strong_emphasis:D.strong?r.font=m.strong:D.emphasis?r.font=m.emphasis:r.font=m.base,D.hidden||(D.text&&r.fillText(D.text,B,T),h.underline&&(r.moveTo(B,Q),r.lineTo(B+D.width,Q)),(h.strike||D.strike)&&(r.moveTo(B,q),r.lineTo(B+D.width,q)),u&&(D.left=B,D.top=T-S.block,D.height=S.block)),B+=D.width;te++,T=Math.round(ne+te*S.block*L)}}if(r.stroke(),C)r.restore();else if(w){let T=this.layout.dpr;A.drawImage(this.buffer_canvas,0,0,(l.width||0)*T,o*T,g,0,l.width||0,o)}return l}};var Ft=class extends De{constructor(t,r,i,n,o){super(r,i,o);this.options=n;let a=P.GetInstance(t.ownerDocument),s=t.querySelector(".treb-formula-bar");s.removeAttribute("hidden"),this.address_label_container=s.querySelector(".treb-address-label"),this.address_label=this.address_label_container.firstElementChild,this.InitAddressLabel(),this.container_node=t.querySelector(".treb-editor-container");let l=this.container_node.firstElementChild,d={node:l};if(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",()=>{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){let h;this.expand_button=a.Create("button","expand-button",s,{events:{focus:u=>{h=u.relatedTarget instanceof HTMLElement?u.relatedTarget:void 0},click:u=>{u.stopPropagation(),u.preventDefault(),this.active_editor&&(this.active_editor.node.scrollTop=0),s.hasAttribute("expanded")?s.removeAttribute("expanded"):s.setAttribute("expanded",""),h&&h.focus()}}})}}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="&nbsp;",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}IsExpandButton(t){return this.expand_button&&t===this.expand_button}InitAddressLabel(){this.address_label.contentEditable="true",this.address_label.spellcheck=!1,this.address_label.addEventListener("focusin",()=>{let t=this.address_label.ownerDocument;requestAnimationFrame(()=>{let r=t.defaultView.getSelection(),i=t.createRange();i.selectNodeContents(this.address_label),r?.removeAllRanges(),r?.addRange(i)})}),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 o=r[n];switch(o.nodeType){case Node.ELEMENT_NODE:i.push(...this.GetTextContent(o)),o instanceof Element&&o.tagName==="DIV"&&i.push(`
5
+ `}IsDelimeter(e){return e==="*"||e==="_"||e==="~"}Consolidate(e){let t=[],r={},i=[],n={type:"text",text:""};for(let o of e)if(o.type==="newline")n.text.length&&i.push(n),n={...r,text:"",type:"text"},t.push(i),i=[];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,n.text.length&&i.push(n),n={...r,text:"",type:"text"}),o.type){case"text":case"whitespace":n.text+=o.text;break;case"delimeter":for(let a=0;a<o.length;a++)n.text+=o.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 o=this.ApplyFormatting(e.slice(r+1),n);if(o.token){let a=Math.min(o.token.length,n.length),s=n.char==="~",l=!s&&!!(a%2),d=!s&&a>=2;for(let h=r+1;h<=r+o.index;h++)e[h].strong=!!e[h].strong||d,e[h].emphasis=!!e[h].emphasis||l,e[h].strike=!!e[h].strike||s;o.token.length-=a,n.length-=a,n.length>0?r--:r+=o.index}}}}return{index:r}}Tokenize(e=""){let t=[],r=e.length,i=0,n=!1,o="";for(i=0;i<r;i++){let a=e[i];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(this.IsWhitespace(l))s+=l,i++;else break}t.push({type:"whitespace",text:s}),n=!1,o=""}else if(this.IsNewline(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(this.IsNewline(l))s+=l,i++;else break}t.push({type:"newline",text:s}),n=!1,o=""}else if(n)o+=a,n=!1;else if(this.IsDelimeter(a)){o&&t.push({type:"text",text:o});let s=a;for(;;){let l=e[i+1];if(l===a)s+=l,i++;else break}t.push({type:"delimeter",text:s,char:a,length:s.length}),n=!1,o=""}else a==="\\"?n=!0:o+=a}return o&&t.push({type:"text",text:o}),t}};var V=c=>c!==null&&typeof c=="object"&&"row"in c&&"column"in c,tt=c=>c!==null&&typeof c=="object"&&"start"in c&&V(c.start)&&"end"in c&&V(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){if(e.row===1/0&&e.column===1/0)throw new Error("this is going to break something");let r=t?`${e.sheet_id||0}!`:"";return e.row===1/0?r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column):e.column===1/0?r+(e.absolute_row?"$":"")+(e.row+1):r+(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:o}=t,a=new c(e.start,e.end),s=e.start.sheet_id;if(i&&r<=a.end.column){if(i>0)r<=a.start.column?a.Shift(0,i):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(a));else if(i<0)if(r-i<=a.start.column)a.Shift(0,i);else{if(r<=a.start.column&&r-i>a.end.column)return!1;if(r<=a.start.column){let l=r-i-1;a=new c({row:a.start.row,column:l+1+i,sheet_id:s},{row:a.end.row,column:a.end.column+i})}else r<=a.end.column?r-i-1>=a.end.column?a=new c({row:a.start.row,column:a.start.column,sheet_id:s},{row:a.end.row,column:r-1}):a=new c({row:a.start.row,column:a.start.column,sheet_id:s},{row:a.end.row,column:a.start.column+a.columns+i-1}):console.warn("AA X case 2",r,i,JSON.stringify(a))}}if(o&&n<=a.end.row){if(o>0)n<=a.start.row?a.Shift(o,0):n>a.start.row&&n<=a.end.row?a.ConsumeAddress({row:a.end.row+o,column:a.end.column}):console.warn("AA X case 3",n,o,JSON.stringify(a));else if(o<0)if(n-o<=a.start.row)a.Shift(o,0);else{if(n<=a.start.row&&n-o>a.end.row)return!1;if(n<=a.start.row){let l=n-o-1;a=new c({column:a.start.column,row:l+1+o,sheet_id:s},{column:a.end.column,row:a.end.row+o})}else n<=a.end.row?n-o-1>=a.end.row?a=new c({column:a.start.column,row:a.start.row,sheet_id:s},{column:a.end.column,row:n-1}):a=new c({column:a.start.column,row:a.start.row,sheet_id:s},{column:a.end.column,row:a.start.row+a.rows+o-1}):console.warn("AA X case 4",n,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}Equals2(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)}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}[Symbol.iterator](){if(this.entire_row||this.entire_column)throw new Error("don't iterate infinite area");let e=this.start_.row,t=this.start_.column;return{next:()=>{let r={column:t,row:e,sheet_id:this.start_.sheet_id};return t>this.end_.column?{done:!0,value:void 0}:(++e>this.end_.row&&(e=this.start_.row,t++),{value:r})}}}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 ae=c=>typeof c=="object"&&!!c&&typeof c.real=="number"&&typeof c.imaginary=="number",Oe=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",vr=c=>typeof c=="object"&&!!c&&typeof c.value=="number"&&typeof c.unit=="string",xr=["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:ae(c)?7:vr(c)?9:5;case"string":return c[0]==="="?1:2;default:return 6}};var re=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;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 wr=c=>!c.cells,rt=c=>!!c[0]&&wr(c[0]),Cr=c=>!!c[0]&&c[0].row!==void 0,Pn=xr.map((c,e)=>({[c]:e})).reduce((c,e)=>({...c,...e}),{}),yt=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){this.data=this.data.map(r=>{if(r.length>=e){let i=r.slice(0,e),n=e+t,o=r.slice(e);for(let a=0;a<o.length;a++)i[n++]=o[a];return i}return r}),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 re,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 re,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 o=e[n];r=Math.max(r,o.length);for(let a=0;a<o.length;a++)this.data[a]||(this.data[a]=[]),this.data[a][n]=new re(o[a])}}else{r=e.length;for(let n=0;n<r;n++){let o=[],a=e[n];i=Math.max(i,a.length);for(let s=0;s<a.length;s++)o[s]=new re(a[s]);this.data[n]=o}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Pn[e]||void 0}ValueTypeToSerializedType(e){return e?xr[e]:void 0}FromJSON(e=[],t){if(this.data=[],!rt(e)){let i=[];if(Cr(e))for(let n of e)for(let o of n.cells)i.push({...o,row:n.row});else for(let n of e)for(let o of n.cells)i.push({...o,column:n.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let n=new re(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 o=new y(i.area.start,i.area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=o.end.column;s++)this.data[a]||(this.data[a]=[]),this.data[a][s]||(this.data[a][s]=new re),this.data[a][s].area=o}if(i.table&&r.push({...i.table}),i.merge_area){let o=new y(i.merge_area.start,i.merge_area.end);for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=o.end.column;s++)this.data[a]||(this.data[a]=[]),this.data[a][s]||(this.data[a][s]=new re),this.data[a][s].merge_area=o}}for(let i of r)for(let n=i.area.start.row;n<=i.area.end.row;n++)for(let o=i.area.start.column;o<=i.area.end.column;o++)this.data[n]||(this.data[n]=[]),this.data[n][o]||(this.data[n][o]=new re),this.data[n][o].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 o=[],a=-1,s=-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,b=f&&f.area&&f.area.start.row===h&&f.area.start.column===m,g=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===m,C=f?f.type===2&&!f.value:!0;if(f&&(!C||e.preserve_empty_strings)&&(p||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||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:m,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&&g&&e.tables&&(x.table=JSON.parse(JSON.stringify(f.table))),f.area&&b&&(x.area=f.area.toJSON()),f.merge_area&&(x.merge_area=f.merge_area.toJSON()),e.cell_style_refs&&e.cell_style_refs[m]&&e.cell_style_refs[m][h]&&(x.style_ref=e.cell_style_refs[m][h],e.cell_style_refs[m][h]=0),l[h]=h,d[m]=m,a=Math.max(h,a),s=Math.max(m,s),o.push(x)}}}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 o){let{row:b,...g}=p;m[p.row]||(m[p.row]=[]),m[p.row].push(g)}for(let p of h){let b=Number(p);f.push({row:b,cells:m[b]})}return{data:f,rows:a,columns:s+1}}else if(u.length){let m={},f=[];for(let p of o){let{column:b,...g}=p;m[p.column]||(m[p.column]=[]),m[p.column].push(g)}for(let p of u){let b=Number(p);f.push({column:b,cells:m[b]})}return{data:f,rows:a,columns:s+1}}}return{data:o,rows:a+1,columns:s+1}}GetAll(e=!1){return this.GetRange({row:0,column:0},{row:this.rows_-1,column:this.columns_-1},e)}Normalize(e,t){return e={...e,row:e.row==1/0?0:e.row,column:e.column==1/0?0:e.column},t&&(t={...t,row:t.row==1/0?this.rows_-1:t.row,column:t.column==1/0?this.columns_-1:t.column}),{from:e,to:t}}RawValue(e,t=e){if({from:e,to:t}=this.Normalize(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,o=t.column+1;for(let a of i){let s=[];for(let l=n,d=0;l<o;l++,d++){let h=a[l];s.push(h?h.value:void 0)}r.push(s)}return r}GetRange(e,t,r=!1){if({from:e,to:t}=this.Normalize(e,t),!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 o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][n]?o.push(this.data[a][n].GetValue()):o.push(void 0);i.push(o)}else for(let n=e.row;n<=t.row;n++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[n]&&this.data[n][a]?o.push(this.data[n][a].GetValue()):o.push(void 0);i.push(o)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize(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 o=[];for(let a=e.row;a<=t.row;a++)this.data[a]&&this.data[a][n]?o.push(this.data[a][n].GetValue4()):o.push({type:0});i.push(o)}else for(let n=e.row;n<=t.row;n++){let o=[];for(let a=e.column;a<=t.column;a++)this.data[n]&&this.data[n][a]?o.push(this.data[n][a].GetValue4()):o.push({type:0});i.push(o)}return{type:8,value:i}}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 o=e.start.column,a=0;o<=e.end.column;o++,a++)n[o]||(n[o]=new re),n[o].Set(t[i][a])}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 o=e.start.column;o<=e.end.column;o++)n[o]||(n[o]=new re),n[o].Set(t,r)}}this.rows_=Math.max(this.rows_,e.end.row+1),this.columns_=Math.max(this.columns_,e.end.column+1)}*Iterate(e,t=!1){if(!e&&t&&(e=new y({row:0,column:0},{row:this.rows_-1,column:this.columns-1})),e){V(e)&&(e=new y(e)),(e.entire_column||e.entire_row)&&(e=new y(e.start,e.end),e.start.column===1/0&&(e.start.column=0,e.end.column=this.columns_-1),e.start.row===1/0&&(e.start.row=0,e.end.row=this.rows_-1));let r=e.start,i=e.end;if(t)for(let n=r.row;n<=i.row;n++){this.data[n]||(this.data[n]=[]);let o=this.data[n];for(let a=r.column;a<=i.column;a++)o[a]||(o[a]=new re),yield o[a]}else for(let n=r.row;n<=i.row;n++)if(this.data[n]){let o=this.data[n];for(let a=r.column;a<=i.column;a++)o[a]&&(yield o[a])}}else for(let r of this.data)if(r)for(let i of r)i&&(yield i)}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 N=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)}this.locale==="C"&&(console.warn("Locale not set, defaulting to en-us"),this.locale="en-us");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"}))}};N.UpdateLocale();var G=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!!e&&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 Gn=JSON.stringify({}),$n={Background:0,Text:1,Background2:2,Text2:3,Accent:4,Accent2:5,Accent3:6,Accent4:7,Accent5:8,Accent6:9},Sr=c=>typeof c.theme=="number"?c.theme:$n[c.theme]||0,J=c=>!!c&&typeof c.text=="string",Ze=c=>!!c&&typeof c.theme<"u",di=c=>!!c&&(typeof c.text=="string"||typeof c.theme<"u"),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)===Gn,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 Ar=c=>!!c&&Array.isArray(c)&&Array.isArray(c[0]),W=(c,e)=>(typeof e>"u"&&(e=se(c)),{value:c,type:e}),me=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real};var K={Darken:(c,e,t,r,i=!1)=>{let{h:n,s:o,l:a}=K.RGBToHSL(c,e,t);return i?a-=a*r/100:a-=r/100,a=Math.max(0,Math.min(1,a)),K.HSLToRGB(n,o,a)},Lighten:(c,e,t,r,i=!1)=>{let{h:n,s:o,l:a}=K.RGBToHSL(c,e,t);return i?a+=a*r/100:a+=r/100,a=Math.max(0,Math.min(1,a)),K.HSLToRGB(n,o,a)},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,o=0,a=(r+i)/2;if(r===i)n=o=0;else{let s=r-i;switch(o=a>.5?s/(2-r-i):s/(r+i),r){case c:n=(e-t)/s+(e<t?6:0);break;case e:n=(t-c)/s+2;break;case t:n=(c-e)/s+4;break}n/=6}return{h:n*360,s:o,l:a}},HSLToRGB:(c,e,t)=>{let r,i,n;if(e===0)r=i=n=t;else{c=c/360;let o=t<.5?t*(1+e):t+e-t*e,a=2*t-o;r=K.HueToRGB(a,o,c+.3333333333333333),i=K.HueToRGB(a,o,c),n=K.HueToRGB(a,o,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 Hn="http://www.w3.org/2000/svg",P=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(Hn,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[o,a]of Object.entries(i.attrs))n.setAttribute(o,a);if(i.data)for(let[o,a]of Object.entries(i.data))n.dataset[o]=a;if(i.text&&(n.textContent=i.text),i.html&&(n.innerHTML=i.html),i.events)for(let[o,a]of Object.entries(i.events))n.addEventListener(o,a);if(i.style)for(let[o,a]of Object.entries(i.style))n.style[o]=a}return r&&r.appendChild(n),n}};var vt={grid_color:"#ccc",note_marker_color:"#d2c500",mode:"light",offset_cache:{},offset_light:"#fff",offset_dark:"#000"},On=(c,e)=>{let t=Sr(e),r=e.tint||0;c.mode==="dark"&&(r=-r),c.tint_cache||(c.tint_cache=[]),c.tint_cache[t]||(c.tint_cache[t]={});let i=c.tint_cache[t][r];if(!i){let n=(c.theme_colors_rgb?c.theme_colors_rgb[t]:[0,0,0])||[0,0,0],o;r>0?o=K.Lighten(n[0],n[1],n[2],r*100,!0):o=K.Darken(n[0],n[1],n[2],-r*100,!0),i=`rgb(${o.r},${o.g},${o.b})`,c.tint_cache[t][r]=i}return i},R=(c,e,t)=>{if(e&&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?K.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 J(e)?e.text==="none"?"":e.text:Ze(e)?e.tint?On(c,e):c.theme_colors?c.theme_colors[Sr(e)]:"":(t||t===0)&&c.theme_colors?c.theme_colors[t]:""},Zn=c=>{let e=10,t="pt",r=c.match(/^([\d.]+)(\D.*)$/);return r&&(e=Number(r[1]),t=r[2]),{value:e,unit:t}},hi=c=>{let{value:e,unit:t}=Zn(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},Bn=(c,e)=>{let t=c.grid_cell?.text,r=c.grid_cell?.fill;e.fillStyle=J(t)?t.text:"",e.fillRect(0,0,3,3);let i=K.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));e.fillStyle=J(r)?r.text:"",e.fillRect(0,0,3,3);let n=K.RGBToHSL(...Array.from(e.getImageData(1,1,1,1).data));return i.l>n.l?"dark":"light"},xt=(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}}},ui=c=>{let e=JSON.parse(JSON.stringify(vt)),t=P.GetInstance(c.ownerDocument),r=(h,u)=>t.Div(u,h),i=(h,u)=>t.view?.getComputedStyle(r(h,u)),n=r(c,""),o=i.bind(0,n),a=o("grid-cells");e.grid_cell=hi(a),e.grid_color=a.stroke||"",a=o("grid-headers"),e.headers=hi(a),e.headers_grid_color=a.stroke,(!e.headers_grid_color||e.headers_grid_color==="none")&&(e.headers_grid_color=e.grid_color),a=o("treb-offset-dark"),a.color&&(e.offset_dark=a.color),a=o("treb-offset-light"),a.color&&(e.offset_light=a.color),a=o("note-marker"),e.note_marker_color=a.backgroundColor,n.style.color="rgba(1,2,3,.4)",a=o("");let s=a.color;e.theme_colors=[J(e.grid_cell.fill)?e.grid_cell.fill.text:"rgb(255, 255, 255)",J(e.grid_cell.text)?e.grid_cell.text.text:"rgb(51, 51, 51)"];for(let h=1;h<32&&(a=o(`theme-color-${h}`),!(!a.color||a.color===s));h++)e.theme_colors.push(a.color);let l=t.Create("canvas");l.width=3,l.height=3;let d=l.getContext("2d",{willReadFrequently:!0});return d&&(e.mode=Bn(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=xt(4),n.parentElement?.removeChild(n),e};var mi={column:0,type:"auto",asc:!0};var Wn=1e3,le=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=Wn++;return this.subscribers.push({subscriber:e,token:t}),t}Cancel(e){this.subscribers=this.subscribers.filter(t=>t.token!==e)}CancelAll(){this.subscribers=[]}};var ye=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 kr,fi=c=>{let e={};for(let t=0;t<c.length;t++){let r=c[t];e[r]=c.getPropertyValue(r)}return e},jn=(c,e,t)=>{let r={},i=fi(e);for(let n of Object.keys(i))i[n]!==t[n]&&(r[n]=t[n]);return(Object.keys(r).map(n=>`${n}: ${r[n]}`).join("; ")+"; "+(c.getAttribute("style")||"")).trim().replace(/"/g,"'")},pi=(c,e)=>{let t=c.cloneNode(!1),r=getComputedStyle(c),i=jn(c,r,e);t.removeAttribute("class"),t.setAttribute("style",i);let n;return Array.prototype.forEach.call(c.childNodes,o=>{switch(o.nodeType){case Node.ELEMENT_NODE:n||(n=fi(r)),t.appendChild(pi(o,n));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",o)}}),t},bi=c=>{if(!kr){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,o=>e[o]=n[o])}document.body.removeChild(t),kr=e}return pi(c,kr)};var Yn={data:!0,same_origin:!0,remote:!1},wt=(c,e={})=>{let t={...Yn,...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 gi=(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,o=Math.log(n)/Math.log(10),a=Math.floor(Math.abs(o))*(o<0?-1:1)-1;i&&(a=Math.max(0,a));let s=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 s){let u=h*Math.pow(10,a),m=Math.floor(c/u)*u,p=(Math.ceil(e/u)*u-m)/u,b=Math.abs(p-t);(l<0||b<d)&&(!r||p<=t)&&(d=b,l=u)}return c=Math.floor(c/l)*l,e=Math.ceil(e/l)*l,t=Math.round((e-c)/l),{scale:a,step:l,count:t,min:c,max:e}};var Ct=class{constructor(e,t,r="RGB"){this.color_space=r;this.mapped=e.map(i=>{if(i.value<0||i.value>1)throw new Error("invalid stop value");let n=ye.MeasureColor(R(t,i.color)),o=[];if(r==="HSL"){let a=K.RGBToHSL(n[0],n[1],n[2]);o=[a.h,a.s,a.l]}else o=[...n];return{...i,resolved:o}}),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,o=n.value-i.value,a=e-i.value,s=[0,1,2].map(l=>i.resolved[l]+(n.resolved[l]-i.resolved[l])/o*a);return this.RenderColor(s)}}return{text:""}}};var St=class{constructor(e){this.parser=e}named=new Map;get list(){return this.named.values()}SetNamedExpression(e,t,r){return this.SetName({type:"expression",name:e,expression:t,scope:r})}SetNamedRange(e,t,r){return this.SetName({type:"range",name:e,area:new y(t.start,t.end),scope:r})}SetName(e){let t=e.name;return this.ValidateNamed(t)?(this.named.set(this.ScopedName(t,e.scope),e),!0):(console.warn("invalid name",{name:t}),!1)}ScopedName(e,t){return typeof t=="number"?t+":"+e.toLowerCase():e.toLowerCase()}ClearName(e,t){typeof t=="number"?this.named.delete(this.ScopedName(e,t)):this.named.delete(e.toLowerCase())}RemoveRangesForSheet(e){let t=[];for(let[r,i]of this.named)(i.type==="range"&&i.area.start.sheet_id===e||i.scope===e)&&t.push(r);for(let r of t)this.named.delete(r)}Reset(){this.named.clear()}Get_(e,t,r=!1){return r?this.named.get(this.ScopedName(e,t)):this.named.get(this.ScopedName(e,t))||this.named.get(e.toLowerCase())}ValidateNamed(e){return e=e.trim().toUpperCase(),!e.length||/[^A-Z\d_.?]/.test(e)||/^[^A-Z_]/.test(e)||e==="R"||e==="C"||/^[A-Z]{1,3}[1-9]\d*$/.test(e)||/^R[[\]\d]+C/.test(e)?!1:e}MatchSelection(e,t){if(!e.start.sheet_id)throw new Error("match selection without sheet id");let r;for(let i of this.named.values())if(i.type==="range"&&i.area.start.sheet_id===e.start.sheet_id&&(e.Equals(i.area)&&(r=i.name),t?.Equals(i.area)))return i.name;return r}PatchNamedRanges(e,t,r,i,n){let o=[...this.list];for(let a of o){if(a.type==="expression")continue;let s=a.name,l=a.area;if(l.start.sheet_id!==e){console.info("skipping name",s);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(s);else if(t<=l.start.column){let d=t-r-1;this.SetName({type:"range",area:new y({row:l.start.row,column:d+1+r,sheet_id:e},{row:l.end.row,column:l.end.column+r}),name:s})}else t<=l.end.column?t-r-1>=l.end.column?this.SetName({type:"range",area:new y({row:l.start.row,column:l.start.column,sheet_id:e},{row:l.end.row,column:t-1}),name:s}):this.SetName({type:"range",name:s,area: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})}):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(s);else if(i<=l.start.row){let d=i-n-1;this.SetNamedRange(s,new y({column:l.start.column,row:d+1+n,sheet_id:e},{column:l.end.column,row:l.end.row+n}))}else i<=l.end.row?i-n-1>=l.end.row?this.SetNamedRange(s,new y({column:l.start.column,row:l.start.row,sheet_id:e},{column:l.end.column,row:i-1})):this.SetNamedRange(s,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})):console.warn("PNR X case 4",i,n,JSON.stringify(l))}}}};var it=class{parser=new He;document_name;user_data;sheets=new pt;named=new St(this.parser);macro_functions=new Map;view_count=0;theme_style_properties=JSON.parse(JSON.stringify(U.DefaultProperties));tables=new Map;GetName(e,t){let r=e.split(/!/);if(r.length===1)return this.named.Get_(e,t);let i=r[0];/^'.*?'$/.test(i)&&(i=i.substring(1,i.length-1));let n=this.sheets.ID(i);return this.named.Get_(r[1],n||0,!0)}UnserializeNames(e,t){this.parser.Save(),this.parser.SetLocaleSettings(".",",");for(let r of e){if(!r.expression)continue;let i=this.parser.Parse(r.expression);if(i.expression){let n=typeof r.scope=="string"?this.sheets.ID(r.scope):void 0;if(i.expression.type==="address"||i.expression.type==="range"){let[o,a]=i.expression.type==="range"?[i.expression.start,i.expression.end]:[i.expression,i.expression];if(o.sheet)if(/^\[\d+\]/.test(o.sheet))console.warn("named range refers to an external file");else{let s=new y({...o,sheet_id:this.sheets.ID(o.sheet)},a);s.start.sheet_id?this.named.SetNamedRange(r.name,s,n):console.warn("missing sheet ID?",o)}else console.warn("missing sheet name?",o)}else this.parser.Walk(i.expression,o=>o.type==="address"||o.type==="range"?(o.type==="range"&&(o=o.start),o.sheet_id||o.sheet&&(o.sheet_id=this.sheets.ID(o.sheet)),o.sheet_id||(o.sheet_id=t?.id),!1):!0),this.named.SetNamedExpression(r.name,i.expression,n)}}this.parser.Restore()}SerializeNames(e){let t=[];for(let r of this.named.list){let i={name:r.name,expression:""};if(r.scope&&(i.scope=this.sheets.Name(r.scope)),r.type==="expression")this.parser.Walk(r.expression,n=>{if(n.type==="address"||n.type==="range"){let o=n.type==="range"?n.start:n;return o.absolute_column=o.absolute_row=!0,o.sheet||(o.sheet_id&&(o.sheet=this.sheets.Name(o.sheet_id)),o.sheet||(o.sheet=e?.name)),n.type==="range"&&(n.end.absolute_column=n.end.absolute_row=!0),!1}return!0}),i.expression=this.parser.Render(r.expression,{missing:""});else{let n={start:{...r.area.start,absolute_column:!0,absolute_row:!0},end:{...r.area.end,absolute_column:!0,absolute_row:!0}};i.expression=this.AddressToLabel(n)}t.push(i)}return t}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 o=0;o<r.columns.length;o++)if(i===r.columns[o]){n=r.area.start.column+o;break}}if(!(n<0))if(e.scope==="row"){let o=t.row;return o<r.area.start.row||o>r.area.end.row?void 0:{label:e.label,type:"address",row:o,column:n,sheet_id:r.area.start.sheet_id,id:e.id,position:e.position}}else{let o=r.area.start.row,a=r.area.end.row;return e.scope==="column"&&(o++,r.totals_row&&a--),{label:e.label,type:"range",position:e.position,id:e.id,start:{type:"address",row:o,column:n,sheet_id:r.area.start.sheet_id,label:e.label,position:e.position,id:0},end:{type:"address",row:a,column:n,label:e.label,position:e.position,id:0}}}}AddressToLabel(e){let t=V(e)?e:e.start,r=V(e)?[y.CellAddressToLabel(e)]:[y.CellAddressToLabel(e.start),y.CellAddressToLabel(e.end)],i=this.sheets.Find(t.sheet_id||0),n=i?.name?xe.test(i.name)?`'${i.name}'`:i.name:"";return n+(n?"!":"")+(r[0]===r[1]?r[0]:r.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 V(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.GetName(r.expression.name,t.id);if(i?.type==="range")return i.area}return{row:0,column:0}}return e}AddConnectedElement(e){let t=this.connected_element_id++;return this.connected_elements.set(t,e),t}RemoveConnectedElement(e){let t=this.connected_elements.get(e);return this.connected_elements.delete(e),t}connected_element_id=100;connected_elements=new Map};var ke=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 _i=42,yi=95,Tr=63,At=48,vi=46,Rr=44,xi=37,Er=34,nt=35,wi=59,kt=92,Ci=64,Jn=91,Xn=93,Si=69,Ai=101,Qn=72,qn=104,Kn=77,eo=109,to=83,ro=115,io=68,no=100,oo=89,ao=121,so=65,lo=97;var Tt=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new ke;static preserve_formatting_characters=!1;static decimal_mark=vi;static group_separator=Rr;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new ke,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new ke,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 kt: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 Er: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 kt:throw new Error("invalid escape character in formatting block");case Xn: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===nt||n===At)r=!0;else if(n!==Rr)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 nt:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case At: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===Tr||e===nt)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case wi:this.char_index++,this.current_section=new ke,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case Ci:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case At:case nt:case vi:case Rr:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case Jn:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Er:this.AppendString(this.ConsumeString());break;case Tr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case yi: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 _i: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 Si: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 xi:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case kt: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 wi:this.char_index=this.characters.length;break;case At:case nt:case Ai:case Si:case xi:case Ci:this.date_pattern=!1;break;case Qn:case qn:case Kn:case eo:case to:case ro:case io:case no:case oo:case ao:this.AppendTextPart(this.ConsumeDatePart());break;case so:case lo:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Er:this.AppendString(this.ConsumeString());break;case Tr:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case yi: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 _i: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 kt: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 we=c=>(c>=60&&c--,new Date(-22090752e5+864e5*c)),Ce=(c,e=!0)=>{if(e){let t=new Date(c);c=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()).getTime()}return c=(c+22090752e5)/864e5,c>=60&&c++,c},ie=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=Tt.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new ke),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,o)=>{switch(n.flag){case 2:return r=o,n.text;case 1:return n.text.replace(/./g," ");case 6:return"";default:return n.text}});if(r>=0&&t){let n=i.reduce((a,s,l)=>l===r?a:a+s.length,0),o="";for(let a=0;a<t-n;a++)o+=i[r];i[r]=o}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(vr(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(s=>/[1-9]/.test(s.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 o=!!e.real;o&&(r=this.FormatParts(e.real),o=r.some(s=>/[1-9]/.test(s.text)));let a=[];if(o||!o&&!n){if(a.push(...r),n){a.push({text:e.imaginary<0?` ${c.minus_character} `:" + "});let s=i?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...s,{text:c.imaginary_character})}}else n&&a.push(...t,{text:c.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),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(N.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=we(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=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 s=o.text.split("/");return{text:t.getUTCHours()>12?s[1]:s[0]}}case"mmmmm":return{text:N.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:N.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:N.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:N.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:N.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:N.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:N.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:N.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:N.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 a=o.text.match(/^(s+)\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+N.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),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 o=2;o<=n;o++){let a=Math.round(e*o),s=Math.abs(a/o-e);if(s<r.error&&(r={numerator:a,denominator:o,error:s},!s))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,o=Math.abs(e);if(o<n&&(t=this.sections[2],r=this.decimal_zero_regexp[2]),t.scaling&&(o/=t.scaling,o<n&&(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 s=a.split(".");for(;s[0].length<t.integer_min_digits;)s[0]=("0000000000000000"+s[0]).slice(-t.integer_min_digits);return t.integer_min_digits===0&&s[0]==="0"&&(s[0]=""),t.grouping&&(s[0]=s[0].replace(c.grouping_regexp,"$&"+N.grouping_separator)),{parts:s,section:t}}};var z=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 ie(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 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}};z.InitCache();var ki=new Date().getUTCFullYear(),Ir=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(s=>s.trim()).filter(s=>!!s);if(!n.length)return t;if(!this.compare_month){this.compare_month={};for(let s=0;s<12;s++)this.compare_month[N.date_components.long_months[s].toLocaleLowerCase().replace(/\./,"")]=s,this.compare_month[N.date_components.short_months[s].toLocaleLowerCase().replace(/\./,"")]=s}if(!this.compare_day){this.compare_day={};for(let s=0;s<7;s++)this.compare_day[N.date_components.long_days[s].toLocaleLowerCase().replace(/\./,"")]=s,this.compare_day[N.date_components.short_days[s].toLocaleLowerCase().replace(/\./,"")]=s}let o=!1,a=!1;for(let s of n){let l=!1;for(let[d,h]of Object.entries(this.compare_month))if(s===d){if(o||r.getUTCMonth()!==h)return!1;l=!0,o=!0}if(!l){for(let[d,h]of Object.entries(this.compare_day))if(s===d){if(a||r.getUTCDay()!==h)return!1;l=!0,a=!0}}if(!l)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(),i=r.match(/^[$](.*?)$/);i&&(r=i[1],t.Currency=!0);let n=r.match(/^\((.*?)\)$/);n&&(r=n[1],t.Parens=!0);let o=r.match(/^(.*?)%\s*$/);o&&(r=o[1],t.Percent=!0),N.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 s=e.toLowerCase();if(s==="false")return{value:!1,type:4};if(s==="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>=ki-200&&h<=ki+200)return t={Date:!0},(d.getHours()||d.getMinutes()||d.getSeconds())&&(t.Time=!0),{value:Ce(l,!0),type:3,hints:t}}return{value:e,type:2}}if(n&&(a=-a),o){let s=a<0?-1:1,l=(s*a).toString().split(".");l[0]=("00"+l[0]).replace(/(\d\d)$/,".$1"),a=Number(l.join(""))*s}return/e/.test(e)&&(t.Exponential=!0),{value:a,type:3,hints:t}}},ce=new Ir;var Ti=()=>({target:{row:0,column:0},area:new y({row:0,column:0}),empty:!0});var co=100,Ri={move_with_cells:!0,resize_with_cells:!0,movable:!0,resizable:!0,removable:!0,selectable:!0},Ne=class{data={...Ri};get key(){return this.key_}rect;scaled_rect;temp={};view=[];dirty;key_=co++;constructor(e={}){this.data={...Ri,...JSON.parse(JSON.stringify(e))},e.rect&&(this.rect=G.Create(e.rect))}toJSON(){return{...this.data,rect:this.rect}}};var ho=100,Ei=60,X=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 yt;selection=Ti();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=[];data_validation=[];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=ho,this.row_header_width=Ei,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),r.data_validation=(i.data_validations||[]).map(l=>({...l,target:(l.target||[]).map(d=>new y(d.start,d.end))})),i.id&&(r.id=i.id),i.name&&(r.name=i.name),i.background_image&&(r.background_image=i.background_image);let o=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)},a=i.styles||i.cell_style_refs||[];for(let l of a)o(l);if(r.cell_style=[],a&&(i.cell_styles||[]).forEach(l=>{typeof l.ref=="number"&&(l.style=JSON.parse(JSON.stringify(a[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(rt(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(a[l.style_ref])));else if(Cr(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(a[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(a[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 s=(l,d)=>{for(let h of Object.keys(l)){let u=Number(h),m=l[u];if(typeof m=="number"){let f=a[m];f&&(d[u]=JSON.parse(JSON.stringify(f)),o(d[u]))}else m&&(d[u]=m,o(d[u]))}};s(i.row_style,r.row_styles),s(i.column_style,r.column_styles),r.row_pattern=i.row_pattern||[],o(r.sheet_style||{});for(let l of r.row_pattern)o(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 Ne(l)),i.selection&&(r.selection=JSON.parse(JSON.stringify(i.selection))),r.visible=!0,typeof i.visible<"u"&&(r.visible=!!i.visible),r}AddValidation(e){this.data_validation.push({...e,target:(e.target||[]).map(t=>new y(t.start,t.end))})}RemoveValidations(e){let t=new y(e.start,e.end);this.data_validation=this.data_validation.filter(r=>(r.target=r.target.filter(i=>!t.Equals2(i)),r.target.length>0))}GetValidation(e){let t=[];for(let r of this.data_validation)for(let i of r.target)if(i.Contains(e)){t.push(r);break}return t}Activate(e){if(this.background_image){let t=wt(this.background_image);t&&(this._image=e.Create("img"),this._image.src=t)}}MergeCells(e){e=e.Clone();let t=[...this.cells.Iterate(e,!0)];for(let[r,i]of t.entries())i.merge_area=e,i.render_clean=[],r&&i.Reset()}UnmergeCells(e){for(let t of this.cells.Iterate(e,!1))if(!t.merge_area||!e.Equals(t.merge_area)){console.warn("area mismatch");return}for(let t of this.cells.Iterate(e,!1))t.merge_area=void 0,t.render_clean=[]}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=ye.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 o=e[n],a=t[n];typeof o=="object"&&typeof a=="object"?JSON.stringify(o)!==JSON.stringify(a)&&(r[n]=a):o!==a&&(r[n]=a)}return r}UpdateCellStyle(e,t,r=!0){let{row:i,column:n}=e;this.cell_style[n]||(this.cell_style[n]=[]);let o=this.CompositeStyleForCell(e,!1,!1,void 0,!1),a=U.Composite([this.default_style_properties,o,U.Merge(this.cell_style[n][i]||{},t,r)]),s=this.Delta(o,a);this.cell_style[n][i]=s,this.BleedFlush({start:e,end:e})}Invalidate(e){for(let t of this.cells.Iterate(this.RealArea(e),!1))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 for(let i of e)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 o=e.area.end.row;for(;o>=e.area.start.row;o--)if(this.GetRowHeight(o)){r.last=o===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,o=e.row+1,a=e.row-1;for(;this.column_width_[i]===0;i++);for(;this.row_height_[o]===0;o++);for(;n>=0&&this.column_width_[n]===0;n--);for(;a>=0&&this.row_height_[a]===0;a--);return n>=0&&a>=0&&(r[7]=this.CellStyleData({row:a,column:n},t)||{}),n>=0&&(r[4]=this.CellStyleData({row:e.row,column:n},t)||{},r[1]=this.CellStyleData({row:o,column:n},t)||{}),a>=0&&(r[8]=this.CellStyleData({row:a,column:e.column},t)||{},r[9]=this.CellStyleData({row:a,column:i},t)||{}),r[6]=this.CellStyleData({row:e.row,column:i},t)||{},r[2]=this.CellStyleData({row:o,column:e.column},t)||{},r[3]=this.CellStyleData({row:o,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)),o=this.TableRow(r.table,e.row);return o.header?i.header&&(n=U.Composite([n,i.header])):o.totals?i.total&&(n=U.Composite([n,i.total])):o.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 o=z.Get(t.style.number_format||"",!0);t.formatted=o.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=z.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=z.Get(t).FormatParts(e);return r.length?r.length===1&&!r[0].flag?r[0].text||"":r:""}SetHeaderSize(e=Ei,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 o=0;o<this.cells.columns;o++){let a=this.CellData({row:e,column:o}),s=a.style,l=a.formatted||"";if(typeof l!="string"&&(l=l.map(d=>d.text).join("")),s&&l&&l.length){let d=l.split(/\n/),h=Math.round(this.StyleFontSize(s,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 s=0;s<this.cells.columns;s++){let l=this.cells.GetCell({row:e-1,column:s},!1);if(l&&l.area){let d=this.cells.GetCell({row:e,column:s},!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 s=e;s<this.cells.rows;s++)for(let l=0;l<this.cells.columns;l++){let d=this.cells.GetCell({row:s,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 s of Object.keys(i)){let l=i[s],d=new y({row:l.start.row+t,column:l.start.column},{row:l.end.row+t,column:l.end.column});for(let h of d){let u=this.cells.GetCell(h,!0);u.area=d}}for(let s of Object.keys(r)){let l=r[s],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});for(let u of h){let m=this.cells.GetCell(u,!0);m.merge_area=h}}let n=Object.keys(this.row_styles),o={};n.forEach(s=>{let l=Number(s);l<e?o[l]=this.row_styles[l]:t<0&&l<e-t||(o[l+t]=this.row_styles[l])}),this.row_styles=o;let a=[];if(t<0)a=[e,-t];else{a=[e,0];for(let s=0;s<t;s++)a.push(void 0)}return this.cell_style.forEach(s=>{s&&s.length>=e&&s.splice.apply(s,a)}),this.row_height_.splice.apply(this.row_height_,a),this.FlushCellStyles(),!0}InsertColumns(e=0,t=1){if(e)for(let s=0;s<this.cells.rows;s++){let l=this.cells.GetCell({row:s,column:e-1},!1);if(l&&l.area){let d=this.cells.GetCell({row:s,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 s=e;s<this.cells.columns;s++)for(let l=0;l<this.cells.rows;l++){let d=this.cells.GetCell({row:l,column:s},!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 s of Object.keys(i)){let l=i[s],d=new y({row:l.start.row,column:l.start.column+t},{row:l.end.row,column:l.end.column+t});for(let h of d){let u=this.cells.GetCell(h,!0);u.area=d}}for(let s of Object.keys(r)){let l=r[s],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});for(let u of h){let m=this.cells.GetCell(u,!0);m.merge_area=h}}let n=Object.keys(this.column_styles),o={};n.forEach(s=>{let l=Number(s);l<e?o[l]=this.column_styles[l]:t<0&&l<e-t||(o[l+t]=this.column_styles[l])}),this.column_styles=o;let a=[];if(t<0)a=[e,-t];else{a=[e,0];for(let s=0;s<t;s++)a.push(void 0)}return this.cell_style.splice.apply(this.cell_style,a),this.column_width_.splice.apply(this.column_width_,a),this.FlushCellStyles(),!0}ClearArea(e){for(let t of this.cells.Iterate(this.RealArea(e),!1))t.Reset()}SetAreaValues2(e,t){e=this.RealArea(e),this.cells.SetArea(e,t)}SetArrayValue(e,t){e=this.RealArea(e);for(let i of this.cells.Iterate(e,!0))i.SetArray(e);this.cells.GetCell(e.start,!0).SetArrayHead(e,t)}SetCellValue(e,t){this.cells.GetCell(e,!0).Set(t)}TablesFromArea(e,t=!1){if(V(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 o=this.cells.GetCell({row:i,column:n},!1);o?.table&&!r.has(o.table)&&(!t||i===o.table.area.start.row)&&r.add(o.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(V(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 o=e.start.column;o<=e.end.column;o++)n.push(this.CompositeStyleForCell({row:i,column:o},!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 o=e.column;o<=t.column;o++)n.push(this.FormattedCellValue({row:i,column:o}));r.push(n)}return r}NumberFormatsAndColors(e,t){let r=i=>{i.number_format&&(t[i.number_format]=1),J(i.text)&&(e[i.text.text]=1),J(i.fill)&&(e[i.fill.text]=1),J(i.border_top_fill)&&(e[i.border_top_fill.text]=1),J(i.border_left_fill)&&(e[i.border_left_fill.text]=1),J(i.border_right_fill)&&(e[i.border_right_fill.text]=1),J(i.border_bottom_fill)&&(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 o=i[n];if(o){let a=n+1;for(;a<i.length&&i[a]===o;a++);a>n+1?t.push({row:n,column:r,ref:o,rows:a-n}):t.push({row:n,column:r,ref:o}),n=a-1}}}return t}toJSON(e={}){let t=(w,A)=>{let S={};for(let I=0;I<w.length;I++)typeof w[I]<"u"&&w[I]!==A&&(S[I]=w[I]);if(Object.keys(S).length)return S},r=[{}],i={},n=[],o=JSON.stringify({});for(let w=0;w<this.cell_style.length;w++){let A=this.cell_style[w];if(A){n[w]=[];for(let S=0;S<A.length;S++)if(A[S]){let I=JSON.stringify(A[S]);if(I!==o){let L=i[I];typeof L!="number"&&(i[I]=L=r.length,r.push(A[S])),n[w][S]=L}}}}let a=w=>{let A=JSON.stringify(w);if(A===o)return 0;let S=i[A];return typeof S!="number"&&(i[A]=S=r.length,r.push(w)),S};r=JSON.parse(JSON.stringify(r));let s=JSON.parse(JSON.stringify(this.sheet_style)),l=JSON.parse(JSON.stringify(this.row_pattern)),d={},h={};for(let w of Object.keys(this.column_styles)){let A=Number(w),S=this.column_styles[A];if(S){let I=a(S);I&&(d[A]=I)}}if(this.row_pattern&&this.row_pattern.length&&e.apply_row_pattern){let w=this.rows+1;for(let A of Object.keys(this.row_styles)){let S=Number(A);!isNaN(S)&&S>=w&&(w=S+1)}for(let A=0;A<w;A++){let S=this.row_pattern[A%this.row_pattern.length],I=this.row_styles[A]||{},L=U.Composite([S,I]),O=a(L);O&&(h[A]=O)}}else for(let w of Object.keys(this.row_styles)){let A=Number(w),S=this.row_styles[A];if(S){let I=a(S);I&&(h[A]=I)}}let u=(w={},A={})=>{let S={...A,...w};if(J(S))return S.text=ye.MeasureColorARGB(S.text),S;if(Ze(S))return S};if(e.export_colors){let w=[];for(let A of[r,[s],l])if(Array.isArray(A))for(let S of A)w.push(S);else for(let S of Object.keys(A))w.push(A[S]);for(let A of w){let S=u(A.border_top_fill,U.DefaultProperties.border_top_fill);S!==void 0&&(A.border_top_fill=S),S=u(A.border_left_fill,U.DefaultProperties.border_left_fill),S!==void 0&&(A.border_left_fill=S),S=u(A.border_right_fill,U.DefaultProperties.border_right_fill),S!==void 0&&(A.border_right_fill=S),S=u(A.border_bottom_fill,U.DefaultProperties.border_bottom_fill),S!==void 0&&(A.border_bottom_fill=S),J(A.fill)&&(A.fill.text=ye.MeasureColorARGB(A.fill.text)),J(A.text)&&(A.text.text=ye.MeasureColorARGB(A.text.text))}}let m={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},f=this.cells.toJSON(m),p=f.data,{rows:b,columns:g}=f;e.shrink?(b+=2,g+=1):(b=this.rows,g=this.columns);for(let w of this.annotations)w.data.extent||this.CalculateAnnotationExtent(w),w.data.extent&&(b=Math.max(b,w.data.extent.row+1),g=Math.max(g,w.data.extent.column+1));let C=this.CompressCellStyles(n),x=this.conditional_formats.length?JSON.parse(JSON.stringify(this.conditional_formats.map(w=>({...w,internal:void 0})))):void 0,v=this.data_validation.length?JSON.parse(JSON.stringify(this.data_validation)):void 0,_={id:this.id,name:this.name,data:p,sheet_style:s,rows:b,columns:g,cell_styles:C,styles:r,row_style:h,column_style:d,conditional_formats:x,data_validations:v,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||(_.visible=this.visible),(this.scroll_offset.x||this.scroll_offset.y)&&(_.scroll=this.scroll_offset),this.background_image&&(_.background_image=this.background_image),(this.freeze.rows||this.freeze.columns)&&(_.freeze=this.freeze),_}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 o=0;o<i.length;o++)i[o]&&this.UpdateAreaStyle(new y({row:1/0,column:o},{row:1/0,column:o}),t[i[o]]);if(e.row_styles)for(let[o,a]of e.row_styles.entries())a&&this.UpdateAreaStyle(new y({row:o,column:1/0}),t[a]);this.cells.FromJSON(e.cells),e.name&&(this.name=e.name||"");let n=this.cell_style;for(let o of e.cells)o.style_ref&&(n[o.column]||(n[o.column]=[]),n[o.column][o.row]=t[o.style_ref]);for(let o=0;o<e.column_widths.length;o++)typeof e.column_widths[o]<"u"&&this.SetColumnWidth(o,e.column_widths[o]);for(let o=0;o<e.row_heights.length;o++)typeof e.row_heights[o]<"u"&&this.SetRowHeight(o,e.row_heights[o]);for(let o of e.annotations||[])this.annotations.push(new Ne(o));for(let o of e.conditional_formats||[])this.conditional_formats.push(o);for(let o of e.data_validations||[])this.AddValidation(o);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(o=>delete n[o]);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(o=>delete n[e][o]);for(let n=0;n<this.cells.columns;n++)if(this.column_styles[n]){let o=this.column_styles[n],a=this.cell_style[n]?this.cell_style[n][e]||{}:{};for(let s of i)typeof o[s]<"u"&&(a[s]=t[s]);Object.keys(a).length&&(this.cell_style[n]||(this.cell_style[n]=[]),this.cell_style[n][e]=JSON.parse(JSON.stringify(a)))}for(let n of this.cells.Iterate(this.RealArea(y.FromRow(e))))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(o=>delete n[o]);for(let n of this.cells.Iterate(this.RealArea(y.FromColumn(e))))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){i.internal?.vertex?.updated&&(i.internal.vertex.updated=!1);let n=JSON.parse(JSON.stringify(i.area));(n.start.row===null||n.end.row===null)&&(n.start.row=0,n.end.row=this.cells.rows-1),(n.start.column===null||n.end.column===null)&&(n.start.column=0,n.end.column=this.cells.columns-1);let o=i.internal?.vertex?.result;if(i.type==="gradient"){if(o&&i.internal?.gradient){let a=i.property??"fill";if(o.type===8)for(let s=n.start.row;s<=n.end.row;s++)for(let l=n.start.column;l<=n.end.column;l++){let d=o.value[l-n.start.column][s-n.start.row];if(d.type===3){t[s]||(t[s]=[]),t[s][l]||(t[s][l]=[]);let h=i.internal.gradient.Interpolate(d.value);t[s][l].push({[a]:h})}}else if(o.type===3){let s=i.internal.gradient.Interpolate(o.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({[a]:s})}}r.push(n),this.conditional_format_checklist.push(n)}}else if(o){if(o.type===8)for(let a=n.start.row;a<=n.end.row;a++)for(let s=n.start.column;s<=n.end.column;s++){let l=o.value[s-n.start.column][a-n.start.row];l&&(l.type===4||l.type===3)&&l.value&&(t[a]||(t[a]=[]),t[a][s]||(t[a][s]=[]),t[a][s].push(i.style))}else if((o.type===4||o.type===3)&&o.value)for(let a=n.start.row;a<=n.end.row;a++){t[a]||(t[a]=[]);for(let s=n.start.column;s<=n.end.column;s++)t[a][s]||(t[a][s]=[]),t[a][s].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:o,column:a}=e,s=[];return i&&s.push(this.default_style_properties),s.push(this.sheet_style),r&&this.row_pattern.length&&s.push(this.row_pattern[o%this.row_pattern.length]),this.row_styles[o]&&s.push(this.row_styles[o]),this.column_styles[a]&&s.push(this.column_styles[a]),t&&this.cell_style[a]&&this.cell_style[a][o]&&s.push(this.cell_style[a][o]),n&&s.push(...this.ConditionalFormatForCell(e)),U.Composite(s)}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 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 Rt=class{constructor(e,t,r={x:0,y:0},i){this.theme=t;this.offset=r;let n=P.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 Ue=class{constructor(e,t,r){this.theme=e;this.container=t;this.orientation=r;let i=P.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 Et=class{constructor(e,t,r,i,n,o){this.theme=e;this.layout=t;this.model=r;this.view=i;this.primary_selection=n;this.additional_selections=o}nub_rectangle=new G(-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 Ue(this.theme,this.layout.row_header_selection,0),this.column_overlay=new Ue(this.theme,this.layout.column_header_selection,1),this.corner_row_overlay=new Ue(this.theme,this.layout.corner_selection,0),this.corner_column_overlay=new Ue(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 G(-1,-1,0,0);if(!this.primary_selection.empty){let s=this.view.active_sheet.RealArea(this.primary_selection.area);n=this.layout.CellAddressToRectangle(s.start).Combine(this.layout.CellAddressToRectangle(s.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 o=[],a=[];if(this.primary_selection.empty)o.push(!1),a.push(!1);else{let s=this.primary_selection.area.start;o.push(s.row<=this.view.active_sheet.freeze.rows||s.row===1/0),a.push(s.column<=this.view.active_sheet.freeze.columns||s.column===1/0)}for(let{area:s}of this.additional_selections)o.push(s.start.row<=this.view.active_sheet.freeze.rows||s.start.row===1/0),a.push(s.start.column<=this.view.active_sheet.freeze.columns||s.start.column===1/0);this.view.active_sheet.freeze.rows&&this.RenderSelectionGroup(i,this.layout.row_header_selection,o,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,a,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,a,o,this.corner_selections,{...this.layout.header_offset}),this.primary_selection.empty=r}RenderSelectionGroup(e,t,r,i,n,o,a=!0){for(let s=0;s<e.length;s++)if((!e[s].area.start.sheet_id||e[s].area.start.sheet_id===this.view.active_sheet.id)&&!e[s].empty&&(!r||r[s])&&(!i||i[s])){if(a||!e[s].rendered){let d=this.EnsureGridSelectionBlock(t,n,s,o);this.RenderSVGSelection(e[s],d,s)}}else n[s]&&n[s].Show(!1);for(let s=e.length;s<n.length;s++)n[s]&&n[s].Show(!1)}EnsureGridSelectionBlock(e,t,r,i){let n=t[r];if(!n)if(n=new Rt(!r,this.theme,void 0,e),t[r]=n,r){let o=e.querySelector(".alternate-selections");o||(o=this.layout.DOM.SVG("g","alternate-selections"),e.appendChild(o)),o?.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 o=this.view.active_sheet.CellData(e.target);o.merge_area&&(n=this.layout.CellAddressToRectangle(o.merge_area.start),n=n.Combine(this.layout.CellAddressToRectangle(o.merge_area.end)))}if(r||(this.nub_rectangle=new G(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 o=this.layout.CellAddressToRectangle(e.target),a=this.view.active_sheet.CellData(e.target);a.merge_area&&(o=this.layout.CellAddressToRectangle(a.merge_area.start),o=o.Combine(this.layout.CellAddressToRectangle(a.merge_area.end))),t.SetFill(o,n),t.SetNub(n)}t.Show()}};function ve(c,e=[],t,r){typeof e=="string"&&(e=[e]);let i,n=a=>{a.stopPropagation(),a.preventDefault(),i(),r&&r(a)},o=a=>{if(a.stopPropagation(),a.preventDefault(),!a.buttons){i(),r&&r(a);return}t&&t(a)};i=()=>{c.style.display="none",c.removeEventListener("mousemove",o),c.removeEventListener("mouseup",n);for(let a of e)c.classList.remove(a)};for(let a of e)c.classList.add(a);c.style.display="block",t&&c.addEventListener("mousemove",o),r&&c.addEventListener("mouseup",n)}var Mt=class extends le{constructor(t){super();this.container=t;this.format=z.Get("0.0");let r=P.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 o=ce.TryParse(n);o.type===3?this.UpdateScale(Number(o.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 It=class extends le{constructor(t,r,i,n,o){super();this.layout=t;this.model=r;this.view=i;this.options=n;if(this.DOM=P.GetInstance(o.ownerDocument),this.container=o.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",a=>{let s=a.target?.dataset.command;if(s)switch(a.stopPropagation(),a.preventDefault(),s){case"add-tab":this.Publish({type:"add-sheet"});break;case"delete-tab":this.Publish({type:"delete-sheet"});break;default:console.info("unhandled command",s)}}),this.options.stats&&(this.stats_panel=this.container.querySelector(".treb-stats-panel")),this.options.scale_control){let a=this.container.querySelector(".treb-scale-control");this.scale_control=new Mt(a),this.scale_control.Subscribe(s=>{this.Publish(s)}),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 o=this.DOM.doc.createRange();o.selectNodeContents(r),n.addRange(o)}}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,o){if(t.stopPropagation(),t.preventDefault(),this.IsDoubleClick(n))return;this.Publish({type:"activate-sheet",sheet:i});let a=o.map(p=>p.getBoundingClientRect()),s=n*2-1,l=a[0].left,d=a[a.length-1].right,h=a[0].top,u=a[0].bottom,m=-1,f=(a.length-1)*2+1;for(let p of o)this.SetActive(p,p===r);this.dragging=!0,ve(this.layout.mask,[],p=>{let[b,g]=[p.clientX,p.clientY];if(g>h&&g<u){let C=s;if(b<l)C=m;else if(b>d)C=f;else for(let x=0;x<a.length;x++){let v=a[x];if(b>=v.left&&b<=v.right){x!==n&&(b>=v.left+v.width/2?C=x*2+1:C=x*2-1);break}}C!==s&&(s=C,r.style.order=s.toString(),a=o.map(x=>x.getBoundingClientRect()))}},()=>{let p=n,b=(s+1)/2;this.dragging=!1;for(let g=0;g<this.model.sheets.length;g++)this.model.sheets.list[g].visible||(p>=g&&p++,b>=g&&b++);p===b||p===0&&b<=0||p===o.length-1&&b>=o.length-1||this.Publish({type:"reorder-sheet",index:p,move_before:b})})}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 o=s=>this.MouseDownTab(s,n,r,i,t),a=s=>{n.removeEventListener("mousedown",o),n.removeEventListener("dblclick",a),this.DoubleClickTab(s,n,r)};n.textContent=r.name,n.addEventListener("dblclick",a),n.addEventListener("mousedown",o),this.tab_container.appendChild(n),t.push(n)}}};var Be=class{constructor(e,t,r=!1,i=P.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",o=>{o.stopPropagation(),o.preventDefault(),this.grid_cover.classList.remove("nub-select");let a=this.dropdown_caret.getAttribute("class")||"";/active/i.test(a)?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",o=>{let a=0;switch(o.key){case"ArrowDown":a=1;break;case"ArrowUp":a=-1;break;case"Escape":break;case"Enter":break;default:console.info(o.key);return}if(o.stopPropagation(),o.preventDefault(),o.key==="Escape"||o.key==="Enter"){if(this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),o.key==="Enter"&&this.dropdown_callback&&this.dropdown_selected){let s=this.dropdown_selected.dataset.dropdown_value;this.dropdown_callback.call(0,s?JSON.parse(s):void 0)}}else if(a&&this.dropdown_selected)if(a>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 s=this.dropdown_selected.offsetTop+this.dropdown_selected.offsetHeight;s>this.dropdown_list.offsetHeight+this.dropdown_list.scrollTop&&(this.dropdown_list.scrollTop=s-this.dropdown_list.offsetHeight)}else a<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",o=>{let a=o.target;if(o.target!==this.dropdown_list&&(o.stopPropagation(),o.preventDefault(),this.container?.focus(),this.dropdown_caret.setAttribute("class","treb-dropdown-caret"),this.dropdown_callback)){let s=a.dataset.dropdown_value;this.dropdown_callback.call(0,s?JSON.parse(s):void 0)}}),this.dropdown_list.addEventListener("mousemove",o=>{let a=o.target;a!==this.dropdown_selected&&(this.grid_cover.classList.remove("nub-select"),this.dropdown_selected&&this.dropdown_selected.classList.remove("selected"),a.classList.add("selected"),this.dropdown_selected=a)}),this.mock_selection=i.Div("mock-selection-node",void 0,{html:"&nbsp;"}),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 o=this.OffsetCellAddressToRectangle(r).Shift(this.header_size.width,this.header_size.height),a=this.sort_button.getBoundingClientRect();this.sort_button.style.left=o.right-a.width-a.width/2+"px",this.sort_button.style.top=o.top+(o.height-a.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(),o=this.note_node.parentElement.getBoundingClientRect(),a={x:8,y:2},s=this.OffsetCellAddressToRectangle(t).Shift(this.header_size.width,this.header_size.height);this.note_node.style.left=o.left+s.right-this.scroll_reference_node.scrollLeft+a.x+"px",this.note_node.style.top=o.top+s.top-this.scroll_reference_node.scrollTop-n.height/5-a.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 o=this.view.active_sheet.annotations[n].key,a=this.container?.querySelectorAll(`.annotation[data-key="${o}"]`);if(a)for(let s=0;s<a?.length;s++)a[s].style.zIndex=(n+1).toString()}return!0}PointToAnnotationCorner(e){let t=this.PointToAddress_Grid(e,!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 G(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"),o=r.querySelector(".annotation-resize-target");r.addEventListener("mousedown",a=>{let s=i.node;requestAnimationFrame(()=>{s?.focus()}),this.AnnotationMouseDown(e,i.node,a,n,o)}),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 o=e.scaled_rect;return o?new Promise(a=>{let s={left:o.left,top:o.top,width:o.width,height:o.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-o.left,y:h.top+r.offsetY-o.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);ve(this.mask,"move",b=>{if(b.offsetY-d.top<this.header_offset.y){let g=Math.min(f,l.scrollTop);l.scrollTop-=g,u.y+=g}else if(b.offsetY-d.top>=d.height&&l.scrollTop+d.height<p.height){let g=f;l.scrollTop+=g,u.y-=g}if(b.offsetX-d.left<this.header_offset.x){let g=Math.min(f,l.scrollLeft);l.scrollLeft-=g,u.x+=g}else if(b.offsetX-d.left>=d.width&&l.scrollLeft+d.width<p.width){let g=f;l.scrollLeft+=g,u.x-=g}if(o.top=b.offsetY-u.y,o.left=b.offsetX-u.x,b.shiftKey){let g=Math.abs(o.left-s.left),C=Math.abs(o.top-s.top);g<=C?o.left=s.left:o.top=s.top}if(b.ctrlKey){let g=this.ClampToGrid({x:o.left,y:o.top});o.left=g.x,o.top=g.y}for(let g of m)g.style.top=o.top+"px",g.style.left=o.left+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(o),a({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-o.width+n.offsetLeft,y:m.top+r.offsetY-o.height+n.offsetTop};ve(this.mask,"nw-resize",p=>{let b=[t,...this.GetFrozenAnnotations(e)];if(o.height=p.offsetY-f.y,o.width=p.offsetX-f.x,p.shiftKey&&p.ctrlKey){if(u){let g=Math.abs(o.width-s.width),C=Math.abs(o.height-s.height);g<C?o.width=u*o.height:o.height=o.width/u}}else if(p.shiftKey){let g=Math.abs(o.height-s.height),C=Math.abs(o.width-s.width);g>C?o.width=s.width:o.height=s.height}else if(p.ctrlKey){let g=this.ClampToGrid({x:o.right,y:o.bottom});o.width=g.x-o.left+1,o.height=g.y-o.top+1}for(let g of b)g.style.height=o.height+"px",g.style.width=o.width+"px"},()=>{e.data.extent=void 0,e.data.layout=this.RectToAnnotationLayout(o),a({type:"annotation",annotation:e,event:"resize"})});return}else a()}):(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,o,a,s=!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=o,l.pixel_end={x:o.x+t.width,y:o.y+t.height},l.dirty=!!s,l.needs_full_repaint=!0,a.appendChild(l),l}ApplyTheme(e){this.row_header.style.backgroundColor=this.column_header.style.backgroundColor=this.corner.style.backgroundColor=e.headers?.fill?R(e,e.headers.fill,0):"",this.corner.style.borderColor=e.grid_color||"";for(let t of this.grid_tiles)for(let r of t)r.style.backgroundColor=R(e,e.grid_cell?.fill,0)||"#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.style.fontSize=this.scale.toFixed(2)+"em",this.dropdown_list.textContent="";for(let o of t){let a=this.DOM.Div(void 0,this.dropdown_list);r===o&&(this.dropdown_selected=a,a.classList.add("selected")),a.dataset.dropdown_value=JSON.stringify(o),a.textContent=o?.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 o={left:this.scroll_reference_node.scrollLeft,top:this.scroll_reference_node.scrollTop},a={left:t?n.left:o.left,top:r?n.top:o.top,behavior:"smooth"};this.scroll_reference_node.scrollTo(a)}else r&&(this.scroll_reference_node.scrollTop=n.top),t&&(this.scroll_reference_node.scrollLeft=n.left)}ScrollIntoView(e,t=!1){let r=this.CellAddressToRectangle(e),i=this.scroll_reference_node.clientWidth-this.row_header.offsetWidth,n=this.scroll_reference_node.clientHeight-this.column_header.offsetHeight,o={x:0,y:0},a={x:!1,y:!1},s=new G(this.scroll_reference_node.scrollLeft,this.scroll_reference_node.scrollTop,i,n);(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?o.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?o.x=this.frozen_column_tiles[0].logical_size.width:this.view.active_sheet.freeze.columns&&(a.x=!0));let l={behavior:t?"smooth":"auto"};e.row!==1/0&&(r.top<s.top+o.y&&!a.y?l.top=r.top-o.y:r.bottom>s.bottom&&(l.top=r.bottom-n)),e.column!==1/0&&(r.left<s.left+o.x&&!a.x?l.left=r.left-o.x:r.right>s.right&&(l.left=r.right-i)),this.scroll_reference_node.scrollTo(l)}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=!0){if(t){if(this.view.active_sheet.freeze.rows){let o=this.frozen_row_tiles[0].logical_size.height;e.y-this.scroll_reference_node.scrollTop<o&&(e.y-=this.scroll_reference_node.scrollTop)}if(this.view.active_sheet.freeze.columns){let o=this.frozen_column_tiles[0].logical_size.width;e.x-this.scroll_reference_node.scrollLeft<o&&(e.x-=this.scroll_reference_node.scrollLeft)}}let r={row:0,column:0},i=this.grid_tiles[this.grid_tiles.length-1],n=i[i.length-1];if(e.y>n.pixel_end.y){let o=e.y-n.pixel_end.y;for(r.row=n.last_cell.row;o>0;)r.row++,o-=this.default_row_height}else for(let o of i)if(o.pixel_start.y<=e.y&&o.pixel_end.y>=e.y){let a=e.y-o.pixel_start.y,s=0;for(r.row=o.first_cell.row;r.row<=o.last_cell.row&&(s=this.RowHeight(r.row),!(s>a));r.row++,a-=s);break}if(e.x>n.pixel_end.x){let o=e.x-n.pixel_end.x;for(r.column=n.last_cell.column;o>0;)r.column++,o-=this.default_column_width}else for(let o of this.grid_tiles)if(o[0].pixel_start.x<=e.x&&o[0].pixel_end.x>=e.x){let a=o[0],s=e.x-a.pixel_start.x,l=0;for(r.column=a.first_cell.column;r.column<=a.last_cell.column&&(l=this.ColumnWidth(r.column),!(l>s));r.column++,s-=l);break}return r}AdjacentTile(e,t=0,r=0){if(!t&&!r)return e;let i=e.tile_position,n=e.tile_position.row+t,o=e.tile_position.column+r;if(!(n<0||o<0)){if(this.grid_tiles[i.column]&&this.grid_tiles[i.column][i.row]===e&&this.grid_tiles[o])return this.grid_tiles[o][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[o]}}UpdateTiles(){if(!this.container)throw new Error("invalid container");this.grid_tiles.forEach(v=>{v.forEach(_=>{_.parentElement&&_.parentElement.removeChild(_)})});for(let v of[this.column_header_tiles,this.row_header_tiles,this.frozen_row_tiles,this.frozen_column_tiles])for(let _ of v)_.parentElement&&_.parentElement.removeChild(_);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 v=0;v<t;v++)i+=this.RowHeight(v);for(let v=0;v<r;v++)n+=this.ColumnWidth(v);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 v=Math.ceil((this.container.offsetWidth-n)/this.default_column_width);n+=v*this.default_column_width,r+=v}if(this.last_column=r,this.container.clientHeight>i+this.header_size.height){let v=Math.ceil((this.container.offsetHeight-i)/this.default_row_height);i+=v*this.default_row_height,t+=v}this.column_header.style.width=this.contents.style.width=`${n}px`,this.row_header.style.height=this.contents.style.height=`${i}px`;let o=[],a=[],s=0,l=0;for(let v=0;v<r;v++){let _=this.ColumnWidth(v);s&&s+_>this.default_tile_size.width&&(o.push(s),a.push(l),l=v,s=0),s+=_}o.push(s),a.push(l);let d=[],h=[],u=0,m=0;for(let v=0;v<t;v++){let _=this.RowHeight(v);u&&u+_>this.default_tile_size.height&&(d.push(u),h.push(m),u=0,m=v),u+=_}d.push(u),h.push(m);let f=o.length,p=d.length,b=0,g=0,C=0,x=0;for(let v=0;v<this.view.active_sheet.freeze.rows;v++)C+=this.RowHeight(v);for(let v=0;v<this.view.active_sheet.freeze.columns;v++)x+=this.ColumnWidth(v);for(let v=0;v<f;v++){let _=[];b=0;let w=v===f-1?r-a[v]:a[v+1]-a[v];this.column_header_tiles.push(this.CreateTile("column-header-tile",{height:this.header_offset.y,width:o[v]},{row:0,column:v},{row:0,column:a[v]},{rows:0,columns:w},{x:g,y:0},this.column_header)),this.view.active_sheet.freeze.rows&&this.frozen_row_tiles.push(this.CreateTile("frozen-row-tile",{height:C,width:o[v]},{row:1,column:v},{row:0,column:a[v]},{rows:0,columns:w},{x:g,y:0},this.column_header));for(let A=0;A<p;A++){let S=A===p-1?t-h[A]:h[A+1]-h[A];v||(this.row_header_tiles.push(this.CreateTile("row-header-tile",{height:d[A],width:this.header_offset.x},{row:A,column:0},{row:h[A],column:0},{rows:S,columns:1},{x:0,y:b},this.row_header)),this.view.active_sheet.freeze.columns&&this.frozen_column_tiles.push(this.CreateTile("frozen-column-tile",{height:d[A],width:x},{row:A,column:1},{row:h[A],column:0},{rows:S,columns:1},{x:0,y:b},this.row_header))),_.push(this.CreateTile("grid-tile",{height:d[A],width:o[v]},{row:A,column:v},{row:h[A],column:a[v]},{rows:S,columns:w},{x:g,y:b},this.contents)),b+=d[A]}this.grid_tiles.push(_),g+=o[v]}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 o=r.row;o<=i.row;o++)this.grid_tiles[n][o].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 o of this.grid_tiles){let a=o[0];if(a.pixel_start.x<=t&&a.pixel_end.x>=t){for(a of o)if(a.pixel_start.y<=i&&a.pixel_end.y>=i){e[0]=a.tile_position;break}}if(o===this.grid_tiles[this.grid_tiles.length-1]||a.pixel_start.x<=r&&a.pixel_end.x>=r){for(a of o)if(a===o[o.length-1]||a.pixel_start.y<=n&&a.pixel_end.y>=n)return e[1]=a.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 o=0;for(let s=n.first_cell.row;s<=n.last_cell.row;s++)o+=this.RowHeight(s);let a=n.logical_size.height===o;if(n.pixel_start.y=r,r+=o,n.pixel_end.y=r,!a){if(n.logical_size.height=o,n.style.height=`${o}px`,n.height=this.dpr*o,this.view.active_sheet.freeze.columns){let s=this.frozen_column_tiles[i];s.logical_size.height=o,s.style.height=`${o}px`,s.height=this.dpr*o}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let s of this.grid_tiles){let l=s[i];l.pixel_start.y=n.pixel_start.y,l.pixel_end.y=n.pixel_end.y,a||(l.logical_size.height=o,l.style.height=`${o}px`,l.height=this.dpr*o,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],o=this.grid_tiles[i];if(t>n.last_cell.column){r+=n.logical_size.width;continue}let a=0;for(let l=n.first_cell.column;l<=n.last_cell.column;l++)a+=this.ColumnWidth(l);let s=n.logical_size.width===a;if(n.pixel_start.x=r,r+=a,n.pixel_end.x=r,!s){if(n.logical_size.width=a,n.style.width=`${a}px`,n.width=this.dpr*a,this.view.active_sheet.freeze.rows){let l=this.frozen_row_tiles[i];l.logical_size.width=a,l.style.width=`${a}px`,l.width=this.dpr*a}e&&(n.dirty=!0,n.needs_full_repaint=!0)}for(let l of o)l.pixel_start.x=n.pixel_start.x,l.pixel_end.x=n.pixel_end.x,s||(l.logical_size.width=a,l.style.width=`${a}px`,l.width=this.dpr*a,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 o=this.column_cache.length-1;o<=r;o++)this.column_cache[o+1]=this.column_cache[o]+this.ColumnWidth(o)}if(this.row_cache.length<=t+1){this.row_cache.length||(this.row_cache[0]=0);for(let o=this.row_cache.length-1;o<=t;o++)this.row_cache[o+1]=this.row_cache[o]+this.RowHeight(o)}let i=this.column_cache[r],n=this.row_cache[t];return new G(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 a=e+1;a<this.column_header_tiles.length;a++){this.column_header_tiles[a].pixel_start.x+=n,this.column_header_tiles[a].pixel_end.x+=n;for(let s of this.grid_tiles[a])s.pixel_start.x+=n,s.pixel_end.x+=n}let o=this.grid_tiles[e];for(i of o)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 o=e+1;o<this.row_header_tiles.length;o++)i=this.row_header_tiles[o],i.pixel_start.y+=n,i.pixel_end.y+=n;for(let o of this.grid_tiles){i=o[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 a=e+1;a<o.length;a++)o[a].pixel_start.y+=n,o[a].pixel_end.y+=n}this.UpdateTotalSize(),this.UpdateGridTemplates(!1,!0),this.UpdateContentsSize()}};var zt=class extends Be{constructor(e,t){super(e,t,!0)}InitializeInternal(){}UpdateGridTemplates(){}UpdateTileGridPosition(){}UpdateContainingGrid(){}ResizeCursor(){}};var Nt=class extends Be{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(){let e=0,t=0;this.column_header.style.gridTemplateColumns=this.contents.style.gridTemplateColumns=this.column_header_tiles.map(a=>(e+=a.logical_size.width,`${a.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(a=>(t+=a.logical_size.height,`${a.logical_size.height}px`)).join(" ");let r=this.header_offset.y;if(this.view.active_sheet.freeze.rows)for(let a=0;a<this.view.active_sheet.freeze.rows;a++)r+=this.RowHeight(a);this.column_header.style.height=`${r}px`,this.row_header_selection.style.display="block",this.row_header_selection.style.width=`${e}px`,this.corner_selection.style.height=this.row_header_selection.style.height=`${r}px`,this.corner_selection.style.top=this.row_header_selection.style.top="0px",this.row_header_selection.style.left="0px";let i=this.header_offset.x;if(this.view.active_sheet.freeze.columns)for(let a=0;a<this.view.active_sheet.freeze.columns;a++)i+=this.ColumnWidth(a);this.column_header_selection.style.display="block",this.corner_selection.style.width=this.column_header_selection.style.width=`${i}px`,this.column_header_selection.style.height=`${t}px`,this.column_header_selection.style.top="0px",this.corner_selection.style.left=this.column_header_selection.style.left="0px";let n={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=`${e}px`,this.corner_annotations.style.height=this.row_header_annotations.style.height=`${r-n.y}px`,this.corner_annotations.style.top=this.row_header_annotations.style.top=`${n.y}px`,this.column_header_annotations.style.width=this.corner_annotations.style.width=`${i-n.x}px`,this.column_header_annotations.style.height=`${t}px`,this.corner_annotations.style.left=this.column_header_annotations.style.left=`${n.x}px`,this.corner_selection.style.display="block",this.grid_selection.style.width=`${e}px`,this.grid_selection.style.height=`${t}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=`${e}px`,this.annotation_container.style.height=`${t}px`,this.annotation_container.style.top=`${this.header_offset.y}px`,this.annotation_container.style.left=`${this.header_offset.x}px`}};var De=class c extends le{constructor(t,r,i){super();this.model=t;this.view=r;this.autocomplete=i;this.parser=t.parser}static FormulaChars=("$^&*(-+={[<>/~%"+N.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 o=r?.getRangeAt(0);if((o?.endContainer instanceof t.HTMLElement?o.endContainer:o.endContainer?.parentElement)?.dataset.reference!==void 0)return!0;if(o?.startContainer instanceof t.Text){let s=(o.startContainer.textContent?.substring(0,o.startOffset)||"").trim();if(s.length&&c.FormulaChars.includes(s[s.length-1]))return!0}else console.info("mark 21",o)}let n=this.SubstringToCaret2(this.active_editor.node)[1].trim();if(n.length){let o=n[n.length-1];return c.FormulaChars.includes(o)}}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,o=n.getSelection(),a=i?.createRange(),s=d=>{let h=d;for(;h&&!(h instanceof n.Text)&&h.firstChild;)h=h.firstChild;return h},l=s(t.node);if(r){let d=s(r.node);o&&a&&(a.setStart(l,t.offset),a.setEnd(d,r.offset),o.removeAllRanges(),o.addRange(a))}else o&&a&&(a.setStart(l,t.offset),a.setEnd(l,t.offset),a.collapse(!0),o.removeAllRanges(),o.addRange(a))}InsertReference(t){if(!this.active_editor)return;let r=this.active_editor.node.ownerDocument.defaultView,i=r.getSelection();if(!i)throw new Error("error getting selection");if(i.rangeCount===0)return"";let n=i.getRangeAt(0),o=this.active_editor.node.textContent||"";if(n.startContainer instanceof r.Text)if(!n.collapsed&&n.startOffset<n.endOffset){let a=this.SubstringToCaret2(this.active_editor.node);this.active_editor.node.textContent=a[0]+t+o.substring(a[1].length),this.SetCaret({node:this.active_editor.node,offset:a[0].length},{node:this.active_editor.node,offset:a[0].length+t.length})}else{let a=n.startContainer.parentElement;if(a instanceof r.HTMLElement&&a.dataset.reference)a.textContent=t,this.SetCaret({node:a,offset:t.length});else{let s=this.SubstringToCaret2(this.active_editor.node)[1],l="",d=s.trim();if(d.length){let h=d[d.length-1];c.FormulaChars.includes(h)||(s.length===d.length?l=" +":l="+")}this.active_editor.node.textContent=s+l+t+o.substring(s.length),this.SetCaret({node:this.active_editor.node,offset:s.length+t.length+l.length})}}else n.startContainer instanceof r.HTMLElement?(n.startContainer.textContent=t,this.SetCaret({node:n.startContainer,offset:t.length})):console.warn("unexpected range start container",n.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 o of this.nodes)for(let a of o.references||[]){let s=this.model.AddressToLabel(a);r.has(s)||(r.set(s,a),i.set(s,i.size))}for(let o of this.nodes){for(let a of Array.from(o.node.childNodes)){let s=a.ownerDocument?.defaultView;if(s&&a instanceof s.HTMLElement&&a.dataset.reference){let l=i.get(a.dataset.reference);a.dataset.highlightIndex=typeof l=="number"?(l%5+1).toString():"?"}}o.check=o.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 s of r.full_reference_list||[])switch(s.type){case"address":case"range":{let l=s.type==="range"?s.start:s;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(s);break}case"structured-reference":if(this.target_address){let l=this.model.ResolveStructuredReference(s,this.target_address);l&&i.push(l)}else console.info("target address not set");break;case"identifier":{let l=this.model.GetName(s.name,this.view.active_sheet.id);l?.type==="range"&&(l.area.count===1?i.push({type:"address",...l.area.start,label:s.name,position:s.position,id:s.id}):i.push({type:"range",start:{type:"address",position:s.position,id:s.id,label:s.name,...l.area.start},end:{type:"address",position:s.position,label:s.name,id:s.id,...l.area.end},label:s.name,position:s.position,id:s.id}));break}}i.sort((s,l)=>s.position-l.position);let n=[],o=new Set,a=new Map;for(let s of i){let l=this.model.AddressToLabel(s),d=V(s)?new y(s):new y(s.start,s.end);o.has(l)||(n.push(d),o.add(l)),a.set(s,l)}return this.UpdateReferences(t,n),a}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||"",o=P.GetInstance(i.ownerDocument);if(this.text_formula=n[0]==="=",this.active_editor&&!this.assume_formula&&(this.active_editor.node.spellcheck=!this.text_formula,!this.text_formula)||n===t.formatted_text)return;let[a,s]=this.SubstringToCaret2(i),l=a.length,d=s.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,b,g,C=0,x,v=o.Fragment(),_=(w,A="text",S="",I=!1)=>{let L=o.Text(w);if((I||(l>C||l===0&&C===0)&&l<=C+w.length)&&(b={offset:l-C,node:L}),d>C&&d<=C+w.length&&(g={offset:d-C,node:L}),A!=="text"){let O=o.Create("span",A);S&&(O.dataset.reference=S),O.appendChild(L),v.appendChild(O)}else v.appendChild(L);x=L,C+=w.length};this.parser.Walk(u.expression,w=>{if(w.type==="missing"||w.type==="group"||w.type==="dimensioned")return!0;let A=w.position+f,S=n.substring(p,A),I="",L=w.type,O="";switch(w.type){case"identifier":case"call":I=n.substring(A,A+w.name.length);break;case"literal":if(typeof w.value=="string")I=n.substring(A,A+w.value.length+2),L="string";else return!1;break;case"address":case"range":case"structured-reference":O=m.get(w)||"???",I=r.rewrite_addresses?w.label:n.substring(A,A+w.label.length);break;default:return!0}return _(S),_(I,L,O),p=A+I.length,w.type!=="range"}),p<n.length&&_(n.substring(p)),b||(x?b={node:x,offset:(x.data||"").length}:_("",void 0,"",!0)),i.textContent="",i.appendChild(v),b&&!r.format_only&&i===this.active_editor?.node&&this.SetCaret(b,g)}}t.formatted_text=n;let h=this.autocomplete_matcher;h&&Promise.resolve().then(()=>{let u=h.Exec({text:n,cursor:s.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;if(t.data&&t.data.completions){for(let d of t.data.completions)if(d.name.toLowerCase()===t.value?.toLowerCase()){r=d.type;break}}let i=t.data?.position||0,n=i+(t.data?.token?.length||0),o=r==="token"?t.value:t.value+"(",a=this.active_editor.node.textContent||"",s=a.substring(0,i)+o,l=s.length;s+=a.substring(n),this.active_editor.node.textContent=s,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 G(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,o=[!1,!1],a=(l,d)=>{if(l===d.startContainer&&l===d.endContainer&&!(l instanceof n.Text)){o[0]=o[1]=!0,r[0]+=l.textContent,r[1]+=l.textContent;return}if(l===d.startContainer&&(r[0]+=(l.textContent||"").substring(0,d.startOffset),o[0]=!0),l===d.endContainer&&(r[1]+=(l.textContent||"").substring(0,d.endOffset),o[1]=!0),!(o[0]&&o[1])){if(l instanceof n.Text){let h=l.textContent||"";o[0]||(r[0]+=h),o[1]||(r[1]+=h)}else if(l.hasChildNodes()){for(let h of Array.from(l.childNodes))if(a(h,d),o[0]&&o[1])return}}},s=n.getSelection();if(s?.rangeCount??!1){let l=s?.getRangeAt(0);l&&a(t,l)}return r}};var uo=typeof navigator>"u"?"":navigator.appVersion,Te=typeof navigator>"u"?"":navigator.userAgent,zr=class{is_edge=/Edge/.test(uo);is_ipad=/iPad|iPhone/.test(Te);is_android=/android|samsung/i.test(Te);is_mobile=this.is_ipad||this.is_android;is_firefox=/firefox/i.test(Te);is_safari=/safari/i.test(Te)&&!/edg/i.test(Te);is_mac=/macintosh/i.test(Te);is_chrome=/Chrome/i.test(Te);is_windows=/win64|win32|windows\s+nt/i.test(Te);is_modern=!this.is_edge&&!(this.is_firefox&&this.is_android)&&/webkit|firefox/i.test(Te)},mo={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},ee=typeof navigator>"u"?mo:new zr;var Dt=class extends De{constructor(t,r,i,n,o){super(i,n,o);this.container=t;this.theme=r;this.container_node=t.querySelector(".treb-overlay-container"),this.edit_node=this.container_node.querySelector(".treb-overlay-editor"),ee.is_firefox&&this.edit_node.classList.add("firefox"),this.edit_node.inputMode="none";let a={node:this.edit_node};this.nodes=[a],this.active_editor=a,this.RegisterListener(a,"input",s=>{if(s instanceof InputEvent&&s.isComposing)return;if(!s.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(a),this.UpdateColors())}),this.RegisterListener(a,"keyup",s=>{s.isComposing||!this.editing||this.autocomplete&&this.autocomplete.HandleKey("keyup",s).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(){ee.is_firefox?this.edit_node.innerHTML="<span></span>":this.edit_node.textContent=""}Edit(t,r,i,n,o){this.Publish({type:"start-editing",editor:"ice"}),this.active_cell=i,this.target_address={...t.target},this.reset_selection=!1;let a=i.style||{};switch(this.edit_node.style.font=U.Font(a,this.scale),this.edit_node.style.color=R(this.theme,a.text,1),this.edit_inset.style.backgroundColor=R(this.theme,a.fill,0),a.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 s=n?.toString()||"";if(s&&s[0]==="="&&(this.edit_node.spellcheck=!1),r.ApplyStyle(this.container_node),this.autocomplete?.ResetBlock(),this.selection=t,typeof n<"u"){let l=s[0]!=="="&&s[s.length-1]==="%",d=s.length;this.edit_node.textContent=s,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()),!o&&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 Nr=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"),o=Math.ceil(n.width);if(this.canvas.setAttribute("width",o.toString()),this.canvas.setAttribute("height",o.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 a=Math.round(o*2/3),s=Math.round(o/2);i.clearRect(0,0,o,o);for(let u=32;u<=126;u++){let m=String.fromCharCode(u);i.fillText(m,s,a)}let l=i.getImageData(0,0,this.canvas.width,this.canvas.height).data,d=Math.floor(this.GetFirstIndex(l)/o),h=Math.floor(this.GetLastIndex(l)/o);return{ascender:a-d,descender:h-a,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}},Vt=new Nr;var fo=" ",Dr="bottom",Ii=/webkit/i.test(typeof navigator>"u"?"":navigator?.userAgent||"")?1:0,Ut=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 o=this.buffer_canvas.getContext("2d",{alpha:!1});if(o){let a=this.layout.dpr;this.buffer_context=o,this.buffer_context.setTransform(a,0,0,a,0,0),this.buffer_context.textAlign="left",this.buffer_context.textBaseline=Dr}}cell_edge_buffer=4;overflow_areas=[];buffer_canvas;buffer_context;buffer_canvas_size={width:256,height:256};FlushOverflows(){let e=this.view.active_sheet.cells;for(let t of e.Iterate())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=Dr)}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 o=r.area.start.column;!n&&o<=r.area.end.column;o++){let a=this.view.active_sheet.cells.GetCell({row:i,column:o},!1);n=!!(a&&!a.render_clean[this.view.view_index])}if(n){for(let o=r.area.start.column;o<=r.area.end.column;o++){let a=this.view.active_sheet.cells.GetCell({row:i,column:o},!1);a&&(a.render_clean[this.view.view_index]=!1,a.renderer_data&&a.renderer_data.overflowed&&(a.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=Vt.Get(U.Font(this.theme.headers||{},this.layout.scale)),i=this.layout.dpr,n=this.layout.header_offset,o=n.x;for(let s=0;s<this.view.active_sheet.freeze.columns;s++)o+=this.layout.ColumnWidth(s);let a=n.y;for(let s=0;s<this.view.active_sheet.freeze.rows;s++)a+=this.layout.RowHeight(s);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,o,n.y),t.fillRect(0,0,n.x,a),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(),a!==n.y&&(t.moveTo(n.x-.5,n.y),t.lineTo(n.x-.5,a)),o!==n.x&&(t.moveTo(n.x,n.y-.5),t.lineTo(o,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),o=y.ColumnToLabel(t),a=e.measureText(o);n>a.width&&e.fillText(o,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 o=this.layout.RowHeight(t);o>=i*1.2&&e.fillText(`${t+1}`,n/2,o/2+1),e.moveTo(0,o-.5),e.lineTo(n,o-.5),e.translate(0,o)}e.stroke()}}RenderHeaders(e,t=!1){let r=this.layout.dpr,i=this.layout.header_offset,n=Vt.Get(U.Font(this.theme.headers||{},this.layout.scale));for(let o=e.start.column;o<=e.end.column;o++){let a=this.layout.column_header_tiles[o];if(a.dirty||t){let s=a.getContext("2d",{alpha:!1});if(!s)continue;s.setTransform(r,0,0,r,0,0),s.textAlign="center",s.textBaseline="middle",s.font=U.Font(this.theme.headers||{},this.layout.scale),s.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",s.fillRect(0,0,a.logical_size.width,this.layout.header_offset.y),s.strokeStyle=this.theme.headers_grid_color||"",s.beginPath(),s.moveTo(0,i.y-.5),s.lineTo(a.logical_size.width,i.y-.5),s.stroke(),s.strokeStyle=this.theme.headers_grid_color||"",this.RenderColumnLabels(s,a.first_cell.column,a.last_cell.column),a.dirty=!1}}for(let o=e.start.row;o<=e.end.row;o++){let a=this.layout.row_header_tiles[o];if(a.dirty||t){let s=a.getContext("2d",{alpha:!1});if(!s)continue;s.fillStyle=this.theme.headers?.fill?R(this.theme,this.theme.headers.fill):"",s.setTransform(r,0,0,r,0,0),s.textAlign="center",s.textBaseline="middle",s.font=U.Font(this.theme.headers||{},this.layout.scale),s.fillRect(0,0,this.layout.header_offset.x,a.logical_size.height),s.strokeStyle=this.theme.headers_grid_color||"",s.beginPath(),s.moveTo(i.x-.5,0),s.lineTo(i.x-.5,a.logical_size.height),s.stroke(),s.strokeStyle=this.theme.headers_grid_color||"",this.RenderRowLabels(s,a.first_cell.row,a.last_cell.row,n.block),a.dirty=!1}}(this.view.active_sheet.freeze.rows||this.view.active_sheet.freeze.columns)&&this.RenderCorner()}CopyToAdjacent(e,t,r,i,n,o,a){let s=this.layout.AdjacentTile(e,i,r);if(!s)return;let l=n,d=o;r>0?l=n-(e.pixel_end.x-e.pixel_start.x)*t:r<0&&(l=n+(s.pixel_end.x-s.pixel_start.x)*t),i>0&&(d=o-(e.pixel_end.y-e.pixel_start.y)*t);let h=s.getContext("2d",{alpha:!1});h&&(h.setTransform(t,0,0,t,l,d),h.drawImage(this.buffer_canvas,0,0,(a.width||0)*t,(a.height||0)*t,a.left||0,0,a.width||0,a.height||0))}Render(e){let t=e.getContext("2d",{alpha:!1});if(!t)return;t.textBaseline=Dr;let r=this.layout.dpr;t.setTransform(r,0,0,r,0,0);let i=0,n=0;for(let s=e.first_cell.column;s<=e.last_cell.column;s++){let l=this.layout.ColumnWidth(s);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:s});if(e.needs_full_repaint||!u.render_clean[this.view.view_index]){let m=this.RenderCell(e,u,t,{row:d,column:s},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 o=0,a=0;if(e.first_cell.row<=this.view.active_sheet.freeze.rows-1)for(let s=e.first_cell.row;s<this.view.active_sheet.freeze.rows&&s<=e.last_cell.row;s++)o+=this.layout.RowHeight(s);if(e.first_cell.column<=this.view.active_sheet.freeze.columns-1)for(let s=e.first_cell.column;s<this.view.active_sheet.freeze.columns&&s<=e.last_cell.column;s++)a+=this.layout.ColumnWidth(s);if(o){let s=this.layout.frozen_row_tiles[e.tile_position.column];if(!s)throw new Error("can't find matching header tile");let l=s.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,o*r,0,0,e.logical_size.width,o)}if(a){let s=this.layout.frozen_column_tiles[e.tile_position.row];if(!s)throw new Error("can't find matching header tile");let l=s.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,a*r,e.logical_size.height*r,0,0,a,e.logical_size.height)}if(a&&o){let s=this.layout.corner_canvas.getContext("2d",{alpha:"false"});if(!s)throw new Error("corner context failed");s.setTransform(r,0,0,r,this.layout.header_offset.x*r,this.layout.header_offset.y*r),s.drawImage(e,0,0,a*r,o*r,0,0,a,o)}}PrepText(e,t,r,i){let n=[],o=r.style||{},a,s=0,l,d=r.editing?"":r.formatted;Array.isArray(d)&&(d=d.filter(m=>m.flag!==8));let h="",u;if(o.indent){for(let m=0;m<o.indent;m++)h+=fo;u=o.horizontal_align,u||(u=r.type===3||r.calculated_type===3||r.type===7||r.calculated_type===7?"right":"left")}if(Array.isArray(d)){h&&(u==="right"?d.push({text:h,flag:8}):(u==="left"||typeof u>"u")&&d.unshift({text:h,flag:8}));for(let m of d){if(m.flag===6){l=m.text;continue}let f=e.measureText(m.text).width,p={width:f,text:m.text,hidden:m.flag===1};n.push(p),m.flag===2?a=p:s+=f}if(a){let m=a.text,f=a.width,p=i-s-2*this.cell_edge_buffer;if(a.width=Math.max(0,p),p>0){let b=Math.floor(p/f);for(let g=1;g<b;g++)a.text+=m;s=i-2*this.cell_edge_buffer}else a.text=""}return{strings:[n],format:l,width:s}}else if(d){r.type===2&&d[0]==="'"&&(d=d.slice(1));let m;this.options.markdown?m=ze.instance.Parse(d):(m=ze.instance.Dummy(d),e.font=t.base);let f=0,p=i-2*this.cell_edge_buffer,b=[];if(o.wrap){let g=h&&o.horizontal_align!=="center"?e.measureText(h).width:0;p-=g;for(let C of m){for(let v=1;v<C.length;v++){let _=C[v].text.match(/^(\s+)/);_&&(C[v-1].text+=_[1],C[v].text=C[v].text.replace(/^\s+/,""))}let x=[];for(let v of C){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 _=v.text.match(/\S+\s*/g);if(_&&_.length)for(let w of _){let A=e.measureText(w.trim()).width,S=e.measureText(w).width;x.push({part:v,text:w,trimmed:A,width:S})}}for(;x.length;){let v=x.shift(),_=[v],w=v.trimmed;for(;w<p&&x.length;){let S=x[0],I=w-v.trimmed+v.width+S.trimmed;if(I>=p)break;v=S,_.push(S),w=I,x.shift(),f=Math.max(f,w)}v.text=v.text.trim(),v.width=v.trimmed,f=Math.max(f,v.width);let A=_.map(S=>({...S.part,hidden:!1,width:S.width,text:S.text}));o.indent&&(u==="right"?A.push({text:h,hidden:!1,width:g}):u==="left"&&A.unshift({text:h,hidden:!1,width:g})),b.push(A)}}}else for(let g of m){let C=[];o.indent&&(u==="right"?g.push({text:h}):u==="left"&&g.unshift({text:h}));let x=0;for(let v of g){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;x+=_,C.push({...v,hidden:!1,width:_})}f=Math.max(f,x),b.push(C)}return{strings:b,width:f}}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,o=0,a=0){let s=this.view.active_sheet.SurroundingStyle(e,this.theme.table),l=R(this.theme,s[8].fill);l&&(t.fillStyle=l,t.fillRect(i+0,n-1,o,1)),l=R(this.theme,s[4].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n,1,a)),l=R(this.theme,r.fill),l&&(t.fillStyle=l,t.fillRect(i-1,n-1,o+1,a+1)),l=R(this.theme,s[6].fill),l&&(t.fillStyle=l,t.fillRect(i+o-1,n-1,1,a+1)),l=R(this.theme,s[2].fill),l&&(t.fillStyle=l,t.fillRect(i-1,n+a-1,o+1,1)),s[6].border_top&&!s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_top_fill,1),t.fillRect(i+o-1,n-2+s[6].border_top,1,1)),s[9].border_left&&(t.fillStyle=R(this.theme,s[9].border_left_fill,1),t.fillRect(i+o-1,n-1,1,1)),s[9].border_bottom&&(t.fillStyle=R(this.theme,s[9].border_bottom_fill,1),t.fillRect(i+o-1,n-2+s[9].border_bottom,1,1)),s[4].border_top&&!s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_right_fill,1),t.fillRect(i-1,n-2+s[4].border_top,1,1)),s[7].border_right&&(t.fillStyle=R(this.theme,s[7].border_right_fill,1),t.fillRect(i-1,n-1,1,1)),s[7].border_bottom&&(t.fillStyle=R(this.theme,s[7].border_bottom_fill,1),t.fillRect(i-1,n-2+s[7].border_bottom,1,1)),s[6].border_bottom&&!s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_bottom_fill,1),t.fillRect(i+o-1,n+a-s[6].border_bottom,1,1)),s[3].border_left&&(t.fillStyle=R(this.theme,s[3].border_left_fill,1),t.fillRect(i+o-1,n+a-1,1,1)),s[3].border_top&&(t.fillStyle=R(this.theme,s[3].border_top_fill,1),t.fillRect(i+o-1,n+a-s[3].border_top,1,1)),s[4].border_bottom&&!s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_bottom_fill,1),t.fillRect(i-1,n+a-s[4].border_bottom,1,1)),s[1].border_right&&(t.fillStyle=R(this.theme,s[1].border_right_fill,1),t.fillRect(i-1,n+a-1,1,1)),s[1].border_top&&(t.fillStyle=R(this.theme,s[1].border_top_fill,1),t.fillRect(i-1,n+a-s[1].border_top,1,1)),s[8].border_bottom&&(t.fillStyle=R(this.theme,s[8].border_bottom_fill,1),s[8].border_bottom===2&&(t.fillRect(i-1,n-2,o+1,1),t.fillRect(i-1,n-0,o+1,1),t.fillStyle=R(this.theme,s[8].fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n-1,o+1,1)),s[4].border_right&&(t.fillStyle=R(this.theme,s[4].border_right_fill,1),t.fillRect(i-1,n-1,1,a+1)),s[6].border_left&&(t.fillStyle=R(this.theme,s[6].border_left_fill,1),t.fillRect(i+o-1,n-1,1,a+1)),s[2].border_top&&(t.fillStyle=R(this.theme,s[2].border_top_fill,1),s[2].border_top===2&&(t.fillRect(i-1,n+a-2,o+1,1),t.fillRect(i-1,n+a-0,o+1,1),t.fillStyle=R(this.theme,s[2].fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n+a-1,o+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,o+1,1),t.fillRect(i-1,n+0,o+1,1),t.fillStyle=R(this.theme,r.fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n-1,o+1,1)),r.border_left&&(t.fillStyle=R(this.theme,r.border_left_fill,1),t.fillRect(i-1,n-1,1,a+1)),r.border_right&&(t.fillStyle=R(this.theme,r.border_right_fill,1),t.fillRect(i+o-1,n-1,1,a+1)),r.border_bottom&&(t.fillStyle=R(this.theme,r.border_bottom_fill,1),r.border_bottom===2&&(t.fillRect(i-1,n+a-2,o+1,1),t.fillRect(i-1,n+a+0,o+1,1),t.fillStyle=R(this.theme,r.fill)||R(this.theme,this.theme.grid_cell?.fill,0)||"#fff"),t.fillRect(i-1,n+a-1,o+1,1))}PaintBackgroundImage(e,t,r,i,n,o,a=0,s=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=o/d,p=h+m>t.width,b=u+f>t.height;p&&e.drawImage(t,h-t.width,u,m,f,a,s,n-l,o-l),b&&e.drawImage(t,h,u-t.height,m,f,a,s,n-l,o-l),p&&b&&e.drawImage(t,h-t.width,u-t.height,m,f,a,s,n-l,o-l),e.drawImage(t,h,u,m,f,a,s,n-l,o-l)}RenderCellBackground(e,t,r,i,n,o,a=0,s=0){if(r.fillStyle=this.theme.grid_color,r.fillRect(0,0,n,o),this.view.active_sheet.image)this.PaintBackgroundImage(r,this.view.active_sheet.image,a,s,n,o,0,0,1);else{let l=R(this.theme,i.fill);l?(r.fillStyle=l,r.fillRect(0,0,n-1,o-1)):(r.fillStyle=R(this.theme,this.theme.grid_cell?.fill,0)||"#fff",r.fillRect(0,0,n-1,o-1))}this.RenderCellBorders(t,r,i,0,0,n,o),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,9),r.lineTo(n-2,1),r.fill())}RenderCell(e,t,r,i,n,o,a=0,s=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 T=t.merge_area.start.column+1;T<=t.merge_area.end.column;T++)n+=this.layout.ColumnWidth(T);for(let T=t.merge_area.start.row+1;T<=t.merge_area.end.row;T++)o+=this.layout.RowHeight(T);if(t.merge_area.count>1){let T=this.view.active_sheet.CellStyleData(t.merge_area.end);T&&(h.border_bottom=T.border_bottom,h.border_right=T.border_right,h.border_bottom_fill=T.border_bottom_fill,h.border_right_fill=T.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,o),r.strokeStyle=r.fillStyle=R(this.theme,h.text,1);let T=this.ResolveColors(h);if(t.render_function.call(void 0,{width:n,height:o,context:r,cell:t,style:T,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!==o){let T=this.PrepText(r,m,t,n);t.renderer_data={text_data:T,width:n,height:o}}let f=t.renderer_data.text_data,p=f.width>n-2*this.cell_edge_buffer,b=n,g=0,C=!1,x=t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7||t.type===9||t.calculated_type===9,v=h.horizontal_align;v||(v=x?"right":"left");let _=[];if(p)if(t.type!==3&&t.calculated_type!==3&&!h.wrap&&!t.merge_area){let te=f.width-n+this.cell_edge_buffer,oe=0,k=0;v==="center"?oe=k=te/2:v==="right"?oe=te:k=te;let Q=i.column,q=i.column;for(;k>0&&Q<this.layout.last_column;){Q++;let B={row:i.row,column:Q},D=this.view.active_sheet.CellData(B),Y=this.layout.ColumnWidth(Q);if(k-=Y,D&&!D.type&&!D.calculated_type)_.push({address:B,cell:D,grid:new G(b,0,Y,o),background:new G(b-1,0,Y,o-1),border:new G(b,0,Y,o)}),b+=Y,D.render_clean[this.view.view_index]=!0,D.renderer_data={overflowed:!0};else{C=!0;break}}for(Q>e.last_cell.column&&(l.tile_overflow_right=!0);oe>0&&q>=1;){q--;let B={row:i.row,column:q},D=this.view.active_sheet.CellData(B),Y=this.layout.ColumnWidth(q);if(oe-=Y,D&&!D.type&&!D.calculated_type)g-=Y,_.push({address:B,cell:D,grid:new G(g,0,Y,o),background:new G(g,0,Y,o-1),border:new G(g,0,Y,o)});else{C=!0;break}}q<e.first_cell.column&&(l.tile_overflow_left=!0),this.overflow_areas.push({head:{...i},tile:e,area:new y({row:i.row,column:q},{row:i.row,column:Q})})}else C=!x;let w=!1,A=r;(l.tile_overflow_bottom||l.tile_overflow_left||l.tile_overflow_right)&&(w=!0,l.width=b-g,l.height=o,l.left=g,this.EnsureBuffer(l.width+1,o+1,-g),r=this.buffer_context,r.font=m.base),this.RenderCellBackground(!!t.note,i,r,h,n,o,a,s);for(let T of _)T.cell.style?.fill&&di(T.cell.style.fill)&&!this.options.grid_over_background?(r.fillStyle=R(this.theme,T.cell.style.fill,0),r.fillRect(T.grid.left,T.grid.top,T.grid.width,T.grid.height)):(r.fillStyle=this.theme.grid_color||"",r.fillRect(T.grid.left,T.grid.top,T.grid.width,T.grid.height),this.view.active_sheet.image?this.PaintBackgroundImage(r,this.view.active_sheet.image,a+T.background.left,s+T.background.top,T.background.width,T.background.height,T.background.left,T.background.top,0):(r.fillStyle=this.theme.grid_cell?.fill?R(this.theme,this.theme.grid_cell.fill,0):"",r.fillRect(T.background.left,T.background.top,T.background.width,T.background.height))),T.cell.style&&this.RenderCellBorders(T.address,r,T.cell.style,T.border.left,T.border.top,T.border.width,T.border.height);let S=Vt.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 I=this.cell_edge_buffer,L=1.25,O=f.strings.length,_e=O*S.block*L;C=(C||_e>=o)&&!w,C&&(r.save(),r.beginPath(),r.moveTo(g+1.5,0),r.lineTo(g+1.5,o),r.lineTo(b-1.5,o),r.lineTo(b-1.5,0),r.clip()),r.beginPath();let ne=Math.round(o-2-S.block*L*(O-1)+Ii);switch(h.vertical_align){case"top":ne=Math.round(S.block*L)+1;break;case"middle":ne=Math.round((o-_e)/2+S.block*L);break}if((t.type===3||t.calculated_type===3||t.type===7||t.calculated_type===7)&&p){let T=Math.floor((n-2*this.cell_edge_buffer)/S.hash),te="";for(let k=0;k<T;k++)te+="#";let oe=r.measureText(te).width;v==="center"?I=Math.round((n-oe)/2):v==="right"&&(I=n-this.cell_edge_buffer-oe),r.fillText(te,I,ne)}else{let T=ne,te=0;for(let oe of f.strings){let k=0;for(let D of oe)k+=D.width;v==="center"?I=Math.round((n-k)/2):v==="right"&&(I=n-this.cell_edge_buffer-k);let Q=Math.floor(T+1.5-S.descender-Ii)+.5,q=Math.floor(T-S.descender-S.ascender/2)+.5,B=I;for(let D of oe)D.strong&&D.emphasis?r.font=m.strong_emphasis:D.strong?r.font=m.strong:D.emphasis?r.font=m.emphasis:r.font=m.base,D.hidden||(D.text&&r.fillText(D.text,B,T),h.underline&&(r.moveTo(B,Q),r.lineTo(B+D.width,Q)),(h.strike||D.strike)&&(r.moveTo(B,q),r.lineTo(B+D.width,q)),u&&(D.left=B,D.top=T-S.block,D.height=S.block)),B+=D.width;te++,T=Math.round(ne+te*S.block*L)}}if(r.stroke(),C)r.restore();else if(w){let T=this.layout.dpr;A.drawImage(this.buffer_canvas,0,0,(l.width||0)*T,o*T,g,0,l.width||0,o)}return l}};var Ft=class extends De{constructor(t,r,i,n,o){super(r,i,o);this.options=n;let a=P.GetInstance(t.ownerDocument),s=t.querySelector(".treb-formula-bar");s.removeAttribute("hidden"),this.address_label_container=s.querySelector(".treb-address-label"),this.address_label=this.address_label_container.firstElementChild,this.InitAddressLabel(),this.container_node=t.querySelector(".treb-editor-container");let l=this.container_node.firstElementChild,d={node:l};if(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",()=>{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){let h;this.expand_button=a.Create("button","expand-button",s,{events:{focus:u=>{h=u.relatedTarget instanceof HTMLElement?u.relatedTarget:void 0},click:u=>{u.stopPropagation(),u.preventDefault(),this.active_editor&&(this.active_editor.node.scrollTop=0),s.hasAttribute("expanded")?s.removeAttribute("expanded"):s.setAttribute("expanded",""),h&&h.focus()}}})}}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="&nbsp;",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}IsExpandButton(t){return this.expand_button&&t===this.expand_button}InitAddressLabel(){this.address_label.contentEditable="true",this.address_label.spellcheck=!1,this.address_label.addEventListener("focusin",()=>{let t=this.address_label.ownerDocument;requestAnimationFrame(()=>{let r=t.defaultView.getSelection(),i=t.createRange();i.selectNodeContents(this.address_label),r?.removeAllRanges(),r?.addRange(i)})}),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 o=r[n];switch(o.nodeType){case Node.ELEMENT_NODE:i.push(...this.GetTextContent(o)),o instanceof Element&&o.tagName==="DIV"&&i.push(`
6
6
  `);break;case Node.TEXT_NODE:o.nodeValue&&i.push(o.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 ot=class{constructor(e={}){this.options=e;if(this.DOM=P.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 o=this.completion_list.getBoundingClientRect();this.selected_index+=r,this.selected_index=Math.max(0,this.selected_index);let a=this.completion_list.querySelectorAll("a");this.selected_index=Math.min(this.selected_index,a.length-1);for(let s=0;s<a.length;s++){let l=a[s];if(s===this.selected_index){l.classList.add("selected"),this.active_element=l;let d=l.getBoundingClientRect();d.top<o.top?this.completion_list.scrollBy(0,-d.height):d.bottom>o.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((a,s)=>(a.name===this.last_completion&&(this.selected_index=s),`<li><a data-index="${s}">${a.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 o=this.completion_list.querySelectorAll("a");this.active_element=o[this.selected_index],o[this.selected_index].classList.add("selected"),this.last_completion=o[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 at=(k=>(k[k.Null=0]="Null",k[k.InsertRows=1]="InsertRows",k[k.InsertColumns=2]="InsertColumns",k[k.ResizeRows=3]="ResizeRows",k[k.ResizeColumns=4]="ResizeColumns",k[k.Select=5]="Select",k[k.SetRange=6]="SetRange",k[k.UpdateStyle=7]="UpdateStyle",k[k.UpdateBorders=8]="UpdateBorders",k[k.Indent=9]="Indent",k[k.MergeCells=10]="MergeCells",k[k.UnmergeCells=11]="UnmergeCells",k[k.Clear=12]="Clear",k[k.UpdateTheme=13]="UpdateTheme",k[k.SetNote=14]="SetNote",k[k.SetLink=15]="SetLink",k[k.Freeze=16]="Freeze",k[k.SetName=17]="SetName",k[k.ShowHeaders=18]="ShowHeaders",k[k.AddSheet=19]="AddSheet",k[k.DuplicateSheet=20]="DuplicateSheet",k[k.DeleteSheet=21]="DeleteSheet",k[k.ActivateSheet=22]="ActivateSheet",k[k.RenameSheet=23]="RenameSheet",k[k.ReorderSheet=24]="ReorderSheet",k[k.ShowSheet=25]="ShowSheet",k[k.DataValidation=26]="DataValidation",k[k.Reset=27]="Reset",k[k.SortTable=28]="SortTable",k[k.InsertTable=29]="InsertTable",k[k.RemoveTable=30]="RemoveTable",k[k.AddConditionalFormat=31]="AddConditionalFormat",k[k.RemoveConditionalFormat=32]="RemoveConditionalFormat",k))(at||{});var Lt=class{function_names=[];argument_separator=N.argument_separator.charCodeAt(0);function_map=new Map;RemoveFunctions(e){Array.isArray(e)||(e=[e]);for(let t of e)this.function_map.delete(t.name.toLowerCase());this.UpdateNameList()}AddFunctions(e){Array.isArray(e)||(e=[e]);for(let t of e)this.function_map.set(t.name.toLowerCase(),t);this.UpdateNameList()}SetFunctions(e){this.function_map.clear();for(let t of e)this.function_map.set(t.name.toLowerCase(),t);this.UpdateNameList()}NormalizeIdentifier(e){return this.function_map.get(e.toLowerCase())?.name}Get(e){return this.function_map.get(e.toLowerCase())}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],o=new RegExp("^"+n.replace(".","\\."),"i");r={completions:this.function_names.filter(s=>o.test(s)).map(s=>this.function_map.get(s.toLowerCase())).filter(s=>!!s),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.get(i.function.toLowerCase());n&&(r.tooltip='<span class="notranslate">'+n.name+"</span>",r.arguments="("+(n.arguments||[]).map((o,a)=>{let s=o.name||"argument";return a===i.argument?`<span class="active-argument">${s}</span>`:s}).join(N.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,o=0;for(let s of e){let l=s.charCodeAt(0);if(n)l===34&&(n=!1);else switch(l){case 40:t.push({buffer:i.trim(),argument:r,position:o-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+=s:i=""}o++}let a=t.pop();return{function:a?.buffer||void 0,position:a?.position||0,argument:r}}UpdateNameList(){this.function_names=[...this.function_map.keys()].sort((e,t)=>e.toLowerCase().localeCompare(t.toLowerCase()))}};var zi={scrollbars:!0,in_cell_editor:!0,formula_bar:!0,add_tab:!1,tab_bar:"auto",expand_formula_button:!1,expand:!0,repaint_on_cell_change:!0,grid_over_background:!1};var po=c=>{console.error("invalid case")},st=class{grid_events=new le;command_log=new le;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 Lt;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={...zi,...e}}RemoveConditionalFormat(e){this.ExecCommand({key:32,...e})}AddConditionalFormat(e){this.ExecCommand({key:31,format:e})}RemoveTable(e){this.ExecCommand({key:30,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 o=e.start.row;o<=e.end.row;o++)for(let a=e.start.column;a<=e.end.column;a++){let s=n.cells.GetCell({row:o,column:a},!1);if(s&&(s.area||s.merge_area||s.table)){this.Error(4);return}}this.ExecCommand({key:29,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:22,index:t,name:r})}ActivateSheetID(e){this.ExecCommand({key:22,id:e})}DuplicateSheet(e,t,r){let i={key:20,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:19,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:21,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:19,insert_index:e,name:t,show:!0})}DeleteSheetID(e){this.ExecCommand({key:21,id:e})}Reset(){this.ExecCommand({key:27})}SetLink(e,t){this.ExecCommand({key:15,area:e,reference:t})}ShowAll(){let e=[];for(let t=0;t<this.model.sheets.length;t++)e.push({key:25,index:t,show:!0});this.ExecCommand(e)}ShowSheet(e=0,t=!0){let r={key:25,show:t};typeof e=="string"?r.name=e:r.index=e,this.ExecCommand(r)}SortTable(e,t={}){this.ExecCommand({key:28,table:JSON.parse(JSON.stringify(e)),...mi,...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){this.parser.Save(),this.parser.SetLocaleSettings(".");let r=ci(e).map(n=>n.map(o=>{if(o){let a=this.parser.Parse(o);if(a.expression?.type==="complex")return a.expression}return ce.TryParse(o).value}));this.parser.Restore();let i={row:Math.max(0,r.length-1),column:r.reduce((n,o)=>Math.max(n,Math.max(0,o.length-1)),0)};this.ExecCommand([{key:27},{key:6,area:{start:{row:0,column:0},end:i},value:r}])}InsertColumns(e=0,t=1){this.ExecCommand({key:2,before_column:e,count:t})}ReorderSheet(e,t){this.ExecCommand({key:24,index:e,move_before:t})}RenameSheet(e,t){this.ExecCommand({key:23,new_name:t,id:e.id})}Freeze(e=0,t=0,r=!0){this.ExecCommand({key:16,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){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 o=[],a=[],s=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<=s;l++){let d=n.CellData({row:l,column:t}),h=r(d),u=n.GetRowHeight(l);h&&!u?o.push(l):!h&&u&&a.push(l)}o&&i.push({key:3,sheet_id:n.id,row:o,height:n.default_row_height}),a&&i.push({key:3,sheet_id:n.id,row:a,height:0}),i.length&&this.ExecCommand(i)}UpdateSheets(e,t=!1,r){X.Reset();let i=e.map(n=>X.FromJSON(n,this.model.theme_style_properties));if(i.length===0&&i.push(X.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.list)t.push({name:i.name,named:!0,type:"token"});let r=e.slice(0).concat(t);this.autocomplete_matcher.SetFunctions(r)}ResetMetadata(){this.model.document_name=void 0,this.model.user_data=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(){X.Reset(),this.UpdateSheets([],!0),this.model.named.Reset(),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;for(let i of r.cells.Iterate(t)){if(i.style?.locked)return console.info("invalid: locked cells"),!1;if(i.merge_area&&(!t.Contains(i.merge_area.start)||!t.Contains(i.merge_area.end)))return console.info("invalid: merge area"),!1;if(i.area&&(!t.Contains(i.area.start)||!t.Contains(i.area.end)))return console.info("invalid: array"),!1}}return!0}SetValidationInternal(e){let t=this.FindSheet(e.area);if(!t)throw new Error("invalid sheet in set validation");let r={start:e.area.start,end:e.area.end};e.range?t.AddValidation({type:"range",error:!!e.error,area:e.range,target:[r]}):e.list?t.AddValidation({type:"list",error:!!e.error,list:JSON.parse(JSON.stringify(e.list)),target:[r]}):t.RemoveValidations(r)}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 o=r.CellData({row:i,column:n});o&&o.formatted&&(typeof o.formatted=="string"?t.push(o.formatted):t.push(ie.FormatPartsAsText(o.formatted)))}}return t}DeleteSheetInternal(e){let t=!1,r=-1,i="",n=!1,o=e.name?e.name.toLowerCase():"",a=this.model.sheets.list.filter((s,l)=>l===e.index||s.id===e.id||s.name.toLowerCase()===o?(t=s===this.active_sheet,this.model.named.RemoveRangesForSheet(s.id),i=s.name,r=l,!1):!0);if(i&&this.RenameSheetReferences(a,i,"#REF")>0&&(n=!0),!a.length)a.push(X.Blank(this.model.theme_style_properties)),r=0;else if(a.every(s=>!s.visible))a.unshift(X.Blank(this.model.theme_style_properties)),r=0;else for(r>=a.length&&(r=0);!a[r].visible;)r++;return this.model.sheets.Assign(a),t&&this.ActivateSheetInternal({key:22,index:r}),n}RenameSheetInternal(e,t){if(!t||li.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 o=0,a=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 b=t.CellData({row:u,column:p});if(p===e.column+e.table.area.start.column){let g=b.calculated_type||b.type;g===2?o++:g===3&&a++;let C=b.calculated_type?b.calculated:b.value;f.text=C?.toString()||"",f.number=Number(C)||0,f.type=b.calculated_type||b.type}f.data.push({address:{row:u,column:p},data:b.value,type:b.type,style:b.style})}r.push(f)}let s=e.type;s==="auto"&&(a>o?s="numeric":s="text");let l=e.asc?1:-1;switch(s){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,b={columns:0,rows:d.row-m.row},g=this.parser.Parse(p);g.expression&&(p="="+this.parser.Render(g.expression,{offset:b,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,o=e.area.end.column-e.area.start.column+1,a=e.area.start.column;for(let s=0;s<o;s++,a++){let l=t.CellData({row:n,column:a}),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${s+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 s=new Map;for(let l=0;l<r.length;l++){let d=r[l].toLowerCase();d!==i[l]&&s.set(d,i[l])}if(s.size){let l=e.name.toLowerCase();for(let d of this.model.sheets.list)for(let h of d.cells.Iterate())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,b]of s.entries())f.column.toLowerCase()===p&&(f.column=b,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=V(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)),V(e.area)){let n=i.CellData(e.area);if(n.area&&(n.area.rows>1||n.area.columns>1)){this.Error(2);return}let o=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;return e.r1c1&&(o=this.TranslateR1C1(e.area,o)),e.array?i.SetArrayValue(r,o):i.SetCellValue(e.area,o),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 o=e.value[n];for(let a=0;a<o.length&&a<r.columns;a++){let s={...r.start,row:r.start.row+n,column:r.start.column+a};o[a]=this.TranslateR1C1(s,o[a])}}else if(typeof e.value=="string"&&e.value[0]==="="){let n=[];for(let o=0;o<r.rows;o++){let a=[];for(let s=0;s<r.columns;s++){let l={...r.start,row:r.start.row+o,column:r.start.column+s};a.push(this.TranslateR1C1(l,e.value))}n.push(a)}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:22,index:n});return}for(let n=0;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:22,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 18:case 25:case 19:case 20:case 21:case 22:case 23:case 24:case 27:break;case 28:case 30:r.table.area.start.sheet_id||(r.table.area.start.sheet_id=t);break;case 31:r.format.area.start.sheet_id||(r.format.area.start.sheet_id=t);break;case 3:case 4:case 2:case 1:case 16:r.sheet_id||(r.sheet_id=t);break;case 12:case 14:case 15:case 9:case 8:case 10:case 11:case 26:case 6:case 7:case 17:case 5:case 29:case 32:r.area&&(V(r.area)?r.area.sheet_id||(r.area.sheet_id=t):r.area.start.sheet_id||(r.area.start.sheet_id=t));break;default:po(r)}return e}AddSheetInternal(e=X.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=X.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:V(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,o,a){let s=this.parser.Parse(e||""),l=!1;if(s.expression&&(this.parser.Walk(s.expression,d=>{if(d.type==="range"||d.type==="address"){let h=[];d.type==="range"?(d.start.sheet&&d.start.sheet.toLowerCase()===o||!d.start.sheet&&a)&&h.push(d.start,d.end):d.type==="address"&&(d.sheet&&d.sheet.toLowerCase()===o||!d.sheet&&a)&&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(s.expression,{missing:""})}PatchExpressionSheetName(e,t,r){let i=!1,n=this.parser.Parse(e||"");if(n.expression&&(this.parser.Walk(n.expression,o=>(o.type==="address"&&o.sheet&&o.sheet.toLowerCase()===t&&(o.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){for(let o of n.cells.Iterate())if(o.ValueIsFormula()){let a=this.PatchExpressionSheetName(o.value||"",t,r);a&&(o.value=a,i++)}if(n.conditional_formats?.length)for(let o of n.conditional_formats)switch(o.type){case"cell-match":case"expression":{let a=this.PatchExpressionSheetName(o.expression,t,r);a&&(o.expression=a,i++)}break}for(let o of n.annotations)if(o.data.formula){let a=this.PatchExpressionSheetName(o.data.formula,t,r);a&&(o.data.formula=a,i++)}}for(let n of this.model.connected_elements.values())if(n.formula){let o=this.PatchExpressionSheetName(n.formula,t,r);o&&(n.formula=o,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 o={border_top:r},a={border_bottom:r},s={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?(o.border_top_fill={...e.color},a.border_bottom_fill={...e.color},s.border_left_fill={...e.color},l.border_right_fill={...e.color}):(o.border_top_fill={},a.border_bottom_fill={},s.border_left_fill={},l.border_right_fill={}),(t==="none"||t==="all")&&n.UpdateAreaStyle(i,{...o,...a,...s,...l},!0),(t==="top"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.top,{...o},!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,{...a},!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,{...s},!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,o=>(o.type==="address"&&o.r1c1&&(r=!0,o.offset_column?(o.absolute_column=!1,o.column=o.column+e.column):o.absolute_column=!0,o.offset_row?(o.absolute_row=!1,o.row=o.row+e.row):o.absolute_row=!0),!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}e=t.RealArea(e);for(let i of t.cells.Iterate(e))if(i.area&&!e.ContainsArea(i.area)){this.Error(2);return}let r=this.model.tables.keys();for(let i of r){let n=this.model.tables.get(i);if(n&&n.area.start.sheet_id===t.id){let o=new y(n.area.start,n.area.end);if(e.ContainsArea(o)){for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=n.area.end.column;s++){let l=t.cells.GetCell({row:a,column:s},!1);l&&(l.table=void 0)}this.model.tables.delete(i)}}}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((s,l)=>Math.max(s,l.id),0)+1,i=-1;for(let s=0;s<this.model.sheets.length;s++)this.model.sheets.list[s]===t&&(i=s+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 s=e.insert_before.toLowerCase();for(let l=0;l<this.model.sheets.length;l++)if(this.model.sheets.list[l].name.toLowerCase()===s){i=l;break}}let n={rendered_values:!0},o=X.FromJSON(t.toJSON(n),this.model.theme_style_properties),a=e.new_name||t.name;for(;this.model.sheets.list.some(s=>s.name===a);){let s=a.match(/^(.*?)(\d+)$/);s?a=s[1]+(Number(s[2])+1):a=a+"2"}return o.name=a,o.id=r,this.model.sheets.Splice(i,0,o),o.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 o=y.PatchArea(n,t);o?(n.start.row=o.start.row,n.start.column=o.start.column,n.end.row=o.end.row,n.end.column=o.end.column):n.start.row=n.end.row=n.start.column=n.end.column=-1}return r++,!1}else if(n.type==="address"){let o=y.PatchArea({start:n,end:n},t);return o?(n.row=o.start.row,n.column=o.start.column):n.row=n.column=-1,r++,!1}return!0}),r))return this.parser.Render(i.expression,{missing:""})}PatchConditionalsAndValidations(e){if(e.sheet.data_validation.length){let t=new Set;for(let r of e.sheet.data_validation){let i=[];for(let n of r.target){let o=y.PatchArea(n,e);o&&i.push(o)}if(i.length>0){if(r.target=i,r.type==="range"&&r.area.start.sheet_id===e.sheet.id){let n=y.PatchArea(r.area,e);n?r.area=n:t.add(r)}}else t.add(r)}t.size&&(e.sheet.data_validation=e.sheet.data_validation.filter(r=>!t.has(r)))}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.PatchConditionalsAndValidations({sheet:t,before_column:0,column_count:0,before_row:e.before_row,row_count:e.count});for(let s of this.model.connected_elements.values())if(s.formula){let l=this.PatchFormulasInternal(s.formula,e.before_row,e.count,0,0,t.name.toLowerCase(),!1);l&&(s.formula=l)}let r=Array.from(this.model.tables.values());for(let s of r)if(s.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_row<=s.area.start.row)s.area.start.row+=e.count,s.area.end.row+=e.count;else if(e.before_row<=s.area.end.row){s.area.end.row+=e.count;for(let l=s.area.start.row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=s}}}else if(e.before_row<=s.area.start.row)if(e.before_row-e.count<=s.area.start.row)s.area.start.row+=e.count,s.area.end.row+=e.count;else if(e.before_row-e.count>=s.area.end.row)this.model.tables.delete(s.name.toLowerCase());else{this.model.tables.delete(s.name.toLowerCase());for(let l=e.before_row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table===s&&(h.table=void 0)}}else e.before_row<=s.area.end.row&&(e.before_row-e.count>s.area.end.row&&(s.totals_row=!1),s.area.end.row=Math.max(0,s.area.end.row+e.count,e.before_row-1));this.model.named.PatchNamedRanges(t.id,0,0,e.before_row,e.count);let i=t.name.toLowerCase();for(let s of this.model.sheets.list){let l=s===t;for(let d of s.cells.Iterate())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 s.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=[],o=[],a=[];if(e.count>0){let s=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(s<=d)l.data.layout.tl.address.row+=e.count,l.data.layout.br.address.row+=e.count;else if(s<h||s===h&&u>0)l.data.layout.br.address.row+=e.count,o.push(l);else continue;n.push(l)}}else if(e.count<0){let s=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(s<=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=s,d.data.layout.tl.offset.y=0,d.data.layout.br.address.row+=e.count,o.push(d);else{a.push(d);continue}else if(s<u||s===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.row+=e.count,o.push(d)):(d.data.layout.br.address.row=s,d.data.layout.br.offset.y=0,o.push(d));else continue;n.push(d)}}for(let s of a)t.annotations=t.annotations.filter(l=>l!==s);return{update_annotations_list:n,resize_annotations_list:o,delete_annotations_list:a}}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.PatchConditionalsAndValidations({sheet:t,before_column:e.before_column,column_count:e.count,before_row:0,row_count:0});for(let s of this.model.connected_elements.values())if(s.formula){let l=this.PatchFormulasInternal(s.formula,0,0,e.before_column,e.count,t.name.toLowerCase(),!1);l&&(s.formula=l)}let r=Array.from(this.model.tables.values());for(let s of r)if(s.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_column<=s.area.start.column)s.area.start.column+=e.count,s.area.end.column+=e.count;else if(e.before_column<=s.area.end.column){s.area.end.column+=e.count;for(let l=s.area.start.row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=s}this.UpdateTableColumns(s)}}else e.before_column<=s.area.start.column?e.before_column-e.count<=s.area.start.column?(s.area.start.column+=e.count,s.area.end.column+=e.count):e.before_column-e.count>=s.area.end.column?this.model.tables.delete(s.name.toLowerCase()):(s.area.start.column=e.before_column,s.area.end.column+=e.count,this.UpdateTableColumns(s)):e.before_column<=s.area.end.column&&(s.area.end.column=Math.max(0,s.area.end.column+e.count,e.before_column-1),this.UpdateTableColumns(s));this.model.named.PatchNamedRanges(t.id,e.before_column,e.count,0,0);let i=t.name.toLowerCase();for(let s of this.model.sheets.list){let l=s===t;for(let d of s.cells.Iterate())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 s.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=[],o=[],a=[];if(e.count>0){let s=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(s<=d)l.data.layout.tl.address.column+=e.count,l.data.layout.br.address.column+=e.count;else if(s<h||s===h&&u>0)l.data.layout.br.address.column+=e.count,o.push(l);else continue;n.push(l)}}else if(e.count<0){let s=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(s<=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=s,d.data.layout.tl.offset.x=0,d.data.layout.br.address.column+=e.count,o.push(d);else{a.push(d);continue}else if(s<u||s===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.column+=e.count,o.push(d)):(d.data.layout.br.address.column=s,d.data.layout.br.offset.x=0,o.push(d));else continue;n.push(d)}}for(let s of a)t.annotations=t.annotations.filter(l=>l!==s);return{update_annotations_list:n,resize_annotations_list:o,delete_annotations_list:a}}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 27:this.ResetInternal();break;case 12:if(n.area){let o=new y(n.area.start,n.area.end);this.ClearAreaInternal(o),r.data_area=y.Join(o,r.data_area),r.formula=!0}break;case 5:this.SelectInternal(n);break;case 16:this.FreezeInternal(n),r.structure_event=!0;break;case 31:{let o=this.FindSheet(n.format.area);o.conditional_formats.push(n.format),o.Invalidate(new y(n.format.area.start,n.format.area.end)),o===this.active_sheet&&(r.render_area=y.Join(n.format.area,r.render_area)),r.structure_event=!0,r.conditional_formatting_event=!0}break;case 32:{let o,a=0;if(n.format){let s=JSON.stringify(n.format);o=this.FindSheet(n.format.area),o.conditional_formats=o.conditional_formats.filter(l=>JSON.stringify(l)===s?(a++,r.render_area=y.Join(l.area,r.render_area),!1):!0)}else if(n.area){let s=new y(n.area.start,n.area.end);o=this.FindSheet(n.area),o.conditional_formats=o.conditional_formats.filter(l=>{let d=new y(l.area.start,l.area.end);return d.Intersects(s)?(a++,r.render_area=y.Join(d,r.render_area),!1):!0})}o&&a&&(o.FlushConditionalFormats(),r.structure_event=!0,r.conditional_formatting_event=!0)}break;case 29:{let o=this.FindSheet(n.area),a=new y(n.area.start,n.area.end),s=!0;e:for(let l=a.start.row;l<=a.end.row;l++)for(let d=a.start.column;d<=a.end.column;d++){let h=o.cells.GetCell({row:l,column:d},!1);if(h&&(h.area||h.merge_area||h.table)){s=!1;break e}}if(s){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=a.start.row;u<=a.end.row;u++)for(let m=a.start.column;m<=a.end.column;m++){let f=o.cells.GetCell({row:u,column:m},!0);f.table=h}this.UpdateTableColumns(h),o.Invalidate(new y(h.area.start,h.area.end)),o===this.active_sheet?(r.style_area=y.Join(a,r.style_area),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}}break;case 30:{let o=this.FindSheet(n.table.area),a=new y(n.table.area.start,n.table.area.end);for(let l=a.start.row;l<=a.end.row;l++)for(let d=a.start.column;d<=a.end.column;d++){let h=o.cells.GetCell({row:l,column:d},!1);h&&(h.table=void 0)}this.model.tables.delete(n.table.name.toLowerCase());let s=o.RealArea(a.Clone().Shift(-1,-1).Resize(a.rows+2,a.columns+2));o.Invalidate(s),o===this.active_sheet?(r.style_area=y.Join(a,r.style_area),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}break;case 10:{let o=this.FindSheet(n.area);o.MergeCells(new y(n.area.start,n.area.end)),r.structure_event=!0,r.structure_rebuild_required=!0,o===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(o.id))}break;case 11:{let o=this.FindSheet(n.area),a={},s=new y(n.area.start,n.area.end);for(let d of o.cells.Iterate(s,!1))if(d.merge_area){let h=y.CellAddressToLabel(d.merge_area.start)+":"+y.CellAddressToLabel(d.merge_area.end);a[h]=d.merge_area}let l=Object.keys(a);for(let d=0;d<l.length;d++)o.UnmergeCells(a[l[d]]);o===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(o.id)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 9:{let o,a=this.FindSheet(n.area);if(V(n.area)){o=new y(n.area);let s=a.GetCellStyle(n.area,!0);a.UpdateCellStyle(n.area,{indent:Math.max(0,(s.indent||0)+n.delta)},!0)}else{o=new y(n.area.start,n.area.end);for(let s of o){let l=a.GetCellStyle(s,!0);a.UpdateCellStyle(s,{indent:Math.max(0,(l.indent||0)+n.delta)},!0)}}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 7:{let o,a=this.FindSheet(n.area);V(n.area)?(o=new y(n.area),a.UpdateCellStyle(n.area,n.style,!!n.delta)):(o=new y(n.area.start,n.area.end),a.UpdateAreaStyle(o,n.style,!!n.delta)),a===this.active_sheet?(r.style_area=y.Join(o,r.style_area),(!n.delta||n.style.fill||n.style.border_top||n.style.border_left||n.style.border_right||n.style.border_bottom)&&(o=y.Bleed(o),this.active_sheet.Invalidate(o)),r.render_area=y.Join(o,r.render_area)):r.style_event=!0}break;case 26:this.SetValidationInternal(n),(!n.area.start.sheet_id||n.area.start.sheet_id===this.active_sheet.id)&&(r.render_area=y.Join(new y(n.area.start,n.area.end),r.render_area));break;case 17:{let o={type:"token",named:!0,name:n.name,scope:n.scope};n.area||n.expression?(n.area?this.model.named.SetNamedRange(n.name,new y(n.area.start,n.area.end),n.scope):n.expression&&this.model.named.SetNamedExpression(n.name,n.expression,n.scope),this.autocomplete_matcher.AddFunctions(o)):(this.model.named.ClearName(n.name,n.scope),this.autocomplete_matcher.RemoveFunctions(o)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 8:{let o=this.ApplyBordersInternal(n);o.start.sheet_id===this.active_sheet.id?(r.render_area=y.Join(o,r.render_area),r.style_area=y.Join(o,r.style_area)):r.style_event=!0}break;case 25:this.ShowSheetInternal(n),r.sheets=!0,r.structure_event=!0;break;case 24:{let o=[],a=this.model.sheets.list[n.index];for(let s=0;s<this.model.sheets.length;s++)s!==n.index&&(s===n.move_before&&o.push(a),o.push(this.model.sheets.list[s]));n.move_before>=this.model.sheets.length&&o.push(a),this.model.sheets.Assign(o),r.sheets=!0,r.structure_event=!0}break;case 23:{let o=this.ResolveSheet(n);o&&(this.RenameSheetInternal(o,n.new_name),r.sheets=!0,r.structure_event=!0)}break;case 3:{let o=this.ResizeRowsInternal(n);if(o)if(o.start.sheet_id===this.active_sheet.id){let a=this.active_sheet.RealArea(new y(o.start,o.end));r.render_area=y.Join(a,r.render_area),r.data_area=y.Join(a,r.data_area),r.data_event=!0}else r.data_event=!0,r.pending||(r.pending=[]),o.start.sheet_id&&r.pending.push(o.start.sheet_id);r.structure_event=!0}break;case 4:this.ResizeColumnsInternal(n),r.structure_event=!0;break;case 18: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 15:case 14:{let o=this.FindSheet(n.area),a=o.cells.GetCell(n.area,!0);if(a){let s;a.merge_area?(s=new y(a.merge_area.start),a=o.cells.GetCell(a.merge_area.start,!0)):s=new y(n.area),n.key===14?a.SetNote(n.note):(a.hyperlink=n.reference||void 0,a.render_clean=[]),o===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 28:{let o=this.SortTableInternal(n);o&&o.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(o,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(o,r.render_area))):r.data_event=!0}break;case 6:{let o=this.SetRangeInternal(n,r);if(o){let s=this.model.sheets.Find(o.start.sheet_id||this.active_sheet.id)?.TablesFromArea(o,!0)||[];for(let l of s)this.UpdateTableColumns(l)}o&&o.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(o,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(o,r.render_area))):r.data_event=!0}break;case 21:this.DeleteSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 20:this.DuplicateSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 19:{let o=this.AddSheetInternal(n.name,n.insert_index);typeof o=="number"&&n.show&&this.ActivateSheetInternal({key:22,id:o}),r.structure_event=!0,r.sheets=!0,r.structure=!0}break;case 22:this.ActivateSheetInternal(n);break;default:console.warn(`unhandled command: ${at[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,conditional_format:r.conditional_formatting_event}),this.batch?this.batch_events.push(...i):this.grid_events.Publish(i),r}};var Pt=class extends De{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,o]of i.listeners.entries())i.node.removeEventListener(n,o);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 lt=class extends st{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=P.GetInstance();constructor(e={},t,r=vt,i=!0,n){if(super(e,t),this.decimal_separator_code=N.decimal_separator.charCodeAt(0),this.theme=JSON.parse(JSON.stringify(r)),!i){this.headless=!0,this.layout=new zt(this.model,this.view);return}this.DOM=n,this.layout=new Nt(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 Ut(this.theme,this.layout,this.model,this.view,this.options),this.selection_renderer=new Et(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:14,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 Ne(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 o=this.layout.AnnotationLayoutToRect(n.data.layout).Shift(20,20),a=!0;for(;a;){a=!1;for(let s of this.active_sheet.annotations)if(s!==n&&s.scaled_rect&&s.scaled_rect.top===o.top&&s.scaled_rect.left===o.left){o=o.Shift(20,20),a=!0;break}}n.data.layout=this.layout.RectToAnnotationLayout(o)}return i&&(G.IsRectangle(i)?(n.data.layout=void 0,n.rect=G.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(o=>o===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:s=>{s.button===0&&this.layout.AnnotationMouseDown(e,n,s,o,a).then(l=>{l&&this.grid_events.Publish(l),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)})},focusin:()=>{for(let s of this.layout.GetFrozenAnnotations(e))s.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:s=>{for(let l of this.layout.GetFrozenAnnotations(e))l.classList.remove("clone-focus");this.formula_bar&&this.formula_bar.IsElement(s.relatedTarget)?(this.primary_selection.empty=!0,this.RenderSelections(),this.editing_annotation=e,this.layout.ShowSelections(!0)):this.formula_bar?.IsExpandButton(s.relatedTarget)||(this.selected_annotation===e&&(this.selected_annotation=void 0),this.ShowGridSelection())}}});i.node=n,i.content_node=this.DOM.Div("annotation-content",n);let o=this.DOM.Div("annotation-move-target",n),a=this.DOM.Div("annotation-resize-target",n);n.addEventListener("keydown",s=>{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(s.key){case"ArrowUp":case"Up":s.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(s.ctrlKey)return;h.x--;break;case"ArrowRight":case"Right":if(s.ctrlKey)return;h.x++;break;case"ArrowDown":case"Down":s.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"Backspace":s.metaKey&&ee.is_mac&&(this.Focus(),this.RemoveAnnotation(e));break;case"Delete":case"Del":this.Focus(),this.RemoveAnnotation(e);break;default:return}if(s.stopPropagation(),s.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()}ShowHeaders(e=!0){this.ExecCommand({key:18,show:e})}FromImportData(e,t=!1){this.RemoveAnnotationNodes();let r=e.sheets,i=r.map(()=>X.Blank(this.model.theme_style_properties).toJSON()),n;if(typeof e.active_tab=="number")n=i[e.active_tab]?.id;else for(let a=0;a<e.sheets.length;a++)if(!e.sheets[a].hidden){n=i[a].id;break}this.UpdateSheets(i,!0,n);let o={};this.model.macro_functions.clear(),this.ClearSelection(this.primary_selection),this.model.tables.clear();for(let a=0;a<r.length;a++){let s=this.model.sheets.list[a];s.ImportData(r[a]),o[s.name]=s.id;for(let l of r[a].cells)l.table&&(l.table.area.start.sheet_id=s.id,this.model.tables.set(l.table.name.toLowerCase(),l.table));for(let l of this.model.tables.values())this.UpdateTableColumns(l)}this.model.sheets.UpdateIndexes(),this.model.named.Reset(),e.named&&this.model.UnserializeNames(e.named,this.active_sheet);for(let a of this.active_sheet.annotations)this.AddAnnotation(a,!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)}UpdateTabBar(){this.tab_bar&&this.tab_bar.Update()}UpdateTheme(e=!1,t){if(!e)for(let i of Object.keys(this.theme))delete this.theme[i];let r=JSON.parse(JSON.stringify(vt));this.view_node&&(r={...ui(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 ot({theme:this.theme,container:i})),this.InitFormulaBar(e,this.autocomplete)),this.options.tab_bar&&(this.tab_bar=new It(this.layout,this.model,this.view,this.options,e),this.tab_bar.Subscribe(n=>{switch(n.type){case"cancel":break;case"scale":{let o=this.layout.scale;if(o=Math.round(n.value*1e3)/1e3,o=Math.min(2,Math.max(o,.5)),this.options.persist_scale_key&&localStorage.setItem(this.options.persist_scale_key,JSON.stringify({scale:o})),this.scale=o,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"),ee.is_mac&&ee.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,o,a)=>{let s=this.model.tables.get(n.toLowerCase());s&&this.SortTable(s,{column:o,asc:a})},focus:()=>this.Focus()},this.options.scrollbars),this.selection_renderer.Initialize(),this.layout.UpdateTiles(),this.autocomplete||(this.autocomplete=new ot({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:10,area:e||this.primary_selection.area}))}UnmergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:11,area:e||this.primary_selection.area}))}Focus(e=""){ee.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.area}let i=new y(e.start,e.end),n={key:26,area:{start:i.start,end:i.end},error:r};t&&(Array.isArray(t)?n.list=t:typeof t=="object"&&t.start&&t.end&&V(t.start)&&V(t.end)&&(n.range=t)),this.ExecCommand(n),!this.primary_selection.empty&&(!e.start.sheet_id||e.start.sheet_id===this.active_sheet.id)&&i.Contains(this.primary_selection.target)&&requestAnimationFrame(()=>this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target))}SetName(e,t,r,i,n=!1){let o=this.model.named.ValidateNamed(e);if(!o)throw new Error("invalid name");if(e=o,this.autocomplete_matcher){let s=this.autocomplete_matcher.Get(e);if(s&&(!s.named||!n)&&(t||r))throw new Error("name already defined")}let a={key:17,name:e,scope:i};if(t)V(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,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.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=>V(r)?new y(r):new y(r.start,r.end));if(e.nodes?.length){if(!this.external_editor){let r=new Pt(this.model,this.view);this.external_editor=r,r.Subscribe(()=>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(V(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}FormatR1C1(e,t){tt(t)&&(t=t.start),Array.isArray(e)||(e=[[e]]);let r={type:"address",label:"",row:t.row,column:t.column,sheet:t.sheet_id?this.model.sheets.Name(t.sheet_id):this.active_sheet.name,position:0,id:0};for(let i=0;i<e.length;i++){let n=e[i];for(let o=0;o<n.length;o++){let a=n[o];if(typeof a=="string"&&a[0]==="="){let s=this.parser.Parse(a);s.expression&&(n[o]="="+this.parser.Render(s.expression,{missing:"",r1c1:!0,r1c1_base:{...r,row:t.row+i,column:t.column+o}}))}}}return e}GetRange(e,t){if(V(e)){let i=this.model.sheets.Find(e.sheet_id||this.active_sheet.id);if(i){if(t==="A1"||t==="R1C1"){let n=i.cells.RawValue(e);return t==="R1C1"?this.FormatR1C1(n,e):n}return t==="formatted"?i.GetFormattedRange(e):i.cells.GetRange(e)}return}let r=this.model.sheets.Find(e.start.sheet_id||this.active_sheet.id);if(r){if(t==="A1"||t==="R1C1"){let i=r.cells.RawValue(e.start,e.end);return t==="R1C1"?this.FormatR1C1(i,e):i}return 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:o,r1c1:a}=r;if(r.argument_separator){let s={argument_separator:this.parser.argument_separator,decimal_mark:this.parser.decimal_mark};this.parser.Save();let l=!1;if(r.argument_separator===","&&this.parser.argument_separator!==","&&(this.parser.SetLocaleSettings("."),l=!0),r.argument_separator===";"&&this.parser.argument_separator!==";"&&(this.parser.SetLocaleSettings(","),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:s.decimal_mark,convert_argument_separator:s.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.Restore()}if(t=this.UntranslateData(t),!Array.isArray(t))i||o?this.ExecCommand({key:6,area:e,value:t,array:o,r1c1:a}):this.ExecCommand({key:6,area:e.start,value:t,array:o,r1c1:a});else{if(Ar(t)){if(i){if(e.rows>t.length){let l=Math.floor(e.rows/t.length);if(l>1){let d=[...t];for(let h=0;h<l;h++){let u=JSON.parse(JSON.stringify(d));t.push(...u)}}}let s=0;for(let l of t)s=Math.max(s,l.length);if(e.columns>s){let l=Math.floor(e.columns/s);if(l>1)for(let d of t){for(;d.length<s;)d.push(void 0);let h=[...d];for(let u=0;u<l;u++){let m=JSON.parse(JSON.stringify(h));d.push(...m)}}}}}else if(i){let s=e.entire_column?this.active_sheet.rows:e.rows,l=e.entire_row?this.active_sheet.columns:e.columns,d=s*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+=s)h[u]=t.slice(m,m+s);t=h}else t=[t];n&&(t=this.Transpose(t)),this.ExecCommand({key:6,area:e,value:t,array:o,r1c1:a})}!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}X.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)}Indent(e,t=0){if(!e){if(this.primary_selection.empty)return;e=this.active_sheet.RealArea(this.primary_selection.area)}this.ExecCommand({key:9,area:e,delta: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,t=!1){this.options.scrollbars&&this.layout.ScrollIntoView(e,t)}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 o=t[n.name.toUpperCase()];o&&(i=!0,n.name=o)}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)?Ar(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=0,n=12;r||(i=e.GetColumnWidth(t));for(let o=0;o<e.cells.rows;o++){let a=e.CellData({row:o,column:t}),s=a.formatted||"";if(typeof s!="string"&&(s=s.map(l=>l.text).join("")),s&&s.length){let l=this.tile_renderer.MeasureText(s,F.Font(a.style||{}));i=Math.max(i,Math.ceil(l.width)+n)}}i>n+2&&e.SetColumnWidth(t,i)}EnsureActiveSheet(e=!1){for(let t of this.model.sheets.list)if(t===this.active_sheet){e&&this.ActivateSheetInternal({key:22,id:t.id,force:!0});return}this.ActivateSheetInternal({key:22,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 o of n)this.AddAnnotation(o,!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=(o="")=>{let a=o.toLowerCase();for(let s of this.model.sheets.list)if(s.name.toLowerCase()===a)return s.id;return this.active_sheet.id},r=o=>{for(let a of this.model.sheets.list)if(a.id===o)return a;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":{let o=this.model.GetName(n.expression.name,this.active_sheet.id);o?.type==="range"&&(i=o.area),i||this.primary_selection.empty||this.SetName(n.expression.name.toUpperCase(),this.primary_selection.area)}break;default:break}if(i){let o=r(i.start.sheet_id);if(o.columns>=i.end.column&&o.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 Ft(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 Dt(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 s of this.layout.grid_tiles)for(let l of s)l.dirty=!0;let i=this.render_tiles.start,n=this.render_tiles.end,o=[];for(let s=i.row;s<=n.row;s++)o.push(s);let a=[];for(let s=i.column;s<=n.column;s++)a.push(s);i.row>0&&this.active_sheet.freeze.rows&&o.push(0),i.column>0&&this.active_sheet.freeze.columns&&a.push(0);for(let s of a)for(let l of o){let d=this.layout.grid_tiles[s][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,o=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 a=this.layout.RowHeight(n),s=a,l=this.layout.OffsetCellAddressToRectangle({row:n,column:0}),d=i.y+l.bottom;this.layout.ShowTooltip({left:!0,text:`${s}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)],b=m.view[this.view_index]?.node;b&&p.push(b),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})}ve(this.layout.mask,"row-resize",m=>{let f=Math.max(-a,Math.round(m.offsetY-o));if(f+a!==s){s=f+a,this.layout.SetRowHeight(n,s),this.layout.UpdateTooltip({text:`${s}px`,y:d+f});for(let{annotation:p,y:b}of h)p.scaled_rect&&(p.scaled_rect.top=b+f);for(let{annotation:p,height:b}of u)p.scaled_rect&&(p.scaled_rect.height=b+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:b}of u)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);for(let{annotation:p,nodes:b}of h)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);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,a),this.ExecCommand({key:3,row:m,height:s/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 o=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=o}else this.Select(n,new y(t),{column:0,row:t.row});this.RenderSelections(),ve(this.layout.mask,[],o=>{let a=this.layout.CoordinateToRowHeader(o.offsetY-i.y),s=new y(a,t,!0);(n.empty||!s.Equals(n.area))&&(this.Select(n,s,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,o=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 a=this.layout.ColumnWidth(n),s=a,l=this.layout.OffsetCellAddressToRectangle({row:0,column:n}),d=i.x+l.right;this.layout.ShowTooltip({up:!0,text:`${s}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)],b=m.view[this.view_index]?.node;b&&p.push(b),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})}ve(this.layout.mask,"column-resize",m=>{let f=Math.max(-a,Math.round(m.offsetX-o));if(f+a!==s){s=f+a,this.layout.UpdateTooltip({text:`${s}px`,x:d+f}),this.layout.SetColumnWidth(n,s);for(let{annotation:p,x:b}of h)p.scaled_rect&&(p.scaled_rect.left=b+f);for(let{annotation:p,width:b}of u)p.scaled_rect&&(p.scaled_rect.width=b+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:b}of u)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);for(let{annotation:p,nodes:b}of h)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);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:s/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 o=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=o}else this.Select(n,new y(t),{row:0,column:t.column});this.RenderSelections(),ve(this.layout.mask,[],o=>{let a=this.layout.CoordinateToColumnHeader(o.offsetX-i.x),s=new y(a,t,!0);(n.empty||!s.Equals(n.area))&&(this.Select(n,s,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?ze.instance.HTML(ze.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,o=t.y-i.top,a=r.renderer_data?.text_data?.strings||[];for(let s of a)for(let l of s)if(typeof l.left=="number"&&typeof l.top=="number"&&typeof l.width=="number"&&typeof l.height=="number"&&n>=l.left&&o>=l.top&&n<=l.left+l.width&&o<=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)){ee.is_mobile&&this.overlay_editor?.edit_node?.focus(),this.OverlayEditCell({target:i,area:new y(i)},!1);return}let o=this.layout.grid_cover.getBoundingClientRect(),a={x:o.left,y:o.top},s=[],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(),s.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",reference: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);ve(this.layout.mask,s,h=>{let u={x:h.offsetX-a.x,y:h.offsetY-a.y},m=d.Clamp(u.x,u.y),f=this.layout.PointToAddress_Grid(m),p=this.layout.scroll_reference_node,b=!1;this.container&&this.options.scrollbars&&(u.x<p.scrollLeft?(p.scrollLeft-=25,b=!0):u.x>p.scrollLeft+this.container.clientWidth&&(p.scrollLeft+=25,b=!0),u.y<p.scrollTop?(p.scrollTop-=25,b=!0):u.y>p.scrollTop+this.container.clientHeight&&(p.scrollTop+=25,b=!0),b&&(o=this.layout.grid_cover.getBoundingClientRect(),a.x=o.left+document.body.scrollLeft,a.y=o.top+document.body.scrollTop));let g=new y(f,i,!0);if(l&&(g=l.Clone(),g.ConsumeAddress(f),g.rows!==l.rows&&g.columns!==l.columns)){let C={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};C.rows>=C.columns?g=new y({row:g.start.row,column:l.start.column},{row:g.end.row,column:l.end.column}):g=new y({row:l.start.row,column:g.start.column},{row:l.end.row,column:g.end.column})}(n.empty||!g.Equals(n.area))&&(this.Select(n,g,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 o=0;o<r;o++)t[n][o]=e[o][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:30,table:h},{key:29,area:e,sortable:u,totals:m,theme:f}]);return}let i=[],n=[],o=t.columns,a=e.rows,s=!1,l=!1;e.columns===t.columns?s=e.start.row<t.start.row:(o=t.rows,a=e.columns,s=e.start.column<t.start.column,r=this.Transpose(r),l=!0);for(let h=0;h<a;h++)i[h]=[],n[h]=[];for(let h=0;h<o;h++){let u=0;if(r.length>1){u=1;let m=[],f=[];for(let p=0;p<r.length;p++){let b=r[p][h];b.ValueIsNumber()&&(f.push(p),m.push(b.value))}if(m.length>1){let p=m.slice(1).map((b,g)=>b-m[g]);p.every(b=>b===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 _=this.parser.Parse(p.value);_.expression&&_.full_reference_list?.length&&(f=_.expression)}let b=0,g=m,C=r.length,x=0,v=u;s&&(g=a-r.length+m,C=-r.length,v=-u);for(let _=g;_>=0&&_<a;_+=C,b+=C,x+=v){if(f)i[_][h]="="+this.parser.Render(f,{offset:{rows:b,columns:0}});else{let w=r[m][h];w.ValueIsNumber()?i[_][h]=w.value+x:i[_][h]=w.value}n[_][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.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;xe.test(n)?i=`'${n}'!${i}`:i=`${n}!${i}`}if(this.overlay_editor?.editing&&this.overlay_editor.selecting)this.overlay_editor.InsertReference(i);else if(this.formula_bar&&this.formula_bar.selecting)this.formula_bar.InsertReference(i);else if(this.external_editor_config&&(this.external_editor?.active&&(this.external_editor.FocusEditor(),this.external_editor.InsertReference(i)),this.external_editor_config.update)){let n=this.external_editor_config.update.call(0,i);n&&Array.isArray(n)&&this.HighlightDependencies(n.filter(o=>!!o).map(o=>V(o)?new y(o):new y(o.start,o.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||ee.is_mac&&e.metaKey)&&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},o=!1,a=!1;if(e.ctrlKey||ee.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"Backspace":e.metaKey&&ee.is_mac&&(i.empty||this.DeleteSelection(i));break;case"Delete":case"Del":{e.stopPropagation(),e.preventDefault();for(let s=0;s<this.model.sheets.length;s++)if(this.model.sheets.list[s]===this.active_sheet){this.DeleteSheet(s);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 s={},l=this.primary_selection.empty?{}:this.active_sheet.CellData(this.primary_selection.target).style||{};switch(e.key.toLowerCase()){case"b":s.bold=!l.bold;break;case"i":s.italic=!l.italic;break;case"u":s.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(s).length&&this.ApplyStyle(void 0,s)}}else{if(/^F\d+$/.test(e.key))return;switch(e.key){case"Tab":e.shiftKey?n.columns--:n.columns++,o=!0;break;case"Enter":e.shiftKey?n.rows--:n.rows++,o=!0;break;case"ArrowDown":case"Down":n.rows++,a=e.shiftKey;break;case"ArrowUp":case"Up":n.rows--,a=e.shiftKey;break;case"ArrowLeft":case"Left":n.columns--,a=e.shiftKey;break;case"ArrowRight":case"Right":n.columns++,a=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,o,a,!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 o={...e.target};i>0?o.row=Math.max(o.row,e.area.end.row):i<0&&(o.row=Math.min(o.row,e.area.start.row)),r>0?o.column=Math.max(o.column,e.area.end.column):r<0&&(o.column=Math.min(o.column,e.area.start.column));let a=this.active_sheet.cells,s=a.GetCell(e.target,!1);if(!s||s.type===0&&!s.area)return!1;let l={...o};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++)s=a.GetCell({row:d.row,column:u},!1),h=h||!!s&&(s.type!==0||!!s.area),!h&&s&&s.merge_area&&(s=a.GetCell(s.merge_area.start,!1),h=h||!!s&&(s.type!==0||!!s.area));else for(let u=e.area.start.row;!h&&u<=e.area.end.row;u++)s=a.GetCell({row:u,column:d.column},!1),h=h||!!s&&(s.type!==0||!!s.area),!h&&s&&s.merge_area&&(s=a.GetCell(s.merge_area.start,!1),h=h||!!s&&(s.type!==0||!!s.area));if(!h)break;l=d}if(t){i?(o.row=e.target.row,o.column=e.area.start.column,l.column=e.area.end.column):(o.column=e.target.column,o.row=e.area.start.row,l.row=e.area.end.row);let d=new y(o,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:12,area:t})}SetInferredType(e,t,r=!1,i=!0){let n=e.target||e.area.start,o=this.active_sheet.CellData(n);if(o.area){if(!r&&o.area.count>1||!e.area||!e.area.Equals(o.area)){this.Error(2);return}}else if(r){for(let u of this.active_sheet.cells.Iterate(e.area,!1))if(u.area){this.Error(2);return}}let a=this.active_sheet.GetValidation(n)[0];if(a&&a.error){let u;if(a.type==="list"?u=a.list:a.type==="range"&&(u=this.GetValidationRange(a.area)),u&&u.length){let m=!1;if(t){let f=t.toUpperCase();for(let p of u)if(p&&p.toString().toUpperCase()===f){t=p.toString(),m=!0;break}}if(!m){this.Error(3);return}}}o.merge_area&&(n=o.merge_area.start);let s=typeof t=="string"&&t.trim()[0]==="=",l=[];if(s&&(t=this.FixFormula(t||""),!this.active_sheet.HasCellStyle(n))){let u=this.parser.Parse(t);if(u){if(u.expression?.type==="call"&&(!o.style||!o.style.number_format||z.Equals(o.style.number_format,"General"))){let m=u.expression.name.toLowerCase(),f;switch(m){case"today":f="Short Date";break;case"now":f="Timestamp";break}f&&l.push({key:7,area:r?e.area:n,style:{number_format:f},delta:!0})}if(u.dependencies){let m,f=u.dependencies;for(let p of Object.keys(f.addresses)){let b=f.addresses[p];if(this.active_sheet.HasCellStyle({...b})){let g=this.active_sheet.CellData({...b});if(g.style&&g.style.number_format&&(!m||/%/.test(m))&&(m=z.Translate(g.style.number_format),!/%/.test(m)))break}}if(m){let p={number_format:z.SymbolicName(m)||m};l.push({key:7,area:r?e.area:n,style:p,delta:!0})}}}}let d=this.parser.Parse(t||"").expression;d?.type==="group"&&d.elements.length===1&&d.elements[0].type==="complex"&&(d=d.elements[0]);let h=d&&d.type==="complex"?{type:7,value:{real:d.real,imaginary:d.imaginary}}:ce.TryParse(t);if(!s&&h.type===3){let u="",m=h.hints||{};(!o.style||!o.style.number_format||z.Equals(o.style.number_format,"General"))&&(m.Date?u="Short Date":m.Exponential?u="Exponential":m.Percent?u="Percent":m.Currency?u="Currency":(m.Grouping||m.Parens)&&(u="Accounting")),u&&l.push({key:7,area:r?e.area:n,style:{number_format:u},delta:!0})}if(l.push({key:6,area:r?e.area:n,array:r,value:s?this.UntranslateFunction(t||""):h.value}),i)this.ExecCommand(l);else return l}FixFormula(e){if(e.trim()[0]!=="=")return e;e=e.replace(/^\s+/,"");let t=!1,r=!1,i=0,n=!1,o=e.length;for(let a=0;a<o;a++){let s=e[a];if(!n)switch(s){case'"':t?e[a+1]==='"'?a++: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.GetName(r.name,this.active_sheet.id)?.type==="range"&&(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(z.Get(e.style.number_format).date_format){let i=we(e.value),n=i.getUTCHours()||i.getUTCMinutes()||i.getUTCSeconds()?"Timestamp":"Short Date";t=z.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)+"%",N.decimal_separator===","&&(t=t.replace(/\./,","))}else t&&N.decimal_separator===","&&(t=e.value.toString().replace(/\./,","));else{if(e.ValueIsBoolean())return e.value.toString().toUpperCase();e.ValueIsNumber()?t&&N.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(),N.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),o;if(this.HideHoverInfo(),n.merge_area?(o=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)):o=this.layout.OffsetCellAddressToRectangle(i),n.style?.locked){console.info("cell is locked for editing");return}o=o.Shift(this.layout.header_size.width,this.layout.header_size.height);let a=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)))?a="%":a=void 0:a=this.NormalizeCellValue(n),this.overlay_editor?.Edit(e,o.Expand(-1,-1),n,a,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 o=this.SelectingArgument();if(t.empty)if(o){let a={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(a))}else this.Select(t,new y({row:0,column:0}));else{let a=this.active_sheet.CellData(t.target);if(a.merge_area&&r&&(r=!a.merge_area.Equals(t.area)),r&&t.area.count>1){let s=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,s);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,s,l)}else if(i&&t&&t.target){let s=t.area,l=t.target,d=s.start,h=s.end,u={row:1/0,column:1/0};if(e.columns&&(s.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):s.end.column>l.column?(h.column=this.StepVisibleColumns(h.column,e.columns),u.column=h.column):s.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&&(s.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):s.end.row>l.row?(h.row=this.StepVisibleRows(h.row,e.rows),u.row=h.row):s.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 s=t.target;a.merge_area?(e.columns<0?s.column=this.StepVisibleColumns(a.merge_area.start.column,-1):e.columns>0&&(s.column=this.StepVisibleColumns(a.merge_area.end.column,1)),e.rows<0?s.row=this.StepVisibleRows(a.merge_area.start.row,-1):e.rows>0&&(s.row=this.StepVisibleRows(a.merge_area.end.row,1))):(s.row=this.StepVisibleRows(s.row,e.rows),s.column=this.StepVisibleColumns(s.column,e.columns)),this.EnsureAddress(s)&&(n=!0),this.Select(t,new y({row:Math.min(Math.max(0,s.row),this.active_sheet.rows-1),column:Math.min(Math.max(0,s.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 o=0;o<r;o++)if(this.additional_selections[o].area.spreadsheet_label===n&&this.additional_selections[o].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);e:for(;;){for(let s of this.active_sheet.cells.Iterate(n,!1))if(s.merge_area&&!n.ContainsArea(s.merge_area)){t.ConsumeArea(s.merge_area),n=this.active_sheet.RealArea(t);continue e}break}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 o=this.active_sheet.CellData(e.target),a="";o.formatted&&(typeof o.formatted=="string"?a=o.formatted:a=o.formatted.map(s=>s.flag===1||s.flag===6?"":s.text).join("")),this.overlay_editor?.UpdateCaption(a)}else e.empty=!0;e===this.primary_selection&&(ee.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),n=this.active_sheet.GetValidation(this.primary_selection.target)[0];if(n&&!t.style?.locked){let o;n.type==="list"?o=n.list:n.type==="range"&&(o=this.GetValidationRange(n.area)),o&&o.length&&this.layout.ShowDropdownCaret(t.merge_area||new y(this.primary_selection.target),o,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 o of e)for(let a of o)typeof a=="number"?(i.real+=a,r++):ae(a)&&(i.real+=a.real,i.imaginary+=a.imaginary,r++),typeof a<"u"&&t++;let n=o=>{let a=Math.floor(Math.log10(o));return a<-6||a>10?z.Get("Exponential"):a<=-1?z.Get("General"):z.Get("Number")};if(t>1)if(r>0){let o=z.Get("General");if(i.imaginary){let a={real:i.real/r,imaginary:i.imaginary/r};return[{label:"Count",value:t.toString()},{label:"Sum",value:ie.FormatPartsAsText(o.FormatComplex(i))},{label:"Average",value:ie.FormatPartsAsText(o.FormatComplex(a))}]}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.MatchSelection(e.area,i)||y.CellAddressToLabel(i.start)}}OnDropdownSelect(e){if(typeof e<"u"){let i=ce.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=bi(i).outerHTML;e.clipboardData.setData("text/plain",n)}}}}else{let t=this.active_sheet.RealArea(this.primary_selection.area),r=t.columns,i=t.rows,n=[],o=[];for(let s=0;s<i;s++){let l=[];for(let d=0;d<r;d++){let h={row:t.start.row+s,column:t.start.column+d},u=this.active_sheet.CellData(h),m="";u.calculated!==void 0?u.calculated_type===7?m=Oe(u.calculated):m=u.calculated.toString():u.type===7?m=Oe(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}),o.push(JSON.parse(JSON.stringify(f)))}n.push(l)}let a=n.map(s=>s.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 o=this.completion_list.querySelectorAll("a");this.active_element=o[this.selected_index],o[this.selected_index].classList.add("selected"),this.last_completion=o[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 at=(k=>(k[k.Null=0]="Null",k[k.InsertRows=1]="InsertRows",k[k.InsertColumns=2]="InsertColumns",k[k.ResizeRows=3]="ResizeRows",k[k.ResizeColumns=4]="ResizeColumns",k[k.Select=5]="Select",k[k.SetRange=6]="SetRange",k[k.UpdateStyle=7]="UpdateStyle",k[k.UpdateBorders=8]="UpdateBorders",k[k.Indent=9]="Indent",k[k.MergeCells=10]="MergeCells",k[k.UnmergeCells=11]="UnmergeCells",k[k.Clear=12]="Clear",k[k.UpdateTheme=13]="UpdateTheme",k[k.SetNote=14]="SetNote",k[k.SetLink=15]="SetLink",k[k.Freeze=16]="Freeze",k[k.SetName=17]="SetName",k[k.ShowHeaders=18]="ShowHeaders",k[k.AddSheet=19]="AddSheet",k[k.DuplicateSheet=20]="DuplicateSheet",k[k.DeleteSheet=21]="DeleteSheet",k[k.ActivateSheet=22]="ActivateSheet",k[k.RenameSheet=23]="RenameSheet",k[k.ReorderSheet=24]="ReorderSheet",k[k.ShowSheet=25]="ShowSheet",k[k.DataValidation=26]="DataValidation",k[k.Reset=27]="Reset",k[k.SortTable=28]="SortTable",k[k.InsertTable=29]="InsertTable",k[k.RemoveTable=30]="RemoveTable",k[k.AddConditionalFormat=31]="AddConditionalFormat",k[k.RemoveConditionalFormat=32]="RemoveConditionalFormat",k))(at||{});var Lt=class{function_names=[];argument_separator=N.argument_separator.charCodeAt(0);function_map=new Map;RemoveFunctions(e){Array.isArray(e)||(e=[e]);for(let t of e)this.function_map.delete(t.name.toLowerCase());this.UpdateNameList()}AddFunctions(e){Array.isArray(e)||(e=[e]);for(let t of e)this.function_map.set(t.name.toLowerCase(),t);this.UpdateNameList()}SetFunctions(e){this.function_map.clear();for(let t of e)this.function_map.set(t.name.toLowerCase(),t);this.UpdateNameList()}NormalizeIdentifier(e){return this.function_map.get(e.toLowerCase())?.name}Get(e){return this.function_map.get(e.toLowerCase())}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],o=new RegExp("^"+n.replace(".","\\."),"i");r={completions:this.function_names.filter(s=>o.test(s)).map(s=>this.function_map.get(s.toLowerCase())).filter(s=>!!s),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.get(i.function.toLowerCase());n&&(r.tooltip='<span class="notranslate">'+n.name+"</span>",r.arguments="("+(n.arguments||[]).map((o,a)=>{let s=o.name||"argument";return a===i.argument?`<span class="active-argument">${s}</span>`:s}).join(N.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,o=0;for(let s of e){let l=s.charCodeAt(0);if(n)l===34&&(n=!1);else switch(l){case 40:t.push({buffer:i.trim(),argument:r,position:o-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+=s:i=""}o++}let a=t.pop();return{function:a?.buffer||void 0,position:a?.position||0,argument:r}}UpdateNameList(){this.function_names=[...this.function_map.keys()].sort((e,t)=>e.toLowerCase().localeCompare(t.toLowerCase()))}};var zi={scrollbars:!0,in_cell_editor:!0,formula_bar:!0,add_tab:!1,tab_bar:"auto",expand_formula_button:!1,expand:!0,repaint_on_cell_change:!0,grid_over_background:!1};var po=c=>{console.error("invalid case")},st=class{grid_events=new le;command_log=new le;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 Lt;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={...zi,...e}}RemoveConditionalFormat(e){this.ExecCommand({key:32,...e})}AddConditionalFormat(e){this.ExecCommand({key:31,format:e})}RemoveTable(e){this.ExecCommand({key:30,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 o=e.start.row;o<=e.end.row;o++)for(let a=e.start.column;a<=e.end.column;a++){let s=n.cells.GetCell({row:o,column:a},!1);if(s&&(s.area||s.merge_area||s.table)){this.Error(4);return}}this.ExecCommand({key:29,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:22,index:t,name:r})}ActivateSheetID(e){this.ExecCommand({key:22,id:e})}DuplicateSheet(e,t,r){let i={key:20,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:19,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:21,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:19,insert_index:e,name:t,show:!0})}DeleteSheetID(e){this.ExecCommand({key:21,id:e})}Reset(){this.ExecCommand({key:27})}SetLink(e,t){this.ExecCommand({key:15,area:e,reference:t})}ShowAll(){let e=[];for(let t=0;t<this.model.sheets.length;t++)e.push({key:25,index:t,show:!0});this.ExecCommand(e)}ShowSheet(e=0,t=!0){let r={key:25,show:t};typeof e=="string"?r.name=e:r.index=e,this.ExecCommand(r)}SortTable(e,t={}){this.ExecCommand({key:28,table:JSON.parse(JSON.stringify(e)),...mi,...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){this.parser.Save(),this.parser.SetLocaleSettings(".");let r=ci(e).map(n=>n.map(o=>{if(o){let a=this.parser.Parse(o);if(a.expression?.type==="complex")return a.expression}return ce.TryParse(o).value}));this.parser.Restore();let i={row:Math.max(0,r.length-1),column:r.reduce((n,o)=>Math.max(n,Math.max(0,o.length-1)),0)};this.ExecCommand([{key:27},{key:6,area:{start:{row:0,column:0},end:i},value:r}])}InsertColumns(e=0,t=1){this.ExecCommand({key:2,before_column:e,count:t})}ReorderSheet(e,t){this.ExecCommand({key:24,index:e,move_before:t})}RenameSheet(e,t){this.ExecCommand({key:23,new_name:t,id:e.id})}Freeze(e=0,t=0,r=!0){this.ExecCommand({key:16,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){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 o=[],a=[],s=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<=s;l++){let d=n.CellData({row:l,column:t}),h=r(d),u=n.GetRowHeight(l);h&&!u?o.push(l):!h&&u&&a.push(l)}o&&i.push({key:3,sheet_id:n.id,row:o,height:n.default_row_height}),a&&i.push({key:3,sheet_id:n.id,row:a,height:0}),i.length&&this.ExecCommand(i)}UpdateSheets(e,t=!1,r){X.Reset();let i=e.map(n=>X.FromJSON(n,this.model.theme_style_properties));if(i.length===0&&i.push(X.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.list)t.push({name:i.name,named:!0,type:"token"});let r=e.slice(0).concat(t);this.autocomplete_matcher.SetFunctions(r)}ResetMetadata(){this.model.document_name=void 0,this.model.user_data=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(){X.Reset(),this.UpdateSheets([],!0),this.model.named.Reset(),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;for(let i of r.cells.Iterate(t)){if(i.style?.locked)return console.info("invalid: locked cells"),!1;if(i.merge_area&&(!t.Contains(i.merge_area.start)||!t.Contains(i.merge_area.end)))return console.info("invalid: merge area"),!1;if(i.area&&(!t.Contains(i.area.start)||!t.Contains(i.area.end)))return console.info("invalid: array"),!1}}return!0}SetValidationInternal(e){let t=this.FindSheet(e.area);if(!t)throw new Error("invalid sheet in set validation");let r={start:e.area.start,end:e.area.end};e.range?t.AddValidation({type:"range",error:!!e.error,area:e.range,target:[r]}):e.list?t.AddValidation({type:"list",error:!!e.error,list:JSON.parse(JSON.stringify(e.list)),target:[r]}):t.RemoveValidations(r)}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 o=r.CellData({row:i,column:n});o&&o.formatted&&(typeof o.formatted=="string"?t.push(o.formatted):t.push(ie.FormatPartsAsText(o.formatted)))}}return t}DeleteSheetInternal(e){let t=!1,r=-1,i="",n=!1,o=e.name?e.name.toLowerCase():"",a=this.model.sheets.list.filter((s,l)=>l===e.index||s.id===e.id||s.name.toLowerCase()===o?(t=s===this.active_sheet,this.model.named.RemoveRangesForSheet(s.id),i=s.name,r=l,!1):!0);if(i&&this.RenameSheetReferences(a,i,"#REF")>0&&(n=!0),!a.length)a.push(X.Blank(this.model.theme_style_properties)),r=0;else if(a.every(s=>!s.visible))a.unshift(X.Blank(this.model.theme_style_properties)),r=0;else for(r>=a.length&&(r=0);!a[r].visible;)r++;return this.model.sheets.Assign(a),t&&this.ActivateSheetInternal({key:22,index:r}),n}RenameSheetInternal(e,t){if(!t||li.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 o=0,a=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 b=t.CellData({row:u,column:p});if(p===e.column+e.table.area.start.column){let g=b.calculated_type||b.type;g===2?o++:g===3&&a++;let C=b.calculated_type?b.calculated:b.value;f.text=C?.toString()||"",f.number=Number(C)||0,f.type=b.calculated_type||b.type}f.data.push({address:{row:u,column:p},data:b.value,type:b.type,style:b.style})}r.push(f)}let s=e.type;s==="auto"&&(a>o?s="numeric":s="text");let l=e.asc?1:-1;switch(s){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,b={columns:0,rows:d.row-m.row},g=this.parser.Parse(p);g.expression&&(p="="+this.parser.Render(g.expression,{offset:b,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,o=e.area.end.column-e.area.start.column+1,a=e.area.start.column;for(let s=0;s<o;s++,a++){let l=t.CellData({row:n,column:a}),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${s+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 s=new Map;for(let l=0;l<r.length;l++){let d=r[l].toLowerCase();d!==i[l]&&s.set(d,i[l])}if(s.size){let l=e.name.toLowerCase();for(let d of this.model.sheets.list)for(let h of d.cells.Iterate())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,b]of s.entries())f.column.toLowerCase()===p&&(f.column=b,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=V(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)),V(e.area)){let n=i.CellData(e.area);if(n.area&&(n.area.rows>1||n.area.columns>1)){this.Error(2);return}let o=Array.isArray(e.value)?Array.isArray(e.value[0])?e.value[0][0]:e.value[0]:e.value;return e.r1c1&&(o=this.TranslateR1C1(e.area,o)),e.array?i.SetArrayValue(r,o):i.SetCellValue(e.area,o),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 o=e.value[n];for(let a=0;a<o.length&&a<r.columns;a++){let s={...r.start,row:r.start.row+n,column:r.start.column+a};o[a]=this.TranslateR1C1(s,o[a])}}else if(typeof e.value=="string"&&e.value[0]==="="){let n=[];for(let o=0;o<r.rows;o++){let a=[];for(let s=0;s<r.columns;s++){let l={...r.start,row:r.start.row+o,column:r.start.column+s};a.push(this.TranslateR1C1(l,e.value))}n.push(a)}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:22,index:n});return}for(let n=0;n<r.length;n++)if(r[n].visible){this.ActivateSheetInternal({key:22,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 18:case 25:case 19:case 20:case 21:case 22:case 23:case 24:case 27:break;case 28:case 30:r.table.area.start.sheet_id||(r.table.area.start.sheet_id=t);break;case 31:r.format.area.start.sheet_id||(r.format.area.start.sheet_id=t);break;case 3:case 4:case 2:case 1:case 16:r.sheet_id||(r.sheet_id=t);break;case 12:case 14:case 15:case 9:case 8:case 10:case 11:case 26:case 6:case 7:case 17:case 5:case 29:case 32:r.area&&(V(r.area)?r.area.sheet_id||(r.area.sheet_id=t):r.area.start.sheet_id||(r.area.start.sheet_id=t));break;default:po(r)}return e}AddSheetInternal(e=X.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=X.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:V(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,o,a){let s=this.parser.Parse(e||""),l=!1;if(s.expression&&(this.parser.Walk(s.expression,d=>{if(d.type==="range"||d.type==="address"){let h=[];d.type==="range"?(d.start.sheet&&d.start.sheet.toLowerCase()===o||!d.start.sheet&&a)&&h.push(d.start,d.end):d.type==="address"&&(d.sheet&&d.sheet.toLowerCase()===o||!d.sheet&&a)&&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(s.expression,{missing:""})}PatchExpressionSheetName(e,t,r){let i=!1,n=this.parser.Parse(e||"");if(n.expression&&(this.parser.Walk(n.expression,o=>(o.type==="address"&&o.sheet&&o.sheet.toLowerCase()===t&&(o.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){for(let o of n.cells.Iterate())if(o.ValueIsFormula()){let a=this.PatchExpressionSheetName(o.value||"",t,r);a&&(o.value=a,i++)}if(n.conditional_formats?.length)for(let o of n.conditional_formats)switch(o.type){case"cell-match":case"expression":{let a=this.PatchExpressionSheetName(o.expression,t,r);a&&(o.expression=a,i++)}break}for(let o of n.annotations)if(o.data.formula){let a=this.PatchExpressionSheetName(o.data.formula,t,r);a&&(o.data.formula=a,i++)}}for(let n of this.model.connected_elements.values())if(n.formula){let o=this.PatchExpressionSheetName(n.formula,t,r);o&&(n.formula=o,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 o={border_top:r},a={border_bottom:r},s={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?(o.border_top_fill={...e.color},a.border_bottom_fill={...e.color},s.border_left_fill={...e.color},l.border_right_fill={...e.color}):(o.border_top_fill={},a.border_bottom_fill={},s.border_left_fill={},l.border_right_fill={}),(t==="none"||t==="all")&&n.UpdateAreaStyle(i,{...o,...a,...s,...l},!0),(t==="top"||t==="outside")&&(i.entire_column||n.UpdateAreaStyle(i.top,{...o},!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,{...a},!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,{...s},!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,o=>(o.type==="address"&&o.r1c1&&(r=!0,o.offset_column?(o.absolute_column=!1,o.column=o.column+e.column):o.absolute_column=!0,o.offset_row?(o.absolute_row=!1,o.row=o.row+e.row):o.absolute_row=!0),!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}e=t.RealArea(e);for(let i of t.cells.Iterate(e))if(i.area&&!e.ContainsArea(i.area)){this.Error(2);return}let r=this.model.tables.keys();for(let i of r){let n=this.model.tables.get(i);if(n&&n.area.start.sheet_id===t.id){let o=new y(n.area.start,n.area.end);if(e.ContainsArea(o)){for(let a=o.start.row;a<=o.end.row;a++)for(let s=o.start.column;s<=n.area.end.column;s++){let l=t.cells.GetCell({row:a,column:s},!1);l&&(l.table=void 0)}this.model.tables.delete(i)}}}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((s,l)=>Math.max(s,l.id),0)+1,i=-1;for(let s=0;s<this.model.sheets.length;s++)this.model.sheets.list[s]===t&&(i=s+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 s=e.insert_before.toLowerCase();for(let l=0;l<this.model.sheets.length;l++)if(this.model.sheets.list[l].name.toLowerCase()===s){i=l;break}}let n={rendered_values:!0},o=X.FromJSON(t.toJSON(n),this.model.theme_style_properties),a=e.new_name||t.name;for(;this.model.sheets.list.some(s=>s.name===a);){let s=a.match(/^(.*?)(\d+)$/);s?a=s[1]+(Number(s[2])+1):a=a+"2"}return o.name=a,o.id=r,this.model.sheets.Splice(i,0,o),o.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 o=y.PatchArea(n,t);o?(n.start.row=o.start.row,n.start.column=o.start.column,n.end.row=o.end.row,n.end.column=o.end.column):n.start.row=n.end.row=n.start.column=n.end.column=-1}return r++,!1}else if(n.type==="address"){let o=y.PatchArea({start:n,end:n},t);return o?(n.row=o.start.row,n.column=o.start.column):n.row=n.column=-1,r++,!1}return!0}),r))return this.parser.Render(i.expression,{missing:""})}PatchConditionalsAndValidations(e){if(e.sheet.data_validation.length){let t=new Set;for(let r of e.sheet.data_validation){let i=[];for(let n of r.target){let o=y.PatchArea(n,e);o&&i.push(o)}if(i.length>0){if(r.target=i,r.type==="range"&&r.area.start.sheet_id===e.sheet.id){let n=y.PatchArea(r.area,e);n?r.area=n:t.add(r)}}else t.add(r)}t.size&&(e.sheet.data_validation=e.sheet.data_validation.filter(r=>!t.has(r)))}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.PatchConditionalsAndValidations({sheet:t,before_column:0,column_count:0,before_row:e.before_row,row_count:e.count});for(let s of this.model.connected_elements.values())if(s.formula){let l=this.PatchFormulasInternal(s.formula,e.before_row,e.count,0,0,t.name.toLowerCase(),!1);l&&(s.formula=l)}let r=Array.from(this.model.tables.values());for(let s of r)if(s.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_row<=s.area.start.row)s.area.start.row+=e.count,s.area.end.row+=e.count;else if(e.before_row<=s.area.end.row){s.area.end.row+=e.count;for(let l=s.area.start.row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=s}}}else if(e.before_row<=s.area.start.row)if(e.before_row-e.count<=s.area.start.row)s.area.start.row+=e.count,s.area.end.row+=e.count;else if(e.before_row-e.count>=s.area.end.row)this.model.tables.delete(s.name.toLowerCase());else{this.model.tables.delete(s.name.toLowerCase());for(let l=e.before_row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table===s&&(h.table=void 0)}}else e.before_row<=s.area.end.row&&(e.before_row-e.count>s.area.end.row&&(s.totals_row=!1),s.area.end.row=Math.max(0,s.area.end.row+e.count,e.before_row-1));this.model.named.PatchNamedRanges(t.id,0,0,e.before_row,e.count);let i=t.name.toLowerCase();for(let s of this.model.sheets.list){let l=s===t;for(let d of s.cells.Iterate())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 s.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=[],o=[],a=[];if(e.count>0){let s=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(s<=d)l.data.layout.tl.address.row+=e.count,l.data.layout.br.address.row+=e.count;else if(s<h||s===h&&u>0)l.data.layout.br.address.row+=e.count,o.push(l);else continue;n.push(l)}}else if(e.count<0){let s=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(s<=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=s,d.data.layout.tl.offset.y=0,d.data.layout.br.address.row+=e.count,o.push(d);else{a.push(d);continue}else if(s<u||s===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.row+=e.count,o.push(d)):(d.data.layout.br.address.row=s,d.data.layout.br.offset.y=0,o.push(d));else continue;n.push(d)}}for(let s of a)t.annotations=t.annotations.filter(l=>l!==s);return{update_annotations_list:n,resize_annotations_list:o,delete_annotations_list:a}}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.PatchConditionalsAndValidations({sheet:t,before_column:e.before_column,column_count:e.count,before_row:0,row_count:0});for(let s of this.model.connected_elements.values())if(s.formula){let l=this.PatchFormulasInternal(s.formula,0,0,e.before_column,e.count,t.name.toLowerCase(),!1);l&&(s.formula=l)}let r=Array.from(this.model.tables.values());for(let s of r)if(s.area.start.sheet_id===e.sheet_id)if(e.count>0){if(e.before_column<=s.area.start.column)s.area.start.column+=e.count,s.area.end.column+=e.count;else if(e.before_column<=s.area.end.column){s.area.end.column+=e.count;for(let l=s.area.start.row;l<=s.area.end.row;l++)for(let d=s.area.start.column;d<=s.area.end.column;d++){let h=t.CellData({row:l,column:d});h.table=s}this.UpdateTableColumns(s)}}else e.before_column<=s.area.start.column?e.before_column-e.count<=s.area.start.column?(s.area.start.column+=e.count,s.area.end.column+=e.count):e.before_column-e.count>=s.area.end.column?this.model.tables.delete(s.name.toLowerCase()):(s.area.start.column=e.before_column,s.area.end.column+=e.count,this.UpdateTableColumns(s)):e.before_column<=s.area.end.column&&(s.area.end.column=Math.max(0,s.area.end.column+e.count,e.before_column-1),this.UpdateTableColumns(s));this.model.named.PatchNamedRanges(t.id,e.before_column,e.count,0,0);let i=t.name.toLowerCase();for(let s of this.model.sheets.list){let l=s===t;for(let d of s.cells.Iterate())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 s.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=[],o=[],a=[];if(e.count>0){let s=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(s<=d)l.data.layout.tl.address.column+=e.count,l.data.layout.br.address.column+=e.count;else if(s<h||s===h&&u>0)l.data.layout.br.address.column+=e.count,o.push(l);else continue;n.push(l)}}else if(e.count<0){let s=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(s<=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=s,d.data.layout.tl.offset.x=0,d.data.layout.br.address.column+=e.count,o.push(d);else{a.push(d);continue}else if(s<u||s===u&&m>0)l<u-1||l===u-1&&m>0?(d.data.layout.br.address.column+=e.count,o.push(d)):(d.data.layout.br.address.column=s,d.data.layout.br.offset.x=0,o.push(d));else continue;n.push(d)}}for(let s of a)t.annotations=t.annotations.filter(l=>l!==s);return{update_annotations_list:n,resize_annotations_list:o,delete_annotations_list:a}}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 27:this.ResetInternal();break;case 12:if(n.area){let o=new y(n.area.start,n.area.end);this.ClearAreaInternal(o),r.data_area=y.Join(o,r.data_area),r.formula=!0}break;case 5:this.SelectInternal(n);break;case 16:this.FreezeInternal(n),r.structure_event=!0;break;case 31:{let o=this.FindSheet(n.format.area);o.conditional_formats.push(n.format),o.Invalidate(new y(n.format.area.start,n.format.area.end)),o===this.active_sheet&&(r.render_area=y.Join(n.format.area,r.render_area)),r.structure_event=!0,r.conditional_formatting_event=!0}break;case 32:{let o,a=0;if(n.format){let s=JSON.stringify(n.format);o=this.FindSheet(n.format.area),o.conditional_formats=o.conditional_formats.filter(l=>JSON.stringify(l)===s?(a++,r.render_area=y.Join(l.area,r.render_area),!1):!0)}else if(n.area){let s=new y(n.area.start,n.area.end);o=this.FindSheet(n.area),o.conditional_formats=o.conditional_formats.filter(l=>{let d=new y(l.area.start,l.area.end);return d.Intersects(s)?(a++,r.render_area=y.Join(d,r.render_area),!1):!0})}o&&a&&(o.FlushConditionalFormats(),r.structure_event=!0,r.conditional_formatting_event=!0)}break;case 29:{let o=this.FindSheet(n.area),a=new y(n.area.start,n.area.end),s=!0;e:for(let l=a.start.row;l<=a.end.row;l++)for(let d=a.start.column;d<=a.end.column;d++){let h=o.cells.GetCell({row:l,column:d},!1);if(h&&(h.area||h.merge_area||h.table)){s=!1;break e}}if(s){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=a.start.row;u<=a.end.row;u++)for(let m=a.start.column;m<=a.end.column;m++){let f=o.cells.GetCell({row:u,column:m},!0);f.table=h}this.UpdateTableColumns(h),o.Invalidate(new y(h.area.start,h.area.end)),o===this.active_sheet?(r.style_area=y.Join(a,r.style_area),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}}break;case 30:{let o=this.FindSheet(n.table.area),a=new y(n.table.area.start,n.table.area.end);for(let l=a.start.row;l<=a.end.row;l++)for(let d=a.start.column;d<=a.end.column;d++){let h=o.cells.GetCell({row:l,column:d},!1);h&&(h.table=void 0)}this.model.tables.delete(n.table.name.toLowerCase());let s=o.RealArea(a.Clone().Shift(-1,-1).Resize(a.rows+2,a.columns+2));o.Invalidate(s),o===this.active_sheet?(r.style_area=y.Join(a,r.style_area),r.render_area=y.Join(a,r.render_area)):r.style_event=!0}break;case 10:{let o=this.FindSheet(n.area);o.MergeCells(new y(n.area.start,n.area.end)),r.structure_event=!0,r.structure_rebuild_required=!0,o===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(o.id))}break;case 11:{let o=this.FindSheet(n.area),a={},s=new y(n.area.start,n.area.end);for(let d of o.cells.Iterate(s,!1))if(d.merge_area){let h=y.CellAddressToLabel(d.merge_area.start)+":"+y.CellAddressToLabel(d.merge_area.end);a[h]=d.merge_area}let l=Object.keys(a);for(let d=0;d<l.length;d++)o.UnmergeCells(a[l[d]]);o===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(o.id)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 9:{let o,a=this.FindSheet(n.area);if(V(n.area)){o=new y(n.area);let s=a.GetCellStyle(n.area,!0);a.UpdateCellStyle(n.area,{indent:Math.max(0,(s.indent||0)+n.delta)},!0)}else{o=new y(n.area.start,n.area.end);for(let s of o){let l=a.GetCellStyle(s,!0);a.UpdateCellStyle(s,{indent:Math.max(0,(l.indent||0)+n.delta)},!0)}}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 7:{let o,a=this.FindSheet(n.area);V(n.area)?(o=new y(n.area),a.UpdateCellStyle(n.area,n.style,!!n.delta)):(o=new y(n.area.start,n.area.end),a.UpdateAreaStyle(o,n.style,!!n.delta)),a===this.active_sheet?(r.style_area=y.Join(o,r.style_area),(!n.delta||n.style.fill||n.style.border_top||n.style.border_left||n.style.border_right||n.style.border_bottom)&&(o=y.Bleed(o),this.active_sheet.Invalidate(o)),r.render_area=y.Join(o,r.render_area)):r.style_event=!0}break;case 26:this.SetValidationInternal(n),(!n.area.start.sheet_id||n.area.start.sheet_id===this.active_sheet.id)&&(r.render_area=y.Join(new y(n.area.start,n.area.end),r.render_area));break;case 17:{let o={type:"token",named:!0,name:n.name,scope:n.scope};n.area||n.expression?(n.area?this.model.named.SetNamedRange(n.name,new y(n.area.start,n.area.end),n.scope):n.expression&&this.model.named.SetNamedExpression(n.name,n.expression,n.scope),this.autocomplete_matcher.AddFunctions(o)):(this.model.named.ClearName(n.name,n.scope),this.autocomplete_matcher.RemoveFunctions(o)),r.structure_event=!0,r.structure_rebuild_required=!0}break;case 8:{let o=this.ApplyBordersInternal(n);o.start.sheet_id===this.active_sheet.id?(r.render_area=y.Join(o,r.render_area),r.style_area=y.Join(o,r.style_area)):r.style_event=!0}break;case 25:this.ShowSheetInternal(n),r.sheets=!0,r.structure_event=!0;break;case 24:{let o=[],a=this.model.sheets.list[n.index];for(let s=0;s<this.model.sheets.length;s++)s!==n.index&&(s===n.move_before&&o.push(a),o.push(this.model.sheets.list[s]));n.move_before>=this.model.sheets.length&&o.push(a),this.model.sheets.Assign(o),r.sheets=!0,r.structure_event=!0}break;case 23:{let o=this.ResolveSheet(n);o&&(this.RenameSheetInternal(o,n.new_name),r.sheets=!0,r.structure_event=!0)}break;case 3:{let o=this.ResizeRowsInternal(n);if(o)if(o.start.sheet_id===this.active_sheet.id){let a=this.active_sheet.RealArea(new y(o.start,o.end));r.render_area=y.Join(a,r.render_area),r.data_area=y.Join(a,r.data_area),r.data_event=!0}else r.data_event=!0,r.pending||(r.pending=[]),o.start.sheet_id&&r.pending.push(o.start.sheet_id);r.structure_event=!0}break;case 4:this.ResizeColumnsInternal(n),r.structure_event=!0;break;case 18: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 15:case 14:{let o=this.FindSheet(n.area),a=o.cells.GetCell(n.area,!0);if(a){let s;a.merge_area?(s=new y(a.merge_area.start),a=o.cells.GetCell(a.merge_area.start,!0)):s=new y(n.area),n.key===14?a.SetNote(n.note):(a.hyperlink=n.reference||void 0,a.render_clean=[]),o===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 28:{let o=this.SortTableInternal(n);o&&o.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(o,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(o,r.render_area))):r.data_event=!0}break;case 6:{let o=this.SetRangeInternal(n,r);if(o){let s=this.model.sheets.Find(o.start.sheet_id||this.active_sheet.id)?.TablesFromArea(o,!0)||[];for(let l of s)this.UpdateTableColumns(l)}o&&o.start.sheet_id===this.active_sheet.id?(r.data_area=y.Join(o,r.data_area),this.options.repaint_on_cell_change&&(r.render_area=y.Join(o,r.render_area))):r.data_event=!0}break;case 21:this.DeleteSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 20:this.DuplicateSheetInternal(n),r.sheets=!0,r.structure_event=!0,r.structure_rebuild_required=!0;break;case 19:{let o=this.AddSheetInternal(n.name,n.insert_index);typeof o=="number"&&n.show&&this.ActivateSheetInternal({key:22,id:o}),r.structure_event=!0,r.sheets=!0,r.structure=!0}break;case 22:this.ActivateSheetInternal(n);break;default:console.warn(`unhandled command: ${at[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,conditional_format:r.conditional_formatting_event}),this.batch?this.batch_events.push(...i):this.grid_events.Publish(i),r}};var Pt=class extends De{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,o]of i.listeners.entries())i.node.removeEventListener(n,o);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 lt=class extends st{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=P.GetInstance();constructor(e={},t,r=vt,i=!0,n){if(super(e,t),this.decimal_separator_code=N.decimal_separator.charCodeAt(0),this.theme=JSON.parse(JSON.stringify(r)),!i){this.headless=!0,this.layout=new zt(this.model,this.view);return}this.DOM=n,this.layout=new Nt(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 Ut(this.theme,this.layout,this.model,this.view,this.options),this.selection_renderer=new Et(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:14,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 Ne(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 o=this.layout.AnnotationLayoutToRect(n.data.layout).Shift(20,20),a=!0;for(;a;){a=!1;for(let s of this.active_sheet.annotations)if(s!==n&&s.scaled_rect&&s.scaled_rect.top===o.top&&s.scaled_rect.left===o.left){o=o.Shift(20,20),a=!0;break}}n.data.layout=this.layout.RectToAnnotationLayout(o)}return i&&(G.IsRectangle(i)?(n.data.layout=void 0,n.rect=G.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(o=>o===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:s=>{s.button===0&&this.layout.AnnotationMouseDown(e,n,s,o,a).then(l=>{l&&this.grid_events.Publish(l),e.data.layout&&this.EnsureAddress(e.data.layout.br.address,1)})},focusin:()=>{for(let s of this.layout.GetFrozenAnnotations(e))s.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:s=>{for(let l of this.layout.GetFrozenAnnotations(e))l.classList.remove("clone-focus");this.formula_bar&&this.formula_bar.IsElement(s.relatedTarget)?(this.primary_selection.empty=!0,this.RenderSelections(),this.editing_annotation=e,this.layout.ShowSelections(!0)):this.formula_bar?.IsExpandButton(s.relatedTarget)||(this.selected_annotation===e&&(this.selected_annotation=void 0),this.ShowGridSelection())}}});i.node=n,i.content_node=this.DOM.Div("annotation-content",n);let o=this.DOM.Div("annotation-move-target",n),a=this.DOM.Div("annotation-resize-target",n);n.addEventListener("keydown",s=>{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(s.key){case"ArrowUp":case"Up":s.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(s.ctrlKey)return;h.x--;break;case"ArrowRight":case"Right":if(s.ctrlKey)return;h.x++;break;case"ArrowDown":case"Down":s.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"Backspace":s.metaKey&&ee.is_mac&&(this.Focus(),this.RemoveAnnotation(e));break;case"Delete":case"Del":this.Focus(),this.RemoveAnnotation(e);break;default:return}if(s.stopPropagation(),s.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()}ShowHeaders(e=!0){this.ExecCommand({key:18,show:e})}FromImportData(e,t=!1){this.RemoveAnnotationNodes();let r=e.sheets,i=r.map(()=>X.Blank(this.model.theme_style_properties).toJSON()),n;if(typeof e.active_tab=="number")n=i[e.active_tab]?.id;else for(let a=0;a<e.sheets.length;a++)if(!e.sheets[a].hidden){n=i[a].id;break}this.UpdateSheets(i,!0,n);let o={};this.model.macro_functions.clear(),this.ClearSelection(this.primary_selection),this.model.tables.clear();for(let a=0;a<r.length;a++){let s=this.model.sheets.list[a];s.ImportData(r[a]),o[s.name]=s.id;for(let l of r[a].cells)l.table&&(l.table.area.start.sheet_id=s.id,this.model.tables.set(l.table.name.toLowerCase(),l.table));for(let l of this.model.tables.values())this.UpdateTableColumns(l)}this.model.sheets.UpdateIndexes(),this.model.named.Reset(),e.named&&this.model.UnserializeNames(e.named,this.active_sheet);for(let a of this.active_sheet.annotations)this.AddAnnotation(a,!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)}UpdateTabBar(){this.tab_bar&&this.tab_bar.Update()}UpdateTheme(e=!1,t){if(!e)for(let i of Object.keys(this.theme))delete this.theme[i];let r=JSON.parse(JSON.stringify(vt));this.view_node&&(r={...ui(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 ot({theme:this.theme,container:i})),this.InitFormulaBar(e,this.autocomplete)),this.options.tab_bar&&(this.tab_bar=new It(this.layout,this.model,this.view,this.options,e),this.tab_bar.Subscribe(n=>{switch(n.type){case"cancel":break;case"scale":{let o=this.layout.scale;if(o=Math.round(n.value*1e3)/1e3,o=Math.min(2,Math.max(o,.5)),this.options.persist_scale_key&&localStorage.setItem(this.options.persist_scale_key,JSON.stringify({scale:o})),this.scale=o,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"),ee.is_mac&&ee.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,o,a)=>{let s=this.model.tables.get(n.toLowerCase());s&&this.SortTable(s,{column:o,asc:a})},focus:()=>this.Focus()},this.options.scrollbars),this.selection_renderer.Initialize(),this.layout.UpdateTiles(),this.autocomplete||(this.autocomplete=new ot({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:10,area:e||this.primary_selection.area}))}UnmergeCells(e){!e&&this.primary_selection.empty||(this.layout.HideDropdownCaret(),this.ExecCommand({key:11,area:e||this.primary_selection.area}))}Focus(e=""){ee.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.area}let i=new y(e.start,e.end),n={key:26,area:{start:i.start,end:i.end},error:r};t&&(Array.isArray(t)?n.list=t:typeof t=="object"&&t.start&&t.end&&V(t.start)&&V(t.end)&&(n.range=t)),this.ExecCommand(n),!this.primary_selection.empty&&(!e.start.sheet_id||e.start.sheet_id===this.active_sheet.id)&&i.Contains(this.primary_selection.target)&&requestAnimationFrame(()=>this.Select(this.primary_selection,this.primary_selection.area,this.primary_selection.target))}SetName(e,t,r,i,n=!1){let o=this.model.named.ValidateNamed(e);if(!o)throw new Error("invalid name");if(e=o,this.autocomplete_matcher){let s=this.autocomplete_matcher.Get(e);if(s&&(!s.named||!n)&&(t||r))throw new Error("name already defined")}let a={key:17,name:e,scope:i};if(t)V(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,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.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=>V(r)?new y(r):new y(r.start,r.end));if(e.nodes?.length){if(!this.external_editor){let r=new Pt(this.model,this.view);this.external_editor=r,r.Subscribe(()=>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(V(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}FormatR1C1(e,t){tt(t)&&(t=t.start),Array.isArray(e)||(e=[[e]]);let r={type:"address",label:"",row:t.row,column:t.column,sheet:t.sheet_id?this.model.sheets.Name(t.sheet_id):this.active_sheet.name,position:0,id:0};for(let i=0;i<e.length;i++){let n=e[i];for(let o=0;o<n.length;o++){let a=n[o];if(typeof a=="string"&&a[0]==="="){let s=this.parser.Parse(a);s.expression&&(n[o]="="+this.parser.Render(s.expression,{missing:"",r1c1:!0,r1c1_base:{...r,row:t.row+i,column:t.column+o}}))}}}return e}GetRange(e,t){if(V(e)){let i=this.model.sheets.Find(e.sheet_id||this.active_sheet.id);if(i){if(t==="A1"||t==="R1C1"){let n=i.cells.RawValue(e);return t==="R1C1"?this.FormatR1C1(n,e):n}return t==="formatted"?i.GetFormattedRange(e):i.cells.GetRange(e)}return}let r=this.model.sheets.Find(e.start.sheet_id||this.active_sheet.id);if(r){if(t==="A1"||t==="R1C1"){let i=r.cells.RawValue(e.start,e.end);return t==="R1C1"?this.FormatR1C1(i,e):i}return 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:o,r1c1:a}=r;if(r.argument_separator){let s={argument_separator:this.parser.argument_separator,decimal_mark:this.parser.decimal_mark};this.parser.Save();let l=!1;if(r.argument_separator===","&&this.parser.argument_separator!==","&&(this.parser.SetLocaleSettings("."),l=!0),r.argument_separator===";"&&this.parser.argument_separator!==";"&&(this.parser.SetLocaleSettings(","),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:s.decimal_mark,convert_argument_separator:s.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.Restore()}if(t=this.UntranslateData(t),!Array.isArray(t))i||o?this.ExecCommand({key:6,area:e,value:t,array:o,r1c1:a}):this.ExecCommand({key:6,area:e.start,value:t,array:o,r1c1:a});else{if(Ar(t)){if(i){if(e.rows>t.length){let l=Math.floor(e.rows/t.length);if(l>1){let d=[...t];for(let h=0;h<l;h++){let u=JSON.parse(JSON.stringify(d));t.push(...u)}}}let s=0;for(let l of t)s=Math.max(s,l.length);if(e.columns>s){let l=Math.floor(e.columns/s);if(l>1)for(let d of t){for(;d.length<s;)d.push(void 0);let h=[...d];for(let u=0;u<l;u++){let m=JSON.parse(JSON.stringify(h));d.push(...m)}}}}}else if(i){let s=e.entire_column?this.active_sheet.rows:e.rows,l=e.entire_row?this.active_sheet.columns:e.columns,d=s*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+=s)h[u]=t.slice(m,m+s);t=h}else t=[t];n&&(t=this.Transpose(t)),this.ExecCommand({key:6,area:e,value:t,array:o,r1c1:a})}!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}X.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)}Indent(e,t=0){if(!e){if(this.primary_selection.empty)return;e=this.active_sheet.RealArea(this.primary_selection.area)}this.ExecCommand({key:9,area:e,delta: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,t=!1){this.options.scrollbars&&this.layout.ScrollIntoView(e,t)}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 o=t[n.name.toUpperCase()];o&&(i=!0,n.name=o)}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)?Ar(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=0,n=12;r||(i=e.GetColumnWidth(t));for(let o=0;o<e.cells.rows;o++){let a=e.CellData({row:o,column:t}),s=a.formatted||"";if(typeof s!="string"&&(s=s.map(l=>l.text).join("")),s&&s.length){let l=this.tile_renderer.MeasureText(s,U.Font(a.style||{}));i=Math.max(i,Math.ceil(l.width)+n)}}i>n+2&&e.SetColumnWidth(t,i)}EnsureActiveSheet(e=!1){for(let t of this.model.sheets.list)if(t===this.active_sheet){e&&this.ActivateSheetInternal({key:22,id:t.id,force:!0});return}this.ActivateSheetInternal({key:22,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 o of n)this.AddAnnotation(o,!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=(o="")=>{let a=o.toLowerCase();for(let s of this.model.sheets.list)if(s.name.toLowerCase()===a)return s.id;return this.active_sheet.id},r=o=>{for(let a of this.model.sheets.list)if(a.id===o)return a;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":{let o=this.model.GetName(n.expression.name,this.active_sheet.id);o?.type==="range"&&(i=o.area),i||this.primary_selection.empty||this.SetName(n.expression.name.toUpperCase(),this.primary_selection.area)}break;default:break}if(i){let o=r(i.start.sheet_id);if(o.columns>=i.end.column&&o.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 Ft(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 Dt(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 s of this.layout.grid_tiles)for(let l of s)l.dirty=!0;let i=this.render_tiles.start,n=this.render_tiles.end,o=[];for(let s=i.row;s<=n.row;s++)o.push(s);let a=[];for(let s=i.column;s<=n.column;s++)a.push(s);i.row>0&&this.active_sheet.freeze.rows&&o.push(0),i.column>0&&this.active_sheet.freeze.columns&&a.push(0);for(let s of a)for(let l of o){let d=this.layout.grid_tiles[s][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,o=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 a=this.layout.RowHeight(n),s=a,l=this.layout.OffsetCellAddressToRectangle({row:n,column:0}),d=i.y+l.bottom;this.layout.ShowTooltip({left:!0,text:`${s}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)],b=m.view[this.view_index]?.node;b&&p.push(b),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})}ve(this.layout.mask,"row-resize",m=>{let f=Math.max(-a,Math.round(m.offsetY-o));if(f+a!==s){s=f+a,this.layout.SetRowHeight(n,s),this.layout.UpdateTooltip({text:`${s}px`,y:d+f});for(let{annotation:p,y:b}of h)p.scaled_rect&&(p.scaled_rect.top=b+f);for(let{annotation:p,height:b}of u)p.scaled_rect&&(p.scaled_rect.height=b+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:b}of u)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);for(let{annotation:p,nodes:b}of h)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);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,a),this.ExecCommand({key:3,row:m,height:s/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 o=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=o}else this.Select(n,new y(t),{column:0,row:t.row});this.RenderSelections(),ve(this.layout.mask,[],o=>{let a=this.layout.CoordinateToRowHeader(o.offsetY-i.y),s=new y(a,t,!0);(n.empty||!s.Equals(n.area))&&(this.Select(n,s,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,o=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 a=this.layout.ColumnWidth(n),s=a,l=this.layout.OffsetCellAddressToRectangle({row:0,column:n}),d=i.x+l.right;this.layout.ShowTooltip({up:!0,text:`${s}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)],b=m.view[this.view_index]?.node;b&&p.push(b),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})}ve(this.layout.mask,"column-resize",m=>{let f=Math.max(-a,Math.round(m.offsetX-o));if(f+a!==s){s=f+a,this.layout.UpdateTooltip({text:`${s}px`,x:d+f}),this.layout.SetColumnWidth(n,s);for(let{annotation:p,x:b}of h)p.scaled_rect&&(p.scaled_rect.left=b+f);for(let{annotation:p,width:b}of u)p.scaled_rect&&(p.scaled_rect.width=b+f);requestAnimationFrame(()=>{for(let{annotation:p,nodes:b}of u)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);for(let{annotation:p,nodes:b}of h)if(p.scaled_rect)for(let g of b)p.scaled_rect.ApplyStyle(g);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:s/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 o=n.target;this.Select(n,new y(n.target,t,!0),void 0,!0),t=o}else this.Select(n,new y(t),{row:0,column:t.column});this.RenderSelections(),ve(this.layout.mask,[],o=>{let a=this.layout.CoordinateToColumnHeader(o.offsetX-i.x),s=new y(a,t,!0);(n.empty||!s.Equals(n.area))&&(this.Select(n,s,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?ze.instance.HTML(ze.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,o=t.y-i.top,a=r.renderer_data?.text_data?.strings||[];for(let s of a)for(let l of s)if(typeof l.left=="number"&&typeof l.top=="number"&&typeof l.width=="number"&&typeof l.height=="number"&&n>=l.left&&o>=l.top&&n<=l.left+l.width&&o<=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)){ee.is_mobile&&this.overlay_editor?.edit_node?.focus(),this.OverlayEditCell({target:i,area:new y(i)},!1);return}let o=this.layout.grid_cover.getBoundingClientRect(),a={x:o.left,y:o.top},s=[],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(),s.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",reference: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);ve(this.layout.mask,s,h=>{let u={x:h.offsetX-a.x,y:h.offsetY-a.y},m=d.Clamp(u.x,u.y),f=this.layout.PointToAddress_Grid(m),p=this.layout.scroll_reference_node,b=!1;this.container&&this.options.scrollbars&&(u.x<p.scrollLeft?(p.scrollLeft-=25,b=!0):u.x>p.scrollLeft+this.container.clientWidth&&(p.scrollLeft+=25,b=!0),u.y<p.scrollTop?(p.scrollTop-=25,b=!0):u.y>p.scrollTop+this.container.clientHeight&&(p.scrollTop+=25,b=!0),b&&(o=this.layout.grid_cover.getBoundingClientRect(),a.x=o.left+document.body.scrollLeft,a.y=o.top+document.body.scrollTop));let g=new y(f,i,!0);if(l&&(g=l.Clone(),g.ConsumeAddress(f),g.rows!==l.rows&&g.columns!==l.columns)){let C={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};C.rows>=C.columns?g=new y({row:g.start.row,column:l.start.column},{row:g.end.row,column:l.end.column}):g=new y({row:l.start.row,column:g.start.column},{row:l.end.row,column:g.end.column})}(n.empty||!g.Equals(n.area))&&(this.Select(n,g,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 o=0;o<r;o++)t[n][o]=e[o][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:30,table:h},{key:29,area:e,sortable:u,totals:m,theme:f}]);return}let i=[],n=[],o=t.columns,a=e.rows,s=!1,l=!1;e.columns===t.columns?s=e.start.row<t.start.row:(o=t.rows,a=e.columns,s=e.start.column<t.start.column,r=this.Transpose(r),l=!0);for(let h=0;h<a;h++)i[h]=[],n[h]=[];for(let h=0;h<o;h++){let u=0;if(r.length>1){u=1;let m=[],f=[];for(let p=0;p<r.length;p++){let b=r[p][h];b.ValueIsNumber()&&(f.push(p),m.push(b.value))}if(m.length>1){let p=m.slice(1).map((b,g)=>b-m[g]);p.every(b=>b===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 _=this.parser.Parse(p.value);_.expression&&_.full_reference_list?.length&&(f=_.expression)}let b=0,g=m,C=r.length,x=0,v=u;s&&(g=a-r.length+m,C=-r.length,v=-u);for(let _=g;_>=0&&_<a;_+=C,b+=C,x+=v){if(f)i[_][h]="="+this.parser.Render(f,{offset:{rows:b,columns:0}});else{let w=r[m][h];w.ValueIsNumber()?i[_][h]=w.value+x:i[_][h]=w.value}n[_][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.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;xe.test(n)?i=`'${n}'!${i}`:i=`${n}!${i}`}if(this.overlay_editor?.editing&&this.overlay_editor.selecting)this.overlay_editor.InsertReference(i);else if(this.formula_bar&&this.formula_bar.selecting)this.formula_bar.InsertReference(i);else if(this.external_editor_config&&(this.external_editor?.active&&(this.external_editor.FocusEditor(),this.external_editor.InsertReference(i)),this.external_editor_config.update)){let n=this.external_editor_config.update.call(0,i);n&&Array.isArray(n)&&this.HighlightDependencies(n.filter(o=>!!o).map(o=>V(o)?new y(o):new y(o.start,o.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||ee.is_mac&&e.metaKey)&&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},o=!1,a=!1;if(e.ctrlKey||ee.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"Backspace":e.metaKey&&ee.is_mac&&(i.empty||this.DeleteSelection(i));break;case"Delete":case"Del":{e.stopPropagation(),e.preventDefault();for(let s=0;s<this.model.sheets.length;s++)if(this.model.sheets.list[s]===this.active_sheet){this.DeleteSheet(s);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 s={},l=this.primary_selection.empty?{}:this.active_sheet.CellData(this.primary_selection.target).style||{};switch(e.key.toLowerCase()){case"b":s.bold=!l.bold;break;case"i":s.italic=!l.italic;break;case"u":s.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(s).length&&this.ApplyStyle(void 0,s)}}else{if(/^F\d+$/.test(e.key))return;switch(e.key){case"Tab":e.shiftKey?n.columns--:n.columns++,o=!0;break;case"Enter":e.shiftKey?n.rows--:n.rows++,o=!0;break;case"ArrowDown":case"Down":n.rows++,a=e.shiftKey;break;case"ArrowUp":case"Up":n.rows--,a=e.shiftKey;break;case"ArrowLeft":case"Left":n.columns--,a=e.shiftKey;break;case"ArrowRight":case"Right":n.columns++,a=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,o,a,!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 o={...e.target};i>0?o.row=Math.max(o.row,e.area.end.row):i<0&&(o.row=Math.min(o.row,e.area.start.row)),r>0?o.column=Math.max(o.column,e.area.end.column):r<0&&(o.column=Math.min(o.column,e.area.start.column));let a=this.active_sheet.cells,s=a.GetCell(e.target,!1);if(!s||s.type===0&&!s.area)return!1;let l={...o};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++)s=a.GetCell({row:d.row,column:u},!1),h=h||!!s&&(s.type!==0||!!s.area),!h&&s&&s.merge_area&&(s=a.GetCell(s.merge_area.start,!1),h=h||!!s&&(s.type!==0||!!s.area));else for(let u=e.area.start.row;!h&&u<=e.area.end.row;u++)s=a.GetCell({row:u,column:d.column},!1),h=h||!!s&&(s.type!==0||!!s.area),!h&&s&&s.merge_area&&(s=a.GetCell(s.merge_area.start,!1),h=h||!!s&&(s.type!==0||!!s.area));if(!h)break;l=d}if(t){i?(o.row=e.target.row,o.column=e.area.start.column,l.column=e.area.end.column):(o.column=e.target.column,o.row=e.area.start.row,l.row=e.area.end.row);let d=new y(o,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:12,area:t})}SetInferredType(e,t,r=!1,i=!0){let n=e.target||e.area.start,o=this.active_sheet.CellData(n);if(o.area){if(!r&&o.area.count>1||!e.area||!e.area.Equals(o.area)){this.Error(2);return}}else if(r){for(let u of this.active_sheet.cells.Iterate(e.area,!1))if(u.area){this.Error(2);return}}let a=this.active_sheet.GetValidation(n)[0];if(a&&a.error){let u;if(a.type==="list"?u=a.list:a.type==="range"&&(u=this.GetValidationRange(a.area)),u&&u.length){let m=!1;if(t){let f=t.toUpperCase();for(let p of u)if(p&&p.toString().toUpperCase()===f){t=p.toString(),m=!0;break}}if(!m){this.Error(3);return}}}o.merge_area&&(n=o.merge_area.start);let s=typeof t=="string"&&t.trim()[0]==="=",l=[];if(s&&(t=this.FixFormula(t||""),!this.active_sheet.HasCellStyle(n))){let u=this.parser.Parse(t);if(u){if(u.expression?.type==="call"&&(!o.style||!o.style.number_format||z.Equals(o.style.number_format,"General"))){let m=u.expression.name.toLowerCase(),f;switch(m){case"today":f="Short Date";break;case"now":f="Timestamp";break}f&&l.push({key:7,area:r?e.area:n,style:{number_format:f},delta:!0})}if(u.dependencies){let m,f=u.dependencies;for(let p of Object.keys(f.addresses)){let b=f.addresses[p];if(this.active_sheet.HasCellStyle({...b})){let g=this.active_sheet.CellData({...b});if(g.style&&g.style.number_format&&(!m||/%/.test(m))&&(m=z.Translate(g.style.number_format),!/%/.test(m)))break}}if(m){let p={number_format:z.SymbolicName(m)||m};l.push({key:7,area:r?e.area:n,style:p,delta:!0})}}}}let d=this.parser.Parse(t||"").expression;d?.type==="group"&&d.elements.length===1&&d.elements[0].type==="complex"&&(d=d.elements[0]);let h=d&&d.type==="complex"?{type:7,value:{real:d.real,imaginary:d.imaginary}}:ce.TryParse(t);if(!s&&h.type===3){let u="",m=h.hints||{};(!o.style||!o.style.number_format||z.Equals(o.style.number_format,"General"))&&(m.Date?u="Short Date":m.Exponential?u="Exponential":m.Percent?u="Percent":m.Currency?u="Currency":(m.Grouping||m.Parens)&&(u="Accounting")),u&&l.push({key:7,area:r?e.area:n,style:{number_format:u},delta:!0})}if(l.push({key:6,area:r?e.area:n,array:r,value:s?this.UntranslateFunction(t||""):h.value}),i)this.ExecCommand(l);else return l}FixFormula(e){if(e.trim()[0]!=="=")return e;e=e.replace(/^\s+/,"");let t=!1,r=!1,i=0,n=!1,o=e.length;for(let a=0;a<o;a++){let s=e[a];if(!n)switch(s){case'"':t?e[a+1]==='"'?a++: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.GetName(r.name,this.active_sheet.id)?.type==="range"&&(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(z.Get(e.style.number_format).date_format){let i=we(e.value),n=i.getUTCHours()||i.getUTCMinutes()||i.getUTCSeconds()?"Timestamp":"Short Date";t=z.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)+"%",N.decimal_separator===","&&(t=t.replace(/\./,","))}else t&&N.decimal_separator===","&&(t=e.value.toString().replace(/\./,","));else{if(e.ValueIsBoolean())return e.value.toString().toUpperCase();e.ValueIsNumber()?t&&N.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(),N.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),o;if(this.HideHoverInfo(),n.merge_area?(o=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)):o=this.layout.OffsetCellAddressToRectangle(i),n.style?.locked){console.info("cell is locked for editing");return}o=o.Shift(this.layout.header_size.width,this.layout.header_size.height);let a=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)))?a="%":a=void 0:a=this.NormalizeCellValue(n),this.overlay_editor?.Edit(e,o.Expand(-1,-1),n,a,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 o=this.SelectingArgument();if(t.empty)if(o){let a={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(a))}else this.Select(t,new y({row:0,column:0}));else{let a=this.active_sheet.CellData(t.target);if(a.merge_area&&r&&(r=!a.merge_area.Equals(t.area)),r&&t.area.count>1){let s=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,s);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,s,l)}else if(i&&t&&t.target){let s=t.area,l=t.target,d=s.start,h=s.end,u={row:1/0,column:1/0};if(e.columns&&(s.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):s.end.column>l.column?(h.column=this.StepVisibleColumns(h.column,e.columns),u.column=h.column):s.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&&(s.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):s.end.row>l.row?(h.row=this.StepVisibleRows(h.row,e.rows),u.row=h.row):s.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 s=t.target;a.merge_area?(e.columns<0?s.column=this.StepVisibleColumns(a.merge_area.start.column,-1):e.columns>0&&(s.column=this.StepVisibleColumns(a.merge_area.end.column,1)),e.rows<0?s.row=this.StepVisibleRows(a.merge_area.start.row,-1):e.rows>0&&(s.row=this.StepVisibleRows(a.merge_area.end.row,1))):(s.row=this.StepVisibleRows(s.row,e.rows),s.column=this.StepVisibleColumns(s.column,e.columns)),this.EnsureAddress(s)&&(n=!0),this.Select(t,new y({row:Math.min(Math.max(0,s.row),this.active_sheet.rows-1),column:Math.min(Math.max(0,s.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 o=0;o<r;o++)if(this.additional_selections[o].area.spreadsheet_label===n&&this.additional_selections[o].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);e:for(;;){for(let s of this.active_sheet.cells.Iterate(n,!1))if(s.merge_area&&!n.ContainsArea(s.merge_area)){t.ConsumeArea(s.merge_area),n=this.active_sheet.RealArea(t);continue e}break}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 o=this.active_sheet.CellData(e.target),a="";o.formatted&&(typeof o.formatted=="string"?a=o.formatted:a=o.formatted.map(s=>s.flag===1||s.flag===6?"":s.text).join("")),this.overlay_editor?.UpdateCaption(a)}else e.empty=!0;e===this.primary_selection&&(ee.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),n=this.active_sheet.GetValidation(this.primary_selection.target)[0];if(n&&!t.style?.locked){let o;n.type==="list"?o=n.list:n.type==="range"&&(o=this.GetValidationRange(n.area)),o&&o.length&&this.layout.ShowDropdownCaret(t.merge_area||new y(this.primary_selection.target),o,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 o of e)for(let a of o)typeof a=="number"?(i.real+=a,r++):ae(a)&&(i.real+=a.real,i.imaginary+=a.imaginary,r++),typeof a<"u"&&t++;let n=o=>{let a=Math.floor(Math.log10(o));return a<-6||a>10?z.Get("Exponential"):a<=-1?z.Get("General"):z.Get("Number")};if(t>1)if(r>0){let o=z.Get("General");if(i.imaginary){let a={real:i.real/r,imaginary:i.imaginary/r};return[{label:"Count",value:t.toString()},{label:"Sum",value:ie.FormatPartsAsText(o.FormatComplex(i))},{label:"Average",value:ie.FormatPartsAsText(o.FormatComplex(a))}]}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.MatchSelection(e.area,i)||y.CellAddressToLabel(i.start)}}OnDropdownSelect(e){if(typeof e<"u"){let i=ce.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=bi(i).outerHTML;e.clipboardData.setData("text/plain",n)}}}}else{let t=this.active_sheet.RealArea(this.primary_selection.area),r=t.columns,i=t.rows,n=[],o=[];for(let s=0;s<i;s++){let l=[];for(let d=0;d<r;d++){let h={row:t.start.row+s,column:t.start.column+d},u=this.active_sheet.CellData(h),m="";u.calculated!==void 0?u.calculated_type===7?m=Oe(u.calculated):m=u.calculated.toString():u.type===7?m=Oe(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}),o.push(JSON.parse(JSON.stringify(f)))}n.push(l)}let a=n.map(s=>s.join(" ")).join(`
9
9
  `);e.clipboardData&&(e.clipboardData.clearData(),e.clipboardData.setData("text/plain",a),e.clipboardData.setData("text/x-treb",JSON.stringify({source:t,data:o})))}}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:12,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 o=JSON.parse(t);if(o.source&&o.source!==this.active_sheet.id&&o.data&&o.data.formula){let l="",d=this.model.sheets.Find(o.source);if(d&&(l=d.name),l){let h=this.parser.Parse(o.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)),o.data.formula="="+this.parser.Render(h.expression,{missing:""}))}}let s=this.CreateAnnotation(o.data,!0,!0).view[this.view_index];if(s&&s.node){let l=s.node;setTimeout(()=>{l.focus()},1)}}catch(o){console.error(o)}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 o=JSON.parse(n),a=new y(o.source.start,o.source.end),s=this.RecyclePasteAreas(a,r);if(s.length===1&&r.Resize(s[0].rows,s[0].columns),!this.ValidatePasteAreas(s)){this.Error(5);return}let l=[];for(let d of s){this.active_sheet.cells.EnsureCell(d.end),i.push({key:12,area:d});let h={rows:d.start.row-a.start.row,columns:d.start.column-a.start.column};o.data.forEach(u=>{let m=u.data,f={row:u.address.row-a.start.row+d.start.row,column:u.address.column-a.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}},b={key:6,value:m,array:!0,area:p};l.push(new y(p.start,p.end)),i.push(b)}else{let p=!1;for(let b of l)if(b.Contains(f)){p=!0;break}p||i.push({key:6,value:m,area:f})}i.push({key:7,style:u.style||{},area:f})})}}catch(o){console.error("invalid treb data on clipboard"),console.info(o);return}else{let o=e.clipboardData.getData("text/plain");if(!o)return!0;let s=o.trim().split(`
10
- `).map(d=>d.split(" ").map(h=>h.trim())),l=this.RecyclePasteAreas(new y({row:0,column:0},{row:s.length-1,column:s[0].length-1}),r);if(l.length===1&&(r.Resize(s.length,s[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<s.length;h++)for(let u=0;u<s[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),s[h][u]){let f=this.SetInferredType({area:m,target:m.start,empty:!1},s[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:12,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 o=0;o<t.columns;o++)r.push(o)}typeof r=="number"&&(r=[r]);let i=typeof e.width!="number",n=Math.round(e.width||0/this.scale);if(i)for(let o of r)this.AutoSizeColumn(t,o,!0);else for(let o of r)t.SetColumnWidth(o,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 s=0;s<r.rows;s++)i.push(s)}typeof i=="number"&&(i=[i]);let n=typeof e.shrink=="boolean"?e.shrink:!0,o=typeof e.height!="number",a=Math.round(e.height||0/this.scale);if(o)for(let s of i)r.GetRowHeight(s)||(t?t.ConsumeAddress({row:s,column:1}):t=new y({row:s,column:1/0,sheet_id:r.id})),r.AutoSizeRow(s,this.theme.grid_cell,n);else for(let s of i){let l=r.GetRowHeight(s);(!l&&a||l&&!a)&&(t?t.ConsumeAddress({row:s,column:1}):t=new y({row:s,column:1/0,sheet_id:r.id})),r.SetRowHeight(s,a)}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:22,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 Gt=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 We=class extends Gt{dirty=!1};var Di={error:"NOTIMPL"},de=()=>({type:6,value:"N/A"}),Se=()=>({type:6,value:"EXPR"});var fe=()=>({type:6,value:"DIV/0"}),U=()=>({type:6,value:"ARG"}),E=()=>({type:6,value:"VALUE"}),O=()=>({type:6,value:"REF"}),Ur=()=>({type:6,value:"NAME"}),$t=()=>({type:6,value:"UNK"});var Re=class c extends We{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=W(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 Fe=class c extends We{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 Ot=class{vertices=[[]];volatile_list=[];calculation_list=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===Re.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),Fe.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 Re;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,Fe.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 a=Fe.GetContainingArrays(e);for(let s of a)this.SetVertexDirty(s)}return}let o=[];if(i&&(o=Array.from(n.edges_in)),n.ClearDependencies(),t&&this.SetVertexDirty(n),i){n.has_outbound_edges||this.RemoveVertex(e);for(let a of o)if(!a.has_inbound_edges&&!a.has_outbound_edges){let s=a;s.address&&this.RemoveVertex(s.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 o of n)o&&(o.color=o.edges_out.size?0:2,t.push(o))}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],o=!0;if(n.color!==2)for(let a of n.edges_out){if(a.color===1)return this.loop_hint=this.RenderAddress(i.address),console.info("loop detected @",this.loop_hint),!0;a.color===0&&(r.push(a),o=!1)}o&&(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}CompositeAddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let[r,i]=Fe.GetVertex(e);if(t.DependsOn(r),this.loop_check_required=!0,!i)return;let n=this.vertices[e.start.sheet_id];if(n){if(e.entire_row){for(let o=0;o<n.length;o++)if(n[o])for(let a=e.start.row;a<=e.end.row;a++){let s=n[o][a];s&&r.DependsOn(s)}}else if(e.entire_column){for(let o=e.start.column;o<=e.end.column;o++)if(n[o])for(let a of n[o])a?.address&&r.DependsOn(a)}else for(let o=e.start.row;o<=e.end.row;o++)for(let a=e.start.column;a<=e.end.column;a++)if(n[a]){let s=n[a][o];s&&r.DependsOn(s)}}}AddLeafVertexArrayEdge(e,t){this.CompositeAddArrayEdge(e,t)}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0);this.CompositeAddArrayEdge(e,r)}AddEdge(e,t){let r=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(r),r.reference&&r.reference.area&&!r.array_head&&this.AddEdge({...e,row:r.reference.area.start.row,column:r.reference.area.start.column},t),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),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 bo=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 go=c=>{let{r:e,theta:t}=c,r=e*Math.cos(t),i=e*Math.sin(t);return{real:r,imaginary:i}},Zt=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}},he=(c,e)=>({real:c.real*e.real-c.imaginary*e.imaginary,imaginary:c.real*e.imaginary+c.imaginary*e.real}),_o=(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}},Fr=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let o=0;for(let a=0;a<c.n;a++)o+=c.array[r][a]*e.array[a][n];i.push(o)}t.push(i)}return{array:t,m:c.m,n:e.n}},Ui=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let o={real:0,imaginary:0};for(let a=0;a<c.n;a++)o.real+=c.array[r][a].real*e.array[a][n].real-c.array[r][a].imaginary*e.array[a][n].imaginary,o.imaginary+=c.array[r][a].real*e.array[a][n].imaginary+c.array[r][a].imaginary*e.array[a][n].real;i.push(o)}t.push(i)}return t},Bt=c=>{let e={real:0,imaginary:0},t=c.n;if(t==2){let i=he(c.array[0][0],c.array[1][1]),n=he(c.array[1][0],c.array[0][1]);return{real:i.real-n.real,imaginary:i.imaginary-n.imaginary}}let r=bo(c.n);for(let i=0;i<t;i++){let n=0;for(let s=1;s<t;s++){let l=0;for(let d=0;d<t;d++)d!=i&&(r.array[n][l]={...c.array[s][d]},l++);n++}r.m=r.n=t-1;let o=Math.pow(-1,i),a=he({real:c.array[0][i].real*o,imaginary:c.array[0][i].imaginary*o},Bt(r));e.real+=a.real,e.imaginary+=a.imaginary}return e};var yo=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],o=[],a=[];for(let s=0;s<c.n;s++)n[s].real&&(e.real_values=!0),n[s].imaginary&&(e.imaginary_values=!0),s===i&&e.unit_diagonal&&(n[s].real!==1||n[s].imaginary!==0)&&(e.unit_diagonal=!1),o.push(n[s].real),a.push(n[s].imaginary);t.array.push(o),r.array.push(a)}return{real:t,imaginary:r,flags:e}},vo=c=>{let e=c.array.map(t=>t.slice(0));return{m:c.m,n:c.n,array:e}},Vi=c=>{if(c.m!==c.n)return;let e=vo(c),t=e.array,r=0,i=0,n=0,o=0,a=c.m;for(i=1;i<a;i++)t[0][i]/=t[0][0];for(i=1;i<a;i++){for(n=i;n<a;n++){for(r=0,o=0;o<i;o++)r+=t[n][o]*t[o][i];t[n][i]-=r}if(i!=a-1)for(n=i+1;n<a;n++){for(r=0,o=0;o<i;o++)r+=t[i][o]*t[o][n];t[i][n]=(t[i][n]-r)/t[i][i]}}for(i=0;i<a;i++)for(n=i;n<a;n++){let s=1;if(i!=n)for(s=0,o=i;o<n;o++)s-=t[n][o]*t[o][i];t[n][i]=s/t[n][n]}for(i=0;i<a;i++)for(n=i;n<a;n++)if(i!=n){for(r=0,o=i;o<n;o++)r+=t[o][n]*(i==o?1:t[i][o]);t[i][n]=-r}for(i=0;i<a;i++)for(n=0;n<a;n++){for(r=0,o=i>n?i:n;o<a;o++)r+=(n==o?1:t[n][o])*t[o][i];t[n][i]=r}return e},Fi=c=>{let e=[];if(c.m!==c.n)return;let{real:t,imaginary:r,flags:i}=yo(c),n=Vi(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 o=Fr(n,r),a=Fr(r,o),s=_o(t,a),l=Vi(s);if(!l)return;let d=Fr(o,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},Li=(c,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=he(c,t),i=he(e,t);return{real:r.real/i.real,imaginary:r.imaginary/i.real}},Lr=c=>{let e=c.real||0,t=c.imaginary||0;return he({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},xo=c=>{let e=Zt(c);return{real:Math.log(e.r),imaginary:e.theta}},pe=(c,e)=>{if(e.imaginary)return Lr(he(e,xo(c)));{let t=Zt(c);return go({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var Pi=(c,e=0)=>c&&c.type===7?c:{type:7,value:{real:e,imaginary:0}},Le=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real},Pe=(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]=Pi(t[3],t[0]),t[4]=Pi(t[4],t[1])),t},wo=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le({real:n.value.real+o.value.real,imaginary:n.value.imaginary+o.value.imaginary}):{value:t+r,type:3})},Hr=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le({real:n.value.real-o.value.real,imaginary:n.value.imaginary-o.value.imaginary}):{value:t-r,type:3})},Co=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);if(i)return i;if(n&&o)return Le(pe(n.value,o.value));let a=Math.pow(t,r);return isNaN(a)?E():{type:3,value:a}},So=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);if(i)return i;if(n&&o)return Le(pe(n.value,o.value));if(t<0&&r!==0&&Math.abs(r)<1)return Le(pe({real:t,imaginary:0},{real:r,imaginary:0}));let a=Math.pow(t,r);return isNaN(a)?E():{type:3,value:a}},Gr=Co,Ao=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le(he(n.value,o.value)):{value:t*r,type:3})},ko=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?o.value.real===0&&o.value.imaginary===0?fe():Le(Li(n.value,o.value)):r===0?fe():{value:t/r,type:3})},To=(c,e)=>{let[t,r,i]=Pe(c,e);return i||(r===0?fe():{value:t%r,type:3})},Ro=(c,e)=>c.type===6?c:e.type===6?e:{type:2,value:`${c.type===0?"":c.value}${e.type===0?"":e.value}`},$r=(c,e)=>c.type===6?c:e.type===6?e: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)?{type:4,value:!0}:c.type===7?e.type===7?{type:4,value:c.value.imaginary===e.value.imaginary&&c.value.real===e.value.real}:{type:4,value:!c.value.imaginary&&c.value.real===e.value}:e.type===7?{type:4,value:!e.value.imaginary&&c.value===e.value.real}:c.type===2&&e.type===2?{type:4,value:c.value.toLowerCase()===e.value.toLowerCase()}:{type:4,value:c.value==e.value},Gi=(c,e)=>{let t=$r(c,e);return t.type===6?t:{type:4,value:!t.value}},Eo=(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)},Or=(c,e)=>!(c.type===7||c.type===8||c.type===9||c.type===5||e.type===7||e.type===8||e.type===9||e.type===5),Mo=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)>=(e.value||0)}:E(),Io=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)<(e.value||0)}:E(),zo=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)<=(e.value||0)}:E(),$i=()=>{Gr=So},Hi=c=>{switch(c){case"&":return Ro;case"+":return wo;case"-":return Hr;case"*":return Ao;case"/":return ko;case"^":return Gr;case"**":return Gr;case"%":return To;case"=":return $r;case"==":return $r;case"!=":return Gi;case"<>":return Gi;case">":return Eo;case">=":return Mo;case"<":return Io;case"<=":return zo}};var Zi=c=>!Array.isArray(c)&&c.type===5&&!!c.value.type,ct=c=>c.type===5&&c.key==="metadata",Wt=class{constructor(e,t,r){this.data_model=e;this.library=t;this.parser=r}context={address:{row:-1,column:-1},volatile:!1};Calculate(e,t,r=!1){return r||(this.context.address=t,this.context.volatile=!1),{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()=>O();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>O();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)||O():O()}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.data_model.GetName(e.name,this.context.address.sheet_id||0);n?.type==="range"&&(n.area.count===1?r=n.area.start:i=n.area)}break;case"call":{let n=this.CalculateExpression(e,!0);if(Zi(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]"),O();let o=n.CellData(r),a=o.calculated_type?o.calculated:o.value,s={type:"metadata",address:{...r,position:0,id:0,type:"address",label:new y(r).spreadsheet_label},value:a,format:o.style?o.style.number_format:void 0,...t(o,r)};return{type:5,value:s,key:"metadata"}}else if(i){if(i.start.row===1/0||i.start.column===1/0)return O();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 o=[];for(let a=i.start.column;a<=i.end.column;a++){let s=[];for(let l=i.start.row;l<=i.end.row;l++){let d=n.CellData({row:l,column:a});r={...i.start,row:l,column:a};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)};s.push({type:5,value:u,key:"metadata"})}o.push(s)}return{type:8,value:o}}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()=>Se();let r=JSON.stringify(t.expression),i={},n=t.argument_names?.map(o=>o.toUpperCase())||[];return o=>{let a=JSON.parse(r);for(let s=0;s<n.length;s++)i[n[s]]=o.args[s]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(a,i))}}CallExpression(e,t=!1){let r=this.library.Get(e.name);return r?i=>{this.context.volatile=this.context.volatile||!!r.volatile;let n=e.name.toLowerCase()==="if",o=-1,a,s=r.arguments||[],l=i.args.map((d,h)=>{if(a)return;let u=s[Math.min(h,s.length-1)]||{};if(h===o)return u.boxed?{type:0}:void 0;if(typeof d>"u")return n&&h===0&&(o=1),u.boxed?{type:0}:void 0;if(u.address)return u.boxed?{type:2,value:this.parser.Render(d).replace(/\$/g,"")}:this.parser.Render(d).replace(/\$/g,"");if(u.metadata)return this.GetMetadata(d,()=>({}));{let m=this.CalculateExpression(d);if(m.type===6){if(u.allow_error)return m;a=m;return}if(n&&h===0&&m.type!==8){let f=!1;if(m.type===2){let p=m.value.toLowerCase().trim();f=p!=="false"&&p!=="f"}else f=!!m.value;o=f?2:1}return u.boxed?m:m.type===8?m.value.map(f=>f.map(p=>p.value)):m.value}});if(a)return a;if(r.return_type===1){let d=r.fn.apply(null,l);if(t)return d;if(Zi(d)){if(d.value.type==="address")return this.CellFunction2(d.value)();if(d.value.type==="range")return this.CellFunction4(d.value.start,d.value.end)}return d}return r.fn.apply(null,l)}:()=>Ur()}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()=>O()}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=Hr,r={type:3,value:0};return i=>{let n=this.CalculateExpression(i.operand);return n.type===8?{type:8,value:n.value.map(o=>o.map(a=>t(r,a)))}:t(r,n)}}default:return()=>(console.warn("unexpected unary operator:",e.operator),Se())}}RecycleArray(e,t,r){if(e[0].length<r){let i=e[0].length;for(let n of e)for(let o=i;o<r;o++)n[o]=n[o%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),o=this.RecycleArray(t.value,i,n),a=this.RecycleArray(r.value,i,n),s=[];for(let l=0;l<i;l++){let d=[];for(let h=0;h<n;h++)d[h]=e(o[l][h]||{type:0},a[l][h]||{type:0});s.push(d)}return{type:8,value:s}}BinaryExpression(e){let t=Hi(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})`),Se())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>O();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.data_model.GetName(r,this.context.address.sheet_id||0);if(i?.type==="range")return i.area.count===1?this.CellFunction4(i.area.start,i.area.start):this.CellFunction4(i.area.start,i.area.end);let n=this.data_model.GetName(t,this.context.address.sheet_id||0);return n&&n.type==="expression"?this.CalculateExpression(n.expression):Ur()}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>Se()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.fn)return e.fn(e);switch(e.type){case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.fn=this.CallMacro(e,r))(e):(e.fn=this.CallExpression(e,t))(e)}case"address":return(e.fn=this.CellFunction2(e))();case"range":return(e.fn=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.fn=this.BinaryExpression(e))(e);case"unary":return(e.fn=this.UnaryExpression(e))(e);case"identifier":return(e.fn=this.Identifier(e))();case"missing":return(e.fn=()=>({value:void 0,type:0}))();case"dimensioned":return(e.fn=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:se(e.value)};return(e.fn=()=>r)()}case"group":return(e.fn=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:7};return(e.fn=()=>r)()}case"structured-reference":return(e.fn=this.ResolveStructuredReference(e))();case"array":return(e.fn=()=>({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),$t()}}};var yd=1e3*60*60*24;var jt=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},dt=c=>{if(!c)return[];if(typeof c[0]>"u")return[];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 be=c=>{let e=[];for(let t of c)if(t.type===8)for(let r of t.value)e=e.concat(be(r));else e.push(t);return e},j=c=>Array.isArray(c)?c.reduce((e,t)=>typeof t>"u"?e:Array.isArray(t)?e.concat(j(t)):t instanceof Float32Array||t instanceof Float64Array?e.concat(Array.from(t)):e.concat([t]),[]):[c],ue=c=>j(c).filter(e=>typeof e=="number"),Zr=c=>c.filter(e=>{switch(typeof e){case"number":case"undefined":case"string":case"boolean":return!0}return!1}),Do=c=>!!c&&typeof c=="object"&&c.type===8,Bi=(c,e)=>(...t)=>{let r=[],i=[];for(let[n,o]of t.entries())if(o&&c[n]){let a=Array.isArray(o)?o:Do(o)?o.value:void 0;a&&(r[n]=a,i.length||(i=a))}return r.length?{type:8,value:i.map((n,o)=>n.map((a,s)=>{let l=t.map((d,h)=>r[h]?r[h][o][s]||{type:0}:d);return e(...l)}))}:e(...t)},ht=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 o=0;o<r.length;o++)if(n===r[o]){e.push("\\");break}e.push(n);break}}return e.join("")};var Jt=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];if(n.canonical_name=r,!n.unrolled){let o=n.arguments?.map(a=>!!a.unroll);o?.some(a=>!!a)&&(n.fn=Bi(o,n.fn),n.unrolled=!0)}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 ut=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=J(t.text)?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:o,colors:a}=this.SparklineCommon(i,n),s=.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<o.length;f++){let p=o[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*s)/(o.length-1),p=u-h,b=t*(1-2*l),g=t*l;r.strokeStyle=a[0],r.lineWidth=d,r.lineCap="round",r.lineJoin="round",r.beginPath();let C=0;for(let x=m;x<o.length;x++){let v=o[x];if(typeof v=="number"){let _=e*s+f*x,w=t-(v-h)*b/p-g;C===0?(r.moveTo(_,w),C=1):r.lineTo(_,w)}else C=0}r.stroke()}}static RenderColumn(e,t,r,i,n){let{values:o,colors:a}=this.SparklineCommon(i,n),s=3,l=2.5,d=0,h=0,u=!1;for(let m of o)typeof m=="number"&&(u?(d=Math.min(d,m),h=Math.max(h,m)):(u=!0,d=h=m));if(o.length){let m=(e-2*s-2)/(o.length-0),f=t-2*l,p=l;if(d!==h)if(d<0&&h>0){let b=h-d,g=p+h/b*f;for(let C=0;C<o.length;C++){let x=o[C];if(typeof x=="number"){let v=s+C*m,_=Math.abs(x)/b*f;if(x>=0){r.fillStyle=a[0];let w=g-_;r.fillRect(v+2,w,m-2,_)}else{r.fillStyle=a[1];let w=g;r.fillRect(v+2,w,m-2,_)}}}}else if(h>0){r.fillStyle=a[0];let b=h-d;for(let g=0;g<o.length;g++){let C=o[g];if(typeof C=="number"){let x=s+g*m,v=Math.max(1,(C-d)/b*f),_=t-p-v;r.fillRect(x+2,_,m-2,v)}}}else{r.fillStyle=a[1];let b=h-d;for(let g=0;g<o.length;g++){let C=o[g];if(typeof C=="number"){let x=s+g*m,v=Math.max(1,Math.abs(h-C)/b*f),_=p;r.fillRect(x+2,_,m-2,v)}}}}}};var Wi=c=>{let{x:e,y:t,width:r,height:i,cell:n}=c,o={},a=3,s=Math.round(16*(c.scale||1));if(n&&r&&i&&e&&t){let l={x:a,y:i-a-s};if(n.style){switch(n.style.vertical_align){case"top":l.y=a;break;case"middle":l.y=Math.round((i-s)/2);break}switch(n.style.horizontal_align){case"right":l.x=Math.round(r-a-s);break;case"center":l.x=Math.round((r-s)/2);break}}e>=l.x&&e<=l.x+s&&t>=l.y&&t<=l.y+s&&(o.value=`=Checkbox(${n.calculated?"FALSE":"TRUE"})`,o.block_selection=!0)}return o},ji=c=>{let{context:e,width:t,height:r,cell:i}=c,n=c.scale||1;e.lineJoin="round",e.lineCap="round";let o=3*n,a=16*n,s=o,l=r-o-a;if(i.style){switch(i.style.vertical_align){case"top":l=o;break;case"middle":l=(r-a)/2;break}switch(i.style.horizontal_align){case"right":s=t-o-a;break;case"center":s=(t-a)/2;break}}s=Math.floor(s)+.5,l=Math.floor(l)+.5;let d=Math.floor(s+a)+.5,h=Math.floor(l+a)+.5;if(i&&i.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(s,l),e.lineTo(s+16*n,l),e.lineTo(s+16*n,l+16*n),e.lineTo(s,l+16*n),e.closePath(),e.moveTo(s+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(s+u[0]*n,l+u[1]*n);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(d,l),e.lineTo(d,h),e.lineTo(s,h),e.closePath(),e.stroke();return{handled:!0}};var Ve=c=>{switch(c.type){case 7:return c.value;case 3:return{real:c.value,imaginary:0};case 4:return{real:c.value?1:0,imaginary:0};case 0:return{real:0,imaginary:0}}return!1};var Yi=c=>{let e=.254829592,t=-.284496736,r=1.421413741,i=-1.453152027,n=1.061405429,o=.3275911;c=Math.abs(c);let a=1/(1+o*c);return 1-((((n*a+i)*a+r)*a+t)*a+e)*a*Math.exp(-1*c*c)},Vo=Math.sqrt(2*Math.PI),Ji=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},Xi=(c,e)=>{let t=new Date(we(c)),r=t.getUTCMonth()+e,i=t.getUTCFullYear();for(t.setUTCHours(12),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);r<0;)r+=12,i--;for(;r>11;)r-=12,i++;if(t.setUTCMonth(r),t.setUTCFullYear(i),t.getUTCMonth()!==r){let o=t.getUTCDate();t=new Date(t.getTime()-o*86400*1e3)}return t},Qi=[{name:"Lookup value"},{name:"Table"},{name:"Result index"},{name:"Inexact",default:!0}],qi=(c,e,t,r=!0,i=!1)=>{if(i&&(e=dt(e)),t=Math.max(0,t-1),r){let n=e[t][0];if(typeof c=="number"){let o=Number(e[0][0]);if(isNaN(o)||o>c)return de();for(let a=1;a<e[0].length&&(o=Number(e[0][a]),!(isNaN(o)||o>c));a++)n=e[t][a]}else{c=(c||"").toString().toLowerCase();let o=(e[0][0]||"").toString().toLowerCase();if(o.localeCompare(c)>0)return de();for(let a=1;a<e[0].length&&(o=(e[0][a]||"").toString().toLowerCase(),!(o.localeCompare(c)>0));a++)n=e[t][a]}return W(n)}else{for(let n=0;n<e[0].length;n++)if(e[0][n]==c)return W(e[t][n]);return de()}},Br={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:c=>{if(c.type===7){let e=pe(c.value,{real:.5,imaginary:0});return me(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3&&c.value<0){let e=pe({real:c.value,imaginary:0},{real:.5,imaginary:0});return{type:7,value:e}}else if(c.type===3){let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}else return E()}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(c,e)=>{if(c.type===3&&e.type===3&&(c.value>=0||e.value===0||Math.abs(e.value)>=1)){let i=Math.pow(c.value,e.value);return isNaN(i)?E():{type:3,value:i}}let t=Ve(c),r=Ve(e);if(t&&r){let i=pe(t,r);return me(i)}return E()}}},je={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=be(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 me(e)}},EDate:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(c,e=0)=>{if(typeof c!="number"||typeof e!="number")return U();let t=Xi(c,e);return{type:3,value:Ce(t.getTime(),!1)}}},EOMonth:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(c,e=0)=>{if(typeof c!="number"||typeof e!="number")return U();let t=Xi(c,e);switch(t.getUTCMonth()){case 1:{let i=t.getUTCFullYear();i%4===0&&(i===1900||i%400===0||i%100!==0)?t.setUTCDate(29):t.setUTCDate(28)}break;case 0:case 2:case 4:case 6:case 7:case 9:case 11:t.setUTCDate(31);break;default:t.setUTCDate(30);break}return{type:3,value:Ce(t.getTime(),!1)}}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:Ce(new Date().getTime())})},YearFrac:{description:"Returns the fraction of a year between two dates",arguments:[{name:"Start"},{name:"End"},{name:"Basis",default:0}],fn:(c,e,t)=>{if(e<c){let n=c;c=e,e=n}let r=Math.max(0,e-c),i=360;if(t&&t<0||t>4)return U();switch(t){case 1:break;case 2:break;case 3:i=365;break}return{type:3,value:r/i}}},Date:{description:"Constructs a Lotus date from parts",arguments:[{name:"year",unroll:!0},{name:"month",unroll:!0},{name:"day",unroll:!0}],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?U():(c<1899&&(c+=1900),r.setFullYear(c),e<1||e>12?U():(r.setMonth(e-1),t<1||t>31?U():(r.setDate(t),{type:3,value:Ce(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:Ce(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},IsNA:{description:"Checks if another cell contains a #NA error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=be(c);for(let t of e)if(t.type===6&&t.value==="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=be(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",unroll:!0},{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:(c,e)=>{if(!ct(e))return O();if(c)switch(c.toString().toLowerCase()){case"format":return e.value.format?{type:2,value:e.value.format}:O();case"address":return{type:2,value:e.value.address.label.replace(/\$/g,"")}}return{type:6,value:Di.error}}},Year:{description:"Returns year from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees",unroll:!0}],fn:c=>W(c*Math.PI/180)},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians",unroll:!0}],fn:c=>W(c/Math.PI*180)},CountA:{description:"Counts cells that are not empty",fn:(...c)=>W(j(c).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...c)=>W(j(c).reduce((e,t)=>typeof t=="number"||ae(t)?e+1:e,0))},Or:{fn:(...c)=>{let e=!1;c=j(c);for(let t of c)e=e||!!t;return W(e)}},And:{fn:(...c)=>{let e=!0;c=j(c);for(let t of c)e=e&&!!t;return W(e)}},Not:{arguments:[{unroll:!0}],fn:(...c)=>c.length===0?U():c.length===1?W(!c[0]):W(!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((o,a)=>o.map((s,l)=>(s.type===2?s.value.toLowerCase()!=="false"&&s.value.toLowerCase()!=="f":!!s.value)?r?e.value[a][l]:e:i?t.value[a][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",unroll:!0}],fn:c=>{c=Math.round(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,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(c,e)=>{let t=Ve(c),r=Ve(e);if(!t||!r)return E();if(c.type===7||e.type===7)return me(pe(t,r));{let i=Math.pow(t.real,r.real);return isNaN(i)?E():{type:3,value:i}}}},Mod:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e)=>e?W(c%e):fe()},Large:{description:"Returns the nth numeric value from the data, in descending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(c,e)=>{if(e<=0)return U();let t=ue(c);return t.sort((r,i)=>i-r),e<=t.length?{type:3,value:t[e-1]}:U()}},Small:{description:"Returns the nth numeric value from the data, in ascending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(c,e)=>{if(e<=0)return U();let t=ue(c);return t.sort((r,i)=>r-i),e<=t.length?{type:3,value:t[e-1]}:U()}},Sort:{arguments:[{name:"values"}],fn:(...c)=>(c=j(c),c.every(e=>typeof e=="number")?c.sort((e,t)=>e-t):c.sort(),{type:8,value:[c.map(e=>W(e))]})},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>c.type===8?{type:8,value:jt(c.value)}:c},Max:{fn:(...c)=>({type:3,value:Math.max.apply(0,ue(c))})},Min:{fn:(...c)=>({type:3,value:Math.min.apply(0,ue(c))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...c)=>{let e=c.map(i=>j(i)),t=Math.max.apply(0,e.map(i=>i.length)),r=0;for(let i=0;i<t;i++)r+=e.reduce((n,o)=>{let a=o[i];return a===!0&&(a=1),typeof a=="number"?n*a:0},1);return{type:3,value:r}}},XLOOKUP:{arguments:[{name:"Lookup value"},{name:"Lookup array"},{name:"Return array"},{name:"Not found",boxed:!0},{name:"Match mode",default:0},{name:"Search mode",default:1}],xlfn:!0,fn:(c,e,t,r,i=0,n=1)=>{if(!Array.isArray(e))return console.info("lookup is not an array"),E();let o=e[0];if(!Array.isArray(o))return console.info("lookip is not a 2d array"),E();if(e.length!==1&&o.length!==1)return console.info("lookup array has invalid dimensions"),E();if(!Array.isArray(t))return console.info("return array is not an array"),E();let a=e.length===1;a&&(e=dt(e),t=dt(t)),n<0&&(e.reverse(),t.reverse());let s=l=>{let d=t[l];if(!d)return{type:0};if(!Array.isArray(d))return W(d);let h=[d.map(u=>W(u))];return a&&(h=dt(h)),{type:8,value:h}};if(i===2&&typeof c!="string"&&(i=0),(i===1||i===-1)&&typeof c=="number"){let l=0,d=-1;for(let h=0;h<e.length;h++){let u=e[h][0];if(typeof u=="number"){if(u===c)return s(h);let m=Math.abs(u-c);(i===1&&u>c||i===-1&&u<c)&&(d<0||m<l)&&(l=m,d=h)}}if(d>=0)return s(d)}switch(i){case 2:{let l=ht(c?.toString()||""),d=new RegExp("^"+l+"$","i");for(let h=0;h<e.length;h++){let u=e[h][0];if(typeof u=="string"&&d.exec(u))return s(h)}}break;case 0:typeof c=="string"&&(c=c.toLowerCase());for(let l=0;l<e.length;l++){let d=e[l][0];if(typeof d=="string"&&(d=d.toLowerCase()),d===c)return s(l)}break}return r&&r.type!==0?r:de()}},HLookup:{arguments:[...Qi],fn:(c,e,t,r=!0)=>qi(c,e,t,r,!0)},VLookup:{arguments:[...Qi],fn:(c,e,t,r=!0)=>qi(c,e,t,r,!1)},Product:{arguments:[{boxed:!0}],fn:(...c)=>{let e={real:1,imaginary:0};c=be(c);for(let t of c)t.type===7?e=he(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return me(e)}},Log:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=10)=>({type:3,value:Math.log(c)/Math.log(e)})},Log10:{arguments:[{unroll:!0}],fn:c=>({type:3,value:Math.log(c)/Math.log(10)})},Ln:{arguments:[{unroll:!0}],fn:c=>({type:3,value:Math.log(c)})},Round:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*c)/t}}},RoundDown:{arguments:[{unroll:!0},{unroll:!0}],fn:(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}}},RoundUp:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=0)=>{let t=Math.pow(10,e),r=c>=0;return{type:3,value:r?Math.ceil(t*c)/t:Math.floor(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,unroll:!0}],fn:c=>{if(c.type===7){let e=Lr(c.value);return me(e)}return c.type!==3?E():{type:3,value:Math.exp(c.value)}}},Abs:{arguments:[{boxed:!0,unroll:!0}],fn:c=>c.type===7?{type:3,value:Math.sqrt(c.value.real*c.value.real+c.value.imaginary*c.value.imaginary)}:c.type!==3?E():{type:3,value:Math.abs(c.value||0)}},Simplify:{arguments:[{name:"value",unroll:!0},{name:"significant digits",unroll:!0}],fn:(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:Yi(c)})},NormsInv:{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"}],fn:c=>({type:3,value:Ji(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:Ji(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)*Yi(Math.abs(c-e)/(t*Math.sqrt(2)))):i=Math.exp(-1/2*Math.pow((c-e)/t,2))/(t*Vo),{type:3,value:i}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:c=>{if(c.type===7){let e=pe(c.value,{real:.5,imaginary:0});return me(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3)return{type:3,value:Math.sqrt(c.value)}}return E()}},HexToDec:{arguments:[{description:"hexadecimal string",unroll:!0}],fn:c=>({type:3,value:parseInt(c,16)})},DecToHex:{arguments:[{description:"number",unroll:!0}],fn:c=>({type:2,value:c.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Wi,render:ji,fn:c=>({value:!!c,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:c=>(ut.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=>(ut.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=n=>{if(n)switch(n.type){case 2:case 3:case 4:return n.value;case 0:return"";default:return console.info("check",n,n.value),n.value?.toString()||""}else return""},t=new Set,r=new Set;for(let n of c.value)for(let o of n){let a=e(o);t.has(a)?r.add(a):t.add(a)}let i=[];for(let n of c.value){let o=[];for(let a of n){let s=e(a);o.push({type:4,value:!r.has(s)})}i.push(o)}return{type:8,value:i}}return{type:4,value:!0}}},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(c,e,t)=>{let r=be([c]),i=0,n=0,o=0;for(let d of r){if(d.type===6)return d;d.type===3&&(i===0?(n=d.value,o=d.value):(n=Math.min(n,d.value),o=Math.max(o,d.value)),i++)}typeof t=="number"&&(o=t),typeof e=="number"&&(n=e);let a=o-n,s=1,l=1;if(c.type===8){s=c.value.length,l=c.value[0]?.length||0;let d=[];for(let h=0;h<s;h++){let u=[];for(let m=0;m<l;m++){let f=c.value[h][m];if(f.type===3){let p=0;o===n?f.value>o?p=1:f.value<o?p=0:p=.5:a>0&&(p=(f.value-n)/a),u.push({type:3,value:p})}else u.push({type:0})}d.push(u)}return{type:8,value:d}}else return U()}}},Ki={};for(let c of Object.keys(je))Ki[c.toLowerCase()]=c;var Uo=["pow"],en={};for(let c of Uo)en[c.toLowerCase()]=c;for(let c of Object.getOwnPropertyNames(Math)){let e=c.toLowerCase();if(Ki[e]||en[e])continue;let t=Object.getOwnPropertyDescriptor(Math,c);if(!t)continue;let r=t.value,i=typeof r;switch(i){case"number":je[c]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":je[c]={fn:(...n)=>W(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 mt=(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),rn=(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),Wr=(c,e,t,r=0,i=0,n=0)=>{if(e<1)return NaN;if(e===1&&n)return 0;let o=mt(c,t,r,i,n),a=rn(c,e-1,o,r,n)*c;return n?a/(1+c):a},tn=(c,e,t,r=0,i=0,n=0)=>mt(c,t,r,i,n)-Wr(c,e,t,r,i,n),nn={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=j(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 U();if(e=j(e),t=j(t),e.length!==t.length)return U();let r=[];for(let o of e){if(typeof o!="number")return U();r.push(o)}let i=[];for(let o of t){if(typeof o!="number")return U();i.push(Math.floor(o))}let n=0;for(let o=0;o<r.length;o++)n+=(r[o]||0)/Math.pow(1+c,(i[o]-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=j(c),e=j(e),c.length!==e.length)return U();let r=0,i=0,n=[];for(let h of c){if(typeof h!="number")return U();h>0&&r++,h<0&&i++,n.push(h)}if(r<=0||i<=0)return U();let o=[];for(let h of e){if(typeof h!="number")return U();o.push(Math.floor(h))}let a=o[0];for(let h of o)if(h<a)return U();let s=.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,(o[m]-o[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+=s;continue}}else if(l[1].value=l[1].found?Math.min(l[1].value,t):t,l[1].found=!0,!l[0].found){t-=s;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=j(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 o=0;for(let a=0;a<t.length;a++)o+=Math.pow(1+e,-(a+1))*t[a];if(Math.abs(o)<=.00125)return{type:3,value:e};if(o>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 o=0;for(let a=r;a<=i;a++)o+=tn(c,a,e,t,0,n);return{type:3,value:o}}},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 o=0;for(let a=r;a<=i;a++)o+=Wr(c,a,e,t,0,n);return{type:3,value:o}}},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:Wr(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:tn(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,o=[-1,1],a=32,s=1e-6;for(let l=0;l<a;l++){let d=mt(n,c,t,r,i);if(Math.abs(d-e)<=s)return{type:3,value:n};let h=mt(o[1],c,t,r,i);e>=d&&e<=h||e>=h&&e<=d?o[0]=n:o[1]=n,n=o[0]+(o[1]-o[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:rn(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:mt(c,e,t,r,i)})}};var on={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=ce.TryParse(c);return e.type===3?{type:3,value:e.value}:U()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(c,e="0.00####")=>({type:2,value:z.Get(e).Format(c||0)}),category:["text"]},WildcardMatch:{visibility:"internal",arguments:[{name:"text",unroll:!0},{name:"text",unroll:!0},{name:"invert"}],fn:(c,e,t=!1)=>{if(typeof c=="string"&&typeof e=="string"){let r=ht(e),i=new RegExp("^"+r+"$","i").exec(c);return{type:4,value:t?!i:!!i}}return{type:4,value:c===e||c?.toString()===e?.toString()}}},Exact:{arguments:[{name:"text",boxed:!0,unroll:!0},{name:"text",boxed:!0,unroll:!0}],category:["text"],fn:(c,e)=>({type:4,value:c?.value?.toString()===e?.value?.toString()})},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=ht(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=j(c).map(r=>{let i=r?.toString()||"";return typeof r=="number"&&N.decimal_separator===","?i.replace(/\./,","):i}).join("");return{type:2,value:t}}}},jr={Concatenate:"Concat"};var Xt=(c,e)=>({type:4,value:typeof e.value?.value===c}),Qt=[{name:"Reference",metadata:!0,unroll:!0}],an={IsBlank:{description:"Returns true if the reference is blank",arguments:Qt,fn:Xt.bind(0,"undefined")},IsNumber:{description:"Returns true if the reference is a number",arguments:Qt,fn:Xt.bind(0,"number")},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:Qt,fn:Xt.bind(0,"boolean")},IsText:{description:"Returns true if the reference is text",arguments:Qt,fn:Xt.bind(0,"string")}};var Ee=(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 o=c[n]-r;i+=o*o}return e?i/(t-1):i/t},sn={"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(Ee(ue(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(Ee(ue(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:Ee(ue(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:Ee(ue(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 U();let t=0,r=0,i={x:0,y:0},n={x:[],y:[]};for(let o=0;o<c.length;o++){if(!c[o]||!e[o])continue;if(c[o].length!==e[o].length)return U();let a=c[o].length;r+=a;for(let s=0;s<a;s++)i.x+=c[o][s]||0,i.y+=e[o][s]||0,n.x.push(c[o][s]||0),n.y.push(e[o][s]||0)}if(r===0)return de();i.x/=r,i.y/=r;for(let o=0;o<r;o++)t+=(n.x[o]-i.x)*(n.y[o]-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,o=0,a=0,s=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,o+=u*u,a+=m*m,s++)}}return t=s*r-i*n,t&&(t/=Math.sqrt((s*o-i*i)*(s*a-n*n))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=be(c);let e=0,t={real:1,imaginary:0},r=!1,i=!1;for(let n of c)n.type===7?(r=!0,t=he(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=pe(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=be(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=ue(c);t.sort((s,l)=>s-l);let r=t.length,i=Math.pow(10,8),n=Math.round((1+(r-1)*e)*i)/i,o=Math.floor(n),a=Math.ceil(n);return{type:3,value:(t[o-1]+t[a-1])/2}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...c)=>{let e=ue(c);e.sort((o,a)=>o-a);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}}},Rank:{arguments:[{name:"Value"},{name:"Source"},{name:"Order"}],fn:(c,e,t=0)=>{if(typeof c!="number")return U();let r=ue(e);r.sort(t?(i,n)=>i-n:(i,n)=>n-i);for(let i=0;i<r.length;i++)if(r[i]===c)return{type:3,value:i+1};return E()}}},Yr={Mean:"Average",StDev:"StDev.S",Var:"Var.S"};var ln={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0,unroll:!0}],fn:c=>({type:4,value:!!c?.value&&ae(c.value.value)})},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0,unroll:!0}],fn: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,unroll:!0}],fn: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,unroll:!0}],fn:c=>{let e=Ve(c);return e?e.imaginary?{type:7,value:{real:e.real,imaginary:-e.imaginary}}:{type:3,value:e.real}:E()}},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0,unroll:!0}],fn: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,unroll:!0}],fn:c=>{let e=Ve(c);return e?{type:7,value:e}:E()}},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0,unroll:!0}],fn: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=Zt(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 qt=c=>{let e=[];c.type===8?e=c.value:e=[[c]];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 o=[];for(let a=0;a<r;a++){let s=e[n][a];if(s.type===7)o.push({...s.value});else if(s.type===3)o.push({real:s.value,imaginary:0});else if(s.type===0||s.value==="")o.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}i.push(o)}return{m:t,n:r,array:i}},cn={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=qt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Bt(e);return t?me(t):E()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=qt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Bt(e);if(t&&t.real===0&&t?.imaginary===0)return E();let r=Fi(e);return r?{type:8,value:r.map(i=>i.map(n=>me(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=qt(c),r=qt(e);if(!t.array||t.error||!r.array||r.error)return E();if(t.m!==r.n)return E();let i=Ui(r,t);return{type:8,value:i.map(n=>n.map(o=>me(o)))}}}};var ft=class c extends Re{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(){if(this.dirty){for(let e of this.edges_in)if(e.dirty)return;this.UpdateState(),this.dirty=!1}}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var Kt=class c extends Re{static type="calculation-leaf-vertex";type=c.type;address={row:-1,column:-1};use;updated=!1;color=2;Calculate(e){if(!this.dirty)return;for(let r of this.edges_in)if(r.dirty)return;let t=e.CalculationCallback.call(e,this);this.result=t.value,this.dirty=!1,this.updated=!0}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var Fo=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},Lo={complex_numbers:"off"},er=class extends Ot{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Wt(this.model,this.library,this.parser),{...Lo,...r}.complex_numbers==="on"){for(let a of Object.keys(Br))je[a]=Br[a];$i()}this.UpdateLocale(),this.library.Register(je,on,sn,nn,an,ln,cn);for(let a of Object.keys(Yr))this.library.Alias(a,Yr[a]);for(let a of Object.keys(jr))this.library.Alias(a,jr[a]);let n=a=>{let s=[];for(let l of a.value)for(let d of l)s.push(d.type===4&&d.value);return s},o=(a,s)=>{let l=j(a),d,h,u="=";if(typeof s=="string"){s=s.trim();let f=s.match(/^([=<>]+)/);f&&(u=f[1],s=s.substring(u.length));let p=ce.TryParse(s);if(p?.type===2?s=`"${p.value}"`:s=p?.value?.toString()||"",/[?*]/.test(s)){let b=this.parser.argument_separator;if(u==="="||u==="<>"){if(d=this.parser.Parse(`=WildcardMatch({}${b} ${s}${b} ${u==="<>"})`),h=d.expression,d.error||!h)return Se();h?.type==="call"&&h.args[0]?.type==="array"&&(h.args[0].values=[Zr(l)])}}}else s=(s||0).toString();if(!d){if(d=this.parser.Parse("{}"+u+s),h=d.expression,d.error||!h)return Se();if(h.type!=="binary")return console.warn("invalid expression [1]",h),Se();if(h.left.type!=="array")return console.warn("invalid expression [1]",h),Se();h.right.type==="identifier"&&(console.warn("will never happen"),h.right={...h.right,type:"literal",value:h.right.name}),h.left.values=[Zr(l)]}return h?this.CalculateExpression(h):E()};this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(a,...s)=>{if(a=Fo(a),a>100&&(a-=100),a<1||a>11)return U();let l=be(s),d=[],h=0,u=0,m;for(let p of l){let b=p.value?.address;if(!b)return O();if(!m||m.id!==b.sheet_id){if(!b.sheet_id)return console.warn("invalid reference in metadata"),O();if(m=this.model.sheets.Find(b.sheet_id),!m)return console.warn("invalid sheet in metadata"),O()}if(!m.GetRowHeight(b.row))continue;let C=p.value?.value;typeof C>"u"||(h++,typeof C=="number"&&(u+=C,d.push(C)))}let f=0;switch(a){case 1:if(d.length===0)return fe();f=u/d.length;break;case 2:f=d.length;break;case 3:f=h;break;case 4:if(d.length===0)return E();f=Math.max.apply(0,d);break;case 5:if(d.length===0)return E();f=Math.min.apply(0,d);break;case 6:if(d.length===0)return E();f=1;for(let p of d)f*=p;break;case 7:if(d.length<2)return fe();f=Math.sqrt(Ee(d,!0));break;case 8:if(d.length===0)return fe();f=Math.sqrt(Ee(d,!1));break;case 9:f=u;break;case 10:if(d.length<2)return fe();f=Ee(d,!0);break;case 11:if(d.length===0)return fe();f=Ee(d,!1);break}return{type:3,value:f}}},CountIfs:{arguments:[{name:"range1"},{name:"criteria1"},{name:"range2"},{name:"criteria2"}],fn:(...a)=>{let s=0,l=o(a[0],a[1]);if(l.type!==8)return l;let d=n(l);for(let h=2;h<a.length;h+=2)if(a[h]&&a[h+1]){let u=o(a[h],a[h+1]);if(u.type!==8)return u;let m=n(u);for(let[f,p]of d.entries())d[f]=p&&m[f]}for(let h of d)h&&s++;return{type:3,value:s}}},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(a,s)=>{let l=o(a,s);if(l.type===8){let d=0;for(let h of l.value)for(let u of h)u.value&&d++;return{type:3,value:d}}return l}},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:((a,s=0,l=0,d,h)=>{if(!a)return U();if(a.type===8){let m=typeof d=="number"?s+d:void 0,f=typeof h=="number"?l+h:void 0;return{type:8,value:a.value.slice(s,m).map(b=>b.slice(l,f))}}if(!ct(a))return console.info("e2",{reference:a}),O();let u=this.DynamicDependencies(a.value.address,this.expression_calculator.context.address,!0,s,l,h,d);if(!u)return console.info("e1",{check_result:u}),O();if(u.dirty){let m=this.GetVertex(this.expression_calculator.context.address,!0);return m.short_circuit=!0,{type:0,value:void 0}}if(u.area){let m={type:"address",...u.area.start,label:"",position:0,id:0},f={type:"address",...u.area.end,label:"",position:0,id:0},p=u.area.count===1?m:{type:"range",start:m,end:f,label:"",position:0,id:0};return{type:5,value:p}}return E()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:1,volatile:!0,fn:(a=>{if(!a||typeof a!="string")return U();let s=this.parser.Parse(a);if(s.error||!s.expression||s.expression.type!=="address"&&s.expression.type!=="range")return O();let l=this.DynamicDependencies(s.expression,this.expression_calculator.context.address);if(!l)return O();if(l.dirty){let d=this.GetVertex(this.expression_calculator.context.address,!0);return d.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:s.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(a,s,l=0)=>{if(l)return console.warn("inexact match not supported",{value:a,range:s,type:l}),de();if(s.type===8){if(s.value.length===1){let d=s.value[0];for(let h=0;h<d.length;h++)if(a.type==d[h].type&&a.value===d[h].value)return{type:3,value:h+1}}else for(let d=0;d<s.value.length;d++){let h=s.value[d];if(h.length!==1)return de();if(a.type==h[0].type&&a.value===h[0].value)return{type:3,value:d+1}}return de()}else return a.type===s.type&&a.value===s.value?{type:3,value:1}:de();return U()}},Index:{arguments:[{name:"range",boxed:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(a,s,l)=>{if(a&&a.type!==8&&(a={type:8,value:[[a]]}),s&&l){let d=a.value[l-1];if(d){let h=d[s-1];if(h)return h}}else if(s){let d=[];for(let h of a.value){if(!h[s-1])return U();d.push([h[s-1]])}return{type:8,value:d}}else if(l){let d=a.value[l-1];if(d)return{type:8,value:[d]}}return U()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:a=>{if(!a)return U();if(Array.isArray(a)){let s=a[0];return Array.isArray(s)?{type:3,value:s.length}:E()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:a=>a?Array.isArray(a)?{type:3,value:a.length}:{type:3,value:1}:U()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:a=>{if(!ct(a))return O();let s=this.model.sheets.Find(a.value?.address?.sheet_id||0);if(s){let l=s.cells.GetCell(a.value.address,!1);return{type:2,value:l?.value?.toString()||""}}return O()}},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",unroll:!0,metadata:!0}],fn:a=>{let s=a?.value?.address,l=this.model.sheets.Find(s?.sheet_id||0);if(s&&l){let d=l.cells.GetCell(s,!1);return{type:4,value:d?.type===1}}return{type:4,value:!1}}}})}get parser(){return this.model.parser}library=new Jt;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 o=n.rows,a=n.columns;if(r.type===8){let s=jt(r.value);for(let l=0;l<o;l++)if(s[l]){let d=0;for(;d<a&&d<s[l].length;d++){let h=s[l][d];switch(h.type===8&&(h=h.value[0][0]),h.type){case 8:case 5:i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0);break;default:i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(h.value,h.type)}}for(;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let d=0;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else{let s={...r};s.type===5&&(s={type:0,value:void 0});for(let l=0;l<o;l++)for(let d=0;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(s.value,s.type)}}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:$t()}:this.expression_calculator.Calculate(t.expression,t.address)}DynamicDependencies(t,r,i=!1,n=0,o=0,a=1,s=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+o,row:l.start.row+n,sheet_id:l.start.sheet_id},{column:l.start.column+o+a-1,row:l.start.row+n+s-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(){N.decimal_separator===","?this.parser.SetLocaleSettings(","):this.parser.SetLocaleSettings(".")}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(o=>({name:o.name||""})),type:"function"}});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})),type:"function"});return r}RegisterLibrary(t,r){return this.registered_libraries[t]?!1:(this.RegisterFunction(r),this.registered_libraries[t]=!0,!0)}RegisterFunction(t){for(let r of Object.keys(t)){let i=t[r],n=i.fn;i.fn=(...o)=>n.apply({address:{...this.expression_calculator.context.address}},o),this.library.Register({[r]:i})}}Calculate(t){if(t&&!t.start.sheet_id)throw new Error("CalculateInternal called with subset w/out sheet ID");this.full_rebuild_required&&(t=void 0,this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.full_rebuild_required=!1),this.RebuildGraph(t);try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let 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){this.parser.Save(),i.argument_separator&&(i.argument_separator===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",")),i.r1c1&&(this.parser.flags.r1c1=i.r1c1);let o=this.parser.Parse(t);if(this.parser.Restore(),o&&o.expression){this.parser.Walk(o.expression,s=>{if(s.type==="address"||s.type==="range"){if(s.type==="address"){if(s.offset_column||s.offset_row)throw new Error("Evaluate does not support offset references")}else if(s.start.offset_column||s.start.offset_row||s.end.offset_column||s.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(s,void 0,r)}return!0});let a=this.CalculateExpression(o.expression);return n?a:a.type===8?a.value.map(s=>s.map(l=>l.value)):a.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.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},i=[];for(let n of t){let o={column:n.column,row:n.row,sheet_id:n.sheet_id},a=y.CellAddressToLabel(o,!0);r[a]||(r[a]=a,i.push(o))}return i}Unresolve(t,r,i=!0,n=!0){let o="",a=V(t)?new y(t):new y(t.start,t.end);if(n){let d=this.model.named.MatchSelection(a);if(d)return d}if(o=a.spreadsheet_label,!i)return o;let s=a.start.sheet_id||r?.id,l=this.ResolveSheetName(s,!0);return l?l+"!"+o:o}ResolveSheetName(t,r=!1){let i=this.model.sheets.Find(t);if(i)return r&&xe.test(i.name)?`'${i.name}'`:i.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}RemoveConnectedELement(t){let r=t.internal;return r?.vertex?(this.RemoveLeafVertex(r.vertex),!0):!1}UpdateConnectedElements(t,r){if(t||(t=this.model.sheets.list[0]),r){let n=r.internal;n?.vertex&&this.RemoveLeafVertex(n.vertex)}let i=r?[r]:this.model.connected_elements.values();for(let n of i){let o=n.internal;o||(o={vertex:new ft},n.internal=o);let a=o.vertex;this.AddLeafVertex(a),this.UpdateLeafVertex(a,n.formula,t)}}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){let a=new Kt;a.use="conditional",i.internal.vertex=a;let s;i.type!=="gradient"&&i.type!=="duplicate-values"&&(s=i.options);let l=this.Evaluate(n,r,s,!0);i.internal.vertex.result=l,i.internal.vertex.updated=!0}let o=i.internal.vertex;this.AddLeafVertex(o),this.UpdateLeafVertex(o,n,r)}}RemoveAnnotation(t){let r=t.temp;r.vertex&&(r.vertex.Reset(),this.RemoveLeafVertex(r.vertex))}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){let n=i.temp;n.vertex||(n.vertex=new ft),this.AddLeafVertex(n.vertex),this.UpdateLeafVertex(n.vertex,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.GetName(t.name,r?.sheet_id||0);if(i&&i.type==="range")return new y(i.area.start,i.area.end)}break}}NamedRangeToAddressUnit(t,r){let i=t.name.toUpperCase(),n=this.model.GetName(i,r.sheet_id||0);if(n&&n.type==="range")return n.area.count===1?this.ConstructAddressUnit(n.area.start,i,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(n.area.start,i,t.id,t.position),end:this.ConstructAddressUnit(n.area.end,i,t.id,t.position),label:i,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:{}},o){if(!i){let a=this.model.sheets.Find(r);a&&(i=a.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let a=this.model.GetName(t.name,o.sheet_id||0);if(a?.type==="expression")this.RebuildDependencies(a.expression,r,i,n,o);else{let s=this.NamedRangeToAddressUnit(t,o);s&&(s.type==="address"?n.addresses[s.label]=s:n.ranges[s.label]=s)}}break;case"structured-reference":{let a=this.model.ResolveStructuredReference(t,o);a&&(a.type==="address"?n.addresses[a.sheet_id+"!"+a.label]=a:n.ranges[a.label]=a);let s=this.model.tables.get(t.table.toLowerCase());if(s){let l=o.row;if(l<s.area.start.row||l>s.area.end.row)break;let d=t.column.toLowerCase(),h=-1;if(s.columns){for(let u=0;u<s.columns.length;u++)if(d===s.columns[u]){h=s.area.start.column+u;break}}if(h>=0){let u={label:t.label,type:"address",row:l,column:h,sheet_id:s.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 a=this.model.sheets.Find(t.sheet);a&&(t.sheet_id=a.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 a=this.model.sheets.Find(t.start.sheet);a&&(t.start.sheet_id=a.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,o);break;case"binary":this.RebuildDependencies(t.left,r,i,n,o),this.RebuildDependencies(t.right,r,i,n,o);break;case"group":t.elements.forEach(a=>this.RebuildDependencies(a,r,i,n,o));break;case"call":{let a=t.args.slice(0),s=this.library.Get(t.name);s&&s.arguments&&s.arguments.forEach((l,d)=>{l&&l.address&&(this.RebuildDependencies(a[d],r,i,void 0,o),a[d]={type:"missing",id:-1})}),a.forEach(l=>this.RebuildDependencies(l,r,i,n,o))}break}return n}UpdateLeafVertex(t,r,i){t.Reset();let n=this.parser.Parse(r);if(n.expression){let o=this.RebuildDependencies(n.expression,i.id,i.name,void 0,{row:0,column:0});for(let a of Object.keys(o.ranges)){let s=o.ranges[a],l=new y(s.start,s.end);l.entire_column||l.entire_row||l.count>1?this.AddLeafVertexArrayEdge(l,t):this.AddLeafVertexEdge(l.start,t)}for(let a of Object.keys(o.addresses)){let s=o.addresses[a];this.AddLeafVertexEdge(s,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,o=i.sheet_id||r.sheet_id;i.sheet_id||(i.sheet_id=o);for(let a=i.column;a<=n.column;a++)for(let s=i.row;s<=n.row;s++)this.ResetInbound({column:a,row:s,sheet_id:o},!0,!1);this.SetDirty(r);for(let a=i.column;a<=n.column;a++)for(let s=i.row;s<=n.row;s++)s===i.row&&a===i.column||this.AddEdge(i,{...i,row:s,column:a})}if(t.type===1){this.ResetInbound(r,!0);let i=this.parser.Parse(t.value);if(i.expression){if(i.expression.type==="call"){let a=this.library.Get(i.expression.name);a&&(a.render||a.click)&&(t.render_function=a.render,t.click_function=a.click)}let o=this.RebuildDependencies(i.expression,r.sheet_id,"",void 0,r);for(let a of Object.keys(o.ranges)){let s=o.ranges[a],l=new y(s.start,s.end);if(l.entire_row||l.entire_column)this.AddArrayEdge(l,r);else for(let d of l)this.AddEdge(d,r)}for(let a of Object.keys(o.addresses)){let s=o.addresses[a];this.AddEdge(s,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 o=t.start.column;o<=t.end.column;o++){let a=n[o];a&&this.RebuildGraphCell(a,{row:i,column:o,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 o=r.cells.data[n];if(o){let a=o.length;for(let s=0;s<a;s++){let l=o[s];l&&this.RebuildGraphCell(l,{row:n,column:s,sheet_id:r.id})}}}}}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 tr=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 29.5.1"];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()})}Node(e){return this.model[e]}Update(e,t=!0){t&&(e={...this.options_,...e}),this.options=e}HideDialog(){this.visible=!1}ShowDialog(e){return new Promise(t=>{this.pending_dialog_resoltion.push(t),this.options=e,this.visible=!0,this.timeout&&(window.clearTimeout(this.timeout),this.timeout=0),e.timeout&&(this.timeout=window.setTimeout(()=>this.HideDialog(),e.timeout))})}};var rr=class{constructor(e){this.container=e;let t=P.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 dn={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 ge=c=>!!c&&typeof c=="object"&&c.key==="metadata"&&!!c.value&&c.value.type==="metadata",Jr=c=>!!c&&typeof c=="object"&&c.key==="series"&&Array.isArray(c.value),hn=c=>!!c&&typeof c=="object"&&c.type===8&&Array.isArray(c.value);var $=class{static Scale(e,t,r=6.5,i,n){return gi(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 Xr="#,##0.00",un=c=>{let[e,t,r,i,n,o,a]=c,s={x:{data:[]},y:{data:[]}};if(typeof n=="number"&&(s.index=n),o&&(s.subtype=o.toString()),a){let h=$.Flatten(Array.isArray(a)?a:[a]);s.labels=h.map(u=>typeof u>"u"?"":u.toString())}e&&(s.label=e.toString());let l=(h,u=!1)=>{let m;if(ge(h)&&(h={type:8,value:[[h]]}),hn(h)){m={data:[]};let f=$.Flatten(h.value);if(m.data=f.map(p=>{if(ge(p)){if(typeof p.value.value=="number")return p.value.value}else if(p.type===3)return p.value}),ge(f[0])&&f[0].value?.format&&(m.format=f[0].value.format,u)){let p=z.Get(m.format);m.labels=m.data.map(b=>b===void 0?void 0:p.Format(b))}}return m};s.y=l(r,!0)||{data:[]},s.x=l(t)||{data:[]},s.z=l(i);let d=[s.x,s.y];for(let h of d)if(h.data.length){let u=h.data.filter(m=>m||m===0);h.range={min:Math.min.apply(0,u),max:Math.max.apply(0,u)}}return s},mn=c=>{let e={x:{data:[]},y:{data:[]}},t=$.Flatten(c.value);e.y.data=t.map((n,o)=>{if(typeof n.value=="number")return n.value;if(ge(n)){if(ae(n.value.value))return e.x.data[o]=n.value.value.real,n.value.value.imaginary;if(typeof n.value.value=="number")return n.value.value}});let r="";if(ge(t[0])&&(r=t[0].value.format||""),r){e.y.format=r;let n=z.Get(e.y.format||"");e.y.labels=e.y.data.map(o=>o===void 0?void 0:n.Format(o))}let i=e.y.data.filter(n=>n||n===0);if(e.y.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)},e.x.data.length){let n=e.x.data.filter(o=>typeof o=="number");if(e.x.range={min:Math.min.apply(0,n),max:Math.max.apply(0,n)},r){e.x.format=r;let o=z.Get(e.x.format||"");e.x.labels=e.x.data.map(a=>a===void 0?void 0:o.Format(a))}}return e},nr=(c,e)=>{if(!c)return[];let t=[];if(c.type===5){if(c.key==="group"){if(Array.isArray(c.value)){for(let[n,o]of c.value.entries())if(o&&typeof o=="object")if(Jr(o)){let a=un(o.value);typeof a.index>"u"&&(a.index=n+1),t.push(a)}else o.type===8&&t.push(mn(o))}}else if(Jr(c)){let n=un(c.value);t.push(n)}}else c.type===8&&t.push(mn(c));let r,i=0;if(e?.type===8){let n=$.Flatten(e.value),o="0.00###";ge(n[0])&&n[0].value.format&&(o=n[0].value.format);let a=n.map(l=>{if(l.type===3)return l.value;if(ge(l)&&typeof l.value.value=="number")return l.value.value}),s=a.filter(l=>typeof l=="number");r={data:a,format:o,range:{min:Math.min.apply(0,s),max:Math.max.apply(0,s)}}}for(let n of t)i=Math.max(i,n.y.data.length),n.x.data.length&&(r||(r=n.x));if(!r){r={data:[],range:{min:0,max:Math.max(0,i-1)}};for(let n=0;n<i;n++)r.data.push(n)}for(let n of t)n.x.data.length||(n.x=r);return t},or=(c,e,t,r,i)=>{let n="",o="";for(let g of c)g.y.format&&!o&&(o=g.y.format),g.x.format&&!n&&(n=g.x.format);let a;c.some(g=>g.label&&g.label.length>0)&&(a=c.map((g,C)=>({label:g.label||`Series ${C+1}`,index:typeof g.index=="number"?g.index:C+1})));let s=c.filter(g=>g.x.range),l=Math.min.apply(0,s.map(g=>g.x.range?.min||0)),d=Math.max.apply(0,s.map(g=>g.x.range?.max||0)),h=Math.min.apply(0,s.map(g=>g.y.range?.min||0)),u=Math.max.apply(0,s.map(g=>g.y.range?.max||0));for(let g of c)if(g.z){for(let[C,x]of g.z.data.entries())if(typeof x<"u"){let v=g.x.data[C],_=Math.max(0,x/2);typeof v<"u"&&(l=Math.min(l,v-_),d=Math.max(d,v+_));let w=g.y.data[C];typeof w<"u"&&(h=Math.min(h,w-_),u=Math.max(u,w+_))}}typeof r<"u"&&(l=Math.min(l,r)),typeof i<"u"&&(l=Math.max(l,i)),typeof e<"u"&&(h=Math.min(h,e)),typeof t<"u"&&(u=Math.max(u,t));let m=$.Scale(l,d,7),f=$.Scale(h,u,7),p,b;if(n){p=[];let g=z.Get(n);for(let C=0;C<=m.count;C++)p.push(g.Format(m.min+C*m.step))}if(o){b=[];let g=z.Get(o);for(let C=0;C<=f.count;C++)b.push(g.Format(f.min+C*f.step))}return{x:{format:n,scale:m,labels:p},y:{format:o,scale:f,labels:b},legend:a}},ir=(c,e,t)=>{for(let r of c){let i={x:z.Get(r.x.format||""),y:z.Get(r.y.format||"")};r.y.labels=[];for(let n=0;n<r.y.data.length;n++){let o=t?t[n]:typeof r.x.data[n]=="number"?i.x.Format(r.x.data[n]):"",a=typeof r.y.data[n]=="number"?i.y.Format(r.y.data[n]):"";r.y.labels[n]=e.replace(/\bx\b/g,o).replace(/\by\b/g,a)}}},fn=c=>{let e=nr(c[0]),t,r;for(let a of e)typeof a.x.range?.min=="number"&&a.x.range.min>0&&a.x.range.min<50&&(r=0),typeof a.y.range?.min=="number"&&a.y.range.min>0&&a.y.range.min<50&&(t=0);let i=or(e,t,void 0,r),n=c[1]?.toString()||void 0;return{legend:i.legend,legend_style:2,type:"bubble",series:e,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels}},Qr=(c,e="plot")=>{let t=nr(c[0]),r=or(t),i=c[1]?.toString()||void 0,n=c[2]?.toString()||void 0,o={legend:r.legend,style:e,type:"scatter2",series:t,title:i,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:e==="line",points:e==="plot"};if(n){o.markers=/marker/i.test(n),o.smooth=/smooth/i.test(n),o.data_labels=/labels/i.test(n);let a=n.match(/labels="(.*?)"/);a&&o.series?ir(o.series,a[1]):(a=n.match(/labels=([^\s\r\n,]+)(?:\W|$)/),a&&o.series&&ir(o.series,a[1])),a=n.match(/class=([\w_-]+)(?:\W|$)/),a&&(o.class_name=a[1])}return o},qr=(c,e)=>{let[t,r,i,n]=c,o=nr(t),a=or(o),s;if(r){s=(r.type===8?$.Flatten(r.value):$.Flatten(r)).map(f=>!f||!f.value?"":ge(f)?typeof f.value.value=="number"?z.Get(f.value.format||Xr).Format(f.value.value):f.value.value?.toString()||"":typeof f.value=="number"?z.Get(Xr).Format(f.value):f.value.toString());let m=o.reduce((f,p)=>Math.max(f,p.y.data.length),0);for(m<s.length&&(s=s.slice(0,m));m>s.length;)s.push("")}let l=i?.toString()||void 0,d=n?.toString()||void 0,h={type:e,legend:a.legend,legend_style:1,series2:o,scale:a.y.scale,title:l,y_labels:e==="bar"?s:a.y.labels,x_labels:e==="bar"?a.y.labels:s};if(d){h.round=/round/i.test(d),h.data_labels=/labels/i.test(d);let u=d.match(/labels="(.*?)"/);u&&o?ir(o,u[1],s):(u=d.match(/labels=([^\s\r\n,]+)(?:\W|$)/),u&&o&&ir(o,u[1],s)),u=d.match(/class=([\w_-]+)(?:\W|$)/),u&&(h.class_name=u[1])}return h},Kr=(c,e)=>{let t=nr(c[0],c[1]),r=or(t,0,0),i=c[2]?.toString()||void 0,n=c[3]?.toString()||void 0,o={legend:r.legend,type:"scatter2",series:t,title:i,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:!0,filled:e==="area"};if(n){o.smooth=/smooth/i.test(n);let a=n.match(/class=([\w_-]+)(?:\W|$)/);a&&(o.class_name=a[1])}return o},pn=(c,e=!1)=>{let[t,r,i,n,o]=c,a=c[0]?.type===8?c[0].value:c[0],s=a?$.Flatten(a):[],l=s.map(_=>{if(ge(_)&&typeof _.value.value=="number")return _.value.value}),d=c[1]?.type===8?c[1].value:c[1],h=$.Flatten(d||[]).map(_=>ge(_)?typeof _.value.value=="number"&&_.value.format?z.Get(_.value.format).Format(_.value.value):_.value.value?.toString()||"":_.value?.toString()||""),u=!1;l=l.map(_=>_&&_<0?(u||(console.warn("pie/donut chart does not support negative values (omitted)"),u=!0),0):_);let m=0,f=l.map((_,w)=>(typeof _<"u"&&(m+=_),{value:_||0,label:h[w]||"",index:w+1,percent:0}));if(m)for(let _ of f)_.percent=(_.value||0)/m;let p="";for(let _ of s)if(ge(_)){p=_.value.format||"";break}let b=z.Get(p||Xr),g=z.Get("percent");typeof c[4]>"u"&&c[1]&&(c[4]="label");let C=c[4]||"";if(C)for(let _ of f){let w=b.Format(_.value||0),A=g.Format(_.percent);_.title=C.replace(/value%/ig,g.Format(_.value||0)).replace(/value/ig,w).replace(/percent/ig,A).replace(/label/ig,_.label||"").trim()}let x=(n||"").toUpperCase();if(x==="ASC"||x==="ASCENDING"||x==="INC")f.sort((_,w)=>(_.value||0)-(w.value||0));else if(x==="DESC"||x==="DESCENDING"||x==="DEC")f.sort((_,w)=>(w.value||0)-(_.value||0));else{let _=(n||"").match(/sort=([\w]+)(?:\W|$)/i);_&&(x=_[1],/^(asc|inc)/i.test(x)?f.sort((w,A)=>(w.value||0)-(A.value||0)):/^(desc|dec)/i.test(x)&&f.sort((w,A)=>(A.value||0)-(w.value||0)))}let v={type:e?"pie":"donut",slices:f,title:i||""};if(n){let _=n.match(/class=([_-\w]+)(?:\W|$)/);_&&(v.class_name=_[1])}return v};var Me=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 Oo="http://www.w3.org/2000/svg",M=(c,e={},t)=>{let r=document.createElementNS(Oo,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},ar=class{parent;svg_node;text_measurement_node;container_group;group;axis_group;label_group;size={width:0,height:0};bounds=new Me;constructor(){this.container_group=M("g"),this.group=M("g"),this.axis_group=M("g",{class:"axis-group"}),this.label_group=M("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=M("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=M("g");this.group.appendChild(t);let r=M("text");t.appendChild(r),t.setAttribute("class","legend");let i=[[]],n=10,o=e.area.width,a=0,s=0,l=e.area.width,d=e.style===1?14:26,h=e.labels.map((b,g)=>{r.textContent=b.label;let C=r.getBoundingClientRect(),x={width:C.width,height:C.height},v=x.width+d+n;return s=Math.max(s,x.height),e.layout===1?i[g]=[g]:v>o?i[a].length===0?(i[a].push(g),a++,i[a]=[],o=l):(a++,i[a]=[g],o=l-v):(i[a].push(g),o-=v),x});t.removeChild(r);let u=s,m=e.layout||0;m===0&&i.every(b=>b.length<=1)&&(m=0);for(let b=0;b<i.length;b++){let g=i[b].reduce((v,_)=>v+h[_].width+d,(i[b].length-1)*n),C=0,x=m===0?Math.round((l-g)/2):Math.round(n/2);for(let v=0;v<i[b].length;v++){let _=i[b][v],w=h[_],A=e.labels[_],S=u-1,I=!1;typeof navigator<"u"&&(I=/trident/i.test(navigator?.userAgent||""));let L=typeof A.index=="number"?A.index:_+1;switch(t.appendChild(M("text",{"dominant-baseline":"middle",x:x+d,y:u,dy:I?".3em":void 0},A.label)),e.style){case 1:t.appendChild(M("rect",{class:`series-${L}`,x,y:S-4,width:8,height:8}));break;case 2:t.appendChild(M("circle",{class:`series-${L}`,cx:x+d-11,cy:S-4+3}));break;default:t.appendChild(M("rect",{class:`series-${L}`,x,y:S-1,width:d-3,height:2}));break}C=Math.max(C,w.height),x+=w.width+d+n}u=Math.round(u+C*1.1)}let f=t.getBoundingClientRect(),p={width:f.width,height:f.height+s};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=M("text",{class:"chart-title",x:Math.round(t.width/2)},e);n.style.textAnchor="middle",this.group.appendChild(n);let o=n.getBoundingClientRect();switch(i){case"bottom":n.setAttribute("y",Math.round(t.bottom-o.height).toString()),t.bottom-=o.height+r;break;default:n.setAttribute("y",Math.round(t.top+r+o.height).toString()),t.top+=o.height+r;break}}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=M("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 o=[],a=e.width/i;for(let s=0;s<i;s++){let l=Math.round(e.left+a/2+a*s)-.5;o.push(`M${l} ${t} L${l} ${r}`)}this.group.appendChild(M("path",{d:o,class:n}))}RenderXAxisBar(e,t,r,i,n){let o=r.length;if(!o)return;let a=4,s=t?e.width/o:e.width/(o-1),l=t?s/2:0,d=1,h=!0;for(;h;){h=!1;let u=0;for(let m=0;m<o;m+=d){let f=Math.round(e.left+l+s*m),p=f-i[m].width/2;if(u&&p<=u){d++,h=!0;break}u=f+i[m].width/2+a}}for(let u=0;u<o;u+=d){let m=Math.round(e.left+l+s*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,o=[];for(let a=0;a<r;a++){let s=Math.round(e.left+n+i*a)+.5;o.push(`M${s},${e.bottom+.5} v6`)}this.axis_group.appendChild(M("path",{d:o.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,i,n){let o=r.length;if(!o)return;let a=4,s=t?e.width/o:e.width/(o-1),l=t?s/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<o;p+=d){let b=Math.round(e.left+l+s*p),g=b-i[p].width/2;if(f&&g<=f){d++,h=!0;break}f=b+i[p].width/2+a}}d===3&&!m&&u&&d++;for(let f=0;f<o;f+=d){let p=Math.round(e.left+l+s*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 o=e.height/n,a=1,s=!0;for(;s;){s=!1;let l=0;for(let d=0;d<n;d+=a){let h=r[d],u=Math.round(e.bottom-o*(d+.5)+h.metrics.height/4);if(l&&u>=l){a++,s=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=a){let d=r[l],h=Math.round(e.bottom-o*(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 o=e.height/(n-1),a=1,s=!0;for(;s;){s=!1;let l=0;for(let d=0;d<n;d+=a){let h=r[d],u=Math.round(e.bottom-o*d+h.metrics.height/4);if(l&&u>=l){a++,s=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=a){let d=r[l],h=Math.round(e.bottom-o*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 o=M("g"),a=[],s=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=t.map((b,g)=>{if(!(typeof b>"u"))return{x:Math.round(e.left+e.width/d*g),y:e.bottom-b}}),f=[],p=()=>{if(f.length<2)return;let b="",g=f[0],C=f[f.length-1];f.length===2?b=`${f[0].x},${f[0].y} L${f[1].x},${f[1].y}`:f.length>2&&(b=""+this.CatmullRomChain(f).map(v=>`${v.x},${v.y}`).join(" L")),b&&(a.push("M"+b),r&&(s.push(`M ${g.x},${e.bottom} L ${g.x},${g.y}`),s.push("L"+b),s.push(`L ${C.x},${e.bottom}`)))};for(let b of m)b?f.push(b):(p(),f=[]);if(f.length&&p(),r&&o.appendChild(M("path",{class:"fill",d:s})),o.appendChild(M("path",{class:"line",d:a})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),o.setAttribute("class",n.join(" "))),this.group.appendChild(o),i&&u.length){let b=M("g");for(let g of u){let C=M("circle",{cx:g.x,cy:g.y,r:h});C.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i[g.i]||"")}),C.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),b.appendChild(C)}b.setAttribute("class","mouse-layer"),this.group.appendChild(b)}}RenderLine(e,t,r=!1,i,n){let o=M("g"),a=[],s=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=0,f=!0,p;for(;m<l;m++){let b=t[m];if(typeof b>"u"){f=!0,r&&typeof p<"u"&&s.push(`L${p} ${e.bottom}Z`),p=void 0;continue}let g=Math.round(+e.left+e.width/d*m);f?(r&&s.push(`M${g} ${e.bottom} L${g} ${e.bottom-b}`),a.push(`M${g} ${e.bottom-b}`)):(a.push(`L${g} ${e.bottom-b}`),s.push(`L${g} ${e.bottom-b}`)),u.push({x:g,y:e.bottom-b,i:m}),p=g,f=!1}if(r&&typeof p<"u"&&s.push(`L${p} ${e.bottom}Z`),r&&o.appendChild(M("path",{class:"fill",d:s})),o.appendChild(M("path",{class:"line",d:a})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),o.setAttribute("class",n.join(" "))),this.group.appendChild(o),i&&u.length){let b=M("g");for(let g of u){let C=M("circle",{cx:g.x,cy:g.y,r:h});C.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i[g.i]||"")}),C.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),b.appendChild(C)}b.setAttribute("class","mouse-layer"),this.group.appendChild(b)}}RenderBarGrid(e,t,r){let i=[],n=e.width/t;for(let o=0;o<=t;o++){let a=Math.round(e.left+n*o)-.5;i.push(`M${a} ${e.top} L${a} ${e.bottom}`)}this.group.appendChild(M("path",{d:i,class:r}))}RenderGrid(e,t,r=0,i,n){let o=[],a=[],s=e.height/t;for(let l=0;l<=t;l++){let d=Math.round(e.top+s*l)-.5;n&&n[1]===l?a.push(`M${e.left} ${d} L${e.right} ${d}`):o.push(`M${e.left} ${d} L${e.right} ${d}`)}s=e.width/(r-1);for(let l=0;l<r;l++){let d=Math.round(e.left+s*l)-.5;n&&n[0]===l?a.push(`M${d} ${e.top} L${d} ${e.bottom}`):o.push(`M${d} ${e.top} L${d} ${e.bottom}`)}this.group.appendChild(M("path",{d:o,class:i})),a.length&&(i?Array.isArray(i)?i.push("zero"):i=i+" zero":i="zero",this.group.appendChild(M("path",{d:a,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:b,y:g}=m;return((b-f)**2+(g-p)**2)**r+h},n=0,o=i(n,e[0],e[1]),a=i(o,e[1],e[2]),s=i(a,e[2],e[3]),l=(a-o)/t,d=[];for(let h=0;h<t;h++){let u=o+l*h,m=this.AddPoints(this.MultiplyPoint(e[0],(o-u)/(o-n)),this.MultiplyPoint(e[1],(u-n)/(o-n))),f=this.AddPoints(this.MultiplyPoint(e[1],(a-u)/(a-o)),this.MultiplyPoint(e[2],(u-o)/(a-o))),p=this.AddPoints(this.MultiplyPoint(e[2],(s-u)/(s-a)),this.MultiplyPoint(e[3],(u-a)/(s-a))),b=this.AddPoints(this.MultiplyPoint(m,(a-u)/(a-n)),this.MultiplyPoint(f,(u-n)/(a-n))),g=this.AddPoints(this.MultiplyPoint(f,(s-u)/(s-o)),this.MultiplyPoint(p,(u-o)/(s-o))),C=this.AddPoints(this.MultiplyPoint(b,(a-u)/(a-o)),this.MultiplyPoint(g,(u-o)/(a-o)));d.push(C)}return d}CatmullRomChain(e,t=30){let r=e.slice(0),i=[],n=r.length;if(n){let o=r[n-1].x-r[n-2].x,a=r[n-1].y-r[n-2].y;r.push({x:r[n-1].x+o,y:r[n-1].y+a}),r.push({x:r[n-1].x+o,y:r[n-1].y+a}),o=r[1].x-r[0].x,a=r[1].y-r[0].y,r.unshift({x:r[0].x-o,y:r[0].y-a});for(let s=0;s<r.length-4;s++){let l=r.slice(s,s+4),d=this.CatmullRomSpline(l,t);i.push(...d)}}return i}RenderDataLabels(e,t,r,i,n,o,a){let s=Math.max(t.length,r.length),l=i.max-i.min||1,d=n.max-n.min||1;for(let h=0;h<s;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=o[h];if(p){this.label_group.appendChild(M("circle",{class:"label-target",cx:f.x,cy:f.y,r:10}));let b=M("g",{class:"data-label",transform:`translate(${f.x+10},${f.y})`});this.label_group.appendChild(b);let g=M("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${a}`});b.appendChild(g);let C=M("text",{x:4,y:0},p);b.appendChild(C);let x=C.getBoundingClientRect(),v=x.height,_=x.width+8;_+15+f.x>=e.right&&(b.setAttribute("transform",`translate(${f.x-_-15},${f.y})`),g.setAttribute("cx",(_+15).toString()));let w=M("path",{d:`M0,5 h${_} v-${v} h-${_} Z`});b.insertBefore(w,C)}}}}RenderBubbleSeries(e,t,r,i,n){let o=r.max-r.min||1,a=i.max-i.min||1,s=[],l=[],d=M("g",{class:n});if(this.group.appendChild(d),t.z)for(let[h,u]of t.z.data.entries()){let m=t.x.data[h],f=t.y.data[h];if(typeof m<"u"&&typeof f<"u"&&typeof u<"u"&&u>0){let p=u/o*e.width,b=u/a*e.height,g=Math.max(p,b),C={x:e.left+(m-r.min)/o*e.width,y:e.bottom-(f-i.min)/a*e.height,z:g};if(s.push(C),t.labels?.[h]){let x=C.z/2;l.push({x:C.x,y:C.y,text:t.labels?.[h]||"",offset:Math.cos(Math.PI/4)*x})}}}for(let h of s)h&&d.appendChild(M("circle",{cx:h.x,cy:h.y,r:h.z/2,class:"point"}));if(l.length){let h=this.label_group.getBoundingClientRect();for(let u of l)if(u.text){let m=this.label_group.appendChild(M("g",{class:"bubble-label"})),f=m.appendChild(M("rect",{x:u.x,y:u.y,class:"label-background"})),b=m.appendChild(M("text",{x:u.x,y:u.y,offset:u.offset,class:"label-text","text-anchor":"middle","alignment-baseline":"middle",style:`--translate-offset: ${Math.round(u.offset)}px`},u.text)).getBoundingClientRect();f.setAttribute("x",(b.left-h.left-2).toString()),f.setAttribute("y",(b.top-h.top-1).toString()),f.style.height=b.height+2+"px",f.style.width=b.width+4+"px"}}}RenderScatterSeries(e,t,r,i,n,o=!0,a=!1,s=!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=[],b=[],g=[],C=M("g",{class:h});this.group.appendChild(C);for(let x=0;x<u;x++){let v=t[x],_=r[x];typeof v>"u"||typeof _>"u"?p.push(void 0):p.push({x:e.left+(v-i.min)/m*e.width,y:e.bottom-(_-n.min)/f*e.height})}if(o){let x=[],v=d?()=>x.length===2?`${x[0].x},${x[0].y} L${x[1].x},${x[1].y}`:x.length>2?this.CatmullRomChain(x).map(w=>`${w.x},${w.y}`).join(" L"):"":()=>x.map(_=>`${_.x},${_.y}`).join(" L");for(let _ of p)if(_)x.push(_);else{if(x.length>=2){let w=v();b.push("M"+w),g.push(`M${x[0].x},${e.bottom}L`+w+`L${x[x.length-1].x},${e.bottom}Z`)}x=[]}if(x.length>=2){let _=v();b.push("M"+_),g.push(`M${x[0].x},${e.bottom}L`+_+`L${x[x.length-1].x},${e.bottom}Z`)}}if(s&&C.appendChild(M("path",{d:g,class:"fill"})),o&&C.appendChild(M("path",{d:b,class:"line"})),a)for(let x of p)x&&C.appendChild(M("circle",{cx:x.x,cy:x.y,r:1,class:"point"}));if(l)for(let x of p)x&&C.appendChild(M("circle",{cx:x.x,cy:x.y,r:3,class:"marker"}))}RenderPoints(e,t,r,i){let n=[];for(let o=0;o<t.length;o++){let a=t[o]*e.width+e.left,s=e.bottom-r[o]*e.height;n.push(`M${a-1},${s-1} L${a+1},${s+1}`),n.push(`M${a-1},${s+1} L${a+1},${s-1}`)}this.group.appendChild(M("path",{d:n,class:i}))}RenderPoint(e,t,r){this.group.appendChild(M("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=M("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(M("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,i,n,o){let a="";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);a=`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);a=`M${e.left},${e.top+e.height/2-h} a${l},${l} 0 0 1 0,${h*2} z`}else a=`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 a=`M${e.left},${e.top} h${e.width} v${e.height} h${-e.width} v${-e.height} `;let s=M("path",{d:a,class:r});if(i&&(s.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i)}),s.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")})),this.group.appendChild(s),n){this.label_group.appendChild(M("path",{class:"label-target",d:a}));let l=o||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},d=M("g",{class:"data-label",transform:`translate(${l.x},${l.y})`});this.label_group.appendChild(d);let h=M("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),b=M("rect",{rx:3,x:-f/2,y:Math.round(-m+p*2/3),width:f,height:m+p});d.insertBefore(b,h)}}RenderText(e,t,r,i,n){let o=M("text",{x:i.x,y:i.y,class:n},t);switch(r){case"right":o.style.textAnchor="end";break;case"center":o.style.textAnchor="middle";break;default:o.style.textAnchor="start";break}(e||this.group).appendChild(o)}RenderDonut(e,t,r,i,n,o,a){let s=-Math.PI/2,l=0;o&&(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=[],b=0,g=d.bind(0,t,r),C=d.bind(0,t,i);if(m>.5){b=s+m/2*Math.PI*2,l=s+m*Math.PI*2;let _=b-s,w=l-b;p.push(`M${g(s)}`,`A${r},${r},${_},0,1,${g(b)}`,`A${r},${r},${w},0,1,${g(l)}`,`L${C(l)}`,`A${i},${i},${w},0,0,${C(b)}`,`A${i},${i},${_},0,0,${C(s)}`,"Z")}else{l=s+m*Math.PI*2,b=(l-s)/2+s;let _=l-s;p.push(`M${g(s)}`,`A${r},${r},${_},0,1,${g(l)}`,`L${C(l)}`,`A${i},${i},${_},0,0,${C(s)}`,"Z")}let x=M("path",{d:p,class:typeof f>"u"?void 0:`series-${f}`});typeof f<"u"&&x.setAttribute("data-index",f.toString());let v=M("g",{class:a});if(v.appendChild(x),this.group.appendChild(v),m>=.05&&u){let _=r-i;p=[];let w=d(t,i+(r-i)/2+_,b);p.push(`M${d(t,i+(r-i)/2,b)}`),p.push(`L${w}`),v.appendChild(M("path",{d:p,class:"callout"}));let A=[],S=M("text",{class:"callout-label"});v.appendChild(S);let I=b+Math.PI/2,L=u;S.textContent=L;let Z=S.getBoundingClientRect(),_e={width:Z.width,height:Z.height},[ne,T]=w;ne+=_e.height/2*Math.cos(b),T+=_e.height/4+_e.height/2*Math.sin(b);let te=!1;I>Math.PI?ne-_e.width<=n.left&&(te=!0):ne+_e.width>n.right&&(te=!0);let oe=/[\s-]/;if(te&&oe.test(L)){let Q=-1,q=1;for(let B=0;B<L.length;B++)if(oe.test(L[B])){let D=Math.abs(.5-B/L.length);D<q&&(q=D,Q=B)}Q>0&&(A.push(L.substr(0,Q+1).trim()),A.push(L.substr(Q+1).trim()))}if(A.length){let Q=0,q=0,B=A.map(D=>{S.textContent=D,Z=S.getBoundingClientRect();let Y={width:Z.width,height:Z.height};return q=Math.max(q,Y.width),{text:D,metrics:Y}});S.textContent="";for(let D of B){let Y=M("tspan");Y.textContent=D.text;let vn=I>Math.PI?ne-(q-D.metrics.width)/2:ne+(q-D.metrics.width)/2;Y.setAttribute("x",vn.toString()),Y.setAttribute("dy",Q.toString()),S.appendChild(Y),Q=D.metrics.height}}let k=I>Math.PI?"end":"start";S.setAttribute("text-anchor",k),S.setAttribute("x",ne.toString()),S.setAttribute("y",T.toString()),typeof f<"u"&&S.setAttribute("data-index",f.toString())}s=l}}};var sr=class{renderer=new ar;margin={top:.025,left:.05,bottom:.025,right:.075};Resize(e,t){this.renderer.Resize()}Initialize(e){this.renderer.Initialize(e)}Update(e,t){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(t.class_name);let r=new Me(0,0,this.renderer.size.width,this.renderer.size.height),i={top:Math.round(r.height)*this.margin.top,bottom:Math.round(r.height)*this.margin.bottom,left:Math.round(r.width)*this.margin.left,right:Math.round(r.width)*this.margin.right},n=t.title;if(n&&this.renderer.RenderTitle(n,r,i.top,t.title_layout||"top"),r.top+=i.top,r.left+=i.left,r.bottom-=i.bottom,r.right-=i.right,t.legend&&t.legend.length){let a=0;t.title&&(!t.title_layout||t.title_layout==="top")&&(a=1);let s=t.legend_position||a;this.renderer.Legend({labels:t.legend,position:s,style:t.legend_style,layout:s===0||s===1?0:1,area:r})}if(t.type==="histogram"||t.type==="line"||t.type==="area"||t.type==="column"||t.type==="histogram2"||t.type==="bar"||t.type==="scatter2"||t.type==="bubble"){let a=[],s=0;if(t.x_labels&&t.x_labels.length&&(a=t.x_labels.map(l=>{let d=this.renderer.MeasureText(l,["axis-label","x-axis-label"],!0);return s=Math.max(s,d.height),d})),t.y_labels&&t.y_labels.length){let l=[],d=0,h=0,u=t.type==="scatter2"||t.type==="bubble"?t.y_scale:t.scale,m=t.type==="bar"?t.y_labels.length:u.count+1;for(let f=0;f<m;f++){let p=this.renderer.MeasureText(t.y_labels[f],["axis-label","y-axis-label"]);l.push({label:t.y_labels[f],metrics:p}),d=Math.max(d,p.width),h=Math.max(h,p.height)}r.bottom=Math.round(r.bottom-h/2),r.top=Math.round(r.top+h/2),a.length&&(r.bottom-=s+i.bottom),t.type==="bar"?this.renderer.RenderYAxisBar(r,r.left+d,l,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(r,r.left+d,l,["axis-label","y-axis-label"]),r.left+=d+i.left}if(a.length&&t.x_labels&&t.x_labels.length){let l=t.type==="histogram2",d=t.type!=="line"&&t.type!=="area"&&t.type!=="bar"&&t.type!=="scatter2"&&t.type!=="bubble"&&t.type!=="histogram2";l&&this.renderer.RenderXAxisTicks(r,d,t.x_labels.length),t.y_labels&&(r.bottom+=s+i.bottom),this.renderer.RenderXAxis(r,d,t.x_labels,a,["axis-label","x-axis-label"]),r.bottom-=s+i.bottom}}let o=[];switch(t.type){case"scatter":this.renderer.RenderPoints(r,t.x,t.y,"mc mc-correlation series-1");break;case"bubble":t.x_scale.min<=0&&t.x_scale.max>=0&&(o[0]=Math.round(Math.abs(t.x_scale.min/t.x_scale.step))),t.y_scale.min<=0&&t.y_scale.max>=0&&(o[1]=Math.round(Math.abs(t.y_scale.max/t.y_scale.step))),this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid",o);for(let[a,s]of t.series.entries()){let l=typeof s.index=="number"?s.index:a+1;this.renderer.RenderBubbleSeries(r,s,t.x_scale,t.y_scale,`bubble-chart series-${l}`)}break;case"scatter2":if(this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid"),t.series){for(let a=0;a<t.series.length;a++){let s=t.series[a],l=!!t.lines,d=!!t.points;s.subtype==="plot"?(d=!0,l=!1):s.subtype==="line"&&(d=!1,l=!0);let h=typeof s.index=="number"?s.index:a+1;this.renderer.RenderScatterSeries(r,s.x.data,s.y.data,t.x_scale,t.y_scale,l,d,!!t.filled,!!t.markers,!!t.smooth,`scatter-plot series-${h}`)}if(t.data_labels)for(let a=0;a<t.series.length;a++){let s=t.series[a];s.y.labels&&this.renderer.RenderDataLabels(r,s.x.data,s.y.data,t.x_scale,t.y_scale,s.y.labels,a+1)}}break;case"pie":case"donut":{let a=Math.min(r.height,r.width)/2*.9,s=t.type==="pie"?0:a*.8;this.renderer.RenderDonut(t.slices,r.center,a,s,r,!0,"donut")}break;case"line":case"area":{let a=t.scale;if(t.series){let s=t.x_scale?t.x_scale.max:Math.max.apply(0,t.series.map(h=>h.length)),l=t.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(r,t.scale.count,t.x_scale?t.x_scale.count+1:s,"chart-grid");let d=0;for(let h of t.series){let u=h.map(f=>{if(!(typeof f>"u"))return $.ApplyScale(f,r.height,a)});if(u.length<s)for(let f=u.length;f<s;f++)u.push(void 0);let m=[t.type==="area"?"chart-area":"chart-line",`series-${d+1}`];l.call(this.renderer,r,u,t.type==="area",t.titles,m),d++}}}break;case"bar":{let a;if(this.renderer.RenderBarGrid(r,t.scale.count,"chart-grid"),t.series2){let s=0,l=t.series2.length;for(let p of t.series2)s=Math.max(s,p.y.data.length);let d=r.height/s,h=.7;typeof t.space=="number"&&(h=Math.max(0,Math.min(1,1-t.space)));let u=d*(1-h)/2,m=(d-u*2)/l,f=0;if(t.scale.min<0&&(f=$.ApplyScale(0,r.width,t.scale)),t.round){let p=Math.floor(m/2);a=[0,p,p,0]}for(let p=0;p<l;p++){let b=t.series2[p],g=typeof b.index=="number"?b.index:p+1;for(let C=0;C<b.y.data.length;C++){let x=b.y.data[C];if(typeof x=="number"){let v=Math.round(r.top+C*d+u)+p*m,_=0,w=0;f?x>0?(w=$.ApplyScale(x+t.scale.min,r.width,t.scale),_=r.left+f):(w=$.ApplyScale(t.scale.min-x,r.width,t.scale),_=r.left+f-w):(w=$.ApplyScale(x,r.width,t.scale),_=r.left),w&&this.renderer.RenderRectangle(new Me(_,v,_+w,v+m),a,["chart-column",`series-${g}`],void 0||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid"),t.series2){let a=0,s=t.series2.length;for(let p of t.series2)a=Math.max(a,p.y.data.length);let l=r.width/a,d=.7;typeof t.space=="number"&&(d=Math.max(0,Math.min(1,1-t.space)));let h=l*(1-d)/2,u=(l-h*2)/s,m=0;if(t.scale.min<0&&(m=$.ApplyScale(0,r.height,t.scale)),t.callouts&&t.x_scale){let p=t.x_scale,b=t.callouts.map((g,C)=>{let x=Math.round(r.left+$.ApplyScale(g.value,r.width,p))+.5;return{x1:x,y1:r.bottom-r.height,x2:x,y2:r.bottom,classes:`callout-${C+1}`}});this.renderer.RenderCalloutLines(b)}let f;if(t.round){let p=Math.floor(u/2);f=[p,p,0,0]}for(let p=0;p<s;p++){let b=t.series2[p],g=typeof b.index=="number"?b.index:p+1;for(let C=0;C<b.y.data.length;C++){let x=b.y.data[C];if(typeof x=="number"){let v=r.left+C*l+h+p*u,_=0,w=0;m?x>0?(_=$.ApplyScale(x+t.scale.min,r.height,t.scale),w=r.bottom-_-m):(_=$.ApplyScale(t.scale.min-x,r.height,t.scale),w=r.bottom-m):(_=$.ApplyScale(x,r.height,t.scale),w=r.bottom-_);let A=void 0;if(_){let S=t.data_labels&&b.y.labels?b.y.labels[C]:"",I={x:Math.round(v+u/2),y:Math.round(w-10)};this.renderer.RenderRectangle(new Me(v,w,v+u,w+_),f,["chart-column",`series-${g}`],A||void 0,S,I)}}}}}break;case"histogram":{this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid");let a=r.width/t.count,s=t.column_width,l=a*(1-s)/2;for(let d=0;d<t.count;d++){let h=Math.round(r.left+d*a+l),u=a-l*2,m=$.ApplyScale(t.bins[d],r.height,t.scale),f=r.bottom-m,p=t.titles?t.titles[d]:void 0;this.renderer.RenderRectangle(new Me(h,f,h+u,f+m),void 0,"chart-column series-1",p||void 0)}}break}}};var Ge=class{constructor(e=new sr){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};node;Initialize(e){this.node=e,this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.chart_data=qr(r,"column");break;case"bar.chart":this.chart_data=qr(r,"bar");break;case"line.chart":this.chart_data=Kr(r,"line");break;case"area.chart":this.chart_data=Kr(r,"area");break;case"donut.chart":case"pie.chart":this.chart_data=pn(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.chart_data=Qr(r,"plot");break;case"scatter.line":this.chart_data=Qr(r,"line");break;case"bubble.chart":this.chart_data=fn(r);break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}Resize(){this.node&&this.renderer.Resize(this.node,this.chart_data)}Update(){this.node&&this.renderer.Update(this.node,this.chart_data)}};var Ie=(...c)=>({type:5,value:c,key:"arguments"}),ei={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:"Z",metadata:!0},{name:"index"},{name:"subtype"},{name:"Labels",description:"Labels for bubble charts only (atm)"}],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},"Bubble.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"}],fn:Ie}};var ti={};wn(ti,{default:()=>ri});var ri='var Zn=Object.create;var or=Object.defineProperty;var Fn=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,En=Object.prototype.hasOwnProperty;var re=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Rn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Mn(e))!En.call(n,i)&&i!==t&&or(n,i,{get:()=>e[i],enumerable:!(r=Fn(e,i))||r.enumerable});return n};var ve=(n,e,t)=>(t=n!=null?Zn(kn(n)):{},Rn(e||!n||!n.__esModule?or(t,"default",{value:n,enumerable:!0}):t,n));var nt=re(rt=>{"use strict";rt.byteLength=Wn;rt.toByteArray=zn;rt.fromByteArray=Ln;var me=[],ce=[],$n=typeof Uint8Array<"u"?Uint8Array:Array,Tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ie=0,lr=Tt.length;Ie<lr;++Ie)me[Ie]=Tt[Ie],ce[Tt.charCodeAt(Ie)]=Ie;var Ie,lr;ce[45]=62;ce[95]=63;function cr(n){var e=n.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=n.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function Wn(n){var e=cr(n),t=e[0],r=e[1];return(t+r)*3/4-r}function Gn(n,e,t){return(e+t)*3/4-t}function zn(n){var e,t=cr(n),r=t[0],i=t[1],s=new $n(Gn(n,r,i)),o=0,a=i>0?r-4:r,l;for(l=0;l<a;l+=4)e=ce[n.charCodeAt(l)]<<18|ce[n.charCodeAt(l+1)]<<12|ce[n.charCodeAt(l+2)]<<6|ce[n.charCodeAt(l+3)],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=e&255;return i===2&&(e=ce[n.charCodeAt(l)]<<2|ce[n.charCodeAt(l+1)]>>4,s[o++]=e&255),i===1&&(e=ce[n.charCodeAt(l)]<<10|ce[n.charCodeAt(l+1)]<<4|ce[n.charCodeAt(l+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function Bn(n){return me[n>>18&63]+me[n>>12&63]+me[n>>6&63]+me[n&63]}function Un(n,e,t){for(var r,i=[],s=e;s<t;s+=3)r=(n[s]<<16&16711680)+(n[s+1]<<8&65280)+(n[s+2]&255),i.push(Bn(r));return i.join("")}function Ln(n){for(var e,t=n.length,r=t%3,i=[],s=16383,o=0,a=t-r;o<a;o+=s)i.push(Un(n,o,o+s>a?a:o+s));return r===1?(e=n[t-1],i.push(me[e>>2]+me[e<<4&63]+"==")):r===2&&(e=(n[t-2]<<8)+n[t-1],i.push(me[e>>10]+me[e>>4&63]+me[e<<2&63]+"=")),i.join("")}});var ot=re(pe=>{"use strict";var ur=":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",Qn=ur+"\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040",fr="["+ur+"]["+Qn+"]*",qn=new RegExp("^"+fr+"$"),Kn=function(n,e){let t=[],r=e.exec(n);for(;r;){let i=[];i.startIndex=e.lastIndex-r[0].length;let s=r.length;for(let o=0;o<s;o++)i.push(r[o]);t.push(i),r=e.exec(n)}return t},ei=function(n){let e=qn.exec(n);return!(e===null||typeof e>"u")};pe.isExist=function(n){return typeof n<"u"};pe.isEmptyObject=function(n){return Object.keys(n).length===0};pe.merge=function(n,e,t){if(e){let r=Object.keys(e),i=r.length;for(let s=0;s<i;s++)t==="strict"?n[r[s]]=[e[r[s]]]:n[r[s]]=e[r[s]]}};pe.getValue=function(n){return pe.isExist(n)?n:""};pe.isName=ei;pe.getAllMatches=Kn;pe.nameRegexp=fr});var kt=re(yr=>{"use strict";var Mt=ot(),ti={allowBooleanAttributes:!1,unpairedTags:[]};yr.validate=function(n,e){e=Object.assign({},ti,e);let t=[],r=!1,i=!1;n[0]==="\\uFEFF"&&(n=n.substr(1));for(let s=0;s<n.length;s++)if(n[s]==="<"&&n[s+1]==="?"){if(s+=2,s=pr(n,s),s.err)return s}else if(n[s]==="<"){let o=s;if(s++,n[s]==="!"){s=br(n,s);continue}else{let a=!1;n[s]==="/"&&(a=!0,s++);let l="";for(;s<n.length&&n[s]!==">"&&n[s]!==" "&&n[s]!==" "&&n[s]!==`\n`&&n[s]!=="\\r";s++)l+=n[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!ci(l)){let h;return l.trim().length===0?h="Invalid space after \'<\'.":h="Tag \'"+l+"\' is an invalid name.",H("InvalidTag",h,ie(n,s))}let d=ii(n,s);if(d===!1)return H("InvalidAttr","Attributes for \'"+l+"\' have open quote.",ie(n,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 m=gr(c,e);if(m===!0)r=!0;else return H(m.err.code,m.err.msg,ie(n,h+m.err.line))}else if(a)if(d.tagClosed){if(c.trim().length>0)return H("InvalidTag","Closing tag \'"+l+"\' can\'t have attributes or invalid starting.",ie(n,o));{let h=t.pop();if(l!==h.tagName){let m=ie(n,h.tagStartPos);return H("InvalidTag","Expected closing tag \'"+h.tagName+"\' (opened in line "+m.line+", col "+m.col+") instead of closing tag \'"+l+"\'.",ie(n,o))}t.length==0&&(i=!0)}}else return H("InvalidTag","Closing tag \'"+l+"\' doesn\'t have proper closing.",ie(n,s));else{let h=gr(c,e);if(h!==!0)return H(h.err.code,h.err.msg,ie(n,s-c.length+h.err.line));if(i===!0)return H("InvalidXml","Multiple possible root nodes found.",ie(n,s));e.unpairedTags.indexOf(l)!==-1||t.push({tagName:l,tagStartPos:o}),r=!0}for(s++;s<n.length;s++)if(n[s]==="<")if(n[s+1]==="!"){s++,s=br(n,s);continue}else if(n[s+1]==="?"){if(s=pr(n,++s),s.err)return s}else break;else if(n[s]==="&"){let h=oi(n,s);if(h==-1)return H("InvalidChar","char \'&\' is not expected.",ie(n,s));s=h}else if(i===!0&&!mr(n[s]))return H("InvalidXml","Extra text at the end",ie(n,s));n[s]==="<"&&s--}}else{if(mr(n[s]))continue;return H("InvalidChar","char \'"+n[s]+"\' is not expected.",ie(n,s))}if(r){if(t.length==1)return H("InvalidTag","Unclosed tag \'"+t[0].tagName+"\'.",ie(n,t[0].tagStartPos));if(t.length>0)return H("InvalidXml","Invalid \'"+JSON.stringify(t.map(s=>s.tagName),null,4).replace(/\\r?\\n/g,"")+"\' found.",{line:1,col:1})}else return H("InvalidXml","Start tag expected.",1);return!0};function mr(n){return n===" "||n===" "||n===`\n`||n==="\\r"}function pr(n,e){let t=e;for(;e<n.length;e++)if(n[e]=="?"||n[e]==" "){let r=n.substr(t,e-t);if(e>5&&r==="xml")return H("InvalidXml","XML declaration allowed only at the start of the document.",ie(n,e));if(n[e]=="?"&&n[e+1]==">"){e++;break}else continue}return e}function br(n,e){if(n.length>e+5&&n[e+1]==="-"&&n[e+2]==="-"){for(e+=3;e<n.length;e++)if(n[e]==="-"&&n[e+1]==="-"&&n[e+2]===">"){e+=2;break}}else if(n.length>e+8&&n[e+1]==="D"&&n[e+2]==="O"&&n[e+3]==="C"&&n[e+4]==="T"&&n[e+5]==="Y"&&n[e+6]==="P"&&n[e+7]==="E"){let t=1;for(e+=8;e<n.length;e++)if(n[e]==="<")t++;else if(n[e]===">"&&(t--,t===0))break}else if(n.length>e+9&&n[e+1]==="["&&n[e+2]==="C"&&n[e+3]==="D"&&n[e+4]==="A"&&n[e+5]==="T"&&n[e+6]==="A"&&n[e+7]==="["){for(e+=8;e<n.length;e++)if(n[e]==="]"&&n[e+1]==="]"&&n[e+2]===">"){e+=2;break}}return e}var ri=\'"\',ni="\'";function ii(n,e){let t="",r="",i=!1;for(;e<n.length;e++){if(n[e]===ri||n[e]===ni)r===""?r=n[e]:r!==n[e]||(r="");else if(n[e]===">"&&r===""){i=!0;break}t+=n[e]}return r!==""?!1:{value:t,index:e,tagClosed:i}}var si=new RegExp(`(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*([\'"])(([\\\\s\\\\S])*?)\\\\5)?`,"g");function gr(n,e){let t=Mt.getAllMatches(n,si),r={};for(let i=0;i<t.length;i++){if(t[i][1].length===0)return H("InvalidAttr","Attribute \'"+t[i][2]+"\' has no space in starting.",Ue(t[i]));if(t[i][3]!==void 0&&t[i][4]===void 0)return H("InvalidAttr","Attribute \'"+t[i][2]+"\' is without value.",Ue(t[i]));if(t[i][3]===void 0&&!e.allowBooleanAttributes)return H("InvalidAttr","boolean attribute \'"+t[i][2]+"\' is not allowed.",Ue(t[i]));let s=t[i][2];if(!li(s))return H("InvalidAttr","Attribute \'"+s+"\' is an invalid name.",Ue(t[i]));if(!r.hasOwnProperty(s))r[s]=1;else return H("InvalidAttr","Attribute \'"+s+"\' is repeated.",Ue(t[i]))}return!0}function ai(n,e){let t=/\\d/;for(n[e]==="x"&&(e++,t=/[\\da-fA-F]/);e<n.length;e++){if(n[e]===";")return e;if(!n[e].match(t))break}return-1}function oi(n,e){if(e++,n[e]===";")return-1;if(n[e]==="#")return e++,ai(n,e);let t=0;for(;e<n.length;e++,t++)if(!(n[e].match(/\\w/)&&t<20)){if(n[e]===";")break;return-1}return e}function H(n,e,t){return{err:{code:n,msg:e,line:t.line||t,col:t.col}}}function li(n){return Mt.isName(n)}function ci(n){return Mt.isName(n)}function ie(n,e){let t=n.substring(0,e).split(/\\r?\\n/);return{line:t.length,col:t[t.length-1].length+1}}function Ue(n){return n.startIndex+n[1].length}});var _r=re(Et=>{var xr={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(n,e){return e},attributeValueProcessor:function(n,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(n,e,t){return n}},di=function(n){return Object.assign({},xr,n)};Et.buildOptions=di;Et.defaultOptions=xr});var Ar=re((io,wr)=>{"use strict";var Rt=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})}};wr.exports=Rt});var vr=re((so,Cr)=>{var hi=ot();function ui(n,e){let t={};if(n[e+3]==="O"&&n[e+4]==="C"&&n[e+5]==="T"&&n[e+6]==="Y"&&n[e+7]==="P"&&n[e+8]==="E"){e=e+9;let r=1,i=!1,s=!1,o="";for(;e<n.length;e++)if(n[e]==="<"&&!s){if(i&&pi(n,e))e+=7,[entityName,val,e]=fi(n,e+1),val.indexOf("&")===-1&&(t[xi(entityName)]={regx:RegExp(`&${entityName};`,"g"),val});else if(i&&bi(n,e))e+=8;else if(i&&gi(n,e))e+=8;else if(i&&yi(n,e))e+=9;else if(mi)s=!0;else throw new Error("Invalid DOCTYPE");r++,o=""}else if(n[e]===">"){if(s?n[e-1]==="-"&&n[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else n[e]==="["?i=!0:o+=n[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:t,i:e}}function fi(n,e){let t="";for(;e<n.length&&n[e]!=="\'"&&n[e]!==\'"\';e++)t+=n[e];if(t=t.trim(),t.indexOf(" ")!==-1)throw new Error("External entites are not supported");let r=n[e++],i="";for(;e<n.length&&n[e]!==r;e++)i+=n[e];return[t,i,e]}function mi(n,e){return n[e+1]==="!"&&n[e+2]==="-"&&n[e+3]==="-"}function pi(n,e){return n[e+1]==="!"&&n[e+2]==="E"&&n[e+3]==="N"&&n[e+4]==="T"&&n[e+5]==="I"&&n[e+6]==="T"&&n[e+7]==="Y"}function bi(n,e){return n[e+1]==="!"&&n[e+2]==="E"&&n[e+3]==="L"&&n[e+4]==="E"&&n[e+5]==="M"&&n[e+6]==="E"&&n[e+7]==="N"&&n[e+8]==="T"}function gi(n,e){return n[e+1]==="!"&&n[e+2]==="A"&&n[e+3]==="T"&&n[e+4]==="T"&&n[e+5]==="L"&&n[e+6]==="I"&&n[e+7]==="S"&&n[e+8]==="T"}function yi(n,e){return n[e+1]==="!"&&n[e+2]==="N"&&n[e+3]==="O"&&n[e+4]==="T"&&n[e+5]==="A"&&n[e+6]==="T"&&n[e+7]==="I"&&n[e+8]==="O"&&n[e+9]==="N"}function xi(n){if(hi.isName(n))return n;throw new Error(`Invalid entity name ${n}`)}Cr.exports=ui});var Nr=re((ao,Ir)=>{var _i=/^[-+]?0x[a-fA-F0-9]+$/,wi=/^([\\-\\+])?(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 Ai={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function Ci(n,e={}){if(e=Object.assign({},Ai,e),!n||typeof n!="string")return n;let t=n.trim();if(e.skipLike!==void 0&&e.skipLike.test(t))return n;if(e.hex&&_i.test(t))return Number.parseInt(t,16);{let r=wi.exec(t);if(r){let i=r[1],s=r[2],o=vi(r[3]),a=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&i&&t[2]!==".")return n;if(!e.leadingZeros&&s.length>0&&!i&&t[1]!==".")return n;{let l=Number(t),d=""+l;return d.search(/[eE]/)!==-1||a?e.eNotation?l:n:t.indexOf(".")!==-1?d==="0"&&o===""||d===o||i&&d==="-"+o?l:n:s?o===d||i+o===d?l:n:t===d||t===i+d?l:n}}else return n}}function vi(n){return n&&n.indexOf(".")!==-1&&(n=n.replace(/0+$/,""),n==="."?n="0":n[0]==="."?n="0"+n:n[n.length-1]==="."&&(n=n.substr(0,n.length-1))),n}Ir.exports=Ci});var Pr=re((oo,Tr)=>{"use strict";var Sr=ot(),Le=Ar(),Ii=vr(),Ni=Nr(),$t=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=Si,this.parseXml=Mi,this.parseTextData=Ti,this.resolveNameSpace=Pi,this.buildAttributesMap=Fi,this.isItStopNode=$i,this.replaceEntitiesValue=Ei,this.readStopNodeData=Gi,this.saveTextToParentTag=Ri,this.addChild=ki}};function Si(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:n[r]}}}function Ti(n,e,t,r,i,s,o){if(n!==void 0&&(this.options.trimValues&&!r&&(n=n.trim()),n.length>0)){o||(n=this.replaceEntitiesValue(n));let a=this.options.tagValueProcessor(e,n,t,i,s);return a==null?n:typeof a!=typeof n||a!==n?a:this.options.trimValues?Gt(n,this.options.parseTagValue,this.options.numberParseOptions):n.trim()===n?Gt(n,this.options.parseTagValue,this.options.numberParseOptions):n}}function Pi(n){if(this.options.removeNSPrefix){let e=n.split(":"),t=n.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(n=t+e[1])}return n}var Zi=new RegExp(`([^\\\\s=]+)\\\\s*(=\\\\s*([\'"])([\\\\s\\\\S]*?)\\\\3)?`,"gm");function Fi(n,e,t){if(!this.options.ignoreAttributes&&typeof n=="string"){let r=Sr.getAllMatches(n,Zi),i=r.length,s={};for(let o=0;o<i;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]=Gt(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 Mi=function(n){n=n.replace(/\\r\\n?/g,`\n`);let e=new Le("!xml"),t=e,r="",i="";for(let s=0;s<n.length;s++)if(n[s]==="<")if(n[s+1]==="/"){let a=Ze(n,">",s,"Closing Tag is not closed."),l=n.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,i));let d=i.substring(i.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=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):c=i.lastIndexOf("."),i=i.substring(0,c),t=this.tagsNodeStack.pop(),r="",s=a}else if(n[s+1]==="?"){let a=Wt(n,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,t,i),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){let l=new Le(a.tagName);l.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(l[":@"]=this.buildAttributesMap(a.tagExp,i,a.tagName)),this.addChild(t,l,i)}s=a.closeIndex+1}else if(n.substr(s+1,3)==="!--"){let a=Ze(n,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){let l=n.substring(s+4,a-2);r=this.saveTextToParentTag(r,t,i),t.add(this.options.commentPropName,[{[this.options.textNodeName]:l}])}s=a}else if(n.substr(s+1,2)==="!D"){let a=Ii(n,s);this.docTypeEntities=a.entities,s=a.i}else if(n.substr(s+1,2)==="!["){let a=Ze(n,"]]>",s,"CDATA is not closed.")-2,l=n.substring(s+9,a);r=this.saveTextToParentTag(r,t,i);let d=this.parseTextData(l,t.tagname,i,!0,!1,!0,!0);d==null&&(d=""),this.options.cdataPropName?t.add(this.options.cdataPropName,[{[this.options.textNodeName]:l}]):t.add(this.options.textNodeName,d),s=a+2}else{let a=Wt(n,s,this.options.removeNSPrefix),l=a.tagName,d=a.rawTagName,c=a.tagExp,h=a.attrExpPresent,m=a.closeIndex;this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&r&&t.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,t,i,!1));let u=t;if(u&&this.options.unpairedTags.indexOf(u.tagname)!==-1&&(t=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),l!==e.tagname&&(i+=i?"."+l:l),this.isItStopNode(this.options.stopNodes,i,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 w=this.readStopNodeData(n,d,m+1);if(!w)throw new Error(`Unexpected end of ${d}`);s=w.i,f=w.tagContent}let g=new Le(l);l!==c&&h&&(g[":@"]=this.buildAttributesMap(c,i,l)),f&&(f=this.parseTextData(f,l,i,!0,h,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),g.add(this.options.textNodeName,f),this.addChild(t,g,i)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){l[l.length-1]==="/"?(l=l.substr(0,l.length-1),i=i.substr(0,i.length-1),c=l):c=c.substr(0,c.length-1),this.options.transformTagName&&(l=this.options.transformTagName(l));let f=new Le(l);l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,i,l)),this.addChild(t,f,i),i=i.substr(0,i.lastIndexOf("."))}else{let f=new Le(l);this.tagsNodeStack.push(t),l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,i,l)),this.addChild(t,f,i),t=f}r="",s=m}}else r+=n[s];return e.child};function ki(n,e,t){let r=this.options.updateTag(e.tagname,t,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),n.addChild(e))}var Ei=function(n){if(this.options.processEntities){for(let e in this.docTypeEntities){let t=this.docTypeEntities[e];n=n.replace(t.regx,t.val)}for(let e in this.lastEntities){let t=this.lastEntities[e];n=n.replace(t.regex,t.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){let t=this.htmlEntities[e];n=n.replace(t.regex,t.val)}n=n.replace(this.ampEntity.regex,this.ampEntity.val)}return n};function Ri(n,e,t,r){return n&&(r===void 0&&(r=Object.keys(e.child).length===0),n=this.parseTextData(n,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),n!==void 0&&n!==""&&e.add(this.options.textNodeName,n),n=""),n}function $i(n,e,t){let r="*."+t;for(let i in n){let s=n[i];if(r===s||e===s)return!0}return!1}function Wi(n,e,t=">"){let r,i="";for(let s=e;s<n.length;s++){let o=n[s];if(r)o===r&&(r="");else if(o===\'"\'||o==="\'")r=o;else if(o===t[0])if(t[1]){if(n[s+1]===t[1])return{data:i,index:s}}else return{data:i,index:s};else o===" "&&(o=" ");i+=o}}function Ze(n,e,t,r){let i=n.indexOf(e,t);if(i===-1)throw new Error(r);return i+e.length-1}function Wt(n,e,t,r=">"){let i=Wi(n,e+1,r);if(!i)return;let s=i.data,o=i.index,a=s.search(/\\s/),l=s,d=!0;a!==-1&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());let c=l;if(t){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1),d=l!==i.data.substr(h+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:d,rawTagName:c}}function Gi(n,e,t){let r=t,i=1;for(;t<n.length;t++)if(n[t]==="<")if(n[t+1]==="/"){let s=Ze(n,">",t,`${e} is not closed`);if(n.substring(t+2,s).trim()===e&&(i--,i===0))return{tagContent:n.substring(r,t),i:s};t=s}else if(n[t+1]==="?")t=Ze(n,"?>",t+1,"StopNode is not closed.");else if(n.substr(t+1,3)==="!--")t=Ze(n,"-->",t+3,"StopNode is not closed.");else if(n.substr(t+1,2)==="![")t=Ze(n,"]]>",t,"StopNode is not closed.")-2;else{let s=Wt(n,t,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,t=s.closeIndex)}}function Gt(n,e,t){if(e&&typeof n=="string"){let r=n.trim();return r==="true"?!0:r==="false"?!1:Ni(n,t)}else return Sr.isExist(n)?n:""}Tr.exports=$t});var Mr=re(Fr=>{"use strict";function zi(n,e){return Zr(n,e)}function Zr(n,e,t){let r,i={};for(let s=0;s<n.length;s++){let o=n[s],a=Bi(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=Zr(o[a],e,l),c=Li(d,e);o[":@"]?Ui(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=""),i[a]!==void 0&&i.hasOwnProperty(a)?(Array.isArray(i[a])||(i[a]=[i[a]]),i[a].push(d)):e.isArray(a,l,c)?i[a]=[d]:i[a]=d}}}return typeof r=="string"?r.length>0&&(i[e.textNodeName]=r):r!==void 0&&(i[e.textNodeName]=r),i}function Bi(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];if(r!==":@")return r}}function Ui(n,e,t,r){if(e){let i=Object.keys(e),s=i.length;for(let o=0;o<s;o++){let a=i[o];r.isArray(a,t+"."+a,!0,!0)?n[a]=[e[a]]:n[a]=e[a]}}}function Li(n,e){let{textNodeName:t}=e,r=Object.keys(n).length;return!!(r===0||r===1&&(n[t]||typeof n[t]=="boolean"||n[t]===0))}Fr.prettify=zi});var Er=re((co,kr)=>{var{buildOptions:Vi}=_r(),Yi=Pr(),{prettify:Oi}=Mr(),ji=kt(),zt=class{constructor(e){this.externalEntities={},this.options=Vi(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=ji.validate(e,t);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}let r=new Yi(this.options);r.addExternalEntities(this.externalEntities);let i=r.parseXml(e);return this.options.preserveOrder||i===void 0?i:Oi(i,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 \'&#xD;\'");if(t==="&")throw new Error("An entity with value \'&\' is not permitted");this.externalEntities[e]=t}};kr.exports=zt});var zr=re((ho,Gr)=>{var Di=`\n`;function Hi(n,e){let t="";return e.format&&e.indentBy.length>0&&(t=Di),$r(n,e,"",t)}function $r(n,e,t,r){let i="",s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=Ji(a);if(l===void 0)continue;let d="";if(t.length===0?d=l:d=`${t}.${l}`,l===e.textNodeName){let f=a[l];Xi(d,e)||(f=e.tagValueProcessor(l,f),f=Wr(f,e)),s&&(i+=r),i+=f,s=!1;continue}else if(l===e.cdataPropName){s&&(i+=r),i+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,s=!1;continue}else if(l===e.commentPropName){i+=r+`<!--${a[l][0][e.textNodeName]}-->`,s=!0;continue}else if(l[0]==="?"){let f=Rr(a[":@"],e),g=l==="?xml"?"":r,w=a[l][0][e.textNodeName];w=w.length!==0?" "+w:"",i+=g+`<${l}${w}${f}?>`,s=!0;continue}let c=r;c!==""&&(c+=e.indentBy);let h=Rr(a[":@"],e),m=r+`<${l}${h}`,u=$r(a[l],e,d,c);e.unpairedTags.indexOf(l)!==-1?e.suppressUnpairedNode?i+=m+">":i+=m+"/>":(!u||u.length===0)&&e.suppressEmptyNode?i+=m+"/>":u&&u.endsWith(">")?i+=m+`>${u}${r}</${l}>`:(i+=m+">",u&&r!==""&&(u.includes("/>")||u.includes("</"))?i+=r+e.indentBy+u+r:i+=u,i+=`</${l}>`),s=!0}return i}function Ji(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];if(n.hasOwnProperty(r)&&r!==":@")return r}}function Rr(n,e){let t="";if(n&&!e.ignoreAttributes)for(let r in n){if(!n.hasOwnProperty(r))continue;let i=e.attributeValueProcessor(r,n[r]);i=Wr(i,e),i===!0&&e.suppressBooleanAttributes?t+=` ${r.substr(e.attributeNamePrefix.length)}`:t+=` ${r.substr(e.attributeNamePrefix.length)}="${i}"`}return t}function Xi(n,e){n=n.substr(0,n.length-e.textNodeName.length-1);let t=n.substr(n.lastIndexOf(".")+1);for(let r in e.stopNodes)if(e.stopNodes[r]===n||e.stopNodes[r]==="*."+t)return!0;return!1}function Wr(n,e){if(n&&n.length>0&&e.processEntities)for(let t=0;t<e.entities.length;t++){let r=e.entities[t];n=n.replace(r.regex,r.val)}return n}Gr.exports=Hi});var Ur=re((uo,Br)=>{"use strict";var Qi=zr(),qi={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(n,e){return e},attributeValueProcessor:function(n,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("\'","g"),val:"&apos;"},{regex:new RegExp(\'"\',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function _e(n){this.options=Object.assign({},qi,n),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ts),this.processTextOrObjNode=Ki,this.options.format?(this.indentate=es,this.tagEndChar=`>\n`,this.newLine=`\n`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}_e.prototype.build=function(n){return this.options.preserveOrder?Qi(n,this.options):(Array.isArray(n)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(n={[this.options.arrayNodeName]:n}),this.j2x(n,0).val)};_e.prototype.j2x=function(n,e){let t="",r="";for(let i in n)if(Object.prototype.hasOwnProperty.call(n,i))if(typeof n[i]>"u")this.isAttribute(i)&&(r+="");else if(n[i]===null)this.isAttribute(i)?r+="":i[0]==="?"?r+=this.indentate(e)+"<"+i+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+i+"/"+this.tagEndChar;else if(n[i]instanceof Date)r+=this.buildTextValNode(n[i],i,"",e);else if(typeof n[i]!="object"){let s=this.isAttribute(i);if(s)t+=this.buildAttrPairStr(s,""+n[i]);else if(i===this.options.textNodeName){let o=this.options.tagValueProcessor(i,""+n[i]);r+=this.replaceEntitiesValue(o)}else r+=this.buildTextValNode(n[i],i,"",e)}else if(Array.isArray(n[i])){let s=n[i].length,o="";for(let a=0;a<s;a++){let l=n[i][a];typeof l>"u"||(l===null?i[0]==="?"?r+=this.indentate(e)+"<"+i+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+i+"/"+this.tagEndChar:typeof l=="object"?this.options.oneListGroup?o+=this.j2x(l,e+1).val:o+=this.processTextOrObjNode(l,i,e):o+=this.buildTextValNode(l,i,"",e))}this.options.oneListGroup&&(o=this.buildObjectNode(o,i,"",e)),r+=o}else if(this.options.attributesGroupName&&i===this.options.attributesGroupName){let s=Object.keys(n[i]),o=s.length;for(let a=0;a<o;a++)t+=this.buildAttrPairStr(s[a],""+n[i][s[a]])}else r+=this.processTextOrObjNode(n[i],i,e);return{attrStr:t,val:r}};_e.prototype.buildAttrPairStr=function(n,e){return e=this.options.attributeValueProcessor(n,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+n:" "+n+\'="\'+e+\'"\'};function Ki(n,e,t){let r=this.j2x(n,t+1);return n[this.options.textNodeName]!==void 0&&Object.keys(n).length===1?this.buildTextValNode(n[this.options.textNodeName],e,r.attrStr,t):this.buildObjectNode(r.val,e,r.attrStr,t)}_e.prototype.buildObjectNode=function(n,e,t,r){if(n==="")return e[0]==="?"?this.indentate(r)+"<"+e+t+"?"+this.tagEndChar:this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar;{let i="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",i=""),(t||t==="")&&n.indexOf("<")===-1?this.indentate(r)+"<"+e+t+s+">"+n+i:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${n}-->`+this.newLine:this.indentate(r)+"<"+e+t+s+this.tagEndChar+n+this.indentate(r)+i}};_e.prototype.closeTag=function(n){let e="";return this.options.unpairedTags.indexOf(n)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${n}`,e};_e.prototype.buildTextValNode=function(n,e,t,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${n}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${n}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+t+"?"+this.tagEndChar;{let i=this.options.tagValueProcessor(e,n);return i=this.replaceEntitiesValue(i),i===""?this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+t+">"+i+"</"+e+this.tagEndChar}};_e.prototype.replaceEntitiesValue=function(n){if(n&&n.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){let t=this.options.entities[e];n=n.replace(t.regex,t.val)}return n};function es(n){return this.options.indentBy.repeat(n)}function ts(n){return n.startsWith(this.options.attributeNamePrefix)&&n!==this.options.textNodeName?n.substr(this.attrPrefixLen):!1}Br.exports=_e});var lt=re((fo,Lr)=>{"use strict";var rs=kt(),ns=Er(),is=Ur();Lr.exports={XMLParser:ns,XMLValidator:rs,XMLBuilder:is}});var An=re((Zl,nr)=>{var p={};typeof nr=="object"&&(nr.exports=p);p.parse=function(n,e){for(var t=p.bin.readUshort,r=p.bin.readUint,a=0,i={},s=new Uint8Array(n),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 m=0;m<l;m++){var u=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 w=t(s,a),A=t(s,a+2),_=t(s,a+4);a+=6,a+=8;var b=r(s,a);a+=4,a+=w+A+_,p._readLocal(s,b,i,c,g,e)}return i};p._readLocal=function(n,e,t,r,i,s){var o=p.bin.readUshort,a=p.bin.readUint,l=a(n,e);e+=4;var d=o(n,e);e+=2;var c=o(n,e);e+=2;var h=o(n,e);e+=2;var m=a(n,e);e+=4;var u=a(n,e);e+=4,e+=8;var f=o(n,e);e+=2;var g=o(n,e);e+=2;var w=p.bin.readUTF8(n,e,f);if(e+=f,e+=g,s){t[w]={size:i,csize:r};return}var A=new Uint8Array(n.buffer,e);if(h==0)t[w]=new Uint8Array(A.buffer.slice(e,e+r));else if(h==8){var _=new Uint8Array(i);p.inflateRaw(A,_),t[w]=_}else throw"unknown compression method: "+h};p.inflateRaw=function(n,e){return p.F.inflate(n,e)};p.inflate=function(n,e){var t=n[0],r=n[1],i=t&15,s=t>>>4;return p.inflateRaw(new Uint8Array(n.buffer,n.byteOffset+2,n.length-6),e)};p.deflate=function(n,e){e==null&&(e={level:6});var t=0,r=new Uint8Array(50+Math.floor(n.length*1.1));r[t]=120,r[t+1]=156,t+=2,t=p.F.deflateRaw(n,r,t,e.level);var i=p.adler(n,0,n.length);return r[t+0]=i>>>24&255,r[t+1]=i>>>16&255,r[t+2]=i>>>8&255,r[t+3]=i>>>0&255,new Uint8Array(r.buffer,0,t+4)};p.deflateRaw=function(n,e){e==null&&(e={level:6});var t=new Uint8Array(50+Math.floor(n.length*1.1)),r=p.F.deflateRaw(n,t,r,e.level);return new Uint8Array(t.buffer,0,r)};p.encode=function(n,e){e==null&&(e=!1);var t=0,r=p.bin.writeUint,i=p.bin.writeUshort,s={};for(var o in n){var a=!p._noNeed(o)&&!e,l=n[o],d=p.crc.crc(l,0,l.length);s[o]={cpr:a,usize:l.length,crc:d,file:a?p.deflateRaw(l):l}}for(var o in s)t+=s[o].file.length+30+46+2*p.bin.sizeUTF8(o);t+=22;var c=new Uint8Array(t),h=0,m=[];for(var o in s){var u=s[o];m.push(h),h=p._writeHeader(c,h,o,u,0)}var f=0,g=h;for(var o in s){var u=s[o];m.push(h),h=p._writeHeader(c,h,o,u,1,m[f++])}var w=h-g;return r(c,h,101010256),h+=4,h+=4,i(c,h,f),h+=2,i(c,h,f),h+=2,r(c,h,w),h+=4,r(c,h,g),h+=4,h+=2,c.buffer};p._noNeed=function(n){var e=n.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(e)!=-1};p._writeHeader=function(n,e,t,r,i,s){var o=p.bin.writeUint,a=p.bin.writeUshort,l=r.file;o(n,e,i==0?67324752:33639248),e+=4,i==1&&(e+=2),a(n,e,20),e+=2,a(n,e,0),e+=2,a(n,e,r.cpr?8:0),e+=2,o(n,e,0),e+=4,o(n,e,r.crc),e+=4,o(n,e,l.length),e+=4,o(n,e,r.usize),e+=4,a(n,e,p.bin.sizeUTF8(t)),e+=2,a(n,e,0),e+=2,i==1&&(e+=2,e+=2,e+=6,o(n,e,s),e+=4);var d=p.bin.writeUTF8(n,e,t);return e+=d,i==0&&(n.set(l,e),e+=l.length),e};p.crc={table:function(){for(var n=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;n[e]=t}return n}(),update:function(n,e,t,r){for(var i=0;i<r;i++)n=p.crc.table[(n^e[t+i])&255]^n>>>8;return n},crc:function(n,e,t){return p.crc.update(4294967295,n,e,t)^4294967295}};p.adler=function(n,e,t){for(var r=1,i=0,s=e,o=e+t;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=n[s++],i+=r;r=r%65521,i=i%65521}return i<<16|r};p.bin={readUshort:function(n,e){return n[e]|n[e+1]<<8},writeUshort:function(n,e,t){n[e]=t&255,n[e+1]=t>>8&255},readUint:function(n,e){return n[e+3]*(256*256*256)+(n[e+2]<<16|n[e+1]<<8|n[e])},writeUint:function(n,e,t){n[e]=t&255,n[e+1]=t>>8&255,n[e+2]=t>>16&255,n[e+3]=t>>24&255},readASCII:function(n,e,t){for(var r="",i=0;i<t;i++)r+=String.fromCharCode(n[e+i]);return r},writeASCII:function(n,e,t){for(var r=0;r<t.length;r++)n[e+r]=t.charCodeAt(r)},pad:function(n){return n.length<2?"0"+n:n},readUTF8:function(n,e,t){for(var r="",i,s=0;s<t;s++)r+="%"+p.bin.pad(n[e+s].toString(16));try{i=decodeURIComponent(r)}catch{return p.bin.readASCII(n,e,t)}return i},writeUTF8:function(n,e,t){for(var r=t.length,i=0,s=0;s<r;s++){var o=t.charCodeAt(s);if(!(o&4294967168))n[e+i]=o,i++;else if(!(o&4294965248))n[e+i]=192|o>>6,n[e+i+1]=128|o>>0&63,i+=2;else if(!(o&4294901760))n[e+i]=224|o>>12,n[e+i+1]=128|o>>6&63,n[e+i+2]=128|o>>0&63,i+=3;else if(!(o&4294967295-(1<<21)+1))n[e+i]=240|o>>18,n[e+i+1]=128|o>>12&63,n[e+i+2]=128|o>>6&63,n[e+i+3]=128|o>>0&63,i+=4;else throw"e"}return i},sizeUTF8:function(n){for(var e=n.length,t=0,r=0;r<e;r++){var i=n.charCodeAt(r);if(!(i&4294967168))t++;else if(!(i&4294965248))t+=2;else if(!(i&4294901760))t+=3;else if(!(i&4294967295-(1<<21)+1))t+=4;else throw"e"}return t}};p.F={};p.F.deflateRaw=function(n,e,t,r){var i=[[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=i[r],o=p.F.U,a=p.F._goodIndex,l=p.F._hash,d=p.F._putsE,c=0,h=t<<3,m=0,u=n.length;if(r==0){for(;c<u;){var f=Math.min(65535,u-c);d(e,h,c+f==u?1:0),h=p.F._copyExact(n,c,f,e,h+8),c+=f}return h>>>3}var g=o.lits,w=o.strt,A=o.prev,_=0,b=0,N=0,$=0,Y=0,W=0;u>2&&(W=p.F._hash(n,0),w[W]=0);var k=0,q=0;for(c=0;c<u;c++){if(Y=W,c+1<u-2){W=p.F._hash(n,c+1);var X=c+1&32767;A[X]=w[W],w[W]=X}if(m<=c){(_>14e3||b>26697)&&u-c>100&&(m<c&&(g[_]=c-m,_+=2,m=c),h=p.F._writeBlock(c==u-1||m==u?1:0,g,_,$,n,N,c-N,e,h),_=b=$=0,N=c);var B=0;c<u-2&&(B=p.F._bestMatch(n,c,A,Y,Math.min(s[2],u-c),s[3]));var f=B>>>16,K=B&65535;if(B!=0){var f=B>>>16,K=B&65535,D=a(f,o.of0);o.lhst[257+D]++;var O=a(K,o.df0);o.dhst[O]++,$+=o.exb[D]+o.dxb[O],g[_]=f<<23|c-m,g[_+1]=K<<16|D<<8|O,_+=2,m=c+f}else o.lhst[n[c]]++;b++}}for((N!=c||n.length==0)&&(m<c&&(g[_]=c-m,_+=2,m=c),h=p.F._writeBlock(1,g,_,$,n,N,c-N,e,h),_=0,b=0,_=b=$=0,N=c);h&7;)h++;return h>>>3};p.F._bestMatch=function(n,e,t,r,i,s){var o=e&32767,a=t[o],l=o-a+32768&32767;if(a==o||r!=p.F._hash(n,e-l))return 0;for(var d=0,c=0,h=Math.min(32767,e);l<=h&&--s!=0&&a!=o;){if(d==0||n[e+d]==n[e+d-l]){var m=p.F._howLong(n,e,l);if(m>d){if(d=m,c=l,d>=i)break;l+2<m&&(m=l+2);for(var u=0,f=0;f<m-2;f++){var g=e-l+f+32768&32767,w=t[g],A=g-w+32768&32767;A>u&&(u=A,a=g)}}}o=a,a=t[o],l+=o-a+32768&32767}return d<<16|c};p.F._howLong=function(n,e,t){if(n[e]!=n[e-t]||n[e+1]!=n[e+1-t]||n[e+2]!=n[e+2-t])return 0;var r=e,i=Math.min(n.length,e+258);for(e+=3;e<i&&n[e]==n[e-t];)e++;return e-r};p.F._hash=function(n,e){return(n[e]<<8|n[e+1])+(n[e+2]<<4)&65535};p.saved=0;p.F._writeBlock=function(n,e,t,r,i,s,o,a,l){var d=p.F.U,c=p.F._putsF,h=p.F._putsE,m,u,f,g,w,A,_,b,N;d.lhst[256]++,m=p.F.getTrees(),u=m[0],f=m[1],g=m[2],w=m[3],A=m[4],_=m[5],b=m[6],N=m[7];var $=(l+3&7?8-(l+3&7):0)+32+(o<<3),Y=r+p.F.contSize(d.fltree,d.lhst)+p.F.contSize(d.fdtree,d.dhst),W=r+p.F.contSize(d.ltree,d.lhst)+p.F.contSize(d.dtree,d.dhst);W+=14+3*_+p.F.contSize(d.itree,d.ihst)+(d.ihst[16]*2+d.ihst[17]*3+d.ihst[18]*7);for(var k=0;k<286;k++)d.lhst[k]=0;for(var k=0;k<30;k++)d.dhst[k]=0;for(var k=0;k<19;k++)d.ihst[k]=0;var q=$<Y&&$<W?0:Y<W?1:2;c(a,l,n),c(a,l+1,q),l+=3;var X=l;if(q==0){for(;l&7;)l++;l=p.F._copyExact(i,s,o,a,l)}else{var B,K;if(q==1&&(B=d.fltree,K=d.fdtree),q==2){p.F.makeCodes(d.ltree,u),p.F.revCodes(d.ltree,u),p.F.makeCodes(d.dtree,f),p.F.revCodes(d.dtree,f),p.F.makeCodes(d.itree,g),p.F.revCodes(d.itree,g),B=d.ltree,K=d.dtree,h(a,l,w-257),l+=5,h(a,l,A-1),l+=5,h(a,l,_-4),l+=4;for(var D=0;D<_;D++)h(a,l+D*3,d.itree[(d.ordr[D]<<1)+1]);l+=3*_,l=p.F._codeTiny(b,d.itree,a,l),l=p.F._codeTiny(N,d.itree,a,l)}for(var O=s,ee=0;ee<t;ee+=2){for(var G=e[ee],se=G>>>23,te=O+(G&(1<<23)-1);O<te;)l=p.F._writeLit(i[O++],B,a,l);if(se!=0){var y=e[ee+1],Z=y>>16,S=y>>8&255,C=y&255;l=p.F._writeLit(257+S,B,a,l),h(a,l,se-d.of0[S]),l+=d.exb[S],l=p.F._writeLit(C,K,a,l),c(a,l,Z-d.df0[C]),l+=d.dxb[C],O+=se}}l=p.F._writeLit(256,B,a,l)}return l};p.F._copyExact=function(n,e,t,r,i){var s=i>>>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(n.buffer,e,t),s),i+(t+4<<3)};p.F.getTrees=function(){for(var n=p.F.U,e=p.F._hufTree(n.lhst,n.ltree,15),t=p.F._hufTree(n.dhst,n.dtree,15),r=[],i=p.F._lenCodes(n.ltree,r),s=[],o=p.F._lenCodes(n.dtree,s),a=0;a<r.length;a+=2)n.ihst[r[a]]++;for(var a=0;a<s.length;a+=2)n.ihst[s[a]]++;for(var l=p.F._hufTree(n.ihst,n.itree,7),d=19;d>4&&n.itree[(n.ordr[d-1]<<1)+1]==0;)d--;return[e,t,l,i,o,d,r,s]};p.F.getSecond=function(n){for(var e=[],t=0;t<n.length;t+=2)e.push(n[t+1]);return e};p.F.nonZero=function(n){for(var e="",t=0;t<n.length;t+=2)n[t+1]!=0&&(e+=(t>>1)+",");return e};p.F.contSize=function(n,e){for(var t=0,r=0;r<e.length;r++)t+=e[r]*n[(r<<1)+1];return t};p.F._codeTiny=function(n,e,t,r){for(var i=0;i<n.length;i+=2){var s=n[i],o=n[i+1];r=p.F._writeLit(s,e,t,r);var a=s==16?2:s==17?3:7;s>15&&(p.F._putsE(t,r,o,a),r+=a)}return r};p.F._lenCodes=function(n,e){for(var t=n.length;t!=2&&n[t-1]==0;)t-=2;for(var r=0;r<t;r+=2){var i=n[r+1],s=r+3<t?n[r+3]:-1,o=r+5<t?n[r+5]:-1,a=r==0?-1:n[r-1];if(i==0&&s==i&&o==i){for(var l=r+5;l+2<t&&n[l+2]==i;)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(i==a&&s==i&&o==i){for(var l=r+5;l+2<t&&n[l+2]==i;)l+=2;var d=Math.min(l+1-r>>>1,6);e.push(16,d-3),r+=d*2-2}else e.push(i,0)}return t>>>1};p.F._hufTree=function(n,e,t){var r=[],i=n.length,s=e.length,o=0;for(o=0;o<s;o+=2)e[o]=0,e[o+1]=0;for(o=0;o<i;o++)n[o]!=0&&r.push({lit:o,f:n[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(w,A){return w.f-A.f});var c=r[0],h=r[1],m=0,u=1,f=2;for(r[0]={lit:-1,f:c.f+h.f,l:c,r:h,d:0};u!=a-1;)m!=u&&(f==a||r[m].f<r[f].f)?c=r[m++]:c=r[f++],m!=u&&(f==a||r[m].f<r[f].f)?h=r[m++]:h=r[f++],r[u++]={lit:-1,f:c.f+h.f,l:c,r:h};var g=p.F.setDepth(r[u-1],0);for(g>t&&(p.F.restrictDepth(l,t,g),g=t),o=0;o<a;o++)e[(l[o].lit<<1)+1]=l[o].d;return g};p.F.setDepth=function(n,e){return n.lit!=-1?(n.d=e,e):Math.max(p.F.setDepth(n.l,e+1),p.F.setDepth(n.r,e+1))};p.F.restrictDepth=function(n,e,t){var r=0,i=1<<t-e,s=0;for(n.sort(function(a,l){return l.d==a.d?a.f-l.f:l.d-a.d}),r=0;r<n.length&&n[r].d>e;r++){var o=n[r].d;n[r].d=e,s+=i-(1<<t-o)}for(s=s>>>t-e;s>0;){var o=n[r].d;o<e?(n[r].d++,s-=1<<e-o-1):r++}for(;r>=0;r--)n[r].d==e&&s<0&&(n[r].d--,s++);s!=0&&console.log("debt left")};p.F._goodIndex=function(n,e){var t=0;return e[t|16]<=n&&(t|=16),e[t|8]<=n&&(t|=8),e[t|4]<=n&&(t|=4),e[t|2]<=n&&(t|=2),e[t|1]<=n&&(t|=1),t};p.F._writeLit=function(n,e,t,r){return p.F._putsF(t,r,e[n<<1]),r+e[(n<<1)+1]};p.F.inflate=function(n,e){var t=Uint8Array;if(n[0]==3&&n[1]==0)return e||new t(0);var r=p.F,i=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(n.length>>>2<<3));for(var m=0,u=0,f=0,g=0,w=0,A=0,_=0,b=0,N=0,$,Y;m==0;){if(m=i(n,N,1),u=i(n,N+1,2),N+=3,u==0){N&7&&(N+=8-(N&7));var W=(N>>>3)+4,k=n[W-4]|n[W-3]<<8;h&&(e=p.F._check(e,b+k)),e.set(new t(n.buffer,n.byteOffset+W,k),b),N=W+k<<3,b+=k;continue}if(h&&(e=p.F._check(e,b+(1<<17))),u==1&&($=c.flmap,Y=c.fdmap,A=511,_=31),u==2){f=s(n,N,5)+257,g=s(n,N+5,5)+1,w=s(n,N+10,4)+4,N+=14;for(var q=N,X=0;X<38;X+=2)c.itree[X]=0,c.itree[X+1]=0;for(var B=1,X=0;X<w;X++){var K=s(n,N+X*3,3);c.itree[(c.ordr[X]<<1)+1]=K,K>B&&(B=K)}N+=3*w,a(c.itree,B),l(c.itree,B,c.imap),$=c.lmap,Y=c.dmap,N=o(c.imap,(1<<B)-1,f+g,n,N,c.ttree);var D=r._copyOut(c.ttree,0,f,c.ltree);A=(1<<D)-1;var O=r._copyOut(c.ttree,f,g,c.dtree);_=(1<<O)-1,a(c.ltree,D),l(c.ltree,D,$),a(c.dtree,O),l(c.dtree,O,Y)}for(;;){var ee=$[d(n,N)&A];N+=ee&15;var G=ee>>>4;if(!(G>>>8))e[b++]=G;else{if(G==256)break;var se=b+G-254;if(G>264){var te=c.ldef[G-257];se=b+(te>>>3)+s(n,N,te&7),N+=te&7}var y=Y[d(n,N)&_];N+=y&15;var Z=y>>>4,S=c.ddef[Z],C=(S>>>4)+i(n,N,S&15);for(N+=S&15,h&&(e=p.F._check(e,b+(1<<17)));b<se;)e[b]=e[b++-C],e[b]=e[b++-C],e[b]=e[b++-C],e[b]=e[b++-C];b=se}}}return e.length==b?e:e.slice(0,b)};p.F._check=function(n,e){var t=n.length;if(e<=t)return n;var r=new Uint8Array(Math.max(t<<1,e));return r.set(n,0),r};p.F._decodeTiny=function(n,e,t,r,i,s){for(var o=p.F._bitsE,a=p.F._get17,l=0;l<t;){var d=n[a(r,i)&e];i+=d&15;var c=d>>>4;if(c<=15)s[l]=c,l++;else{var h=0,m=0;c==16?(m=3+o(r,i,2),i+=2,h=s[l-1]):c==17?(m=3+o(r,i,3),i+=3):c==18&&(m=11+o(r,i,7),i+=7);for(var u=l+m;l<u;)s[l]=h,l++}}return i};p.F._copyOut=function(n,e,t,r){for(var i=0,s=0,o=r.length>>>1;s<t;){var a=n[s+e];r[s<<1]=0,r[(s<<1)+1]=a,a>i&&(i=a),s++}for(;s<o;)r[s<<1]=0,r[(s<<1)+1]=0,s++;return i};p.F.makeCodes=function(n,e){for(var t=p.F.U,r=n.length,i,s,o,a,l,d=t.bl_count,a=0;a<=e;a++)d[a]=0;for(a=1;a<r;a+=2)d[n[a]]++;var c=t.next_code;for(i=0,d[0]=0,s=1;s<=e;s++)i=i+d[s-1]<<1,c[s]=i;for(o=0;o<r;o+=2)l=n[o+1],l!=0&&(n[o]=c[l],c[l]++)};p.F.codes2map=function(n,e,t){for(var r=n.length,i=p.F.U,s=i.rev15,o=0;o<r;o+=2)if(n[o+1]!=0)for(var a=o>>1,l=n[o+1],d=a<<4|l,c=e-l,h=n[o]<<c,m=h+(1<<c);h!=m;){var u=s[h]>>>15-e;t[u]=d,h++}};p.F.revCodes=function(n,e){for(var t=p.F.U.rev15,r=15-e,i=0;i<n.length;i+=2){var s=n[i]<<e-n[i+1];n[i]=t[s]>>>r}};p.F._putsE=function(n,e,t){t=t<<(e&7);var r=e>>>3;n[r]|=t,n[r+1]|=t>>>8};p.F._putsF=function(n,e,t){t=t<<(e&7);var r=e>>>3;n[r]|=t,n[r+1]|=t>>>8,n[r+2]|=t>>>16};p.F._bitsE=function(n,e,t){return(n[e>>>3]|n[(e>>>3)+1]<<8)>>>(e&7)&(1<<t)-1};p.F._bitsF=function(n,e,t){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16)>>>(e&7)&(1<<t)-1};p.F._get17=function(n,e){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16)>>>(e&7)};p.F._get25=function(n,e){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16|n[(e>>>3)+3]<<24)>>>(e&7)};p.F.U=function(){var n=Uint16Array,e=Uint32Array;return{next_code:new n(16),bl_count:new n(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 n(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 n(512),fltree:[],fdmap:new n(32),fdtree:[],lmap:new n(32768),ltree:[],ttree:[],dmap:new n(32768),dtree:[],imap:new n(512),itree:[],rev15:new n(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new n(65536),prev:new n(32768)}}();(function(){for(var n=p.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,n.rev15[t]=(r>>>16|r<<16)>>>17}function i(s,o,a){for(;o--!=0;)s.push(0,a)}for(var t=0;t<32;t++)n.ldef[t]=n.of0[t]<<3|n.exb[t],n.ddef[t]=n.df0[t]<<4|n.dxb[t];i(n.fltree,144,8),i(n.fltree,112,9),i(n.fltree,24,7),i(n.fltree,8,8),p.F.makeCodes(n.fltree,9),p.F.codes2map(n.fltree,9,n.flmap),p.F.revCodes(n.fltree,9),i(n.fdtree,32,5),p.F.makeCodes(n.fdtree,5),p.F.codes2map(n.fdtree,5,n.fdmap),p.F.revCodes(n.fdtree,5),i(n.itree,19,0),i(n.ltree,286,0),i(n.dtree,30,0),i(n.ttree,320,0)})()});var vn=ve(nt());var it=n=>{let e=Math.floor((n-5)/7*100+.5)/100;return Math.floor((e*7+5)/7*256)/256},Pt=n=>Math.floor((256*n+Math.floor(18.285714285714285))/256*7);var dr="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 hr=n=>n!==null&&typeof n=="object"&&"row"in n&&"column"in n;var j=class n{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 n({row:1/0,column:e})}static FromRow(e){return new n({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){if(e.row===1/0&&e.column===1/0)throw new Error("this is going to break something");let r=t?`${e.sheet_id||0}!`:"";return e.row===1/0?r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column):e.column===1/0?r+(e.absolute_row?"$":"")+(e.row+1):r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new n(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 n({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:s,row_count:o}=t,a=new n(e.start,e.end),l=e.start.sheet_id;if(i&&r<=a.end.column){if(i>0)r<=a.start.column?a.Shift(0,i):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(a));else if(i<0)if(r-i<=a.start.column)a.Shift(0,i);else{if(r<=a.start.column&&r-i>a.end.column)return!1;if(r<=a.start.column){let d=r-i-1;a=new n({row:a.start.row,column:d+1+i,sheet_id:l},{row:a.end.row,column:a.end.column+i})}else r<=a.end.column?r-i-1>=a.end.column?a=new n({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:r-1}):a=new n({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:a.start.column+a.columns+i-1}):console.warn("AA X case 2",r,i,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 n({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 n({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:s-1}):a=new n({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}Equals2(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 n(this.start,this.end)}get left(){let e=new n(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new n(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new n(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new n(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}[Symbol.iterator](){if(this.entire_row||this.entire_column)throw new Error("don\'t iterate infinite area");let e=this.start_.row,t=this.start_.column;return{next:()=>{let r={column:t,row:e,sheet_id:this.start_.sheet_id};return t>this.end_.column?{done:!0,value:void 0}:(++e>this.end_.row&&(e=this.start_.row,t++),{value:r})}}}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=n.ColumnToLabel(this.start_.column),e+=":"+n.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=n.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+n.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var Vn=n=>typeof n=="object"&&!!n&&typeof n.real=="number"&&typeof n.imaginary=="number";var Zt=n=>typeof n=="object"&&!!n&&typeof n.value=="number"&&typeof n.unit=="string",Ft=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var Ne=n=>{switch(typeof n){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return n===null?0:Vn(n)?7:Zt(n)?9:5;case"string":return n[0]==="="?1:2;default:return 6}};var ne=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;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=Ne(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=Ne(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=Ne(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 Yn=n=>!n.cells,On=n=>!!n[0]&&Yn(n[0]),jn=n=>!!n[0]&&n[0].row!==void 0,Dn=Ft.map((n,e)=>({[n]:e})).reduce((n,e)=>({...n,...e}),{}),at=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){this.data=this.data.map(r=>{if(r.length>=e){let i=r.slice(0,e),s=e+t,o=r.slice(e);for(let a=0;a<o.length;a++)i[s++]=o[a];return i}return r}),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 ne,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 s=i[r];return s||(s=i[r]=new ne,this.columns_=Math.max(this.columns_,r+1)),s}FromArray(e=[],t=!1){this.data=[];let r=0,i=0;if(t){i=e.length;for(let s=0;s<i;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 ne(o[a])}}else{r=e.length;for(let s=0;s<r;s++){let o=[],a=e[s];i=Math.max(i,a.length);for(let l=0;l<a.length;l++)o[l]=new ne(a[l]);this.data[s]=o}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Dn[e]||void 0}ValueTypeToSerializedType(e){return e?Ft[e]:void 0}FromJSON(e=[],t){if(this.data=[],!On(e)){let i=[];if(jn(e))for(let s of e)for(let o of s.cells)i.push({...o,row:s.row});else for(let s of e)for(let o of s.cells)i.push({...o,column:s.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let s=new ne(i.value);if(typeof i.calculated<"u"&&s.SetCalculatedValue(i.calculated,this.SerializedTypeToValueType(i.calculated_type)),t&&typeof i.style_ref<"u"&&(s.style=t[i.style_ref]),typeof i.note<"u"&&(s.note=i.note),typeof i.hyperlink<"u"&&(s.hyperlink=i.hyperlink),this.data[i.row][i.column]&&this.data[i.row][i.column].area&&(s.area=this.data[i.row][i.column].area),this.data[i.row][i.column]=s,i.area){let o=new j(i.area.start,i.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 ne),this.data[a][l].area=o}if(i.table&&r.push({...i.table}),i.merge_area){let o=new j(i.merge_area.start,i.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 ne),this.data[a][l].merge_area=o}}for(let i of r)for(let s=i.area.start.row;s<=i.area.end.row;s++)for(let o=i.area.start.column;o<=i.area.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ne),this.data[s][o].table=i;this.rows_=this.data.length,this.columns_=this.data.reduce((i,s)=>Math.max(i,s.length),0)}toJSON(e={}){let t=0,r=0,i=this.data.length-1,s;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,i=e.subset.end.row);let o=[],a=-1,l=-1,d={},c={};for(let h=r;h<=i;h++)if(this.data[h]){let m=this.data[h];s=m.length-1,e.subset&&(s=e.subset.end.column);for(let u=t;u<=s;u++){let f=m[u],g=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===u,w=f&&f.area&&f.area.start.row===h&&f.area.start.column===u,A=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===u,_=f?f.type===2&&!f.value:!0;if(f&&(!_||e.preserve_empty_strings)&&(g||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||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 b={row:h,column:u,value:f.value};f.note&&(b.note=f.note),f.hyperlink&&(b.hyperlink=f.hyperlink),e.preserve_type&&(b.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(b.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(b.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(b.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&A&&e.tables&&(b.table=JSON.parse(JSON.stringify(f.table))),f.area&&w&&(b.area=f.area.toJSON()),f.merge_area&&(b.merge_area=f.merge_area.toJSON()),e.cell_style_refs&&e.cell_style_refs[u]&&e.cell_style_refs[u][h]&&(b.style_ref=e.cell_style_refs[u][h],e.cell_style_refs[u][h]=0),d[h]=h,c[u]=u,a=Math.max(h,a),l=Math.max(u,l),o.push(b)}}}if(e.nested){let h=Object.keys(d),m=Object.keys(c);if(h.length<=m.length&&h.length){let u={},f=[];for(let g of o){let{row:w,...A}=g;u[g.row]||(u[g.row]=[]),u[g.row].push(A)}for(let g of h){let w=Number(g);f.push({row:w,cells:u[w]})}return{data:f,rows:a,columns:l+1}}else if(m.length){let u={},f=[];for(let g of o){let{column:w,...A}=g;u[g.column]||(u[g.column]=[]),u[g.column].push(A)}for(let g of m){let w=Number(g);f.push({column:w,cells:u[w]})}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)}Normalize(e,t){return e={...e,row:e.row==1/0?0:e.row,column:e.column==1/0?0:e.column},t&&(t={...t,row:t.row==1/0?this.rows_-1:t.row,column:t.column==1/0?this.columns_-1:t.column}),{from:e,to:t}}RawValue(e,t=e){if({from:e,to:t}=this.Normalize(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),s=e.column,o=t.column+1;for(let a of i){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({from:e,to:t}=this.Normalize(e,t),!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 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);i.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);i.push(o)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize(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 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});i.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});i.push(o)}return{type:8,value:i}}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 s=this.data[r];if(t[i])for(let o=e.start.column,a=0;o<=e.end.column;o++,a++)s[o]||(s[o]=new ne),s[o].Set(t[i][a])}else{let r=Ne(t);for(let i=e.start.row;i<=e.end.row;i++){this.data[i]||(this.data[i]=[]);let s=this.data[i];for(let o=e.start.column;o<=e.end.column;o++)s[o]||(s[o]=new ne),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)}*Iterate(e,t=!1){if(!e&&t&&(e=new j({row:0,column:0},{row:this.rows_-1,column:this.columns-1})),e){hr(e)&&(e=new j(e)),(e.entire_column||e.entire_row)&&(e=new j(e.start,e.end),e.start.column===1/0&&(e.start.column=0,e.end.column=this.columns_-1),e.start.row===1/0&&(e.start.row=0,e.end.row=this.rows_-1));let r=e.start,i=e.end;if(t)for(let s=r.row;s<=i.row;s++){this.data[s]||(this.data[s]=[]);let o=this.data[s];for(let a=r.column;a<=i.column;a++)o[a]||(o[a]=new ne),yield o[a]}else for(let s=r.row;s<=i.row;s++)if(this.data[s]){let o=this.data[s];for(let a=r.column;a<=i.column;a++)o[a]&&(yield o[a])}}else for(let r of this.data)if(r)for(let i of r)i&&(yield i)}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 U=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 s=i.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)}this.locale==="C"&&(console.warn("Locale not set, defaulting to en-us"),this.locale="en-us");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"}))}};U.UpdateLocale();var Hn=JSON.stringify({}),Jn={Background:0,Text:1,Background2:2,Text2:3,Accent:4,Accent2:5,Accent3:6,Accent4:7,Accent5:8,Accent6:9},Se=n=>typeof n.theme=="number"?n.theme:Jn[n.theme]||0,Te=n=>!!n&&typeof n.text=="string",Pe=n=>!!n&&typeof n.theme<"u";var Fe={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:n=>({top:{width:n.border_top||0,color:n.border_top_fill||{}},left:{width:n.border_left||0,color:n.border_left_fill||{}},right:{width:n.border_right||0,color:n.border_right_fill||{}},bottom:{width:n.border_bottom||0,color:n.border_bottom_fill||{}}}),Merge:(n,e,t=!0)=>{let r=t?{...n,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:n=>JSON.parse(JSON.stringify(n.reduce((e,t)=>({...e,...t}),{}))),Empty:n=>JSON.stringify(n)===Hn,ParseFontSize:(n="",e="em")=>{let t=n.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:(n,e)=>{let t=12,r=12;switch(n.font_size?.unit){case"pt":if(!n.font_size.value)return 1;r=n.font_size.value;break;case"px":if(!n.font_size.value)return 1;r=Math.round(n.font_size.value*300/4)/100;break;case"em":return n.font_size.value||1;case"%":return(n.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:(n,e=!0)=>{let t=n.font_size?.value;switch(n.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:(n,e=1)=>{let t=[];return n.bold&&t.push("bold"),n.italic&&t.push("italic"),t.push(((n.font_size?.value||0)*e).toFixed(2)+(n.font_size?.unit||"pt")),t.push(n.font_face||""),t.join(" ")}};var In=ve(lt());var ss={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":\'"\',"&apos;":"\'"},as=/&\\w+;/g,os=n=>n.replace(as,e=>ss[e]||e);var ct=os;var Vr=ve(lt()),Yr=(n,e)=>ct(e),Bt=n=>{if(n){if(Array.isArray(n))for(let e of n)Bt(e);else if(typeof n=="object")for(let[e,t]of Object.entries(n))if(e==="a$"){if(typeof t=="object"){let r={};for(let[i,s]of Object.entries(t))s!==void 0&&(r[i]=s);n[e]=r}}else Bt(t)}return n},Or=n=>{let e=new Vr.XMLBuilder(n),t=e.build;return e.build=r=>t.call(e,Bt(r)),e},jr={ignoreAttributes:!1,attributeNamePrefix:"__",trimValues:!1,textNodeName:"text__",tagValueProcessor:Yr,ignoreDeclaration:!0},dt={ignoreAttributes:!1,attributesGroupName:"a$",attributeNamePrefix:"",textNodeName:"t$",trimValues:!1,ignoreDeclaration:!0,isArray:n=>/Relationship$/.test(n),tagValueProcessor:Yr},M=class{static FindChild(e={},t){let r=t.split("/");for(let i of r)if(e=e[i],!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,i)=>r.concat(this.FindAllTail(i,t)),[]);for(let r=0;r<t.length;r++){let i=t[r];if(i==="*"?e=Object.keys(e).filter(s=>s!=="a$"&&s!=="t$").map(s=>e[s]):e=e[i],!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 Me=class{strings=[];reverse={};FromXML(e){this.strings=[],this.reverse={};let t=0;for(let r of M.FindAll(e,"sst/si")){if(r.t!==void 0){let i="";typeof r.t=="string"?i=r.t:r.t.t$&&(i=r.t.t$),this.strings[t]=i,this.reverse[i]=t}else if(r.r){let s=M.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 we=class n{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="",i=t.toString().match(/^(.*?):/);if(i&&(r=i[1]+":"),e[t]&&e[t][`${r}themeElements`]){let s=e[t][`${r}themeElements`][`${r}clrScheme`];for(let o of n.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 be=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 Dr=42,Hr=95,Ut=63,ht=48,Jr=46,Lt=44,Xr=37,Vt=34,Ve=35,Qr=59,ut=92,qr=64,cs=91,ds=93,Kr=69,en=101,hs=72,us=104,fs=77,ms=109,ps=83,bs=115,gs=68,ys=100,xs=89,_s=121,ws=65,As=97;var ft=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new be;static preserve_formatting_characters=!1;static decimal_mark=Jr;static group_separator=Lt;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new be,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new be,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 ut: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 Vt: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 ut:throw new Error("invalid escape character in formatting block");case ds: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 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+=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 s=this.characters[i];if(s===this.decimal_mark||s===Ve||s===ht)r=!0;else if(s!==Lt)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 Ve:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case ht: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===Ut||e===Ve)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case Qr:this.char_index++,this.current_section=new be,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case qr:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case ht:case Ve:case Jr:case Lt:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case cs:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Vt:this.AppendString(this.ConsumeString());break;case Ut:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Hr: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 Dr: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 en:case Kr: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 Xr:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case ut: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 Qr:this.char_index=this.characters.length;break;case ht:case Ve:case en:case Kr:case Xr:case qr:this.date_pattern=!1;break;case hs:case us:case fs:case ms:case ps:case bs:case gs:case ys:case xs:case _s:this.AppendTextPart(this.ConsumeDatePart());break;case ws:case As:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Vt:this.AppendString(this.ConsumeString());break;case Ut:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Hr: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 Dr: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 ut: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 Cs=n=>(n>=60&&n--,new Date(-22090752e5+864e5*n)),tn=(n,e=!0)=>{if(e){let t=new Date(n);n=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()).getTime()}return n=(n+22090752e5)/864e5,n>=60&&n++,n},ke=class n{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=ft.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new be),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((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=i.reduce((a,l,d)=>d===r?a:a+l.length,0),o="";for(let a=0;a<t-s;a++)o+=i[r];i[r]=o}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 s=0;s<e.fraction_denominator_digits;s++)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(Zt(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,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="",i=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",i=!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){a.push({text:e.imaginary<0?` ${n.minus_character} `:" + "});let l=i?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...l,{text:n.imaginary_character})}}else s&&a.push(...t,{text:n.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),i=[];if(r.date_format||r.string_format)for(let s of t)typeof s=="string"?i.push({text:s}):i.push(s);else this.magic_decimal&&t[1]===""&&t.splice(1,1),i=[...r.prefix.map(s=>({...s})),{text:r.has_number_format?t.join(U.decimal_separator):""},...r.suffix.map(s=>({...s}))];for(let s=1;s<i.length;s++)i[s].flag===i[s-1].flag&&(i[s].text=i[s-1].text+i[s].text,i[s-1].text="");return i.filter(s=>s.text)}Format(e,t=0){return n.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=Cs(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=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:U.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:U.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:U.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:U.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:U.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:U.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:U.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:U.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:U.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 a=o.text.match(/^(s+)\\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+U.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),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 s=n.fraction_limits[t.fraction_denominator_digits-1]||n.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 i=[];if(t.fraction_integer){let s=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(s||!r.numerator)&&(i.push(s.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,s=Math.pow(10,-i)/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(n.grouping_regexp,"$&"+U.grouping_separator)),{parts:l,section:t}}};var Ye=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 ke(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 ke(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new ke("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}};Ye.InitCache();var rn=new Date().getUTCFullYear(),Yt=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[U.date_components.long_months[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_month[U.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[U.date_components.long_days[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_day[U.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(),i=r.match(/^[$](.*?)$/);i&&(r=i[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),U.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>=rn-200&&h<=rn+200)return t={Date:!0},(c.getHours()||c.getMinutes()||c.getSeconds())&&(t.Time=!0),{value:tn(d,!0),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}}},Mo=new Yt;var nn=11,Ot={top:{},left:{},bottom:{},right:{},diagonal:{}},Ee=class n{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 we;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),i=parseInt(e.substr(2,2),16),s=parseInt(e.substr(4,2),16);return t<0?(r=Math.round(r*t+r),i=Math.round(i*t+i),s=Math.round(s*t+s)):(r=Math.round((255-r)*t+r),i=Math.round((255-i)*t+i),s=Math.round((255-s)*t+s)),[r,i,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={},i={pattern_type:"none"},s=JSON.parse(JSON.stringify(Ot)),o={font:r,border:s};t.number_format&&(o.number_format={format:Ye.Translate(t.number_format),symbolic_name:t.number_format}),t.font_size?.unit&&t.font_size.value&&(t.font_size.unit==="em"?r.size=t.font_size.value*nn:t.font_size.unit==="%"?r.size=t.font_size.value*nn/100:t.font_size.unit==="pt"?r.size=t.font_size.value:t.font_size.unit==="px"?r.size=t.font_size.value*.75:console.warn("Unhandled font size unit",t.font_size)),t.bold&&(r.bold=!0),t.italic&&(r.italic=!0),t.underline&&(r.underline=!0),t.text&&(Te(t.text)?r.color_argb=t.text.text:Pe(t.text)&&(r.color_theme=Se(t.text),t.text.tint&&(r.color_tint=t.text.tint)));let a=(d,c)=>{d.width&&(c.style="thin",Te(d.color)?c.rgba=d.color.text:Pe(d.color)?(c.theme=Se(d.color),d.color.tint&&(c.tint=d.color.tint)):c.color=64)},l=Fe.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 o.indent=t.indent,t.fill&&(i.pattern_type="solid",Te(t.fill)?(i.fg_color={argb:t.fill.text},o.fill=i):Pe(t.fill)&&(i.fg_color={theme:Se(t.fill)},t.fill.tint&&(i.fg_color.tint=t.fill.tint),o.fill=i)),t.wrap&&(o.wrap=!0),o}CellXfToStyle(e){let t={},r=n.default_styles[e.number_format];if(!r){for(let d of this.number_formats)if(d.id===e.number_format&&d.format){r=d.format;break}}if(r){let d=/\\[\\$(.)-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(d,"$1");let c=/\\[\\$-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(c,""),t.number_format=r}let i=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),i&&i.size&&s.size&&i.size!==s.size&&(t.font_size={value:100*s.size/i.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 d=Math.round((o.pattern_gray||0)/1e3*255);t.fill={text:`rgb(${d}, ${d}, ${d})`}}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}t.indent=typeof e.indent=="string"?Number(e.indent):e.indent,e.wrap_text&&(t.wrap=!0);let a=d=>{if(typeof d.theme<"u")return{theme:d.theme,tint:d.tint}},l=this.borders[e.border||0];return l&&(l.bottom.style&&(l.bottom.style==="double"?t.border_bottom=2:t.border_bottom=1,t.border_bottom_fill=a(l.bottom)),l.left.style&&(t.border_left=1,t.border_left_fill=a(l.left)),l.top.style&&(t.border_top=1,t.border_top_fill=a(l.top)),l.right.style&&(t.border_right=1,t.border_right_fill=a(l.right))),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 i=n.default_styles[r];if(i&&i===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 i=this.borders[r];if(this.CompareBorder(i,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 i=this.fills[r];if(this.MatchColor(e.bg_color,i.bg_color)&&this.MatchColor(e.fg_color,i.fg_color)&&e.pattern_gray===i.pattern_gray&&e.pattern_type===i.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 i=this.fonts[r];if(i.bold===t.bold&&i.italic===t.italic&&i.underline===t.underline&&i.size===t.size&&i.strike===t.strike&&i.color_argb===t.color_argb&&i.color_theme===t.color_theme&&i.color_tint===t.color_tint&&i.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||Ot),i=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===i&&!!l.wrap_text==!!e.wrap&&l.indent===e.indent&&(!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:i,indent:e.indent};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=M.FindAll.bind(M,e);this.theme=t;let i=r("styleSheet/numFmts/numFmt");this.number_formats=i.map(c=>({id:Number(c.a$?.numFmtId||0),format:ct(c.a$?.formatCode||"")})),i=r("styleSheet/borders/border");let s=(c,h)=>{c?.a$&&(h.style=c.a$.style,typeof c.color=="object"&&(typeof c.color.a$?.indexed<"u"&&(h.color=Number(c.color.a$.indexed)),typeof c.color.a$?.theme<"u"&&(h.theme=Number(c.color.a$.theme)),typeof c.color.a$?.tint<"u"&&(h.tint=Number(c.color.a$.tint))))};this.borders=i.map(c=>{let h=JSON.parse(JSON.stringify(Ot));return s(c.left,h.left),s(c.right,h.right),s(c.top,h.top),s(c.bottom,h.bottom),h}),i=r("styleSheet/cellXfs/xf"),this.cell_xfs=i.map(c=>{let h={number_format:Number(c.a$.numFmtId),font:Number(c.a$.fontId),fill:Number(c.a$.fillId),border:Number(c.a$.borderId),xfid:Number(c.a$.xfId)};return c.alignment&&(h.horizontal_alignment=c.alignment.a$.horizontal,h.vertical_alignment=c.alignment.a$.vertical,h.wrap_text=!!c.alignment.a$.wrapText,h.indent=c.alignment.a$.indent||void 0),h});let o=c=>{let h={pattern_type:"none"};if(c.patternFill){let m=c.patternFill.a$?.patternType;switch(m){case"none":case void 0:break;case"solid":h.pattern_type="solid",c.patternFill.fgColor&&(h.fg_color={theme:c.patternFill.fgColor.a$?.theme?Number(c.patternFill.fgColor.a$.theme):void 0,indexed:c.patternFill.fgColor.a$?.indexed?Number(c.patternFill.fgColor.a$.indexed):void 0,tint:c.patternFill.fgColor.a$?.tint?Number(c.patternFill.fgColor.a$.tint):void 0,argb:c.patternFill.fgColor.a$?.rgb});break;default:{let u=m?.match(/^gray(\\d+)$/);if(u){h.pattern_type="gray",h.pattern_gray=Number(u[1]);break}}}}return h};i=r("styleSheet/fills/fill"),this.fills=i.map(o);let a=c=>{let h={};return h.italic=typeof c.i<"u",h.bold=typeof c.b<"u",h.underline=typeof c.u<"u",h.strike=typeof c.strike<"u",c.sz&&(h.size=Number(c.sz.a$.val)),c.scheme&&(h.scheme=c.scheme.a$.val),c.name&&(h.name=c.name.a$.val),c.family&&(h.family=Number(c.family.a$.val)),c.color&&(c.color.a$?.theme&&(h.color_theme=Number(c.color.a$.theme)),c.color.a$?.tint&&(h.color_tint=Number(c.color.a$.tint)),c.color.a$?.rgb&&(h.color_argb=c.color.a$.rgb)),h};i=r("styleSheet/fonts/font"),this.fonts=i.map(a);let l=c=>{let h={};return c.a$.rgb?h.text="#"+c.a$.rgb.substring(2):c.a$.theme&&(h.theme=Number(c.a$.theme)||0,c.a$.tint&&(h.tint=Math.round(c.a$.tint*1e3)/1e3)),h},d=r("styleSheet/dxfs/dxf");this.dxf_styles=d.map(c=>{let h={};return c.font&&(h.bold=!!c.font.b,h.italic=!!c.font.i&&c.font.i.a$.val!=="0"),c.font?.color?.a$&&(h.text=l(c.font.color)),c.fill?.patternFill?.bgColor?.a$&&(h.fill=l(c.fill.patternFill.bgColor)),h})}};var he=(n,e,t,r)=>{let s=`rId${Object.keys(n).length+1}`;return n[s]={id:s,type:e,target:t,mode:r},s};var sn={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0,decimal_mark:".",argument_separator:","};var an=/[\\s-+=<>!()]/;var jt=34,Dt=39,vs=160,on=32,Is=9,Ns=10,Ss=13,ge=48,Oe=57,Ht=46,Jt=43,je=45,ln=40,Xt=41,De=44,Ts=37,Qt=95,mt=36,Ps=123,Zs=125,He=91,cn=93,Fs=63,Ms=33,dn=59,ks=35,Es=64,Re=65,Je=97,Rs=69,$s=101,pt=90,bt=122,Ws=105,qt=192,Kt=312,er={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},Gs=Object.keys(er).sort((n,e)=>e.length-n.length),zs={"-":100,"+":100},$e=class{get argument_separator(){return this.flags.argument_separator}get decimal_mark(){return this.flags.decimal_mark}flags={...sn};r1c1_regex=/[rR]((?:\\[[-+]{0,1}\\d+\\]|\\d+))[cC]((?:\\[[-+]{0,1}\\d+\\]|\\d+))$/;argument_separator_char=De;decimal_mark_char=Ht;imaginary_char=Ws;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=[];parser_state_cache=[];SetLocaleSettings(e,t){if(typeof t>"u"&&(t=e===","?";":","),t===e)throw new Error("invalid locale setting");this.flags.argument_separator=t,this.flags.decimal_mark=e}Save(){this.parser_state_cache.push(JSON.stringify(this.flags))}Restore(){let e=this.parser_state_cache.shift();if(e)try{this.flags=JSON.parse(e)}catch(t){console.error(t)}else console.warn("No parser state to restore")}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 s=0;s<t;s++)Array.isArray(e[s])&&(i=Math.max(i,e[s].length));for(let s=0;s<i;s++){r[s]=[];for(let o=0;o<t;o++)r[s][o]=e[o]?e[o][s]:void 0}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},i=t.missing??"(missing)",{convert_decimal:s,convert_argument_separator:o,long_structured_references:a,table_name:l}=t,d=this.flags.argument_separator+" ";o===","?d=", ":o===";"&&(d="; ");let c=s===","?",":".",h=this.flags.decimal_mark===","?/,/:/\\./,m=this.flags.decimal_mark===","?/,/g:/\\./g;switch(e.type){case"address":return t.r1c1?this.R1C1Label(e,t.r1c1_base):this.AddressLabel(e,r);case"range":return t.r1c1?this.R1C1Label(e.start,t.r1c1_base)+":"+this.R1C1Label(e.end,t.r1c1_base):this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return i;case"array":return"{"+this.Transpose(e.values).map(u=>u.map(f=>typeof f=="string"?\'"\'+f+\'"\':f).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(m,c):e.text;{let u=Math.abs(e.imaginary).toString();if((s===","||this.flags.decimal_mark===",")&&(u=u.replace(/\\./,",")),e.real){let f=e.real.toString();(s===","||this.flags.decimal_mark===",")&&(f=f.replace(/\\./,","));let g=Math.abs(e.imaginary);return`${f}${e.imaginary<0?" - ":" + "}${g===1?"":u}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${u}i`}break;case"literal":if(typeof e.value=="string")return\'"\'+e.value.replace(/"/g,\'""\')+\'"\';if(s&&typeof e.value=="number")if(e.text){let u=e.text;return s===","&&this.flags.decimal_mark==="."&&(u=u.replace(/,/g,"")),u.replace(h,c)}else return e.value.toString().replace(/\\./,c);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(u=>this.Render(u,t)).join(d)+")":e.elements.map(u=>this.Render(u,t)).join(d);case"call":return e.name+"("+e.args.map(u=>this.Render(u,t)).join(d)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let u=e.column;/[^A-Za-z]/.test(u)&&(u="["+u+"]");let f=e.table;switch(!f&&a&&l&&(f=l),e.scope){case"all":return`${f}[[#all],${u}]`;case"row":return a?`${f}[[#this row],${u}]`:`${f}[@${u}]`;case"column":return`${f}[${u}]`}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.flags.argument_separator){case";":this.argument_separator_char=dn;break;default:this.argument_separator_char=De;break}switch(this.flags.decimal_mark){case",":this.decimal_mark_char=De;break;default:this.decimal_mark_char=Ht;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.flags.argument_separator,decimal_mark:this.flags.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}R1C1Label(e,t){let r="";e.sheet&&(r=(an.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!");let i=e.absolute_row||!t?(e.row+1).toString():`[${e.row-t.row}]`,s=e.absolute_column||!t?(e.column+1).toString():`[${e.column-t.column}]`;return r+=`R${i}C${s}`,r}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 s="";return e.sheet&&(s=(an.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!"),i===1/0?s+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?s+(e.absolute_row?"$":"")+(i+1):s+(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===ln){this.index++;let i=this.ParseGeneric([Xt]);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=o=>o.type==="literal"&&typeof o.value=="number"&&o.value%1===0,s=0;for(;s<t.length-3;s++)if(i(t[s])&&i(t[s+1])&&t[s+2].type==="operator"&&t[s+2].operator==="/"&&i(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=[],i;for(let s=0;s<t.length;s++){let o=t[s];if(!i)i=o;else if(o.type==="identifier"&&(i.type==="literal"||i.type==="group"||i.type==="call")){let a=o;for(;t[s+1]?.type==="identifier";)a.name+=" "+t[++s].name;r.push({type:"dimensioned",expression:i,unit:o,id:this.id_counter++}),i=void 0}else r.push(i),i=o}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 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-Re)}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 i=e[r],s=e[r+1],o=e[r+2],a,l="",d;if(i&&s&&o&&s.type==="operator"&&s.operator===":"){if(i.type==="address"&&o.type==="address"){let c=i.position+i.label.length,h=o.position;a={type:"range",id:this.id_counter++,position:i.position,start:i,end:o,label:i.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 m=[i.position,o.position];this.full_reference_list=this.full_reference_list.filter(u=>u.position!==m[0]&&u.position!==m[1])}else if((i.type==="literal"||i.type==="identifier")&&(o.type==="literal"||o.type==="identifier")){let c=this.UnitToAddress(i);if(!c&&i.type==="literal"&&typeof i.value=="number"&&i.value<0){let m={...i,text:(i.text||"").replace(/^-/,""),position:i.position+1,value:-i.value};c=this.UnitToAddress(m),c&&(d={type:"operator",operator:"-",position:i.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(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,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(i,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 i=this.UnitToAddress(e.left),s=this.UnitToAddress(e.right);i&&s&&(i.column===1/0&&s.column===1/0||i.row===1/0&&s.row===1/0)&&(r=i.label+":"+s.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:i,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 i=e[r];if(i.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(zs[i.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:i.operator,operand:s.left,position:i.position},i=s):i={type:"unary",id:this.id_counter++,operator:i.operator,operand:s,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 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:i};s.type==="binary"&&er[a]>er[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:i,operator:a,position:o.position}),t.splice(-2,2,l)}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===jt)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ge&&t<=Oe||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===Ps)return this.ConsumeArray();if(e&&(t===je||t===Jt)){let r=this.data[this.index+1];if(r>=ge&&r<=Oe||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Re&&t<=pt||t>=Je&&t<=bt||t===Qt||t===ks||t===Dt||t===mt||t===He||t>=qt&&t<=Kt)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(),s=this.index;if(typeof i=="number")switch(this.index++,i){case dn:r++,t=0;break;case De:t++;break;case Zs:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=s,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=s,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of Gs)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,Xt]);r!==null&&t.push(r);let i=this.data[this.index];if(i===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(i===Xt)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,i=e===Dt,s=0,o=!1;for(e===He&&(s=1,o=!0),++this.index;this.index<this.length;this.index++){let c=this.data[this.index];if(c>=Re&&c<=pt||c>=Je&&c<=bt||c>=qt&&c<=Kt||c===Qt||c===mt||c===Ht||c===Ms||i||c>=ge&&c<=Oe||c===He||s>0&&c===cn||c===je&&this.flags.r1c1&&s===1||s>0&&c===Es&&this.data[this.index-1]===He||s===1&&(c===De||c===on)||s>1||c===Fs&&s===0)t.push(c),c===He&&(s++,o=!0),c===cn&&s--,c===Dt&&(i=!1);else break}let a=t.map(c=>String.fromCharCode(c)).join("");if(i)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]===ln){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=e.length,i=e,s="",o=0;for(;o<r;o++){if(e[o]==="["){e=e.substring(o);break}s+=e[o]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let a=e.split(",").map(h=>h.trim()),l="column",d="";if(a.length>2)return;a.length===2?(/\\[#this row\\]/i.test(a[0])?l="row":/\\[#all\\]/i.test(a[0])&&(l="all"),d=a[1]):(d=a[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 c={type:"structured-reference",id:this.id_counter++,label:i,position:t,scope:l,column:d,table:s};return this.full_reference_list.push(c),c}ConsumeAddress(e,t){let r=t,i=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 m={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:s,r1c1:!0};return h[1][0]==="["?(m.offset_row=!0,m.row=Number(h[1].substring(1,h[1].length-1))):m.row=Number(h[1])-1,h[2][0]==="["?(m.offset_column=!0,m.column=Number(h[2].substring(1,h[2].length-1))):m.column=Number(h[2])-1,m}}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 i!==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]===mt;t&&e++;let r=e,i=0;for(;;e++){let s=this.data[e];if(s>=ge&&s<=Oe)i*=10,i+=s-ge;else break}return r===e||i===0?!1:{absolute:t,row:i-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,i=this.data[e]===mt;for(i&&e++;;e++,r++){if(r>=4)return!1;let s=this.data[e];if(s>=Re&&s<=pt)t=26*(1+t)+(s-Re);else if(s>=Je&&s<=bt)t=26*(1+t)+(s-Je);else break}return t<0?!1:{absolute:i,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,i=!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 u=this.data[this.index];if(u===this.decimal_mark_char)if(l==="integer")l="fraction";else break;else if(u===Ts){s/=100,a/=100,this.index++;break}else if(u===Jt||u===je)if(d===0)u===je&&(i=!0);else break;else if(u===Rs||u===$s)if(l==="integer"||l==="fraction")l="exponent",this.index<this.length-1&&(this.data[this.index+1]===Jt?this.index++:this.data[this.index+1]===je&&(this.index++,r=!0));else break;else if(u===this.imaginary_char){let f=this.data[this.index+1];if(f>=Re&&f<=pt||f>=Je&&f<=bt||f>=qt&&f<=Kt||f===Qt)break;if(l==="integer"||l==="fraction"){this.index++,c=!0;break}}else if(u>=ge&&u<=Oe)switch(l){case"integer":s=s*10+(u-ge);break;case"fraction":a=a*10+(u-ge),o++;break;case"exponent":t=t*10+(u-ge);break}else break}let m=s+a/Math.pow(10,o);return l==="exponent"&&(m=m*Math.pow(10,(r?-1:1)*t)),c?{type:"complex",id:this.id_counter++,position:e,imaginary:i?-m:m,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:i?-m:m,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===jt&&(this.index++,this.index>=this.length||this.data[this.index]!==jt))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===on||e===Is||e===Ns||e===Ss||e===vs)this.index++;else return}}};var hn=class n{static _instance=new n;constructor(){}static get instance(){return this._instance}HTML(e){let t=[];for(let r of e){let i=[];for(let s of r)s.pre&&i.push("<pre>"),s.emphasis&&i.push("<em>"),s.strong&&i.push("<strong>"),s.strike&&i.push("<strike>"),i.push(s.text),s.strike&&i.push("</strike>"),s.strong&&i.push("</strong>"),s.emphasis&&i.push("</em>"),s.pre&&i.push("</pre>");t.push(i.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 i=t[r];if(i.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);i.left_flanking=!d&&(!c||a),i.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={},i=[],s={type:"text",text:""};for(let o of e)if(o.type==="newline")s.text.length&&i.push(s),s={...r,text:"",type:"text"},t.push(i),i=[];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&&i.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&&i.push(s),i.length&&t.push(i),t}ApplyFormatting(e,t){let r=0,i=e.length;for(r=0;r<i;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,i=0,s=!1,o="";for(i=0;i<r;i++){let a=e[i];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[i+1];if(this.IsWhitespace(d))l+=d,i++;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[i+1];if(this.IsNewline(d))l+=d,i++;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[i+1];if(d===a)l+=d,i++;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 un={"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"}}}}},fn={"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"}}}}},Xe={"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 mn={"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}"}}}}},pn={"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 bn={"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 gn={"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"}}},yn={"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 xn={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:bubbleChart":{"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"}}},_n={"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"},"a:alpha":{a$:{val:"75000"}}}},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:xVal":{"c:numRef":{"c:f":""}},"c:yVal":{"c:numRef":{"c:f":""}},"c:bubbleSize":{"c:numRef":{"c:f":""}},"c:bubble3D":{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-03D7-43A5-9DAB-5775FFEF9C03}"}}}}};var We=class n{constructor(e,t=n.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(fn)),i=r["c:tx"]["c:rich"]["a:p"];i["a:r"]={"a:rPr":{a$:{lang:U.locale}},"a:t":t.value},e["c:title"]=r}else if(t){let r=JSON.parse(JSON.stringify(un));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"bubble":return this.CreateBubbleChart();case"donut":return this.CreateDonutChart();default:console.info("unhandled chart type",this.options.type)}return this.CreateBarChart()}CreateBubbleChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(xn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=t["c:chart"]["c:plotArea"]["c:bubbleChart"]["c:ser"],s=!1;for(let o=0;o<this.options.data.length;o++){let a=JSON.parse(JSON.stringify(_n));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: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.labels3&&this.options.labels3[o]&&(a["c:bubbleSize"]["c:numRef"]["c:f"]=this.options.labels3[o]?.label),i.push(a)}return s&&(t["c:chart"]["c:legend"]={"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}}}),e}CreateScatterChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(gn));this.options.smooth&&(r["c:plotArea"]["c:scatterChart"]["c:scatterStyle"].a$.val="smoothMarker"),t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=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(yn));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}}),i.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(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(bn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=r["c:plotArea"]["c:doughnutChart"];return i&&(i["c:ser"]["c:cat"]["c:strRef"]["c:f"]=this.options.labels?.label||"",i["c:ser"]["c:val"]["c:numRef"]["c:f"]=this.options.data[0]?.label||""),e}CreateBarChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(pn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=r["c:plotArea"]["c:barChart"];if(i){let s=i["c:barDir"];s&&(s.a$.val=this.options.type==="bar"?"bar":"col");let o=i["c:ser"];for(let a=0;a<this.options.data.length;a++){let l=JSON.parse(JSON.stringify(mn));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 gt=class n{constructor(e,t=n.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 wn=9525,Qe=class n{constructor(e=n.next_drawing_index++){this.index=e}static next_drawing_index=1;sheet_drawing_relationship=0;charts=[];images=[];relationships={};AddImage(e,t){let r=new gt(e);if(r.extension){let i=he(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",`../media/image${r.index}.${r.extension}`);this.images.push({image:r,relationship:i,anchor:t})}}AddChart(e,t){let r=new We(e),i=he(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",`../charts/chart${r.index}.xml`);this.charts.push({chart:r,anchor:t,relationship:i})}CornerToJSON(e){return{"xdr:col":e.column,"xdr:colOff":(e.column_offset||0)*wn,"xdr:row":e.row,"xdr:rowOff":(e.row_offset||0)*wn}}AnchorToJSON(e){return{"xdr:from":{...this.CornerToJSON(e.from)},"xdr:to":{...this.CornerToJSON(e.to)}}}toJSON(){let e=this.images.map(i=>({a$:{editAs:"oneCell"},...this.AnchorToJSON(i.anchor),"xdr:pic":{"xdr:nvPicPr":{"xdr:cNvPr":{a$:{id:i.image.index+1,name:"Image "+i.image.index}},"xdr:cNvPicPr":{"a:picLocks":{a$:{noChangeAspect:1}}}},"xdr:blipFill":{"a:blip":{a$:i.image.extension==="svg"?{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships"}:{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:embed":i.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}}},i.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":i.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(i=>({...this.AnchorToJSON(i.anchor),"xdr:graphicFrame":{a$:{macro:""},"xdr:nvGraphicFramePr":{"xdr:cNvPr":{a$:{id:i.chart.index+1,name:`Chart ${i.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":i.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 rr=ve(lt());var Ge=n=>"row"in n&&"col"in n,Ae=n=>"from"in n&&"to"in n&&Ge(n.from)&&Ge(n.to),yt=(n,e)=>e.sheet===n.sheet&&e.row>=n.from.row&&e.row<=n.to.row&&e.col>=n.from.col&&e.col<=n.to.col,tr=(n,e=0,t=0)=>({from:{row:n.from.row+e,col:n.from.col+t,sheet:n.from.sheet},to:{row:n.to.row+e,col:n.to.col+t,sheet:n.to.sheet}});var xt=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,i=0;if(t=e.match(/^([A-Z]+)(\\d+)$/),t){r=Number(t[2]),i=0;let s=t[1].length;for(let o=0;o<s;o++){let a=t[1].charCodeAt(o)-64;i=i*26+a}}return{row:r,col:i}}Address(e,t=!1){if(Ae(e))return this.Address(e.from,t)+":"+this.Address(e.to,t);let r="",i=e.col;for(;i>0;){let o=(i-1)%26+1;r=String.fromCharCode(64+o)+r,i=(i-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||"");Ae(t)?this.extent=JSON.parse(JSON.stringify(t)):this.extent={from:JSON.parse(JSON.stringify(t)),to:JSON.parse(JSON.stringify(t))}}};var Us=new rr.XMLParser(jr),Ce=new rr.XMLParser(dt),wt={greaterThan:">",greaterThanOrEquals:">=",lessThan:"<",lessThanOrEquals:"<=",equal:"=",notEqual:"<>"};var _t=class{constructor(e){this.zip=e}xml={};shared_strings=new Me;style_cache=new Ee;theme=new we;named=[];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):"",i=Ce.parse(r||"");for(let s of i.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=Ce.parse(e||"");this.shared_strings.FromXML(t),e=this.zip.Get("xl/theme/theme1.xml"),t=Ce.parse(e),this.theme.FromXML(t),e=this.zip.Get("xl/styles.xml"),t=Ce.parse(e),this.style_cache.FromXML(t,this.theme),e=this.zip.Get("xl/workbook.xml"),t=Ce.parse(e),this.named=[];let r=M.FindAll(t,"workbook/definedNames/definedName");for(let o of r){let a=o.a$?.name,l=o.t$||"",d=o.a$?.localSheetId?Number(o.a$.localSheetId):void 0;this.named.push({name:a,expression:typeof l=="string"?l:l?.toString()||"",local_scope:d})}let i=M.FindAll(t,"workbook/bookViews/workbookView");i[0]?.a$?.activeTab&&(this.active_tab=Number(i[0].a$.activeTab)||0);let s=M.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 xt({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=Ce.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=Ce.parse(t),i=r.table?.a$?.name||"";return{name:i,display_name:r.table?.a$?.displayName||i,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=Ce.parse(t),i=this.ReadRels(e.replace(/^..\\/drawings/,"xl/drawings/_rels")+".rels"),s=[],o=M.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=M.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},m=i[c.a$["r:id"]];m&&m.target&&(h.chart=this.ReadChart(m.target)),s.push(h)}else{let h=M.FindAll(l,"xdr:pic/xdr:blipFill/a:blip")[0];if(h&&h.a$["r:embed"]){let m=i[h.a$["r:embed"]];if(m&&m.target&&/(?:jpg|jpeg|png|gif)$/i.test(m.target)){let u=m.target.replace(/^\\.\\./,"xl"),f=u.replace(/^.*\\//,""),g={type:"image",anchor:d,image:this.zip.GetBinary(u),filename:f};s.push(g)}}else{let m,u=M.FindAll(l,"xdr:sp/xdr:spPr")[0];if(u){m={};let g=u["a:solidFill"];if(g&&g["a:schemeClr"]?.a$?.val){let w=g["a:schemeClr"].a$.val.match(/accent(\\d+)/);if(w&&(m.fill={theme:Number(w[1])+3},g["a:schemeClr"]["a:lumOff"]?.a$?.val)){let A=Number(g["a:schemeClr"]["a:lumOff"].a$.val);isNaN(A)||(m.fill.tint=A/1e5)}}}let f=M.FindAll(l,"xdr:sp/xdr:txBody")[0];if(f){let g=[],w=M.FindAll(f,"a:p");for(let A of w){let _=[],b,N=A["a:pPr"];N&&(b={},N.a$?.algn==="r"?b.horizontal_align="right":N.a$?.algn==="ctr"&&(b.horizontal_align="center"));let $=A["a:r"];if($){Array.isArray($)||($=[$]);for(let Y of $){let W={text:Y["a:t"]||""},k=Y["a:rPr"];k&&(W.style={},k.a$?.b==="1"&&(W.style.bold=!0),k.a$?.i==="1"&&(W.style.italic=!0)),_.push(W)}}g.push({content:_,style:b})}s.push({type:"textbox",style:m,paragraphs:g,anchor:d})}}}}return s}ReadChart(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=Us.parse(t),i={type:0},s=M.FindChild(r,"c:chartSpace/c:chart/c:title");if(s){let l=M.FindChild(s,"c:tx/c:strRef/c:f");if(l)typeof l=="string"?i.title=l:l.text__&&(i.title=l.text__);else{let d=M.FindAll(s,"c:tx/c:rich/a:p/a:r/a:t");i.title=\'"\'+d.join("")+\'"\'}}let o=(l,d)=>{let c=[],h=l["c:ser"]||[];Array.isArray(h)||(h=[h]);for(let m of h){let u=c.length,f=m["c:order"];f&&(u=Number(f.__val||0)||0);let g={},w=M.FindChild(m,"c:tx/c:v");if(w){let A=w;A&&(g.title=`"${A}"`)}else w=M.FindChild(m,"c:tx/c:strRef/c:f"),w&&(g.title=w);if(d===4||d===7){let A=M.FindChild(m,"c:xVal/c:numRef/c:f");A&&(g.categories=A);let _=M.FindChild(m,"c:yVal/c:numRef/c:f");if(_&&(g.values=_),d===7){let b=M.FindChild(m,"c:bubbleSize/c:numRef/c:f");b&&(g.bubble_size=b)}}else{let A=M.FindChild(m,"c:val/c:numRef/c:f");A&&(g.values=A);let _=M.FindChild(m,"c:cat/c:strRef/c:f");_||(_=M.FindChild(m,"c:cat/c:numRef/c:f")),_&&(g.categories=_)}c[u]=g}return c},a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:barChart");return a&&(i.type=2,a["c:barDir"]&&a["c:barDir"].__val==="col"&&(i.type=1),i.series=o(a)),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:lineChart"),a&&(i.type=3,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:doughnutChart"),a&&(i.type=5,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:pieChart"),a&&(i.type=6,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:scatterChart"),a&&(i.type=4,i.series=o(a,4))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:bubbleChart"),a&&(i.type=7,i.series=o(a,7),console.info("Bubble series?",i.series))),a||console.info("Chart type not handled"),i}GetNamedRanges(){return this.named}};var ir=ve(An()),Cn=ve(nt()),ze=class{records;text=new Map;constructor(e){this.records=ir.default.parse(e)}Has(e){return this.text.has(e)||!!this.records?.[e]}ArrayBuffer(){let e={};if(this.records)for(let[r,i]of Object.entries(this.records))e[r]=new Uint8Array(i);let t=new TextEncoder;for(let[r,i]of this.text.entries())e[r]=t.encode(i);return ir.default.encode(e)}SetBinary(e,t,r){if(r==="base64"){let i=Cn.default.toByteArray(t);this.records[e]=i}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 ye=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n`,sr=n=>{if(Te(n))return{a$:{rgb:"FF"+n.text.substring(1)}};if(Pe(n))return{a$:{theme:Se(n),tint:n.tint}}},At=class{zip;xmloptions={format:!0,attributesGroupName:"a$",textNodeName:"t$",ignoreAttributes:!1,suppressEmptyNode:!0};xmlbuilder1=Or(this.xmloptions);xmlparser2=new In.XMLParser(dt);parser=new $e;decorated_functions={};Init(e={}){for(let r of Object.keys(e))this.decorated_functions[r.toLowerCase()]=e[r];let t=vn.toByteArray(dr);this.zip=new ze(t)}WriteRels(e,t,r=!1){if(!this.zip)throw new Error("missing zip");let i=Object.keys(e),s={Relationships:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/relationships"},Relationship:i.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=ye+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=u=>{let f={};return u.indexed!==void 0&&(f.indexed=u.indexed),u.theme!==void 0&&(f.theme=u.theme),u.tint!==void 0&&(f.tint=u.tint),u.argb!==void 0&&(f.rgb=u.argb),f},r=e.cell_xfs.map(u=>{let f={a$:{numFmtId:u.number_format,fontId:u.font,fillId:u.fill,borderId:u.border}};if(u.horizontal_alignment||u.vertical_alignment||u.wrap_text||u.indent){let g={};u.horizontal_alignment&&(g.horizontal=u.horizontal_alignment),u.vertical_alignment&&(g.vertical=u.vertical_alignment),u.wrap_text&&(g.wrapText=1),u.indent&&u.horizontal_alignment!=="center"&&(g.indent=u.indent),f.alignment={a$:g}}return f}),i=u=>{if(u.color)return{indexed:u.color};if(u.rgba)return{rgb:u.rgba};if(u.theme)return{theme:u.theme,tint:u.tint}},s=e.borders.map(u=>{let f={},g={},w={},A={},_={};if(u.top.style){f.a$={style:u.top.style};let b=i(u.top);b&&(f.color={a$:b})}if(u.left.style){g.a$={style:u.left.style};let b=i(u.left);b&&(g.color={a$:b})}if(u.bottom.style){A.a$={style:u.bottom.style};let b=i(u.bottom);b&&(A.color={a$:b})}if(u.right.style){w.a$={style:u.right.style};let b=i(u.right);b&&(w.color={a$:b})}if(u.diagonal.style){_.a$={style:u.diagonal.style};let b=i(u.diagonal);b&&(_.color={a$:b})}return{left:g,right:w,top:f,bottom:A,diagonal:_}}),o=e.fills.map(u=>({patternFill:{a$:{patternType:u.pattern_gray!==void 0?`gray${u.pattern_gray}`:u.pattern_type},bgColor:u.bg_color?{a$:t(u.bg_color)}:void 0,fgColor:u.fg_color?{a$:t(u.fg_color)}:void 0}})),a=u=>{if(!(typeof u>"u"))return{a$:{val:u}}},l=e.fonts.map(u=>({b:u.bold?"":void 0,i:u.italic?"":void 0,u:u.underline?"":void 0,strike:u.strike?"":void 0,sz:a(u.size),family:a(u.family),name:a(u.name),scheme:a(u.scheme),color:u.color_argb?{a$:{rgb:u.color_argb}}:u.color_theme?{a$:{theme:u.color_theme,tint:u.color_tint}}:void 0})),d=(u,f)=>{if(f.length)return{a$:{count:f.length},[u]:f}},c=e.dxf_styles.map(u=>{let f={fill:u.fill?{patternFill:{bgColor:sr(u.fill)}}:void 0};return(u.text||u.bold||u.italic||u.underline)&&(f.font={b:u.bold?{}:void 0,i:u.italic?{}:void 0,u:u.underline?{}:void 0,strike:u.strike?{}:void 0,color:sr(u.text)}),f}),h={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"},numFmts:e.number_formats.length?{a$:{count:e.number_formats.length},numFmt:e.number_formats.map(u=>({a$:{numFmtId:u.id,formatCode:u.format}}))}:void 0,fonts:d("font",l),fills:d("fill",o),borders:d("border",s),cellXfs:d("xf",r),dxfs:d("dxf",c)}},m=ye+this.xmlbuilder1.build(h);this.zip?.Set("xl/styles.xml",m)}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(i=>({t:i}))]}},r=ye+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 i=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.row_style){let a=e.row_style[r];typeof a=="number"&&(a=i[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(Fe.Composite(s));return t.EnsureStyle(o)}ColumnStyle(e,t,r){let i=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.column_style){let a=e.column_style[r];typeof a=="number"&&(a=i[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(Fe.Composite(s));return t.EnsureStyle(o)}StyleFromCell(e,t,r,i,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[i];typeof d=="number"&&(d=o[d]),d&&a.push(d)}a.push(s);let l=t.StyleOptionsFromProperties(Fe.Composite(a));return t.EnsureStyle(l)}NormalizeAddress(e,t){let r=e.type==="address"?[e]:[e.start,e.end];for(let i of r)i.absolute_row=!0,i.absolute_column=!0,i.sheet||(i.sheet=t.name);return e.type==="range"&&(e.end.sheet=void 0),e.label=this.parser.Render(e),e}EnsureRange(e){return e.type==="range"?e:{type:"range",start:e,end:e,label:e.label,id:e.id,position:e.position}}AnnotationLayoutToAnchor(e,t){let r=i=>{let s=t.column_width&&t.column_width[i.address.column]?t.column_width[i.address.column]:t.default_column_width||100,o=t.row_height&&t.row_height[i.address.row]?t.row_height[i.address.row]:t.default_row_height||20;return{...i.address,row_offset:Math.round(i.offset.y*o),column_offset:Math.round(i.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}},i={top:0,left:0,width:301,height:301,...e},s={...i,right:i.left+i.width,bottom:i.top+i.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 i=r.data.src,s=i.match(/^data:image\\/([^;]*?);base64,/);if(s){let o=i.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=(i,s,o)=>{if(i.type==="range")s.data.push(this.NormalizeAddress(i,e));else if(i.type==="call"){if(/group/i.test(i.name))for(let a of i.args||[])r(a,s,o?o+" (recurse)":void 0);else if(/series/i.test(i.name)){let[a,l,d,c]=i.args;d&&(d.type==="range"||d.type==="address")?(s.data.push(this.EnsureRange(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"||l.type==="address")&&(s.labels2[s.data.length-1]=this.EnsureRange(this.NormalizeAddress(l,e))),c&&(c.type==="range"||c.type==="address")&&(s.labels3||(s.labels3=[]),s.labels3[s.data.length-1]=this.EnsureRange(this.NormalizeAddress(c,e)))):console.info("invalid series missing Y",{y:d,arg:i,ref:o})}}};for(let i of e.annotations||[]){let s=this.parser.Parse(i.formula||"");if(s.expression&&s.expression.type==="call"){let o="";switch(s.expression.name.toLowerCase()){case"line.chart":o="scatter";break;case"bubble.chart":o="bubble";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"||o==="bubble"){let a={type:o,data:[]},l=o==="scatter2"||o==="bubble"?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"||o==="bubble")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 m of h.args)m.type==="range"?a.data.push(this.NormalizeAddress(m,e)):m.type==="call"&&/series/i.test(m.name)&&m.args[2]&&m.args[2].type==="range"&&a.data.push(this.NormalizeAddress(m.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"&&o!=="bubble"&&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=i.rect;i.layout?t.push({anchor:this.AnnotationLayoutToAnchor(i.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 i=t.table?.name||"";return this.parser.Render(r.expression,{missing:"",long_structured_references:!0,table_name:i})}else return console.warn("parsing function failed"),console.warn(e),e.substring(1)}Export(e){let t=0,r=[];for(let _=0;_<e.sheet_data.length;_++){let b=e.sheet_data[_],N=b.id||0;N&&(r[N]=b.name||""),N===e.active_sheet&&(t=_)}let i=new Me,s=new Ee,o=new we,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),Qe.next_drawing_index=1,We.next_chart_index=1;let l=[],d=[];for(let _=0;_<e.sheet_data.length;_++){let b=e.sheet_data[_],N={},$={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=b.default_row_height?b.default_row_height/20*15:15,W=b.styles||b.cell_style_refs||[],k=new at;k.FromJSON(b.data,W);for(let x of b.cell_styles){let E=k.EnsureCell(x);E.style||(E.style=W[x.ref])}let q={start:{row:k.rows+1,column:k.columns+1},end:{row:k.rows+1,column:k.columns+1}},X=[],B=[],K=[],D=[],O=[],ee=[],G=this.SheetStyle(b,s);for(let x=0;x<k.data.length;x++){let E=this.RowStyle(b,s,x);if(k.data[x]&&k.data[x].length){x<q.start.row&&(q.start.row=x);let R={start:-1,end:-1},F=[];for(let T=0;T<k.data[x].length;T++){ee[T]||(ee[T]=this.ColumnStyle(b,s,T));let P=k.data[x][T];if(P){if(P.table&&P.table.area.start.row===x&&P.table.area.start.column===T){let ae=new j(P.table.area.start,P.table.area.end),Ke=d.length+1,Sn=`../tables/table${Ke}.xml`,It=[];for(let le=0;le<ae.columns;le++){let Q=k.data[x][T+le],xe="";Q.type!==2?(typeof Q.calculated<"u"?xe=Q.calculated.toString():typeof Q.value<"u"&&(xe=Q.value.toString()),Q.type=2,Q.value=xe):xe=Q.value||"",xe||(xe=`Column${le+1}`);let tt=xe,St=!1,Tn=1;for(;!St;){St=!0;e:for(let Pn of It)if(Pn.toLowerCase()===tt.toLowerCase()){St=!1,tt=`${xe}${++Tn}`;break e}}Q.value=tt,It.push(tt)}let et;if(P.table.totals_row){et=[];for(let le=0;le<ae.columns;le++){let Q=k.data[ae.end.row][ae.start.column+le];Q.type&&(Q.type===1?et[le]={type:"formula",value:(Q.value||"").toString().substring(1)}:(Q.type!==2&&(Q.type=2,Q.value=Q.value?.toString()||""),et[le]={type:"label",value:Q.value}))}}let Nt={rel:he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",Sn),index:Ke,ref:ae.spreadsheet_label,name:`Table${Ke}`,display_name:`Table${Ke}`,totals_row_shown:0,totals_row_count:P.table?.totals_row?1:0,columns:It,footers:et};if(P.table.totals_row){let le=new j(ae.start,{row:ae.end.row-1,column:ae.end.column});Nt.filterRef=le.spreadsheet_label}O.push(Nt),d.push(Nt)}if(P.merge_area&&P.merge_area.start.row===x&&P.merge_area.start.column===T&&D.push(new j(P.merge_area.start,P.merge_area.end)),P.hyperlink){let ae=he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",P.hyperlink,"External");B.push({rel:ae,target:P.hyperlink,address:{row:x,column:T}})}if(P.type===1&&/^=?sparkline\\./i.test(P.value)){K.push({address:{row:x,column:T},formula:P.value,style:P.style});continue}T<q.start.column&&(q.start.column=T),R.start<0&&(R.start=T),R.end=T;let J=this.StyleFromCell(b,s,x,T,P.style);if(P.type===0&&(E&&J===E||!E&&ee[T]&&J===ee[T]))continue;let V,de,fe;switch(P.type){case 1:switch(fe=this.FormulaText(P.value,P),P.calculated_type){case 2:V=P.calculated,de="str";break;case 3:V=P.calculated;break;case 4:V=P.calculated?1:0,de="b";break}break;case 2:V=i.Ensure(P.value),de="s";break;case 3:V=P.value;break;case 4:V=P.value?1:0,de="b";break}P.area&&P.area.start.row===x&&P.area.start.column===T&&typeof fe=="string"&&(fe={t$:fe,a$:{t:"array",ref:P.area.spreadsheet_label}}),F.push({a$:{r:j.CellAddressToLabel({row:x,column:T}),t:de,s:J},f:fe,v:V})}}if(F.length||E&&E!==G){let T,P,J,V;b.row_height&&typeof b.row_height[x]=="number"&&b.row_height[x]!==b.default_row_height&&(T=1,P=b.row_height[x]*3/4),E&&E!==G&&(J=E,V=1),X.push({a$:{r:x+1,spans:`${R.start+1}:${R.end+1}`,customHeight:T,ht:P,s:J,customFormat:V},c:F})}}}let se=[];for(let x=0;x<b.columns;x++){let E={index:x};b.column_width&&b.default_column_width&&typeof b.column_width[x]=="number"&&b.column_width[x]!==b.default_column_width&&(E.width=it(b.column_width[x]));let R=ee[x];R&&R!==G&&(E.style=R),(E.style!==void 0||E.width!==void 0)&&(se[x]=E)}let te;if(se.length||G){let x=[],E=it(b.default_column_width||90);{let R=0;for(let F of se)F&&(G&&F.index>R+1&&x.push({a$:{min:R+1,max:F.index,style:G,width:E}}),x.push({a$:{min:F.index+1,max:F.index+1,style:F.style===void 0?G:F.style,width:F.width===void 0?E:F.width,customWidth:F.width===void 0?void 0:1}}),R=F.index);G&&R<16384&&x.push({a$:{min:R+1,max:16384,style:G,width:E}}),te={col:x}}}let y;b.data_validations?.length&&(y={a$:{count:b.data_validations.length},dataValidation:b.data_validations.map(x=>{let E=x.target.map(F=>new j(F.start,F.end).spreadsheet_label).join(" "),R;if(x.type==="range"){let F={id:0,type:"range",label:"",position:0,start:{...x.area.start,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"},end:{...x.area.end,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"}};typeof x.area.start.sheet_id<"u"&&(F.start.sheet=r[x.area.start.sheet_id]),R=this.parser.Render(F)}else x.type==="list"&&(R=`"${x.list.join(",")}"`);return{a$:{type:"list",allowBlank:1,showInputMessage:1,showErrorMessage:1,sqref:E},formula1:R}})});let Z;O.length&&(Z={a$:{count:O.length},tablePart:O.map(x=>({a$:{"r:id":x.rel||""}}))});for(let x of O){let E={};x.totals_row_count&&(E.totalsRowCount=1);let R={a$:{count:(x.columns||[]).length},tableColumn:(x.columns||[]).map((P,J)=>{let V=(x.footers||[])[J];return{a$:{id:J+1,name:P||`Column${J+1}`,totalsRowLabel:V?.type==="label"?V.value:void 0,totalsRowFunction:V?.type==="formula"?"custom":void 0},totalsRowFormula:V?.type==="formula"?V.value:void 0}})},F={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:x.index||0,name:x.name,displayName:x.display_name,...E,ref:x.ref},autoFilter:{a$:{ref:x.filterRef||x.ref}},tableColumns:R,tableStyleInfo:{a$:{name:"TableStyleMedium2",showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}}}},T=ye+this.xmlbuilder1.build(F);this.zip?.Set(`xl/tables/table${x.index}.xml`,T)}let S;if(b.conditional_formats?.length){let x=[],E=1,R={},F=Object.entries(wt).map(T=>(R[T[1]]=T[0],T[1]));F.sort((T,P)=>P.length-T.length);for(let T of b.conditional_formats){let P=0;switch(T.type!=="gradient"&&(P=s.dxf_styles.length,s.dxf_styles.push(T.style)),T.type){case"cell-match":{let J="",V="";for(let de of F)if(new RegExp("^"+de+"\\\\s").test(T.expression)){J=R[de],V=T.expression.substring(de.length).trim();break}J&&x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"cellIs",dxfId:P,operator:J,priority:E++},formula:V}})}break;case"expression":x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"expression",dxfId:P,priority:E++},formula:T.expression}});break;case"duplicate-values":x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:T.unique?"uniqueValues":"duplicateValues",dxfId:P,priority:E++}}});break;case"gradient":{let J=[],V=[];for(let fe of T.stops){fe.value===0?J.push({a$:{type:"min"}}):fe.value===1?J.push({a$:{type:"max"}}):J.push({a$:{type:"percentile",val:fe.value*100}});let ae=sr(fe.color);ae&&V.push(ae)}let de={a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"colorScale",priority:E++},colorScale:{cfvo:J,color:V}}};x.push(de)}break}}x.length&&(S=x.length>1?x:x[0])}let C;D.length&&(C={a$:{count:D.length},mergeCell:D.map(x=>({a$:{ref:x.spreadsheet_label}}))});let I;B.length&&(I={hyperlink:B.map(x=>({a$:{"r:id":x.rel,ref:new j(x.address).spreadsheet_label,"xr:uid":"{0C6B7792-7EA0-4932-BF15-D49C453C565D}"}}))});let v;if(K.length){let x={a$:{"xmlns:xm":"http://schemas.microsoft.com/office/excel/2006/main"},"x14:sparklineGroup":K.map(E=>{let R=this.parser.Parse(E.formula),F="";if(R.expression&&R.expression.type==="call"&&R.expression.args.length>0){let T=R.expression.args[0];if(T.type==="range"||T.type==="address"){let P=T.type==="range"?T.start:T;P.sheet||(typeof P.sheet_id<"u"?P.sheet=r[P.sheet_id]:P.sheet=b.name),F=this.parser.Render(T)}}return{a$:{displayEmptyCellsAs:"gap",type:/column/i.test(E.formula)?"column":void 0},"x14:colorSeries":{a$:{rgb:"FF376092"}},"x14:sparklines":{"x14:sparkline":{"xm:f":F,"xm:sqref":new j(E.address).spreadsheet_label}}}})};v={ext:{a$:{uri:"{05C60535-1F16-4fd2-B633-F4F36F0B64E0}","xmlns:x14":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"},"x14:sparklineGroups":x}}}let L,z=this.ParseCharts(b),oe=this.ParseImages(b);if(z.length||oe.length){let x=new Qe;for(let F of z)x.AddChart(F.options,F.anchor);for(let F of oe)x.AddImage(F.options,F.anchor);for(let{image:F}of x.images)F.options.data&&this.zip?.SetBinary(`xl/media/image${F.index}.${F.extension}`,F.options.data,F.options.encoding);for(let{chart:F}of x.charts){let T=F.toJSON(),P=ye+this.xmlbuilder1.build(T);this.zip?.Set(`xl/charts/chart${F.index}.xml`,P),this.WriteRels(F.relationships,`xl/charts/_rels/chart${F.index}.xml.rels`)}this.WriteRels(x.relationships,`xl/drawings/_rels/drawing${x.index}.xml.rels`);let E=ye+this.xmlbuilder1.build(x.toJSON());this.zip?.Set(`xl/drawings/drawing${x.index}.xml`,E),l.push(x),L={a$:{"r:id":he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",`../drawings/drawing${x.index}.xml`)}}}let ue={a$:{"x14ac:dyDescent":.25,defaultRowHeight:Y===15?void 0:Y,customHeight:Y===15?void 0:1,defaultColWidth:b.default_column_width?it(b.default_column_width):void 0}},Be={worksheet:{a$:{...$},dimension:{a$:{ref:new j(q.start,q.end).spreadsheet_label}},sheetViews:{sheetView:{a$:{workbookViewId:0}}},sheetFormatPr:ue,cols:te,sheetData:{row:X},mergeCells:C,conditionalFormatting:S,dataValidations:y,hyperlinks:I,pageMargins:{a$:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3}},drawing:L,tableParts:Z,extLst:v}},qe=ye+this.xmlbuilder1.build(Be);this.zip?.Set(`xl/worksheets/sheet${_+1}.xml`,qe),Object.keys(N).length&&this.WriteRels(N,`xl/worksheets/_rels/sheet${_+1}.xml.rels`)}this.WriteSharedStrings(i),this.WriteStyleCache(s);let c={};he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles","styles.xml"),he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme","theme/theme1.xml"),he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings","sharedStrings.xml");let h=e.sheet_data.map((_,b)=>he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",`worksheets/sheet${b+1}.xml`));this.WriteRels(c,"xl/_rels/workbook.xml.rels");let m=e.named?.length?{definedName:(e.named||[]).map(_=>{let b;if(_.scope){let N=_.scope.toLowerCase();for(let[$,Y]of e.sheet_data.entries())if(Y.name?.toLowerCase()===N){b=$.toString();break}}return{a$:{name:_.name,localSheetId:b},t$:_.expression}})}:void 0,u={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((_,b)=>({a$:{name:_.name||`Sheet${b+1}`,sheetId:b+1,"r:id":h[b],state:_.visible===!1?"hidden":void 0}}))},definedNames:m}},f=ye+this.xmlbuilder1.build(u);this.zip?.Set("xl/workbook.xml",f);let g={};for(let _ of l)for(let b of _.images)switch(b.image.extension){case"gif":case"png":case"jpeg":g[b.image.extension]="image/"+b.image.extension;break;case"svg":g.svg="image/svg+xml";break}let w={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(_=>({a$:{Extension:_,ContentType:g[_]}}))],Override:[{a$:{PartName:"/xl/workbook.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"}},...e.sheet_data.map((_,b)=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",PartName:`/xl/worksheets/sheet${b+1}.xml`}})),...l.reduce((_,b)=>_.concat([...b.charts.map(N=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",PartName:`/xl/charts/chart${N.chart.index}.xml`}})),{a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawing+xml",PartName:`/xl/drawings/drawing${b.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(_=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",PartName:`/xl/tables/table${_.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"}}]}},A=ye+this.xmlbuilder1.build(w);this.zip?.Set("[Content_Types].xml",A)}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 Nn=ve(nt());var Ct=class{parser=new $e;workbook;zip;Init(e){this.zip=new ze(e),this.workbook=new _t(this.zip),this.workbook.Init()}SheetCount(){return this.workbook?.sheet_count||0}ParseCell(e,t,r,i,s,o){let a=t.a$?.r;if(!a){console.warn("cell missing address");return}let l=e.TranslateAddress(a);if(Ae(l)){console.warn("cell has range address");return}let d,c="undefined",h,m="undefined";if(t.a$?.t&&t.a$.t==="s"){if(c="string",typeof t.v<"u"){let g=Number(t.v);!isNaN(g)&&e.shared_strings&&(d=e.shared_strings.Get(g)||"",d[0]==="="&&(d="\'"+d))}}else if(typeof t.f<"u"){c="formula";let g=(typeof t.f=="string"?t.f:t.f.t$)||"";if(g){d="="+g.replace(/^_xll\\./g,"");let w=this.parser.Parse(g);w.expression&&(this.parser.Walk(w.expression,A=>(A.type==="call"&&(/^_xll\\./.test(A.name)?A.name=A.name.substring(5):/^_xlfn\\./.test(A.name)&&(A.name=A.name.substring(6))),!0)),d="="+this.parser.Render(w.expression,{missing:""})),typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si&&(r[t.f.a$.si]={row:l.row-1,column:l.col-1,formula:d,parse_result:this.parser.Parse(d)})}else if(typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si){let w=r[t.f.a$.si];w&&(w.parse_result.expression?d="="+this.parser.Render(w.parse_result.expression,{offset:{rows:l.row-1-w.row,columns:l.col-1-w.column},missing:""}):d=w.formula)}if(typeof t.f!="string"&&t.f.a$?.t==="array"){let w=e.TranslateAddress(t.f.a$.ref||"");Ae(w)&&i.push(tr(w,-1,-1))}if(typeof t.v<"u"){let w=typeof t.v=="object"?t.v?.t$:t.v,A=Number(w.toString());isNaN(A)?(m="string",h=w.toString()):(m="number",h=A)}}else if(typeof t.v<"u"){let g=Number(t.v.toString());isNaN(g)?(c="string",d=t.v.toString()):(c="number",d=g)}let u={row:l.row-1,col:l.col-1};for(let g of i)yt(g,u)&&(u.row!==g.from.row||u.col!==g.from.col)&&(m=c,h=d,d=void 0,c="undefined");let f={row:u.row,column:u.col,value:d,type:c};typeof h<"u"&&(f.calculated_type=m,f.calculated=h),t.a$?.s&&(f.style_ref=Number(t.a$.s));for(let g of o)g.address.row===l.row&&g.address.col===l.col&&(f.hyperlink=g.reference);for(let g of s)yt(g,u)&&(f.merge_area={start:{row:g.from.row,column:g.from.col},end:{row:g.to.row,column:g.to.col}});for(let g of i)yt(g,u)&&(f.area={start:{row:g.from.row,column:g.from.col},end:{row:g.to.row,column:g.to.col}});return f}AddressToArea(e){return Ge(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),i=wt;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 s={};if(t.a$.dxfId){let a=Number(t.a$.dxfId);isNaN(a)||(s=this.workbook?.style_cache.dxf_styles[a]||{})}let o=i[t.a$.operator||""];if(!o)console.info("unhandled cellIs operator:",t.a$.operator);else return{type:"cell-match",expression:o+" "+t.formula,area:r,style:s}}break;case"containsErrors":case"notContainsErrors":case"expression":if(t.formula){typeof t.formula!="string"&&(t.formula.t$?t.formula=t.formula.t$:console.info("unexpected conditional expression",{rule:t}));let s={};if(t.a$.dxfId){let o=Number(t.a$.dxfId);isNaN(o)||(s=this.workbook?.style_cache.dxf_styles[o]||{})}return{type:"expression",expression:t.formula,area:r,style:s}}break;case"colorScale":if(t.colorScale&&Array.isArray(t.colorScale.cfvo)&&Array.isArray(t.colorScale.color)){let s=[];for(let[o,a]of t.colorScale.cfvo.entries()){let l=0,d={},c=t.colorScale.color[o];switch(c.a$.rgb?d.text="#"+c.a$.rgb.substring(2):c.a$.theme&&(d.theme=Number(c.a$.theme)||0,c.a$.tint&&(d.tint=Math.round(c.a$.tint*1e3)/1e3)),a.a$.type){case"min":l=0;break;case"max":l=1;break;case"percentile":l=(Number(a.a$.val)||0)/100;break}s.push({color:d,value:l})}return{type:"gradient",stops:s,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=[],i={},s=[],o=[],a=[],l=[],d=[],c=[],h=[],m=M.FindAll.bind(M,t.sheet_data),u=m("worksheet/conditionalFormatting");for(let y of u)if(y.a$?.sqref){let Z=y.a$.sqref.split(/\\s+/);for(let S of Z){let C=t.TranslateAddress(S);if(y.cfRule){let I=Array.isArray(y.cfRule)?y.cfRule:[y.cfRule];for(let v of I){let L=this.ParseConditionalFormat(C,v);L&&a.push(L)}}}}let f=m("worksheet/mergeCells/mergeCell");for(let y of f)if(y.a$.ref){let Z=t.TranslateAddress(y.a$.ref);Ae(Z)&&o.push(tr(Z,-1,-1))}let g=m("worksheet/dataValidations/dataValidation");for(let y of g){let Z=y.a$?.type,S=y.a$?.sqref,C=y.formula1;if(S&&C&&Z==="list"){let I,v=this.parser.Parse(S),L=[];v.expression&&(v.expression.type==="address"?L.push({start:v.expression,end:v.expression}):v.expression.type==="range"&&L.push(v.expression)),v=this.parser.Parse(C),v.expression&&(v.expression.type==="range"?I={type:"range",area:v.expression,target:L}:v.expression.type==="literal"&&(I={type:"list",target:L,list:v.expression.value.toString().split(/,/).map(z=>{let oe=Number(z);return isNaN(oe)?z.toLowerCase()==="true"?!0:z.toLowerCase()==="false"?!1:z:oe})})),L.length&&I&&c.push(I)}}let w=m("worksheet/hyperlinks/hyperlink");for(let y of w){let Z=t.TranslateAddress(y.a$?.ref||"");Ae(Z)&&(Z=Z.from);let S="",C="";if(y.a$&&y.a$["r:id"]){S="remote link";let I=t.rels[y.a$["r:id"]];I&&(C=I.target||"")}else C=y.__location||"",S=y.__display||"";l.push({address:Z,reference:C,text:S})}let A=21,_=100,b=t.sheet_data.worksheet?.sheetFormatPr;if(b){if(b.a$?.defaultColWidth){let y=Number(b.a$.defaultColWidth);isNaN(y)||(_=Pt(y))}if(b.a$?.defaultRowHeight){let y=Number(b.a$.defaultRowHeight);isNaN(y)||(A=Math.round(y*4/3))}}let N=[],$=[],Y=m("worksheet/sheetData/row");for(let y of Y){let Z=y.a$?.r?Number(y.a$.r):1,S=A;if(y.a$?.ht){let I=Number(y.a$.ht);isNaN(I)||(S=Math.round(I*4/3))}if(y.a$?.outlineLevel){let I=Number(y.a$.outlineLevel);isNaN(I)||($[Z-1]=I)}if(y.a$?.s){let I=Number(y.a$?.s);isNaN(I)||(d[Z-1]=I)}S!==A&&(N[Z-1]=S);let C=y.c||[];Array.isArray(C)||(C=[C]);for(let I of C){let v=this.ParseCell(t,I,i,s,o,l);v&&r.push(v)}}let W=[],k=-1,q=[],X=m("worksheet/cols/col");for(let y of X){let Z=Number(y.a$?.min),S=Number(y.a$?.max);if(y.a$?.style){let C=Number(y.a$.style);if(!isNaN(Z)&&!isNaN(S)&&!isNaN(C))if(t.extent&&S>=t.extent.to.col||S-Z>100)k=C;else for(let I=Z;I<=S;I++)W[I]=C}if(y.a$?.customWidth){let C=Number(y.a$.width);if(!isNaN(Z)&&!isNaN(S)&&!isNaN(C)&&S!==16384){C=Pt(C);for(let I=Z;I<=S;I++)q[I-1]=C}}}let B=m("worksheet/tableParts/tablePart");for(let y of B){let Z=y.a$?y.a$["r:id"]:void 0;if(Z){let S="",C=t.rels[Z];if(C){S=C.target||"";let I=this.workbook.ReadTable(S);if(I){let v=t.TranslateAddress(I.ref),L=Ge(v)?{start:{row:v.row-1,column:v.col-1},end:{row:v.row-1,column:v.col-1}}:{start:{row:v.from.row-1,column:v.from.col-1},end:{row:v.to.row-1,column:v.to.col-1}};for(let z of r)if(z.row===L.start.row&&z.column===L.start.column){z.table={area:L,name:I.name,totals_row:!!I.totals_row_count};break}}}}}let K=m("worksheet/drawing"),D=[],O=[],ee=[];for(let y of K){let Z=y.a$?y.a$["r:id"]:void 0;if(Z){let S="",C=t.rels[Z];if(C&&(S=C.target||""),S){let I=this.workbook.ReadDrawing(S);if(I&&I.length)for(let v of I)switch(v.type){case"chart":D.push(v);break;case"image":O.push(v);break;case"textbox":ee.push(v);break}}}}let G=y=>{let Z={address:{row:y.row,column:y.column},offset:{x:0,y:0}};if(y.row_offset){let S=N[y.row];S===void 0&&(S=A),Z.offset.y=y.row_offset/9525/S}if(y.column_offset){let S=q[y.column];S===void 0&&(S=_),Z.offset.x=y.column_offset/9525/S}return Z};for(let y of ee){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)};h.push({layout:Z,type:"textbox",data:{style:y.style,paragraphs:y.paragraphs}})}for(let y of O)if(y&&y.image){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)},S="image",C=Nn.default.fromByteArray(y.image),I="";if(y.filename&&(/jpe*g$/i.test(y.filename)?I="jpeg":/png$/i.test(y.filename)?I="png":/gif$/i.test(y.filename)&&(I="gif")),I&&C){let v="data:image/"+I+";base64,"+C;h.push({layout:Z,type:S,data:{src:v}})}}for(let y of D)if(y&&y.chart){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)},S,C=[],I="",v=y.chart?.series;switch(y.chart.type){case 7:S="treb-chart",I="Bubble.Chart",v&&v.length&&(C[0]=`Group(${v.map(z=>`Series(${[z.title||"",z.values||"",z.categories||"",z.bubble_size||""].join(", ")})`).join(", ")})`),C[1]=y.chart.title;break;case 4:S="treb-chart",I="Scatter.Line",v&&v.length&&(C[0]=`Group(${v.map(z=>`Series(${z.title||""},${z.categories||""},${z.values||""})`||"").join(", ")})`),C[1]=y.chart.title;break;case 5:case 6:I=y.chart.type===5?"Donut.Chart":"Pie.Chart",S="treb-chart",v&&v[0]&&(C[0]=v[0].values,C[1]=v[0]?.categories||""),C[2]=y.chart.title;break;case 2:case 1:case 3:switch(C[2]=y.chart.title,S="treb-chart",y.chart.type){case 2:I="Bar.Chart";break;case 1:I="Column.Chart";break;default:I="Line.Chart"}v&&(v.length>1?C[0]=`Group(${v.map(z=>`Series(${z.title||""},,${z.values||""})`||"").join(", ")})`:v.length===1&&(v[0].title?C[0]=`Series(${v[0].title||""},,${v[0].values||""})`:C[0]=v[0].values),C[1]=v[0]?.categories||"");break}let L=`=${I}(${C.join(", ")})`;S&&L&&h.push({layout:Z,type:S,formula:L})}let se=m("worksheet/extLst/ext");for(let y of se){let Z="";for(let C of Object.keys(y?.a$||{})){let I=C.match(/^xmlns:(.*)$/);if(I){Z=I[1];break}}let S=M.FindAll(y,`${Z}:sparklineGroups/${Z}:sparklineGroup`);for(let C of S){let I="Sparkline.line",v="",L="";C.a$?.type==="column"&&(I="Sparkline.column");let z=M.FindAll(C,`${Z}:sparklines/${Z}:sparkline`);for(let oe of z)for(let ue of Object.keys(oe))/:f$/.test(ue)?L=oe[ue]:/:sqref$/.test(ue)&&(v=oe[ue]);if(L&&v){let oe=`=${I}(${L})`,ue=t.TranslateAddress(v);if(Ge(ue)){let Be={row:ue.row-1,column:ue.col-1,value:oe,type:"formula"},qe=!1;for(let x of r)if(x.row===Be.row&&x.column===Be.column){qe=!0,x.type="formula",x.value=oe;break}qe||r.push(Be)}}}}let te={name:t.options.name,cells:r,default_column_width:_,column_widths:q,row_heights:N,row_styles:d,annotations:h,conditional_formats:a,data_validations:c,styles:this.workbook?.style_cache?.CellXfToStyles()||[]};return $.length&&(te.outline=$),(t.visible_state===1||t.visible_state===2)&&(te.hidden=!0),k>=0&&(te.sheet_style=k),W.length&&(te.column_styles=W),te}};var vt=self,ar=new At,Ls=n=>{n.sheet&&(ar.Init(n.decorated||[]),ar.Export(n.sheet),vt.postMessage({status:"complete",blob:ar.Blob()}))},Vs=n=>{let e=new Ct;try{e.Init(n.data);let t=e.workbook?.GetNamedRanges(),r=e.SheetCount(),i={sheets:[],named:t,active_tab:e.workbook?.active_tab};for(let s=0;s<r;s++){let o=e.GetSheet(s);o&&i.sheets.push(o)}for(let s of t||[])if(typeof s.local_scope=="number"){let o=i.sheets[s.local_scope];o&&(s.scope=o.name)}vt.postMessage({status:"complete",results:i})}catch(t){console.warn("error importing xlsx file"),console.info(t),vt.postMessage({status:"error",data:t})}};vt.addEventListener("message",n=>{n.data&&n.data.command==="export"?Ls(n.data):n.data&&n.data.command==="import"&&Vs(n.data)});\n';var lr=class c{static treb_base_path="";static treb_embedded_script_path="";static one_time_warnings={};DOM=P.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return N}language_model;events=new le;calculation=0;file_version=0;last_save_version=0;initial_load_source=void 0;calculator;grid;model;dialog;spinner;file_chooser;file_chooser_operation=0;get parser(){return this.model.parser}view_node;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;get active_sheet(){let e=this.grid.active_sheet.name;return xe.test(e)?`'${e}'`:e}get modified(){return this.undo_stack.length!==1}get document_name(){return this.grid.model.document_name}set document_name(e){this.grid.model.document_name=e,this.DocumentChange()}get user_data(){return this.grid.model.user_data}set user_data(e){this.grid.model.user_data=e,this.DocumentChange()}get scale(){return this.grid.scale}set scale(e){this.grid.scale=e}get headless(){return this.grid.headless}set headless(e){this.grid.headless!==e&&(this.grid.headless=e,e||(this.grid.Update(!0),this.RebuildAllAnnotations()))}get state(){return this.file_version}get can_revert(){return!this.options.inline_document&&!this.options.document?!1:this.initial_load_source==="local-storage"?!0:this.dirty}get dirty(){return this.file_version!==this.last_save_version}set dirty(e){e?this.file_version++:this.last_save_version=this.file_version}get sheet_names(){return this.model.sheets.list.map(e=>e.name)}constructor(e){e.storage_key&&!e.local_storage&&(e.local_storage=e.storage_key),this.options={...dn,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(ie.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",()=>{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 o={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&&(o.initial_scale=this.options.scale),this.options.stats&&(o.stats=this.options.stats,o.tab_bar=!0),this.options.scale_control&&(o.scale_control=!0,o.tab_bar=!0,this.options.persist_scale&&(o.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),o.persist_scale_key))){let a=localStorage.getItem(o.persist_scale_key);if(a)try{let s=JSON.parse(a);o.initial_scale=s.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 it,this.model.sheets.Add(X.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,e)),n&&(this.DOM=P.GetInstance(n.ownerDocument)),this.grid=new lt(o,this.model,void 0,!!n,this.DOM),this.options.headless&&(this.grid.headless=!0),n){this.DOM=P.GetInstance(n.ownerDocument),this.parent_view||(ee.is_windows?n.parentElement?.classList.add("treb-ua-windows"):ee.is_mac&&n.parentElement?.classList.add("treb-ua-osx"));let a=n.querySelector(".treb-view-template");this.view_node=a.content.firstElementChild?.cloneNode(!0),n.prepend(this.view_node),this.view_node.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=l=>this.HandleKeyDown(l),n.addEventListener("keydown",this.key_listener);let s=!!(r||this.options.document);this.grid.Initialize(this.view_node,s),this.options.dnd&&(this.view_node.addEventListener("dragenter",l=>this.HandleDrag(l)),this.view_node.addEventListener("dragover",l=>this.HandleDrag(l)),this.view_node.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(),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.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),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(e.preload&&e.preload.call(0,this),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 a=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(a)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),n&&this.options.spinner&&(this.spinner=new rr(n)),t&&!e.model&&!r&&this.LoadNetworkDocument(t,this.options),n&&(this.dialog=new tr(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 er(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_node?.parentElement&&(t.key_listener&&t.view_node.parentElement.removeEventListener("keydown",t.key_listener),t.view_node.parentElement.removeChild(t.view_node)),this.view_node?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view_node?.addEventListener("focusin",()=>{this.focus_target!==e&&(this.Publish({type:"focus-view"}),this.focus_target=e)}),e.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(this.grid.EnsureActiveSheet(),this.grid.UpdateLayout(),this.grid.UpdateTabBar())}),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.UpdateTabBar())});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){return this.grid.AddConditionalFormat(e),e}RemoveConditionalFormat(e){this.grid.RemoveConditionalFormat({format:e})}RemoveConditionalFormats(e){if(e===void 0){let r=this.GetSelectionReference();if(r.empty)throw new Error("invalid range (no selection)");e=r.area}let t=this.model.ResolveArea(e,this.grid.active_sheet);this.grid.RemoveConditionalFormat({area:t})}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 o=n.area.spreadsheet_label;this.InsertAnnotation(`=${i}(${o},,"${o}")`,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),o=Number(e.scale||1);if(o&&!isNaN(o)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:o}},!0);let a=[];for(let s=n.start.row;s<=n.end.row;s++)a.push(s);this.selection_state?.merge||this.grid.SetRowHeight(a,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=z.Get(this.selection_state.style.number_format||"General");if(i.date_format)break;let n=new ie(i.pattern);if(i.magic_decimal){let o=0,a=this.GetRange();Array.isArray(a)||(a=[[a]]);e:for(let s=0;s<a.length;s++)for(let l=0;l<a[s].length;l++){let d=a[s][l];if(typeof d<"u"&&ae(d)){let h=z.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"&&(o=u.parts[1].length),m.parts&&typeof m.parts[1]=="string"&&(o=Math.max(o,m.parts[1].length));break e}else if(typeof d=="number"){let h=i.BaseFormat(d);h.parts&&typeof h.parts[1]=="string"&&(o=h.parts[1].length);break e}}e.command==="increase-precision"?n.SetDecimal(o+1):n.SetDecimal(Math.max(0,o-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:s.length-1,column:s[0].length-1}),r);if(l.length===1&&(r.Resize(s.length,s[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<s.length;h++)for(let u=0;u<s[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),s[h][u]){let f=this.SetInferredType({area:m,target:m.start,empty:!1},s[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:12,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 o=0;o<t.columns;o++)r.push(o)}typeof r=="number"&&(r=[r]);let i=typeof e.width!="number",n=Math.round(e.width||0/this.scale);if(i)for(let o of r)this.AutoSizeColumn(t,o,!0);else for(let o of r)t.SetColumnWidth(o,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 s=0;s<r.rows;s++)i.push(s)}typeof i=="number"&&(i=[i]);let n=typeof e.shrink=="boolean"?e.shrink:!0,o=typeof e.height!="number",a=Math.round(e.height||0/this.scale);if(o)for(let s of i)r.GetRowHeight(s)||(t?t.ConsumeAddress({row:s,column:1}):t=new y({row:s,column:1/0,sheet_id:r.id})),r.AutoSizeRow(s,this.theme.grid_cell,n);else for(let s of i){let l=r.GetRowHeight(s);(!l&&a||l&&!a)&&(t?t.ConsumeAddress({row:s,column:1}):t=new y({row:s,column:1/0,sheet_id:r.id})),r.SetRowHeight(s,a)}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:22,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 Gt=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 We=class extends Gt{dirty=!1};var Di={error:"NOTIMPL"},de=()=>({type:6,value:"N/A"}),Se=()=>({type:6,value:"EXPR"});var fe=()=>({type:6,value:"DIV/0"}),F=()=>({type:6,value:"ARG"}),E=()=>({type:6,value:"VALUE"}),Z=()=>({type:6,value:"REF"}),Ur=()=>({type:6,value:"NAME"}),$t=()=>({type:6,value:"UNK"});var Re=class c extends We{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=W(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 Fe=class c extends We{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 Ot=class{vertices=[[]];volatile_list=[];calculation_list=[];loop_hint;leaf_vertices=new Set;dirty_list=[];loop_check_required=!1;IsSpreadsheetVertex(e){return e.type===Re.type}FlushTree(){this.dirty_list=[],this.volatile_list=[],this.vertices=[[]],this.leaf_vertices.clear(),Fe.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 Re;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,Fe.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 a=Fe.GetContainingArrays(e);for(let s of a)this.SetVertexDirty(s)}return}let o=[];if(i&&(o=Array.from(n.edges_in)),n.ClearDependencies(),t&&this.SetVertexDirty(n),i){n.has_outbound_edges||this.RemoveVertex(e);for(let a of o)if(!a.has_inbound_edges&&!a.has_outbound_edges){let s=a;s.address&&this.RemoveVertex(s.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 o of n)o&&(o.color=o.edges_out.size?0:2,t.push(o))}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],o=!0;if(n.color!==2)for(let a of n.edges_out){if(a.color===1)return this.loop_hint=this.RenderAddress(i.address),console.info("loop detected @",this.loop_hint),!0;a.color===0&&(r.push(a),o=!1)}o&&(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}CompositeAddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let[r,i]=Fe.GetVertex(e);if(t.DependsOn(r),this.loop_check_required=!0,!i)return;let n=this.vertices[e.start.sheet_id];if(n){if(e.entire_row){for(let o=0;o<n.length;o++)if(n[o])for(let a=e.start.row;a<=e.end.row;a++){let s=n[o][a];s&&r.DependsOn(s)}}else if(e.entire_column){for(let o=e.start.column;o<=e.end.column;o++)if(n[o])for(let a of n[o])a?.address&&r.DependsOn(a)}else for(let o=e.start.row;o<=e.end.row;o++)for(let a=e.start.column;a<=e.end.column;a++)if(n[a]){let s=n[a][o];s&&r.DependsOn(s)}}}AddLeafVertexArrayEdge(e,t){this.CompositeAddArrayEdge(e,t)}AddArrayEdge(e,t){if(!e.start.sheet_id)throw new Error("AddArrayEdge called without sheet ID");let r=this.GetVertex(t,!0);this.CompositeAddArrayEdge(e,r)}AddEdge(e,t){let r=this.GetVertex(e,!0);this.GetVertex(t,!0).DependsOn(r),r.reference&&r.reference.area&&!r.array_head&&this.AddEdge({...e,row:r.reference.area.start.row,column:r.reference.area.start.column},t),this.loop_check_required=!0}RemoveEdge(e,t){let r=this.GetVertex(e,!1),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 bo=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 go=c=>{let{r:e,theta:t}=c,r=e*Math.cos(t),i=e*Math.sin(t);return{real:r,imaginary:i}},Zt=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}},he=(c,e)=>({real:c.real*e.real-c.imaginary*e.imaginary,imaginary:c.real*e.imaginary+c.imaginary*e.real}),_o=(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}},Fr=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let o=0;for(let a=0;a<c.n;a++)o+=c.array[r][a]*e.array[a][n];i.push(o)}t.push(i)}return{array:t,m:c.m,n:e.n}},Ui=(c,e)=>{let t=[];for(let r=0;r<c.m;r++){let i=[];for(let n=0;n<e.n;n++){let o={real:0,imaginary:0};for(let a=0;a<c.n;a++)o.real+=c.array[r][a].real*e.array[a][n].real-c.array[r][a].imaginary*e.array[a][n].imaginary,o.imaginary+=c.array[r][a].real*e.array[a][n].imaginary+c.array[r][a].imaginary*e.array[a][n].real;i.push(o)}t.push(i)}return t},Bt=c=>{let e={real:0,imaginary:0},t=c.n;if(t==2){let i=he(c.array[0][0],c.array[1][1]),n=he(c.array[1][0],c.array[0][1]);return{real:i.real-n.real,imaginary:i.imaginary-n.imaginary}}let r=bo(c.n);for(let i=0;i<t;i++){let n=0;for(let s=1;s<t;s++){let l=0;for(let d=0;d<t;d++)d!=i&&(r.array[n][l]={...c.array[s][d]},l++);n++}r.m=r.n=t-1;let o=Math.pow(-1,i),a=he({real:c.array[0][i].real*o,imaginary:c.array[0][i].imaginary*o},Bt(r));e.real+=a.real,e.imaginary+=a.imaginary}return e};var yo=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],o=[],a=[];for(let s=0;s<c.n;s++)n[s].real&&(e.real_values=!0),n[s].imaginary&&(e.imaginary_values=!0),s===i&&e.unit_diagonal&&(n[s].real!==1||n[s].imaginary!==0)&&(e.unit_diagonal=!1),o.push(n[s].real),a.push(n[s].imaginary);t.array.push(o),r.array.push(a)}return{real:t,imaginary:r,flags:e}},vo=c=>{let e=c.array.map(t=>t.slice(0));return{m:c.m,n:c.n,array:e}},Vi=c=>{if(c.m!==c.n)return;let e=vo(c),t=e.array,r=0,i=0,n=0,o=0,a=c.m;for(i=1;i<a;i++)t[0][i]/=t[0][0];for(i=1;i<a;i++){for(n=i;n<a;n++){for(r=0,o=0;o<i;o++)r+=t[n][o]*t[o][i];t[n][i]-=r}if(i!=a-1)for(n=i+1;n<a;n++){for(r=0,o=0;o<i;o++)r+=t[i][o]*t[o][n];t[i][n]=(t[i][n]-r)/t[i][i]}}for(i=0;i<a;i++)for(n=i;n<a;n++){let s=1;if(i!=n)for(s=0,o=i;o<n;o++)s-=t[n][o]*t[o][i];t[n][i]=s/t[n][n]}for(i=0;i<a;i++)for(n=i;n<a;n++)if(i!=n){for(r=0,o=i;o<n;o++)r+=t[o][n]*(i==o?1:t[i][o]);t[i][n]=-r}for(i=0;i<a;i++)for(n=0;n<a;n++){for(r=0,o=i>n?i:n;o<a;o++)r+=(n==o?1:t[n][o])*t[o][i];t[n][i]=r}return e},Fi=c=>{let e=[];if(c.m!==c.n)return;let{real:t,imaginary:r,flags:i}=yo(c),n=Vi(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 o=Fr(n,r),a=Fr(r,o),s=_o(t,a),l=Vi(s);if(!l)return;let d=Fr(o,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},Li=(c,e)=>{let t={real:e.real,imaginary:-e.imaginary},r=he(c,t),i=he(e,t);return{real:r.real/i.real,imaginary:r.imaginary/i.real}},Lr=c=>{let e=c.real||0,t=c.imaginary||0;return he({real:Math.exp(e),imaginary:0},{real:Math.cos(t),imaginary:Math.sin(t)})},xo=c=>{let e=Zt(c);return{real:Math.log(e.r),imaginary:e.theta}},pe=(c,e)=>{if(e.imaginary)return Lr(he(e,xo(c)));{let t=Zt(c);return go({r:Math.pow(t.r,e.real),theta:t.theta*e.real})}};var Pi=(c,e=0)=>c&&c.type===7?c:{type:7,value:{real:e,imaginary:0}},Le=c=>c.imaginary?{type:7,value:c}:{type:3,value:c.real},Pe=(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]=Pi(t[3],t[0]),t[4]=Pi(t[4],t[1])),t},wo=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le({real:n.value.real+o.value.real,imaginary:n.value.imaginary+o.value.imaginary}):{value:t+r,type:3})},Hr=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le({real:n.value.real-o.value.real,imaginary:n.value.imaginary-o.value.imaginary}):{value:t-r,type:3})},Co=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);if(i)return i;if(n&&o)return Le(pe(n.value,o.value));let a=Math.pow(t,r);return isNaN(a)?E():{type:3,value:a}},So=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);if(i)return i;if(n&&o)return Le(pe(n.value,o.value));if(t<0&&r!==0&&Math.abs(r)<1)return Le(pe({real:t,imaginary:0},{real:r,imaginary:0}));let a=Math.pow(t,r);return isNaN(a)?E():{type:3,value:a}},Gr=Co,Ao=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?Le(he(n.value,o.value)):{value:t*r,type:3})},ko=(c,e)=>{let[t,r,i,n,o]=Pe(c,e);return i||(n&&o?o.value.real===0&&o.value.imaginary===0?fe():Le(Li(n.value,o.value)):r===0?fe():{value:t/r,type:3})},To=(c,e)=>{let[t,r,i]=Pe(c,e);return i||(r===0?fe():{value:t%r,type:3})},Ro=(c,e)=>c.type===6?c:e.type===6?e:{type:2,value:`${c.type===0?"":c.value}${e.type===0?"":e.value}`},$r=(c,e)=>c.type===6?c:e.type===6?e: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)?{type:4,value:!0}:c.type===7?e.type===7?{type:4,value:c.value.imaginary===e.value.imaginary&&c.value.real===e.value.real}:{type:4,value:!c.value.imaginary&&c.value.real===e.value}:e.type===7?{type:4,value:!e.value.imaginary&&c.value===e.value.real}:c.type===2&&e.type===2?{type:4,value:c.value.toLowerCase()===e.value.toLowerCase()}:{type:4,value:c.value==e.value},Gi=(c,e)=>{let t=$r(c,e);return t.type===6?t:{type:4,value:!t.value}},Eo=(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)},Or=(c,e)=>!(c.type===7||c.type===8||c.type===9||c.type===5||e.type===7||e.type===8||e.type===9||e.type===5),Mo=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)>=(e.value||0)}:E(),Io=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)<(e.value||0)}:E(),zo=(c,e)=>c.type===6?c:e.type===6?e:Or(c,e)?{type:4,value:(c.value||0)<=(e.value||0)}:E(),$i=()=>{Gr=So},Hi=c=>{switch(c){case"&":return Ro;case"+":return wo;case"-":return Hr;case"*":return Ao;case"/":return ko;case"^":return Gr;case"**":return Gr;case"%":return To;case"=":return $r;case"==":return $r;case"!=":return Gi;case"<>":return Gi;case">":return Eo;case">=":return Mo;case"<":return Io;case"<=":return zo}};var Zi=c=>!Array.isArray(c)&&c.type===5&&!!c.value.type,ct=c=>c.type===5&&c.key==="metadata",Wt=class{constructor(e,t,r){this.data_model=e;this.library=t;this.parser=r}context={address:{row:-1,column:-1},volatile:!1};Calculate(e,t,r=!1){return r||(this.context.address=t,this.context.volatile=!1),{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()=>Z();let t=this.data_model.sheets.Find(e.sheet_id)?.cells;if(!t)return console.warn("missing cells reference @ "+e.sheet_id),()=>Z();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)||Z():Z()}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.data_model.GetName(e.name,this.context.address.sheet_id||0);n?.type==="range"&&(n.area.count===1?r=n.area.start:i=n.area)}break;case"call":{let n=this.CalculateExpression(e,!0);if(Zi(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]"),Z();let o=n.CellData(r),a=o.calculated_type?o.calculated:o.value,s={type:"metadata",address:{...r,position:0,id:0,type:"address",label:new y(r).spreadsheet_label},value:a,format:o.style?o.style.number_format:void 0,...t(o,r)};return{type:5,value:s,key:"metadata"}}else if(i){if(i.start.row===1/0||i.start.column===1/0)return Z();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 o=[];for(let a=i.start.column;a<=i.end.column;a++){let s=[];for(let l=i.start.row;l<=i.end.row;l++){let d=n.CellData({row:l,column:a});r={...i.start,row:l,column:a};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)};s.push({type:5,value:u,key:"metadata"})}o.push(s)}return{type:8,value:o}}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()=>Se();let r=JSON.stringify(t.expression),i={},n=t.argument_names?.map(o=>o.toUpperCase())||[];return o=>{let a=JSON.parse(r);for(let s=0;s<n.length;s++)i[n[s]]=o.args[s]||{type:"missing",id:0};return this.CalculateExpression(this.RewriteMacro(a,i))}}CallExpression(e,t=!1){let r=this.library.Get(e.name);return r?i=>{this.context.volatile=this.context.volatile||!!r.volatile;let n=e.name.toLowerCase()==="if",o=-1,a,s=r.arguments||[],l=i.args.map((d,h)=>{if(a)return;let u=s[Math.min(h,s.length-1)]||{};if(h===o)return u.boxed?{type:0}:void 0;if(typeof d>"u")return n&&h===0&&(o=1),u.boxed?{type:0}:void 0;if(u.address)return u.boxed?{type:2,value:this.parser.Render(d).replace(/\$/g,"")}:this.parser.Render(d).replace(/\$/g,"");if(u.metadata)return this.GetMetadata(d,()=>({}));{let m=this.CalculateExpression(d);if(m.type===6){if(u.allow_error)return m;a=m;return}if(n&&h===0&&m.type!==8){let f=!1;if(m.type===2){let p=m.value.toLowerCase().trim();f=p!=="false"&&p!=="f"}else f=!!m.value;o=f?2:1}return u.boxed?m:m.type===8?m.value.map(f=>f.map(p=>p.value)):m.value}});if(a)return a;if(r.return_type===1){let d=r.fn.apply(null,l);if(t)return d;if(Zi(d)){if(d.value.type==="address")return this.CellFunction2(d.value)();if(d.value.type==="range")return this.CellFunction4(d.value.start,d.value.end)}return d}return r.fn.apply(null,l)}:()=>Ur()}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()=>Z()}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=Hr,r={type:3,value:0};return i=>{let n=this.CalculateExpression(i.operand);return n.type===8?{type:8,value:n.value.map(o=>o.map(a=>t(r,a)))}:t(r,n)}}default:return()=>(console.warn("unexpected unary operator:",e.operator),Se())}}RecycleArray(e,t,r){if(e[0].length<r){let i=e[0].length;for(let n of e)for(let o=i;o<r;o++)n[o]=n[o%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),o=this.RecycleArray(t.value,i,n),a=this.RecycleArray(r.value,i,n),s=[];for(let l=0;l<i;l++){let d=[];for(let h=0;h<n;h++)d[h]=e(o[l][h]||{type:0},a[l][h]||{type:0});s.push(d)}return{type:8,value:s}}BinaryExpression(e){let t=Hi(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})`),Se())}Identifier(e){let t=e.name;if(t[0]==="#")return()=>Z();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.data_model.GetName(r,this.context.address.sheet_id||0);if(i?.type==="range")return i.area.count===1?this.CellFunction4(i.area.start,i.area.start):this.CellFunction4(i.area.start,i.area.end);let n=this.data_model.GetName(t,this.context.address.sheet_id||0);return n&&n.type==="expression"?this.CalculateExpression(n.expression):Ur()}}GroupExpression(e){return!e.elements||e.elements.length!==1?(console.warn("Can't handle group !== 1"),()=>Se()):t=>this.CalculateExpression(t.elements[0])}CalculateExpression(e,t=!1){if(e.fn)return e.fn(e);switch(e.type){case"call":{let r=this.data_model.macro_functions.get(e.name.toUpperCase());return r?(e.fn=this.CallMacro(e,r))(e):(e.fn=this.CallExpression(e,t))(e)}case"address":return(e.fn=this.CellFunction2(e))();case"range":return(e.fn=r=>this.CellFunction4(r.start,r.end))(e);case"binary":return(e.fn=this.BinaryExpression(e))(e);case"unary":return(e.fn=this.UnaryExpression(e))(e);case"identifier":return(e.fn=this.Identifier(e))();case"missing":return(e.fn=()=>({value:void 0,type:0}))();case"dimensioned":return(e.fn=this.ResolveDimensionedQuantity())(e);case"literal":{let r={value:e.value,type:se(e.value)};return(e.fn=()=>r)()}case"group":return(e.fn=this.GroupExpression(e))(e);case"complex":{let r={value:{real:e.real,imaginary:e.imaginary},type:7};return(e.fn=()=>r)()}case"structured-reference":return(e.fn=this.ResolveStructuredReference(e))();case"array":return(e.fn=()=>({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),$t()}}};var yd=1e3*60*60*24;var jt=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},dt=c=>{if(!c)return[];if(typeof c[0]>"u")return[];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 be=c=>{let e=[];for(let t of c)if(t.type===8)for(let r of t.value)e=e.concat(be(r));else e.push(t);return e},j=c=>Array.isArray(c)?c.reduce((e,t)=>typeof t>"u"?e:Array.isArray(t)?e.concat(j(t)):t instanceof Float32Array||t instanceof Float64Array?e.concat(Array.from(t)):e.concat([t]),[]):[c],ue=c=>j(c).filter(e=>typeof e=="number"),Zr=c=>c.filter(e=>{switch(typeof e){case"number":case"undefined":case"string":case"boolean":return!0}return!1}),Do=c=>!!c&&typeof c=="object"&&c.type===8,Bi=(c,e)=>(...t)=>{let r=[],i=[];for(let[n,o]of t.entries())if(o&&c[n]){let a=Array.isArray(o)?o:Do(o)?o.value:void 0;a&&(r[n]=a,i.length||(i=a))}return r.length?{type:8,value:i.map((n,o)=>n.map((a,s)=>{let l=t.map((d,h)=>r[h]?r[h][o][s]||{type:0}:d);return e(...l)}))}:e(...t)},ht=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 o=0;o<r.length;o++)if(n===r[o]){e.push("\\");break}e.push(n);break}}return e.join("")};var Jt=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];if(n.canonical_name=r,!n.unrolled){let o=n.arguments?.map(a=>!!a.unroll);o?.some(a=>!!a)&&(n.fn=Bi(o,n.fn),n.unrolled=!0)}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 ut=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=J(t.text)?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:o,colors:a}=this.SparklineCommon(i,n),s=.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<o.length;f++){let p=o[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*s)/(o.length-1),p=u-h,b=t*(1-2*l),g=t*l;r.strokeStyle=a[0],r.lineWidth=d,r.lineCap="round",r.lineJoin="round",r.beginPath();let C=0;for(let x=m;x<o.length;x++){let v=o[x];if(typeof v=="number"){let _=e*s+f*x,w=t-(v-h)*b/p-g;C===0?(r.moveTo(_,w),C=1):r.lineTo(_,w)}else C=0}r.stroke()}}static RenderColumn(e,t,r,i,n){let{values:o,colors:a}=this.SparklineCommon(i,n),s=3,l=2.5,d=0,h=0,u=!1;for(let m of o)typeof m=="number"&&(u?(d=Math.min(d,m),h=Math.max(h,m)):(u=!0,d=h=m));if(o.length){let m=(e-2*s-2)/(o.length-0),f=t-2*l,p=l;if(d!==h)if(d<0&&h>0){let b=h-d,g=p+h/b*f;for(let C=0;C<o.length;C++){let x=o[C];if(typeof x=="number"){let v=s+C*m,_=Math.abs(x)/b*f;if(x>=0){r.fillStyle=a[0];let w=g-_;r.fillRect(v+2,w,m-2,_)}else{r.fillStyle=a[1];let w=g;r.fillRect(v+2,w,m-2,_)}}}}else if(h>0){r.fillStyle=a[0];let b=h-d;for(let g=0;g<o.length;g++){let C=o[g];if(typeof C=="number"){let x=s+g*m,v=Math.max(1,(C-d)/b*f),_=t-p-v;r.fillRect(x+2,_,m-2,v)}}}else{r.fillStyle=a[1];let b=h-d;for(let g=0;g<o.length;g++){let C=o[g];if(typeof C=="number"){let x=s+g*m,v=Math.max(1,Math.abs(h-C)/b*f),_=p;r.fillRect(x+2,_,m-2,v)}}}}}};var Wi=c=>{let{x:e,y:t,width:r,height:i,cell:n}=c,o={},a=3,s=Math.round(16*(c.scale||1));if(n&&r&&i&&e&&t){let l={x:a,y:i-a-s};if(n.style){switch(n.style.vertical_align){case"top":l.y=a;break;case"middle":l.y=Math.round((i-s)/2);break}switch(n.style.horizontal_align){case"right":l.x=Math.round(r-a-s);break;case"center":l.x=Math.round((r-s)/2);break}}e>=l.x&&e<=l.x+s&&t>=l.y&&t<=l.y+s&&(o.value=`=Checkbox(${n.calculated?"FALSE":"TRUE"})`,o.block_selection=!0)}return o},ji=c=>{let{context:e,width:t,height:r,cell:i}=c,n=c.scale||1;e.lineJoin="round",e.lineCap="round";let o=3*n,a=16*n,s=o,l=r-o-a;if(i.style){switch(i.style.vertical_align){case"top":l=o;break;case"middle":l=(r-a)/2;break}switch(i.style.horizontal_align){case"right":s=t-o-a;break;case"center":s=(t-a)/2;break}}s=Math.floor(s)+.5,l=Math.floor(l)+.5;let d=Math.floor(s+a)+.5,h=Math.floor(l+a)+.5;if(i&&i.calculated){e.lineWidth=.5,e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(s,l),e.lineTo(s+16*n,l),e.lineTo(s+16*n,l+16*n),e.lineTo(s,l+16*n),e.closePath(),e.moveTo(s+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(s+u[0]*n,l+u[1]*n);e.closePath(),e.fill()}else e.lineWidth=1,e.lineJoin="round",e.beginPath(),e.moveTo(s,l),e.lineTo(d,l),e.lineTo(d,h),e.lineTo(s,h),e.closePath(),e.stroke();return{handled:!0}};var Ve=c=>{switch(c.type){case 7:return c.value;case 3:return{real:c.value,imaginary:0};case 4:return{real:c.value?1:0,imaginary:0};case 0:return{real:0,imaginary:0}}return!1};var Yi=c=>{let e=.254829592,t=-.284496736,r=1.421413741,i=-1.453152027,n=1.061405429,o=.3275911;c=Math.abs(c);let a=1/(1+o*c);return 1-((((n*a+i)*a+r)*a+t)*a+e)*a*Math.exp(-1*c*c)},Vo=Math.sqrt(2*Math.PI),Ji=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},Xi=(c,e)=>{let t=new Date(we(c)),r=t.getUTCMonth()+e,i=t.getUTCFullYear();for(t.setUTCHours(12),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);r<0;)r+=12,i--;for(;r>11;)r-=12,i++;if(t.setUTCMonth(r),t.setUTCFullYear(i),t.getUTCMonth()!==r){let o=t.getUTCDate();t=new Date(t.getTime()-o*86400*1e3)}return t},Qi=[{name:"Lookup value"},{name:"Table"},{name:"Result index"},{name:"Inexact",default:!0}],qi=(c,e,t,r=!0,i=!1)=>{if(i&&(e=dt(e)),t=Math.max(0,t-1),r){let n=e[t][0];if(typeof c=="number"){let o=Number(e[0][0]);if(isNaN(o)||o>c)return de();for(let a=1;a<e[0].length&&(o=Number(e[0][a]),!(isNaN(o)||o>c));a++)n=e[t][a]}else{c=(c||"").toString().toLowerCase();let o=(e[0][0]||"").toString().toLowerCase();if(o.localeCompare(c)>0)return de();for(let a=1;a<e[0].length&&(o=(e[0][a]||"").toString().toLowerCase(),!(o.localeCompare(c)>0));a++)n=e[t][a]}return W(n)}else{for(let n=0;n<e[0].length;n++)if(e[0][n]==c)return W(e[t][n]);return de()}},Br={Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:c=>{if(c.type===7){let e=pe(c.value,{real:.5,imaginary:0});return me(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3&&c.value<0){let e=pe({real:c.value,imaginary:0},{real:.5,imaginary:0});return{type:7,value:e}}else if(c.type===3){let e=Math.sqrt(c.value);return isNaN(e)?E():{type:3,value:e}}else return E()}}},Power:{description:"Returns base raised to the given power",arguments:[{name:"base",boxed:!0,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(c,e)=>{if(c.type===3&&e.type===3&&(c.value>=0||e.value===0||Math.abs(e.value)>=1)){let i=Math.pow(c.value,e.value);return isNaN(i)?E():{type:3,value:i}}let t=Ve(c),r=Ve(e);if(t&&r){let i=pe(t,r);return me(i)}return E()}}},je={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=be(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 me(e)}},EDate:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(c,e=0)=>{if(typeof c!="number"||typeof e!="number")return F();let t=Xi(c,e);return{type:3,value:Ce(t.getTime(),!1)}}},EOMonth:{arguments:[{name:"Start date",unroll:!0},{name:"Months",unroll:!0}],fn:(c,e=0)=>{if(typeof c!="number"||typeof e!="number")return F();let t=Xi(c,e);switch(t.getUTCMonth()){case 1:{let i=t.getUTCFullYear();i%4===0&&(i===1900||i%400===0||i%100!==0)?t.setUTCDate(29):t.setUTCDate(28)}break;case 0:case 2:case 4:case 6:case 7:case 9:case 11:t.setUTCDate(31);break;default:t.setUTCDate(30);break}return{type:3,value:Ce(t.getTime(),!1)}}},Now:{description:"Returns current time",volatile:!0,fn:()=>({type:3,value:Ce(new Date().getTime())})},YearFrac:{description:"Returns the fraction of a year between two dates",arguments:[{name:"Start"},{name:"End"},{name:"Basis",default:0}],fn:(c,e,t)=>{if(e<c){let n=c;c=e,e=n}let r=Math.max(0,e-c),i=360;if(t&&t<0||t>4)return F();switch(t){case 1:break;case 2:break;case 3:i=365;break}return{type:3,value:r/i}}},Date:{description:"Constructs a Lotus date from parts",arguments:[{name:"year",unroll:!0},{name:"month",unroll:!0},{name:"day",unroll:!0}],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?F():(c<1899&&(c+=1900),r.setFullYear(c),e<1||e>12?F():(r.setMonth(e-1),t<1||t>31?F():(r.setDate(t),{type:3,value:Ce(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:Ce(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},IsNA:{description:"Checks if another cell contains a #NA error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=be(c);for(let t of e)if(t.type===6&&t.value==="N/A")return{type:4,value:!0};return{type:4,value:!1}}},IsError:{description:"Checks if another cell contains an error",arguments:[{name:"reference",allow_error:!0,boxed:!0}],fn:(...c)=>{let e=be(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",unroll:!0},{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:(c,e)=>{if(!ct(e))return Z();if(c)switch(c.toString().toLowerCase()){case"format":return e.value.format?{type:2,value:e.value.format}:Z();case"address":return{type:2,value:e.value.address.label.replace(/\$/g,"")}}return{type:6,value:Di.error}}},Year:{description:"Returns year from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCFullYear())},Month:{description:"Returns month from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCMonth()+1)},Day:{description:"Returns day of month from date",arguments:[{name:"date",unroll:!0}],fn:c=>W(new Date(we(c)).getUTCDate())},Radians:{description:"Converts degrees to radians",arguments:[{name:"Degrees",description:"Angle in degrees",unroll:!0}],fn:c=>W(c*Math.PI/180)},Degrees:{description:"Converts radians to degrees",arguments:[{name:"Radians",description:"Angle in radians",unroll:!0}],fn:c=>W(c/Math.PI*180)},CountA:{description:"Counts cells that are not empty",fn:(...c)=>W(j(c).reduce((e,t)=>typeof t>"u"?e:e+1,0))},Count:{description:"Counts cells that contain numbers",fn:(...c)=>W(j(c).reduce((e,t)=>typeof t=="number"||ae(t)?e+1:e,0))},Or:{fn:(...c)=>{let e=!1;c=j(c);for(let t of c)e=e||!!t;return W(e)}},And:{fn:(...c)=>{let e=!0;c=j(c);for(let t of c)e=e&&!!t;return W(e)}},Not:{arguments:[{unroll:!0}],fn:(...c)=>c.length===0?F():c.length===1?W(!c[0]):W(!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((o,a)=>o.map((s,l)=>(s.type===2?s.value.toLowerCase()!=="false"&&s.value.toLowerCase()!=="f":!!s.value)?r?e.value[a][l]:e:i?t.value[a][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",unroll:!0}],fn:c=>{c=Math.round(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,unroll:!0},{name:"exponent",boxed:!0,unroll:!0}],fn:(c,e)=>{let t=Ve(c),r=Ve(e);if(!t||!r)return E();if(c.type===7||e.type===7)return me(pe(t,r));{let i=Math.pow(t.real,r.real);return isNaN(i)?E():{type:3,value:i}}}},Mod:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e)=>e?W(c%e):fe()},Large:{description:"Returns the nth numeric value from the data, in descending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(c,e)=>{if(e<=0)return F();let t=ue(c);return t.sort((r,i)=>i-r),e<=t.length?{type:3,value:t[e-1]}:F()}},Small:{description:"Returns the nth numeric value from the data, in ascending order",arguments:[{name:"values"},{name:"index",unroll:!0}],fn:(c,e)=>{if(e<=0)return F();let t=ue(c);return t.sort((r,i)=>r-i),e<=t.length?{type:3,value:t[e-1]}:F()}},Sort:{arguments:[{name:"values"}],fn:(...c)=>(c=j(c),c.every(e=>typeof e=="number")?c.sort((e,t)=>e-t):c.sort(),{type:8,value:[c.map(e=>W(e))]})},Transpose:{description:"Returns transpose of input matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>c.type===8?{type:8,value:jt(c.value)}:c},Max:{fn:(...c)=>({type:3,value:Math.max.apply(0,ue(c))})},Min:{fn:(...c)=>({type:3,value:Math.min.apply(0,ue(c))})},SumProduct:{description:"Returns the sum of pairwise products of two or more ranges",fn:(...c)=>{let e=c.map(i=>j(i)),t=Math.max.apply(0,e.map(i=>i.length)),r=0;for(let i=0;i<t;i++)r+=e.reduce((n,o)=>{let a=o[i];return a===!0&&(a=1),typeof a=="number"?n*a:0},1);return{type:3,value:r}}},XLOOKUP:{arguments:[{name:"Lookup value"},{name:"Lookup array"},{name:"Return array"},{name:"Not found",boxed:!0},{name:"Match mode",default:0},{name:"Search mode",default:1}],xlfn:!0,fn:(c,e,t,r,i=0,n=1)=>{if(!Array.isArray(e))return console.info("lookup is not an array"),E();let o=e[0];if(!Array.isArray(o))return console.info("lookip is not a 2d array"),E();if(e.length!==1&&o.length!==1)return console.info("lookup array has invalid dimensions"),E();if(!Array.isArray(t))return console.info("return array is not an array"),E();let a=e.length===1;a&&(e=dt(e),t=dt(t)),n<0&&(e.reverse(),t.reverse());let s=l=>{let d=t[l];if(!d)return{type:0};if(!Array.isArray(d))return W(d);let h=[d.map(u=>W(u))];return a&&(h=dt(h)),{type:8,value:h}};if(i===2&&typeof c!="string"&&(i=0),(i===1||i===-1)&&typeof c=="number"){let l=0,d=-1;for(let h=0;h<e.length;h++){let u=e[h][0];if(typeof u=="number"){if(u===c)return s(h);let m=Math.abs(u-c);(i===1&&u>c||i===-1&&u<c)&&(d<0||m<l)&&(l=m,d=h)}}if(d>=0)return s(d)}switch(i){case 2:{let l=ht(c?.toString()||""),d=new RegExp("^"+l+"$","i");for(let h=0;h<e.length;h++){let u=e[h][0];if(typeof u=="string"&&d.exec(u))return s(h)}}break;case 0:typeof c=="string"&&(c=c.toLowerCase());for(let l=0;l<e.length;l++){let d=e[l][0];if(typeof d=="string"&&(d=d.toLowerCase()),d===c)return s(l)}break}return r&&r.type!==0?r:de()}},HLookup:{arguments:[...Qi],fn:(c,e,t,r=!0)=>qi(c,e,t,r,!0)},VLookup:{arguments:[...Qi],fn:(c,e,t,r=!0)=>qi(c,e,t,r,!1)},Product:{arguments:[{boxed:!0}],fn:(...c)=>{let e={real:1,imaginary:0};c=be(c);for(let t of c)t.type===7?e=he(e,t.value):t.type===3&&(e.real*=t.value,e.imaginary*=t.value);return me(e)}},Log:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=10)=>({type:3,value:Math.log(c)/Math.log(e)})},Log10:{arguments:[{unroll:!0}],fn:c=>({type:3,value:Math.log(c)/Math.log(10)})},Ln:{arguments:[{unroll:!0}],fn:c=>({type:3,value:Math.log(c)})},Round:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=0)=>{let t=Math.pow(10,e);return{type:3,value:Math.round(t*c)/t}}},RoundDown:{arguments:[{unroll:!0},{unroll:!0}],fn:(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}}},RoundUp:{arguments:[{unroll:!0},{unroll:!0}],fn:(c,e=0)=>{let t=Math.pow(10,e),r=c>=0;return{type:3,value:r?Math.ceil(t*c)/t:Math.floor(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,unroll:!0}],fn:c=>{if(c.type===7){let e=Lr(c.value);return me(e)}return c.type!==3?E():{type:3,value:Math.exp(c.value)}}},Abs:{arguments:[{boxed:!0,unroll:!0}],fn:c=>c.type===7?{type:3,value:Math.sqrt(c.value.real*c.value.real+c.value.imaginary*c.value.imaginary)}:c.type!==3?E():{type:3,value:Math.abs(c.value||0)}},Simplify:{arguments:[{name:"value",unroll:!0},{name:"significant digits",unroll:!0}],fn:(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:Yi(c)})},NormsInv:{description:"Inverse of the normal cumulative distribution",arguments:[{name:"probability"}],fn:c=>({type:3,value:Ji(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:Ji(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)*Yi(Math.abs(c-e)/(t*Math.sqrt(2)))):i=Math.exp(-1/2*Math.pow((c-e)/t,2))/(t*Vo),{type:3,value:i}}},Sqrt:{description:"Returns the square root of the argument",arguments:[{boxed:!0,unroll:!0}],fn:c=>{if(c.type===7){let e=pe(c.value,{real:.5,imaginary:0});return me(e)}else{if(c.type===0||!c.value)return{type:3,value:0};if(c.type===3)return{type:3,value:Math.sqrt(c.value)}}return E()}},HexToDec:{arguments:[{description:"hexadecimal string",unroll:!0}],fn:c=>({type:3,value:parseInt(c,16)})},DecToHex:{arguments:[{description:"number",unroll:!0}],fn:c=>({type:2,value:c.toString(16)})},Checkbox:{arguments:[{name:"checked"}],click:Wi,render:ji,fn:c=>({value:!!c,type:4})},"Sparkline.Column":{arguments:[{name:"data"},{name:"color"},{name:"negative color"}],render:c=>(ut.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=>(ut.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=n=>{if(n)switch(n.type){case 2:case 3:case 4:return n.value;case 0:return"";default:return console.info("check",n,n.value),n.value?.toString()||""}else return""},t=new Set,r=new Set;for(let n of c.value)for(let o of n){let a=e(o);t.has(a)?r.add(a):t.add(a)}let i=[];for(let n of c.value){let o=[];for(let a of n){let s=e(a);o.push({type:4,value:!r.has(s)})}i.push(o)}return{type:8,value:i}}return{type:4,value:!0}}},Gradient:{arguments:[{name:"range",boxed:!0},{name:"min"},{name:"max"}],visibility:"internal",fn:(c,e,t)=>{let r=be([c]),i=0,n=0,o=0;for(let d of r){if(d.type===6)return d;d.type===3&&(i===0?(n=d.value,o=d.value):(n=Math.min(n,d.value),o=Math.max(o,d.value)),i++)}typeof t=="number"&&(o=t),typeof e=="number"&&(n=e);let a=o-n,s=1,l=1;if(c.type===8){s=c.value.length,l=c.value[0]?.length||0;let d=[];for(let h=0;h<s;h++){let u=[];for(let m=0;m<l;m++){let f=c.value[h][m];if(f.type===3){let p=0;o===n?f.value>o?p=1:f.value<o?p=0:p=.5:a>0&&(p=(f.value-n)/a),u.push({type:3,value:p})}else u.push({type:0})}d.push(u)}return{type:8,value:d}}else return F()}}},Ki={};for(let c of Object.keys(je))Ki[c.toLowerCase()]=c;var Uo=["pow"],en={};for(let c of Uo)en[c.toLowerCase()]=c;for(let c of Object.getOwnPropertyNames(Math)){let e=c.toLowerCase();if(Ki[e]||en[e])continue;let t=Object.getOwnPropertyDescriptor(Math,c);if(!t)continue;let r=t.value,i=typeof r;switch(i){case"number":je[c]={fn:()=>({type:3,value:r}),category:["Math Functions"]};break;case"function":je[c]={fn:(...n)=>W(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 mt=(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),rn=(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),Wr=(c,e,t,r=0,i=0,n=0)=>{if(e<1)return NaN;if(e===1&&n)return 0;let o=mt(c,t,r,i,n),a=rn(c,e-1,o,r,n)*c;return n?a/(1+c):a},tn=(c,e,t,r=0,i=0,n=0)=>mt(c,t,r,i,n)-Wr(c,e,t,r,i,n),nn={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=j(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 F();if(e=j(e),t=j(t),e.length!==t.length)return F();let r=[];for(let o of e){if(typeof o!="number")return F();r.push(o)}let i=[];for(let o of t){if(typeof o!="number")return F();i.push(Math.floor(o))}let n=0;for(let o=0;o<r.length;o++)n+=(r[o]||0)/Math.pow(1+c,(i[o]-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=j(c),e=j(e),c.length!==e.length)return F();let r=0,i=0,n=[];for(let h of c){if(typeof h!="number")return F();h>0&&r++,h<0&&i++,n.push(h)}if(r<=0||i<=0)return F();let o=[];for(let h of e){if(typeof h!="number")return F();o.push(Math.floor(h))}let a=o[0];for(let h of o)if(h<a)return F();let s=.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,(o[m]-o[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+=s;continue}}else if(l[1].value=l[1].found?Math.min(l[1].value,t):t,l[1].found=!0,!l[0].found){t-=s;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=j(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 o=0;for(let a=0;a<t.length;a++)o+=Math.pow(1+e,-(a+1))*t[a];if(Math.abs(o)<=.00125)return{type:3,value:e};if(o>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 o=0;for(let a=r;a<=i;a++)o+=tn(c,a,e,t,0,n);return{type:3,value:o}}},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 o=0;for(let a=r;a<=i;a++)o+=Wr(c,a,e,t,0,n);return{type:3,value:o}}},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:Wr(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:tn(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,o=[-1,1],a=32,s=1e-6;for(let l=0;l<a;l++){let d=mt(n,c,t,r,i);if(Math.abs(d-e)<=s)return{type:3,value:n};let h=mt(o[1],c,t,r,i);e>=d&&e<=h||e>=h&&e<=d?o[0]=n:o[1]=n,n=o[0]+(o[1]-o[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:rn(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:mt(c,e,t,r,i)})}};var on={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=ce.TryParse(c);return e.type===3?{type:3,value:e.value}:F()},category:["text"]},Text:{arguments:[{name:"value"},{name:"number format"}],fn:(c,e="0.00####")=>({type:2,value:z.Get(e).Format(c||0)}),category:["text"]},WildcardMatch:{visibility:"internal",arguments:[{name:"text",unroll:!0},{name:"text",unroll:!0},{name:"invert"}],fn:(c,e,t=!1)=>{if(typeof c=="string"&&typeof e=="string"){let r=ht(e),i=new RegExp("^"+r+"$","i").exec(c);return{type:4,value:t?!i:!!i}}return{type:4,value:c===e||c?.toString()===e?.toString()}}},Exact:{arguments:[{name:"text",boxed:!0,unroll:!0},{name:"text",boxed:!0,unroll:!0}],category:["text"],fn:(c,e)=>({type:4,value:c?.value?.toString()===e?.value?.toString()})},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=ht(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=j(c).map(r=>{let i=r?.toString()||"";return typeof r=="number"&&N.decimal_separator===","?i.replace(/\./,","):i}).join("");return{type:2,value:t}}}},jr={Concatenate:"Concat"};var Xt=(c,e)=>({type:4,value:typeof e.value?.value===c}),Qt=[{name:"Reference",metadata:!0,unroll:!0}],an={IsBlank:{description:"Returns true if the reference is blank",arguments:Qt,fn:Xt.bind(0,"undefined")},IsNumber:{description:"Returns true if the reference is a number",arguments:Qt,fn:Xt.bind(0,"number")},IsLogical:{description:"Returns true if the reference is a logical TRUE or FALSE",arguments:Qt,fn:Xt.bind(0,"boolean")},IsText:{description:"Returns true if the reference is text",arguments:Qt,fn:Xt.bind(0,"string")}};var Ee=(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 o=c[n]-r;i+=o*o}return e?i/(t-1):i/t},sn={"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(Ee(ue(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(Ee(ue(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:Ee(ue(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:Ee(ue(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 F();let t=0,r=0,i={x:0,y:0},n={x:[],y:[]};for(let o=0;o<c.length;o++){if(!c[o]||!e[o])continue;if(c[o].length!==e[o].length)return F();let a=c[o].length;r+=a;for(let s=0;s<a;s++)i.x+=c[o][s]||0,i.y+=e[o][s]||0,n.x.push(c[o][s]||0),n.y.push(e[o][s]||0)}if(r===0)return de();i.x/=r,i.y/=r;for(let o=0;o<r;o++)t+=(n.x[o]-i.x)*(n.y[o]-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,o=0,a=0,s=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,o+=u*u,a+=m*m,s++)}}return t=s*r-i*n,t&&(t/=Math.sqrt((s*o-i*i)*(s*a-n*n))),{type:3,value:t}}},GeoMean:{description:"Returns the geometric mean of all numeric arguments",arguments:[{boxed:!0}],fn:(...c)=>{c=be(c);let e=0,t={real:1,imaginary:0},r=!1,i=!1;for(let n of c)n.type===7?(r=!0,t=he(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=pe(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=be(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=ue(c);t.sort((s,l)=>s-l);let r=t.length,i=Math.pow(10,8),n=Math.round((1+(r-1)*e)*i)/i,o=Math.floor(n),a=Math.ceil(n);return{type:3,value:(t[o-1]+t[a-1])/2}}},Median:{description:"Returns the median value of the range of data",arguments:[{name:"range"}],fn:(...c)=>{let e=ue(c);e.sort((o,a)=>o-a);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}}},Rank:{arguments:[{name:"Value"},{name:"Source"},{name:"Order"}],fn:(c,e,t=0)=>{if(typeof c!="number")return F();let r=ue(e);r.sort(t?(i,n)=>i-n:(i,n)=>n-i);for(let i=0;i<r.length;i++)if(r[i]===c)return{type:3,value:i+1};return E()}}},Yr={Mean:"Average",StDev:"StDev.S",Var:"Var.S"};var ln={IsComplex:{description:"Returns true if the reference is a complex number",arguments:[{name:"Reference",metadata:!0,unroll:!0}],fn:c=>({type:4,value:!!c?.value&&ae(c.value.value)})},Real:{description:"Returns the real part of a complex number",arguments:[{boxed:!0,unroll:!0}],fn: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,unroll:!0}],fn: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,unroll:!0}],fn:c=>{let e=Ve(c);return e?e.imaginary?{type:7,value:{real:e.real,imaginary:-e.imaginary}}:{type:3,value:e.real}:E()}},Arg:{description:"Returns the principal argument of a complex number (in radians)",arguments:[{boxed:!0,unroll:!0}],fn: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,unroll:!0}],fn:c=>{let e=Ve(c);return e?{type:7,value:e}:E()}},ComplexLog:{description:"Returns the principal value Log(z) of a complex number z",arguments:[{boxed:!0,unroll:!0}],fn: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=Zt(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 qt=c=>{let e=[];c.type===8?e=c.value:e=[[c]];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 o=[];for(let a=0;a<r;a++){let s=e[n][a];if(s.type===7)o.push({...s.value});else if(s.type===3)o.push({real:s.value,imaginary:0});else if(s.type===0||s.value==="")o.push({real:0,imaginary:0});else return{m:t,n:r,error:!0,array:[]}}i.push(o)}return{m:t,n:r,array:i}},cn={MDeterm:{description:"Returns the determinant of a matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=qt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Bt(e);return t?me(t):E()}},MInverse:{description:"Returns the inverse matrix",arguments:[{name:"matrix",boxed:!0}],fn:c=>{let e=qt(c);if(!e.array||!e.m||!e.n||e.m!==e.n||e.error)return E();let t=Bt(e);if(t&&t.real===0&&t?.imaginary===0)return E();let r=Fi(e);return r?{type:8,value:r.map(i=>i.map(n=>me(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=qt(c),r=qt(e);if(!t.array||t.error||!r.array||r.error)return E();if(t.m!==r.n)return E();let i=Ui(r,t);return{type:8,value:i.map(n=>n.map(o=>me(o)))}}}};var ft=class c extends Re{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(){if(this.dirty){for(let e of this.edges_in)if(e.dirty)return;this.UpdateState(),this.dirty=!1}}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var Kt=class c extends Re{static type="calculation-leaf-vertex";type=c.type;address={row:-1,column:-1};use;updated=!1;color=2;Calculate(e){if(!this.dirty)return;for(let r of this.edges_in)if(r.dirty)return;let t=e.CalculationCallback.call(e,this);this.result=t.value,this.dirty=!1,this.updated=!0}AddDependent(){throw new Error("leaf vertex cannot have dependents")}};var Fo=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},Lo={complex_numbers:"off"},er=class extends Ot{constructor(t,r={}){super();this.model=t;if(this.expression_calculator=new Wt(this.model,this.library,this.parser),{...Lo,...r}.complex_numbers==="on"){for(let a of Object.keys(Br))je[a]=Br[a];$i()}this.UpdateLocale(),this.library.Register(je,on,sn,nn,an,ln,cn);for(let a of Object.keys(Yr))this.library.Alias(a,Yr[a]);for(let a of Object.keys(jr))this.library.Alias(a,jr[a]);let n=a=>{let s=[];for(let l of a.value)for(let d of l)s.push(d.type===4&&d.value);return s},o=(a,s)=>{let l=j(a),d,h,u="=";if(typeof s=="string"){s=s.trim();let f=s.match(/^([=<>]+)/);f&&(u=f[1],s=s.substring(u.length));let p=ce.TryParse(s);if(p?.type===2?s=`"${p.value}"`:s=p?.value?.toString()||"",/[?*]/.test(s)){let b=this.parser.argument_separator;if(u==="="||u==="<>"){if(d=this.parser.Parse(`=WildcardMatch({}${b} ${s}${b} ${u==="<>"})`),h=d.expression,d.error||!h)return Se();h?.type==="call"&&h.args[0]?.type==="array"&&(h.args[0].values=[Zr(l)])}}}else s=(s||0).toString();if(!d){if(d=this.parser.Parse("{}"+u+s),h=d.expression,d.error||!h)return Se();if(h.type!=="binary")return console.warn("invalid expression [1]",h),Se();if(h.left.type!=="array")return console.warn("invalid expression [1]",h),Se();h.right.type==="identifier"&&(console.warn("will never happen"),h.right={...h.right,type:"literal",value:h.right.name}),h.left.values=[Zr(l)]}return h?this.CalculateExpression(h):E()};this.library.Register({Subtotal:{arguments:[{name:"type"},{name:"range",metadata:!0}],fn:(a,...s)=>{if(a=Fo(a),a>100&&(a-=100),a<1||a>11)return F();let l=be(s),d=[],h=0,u=0,m;for(let p of l){let b=p.value?.address;if(!b)return Z();if(!m||m.id!==b.sheet_id){if(!b.sheet_id)return console.warn("invalid reference in metadata"),Z();if(m=this.model.sheets.Find(b.sheet_id),!m)return console.warn("invalid sheet in metadata"),Z()}if(!m.GetRowHeight(b.row))continue;let C=p.value?.value;typeof C>"u"||(h++,typeof C=="number"&&(u+=C,d.push(C)))}let f=0;switch(a){case 1:if(d.length===0)return fe();f=u/d.length;break;case 2:f=d.length;break;case 3:f=h;break;case 4:if(d.length===0)return E();f=Math.max.apply(0,d);break;case 5:if(d.length===0)return E();f=Math.min.apply(0,d);break;case 6:if(d.length===0)return E();f=1;for(let p of d)f*=p;break;case 7:if(d.length<2)return fe();f=Math.sqrt(Ee(d,!0));break;case 8:if(d.length===0)return fe();f=Math.sqrt(Ee(d,!1));break;case 9:f=u;break;case 10:if(d.length<2)return fe();f=Ee(d,!0);break;case 11:if(d.length===0)return fe();f=Ee(d,!1);break}return{type:3,value:f}}},CountIfs:{arguments:[{name:"range1"},{name:"criteria1"},{name:"range2"},{name:"criteria2"}],fn:(...a)=>{let s=0,l=o(a[0],a[1]);if(l.type!==8)return l;let d=n(l);for(let h=2;h<a.length;h+=2)if(a[h]&&a[h+1]){let u=o(a[h],a[h+1]);if(u.type!==8)return u;let m=n(u);for(let[f,p]of d.entries())d[f]=p&&m[f]}for(let h of d)h&&s++;return{type:3,value:s}}},CountIf:{arguments:[{name:"range"},{name:"criteria"}],fn:(a,s)=>{let l=o(a,s);if(l.type===8){let d=0;for(let h of l.value)for(let u of h)u.value&&d++;return{type:3,value:d}}return l}},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:((a,s=0,l=0,d,h)=>{if(!a)return F();if(a.type===8){let m=typeof d=="number"?s+d:void 0,f=typeof h=="number"?l+h:void 0;return{type:8,value:a.value.slice(s,m).map(b=>b.slice(l,f))}}if(!ct(a))return console.info("e2",{reference:a}),Z();let u=this.DynamicDependencies(a.value.address,this.expression_calculator.context.address,!0,s,l,h,d);if(!u)return console.info("e1",{check_result:u}),Z();if(u.dirty){let m=this.GetVertex(this.expression_calculator.context.address,!0);return m.short_circuit=!0,{type:0,value:void 0}}if(u.area){let m={type:"address",...u.area.start,label:"",position:0,id:0},f={type:"address",...u.area.end,label:"",position:0,id:0},p=u.area.count===1?m:{type:"range",start:m,end:f,label:"",position:0,id:0};return{type:5,value:p}}return E()}).bind(this)},Indirect:{arguments:[{name:"reference",description:"Cell reference (string)"}],return_type:1,volatile:!0,fn:(a=>{if(!a||typeof a!="string")return F();let s=this.parser.Parse(a);if(s.error||!s.expression||s.expression.type!=="address"&&s.expression.type!=="range")return Z();let l=this.DynamicDependencies(s.expression,this.expression_calculator.context.address);if(!l)return Z();if(l.dirty){let d=this.GetVertex(this.expression_calculator.context.address,!0);return d.short_circuit=!0,{type:0,value:void 0}}return{type:5,value:s.expression}}).bind(this)},Match:{arguments:[{name:"value",boxed:!0},{name:"range",boxed:!0},{name:"type"}],fn:(a,s,l=0)=>{if(l)return console.warn("inexact match not supported",{value:a,range:s,type:l}),de();if(s.type===8){if(s.value.length===1){let d=s.value[0];for(let h=0;h<d.length;h++)if(a.type==d[h].type&&a.value===d[h].value)return{type:3,value:h+1}}else for(let d=0;d<s.value.length;d++){let h=s.value[d];if(h.length!==1)return de();if(a.type==h[0].type&&a.value===h[0].value)return{type:3,value:d+1}}return de()}else return a.type===s.type&&a.value===s.value?{type:3,value:1}:de();return F()}},Index:{arguments:[{name:"range",boxed:!0},{name:"row"},{name:"column"}],volatile:!1,fn:(a,s,l)=>{if(a&&a.type!==8&&(a={type:8,value:[[a]]}),s&&l){let d=a.value[l-1];if(d){let h=d[s-1];if(h)return h}}else if(s){let d=[];for(let h of a.value){if(!h[s-1])return F();d.push([h[s-1]])}return{type:8,value:d}}else if(l){let d=a.value[l-1];if(d)return{type:8,value:[d]}}return F()}},Rows:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:a=>{if(!a)return F();if(Array.isArray(a)){let s=a[0];return Array.isArray(s)?{type:3,value:s.length}:E()}return{type:3,value:1}}},Columns:{arguments:[{name:"reference",description:"Array or reference"}],volatile:!1,fn:a=>a?Array.isArray(a)?{type:3,value:a.length}:{type:3,value:1}:F()},FormulaText:{description:"Returns a formula as a string",arguments:[{name:"reference",description:"Cell reference",metadata:!0,unroll:!0}],fn:a=>{if(!ct(a))return Z();let s=this.model.sheets.Find(a.value?.address?.sheet_id||0);if(s){let l=s.cells.GetCell(a.value.address,!1);return{type:2,value:l?.value?.toString()||""}}return Z()}},IsFormula:{description:"Returns true if the reference is a formula",arguments:[{name:"Reference",unroll:!0,metadata:!0}],fn:a=>{let s=a?.value?.address,l=this.model.sheets.Find(s?.sheet_id||0);if(s&&l){let d=l.cells.GetCell(s,!1);return{type:4,value:d?.type===1}}return{type:4,value:!1}}}})}get parser(){return this.model.parser}library=new Jt;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 o=n.rows,a=n.columns;if(r.type===8){let s=jt(r.value);for(let l=0;l<o;l++)if(s[l]){let d=0;for(;d<a&&d<s[l].length;d++){let h=s[l][d];switch(h.type===8&&(h=h.value[0][0]),h.type){case 8:case 5:i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0);break;default:i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(h.value,h.type)}}for(;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else for(let d=0;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(void 0,0)}else{let s={...r};s.type===5&&(s={type:0,value:void 0});for(let l=0;l<o;l++)for(let d=0;d<a;d++)i.data[l+n.start.row][d+n.start.column].SetCalculatedValue(s.value,s.type)}}}CalculationCallback(t){if(!t.address)throw new Error("vertex missing address");return t.expression_error?{value:$t()}:this.expression_calculator.Calculate(t.expression,t.address)}DynamicDependencies(t,r,i=!1,n=0,o=0,a=1,s=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+o,row:l.start.row+n,sheet_id:l.start.sheet_id},{column:l.start.column+o+a-1,row:l.start.row+n+s-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(){N.decimal_separator===","?this.parser.SetLocaleSettings(","):this.parser.SetLocaleSettings(".")}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(o=>({name:o.name||""})),type:"function"}});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})),type:"function"});return r}RegisterLibrary(t,r){return this.registered_libraries[t]?!1:(this.RegisterFunction(r),this.registered_libraries[t]=!0,!0)}RegisterFunction(t){for(let r of Object.keys(t)){let i=t[r],n=i.fn;i.fn=(...o)=>n.apply({address:{...this.expression_calculator.context.address}},o),this.library.Register({[r]:i})}}Calculate(t){if(t&&!t.start.sheet_id)throw new Error("CalculateInternal called with subset w/out sheet ID");this.full_rebuild_required&&(t=void 0,this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.full_rebuild_required=!1),this.RebuildGraph(t);try{this.Recalculate()}catch(r){console.error(r),console.info("calculation error trapped")}}Reset(){this.FlushTree(),this.full_rebuild_required=!0}DecoratedFunctionList(){let t={},r=this.library.List();for(let 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){this.parser.Save(),i.argument_separator&&(i.argument_separator===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",")),i.r1c1&&(this.parser.flags.r1c1=i.r1c1);let o=this.parser.Parse(t);if(this.parser.Restore(),o&&o.expression){this.parser.Walk(o.expression,s=>{if(s.type==="address"||s.type==="range"){if(s.type==="address"){if(s.offset_column||s.offset_row)throw new Error("Evaluate does not support offset references")}else if(s.start.offset_column||s.start.offset_row||s.end.offset_column||s.end.offset_row)throw new Error("Evaluate does not support offset references");this.model.ResolveSheetID(s,void 0,r)}return!0});let a=this.CalculateExpression(o.expression);return n?a:a.type===8?a.value.map(s=>s.map(l=>l.value)):a.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.RebuildGraph(),this.UpdateAnnotations(),this.UpdateConditionals(),this.UpdateConnectedElements(),this.InitializeGraph(),t&&this.volatile_list.length&&this.Recalculate()}FlattenCellList(t){let r={},i=[];for(let n of t){let o={column:n.column,row:n.row,sheet_id:n.sheet_id},a=y.CellAddressToLabel(o,!0);r[a]||(r[a]=a,i.push(o))}return i}Unresolve(t,r,i=!0,n=!0){let o="",a=V(t)?new y(t):new y(t.start,t.end);if(n){let d=this.model.named.MatchSelection(a);if(d)return d}if(o=a.spreadsheet_label,!i)return o;let s=a.start.sheet_id||r?.id,l=this.ResolveSheetName(s,!0);return l?l+"!"+o:o}ResolveSheetName(t,r=!1){let i=this.model.sheets.Find(t);if(i)return r&&xe.test(i.name)?`'${i.name}'`:i.name}RemoveConditional(t){if(t.type==="expression"){let r=t.internal?.vertex;r&&(r.Reset(),this.RemoveLeafVertex(r))}}RemoveConnectedELement(t){let r=t.internal;return r?.vertex?(this.RemoveLeafVertex(r.vertex),!0):!1}UpdateConnectedElements(t,r){if(t||(t=this.model.sheets.list[0]),r){let n=r.internal;n?.vertex&&this.RemoveLeafVertex(n.vertex)}let i=r?[r]:this.model.connected_elements.values();for(let n of i){let o=n.internal;o||(o={vertex:new ft},n.internal=o);let a=o.vertex;this.AddLeafVertex(a),this.UpdateLeafVertex(a,n.formula,t)}}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){let a=new Kt;a.use="conditional",i.internal.vertex=a;let s;i.type!=="gradient"&&i.type!=="duplicate-values"&&(s=i.options);let l=this.Evaluate(n,r,s,!0);i.internal.vertex.result=l,i.internal.vertex.updated=!0}let o=i.internal.vertex;this.AddLeafVertex(o),this.UpdateLeafVertex(o,n,r)}}RemoveAnnotation(t){let r=t.temp;r.vertex&&(r.vertex.Reset(),this.RemoveLeafVertex(r.vertex))}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){let n=i.temp;n.vertex||(n.vertex=new ft),this.AddLeafVertex(n.vertex),this.UpdateLeafVertex(n.vertex,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.GetName(t.name,r?.sheet_id||0);if(i&&i.type==="range")return new y(i.area.start,i.area.end)}break}}NamedRangeToAddressUnit(t,r){let i=t.name.toUpperCase(),n=this.model.GetName(i,r.sheet_id||0);if(n&&n.type==="range")return n.area.count===1?this.ConstructAddressUnit(n.area.start,i,t.id,t.position):{type:"range",start:this.ConstructAddressUnit(n.area.start,i,t.id,t.position),end:this.ConstructAddressUnit(n.area.end,i,t.id,t.position),label:i,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:{}},o){if(!i){let a=this.model.sheets.Find(r);a&&(i=a.name)}switch(t.type){case"literal":case"missing":case"operator":break;case"identifier":{let a=this.model.GetName(t.name,o.sheet_id||0);if(a?.type==="expression")this.RebuildDependencies(a.expression,r,i,n,o);else{let s=this.NamedRangeToAddressUnit(t,o);s&&(s.type==="address"?n.addresses[s.label]=s:n.ranges[s.label]=s)}}break;case"structured-reference":{let a=this.model.ResolveStructuredReference(t,o);a&&(a.type==="address"?n.addresses[a.sheet_id+"!"+a.label]=a:n.ranges[a.label]=a);let s=this.model.tables.get(t.table.toLowerCase());if(s){let l=o.row;if(l<s.area.start.row||l>s.area.end.row)break;let d=t.column.toLowerCase(),h=-1;if(s.columns){for(let u=0;u<s.columns.length;u++)if(d===s.columns[u]){h=s.area.start.column+u;break}}if(h>=0){let u={label:t.label,type:"address",row:l,column:h,sheet_id:s.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 a=this.model.sheets.Find(t.sheet);a&&(t.sheet_id=a.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 a=this.model.sheets.Find(t.start.sheet);a&&(t.start.sheet_id=a.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,o);break;case"binary":this.RebuildDependencies(t.left,r,i,n,o),this.RebuildDependencies(t.right,r,i,n,o);break;case"group":t.elements.forEach(a=>this.RebuildDependencies(a,r,i,n,o));break;case"call":{let a=t.args.slice(0),s=this.library.Get(t.name);s&&s.arguments&&s.arguments.forEach((l,d)=>{l&&l.address&&(this.RebuildDependencies(a[d],r,i,void 0,o),a[d]={type:"missing",id:-1})}),a.forEach(l=>this.RebuildDependencies(l,r,i,n,o))}break}return n}UpdateLeafVertex(t,r,i){t.Reset();let n=this.parser.Parse(r);if(n.expression){let o=this.RebuildDependencies(n.expression,i.id,i.name,void 0,{row:0,column:0});for(let a of Object.keys(o.ranges)){let s=o.ranges[a],l=new y(s.start,s.end);l.entire_column||l.entire_row||l.count>1?this.AddLeafVertexArrayEdge(l,t):this.AddLeafVertexEdge(l.start,t)}for(let a of Object.keys(o.addresses)){let s=o.addresses[a];this.AddLeafVertexEdge(s,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,o=i.sheet_id||r.sheet_id;i.sheet_id||(i.sheet_id=o);for(let a=i.column;a<=n.column;a++)for(let s=i.row;s<=n.row;s++)this.ResetInbound({column:a,row:s,sheet_id:o},!0,!1);this.SetDirty(r);for(let a=i.column;a<=n.column;a++)for(let s=i.row;s<=n.row;s++)s===i.row&&a===i.column||this.AddEdge(i,{...i,row:s,column:a})}if(t.type===1){this.ResetInbound(r,!0);let i=this.parser.Parse(t.value);if(i.expression){if(i.expression.type==="call"){let a=this.library.Get(i.expression.name);a&&(a.render||a.click)&&(t.render_function=a.render,t.click_function=a.click)}let o=this.RebuildDependencies(i.expression,r.sheet_id,"",void 0,r);for(let a of Object.keys(o.ranges)){let s=o.ranges[a],l=new y(s.start,s.end);if(l.entire_row||l.entire_column)this.AddArrayEdge(l,r);else for(let d of l)this.AddEdge(d,r)}for(let a of Object.keys(o.addresses)){let s=o.addresses[a];this.AddEdge(s,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 o=t.start.column;o<=t.end.column;o++){let a=n[o];a&&this.RebuildGraphCell(a,{row:i,column:o,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 o=r.cells.data[n];if(o){let a=o.length;for(let s=0;s<a;s++){let l=o[s];l&&this.RebuildGraphCell(l,{row:n,column:s,sheet_id:r.id})}}}}}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 tr=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 29.5.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()})}Node(e){return this.model[e]}Update(e,t=!0){t&&(e={...this.options_,...e}),this.options=e}HideDialog(){this.visible=!1}ShowDialog(e){return new Promise(t=>{this.pending_dialog_resoltion.push(t),this.options=e,this.visible=!0,this.timeout&&(window.clearTimeout(this.timeout),this.timeout=0),e.timeout&&(this.timeout=window.setTimeout(()=>this.HideDialog(),e.timeout))})}};var rr=class{constructor(e){this.container=e;let t=P.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 dn={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 ge=c=>!!c&&typeof c=="object"&&c.key==="metadata"&&!!c.value&&c.value.type==="metadata",Jr=c=>!!c&&typeof c=="object"&&c.key==="series"&&Array.isArray(c.value),hn=c=>!!c&&typeof c=="object"&&c.type===8&&Array.isArray(c.value);var $=class{static Scale(e,t,r=6.5,i,n){return gi(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 Xr="#,##0.00",un=c=>{let[e,t,r,i,n,o,a]=c,s={x:{data:[]},y:{data:[]}};if(typeof n=="number"&&(s.index=n),o&&(s.subtype=o.toString()),a){let h=$.Flatten(Array.isArray(a)?a:[a]);s.labels=h.map(u=>typeof u>"u"?"":u.toString())}e&&(s.label=e.toString());let l=(h,u=!1)=>{let m;if(ge(h)&&(h={type:8,value:[[h]]}),hn(h)){m={data:[]};let f=$.Flatten(h.value);if(m.data=f.map(p=>{if(ge(p)){if(typeof p.value.value=="number")return p.value.value}else if(p.type===3)return p.value}),ge(f[0])&&f[0].value?.format&&(m.format=f[0].value.format,u)){let p=z.Get(m.format);m.labels=m.data.map(b=>b===void 0?void 0:p.Format(b))}}return m};s.y=l(r,!0)||{data:[]},s.x=l(t)||{data:[]},s.z=l(i);let d=[s.x,s.y];for(let h of d)if(h.data.length){let u=h.data.filter(m=>m||m===0);h.range={min:Math.min.apply(0,u),max:Math.max.apply(0,u)}}return s},mn=c=>{let e={x:{data:[]},y:{data:[]}},t=$.Flatten(c.value);e.y.data=t.map((n,o)=>{if(typeof n.value=="number")return n.value;if(ge(n)){if(ae(n.value.value))return e.x.data[o]=n.value.value.real,n.value.value.imaginary;if(typeof n.value.value=="number")return n.value.value}});let r="";if(ge(t[0])&&(r=t[0].value.format||""),r){e.y.format=r;let n=z.Get(e.y.format||"");e.y.labels=e.y.data.map(o=>o===void 0?void 0:n.Format(o))}let i=e.y.data.filter(n=>n||n===0);if(e.y.range={min:Math.min.apply(0,i),max:Math.max.apply(0,i)},e.x.data.length){let n=e.x.data.filter(o=>typeof o=="number");if(e.x.range={min:Math.min.apply(0,n),max:Math.max.apply(0,n)},r){e.x.format=r;let o=z.Get(e.x.format||"");e.x.labels=e.x.data.map(a=>a===void 0?void 0:o.Format(a))}}return e},nr=(c,e)=>{if(!c)return[];let t=[];if(c.type===5){if(c.key==="group"){if(Array.isArray(c.value)){for(let[n,o]of c.value.entries())if(o&&typeof o=="object")if(Jr(o)){let a=un(o.value);typeof a.index>"u"&&(a.index=n+1),t.push(a)}else o.type===8&&t.push(mn(o))}}else if(Jr(c)){let n=un(c.value);t.push(n)}}else c.type===8&&t.push(mn(c));let r,i=0;if(e?.type===8){let n=$.Flatten(e.value),o="0.00###";ge(n[0])&&n[0].value.format&&(o=n[0].value.format);let a=n.map(l=>{if(l.type===3)return l.value;if(ge(l)&&typeof l.value.value=="number")return l.value.value}),s=a.filter(l=>typeof l=="number");r={data:a,format:o,range:{min:Math.min.apply(0,s),max:Math.max.apply(0,s)}}}for(let n of t)i=Math.max(i,n.y.data.length),n.x.data.length&&(r||(r=n.x));if(!r){r={data:[],range:{min:0,max:Math.max(0,i-1)}};for(let n=0;n<i;n++)r.data.push(n)}for(let n of t)n.x.data.length||(n.x=r);return t},or=(c,e,t,r,i)=>{let n="",o="";for(let g of c)g.y.format&&!o&&(o=g.y.format),g.x.format&&!n&&(n=g.x.format);let a;c.some(g=>g.label&&g.label.length>0)&&(a=c.map((g,C)=>({label:g.label||`Series ${C+1}`,index:typeof g.index=="number"?g.index:C+1})));let s=c.filter(g=>g.x.range),l=Math.min.apply(0,s.map(g=>g.x.range?.min||0)),d=Math.max.apply(0,s.map(g=>g.x.range?.max||0)),h=Math.min.apply(0,s.map(g=>g.y.range?.min||0)),u=Math.max.apply(0,s.map(g=>g.y.range?.max||0));for(let g of c)if(g.z){for(let[C,x]of g.z.data.entries())if(typeof x<"u"){let v=g.x.data[C],_=Math.max(0,x/2);typeof v<"u"&&(l=Math.min(l,v-_),d=Math.max(d,v+_));let w=g.y.data[C];typeof w<"u"&&(h=Math.min(h,w-_),u=Math.max(u,w+_))}}typeof r<"u"&&(l=Math.min(l,r)),typeof i<"u"&&(l=Math.max(l,i)),typeof e<"u"&&(h=Math.min(h,e)),typeof t<"u"&&(u=Math.max(u,t));let m=$.Scale(l,d,7),f=$.Scale(h,u,7),p,b;if(n){p=[];let g=z.Get(n);for(let C=0;C<=m.count;C++)p.push(g.Format(m.min+C*m.step))}if(o){b=[];let g=z.Get(o);for(let C=0;C<=f.count;C++)b.push(g.Format(f.min+C*f.step))}return{x:{format:n,scale:m,labels:p},y:{format:o,scale:f,labels:b},legend:a}},ir=(c,e,t)=>{for(let r of c){let i={x:z.Get(r.x.format||""),y:z.Get(r.y.format||"")};r.y.labels=[];for(let n=0;n<r.y.data.length;n++){let o=t?t[n]:typeof r.x.data[n]=="number"?i.x.Format(r.x.data[n]):"",a=typeof r.y.data[n]=="number"?i.y.Format(r.y.data[n]):"";r.y.labels[n]=e.replace(/\bx\b/g,o).replace(/\by\b/g,a)}}},fn=c=>{let e=nr(c[0]),t,r;for(let a of e)typeof a.x.range?.min=="number"&&a.x.range.min>0&&a.x.range.min<50&&(r=0),typeof a.y.range?.min=="number"&&a.y.range.min>0&&a.y.range.min<50&&(t=0);let i=or(e,t,void 0,r),n=c[1]?.toString()||void 0;return{legend:i.legend,legend_style:2,type:"bubble",series:e,title:n,x_scale:i.x.scale,x_labels:i.x.labels,y_scale:i.y.scale,y_labels:i.y.labels}},Qr=(c,e="plot")=>{let t=nr(c[0]),r=or(t),i=c[1]?.toString()||void 0,n=c[2]?.toString()||void 0,o={legend:r.legend,style:e,type:"scatter2",series:t,title:i,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:e==="line",points:e==="plot"};if(n){o.markers=/marker/i.test(n),o.smooth=/smooth/i.test(n),o.data_labels=/labels/i.test(n);let a=n.match(/labels="(.*?)"/);a&&o.series?ir(o.series,a[1]):(a=n.match(/labels=([^\s\r\n,]+)(?:\W|$)/),a&&o.series&&ir(o.series,a[1])),a=n.match(/class=([\w_-]+)(?:\W|$)/),a&&(o.class_name=a[1])}return o},qr=(c,e)=>{let[t,r,i,n]=c,o=nr(t),a=or(o),s;if(r){s=(r.type===8?$.Flatten(r.value):$.Flatten(r)).map(f=>!f||!f.value?"":ge(f)?typeof f.value.value=="number"?z.Get(f.value.format||Xr).Format(f.value.value):f.value.value?.toString()||"":typeof f.value=="number"?z.Get(Xr).Format(f.value):f.value.toString());let m=o.reduce((f,p)=>Math.max(f,p.y.data.length),0);for(m<s.length&&(s=s.slice(0,m));m>s.length;)s.push("")}let l=i?.toString()||void 0,d=n?.toString()||void 0,h={type:e,legend:a.legend,legend_style:1,series2:o,scale:a.y.scale,title:l,y_labels:e==="bar"?s:a.y.labels,x_labels:e==="bar"?a.y.labels:s};if(d){h.round=/round/i.test(d),h.data_labels=/labels/i.test(d);let u=d.match(/labels="(.*?)"/);u&&o?ir(o,u[1],s):(u=d.match(/labels=([^\s\r\n,]+)(?:\W|$)/),u&&o&&ir(o,u[1],s)),u=d.match(/class=([\w_-]+)(?:\W|$)/),u&&(h.class_name=u[1])}return h},Kr=(c,e)=>{let t=nr(c[0],c[1]),r=or(t,0,0),i=c[2]?.toString()||void 0,n=c[3]?.toString()||void 0,o={legend:r.legend,type:"scatter2",series:t,title:i,x_scale:r.x.scale,x_labels:r.x.labels,y_scale:r.y.scale,y_labels:r.y.labels,lines:!0,filled:e==="area"};if(n){o.smooth=/smooth/i.test(n);let a=n.match(/class=([\w_-]+)(?:\W|$)/);a&&(o.class_name=a[1])}return o},pn=(c,e=!1)=>{let[t,r,i,n,o]=c,a=c[0]?.type===8?c[0].value:c[0],s=a?$.Flatten(a):[],l=s.map(_=>{if(ge(_)&&typeof _.value.value=="number")return _.value.value}),d=c[1]?.type===8?c[1].value:c[1],h=$.Flatten(d||[]).map(_=>ge(_)?typeof _.value.value=="number"&&_.value.format?z.Get(_.value.format).Format(_.value.value):_.value.value?.toString()||"":_.value?.toString()||""),u=!1;l=l.map(_=>_&&_<0?(u||(console.warn("pie/donut chart does not support negative values (omitted)"),u=!0),0):_);let m=0,f=l.map((_,w)=>(typeof _<"u"&&(m+=_),{value:_||0,label:h[w]||"",index:w+1,percent:0}));if(m)for(let _ of f)_.percent=(_.value||0)/m;let p="";for(let _ of s)if(ge(_)){p=_.value.format||"";break}let b=z.Get(p||Xr),g=z.Get("percent");typeof c[4]>"u"&&c[1]&&(c[4]="label");let C=c[4]||"";if(C)for(let _ of f){let w=b.Format(_.value||0),A=g.Format(_.percent);_.title=C.replace(/value%/ig,g.Format(_.value||0)).replace(/value/ig,w).replace(/percent/ig,A).replace(/label/ig,_.label||"").trim()}let x=(n||"").toUpperCase();if(x==="ASC"||x==="ASCENDING"||x==="INC")f.sort((_,w)=>(_.value||0)-(w.value||0));else if(x==="DESC"||x==="DESCENDING"||x==="DEC")f.sort((_,w)=>(w.value||0)-(_.value||0));else{let _=(n||"").match(/sort=([\w]+)(?:\W|$)/i);_&&(x=_[1],/^(asc|inc)/i.test(x)?f.sort((w,A)=>(w.value||0)-(A.value||0)):/^(desc|dec)/i.test(x)&&f.sort((w,A)=>(A.value||0)-(w.value||0)))}let v={type:e?"pie":"donut",slices:f,title:i||""};if(n){let _=n.match(/class=([_-\w]+)(?:\W|$)/);_&&(v.class_name=_[1])}return v};var Me=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 Oo="http://www.w3.org/2000/svg",M=(c,e={},t)=>{let r=document.createElementNS(Oo,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},ar=class{parent;svg_node;text_measurement_node;container_group;group;axis_group;label_group;size={width:0,height:0};bounds=new Me;constructor(){this.container_group=M("g"),this.group=M("g"),this.axis_group=M("g",{class:"axis-group"}),this.label_group=M("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=M("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=M("g");this.group.appendChild(t);let r=M("text");t.appendChild(r),t.setAttribute("class","legend");let i=[[]],n=10,o=e.area.width,a=0,s=0,l=e.area.width,d=e.style===1?14:26,h=e.labels.map((b,g)=>{r.textContent=b.label;let C=r.getBoundingClientRect(),x={width:C.width,height:C.height},v=x.width+d+n;return s=Math.max(s,x.height),e.layout===1?i[g]=[g]:v>o?i[a].length===0?(i[a].push(g),a++,i[a]=[],o=l):(a++,i[a]=[g],o=l-v):(i[a].push(g),o-=v),x});t.removeChild(r);let u=s,m=e.layout||0;m===0&&i.every(b=>b.length<=1)&&(m=0);for(let b=0;b<i.length;b++){let g=i[b].reduce((v,_)=>v+h[_].width+d,(i[b].length-1)*n),C=0,x=m===0?Math.round((l-g)/2):Math.round(n/2);for(let v=0;v<i[b].length;v++){let _=i[b][v],w=h[_],A=e.labels[_],S=u-1,I=!1;typeof navigator<"u"&&(I=/trident/i.test(navigator?.userAgent||""));let L=typeof A.index=="number"?A.index:_+1;switch(t.appendChild(M("text",{"dominant-baseline":"middle",x:x+d,y:u,dy:I?".3em":void 0},A.label)),e.style){case 1:t.appendChild(M("rect",{class:`series-${L}`,x,y:S-4,width:8,height:8}));break;case 2:t.appendChild(M("circle",{class:`series-${L}`,cx:x+d-11,cy:S-4+3}));break;default:t.appendChild(M("rect",{class:`series-${L}`,x,y:S-1,width:d-3,height:2}));break}C=Math.max(C,w.height),x+=w.width+d+n}u=Math.round(u+C*1.1)}let f=t.getBoundingClientRect(),p={width:f.width,height:f.height+s};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=M("text",{class:"chart-title",x:Math.round(t.width/2)},e);n.style.textAnchor="middle",this.group.appendChild(n);let o=n.getBoundingClientRect();switch(i){case"bottom":n.setAttribute("y",Math.round(t.bottom-o.height).toString()),t.bottom-=o.height+r;break;default:n.setAttribute("y",Math.round(t.top+r+o.height).toString()),t.top+=o.height+r;break}}MeasureText(e,t,r=!1){this.text_measurement_node||(this.text_measurement_node=M("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 o=[],a=e.width/i;for(let s=0;s<i;s++){let l=Math.round(e.left+a/2+a*s)-.5;o.push(`M${l} ${t} L${l} ${r}`)}this.group.appendChild(M("path",{d:o,class:n}))}RenderXAxisBar(e,t,r,i,n){let o=r.length;if(!o)return;let a=4,s=t?e.width/o:e.width/(o-1),l=t?s/2:0,d=1,h=!0;for(;h;){h=!1;let u=0;for(let m=0;m<o;m+=d){let f=Math.round(e.left+l+s*m),p=f-i[m].width/2;if(u&&p<=u){d++,h=!0;break}u=f+i[m].width/2+a}}for(let u=0;u<o;u+=d){let m=Math.round(e.left+l+s*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,o=[];for(let a=0;a<r;a++){let s=Math.round(e.left+n+i*a)+.5;o.push(`M${s},${e.bottom+.5} v6`)}this.axis_group.appendChild(M("path",{d:o.join(" "),class:"x-axis-tick axis-tick"}))}RenderXAxis(e,t,r,i,n){let o=r.length;if(!o)return;let a=4,s=t?e.width/o:e.width/(o-1),l=t?s/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<o;p+=d){let b=Math.round(e.left+l+s*p),g=b-i[p].width/2;if(f&&g<=f){d++,h=!0;break}f=b+i[p].width/2+a}}d===3&&!m&&u&&d++;for(let f=0;f<o;f+=d){let p=Math.round(e.left+l+s*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 o=e.height/n,a=1,s=!0;for(;s;){s=!1;let l=0;for(let d=0;d<n;d+=a){let h=r[d],u=Math.round(e.bottom-o*(d+.5)+h.metrics.height/4);if(l&&u>=l){a++,s=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=a){let d=r[l],h=Math.round(e.bottom-o*(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 o=e.height/(n-1),a=1,s=!0;for(;s;){s=!1;let l=0;for(let d=0;d<n;d+=a){let h=r[d],u=Math.round(e.bottom-o*d+h.metrics.height/4);if(l&&u>=l){a++,s=!0;break}l=u-h.metrics.height}}for(let l=0;l<n;l+=a){let d=r[l],h=Math.round(e.bottom-o*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 o=M("g"),a=[],s=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=t.map((b,g)=>{if(!(typeof b>"u"))return{x:Math.round(e.left+e.width/d*g),y:e.bottom-b}}),f=[],p=()=>{if(f.length<2)return;let b="",g=f[0],C=f[f.length-1];f.length===2?b=`${f[0].x},${f[0].y} L${f[1].x},${f[1].y}`:f.length>2&&(b=""+this.CatmullRomChain(f).map(v=>`${v.x},${v.y}`).join(" L")),b&&(a.push("M"+b),r&&(s.push(`M ${g.x},${e.bottom} L ${g.x},${g.y}`),s.push("L"+b),s.push(`L ${C.x},${e.bottom}`)))};for(let b of m)b?f.push(b):(p(),f=[]);if(f.length&&p(),r&&o.appendChild(M("path",{class:"fill",d:s})),o.appendChild(M("path",{class:"line",d:a})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),o.setAttribute("class",n.join(" "))),this.group.appendChild(o),i&&u.length){let b=M("g");for(let g of u){let C=M("circle",{cx:g.x,cy:g.y,r:h});C.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i[g.i]||"")}),C.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),b.appendChild(C)}b.setAttribute("class","mouse-layer"),this.group.appendChild(b)}}RenderLine(e,t,r=!1,i,n){let o=M("g"),a=[],s=[],l=t.length,d=l-1,h=e.width/l/2,u=[],m=0,f=!0,p;for(;m<l;m++){let b=t[m];if(typeof b>"u"){f=!0,r&&typeof p<"u"&&s.push(`L${p} ${e.bottom}Z`),p=void 0;continue}let g=Math.round(+e.left+e.width/d*m);f?(r&&s.push(`M${g} ${e.bottom} L${g} ${e.bottom-b}`),a.push(`M${g} ${e.bottom-b}`)):(a.push(`L${g} ${e.bottom-b}`),s.push(`L${g} ${e.bottom-b}`)),u.push({x:g,y:e.bottom-b,i:m}),p=g,f=!1}if(r&&typeof p<"u"&&s.push(`L${p} ${e.bottom}Z`),r&&o.appendChild(M("path",{class:"fill",d:s})),o.appendChild(M("path",{class:"line",d:a})),typeof n<"u"&&(typeof n=="string"&&(n=[n]),o.setAttribute("class",n.join(" "))),this.group.appendChild(o),i&&u.length){let b=M("g");for(let g of u){let C=M("circle",{cx:g.x,cy:g.y,r:h});C.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i[g.i]||"")}),C.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")}),b.appendChild(C)}b.setAttribute("class","mouse-layer"),this.group.appendChild(b)}}RenderBarGrid(e,t,r){let i=[],n=e.width/t;for(let o=0;o<=t;o++){let a=Math.round(e.left+n*o)-.5;i.push(`M${a} ${e.top} L${a} ${e.bottom}`)}this.group.appendChild(M("path",{d:i,class:r}))}RenderGrid(e,t,r=0,i,n){let o=[],a=[],s=e.height/t;for(let l=0;l<=t;l++){let d=Math.round(e.top+s*l)-.5;n&&n[1]===l?a.push(`M${e.left} ${d} L${e.right} ${d}`):o.push(`M${e.left} ${d} L${e.right} ${d}`)}s=e.width/(r-1);for(let l=0;l<r;l++){let d=Math.round(e.left+s*l)-.5;n&&n[0]===l?a.push(`M${d} ${e.top} L${d} ${e.bottom}`):o.push(`M${d} ${e.top} L${d} ${e.bottom}`)}this.group.appendChild(M("path",{d:o,class:i})),a.length&&(i?Array.isArray(i)?i.push("zero"):i=i+" zero":i="zero",this.group.appendChild(M("path",{d:a,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:b,y:g}=m;return((b-f)**2+(g-p)**2)**r+h},n=0,o=i(n,e[0],e[1]),a=i(o,e[1],e[2]),s=i(a,e[2],e[3]),l=(a-o)/t,d=[];for(let h=0;h<t;h++){let u=o+l*h,m=this.AddPoints(this.MultiplyPoint(e[0],(o-u)/(o-n)),this.MultiplyPoint(e[1],(u-n)/(o-n))),f=this.AddPoints(this.MultiplyPoint(e[1],(a-u)/(a-o)),this.MultiplyPoint(e[2],(u-o)/(a-o))),p=this.AddPoints(this.MultiplyPoint(e[2],(s-u)/(s-a)),this.MultiplyPoint(e[3],(u-a)/(s-a))),b=this.AddPoints(this.MultiplyPoint(m,(a-u)/(a-n)),this.MultiplyPoint(f,(u-n)/(a-n))),g=this.AddPoints(this.MultiplyPoint(f,(s-u)/(s-o)),this.MultiplyPoint(p,(u-o)/(s-o))),C=this.AddPoints(this.MultiplyPoint(b,(a-u)/(a-o)),this.MultiplyPoint(g,(u-o)/(a-o)));d.push(C)}return d}CatmullRomChain(e,t=30){let r=e.slice(0),i=[],n=r.length;if(n){let o=r[n-1].x-r[n-2].x,a=r[n-1].y-r[n-2].y;r.push({x:r[n-1].x+o,y:r[n-1].y+a}),r.push({x:r[n-1].x+o,y:r[n-1].y+a}),o=r[1].x-r[0].x,a=r[1].y-r[0].y,r.unshift({x:r[0].x-o,y:r[0].y-a});for(let s=0;s<r.length-4;s++){let l=r.slice(s,s+4),d=this.CatmullRomSpline(l,t);i.push(...d)}}return i}RenderDataLabels(e,t,r,i,n,o,a){let s=Math.max(t.length,r.length),l=i.max-i.min||1,d=n.max-n.min||1;for(let h=0;h<s;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=o[h];if(p){this.label_group.appendChild(M("circle",{class:"label-target",cx:f.x,cy:f.y,r:10}));let b=M("g",{class:"data-label",transform:`translate(${f.x+10},${f.y})`});this.label_group.appendChild(b);let g=M("circle",{cx:-10,y:0,r:5,class:`marker-highlight series-${a}`});b.appendChild(g);let C=M("text",{x:4,y:0},p);b.appendChild(C);let x=C.getBoundingClientRect(),v=x.height,_=x.width+8;_+15+f.x>=e.right&&(b.setAttribute("transform",`translate(${f.x-_-15},${f.y})`),g.setAttribute("cx",(_+15).toString()));let w=M("path",{d:`M0,5 h${_} v-${v} h-${_} Z`});b.insertBefore(w,C)}}}}RenderBubbleSeries(e,t,r,i,n){let o=r.max-r.min||1,a=i.max-i.min||1,s=[],l=[],d=M("g",{class:n});if(this.group.appendChild(d),t.z)for(let[h,u]of t.z.data.entries()){let m=t.x.data[h],f=t.y.data[h];if(typeof m<"u"&&typeof f<"u"&&typeof u<"u"&&u>0){let p=u/o*e.width,b=u/a*e.height,g=Math.max(p,b),C={x:e.left+(m-r.min)/o*e.width,y:e.bottom-(f-i.min)/a*e.height,z:g};if(s.push(C),t.labels?.[h]){let x=C.z/2;l.push({x:C.x,y:C.y,text:t.labels?.[h]||"",offset:Math.cos(Math.PI/4)*x})}}}for(let h of s)h&&d.appendChild(M("circle",{cx:h.x,cy:h.y,r:h.z/2,class:"point"}));if(l.length){let h=this.label_group.getBoundingClientRect();for(let u of l)if(u.text){let m=this.label_group.appendChild(M("g",{class:"bubble-label"})),f=m.appendChild(M("rect",{x:u.x,y:u.y,class:"label-background"})),b=m.appendChild(M("text",{x:u.x,y:u.y,offset:u.offset,class:"label-text","text-anchor":"middle","alignment-baseline":"middle",style:`--translate-offset: ${Math.round(u.offset)}px`},u.text)).getBoundingClientRect();f.setAttribute("x",(b.left-h.left-2).toString()),f.setAttribute("y",(b.top-h.top-1).toString()),f.style.height=b.height+2+"px",f.style.width=b.width+4+"px"}}}RenderScatterSeries(e,t,r,i,n,o=!0,a=!1,s=!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=[],b=[],g=[],C=M("g",{class:h});this.group.appendChild(C);for(let x=0;x<u;x++){let v=t[x],_=r[x];typeof v>"u"||typeof _>"u"?p.push(void 0):p.push({x:e.left+(v-i.min)/m*e.width,y:e.bottom-(_-n.min)/f*e.height})}if(o){let x=[],v=d?()=>x.length===2?`${x[0].x},${x[0].y} L${x[1].x},${x[1].y}`:x.length>2?this.CatmullRomChain(x).map(w=>`${w.x},${w.y}`).join(" L"):"":()=>x.map(_=>`${_.x},${_.y}`).join(" L");for(let _ of p)if(_)x.push(_);else{if(x.length>=2){let w=v();b.push("M"+w),g.push(`M${x[0].x},${e.bottom}L`+w+`L${x[x.length-1].x},${e.bottom}Z`)}x=[]}if(x.length>=2){let _=v();b.push("M"+_),g.push(`M${x[0].x},${e.bottom}L`+_+`L${x[x.length-1].x},${e.bottom}Z`)}}if(s&&C.appendChild(M("path",{d:g,class:"fill"})),o&&C.appendChild(M("path",{d:b,class:"line"})),a)for(let x of p)x&&C.appendChild(M("circle",{cx:x.x,cy:x.y,r:1,class:"point"}));if(l)for(let x of p)x&&C.appendChild(M("circle",{cx:x.x,cy:x.y,r:3,class:"marker"}))}RenderPoints(e,t,r,i){let n=[];for(let o=0;o<t.length;o++){let a=t[o]*e.width+e.left,s=e.bottom-r[o]*e.height;n.push(`M${a-1},${s-1} L${a+1},${s+1}`),n.push(`M${a-1},${s+1} L${a+1},${s-1}`)}this.group.appendChild(M("path",{d:n,class:i}))}RenderPoint(e,t,r){this.group.appendChild(M("circle",{cx:e,cy:t,r:1,class:r}))}RenderCalloutLines(e){let t=M("g",{class:"callouts"});this.label_group.appendChild(t);for(let r of e)t.appendChild(M("path",{d:`M${r.x1},${r.y1} L${r.x2},${r.y2}`,class:"callout "+(r.classes||"").trim()}))}RenderRectangle(e,t,r,i,n,o){let a="";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);a=`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);a=`M${e.left},${e.top+e.height/2-h} a${l},${l} 0 0 1 0,${h*2} z`}else a=`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 a=`M${e.left},${e.top} h${e.width} v${e.height} h${-e.width} v${-e.height} `;let s=M("path",{d:a,class:r});if(i&&(s.addEventListener("mouseenter",()=>{this.parent.setAttribute("title",i)}),s.addEventListener("mouseleave",()=>{this.parent.setAttribute("title","")})),this.group.appendChild(s),n){this.label_group.appendChild(M("path",{class:"label-target",d:a}));let l=o||{x:Math.round(e.left+e.width/2),y:Math.round(e.top-10)},d=M("g",{class:"data-label",transform:`translate(${l.x},${l.y})`});this.label_group.appendChild(d);let h=M("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),b=M("rect",{rx:3,x:-f/2,y:Math.round(-m+p*2/3),width:f,height:m+p});d.insertBefore(b,h)}}RenderText(e,t,r,i,n){let o=M("text",{x:i.x,y:i.y,class:n},t);switch(r){case"right":o.style.textAnchor="end";break;case"center":o.style.textAnchor="middle";break;default:o.style.textAnchor="start";break}(e||this.group).appendChild(o)}RenderDonut(e,t,r,i,n,o,a){let s=-Math.PI/2,l=0;o&&(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=[],b=0,g=d.bind(0,t,r),C=d.bind(0,t,i);if(m>.5){b=s+m/2*Math.PI*2,l=s+m*Math.PI*2;let _=b-s,w=l-b;p.push(`M${g(s)}`,`A${r},${r},${_},0,1,${g(b)}`,`A${r},${r},${w},0,1,${g(l)}`,`L${C(l)}`,`A${i},${i},${w},0,0,${C(b)}`,`A${i},${i},${_},0,0,${C(s)}`,"Z")}else{l=s+m*Math.PI*2,b=(l-s)/2+s;let _=l-s;p.push(`M${g(s)}`,`A${r},${r},${_},0,1,${g(l)}`,`L${C(l)}`,`A${i},${i},${_},0,0,${C(s)}`,"Z")}let x=M("path",{d:p,class:typeof f>"u"?void 0:`series-${f}`});typeof f<"u"&&x.setAttribute("data-index",f.toString());let v=M("g",{class:a});if(v.appendChild(x),this.group.appendChild(v),m>=.05&&u){let _=r-i;p=[];let w=d(t,i+(r-i)/2+_,b);p.push(`M${d(t,i+(r-i)/2,b)}`),p.push(`L${w}`),v.appendChild(M("path",{d:p,class:"callout"}));let A=[],S=M("text",{class:"callout-label"});v.appendChild(S);let I=b+Math.PI/2,L=u;S.textContent=L;let O=S.getBoundingClientRect(),_e={width:O.width,height:O.height},[ne,T]=w;ne+=_e.height/2*Math.cos(b),T+=_e.height/4+_e.height/2*Math.sin(b);let te=!1;I>Math.PI?ne-_e.width<=n.left&&(te=!0):ne+_e.width>n.right&&(te=!0);let oe=/[\s-]/;if(te&&oe.test(L)){let Q=-1,q=1;for(let B=0;B<L.length;B++)if(oe.test(L[B])){let D=Math.abs(.5-B/L.length);D<q&&(q=D,Q=B)}Q>0&&(A.push(L.substr(0,Q+1).trim()),A.push(L.substr(Q+1).trim()))}if(A.length){let Q=0,q=0,B=A.map(D=>{S.textContent=D,O=S.getBoundingClientRect();let Y={width:O.width,height:O.height};return q=Math.max(q,Y.width),{text:D,metrics:Y}});S.textContent="";for(let D of B){let Y=M("tspan");Y.textContent=D.text;let vn=I>Math.PI?ne-(q-D.metrics.width)/2:ne+(q-D.metrics.width)/2;Y.setAttribute("x",vn.toString()),Y.setAttribute("dy",Q.toString()),S.appendChild(Y),Q=D.metrics.height}}let k=I>Math.PI?"end":"start";S.setAttribute("text-anchor",k),S.setAttribute("x",ne.toString()),S.setAttribute("y",T.toString()),typeof f<"u"&&S.setAttribute("data-index",f.toString())}s=l}}};var sr=class{renderer=new ar;margin={top:.025,left:.05,bottom:.025,right:.075};Resize(e,t){this.renderer.Resize()}Initialize(e){this.renderer.Initialize(e)}Update(e,t){this.renderer.Resize(),this.renderer.Prerender(),this.renderer.Clear(t.class_name);let r=new Me(0,0,this.renderer.size.width,this.renderer.size.height),i={top:Math.round(r.height)*this.margin.top,bottom:Math.round(r.height)*this.margin.bottom,left:Math.round(r.width)*this.margin.left,right:Math.round(r.width)*this.margin.right},n=t.title;if(n&&this.renderer.RenderTitle(n,r,i.top,t.title_layout||"top"),r.top+=i.top,r.left+=i.left,r.bottom-=i.bottom,r.right-=i.right,t.legend&&t.legend.length){let a=0;t.title&&(!t.title_layout||t.title_layout==="top")&&(a=1);let s=t.legend_position||a;this.renderer.Legend({labels:t.legend,position:s,style:t.legend_style,layout:s===0||s===1?0:1,area:r})}if(t.type==="histogram"||t.type==="line"||t.type==="area"||t.type==="column"||t.type==="histogram2"||t.type==="bar"||t.type==="scatter2"||t.type==="bubble"){let a=[],s=0;if(t.x_labels&&t.x_labels.length&&(a=t.x_labels.map(l=>{let d=this.renderer.MeasureText(l,["axis-label","x-axis-label"],!0);return s=Math.max(s,d.height),d})),t.y_labels&&t.y_labels.length){let l=[],d=0,h=0,u=t.type==="scatter2"||t.type==="bubble"?t.y_scale:t.scale,m=t.type==="bar"?t.y_labels.length:u.count+1;for(let f=0;f<m;f++){let p=this.renderer.MeasureText(t.y_labels[f],["axis-label","y-axis-label"]);l.push({label:t.y_labels[f],metrics:p}),d=Math.max(d,p.width),h=Math.max(h,p.height)}r.bottom=Math.round(r.bottom-h/2),r.top=Math.round(r.top+h/2),a.length&&(r.bottom-=s+i.bottom),t.type==="bar"?this.renderer.RenderYAxisBar(r,r.left+d,l,["axis-label","y-axis-label"]):this.renderer.RenderYAxis(r,r.left+d,l,["axis-label","y-axis-label"]),r.left+=d+i.left}if(a.length&&t.x_labels&&t.x_labels.length){let l=t.type==="histogram2",d=t.type!=="line"&&t.type!=="area"&&t.type!=="bar"&&t.type!=="scatter2"&&t.type!=="bubble"&&t.type!=="histogram2";l&&this.renderer.RenderXAxisTicks(r,d,t.x_labels.length),t.y_labels&&(r.bottom+=s+i.bottom),this.renderer.RenderXAxis(r,d,t.x_labels,a,["axis-label","x-axis-label"]),r.bottom-=s+i.bottom}}let o=[];switch(t.type){case"scatter":this.renderer.RenderPoints(r,t.x,t.y,"mc mc-correlation series-1");break;case"bubble":t.x_scale.min<=0&&t.x_scale.max>=0&&(o[0]=Math.round(Math.abs(t.x_scale.min/t.x_scale.step))),t.y_scale.min<=0&&t.y_scale.max>=0&&(o[1]=Math.round(Math.abs(t.y_scale.max/t.y_scale.step))),this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid",o);for(let[a,s]of t.series.entries()){let l=typeof s.index=="number"?s.index:a+1;this.renderer.RenderBubbleSeries(r,s,t.x_scale,t.y_scale,`bubble-chart series-${l}`)}break;case"scatter2":if(this.renderer.RenderGrid(r,t.y_scale.count,t.x_scale.count+1,"chart-grid"),t.series){for(let a=0;a<t.series.length;a++){let s=t.series[a],l=!!t.lines,d=!!t.points;s.subtype==="plot"?(d=!0,l=!1):s.subtype==="line"&&(d=!1,l=!0);let h=typeof s.index=="number"?s.index:a+1;this.renderer.RenderScatterSeries(r,s.x.data,s.y.data,t.x_scale,t.y_scale,l,d,!!t.filled,!!t.markers,!!t.smooth,`scatter-plot series-${h}`)}if(t.data_labels)for(let a=0;a<t.series.length;a++){let s=t.series[a];s.y.labels&&this.renderer.RenderDataLabels(r,s.x.data,s.y.data,t.x_scale,t.y_scale,s.y.labels,a+1)}}break;case"pie":case"donut":{let a=Math.min(r.height,r.width)/2*.9,s=t.type==="pie"?0:a*.8;this.renderer.RenderDonut(t.slices,r.center,a,s,r,!0,"donut")}break;case"line":case"area":{let a=t.scale;if(t.series){let s=t.x_scale?t.x_scale.max:Math.max.apply(0,t.series.map(h=>h.length)),l=t.smooth?this.renderer.RenderSmoothLine:this.renderer.RenderLine;this.renderer.RenderGrid(r,t.scale.count,t.x_scale?t.x_scale.count+1:s,"chart-grid");let d=0;for(let h of t.series){let u=h.map(f=>{if(!(typeof f>"u"))return $.ApplyScale(f,r.height,a)});if(u.length<s)for(let f=u.length;f<s;f++)u.push(void 0);let m=[t.type==="area"?"chart-area":"chart-line",`series-${d+1}`];l.call(this.renderer,r,u,t.type==="area",t.titles,m),d++}}}break;case"bar":{let a;if(this.renderer.RenderBarGrid(r,t.scale.count,"chart-grid"),t.series2){let s=0,l=t.series2.length;for(let p of t.series2)s=Math.max(s,p.y.data.length);let d=r.height/s,h=.7;typeof t.space=="number"&&(h=Math.max(0,Math.min(1,1-t.space)));let u=d*(1-h)/2,m=(d-u*2)/l,f=0;if(t.scale.min<0&&(f=$.ApplyScale(0,r.width,t.scale)),t.round){let p=Math.floor(m/2);a=[0,p,p,0]}for(let p=0;p<l;p++){let b=t.series2[p],g=typeof b.index=="number"?b.index:p+1;for(let C=0;C<b.y.data.length;C++){let x=b.y.data[C];if(typeof x=="number"){let v=Math.round(r.top+C*d+u)+p*m,_=0,w=0;f?x>0?(w=$.ApplyScale(x+t.scale.min,r.width,t.scale),_=r.left+f):(w=$.ApplyScale(t.scale.min-x,r.width,t.scale),_=r.left+f-w):(w=$.ApplyScale(x,r.width,t.scale),_=r.left),w&&this.renderer.RenderRectangle(new Me(_,v,_+w,v+m),a,["chart-column",`series-${g}`],void 0||void 0)}}}}}break;case"column":case"histogram2":if(this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid"),t.series2){let a=0,s=t.series2.length;for(let p of t.series2)a=Math.max(a,p.y.data.length);let l=r.width/a,d=.7;typeof t.space=="number"&&(d=Math.max(0,Math.min(1,1-t.space)));let h=l*(1-d)/2,u=(l-h*2)/s,m=0;if(t.scale.min<0&&(m=$.ApplyScale(0,r.height,t.scale)),t.callouts&&t.x_scale){let p=t.x_scale,b=t.callouts.map((g,C)=>{let x=Math.round(r.left+$.ApplyScale(g.value,r.width,p))+.5;return{x1:x,y1:r.bottom-r.height,x2:x,y2:r.bottom,classes:`callout-${C+1}`}});this.renderer.RenderCalloutLines(b)}let f;if(t.round){let p=Math.floor(u/2);f=[p,p,0,0]}for(let p=0;p<s;p++){let b=t.series2[p],g=typeof b.index=="number"?b.index:p+1;for(let C=0;C<b.y.data.length;C++){let x=b.y.data[C];if(typeof x=="number"){let v=r.left+C*l+h+p*u,_=0,w=0;m?x>0?(_=$.ApplyScale(x+t.scale.min,r.height,t.scale),w=r.bottom-_-m):(_=$.ApplyScale(t.scale.min-x,r.height,t.scale),w=r.bottom-m):(_=$.ApplyScale(x,r.height,t.scale),w=r.bottom-_);let A=void 0;if(_){let S=t.data_labels&&b.y.labels?b.y.labels[C]:"",I={x:Math.round(v+u/2),y:Math.round(w-10)};this.renderer.RenderRectangle(new Me(v,w,v+u,w+_),f,["chart-column",`series-${g}`],A||void 0,S,I)}}}}}break;case"histogram":{this.renderer.RenderGrid(r,t.scale.count,0,"chart-grid");let a=r.width/t.count,s=t.column_width,l=a*(1-s)/2;for(let d=0;d<t.count;d++){let h=Math.round(r.left+d*a+l),u=a-l*2,m=$.ApplyScale(t.bins[d],r.height,t.scale),f=r.bottom-m,p=t.titles?t.titles[d]:void 0;this.renderer.RenderRectangle(new Me(h,f,h+u,f+m),void 0,"chart-column series-1",p||void 0)}}break}}};var Ge=class{constructor(e=new sr){this.renderer=e}static functions_registered=!1;chart_data={type:"null"};node;Initialize(e){this.node=e,this.renderer.Initialize(e)}Exec(e,t){let r=t?.value||[];switch(e.toLowerCase()){case"column.chart":this.chart_data=qr(r,"column");break;case"bar.chart":this.chart_data=qr(r,"bar");break;case"line.chart":this.chart_data=Kr(r,"line");break;case"area.chart":this.chart_data=Kr(r,"area");break;case"donut.chart":case"pie.chart":this.chart_data=pn(r,e.toLowerCase()==="pie.chart");break;case"scatter.plot":this.chart_data=Qr(r,"plot");break;case"scatter.line":this.chart_data=Qr(r,"line");break;case"bubble.chart":this.chart_data=fn(r);break;default:this.Clear();break}}Clear(){this.chart_data={type:"null"}}Resize(){this.node&&this.renderer.Resize(this.node,this.chart_data)}Update(){this.node&&this.renderer.Update(this.node,this.chart_data)}};var Ie=(...c)=>({type:5,value:c,key:"arguments"}),ei={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:"Z",metadata:!0},{name:"index"},{name:"subtype"},{name:"Labels",description:"Labels for bubble charts only (atm)"}],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},"Bubble.Chart":{arguments:[{name:"Data",metadata:!0},{name:"Chart Title"}],fn:Ie}};var ti={};wn(ti,{default:()=>ri});var ri='var Zn=Object.create;var or=Object.defineProperty;var Fn=Object.getOwnPropertyDescriptor;var Mn=Object.getOwnPropertyNames;var kn=Object.getPrototypeOf,En=Object.prototype.hasOwnProperty;var re=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var Rn=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Mn(e))!En.call(n,i)&&i!==t&&or(n,i,{get:()=>e[i],enumerable:!(r=Fn(e,i))||r.enumerable});return n};var ve=(n,e,t)=>(t=n!=null?Zn(kn(n)):{},Rn(e||!n||!n.__esModule?or(t,"default",{value:n,enumerable:!0}):t,n));var nt=re(rt=>{"use strict";rt.byteLength=Wn;rt.toByteArray=zn;rt.fromByteArray=Ln;var me=[],ce=[],$n=typeof Uint8Array<"u"?Uint8Array:Array,Tt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Ie=0,lr=Tt.length;Ie<lr;++Ie)me[Ie]=Tt[Ie],ce[Tt.charCodeAt(Ie)]=Ie;var Ie,lr;ce[45]=62;ce[95]=63;function cr(n){var e=n.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=n.indexOf("=");t===-1&&(t=e);var r=t===e?0:4-t%4;return[t,r]}function Wn(n){var e=cr(n),t=e[0],r=e[1];return(t+r)*3/4-r}function Gn(n,e,t){return(e+t)*3/4-t}function zn(n){var e,t=cr(n),r=t[0],i=t[1],s=new $n(Gn(n,r,i)),o=0,a=i>0?r-4:r,l;for(l=0;l<a;l+=4)e=ce[n.charCodeAt(l)]<<18|ce[n.charCodeAt(l+1)]<<12|ce[n.charCodeAt(l+2)]<<6|ce[n.charCodeAt(l+3)],s[o++]=e>>16&255,s[o++]=e>>8&255,s[o++]=e&255;return i===2&&(e=ce[n.charCodeAt(l)]<<2|ce[n.charCodeAt(l+1)]>>4,s[o++]=e&255),i===1&&(e=ce[n.charCodeAt(l)]<<10|ce[n.charCodeAt(l+1)]<<4|ce[n.charCodeAt(l+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function Bn(n){return me[n>>18&63]+me[n>>12&63]+me[n>>6&63]+me[n&63]}function Un(n,e,t){for(var r,i=[],s=e;s<t;s+=3)r=(n[s]<<16&16711680)+(n[s+1]<<8&65280)+(n[s+2]&255),i.push(Bn(r));return i.join("")}function Ln(n){for(var e,t=n.length,r=t%3,i=[],s=16383,o=0,a=t-r;o<a;o+=s)i.push(Un(n,o,o+s>a?a:o+s));return r===1?(e=n[t-1],i.push(me[e>>2]+me[e<<4&63]+"==")):r===2&&(e=(n[t-2]<<8)+n[t-1],i.push(me[e>>10]+me[e>>4&63]+me[e<<2&63]+"=")),i.join("")}});var ot=re(pe=>{"use strict";var ur=":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",Qn=ur+"\\\\-.\\\\d\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040",fr="["+ur+"]["+Qn+"]*",qn=new RegExp("^"+fr+"$"),Kn=function(n,e){let t=[],r=e.exec(n);for(;r;){let i=[];i.startIndex=e.lastIndex-r[0].length;let s=r.length;for(let o=0;o<s;o++)i.push(r[o]);t.push(i),r=e.exec(n)}return t},ei=function(n){let e=qn.exec(n);return!(e===null||typeof e>"u")};pe.isExist=function(n){return typeof n<"u"};pe.isEmptyObject=function(n){return Object.keys(n).length===0};pe.merge=function(n,e,t){if(e){let r=Object.keys(e),i=r.length;for(let s=0;s<i;s++)t==="strict"?n[r[s]]=[e[r[s]]]:n[r[s]]=e[r[s]]}};pe.getValue=function(n){return pe.isExist(n)?n:""};pe.isName=ei;pe.getAllMatches=Kn;pe.nameRegexp=fr});var kt=re(yr=>{"use strict";var Mt=ot(),ti={allowBooleanAttributes:!1,unpairedTags:[]};yr.validate=function(n,e){e=Object.assign({},ti,e);let t=[],r=!1,i=!1;n[0]==="\\uFEFF"&&(n=n.substr(1));for(let s=0;s<n.length;s++)if(n[s]==="<"&&n[s+1]==="?"){if(s+=2,s=pr(n,s),s.err)return s}else if(n[s]==="<"){let o=s;if(s++,n[s]==="!"){s=br(n,s);continue}else{let a=!1;n[s]==="/"&&(a=!0,s++);let l="";for(;s<n.length&&n[s]!==">"&&n[s]!==" "&&n[s]!==" "&&n[s]!==`\n`&&n[s]!=="\\r";s++)l+=n[s];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),s--),!ci(l)){let h;return l.trim().length===0?h="Invalid space after \'<\'.":h="Tag \'"+l+"\' is an invalid name.",H("InvalidTag",h,ie(n,s))}let d=ii(n,s);if(d===!1)return H("InvalidAttr","Attributes for \'"+l+"\' have open quote.",ie(n,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 m=gr(c,e);if(m===!0)r=!0;else return H(m.err.code,m.err.msg,ie(n,h+m.err.line))}else if(a)if(d.tagClosed){if(c.trim().length>0)return H("InvalidTag","Closing tag \'"+l+"\' can\'t have attributes or invalid starting.",ie(n,o));{let h=t.pop();if(l!==h.tagName){let m=ie(n,h.tagStartPos);return H("InvalidTag","Expected closing tag \'"+h.tagName+"\' (opened in line "+m.line+", col "+m.col+") instead of closing tag \'"+l+"\'.",ie(n,o))}t.length==0&&(i=!0)}}else return H("InvalidTag","Closing tag \'"+l+"\' doesn\'t have proper closing.",ie(n,s));else{let h=gr(c,e);if(h!==!0)return H(h.err.code,h.err.msg,ie(n,s-c.length+h.err.line));if(i===!0)return H("InvalidXml","Multiple possible root nodes found.",ie(n,s));e.unpairedTags.indexOf(l)!==-1||t.push({tagName:l,tagStartPos:o}),r=!0}for(s++;s<n.length;s++)if(n[s]==="<")if(n[s+1]==="!"){s++,s=br(n,s);continue}else if(n[s+1]==="?"){if(s=pr(n,++s),s.err)return s}else break;else if(n[s]==="&"){let h=oi(n,s);if(h==-1)return H("InvalidChar","char \'&\' is not expected.",ie(n,s));s=h}else if(i===!0&&!mr(n[s]))return H("InvalidXml","Extra text at the end",ie(n,s));n[s]==="<"&&s--}}else{if(mr(n[s]))continue;return H("InvalidChar","char \'"+n[s]+"\' is not expected.",ie(n,s))}if(r){if(t.length==1)return H("InvalidTag","Unclosed tag \'"+t[0].tagName+"\'.",ie(n,t[0].tagStartPos));if(t.length>0)return H("InvalidXml","Invalid \'"+JSON.stringify(t.map(s=>s.tagName),null,4).replace(/\\r?\\n/g,"")+"\' found.",{line:1,col:1})}else return H("InvalidXml","Start tag expected.",1);return!0};function mr(n){return n===" "||n===" "||n===`\n`||n==="\\r"}function pr(n,e){let t=e;for(;e<n.length;e++)if(n[e]=="?"||n[e]==" "){let r=n.substr(t,e-t);if(e>5&&r==="xml")return H("InvalidXml","XML declaration allowed only at the start of the document.",ie(n,e));if(n[e]=="?"&&n[e+1]==">"){e++;break}else continue}return e}function br(n,e){if(n.length>e+5&&n[e+1]==="-"&&n[e+2]==="-"){for(e+=3;e<n.length;e++)if(n[e]==="-"&&n[e+1]==="-"&&n[e+2]===">"){e+=2;break}}else if(n.length>e+8&&n[e+1]==="D"&&n[e+2]==="O"&&n[e+3]==="C"&&n[e+4]==="T"&&n[e+5]==="Y"&&n[e+6]==="P"&&n[e+7]==="E"){let t=1;for(e+=8;e<n.length;e++)if(n[e]==="<")t++;else if(n[e]===">"&&(t--,t===0))break}else if(n.length>e+9&&n[e+1]==="["&&n[e+2]==="C"&&n[e+3]==="D"&&n[e+4]==="A"&&n[e+5]==="T"&&n[e+6]==="A"&&n[e+7]==="["){for(e+=8;e<n.length;e++)if(n[e]==="]"&&n[e+1]==="]"&&n[e+2]===">"){e+=2;break}}return e}var ri=\'"\',ni="\'";function ii(n,e){let t="",r="",i=!1;for(;e<n.length;e++){if(n[e]===ri||n[e]===ni)r===""?r=n[e]:r!==n[e]||(r="");else if(n[e]===">"&&r===""){i=!0;break}t+=n[e]}return r!==""?!1:{value:t,index:e,tagClosed:i}}var si=new RegExp(`(\\\\s*)([^\\\\s=]+)(\\\\s*=)?(\\\\s*([\'"])(([\\\\s\\\\S])*?)\\\\5)?`,"g");function gr(n,e){let t=Mt.getAllMatches(n,si),r={};for(let i=0;i<t.length;i++){if(t[i][1].length===0)return H("InvalidAttr","Attribute \'"+t[i][2]+"\' has no space in starting.",Ue(t[i]));if(t[i][3]!==void 0&&t[i][4]===void 0)return H("InvalidAttr","Attribute \'"+t[i][2]+"\' is without value.",Ue(t[i]));if(t[i][3]===void 0&&!e.allowBooleanAttributes)return H("InvalidAttr","boolean attribute \'"+t[i][2]+"\' is not allowed.",Ue(t[i]));let s=t[i][2];if(!li(s))return H("InvalidAttr","Attribute \'"+s+"\' is an invalid name.",Ue(t[i]));if(!r.hasOwnProperty(s))r[s]=1;else return H("InvalidAttr","Attribute \'"+s+"\' is repeated.",Ue(t[i]))}return!0}function ai(n,e){let t=/\\d/;for(n[e]==="x"&&(e++,t=/[\\da-fA-F]/);e<n.length;e++){if(n[e]===";")return e;if(!n[e].match(t))break}return-1}function oi(n,e){if(e++,n[e]===";")return-1;if(n[e]==="#")return e++,ai(n,e);let t=0;for(;e<n.length;e++,t++)if(!(n[e].match(/\\w/)&&t<20)){if(n[e]===";")break;return-1}return e}function H(n,e,t){return{err:{code:n,msg:e,line:t.line||t,col:t.col}}}function li(n){return Mt.isName(n)}function ci(n){return Mt.isName(n)}function ie(n,e){let t=n.substring(0,e).split(/\\r?\\n/);return{line:t.length,col:t[t.length-1].length+1}}function Ue(n){return n.startIndex+n[1].length}});var _r=re(Et=>{var xr={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(n,e){return e},attributeValueProcessor:function(n,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(n,e,t){return n}},di=function(n){return Object.assign({},xr,n)};Et.buildOptions=di;Et.defaultOptions=xr});var Ar=re((io,wr)=>{"use strict";var Rt=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})}};wr.exports=Rt});var vr=re((so,Cr)=>{var hi=ot();function ui(n,e){let t={};if(n[e+3]==="O"&&n[e+4]==="C"&&n[e+5]==="T"&&n[e+6]==="Y"&&n[e+7]==="P"&&n[e+8]==="E"){e=e+9;let r=1,i=!1,s=!1,o="";for(;e<n.length;e++)if(n[e]==="<"&&!s){if(i&&pi(n,e))e+=7,[entityName,val,e]=fi(n,e+1),val.indexOf("&")===-1&&(t[xi(entityName)]={regx:RegExp(`&${entityName};`,"g"),val});else if(i&&bi(n,e))e+=8;else if(i&&gi(n,e))e+=8;else if(i&&yi(n,e))e+=9;else if(mi)s=!0;else throw new Error("Invalid DOCTYPE");r++,o=""}else if(n[e]===">"){if(s?n[e-1]==="-"&&n[e-2]==="-"&&(s=!1,r--):r--,r===0)break}else n[e]==="["?i=!0:o+=n[e];if(r!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:t,i:e}}function fi(n,e){let t="";for(;e<n.length&&n[e]!=="\'"&&n[e]!==\'"\';e++)t+=n[e];if(t=t.trim(),t.indexOf(" ")!==-1)throw new Error("External entites are not supported");let r=n[e++],i="";for(;e<n.length&&n[e]!==r;e++)i+=n[e];return[t,i,e]}function mi(n,e){return n[e+1]==="!"&&n[e+2]==="-"&&n[e+3]==="-"}function pi(n,e){return n[e+1]==="!"&&n[e+2]==="E"&&n[e+3]==="N"&&n[e+4]==="T"&&n[e+5]==="I"&&n[e+6]==="T"&&n[e+7]==="Y"}function bi(n,e){return n[e+1]==="!"&&n[e+2]==="E"&&n[e+3]==="L"&&n[e+4]==="E"&&n[e+5]==="M"&&n[e+6]==="E"&&n[e+7]==="N"&&n[e+8]==="T"}function gi(n,e){return n[e+1]==="!"&&n[e+2]==="A"&&n[e+3]==="T"&&n[e+4]==="T"&&n[e+5]==="L"&&n[e+6]==="I"&&n[e+7]==="S"&&n[e+8]==="T"}function yi(n,e){return n[e+1]==="!"&&n[e+2]==="N"&&n[e+3]==="O"&&n[e+4]==="T"&&n[e+5]==="A"&&n[e+6]==="T"&&n[e+7]==="I"&&n[e+8]==="O"&&n[e+9]==="N"}function xi(n){if(hi.isName(n))return n;throw new Error(`Invalid entity name ${n}`)}Cr.exports=ui});var Nr=re((ao,Ir)=>{var _i=/^[-+]?0x[a-fA-F0-9]+$/,wi=/^([\\-\\+])?(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 Ai={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function Ci(n,e={}){if(e=Object.assign({},Ai,e),!n||typeof n!="string")return n;let t=n.trim();if(e.skipLike!==void 0&&e.skipLike.test(t))return n;if(e.hex&&_i.test(t))return Number.parseInt(t,16);{let r=wi.exec(t);if(r){let i=r[1],s=r[2],o=vi(r[3]),a=r[4]||r[6];if(!e.leadingZeros&&s.length>0&&i&&t[2]!==".")return n;if(!e.leadingZeros&&s.length>0&&!i&&t[1]!==".")return n;{let l=Number(t),d=""+l;return d.search(/[eE]/)!==-1||a?e.eNotation?l:n:t.indexOf(".")!==-1?d==="0"&&o===""||d===o||i&&d==="-"+o?l:n:s?o===d||i+o===d?l:n:t===d||t===i+d?l:n}}else return n}}function vi(n){return n&&n.indexOf(".")!==-1&&(n=n.replace(/0+$/,""),n==="."?n="0":n[0]==="."?n="0"+n:n[n.length-1]==="."&&(n=n.substr(0,n.length-1))),n}Ir.exports=Ci});var Pr=re((oo,Tr)=>{"use strict";var Sr=ot(),Le=Ar(),Ii=vr(),Ni=Nr(),$t=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=Si,this.parseXml=Mi,this.parseTextData=Ti,this.resolveNameSpace=Pi,this.buildAttributesMap=Fi,this.isItStopNode=$i,this.replaceEntitiesValue=Ei,this.readStopNodeData=Gi,this.saveTextToParentTag=Ri,this.addChild=ki}};function Si(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];this.lastEntities[r]={regex:new RegExp("&"+r+";","g"),val:n[r]}}}function Ti(n,e,t,r,i,s,o){if(n!==void 0&&(this.options.trimValues&&!r&&(n=n.trim()),n.length>0)){o||(n=this.replaceEntitiesValue(n));let a=this.options.tagValueProcessor(e,n,t,i,s);return a==null?n:typeof a!=typeof n||a!==n?a:this.options.trimValues?Gt(n,this.options.parseTagValue,this.options.numberParseOptions):n.trim()===n?Gt(n,this.options.parseTagValue,this.options.numberParseOptions):n}}function Pi(n){if(this.options.removeNSPrefix){let e=n.split(":"),t=n.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(n=t+e[1])}return n}var Zi=new RegExp(`([^\\\\s=]+)\\\\s*(=\\\\s*([\'"])([\\\\s\\\\S]*?)\\\\3)?`,"gm");function Fi(n,e,t){if(!this.options.ignoreAttributes&&typeof n=="string"){let r=Sr.getAllMatches(n,Zi),i=r.length,s={};for(let o=0;o<i;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]=Gt(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 Mi=function(n){n=n.replace(/\\r\\n?/g,`\n`);let e=new Le("!xml"),t=e,r="",i="";for(let s=0;s<n.length;s++)if(n[s]==="<")if(n[s+1]==="/"){let a=Ze(n,">",s,"Closing Tag is not closed."),l=n.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,i));let d=i.substring(i.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=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):c=i.lastIndexOf("."),i=i.substring(0,c),t=this.tagsNodeStack.pop(),r="",s=a}else if(n[s+1]==="?"){let a=Wt(n,s,!1,"?>");if(!a)throw new Error("Pi Tag is not closed.");if(r=this.saveTextToParentTag(r,t,i),!(this.options.ignoreDeclaration&&a.tagName==="?xml"||this.options.ignorePiTags)){let l=new Le(a.tagName);l.add(this.options.textNodeName,""),a.tagName!==a.tagExp&&a.attrExpPresent&&(l[":@"]=this.buildAttributesMap(a.tagExp,i,a.tagName)),this.addChild(t,l,i)}s=a.closeIndex+1}else if(n.substr(s+1,3)==="!--"){let a=Ze(n,"-->",s+4,"Comment is not closed.");if(this.options.commentPropName){let l=n.substring(s+4,a-2);r=this.saveTextToParentTag(r,t,i),t.add(this.options.commentPropName,[{[this.options.textNodeName]:l}])}s=a}else if(n.substr(s+1,2)==="!D"){let a=Ii(n,s);this.docTypeEntities=a.entities,s=a.i}else if(n.substr(s+1,2)==="!["){let a=Ze(n,"]]>",s,"CDATA is not closed.")-2,l=n.substring(s+9,a);r=this.saveTextToParentTag(r,t,i);let d=this.parseTextData(l,t.tagname,i,!0,!1,!0,!0);d==null&&(d=""),this.options.cdataPropName?t.add(this.options.cdataPropName,[{[this.options.textNodeName]:l}]):t.add(this.options.textNodeName,d),s=a+2}else{let a=Wt(n,s,this.options.removeNSPrefix),l=a.tagName,d=a.rawTagName,c=a.tagExp,h=a.attrExpPresent,m=a.closeIndex;this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&r&&t.tagname!=="!xml"&&(r=this.saveTextToParentTag(r,t,i,!1));let u=t;if(u&&this.options.unpairedTags.indexOf(u.tagname)!==-1&&(t=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),l!==e.tagname&&(i+=i?"."+l:l),this.isItStopNode(this.options.stopNodes,i,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 w=this.readStopNodeData(n,d,m+1);if(!w)throw new Error(`Unexpected end of ${d}`);s=w.i,f=w.tagContent}let g=new Le(l);l!==c&&h&&(g[":@"]=this.buildAttributesMap(c,i,l)),f&&(f=this.parseTextData(f,l,i,!0,h,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),g.add(this.options.textNodeName,f),this.addChild(t,g,i)}else{if(c.length>0&&c.lastIndexOf("/")===c.length-1){l[l.length-1]==="/"?(l=l.substr(0,l.length-1),i=i.substr(0,i.length-1),c=l):c=c.substr(0,c.length-1),this.options.transformTagName&&(l=this.options.transformTagName(l));let f=new Le(l);l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,i,l)),this.addChild(t,f,i),i=i.substr(0,i.lastIndexOf("."))}else{let f=new Le(l);this.tagsNodeStack.push(t),l!==c&&h&&(f[":@"]=this.buildAttributesMap(c,i,l)),this.addChild(t,f,i),t=f}r="",s=m}}else r+=n[s];return e.child};function ki(n,e,t){let r=this.options.updateTag(e.tagname,t,e[":@"]);r===!1||(typeof r=="string"&&(e.tagname=r),n.addChild(e))}var Ei=function(n){if(this.options.processEntities){for(let e in this.docTypeEntities){let t=this.docTypeEntities[e];n=n.replace(t.regx,t.val)}for(let e in this.lastEntities){let t=this.lastEntities[e];n=n.replace(t.regex,t.val)}if(this.options.htmlEntities)for(let e in this.htmlEntities){let t=this.htmlEntities[e];n=n.replace(t.regex,t.val)}n=n.replace(this.ampEntity.regex,this.ampEntity.val)}return n};function Ri(n,e,t,r){return n&&(r===void 0&&(r=Object.keys(e.child).length===0),n=this.parseTextData(n,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,r),n!==void 0&&n!==""&&e.add(this.options.textNodeName,n),n=""),n}function $i(n,e,t){let r="*."+t;for(let i in n){let s=n[i];if(r===s||e===s)return!0}return!1}function Wi(n,e,t=">"){let r,i="";for(let s=e;s<n.length;s++){let o=n[s];if(r)o===r&&(r="");else if(o===\'"\'||o==="\'")r=o;else if(o===t[0])if(t[1]){if(n[s+1]===t[1])return{data:i,index:s}}else return{data:i,index:s};else o===" "&&(o=" ");i+=o}}function Ze(n,e,t,r){let i=n.indexOf(e,t);if(i===-1)throw new Error(r);return i+e.length-1}function Wt(n,e,t,r=">"){let i=Wi(n,e+1,r);if(!i)return;let s=i.data,o=i.index,a=s.search(/\\s/),l=s,d=!0;a!==-1&&(l=s.substring(0,a),s=s.substring(a+1).trimStart());let c=l;if(t){let h=l.indexOf(":");h!==-1&&(l=l.substr(h+1),d=l!==i.data.substr(h+1))}return{tagName:l,tagExp:s,closeIndex:o,attrExpPresent:d,rawTagName:c}}function Gi(n,e,t){let r=t,i=1;for(;t<n.length;t++)if(n[t]==="<")if(n[t+1]==="/"){let s=Ze(n,">",t,`${e} is not closed`);if(n.substring(t+2,s).trim()===e&&(i--,i===0))return{tagContent:n.substring(r,t),i:s};t=s}else if(n[t+1]==="?")t=Ze(n,"?>",t+1,"StopNode is not closed.");else if(n.substr(t+1,3)==="!--")t=Ze(n,"-->",t+3,"StopNode is not closed.");else if(n.substr(t+1,2)==="![")t=Ze(n,"]]>",t,"StopNode is not closed.")-2;else{let s=Wt(n,t,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,t=s.closeIndex)}}function Gt(n,e,t){if(e&&typeof n=="string"){let r=n.trim();return r==="true"?!0:r==="false"?!1:Ni(n,t)}else return Sr.isExist(n)?n:""}Tr.exports=$t});var Mr=re(Fr=>{"use strict";function zi(n,e){return Zr(n,e)}function Zr(n,e,t){let r,i={};for(let s=0;s<n.length;s++){let o=n[s],a=Bi(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=Zr(o[a],e,l),c=Li(d,e);o[":@"]?Ui(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=""),i[a]!==void 0&&i.hasOwnProperty(a)?(Array.isArray(i[a])||(i[a]=[i[a]]),i[a].push(d)):e.isArray(a,l,c)?i[a]=[d]:i[a]=d}}}return typeof r=="string"?r.length>0&&(i[e.textNodeName]=r):r!==void 0&&(i[e.textNodeName]=r),i}function Bi(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];if(r!==":@")return r}}function Ui(n,e,t,r){if(e){let i=Object.keys(e),s=i.length;for(let o=0;o<s;o++){let a=i[o];r.isArray(a,t+"."+a,!0,!0)?n[a]=[e[a]]:n[a]=e[a]}}}function Li(n,e){let{textNodeName:t}=e,r=Object.keys(n).length;return!!(r===0||r===1&&(n[t]||typeof n[t]=="boolean"||n[t]===0))}Fr.prettify=zi});var Er=re((co,kr)=>{var{buildOptions:Vi}=_r(),Yi=Pr(),{prettify:Oi}=Mr(),ji=kt(),zt=class{constructor(e){this.externalEntities={},this.options=Vi(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=ji.validate(e,t);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}let r=new Yi(this.options);r.addExternalEntities(this.externalEntities);let i=r.parseXml(e);return this.options.preserveOrder||i===void 0?i:Oi(i,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 \'&#xD;\'");if(t==="&")throw new Error("An entity with value \'&\' is not permitted");this.externalEntities[e]=t}};kr.exports=zt});var zr=re((ho,Gr)=>{var Di=`\n`;function Hi(n,e){let t="";return e.format&&e.indentBy.length>0&&(t=Di),$r(n,e,"",t)}function $r(n,e,t,r){let i="",s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=Ji(a);if(l===void 0)continue;let d="";if(t.length===0?d=l:d=`${t}.${l}`,l===e.textNodeName){let f=a[l];Xi(d,e)||(f=e.tagValueProcessor(l,f),f=Wr(f,e)),s&&(i+=r),i+=f,s=!1;continue}else if(l===e.cdataPropName){s&&(i+=r),i+=`<![CDATA[${a[l][0][e.textNodeName]}]]>`,s=!1;continue}else if(l===e.commentPropName){i+=r+`<!--${a[l][0][e.textNodeName]}-->`,s=!0;continue}else if(l[0]==="?"){let f=Rr(a[":@"],e),g=l==="?xml"?"":r,w=a[l][0][e.textNodeName];w=w.length!==0?" "+w:"",i+=g+`<${l}${w}${f}?>`,s=!0;continue}let c=r;c!==""&&(c+=e.indentBy);let h=Rr(a[":@"],e),m=r+`<${l}${h}`,u=$r(a[l],e,d,c);e.unpairedTags.indexOf(l)!==-1?e.suppressUnpairedNode?i+=m+">":i+=m+"/>":(!u||u.length===0)&&e.suppressEmptyNode?i+=m+"/>":u&&u.endsWith(">")?i+=m+`>${u}${r}</${l}>`:(i+=m+">",u&&r!==""&&(u.includes("/>")||u.includes("</"))?i+=r+e.indentBy+u+r:i+=u,i+=`</${l}>`),s=!0}return i}function Ji(n){let e=Object.keys(n);for(let t=0;t<e.length;t++){let r=e[t];if(n.hasOwnProperty(r)&&r!==":@")return r}}function Rr(n,e){let t="";if(n&&!e.ignoreAttributes)for(let r in n){if(!n.hasOwnProperty(r))continue;let i=e.attributeValueProcessor(r,n[r]);i=Wr(i,e),i===!0&&e.suppressBooleanAttributes?t+=` ${r.substr(e.attributeNamePrefix.length)}`:t+=` ${r.substr(e.attributeNamePrefix.length)}="${i}"`}return t}function Xi(n,e){n=n.substr(0,n.length-e.textNodeName.length-1);let t=n.substr(n.lastIndexOf(".")+1);for(let r in e.stopNodes)if(e.stopNodes[r]===n||e.stopNodes[r]==="*."+t)return!0;return!1}function Wr(n,e){if(n&&n.length>0&&e.processEntities)for(let t=0;t<e.entities.length;t++){let r=e.entities[t];n=n.replace(r.regex,r.val)}return n}Gr.exports=Hi});var Ur=re((uo,Br)=>{"use strict";var Qi=zr(),qi={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressUnpairedNode:!0,suppressBooleanAttributes:!0,tagValueProcessor:function(n,e){return e},attributeValueProcessor:function(n,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:[{regex:new RegExp("&","g"),val:"&amp;"},{regex:new RegExp(">","g"),val:"&gt;"},{regex:new RegExp("<","g"),val:"&lt;"},{regex:new RegExp("\'","g"),val:"&apos;"},{regex:new RegExp(\'"\',"g"),val:"&quot;"}],processEntities:!0,stopNodes:[],oneListGroup:!1};function _e(n){this.options=Object.assign({},qi,n),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=ts),this.processTextOrObjNode=Ki,this.options.format?(this.indentate=es,this.tagEndChar=`>\n`,this.newLine=`\n`):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine="")}_e.prototype.build=function(n){return this.options.preserveOrder?Qi(n,this.options):(Array.isArray(n)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(n={[this.options.arrayNodeName]:n}),this.j2x(n,0).val)};_e.prototype.j2x=function(n,e){let t="",r="";for(let i in n)if(Object.prototype.hasOwnProperty.call(n,i))if(typeof n[i]>"u")this.isAttribute(i)&&(r+="");else if(n[i]===null)this.isAttribute(i)?r+="":i[0]==="?"?r+=this.indentate(e)+"<"+i+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+i+"/"+this.tagEndChar;else if(n[i]instanceof Date)r+=this.buildTextValNode(n[i],i,"",e);else if(typeof n[i]!="object"){let s=this.isAttribute(i);if(s)t+=this.buildAttrPairStr(s,""+n[i]);else if(i===this.options.textNodeName){let o=this.options.tagValueProcessor(i,""+n[i]);r+=this.replaceEntitiesValue(o)}else r+=this.buildTextValNode(n[i],i,"",e)}else if(Array.isArray(n[i])){let s=n[i].length,o="";for(let a=0;a<s;a++){let l=n[i][a];typeof l>"u"||(l===null?i[0]==="?"?r+=this.indentate(e)+"<"+i+"?"+this.tagEndChar:r+=this.indentate(e)+"<"+i+"/"+this.tagEndChar:typeof l=="object"?this.options.oneListGroup?o+=this.j2x(l,e+1).val:o+=this.processTextOrObjNode(l,i,e):o+=this.buildTextValNode(l,i,"",e))}this.options.oneListGroup&&(o=this.buildObjectNode(o,i,"",e)),r+=o}else if(this.options.attributesGroupName&&i===this.options.attributesGroupName){let s=Object.keys(n[i]),o=s.length;for(let a=0;a<o;a++)t+=this.buildAttrPairStr(s[a],""+n[i][s[a]])}else r+=this.processTextOrObjNode(n[i],i,e);return{attrStr:t,val:r}};_e.prototype.buildAttrPairStr=function(n,e){return e=this.options.attributeValueProcessor(n,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&e==="true"?" "+n:" "+n+\'="\'+e+\'"\'};function Ki(n,e,t){let r=this.j2x(n,t+1);return n[this.options.textNodeName]!==void 0&&Object.keys(n).length===1?this.buildTextValNode(n[this.options.textNodeName],e,r.attrStr,t):this.buildObjectNode(r.val,e,r.attrStr,t)}_e.prototype.buildObjectNode=function(n,e,t,r){if(n==="")return e[0]==="?"?this.indentate(r)+"<"+e+t+"?"+this.tagEndChar:this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar;{let i="</"+e+this.tagEndChar,s="";return e[0]==="?"&&(s="?",i=""),(t||t==="")&&n.indexOf("<")===-1?this.indentate(r)+"<"+e+t+s+">"+n+i:this.options.commentPropName!==!1&&e===this.options.commentPropName&&s.length===0?this.indentate(r)+`<!--${n}-->`+this.newLine:this.indentate(r)+"<"+e+t+s+this.tagEndChar+n+this.indentate(r)+i}};_e.prototype.closeTag=function(n){let e="";return this.options.unpairedTags.indexOf(n)!==-1?this.options.suppressUnpairedNode||(e="/"):this.options.suppressEmptyNode?e="/":e=`></${n}`,e};_e.prototype.buildTextValNode=function(n,e,t,r){if(this.options.cdataPropName!==!1&&e===this.options.cdataPropName)return this.indentate(r)+`<![CDATA[${n}]]>`+this.newLine;if(this.options.commentPropName!==!1&&e===this.options.commentPropName)return this.indentate(r)+`<!--${n}-->`+this.newLine;if(e[0]==="?")return this.indentate(r)+"<"+e+t+"?"+this.tagEndChar;{let i=this.options.tagValueProcessor(e,n);return i=this.replaceEntitiesValue(i),i===""?this.indentate(r)+"<"+e+t+this.closeTag(e)+this.tagEndChar:this.indentate(r)+"<"+e+t+">"+i+"</"+e+this.tagEndChar}};_e.prototype.replaceEntitiesValue=function(n){if(n&&n.length>0&&this.options.processEntities)for(let e=0;e<this.options.entities.length;e++){let t=this.options.entities[e];n=n.replace(t.regex,t.val)}return n};function es(n){return this.options.indentBy.repeat(n)}function ts(n){return n.startsWith(this.options.attributeNamePrefix)&&n!==this.options.textNodeName?n.substr(this.attrPrefixLen):!1}Br.exports=_e});var lt=re((fo,Lr)=>{"use strict";var rs=kt(),ns=Er(),is=Ur();Lr.exports={XMLParser:ns,XMLValidator:rs,XMLBuilder:is}});var An=re((Zl,nr)=>{var p={};typeof nr=="object"&&(nr.exports=p);p.parse=function(n,e){for(var t=p.bin.readUshort,r=p.bin.readUint,a=0,i={},s=new Uint8Array(n),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 m=0;m<l;m++){var u=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 w=t(s,a),A=t(s,a+2),_=t(s,a+4);a+=6,a+=8;var b=r(s,a);a+=4,a+=w+A+_,p._readLocal(s,b,i,c,g,e)}return i};p._readLocal=function(n,e,t,r,i,s){var o=p.bin.readUshort,a=p.bin.readUint,l=a(n,e);e+=4;var d=o(n,e);e+=2;var c=o(n,e);e+=2;var h=o(n,e);e+=2;var m=a(n,e);e+=4;var u=a(n,e);e+=4,e+=8;var f=o(n,e);e+=2;var g=o(n,e);e+=2;var w=p.bin.readUTF8(n,e,f);if(e+=f,e+=g,s){t[w]={size:i,csize:r};return}var A=new Uint8Array(n.buffer,e);if(h==0)t[w]=new Uint8Array(A.buffer.slice(e,e+r));else if(h==8){var _=new Uint8Array(i);p.inflateRaw(A,_),t[w]=_}else throw"unknown compression method: "+h};p.inflateRaw=function(n,e){return p.F.inflate(n,e)};p.inflate=function(n,e){var t=n[0],r=n[1],i=t&15,s=t>>>4;return p.inflateRaw(new Uint8Array(n.buffer,n.byteOffset+2,n.length-6),e)};p.deflate=function(n,e){e==null&&(e={level:6});var t=0,r=new Uint8Array(50+Math.floor(n.length*1.1));r[t]=120,r[t+1]=156,t+=2,t=p.F.deflateRaw(n,r,t,e.level);var i=p.adler(n,0,n.length);return r[t+0]=i>>>24&255,r[t+1]=i>>>16&255,r[t+2]=i>>>8&255,r[t+3]=i>>>0&255,new Uint8Array(r.buffer,0,t+4)};p.deflateRaw=function(n,e){e==null&&(e={level:6});var t=new Uint8Array(50+Math.floor(n.length*1.1)),r=p.F.deflateRaw(n,t,r,e.level);return new Uint8Array(t.buffer,0,r)};p.encode=function(n,e){e==null&&(e=!1);var t=0,r=p.bin.writeUint,i=p.bin.writeUshort,s={};for(var o in n){var a=!p._noNeed(o)&&!e,l=n[o],d=p.crc.crc(l,0,l.length);s[o]={cpr:a,usize:l.length,crc:d,file:a?p.deflateRaw(l):l}}for(var o in s)t+=s[o].file.length+30+46+2*p.bin.sizeUTF8(o);t+=22;var c=new Uint8Array(t),h=0,m=[];for(var o in s){var u=s[o];m.push(h),h=p._writeHeader(c,h,o,u,0)}var f=0,g=h;for(var o in s){var u=s[o];m.push(h),h=p._writeHeader(c,h,o,u,1,m[f++])}var w=h-g;return r(c,h,101010256),h+=4,h+=4,i(c,h,f),h+=2,i(c,h,f),h+=2,r(c,h,w),h+=4,r(c,h,g),h+=4,h+=2,c.buffer};p._noNeed=function(n){var e=n.split(".").pop().toLowerCase();return"png,jpg,jpeg,zip".indexOf(e)!=-1};p._writeHeader=function(n,e,t,r,i,s){var o=p.bin.writeUint,a=p.bin.writeUshort,l=r.file;o(n,e,i==0?67324752:33639248),e+=4,i==1&&(e+=2),a(n,e,20),e+=2,a(n,e,0),e+=2,a(n,e,r.cpr?8:0),e+=2,o(n,e,0),e+=4,o(n,e,r.crc),e+=4,o(n,e,l.length),e+=4,o(n,e,r.usize),e+=4,a(n,e,p.bin.sizeUTF8(t)),e+=2,a(n,e,0),e+=2,i==1&&(e+=2,e+=2,e+=6,o(n,e,s),e+=4);var d=p.bin.writeUTF8(n,e,t);return e+=d,i==0&&(n.set(l,e),e+=l.length),e};p.crc={table:function(){for(var n=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;n[e]=t}return n}(),update:function(n,e,t,r){for(var i=0;i<r;i++)n=p.crc.table[(n^e[t+i])&255]^n>>>8;return n},crc:function(n,e,t){return p.crc.update(4294967295,n,e,t)^4294967295}};p.adler=function(n,e,t){for(var r=1,i=0,s=e,o=e+t;s<o;){for(var a=Math.min(s+5552,o);s<a;)r+=n[s++],i+=r;r=r%65521,i=i%65521}return i<<16|r};p.bin={readUshort:function(n,e){return n[e]|n[e+1]<<8},writeUshort:function(n,e,t){n[e]=t&255,n[e+1]=t>>8&255},readUint:function(n,e){return n[e+3]*(256*256*256)+(n[e+2]<<16|n[e+1]<<8|n[e])},writeUint:function(n,e,t){n[e]=t&255,n[e+1]=t>>8&255,n[e+2]=t>>16&255,n[e+3]=t>>24&255},readASCII:function(n,e,t){for(var r="",i=0;i<t;i++)r+=String.fromCharCode(n[e+i]);return r},writeASCII:function(n,e,t){for(var r=0;r<t.length;r++)n[e+r]=t.charCodeAt(r)},pad:function(n){return n.length<2?"0"+n:n},readUTF8:function(n,e,t){for(var r="",i,s=0;s<t;s++)r+="%"+p.bin.pad(n[e+s].toString(16));try{i=decodeURIComponent(r)}catch{return p.bin.readASCII(n,e,t)}return i},writeUTF8:function(n,e,t){for(var r=t.length,i=0,s=0;s<r;s++){var o=t.charCodeAt(s);if(!(o&4294967168))n[e+i]=o,i++;else if(!(o&4294965248))n[e+i]=192|o>>6,n[e+i+1]=128|o>>0&63,i+=2;else if(!(o&4294901760))n[e+i]=224|o>>12,n[e+i+1]=128|o>>6&63,n[e+i+2]=128|o>>0&63,i+=3;else if(!(o&4294967295-(1<<21)+1))n[e+i]=240|o>>18,n[e+i+1]=128|o>>12&63,n[e+i+2]=128|o>>6&63,n[e+i+3]=128|o>>0&63,i+=4;else throw"e"}return i},sizeUTF8:function(n){for(var e=n.length,t=0,r=0;r<e;r++){var i=n.charCodeAt(r);if(!(i&4294967168))t++;else if(!(i&4294965248))t+=2;else if(!(i&4294901760))t+=3;else if(!(i&4294967295-(1<<21)+1))t+=4;else throw"e"}return t}};p.F={};p.F.deflateRaw=function(n,e,t,r){var i=[[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=i[r],o=p.F.U,a=p.F._goodIndex,l=p.F._hash,d=p.F._putsE,c=0,h=t<<3,m=0,u=n.length;if(r==0){for(;c<u;){var f=Math.min(65535,u-c);d(e,h,c+f==u?1:0),h=p.F._copyExact(n,c,f,e,h+8),c+=f}return h>>>3}var g=o.lits,w=o.strt,A=o.prev,_=0,b=0,N=0,$=0,Y=0,W=0;u>2&&(W=p.F._hash(n,0),w[W]=0);var k=0,q=0;for(c=0;c<u;c++){if(Y=W,c+1<u-2){W=p.F._hash(n,c+1);var X=c+1&32767;A[X]=w[W],w[W]=X}if(m<=c){(_>14e3||b>26697)&&u-c>100&&(m<c&&(g[_]=c-m,_+=2,m=c),h=p.F._writeBlock(c==u-1||m==u?1:0,g,_,$,n,N,c-N,e,h),_=b=$=0,N=c);var B=0;c<u-2&&(B=p.F._bestMatch(n,c,A,Y,Math.min(s[2],u-c),s[3]));var f=B>>>16,K=B&65535;if(B!=0){var f=B>>>16,K=B&65535,D=a(f,o.of0);o.lhst[257+D]++;var O=a(K,o.df0);o.dhst[O]++,$+=o.exb[D]+o.dxb[O],g[_]=f<<23|c-m,g[_+1]=K<<16|D<<8|O,_+=2,m=c+f}else o.lhst[n[c]]++;b++}}for((N!=c||n.length==0)&&(m<c&&(g[_]=c-m,_+=2,m=c),h=p.F._writeBlock(1,g,_,$,n,N,c-N,e,h),_=0,b=0,_=b=$=0,N=c);h&7;)h++;return h>>>3};p.F._bestMatch=function(n,e,t,r,i,s){var o=e&32767,a=t[o],l=o-a+32768&32767;if(a==o||r!=p.F._hash(n,e-l))return 0;for(var d=0,c=0,h=Math.min(32767,e);l<=h&&--s!=0&&a!=o;){if(d==0||n[e+d]==n[e+d-l]){var m=p.F._howLong(n,e,l);if(m>d){if(d=m,c=l,d>=i)break;l+2<m&&(m=l+2);for(var u=0,f=0;f<m-2;f++){var g=e-l+f+32768&32767,w=t[g],A=g-w+32768&32767;A>u&&(u=A,a=g)}}}o=a,a=t[o],l+=o-a+32768&32767}return d<<16|c};p.F._howLong=function(n,e,t){if(n[e]!=n[e-t]||n[e+1]!=n[e+1-t]||n[e+2]!=n[e+2-t])return 0;var r=e,i=Math.min(n.length,e+258);for(e+=3;e<i&&n[e]==n[e-t];)e++;return e-r};p.F._hash=function(n,e){return(n[e]<<8|n[e+1])+(n[e+2]<<4)&65535};p.saved=0;p.F._writeBlock=function(n,e,t,r,i,s,o,a,l){var d=p.F.U,c=p.F._putsF,h=p.F._putsE,m,u,f,g,w,A,_,b,N;d.lhst[256]++,m=p.F.getTrees(),u=m[0],f=m[1],g=m[2],w=m[3],A=m[4],_=m[5],b=m[6],N=m[7];var $=(l+3&7?8-(l+3&7):0)+32+(o<<3),Y=r+p.F.contSize(d.fltree,d.lhst)+p.F.contSize(d.fdtree,d.dhst),W=r+p.F.contSize(d.ltree,d.lhst)+p.F.contSize(d.dtree,d.dhst);W+=14+3*_+p.F.contSize(d.itree,d.ihst)+(d.ihst[16]*2+d.ihst[17]*3+d.ihst[18]*7);for(var k=0;k<286;k++)d.lhst[k]=0;for(var k=0;k<30;k++)d.dhst[k]=0;for(var k=0;k<19;k++)d.ihst[k]=0;var q=$<Y&&$<W?0:Y<W?1:2;c(a,l,n),c(a,l+1,q),l+=3;var X=l;if(q==0){for(;l&7;)l++;l=p.F._copyExact(i,s,o,a,l)}else{var B,K;if(q==1&&(B=d.fltree,K=d.fdtree),q==2){p.F.makeCodes(d.ltree,u),p.F.revCodes(d.ltree,u),p.F.makeCodes(d.dtree,f),p.F.revCodes(d.dtree,f),p.F.makeCodes(d.itree,g),p.F.revCodes(d.itree,g),B=d.ltree,K=d.dtree,h(a,l,w-257),l+=5,h(a,l,A-1),l+=5,h(a,l,_-4),l+=4;for(var D=0;D<_;D++)h(a,l+D*3,d.itree[(d.ordr[D]<<1)+1]);l+=3*_,l=p.F._codeTiny(b,d.itree,a,l),l=p.F._codeTiny(N,d.itree,a,l)}for(var O=s,ee=0;ee<t;ee+=2){for(var G=e[ee],se=G>>>23,te=O+(G&(1<<23)-1);O<te;)l=p.F._writeLit(i[O++],B,a,l);if(se!=0){var y=e[ee+1],Z=y>>16,S=y>>8&255,C=y&255;l=p.F._writeLit(257+S,B,a,l),h(a,l,se-d.of0[S]),l+=d.exb[S],l=p.F._writeLit(C,K,a,l),c(a,l,Z-d.df0[C]),l+=d.dxb[C],O+=se}}l=p.F._writeLit(256,B,a,l)}return l};p.F._copyExact=function(n,e,t,r,i){var s=i>>>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(n.buffer,e,t),s),i+(t+4<<3)};p.F.getTrees=function(){for(var n=p.F.U,e=p.F._hufTree(n.lhst,n.ltree,15),t=p.F._hufTree(n.dhst,n.dtree,15),r=[],i=p.F._lenCodes(n.ltree,r),s=[],o=p.F._lenCodes(n.dtree,s),a=0;a<r.length;a+=2)n.ihst[r[a]]++;for(var a=0;a<s.length;a+=2)n.ihst[s[a]]++;for(var l=p.F._hufTree(n.ihst,n.itree,7),d=19;d>4&&n.itree[(n.ordr[d-1]<<1)+1]==0;)d--;return[e,t,l,i,o,d,r,s]};p.F.getSecond=function(n){for(var e=[],t=0;t<n.length;t+=2)e.push(n[t+1]);return e};p.F.nonZero=function(n){for(var e="",t=0;t<n.length;t+=2)n[t+1]!=0&&(e+=(t>>1)+",");return e};p.F.contSize=function(n,e){for(var t=0,r=0;r<e.length;r++)t+=e[r]*n[(r<<1)+1];return t};p.F._codeTiny=function(n,e,t,r){for(var i=0;i<n.length;i+=2){var s=n[i],o=n[i+1];r=p.F._writeLit(s,e,t,r);var a=s==16?2:s==17?3:7;s>15&&(p.F._putsE(t,r,o,a),r+=a)}return r};p.F._lenCodes=function(n,e){for(var t=n.length;t!=2&&n[t-1]==0;)t-=2;for(var r=0;r<t;r+=2){var i=n[r+1],s=r+3<t?n[r+3]:-1,o=r+5<t?n[r+5]:-1,a=r==0?-1:n[r-1];if(i==0&&s==i&&o==i){for(var l=r+5;l+2<t&&n[l+2]==i;)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(i==a&&s==i&&o==i){for(var l=r+5;l+2<t&&n[l+2]==i;)l+=2;var d=Math.min(l+1-r>>>1,6);e.push(16,d-3),r+=d*2-2}else e.push(i,0)}return t>>>1};p.F._hufTree=function(n,e,t){var r=[],i=n.length,s=e.length,o=0;for(o=0;o<s;o+=2)e[o]=0,e[o+1]=0;for(o=0;o<i;o++)n[o]!=0&&r.push({lit:o,f:n[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(w,A){return w.f-A.f});var c=r[0],h=r[1],m=0,u=1,f=2;for(r[0]={lit:-1,f:c.f+h.f,l:c,r:h,d:0};u!=a-1;)m!=u&&(f==a||r[m].f<r[f].f)?c=r[m++]:c=r[f++],m!=u&&(f==a||r[m].f<r[f].f)?h=r[m++]:h=r[f++],r[u++]={lit:-1,f:c.f+h.f,l:c,r:h};var g=p.F.setDepth(r[u-1],0);for(g>t&&(p.F.restrictDepth(l,t,g),g=t),o=0;o<a;o++)e[(l[o].lit<<1)+1]=l[o].d;return g};p.F.setDepth=function(n,e){return n.lit!=-1?(n.d=e,e):Math.max(p.F.setDepth(n.l,e+1),p.F.setDepth(n.r,e+1))};p.F.restrictDepth=function(n,e,t){var r=0,i=1<<t-e,s=0;for(n.sort(function(a,l){return l.d==a.d?a.f-l.f:l.d-a.d}),r=0;r<n.length&&n[r].d>e;r++){var o=n[r].d;n[r].d=e,s+=i-(1<<t-o)}for(s=s>>>t-e;s>0;){var o=n[r].d;o<e?(n[r].d++,s-=1<<e-o-1):r++}for(;r>=0;r--)n[r].d==e&&s<0&&(n[r].d--,s++);s!=0&&console.log("debt left")};p.F._goodIndex=function(n,e){var t=0;return e[t|16]<=n&&(t|=16),e[t|8]<=n&&(t|=8),e[t|4]<=n&&(t|=4),e[t|2]<=n&&(t|=2),e[t|1]<=n&&(t|=1),t};p.F._writeLit=function(n,e,t,r){return p.F._putsF(t,r,e[n<<1]),r+e[(n<<1)+1]};p.F.inflate=function(n,e){var t=Uint8Array;if(n[0]==3&&n[1]==0)return e||new t(0);var r=p.F,i=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(n.length>>>2<<3));for(var m=0,u=0,f=0,g=0,w=0,A=0,_=0,b=0,N=0,$,Y;m==0;){if(m=i(n,N,1),u=i(n,N+1,2),N+=3,u==0){N&7&&(N+=8-(N&7));var W=(N>>>3)+4,k=n[W-4]|n[W-3]<<8;h&&(e=p.F._check(e,b+k)),e.set(new t(n.buffer,n.byteOffset+W,k),b),N=W+k<<3,b+=k;continue}if(h&&(e=p.F._check(e,b+(1<<17))),u==1&&($=c.flmap,Y=c.fdmap,A=511,_=31),u==2){f=s(n,N,5)+257,g=s(n,N+5,5)+1,w=s(n,N+10,4)+4,N+=14;for(var q=N,X=0;X<38;X+=2)c.itree[X]=0,c.itree[X+1]=0;for(var B=1,X=0;X<w;X++){var K=s(n,N+X*3,3);c.itree[(c.ordr[X]<<1)+1]=K,K>B&&(B=K)}N+=3*w,a(c.itree,B),l(c.itree,B,c.imap),$=c.lmap,Y=c.dmap,N=o(c.imap,(1<<B)-1,f+g,n,N,c.ttree);var D=r._copyOut(c.ttree,0,f,c.ltree);A=(1<<D)-1;var O=r._copyOut(c.ttree,f,g,c.dtree);_=(1<<O)-1,a(c.ltree,D),l(c.ltree,D,$),a(c.dtree,O),l(c.dtree,O,Y)}for(;;){var ee=$[d(n,N)&A];N+=ee&15;var G=ee>>>4;if(!(G>>>8))e[b++]=G;else{if(G==256)break;var se=b+G-254;if(G>264){var te=c.ldef[G-257];se=b+(te>>>3)+s(n,N,te&7),N+=te&7}var y=Y[d(n,N)&_];N+=y&15;var Z=y>>>4,S=c.ddef[Z],C=(S>>>4)+i(n,N,S&15);for(N+=S&15,h&&(e=p.F._check(e,b+(1<<17)));b<se;)e[b]=e[b++-C],e[b]=e[b++-C],e[b]=e[b++-C],e[b]=e[b++-C];b=se}}}return e.length==b?e:e.slice(0,b)};p.F._check=function(n,e){var t=n.length;if(e<=t)return n;var r=new Uint8Array(Math.max(t<<1,e));return r.set(n,0),r};p.F._decodeTiny=function(n,e,t,r,i,s){for(var o=p.F._bitsE,a=p.F._get17,l=0;l<t;){var d=n[a(r,i)&e];i+=d&15;var c=d>>>4;if(c<=15)s[l]=c,l++;else{var h=0,m=0;c==16?(m=3+o(r,i,2),i+=2,h=s[l-1]):c==17?(m=3+o(r,i,3),i+=3):c==18&&(m=11+o(r,i,7),i+=7);for(var u=l+m;l<u;)s[l]=h,l++}}return i};p.F._copyOut=function(n,e,t,r){for(var i=0,s=0,o=r.length>>>1;s<t;){var a=n[s+e];r[s<<1]=0,r[(s<<1)+1]=a,a>i&&(i=a),s++}for(;s<o;)r[s<<1]=0,r[(s<<1)+1]=0,s++;return i};p.F.makeCodes=function(n,e){for(var t=p.F.U,r=n.length,i,s,o,a,l,d=t.bl_count,a=0;a<=e;a++)d[a]=0;for(a=1;a<r;a+=2)d[n[a]]++;var c=t.next_code;for(i=0,d[0]=0,s=1;s<=e;s++)i=i+d[s-1]<<1,c[s]=i;for(o=0;o<r;o+=2)l=n[o+1],l!=0&&(n[o]=c[l],c[l]++)};p.F.codes2map=function(n,e,t){for(var r=n.length,i=p.F.U,s=i.rev15,o=0;o<r;o+=2)if(n[o+1]!=0)for(var a=o>>1,l=n[o+1],d=a<<4|l,c=e-l,h=n[o]<<c,m=h+(1<<c);h!=m;){var u=s[h]>>>15-e;t[u]=d,h++}};p.F.revCodes=function(n,e){for(var t=p.F.U.rev15,r=15-e,i=0;i<n.length;i+=2){var s=n[i]<<e-n[i+1];n[i]=t[s]>>>r}};p.F._putsE=function(n,e,t){t=t<<(e&7);var r=e>>>3;n[r]|=t,n[r+1]|=t>>>8};p.F._putsF=function(n,e,t){t=t<<(e&7);var r=e>>>3;n[r]|=t,n[r+1]|=t>>>8,n[r+2]|=t>>>16};p.F._bitsE=function(n,e,t){return(n[e>>>3]|n[(e>>>3)+1]<<8)>>>(e&7)&(1<<t)-1};p.F._bitsF=function(n,e,t){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16)>>>(e&7)&(1<<t)-1};p.F._get17=function(n,e){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16)>>>(e&7)};p.F._get25=function(n,e){return(n[e>>>3]|n[(e>>>3)+1]<<8|n[(e>>>3)+2]<<16|n[(e>>>3)+3]<<24)>>>(e&7)};p.F.U=function(){var n=Uint16Array,e=Uint32Array;return{next_code:new n(16),bl_count:new n(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 n(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 n(512),fltree:[],fdmap:new n(32),fdtree:[],lmap:new n(32768),ltree:[],ttree:[],dmap:new n(32768),dtree:[],imap:new n(512),itree:[],rev15:new n(32768),lhst:new e(286),dhst:new e(30),ihst:new e(19),lits:new e(15e3),strt:new n(65536),prev:new n(32768)}}();(function(){for(var n=p.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,n.rev15[t]=(r>>>16|r<<16)>>>17}function i(s,o,a){for(;o--!=0;)s.push(0,a)}for(var t=0;t<32;t++)n.ldef[t]=n.of0[t]<<3|n.exb[t],n.ddef[t]=n.df0[t]<<4|n.dxb[t];i(n.fltree,144,8),i(n.fltree,112,9),i(n.fltree,24,7),i(n.fltree,8,8),p.F.makeCodes(n.fltree,9),p.F.codes2map(n.fltree,9,n.flmap),p.F.revCodes(n.fltree,9),i(n.fdtree,32,5),p.F.makeCodes(n.fdtree,5),p.F.codes2map(n.fdtree,5,n.fdmap),p.F.revCodes(n.fdtree,5),i(n.itree,19,0),i(n.ltree,286,0),i(n.dtree,30,0),i(n.ttree,320,0)})()});var vn=ve(nt());var it=n=>{let e=Math.floor((n-5)/7*100+.5)/100;return Math.floor((e*7+5)/7*256)/256},Pt=n=>Math.floor((256*n+Math.floor(18.285714285714285))/256*7);var dr="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 hr=n=>n!==null&&typeof n=="object"&&"row"in n&&"column"in n;var j=class n{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 n({row:1/0,column:e})}static FromRow(e){return new n({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){if(e.row===1/0&&e.column===1/0)throw new Error("this is going to break something");let r=t?`${e.sheet_id||0}!`:"";return e.row===1/0?r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column):e.column===1/0?r+(e.absolute_row?"$":"")+(e.row+1):r+(e.absolute_column?"$":"")+this.ColumnToLabel(e.column)+(e.absolute_row?"$":"")+(e.row+1)}static Join(e,...t){let r=new n(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 n({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:s,row_count:o}=t,a=new n(e.start,e.end),l=e.start.sheet_id;if(i&&r<=a.end.column){if(i>0)r<=a.start.column?a.Shift(0,i):r>a.start.column&&r<=a.end.column?a.ConsumeAddress({row:a.end.row,column:a.end.column+i}):console.warn("AA X case 1",r,i,JSON.stringify(a));else if(i<0)if(r-i<=a.start.column)a.Shift(0,i);else{if(r<=a.start.column&&r-i>a.end.column)return!1;if(r<=a.start.column){let d=r-i-1;a=new n({row:a.start.row,column:d+1+i,sheet_id:l},{row:a.end.row,column:a.end.column+i})}else r<=a.end.column?r-i-1>=a.end.column?a=new n({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:r-1}):a=new n({row:a.start.row,column:a.start.column,sheet_id:l},{row:a.end.row,column:a.start.column+a.columns+i-1}):console.warn("AA X case 2",r,i,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 n({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 n({column:a.start.column,row:a.start.row,sheet_id:l},{column:a.end.column,row:s-1}):a=new n({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}Equals2(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 n(this.start,this.end)}get left(){let e=new n(this.start_,this.end_);return e.end_.column=e.start_.column,e}get right(){let e=new n(this.start_,this.end_);return e.start_.column=e.end_.column,e}get top(){let e=new n(this.start_,this.end_);return e.end_.row=e.start_.row,e}get bottom(){let e=new n(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}[Symbol.iterator](){if(this.entire_row||this.entire_column)throw new Error("don\'t iterate infinite area");let e=this.start_.row,t=this.start_.column;return{next:()=>{let r={column:t,row:e,sheet_id:this.start_.sheet_id};return t>this.end_.column?{done:!0,value:void 0}:(++e>this.end_.row&&(e=this.start_.row,t++),{value:r})}}}get spreadsheet_label(){let e;return this.entire_sheet?"":this.entire_column?(e=n.ColumnToLabel(this.start_.column),e+=":"+n.ColumnToLabel(this.end_.column),e):this.entire_row?(e=String(this.start_.row+1),e+=":"+(this.end_.row+1),e):(e=n.CellAddressToLabel(this.start_),this.columns>1||this.rows>1?e+":"+n.CellAddressToLabel(this.end_):e)}toJSON(){return{start:{...this.start_},end:{...this.end_}}}};var Vn=n=>typeof n=="object"&&!!n&&typeof n.real=="number"&&typeof n.imaginary=="number";var Zt=n=>typeof n=="object"&&!!n&&typeof n.value=="number"&&typeof n.unit=="string",Ft=["undefined","formula","string","number","boolean","object","error","complex","array","dimensioned_quantity"];var Ne=n=>{switch(typeof n){case"undefined":return 0;case"number":return 3;case"boolean":return 4;case"object":return n===null?0:Vn(n)?7:Zt(n)?9:5;case"string":return n[0]==="="?1:2;default:return 6}};var ne=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;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=Ne(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=Ne(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=Ne(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 Yn=n=>!n.cells,On=n=>!!n[0]&&Yn(n[0]),jn=n=>!!n[0]&&n[0].row!==void 0,Dn=Ft.map((n,e)=>({[n]:e})).reduce((n,e)=>({...n,...e}),{}),at=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){this.data=this.data.map(r=>{if(r.length>=e){let i=r.slice(0,e),s=e+t,o=r.slice(e);for(let a=0;a<o.length;a++)i[s++]=o[a];return i}return r}),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 ne,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 s=i[r];return s||(s=i[r]=new ne,this.columns_=Math.max(this.columns_,r+1)),s}FromArray(e=[],t=!1){this.data=[];let r=0,i=0;if(t){i=e.length;for(let s=0;s<i;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 ne(o[a])}}else{r=e.length;for(let s=0;s<r;s++){let o=[],a=e[s];i=Math.max(i,a.length);for(let l=0;l<a.length;l++)o[l]=new ne(a[l]);this.data[s]=o}}this.rows_=r,this.columns_=i}SerializedTypeToValueType(e){if(e)return typeof e=="number"?e:Dn[e]||void 0}ValueTypeToSerializedType(e){return e?Ft[e]:void 0}FromJSON(e=[],t){if(this.data=[],!On(e)){let i=[];if(jn(e))for(let s of e)for(let o of s.cells)i.push({...o,row:s.row});else for(let s of e)for(let o of s.cells)i.push({...o,column:s.column});e=i}let r=[];for(let i of e){this.data[i.row]||(this.data[i.row]=[]);let s=new ne(i.value);if(typeof i.calculated<"u"&&s.SetCalculatedValue(i.calculated,this.SerializedTypeToValueType(i.calculated_type)),t&&typeof i.style_ref<"u"&&(s.style=t[i.style_ref]),typeof i.note<"u"&&(s.note=i.note),typeof i.hyperlink<"u"&&(s.hyperlink=i.hyperlink),this.data[i.row][i.column]&&this.data[i.row][i.column].area&&(s.area=this.data[i.row][i.column].area),this.data[i.row][i.column]=s,i.area){let o=new j(i.area.start,i.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 ne),this.data[a][l].area=o}if(i.table&&r.push({...i.table}),i.merge_area){let o=new j(i.merge_area.start,i.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 ne),this.data[a][l].merge_area=o}}for(let i of r)for(let s=i.area.start.row;s<=i.area.end.row;s++)for(let o=i.area.start.column;o<=i.area.end.column;o++)this.data[s]||(this.data[s]=[]),this.data[s][o]||(this.data[s][o]=new ne),this.data[s][o].table=i;this.rows_=this.data.length,this.columns_=this.data.reduce((i,s)=>Math.max(i,s.length),0)}toJSON(e={}){let t=0,r=0,i=this.data.length-1,s;e.subset&&(t=e.subset.start.column,r=e.subset.start.row,i=e.subset.end.row);let o=[],a=-1,l=-1,d={},c={};for(let h=r;h<=i;h++)if(this.data[h]){let m=this.data[h];s=m.length-1,e.subset&&(s=e.subset.end.column);for(let u=t;u<=s;u++){let f=m[u],g=f&&f.merge_area&&f.merge_area.start.row===h&&f.merge_area.start.column===u,w=f&&f.area&&f.area.start.row===h&&f.area.start.column===u,A=f&&f.table&&f.table.area.start.row===h&&f.table.area.start.column===u,_=f?f.type===2&&!f.value:!0;if(f&&(!_||e.preserve_empty_strings)&&(g||f.type||f.calculated_type&&e.expand_arrays||f.calculated_type&&e.calculated_value||f.note||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 b={row:h,column:u,value:f.value};f.note&&(b.note=f.note),f.hyperlink&&(b.hyperlink=f.hyperlink),e.preserve_type&&(b.type=this.ValueTypeToSerializedType(f.type)),e.sheet_id&&(b.sheet_id=e.sheet_id),e.calculated_value&&typeof f.calculated<"u"&&(b.calculated=f.calculated,(e.preserve_type||f.calculated_type===6)&&(b.calculated_type=this.ValueTypeToSerializedType(f.calculated_type))),f.table&&A&&e.tables&&(b.table=JSON.parse(JSON.stringify(f.table))),f.area&&w&&(b.area=f.area.toJSON()),f.merge_area&&(b.merge_area=f.merge_area.toJSON()),e.cell_style_refs&&e.cell_style_refs[u]&&e.cell_style_refs[u][h]&&(b.style_ref=e.cell_style_refs[u][h],e.cell_style_refs[u][h]=0),d[h]=h,c[u]=u,a=Math.max(h,a),l=Math.max(u,l),o.push(b)}}}if(e.nested){let h=Object.keys(d),m=Object.keys(c);if(h.length<=m.length&&h.length){let u={},f=[];for(let g of o){let{row:w,...A}=g;u[g.row]||(u[g.row]=[]),u[g.row].push(A)}for(let g of h){let w=Number(g);f.push({row:w,cells:u[w]})}return{data:f,rows:a,columns:l+1}}else if(m.length){let u={},f=[];for(let g of o){let{column:w,...A}=g;u[g.column]||(u[g.column]=[]),u[g.column].push(A)}for(let g of m){let w=Number(g);f.push({column:w,cells:u[w]})}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)}Normalize(e,t){return e={...e,row:e.row==1/0?0:e.row,column:e.column==1/0?0:e.column},t&&(t={...t,row:t.row==1/0?this.rows_-1:t.row,column:t.column==1/0?this.columns_-1:t.column}),{from:e,to:t}}RawValue(e,t=e){if({from:e,to:t}=this.Normalize(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),s=e.column,o=t.column+1;for(let a of i){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({from:e,to:t}=this.Normalize(e,t),!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 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);i.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);i.push(o)}return i}GetRange4(e,t=e,r=!1){if({from:e,to:t}=this.Normalize(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 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});i.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});i.push(o)}return{type:8,value:i}}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 s=this.data[r];if(t[i])for(let o=e.start.column,a=0;o<=e.end.column;o++,a++)s[o]||(s[o]=new ne),s[o].Set(t[i][a])}else{let r=Ne(t);for(let i=e.start.row;i<=e.end.row;i++){this.data[i]||(this.data[i]=[]);let s=this.data[i];for(let o=e.start.column;o<=e.end.column;o++)s[o]||(s[o]=new ne),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)}*Iterate(e,t=!1){if(!e&&t&&(e=new j({row:0,column:0},{row:this.rows_-1,column:this.columns-1})),e){hr(e)&&(e=new j(e)),(e.entire_column||e.entire_row)&&(e=new j(e.start,e.end),e.start.column===1/0&&(e.start.column=0,e.end.column=this.columns_-1),e.start.row===1/0&&(e.start.row=0,e.end.row=this.rows_-1));let r=e.start,i=e.end;if(t)for(let s=r.row;s<=i.row;s++){this.data[s]||(this.data[s]=[]);let o=this.data[s];for(let a=r.column;a<=i.column;a++)o[a]||(o[a]=new ne),yield o[a]}else for(let s=r.row;s<=i.row;s++)if(this.data[s]){let o=this.data[s];for(let a=r.column;a<=i.column;a++)o[a]&&(yield o[a])}}else for(let r of this.data)if(r)for(let i of r)i&&(yield i)}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 U=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 s=i.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)}this.locale==="C"&&(console.warn("Locale not set, defaulting to en-us"),this.locale="en-us");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"}))}};U.UpdateLocale();var Hn=JSON.stringify({}),Jn={Background:0,Text:1,Background2:2,Text2:3,Accent:4,Accent2:5,Accent3:6,Accent4:7,Accent5:8,Accent6:9},Se=n=>typeof n.theme=="number"?n.theme:Jn[n.theme]||0,Te=n=>!!n&&typeof n.text=="string",Pe=n=>!!n&&typeof n.theme<"u";var Fe={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:n=>({top:{width:n.border_top||0,color:n.border_top_fill||{}},left:{width:n.border_left||0,color:n.border_left_fill||{}},right:{width:n.border_right||0,color:n.border_right_fill||{}},bottom:{width:n.border_bottom||0,color:n.border_bottom_fill||{}}}),Merge:(n,e,t=!0)=>{let r=t?{...n,...e}:{...e};return JSON.parse(JSON.stringify(r))},Composite:n=>JSON.parse(JSON.stringify(n.reduce((e,t)=>({...e,...t}),{}))),Empty:n=>JSON.stringify(n)===Hn,ParseFontSize:(n="",e="em")=>{let t=n.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:(n,e)=>{let t=12,r=12;switch(n.font_size?.unit){case"pt":if(!n.font_size.value)return 1;r=n.font_size.value;break;case"px":if(!n.font_size.value)return 1;r=Math.round(n.font_size.value*300/4)/100;break;case"em":return n.font_size.value||1;case"%":return(n.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:(n,e=!0)=>{let t=n.font_size?.value;switch(n.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:(n,e=1)=>{let t=[];return n.bold&&t.push("bold"),n.italic&&t.push("italic"),t.push(((n.font_size?.value||0)*e).toFixed(2)+(n.font_size?.unit||"pt")),t.push(n.font_face||""),t.join(" ")}};var In=ve(lt());var ss={"&lt;":"<","&gt;":">","&amp;":"&","&quot;":\'"\',"&apos;":"\'"},as=/&\\w+;/g,os=n=>n.replace(as,e=>ss[e]||e);var ct=os;var Vr=ve(lt()),Yr=(n,e)=>ct(e),Bt=n=>{if(n){if(Array.isArray(n))for(let e of n)Bt(e);else if(typeof n=="object")for(let[e,t]of Object.entries(n))if(e==="a$"){if(typeof t=="object"){let r={};for(let[i,s]of Object.entries(t))s!==void 0&&(r[i]=s);n[e]=r}}else Bt(t)}return n},Or=n=>{let e=new Vr.XMLBuilder(n),t=e.build;return e.build=r=>t.call(e,Bt(r)),e},jr={ignoreAttributes:!1,attributeNamePrefix:"__",trimValues:!1,textNodeName:"text__",tagValueProcessor:Yr,ignoreDeclaration:!0},dt={ignoreAttributes:!1,attributesGroupName:"a$",attributeNamePrefix:"",textNodeName:"t$",trimValues:!1,ignoreDeclaration:!0,isArray:n=>/Relationship$/.test(n),tagValueProcessor:Yr},M=class{static FindChild(e={},t){let r=t.split("/");for(let i of r)if(e=e[i],!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,i)=>r.concat(this.FindAllTail(i,t)),[]);for(let r=0;r<t.length;r++){let i=t[r];if(i==="*"?e=Object.keys(e).filter(s=>s!=="a$"&&s!=="t$").map(s=>e[s]):e=e[i],!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 Me=class{strings=[];reverse={};FromXML(e){this.strings=[],this.reverse={};let t=0;for(let r of M.FindAll(e,"sst/si")){if(r.t!==void 0){let i="";typeof r.t=="string"?i=r.t:r.t.t$&&(i=r.t.t$),this.strings[t]=i,this.reverse[i]=t}else if(r.r){let s=M.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 we=class n{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="",i=t.toString().match(/^(.*?):/);if(i&&(r=i[1]+":"),e[t]&&e[t][`${r}themeElements`]){let s=e[t][`${r}themeElements`][`${r}clrScheme`];for(let o of n.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 be=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 Dr=42,Hr=95,Ut=63,ht=48,Jr=46,Lt=44,Xr=37,Vt=34,Ve=35,Qr=59,ut=92,qr=64,cs=91,ds=93,Kr=69,en=101,hs=72,us=104,fs=77,ms=109,ps=83,bs=115,gs=68,ys=100,xs=89,_s=121,ws=65,As=97;var ft=class{static date_pattern=!1;static pattern="";static char_index=0;static characters=[];static sections=[];static current_section=new be;static preserve_formatting_characters=!1;static decimal_mark=Jr;static group_separator=Lt;static Parse(e){if(this.pattern=e,this.characters=e.split("").map(t=>t.charCodeAt(0)),this.char_index=0,this.current_section=new be,this.sections=[this.current_section],this.ParseDatePattern())return this.sections;for(this.char_index=0,this.current_section=new be,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 ut: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 Vt: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 ut:throw new Error("invalid escape character in formatting block");case ds: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 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+=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 s=this.characters[i];if(s===this.decimal_mark||s===Ve||s===ht)r=!0;else if(s!==Lt)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 Ve:e===1?this.current_section.decimal_max_digits++:this.current_section.integer_min_digits&&this.current_section.integer_min_digits++;break;case ht: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===Ut||e===Ve)&&!this.current_section.has_number_format&&!this.current_section.string_format&&this.ScanFractionFormat()))switch(e){case Qr:this.char_index++,this.current_section=new be,this.sections.length===3&&(this.current_section.string_format=!0),this.sections.push(this.current_section);break;case qr:this.char_index++,this.AppendTextPart({text:"@",flag:5}),this.current_section.string_format=!0;break;case ht:case Ve:case Jr:case Lt:!this.current_section.has_number_format&&!this.current_section.string_format?(this.ConsumeNumberFormat(),this.current_section.has_number_format=!0):this.AppendCharAsText();break;case cs:this.AppendTextPart({text:this.ConsumeFormatting(),flag:6});break;case Vt:this.AppendString(this.ConsumeString());break;case Ut:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Hr: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 Dr: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 en:case Kr: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 Xr:!this.current_section.exponential&&!this.current_section.string_format&&(this.current_section.percent=!0),this.AppendCharAsText();break;case ut: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 Qr:this.char_index=this.characters.length;break;case ht:case Ve:case en:case Kr:case Xr:case qr:this.date_pattern=!1;break;case hs:case us:case fs:case ms:case ps:case bs:case gs:case ys:case xs:case _s:this.AppendTextPart(this.ConsumeDatePart());break;case ws:case As:{let t=this.ConsumeAMPM();t?this.AppendTextPart(t):this.AppendCharAsText()}break;case Vt:this.AppendString(this.ConsumeString());break;case Ut:this.preserve_formatting_characters?this.AppendCharAsText():(this.AppendTextPart({text:"0",flag:1}),this.char_index++);break;case Hr: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 Dr: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 ut: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 Cs=n=>(n>=60&&n--,new Date(-22090752e5+864e5*n)),tn=(n,e=!0)=>{if(e){let t=new Date(n);n=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()).getTime()}return n=(n+22090752e5)/864e5,n>=60&&n++,n},ke=class n{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=ft.Parse(e),this.sections.length||(this.sections=[]),this.sections[0]||(this.sections[0]=new be),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((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=i.reduce((a,l,d)=>d===r?a:a+l.length,0),o="";for(let a=0;a<t-s;a++)o+=i[r];i[r]=o}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 s=0;s<e.fraction_denominator_digits;s++)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(Zt(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,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="",i=!0):t.length===1&&this.sections[1].integer_min_digits<=1&&t[0].text==="-1"&&(t[0].text="-",i=!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){a.push({text:e.imaginary<0?` ${n.minus_character} `:" + "});let l=i?[]:this.FormatParts(Math.abs(e.imaginary));a.push(...l,{text:n.imaginary_character})}}else s&&a.push(...t,{text:n.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),i=[];if(r.date_format||r.string_format)for(let s of t)typeof s=="string"?i.push({text:s}):i.push(s);else this.magic_decimal&&t[1]===""&&t.splice(1,1),i=[...r.prefix.map(s=>({...s})),{text:r.has_number_format?t.join(U.decimal_separator):""},...r.suffix.map(s=>({...s}))];for(let s=1;s<i.length;s++)i[s].flag===i[s-1].flag&&(i[s].text=i[s-1].text+i[s].text,i[s-1].text="");return i.filter(s=>s.text)}Format(e,t=0){return n.FormatPartsAsText(this.FormatParts(e),t)}ZeroPad(e,t){for(;e.length<t;)e="0"+e;return e}DateFormat(e){let t=Cs(e),r=this.sections[0],i=t.getUTCHours();return r.twelve_hour&&(i>12&&(i-=12),i===0&&(i=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:U.date_components.long_months[t.getUTCMonth()][0]};case"mmmm":return o.text==="MMMM"?{text:U.date_components.long_months[t.getUTCMonth()].toUpperCase()}:{text:U.date_components.long_months[t.getUTCMonth()]};case"mmm":return o.text==="MMM"?{text:U.date_components.short_months[t.getUTCMonth()].toUpperCase()}:{text:U.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:U.date_components.long_days[t.getUTCDay()].toUpperCase()}:{text:U.date_components.long_days[t.getUTCDay()]};case"ddd":return o.text==="DDD"?{text:U.date_components.short_days[t.getUTCDay()].toUpperCase()}:{text:U.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 a=o.text.match(/^(s+)\\.(0+)$/);if(a)return{text:this.ZeroPad(t.getUTCSeconds().toString(),a[1].length)+U.decimal_separator+(t.getUTCMilliseconds()/1e3).toFixed(a[2].length).substr(2)}}return{...o}}),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 s=n.fraction_limits[t.fraction_denominator_digits-1]||n.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 i=[];if(t.fraction_integer){let s=Math.floor(r.numerator/r.denominator);r.numerator%=r.denominator,(s||!r.numerator)&&(i.push(s.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,s=Math.pow(10,-i)/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(n.grouping_regexp,"$&"+U.grouping_separator)),{parts:l,section:t}}};var Ye=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 ke(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 ke(this.base_formats[e]),this.symbolc_name_map[e.toLowerCase()]=e;this.cache.General.magic_decimal=!0,this.complex_general=new ke("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}};Ye.InitCache();var rn=new Date().getUTCFullYear(),Yt=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[U.date_components.long_months[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_month[U.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[U.date_components.long_days[l].toLocaleLowerCase().replace(/\\./,"")]=l,this.compare_day[U.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(),i=r.match(/^[$](.*?)$/);i&&(r=i[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),U.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>=rn-200&&h<=rn+200)return t={Date:!0},(c.getHours()||c.getMinutes()||c.getSeconds())&&(t.Time=!0),{value:tn(d,!0),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}}},Mo=new Yt;var nn=11,Ot={top:{},left:{},bottom:{},right:{},diagonal:{}},Ee=class n{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 we;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),i=parseInt(e.substr(2,2),16),s=parseInt(e.substr(4,2),16);return t<0?(r=Math.round(r*t+r),i=Math.round(i*t+i),s=Math.round(s*t+s)):(r=Math.round((255-r)*t+r),i=Math.round((255-i)*t+i),s=Math.round((255-s)*t+s)),[r,i,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={},i={pattern_type:"none"},s=JSON.parse(JSON.stringify(Ot)),o={font:r,border:s};t.number_format&&(o.number_format={format:Ye.Translate(t.number_format),symbolic_name:t.number_format},/Scientific/i.test(t.number_format)&&(o.number_format.format="0.00E+00")),t.font_size?.unit&&t.font_size.value&&(t.font_size.unit==="em"?r.size=t.font_size.value*nn:t.font_size.unit==="%"?r.size=t.font_size.value*nn/100:t.font_size.unit==="pt"?r.size=t.font_size.value:t.font_size.unit==="px"?r.size=t.font_size.value*.75:console.warn("Unhandled font size unit",t.font_size)),t.bold&&(r.bold=!0),t.italic&&(r.italic=!0),t.underline&&(r.underline=!0),t.text&&(Te(t.text)?r.color_argb=t.text.text:Pe(t.text)&&(r.color_theme=Se(t.text),t.text.tint&&(r.color_tint=t.text.tint)));let a=(d,c)=>{d.width&&(c.style="thin",Te(d.color)?c.rgba=d.color.text:Pe(d.color)?(c.theme=Se(d.color),d.color.tint&&(c.tint=d.color.tint)):c.color=64)},l=Fe.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 o.indent=t.indent,t.fill&&(i.pattern_type="solid",Te(t.fill)?(i.fg_color={argb:t.fill.text},o.fill=i):Pe(t.fill)&&(i.fg_color={theme:Se(t.fill)},t.fill.tint&&(i.fg_color.tint=t.fill.tint),o.fill=i)),t.wrap&&(o.wrap=!0),o}CellXfToStyle(e){let t={},r=n.default_styles[e.number_format];if(!r){for(let d of this.number_formats)if(d.id===e.number_format&&d.format){r=d.format;break}}if(r){let d=/\\[\\$(.)-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(d,"$1");let c=/\\[\\$-[0-9A-Za-z]{1,4}\\]/g;r=r.replace(c,""),t.number_format=r}let i=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),i&&i.size&&s.size&&i.size!==s.size&&(t.font_size={value:100*s.size/i.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 d=Math.round((o.pattern_gray||0)/1e3*255);t.fill={text:`rgb(${d}, ${d}, ${d})`}}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}t.indent=typeof e.indent=="string"?Number(e.indent):e.indent,e.wrap_text&&(t.wrap=!0);let a=d=>{if(typeof d.theme<"u")return{theme:d.theme,tint:d.tint}},l=this.borders[e.border||0];return l&&(l.bottom.style&&(l.bottom.style==="double"?t.border_bottom=2:t.border_bottom=1,t.border_bottom_fill=a(l.bottom)),l.left.style&&(t.border_left=1,t.border_left_fill=a(l.left)),l.top.style&&(t.border_top=1,t.border_top_fill=a(l.top)),l.right.style&&(t.border_right=1,t.border_right_fill=a(l.right))),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 i=n.default_styles[r];if(i&&i===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 i=this.borders[r];if(this.CompareBorder(i,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 i=this.fills[r];if(this.MatchColor(e.bg_color,i.bg_color)&&this.MatchColor(e.fg_color,i.fg_color)&&e.pattern_gray===i.pattern_gray&&e.pattern_type===i.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 i=this.fonts[r];if(i.bold===t.bold&&i.italic===t.italic&&i.underline===t.underline&&i.size===t.size&&i.strike===t.strike&&i.color_argb===t.color_argb&&i.color_theme===t.color_theme&&i.color_tint===t.color_tint&&i.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||Ot),i=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===i&&!!l.wrap_text==!!e.wrap&&l.indent===e.indent&&(!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:i,indent:e.indent};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=M.FindAll.bind(M,e);this.theme=t;let i=r("styleSheet/numFmts/numFmt");this.number_formats=i.map(c=>({id:Number(c.a$?.numFmtId||0),format:ct(c.a$?.formatCode||"")})),i=r("styleSheet/borders/border");let s=(c,h)=>{c?.a$&&(h.style=c.a$.style,typeof c.color=="object"&&(typeof c.color.a$?.indexed<"u"&&(h.color=Number(c.color.a$.indexed)),typeof c.color.a$?.theme<"u"&&(h.theme=Number(c.color.a$.theme)),typeof c.color.a$?.tint<"u"&&(h.tint=Number(c.color.a$.tint))))};this.borders=i.map(c=>{let h=JSON.parse(JSON.stringify(Ot));return s(c.left,h.left),s(c.right,h.right),s(c.top,h.top),s(c.bottom,h.bottom),h}),i=r("styleSheet/cellXfs/xf"),this.cell_xfs=i.map(c=>{let h={number_format:Number(c.a$.numFmtId),font:Number(c.a$.fontId),fill:Number(c.a$.fillId),border:Number(c.a$.borderId),xfid:Number(c.a$.xfId)};return c.alignment&&(h.horizontal_alignment=c.alignment.a$.horizontal,h.vertical_alignment=c.alignment.a$.vertical,h.wrap_text=!!c.alignment.a$.wrapText,h.indent=c.alignment.a$.indent||void 0),h});let o=c=>{let h={pattern_type:"none"};if(c.patternFill){let m=c.patternFill.a$?.patternType;switch(m){case"none":case void 0:break;case"solid":h.pattern_type="solid",c.patternFill.fgColor&&(h.fg_color={theme:c.patternFill.fgColor.a$?.theme?Number(c.patternFill.fgColor.a$.theme):void 0,indexed:c.patternFill.fgColor.a$?.indexed?Number(c.patternFill.fgColor.a$.indexed):void 0,tint:c.patternFill.fgColor.a$?.tint?Number(c.patternFill.fgColor.a$.tint):void 0,argb:c.patternFill.fgColor.a$?.rgb});break;default:{let u=m?.match(/^gray(\\d+)$/);if(u){h.pattern_type="gray",h.pattern_gray=Number(u[1]);break}}}}return h};i=r("styleSheet/fills/fill"),this.fills=i.map(o);let a=c=>{let h={};return h.italic=typeof c.i<"u",h.bold=typeof c.b<"u",h.underline=typeof c.u<"u",h.strike=typeof c.strike<"u",c.sz&&(h.size=Number(c.sz.a$.val)),c.scheme&&(h.scheme=c.scheme.a$.val),c.name&&(h.name=c.name.a$.val),c.family&&(h.family=Number(c.family.a$.val)),c.color&&(c.color.a$?.theme&&(h.color_theme=Number(c.color.a$.theme)),c.color.a$?.tint&&(h.color_tint=Number(c.color.a$.tint)),c.color.a$?.rgb&&(h.color_argb=c.color.a$.rgb)),h};i=r("styleSheet/fonts/font"),this.fonts=i.map(a);let l=c=>{let h={};return c.a$.rgb?h.text="#"+c.a$.rgb.substring(2):c.a$.theme&&(h.theme=Number(c.a$.theme)||0,c.a$.tint&&(h.tint=Math.round(c.a$.tint*1e3)/1e3)),h},d=r("styleSheet/dxfs/dxf");this.dxf_styles=d.map(c=>{let h={};return c.font&&(h.bold=!!c.font.b,h.italic=!!c.font.i&&c.font.i.a$.val!=="0"),c.font?.color?.a$&&(h.text=l(c.font.color)),c.fill?.patternFill?.bgColor?.a$&&(h.fill=l(c.fill.patternFill.bgColor)),h})}};var he=(n,e,t,r)=>{let s=`rId${Object.keys(n).length+1}`;return n[s]={id:s,type:e,target:t,mode:r},s};var sn={spreadsheet_semantics:!0,dimensioned_quantities:!1,fractions:!0,decimal_mark:".",argument_separator:","};var an=/[\\s-+=<>!()]/;var jt=34,Dt=39,vs=160,on=32,Is=9,Ns=10,Ss=13,ge=48,Oe=57,Ht=46,Jt=43,je=45,ln=40,Xt=41,De=44,Ts=37,Qt=95,mt=36,Ps=123,Zs=125,He=91,cn=93,Fs=63,Ms=33,dn=59,ks=35,Es=64,Re=65,Je=97,Rs=69,$s=101,pt=90,bt=122,Ws=105,qt=192,Kt=312,er={"==":6,"!=":6,"<>":6,"=":6,"<":7,">":7,"<=":7,">=":7,"+":9,"-":9,"&":9,"*":10,"/":10,"^":11,":":13},Gs=Object.keys(er).sort((n,e)=>e.length-n.length),zs={"-":100,"+":100},$e=class{get argument_separator(){return this.flags.argument_separator}get decimal_mark(){return this.flags.decimal_mark}flags={...sn};r1c1_regex=/[rR]((?:\\[[-+]{0,1}\\d+\\]|\\d+))[cC]((?:\\[[-+]{0,1}\\d+\\]|\\d+))$/;argument_separator_char=De;decimal_mark_char=Ht;imaginary_char=Ws;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=[];parser_state_cache=[];SetLocaleSettings(e,t){if(typeof t>"u"&&(t=e===","?";":","),t===e)throw new Error("invalid locale setting");this.flags.argument_separator=t,this.flags.decimal_mark=e}Save(){this.parser_state_cache.push(JSON.stringify(this.flags))}Restore(){let e=this.parser_state_cache.shift();if(e)try{this.flags=JSON.parse(e)}catch(t){console.error(t)}else console.warn("No parser state to restore")}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 s=0;s<t;s++)Array.isArray(e[s])&&(i=Math.max(i,e[s].length));for(let s=0;s<i;s++){r[s]=[];for(let o=0;o<t;o++)r[s][o]=e[o]?e[o][s]:void 0}return r}Render(e,t={}){let r=t.offset||{rows:0,columns:0},i=t.missing??"(missing)",{convert_decimal:s,convert_argument_separator:o,long_structured_references:a,table_name:l}=t,d=this.flags.argument_separator+" ";o===","?d=", ":o===";"&&(d="; ");let c=s===","?",":".",h=this.flags.decimal_mark===","?/,/:/\\./,m=this.flags.decimal_mark===","?/,/g:/\\./g;switch(e.type){case"address":return t.r1c1?this.R1C1Label(e,t.r1c1_base):this.AddressLabel(e,r);case"range":return t.r1c1?this.R1C1Label(e.start,t.r1c1_base)+":"+this.R1C1Label(e.end,t.r1c1_base):this.AddressLabel(e.start,r)+":"+this.AddressLabel(e.end,r);case"missing":return i;case"array":return"{"+this.Transpose(e.values).map(u=>u.map(f=>typeof f=="string"?\'"\'+f+\'"\':f).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(m,c):e.text;{let u=Math.abs(e.imaginary).toString();if((s===","||this.flags.decimal_mark===",")&&(u=u.replace(/\\./,",")),e.real){let f=e.real.toString();(s===","||this.flags.decimal_mark===",")&&(f=f.replace(/\\./,","));let g=Math.abs(e.imaginary);return`${f}${e.imaginary<0?" - ":" + "}${g===1?"":u}i`}else return e.imaginary===-1?"-i":e.imaginary===1?"i":`${e.imaginary<0?"-":""}${u}i`}break;case"literal":if(typeof e.value=="string")return\'"\'+e.value.replace(/"/g,\'""\')+\'"\';if(s&&typeof e.value=="number")if(e.text){let u=e.text;return s===","&&this.flags.decimal_mark==="."&&(u=u.replace(/,/g,"")),u.replace(h,c)}else return e.value.toString().replace(/\\./,c);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(u=>this.Render(u,t)).join(d)+")":e.elements.map(u=>this.Render(u,t)).join(d);case"call":return e.name+"("+e.args.map(u=>this.Render(u,t)).join(d)+")";case"dimensioned":return this.Render(e.expression)+" "+this.Render(e.unit);case"structured-reference":{let u=e.column;/[^A-Za-z]/.test(u)&&(u="["+u+"]");let f=e.table;switch(!f&&a&&l&&(f=l),e.scope){case"all":return`${f}[[#all],${u}]`;case"row":return a?`${f}[[#this row],${u}]`:`${f}[@${u}]`;case"column":return`${f}[${u}]`}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.flags.argument_separator){case";":this.argument_separator_char=dn;break;default:this.argument_separator_char=De;break}switch(this.flags.decimal_mark){case",":this.decimal_mark_char=De;break;default:this.decimal_mark_char=Ht;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.flags.argument_separator,decimal_mark:this.flags.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}R1C1Label(e,t){let r="";e.sheet&&(r=(an.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!");let i=e.absolute_row||!t?(e.row+1).toString():`[${e.row-t.row}]`,s=e.absolute_column||!t?(e.column+1).toString():`[${e.column-t.column}]`;return r+=`R${i}C${s}`,r}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 s="";return e.sheet&&(s=(an.test(e.sheet)?"\'"+e.sheet+"\'":e.sheet)+"!"),i===1/0?s+(e.absolute_column?"$":"")+this.ColumnLabel(r):r===1/0?s+(e.absolute_row?"$":"")+(i+1):s+(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===ln){this.index++;let i=this.ParseGeneric([Xt]);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=o=>o.type==="literal"&&typeof o.value=="number"&&o.value%1===0,s=0;for(;s<t.length-3;s++)if(i(t[s])&&i(t[s+1])&&t[s+2].type==="operator"&&t[s+2].operator==="/"&&i(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=[],i;for(let s=0;s<t.length;s++){let o=t[s];if(!i)i=o;else if(o.type==="identifier"&&(i.type==="literal"||i.type==="group"||i.type==="call")){let a=o;for(;t[s+1]?.type==="identifier";)a.name+=" "+t[++s].name;r.push({type:"dimensioned",expression:i,unit:o,id:this.id_counter++}),i=void 0}else r.push(i),i=o}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 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-Re)}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 i=e[r],s=e[r+1],o=e[r+2],a,l="",d;if(i&&s&&o&&s.type==="operator"&&s.operator===":"){if(i.type==="address"&&o.type==="address"){let c=i.position+i.label.length,h=o.position;a={type:"range",id:this.id_counter++,position:i.position,start:i,end:o,label:i.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 m=[i.position,o.position];this.full_reference_list=this.full_reference_list.filter(u=>u.position!==m[0]&&u.position!==m[1])}else if((i.type==="literal"||i.type==="identifier")&&(o.type==="literal"||o.type==="identifier")){let c=this.UnitToAddress(i);if(!c&&i.type==="literal"&&typeof i.value=="number"&&i.value<0){let m={...i,text:(i.text||"").replace(/^-/,""),position:i.position+1,value:-i.value};c=this.UnitToAddress(m),c&&(d={type:"operator",operator:"-",position:i.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(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,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(i,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 i=this.UnitToAddress(e.left),s=this.UnitToAddress(e.right);i&&s&&(i.column===1/0&&s.column===1/0||i.row===1/0&&s.row===1/0)&&(r=i.label+":"+s.label,t={type:"range",id:this.id_counter++,position:e.left.position,start:i,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 i=e[r];if(i.type==="operator")if(t.length===0||t[t.length-1].type==="operator")if(zs[i.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:i.operator,operand:s.left,position:i.position},i=s):i={type:"unary",id:this.id_counter++,operator:i.operator,operand:s,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 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:i};s.type==="binary"&&er[a]>er[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:i,operator:a,position:o.position}),t.splice(-2,2,l)}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===jt)return{type:"literal",id:this.id_counter++,position:this.index,value:this.ConsumeString()};if(t>=ge&&t<=Oe||t===this.decimal_mark_char)return this.ConsumeNumber();if(t===Ps)return this.ConsumeArray();if(e&&(t===je||t===Jt)){let r=this.data[this.index+1];if(r>=ge&&r<=Oe||r===this.decimal_mark_char)return this.ConsumeNumber()}else if(t>=Re&&t<=pt||t>=Je&&t<=bt||t===Qt||t===ks||t===Dt||t===mt||t===He||t>=qt&&t<=Kt)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(),s=this.index;if(typeof i=="number")switch(this.index++,i){case dn:r++,t=0;break;case De:t++;break;case Zs:return e;default:this.valid&&(this.error="invalid character in array literal",this.error_position=s,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=s,this.valid=!1);break}}return e}ConsumeOperator(){for(let e of Gs)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,Xt]);r!==null&&t.push(r);let i=this.data[this.index];if(i===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(i===Xt)return this.index++,t}return t}ConsumeToken(e){let t=[e],r=this.index,i=e===Dt,s=0,o=!1;for(e===He&&(s=1,o=!0),++this.index;this.index<this.length;this.index++){let c=this.data[this.index];if(c>=Re&&c<=pt||c>=Je&&c<=bt||c>=qt&&c<=Kt||c===Qt||c===mt||c===Ht||c===Ms||i||c>=ge&&c<=Oe||c===He||s>0&&c===cn||c===je&&this.flags.r1c1&&s===1||s>0&&c===Es&&this.data[this.index-1]===He||s===1&&(c===De||c===on)||s>1||c===Fs&&s===0)t.push(c),c===He&&(s++,o=!0),c===cn&&s--,c===Dt&&(i=!1);else break}let a=t.map(c=>String.fromCharCode(c)).join("");if(i)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]===ln){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=e.length,i=e,s="",o=0;for(;o<r;o++){if(e[o]==="["){e=e.substring(o);break}s+=e[o]}if(e[0]!=="["||e[e.length-1]!=="]")return;e=e.substring(1,e.length-1);let a=e.split(",").map(h=>h.trim()),l="column",d="";if(a.length>2)return;a.length===2?(/\\[#this row\\]/i.test(a[0])?l="row":/\\[#all\\]/i.test(a[0])&&(l="all"),d=a[1]):(d=a[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 c={type:"structured-reference",id:this.id_counter++,label:i,position:t,scope:l,column:d,table:s};return this.full_reference_list.push(c),c}ConsumeAddress(e,t){let r=t,i=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 m={type:"address",id:this.id_counter++,label:e,row:0,column:0,position:r,sheet:s,r1c1:!0};return h[1][0]==="["?(m.offset_row=!0,m.row=Number(h[1].substring(1,h[1].length-1))):m.row=Number(h[1])-1,h[2][0]==="["?(m.offset_column=!0,m.column=Number(h[2].substring(1,h[2].length-1))):m.column=Number(h[2])-1,m}}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 i!==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]===mt;t&&e++;let r=e,i=0;for(;;e++){let s=this.data[e];if(s>=ge&&s<=Oe)i*=10,i+=s-ge;else break}return r===e||i===0?!1:{absolute:t,row:i-1,position:e}}ConsumeAddressColumn(e){let t=-1,r=0,i=this.data[e]===mt;for(i&&e++;;e++,r++){if(r>=4)return!1;let s=this.data[e];if(s>=Re&&s<=pt)t=26*(1+t)+(s-Re);else if(s>=Je&&s<=bt)t=26*(1+t)+(s-Je);else break}return t<0?!1:{absolute:i,column:t,position:e}}ConsumeNumber(){let e=this.index,t=0,r=!1,i=!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 u=this.data[this.index];if(u===this.decimal_mark_char)if(l==="integer")l="fraction";else break;else if(u===Ts){s/=100,a/=100,this.index++;break}else if(u===Jt||u===je)if(d===0)u===je&&(i=!0);else break;else if(u===Rs||u===$s)if(l==="integer"||l==="fraction")l="exponent",this.index<this.length-1&&(this.data[this.index+1]===Jt?this.index++:this.data[this.index+1]===je&&(this.index++,r=!0));else break;else if(u===this.imaginary_char){let f=this.data[this.index+1];if(f>=Re&&f<=pt||f>=Je&&f<=bt||f>=qt&&f<=Kt||f===Qt)break;if(l==="integer"||l==="fraction"){this.index++,c=!0;break}}else if(u>=ge&&u<=Oe)switch(l){case"integer":s=s*10+(u-ge);break;case"fraction":a=a*10+(u-ge),o++;break;case"exponent":t=t*10+(u-ge);break}else break}let m=s+a/Math.pow(10,o);return l==="exponent"&&(m=m*Math.pow(10,(r?-1:1)*t)),c?{type:"complex",id:this.id_counter++,position:e,imaginary:i?-m:m,real:0,text:this.expression.substring(h,this.index)||""}:{type:"literal",id:this.id_counter++,position:e,value:i?-m:m,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===jt&&(this.index++,this.index>=this.length||this.data[this.index]!==jt))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===on||e===Is||e===Ns||e===Ss||e===vs)this.index++;else return}}};var hn=class n{static _instance=new n;constructor(){}static get instance(){return this._instance}HTML(e){let t=[];for(let r of e){let i=[];for(let s of r)s.pre&&i.push("<pre>"),s.emphasis&&i.push("<em>"),s.strong&&i.push("<strong>"),s.strike&&i.push("<strike>"),i.push(s.text),s.strike&&i.push("</strike>"),s.strong&&i.push("</strong>"),s.emphasis&&i.push("</em>"),s.pre&&i.push("</pre>");t.push(i.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 i=t[r];if(i.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);i.left_flanking=!d&&(!c||a),i.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={},i=[],s={type:"text",text:""};for(let o of e)if(o.type==="newline")s.text.length&&i.push(s),s={...r,text:"",type:"text"},t.push(i),i=[];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&&i.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&&i.push(s),i.length&&t.push(i),t}ApplyFormatting(e,t){let r=0,i=e.length;for(r=0;r<i;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,i=0,s=!1,o="";for(i=0;i<r;i++){let a=e[i];if(this.IsWhitespace(a)){o&&t.push({type:"text",text:o});let l=a;for(;;){let d=e[i+1];if(this.IsWhitespace(d))l+=d,i++;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[i+1];if(this.IsNewline(d))l+=d,i++;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[i+1];if(d===a)l+=d,i++;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 un={"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"}}}}},fn={"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"}}}}},Xe={"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 mn={"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}"}}}}},pn={"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 bn={"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 gn={"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"}}},yn={"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 xn={"c:title":{},"c:autoTitleDeleted":{a$:{val:"0"}},"c:plotArea":{"c:layout":{},"c:bubbleChart":{"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"}}},_n={"c:spPr":{"a:solidFill":{"a:schemeClr":{a$:{val:"accent1"},"a:alpha":{a$:{val:"75000"}}}},"a:ln":{"a:noFill":{}},"a:effectLst":{}},"c:xVal":{"c:numRef":{"c:f":""}},"c:yVal":{"c:numRef":{"c:f":""}},"c:bubbleSize":{"c:numRef":{"c:f":""}},"c:bubble3D":{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-03D7-43A5-9DAB-5775FFEF9C03}"}}}}};var We=class n{constructor(e,t=n.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(fn)),i=r["c:tx"]["c:rich"]["a:p"];i["a:r"]={"a:rPr":{a$:{lang:U.locale}},"a:t":t.value},e["c:title"]=r}else if(t){let r=JSON.parse(JSON.stringify(un));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"bubble":return this.CreateBubbleChart();case"donut":return this.CreateDonutChart();default:console.info("unhandled chart type",this.options.type)}return this.CreateBarChart()}CreateBubbleChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(xn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=t["c:chart"]["c:plotArea"]["c:bubbleChart"]["c:ser"],s=!1;for(let o=0;o<this.options.data.length;o++){let a=JSON.parse(JSON.stringify(_n));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: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.labels3&&this.options.labels3[o]&&(a["c:bubbleSize"]["c:numRef"]["c:f"]=this.options.labels3[o]?.label),i.push(a)}return s&&(t["c:chart"]["c:legend"]={"c:legendPos":{a$:{val:"b"}},"c:overlay":{a$:{val:"0"}}}),e}CreateScatterChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(gn));this.options.smooth&&(r["c:plotArea"]["c:scatterChart"]["c:scatterStyle"].a$.val="smoothMarker"),t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=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(yn));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}}),i.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(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(bn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=r["c:plotArea"]["c:doughnutChart"];return i&&(i["c:ser"]["c:cat"]["c:strRef"]["c:f"]=this.options.labels?.label||"",i["c:ser"]["c:val"]["c:numRef"]["c:f"]=this.options.data[0]?.label||""),e}CreateBarChart(){let e=JSON.parse(JSON.stringify(Xe)),t=e["c:chartSpace"],r=JSON.parse(JSON.stringify(pn));t["c:chart"]=r,this.UpdateChartTitle(t["c:chart"]);let i=r["c:plotArea"]["c:barChart"];if(i){let s=i["c:barDir"];s&&(s.a$.val=this.options.type==="bar"?"bar":"col");let o=i["c:ser"];for(let a=0;a<this.options.data.length;a++){let l=JSON.parse(JSON.stringify(mn));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 gt=class n{constructor(e,t=n.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 wn=9525,Qe=class n{constructor(e=n.next_drawing_index++){this.index=e}static next_drawing_index=1;sheet_drawing_relationship=0;charts=[];images=[];relationships={};AddImage(e,t){let r=new gt(e);if(r.extension){let i=he(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",`../media/image${r.index}.${r.extension}`);this.images.push({image:r,relationship:i,anchor:t})}}AddChart(e,t){let r=new We(e),i=he(this.relationships,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",`../charts/chart${r.index}.xml`);this.charts.push({chart:r,anchor:t,relationship:i})}CornerToJSON(e){return{"xdr:col":e.column,"xdr:colOff":(e.column_offset||0)*wn,"xdr:row":e.row,"xdr:rowOff":(e.row_offset||0)*wn}}AnchorToJSON(e){return{"xdr:from":{...this.CornerToJSON(e.from)},"xdr:to":{...this.CornerToJSON(e.to)}}}toJSON(){let e=this.images.map(i=>({a$:{editAs:"oneCell"},...this.AnchorToJSON(i.anchor),"xdr:pic":{"xdr:nvPicPr":{"xdr:cNvPr":{a$:{id:i.image.index+1,name:"Image "+i.image.index}},"xdr:cNvPicPr":{"a:picLocks":{a$:{noChangeAspect:1}}}},"xdr:blipFill":{"a:blip":{a$:i.image.extension==="svg"?{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships"}:{"xmlns:r":"http://schemas.openxmlformats.org/officeDocument/2006/relationships","r:embed":i.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}}},i.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":i.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(i=>({...this.AnchorToJSON(i.anchor),"xdr:graphicFrame":{a$:{macro:""},"xdr:nvGraphicFramePr":{"xdr:cNvPr":{a$:{id:i.chart.index+1,name:`Chart ${i.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":i.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 rr=ve(lt());var Ge=n=>"row"in n&&"col"in n,Ae=n=>"from"in n&&"to"in n&&Ge(n.from)&&Ge(n.to),yt=(n,e)=>e.sheet===n.sheet&&e.row>=n.from.row&&e.row<=n.to.row&&e.col>=n.from.col&&e.col<=n.to.col,tr=(n,e=0,t=0)=>({from:{row:n.from.row+e,col:n.from.col+t,sheet:n.from.sheet},to:{row:n.to.row+e,col:n.to.col+t,sheet:n.to.sheet}});var xt=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,i=0;if(t=e.match(/^([A-Z]+)(\\d+)$/),t){r=Number(t[2]),i=0;let s=t[1].length;for(let o=0;o<s;o++){let a=t[1].charCodeAt(o)-64;i=i*26+a}}return{row:r,col:i}}Address(e,t=!1){if(Ae(e))return this.Address(e.from,t)+":"+this.Address(e.to,t);let r="",i=e.col;for(;i>0;){let o=(i-1)%26+1;r=String.fromCharCode(64+o)+r,i=(i-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||"");Ae(t)?this.extent=JSON.parse(JSON.stringify(t)):this.extent={from:JSON.parse(JSON.stringify(t)),to:JSON.parse(JSON.stringify(t))}}};var Us=new rr.XMLParser(jr),Ce=new rr.XMLParser(dt),wt={greaterThan:">",greaterThanOrEquals:">=",lessThan:"<",lessThanOrEquals:"<=",equal:"=",notEqual:"<>"};var _t=class{constructor(e){this.zip=e}xml={};shared_strings=new Me;style_cache=new Ee;theme=new we;named=[];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):"",i=Ce.parse(r||"");for(let s of i.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=Ce.parse(e||"");this.shared_strings.FromXML(t),e=this.zip.Get("xl/theme/theme1.xml"),t=Ce.parse(e),this.theme.FromXML(t),e=this.zip.Get("xl/styles.xml"),t=Ce.parse(e),this.style_cache.FromXML(t,this.theme),e=this.zip.Get("xl/workbook.xml"),t=Ce.parse(e),this.named=[];let r=M.FindAll(t,"workbook/definedNames/definedName");for(let o of r){let a=o.a$?.name,l=o.t$||"",d=o.a$?.localSheetId?Number(o.a$.localSheetId):void 0;this.named.push({name:a,expression:typeof l=="string"?l:l?.toString()||"",local_scope:d})}let i=M.FindAll(t,"workbook/bookViews/workbookView");i[0]?.a$?.activeTab&&(this.active_tab=Number(i[0].a$.activeTab)||0);let s=M.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 xt({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=Ce.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=Ce.parse(t),i=r.table?.a$?.name||"";return{name:i,display_name:r.table?.a$?.displayName||i,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=Ce.parse(t),i=this.ReadRels(e.replace(/^..\\/drawings/,"xl/drawings/_rels")+".rels"),s=[],o=M.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=M.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},m=i[c.a$["r:id"]];m&&m.target&&(h.chart=this.ReadChart(m.target)),s.push(h)}else{let h=M.FindAll(l,"xdr:pic/xdr:blipFill/a:blip")[0];if(h&&h.a$["r:embed"]){let m=i[h.a$["r:embed"]];if(m&&m.target&&/(?:jpg|jpeg|png|gif)$/i.test(m.target)){let u=m.target.replace(/^\\.\\./,"xl"),f=u.replace(/^.*\\//,""),g={type:"image",anchor:d,image:this.zip.GetBinary(u),filename:f};s.push(g)}}else{let m,u=M.FindAll(l,"xdr:sp/xdr:spPr")[0];if(u){m={};let g=u["a:solidFill"];if(g&&g["a:schemeClr"]?.a$?.val){let w=g["a:schemeClr"].a$.val.match(/accent(\\d+)/);if(w&&(m.fill={theme:Number(w[1])+3},g["a:schemeClr"]["a:lumOff"]?.a$?.val)){let A=Number(g["a:schemeClr"]["a:lumOff"].a$.val);isNaN(A)||(m.fill.tint=A/1e5)}}}let f=M.FindAll(l,"xdr:sp/xdr:txBody")[0];if(f){let g=[],w=M.FindAll(f,"a:p");for(let A of w){let _=[],b,N=A["a:pPr"];N&&(b={},N.a$?.algn==="r"?b.horizontal_align="right":N.a$?.algn==="ctr"&&(b.horizontal_align="center"));let $=A["a:r"];if($){Array.isArray($)||($=[$]);for(let Y of $){let W={text:Y["a:t"]||""},k=Y["a:rPr"];k&&(W.style={},k.a$?.b==="1"&&(W.style.bold=!0),k.a$?.i==="1"&&(W.style.italic=!0)),_.push(W)}}g.push({content:_,style:b})}s.push({type:"textbox",style:m,paragraphs:g,anchor:d})}}}}return s}ReadChart(e){let t=this.zip.Get(e.replace(/^../,"xl"));if(!t)return;let r=Us.parse(t),i={type:0},s=M.FindChild(r,"c:chartSpace/c:chart/c:title");if(s){let l=M.FindChild(s,"c:tx/c:strRef/c:f");if(l)typeof l=="string"?i.title=l:l.text__&&(i.title=l.text__);else{let d=M.FindAll(s,"c:tx/c:rich/a:p/a:r/a:t");i.title=\'"\'+d.join("")+\'"\'}}let o=(l,d)=>{let c=[],h=l["c:ser"]||[];Array.isArray(h)||(h=[h]);for(let m of h){let u=c.length,f=m["c:order"];f&&(u=Number(f.__val||0)||0);let g={},w=M.FindChild(m,"c:tx/c:v");if(w){let A=w;A&&(g.title=`"${A}"`)}else w=M.FindChild(m,"c:tx/c:strRef/c:f"),w&&(g.title=w);if(d===4||d===7){let A=M.FindChild(m,"c:xVal/c:numRef/c:f");A&&(g.categories=A);let _=M.FindChild(m,"c:yVal/c:numRef/c:f");if(_&&(g.values=_),d===7){let b=M.FindChild(m,"c:bubbleSize/c:numRef/c:f");b&&(g.bubble_size=b)}}else{let A=M.FindChild(m,"c:val/c:numRef/c:f");A&&(g.values=A);let _=M.FindChild(m,"c:cat/c:strRef/c:f");_||(_=M.FindChild(m,"c:cat/c:numRef/c:f")),_&&(g.categories=_)}c[u]=g}return c},a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:barChart");return a&&(i.type=2,a["c:barDir"]&&a["c:barDir"].__val==="col"&&(i.type=1),i.series=o(a)),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:lineChart"),a&&(i.type=3,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:doughnutChart"),a&&(i.type=5,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:pieChart"),a&&(i.type=6,i.series=o(a))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:scatterChart"),a&&(i.type=4,i.series=o(a,4))),a||(a=M.FindChild(r,"c:chartSpace/c:chart/c:plotArea/c:bubbleChart"),a&&(i.type=7,i.series=o(a,7),console.info("Bubble series?",i.series))),a||console.info("Chart type not handled"),i}GetNamedRanges(){return this.named}};var ir=ve(An()),Cn=ve(nt()),ze=class{records;text=new Map;constructor(e){this.records=ir.default.parse(e)}Has(e){return this.text.has(e)||!!this.records?.[e]}ArrayBuffer(){let e={};if(this.records)for(let[r,i]of Object.entries(this.records))e[r]=new Uint8Array(i);let t=new TextEncoder;for(let[r,i]of this.text.entries())e[r]=t.encode(i);return ir.default.encode(e)}SetBinary(e,t,r){if(r==="base64"){let i=Cn.default.toByteArray(t);this.records[e]=i}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 ye=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n`,sr=n=>{if(Te(n))return{a$:{rgb:"FF"+n.text.substring(1)}};if(Pe(n))return{a$:{theme:Se(n),tint:n.tint}}},At=class{zip;xmloptions={format:!0,attributesGroupName:"a$",textNodeName:"t$",ignoreAttributes:!1,suppressEmptyNode:!0};xmlbuilder1=Or(this.xmloptions);xmlparser2=new In.XMLParser(dt);parser=new $e;decorated_functions={};Init(e={}){for(let r of Object.keys(e))this.decorated_functions[r.toLowerCase()]=e[r];let t=vn.toByteArray(dr);this.zip=new ze(t)}WriteRels(e,t,r=!1){if(!this.zip)throw new Error("missing zip");let i=Object.keys(e),s={Relationships:{a$:{xmlns:"http://schemas.openxmlformats.org/package/2006/relationships"},Relationship:i.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=ye+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=u=>{let f={};return u.indexed!==void 0&&(f.indexed=u.indexed),u.theme!==void 0&&(f.theme=u.theme),u.tint!==void 0&&(f.tint=u.tint),u.argb!==void 0&&(f.rgb=u.argb),f},r=e.cell_xfs.map(u=>{let f={a$:{numFmtId:u.number_format,fontId:u.font,fillId:u.fill,borderId:u.border}};if(u.horizontal_alignment||u.vertical_alignment||u.wrap_text||u.indent){let g={};u.horizontal_alignment&&(g.horizontal=u.horizontal_alignment),u.vertical_alignment&&(g.vertical=u.vertical_alignment),u.wrap_text&&(g.wrapText=1),u.indent&&u.horizontal_alignment!=="center"&&(g.indent=u.indent),f.alignment={a$:g}}return f}),i=u=>{if(u.color)return{indexed:u.color};if(u.rgba)return{rgb:u.rgba};if(typeof u.theme<"u")return{theme:u.theme,tint:u.tint}},s=e.borders.map(u=>{let f={},g={},w={},A={},_={};if(u.top.style){f.a$={style:u.top.style};let b=i(u.top);b&&(f.color={a$:b})}if(u.left.style){g.a$={style:u.left.style};let b=i(u.left);b&&(g.color={a$:b})}if(u.bottom.style){A.a$={style:u.bottom.style};let b=i(u.bottom);b&&(A.color={a$:b})}if(u.right.style){w.a$={style:u.right.style};let b=i(u.right);b&&(w.color={a$:b})}if(u.diagonal.style){_.a$={style:u.diagonal.style};let b=i(u.diagonal);b&&(_.color={a$:b})}return{left:g,right:w,top:f,bottom:A,diagonal:_}}),o=e.fills.map(u=>({patternFill:{a$:{patternType:u.pattern_gray!==void 0?`gray${u.pattern_gray}`:u.pattern_type},bgColor:u.bg_color?{a$:t(u.bg_color)}:void 0,fgColor:u.fg_color?{a$:t(u.fg_color)}:void 0}})),a=u=>{if(!(typeof u>"u"))return{a$:{val:u}}},l=e.fonts.map(u=>({b:u.bold?"":void 0,i:u.italic?"":void 0,u:u.underline?"":void 0,strike:u.strike?"":void 0,sz:a(u.size),family:a(u.family),name:a(u.name),scheme:a(u.scheme),color:u.color_argb?{a$:{rgb:u.color_argb}}:typeof u.color_theme<"u"?{a$:{theme:u.color_theme,tint:u.color_tint}}:void 0})),d=(u,f)=>{if(f.length)return{a$:{count:f.length},[u]:f}},c=e.dxf_styles.map(u=>{let f={fill:u.fill?{patternFill:{bgColor:sr(u.fill)}}:void 0};return(u.text||u.bold||u.italic||u.underline)&&(f.font={b:u.bold?{}:void 0,i:u.italic?{}:void 0,u:u.underline?{}:void 0,strike:u.strike?{}:void 0,color:sr(u.text)}),f}),h={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"},numFmts:e.number_formats.length?{a$:{count:e.number_formats.length},numFmt:e.number_formats.map(u=>({a$:{numFmtId:u.id,formatCode:u.format}}))}:void 0,fonts:d("font",l),fills:d("fill",o),borders:d("border",s),cellXfs:d("xf",r),dxfs:d("dxf",c)}},m=ye+this.xmlbuilder1.build(h);this.zip?.Set("xl/styles.xml",m)}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(i=>({t:i}))]}},r=ye+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 i=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.row_style){let a=e.row_style[r];typeof a=="number"&&(a=i[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(Fe.Composite(s));return t.EnsureStyle(o)}ColumnStyle(e,t,r){let i=e.styles||e.cell_style_refs||[],s=[e.sheet_style];if(e.column_style){let a=e.column_style[r];typeof a=="number"&&(a=i[a]),a&&s.push(a)}let o=t.StyleOptionsFromProperties(Fe.Composite(s));return t.EnsureStyle(o)}StyleFromCell(e,t,r,i,s={}){let o=e.styles||e.cell_style_refs||[],a=[e.sheet_style];if(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[i];typeof d=="number"&&(d=o[d]),d&&a.push(d)}a.push(s);let l=t.StyleOptionsFromProperties(Fe.Composite(a));return t.EnsureStyle(l)}NormalizeAddress(e,t){let r=e.type==="address"?[e]:[e.start,e.end];for(let i of r)i.absolute_row=!0,i.absolute_column=!0,i.sheet||(i.sheet=t.name);return e.type==="range"&&(e.end.sheet=void 0),e.label=this.parser.Render(e),e}EnsureRange(e){return e.type==="range"?e:{type:"range",start:e,end:e,label:e.label,id:e.id,position:e.position}}AnnotationLayoutToAnchor(e,t){let r=i=>{let s=t.column_width&&t.column_width[i.address.column]?t.column_width[i.address.column]:t.default_column_width||100,o=t.row_height&&t.row_height[i.address.row]?t.row_height[i.address.row]:t.default_row_height||20;return{...i.address,row_offset:Math.round(i.offset.y*o),column_offset:Math.round(i.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}},i={top:0,left:0,width:301,height:301,...e},s={...i,right:i.left+i.width,bottom:i.top+i.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 i=r.data.src,s=i.match(/^data:image\\/([^;]*?);base64,/);if(s){let o=i.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=(i,s,o)=>{if(i.type==="range")s.data.push(this.NormalizeAddress(i,e));else if(i.type==="call"){if(/group/i.test(i.name))for(let a of i.args||[])r(a,s,o?o+" (recurse)":void 0);else if(/series/i.test(i.name)){let[a,l,d,c]=i.args;d&&(d.type==="range"||d.type==="address")?(s.data.push(this.EnsureRange(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"||l.type==="address")&&(s.labels2[s.data.length-1]=this.EnsureRange(this.NormalizeAddress(l,e))),c&&(c.type==="range"||c.type==="address")&&(s.labels3||(s.labels3=[]),s.labels3[s.data.length-1]=this.EnsureRange(this.NormalizeAddress(c,e)))):console.info("invalid series missing Y",{y:d,arg:i,ref:o})}}};for(let i of e.annotations||[]){let s=this.parser.Parse(i.formula||"");if(s.expression&&s.expression.type==="call"){let o="";switch(s.expression.name.toLowerCase()){case"line.chart":o="scatter";break;case"bubble.chart":o="bubble";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"||o==="bubble"){let a={type:o,data:[]},l=o==="scatter2"||o==="bubble"?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"||o==="bubble")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 m of h.args)m.type==="range"?a.data.push(this.NormalizeAddress(m,e)):m.type==="call"&&/series/i.test(m.name)&&m.args[2]&&m.args[2].type==="range"&&a.data.push(this.NormalizeAddress(m.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"&&o!=="bubble"&&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=i.rect;i.layout?t.push({anchor:this.AnnotationLayoutToAnchor(i.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 i=t.table?.name||"";return this.parser.Render(r.expression,{missing:"",long_structured_references:!0,table_name:i})}else return console.warn("parsing function failed"),console.warn(e),e.substring(1)}Export(e){let t=0,r=[];for(let _=0;_<e.sheet_data.length;_++){let b=e.sheet_data[_],N=b.id||0;N&&(r[N]=b.name||""),N===e.active_sheet&&(t=_)}let i=new Me,s=new Ee,o=new we,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),Qe.next_drawing_index=1,We.next_chart_index=1;let l=[],d=[];for(let _=0;_<e.sheet_data.length;_++){let b=e.sheet_data[_],N={},$={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=b.default_row_height?b.default_row_height/20*15:15,W=b.styles||b.cell_style_refs||[],k=new at;k.FromJSON(b.data,W);for(let x of b.cell_styles){let E=k.EnsureCell(x);E.style||(E.style=W[x.ref])}let q={start:{row:k.rows+1,column:k.columns+1},end:{row:k.rows+1,column:k.columns+1}},X=[],B=[],K=[],D=[],O=[],ee=[],G=this.SheetStyle(b,s);for(let x=0;x<k.data.length;x++){let E=this.RowStyle(b,s,x);if(k.data[x]&&k.data[x].length){x<q.start.row&&(q.start.row=x);let R={start:-1,end:-1},F=[];for(let T=0;T<k.data[x].length;T++){ee[T]||(ee[T]=this.ColumnStyle(b,s,T));let P=k.data[x][T];if(P){if(P.table&&P.table.area.start.row===x&&P.table.area.start.column===T){let ae=new j(P.table.area.start,P.table.area.end),Ke=d.length+1,Sn=`../tables/table${Ke}.xml`,It=[];for(let le=0;le<ae.columns;le++){let Q=k.data[x][T+le],xe="";Q.type!==2?(typeof Q.calculated<"u"?xe=Q.calculated.toString():typeof Q.value<"u"&&(xe=Q.value.toString()),Q.type=2,Q.value=xe):xe=Q.value||"",xe||(xe=`Column${le+1}`);let tt=xe,St=!1,Tn=1;for(;!St;){St=!0;e:for(let Pn of It)if(Pn.toLowerCase()===tt.toLowerCase()){St=!1,tt=`${xe}${++Tn}`;break e}}Q.value=tt,It.push(tt)}let et;if(P.table.totals_row){et=[];for(let le=0;le<ae.columns;le++){let Q=k.data[ae.end.row][ae.start.column+le];Q.type&&(Q.type===1?et[le]={type:"formula",value:(Q.value||"").toString().substring(1)}:(Q.type!==2&&(Q.type=2,Q.value=Q.value?.toString()||""),et[le]={type:"label",value:Q.value}))}}let Nt={rel:he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",Sn),index:Ke,ref:ae.spreadsheet_label,name:`Table${Ke}`,display_name:`Table${Ke}`,totals_row_shown:0,totals_row_count:P.table?.totals_row?1:0,columns:It,footers:et};if(P.table.totals_row){let le=new j(ae.start,{row:ae.end.row-1,column:ae.end.column});Nt.filterRef=le.spreadsheet_label}O.push(Nt),d.push(Nt)}if(P.merge_area&&P.merge_area.start.row===x&&P.merge_area.start.column===T&&D.push(new j(P.merge_area.start,P.merge_area.end)),P.hyperlink){let ae=he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",P.hyperlink,"External");B.push({rel:ae,target:P.hyperlink,address:{row:x,column:T}})}if(P.type===1&&/^=?sparkline\\./i.test(P.value)){K.push({address:{row:x,column:T},formula:P.value,style:P.style});continue}T<q.start.column&&(q.start.column=T),R.start<0&&(R.start=T),R.end=T;let J=this.StyleFromCell(b,s,x,T,P.style);if(P.type===0&&(E&&J===E||!E&&ee[T]&&J===ee[T]))continue;let V,de,fe;switch(P.type){case 1:switch(fe=this.FormulaText(P.value,P),P.calculated_type){case 2:V=P.calculated,de="str";break;case 3:V=P.calculated;break;case 4:V=P.calculated?1:0,de="b";break}break;case 2:V=i.Ensure(P.value),de="s";break;case 3:V=P.value;break;case 4:V=P.value?1:0,de="b";break}P.area&&P.area.start.row===x&&P.area.start.column===T&&typeof fe=="string"&&(fe={t$:fe,a$:{t:"array",ref:P.area.spreadsheet_label}}),F.push({a$:{r:j.CellAddressToLabel({row:x,column:T}),t:de,s:J},f:fe,v:V})}}if(F.length||E&&E!==G){let T,P,J,V;b.row_height&&typeof b.row_height[x]=="number"&&b.row_height[x]!==b.default_row_height&&(T=1,P=b.row_height[x]*3/4),E&&E!==G&&(J=E,V=1),X.push({a$:{r:x+1,spans:`${R.start+1}:${R.end+1}`,customHeight:T,ht:P,s:J,customFormat:V},c:F})}}}let se=[];for(let x=0;x<b.columns;x++){let E={index:x};b.column_width&&b.default_column_width&&typeof b.column_width[x]=="number"&&b.column_width[x]!==b.default_column_width&&(E.width=it(b.column_width[x]));let R=ee[x];R&&R!==G&&(E.style=R),(E.style!==void 0||E.width!==void 0)&&(se[x]=E)}let te;if(se.length||G){let x=[],E=it(b.default_column_width||90);{let R=0;for(let F of se)F&&(G&&F.index>R+1&&x.push({a$:{min:R+1,max:F.index,style:G,width:E}}),x.push({a$:{min:F.index+1,max:F.index+1,style:F.style===void 0?G:F.style,width:F.width===void 0?E:F.width,customWidth:F.width===void 0?void 0:1}}),R=F.index);G&&R<16384&&x.push({a$:{min:R+1,max:16384,style:G,width:E}}),te={col:x}}}let y;b.data_validations?.length&&(y={a$:{count:b.data_validations.length},dataValidation:b.data_validations.map(x=>{let E=x.target.map(F=>new j(F.start,F.end).spreadsheet_label).join(" "),R;if(x.type==="range"){let F={id:0,type:"range",label:"",position:0,start:{...x.area.start,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"},end:{...x.area.end,absolute_column:!0,absolute_row:!0,id:0,label:"",position:0,type:"address"}};typeof x.area.start.sheet_id<"u"&&(F.start.sheet=r[x.area.start.sheet_id]),R=this.parser.Render(F)}else x.type==="list"&&(R=`"${x.list.join(",")}"`);return{a$:{type:"list",allowBlank:1,showInputMessage:1,showErrorMessage:1,sqref:E},formula1:R}})});let Z;O.length&&(Z={a$:{count:O.length},tablePart:O.map(x=>({a$:{"r:id":x.rel||""}}))});for(let x of O){let E={};x.totals_row_count&&(E.totalsRowCount=1);let R={a$:{count:(x.columns||[]).length},tableColumn:(x.columns||[]).map((P,J)=>{let V=(x.footers||[])[J];return{a$:{id:J+1,name:P||`Column${J+1}`,totalsRowLabel:V?.type==="label"?V.value:void 0,totalsRowFunction:V?.type==="formula"?"custom":void 0},totalsRowFormula:V?.type==="formula"?V.value:void 0}})},F={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:x.index||0,name:x.name,displayName:x.display_name,...E,ref:x.ref},autoFilter:{a$:{ref:x.filterRef||x.ref}},tableColumns:R,tableStyleInfo:{a$:{name:"TableStyleMedium2",showFirstColumn:0,showLastColumn:0,showRowStripes:1,showColumnStripes:0}}}},T=ye+this.xmlbuilder1.build(F);this.zip?.Set(`xl/tables/table${x.index}.xml`,T)}let S;if(b.conditional_formats?.length){let x=[],E=1,R={},F=Object.entries(wt).map(T=>(R[T[1]]=T[0],T[1]));F.sort((T,P)=>P.length-T.length);for(let T of b.conditional_formats){let P=0;switch(T.type!=="gradient"&&(P=s.dxf_styles.length,s.dxf_styles.push(T.style)),T.type){case"cell-match":{let J="",V="";for(let de of F)if(new RegExp("^"+de+"\\\\s").test(T.expression)){J=R[de],V=T.expression.substring(de.length).trim();break}J&&x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"cellIs",dxfId:P,operator:J,priority:E++},formula:V}})}break;case"expression":x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"expression",dxfId:P,priority:E++},formula:T.expression}});break;case"duplicate-values":x.push({a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:T.unique?"uniqueValues":"duplicateValues",dxfId:P,priority:E++}}});break;case"gradient":{let J=[],V=[];for(let fe of T.stops){fe.value===0?J.push({a$:{type:"min"}}):fe.value===1?J.push({a$:{type:"max"}}):J.push({a$:{type:"percentile",val:fe.value*100}});let ae=sr(fe.color);ae&&V.push(ae)}let de={a$:{sqref:new j(T.area.start,T.area.end).spreadsheet_label},cfRule:{a$:{type:"colorScale",priority:E++},colorScale:{cfvo:J,color:V}}};x.push(de)}break}}x.length&&(S=x.length>1?x:x[0])}let C;D.length&&(C={a$:{count:D.length},mergeCell:D.map(x=>({a$:{ref:x.spreadsheet_label}}))});let I;B.length&&(I={hyperlink:B.map(x=>({a$:{"r:id":x.rel,ref:new j(x.address).spreadsheet_label,"xr:uid":"{0C6B7792-7EA0-4932-BF15-D49C453C565D}"}}))});let v;if(K.length){let x={a$:{"xmlns:xm":"http://schemas.microsoft.com/office/excel/2006/main"},"x14:sparklineGroup":K.map(E=>{let R=this.parser.Parse(E.formula),F="";if(R.expression&&R.expression.type==="call"&&R.expression.args.length>0){let T=R.expression.args[0];if(T.type==="range"||T.type==="address"){let P=T.type==="range"?T.start:T;P.sheet||(typeof P.sheet_id<"u"?P.sheet=r[P.sheet_id]:P.sheet=b.name),F=this.parser.Render(T)}}return{a$:{displayEmptyCellsAs:"gap",type:/column/i.test(E.formula)?"column":void 0},"x14:colorSeries":{a$:{rgb:"FF376092"}},"x14:sparklines":{"x14:sparkline":{"xm:f":F,"xm:sqref":new j(E.address).spreadsheet_label}}}})};v={ext:{a$:{uri:"{05C60535-1F16-4fd2-B633-F4F36F0B64E0}","xmlns:x14":"http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"},"x14:sparklineGroups":x}}}let L,z=this.ParseCharts(b),oe=this.ParseImages(b);if(z.length||oe.length){let x=new Qe;for(let F of z)x.AddChart(F.options,F.anchor);for(let F of oe)x.AddImage(F.options,F.anchor);for(let{image:F}of x.images)F.options.data&&this.zip?.SetBinary(`xl/media/image${F.index}.${F.extension}`,F.options.data,F.options.encoding);for(let{chart:F}of x.charts){let T=F.toJSON(),P=ye+this.xmlbuilder1.build(T);this.zip?.Set(`xl/charts/chart${F.index}.xml`,P),this.WriteRels(F.relationships,`xl/charts/_rels/chart${F.index}.xml.rels`)}this.WriteRels(x.relationships,`xl/drawings/_rels/drawing${x.index}.xml.rels`);let E=ye+this.xmlbuilder1.build(x.toJSON());this.zip?.Set(`xl/drawings/drawing${x.index}.xml`,E),l.push(x),L={a$:{"r:id":he(N,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",`../drawings/drawing${x.index}.xml`)}}}let ue={a$:{"x14ac:dyDescent":.25,defaultRowHeight:Y===15?void 0:Y,customHeight:Y===15?void 0:1,defaultColWidth:b.default_column_width?it(b.default_column_width):void 0}},Be={worksheet:{a$:{...$},dimension:{a$:{ref:new j(q.start,q.end).spreadsheet_label}},sheetViews:{sheetView:{a$:{workbookViewId:0}}},sheetFormatPr:ue,cols:te,sheetData:{row:X},mergeCells:C,conditionalFormatting:S,dataValidations:y,hyperlinks:I,pageMargins:{a$:{left:.7,right:.7,top:.75,bottom:.75,header:.3,footer:.3}},drawing:L,tableParts:Z,extLst:v}},qe=ye+this.xmlbuilder1.build(Be);this.zip?.Set(`xl/worksheets/sheet${_+1}.xml`,qe),Object.keys(N).length&&this.WriteRels(N,`xl/worksheets/_rels/sheet${_+1}.xml.rels`)}this.WriteSharedStrings(i),this.WriteStyleCache(s);let c={};he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles","styles.xml"),he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme","theme/theme1.xml"),he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings","sharedStrings.xml");let h=e.sheet_data.map((_,b)=>he(c,"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",`worksheets/sheet${b+1}.xml`));this.WriteRels(c,"xl/_rels/workbook.xml.rels");let m=e.named?.length?{definedName:(e.named||[]).map(_=>{let b;if(_.scope){let N=_.scope.toLowerCase();for(let[$,Y]of e.sheet_data.entries())if(Y.name?.toLowerCase()===N){b=$.toString();break}}return{a$:{name:_.name,localSheetId:b},t$:_.expression}})}:void 0,u={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((_,b)=>({a$:{name:_.name||`Sheet${b+1}`,sheetId:b+1,"r:id":h[b],state:_.visible===!1?"hidden":void 0}}))},definedNames:m}},f=ye+this.xmlbuilder1.build(u);this.zip?.Set("xl/workbook.xml",f);let g={};for(let _ of l)for(let b of _.images)switch(b.image.extension){case"gif":case"png":case"jpeg":g[b.image.extension]="image/"+b.image.extension;break;case"svg":g.svg="image/svg+xml";break}let w={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(_=>({a$:{Extension:_,ContentType:g[_]}}))],Override:[{a$:{PartName:"/xl/workbook.xml",ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"}},...e.sheet_data.map((_,b)=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",PartName:`/xl/worksheets/sheet${b+1}.xml`}})),...l.reduce((_,b)=>_.concat([...b.charts.map(N=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",PartName:`/xl/charts/chart${N.chart.index}.xml`}})),{a$:{ContentType:"application/vnd.openxmlformats-officedocument.drawing+xml",PartName:`/xl/drawings/drawing${b.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(_=>({a$:{ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",PartName:`/xl/tables/table${_.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"}}]}},A=ye+this.xmlbuilder1.build(w);this.zip?.Set("[Content_Types].xml",A)}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 Nn=ve(nt());var Ct=class{parser=new $e;workbook;zip;Init(e){this.zip=new ze(e),this.workbook=new _t(this.zip),this.workbook.Init()}SheetCount(){return this.workbook?.sheet_count||0}ParseCell(e,t,r,i,s,o){let a=t.a$?.r;if(!a){console.warn("cell missing address");return}let l=e.TranslateAddress(a);if(Ae(l)){console.warn("cell has range address");return}let d,c="undefined",h,m="undefined";if(t.a$?.t&&t.a$.t==="s"){if(c="string",typeof t.v<"u"){let g=Number(t.v);!isNaN(g)&&e.shared_strings&&(d=e.shared_strings.Get(g)||"",d[0]==="="&&(d="\'"+d))}}else if(typeof t.f<"u"){c="formula";let g=(typeof t.f=="string"?t.f:t.f.t$)||"";if(g){d="="+g.replace(/^_xll\\./g,"");let w=this.parser.Parse(g);w.expression&&(this.parser.Walk(w.expression,A=>(A.type==="call"&&(/^_xll\\./.test(A.name)?A.name=A.name.substring(5):/^_xlfn\\./.test(A.name)&&(A.name=A.name.substring(6))),!0)),d="="+this.parser.Render(w.expression,{missing:""})),typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si&&(r[t.f.a$.si]={row:l.row-1,column:l.col-1,formula:d,parse_result:this.parser.Parse(d)})}else if(typeof t.f!="string"&&t.f.a$?.t==="shared"&&t.f.a$.si){let w=r[t.f.a$.si];w&&(w.parse_result.expression?d="="+this.parser.Render(w.parse_result.expression,{offset:{rows:l.row-1-w.row,columns:l.col-1-w.column},missing:""}):d=w.formula)}if(typeof t.f!="string"&&t.f.a$?.t==="array"){let w=e.TranslateAddress(t.f.a$.ref||"");Ae(w)&&i.push(tr(w,-1,-1))}if(typeof t.v<"u"){let w=typeof t.v=="object"?t.v?.t$:t.v,A=Number(w.toString());isNaN(A)?(m="string",h=w.toString()):(m="number",h=A)}}else if(typeof t.v<"u"){let g=Number(t.v.toString());isNaN(g)?(c="string",d=t.v.toString()):(c="number",d=g)}let u={row:l.row-1,col:l.col-1};for(let g of i)yt(g,u)&&(u.row!==g.from.row||u.col!==g.from.col)&&(m=c,h=d,d=void 0,c="undefined");let f={row:u.row,column:u.col,value:d,type:c};typeof h<"u"&&(f.calculated_type=m,f.calculated=h),t.a$?.s&&(f.style_ref=Number(t.a$.s));for(let g of o)g.address.row===l.row&&g.address.col===l.col&&(f.hyperlink=g.reference);for(let g of s)yt(g,u)&&(f.merge_area={start:{row:g.from.row,column:g.from.col},end:{row:g.to.row,column:g.to.col}});for(let g of i)yt(g,u)&&(f.area={start:{row:g.from.row,column:g.from.col},end:{row:g.to.row,column:g.to.col}});return f}AddressToArea(e){return Ge(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),i=wt;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 s={};if(t.a$.dxfId){let a=Number(t.a$.dxfId);isNaN(a)||(s=this.workbook?.style_cache.dxf_styles[a]||{})}let o=i[t.a$.operator||""];if(!o)console.info("unhandled cellIs operator:",t.a$.operator);else return{type:"cell-match",expression:o+" "+t.formula,area:r,style:s}}break;case"containsErrors":case"notContainsErrors":case"expression":if(t.formula){typeof t.formula!="string"&&(t.formula.t$?t.formula=t.formula.t$:console.info("unexpected conditional expression",{rule:t}));let s={};if(t.a$.dxfId){let o=Number(t.a$.dxfId);isNaN(o)||(s=this.workbook?.style_cache.dxf_styles[o]||{})}return{type:"expression",expression:t.formula,area:r,style:s}}break;case"colorScale":if(t.colorScale&&Array.isArray(t.colorScale.cfvo)&&Array.isArray(t.colorScale.color)){let s=[];for(let[o,a]of t.colorScale.cfvo.entries()){let l=0,d={},c=t.colorScale.color[o];switch(c.a$.rgb?d.text="#"+c.a$.rgb.substring(2):c.a$.theme&&(d.theme=Number(c.a$.theme)||0,c.a$.tint&&(d.tint=Math.round(c.a$.tint*1e3)/1e3)),a.a$.type){case"min":l=0;break;case"max":l=1;break;case"percentile":l=(Number(a.a$.val)||0)/100;break}s.push({color:d,value:l})}return{type:"gradient",stops:s,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=[],i={},s=[],o=[],a=[],l=[],d=[],c=[],h=[],m=M.FindAll.bind(M,t.sheet_data),u=m("worksheet/conditionalFormatting");for(let y of u)if(y.a$?.sqref){let Z=y.a$.sqref.split(/\\s+/);for(let S of Z){let C=t.TranslateAddress(S);if(y.cfRule){let I=Array.isArray(y.cfRule)?y.cfRule:[y.cfRule];for(let v of I){let L=this.ParseConditionalFormat(C,v);L&&a.push(L)}}}}let f=m("worksheet/mergeCells/mergeCell");for(let y of f)if(y.a$.ref){let Z=t.TranslateAddress(y.a$.ref);Ae(Z)&&o.push(tr(Z,-1,-1))}let g=m("worksheet/dataValidations/dataValidation");for(let y of g){let Z=y.a$?.type,S=y.a$?.sqref,C=y.formula1;if(S&&C&&Z==="list"){let I,v=this.parser.Parse(S),L=[];v.expression&&(v.expression.type==="address"?L.push({start:v.expression,end:v.expression}):v.expression.type==="range"&&L.push(v.expression)),v=this.parser.Parse(C),v.expression&&(v.expression.type==="range"?I={type:"range",area:v.expression,target:L}:v.expression.type==="literal"&&(I={type:"list",target:L,list:v.expression.value.toString().split(/,/).map(z=>{let oe=Number(z);return isNaN(oe)?z.toLowerCase()==="true"?!0:z.toLowerCase()==="false"?!1:z:oe})})),L.length&&I&&c.push(I)}}let w=m("worksheet/hyperlinks/hyperlink");for(let y of w){let Z=t.TranslateAddress(y.a$?.ref||"");Ae(Z)&&(Z=Z.from);let S="",C="";if(y.a$&&y.a$["r:id"]){S="remote link";let I=t.rels[y.a$["r:id"]];I&&(C=I.target||"")}else C=y.__location||"",S=y.__display||"";l.push({address:Z,reference:C,text:S})}let A=21,_=100,b=t.sheet_data.worksheet?.sheetFormatPr;if(b){if(b.a$?.defaultColWidth){let y=Number(b.a$.defaultColWidth);isNaN(y)||(_=Pt(y))}if(b.a$?.defaultRowHeight){let y=Number(b.a$.defaultRowHeight);isNaN(y)||(A=Math.round(y*4/3))}}let N=[],$=[],Y=m("worksheet/sheetData/row");for(let y of Y){let Z=y.a$?.r?Number(y.a$.r):1,S=A;if(y.a$?.ht){let I=Number(y.a$.ht);isNaN(I)||(S=Math.round(I*4/3))}if(y.a$?.outlineLevel){let I=Number(y.a$.outlineLevel);isNaN(I)||($[Z-1]=I)}if(y.a$?.s){let I=Number(y.a$?.s);isNaN(I)||(d[Z-1]=I)}S!==A&&(N[Z-1]=S);let C=y.c||[];Array.isArray(C)||(C=[C]);for(let I of C){let v=this.ParseCell(t,I,i,s,o,l);v&&r.push(v)}}let W=[],k=-1,q=[],X=m("worksheet/cols/col");for(let y of X){let Z=Number(y.a$?.min),S=Number(y.a$?.max);if(y.a$?.style){let C=Number(y.a$.style);if(!isNaN(Z)&&!isNaN(S)&&!isNaN(C))if(t.extent&&S>=t.extent.to.col||S-Z>100)k=C;else for(let I=Z;I<=S;I++)W[I]=C}if(y.a$?.customWidth){let C=Number(y.a$.width);if(!isNaN(Z)&&!isNaN(S)&&!isNaN(C)&&S!==16384){C=Pt(C);for(let I=Z;I<=S;I++)q[I-1]=C}}}let B=m("worksheet/tableParts/tablePart");for(let y of B){let Z=y.a$?y.a$["r:id"]:void 0;if(Z){let S="",C=t.rels[Z];if(C){S=C.target||"";let I=this.workbook.ReadTable(S);if(I){let v=t.TranslateAddress(I.ref),L=Ge(v)?{start:{row:v.row-1,column:v.col-1},end:{row:v.row-1,column:v.col-1}}:{start:{row:v.from.row-1,column:v.from.col-1},end:{row:v.to.row-1,column:v.to.col-1}};for(let z of r)if(z.row===L.start.row&&z.column===L.start.column){z.table={area:L,name:I.name,totals_row:!!I.totals_row_count};break}}}}}let K=m("worksheet/drawing"),D=[],O=[],ee=[];for(let y of K){let Z=y.a$?y.a$["r:id"]:void 0;if(Z){let S="",C=t.rels[Z];if(C&&(S=C.target||""),S){let I=this.workbook.ReadDrawing(S);if(I&&I.length)for(let v of I)switch(v.type){case"chart":D.push(v);break;case"image":O.push(v);break;case"textbox":ee.push(v);break}}}}let G=y=>{let Z={address:{row:y.row,column:y.column},offset:{x:0,y:0}};if(y.row_offset){let S=N[y.row];S===void 0&&(S=A),Z.offset.y=y.row_offset/9525/S}if(y.column_offset){let S=q[y.column];S===void 0&&(S=_),Z.offset.x=y.column_offset/9525/S}return Z};for(let y of ee){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)};h.push({layout:Z,type:"textbox",data:{style:y.style,paragraphs:y.paragraphs}})}for(let y of O)if(y&&y.image){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)},S="image",C=Nn.default.fromByteArray(y.image),I="";if(y.filename&&(/jpe*g$/i.test(y.filename)?I="jpeg":/png$/i.test(y.filename)?I="png":/gif$/i.test(y.filename)&&(I="gif")),I&&C){let v="data:image/"+I+";base64,"+C;h.push({layout:Z,type:S,data:{src:v}})}}for(let y of D)if(y&&y.chart){let Z={tl:G(y.anchor.from),br:G(y.anchor.to)},S,C=[],I="",v=y.chart?.series;switch(y.chart.type){case 7:S="treb-chart",I="Bubble.Chart",v&&v.length&&(C[0]=`Group(${v.map(z=>`Series(${[z.title||"",z.values||"",z.categories||"",z.bubble_size||""].join(", ")})`).join(", ")})`),C[1]=y.chart.title;break;case 4:S="treb-chart",I="Scatter.Line",v&&v.length&&(C[0]=`Group(${v.map(z=>`Series(${z.title||""},${z.categories||""},${z.values||""})`||"").join(", ")})`),C[1]=y.chart.title;break;case 5:case 6:I=y.chart.type===5?"Donut.Chart":"Pie.Chart",S="treb-chart",v&&v[0]&&(C[0]=v[0].values,C[1]=v[0]?.categories||""),C[2]=y.chart.title;break;case 2:case 1:case 3:switch(C[2]=y.chart.title,S="treb-chart",y.chart.type){case 2:I="Bar.Chart";break;case 1:I="Column.Chart";break;default:I="Line.Chart"}v&&(v.length>1?C[0]=`Group(${v.map(z=>`Series(${z.title||""},,${z.values||""})`||"").join(", ")})`:v.length===1&&(v[0].title?C[0]=`Series(${v[0].title||""},,${v[0].values||""})`:C[0]=v[0].values),C[1]=v[0]?.categories||"");break}let L=`=${I}(${C.join(", ")})`;S&&L&&h.push({layout:Z,type:S,formula:L})}let se=m("worksheet/extLst/ext");for(let y of se){let Z="";for(let C of Object.keys(y?.a$||{})){let I=C.match(/^xmlns:(.*)$/);if(I){Z=I[1];break}}let S=M.FindAll(y,`${Z}:sparklineGroups/${Z}:sparklineGroup`);for(let C of S){let I="Sparkline.line",v="",L="";C.a$?.type==="column"&&(I="Sparkline.column");let z=M.FindAll(C,`${Z}:sparklines/${Z}:sparkline`);for(let oe of z)for(let ue of Object.keys(oe))/:f$/.test(ue)?L=oe[ue]:/:sqref$/.test(ue)&&(v=oe[ue]);if(L&&v){let oe=`=${I}(${L})`,ue=t.TranslateAddress(v);if(Ge(ue)){let Be={row:ue.row-1,column:ue.col-1,value:oe,type:"formula"},qe=!1;for(let x of r)if(x.row===Be.row&&x.column===Be.column){qe=!0,x.type="formula",x.value=oe;break}qe||r.push(Be)}}}}let te={name:t.options.name,cells:r,default_column_width:_,column_widths:q,row_heights:N,row_styles:d,annotations:h,conditional_formats:a,data_validations:c,styles:this.workbook?.style_cache?.CellXfToStyles()||[]};return $.length&&(te.outline=$),(t.visible_state===1||t.visible_state===2)&&(te.hidden=!0),k>=0&&(te.sheet_style=k),W.length&&(te.column_styles=W),te}};var vt=self,ar=new At,Ls=n=>{n.sheet&&(ar.Init(n.decorated||[]),ar.Export(n.sheet),vt.postMessage({status:"complete",blob:ar.Blob()}))},Vs=n=>{let e=new Ct;try{e.Init(n.data);let t=e.workbook?.GetNamedRanges(),r=e.SheetCount(),i={sheets:[],named:t,active_tab:e.workbook?.active_tab};for(let s=0;s<r;s++){let o=e.GetSheet(s);o&&i.sheets.push(o)}for(let s of t||[])if(typeof s.local_scope=="number"){let o=i.sheets[s.local_scope];o&&(s.scope=o.name)}vt.postMessage({status:"complete",results:i})}catch(t){console.warn("error importing xlsx file"),console.info(t),vt.postMessage({status:"error",data:t})}};vt.addEventListener("message",n=>{n.data&&n.data.command==="export"?Ls(n.data):n.data&&n.data.command==="import"&&Vs(n.data)});\n';var lr=class c{static treb_base_path="";static treb_embedded_script_path="";static one_time_warnings={};DOM=P.GetInstance();loaded=!1;document_styles={number_formats:[],colors:[],theme_colors:[]};selection_state={};options;get Localization(){return N}language_model;events=new le;calculation=0;file_version=0;last_save_version=0;initial_load_source=void 0;calculator;grid;model;dialog;spinner;file_chooser;file_chooser_operation=0;get parser(){return this.model.parser}view_node;key_listener;views=[];focus_target=this;parent_view;export_worker;undo_pointer=0;undo_stack=[];last_selection;get active_sheet(){let e=this.grid.active_sheet.name;return xe.test(e)?`'${e}'`:e}get modified(){return this.undo_stack.length!==1}get document_name(){return this.grid.model.document_name}set document_name(e){this.grid.model.document_name=e,this.DocumentChange()}get user_data(){return this.grid.model.user_data}set user_data(e){this.grid.model.user_data=e,this.DocumentChange()}get scale(){return this.grid.scale}set scale(e){this.grid.scale=e}get headless(){return this.grid.headless}set headless(e){this.grid.headless!==e&&(this.grid.headless=e,e||(this.grid.Update(!0),this.RebuildAllAnnotations()))}get state(){return this.file_version}get can_revert(){return!this.options.inline_document&&!this.options.document?!1:this.initial_load_source==="local-storage"?!0:this.dirty}get dirty(){return this.file_version!==this.last_save_version}set dirty(e){e?this.file_version++:this.last_save_version=this.file_version}get sheet_names(){return this.model.sheets.list.map(e=>e.name)}constructor(e){e.storage_key&&!e.local_storage&&(e.local_storage=e.storage_key),this.options={...dn,...e,local_storage:this.ResolveStorageKey(e.local_storage,"document")},typeof this.options.imaginary_value=="string"&&(ie.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",()=>{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 o={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&&(o.initial_scale=this.options.scale),this.options.stats&&(o.stats=this.options.stats,o.tab_bar=!0),this.options.scale_control&&(o.scale_control=!0,o.tab_bar=!0,this.options.persist_scale&&(o.persist_scale_key=this.ResolveStorageKey(this.options.persist_scale,"scale"),o.persist_scale_key))){let a=localStorage.getItem(o.persist_scale_key);if(a)try{let s=JSON.parse(a);o.initial_scale=s.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 it,this.model.sheets.Add(X.Blank(this.model.theme_style_properties)),this.calculator=this.CreateCalculator(this.model,e)),n&&(this.DOM=P.GetInstance(n.ownerDocument)),this.grid=new lt(o,this.model,void 0,!!n,this.DOM),this.options.headless&&(this.grid.headless=!0),n){this.DOM=P.GetInstance(n.ownerDocument),this.parent_view||(ee.is_windows?n.parentElement?.classList.add("treb-ua-windows"):ee.is_mac&&n.parentElement?.classList.add("treb-ua-osx"));let a=n.querySelector(".treb-view-template");this.view_node=a.content.firstElementChild?.cloneNode(!0),n.prepend(this.view_node),this.view_node.addEventListener("focusin",()=>{this.focus_target!==this&&(this.Publish({type:"focus-view"}),this.focus_target=this)}),this.key_listener=l=>this.HandleKeyDown(l),n.addEventListener("keydown",this.key_listener);let s=!!(r||this.options.document);this.grid.Initialize(this.view_node,s),this.options.dnd&&(this.view_node.addEventListener("dragenter",l=>this.HandleDrag(l)),this.view_node.addEventListener("dragover",l=>this.HandleDrag(l)),this.view_node.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(),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.conditional_format&&(this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1)),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(e.preload&&e.preload.call(0,this),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 a=this.options.scroll;requestAnimationFrame(()=>{this.ScrollTo(a)})}this.UpdateAC(),this.options.global_name&&(self[this.options.global_name]=this),n&&this.options.spinner&&(this.spinner=new rr(n)),t&&!e.model&&!r&&this.LoadNetworkDocument(t,this.options),n&&(this.dialog=new tr(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 er(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_node?.parentElement&&(t.key_listener&&t.view_node.parentElement.removeEventListener("keydown",t.key_listener),t.view_node.parentElement.removeChild(t.view_node)),this.view_node?.focus(),this.Resize()}}ExternalEditor(e){this.grid.ExternalEditor(e)}Split(){let e=this.CreateView();e.grid.EnsureActiveSheet(!0),e.view_node?.addEventListener("focusin",()=>{this.focus_target!==e&&(this.Publish({type:"focus-view"}),this.focus_target=e)}),e.grid.grid_events.Subscribe(r=>{r.type==="structure"&&(this.grid.EnsureActiveSheet(),this.grid.UpdateLayout(),this.grid.UpdateTabBar())}),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.UpdateTabBar())});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){return this.grid.AddConditionalFormat(e),e}RemoveConditionalFormat(e){this.grid.RemoveConditionalFormat({format:e})}RemoveConditionalFormats(e){if(e===void 0){let r=this.GetSelectionReference();if(r.empty)throw new Error("invalid range (no selection)");e=r.area}let t=this.model.ResolveArea(e,this.grid.active_sheet);this.grid.RemoveConditionalFormat({area:t})}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 o=n.area.spreadsheet_label;this.InsertAnnotation(`=${i}(${o},,"${o}")`,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),o=Number(e.scale||1);if(o&&!isNaN(o)){this.grid.ApplyStyle(void 0,{font_size:{unit:"em",value:o}},!0);let a=[];for(let s=n.start.row;s<=n.end.row;s++)a.push(s);this.selection_state?.merge||this.grid.SetRowHeight(a,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=z.Get(this.selection_state.style.number_format||"General");if(i.date_format)break;let n=new ie(i.pattern);if(i.magic_decimal){let o=0,a=this.GetRange();Array.isArray(a)||(a=[[a]]);e:for(let s=0;s<a.length;s++)for(let l=0;l<a[s].length;l++){let d=a[s][l];if(typeof d<"u"&&ae(d)){let h=z.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"&&(o=u.parts[1].length),m.parts&&typeof m.parts[1]=="string"&&(o=Math.max(o,m.parts[1].length));break e}else if(typeof d=="number"){let h=i.BaseFormat(d);h.parts&&typeof h.parts[1]=="string"&&(o=h.parts[1].length);break e}}e.command==="increase-precision"?n.SetDecimal(o+1):n.SetDecimal(Math.max(0,o-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;case"indent":case"outdent":this.grid.Indent(void 0,e.command==="indent"?1:-1);break;default:console.info("unhandled",e.command);break}Object.keys(t).length&&this.grid.ApplyStyle(void 0,t,!0),this.Focus()}ShowToolbar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=!t.hasAttribute("toolbar")),e?t.setAttribute("toolbar",""):t.removeAttribute("toolbar"))}}ShowSidebar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=t.hasAttribute("collapsed")),e?t.removeAttribute("collapsed"):t.setAttribute("collapsed",""))}}CreateChart(){return this.calculator.RegisterLibrary("treb-charts",ei)&&this.UpdateAC(),this.options.chart_renderer?typeof this.options.chart_renderer=="function"?new Ge(this.options.chart_renderer()):new Ge(this.options.chart_renderer):new Ge}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,o=!1;for(let a of i)a.type==="data"?n=!0:a.type==="structure"&&a.rebuild_required&&(o=!0);o&&this.calculator.Reset(),(n||o)&&(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;for(let t of e.annotations)if(t.view&&t.data.type==="textbox"){let r=t.view[this.grid.view_index]||{};r.update_callback&&r.update_callback()}}this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0),this.Publish({type:"theme-change"})}GetSheetID(e){if(typeof e=="number"){let t=this.grid.model.sheets.list[e];if(t)return t.id}else{let t=this.model.sheets.Find(e);if(t)return t.id}}InsertTable(e,t={}){let r=e?this.model.ResolveArea(e,this.grid.active_sheet):this.GetSelectionReference().area,i=t.theme;typeof i=="number"&&(i=xt(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=xt(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}RemoveConnectedChart(e){let t=this.model.RemoveConnectedElement(e);if(t){let r=this.calculator.RemoveConnectedELement(t)}}UpdateConnectedChart(e,t){let r=this.model.connected_elements.get(e);if(r){r.formula=t;let i=r.internal;i?.state&&(i.state=void 0),this.calculator.UpdateConnectedElements(this.grid.active_sheet,r),r.update&&r.update.call(0,r)}}CreateConnectedFormula(e,t,r={}){let i=r?.r1c1||!1,n=r?.argument_separator||this.parser.argument_separator;this.parser.Save(),this.parser.flags.r1c1=i,n===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",");let o=this.parser.Parse(e);if(this.parser.Restore(),o.expression)e="="+this.parser.Render(o.expression,{missing:""});else throw console.warn("invalid formula",o.error),new Error("invalid formula");let a=this.model.AddConnectedElement({formula:e,update:t?s=>{t.call(0,s)}:void 0});return this.calculator.UpdateConnectedElements(this.grid.active_sheet),this.UpdateConnectedElements(),a}CreateConnectedChart(e,t,r){let i=this.CreateChart();i.Initialize(t);let n=o=>{let a=this.parser.Parse(o.formula);if(a&&a.expression&&a.expression.type==="call"){this.parser.Walk(a.expression,d=>((d.type==="address"||d.type==="range")&&this.model.ResolveSheetID(d,void 0,this.grid.active_sheet),!0));let s=a.expression.name.toLowerCase(),l=this.calculator.CalculateExpression(a.expression);i.Exec(s,l)}i.Update()};return this.CreateConnectedFormula(e,n,r)}InsertAnnotation(e,t="treb-chart",r,i){let n,o,a=!1;if(typeof i=="object"?(o=i.argument_separator,a=!!i.r1c1):(i===","||i===";")&&(o=i),r&&(n=G.IsRectangle(r)?r:this.model.ResolveArea(r,this.grid.active_sheet)),o&&o!==this.parser.argument_separator||a){this.parser.Save(),o===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(","),this.parser.flags.r1c1=!!a;let u=this.parser.Parse(e);this.parser.Restore(),u.expression&&(e="="+this.parser.Render(u.expression,{missing:""}))}let{x:s,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:s/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()),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.Serialize({rendered_values:!0,expand_arrays:!0,export_colors:!0,decorated_cells:!0,tables:!0,share_resources:!1,export_functions:!0});r.decimal_mark=N.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.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,o=/csv(?:$|\?|&)/i.test(e),a=/tsv(?:$|\?|&)/i.test(e);try{this.spinner?.Show();let s=await fetch(e);if(this.spinner?.Hide(),!s.ok)throw new Error("network error");let l=await s.text();if(typeof l=="string")if(o)this.LoadCSV(l,"network-file");else{if(a)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(s){console.info("error loading network document",e),console.error(s),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 a=0;a<r.columns;a++)i.push("");let n=[];for(let a=0;a<r.rows;a++)n.push(i.slice(0));let o=new RegExp(`[
13
+ changes in the sidebar.`,close_box:!0,timeout:5e3,type:"info"});break;case"indent":case"outdent":this.grid.Indent(void 0,e.command==="indent"?1:-1);break;default:console.info("unhandled",e.command);break}Object.keys(t).length&&this.grid.ApplyStyle(void 0,t,!0),this.Focus()}ShowToolbar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=!t.hasAttribute("toolbar")),e?t.setAttribute("toolbar",""):t.removeAttribute("toolbar"))}}ShowSidebar(e){if(this.options.toolbar&&this.options.container instanceof HTMLElement){let t=this.options.container.parentElement;t&&(e===void 0&&(e=t.hasAttribute("collapsed")),e?t.removeAttribute("collapsed"):t.setAttribute("collapsed",""))}}CreateChart(){return this.calculator.RegisterLibrary("treb-charts",ei)&&this.UpdateAC(),this.options.chart_renderer?typeof this.options.chart_renderer=="function"?new Ge(this.options.chart_renderer()):new Ge(this.options.chart_renderer):new Ge}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,o=!1;for(let a of i)a.type==="data"?n=!0:a.type==="structure"&&a.rebuild_required&&(o=!0);o&&this.calculator.Reset(),(n||o)&&(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;for(let t of e.annotations)if(t.view&&t.data.type==="textbox"){let r=t.view[this.grid.view_index]||{};r.update_callback&&r.update_callback()}}this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(this.grid.active_sheet,!1),this.grid.Update(!0),this.Publish({type:"theme-change"})}GetSheetID(e){if(typeof e=="number"){let t=this.grid.model.sheets.list[e];if(t)return t.id}else{let t=this.model.sheets.Find(e);if(t)return t.id}}InsertTable(e,t={}){let r=e?this.model.ResolveArea(e,this.grid.active_sheet):this.GetSelectionReference().area,i=t.theme;typeof i=="number"&&(i=xt(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=xt(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}RemoveConnectedChart(e){let t=this.model.RemoveConnectedElement(e);if(t){let r=this.calculator.RemoveConnectedELement(t)}}UpdateConnectedChart(e,t){let r=this.model.connected_elements.get(e);if(r){r.formula=t;let i=r.internal;i?.state&&(i.state=void 0),this.calculator.UpdateConnectedElements(this.grid.active_sheet,r),r.update&&r.update.call(0,r)}}CreateConnectedFormula(e,t,r={}){let i=r?.r1c1||!1,n=r?.argument_separator||this.parser.argument_separator;this.parser.Save(),this.parser.flags.r1c1=i,n===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(",");let o=this.parser.Parse(e);if(this.parser.Restore(),o.expression)e="="+this.parser.Render(o.expression,{missing:""});else throw console.warn("invalid formula",o.error),new Error("invalid formula");let a=this.model.AddConnectedElement({formula:e,update:t?s=>{t.call(0,s)}:void 0});return this.calculator.UpdateConnectedElements(this.grid.active_sheet),this.UpdateConnectedElements(),a}CreateConnectedChart(e,t,r){let i=this.CreateChart();i.Initialize(t);let n=o=>{let a=this.parser.Parse(o.formula);if(a&&a.expression&&a.expression.type==="call"){this.parser.Walk(a.expression,d=>((d.type==="address"||d.type==="range")&&this.model.ResolveSheetID(d,void 0,this.grid.active_sheet),!0));let s=a.expression.name.toLowerCase(),l=this.calculator.CalculateExpression(a.expression);i.Exec(s,l)}i.Update()};return this.CreateConnectedFormula(e,n,r)}InsertAnnotation(e,t="treb-chart",r,i){let n,o,a=!1;if(typeof i=="object"?(o=i.argument_separator,a=!!i.r1c1):(i===","||i===";")&&(o=i),r&&(n=G.IsRectangle(r)?r:this.model.ResolveArea(r,this.grid.active_sheet)),o&&o!==this.parser.argument_separator||a){this.parser.Save(),o===","?this.parser.SetLocaleSettings("."):this.parser.SetLocaleSettings(","),this.parser.flags.r1c1=!!a;let u=this.parser.Parse(e);this.parser.Restore(),u.expression&&(e="="+this.parser.Render(u.expression,{missing:""}))}let{x:s,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:s/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()),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.Serialize({rendered_values:!0,expand_arrays:!0,export_colors:!0,decorated_cells:!0,tables:!0,share_resources:!1,export_functions:!0,apply_row_pattern:!0});r.decimal_mark=N.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.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,o=/csv(?:$|\?|&)/i.test(e),a=/tsv(?:$|\?|&)/i.test(e);try{this.spinner?.Show();let s=await fetch(e);if(this.spinner?.Hide(),!s.ok)throw new Error("network error");let l=await s.text();if(typeof l=="string")if(o)this.LoadCSV(l,"network-file");else{if(a)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(s){console.info("error loading network document",e),console.error(s),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 a=0;a<r.columns;a++)i.push("");let n=[];for(let a=0;a<r.rows;a++)n.push(i.slice(0));let o=new RegExp(`[
14
14
  \r"${e.delimiter}]`);if(rt(r.data))for(let a of r.data){let s="";!e.formulas&&typeof a.calculated<"u"?s=ae(a.calculated)?Oe(a.calculated):a.calculated.toString():typeof a.value=="string"&&a.value[0]==="'"?s=a.value.substr(1):typeof a.value<"u"&&(s=ae(a.value)?Oe(a.value):a.value.toString()),o.test(s)&&(s=s.replace(/"/g,'""'),s='"'+s+'"'),n[a.row][a.column]=s}return n.map(a=>a.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,o=e.split(/\./).filter(s=>s.trim().length),a=o.length?o[o.length-1].toLowerCase():"treb";if(o.length<=1||e==="treb.json")if(e==="treb.json"&&(a=e),(a==="csv"||a==="tsv")&&this.grid.model.sheets.length>1){let s=this.grid.active_sheet.name;e=(r+"-"+s).toLowerCase().replace(/\W+/g,"-")+"."+a}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+a;switch(a){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 s=new Blob([n],{type:"text/plain;charset=utf-8"});this.SaveAs(s,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=V(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=tt(i)?new y(i.start,i.end):new y(i)}if(V(e)&&(e=new y(e)),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.Serialize(e),r={app:"@trebco/treb",version:"29.5.1",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:N.decimal_separator,...t};if(e.share_resources){let i=1,n=new Map,o=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],a=l=>{let d=n.get(l);return d||(d=(i++).toString(),n.set(l,d)),`resource:${d}`};for(let l of o)if(l){l.background_image&&(l.background_image=a(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=a(d.data.src))}let s={};for(let[l,d]of n.entries())s[d]=l;r.shared_resources=s}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"})}ScrollIntoView(e,t=!1){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(r)?r:r.start}this.grid.ScrollIntoView(e,t)}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(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 V(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 ce.TryParse(e).value}FormatNumber(e,t="General"){return z.Get(t).Format(e)}SpreadsheetDate(e){return e instanceof Date&&(e=e.getTime()),Ce(e,!0)}JavascriptDate(e){return we(e).getTime()}ApplyBorders(e,t,r=1){this.grid.ApplyBorders2(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,{},r)}ApplyStyle(e,t={},r=!0){this.grid.ApplyStyle(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,r)}ClearName(e){this.grid.SetName(e)}DefineName(e,t,r,i=!1){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof r=="string"){let n=this.model.sheets.ID(r);if(typeof n=="number")r=n;else throw new Error("invalid scope; use a sheet name or sheet id")}if(typeof t=="object"&&(V(t)||tt(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet),void 0,r,i);return}if(typeof t=="string"){let n=this.parser.Parse(t);if(!n.expression)throw new Error("invalid expression");switch(n.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(n.expression,this.grid.active_sheet),void 0,r,i);return}this.grid.SetName(e,void 0,t,r,i)}else this.grid.SetName(e,void 0,t.toString(),r,i)}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(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 i=this.GetSelectionReference();i.empty||(e=i.area)}if(!e)return;let r=t.type;return r||(t.formatted&&(r="formatted"),t.formula&&(r="A1")),r==="formula"&&(r="A1"),this.grid.GetRange(this.model.ResolveAddress(e,this.grid.active_sheet),r)}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,o=Math.max(0,...t.map(s=>s.length)),a={row:i.start.row+n+1,column:i.start.column+o+1};i.ConsumeAddress(a)}return this.grid.SetRange(i,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}Serialize(e={}){let t=this.grid.active_sheet;t.selection=JSON.parse(JSON.stringify(this.grid.GetSelection()));let r=this.grid.ScrollOffset();r&&(t.scroll_offset=r);let i=this.model.sheets.list.map(s=>s.toJSON(e)),n;this.model.tables.size>0&&(n=Array.from(this.model.tables.values()));let o;if(this.model.macro_functions.size){o=[];for(let s of this.model.macro_functions.values())o.push({...s,expression:void 0})}let a=this.model.SerializeNames(t);return{sheet_data:i,active_sheet:t.id,named:a.length?a:void 0,macro_functions:o,tables:n}}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 Ct(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);V(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()),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.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 t="hyperlink invalid target",r=e.data.reference||"";if(typeof r=="string"){if(/^https{0,1}:\/\//i.test(r)){if(!this.options.hyperlinks){console.warn("hyperlinks are disabled");return}let i=this.DOM.Create("a");i.setAttribute("target",this.options.hyperlinks),i.setAttribute("href",r),i.setAttribute("noreferrer","true"),i.setAttribute("nofollow","true"),i.click();return}else{let i=this.parser.Parse(r);if(i.expression){if(i.expression.type==="address"){(i.expression.sheet||i.expression.sheet_id)&&this.ActivateSheet(i.expression.sheet||i.expression.sheet_id),this.Select(r);return}else if(i.expression.type==="range"){(i.expression.start.sheet||i.expression.start.sheet_id)&&this.ActivateSheet(i.expression.start.sheet||i.expression.start.sheet_id),this.Select(r);return}}}console.warn(t,2);return}}}OnSheetChange(e){for(let t of e.activate.annotations)this.InflateAnnotation(t),this.calculator.UpdateAnnotations(t,e.activate);this.UpdateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(e.activate,!0)}HandleDrag(e){if(e.dataTransfer&&e.dataTransfer.types){if(e.dataTransfer.types.some&&e.dataTransfer.types.some(t=>t==="Files"))e.preventDefault();else for(let t=0;t<e.dataTransfer.types.length;t++)if(e.dataTransfer.types[t]==="files"){e.preventDefault();return}}}HandleDrop(e){if(e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length){e.preventDefault();let t=e.dataTransfer.files[0];/^image/.test(t.type)?this.InsertImageInternal(t):this.LoadFileInternal(t,"drag-and-drop").catch(()=>{})}}SelectFile2(e,t){if(!this.file_chooser){let r=this.DOM.Create("input",void 0,void 0,{attrs:{type:"file"},events:{change:()=>{if(r.files&&r.files[0]){let 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 o;if(typeof n.result=="string")o=n.result;else{o="";let s=new Uint8Array(n.result);for(let l=0;l<s.byteLength;l++)o+=String.fromCharCode(s[l])}let a=this.DOM.Create("img");a.src=o,await Promise.resolve(),this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:o,original_size:{width:a.width||300,height:a.height||300}}},void 0,void 0,{top:30,left:30,width:a.width||300,height:a.height||300})}r()}catch(o){i(o)}},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,o)=>{let a=s=>{i.onload=null,i.onabort=null,i.onerror=null,s?(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(s)),o(s)):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"?a("Unsupported file"):this.ImportXLSX(i.result,t).then(()=>a()).catch(s=>a(s));return}else{let s=JSON.parse(i.result);this.LoadDocument(s,{source:t})}a()}catch(s){a(s?.toString())}},i.onabort=()=>{a("Aborted")},i.onerror=()=>{a("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){let t=e.temp;if(t.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;for(let i of e.view)i.dirty=!0}let r=e.view[this.grid.view_index]||{};r.dirty&&(r.update_callback&&r.update_callback(),this.grid.AnnotationUpdated(e))}this.UpdateConnectedElements()}UpdateConnectedElements(){for(let e of this.model.connected_elements.values()){let t=e.internal;if(t?.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;let r=e.update;r&&Promise.resolve().then(()=>r.call(0,e))}}}RebuildAllAnnotations(){for(let e of this.grid.active_sheet.annotations){this.InflateAnnotation(e);let t=e.view[this.grid.view_index]||{};t.resize_callback&&t.resize_callback(),t.update_callback&&t.update_callback()}}InflateAnnotations(){for(let e of this.grid.active_sheet.annotations)this.InflateAnnotation(e)}InflateAnnotation(e){if(this.grid.headless)return;let t=e.view[this.grid.view_index]||{};if(t.inflated){e.dirty&&(t.resize_callback&&t.resize_callback(),e.dirty=!1);return}if(t.inflated=!0,e.dirty&&(e.dirty=!1),t.content_node){if(e.data.type==="treb-chart"){let r=this.CreateChart();r.Initialize(t.content_node);let 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,s=>((s.type==="address"||s.type==="range")&&this.model.ResolveSheetID(s,void 0,this.grid.active_sheet),!0));let o=n.expression.name.toLowerCase(),a=this.calculator.CalculateExpression(n.expression);r.Exec(o,a)}}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"){if(typeof e.data.data?.src=="string"){let r=wt(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)}}}else if(e.data.type==="textbox"&&e.data.data){let r=document.createElement("div");r.classList.add("treb-annotation-textbox");for(let i of e.data.data.paragraphs){let n=document.createElement("p");i.style&&(i.style.horizontal_align==="right"||i.style.horizontal_align==="center")&&(n.style.textAlign=i.style.horizontal_align);for(let o of i.content){let a=document.createElement("span");a.textContent=o.text||"",o.style?.bold&&(a.style.fontWeight="600"),o.style?.italic&&(a.style.fontStyle="italic"),n.appendChild(a)}r.append(n)}if(t.content_node.append(r),e.data.data.style){let i=e.data.data.style,n=()=>{if(i.fill){let o=R(this.grid.theme,i.fill);r.style.background=o}};t.update_callback=()=>{this.grid.headless||n()},n()}}}}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 o=0,a=i.length;o<a;o++)r=(r<<5)-r+i.charCodeAt(o),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 o=n-16;this.undo_stack=this.undo_stack.slice(o),this.undo_pointer-=o}}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=F.RelativeFontSize(r.style||{},this.grid.theme.grid_cell||{})}this.selection_state=r}UpdateDocumentStyles(){let e={},t={};for(let i of this.grid.model.sheets.list)i.NumberFormatsAndColors(t,e);this.document_styles.colors=Object.keys(t),this.document_styles.number_formats=Object.keys(e),this.document_styles.theme_colors=[];let r=[.5,.25,0,-.25,-.5];for(let i=0;i<10;i++)this.document_styles.theme_colors.push(r.map(n=>{let o={theme:i,tint:n},a=R(this.grid.theme,o);return{color:o,resolved:a}}))}ConvertLocale(e){let t=new He;t.flags={...this.parser.flags};let r,i;e.decimal_mark==="."?(t.SetLocaleSettings("."),r=",",i=";"):(t.SetLocaleSettings(","),r=".",i=",");let n=o=>{let a=t.Parse(o);if(a.expression)return"="+t.Render(a.expression,{missing:"",convert_decimal:r,convert_argument_separator:i})};if(e.macro_functions)for(let o of e.macro_functions){let a=n(o.function_def);a&&(o.function_def=a)}if(e.sheet_data){let o=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let a of o){if(a.annotations){for(let s of a.annotations)if(s.formula){let l=n(s.formula);l&&(s.formula=l)}}if(a.data?.length)for(let s of a.data){let l=wr(s)?[s]:s.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(a=>Number(a)||0).concat([0,0,0]),i=t.split(".").map(a=>Number(a)||0).concat([0,0,0]),n=[0,1,2],o={match:0};for(let a=0;a<3;a++)if(r[a]!==i[a]){o.match=r[a]>i[a]?1:-1,o.level=n[a];break}return o}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],i=this.CompareVersions(e.version,"29.5.1");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 29.5.1).
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 o=e.shared_resources,a=s=>/^resource:/.test(s)?o[s.substring(9)]||"":s;for(let s of r){s.background_image&&(s.background_image=a(s.background_image));for(let l of s.annotations||[])l.type==="image"&&l.data?.src&&(l.data.src=a(l.data.src))}}e.decimal_mark&&e.decimal_mark!==N.decimal_separator&&this.ConvertLocale(e);let n=this.grid.model;if(n.tables.clear(),e.tables)for(let o of e.tables)n.tables.set(o.name.toLowerCase(),o);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let o of this.model.tables.values())if(o.area.start.sheet_id){let a=n.sheets.Find(o.area.start.sheet_id);if(a)for(let s=o.area.start.row;s<=o.area.end.row;s++)for(let l=o.area.start.column;l<=o.area.end.column;l++){let d=a.cells.GetCell({row:s,column:l},!0);d.table=o}}if(n.document_name=e.name,n.user_data=e.user_data,n.named.Reset(),e.named)this.model.UnserializeNames(e.named,this.grid.active_sheet);else{let o=e.named_ranges;if(!o&&r[0]&&r[0].named_ranges&&(o=r[0].named_ranges),o)for(let[a,s]of Object.entries(o))n.named.SetNamedRange(a,new y(s.start,s.end));if(e.named_expressions)for(let a of e.named_expressions)this.model.UnserializeNames([{name:a.name,expression:a.expression}],this.grid.active_sheet)}if(n.macro_functions.clear(),e.macro_functions)for(let o of e.macro_functions)n.macro_functions.set(o.name.toUpperCase(),{...o,expression:this.parser.Parse(o.function_def||"").expression});this.UpdateAC()}async LoadWorker(){if(ti)try{return new Worker(URL.createObjectURL(new Blob([ri],{type:"application/javascript"})))}catch(e){console.info("embedded worker failed"),console.error(e)}throw new Error("creating worker failed")}HandleKeyDown(e){e.ctrlKey&&(e.code==="KeyZ"||e.key==="z")?(e.stopPropagation(),e.preventDefault(),this.Undo()):e.key==="F9"&&this.options.recalculate_on_f9&&(e.stopPropagation(),e.preventDefault(),this.Recalculate())}};var bn=`@charset "UTF-8";.treb-main.treb-main .treb-mouse-mask{background:transparent;bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:9999}.treb-main.treb-main .treb-mouse-mask.column-resize{cursor:col-resize}.treb-main.treb-main .treb-mouse-mask.row-resize{cursor:row-resize}.treb-main.treb-main .treb-mouse-mask.nub-select{cursor:crosshair}.treb-main.treb-main .treb-mouse-mask.move{cursor:move}.treb-main.treb-main .treb-mouse-mask.nw-resize{cursor:nw-resize}.treb-main.treb-main .treb-note{max-width:15em;min-width:15em}.treb-main.treb-main .treb-hover-title,.treb-main.treb-main .treb-note{background:var(--treb-note-background,#fff);border:1px solid var(--treb-note-border-color,var(--treb-ui-border-color,#ddd));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-note-color,#333);font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:10.5pt;left:100px;line-height:normal;opacity:0;padding:7px 10px;position:fixed;top:100px;transition:opacity .2s;white-space:pre-line;z-index:39}.treb-main.treb-main .treb-hover-title{min-width:10em;pointer-events:none}.treb-main.treb-main .treb-sort-button{background:#fff;border:1px solid #ccc;border-radius:2px;height:1em;left:100px;opacity:0;pointer-events:none;position:absolute;top:100px;transition:opacity .1s ease;width:1em;z-index:39}.treb-main.treb-main .treb-sort-button:after{box-sizing:border-box}.treb-main.treb-main .treb-sort-button.asc:after{border:.4em solid transparent;border-top-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-25%);width:.8em}.treb-main.treb-main .treb-sort-button.desc:after{border:.4em solid transparent;border-bottom-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-80%);width:.8em}.treb-main.treb-main .treb-tooltip{border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;line-height:normal;padding:2px 10px;pointer-events:none;position:fixed;z-index:39}.treb-main.treb-main .treb-tooltip.arrow-up:after{border:4px solid transparent;border-bottom-color:inherit;box-sizing:border-box;content:" ";height:8px;left:calc(50% - 4px);overflow:hidden;position:absolute;top:-8px;width:8px}.treb-main.treb-main .treb-tooltip.arrow-left:after{border:4px solid transparent;border-right-color:inherit;box-sizing:border-box;content:" ";height:8px;left:-8px;overflow:hidden;position:absolute;top:calc(50% - 4px);width:8px}.treb-main.treb-main .treb-dropdown-caret{background:var(--treb-dropdown-caret-background,#fff);border:1px solid var(--treb-dropdown-caret-border-color,#ccc);border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;height:20px;position:absolute;width:20px;z-index:39}.treb-main.treb-main .treb-dropdown-caret path{fill:none;stroke:var(--treb-dropdown-caret-color,#444);stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.treb-main.treb-main .treb-dropdown-list{background:var(--treb-dropdown-background,#fff);border:1px solid var(--treb-dropdown-border-color,unset);box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-dropdown-color,inherit);display:none;font-size:10pt;max-height:10em;outline:none;overflow-y:auto;position:absolute;text-align:left;z-index:39}.treb-main.treb-main .treb-dropdown-list div{cursor:default;padding:2px}.treb-main.treb-main .treb-dropdown-list div.selected{background:var(--treb-dropdown-selected-background,#555);color:var(--treb-dropdown-selected-color,#fff)}.treb-main.treb-main .treb-dropdown-caret.active{background:var(--treb-dropdown-caret-active-background,#eee)}.treb-main.treb-main .treb-dropdown-caret.active+.treb-dropdown-list{display:block}.treb-main.treb-main .treb-error-highlight{background:rgba(255,0,0,.25);opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in-out;z-index:40}.treb-main.treb-main .treb-autocomplete{box-sizing:border-box;font-size:inherit;font-weight:400;line-height:normal;max-height:10em;overflow-y:auto;position:fixed;text-align:left;top:-1000px;z-index:39}.treb-main.treb-main .treb-autocomplete *{box-sizing:border-box}.treb-main.treb-main .treb-autocomplete ul{list-style-type:none}.treb-main.treb-main .treb-autocomplete ul,.treb-main.treb-main .treb-autocomplete ul li{font-size:inherit;font-weight:inherit;margin:0;padding:0}.treb-main.treb-main .treb-autocomplete ul li a{color:inherit;cursor:default;display:inline-block;font-size:inherit;font-weight:inherit;padding:3px 6px;text-decoration:none;width:100%}.treb-main.treb-main .treb-autocomplete-tooltip{position:fixed;top:-1000px;white-space:pre;z-index:39}.treb-main.treb-main .treb-formula-bar{display:flex;flex-direction:row;gap:.5em;grid-area:1/1/2/2;max-width:100%;overflow-x:hidden;padding:0 2px 12px;text-align:left}.treb-main.treb-main .treb-formula-bar[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .treb-address-label{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;height:1.75em;justify-content:center;min-height:1.5em;min-width:95px;padding-left:3px;width:95px}.treb-main.treb-main .treb-formula-bar .treb-address-label>div{outline:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button{background:transparent;border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;height:1.75em;min-height:1.5em}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .expand-button{background:transparent;border:0;border-radius:2px;height:1.75em;margin-left:2px;outline:none;padding:1px}.treb-main.treb-main .treb-formula-bar .expand-button:after{border:5px solid transparent;border-top-color:#999;content:" ";display:inline-block;margin:0;padding:0;position:relative;top:-6px;transition:transform .15s ease}.treb-main.treb-main .treb-formula-bar[expanded] .expand-button:after{transform:rotate(180deg) translateY(6px)}.treb-main.treb-main .treb-formula-bar .treb-editor-container{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;flex-grow:1;height:1.75em;justify-content:center;min-width:0}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container{height:4.5em;transition:height .1s ease-in-out}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container>div{overflow-y:auto}.treb-main.treb-main .treb-formula-bar .treb-editor-container>div{flex-grow:1;line-height:1.35;margin:2px;min-height:1em;outline:none;overflow-x:hidden;overflow-y:hidden;white-space:pre-wrap;width:100%}.treb-main.treb-main .treb-mouse-mask .ghost-tab{position:fixed}.treb-main.treb-main .treb-spreadsheet-footer{align-items:center;grid-area:3/1/4/2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tab-container{align-self:flex-start;height:2.2em;overflow:hidden}.treb-main.treb-main .treb-spreadsheet-footer,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{color:var(--treb-ui-color,inherit);display:flex;flex-direction:row;height:2.2em;list-style-type:none;max-width:100%;padding-inline-start:0;z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{height:auto;margin-block-start:0;margin:0;overflow-x:scroll;overflow-y:hidden}.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{height:2.2em;overflow:visible;overflow-x:visible}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:last-of-type{margin-right:0}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab{margin-left:-1px}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control{align-items:center;display:flex;flex-direction:row;font-size:inherit;height:2.2em;justify-content:center;position:relative;width:5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input{background:transparent;border:1px solid transparent;border-radius:2px;color:inherit;font-family:inherit;font-size:inherit;padding:initial;text-align:center;transition:border-color .25s ease,background-color .25s ease;width:4em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container{accent-color:var(--treb-scale-slider-accent-color,undefined);align-items:center;background:var(--treb-scale-slider-background,#fff);border:1px solid var(--treb-scale-slider-border-color,var(--treb-ui-border-color,#ccc));display:flex;flex-direction:row;height:4em;justify-content:center;left:.5em;opacity:0;pointer-events:none;position:absolute;top:0;transform:rotate(-90deg);transform-origin:left top;transition:opacity .25s ease;width:10em;z-index:40}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-scale-input{border-color:var(--treb-ui-border-color,#ccc)}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container>input[type=range]{width:8.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus+.treb-slider-container,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container:focus-within,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-slider-container{opacity:.85;pointer-events:auto}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab{align-items:center;background:transparent;border:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top:0;color:currentColor;cursor:default;display:inline-flex;flex-direction:row;font-size:inherit;margin-right:-2px;min-width:2.5em;padding:.25em .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab svg{height:1em;opacity:.75;pointer-events:none;transition:opacity .125s ease-in-out;width:1em}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:hover svg{opacity:.75}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab path{stroke:currentColor;stroke-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{flex:1 1;overflow:hidden;text-align:end;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel>*{margin-left:.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel .treb-stats-value{background:var(--treb-stats-value-background,#f8f8ff);border:1px solid var(--treb-stats-value-border-color,var(--treb-ui-border-color,#ddd));border-radius:3px;padding:0 .3em}.treb-main.treb-main .treb-grid .treb-overlay-container{margin:0;opacity:0;outline:none;padding:0;position:absolute;z-index:24}.treb-main.treb-main .treb-grid .treb-overlay-container.align-right .treb-overlay-inset{padding-right:3px;right:0;text-align:right}.treb-main.treb-main .treb-grid .treb-overlay-container.align-center .treb-overlay-inset{left:50%;text-align:center;transform:translateX(-50%)}.treb-main.treb-main .treb-grid .treb-overlay-inset{display:flex;flex-direction:column;height:100%;justify-content:flex-end;margin:0;min-width:100%;padding:0 4px;position:absolute}.treb-main.treb-main .treb-grid .treb-overlay-editor{outline:none;position:relative;white-space:nowrap;white-space:pre}.treb-main.treb-main .treb-grid .treb-overlay-editor.firefox:before{content:"\u200B"}.treb-main.treb-main .treb-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{grid-area:2/1/3/2;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{flex-grow:1;order:2;overflow:scroll;position:relative;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;grid-template-columns:100px auto;grid-template-rows:20px auto;outline:none}.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{background:var(--treb-grid-header-background,#eeeef2);color:var(--treb-grid-header-color,var(--treb-grid-default-color,#666));font-family:var(--treb-grid-header-font-family,inherit);font-size:var(--treb-grid-header-font-size,10pt);font-style:var(--treb-grid-header-font-style,normal);font-weight:var(--treb-grid-header-font-weight,normal);stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4))}.treb-main.treb-main .grid-cells{color:var(--treb-grid-default-color,inherit);font-family:var(--treb-grid-font-family,inherit);font-size:var(--treb-grid-font-size,14px);stroke:var(--treb-grid-grid-color,#ccccd4);background:var(--treb-grid-background,#fff)}.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{content:"";height:12px;opacity:.4;position:absolute;right:2px;top:2px;width:12px;--icon:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='currentColor' d='M416 224h-16v-80C400 65 335 0 256 0S112 65 112 144v80H96c-35 0-64 29-64 64v160c0 35 29 64 64 64h320c35 0 64-29 64-64V288c0-35-29-64-64-64m-240-80c0-44 36-80 80-80s80 36 80 80v80H176z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:12px 12px;-webkit-mask-size:12px 12px}.treb-main.treb-main.treb-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-main.treb-main .treb-annotation-textbox{background:Canvas;height:100%;left:0;overflow:hidden;padding:.5em;position:relative;top:0;width:100%}.treb-main.treb-main .treb-annotation-textbox p{margin-block-end:0;margin-block-start:0}.treb-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-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-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-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 .legend circle{fill:currentColor;fill-opacity:.5;stroke:currentColor;stroke-width:2px;r:.25em}.treb-chart .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .chart-grid.zero,.treb-chart .chart-ticks.zero{stroke:var(--treb-chart-grid-zero-color,var(--treb-chart-grid-color,#999))}.treb-chart .label-target{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 .bubble-chart{stroke-width:3;fill:color-mix(in srgb,currentColor 75%,transparent);stroke:currentColor}.treb-chart .bubble-label .label-background{stroke:none;fill:none}.treb-chart .bubble-label .label-text{transform:translate(var(--translate-offset),var(--translate-offset))}.treb-chart .scatter-plot{stroke-width:3;fill:none;stroke:currentColor}.treb-chart .scatter-plot .fill{fill:currentColor;opacity:.5;stroke:none}.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.567'/%3E%3C/svg%3E")}.treb-main.treb-main .treb-icon-64{background:no-repeat 50%/100% var(--treb-icon-svg);height:64px;width:64px}.treb-main.treb-main .treb-dialog-mask{align-items:center;display:flex;height:100%;justify-content:center;left:0;opacity:0;pointer-events:none;position:absolute;top:0;transition:opacity .2s;width:100%;z-index:1000}.treb-main.treb-main .treb-embed-dialog{align-items:center;background:var(--treb-dialog-background,#fff);border:1px solid var(--treb-dialog-border-color,var(--treb-ui-border-color,#999));border-radius:3px;border-top:3px solid #999;box-shadow:0 4px 6px -4px rgba(0,0,0,.3);color:var(--treb-dialog-color,#000);display:flex;flex-direction:row;font-size:var(--treb-dialog-font-size,16px);line-height:1.6em;padding:1rem;position:relative;text-align:left}.treb-main.treb-main .treb-embed-dialog>*{display:none}.treb-main.treb-main .treb-embed-dialog>div{position:relative}.treb-main.treb-main .treb-embed-dialog>:nth-child(2){display:block;flex-grow:1;padding:2px 20px 2px 12px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box{background:transparent;border:0;padding:4px;position:absolute;right:0;top:0}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg{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-.708"/></svg>');--icon-popout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path fill="currentColor" d="M22 14.5v5c0 2.484-2.016 4.5-4.5 4.5h-13A4.5 4.5 0 0 1 0 19.5v-13C0 4.016 2.016 2 4.5 2h11c.281 0 .5.219.5.5v1c0 .281-.219.5-.5.5h-11A2.507 2.507 0 0 0 2 6.5v13C2 20.875 3.125 22 4.5 22h13c1.375 0 2.5-1.125 2.5-2.5v-5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5M28 1v8c0 .547-.453 1-1 1a1 1 0 0 1-.703-.297l-2.75-2.75L13.36 17.14c-.094.094-.234.156-.359.156s-.266-.063-.359-.156l-1.781-1.781c-.094-.094-.156-.234-.156-.359s.063-.266.156-.359L21.048 4.454l-2.75-2.75a1 1 0 0 1-.297-.703c0-.547.453-1 1-1h8c.547 0 1 .453 1 1z"/></svg>');--icon-toolbar:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M5.5 22v2H0v-2zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm2.5-6v2H0v-2zm-10-8v2H0V6zM24 22v2H12.5v-2zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm5 2v2h-3.5v-2zm0-8v2H10.5V6z"/></svg>');--icon-export:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 28"><path fill="currentColor" d="M20 21c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m2-3.5v5a1.5 1.5 0 0 1-1.5 1.5h-23A1.5 1.5 0 0 1 0 22.5v-5A1.5 1.5 0 0 1 1.5 16h7.266l2.109 2.125c.578.562 1.328.875 2.125.875s1.547-.313 2.125-.875L17.25 16h7.25a1.5 1.5 0 0 1 1.5 1.5m-5.078-8.891a.98.98 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.98.98 0 0 1-.219-1.094C5.234 8.25 5.594 8 6 8h4V1c0-.547.453-1 1-1h4c.547 0 1 .453 1 1v7h4c.406 0 .766.25.922.609"/></svg>');--icon-reset:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M23.609 16.5c0 .031 0 .078-.016.109C22.265 22.14 17.702 26 11.937 26c-3.047 0-6-1.203-8.219-3.313l-2.016 2.016A1 1 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a1 1 0 0 1-.297.703l-2.141 2.141A7.99 7.99 0 0 0 11.998 22a7.98 7.98 0 0 0 6.813-3.813c.375-.609.562-1.203.828-1.828.078-.219.234-.359.469-.359h3c.281 0 .5.234.5.5zM24 4v7c0 .547-.453 1-1 1h-7c-.547 0-1-.453-1-1a1 1 0 0 1 .297-.703l2.156-2.156A8.04 8.04 0 0 0 12 6a7.98 7.98 0 0 0-6.813 3.813c-.375.609-.562 1.203-.828 1.828-.078.219-.234.359-.469.359H.781a.503.503 0 0 1-.5-.5v-.109C1.625 5.844 6.234 2 12 2c3.063 0 6.047 1.219 8.266 3.313l2.031-2.016A1 1 0 0 1 23 3c.547 0 1 .453 1 1"/></svg>');--icon-about:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M14 21.5v-3c0-.281-.219-.5-.5-.5h-3c-.281 0-.5.219-.5.5v3c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5M18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328a.49.49 0 0 0 .125.656l2.063 1.563a.48.48 0 0 0 .297.094.5.5 0 0 0 .391-.187c.734-.938 1.047-1.219 1.344-1.437.266-.187.781-.375 1.344-.375 1 0 1.922.641 1.922 1.328 0 .812-.422 1.219-1.375 1.656-1.109.5-2.625 1.797-2.625 3.313v.562c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5 0-.359.453-1.125 1.188-1.547 1.188-.672 2.812-1.578 2.812-3.953zm6 3c0 6.625-5.375 12-12 12S0 20.625 0 14 5.375 2 12 2s12 5.375 12 12"/></svg>');--icon-chevron-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 28"><path fill="currentColor" d="M18.297 4.703 10 13l8.297 8.297a.99.99 0 0 1 0 1.406l-2.594 2.594a.99.99 0 0 1-1.406 0L2.703 13.703a.99.99 0 0 1 0-1.406L14.297.703a.99.99 0 0 1 1.406 0l2.594 2.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-chevron-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 28"><path fill="currentColor" d="M17.297 13.703 5.703 25.297a.99.99 0 0 1-1.406 0l-2.594-2.594a.99.99 0 0 1 0-1.406L10 13 1.703 4.703a.99.99 0 0 1 0-1.406L4.297.703a.99.99 0 0 1 1.406 0l11.594 11.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-revert:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M24 14c0 6.609-5.391 12-12 12a11.97 11.97 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.6.6 0 0 1 .391-.141.5.5 0 0 1 .359.187A7.91 7.91 0 0 0 12 21.999c4.406 0 8-3.594 8-8s-3.594-8-8-8A7.95 7.95 0 0 0 6.563 8.14l2.141 2.156a.96.96 0 0 1 .219 1.078 1 1 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.96.96 0 0 1 1.078.219l2.031 2.016c2.203-2.078 5.187-3.313 8.266-3.313 6.609 0 12 5.391 12 12zM14 9.5v7c0 .281-.219.5-.5.5h-5a.494.494 0 0 1-.5-.5v-1c0-.281.219-.5.5-.5H12V9.5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5"/></svg>');--icon-text-indent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-left"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m.646 2.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L4.293 8 2.646 6.354a.5.5 0 0 1 0-.708M7 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m-5 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-outdent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-right"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m10.646 2.146a.5.5 0 0 1 .708.708L11.707 8l1.647 1.646a.5.5 0 0 1-.708.708l-2-2a.5.5 0 0 1 0-.708zM2 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-center:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-top:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16'%3E%3Cpath d='M8 15a.5.5 0 0 0 .5-.5V5.707l3.146 3.146a.5.5 0 0 0 .707-.707l-4-4a.5.5 0 0 0-.706-.001l-.001.001-4 4a.5.5 0 0 0 .708.707L7.5 5.707V14.5a.5.5 0 0 0 .5.5'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M3 1.5h10'/%3E%3C/svg%3E");--icon-text-align-middle:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8m7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0m-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0z"/></svg>');--icon-text-align-bottom:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16'%3E%3Cpath d='M8 1a.5.5 0 0 0-.5.5v8.793L4.354 7.146a.5.5 0 0 0-.707.707l4 4a.5.5 0 0 0 .707.001l.001-.001 4-4a.5.5 0 0 0-.708-.707L8.5 10.293V1.5A.5.5 0 0 0 8 1'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M13 14.5H3'/%3E%3C/svg%3E");--icon-file-menu:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.54 3.87.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.826a2 2 0 0 1-1.991-1.819l-.637-7a2 2 0 0 1 .342-1.31zM2.19 4a1 1 0 0 0-.996 1.09l.637 7a1 1 0 0 0 .995.91h10.348a1 1 0 0 0 .995-.91l.637-7A1 1 0 0 0 13.81 4zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139q.323-.119.684-.12h5.396z"/></svg>');--icon-wrap-text:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4 5h8a.5.5 0 0 0 0-1H4a.5.5 0 0 0 0 1M10 8H4a.5.5 0 0 0 0 1h6a1.5 1.5 0 0 1 0 3v-1.203l-2.953 1.707L10 14.203V13a2.5 2.5 0 1 0 0-5M3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5"/></svg>');--icon-unmerge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M1.5 1a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0v-4A1.5 1.5 0 0 1 1.5 0h4a.5.5 0 0 1 0 1zM10 .5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 16 1.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5M.5 10a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 0 14.5v-4a.5.5 0 0 1 .5-.5m15 0a.5.5 0 0 1 .5.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5"/></svg>');--icon-merge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M5.5 0a.5.5 0 0 1 .5.5v4A1.5 1.5 0 0 1 4.5 6h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5m5 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 10 4.5v-4a.5.5 0 0 1 .5-.5M0 10.5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 6 11.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5m10 1a1.5 1.5 0 0 1 1.5-1.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0z"/></svg>');--icon-lock:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2m3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2M5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1"/></svg>');--icon-comment:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-2.5a2 2 0 0 0-1.6.8L8 14.333 6.1 11.8a2 2 0 0 0-1.6-.8H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2.5a1 1 0 0 1 .8.4l1.9 2.533a1 1 0 0 0 1.6 0l1.9-2.533a1 1 0 0 1 .8-.4H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/></svg>');--icon-fill-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a3 3 0 0 0-.71-.515c-.217-.104-.56-.205-.882-.02-.367.213-.427.63-.43.896-.003.304.064.664.173 1.044.196.687.556 1.528 1.035 2.402L.752 8.22c-.277.277-.269.656-.218.918.055.283.187.593.36.903.348.627.92 1.361 1.626 2.068.707.707 1.441 1.278 2.068 1.626.31.173.62.305.903.36.262.05.64.059.918-.218l5.615-5.615c.118.257.092.512.05.939-.03.292-.068.665-.073 1.176v.123h.003a1 1 0 0 0 1.993 0H14v-.057a1 1 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4 4 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067S8.857 3.052 8.23 2.704c-.31-.172-.62-.304-.903-.36-.262-.05-.64-.058-.918.219l-.217.216zM4.16 1.867c.381.356.844.922 1.311 1.632l-.704.705c-.382-.727-.66-1.402-.813-1.938a3.3 3.3 0 0 1-.131-.673q.137.09.337.274m.394 3.965c.54.852 1.107 1.567 1.607 2.033a.5.5 0 1 0 .682-.732c-.453-.422-1.017-1.136-1.564-2.027l1.088-1.088q.081.181.183.365c.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626q.183.103.365.183l-4.861 4.862a1 1 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46s-1.168-1.32-1.46-1.846c-.147-.265-.225-.47-.251-.607a1 1 0 0 1-.01-.068zm2.87-1.935a2.4 2.4 0 0 1-.241-.561c.135.033.324.11.562.241.524.292 1.186.8 1.846 1.46.45.45.83.901 1.118 1.31a3.5 3.5 0 0 0-1.066.091 11 11 0 0 1-.76-.694c-.66-.66-1.167-1.322-1.458-1.847z"/></svg>');--icon-text-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604zM8.418 3.604a6 6 0 0 1-.127-.387 4 4 0 0 1-.11-.501h-.035a5.5 5.5 0 0 1-.247.888L5.86 9.211h4.614z"/></svg>');--icon-border-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0z"/></svg>');--icon-border-top:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0v1h16V0zm1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0v16h1V0zm1.906 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM7.5 1.906v.938h1v-.938zm7.5 0v.938h1v-.938zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938zm7.5 0v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM7.5 9.406v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zM1.906 16h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zM16 0h-1v16h1zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zM0 11.281v.938h1v-.938zm7.5 0v.938h1v-.938zM0 13.156v.938h1v-.938zm7.5 0v.938h1v-.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938z"/></svg>');--icon-border-double-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0zm0-2h16v1H0z"/></svg>');--icon-border-all:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0h16v16H0zm1 1v6.5h6.5V1zm7.5 0v6.5H15V1zM15 8.5H8.5V15H15zM7.5 15V8.5H1V15z"/></svg>');--icon-border-outer:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M7.5 1.906v.938h1v-.938zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM7.5 9.406v.938h1v-.938zm0 1.875v.938h1v-.938zm0 1.875v.938h1v-.938z"/><path d="M0 0v16h16V0zm1 1h14v14H1z"/></svg>');--icon-border-none:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0zm2.844 1h-.938V0h.938zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1zm2.813 0h-.938V0h.938zm1.875 0h-.938V0h.938zm1.875 0h-.938V0h.938zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5zM1 1.906v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM1 3.78v.938H0V3.78zm6.5.938V3.78h1v.938zm7.5 0V3.78h1v.938zM1 5.656v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938zm1.875.031h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5zM0 10.344v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 12.22v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 14.094v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5zm2.813 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16z"/></svg>');--icon-palette:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 .5A.5.5 0 0 1 .5 0h5a.5.5 0 0 1 .5.5v5.277l4.147-4.131a.5.5 0 0 1 .707 0l3.535 3.536a.5.5 0 0 1 0 .708L10.261 10H15.5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5H3a3 3 0 0 1-2.121-.879A3 3 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0M15 15v-4H9.258l-4.015 4zM0 .5v12.495zM0 12.995V13z"/></svg>');--icon-layout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="m3 0 17 17.156v-.114z"/><path d="M3 0H0v16h1V1h1.585L19 17.455V19H4v1h16v-2.844z"/><path d="M6.886 3.922 5.343 5.465a.5.5 0 0 0 .708.707l1.539-1.54zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3M5 9v6h6zm1 2.414L8.586 14H6z"/></svg>');--icon-freeze:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><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 0zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0z"/></svg>');--icon-donut-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.01 9.01 0 0 0 12 1.23M2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9 9 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.43 7.43 0 0 1 2.5 10M17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.45 7.45 0 0 1-3.692-.979l-1.093 1.093A8.96 8.96 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7z"/></svg>');--icon-bar-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1z"/></svg>');--icon-line-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><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 0"/><path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z"/></svg>');--icon-recalculate:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M9.478 4.022c2.402-.209 4.583 1.047 5.711 3.014l1.083-.095c-1.233-2.528-3.912-4.175-6.881-3.916-2.97.26-5.321 2.347-6.098 5.051l1.083-.095c.768-2.132 2.698-3.748 5.102-3.959M10.523 15.977c-2.403.211-4.585-1.047-5.712-3.013l-1.08.095c1.234 2.527 3.91 4.175 6.879 3.914 2.971-.259 5.32-2.347 6.095-5.05l-1.08.095c-.769 2.132-2.699 3.749-5.102 3.959"/><path d="m2.272 15.616 5.197-3-4.098-1.097zM17.728 4.384l-5.197 3 4.098 1.098z"/></svg>');--icon-check:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/></svg>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm15 2h-4v3h4zm0 4h-4v3h4zm0 4h-4v3h3a1 1 0 0 0 1-1zm-5 3v-3H6v3zm-5 0v-3H1v2a1 1 0 0 0 1 1zm-4-4h4V8H1zm0-4h4V4H1zm5-3v3h4V4zm4 4H6v3h4z"/></svg>')}.treb-main.treb-main .treb-layout-header{overflow:hidden;overflow-x:scroll;position:relative;-ms-overflow-style:none;scrollbar-width:none}.treb-main.treb-main .treb-layout-header::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-toolbar{color:var(--treb-toolbar-color,var(--treb-ui-color,#333));display:flex;flex-direction:row;font-size:var(--treb-toolbar-font-size,inherit);gap:.5rem}.treb-main.treb-main .treb-toolbar>div{display:flex;flex-direction:row}.treb-main.treb-main .treb-toolbar>div>input,.treb-main.treb-main .treb-toolbar>input{background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:32px;overflow:hidden;padding-left:.5em;padding-right:.5em;text-overflow:ellipsis}.treb-main.treb-main .treb-toolbar>.treb-menu>button{border-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu+button,.treb-main.treb-main .treb-toolbar>.group>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>button+button,.treb-main.treb-main .treb-toolbar>.group>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>input+button,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu+button,.treb-main.treb-main .treb-toolbar>[composite]>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>button+button,.treb-main.treb-main .treb-toolbar>[composite]>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>input+button{border-left-width:0}.treb-main.treb-main .treb-toolbar>.group>button:first-child,.treb-main.treb-main .treb-toolbar>.group>input:first-child,.treb-main.treb-main .treb-toolbar>[composite]>button:first-child,.treb-main.treb-main .treb-toolbar>[composite]>input:first-child{border-bottom-left-radius:3px;border-top-left-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>.group>button:last-child,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>[composite]>button:last-child{border-bottom-right-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button,.treb-main.treb-main .treb-toolbar .treb-menu>button,.treb-main.treb-main .treb-toolbar button[data-icon],.treb-main.treb-main .treb-toolbar>button,.treb-main.treb-main .treb-toolbar>div>button{align-items:center;background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));display:flex;flex-direction:column;height:32px;justify-content:center;position:relative;width:32px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown],.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown],.treb-main.treb-main .treb-toolbar button[data-icon][dropdown],.treb-main.treb-main .treb-toolbar>button[dropdown],.treb-main.treb-main .treb-toolbar>div>button[dropdown]{width:16px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown]:after,.treb-main.treb-main .treb-toolbar button[data-icon][dropdown]:after,.treb-main.treb-main .treb-toolbar>button[dropdown]:after,.treb-main.treb-main .treb-toolbar>div>button[dropdown]:after{border:5px solid transparent;border-top-color:currentcolor;box-sizing:content-box;content:"";height:0;left:50%;position:absolute;top:18px;transform:translate(-50%,-50%);width:0}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button:hover,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[active],.treb-main.treb-main .treb-toolbar .treb-menu>button:hover,.treb-main.treb-main .treb-toolbar .treb-menu>button[active],.treb-main.treb-main .treb-toolbar button[data-icon]:hover,.treb-main.treb-main .treb-toolbar button[data-icon][active],.treb-main.treb-main .treb-toolbar>button:hover,.treb-main.treb-main .treb-toolbar>button[active],.treb-main.treb-main .treb-toolbar>div>button:hover,.treb-main.treb-main .treb-toolbar>div>button[active]{background-color:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar button[data-icon][data-color-bar]:after,.treb-main.treb-main .treb-toolbar>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar>div>button[data-color-bar]:after{background:var(--treb-color-bar-color,var(--treb-default-color,unset));border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));box-sizing:border-box;content:"";display:block;height:6px;position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon]:before,.treb-main.treb-main .treb-toolbar>button[data-command]:before,.treb-main.treb-main .treb-toolbar>button[data-icon]:before,.treb-main.treb-main .treb-toolbar>div>button[data-command]:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon]:before{background:currentColor;content:"";display:block;height:20px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:var(--icon-size,16px 16px);-webkit-mask-size:var(--icon-size,16px 16px);position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-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=indent]{--icon:var(--icon-text-indent)}.treb-main.treb-main .treb-toolbar [data-command=outdent]{--icon:var(--icon-text-outdent)}.treb-main.treb-main .treb-toolbar [data-command=align-top]{--icon:var(--icon-text-align-top)}.treb-main.treb-main .treb-toolbar [data-command=align-middle]{--icon:var(--icon-text-align-middle)}.treb-main.treb-main .treb-toolbar [data-command=align-bottom]{--icon:var(--icon-text-align-bottom)}.treb-main.treb-main .treb-toolbar [data-command=merge-cells]{--icon:var(--icon-merge-cells)}.treb-main.treb-main .treb-toolbar [data-command=unmerge-cells]{--icon:var(--icon-unmerge-cells)}.treb-main.treb-main .treb-toolbar [data-command=fill-color]{--icon:var(--icon-fill-color)}.treb-main.treb-main .treb-toolbar [data-command=text-color]{--icon:var(--icon-text-color)}.treb-main.treb-main .treb-toolbar [data-command=lock-cells]{--icon:var(--icon-lock)}.treb-main.treb-main .treb-toolbar [data-command=wrap-text]{--icon:var(--icon-wrap-text)}.treb-main.treb-main .treb-toolbar [data-icon=comment]{--icon:var(--icon-comment)}.treb-main.treb-main .treb-toolbar [data-icon=table]{--icon:var(--icon-table)}.treb-main.treb-main .treb-toolbar [data-icon=layout]{--icon:var(--icon-layout)}.treb-main.treb-main .treb-toolbar [data-command=freeze-panes]{--icon:var(--icon-freeze)}.treb-main.treb-main .treb-toolbar [data-command=insert-column-chart]{--icon:var(--icon-column-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-donut-chart]{--icon:var(--icon-donut-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-bar-chart]{--icon:var(--icon-bar-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-line-chart]{--icon:var(--icon-line-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-image]{--icon:var(--icon-image)}.treb-main.treb-main .treb-toolbar [data-command=border-bottom]{--icon:var(--icon-border-bottom)}.treb-main.treb-main .treb-toolbar [data-command=border-left]{--icon:var(--icon-border-left)}.treb-main.treb-main .treb-toolbar [data-command=border-right]{--icon:var(--icon-border-right)}.treb-main.treb-main .treb-toolbar [data-command=border-top]{--icon:var(--icon-border-top)}.treb-main.treb-main .treb-toolbar [data-command=border-outside]{--icon:var(--icon-border-outer)}.treb-main.treb-main .treb-toolbar [data-command=border-all]{--icon:var(--icon-border-all)}.treb-main.treb-main .treb-toolbar [data-command=border-none]{--icon:var(--icon-border-none)}.treb-main.treb-main .treb-toolbar [data-command=border-double-bottom]{--icon:var(--icon-border-double-bottom)}.treb-main.treb-main .treb-toolbar [data-icon=palette]{--icon:var(--icon-palette)}.treb-main.treb-main .treb-toolbar [data-command=recalculate]{--icon:var(--icon-recalculate);--icon-size:20px 20px}.treb-main.treb-main .treb-toolbar .treb-font-scale{width:4em}.treb-main.treb-main .treb-toolbar .treb-number-format{width:8em}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]{align-items:center;display:flex;justify-content:center;padding:0;width:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser>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 .treb-toolbar .treb-font-scale{padding-left:2em;text-align:right;width:5em}.treb-main.treb-main .treb-toolbar [composite][font-scale]{position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon{border-radius:3px;left:.5em;line-height:1;opacity:.9;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after,.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{content:"A";position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{font-size:1.2em}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after{font-size:.9em;left:-.125em}.treb-main.treb-main{all:revert;box-sizing:border-box;color:inherit;color-scheme:var(--treb-color-scheme,unset);display:grid;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif");font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:14px;font-style:normal;font-weight:400;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr);height:100%;line-height:normal;position:relative;text-align:start;width:100%}.treb-main.treb-main a,.treb-main.treb-main button,.treb-main.treb-main div,.treb-main.treb-main input,.treb-main.treb-main li,.treb-main.treb-main ol,.treb-main.treb-main svg,.treb-main.treb-main textarea,.treb-main.treb-main ul{all:revert;box-sizing:border-box;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif")}.treb-main.treb-main button,.treb-main.treb-main input{color:inherit;font:inherit}.treb-main.treb-main *{box-sizing:border-box}.treb-main.treb-main [contenteditable]{-webkit-user-modify:read-write;-moz-user-modify:read-write}.treb-main.treb-main[animate] .treb-layout-header{transition:height var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-header{grid-column:1/3;grid-row:1;height:1px;opacity:0}.treb-main.treb-main[toolbar] .treb-layout-header{height:42px;opacity:1}.treb-main.treb-main[dialog] .treb-layout-header,.treb-main.treb-main[dialog]>*{opacity:.6}.treb-main.treb-main[dialog] .treb-dialog-mask{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-layout-spreadsheet{display:flex;flex-direction:row;gap:1em;grid-column:1;grid-row:2;position:relative;transition:opacity .2s ease;z-index:5}.treb-main.treb-main .treb-views.treb-can-revert .treb-view .treb-revert-indicator{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-view{display:grid;flex:1 1 0px;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;position:relative}.treb-main.treb-main .treb-view .treb-spreadsheet-backdrop{box-shadow:0 4px 6px -4px rgba(0,0,0,.4);grid-column:1;grid-row:2;z-index:2}.treb-main.treb-main .treb-view .treb-spreadsheet-body{position:relative;z-index:4}.treb-main.treb-main .treb-view .treb-spreadsheet-footer{position:relative;z-index:5}.treb-main.treb-main .treb-view .treb-layout-resize-handle,.treb-main.treb-main .treb-view .treb-revert-indicator{display:none}.treb-main.treb-main .treb-view:first-of-type .treb-revert-indicator{align-self:start;border-color:orange transparent transparent orange;border-style:solid;border-width:.5em;display:block;grid-area:2/1/3/2;height:1rem;justify-self:start;opacity:0;overflow:hidden;pointer-events:none;position:relative;transition:opacity .125s ease;width:1rem;z-index:20}.treb-main.treb-main .treb-view:last-of-type .treb-layout-resize-handle{align-self:end;border-bottom:.5rem solid var(--treb-resize-handle-color,#0059b9);border-left:.5rem solid transparent;border-right:.5rem solid var(--treb-resize-handle-color,#0059b9);border-top:.5rem solid transparent;cursor:nw-resize;display:block;grid-area:2/1/3/2;height:1rem;justify-self:end;width:1rem;z-index:20}.treb-main.treb-main[animate] .treb-layout-sidebar{transition:width var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-sidebar{align-items:center;display:flex;flex-direction:column;gap:.75rem;grid-column:2;grid-row:2;justify-content:flex-start;overflow:hidden;padding-top:3rem;width:2.5rem;width:3rem}.treb-main.treb-main[collapsed] .treb-layout-sidebar{opacity:0;width:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button{background:var(--treb-toolbar-button-background,#fff);border-bottom-right-radius:0;border-color:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-right-color:var(--treb-toolbar-button-background,transparent);border-top-right-radius:0;right:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button:after{mask-image:var(--icon-chevron-left);-webkit-mask-image:var(--icon-chevron-left)}.treb-main.treb-main .treb-layout-sidebar>button,.treb-main.treb-main .treb-toggle-sidebar-button{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-layout-sidebar>button:after,.treb-main.treb-main .treb-toggle-sidebar-button:after{background:#ccc;content:"";display:block;height:24px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;transition:background-color .1s ease;width:24px}.treb-main.treb-main .treb-layout-sidebar>button[data-can-revert=false],.treb-main.treb-main .treb-toggle-sidebar-button[data-can-revert=false]{display:none}.treb-main.treb-main .treb-layout-sidebar>button:hover:after,.treb-main.treb-main .treb-toggle-sidebar-button:hover:after{background:#666}.treb-main.treb-main .treb-layout-sidebar>button[data-command=recalculate],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=recalculate]{--icon:var(--icon-reset)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=toggle-toolbar],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=toggle-toolbar]{--icon:var(--icon-toolbar)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=revert],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=revert]{--icon:var(--icon-revert)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=export-xlsx],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=export-xlsx]{--icon:var(--icon-export)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=about],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=about]{--icon:var(--icon-about)}.treb-main.treb-main .treb-toggle-sidebar-button{align-items:center;background:transparent;border:1px solid transparent;border-radius:12px;bottom:6rem;display:flex;height:24px;justify-content:center;margin:0;padding:0;position:absolute;right:.5rem;right:calc(1.5rem - 12px);width:24px;z-index:39}.treb-main.treb-main .treb-toggle-sidebar-button:after{height:12px;mask-image:var(--icon-chevron-right);-webkit-mask-image:var(--icon-chevron-right);width:12px}.treb-main.treb-main .treb-resize-rect{border:1px dotted var(--treb-resize-frame-color,blue);display:block;height:100%;left:0;position:fixed;top:0;width:100%;z-index:9998}.treb-main.treb-main .treb-resize-mask{height:100vh;left:0;position:fixed;top:0;width:100vw;z-index:9999}treb-spreadsheet{display:block;overflow:hidden;position:relative}.treb-default-size{height:550px;width:800px}`;var gn='<div class="treb-main treb-theme"><div class="treb-layout-header treb-animate"><div class="treb-toolbar"></div></div><div class="treb-dialog-mask"><div data-bind="dialog" class="treb-embed-dialog"><div data-bind="left"><a href="https://treb.app" target="_blank"><div class="treb-icon-64"></div></a></div><div data-bind="middle"><div data-bind="title" class="treb-embed-dialog-title"></div><div data-bind="message" class="treb-embed-dialog-message"></div><div data-bind="about" class="treb-embed-dialog-body"></div></div><button type="button" data-title="close_dialog" data-bind="close" class="treb-close-box"><svg viewBox="0 0 16 16"><path d="M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"/><path d="M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"/></svg></button></div></div><div class="treb-layout-spreadsheet treb-views"><template class="treb-view-template"><div class="treb-view"><div class="treb-formula-bar notranslate" hidden><div class="treb-address-label"><div></div></div><button class="treb-insert-function-button" data-title="insert_function" data-conditional="insert-function">\u{1D453}<small>(x)</small></button><div class="treb-editor-container"><div contenteditable="true"></div></div></div><div class="treb-spreadsheet-backdrop"></div><div class="treb-spreadsheet-body" role="grid"><div class="treb-grid" tabindex="-1"><div class="treb-overlay-container notranslate" translate="no"><div class="treb-overlay-inset"><div class="treb-overlay-editor" contenteditable tabindex="-1" spellcheck="true" role="gridcell"></div></div></div></div></div><div class="treb-spreadsheet-footer" hidden><button class="treb-delete-tab" data-title="delete_sheet" data-command="delete-tab" data-conditional="delete-tab"><svg tabindex="-1" viewbox="0 0 16 16"><path d="M4,4 L12,12 M12,4 L4,12"/></svg></button><div class="treb-spreadsheet-tab-container"><ol class="treb-spreadsheet-tabs" role="tablist"></ol></div><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" data-title="add_sheet">+</button><div class="treb-stats-panel"></div><div class="treb-scale-control" data-conditional="scale-control"></div></div><div class="treb-layout-resize-handle" data-conditional="resize"></div><div class="treb-revert-indicator" data-command="revert-indicator" data-title="document_modified"></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" data-title="recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" data-title="toggle_toolbar"></button> <button data-command="export-xlsx" data-conditional="export" data-title="export"></button> <button data-command="revert" data-conditional="revert" data-title="revert"></button> <button data-command="about" data-title="about"></button></div><button class="treb-toggle-sidebar-button" data-title="toggle_sidebar"></button></div>';var _n='<div class="treb-menu" title="File menu" file-menu><button data-icon="file-menu" menu-target></button><div><button data-command="reset">New document</button><div separator></div><button data-command="import-file">Open file...</button> <button data-command="save-json">Save JSON</button><div separator xlsx-support></div><button data-command="export-xlsx" xlsx-support>Export XLSX</button></div></div><div composite narrow><button data-command="justify-left" data-target="justify" title="Left-align text"></button><div class="treb-menu"><button dropdown title="Text justify options"></button><div class="treb-icon-buttons" data-replace="justify"><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div></div></div><div composite narrow><button data-command="align-top" data-target="align" title="Align to top"></button><div class="treb-menu"><button dropdown title="Text align options"></button><div class="treb-icon-buttons" data-replace="align"><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div></div></div><div class="group" wide><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div><div class="group" wide><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div><div class="group" wide indent-group><button data-command="outdent" title="Decrease indent"></button> <button data-command="indent" title="Incrase indent"></button></div><div class="group"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-inactive-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-inactive-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-inactive-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-inactive-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-inactive-title="Comment" data-active-title="Update comment"></button><div class="treb-comment-box"><textarea></textarea><div><button data-command="clear-comment">Clear</button> <button data-command="update-comment">Save</button></div></div></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown title="Border options"></button><div class="treb-icon-buttons" data-replace="border"><button data-command="border-top" title="Top border"></button> <button data-command="border-left" title="Left border"></button> <button data-command="border-right" title="Right border"></button> <button data-command="border-bottom" title="Bottom border"></button> <button data-command="border-double-bottom" title="Double bottom border"></button> <button data-command="border-outside" title="Outside borders"></button> <button data-command="border-all" title="All borders"></button> <button data-command="border-none" title="Clear borders"></button><div separator></div><div class="treb-menu treb-color-menu treb-submenu" data-color-command="border-color" data-replace-color="border" title="Border color" data-default-color-text="Default border color"><button data-icon="palette" data-color-bar="border" data-color="{}"></button></div></div></div></div><div composite><button data-command="fill-color" data-color-bar="fill" data-color="{}" title="Fill color"></button><div class="treb-menu treb-color-menu" data-color-command="fill-color" data-replace-color="fill" data-default-color-text="No fill"><button dropdown title="Color options"></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></div><div class="treb-caption">Other colors</div><div class="treb-swatches"></div><div><input placeholder="New color" class="treb-color-input"> <button data-command="set-color" data-color=""><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg></button></div></div></div></div><div composite><button data-command="text-color" data-color-bar="text" data-color="{}" title="Text color"></button><div class="treb-menu treb-color-menu" data-color-command="text-color" data-replace-color="text" data-default-color-text="Default text color"><button dropdown title="Color options"></button></div></div><div composite font-scale><div class="treb-font-scale-icon"></div><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown title="Font scale options"></button><div><button data-command="font-scale" data-scale="0.8">0.80</button> <button data-command="font-scale" data-scale="0.9">0.90</button> <button data-command="font-scale" data-scale="1.0">1.00</button> <button data-command="font-scale" data-scale="1.1">1.10</button> <button data-command="font-scale" data-scale="1.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 composite><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown title="Number formats"></button><div class="treb-number-format-menu"></div></div></div><div class="treb-split"><button data-command="decrease-precision" title="Decrease precision"></button> <button data-command="increase-precision" title="Increase precision"></button></div><div class="treb-menu"><button data-icon="layout" title="Rows & columns"></button><div><button data-command="insert-row">Insert row</button> <button data-command="insert-column">Insert column</button> <button data-command="delete-row">Delete row</button> <button data-command="delete-column">Delete column</button><div separator add-remove-sheet></div><button data-command="insert-sheet" add-remove-sheet>Add sheet</button> <button data-command="delete-sheet" add-remove-sheet>Delete sheet</button></div></div><div composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown title="Chart options"></button><div class="treb-icon-buttons" data-replace="annotation"><button data-command="insert-column-chart" title="Insert column chart"></button> <button data-command="insert-donut-chart" title="Insert donut chart"></button> <button data-command="insert-bar-chart" title="Insert bar chart"></button> <button data-command="insert-line-chart" title="Insert line chart"></button><div separator></div><button data-command="insert-image" title="Insert image"></button></div></div></div><button data-command="recalculate" title="Recalculate" recalculate-button></button>';var yn={close_dialog:"Close dialog",insert_function:"Insert function...",delete_sheet:"Delete current sheet",add_sheet:"Add sheet",document_modified:"This document has been modified from the original version.",recalculate:"Recalculate",toggle_toolbar:"Toggle toolbar",export:"Export as XLSX",revert:"Revert to original version",about:"What's this?",toggle_sidebar:"Toggle sidebar"},Ye=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=P.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:bn,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 o of n){let a=o.split(/=/);a.length===1?e[a[0]]=!0:e[a[0]]=this.CoerceAttributeValue(a[1])}}continue;case"data-treb":continue;case"inline-document":continue;case"src":e.document=this.root.getAttribute("src")||void 0;continue}e[r.replace(/-/g,"_")]=this.CoerceAttributeValue(this.root.getAttribute(r))}}return{...e}}AttachElement(e={}){if(e={...this.ParseOptionAttributes(),...e},this.root){if(!e.headless){let t=this.root.getBoundingClientRect();(!t.width||!t.height)&&this.root.classList.add("treb-default-size")}if(this.root.hasAttribute("inline-document")){let t=this.root.getAttribute("inline-document")||"";for(let r of Array.from(this.root.children))if(this.DOM.view&&r instanceof this.DOM.view.HTMLScriptElement&&r.type==="application/json"){let i=r.getAttribute("name")||"";if(i===t||!i&&t==="true"){let n=r.textContent;if(n)try{e.inline_document=JSON.parse(n)}catch(o){console.error(o)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=gn,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new lr(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 l=this.layout_element;i.addEventListener("click",()=>{let d=l.getAttribute("collapsed");typeof d=="string"&&(d===""||d==="true")?l.removeAttribute("collapsed"):l.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",l=>{let d=l.target;if(d.dataset.command)switch(d.dataset.command){case"toggle-toolbar":this.ToggleToolbar();break;default:e.HandleToolbarMessage({command:d.dataset.command});break}}),e.options.toolbar&&this.AttachToolbar(e,t);let a={"table-button":!!e.options.table_button,revert:!!e.options.revert_button,toolbar:!!e.options.toolbar,export:!!e.options.export,"insert-function":!!e.options.insert_function_button,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[l,d]of Object.entries(a))if(!d){let h=this.layout_element.querySelectorAll(`[data-conditional=${l}]`);for(let u of Array.from(h))u.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let l={width:0,height:0},d={x:0,y:0},h={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let u,m,f=t.querySelector(".treb-layout-resize-handle"),p=()=>g(),b=C=>{C.buttons===0?g():(h.x=C.screenX-d.x,h.y=C.screenY-d.y,m&&(m.style.width=l.width+h.x+"px",m.style.height=l.height+h.y+"px"))},g=()=>{if(h.x||h.y){let C=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=C.width+h.x+"px"),t.style.height=C.height+h.y+"px"}u&&(u.removeEventListener("mouseup",p),u.removeEventListener("mousemove",b),u.parentElement?.removeChild(u),u=void 0),m?.parentElement?.removeChild(m),m=void 0};f.addEventListener("mousedown",C=>{C.stopPropagation(),C.preventDefault();let x=t.querySelector(".treb-main");m=this.DOM.Div("treb-resize-rect",x),u=this.DOM.Div("treb-resize-mask",x,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:p,mousemove:b}}),d.x=C.screenX,d.y=C.screenY,h.x=0,h.y=0;let v=this.views?.querySelectorAll(".treb-spreadsheet-body"),_=Array.from(v||[]).map(w=>w.getBoundingClientRect());if(_.length){let w=JSON.parse(JSON.stringify(_.shift()));for(let I of _)w.top=Math.min(I.top,w.top),w.left=Math.min(I.left,w.left),w.right=Math.max(I.right,w.right),w.bottom=Math.max(I.bottom,w.bottom);let A=w.right-w.left,S=w.bottom-w.top;m.style.top=w.top+"px",m.style.left=w.left+"px",m.style.width=A+"px",m.style.height=S+"px",l.width=A,l.height=S}})}let s=Array.from(this.layout_element.querySelectorAll("[data-title]"));for(let l of s)if(l instanceof HTMLElement){if(l.dataset.activeTitle)continue;l.dataset.title&&yn[l.dataset.title]&&(l.title=yn[l.dataset.title])}setTimeout(()=>this.layout_element?.setAttribute("animate",""),250)}ToggleToolbar(){if(this.layout_element){let e=this.layout_element.getAttribute("toolbar");typeof e=="string"&&(e===""||e==="true")?this.layout_element.removeAttribute("toolbar"):this.layout_element.setAttribute("toolbar","")}}UpdateSelectionStyle(e,t,r){let i=e.selection_state;r.value="";for(let s of Object.values(this.toolbar_controls))s&&(s.removeAttribute("active"),s.dataset.inactiveTitle&&(s.title=s.dataset.inactiveTitle));let n=s=>{s&&(s.setAttribute("active",""),s.dataset.activeTitle&&(s.title=s.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 o=this.toolbar_controls.format;o&&(i.style?.number_format?o.value=z.SymbolicName(i.style.number_format)||i.style.number_format:o.value="General");let a=this.toolbar_controls.scale;switch(a&&(a.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 a=this.DOM.Fragment(),s=e.document_styles.theme_colors.length,l=["Background","Text","Background","Text","Accent"];if(s){let m=e.document_styles.theme_colors[0].length;for(let f=0;f<m;f++)for(let p=0;p<s;p++){let b=e.document_styles.theme_colors[p][f],g=`background: ${b.resolved};`,C=l[p]||l[4];Ze(b.color)&&b.color.tint?C+=` (${(b.color.tint>0?"+":"")+b.color.tint*100}%)`:p===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",b.resolved):p===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",b.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",b.resolved)),this.DOM.Create("button",void 0,a,{attrs:{style:g,title:C},data:{command:"set-color",color:JSON.stringify(b.color)}})}}this.swatch_lists.theme?.replaceChildren(a),a=this.DOM.Fragment(),this.DOM.Create("button","treb-default-color",a,{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,a,{attrs:{style:f,title:m},data:{command:"set-color",color:JSON.stringify({text:m.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(a)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],i=["Timestamp","Long Date","Short Date"];for(let a of e.document_styles.number_formats){if(z.SymbolicName(z.Translate(a)))continue;z.Get(a).date_format?i.push(a):r.push(a)}let n=a=>this.DOM.Create("button",void 0,void 0,{text:a,data:{format:a,command:"number-format"}}),o=this.DOM.Fragment();o.append(...r.map(a=>n(a))),o.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),o.append(...i.map(a=>n(a))),t.textContent="",t.append(o)}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=_n;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.indent_buttons||n.push(i.querySelector("[indent-group]")),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 x of n)x&&x.parentElement?.removeChild(x);let o=i.querySelector(".treb-color-chooser"),a=i.querySelector(".treb-comment-box textarea");for(let[x,v]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 _=i.querySelector(v);_&&(this.toolbar_controls[x]=_)}let s=o.querySelectorAll(".treb-swatches");this.swatch_lists={theme:s[0],other:s[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]"),a.addEventListener("keydown",x=>{x.key==="Enter"&&(x.shiftKey||x.ctrlKey)&&l.click()});for(let x of["border","annotation","align","justify"])this.replace_targets[x]=i.querySelector(`[data-target=${x}`);for(let x of["fill","text","border"])this.color_bar_elements[x]=i.querySelector(`[data-color-bar=${x}]`);i.addEventListener("click",x=>{let v=x.target,_={format:v.dataset.format,scale:v.dataset.scale},w=v?.dataset.command;if(w){let A=v.parentElement?.dataset.replace;if(A){let S=this.replace_targets[A];S&&(S.dataset.command=w,S.title=v.title||"")}switch(/^border-/.test(w)&&(_.color=this.border_color||{}),w){case"text-color":case"fill-color":_.color={};try{_.color=JSON.parse(v.dataset.color||"{}")}catch(S){console.error(S)}break;case"set-color":w=o.dataset.colorCommand||"",_.color={};try{_.color=JSON.parse(v.dataset.color||"{}")}catch(S){console.error(S)}if(w==="border-color"&&(this.border_color=_.color),o.dataset.target){let S=this.color_bar_elements[o.dataset.target];S&&(S.style.setProperty("--treb-color-bar-color",v.style.backgroundColor),S.dataset.color=v.dataset.color||"{}")}break;case"update-comment":_.comment=a.value;break}e.HandleToolbarMessage({command:w,..._})}});let d=(x,v)=>{let _=i.querySelector(x);if(_){let w="";_.addEventListener("focusin",()=>w=_.value),_.addEventListener("keydown",A=>{switch(A.key){case"Escape":_.value=w,e.Focus();break;case"Enter":v(_.value)||(_.value=w,e.Focus());break;default:return}A.stopPropagation(),A.preventDefault()})}};d("input.treb-number-format",x=>x?(e.HandleToolbarMessage({command:"number-format",format:x}),!0):!1),d("input.treb-font-scale",x=>{let v=Number(x);return!v||isNaN(v)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:v}),!0)});let h=o.querySelector("input"),u=o.querySelector("input + button");h.addEventListener("input",x=>{if(x instanceof InputEvent&&x.isComposing)return;u.style.background=h.value||"";let v=u.style.backgroundColor||"#fff",_=ye.MeasureColor(v),w=K.RGBToHSL(_[0],_[1],_[2]);u.style.color=w.l>.5?"#000":"#fff",u.dataset.color=JSON.stringify(u.style.backgroundColor?{text:u.style.backgroundColor}:{})}),h.addEventListener("keydown",x=>{x.key==="Enter"&&(x.stopPropagation(),x.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=x=>{x.key==="Escape"&&(x.stopPropagation(),x.preventDefault(),Promise.resolve().then(()=>e.Focus()))},p=x=>{if(m){if(x.relatedTarget instanceof Node&&i.contains(x.relatedTarget))return;i.removeEventListener("keydown",f),i.removeEventListener("focusout",p),m=!1}},b=x=>{let v=x.target,_=v?.parentElement;if(v?.classList.contains("treb-menu")){_=v;for(let w of Array.from(_.children))if(w.tagName==="BUTTON"){v=w;break}}else if(!_?.classList.contains("treb-menu"))return;if(v&&_){m||(i.addEventListener("focusout",p),i.addEventListener("keydown",f),m=!0),_.dataset.colorCommand&&(o.querySelector(".treb-default-color")?.setAttribute("title",_.dataset.defaultColorText||"Default color"),_.appendChild(o),o.dataset.colorCommand=_.dataset.colorCommand,o.dataset.target=_.dataset.replaceColor||"");let w=_.querySelector("div"),A=r.getBoundingClientRect(),S=v.getBoundingClientRect(),{left:I}=S,L=_.parentElement;L?.hasAttribute("composite")&&(I=L.firstElementChild.getBoundingClientRect().left);let Z=w.getBoundingClientRect();_.classList.contains("treb-submenu")?(w.style.top=S.top-Z.height/2+"px",I+S.width+6+Z.width>A.right?w.style.left=I-6-Z.width+"px":w.style.left=I+S.width+6+"px"):(w.style.top=S.bottom+"px",I+Z.width>A.right-6?w.style.left=S.right-Z.width+"px":w.style.left=I+"px");let _e=w.querySelector("textarea");_e&&requestAnimationFrame(()=>_e.focus())}},g=this.root?.querySelector(".treb-number-format-menu");g&&(this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a),e.Subscribe(x=>{switch(x.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a),this.UpdateRevertState(e);break;case"theme-change":this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a);break;case"selection":this.UpdateSelectionStyle(e,i,a);break}}));let C=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i.addEventListener("focusin",x=>{b(x)}),C){let x=Array.from(i.querySelectorAll(".treb-menu"));for(let v of x)v.tabIndex=0;i.addEventListener("mousedown",v=>{b(v)})}}};var cr=class{version="29.5.1";CreateSpreadsheet(e){let t=e.container,r=new Ye(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},Yo=new cr;if(typeof HTMLElement<"u"){class c extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new Ye(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{Yo as TREB,cr 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,o=e.split(/\./).filter(s=>s.trim().length),a=o.length?o[o.length-1].toLowerCase():"treb";if(o.length<=1||e==="treb.json")if(e==="treb.json"&&(a=e),(a==="csv"||a==="tsv")&&this.grid.model.sheets.length>1){let s=this.grid.active_sheet.name;e=(r+"-"+s).toLowerCase().replace(/\W+/g,"-")+"."+a}else e=r.toLowerCase().replace(/\W+/g,"-")+"."+a;switch(a){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 s=new Blob([n],{type:"text/plain;charset=utf-8"});this.SaveAs(s,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=V(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=tt(i)?new y(i.start,i.end):new y(i)}if(V(e)&&(e=new y(e)),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.Serialize(e),r={app:"@trebco/treb",version:"29.5.4",revision:this.file_version,name:this.grid.model.document_name,user_data:this.grid.model.user_data,decimal_mark:N.decimal_separator,...t};if(e.share_resources){let i=1,n=new Map,o=Array.isArray(r.sheet_data)?r.sheet_data:[r.sheet_data],a=l=>{let d=n.get(l);return d||(d=(i++).toString(),n.set(l,d)),`resource:${d}`};for(let l of o)if(l){l.background_image&&(l.background_image=a(l.background_image));for(let d of l.annotations||[])d.type==="image"&&d.data?.src&&(d.data.src=a(d.data.src))}let s={};for(let[l,d]of n.entries())s[d]=l;r.shared_resources=s}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"})}ScrollIntoView(e,t=!1){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(r)?r:r.start}this.grid.ScrollIntoView(e,t)}ScrollTo(e,t={}){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(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 V(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 ce.TryParse(e).value}FormatNumber(e,t="General"){return z.Get(t).Format(e)}SpreadsheetDate(e){return e instanceof Date&&(e=e.getTime()),Ce(e,!0)}JavascriptDate(e){return we(e).getTime()}ApplyBorders(e,t,r=1){this.grid.ApplyBorders2(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,{},r)}ApplyStyle(e,t={},r=!0){this.grid.ApplyStyle(e?this.model.ResolveArea(e,this.grid.active_sheet):void 0,t,r)}ClearName(e){this.grid.SetName(e)}DefineName(e,t,r,i=!1){if(typeof t>"u"||t===null)throw new Error("invalid value (null or undefined)");if(typeof r=="string"){let n=this.model.sheets.ID(r);if(typeof n=="number")r=n;else throw new Error("invalid scope; use a sheet name or sheet id")}if(typeof t=="object"&&(V(t)||tt(t))){this.grid.SetName(e,this.model.ResolveArea(t,this.grid.active_sheet),void 0,r,i);return}if(typeof t=="string"){let n=this.parser.Parse(t);if(!n.expression)throw new Error("invalid expression");switch(n.expression.type){case"address":case"range":this.grid.SetName(e,this.model.ResolveArea(n.expression,this.grid.active_sheet),void 0,r,i);return}this.grid.SetName(e,void 0,t,r,i)}else this.grid.SetName(e,void 0,t.toString(),r,i)}SetLink(e,t=""){if(typeof e=="string"){let r=this.model.ResolveAddress(e,this.grid.active_sheet);e=V(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 i=this.GetSelectionReference();i.empty||(e=i.area)}if(!e)return;let r=t.type;return r||(t.formatted&&(r="formatted"),t.formula&&(r="A1")),r==="formula"&&(r="A1"),this.grid.GetRange(this.model.ResolveAddress(e,this.grid.active_sheet),r)}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,o=Math.max(0,...t.map(s=>s.length)),a={row:i.start.row+n+1,column:i.start.column+o+1};i.ConsumeAddress(a)}return this.grid.SetRange(i,t,r)}}Subscribe(e){return this.events.Subscribe(e)}Cancel(e){this.events.Cancel(e)}Serialize(e={}){let t=this.grid.active_sheet;t.selection=JSON.parse(JSON.stringify(this.grid.GetSelection()));let r=this.grid.ScrollOffset();r&&(t.scroll_offset=r);let i=this.model.sheets.list.map(s=>s.toJSON(e)),n;this.model.tables.size>0&&(n=Array.from(this.model.tables.values()));let o;if(this.model.macro_functions.size){o=[];for(let s of this.model.macro_functions.values())o.push({...s,expression:void 0})}let a=this.model.SerializeNames(t);return{sheet_data:i,active_sheet:t.id,named:a.length?a:void 0,macro_functions:o,tables:n}}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 Ct(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);V(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()),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.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 t="hyperlink invalid target",r=e.data.reference||"";if(typeof r=="string"){if(/^https{0,1}:\/\//i.test(r)){if(!this.options.hyperlinks){console.warn("hyperlinks are disabled");return}let i=this.DOM.Create("a");i.setAttribute("target",this.options.hyperlinks),i.setAttribute("href",r),i.setAttribute("noreferrer","true"),i.setAttribute("nofollow","true"),i.click();return}else{let i=this.parser.Parse(r);if(i.expression){if(i.expression.type==="address"){(i.expression.sheet||i.expression.sheet_id)&&this.ActivateSheet(i.expression.sheet||i.expression.sheet_id),this.Select(r);return}else if(i.expression.type==="range"){(i.expression.start.sheet||i.expression.start.sheet_id)&&this.ActivateSheet(i.expression.start.sheet||i.expression.start.sheet_id),this.Select(r);return}}}console.warn(t,2);return}}}OnSheetChange(e){for(let t of e.activate.annotations)this.InflateAnnotation(t),this.calculator.UpdateAnnotations(t,e.activate);this.UpdateAnnotations(),this.calculator.UpdateConditionals(),this.ApplyConditionalFormats(e.activate,!0)}HandleDrag(e){if(e.dataTransfer&&e.dataTransfer.types){if(e.dataTransfer.types.some&&e.dataTransfer.types.some(t=>t==="Files"))e.preventDefault();else for(let t=0;t<e.dataTransfer.types.length;t++)if(e.dataTransfer.types[t]==="files"){e.preventDefault();return}}}HandleDrop(e){if(e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length){e.preventDefault();let t=e.dataTransfer.files[0];/^image/.test(t.type)?this.InsertImageInternal(t):this.LoadFileInternal(t,"drag-and-drop").catch(()=>{})}}SelectFile2(e,t){if(!this.file_chooser){let r=this.DOM.Create("input",void 0,void 0,{attrs:{type:"file"},events:{change:()=>{if(r.files&&r.files[0]){let 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 o;if(typeof n.result=="string")o=n.result;else{o="";let s=new Uint8Array(n.result);for(let l=0;l<s.byteLength;l++)o+=String.fromCharCode(s[l])}let a=this.DOM.Create("img");a.src=o,await Promise.resolve(),this.grid.CreateAnnotation({type:"image",formula:"",data:{scale:"",src:o,original_size:{width:a.width||300,height:a.height||300}}},void 0,void 0,{top:30,left:30,width:a.width||300,height:a.height||300})}r()}catch(o){i(o)}},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,o)=>{let a=s=>{i.onload=null,i.onabort=null,i.onerror=null,s?(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(s)),o(s)):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"?a("Unsupported file"):this.ImportXLSX(i.result,t).then(()=>a()).catch(s=>a(s));return}else{let s=JSON.parse(i.result);this.LoadDocument(s,{source:t})}a()}catch(s){a(s?.toString())}},i.onabort=()=>{a("Aborted")},i.onerror=()=>{a("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){let t=e.temp;if(t.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;for(let i of e.view)i.dirty=!0}let r=e.view[this.grid.view_index]||{};r.dirty&&(r.update_callback&&r.update_callback(),this.grid.AnnotationUpdated(e))}this.UpdateConnectedElements()}UpdateConnectedElements(){for(let e of this.model.connected_elements.values()){let t=e.internal;if(t?.vertex&&t.vertex.state_id!==t.state){t.state=t.vertex.state_id;let r=e.update;r&&Promise.resolve().then(()=>r.call(0,e))}}}RebuildAllAnnotations(){for(let e of this.grid.active_sheet.annotations){this.InflateAnnotation(e);let t=e.view[this.grid.view_index]||{};t.resize_callback&&t.resize_callback(),t.update_callback&&t.update_callback()}}InflateAnnotations(){for(let e of this.grid.active_sheet.annotations)this.InflateAnnotation(e)}InflateAnnotation(e){if(this.grid.headless)return;let t=e.view[this.grid.view_index]||{};if(t.inflated){e.dirty&&(t.resize_callback&&t.resize_callback(),e.dirty=!1);return}if(t.inflated=!0,e.dirty&&(e.dirty=!1),t.content_node){if(e.data.type==="treb-chart"){let r=this.CreateChart();r.Initialize(t.content_node);let 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,s=>((s.type==="address"||s.type==="range")&&this.model.ResolveSheetID(s,void 0,this.grid.active_sheet),!0));let o=n.expression.name.toLowerCase(),a=this.calculator.CalculateExpression(n.expression);r.Exec(o,a)}}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"){if(typeof e.data.data?.src=="string"){let r=wt(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)}}}else if(e.data.type==="textbox"&&e.data.data){let r=document.createElement("div");r.classList.add("treb-annotation-textbox");for(let i of e.data.data.paragraphs){let n=document.createElement("p");i.style&&(i.style.horizontal_align==="right"||i.style.horizontal_align==="center")&&(n.style.textAlign=i.style.horizontal_align);for(let o of i.content){let a=document.createElement("span");a.textContent=o.text||"",o.style?.bold&&(a.style.fontWeight="600"),o.style?.italic&&(a.style.fontStyle="italic"),n.appendChild(a)}r.append(n)}if(t.content_node.append(r),e.data.data.style){let i=e.data.data.style,n=()=>{if(i.fill){let o=R(this.grid.theme,i.fill);r.style.background=o}};t.update_callback=()=>{this.grid.headless||n()},n()}}}}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 o=0,a=i.length;o<a;o++)r=(r<<5)-r+i.charCodeAt(o),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 o=n-16;this.undo_stack=this.undo_stack.slice(o),this.undo_pointer-=o}}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(){let e={},t={};for(let i of this.grid.model.sheets.list)i.NumberFormatsAndColors(t,e);this.document_styles.colors=Object.keys(t),this.document_styles.number_formats=Object.keys(e),this.document_styles.theme_colors=[];let r=[.5,.25,0,-.25,-.5];for(let i=0;i<10;i++)this.document_styles.theme_colors.push(r.map(n=>{let o={theme:i,tint:n},a=R(this.grid.theme,o);return{color:o,resolved:a}}))}ConvertLocale(e){let t=new He;t.flags={...this.parser.flags};let r,i;e.decimal_mark==="."?(t.SetLocaleSettings("."),r=",",i=";"):(t.SetLocaleSettings(","),r=".",i=",");let n=o=>{let a=t.Parse(o);if(a.expression)return"="+t.Render(a.expression,{missing:"",convert_decimal:r,convert_argument_separator:i})};if(e.macro_functions)for(let o of e.macro_functions){let a=n(o.function_def);a&&(o.function_def=a)}if(e.sheet_data){let o=Array.isArray(e.sheet_data)?e.sheet_data:[e.sheet_data];for(let a of o){if(a.annotations){for(let s of a.annotations)if(s.formula){let l=n(s.formula);l&&(s.formula=l)}}if(a.data?.length)for(let s of a.data){let l=wr(s)?[s]:s.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(a=>Number(a)||0).concat([0,0,0]),i=t.split(".").map(a=>Number(a)||0).concat([0,0,0]),n=[0,1,2],o={match:0};for(let a=0;a<3;a++)if(r[a]!==i[a]){o.match=r[a]>i[a]?1:-1,o.level=n[a];break}return o}ImportDocumentData(e,t){this.file_version=e.revision||0;let r=[],i=this.CompareVersions(e.version,"29.5.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 29.5.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 o=e.shared_resources,a=s=>/^resource:/.test(s)?o[s.substring(9)]||"":s;for(let s of r){s.background_image&&(s.background_image=a(s.background_image));for(let l of s.annotations||[])l.type==="image"&&l.data?.src&&(l.data.src=a(l.data.src))}}e.decimal_mark&&e.decimal_mark!==N.decimal_separator&&this.ConvertLocale(e);let n=this.grid.model;if(n.tables.clear(),e.tables)for(let o of e.tables)n.tables.set(o.name.toLowerCase(),o);this.grid.UpdateSheets(r,void 0,t||e.active_sheet);for(let o of this.model.tables.values())if(o.area.start.sheet_id){let a=n.sheets.Find(o.area.start.sheet_id);if(a)for(let s=o.area.start.row;s<=o.area.end.row;s++)for(let l=o.area.start.column;l<=o.area.end.column;l++){let d=a.cells.GetCell({row:s,column:l},!0);d.table=o}}if(n.document_name=e.name,n.user_data=e.user_data,n.named.Reset(),e.named)this.model.UnserializeNames(e.named,this.grid.active_sheet);else{let o=e.named_ranges;if(!o&&r[0]&&r[0].named_ranges&&(o=r[0].named_ranges),o)for(let[a,s]of Object.entries(o))n.named.SetNamedRange(a,new y(s.start,s.end));if(e.named_expressions)for(let a of e.named_expressions)this.model.UnserializeNames([{name:a.name,expression:a.expression}],this.grid.active_sheet)}if(n.macro_functions.clear(),e.macro_functions)for(let o of e.macro_functions)n.macro_functions.set(o.name.toUpperCase(),{...o,expression:this.parser.Parse(o.function_def||"").expression});this.UpdateAC()}async LoadWorker(){if(ti)try{return new Worker(URL.createObjectURL(new Blob([ri],{type:"application/javascript"})))}catch(e){console.info("embedded worker failed"),console.error(e)}throw new Error("creating worker failed")}HandleKeyDown(e){e.ctrlKey&&(e.code==="KeyZ"||e.key==="z")?(e.stopPropagation(),e.preventDefault(),this.Undo()):e.key==="F9"&&this.options.recalculate_on_f9&&(e.stopPropagation(),e.preventDefault(),this.Recalculate())}};var bn=`@charset "UTF-8";.treb-main.treb-main .treb-mouse-mask{background:transparent;bottom:0;display:none;left:0;position:fixed;right:0;top:0;z-index:9999}.treb-main.treb-main .treb-mouse-mask.column-resize{cursor:col-resize}.treb-main.treb-main .treb-mouse-mask.row-resize{cursor:row-resize}.treb-main.treb-main .treb-mouse-mask.nub-select{cursor:crosshair}.treb-main.treb-main .treb-mouse-mask.move{cursor:move}.treb-main.treb-main .treb-mouse-mask.nw-resize{cursor:nw-resize}.treb-main.treb-main .treb-note{max-width:15em;min-width:15em}.treb-main.treb-main .treb-hover-title,.treb-main.treb-main .treb-note{background:var(--treb-note-background,#fff);border:1px solid var(--treb-note-border-color,var(--treb-ui-border-color,#ddd));border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-note-color,#333);font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:10.5pt;left:100px;line-height:normal;opacity:0;padding:7px 10px;position:fixed;top:100px;transition:opacity .2s;white-space:pre-line;z-index:39}.treb-main.treb-main .treb-hover-title{min-width:10em;pointer-events:none}.treb-main.treb-main .treb-sort-button{background:#fff;border:1px solid #ccc;border-radius:2px;height:1em;left:100px;opacity:0;pointer-events:none;position:absolute;top:100px;transition:opacity .1s ease;width:1em;z-index:39}.treb-main.treb-main .treb-sort-button:after{box-sizing:border-box}.treb-main.treb-main .treb-sort-button.asc:after{border:.4em solid transparent;border-top-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-25%);width:.8em}.treb-main.treb-main .treb-sort-button.desc:after{border:.4em solid transparent;border-bottom-color:currentcolor;content:"";height:.8em;left:50%;opacity:.5;position:absolute;top:50%;transform:translate(-50%,-80%);width:.8em}.treb-main.treb-main .treb-tooltip{border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;line-height:normal;padding:2px 10px;pointer-events:none;position:fixed;z-index:39}.treb-main.treb-main .treb-tooltip.arrow-up:after{border:4px solid transparent;border-bottom-color:inherit;box-sizing:border-box;content:" ";height:8px;left:calc(50% - 4px);overflow:hidden;position:absolute;top:-8px;width:8px}.treb-main.treb-main .treb-tooltip.arrow-left:after{border:4px solid transparent;border-right-color:inherit;box-sizing:border-box;content:" ";height:8px;left:-8px;overflow:hidden;position:absolute;top:calc(50% - 4px);width:8px}.treb-main.treb-main .treb-dropdown-caret{background:var(--treb-dropdown-caret-background,#fff);border:1px solid var(--treb-dropdown-caret-border-color,#ccc);border-radius:2px;box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);display:none;height:20px;position:absolute;width:20px;z-index:39}.treb-main.treb-main .treb-dropdown-caret path{fill:none;stroke:var(--treb-dropdown-caret-color,#444);stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.treb-main.treb-main .treb-dropdown-list{background:var(--treb-dropdown-background,#fff);border:1px solid var(--treb-dropdown-border-color,unset);box-shadow:0 1px 4px 2px hsla(0,0%,43%,.2);color:var(--treb-dropdown-color,inherit);display:none;font-size:10pt;max-height:10em;outline:none;overflow-y:auto;position:absolute;text-align:left;z-index:39}.treb-main.treb-main .treb-dropdown-list div{cursor:default;padding:2px}.treb-main.treb-main .treb-dropdown-list div.selected{background:var(--treb-dropdown-selected-background,#555);color:var(--treb-dropdown-selected-color,#fff)}.treb-main.treb-main .treb-dropdown-caret.active{background:var(--treb-dropdown-caret-active-background,#eee)}.treb-main.treb-main .treb-dropdown-caret.active+.treb-dropdown-list{display:block}.treb-main.treb-main .treb-error-highlight{background:rgba(255,0,0,.25);opacity:0;pointer-events:none;position:absolute;transition:opacity .15s ease-in-out;z-index:40}.treb-main.treb-main .treb-autocomplete{box-sizing:border-box;font-size:inherit;font-weight:400;line-height:normal;max-height:10em;overflow-y:auto;position:fixed;text-align:left;top:-1000px;z-index:39}.treb-main.treb-main .treb-autocomplete *{box-sizing:border-box}.treb-main.treb-main .treb-autocomplete ul{list-style-type:none}.treb-main.treb-main .treb-autocomplete ul,.treb-main.treb-main .treb-autocomplete ul li{font-size:inherit;font-weight:inherit;margin:0;padding:0}.treb-main.treb-main .treb-autocomplete ul li a{color:inherit;cursor:default;display:inline-block;font-size:inherit;font-weight:inherit;padding:3px 6px;text-decoration:none;width:100%}.treb-main.treb-main .treb-autocomplete-tooltip{position:fixed;top:-1000px;white-space:pre;z-index:39}.treb-main.treb-main .treb-formula-bar{display:flex;flex-direction:row;gap:.5em;grid-area:1/1/2/2;max-width:100%;overflow-x:hidden;padding:0 2px 12px;text-align:left}.treb-main.treb-main .treb-formula-bar[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .treb-address-label{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;height:1.75em;justify-content:center;min-height:1.5em;min-width:95px;padding-left:3px;width:95px}.treb-main.treb-main .treb-formula-bar .treb-address-label>div{outline:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button{background:transparent;border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;height:1.75em;min-height:1.5em}.treb-main.treb-main .treb-formula-bar .treb-insert-function-button[hidden]{display:none}.treb-main.treb-main .treb-formula-bar .expand-button{background:transparent;border:0;border-radius:2px;height:1.75em;margin-left:2px;outline:none;padding:1px}.treb-main.treb-main .treb-formula-bar .expand-button:after{border:5px solid transparent;border-top-color:#999;content:" ";display:inline-block;margin:0;padding:0;position:relative;top:-6px;transition:transform .15s ease}.treb-main.treb-main .treb-formula-bar[expanded] .expand-button:after{transform:rotate(180deg) translateY(6px)}.treb-main.treb-main .treb-formula-bar .treb-editor-container{border:1px solid var(--treb-formula-bar-border-color,var(--treb-ui-border-color,#ccc));border-radius:2px;display:flex;flex-direction:column;flex-grow:1;height:1.75em;justify-content:center;min-width:0}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container{height:4.5em;transition:height .1s ease-in-out}.treb-main.treb-main .treb-formula-bar[expanded] .treb-editor-container>div{overflow-y:auto}.treb-main.treb-main .treb-formula-bar .treb-editor-container>div{flex-grow:1;line-height:1.35;margin:2px;min-height:1em;outline:none;overflow-x:hidden;overflow-y:hidden;white-space:pre-wrap;width:100%}.treb-main.treb-main .treb-mouse-mask .ghost-tab{position:fixed}.treb-main.treb-main .treb-spreadsheet-footer{align-items:center;grid-area:3/1/4/2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tab-container{align-self:flex-start;height:2.2em;overflow:hidden}.treb-main.treb-main .treb-spreadsheet-footer,.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{color:var(--treb-ui-color,inherit);display:flex;flex-direction:row;height:2.2em;list-style-type:none;max-width:100%;padding-inline-start:0;z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs{height:auto;margin-block-start:0;margin:0;overflow-x:scroll;overflow-y:hidden}.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{height:2.2em;overflow:visible;overflow-x:visible}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li:last-of-type{margin-right:0}.treb-main.treb-main .treb-spreadsheet-footer .treb-add-tab{margin-left:-1px}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li{white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-spreadsheet-tabs>li[selected]{z-index:2}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control{align-items:center;display:flex;flex-direction:row;font-size:inherit;height:2.2em;justify-content:center;position:relative;width:5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input{background:transparent;border:1px solid transparent;border-radius:2px;color:inherit;font-family:inherit;font-size:inherit;padding:initial;text-align:center;transition:border-color .25s ease,background-color .25s ease;width:4em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container{accent-color:var(--treb-scale-slider-accent-color,undefined);align-items:center;background:var(--treb-scale-slider-background,#fff);border:1px solid var(--treb-scale-slider-border-color,var(--treb-ui-border-color,#ccc));display:flex;flex-direction:row;height:4em;justify-content:center;left:.5em;opacity:0;pointer-events:none;position:absolute;top:0;transform:rotate(-90deg);transform-origin:left top;transition:opacity .25s ease;width:10em;z-index:40}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-scale-input{border-color:var(--treb-ui-border-color,#ccc)}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container>input[type=range]{width:8.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-scale-input:focus+.treb-slider-container,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control .treb-slider-container:focus-within,.treb-main.treb-main .treb-spreadsheet-footer .treb-scale-control:hover .treb-slider-container{opacity:.85;pointer-events:auto}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab{align-items:center;background:transparent;border:none;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top:0;color:currentColor;cursor:default;display:inline-flex;flex-direction:row;font-size:inherit;margin-right:-2px;min-width:2.5em;padding:.25em .75em;z-index:1}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab svg{height:1em;opacity:.75;pointer-events:none;transition:opacity .125s ease-in-out;width:1em}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab:hover svg{opacity:.75}.treb-main.treb-main .treb-spreadsheet-footer .treb-delete-tab path{stroke:currentColor;stroke-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{flex:1 1;overflow:hidden;text-align:end;text-overflow:ellipsis;white-space:nowrap}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel>*{margin-left:.5em}.treb-main.treb-main .treb-spreadsheet-footer .treb-stats-panel .treb-stats-value{background:var(--treb-stats-value-background,#f8f8ff);border:1px solid var(--treb-stats-value-border-color,var(--treb-ui-border-color,#ddd));border-radius:3px;padding:0 .3em}.treb-main.treb-main .treb-grid .treb-overlay-container{margin:0;opacity:0;outline:none;padding:0;position:absolute;z-index:24}.treb-main.treb-main .treb-grid .treb-overlay-container.align-right .treb-overlay-inset{padding-right:3px;right:0;text-align:right}.treb-main.treb-main .treb-grid .treb-overlay-container.align-center .treb-overlay-inset{left:50%;text-align:center;transform:translateX(-50%)}.treb-main.treb-main .treb-grid .treb-overlay-inset{display:flex;flex-direction:column;height:100%;justify-content:flex-end;margin:0;min-width:100%;padding:0 4px;position:absolute}.treb-main.treb-main .treb-grid .treb-overlay-editor{outline:none;position:relative;white-space:nowrap;white-space:pre}.treb-main.treb-main .treb-grid .treb-overlay-editor.firefox:before{content:"\u200B"}.treb-main.treb-main .treb-buffer-canvas{display:none;position:absolute}.treb-main.treb-main .treb-spreadsheet-body{grid-area:2/1/3/2;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:flex;overflow:hidden;position:relative;z-index:1}.treb-main.treb-main .treb-grid{flex-grow:1;order:2;overflow:scroll;position:relative;-webkit-overflow-scrolling:touch;-webkit-tap-highlight-color:transparent;display:grid;grid-template-columns:100px auto;grid-template-rows:20px auto;outline:none}.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{background:var(--treb-grid-header-background,#eeeef2);color:var(--treb-grid-header-color,var(--treb-grid-default-color,#666));font-family:var(--treb-grid-header-font-family,inherit);font-size:var(--treb-grid-header-font-size,10pt);font-style:var(--treb-grid-header-font-style,normal);font-weight:var(--treb-grid-header-font-weight,normal);stroke:var(--treb-grid-header-grid-color,var(--treb-grid-grid-color,#ccccd4))}.treb-main.treb-main .grid-cells{color:var(--treb-grid-default-color,inherit);font-family:var(--treb-grid-font-family,inherit);font-size:var(--treb-grid-font-size,14px);stroke:var(--treb-grid-grid-color,#ccccd4);background:var(--treb-grid-background,#fff)}.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{content:"";height:12px;opacity:.4;position:absolute;right:2px;top:2px;width:12px;--icon:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath fill='currentColor' d='M416 224h-16v-80C400 65 335 0 256 0S112 65 112 144v80H96c-35 0-64 29-64 64v160c0 35 29 64 64 64h320c35 0 64-29 64-64V288c0-35-29-64-64-64m-240-80c0-44 36-80 80-80s80 36 80 80v80H176z'/%3E%3C/svg%3E");background:var(--treb-formula-bar-lock-icon-color,currentColor);mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:12px 12px;-webkit-mask-size:12px 12px}.treb-main.treb-main.treb-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-main.treb-main .treb-annotation-textbox{background:Canvas;height:100%;left:0;overflow:hidden;padding:.5em;position:relative;top:0;width:100%}.treb-main.treb-main .treb-annotation-textbox p{margin-block-end:0;margin-block-start:0}.treb-dark-theme{--treb-autocomplete-background:#333;--treb-autocomplete-border-color:#fff;--treb-autocomplete-entry-color:#fff;--treb-autocomplete-selected-entry-background:darkred;--treb-autocomplete-tooltip-background:darkred;--treb-autocomplete-tooltip-border-color:#fff;--treb-autocomplete-tooltip-color:#fff;--treb-chart-background:#000;--treb-chart-grid-color:#976;--treb-chart-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-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-grid-zero-color:#fdd;--treb-chart-text-color:#fff;--treb-dialog-background:#000;--treb-dialog-color:#fff;--treb-dropdown-background:#000;--treb-dropdown-border-color:#fff;--treb-dropdown-caret-active-background:darkred;--treb-dropdown-caret-background:#444;--treb-dropdown-caret-border-color:#fff;--treb-dropdown-caret-color:#fff;--treb-dropdown-color:#fff;--treb-dropdown-selected-background:darkred;--treb-grid-background:#000;--treb-grid-default-color:#fff;--treb-grid-grid-color:#444;--treb-grid-header-background:#444;--treb-grid-header-grid-color:#000;--treb-note-background:#333;--treb-note-border-color:#aaa;--treb-note-color:#fff;--treb-note-marker-color:pink;--treb-resize-tooltip-background:#fff;--treb-resize-tooltip-color:#000;--treb-scale-slider-accent-color:#fff;--treb-scale-slider-background:#333;--treb-scale-slider-border-color:#aaa;--treb-selection-color:#ff0;--treb-selection-fill-opacity:.2;--treb-sidebar-button-background:#000;--treb-sidebar-button-border-color:#888;--treb-stats-value-background:#223;--treb-tab-bar-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 .legend circle{fill:currentColor;fill-opacity:.5;stroke:currentColor;stroke-width:2px;r:.25em}.treb-chart .chart-grid,.treb-chart .chart-ticks{stroke:var(--treb-chart-grid-color,#ddd)}.treb-chart .chart-grid.zero,.treb-chart .chart-ticks.zero{stroke:var(--treb-chart-grid-zero-color,var(--treb-chart-grid-color,#999))}.treb-chart .label-target{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 .bubble-chart{stroke-width:3;fill:color-mix(in srgb,currentColor 75%,transparent);stroke:currentColor}.treb-chart .bubble-label .label-background{stroke:none;fill:none}.treb-chart .bubble-label .label-text{transform:translate(var(--translate-offset),var(--translate-offset))}.treb-chart .scatter-plot{stroke-width:3;fill:none;stroke:currentColor}.treb-chart .scatter-plot .fill{fill:currentColor;opacity:.5;stroke:none}.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.567'/%3E%3C/svg%3E")}.treb-main.treb-main .treb-icon-64{background:no-repeat 50%/100% var(--treb-icon-svg);height:64px;width:64px}.treb-main.treb-main .treb-dialog-mask{align-items:center;display:flex;height:100%;justify-content:center;left:0;opacity:0;pointer-events:none;position:absolute;top:0;transition:opacity .2s;width:100%;z-index:1000}.treb-main.treb-main .treb-embed-dialog{align-items:center;background:var(--treb-dialog-background,#fff);border:1px solid var(--treb-dialog-border-color,var(--treb-ui-border-color,#999));border-radius:3px;border-top:3px solid #999;box-shadow:0 4px 6px -4px rgba(0,0,0,.3);color:var(--treb-dialog-color,#000);display:flex;flex-direction:row;font-size:var(--treb-dialog-font-size,16px);line-height:1.6em;padding:1rem;position:relative;text-align:left}.treb-main.treb-main .treb-embed-dialog>*{display:none}.treb-main.treb-main .treb-embed-dialog>div{position:relative}.treb-main.treb-main .treb-embed-dialog>:nth-child(2){display:block;flex-grow:1;padding:2px 20px 2px 12px}.treb-main.treb-main .treb-embed-dialog>.treb-close-box{background:transparent;border:0;padding:4px;position:absolute;right:0;top:0}.treb-main.treb-main .treb-embed-dialog>.treb-close-box>svg{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-.708"/></svg>');--icon-popout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path fill="currentColor" d="M22 14.5v5c0 2.484-2.016 4.5-4.5 4.5h-13A4.5 4.5 0 0 1 0 19.5v-13C0 4.016 2.016 2 4.5 2h11c.281 0 .5.219.5.5v1c0 .281-.219.5-.5.5h-11A2.507 2.507 0 0 0 2 6.5v13C2 20.875 3.125 22 4.5 22h13c1.375 0 2.5-1.125 2.5-2.5v-5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5M28 1v8c0 .547-.453 1-1 1a1 1 0 0 1-.703-.297l-2.75-2.75L13.36 17.14c-.094.094-.234.156-.359.156s-.266-.063-.359-.156l-1.781-1.781c-.094-.094-.156-.234-.156-.359s.063-.266.156-.359L21.048 4.454l-2.75-2.75a1 1 0 0 1-.297-.703c0-.547.453-1 1-1h8c.547 0 1 .453 1 1z"/></svg>');--icon-toolbar:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M5.5 22v2H0v-2zm5.5-2c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H7c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm2.5-6v2H0v-2zm-10-8v2H0V6zM24 22v2H12.5v-2zM9 4c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1H5c-.547 0-1-.453-1-1V5c0-.547.453-1 1-1zm10 8c.547 0 1 .453 1 1v4c0 .547-.453 1-1 1h-4c-.547 0-1-.453-1-1v-4c0-.547.453-1 1-1zm5 2v2h-3.5v-2zm0-8v2H10.5V6z"/></svg>');--icon-export:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 28"><path fill="currentColor" d="M20 21c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m4 0c0-.547-.453-1-1-1s-1 .453-1 1 .453 1 1 1 1-.453 1-1m2-3.5v5a1.5 1.5 0 0 1-1.5 1.5h-23A1.5 1.5 0 0 1 0 22.5v-5A1.5 1.5 0 0 1 1.5 16h7.266l2.109 2.125c.578.562 1.328.875 2.125.875s1.547-.313 2.125-.875L17.25 16h7.25a1.5 1.5 0 0 1 1.5 1.5m-5.078-8.891a.98.98 0 0 1-.219 1.094l-7 7c-.187.203-.453.297-.703.297s-.516-.094-.703-.297l-7-7a.98.98 0 0 1-.219-1.094C5.234 8.25 5.594 8 6 8h4V1c0-.547.453-1 1-1h4c.547 0 1 .453 1 1v7h4c.406 0 .766.25.922.609"/></svg>');--icon-reset:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M23.609 16.5c0 .031 0 .078-.016.109C22.265 22.14 17.702 26 11.937 26c-3.047 0-6-1.203-8.219-3.313l-2.016 2.016A1 1 0 0 1 .999 25c-.547 0-1-.453-1-1v-7c0-.547.453-1 1-1h7c.547 0 1 .453 1 1a1 1 0 0 1-.297.703l-2.141 2.141A7.99 7.99 0 0 0 11.998 22a7.98 7.98 0 0 0 6.813-3.813c.375-.609.562-1.203.828-1.828.078-.219.234-.359.469-.359h3c.281 0 .5.234.5.5zM24 4v7c0 .547-.453 1-1 1h-7c-.547 0-1-.453-1-1a1 1 0 0 1 .297-.703l2.156-2.156A8.04 8.04 0 0 0 12 6a7.98 7.98 0 0 0-6.813 3.813c-.375.609-.562 1.203-.828 1.828-.078.219-.234.359-.469.359H.781a.503.503 0 0 1-.5-.5v-.109C1.625 5.844 6.234 2 12 2c3.063 0 6.047 1.219 8.266 3.313l2.031-2.016A1 1 0 0 1 23 3c.547 0 1 .453 1 1"/></svg>');--icon-about:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M14 21.5v-3c0-.281-.219-.5-.5-.5h-3c-.281 0-.5.219-.5.5v3c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5M18 11c0-2.859-3-5-5.688-5-2.547 0-4.453 1.094-5.797 3.328a.49.49 0 0 0 .125.656l2.063 1.563a.48.48 0 0 0 .297.094.5.5 0 0 0 .391-.187c.734-.938 1.047-1.219 1.344-1.437.266-.187.781-.375 1.344-.375 1 0 1.922.641 1.922 1.328 0 .812-.422 1.219-1.375 1.656-1.109.5-2.625 1.797-2.625 3.313v.562c0 .281.219.5.5.5h3c.281 0 .5-.219.5-.5 0-.359.453-1.125 1.188-1.547 1.188-.672 2.812-1.578 2.812-3.953zm6 3c0 6.625-5.375 12-12 12S0 20.625 0 14 5.375 2 12 2s12 5.375 12 12"/></svg>');--icon-chevron-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 28"><path fill="currentColor" d="M18.297 4.703 10 13l8.297 8.297a.99.99 0 0 1 0 1.406l-2.594 2.594a.99.99 0 0 1-1.406 0L2.703 13.703a.99.99 0 0 1 0-1.406L14.297.703a.99.99 0 0 1 1.406 0l2.594 2.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-chevron-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 28"><path fill="currentColor" d="M17.297 13.703 5.703 25.297a.99.99 0 0 1-1.406 0l-2.594-2.594a.99.99 0 0 1 0-1.406L10 13 1.703 4.703a.99.99 0 0 1 0-1.406L4.297.703a.99.99 0 0 1 1.406 0l11.594 11.594a.99.99 0 0 1 0 1.406"/></svg>');--icon-revert:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 28"><path fill="currentColor" d="M24 14c0 6.609-5.391 12-12 12a11.97 11.97 0 0 1-9.234-4.328.52.52 0 0 1 .031-.672l2.141-2.156a.6.6 0 0 1 .391-.141.5.5 0 0 1 .359.187A7.91 7.91 0 0 0 12 21.999c4.406 0 8-3.594 8-8s-3.594-8-8-8A7.95 7.95 0 0 0 6.563 8.14l2.141 2.156a.96.96 0 0 1 .219 1.078 1 1 0 0 1-.922.625h-7c-.547 0-1-.453-1-1v-7c0-.406.25-.766.625-.922a.96.96 0 0 1 1.078.219l2.031 2.016c2.203-2.078 5.187-3.313 8.266-3.313 6.609 0 12 5.391 12 12zM14 9.5v7c0 .281-.219.5-.5.5h-5a.494.494 0 0 1-.5-.5v-1c0-.281.219-.5.5-.5H12V9.5c0-.281.219-.5.5-.5h1c.281 0 .5.219.5.5"/></svg>');--icon-text-indent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-left"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m.646 2.146a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1 0 .708l-2 2a.5.5 0 0 1-.708-.708L4.293 8 2.646 6.354a.5.5 0 0 1 0-.708M7 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m-5 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-outdent:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-indent-right"><path d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m10.646 2.146a.5.5 0 0 1 .708.708L11.707 8l1.647 1.646a.5.5 0 0 1-.708.708l-2-2a.5.5 0 0 1 0-.708zM2 6.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-center:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5m4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5m-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5"/></svg>');--icon-text-align-top:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16'%3E%3Cpath d='M8 15a.5.5 0 0 0 .5-.5V5.707l3.146 3.146a.5.5 0 0 0 .707-.707l-4-4a.5.5 0 0 0-.706-.001l-.001.001-4 4a.5.5 0 0 0 .708.707L7.5 5.707V14.5a.5.5 0 0 0 .5.5'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M3 1.5h10'/%3E%3C/svg%3E");--icon-text-align-middle:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path fill-rule="evenodd" d="M1 8a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13A.5.5 0 0 1 1 8m7-8a.5.5 0 0 1 .5.5v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 1 1 .708-.708L7.5 4.293V.5A.5.5 0 0 1 8 0m-.5 11.707-1.146 1.147a.5.5 0 0 1-.708-.708l2-2a.5.5 0 0 1 .708 0l2 2a.5.5 0 0 1-.708.708L8.5 11.707V15.5a.5.5 0 0 1-1 0z"/></svg>');--icon-text-align-bottom:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' xml:space='preserve' width='16' height='16'%3E%3Cpath d='M8 1a.5.5 0 0 0-.5.5v8.793L4.354 7.146a.5.5 0 0 0-.707.707l4 4a.5.5 0 0 0 .707.001l.001-.001 4-4a.5.5 0 0 0-.708-.707L8.5 10.293V1.5A.5.5 0 0 0 8 1'/%3E%3Cpath fill='none' stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-miterlimit='10' d='M13 14.5H3'/%3E%3C/svg%3E");--icon-file-menu:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.54 3.87.5 3a2 2 0 0 1 2-2h3.672a2 2 0 0 1 1.414.586l.828.828A2 2 0 0 0 9.828 3h3.982a2 2 0 0 1 1.992 2.181l-.637 7A2 2 0 0 1 13.174 14H2.826a2 2 0 0 1-1.991-1.819l-.637-7a2 2 0 0 1 .342-1.31zM2.19 4a1 1 0 0 0-.996 1.09l.637 7a1 1 0 0 0 .995.91h10.348a1 1 0 0 0 .995-.91l.637-7A1 1 0 0 0 13.81 4zm4.69-1.707A1 1 0 0 0 6.172 2H2.5a1 1 0 0 0-1 .981l.006.139q.323-.119.684-.12h5.396z"/></svg>');--icon-wrap-text:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4 5h8a.5.5 0 0 0 0-1H4a.5.5 0 0 0 0 1M10 8H4a.5.5 0 0 0 0 1h6a1.5 1.5 0 0 1 0 3v-1.203l-2.953 1.707L10 14.203V13a2.5 2.5 0 1 0 0-5M3.75 12.5a.5.5 0 0 0 .5.5H6v-1H4.25a.5.5 0 0 0-.5.5"/></svg>');--icon-unmerge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M1.5 1a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0v-4A1.5 1.5 0 0 1 1.5 0h4a.5.5 0 0 1 0 1zM10 .5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 16 1.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5M.5 10a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 0 14.5v-4a.5.5 0 0 1 .5-.5m15 0a.5.5 0 0 1 .5.5v4a1.5 1.5 0 0 1-1.5 1.5h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5"/></svg>');--icon-merge-cells:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M5.5 0a.5.5 0 0 1 .5.5v4A1.5 1.5 0 0 1 4.5 6h-4a.5.5 0 0 1 0-1h4a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 1 .5-.5m5 0a.5.5 0 0 1 .5.5v4a.5.5 0 0 0 .5.5h4a.5.5 0 0 1 0 1h-4A1.5 1.5 0 0 1 10 4.5v-4a.5.5 0 0 1 .5-.5M0 10.5a.5.5 0 0 1 .5-.5h4A1.5 1.5 0 0 1 6 11.5v4a.5.5 0 0 1-1 0v-4a.5.5 0 0 0-.5-.5h-4a.5.5 0 0 1-.5-.5m10 1a1.5 1.5 0 0 1 1.5-1.5h4a.5.5 0 0 1 0 1h-4a.5.5 0 0 0-.5.5v4a.5.5 0 0 1-1 0z"/></svg>');--icon-lock:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2m3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2M5 8h6a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1"/></svg>');--icon-comment:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1h-2.5a2 2 0 0 0-1.6.8L8 14.333 6.1 11.8a2 2 0 0 0-1.6-.8H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2.5a1 1 0 0 1 .8.4l1.9 2.533a1 1 0 0 0 1.6 0l1.9-2.533a1 1 0 0 1 .8-.4H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/></svg>');--icon-fill-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M6.192 2.78c-.458-.677-.927-1.248-1.35-1.643a3 3 0 0 0-.71-.515c-.217-.104-.56-.205-.882-.02-.367.213-.427.63-.43.896-.003.304.064.664.173 1.044.196.687.556 1.528 1.035 2.402L.752 8.22c-.277.277-.269.656-.218.918.055.283.187.593.36.903.348.627.92 1.361 1.626 2.068.707.707 1.441 1.278 2.068 1.626.31.173.62.305.903.36.262.05.64.059.918-.218l5.615-5.615c.118.257.092.512.05.939-.03.292-.068.665-.073 1.176v.123h.003a1 1 0 0 0 1.993 0H14v-.057a1 1 0 0 0-.004-.117c-.055-1.25-.7-2.738-1.86-3.494a4 4 0 0 0-.211-.434c-.349-.626-.92-1.36-1.627-2.067S8.857 3.052 8.23 2.704c-.31-.172-.62-.304-.903-.36-.262-.05-.64-.058-.918.219l-.217.216zM4.16 1.867c.381.356.844.922 1.311 1.632l-.704.705c-.382-.727-.66-1.402-.813-1.938a3.3 3.3 0 0 1-.131-.673q.137.09.337.274m.394 3.965c.54.852 1.107 1.567 1.607 2.033a.5.5 0 1 0 .682-.732c-.453-.422-1.017-1.136-1.564-2.027l1.088-1.088q.081.181.183.365c.349.627.92 1.361 1.627 2.068.706.707 1.44 1.278 2.068 1.626q.183.103.365.183l-4.861 4.862a1 1 0 0 1-.068-.01c-.137-.027-.342-.104-.608-.252-.524-.292-1.186-.8-1.846-1.46s-1.168-1.32-1.46-1.846c-.147-.265-.225-.47-.251-.607a1 1 0 0 1-.01-.068zm2.87-1.935a2.4 2.4 0 0 1-.241-.561c.135.033.324.11.562.241.524.292 1.186.8 1.846 1.46.45.45.83.901 1.118 1.31a3.5 3.5 0 0 0-1.066.091 11 11 0 0 1-.76-.694c-.66-.66-1.167-1.322-1.458-1.847z"/></svg>');--icon-text-color:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16"><path d="m12.259 14.001-1.389-3.727H5.465l-1.354 3.727h-1.3L7.609 1.397h1.178l4.772 12.604zM8.418 3.604a6 6 0 0 1-.127-.387 4 4 0 0 1-.11-.501h-.035a5.5 5.5 0 0 1-.247.888L5.86 9.211h4.614z"/></svg>');--icon-border-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0z"/></svg>');--icon-border-top:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0v1h16V0zm1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-left:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0v16h1V0zm1.906 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM7.5 1.906v.938h1v-.938zm7.5 0v.938h1v-.938zM7.5 3.781v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM7.5 5.656v.938h1v-.938zm7.5 0v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM7.5 9.406v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zm-8.5.937v.938h1v-.938zm8.5.938v-.938h-1v.938zM1.906 16h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875-.5v.5H16v-.969h-.5V15h-.469v.031H15v.469z"/></svg>');--icon-border-right:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zM16 0h-1v16h1zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zM1 4.719V3.78H0v.938h1zm6.5-.938v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zM0 11.281v.938h1v-.938zm7.5 0v.938h1v-.938zM0 13.156v.938h1v-.938zm7.5 0v.938h1v-.938zM0 16h.969v-.5H1v-.469H.969V15H.5v.031H0zm1.906 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm1.875-.5v.5h.938v-.5H8.5v-.469h-.031V15H7.53v.031H7.5v.469zm1.875.5h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938z"/></svg>');--icon-border-double-bottom:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M.969 0H0v.969h.5V1h.469V.969H1V.5H.969zm.937 1h.938V0h-.938zm1.875 0h.938V0H3.78v1zm1.875 0h.938V0h-.938zM7.531.969V1h.938V.969H8.5V.5h-.031V0H7.53v.5H7.5v.469zM9.406 1h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.938V0h-.938zm1.875 0h.469V.969h.5V0h-.969v.5H15v.469h.031zM1 2.844v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM1 4.719V3.78H0v.938zm6.5-.938v.938h1V3.78h-1zm7.5 0v.938h1V3.78h-1zM1 6.594v-.938H0v.938zm6.5-.938v.938h1v-.938zm7.5 0v.938h1v-.938zM.5 8.5h.469v-.031H1V7.53H.969V7.5H.5v.031H0v.938h.5zm1.406 0h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.469v-.031h.5V7.53h-.5V7.5h-.469v.031H15v.938h.031zM0 9.406v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zm-16 .937v.938h1v-.938zm7.5 0v.938h1v-.938zm8.5.938v-.938h-1v.938zM0 15h16v1H0zm0-2h16v1H0z"/></svg>');--icon-border-all:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0h16v16H0zm1 1v6.5h6.5V1zm7.5 0v6.5H15V1zM15 8.5H8.5V15H15zM7.5 15V8.5H1V15z"/></svg>');--icon-border-outer:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M7.5 1.906v.938h1v-.938zm0 1.875v.938h1V3.78h-1zm0 1.875v.938h1v-.938zM1.906 8.5h.938v-1h-.938zm1.875 0h.938v-1H3.78v1zm1.875 0h.938v-1h-.938zm2.813 0v-.031H8.5V7.53h-.031V7.5H7.53v.031H7.5v.938h.031V8.5zm.937 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zm1.875 0h.938v-1h-.938zM7.5 9.406v.938h1v-.938zm0 1.875v.938h1v-.938zm0 1.875v.938h1v-.938z"/><path d="M0 0v16h16V0zm1 1h14v14H1z"/></svg>');--icon-border-none:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 0h.969v.5H1v.469H.969V1H.5V.969H0zm2.844 1h-.938V0h.938zm1.875 0H3.78V0h.938v1zm1.875 0h-.938V0h.938zm.937 0V.969H7.5V.5h.031V0h.938v.5H8.5v.469h-.031V1zm2.813 0h-.938V0h.938zm1.875 0h-.938V0h.938zm1.875 0h-.938V0h.938zM15.5 1h-.469V.969H15V.5h.031V0H16v.969h-.5zM1 1.906v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM1 3.78v.938H0V3.78zm6.5.938V3.78h1v.938zm7.5 0V3.78h1v.938zM1 5.656v.938H0v-.938zm6.5.938v-.938h1v.938zm7.5 0v-.938h1v.938zM.969 8.5H.5v-.031H0V7.53h.5V7.5h.469v.031H1v.938H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm1.875-.031V8.5H7.53v-.031H7.5V7.53h.031V7.5h.938v.031H8.5v.938zm1.875.031h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.406 0h-.469v-.031H15V7.53h.031V7.5h.469v.031h.5v.938h-.5zM0 10.344v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 12.22v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM0 14.094v-.938h1v.938zm7.5 0v-.938h1v.938zm8.5-.938v.938h-1v-.938zM.969 16H0v-.969h.5V15h.469v.031H1v.469H.969zm1.875 0h-.938v-1h.938zm1.875 0H3.78v-1h.938v1zm1.875 0h-.938v-1h.938zm.937 0v-.5H7.5v-.469h.031V15h.938v.031H8.5v.469h-.031v.5zm2.813 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm1.875 0h-.938v-1h.938zm.937 0v-.5H15v-.469h.031V15h.469v.031h.5V16z"/></svg>');--icon-palette:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 .5A.5.5 0 0 1 .5 0h5a.5.5 0 0 1 .5.5v5.277l4.147-4.131a.5.5 0 0 1 .707 0l3.535 3.536a.5.5 0 0 1 0 .708L10.261 10H15.5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-.5.5H3a3 3 0 0 1-2.121-.879A3 3 0 0 1 0 13.044m6-.21 7.328-7.3-2.829-2.828L6 7.188zM4.5 13a1.5 1.5 0 1 0-3 0 1.5 1.5 0 0 0 3 0M15 15v-4H9.258l-4.015 4zM0 .5v12.495zM0 12.995V13z"/></svg>');--icon-layout:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="m3 0 17 17.156v-.114z"/><path d="M3 0H0v16h1V1h1.585L19 17.455V19H4v1h16v-2.844z"/><path d="M6.886 3.922 5.343 5.465a.5.5 0 0 0 .708.707l1.539-1.54zM9.702 6.763l-1.53 1.53A.5.5 0 0 0 8.879 9l1.526-1.526zM12.517 9.604 11 11.121a.5.5 0 0 0 .707.707l1.514-1.514zM15.332 12.445l-1.504 1.504a.5.5 0 0 0 .707.707l1.501-1.5zM1 16H0a4 4 0 0 0 4 4v-1c-1.654 0-3-1.346-3-3M5 9v6h6zm1 2.414L8.586 14H6z"/></svg>');--icon-freeze:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><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 0zM12.5 17.5a.5.5 0 0 1-1 0v-9a.5.5 0 0 1 1 0zM16.5 17.5a.5.5 0 0 1-1 0v-13a.5.5 0 0 1 1 0zM8.5 17.5a.5.5 0 0 1-1 0v-14a.5.5 0 0 1 1 0z"/></svg>');--icon-donut-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M12 1.23v1.548c2.526.701 4.5 2.699 5.203 5.222h1.565A9.01 9.01 0 0 0 12 1.23M2.5 10c0-3.51 2.426-6.456 5.688-7.27V1.183A9 9 0 0 0 1 10c0 1.761.513 3.397 1.387 4.784l1.093-1.093A7.43 7.43 0 0 1 2.5 10M17.221 12c-.878 3.166-3.778 5.5-7.221 5.5a7.45 7.45 0 0 1-3.692-.979l-1.093 1.093A8.96 8.96 0 0 0 10 19c4.282 0 7.859-2.993 8.77-7z"/></svg>');--icon-bar-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M2.5 4.5a.5.5 0 0 1 0-1h5a.5.5 0 0 1 0 1zM2.5 12.5a.5.5 0 0 1 0-1h9a.5.5 0 0 1 0 1zM2.5 16.5a.5.5 0 0 1 0-1h13a.5.5 0 0 1 0 1zM2.5 8.5a.5.5 0 0 1 0-1h14a.5.5 0 0 1 0 1z"/></svg>');--icon-line-chart:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><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 0"/><path d="M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z"/></svg>');--icon-recalculate:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="20" height="20"><path d="M9.478 4.022c2.402-.209 4.583 1.047 5.711 3.014l1.083-.095c-1.233-2.528-3.912-4.175-6.881-3.916-2.97.26-5.321 2.347-6.098 5.051l1.083-.095c.768-2.132 2.698-3.748 5.102-3.959M10.523 15.977c-2.403.211-4.585-1.047-5.712-3.013l-1.08.095c1.234 2.527 3.91 4.175 6.879 3.914 2.971-.259 5.32-2.347 6.095-5.05l-1.08.095c-.769 2.132-2.699 3.749-5.102 3.959"/><path d="m2.272 15.616 5.197-3-4.098-1.097zM17.728 4.384l-5.197 3 4.098 1.098z"/></svg>');--icon-check:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0"/></svg>');--icon-table:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"><path d="M0 2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm15 2h-4v3h4zm0 4h-4v3h4zm0 4h-4v3h3a1 1 0 0 0 1-1zm-5 3v-3H6v3zm-5 0v-3H1v2a1 1 0 0 0 1 1zm-4-4h4V8H1zm0-4h4V4H1zm5-3v3h4V4zm4 4H6v3h4z"/></svg>')}.treb-main.treb-main .treb-layout-header{overflow:hidden;overflow-x:scroll;position:relative;-ms-overflow-style:none;scrollbar-width:none}.treb-main.treb-main .treb-layout-header::-webkit-scrollbar{display:none}.treb-main.treb-main .treb-toolbar{color:var(--treb-toolbar-color,var(--treb-ui-color,#333));display:flex;flex-direction:row;font-size:var(--treb-toolbar-font-size,inherit);gap:.5rem}.treb-main.treb-main .treb-toolbar>div{display:flex;flex-direction:row}.treb-main.treb-main .treb-toolbar>div>input,.treb-main.treb-main .treb-toolbar>input{background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));height:32px;overflow:hidden;padding-left:.5em;padding-right:.5em;text-overflow:ellipsis}.treb-main.treb-main .treb-toolbar>.treb-menu>button{border-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu+button,.treb-main.treb-main .treb-toolbar>.group>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>button+button,.treb-main.treb-main .treb-toolbar>.group>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>.group>input+button,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu+button,.treb-main.treb-main .treb-toolbar>[composite]>button+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>button+button,.treb-main.treb-main .treb-toolbar>[composite]>input+.treb-menu>button,.treb-main.treb-main .treb-toolbar>[composite]>input+button{border-left-width:0}.treb-main.treb-main .treb-toolbar>.group>button:first-child,.treb-main.treb-main .treb-toolbar>.group>input:first-child,.treb-main.treb-main .treb-toolbar>[composite]>button:first-child,.treb-main.treb-main .treb-toolbar>[composite]>input:first-child{border-bottom-left-radius:3px;border-top-left-radius:3px}.treb-main.treb-main .treb-toolbar>.group>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>.group>button:last-child,.treb-main.treb-main .treb-toolbar>[composite]>.treb-menu:last-child>button,.treb-main.treb-main .treb-toolbar>[composite]>button:last-child{border-bottom-right-radius:3px;border-top-right-radius:3px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button,.treb-main.treb-main .treb-toolbar .treb-menu>button,.treb-main.treb-main .treb-toolbar button[data-icon],.treb-main.treb-main .treb-toolbar>button,.treb-main.treb-main .treb-toolbar>div>button{align-items:center;background-color:var(--treb-toolbar-button-background,transparent);border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));display:flex;flex-direction:column;height:32px;justify-content:center;position:relative;width:32px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown],.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown],.treb-main.treb-main .treb-toolbar button[data-icon][dropdown],.treb-main.treb-main .treb-toolbar>button[dropdown],.treb-main.treb-main .treb-toolbar>div>button[dropdown]{width:16px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[dropdown]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[dropdown]:after,.treb-main.treb-main .treb-toolbar button[data-icon][dropdown]:after,.treb-main.treb-main .treb-toolbar>button[dropdown]:after,.treb-main.treb-main .treb-toolbar>div>button[dropdown]:after{border:5px solid transparent;border-top-color:currentcolor;box-sizing:content-box;content:"";height:0;left:50%;position:absolute;top:18px;transform:translate(-50%,-50%);width:0}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button:hover,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[active],.treb-main.treb-main .treb-toolbar .treb-menu>button:hover,.treb-main.treb-main .treb-toolbar .treb-menu>button[active],.treb-main.treb-main .treb-toolbar button[data-icon]:hover,.treb-main.treb-main .treb-toolbar button[data-icon][active],.treb-main.treb-main .treb-toolbar>button:hover,.treb-main.treb-main .treb-toolbar>button[active],.treb-main.treb-main .treb-toolbar>div>button:hover,.treb-main.treb-main .treb-toolbar>div>button[active]{background-color:var(--treb-toolbar-hover-button-background,#f3f4f6)}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar button[data-icon][data-color-bar]:after,.treb-main.treb-main .treb-toolbar>button[data-color-bar]:after,.treb-main.treb-main .treb-toolbar>div>button[data-color-bar]:after{background:var(--treb-color-bar-color,var(--treb-default-color,unset));border:1px solid var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));box-sizing:border-box;content:"";display:block;height:6px;position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-icon-buttons>button[data-icon]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-command]:before,.treb-main.treb-main .treb-toolbar .treb-menu>button[data-icon]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-command]:before,.treb-main.treb-main .treb-toolbar button[data-icon][data-icon]:before,.treb-main.treb-main .treb-toolbar>button[data-command]:before,.treb-main.treb-main .treb-toolbar>button[data-icon]:before,.treb-main.treb-main .treb-toolbar>div>button[data-command]:before,.treb-main.treb-main .treb-toolbar>div>button[data-icon]:before{background:currentColor;content:"";display:block;height:20px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;mask-size:var(--icon-size,16px 16px);-webkit-mask-size:var(--icon-size,16px 16px);position:relative;width:20px}.treb-main.treb-main .treb-toolbar .treb-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=indent]{--icon:var(--icon-text-indent)}.treb-main.treb-main .treb-toolbar [data-command=outdent]{--icon:var(--icon-text-outdent)}.treb-main.treb-main .treb-toolbar [data-command=align-top]{--icon:var(--icon-text-align-top)}.treb-main.treb-main .treb-toolbar [data-command=align-middle]{--icon:var(--icon-text-align-middle)}.treb-main.treb-main .treb-toolbar [data-command=align-bottom]{--icon:var(--icon-text-align-bottom)}.treb-main.treb-main .treb-toolbar [data-command=merge-cells]{--icon:var(--icon-merge-cells)}.treb-main.treb-main .treb-toolbar [data-command=unmerge-cells]{--icon:var(--icon-unmerge-cells)}.treb-main.treb-main .treb-toolbar [data-command=fill-color]{--icon:var(--icon-fill-color)}.treb-main.treb-main .treb-toolbar [data-command=text-color]{--icon:var(--icon-text-color)}.treb-main.treb-main .treb-toolbar [data-command=lock-cells]{--icon:var(--icon-lock)}.treb-main.treb-main .treb-toolbar [data-command=wrap-text]{--icon:var(--icon-wrap-text)}.treb-main.treb-main .treb-toolbar [data-icon=comment]{--icon:var(--icon-comment)}.treb-main.treb-main .treb-toolbar [data-icon=table]{--icon:var(--icon-table)}.treb-main.treb-main .treb-toolbar [data-icon=layout]{--icon:var(--icon-layout)}.treb-main.treb-main .treb-toolbar [data-command=freeze-panes]{--icon:var(--icon-freeze)}.treb-main.treb-main .treb-toolbar [data-command=insert-column-chart]{--icon:var(--icon-column-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-donut-chart]{--icon:var(--icon-donut-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-bar-chart]{--icon:var(--icon-bar-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-line-chart]{--icon:var(--icon-line-chart)}.treb-main.treb-main .treb-toolbar [data-command=insert-image]{--icon:var(--icon-image)}.treb-main.treb-main .treb-toolbar [data-command=border-bottom]{--icon:var(--icon-border-bottom)}.treb-main.treb-main .treb-toolbar [data-command=border-left]{--icon:var(--icon-border-left)}.treb-main.treb-main .treb-toolbar [data-command=border-right]{--icon:var(--icon-border-right)}.treb-main.treb-main .treb-toolbar [data-command=border-top]{--icon:var(--icon-border-top)}.treb-main.treb-main .treb-toolbar [data-command=border-outside]{--icon:var(--icon-border-outer)}.treb-main.treb-main .treb-toolbar [data-command=border-all]{--icon:var(--icon-border-all)}.treb-main.treb-main .treb-toolbar [data-command=border-none]{--icon:var(--icon-border-none)}.treb-main.treb-main .treb-toolbar [data-command=border-double-bottom]{--icon:var(--icon-border-double-bottom)}.treb-main.treb-main .treb-toolbar [data-icon=palette]{--icon:var(--icon-palette)}.treb-main.treb-main .treb-toolbar [data-command=recalculate]{--icon:var(--icon-recalculate);--icon-size:20px 20px}.treb-main.treb-main .treb-toolbar .treb-font-scale{width:4em}.treb-main.treb-main .treb-toolbar .treb-number-format{width:8em}.treb-main.treb-main .treb-toolbar .treb-color-chooser button[data-command=set-color]{align-items:center;display:flex;justify-content:center;padding:0;width:32px}.treb-main.treb-main .treb-toolbar .treb-color-chooser>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 .treb-toolbar .treb-font-scale{padding-left:2em;text-align:right;width:5em}.treb-main.treb-main .treb-toolbar [composite][font-scale]{position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon{border-radius:3px;left:.5em;line-height:1;opacity:.9;pointer-events:none;position:absolute;top:50%;transform:translateY(-50%)}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after,.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{content:"A";position:relative}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:before{font-size:1.2em}.treb-main.treb-main .treb-toolbar .treb-font-scale-icon:after{font-size:.9em;left:-.125em}.treb-main.treb-main{all:revert;box-sizing:border-box;color:inherit;color-scheme:var(--treb-color-scheme,unset);display:grid;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif");font-family:BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,"sans-serif";font-size:14px;font-style:normal;font-weight:400;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto minmax(0,1fr);height:100%;line-height:normal;position:relative;text-align:start;width:100%}.treb-main.treb-main a,.treb-main.treb-main button,.treb-main.treb-main div,.treb-main.treb-main input,.treb-main.treb-main li,.treb-main.treb-main ol,.treb-main.treb-main svg,.treb-main.treb-main textarea,.treb-main.treb-main ul{all:revert;box-sizing:border-box;font-family:var(--treb-default-font,system-ui,"BlinkMacSystemFont","Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue","sans-serif")}.treb-main.treb-main button,.treb-main.treb-main input{color:inherit;font:inherit}.treb-main.treb-main *{box-sizing:border-box}.treb-main.treb-main [contenteditable]{-webkit-user-modify:read-write;-moz-user-modify:read-write}.treb-main.treb-main[animate] .treb-layout-header{transition:height var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-header{grid-column:1/3;grid-row:1;height:1px;opacity:0}.treb-main.treb-main[toolbar] .treb-layout-header{height:42px;opacity:1}.treb-main.treb-main[dialog] .treb-layout-header,.treb-main.treb-main[dialog]>*{opacity:.6}.treb-main.treb-main[dialog] .treb-dialog-mask{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-layout-spreadsheet{display:flex;flex-direction:row;gap:1em;grid-column:1;grid-row:2;position:relative;transition:opacity .2s ease;z-index:5}.treb-main.treb-main .treb-views.treb-can-revert .treb-view .treb-revert-indicator{opacity:1;pointer-events:auto}.treb-main.treb-main .treb-view{display:grid;flex:1 1 0px;grid-template-columns:minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;position:relative}.treb-main.treb-main .treb-view .treb-spreadsheet-backdrop{box-shadow:0 4px 6px -4px rgba(0,0,0,.4);grid-column:1;grid-row:2;z-index:2}.treb-main.treb-main .treb-view .treb-spreadsheet-body{position:relative;z-index:4}.treb-main.treb-main .treb-view .treb-spreadsheet-footer{position:relative;z-index:5}.treb-main.treb-main .treb-view .treb-layout-resize-handle,.treb-main.treb-main .treb-view .treb-revert-indicator{display:none}.treb-main.treb-main .treb-view:first-of-type .treb-revert-indicator{align-self:start;border-color:orange transparent transparent orange;border-style:solid;border-width:.5em;display:block;grid-area:2/1/3/2;height:1rem;justify-self:start;opacity:0;overflow:hidden;pointer-events:none;position:relative;transition:opacity .125s ease;width:1rem;z-index:20}.treb-main.treb-main .treb-view:last-of-type .treb-layout-resize-handle{align-self:end;border-bottom:.5rem solid var(--treb-resize-handle-color,#0059b9);border-left:.5rem solid transparent;border-right:.5rem solid var(--treb-resize-handle-color,#0059b9);border-top:.5rem solid transparent;cursor:nw-resize;display:block;grid-area:2/1/3/2;height:1rem;justify-self:end;width:1rem;z-index:20}.treb-main.treb-main[animate] .treb-layout-sidebar{transition:width var(--treb-sidebar-transition,.2s ease),opacity var(--treb-sidebar-transition,.2s ease)}.treb-main.treb-main .treb-layout-sidebar{align-items:center;display:flex;flex-direction:column;gap:.75rem;grid-column:2;grid-row:2;justify-content:flex-start;overflow:hidden;padding-top:3rem;width:2.5rem;width:3rem}.treb-main.treb-main[collapsed] .treb-layout-sidebar{opacity:0;width:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button{background:var(--treb-toolbar-button-background,#fff);border-bottom-right-radius:0;border-color:var(--treb-toolbar-border-color,var(--treb-ui-border-color,#d1d5db));border-right-color:var(--treb-toolbar-button-background,transparent);border-top-right-radius:0;right:0}.treb-main.treb-main[collapsed] .treb-toggle-sidebar-button:after{mask-image:var(--icon-chevron-left);-webkit-mask-image:var(--icon-chevron-left)}.treb-main.treb-main .treb-layout-sidebar>button,.treb-main.treb-main .treb-toggle-sidebar-button{background:transparent;border:0;margin:0;padding:0}.treb-main.treb-main .treb-layout-sidebar>button:after,.treb-main.treb-main .treb-toggle-sidebar-button:after{background:#ccc;content:"";display:block;height:24px;mask-image:var(--icon);-webkit-mask-image:var(--icon);mask-position:center;-webkit-mask-position:center;mask-repeat:no-repeat;-webkit-mask-repeat:no-repeat;transition:background-color .1s ease;width:24px}.treb-main.treb-main .treb-layout-sidebar>button[data-can-revert=false],.treb-main.treb-main .treb-toggle-sidebar-button[data-can-revert=false]{display:none}.treb-main.treb-main .treb-layout-sidebar>button:hover:after,.treb-main.treb-main .treb-toggle-sidebar-button:hover:after{background:#666}.treb-main.treb-main .treb-layout-sidebar>button[data-command=recalculate],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=recalculate]{--icon:var(--icon-reset)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=toggle-toolbar],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=toggle-toolbar]{--icon:var(--icon-toolbar)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=revert],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=revert]{--icon:var(--icon-revert)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=export-xlsx],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=export-xlsx]{--icon:var(--icon-export)}.treb-main.treb-main .treb-layout-sidebar>button[data-command=about],.treb-main.treb-main .treb-toggle-sidebar-button[data-command=about]{--icon:var(--icon-about)}.treb-main.treb-main .treb-toggle-sidebar-button{align-items:center;background:transparent;border:1px solid transparent;border-radius:12px;bottom:6rem;display:flex;height:24px;justify-content:center;margin:0;padding:0;position:absolute;right:.5rem;right:calc(1.5rem - 12px);width:24px;z-index:39}.treb-main.treb-main .treb-toggle-sidebar-button:after{height:12px;mask-image:var(--icon-chevron-right);-webkit-mask-image:var(--icon-chevron-right);width:12px}.treb-main.treb-main .treb-resize-rect{border:1px dotted var(--treb-resize-frame-color,blue);display:block;height:100%;left:0;position:fixed;top:0;width:100%;z-index:9998}.treb-main.treb-main .treb-resize-mask{height:100vh;left:0;position:fixed;top:0;width:100vw;z-index:9999}treb-spreadsheet{display:block;overflow:hidden;position:relative}.treb-default-size{height:550px;width:800px}`;var gn='<div class="treb-main treb-theme"><div class="treb-layout-header treb-animate"><div class="treb-toolbar"></div></div><div class="treb-dialog-mask"><div data-bind="dialog" class="treb-embed-dialog"><div data-bind="left"><a href="https://treb.app" target="_blank"><div class="treb-icon-64"></div></a></div><div data-bind="middle"><div data-bind="title" class="treb-embed-dialog-title"></div><div data-bind="message" class="treb-embed-dialog-message"></div><div data-bind="about" class="treb-embed-dialog-body"></div></div><button type="button" data-title="close_dialog" data-bind="close" class="treb-close-box"><svg viewBox="0 0 16 16"><path d="M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"/><path d="M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"/></svg></button></div></div><div class="treb-layout-spreadsheet treb-views"><template class="treb-view-template"><div class="treb-view"><div class="treb-formula-bar notranslate" hidden><div class="treb-address-label"><div></div></div><button class="treb-insert-function-button" data-title="insert_function" data-conditional="insert-function">\u{1D453}<small>(x)</small></button><div class="treb-editor-container"><div contenteditable="true"></div></div></div><div class="treb-spreadsheet-backdrop"></div><div class="treb-spreadsheet-body" role="grid"><div class="treb-grid" tabindex="-1"><div class="treb-overlay-container notranslate" translate="no"><div class="treb-overlay-inset"><div class="treb-overlay-editor" contenteditable tabindex="-1" spellcheck="true" role="gridcell"></div></div></div></div></div><div class="treb-spreadsheet-footer" hidden><button class="treb-delete-tab" data-title="delete_sheet" data-command="delete-tab" data-conditional="delete-tab"><svg tabindex="-1" viewbox="0 0 16 16"><path d="M4,4 L12,12 M12,4 L4,12"/></svg></button><div class="treb-spreadsheet-tab-container"><ol class="treb-spreadsheet-tabs" role="tablist"></ol></div><button class="treb-add-tab" data-command="add-tab" data-conditional="add-tab" data-title="add_sheet">+</button><div class="treb-stats-panel"></div><div class="treb-scale-control" data-conditional="scale-control"></div></div><div class="treb-layout-resize-handle" data-conditional="resize"></div><div class="treb-revert-indicator" data-command="revert-indicator" data-title="document_modified"></div></div></template></div><div class="treb-layout-sidebar treb-animate"><button data-command="recalculate" data-title="recalculate"></button> <button data-command="toggle-toolbar" data-conditional="toolbar" data-title="toggle_toolbar"></button> <button data-command="export-xlsx" data-conditional="export" data-title="export"></button> <button data-command="revert" data-conditional="revert" data-title="revert"></button> <button data-command="about" data-title="about"></button></div><button class="treb-toggle-sidebar-button" data-title="toggle_sidebar"></button></div>';var _n='<div class="treb-menu" title="File menu" file-menu><button data-icon="file-menu" menu-target></button><div><button data-command="reset">New document</button><div separator></div><button data-command="import-file">Open file...</button> <button data-command="save-json">Save JSON</button><div separator xlsx-support></div><button data-command="export-xlsx" xlsx-support>Export XLSX</button></div></div><div composite narrow><button data-command="justify-left" data-target="justify" title="Left-align text"></button><div class="treb-menu"><button dropdown title="Text justify options"></button><div class="treb-icon-buttons" data-replace="justify"><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div></div></div><div composite narrow><button data-command="align-top" data-target="align" title="Align to top"></button><div class="treb-menu"><button dropdown title="Text align options"></button><div class="treb-icon-buttons" data-replace="align"><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div></div></div><div class="group" wide><button data-command="justify-left" title="Left-align text"></button> <button data-command="justify-center" title="Center-align text"></button> <button data-command="justify-right" title="Right-align text"></button></div><div class="group" wide><button data-command="align-top" title="Align to top"></button> <button data-command="align-middle" title="Align to middle"></button> <button data-command="align-bottom" title="Align to bottom"></button></div><div class="group" wide indent-group><button data-command="outdent" title="Decrease indent"></button> <button data-command="indent" title="Incrase indent"></button></div><div class="group"><button data-command="wrap-text" title="Wrap text"></button> <button data-command="merge-cells" data-id="merge" data-inactive-title="Merge cells" data-active-title="Unmerge cells"></button> <button data-command="lock-cells" data-inactive-title="Lock cells" data-active-title="Unlock cells"></button> <button data-command="freeze-panes" data-inactive-title="Freeze panes" data-active-title="Unfreeze panes" freeze-button></button> <button data-command="insert-table" data-icon="table" data-inactive-title="Insert table" data-active-title="Remove table" table-button></button><div class="treb-menu"><button data-icon="comment" data-inactive-title="Comment" data-active-title="Update comment"></button><div class="treb-comment-box"><textarea></textarea><div><button data-command="clear-comment">Clear</button> <button data-command="update-comment">Save</button></div></div></div></div><div composite><button data-command="border-bottom" data-target="border" title="Bottom border"></button><div class="treb-menu"><button dropdown title="Border options"></button><div class="treb-icon-buttons" data-replace="border"><button data-command="border-top" title="Top border"></button> <button data-command="border-left" title="Left border"></button> <button data-command="border-right" title="Right border"></button> <button data-command="border-bottom" title="Bottom border"></button> <button data-command="border-double-bottom" title="Double bottom border"></button> <button data-command="border-outside" title="Outside borders"></button> <button data-command="border-all" title="All borders"></button> <button data-command="border-none" title="Clear borders"></button><div separator></div><div class="treb-menu treb-color-menu treb-submenu" data-color-command="border-color" data-replace-color="border" title="Border color" data-default-color-text="Default border color"><button data-icon="palette" data-color-bar="border" data-color="{}"></button></div></div></div></div><div composite><button data-command="fill-color" data-color-bar="fill" data-color="{}" title="Fill color"></button><div class="treb-menu treb-color-menu" data-color-command="fill-color" data-replace-color="fill" data-default-color-text="No fill"><button dropdown title="Color options"></button><div class="treb-color-chooser"><div class="treb-caption">Theme colors</div><div class="treb-swatches"></div><div class="treb-caption">Other colors</div><div class="treb-swatches"></div><div><input placeholder="New color" class="treb-color-input"> <button data-command="set-color" data-color=""><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg></button></div></div></div></div><div composite><button data-command="text-color" data-color-bar="text" data-color="{}" title="Text color"></button><div class="treb-menu treb-color-menu" data-color-command="text-color" data-replace-color="text" data-default-color-text="Default text color"><button dropdown title="Color options"></button></div></div><div composite font-scale><div class="treb-font-scale-icon"></div><input class="treb-font-scale" title="Font scale"><div class="treb-menu"><button dropdown title="Font scale options"></button><div><button data-command="font-scale" data-scale="0.8">0.80</button> <button data-command="font-scale" data-scale="0.9">0.90</button> <button data-command="font-scale" data-scale="1.0">1.00</button> <button data-command="font-scale" data-scale="1.1">1.10</button> <button data-command="font-scale" data-scale="1.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 composite><input class="treb-number-format" title="Number format"><div class="treb-menu"><button dropdown title="Number formats"></button><div class="treb-number-format-menu"></div></div></div><div class="treb-split"><button data-command="decrease-precision" title="Decrease precision"></button> <button data-command="increase-precision" title="Increase precision"></button></div><div class="treb-menu"><button data-icon="layout" title="Rows & columns"></button><div><button data-command="insert-row">Insert row</button> <button data-command="insert-column">Insert column</button> <button data-command="delete-row">Delete row</button> <button data-command="delete-column">Delete column</button><div separator add-remove-sheet></div><button data-command="insert-sheet" add-remove-sheet>Add sheet</button> <button data-command="delete-sheet" add-remove-sheet>Delete sheet</button></div></div><div composite chart-menu><button data-command="insert-column-chart" data-target="annotation" title="Insert column chart"></button><div class="treb-menu"><button dropdown title="Chart options"></button><div class="treb-icon-buttons" data-replace="annotation"><button data-command="insert-column-chart" title="Insert column chart"></button> <button data-command="insert-donut-chart" title="Insert donut chart"></button> <button data-command="insert-bar-chart" title="Insert bar chart"></button> <button data-command="insert-line-chart" title="Insert line chart"></button><div separator></div><button data-command="insert-image" title="Insert image"></button></div></div></div><button data-command="recalculate" title="Recalculate" recalculate-button></button>';var yn={close_dialog:"Close dialog",insert_function:"Insert function...",delete_sheet:"Delete current sheet",add_sheet:"Add sheet",document_modified:"This document has been modified from the original version.",recalculate:"Recalculate",toggle_toolbar:"Toggle toolbar",export:"Export as XLSX",revert:"Revert to original version",about:"What's this?",toggle_sidebar:"Toggle sidebar"},Ye=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=P.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:bn,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 o of n){let a=o.split(/=/);a.length===1?e[a[0]]=!0:e[a[0]]=this.CoerceAttributeValue(a[1])}}continue;case"data-treb":continue;case"inline-document":continue;case"src":e.document=this.root.getAttribute("src")||void 0;continue}e[r.replace(/-/g,"_")]=this.CoerceAttributeValue(this.root.getAttribute(r))}}return{...e}}AttachElement(e={}){if(e={...this.ParseOptionAttributes(),...e},this.root){if(!e.headless){let t=this.root.getBoundingClientRect();(!t.width||!t.height)&&this.root.classList.add("treb-default-size")}if(this.root.hasAttribute("inline-document")){let t=this.root.getAttribute("inline-document")||"";for(let r of Array.from(this.root.children))if(this.DOM.view&&r instanceof this.DOM.view.HTMLScriptElement&&r.type==="application/json"){let i=r.getAttribute("name")||"";if(i===t||!i&&t==="true"){let n=r.textContent;if(n)try{e.inline_document=JSON.parse(n)}catch(o){console.error(o)}break}}e.inline_document||console.warn("inline document failed")}this.root.innerHTML=gn,e.container=this.root.querySelector(".treb-layout-spreadsheet")}this.sheet=new lr(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 l=this.layout_element;i.addEventListener("click",()=>{let d=l.getAttribute("collapsed");typeof d=="string"&&(d===""||d==="true")?l.removeAttribute("collapsed"):l.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",l=>{let d=l.target;if(d.dataset.command)switch(d.dataset.command){case"toggle-toolbar":this.ToggleToolbar();break;default:e.HandleToolbarMessage({command:d.dataset.command});break}}),e.options.toolbar&&this.AttachToolbar(e,t);let a={"table-button":!!e.options.table_button,revert:!!e.options.revert_button,toolbar:!!e.options.toolbar,export:!!e.options.export,"insert-function":!!e.options.insert_function_button,resize:!!e.options.resizable,"add-tab":!!e.options.add_tab,"delete-tab":!!e.options.delete_tab||!!e.options.add_tab};for(let[l,d]of Object.entries(a))if(!d){let h=this.layout_element.querySelectorAll(`[data-conditional=${l}]`);for(let u of Array.from(h))u.style.display="none"}if(e.options.revert_button&&(this.revert_button=this.layout_element.querySelector("[data-command=revert]")||void 0),e.options.resizable){let l={width:0,height:0},d={x:0,y:0},h={x:0,y:0};this.views=t.querySelector(".treb-views")||void 0;let u,m,f=t.querySelector(".treb-layout-resize-handle"),p=()=>g(),b=C=>{C.buttons===0?g():(h.x=C.screenX-d.x,h.y=C.screenY-d.y,m&&(m.style.width=l.width+h.x+"px",m.style.height=l.height+h.y+"px"))},g=()=>{if(h.x||h.y){let C=t.getBoundingClientRect();e.options.constrain_width||(t.style.width=C.width+h.x+"px"),t.style.height=C.height+h.y+"px"}u&&(u.removeEventListener("mouseup",p),u.removeEventListener("mousemove",b),u.parentElement?.removeChild(u),u=void 0),m?.parentElement?.removeChild(m),m=void 0};f.addEventListener("mousedown",C=>{C.stopPropagation(),C.preventDefault();let x=t.querySelector(".treb-main");m=this.DOM.Div("treb-resize-rect",x),u=this.DOM.Div("treb-resize-mask",x,{attrs:{style:"cursor: nw-resize;"},events:{mouseup:p,mousemove:b}}),d.x=C.screenX,d.y=C.screenY,h.x=0,h.y=0;let v=this.views?.querySelectorAll(".treb-spreadsheet-body"),_=Array.from(v||[]).map(w=>w.getBoundingClientRect());if(_.length){let w=JSON.parse(JSON.stringify(_.shift()));for(let I of _)w.top=Math.min(I.top,w.top),w.left=Math.min(I.left,w.left),w.right=Math.max(I.right,w.right),w.bottom=Math.max(I.bottom,w.bottom);let A=w.right-w.left,S=w.bottom-w.top;m.style.top=w.top+"px",m.style.left=w.left+"px",m.style.width=A+"px",m.style.height=S+"px",l.width=A,l.height=S}})}let s=Array.from(this.layout_element.querySelectorAll("[data-title]"));for(let l of s)if(l instanceof HTMLElement){if(l.dataset.activeTitle)continue;l.dataset.title&&yn[l.dataset.title]&&(l.title=yn[l.dataset.title])}setTimeout(()=>this.layout_element?.setAttribute("animate",""),250)}ToggleToolbar(){if(this.layout_element){let e=this.layout_element.getAttribute("toolbar");typeof e=="string"&&(e===""||e==="true")?this.layout_element.removeAttribute("toolbar"):this.layout_element.setAttribute("toolbar","")}}UpdateSelectionStyle(e,t,r){let i=e.selection_state;r.value="";for(let s of Object.values(this.toolbar_controls))s&&(s.removeAttribute("active"),s.dataset.inactiveTitle&&(s.title=s.dataset.inactiveTitle));let n=s=>{s&&(s.setAttribute("active",""),s.dataset.activeTitle&&(s.title=s.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 o=this.toolbar_controls.format;o&&(i.style?.number_format?o.value=z.SymbolicName(i.style.number_format)||i.style.number_format:o.value="General");let a=this.toolbar_controls.scale;switch(a&&(a.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 a=this.DOM.Fragment(),s=e.document_styles.theme_colors.length,l=["Background","Text","Background","Text","Accent"];if(s){let m=e.document_styles.theme_colors[0].length;for(let f=0;f<m;f++)for(let p=0;p<s;p++){let b=e.document_styles.theme_colors[p][f],g=`background: ${b.resolved};`,C=l[p]||l[4];Ze(b.color)&&b.color.tint?C+=` (${(b.color.tint>0?"+":"")+b.color.tint*100}%)`:p===0?this.color_bar_elements.fill?.style.setProperty("--treb-default-color",b.resolved):p===1&&(this.color_bar_elements.text?.style.setProperty("--treb-default-color",b.resolved),this.color_bar_elements.border?.style.setProperty("--treb-default-color",b.resolved)),this.DOM.Create("button",void 0,a,{attrs:{style:g,title:C},data:{command:"set-color",color:JSON.stringify(b.color)}})}}this.swatch_lists.theme?.replaceChildren(a),a=this.DOM.Fragment(),this.DOM.Create("button","treb-default-color",a,{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,a,{attrs:{style:f,title:m},data:{command:"set-color",color:JSON.stringify({text:m.toLowerCase()})}})}this.swatch_lists.other?.replaceChildren(a)}let r=["General","Number","Integer","Percent","Fraction","Accounting","Currency","Scientific"],i=["Timestamp","Long Date","Short Date"];for(let a of e.document_styles.number_formats){if(z.SymbolicName(z.Translate(a)))continue;z.Get(a).date_format?i.push(a):r.push(a)}let n=a=>this.DOM.Create("button",void 0,void 0,{text:a,data:{format:a,command:"number-format"}}),o=this.DOM.Fragment();o.append(...r.map(a=>n(a))),o.append(this.DOM.Div(void 0,void 0,{attrs:{separator:""}})),o.append(...i.map(a=>n(a))),t.textContent="",t.append(o)}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=_n;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.indent_buttons||n.push(i.querySelector("[indent-group]")),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 x of n)x&&x.parentElement?.removeChild(x);let o=i.querySelector(".treb-color-chooser"),a=i.querySelector(".treb-comment-box textarea");for(let[x,v]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 _=i.querySelector(v);_&&(this.toolbar_controls[x]=_)}let s=o.querySelectorAll(".treb-swatches");this.swatch_lists={theme:s[0],other:s[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]"),a.addEventListener("keydown",x=>{x.key==="Enter"&&(x.shiftKey||x.ctrlKey)&&l.click()});for(let x of["border","annotation","align","justify"])this.replace_targets[x]=i.querySelector(`[data-target=${x}`);for(let x of["fill","text","border"])this.color_bar_elements[x]=i.querySelector(`[data-color-bar=${x}]`);i.addEventListener("click",x=>{let v=x.target,_={format:v.dataset.format,scale:v.dataset.scale},w=v?.dataset.command;if(w){let A=v.parentElement?.dataset.replace;if(A){let S=this.replace_targets[A];S&&(S.dataset.command=w,S.title=v.title||"")}switch(/^border-/.test(w)&&(_.color=this.border_color||{}),w){case"text-color":case"fill-color":_.color={};try{_.color=JSON.parse(v.dataset.color||"{}")}catch(S){console.error(S)}break;case"set-color":w=o.dataset.colorCommand||"",_.color={};try{_.color=JSON.parse(v.dataset.color||"{}")}catch(S){console.error(S)}if(w==="border-color"&&(this.border_color=_.color),o.dataset.target){let S=this.color_bar_elements[o.dataset.target];S&&(S.style.setProperty("--treb-color-bar-color",v.style.backgroundColor),S.dataset.color=v.dataset.color||"{}")}break;case"update-comment":_.comment=a.value;break}e.HandleToolbarMessage({command:w,..._})}});let d=(x,v)=>{let _=i.querySelector(x);if(_){let w="";_.addEventListener("focusin",()=>w=_.value),_.addEventListener("keydown",A=>{switch(A.key){case"Escape":_.value=w,e.Focus();break;case"Enter":v(_.value)||(_.value=w,e.Focus());break;default:return}A.stopPropagation(),A.preventDefault()})}};d("input.treb-number-format",x=>x?(e.HandleToolbarMessage({command:"number-format",format:x}),!0):!1),d("input.treb-font-scale",x=>{let v=Number(x);return!v||isNaN(v)?(console.warn("invalid scale value"),!1):(e.HandleToolbarMessage({command:"font-scale",scale:v}),!0)});let h=o.querySelector("input"),u=o.querySelector("input + button");h.addEventListener("input",x=>{if(x instanceof InputEvent&&x.isComposing)return;u.style.background=h.value||"";let v=u.style.backgroundColor||"#fff",_=ye.MeasureColor(v),w=K.RGBToHSL(_[0],_[1],_[2]);u.style.color=w.l>.5?"#000":"#fff",u.dataset.color=JSON.stringify(u.style.backgroundColor?{text:u.style.backgroundColor}:{})}),h.addEventListener("keydown",x=>{x.key==="Enter"&&(x.stopPropagation(),x.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=x=>{x.key==="Escape"&&(x.stopPropagation(),x.preventDefault(),Promise.resolve().then(()=>e.Focus()))},p=x=>{if(m){if(x.relatedTarget instanceof Node&&i.contains(x.relatedTarget))return;i.removeEventListener("keydown",f),i.removeEventListener("focusout",p),m=!1}},b=x=>{let v=x.target,_=v?.parentElement;if(v?.classList.contains("treb-menu")){_=v;for(let w of Array.from(_.children))if(w.tagName==="BUTTON"){v=w;break}}else if(!_?.classList.contains("treb-menu"))return;if(v&&_){m||(i.addEventListener("focusout",p),i.addEventListener("keydown",f),m=!0),_.dataset.colorCommand&&(o.querySelector(".treb-default-color")?.setAttribute("title",_.dataset.defaultColorText||"Default color"),_.appendChild(o),o.dataset.colorCommand=_.dataset.colorCommand,o.dataset.target=_.dataset.replaceColor||"");let w=_.querySelector("div"),A=r.getBoundingClientRect(),S=v.getBoundingClientRect(),{left:I}=S,L=_.parentElement;L?.hasAttribute("composite")&&(I=L.firstElementChild.getBoundingClientRect().left);let O=w.getBoundingClientRect();_.classList.contains("treb-submenu")?(w.style.top=S.top-O.height/2+"px",I+S.width+6+O.width>A.right?w.style.left=I-6-O.width+"px":w.style.left=I+S.width+6+"px"):(w.style.top=S.bottom+"px",I+O.width>A.right-6?w.style.left=S.right-O.width+"px":w.style.left=I+"px");let _e=w.querySelector("textarea");_e&&requestAnimationFrame(()=>_e.focus())}},g=this.root?.querySelector(".treb-number-format-menu");g&&(this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a),e.Subscribe(x=>{switch(x.type){case"focus-view":break;case"data":case"document-change":case"load":case"reset":this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a),this.UpdateRevertState(e);break;case"theme-change":this.UpdateDocumentStyles(e,g),this.UpdateSelectionStyle(e,i,a);break;case"selection":this.UpdateSelectionStyle(e,i,a);break}}));let C=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);if(i.addEventListener("focusin",x=>{b(x)}),C){let x=Array.from(i.querySelectorAll(".treb-menu"));for(let v of x)v.tabIndex=0;i.addEventListener("mousedown",v=>{b(v)})}}};var cr=class{version="29.5.4";CreateSpreadsheet(e){let t=e.container,r=new Ye(t);if(r.AttachElement(e),!r.sheet)throw new Error("construction failed");return r.sheet}},Yo=new cr;if(typeof HTMLElement<"u"){class c extends HTMLElement{get sheet(){return this.instance.sheet}instance;constructor(){super(),this.instance=new Ye(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{Yo as TREB,cr as TREBGlobal};