@odoo/o-spreadsheet 18.2.19 → 18.2.20

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.
@@ -6,7 +6,7 @@
6
6
  z-index: ${Fe.FigureTooltip};
7
7
  }
8
8
  }
9
- `,nh.add("chartShowValuesPlugin",{register:e=>e.register(Oh),unregister:e=>e.unregister(Oh)}),nh.add("waterfallLinesPlugin",{register:e=>e.register(Mh),unregister:e=>e.unregister(Mh)});class kh extends t.Component{static template="o-spreadsheet-ChartJsComponent";static props={figure:Object};canvas=t.useRef("graphContainer");chart;currentRuntime;currentDevicePixelRatio=window.devicePixelRatio;get background(){return this.chartRuntime.background}get canvasStyle(){return`background-color: ${this.background}`}get chartRuntime(){const e=this.env.model.getters.getChartRuntime(this.props.figure.id);if(!("chartJsConfig"in e))throw new Error("Unsupported chart runtime");return e}setup(){t.onMounted((()=>{const e=this.chartRuntime;this.currentRuntime=e,this.createChart(ze(e.chartJsConfig))})),t.onWillUnmount((()=>this.chart?.destroy())),t.useEffect((()=>{const e=this.chartRuntime;e!==this.currentRuntime?(e.chartJsConfig.type!==this.currentRuntime.chartJsConfig.type?(this.chart?.destroy(),this.createChart(ze(e.chartJsConfig))):this.updateChartJs(ze(e.chartJsConfig)),this.currentRuntime=e):this.currentDevicePixelRatio!==window.devicePixelRatio&&(this.currentDevicePixelRatio=window.devicePixelRatio,this.updateChartJs(ze(this.currentRuntime.chartJsConfig)))}))}createChart(e){const t=this.canvas.el.getContext("2d");this.chart=new window.Chart(t,e)}updateChartJs(e){e.data&&e.data.datasets?(this.chart.data=e.data,e.options?.plugins?.title&&(this.chart.config.options.plugins.title=e.options.plugins.title)):this.chart.data.datasets=[],this.chart.config.options=e.options,this.chart.update()}}class Vh{sheetId;title;getters;constructor(e,t,o){this.title=e.title,this.sheetId=t,this.getters=o}static validateChartDefinition(e,t){throw new Error("This method should be implemented by sub class")}static transformDefinition(e,t){throw new Error("This method should be implemented by sub class")}static getDefinitionFromContextCreation(e){throw new Error("This method should be implemented by sub class")}}function Lh(e,t,o,s,i){if("text"===t||"progress"===t||e?.type!==oi.number||o?.type!==oi.number)return;const n=o.value-e.value;return n>0?s:n<0?i:void 0}function Hh(e,t,o){if("text"===o||e?.type!==oi.number||t?.type!==oi.number)return"neutral";const s=t.value-e.value;return s>0?"up":s<0?"down":"neutral"}function Uh(e){return e.keyValue&&!Br.test(e.keyValue)?"InvalidScorecardKeyValue":"Success"}function Bh(e){return e.baseline&&!Br.test(e.baseline)?"InvalidScorecardBaseline":"Success"}const zh=new window.Path2D("M8.6 4.8a.5.5 0 0 1 0 .75l-3.9 3.9a.5 .5 0 0 1 -.75 0l-3.8 -3.9a.5 .5 0 0 1 0 -.75l.4-.4a.5.5 0 0 1 .75 0l2.3 2.4v-5.7c0-.25.25-.5.5-.5h.6c.25 0 .5.25.5.5v5.8l2.3 -2.4a.5.5 0 0 1 .75 0z"),$h=new window.Path2D("M8.7 5.5a.5.5 0 0 0 0-.75l-3.8-4a.5.5 0 0 0-.75 0l-3.8 4a.5.5 0 0 0 0 .75l.4.4a.5.5 0 0 0 .75 0l2.3-2.4v5.8c0 .25.25.5.5.5h.6c.25 0 .5-.25.5-.5v-5.8l2.2 2.4a.5.5 0 0 0 .75 0z");let Gh=class e extends Vh{keyValue;baseline;baselineMode;baselineDescr;progressBar=!1;background;baselineColorUp;baselineColorDown;fontColor;humanize;type="scorecard";constructor(e,t,o){super(e,t,o),this.keyValue=Xr(o,t,e.keyValue),this.baseline=Xr(o,t,e.baseline),this.baselineMode=e.baselineMode,this.baselineDescr=e.baselineDescr,this.background=e.background,this.baselineColorUp=e.baselineColorUp??Ee,this.baselineColorDown=e.baselineColorDown??Re,this.humanize=e.humanize??!1}static validateChartDefinition(e,t){return e.checkValidations(t,Uh,Bh)}static getDefinitionFromContextCreation(e){return{background:e.background,type:"scorecard",keyValue:e.range?e.range[0].dataRange:void 0,title:e.title||{text:""},baselineMode:Ie,baselineColorUp:Ee,baselineColorDown:Re,baseline:e.auxiliaryRange||""}}static transformDefinition(e,t){let o,s;return e.baseline&&(o=Nc(zo(e.baseline),t)),e.keyValue&&(s=Nc(zo(e.keyValue),t)),{...e,baseline:o?qo(o):void 0,keyValue:s?qo(s):void 0}}duplicateInDuplicatedSheet(t){const o=dh(this.sheetId,t,this.baseline),s=dh(this.sheetId,t,this.keyValue),i=this.getDefinitionWithSpecificRanges(o,s,t);return new e(i,t,this.getters)}copyInSheetId(t){const o=this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue,t);return new e(o,t,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue)}getContextCreation(){return{...this,range:this.keyValue?[{dataRange:this.getters.getRangeString(this.keyValue,this.sheetId)}]:void 0,auxiliaryRange:this.baseline?this.getters.getRangeString(this.baseline,this.sheetId):void 0}}getDefinitionWithSpecificRanges(e,t,o){return{baselineColorDown:this.baselineColorDown,baselineColorUp:this.baselineColorUp,baselineMode:this.baselineMode,title:this.title,type:"scorecard",background:this.background,baseline:e?this.getters.getRangeString(e,o||this.sheetId):void 0,baselineDescr:this.baselineDescr,keyValue:t?this.getters.getRangeString(t,o||this.sheetId):void 0,humanize:this.humanize}}getDefinitionForExcel(){}updateRanges(t){const o=uh(this.baseline,t),s=uh(this.keyValue,t);if(this.baseline===o&&this.keyValue===s)return this;const i=this.getDefinitionWithSpecificRanges(o,s);return new e(i,this.sheetId,this.getters)}};function Wh(e,t){const o=t.getContext("2d"),s=window.devicePixelRatio||1;t.width=s*e.canvas.width,t.height=s*e.canvas.height,o.scale(s,s);const i=e.canvas.width-2*Z;if(o.fillStyle=e.canvas.backgroundColor,o.fillRect(0,0,e.canvas.width,e.canvas.height),e.title){o.font=e.title.style.font,o.fillStyle=e.title.style.color;const t=o.textBaseline;o.textBaseline="middle",o.fillText(Ca(o,e.title.text,i-e.title.position.x),e.title.position.x,e.title.position.y),o.textBaseline=t}if(e.baseline&&(o.font=e.baseline.style.font,o.fillStyle=e.baseline.style.color,wa(o,e.baseline.text,e.baseline.position,e.baseline.style.underline,e.baseline.style.strikethrough)),e.baselineArrow&&e.baselineArrow.style.size>0){o.save(),o.fillStyle=e.baselineArrow.style.color,o.translate(e.baselineArrow.position.x,e.baselineArrow.position.y);const t=e.baselineArrow.style.size/10;switch(o.scale(t,t),e.baselineArrow.direction){case"down":o.fill(zh);break;case"up":o.fill($h)}o.restore()}if(e.baselineDescr){const t=e.baselineDescr[0];o.font=t.style.font,o.fillStyle=t.style.color;for(const t of e.baselineDescr)o.fillText(Ca(o,t.text,i-t.position.x),t.position.x,t.position.y)}if(e.key&&(o.font=e.key.style.font,o.fillStyle=e.key.style.color,wa(o,Ca(o,e.key.text,i-e.key.position.x),e.key.position,e.key.style.underline,e.key.style.strikethrough)),e.progressBar){if(o.fillStyle=e.progressBar.style.backgroundColor,o.beginPath(),o.roundRect(e.progressBar.position.x,e.progressBar.position.y,e.progressBar.dimension.width,e.progressBar.dimension.height,e.progressBar.dimension.height/2),o.fill(),o.fillStyle=e.progressBar.style.color,o.beginPath(),e.progressBar.value>0)o.roundRect(e.progressBar.position.x,e.progressBar.position.y,e.progressBar.dimension.width*Math.max(0,Math.min(1,e.progressBar.value)),e.progressBar.dimension.height,e.progressBar.dimension.height/2);else{const t=e.progressBar.dimension.width*Math.max(0,Math.min(1,-e.progressBar.value));o.roundRect(e.progressBar.position.x+e.progressBar.dimension.width-t,e.progressBar.position.y,t,e.progressBar.dimension.height,e.progressBar.dimension.height/2)}o.fill()}}function qh(e,t){let o,s="";const i=t.getLocale();if(e.keyValue){const n={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};o=t.getEvaluatedCell(n),s=function(e,t,o){return e?t?fr(e,o):e.formattedValue??String(e.value??""):""}(o,e.humanize??!1,i)}let n;const r=e.baseline;if(r){const e={sheetId:r.sheetId,col:r.zone.left,row:r.zone.top};n=t.getEvaluatedCell(e)}const{background:a,fontColor:l}=t.getStyleOfSingleCellChart(e.background,e.keyValue),c=function(e,t,o,s,i){if(!e)return"";if("text"===o||t?.type!==oi.number||e.type!==oi.number)return s?fr(e,i):e.formattedValue;let{value:n,format:r}=e;return"progress"===o?(n=t.value/n,r="0.0%"):(n=Math.abs(t.value-n),"percentage"===o&&0!==n&&(n/=e.value),"percentage"===o&&(r="0.0%"),r||(n=Math.round(100*n)/100)),s?fr({value:n,format:r},i):Kn(n,{format:r,locale:i})}(n,o,e.baselineMode,e.humanize??!1,i),h="progress"===e.baselineMode&&Js(c,i)?ki(c,i):0;return{title:{...e.title,text:e.title.text?Uo(e.title.text):""},keyValue:s,baselineDisplay:c,baselineArrow:Hh(n,o,e.baselineMode),baselineColor:Lh(n,e.baselineMode,o,e.baselineColorUp,e.baselineColorDown),baselineDescr:"progress"!==e.baselineMode&&e.baselineDescr?Uo(e.baselineDescr):"",fontColor:l,background:a,baselineStyle:"percentage"!==e.baselineMode&&"progress"!==e.baselineMode&&r?t.getCellStyle({sheetId:r.sheetId,col:r.zone.left,row:r.zone.top}):void 0,keyValueStyle:e.keyValue?t.getCellStyle({sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top}):void 0,progressBar:"progress"===e.baselineMode?{value:h,color:h>0?e.baselineColorUp:e.baselineColorDown}:void 0}}const Zh=10,jh=.05;function Yh({width:e,height:t},o){return new Xh({width:e,height:t},o).computeDesign()}class Xh{runtime;context;width;height;constructor({width:e,height:t},o){this.runtime=o;const s=document.createElement("canvas");this.width=s.width=e,this.height=s.height=t,this.context=s.getContext("2d")}computeDesign(){const e={canvas:{width:this.width,height:this.height,backgroundColor:this.backgroundColor}},t=this.getTextStyles();let o=0;if(this.title){let s,i;switch(({height:o,width:i}=this.getFullTextDimensions(this.title,t.title.font)),this.runtime.title.align){case"center":s=(this.width-i)/2;break;case"right":s=this.width-i-Zh;break;default:s=Zh}e.title={text:this.title,style:t.title,position:{x:s,y:Zh+o/2}}}const s=t.baselineArrow?.size??0;let{height:i,width:n}=this.getTextDimensions(this.baseline,t.baselineValue.font);this.baseline||(i=this.getTextDimensions(this.baselineDescr,t.baselineDescr.font).height);const r=this.getTextDimensions(this.baselineDescr,t.baselineDescr.font).width;e.baseline={text:this.baseline,style:t.baselineValue,position:{x:(this.width-n-r+s)/2,y:this.keyValue?this.height*(1-jh*(this.runtime.progressBar?1:2)):this.height-(this.height-o-i)/2-Zh}};const a=s+20;if(e.baseline.position.x<a&&(e.baseline.position.x=a),t.baselineArrow&&!this.runtime.progressBar&&(e.baselineArrow={direction:this.baselineArrow,style:t.baselineArrow,position:{x:e.baseline.position.x-s,y:e.baseline.position.y-(i+s)/2}}),this.baselineDescr){const o={x:e.baseline.position.x+n,y:e.baseline.position.y};e.baselineDescr=[{text:this.baselineDescr,style:t.baselineDescr,position:o}]}let l=0;this.runtime.progressBar&&(l=.05*this.height,e.progressBar={position:{x:20,y:.9*this.height-i-l},dimension:{height:l,width:this.width-40},value:this.runtime.progressBar.value,style:{color:this.runtime.progressBar.color,backgroundColor:this.secondaryFontColor}});const{width:c,height:h}=this.getFullTextDimensions(this.keyValue,t.keyValue.font);return this.keyValue&&(e.key={text:this.keyValue,style:t.keyValue,position:{x:Math.max(Zh,(this.width-c)/2),y:.4*this.height+5+(o+h/2)/2}}),e}get title(){return this.runtime.title.text??""}get keyValue(){return this.runtime.keyValue}get baseline(){return this.runtime.baselineDisplay}get baselineDescr(){return function(e,t){const o=e||"";return t&&o?" "+o:o}(this.runtime.baselineDescr,this.baseline)}get baselineArrow(){return this.runtime.baselineArrow}get backgroundColor(){return this.runtime.background}get secondaryFontColor(){return Sh(this.backgroundColor)}getTextDimensions(e,t){this.context.font=t;const o=this.context.measureText(e);return{width:o.width,height:o.actualBoundingBoxAscent+o.actualBoundingBoxDescent}}getFullTextDimensions(e,t){this.context.font=t;const o=this.context.measureText(e);return{width:o.width,height:o.fontBoundingBoxAscent+o.fontBoundingBoxDescent}}getTextStyles(){let e=16;const t=Math.floor(.9*e);return this.runtime.progressBar&&(e/=1.5),{title:{font:la(this.runtime.title.fontSize??14,this.runtime.title.bold,this.runtime.title.italic),color:this.runtime.title.color??this.secondaryFontColor},keyValue:{color:this.runtime.keyValueStyle?.textColor||this.runtime.fontColor,font:la(32,this.runtime.keyValueStyle?.bold,this.runtime.keyValueStyle?.italic),strikethrough:this.runtime.keyValueStyle?.strikethrough,underline:this.runtime.keyValueStyle?.underline},baselineValue:{font:la(e,this.runtime.baselineStyle?.bold,this.runtime.baselineStyle?.italic),strikethrough:this.runtime.baselineStyle?.strikethrough,underline:this.runtime.baselineStyle?.underline,color:this.runtime.baselineStyle?.textColor||this.runtime.baselineColor||this.secondaryFontColor},baselineDescr:{font:la(t),color:this.secondaryFontColor},baselineArrow:"neutral"===this.baselineArrow||this.runtime.progressBar?void 0:{size:this.keyValue?.8*e:0,color:this.runtime.baselineColor||this.secondaryFontColor}}}}class Kh extends t.Component{static template="o-spreadsheet-ScorecardChart";static props={figure:Object};canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}get title(){const e=this.env.model.getters.getChartDefinition(this.props.figure.id).title.text??"";return Uo(e)}setup(){t.useEffect(this.createChart.bind(this),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el,window.devicePixelRatio]}))}createChart(){const e=this.canvas.el;Wh(Yh(e.getBoundingClientRect(),this.runtime),e)}}const Jh=new n;function Qh(e,t,o,s){const i=[];e=e.toLowerCase();for(const n of e){const e=t.toLocaleLowerCase().indexOf(n);-1!==e&&(i.push({value:t.slice(0,e),color:""},{value:t[e],color:o,class:s}),t=t.slice(e+1))}return i.push({value:t}),i.filter((e=>e.value))}Jh.add("dataValidation",{displayAllOnInitialContent:!0,getProposals(e,t){if(t.startsWith("="))return[];if(!this.composer.currentEditedCell)return[];const o=this.composer.currentEditedCell,s=this.getters.getValidationRuleForCell(o);if(!s||"isValueInList"!==s.criterion.type&&"isValueInRange"!==s.criterion.type)return[];let i;if("isValueInList"===s.criterion.type)i=s.criterion.values;else{const e=this.getters.getRangeFromSheetXC(o.sheetId,s.criterion.values[0]);i=Array.from(new Set(this.getters.getRangeValues(e).filter(ct).map((e=>e.toString())).filter((e=>""!==e))))}return i.map((e=>({text:e})))},selectProposal(e,t){this.composer.setCurrentContent(t),this.composer.stopEdition()}});const ed=/(.*?)\((.*?)\)(.*)/,td=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>","META"];function od(e,t=""){return function(e,t){let o=e.match(ed),s=o[1].trim();if(!s)throw new Error(`Function argument definition is missing a name: '${e}'.`);let i,n=[],r=!1,a=!1;for(let e of o[2].split(",")){const t=e.trim().toUpperCase();let o=td.find((e=>t===e));o?n.push(o):"RANGE<ANY>"===t?n.push("RANGE"):"OPTIONAL"===t?r=!0:"REPEATING"===t?a=!0:t.startsWith("DEFAULT=")&&(i=e.trim().slice(8))}const l={name:s,description:t,type:n};(n.includes("ANY")||n.includes("RANGE"))&&(l.acceptErrors=!0);r&&(l.optional=!0);a&&(l.repeating=!0);void 0!==i&&(l.default=!0,l.defaultValue=i);n.some((e=>e.startsWith("RANGE")))&&(l.acceptMatrix=!0);n.every((e=>e.startsWith("RANGE")))&&(l.acceptMatrixOnly=!0);return l}(e,t)}function sd(e){let t=0,o=0,s=0;for(let i of e.args)t++,i.optional||i.repeating||i.default||o++,i.repeating&&s++;const i=e;return i.minArgRequired=o,i.maxArgPossible=s?1/0:t,i.nbrArgRepeating=s,i.getArgToFocus=function(e,t){if(!t)return e=>e;if(1===t)return t=>Math.min(t,e);const o=e-t;return e=>{if(e<=o)return e;return o+((e-o)%t||t)}}(t,s),i.hidden=e.hidden||!1,i}function id(e,t){Fi((()=>1===t.length||1===t[0].length),e)}function nd(e,...t){if(t.every(bi)){const o=t[0].length,s=t[0][0].length;for(const i of t)Fi((()=>i.length===o&&i[0].length===s),e)}else if(t.some((e=>Array.isArray(e)&&(1!==e.length||1!==e[0].length))))throw new Ii(e)}function rd(e,t){Fi((()=>t>0),e)}function ad(e,t){Fi((()=>t.length===t[0].length),e)}const ld={description:Uo("Returns a result array constrained to a specific width and height."),args:[od("input_range (any, range<any>)",Uo("The range to constrain.")),od("rows (number)",Uo("The number of rows in the constrained array.")),od("columns (number)",Uo("The number of columns in the constrained array."))],compute:function(e,t,o){const s=vn(e),i=Ui(t?.value,this.locale),n=Ui(o?.value,this.locale);rd(Uo("The rows argument (%s) must be strictly positive.",i.toString()),i),rd(Uo("The columns argument (%s) must be strictly positive.",i.toString()),n);const r=Math.min(i,s[0].length);return sn(Math.min(n,s.length),r,((e,t)=>s[e][t]))},isExported:!1},cd={description:Uo("Creates a new array from the selected columns in the existing range."),args:[od("array (any, range<any>)",Uo("The array that contains the columns to be returned.")),od("col_num (number, range<number>)",Uo("The first column index of the columns to be returned.")),od("col_num2 (number, range<number>, repeating)",Uo("The columns indexes of the columns to be returned."))],compute:function(e,...t){const o=vn(e),s=bn(t,(e=>Ui(e?.value,this.locale))),i=s.filter((e=>0===e||o.length<Math.abs(e)));Fi((()=>0===i.length),Uo("The columns arguments must be between -%s and %s (got %s), excluding 0.",o.length.toString(),o.length.toString(),i.join(",")));const n=Array(s.length);for(let e=0;e<s.length;e++)s[e]>0?n[e]=o[s[e]-1]:n[e]=o[o.length+s[e]];return n},isExported:!0},hd={description:Uo("Creates a new array from the selected rows in the existing range."),args:[od("array (any, range<any>)",Uo("The array that contains the rows to be returned.")),od("row_num (number, range<number>)",Uo("The first row index of the rows to be returned.")),od("row_num2 (number, range<number>, repeating)",Uo("The rows indexes of the rows to be returned."))],compute:function(e,...t){const o=vn(e),s=bn(t,(e=>Ui(e?.value,this.locale))),i=o.length,n=s.filter((e=>0===e||o[0].length<Math.abs(e)));return Fi((()=>0===n.length),Uo("The rows arguments must be between -%s and %s (got %s), excluding 0.",o[0].length.toString(),o[0].length.toString(),n.join(","))),sn(i,s.length,((e,t)=>s[t]>0?o[e][s[t]-1]:o[e][o[e].length+s[t]]))},isExported:!0},dd={description:Uo("Expands or pads an array to specified row and column dimensions."),args:[od("array (any, range<any>)",Uo("The array to expand.")),od("rows (number)",Uo("The number of rows in the expanded array. If missing, rows will not be expanded.")),od("columns (number, optional)",Uo("The number of columns in the expanded array. If missing, columns will not be expanded.")),od("pad_with (any, default=0)",Uo("The value with which to pad."))],compute:function(e,t,o,s={value:0}){const i=vn(e),n=Ui(t?.value,this.locale),r=void 0!==o?Ui(o.value,this.locale):i.length;return Fi((()=>n>=i[0].length),Uo("The rows arguments (%s) must be greater or equal than the number of rows of the array.",n.toString())),Fi((()=>r>=i.length),Uo("The columns arguments (%s) must be greater or equal than the number of columns of the array.",r.toString())),sn(r,n,((e,t)=>e>=i.length||t>=i[e].length?s:i[e][t]))},isExported:!0},ud={description:Uo("Flattens all the values from one or more ranges into a single column."),args:[od("range (any, range<any>)",Uo("The first range to flatten.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to flatten."))],compute:function(...e){return[bn(e,(e=>void 0===e?{value:""}:e))]},isExported:!1},gd={description:Uo("Calculates the frequency distribution of a range."),args:[od("data (range<number>)",Uo("The array of ranges containing the values to be counted.")),od("classes (number, range<number>)",Uo("The range containing the set of classes."))],compute:function(e,t){const o=bn([e],(e=>e.value)).filter((e=>"number"==typeof e)),s=bn([t],(e=>e.value)).filter((e=>"number"==typeof e)),i=s.map(((e,t)=>({initialIndex:t,value:e,count:0}))).sort(((e,t)=>e.value-t.value));i.push({initialIndex:i.length,value:1/0,count:0});const n=o.sort(((e,t)=>e-t));let r=0;for(const e of n){for(;e>i[r].value&&r<i.length-1;)r++;i[r].count++}return[i.sort(((e,t)=>e.initialIndex-t.initialIndex)).map((e=>e.count))]},isExported:!0},pd={description:Uo("Appends ranges horizontally and in sequence to return a larger array."),args:[od("range1 (any, range<any>)",Uo("The first range to be appended.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to add to range1."))],compute:function(...e){const t=Math.max(...e.map((e=>e?.[0]?.length??0))),o=[];for(const s of e){const e=vn(s);for(let s=0;s<e.length;s++){const i=Array(t).fill({value:null});for(let t=0;t<e[s].length;t++)i[t]=e[s][t];o.push(i)}}return o},isExported:!0},md={description:Uo("Returns the matrix determinant of a square matrix."),args:[od("square_matrix (number, range<number>)",Uo("An range with an equal number of rows and columns representing a matrix whose determinant will be calculated."))],compute:function(e){const t=Li(e,"square_matrix");return ad(Uo("The argument square_matrix must have the same number of columns and rows."),t),fl(t).determinant},isExported:!0},fd={description:Uo("Returns the multiplicative inverse of a square matrix."),args:[od("square_matrix (number, range<number>)",Uo("An range with an equal number of rows and columns representing a matrix whose multiplicative inverse will be calculated."))],compute:function(e){const t=Li(e,"square_matrix");ad(Uo("The argument square_matrix must have the same number of columns and rows."),t);const{inverted:o}=fl(t);return o||new Ii(Uo("The matrix is not invertible."))},isExported:!0},vd={description:Uo("Calculates the matrix product of two matrices."),args:[od("matrix1 (number, range<number>)",Uo("The first matrix in the matrix multiplication operation.")),od("matrix2 (number, range<number>)",Uo("The second matrix in the matrix multiplication operation."))],compute:function(e,t){const o=Li(e,"matrix1"),s=Li(t,"matrix2");return Fi((()=>o.length===s[0].length),Uo("In [[FUNCTION_NAME]], the number of columns of the first matrix (%s) must be equal to the number of rows of the second matrix (%s).",o.length.toString(),s[0].length.toString())),bl(o,s)},isExported:!0},bd={description:Uo("Calculates the sum of the products of corresponding entries in equal-sized ranges."),args:[od("range1 (number, range<number>)",Uo("The first range whose entries will be multiplied with corresponding entries in the other ranges.")),od("range2 (number, range<number>, repeating)",Uo("The other range whose entries will be multiplied with corresponding entries in the other ranges."))],compute:function(...e){nd(Uo("All the ranges must have the same dimensions."),...e);const t=e.map(vn);let o=0;for(let e=0;e<t[0].length;e++)for(let s=0;s<t[0][e].length;s++){if(!t.every((t=>"number"==typeof t[e][s].value)))continue;let i=1;for(const o of t)i*=ki(o[e][s],this.locale);o+=i}return o},isExported:!0};function Sd(e,t,o){nd("The arguments array_x and array_y must have the same dimensions.",e,t);const s=vn(e),i=vn(t);let n=!1,r=0;for(const e in s)for(const t in s[e]){const a=s[e][t].value,l=i[e][t].value;"number"==typeof a&&"number"==typeof l&&(n=!0,r+=o(a,l))}return n?r:new Ii(Uo("The arguments array_x and array_y must contain at least one pair of numbers."))}const yd={description:Uo("Calculates the sum of the difference of the squares of the values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values whose squares will be reduced by the squares of corresponding entries in array_y and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values whose squares will be subtracted from the squares of corresponding entries in array_x and added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>e**2-t**2))},isExported:!0},Cd={description:Uo("Calculates the sum of the sum of the squares of the values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values whose squares will be added to the squares of corresponding entries in array_y and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values whose squares will be added to the squares of corresponding entries in array_x and added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>e**2+t**2))},isExported:!0},wd={description:Uo("Calculates the sum of squares of the differences of values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values that will be reduced by corresponding entries in array_y, squared, and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values that will be subtracted from corresponding entries in array_x, the result squared, and all such results added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>(e-t)**2))},isExported:!0},xd=!1,Id=[od("array (any, range<any>)",Uo("The array which will be transformed.")),od("ignore (number, default=0)",Uo("The control to ignore blanks and errors. 0 (default) is to keep all values, 1 is to ignore blanks, 2 is to ignore errors, and 3 is to ignore blanks and errors.")),od("scan_by_column (number, default=false)",Uo("Whether the array should be scanned by column. True scans the array by column and false (default) scans the array by row."))];function Ed(e){const t=Math.trunc(e);if(0===t)return()=>!0;if(1===t)return e=>null!==e.value;if(2===t)return e=>!Pi(e.value);if(3===t)return e=>null!==e.value&&!Pi(e.value);throw new Ii(Uo("Argument ignore must be between 0 and 3"))}const Rd={description:Uo("Transforms a range of cells into a single column."),args:Id,compute:function(e,t={value:0},o={value:xd}){const s=vn(e),i=ki(t.value,this.locale),n=(Zi(o.value)?s:rn(s)).flat().filter(Ed(i));return 0===n.length?new Ai(Uo("No results for the given arguments of TOCOL.")):[n]},isExported:!0},Td={description:Uo("Transforms a range of cells into a single row."),args:Id,compute:function(e,t={value:0},o={value:xd}){const s=vn(e),i=ki(t.value,this.locale),n=(Zi(o.value)?s:rn(s)).flat().filter(Ed(i)).map((e=>[e]));return 0===n.length||0===n[0].length?new Ai(Uo("No results for the given arguments of TOROW.")):n},isExported:!0},Ad={description:Uo("Transposes the rows and columns of a range."),args:[od("range (any, range<any>)",Uo("The range to be transposed."))],compute:function(e){const t=vn(e);return sn(t[0].length,t.length,((e,o)=>t[o][e]))},isExported:!0},_d={description:Uo("Appends ranges vertically and in sequence to return a larger array."),args:[od("range1 (any, range<any>)",Uo("The first range to be appended.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to add to range1."))],compute:function(...e){const t=Math.max(...e.map((e=>vn(e).length))),o=e.reduce(((e,t)=>e+vn(t)[0].length),0),s=Array(t).fill([]).map((()=>Array(o).fill({value:0})));let i=0;for(const t of e){const e=vn(t);for(let t=0;t<e.length;t++)for(let o=0;o<e[t].length;o++)s[t][i+o]=e[t][o];i+=e[0].length}return s},isExported:!0},Dd={description:Uo("Wraps the provided row or column of cells by columns after a specified number of elements to form a new array."),args:[od("range (any, range<any>)",Uo("The range to wrap.")),od("wrap_count (number)",Uo("The maximum number of cells for each column, rounded down to the nearest whole number.")),od("pad_with (any, default=0)",Uo("The value with which to fill the extra cells in the range."))],compute:function(e,t,o={value:0}){const s=vn(e),i=Ui(t?.value,this.locale);id(Uo("Argument range must be a single row or column."),s);const n=s.flat();return sn(Math.ceil(n.length/i),i,((e,t)=>{const s=e*i+t;return s<n.length?n[s]:o}))},isExported:!0},Od={description:Uo("Wraps the provided row or column of cells by rows after a specified number of elements to form a new array."),args:[od("range (any, range<any>)",Uo("The range to wrap.")),od("wrap_count (number)",Uo("The maximum number of cells for each row, rounded down to the nearest whole number.")),od("pad_with (any, default=0)",Uo("The value with which to fill the extra cells in the range."))],compute:function(e,t,o={value:0}){const s=vn(e),i=Ui(t?.value,this.locale);id(Uo("Argument range must be a single row or column."),s);const n=s.flat(),r=Math.ceil(n.length/i);return sn(i,r,((e,t)=>{const s=t*i+e;return s<n.length?n[s]:o}))},isExported:!0};var Fd=Object.freeze({__proto__:null,ARRAY_CONSTRAIN:ld,CHOOSECOLS:cd,CHOOSEROWS:hd,EXPAND:dd,FLATTEN:ud,FREQUENCY:gd,HSTACK:pd,MDETERM:md,MINVERSE:fd,MMULT:vd,SUMPRODUCT:bd,SUMX2MY2:yd,SUMX2PY2:Cd,SUMXMY2:wd,TOCOL:Rd,TOROW:Td,TRANSPOSE:Ad,VSTACK:_d,WRAPCOLS:Dd,WRAPROWS:Od});const Md={description:Uo("Apply a large number format"),args:[od("value (number)",Uo("The number.")),od("unit (string, optional)",Uo("The formatting unit. Use 'k', 'm', or 'b' to force the unit"))],compute:function(e,t){return{value:ki(e,this.locale),format:vr(e,t,this.locale)}}};var Pd=Object.freeze({__proto__:null,FORMAT_LARGE_NUMBER:Md});const Nd=/^-?[a-z0-9]+$/i,kd={description:Uo("Absolute value of a number."),args:[od("value (number)",Uo("The number of which to return the absolute value."))],compute:function(e){return Math.abs(ki(e,this.locale))},isExported:!0},Vd={description:Uo("Inverse cosine of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<=1),Uo("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.acos(t)},isExported:!0},Ld={description:Uo("Inverse hyperbolic cosine of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic cosine. Must be greater than or equal to 1."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>=1),Uo("The value (%s) must be greater than or equal to 1.",t.toString())),Math.acosh(t)},isExported:!0},Hd={description:Uo("Inverse cotangent of a value."),args:[od("value (number)",Uo("The value for which to calculate the inverse cotangent."))],compute:function(e){const t=ki(e,this.locale);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)},isExported:!0},Ud={description:Uo("Inverse hyperbolic cotangent of a value."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic cotangent. Must not be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)>1),Uo("The value (%s) cannot be between -1 and 1 inclusive.",t.toString())),Math.log((t+1)/(t-1))/2},isExported:!0},Bd={description:Uo("Inverse sine of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<=1),Uo("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.asin(t)},isExported:!0},zd={description:Uo("Inverse hyperbolic sine of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic sine."))],compute:function(e){return Math.asinh(ki(e,this.locale))},isExported:!0},$d={description:Uo("Inverse tangent of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse tangent."))],compute:function(e){return Math.atan(ki(e,this.locale))},isExported:!0},Gd={description:Uo("Angle from the X axis to a point (x,y), in radians."),args:[od("x (number)",Uo("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")),od("y (number)",Uo("The y coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis."))],compute:function(e,t){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>0!==o||0!==s),Uo("Function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero),Math.atan2(s,o)},isExported:!0},Wd={description:Uo("Inverse hyperbolic tangent of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic tangent. Must be between -1 and 1, exclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<1),Uo("The value (%s) must be between -1 and 1 exclusive.",t.toString())),Math.atanh(t)},isExported:!0},qd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("value (number)",Uo("The value to round up to the nearest integer multiple of factor.")),od("factor (number, default=1)",Uo("The number to whose multiples value will be rounded."))],compute:function(e,t={value:1}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>s>=0||o<=0),Uo("The factor (%s) must be positive when the value (%s) is positive.",s.toString(),o.toString())),{value:s?Math.ceil(o/s)*s:0,format:e?.format}},isExported:!0};function Zd(e,t,o=0){return 0===t?0:(t=Math.abs(t),e>=0?Math.ceil(e/t)*t:0===o?-Math.floor(Math.abs(e)/t)*t:-Math.ceil(Math.abs(e)/t)*t)}const jd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded. The sign of significance will be ignored.")),od("mode (number, default=0)",Uo("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded towards zero. Otherwise, it is rounded away from zero."))],compute:function(e,t={value:1},o={value:0}){const s=ki(t,this.locale);return{value:Zd(ki(e,this.locale),s,ki(o,this.locale)),format:e?.format}},isExported:!0},Yd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){const o=ki(t,this.locale);return{value:Zd(ki(e,this.locale),o),format:e?.format}},isExported:!0},Xd={description:Uo("Cosine of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cosine of, in radians."))],compute:function(e){return Math.cos(ki(e,this.locale))},isExported:!0},Kd={description:Uo("Hyperbolic cosine of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cosine of."))],compute:function(e){return Math.cosh(ki(e,this.locale))},isExported:!0},Jd={description:Uo("Cotangent of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cotangent of, in radians."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.tan(t)},isExported:!0},Qd={description:Uo("Hyperbolic cotangent of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cotangent of."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.tanh(t)},isExported:!0},eu={description:Uo("Number of empty values."),args:[od("value1 (any, range)",Uo("The first value or range in which to count the number of blanks.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges in which to count the number of blanks."))],compute:function(...e){return en(e,((e,t)=>void 0===t||null===t.value||""===t.value?e+1:e),0)},isExported:!0},tu={description:Uo("A conditional count across a range."),args:[od("range (range)",Uo("The range that is tested against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to range."))],compute:function(...e){let t=0;return un(e,((e,o)=>{t+=1}),this.locale),t},isExported:!0},ou={description:Uo("Count values depending on multiple criteria."),args:[od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("Additional criteria to check."))],compute:function(...e){let t=0;return un(e,((e,o)=>{t+=1}),this.locale),t},isExported:!0},su={description:Uo("Counts number of unique values in a range."),args:[od("value1 (any, range)",Uo("The first value or range to consider for uniqueness.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider for uniqueness."))],compute:function(...e){return pl(e)}},iu={description:Uo("Counts number of unique values in a range, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the number of unique values will be counted.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=new Set;return un(t,((t,s)=>{const i=e[t]?.[s];Sn(i)&&o.add(i.value)}),this.locale),o.size}},nu={description:Uo("Cosecant of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cosecant of, in radians."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.sin(t)},isExported:!0},ru={description:Uo("Hyperbolic cosecant of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cosecant of."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.sinh(t)},isExported:!0},au={description:Uo("Converts from another base to decimal."),args:[od("value (string)",Uo("The number to convert.")),od("base (number)",Uo("The base to convert the value from."))],compute:function(e,t){let o=ki(t,this.locale);o=Math.floor(o),Fi((()=>2<=o&&o<=36),Uo("The base (%s) must be between 2 and 36 inclusive.",o.toString()));const s=Gi(e);if(""===s)return 0;Fi((()=>Nd.test(s)),Uo("The value (%s) must be a valid base %s representation.",s,o.toString()));const i=parseInt(s,o);return Fi((()=>!isNaN(i)),Uo("The value (%s) must be a valid base %s representation.",s,o.toString())),i},isExported:!0},lu={description:Uo("Converts an angle value in radians to degrees."),args:[od("angle (number)",Uo("The angle to convert from radians to degrees."))],compute:function(e){return 180*ki(e,this.locale)/Math.PI},isExported:!0},cu={description:Uo("Euler's number, e (~2.718) raised to a power."),args:[od("value (number)",Uo("The exponent to raise e."))],compute:function(e){return Math.exp(ki(e,this.locale))},isExported:!0},hu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("value (number)",Uo("The value to round down to the nearest integer multiple of factor.")),od("factor (number, default=1)",Uo("The number to whose multiples value will be rounded."))],compute:function(e,t={value:1}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>s>=0||o<=0),Uo("The factor (%s) must be positive when the value (%s) is positive.",s.toString(),o.toString())),{value:s?Math.floor(o/s)*s:0,format:e?.format}},isExported:!0};function du(e,t,o=0){return 0===t?0:(t=Math.abs(t),e>=0?Math.floor(e/t)*t:0===o?-Math.ceil(Math.abs(e)/t)*t:-Math.floor(Math.abs(e)/t)*t)}const uu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round down to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded. The sign of significance will be ignored.")),od("mode (number, default=0)",Uo("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded away from zero. Otherwise, it is rounded towards zero."))],compute:function(e,t={value:1},o={value:0}){const s=ki(t,this.locale);return{value:du(ki(e,this.locale),s,ki(o,this.locale)),format:e?.format}},isExported:!0},gu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round down to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){const o=ki(t,this.locale);return{value:du(ki(e,this.locale),o),format:e?.format}},isExported:!0},pu={description:Uo("Whether the provided value is even."),args:[od("value (number)",Uo("The value to be verified as even."))],compute:function(e){const t=Hi(e,this.locale);return!(1&Math.floor(Math.abs(t)))},isExported:!0},mu={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){return{value:Zd(ki(e,this.locale),ki(t,this.locale)),format:e?.format}},isExported:!0},fu={description:Uo("Whether the provided value is even."),args:[od("value (number)",Uo("The value to be verified as even."))],compute:function(e){const t=Hi(e,this.locale);return!!(1&Math.floor(Math.abs(t)))},isExported:!0},vu={description:Uo("The logarithm of a number, base e (euler's number)."),args:[od("value (number)",Uo("The value for which to calculate the logarithm, base e."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>0),Uo("The value (%s) must be strictly positive.",t.toString())),Math.log(t)},isExported:!0},bu={description:Uo("The logarithm of a number, for a given base."),args:[od("value (number)",Uo("The value for which to calculate the logarithm.")),od("base (number, default=10)",Uo("The base of the logarithm."))],compute:function(e,t={value:10}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>o>0),Uo("The value (%s) must be strictly positive.",o.toString())),Fi((()=>s>0),Uo("The base (%s) must be strictly positive.",s.toString())),Fi((()=>1!==s),Uo("The base must be different from 1.")),Math.log10(o)/Math.log10(s)},isExported:!0};function Su(e,t){Fi((()=>0!==t),Uo("The divisor must be different from 0."),wi.DivisionByZero);const o=e%t;return o>0&&t<0||o<0&&t>0?o+t:o}const yu={description:Uo("Modulo (remainder) operator."),args:[od("dividend (number)",Uo("The number to be divided to find the remainder.")),od("divisor (number)",Uo("The number to divide by."))],compute:function(e,t){const o=ki(t,this.locale);return{value:Su(ki(e,this.locale),o),format:e?.format}},isExported:!0},Cu={description:Uo("Returns a n x n unit matrix, where n is the input dimension."),args:[od("dimension (number)",Uo("An integer specifying the dimension size of the unit matrix. It must be positive."))],compute:function(e){const t=Ui(e,this.locale);return rd(Uo("The argument dimension must be positive"),t),ml(t)},isExported:!0},wu={description:Uo("Rounds a number up to the nearest odd integer."),args:[od("value (number)",Uo("The value to round to the next greatest odd number."))],compute:function(e){const t=ki(e,this.locale);let o=Math.ceil(Math.abs(t));return o=1&o?o:o+1,{value:t<0?-o:o,format:e?.format}},isExported:!0},xu={description:Uo("The number pi."),args:[],compute:function(){return Math.PI},isExported:!0},Iu={description:Uo("A number raised to a power."),args:[od("base (number)",Uo("The number to raise to the exponent power.")),od("exponent (number)",Uo("The exponent to raise base to."))],compute:function(e,t){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>o>=0||Number.isInteger(s)),Uo("The exponent (%s) must be an integer when the base is negative.",s.toString())),{value:Math.pow(o,s),format:e?.format}},isExported:!0},Eu={description:Uo("Result of multiplying a series of numbers together."),args:[od("factor1 (number, range<number>)",Uo("The first number or range to calculate for the product.")),od("factor2 (number, range<number>, repeating)",Uo("More numbers or ranges to calculate for the product."))],compute:function(...e){let t=0,o=1;for(let s of e)if(bi(s))for(let e of s)for(let s of e){const e=s.value;if("number"==typeof e&&(o*=e,t+=1),Pi(e))return s}else void 0!==s&&null!==s.value&&(o*=Hi(s,this.locale),t+=1);return{value:0===t?0:o,format:Mi(e[0])}},isExported:!0},Ru={description:Uo("A random number between 0 inclusive and 1 exclusive."),args:[],compute:function(){return Math.random()},isExported:!0},Tu={description:Uo("Returns a grid of random numbers between 0 inclusive and 1 exclusive."),args:[od("rows (number, default=1)",Uo("The number of rows to be returned.")),od("columns (number, default=1)",Uo("The number of columns to be returned.")),od("min (number, default=0)",Uo("The minimum number you would like returned.")),od("max (number, default=1)",Uo("The maximum number you would like returned.")),od("whole_number (number, default=FALSE)",Uo("Return a whole number or a decimal value."))],compute:function(e={value:1},t={value:1},o={value:0},s={value:1},i={value:!1}){const n=Ui(t,this.locale),r=Ui(e,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i);rd(Uo("The number of columns (%s) must be positive.",n.toString()),n),rd(Uo("The number of rows (%s) must be positive.",r.toString()),r),Fi((()=>a<=l),Uo("The maximum (%s) must be greater than or equal to the minimum (%s).",l.toString(),a.toString())),c&&Fi((()=>Number.isInteger(a)&&Number.isInteger(l)),Uo("The maximum (%s) and minimum (%s) must be integers when whole_number is TRUE.",l.toString(),a.toString()));const h=Array(n);for(let e=0;e<n;e++){h[e]=Array(r);for(let t=0;t<r;t++)h[e][t]=c?Math.floor(Math.random()*(l-a+1)+a):a+Math.random()*(l-a)}return h},isExported:!0},Au={description:Uo("Random integer between two values, inclusive."),args:[od("low (number)",Uo("The low end of the random range.")),od("high (number)",Uo("The high end of the random range."))],compute:function(e,t){let o=ki(e,this.locale);Number.isInteger(o)||(o=Math.ceil(o));let s=ki(t,this.locale);return Number.isInteger(s)||(s=Math.floor(s)),Fi((()=>o<=s),Uo("The high (%s) must be greater than or equal to the low (%s).",s.toString(),o.toString())),{value:o+Math.ceil((s-o+1)*Math.random())-1,format:e?.format}},isExported:!0},_u={description:Uo("Rounds a number according to standard rules."),args:[od("value (number)",Uo("The value to round to places number of places.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.round(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.round(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Du={description:Uo("Rounds down a number."),args:[od("value (number)",Uo("The value to round to places number of places, always rounding down.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.floor(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.floor(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Ou={description:Uo("Rounds up a number."),args:[od("value (number)",Uo("The value to round to places number of places, always rounding up.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.ceil(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.ceil(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Fu={description:Uo("Secant of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the secant of, in radians."))],compute:function(e){return 1/Math.cos(ki(e,this.locale))},isExported:!0},Mu={description:Uo("Hyperbolic secant of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic secant of."))],compute:function(e){return 1/Math.cosh(ki(e,this.locale))},isExported:!0},Pu={description:Uo("Returns a sequence of numbers."),args:[od("rows (number)",Uo("The number of rows to return")),od("columns (number, optional, default=1)",Uo("The number of columns to return")),od("start (number, optional, default=1)",Uo("The first number in the sequence")),od("step (number, optional, default=1)",Uo("The amount to increment each value in the sequence"))],compute:function(e,t={value:1},o={value:1},s={value:1}){const i=ki(o,this.locale),n=ki(s,this.locale),r=Ui(e,this.locale),a=Ui(t,this.locale);return rd(Uo("The number of columns (%s) must be positive.",a),a),rd(Uo("The number of rows (%s) must be positive.",r),r),sn(a,r,((e,t)=>({value:i+t*a*n+e*n})))},isExported:!0},Nu={description:Uo("Sine of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the sine of, in radians."))],compute:function(e){return Math.sin(ki(e,this.locale))},isExported:!0},ku={description:Uo("Hyperbolic sine of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic sine of."))],compute:function(e){return Math.sinh(ki(e,this.locale))},isExported:!0},Vu={description:Uo("Positive square root of a positive number."),args:[od("value (number)",Uo("The number for which to calculate the positive square root."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>=0),Uo("The value (%s) must be positive or null.",t.toString())),{value:Math.sqrt(t),format:e?.format}},isExported:!0},Lu={description:Uo("Sum of a series of numbers and/or cells."),args:[od("value1 (number, range<number>)",Uo("The first number or range to add together.")),od("value2 (number, range<number>, repeating)",Uo("Additional numbers or ranges to add to value1."))],compute:function(...e){const t=e[0];return{value:gl(e,this.locale),format:Mi(t)}},isExported:!0},Hu={description:Uo("A conditional sum across a range."),args:[od("criteria_range (range)",Uo("The range which is tested against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to range.")),od("sum_range (range, default=criteria_range)",Uo("The range to be summed, if different from range."))],compute:function(e,t,o){void 0===o&&(o=e);let s=0;return un([e,t],((e,t)=>{const i=o[e]?.[t]?.value;"number"==typeof i&&(s+=i)}),this.locale),s},isExported:!0},Uu={description:Uo("Sums a range depending on multiple criteria."),args:[od("sum_range (range)",Uo("The range to sum.")),od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges to check.")),od("criterion2 (string, repeating)",Uo("Additional criteria to check."))],compute:function(e,...t){let o=0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o+=i)}),this.locale),o},isExported:!0},Bu={description:Uo("Tangent of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the tangent of, in radians."))],compute:function(e){return Math.tan(ki(e,this.locale))},isExported:!0},zu={description:Uo("Hyperbolic tangent of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic tangent of."))],compute:function(e){return Math.tanh(ki(e,this.locale))},isExported:!0};function $u(e,t){return 0===t?Math.trunc(e):(Number.isInteger(t)||(t=Math.trunc(t)),Math.trunc(e*Math.pow(10,t))/Math.pow(10,t))}const Gu={description:Uo("Truncates a number."),args:[od("value (number)",Uo("The value to be truncated.")),od("places (number, default=0)",Uo("The number of significant digits to the right of the decimal point to retain."))],compute:function(e,t={value:0}){return{value:$u(ki(e,this.locale),ki(t,this.locale)),format:e?.format}},isExported:!0},Wu={description:Uo("Rounds a number down to the nearest integer that is less than or equal to it."),args:[od("value (number)",Uo("The number to round down to the nearest integer."))],compute:function(e){return Math.floor(ki(e,this.locale))},isExported:!0};var qu=Object.freeze({__proto__:null,ABS:kd,ACOS:Vd,ACOSH:Ld,ACOT:Hd,ACOTH:Ud,ASIN:Bd,ASINH:zd,ATAN:$d,ATAN2:Gd,ATANH:Wd,CEILING:qd,CEILING_MATH:jd,CEILING_PRECISE:Yd,COS:Xd,COSH:Kd,COT:Jd,COTH:Qd,COUNTBLANK:eu,COUNTIF:tu,COUNTIFS:ou,COUNTUNIQUE:su,COUNTUNIQUEIFS:iu,CSC:nu,CSCH:ru,DECIMAL:au,DEGREES:lu,EXP:cu,FLOOR:hu,FLOOR_MATH:uu,FLOOR_PRECISE:gu,INT:Wu,ISEVEN:pu,ISODD:fu,ISO_CEILING:mu,LN:vu,LOG:bu,MOD:yu,MUNIT:Cu,ODD:wu,PI:xu,POWER:Iu,PRODUCT:Eu,RAND:Ru,RANDARRAY:Tu,RANDBETWEEN:Au,ROUND:_u,ROUNDDOWN:Du,ROUNDUP:Ou,SEC:Fu,SECH:Mu,SEQUENCE:Pu,SIN:Nu,SINH:ku,SQRT:Vu,SUM:Lu,SUMIF:Hu,SUMIFS:Uu,TAN:Bu,TANH:zu,TRUNC:Gu});function Zu(e,t){const o=[],s=[];let i=0,n=0;Ki([e],(e=>{o.push(e),i+=1})),Ki([t],(e=>{s.push(e),n+=1})),Fi((()=>i===n),Uo("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",i,n));const r=[],a=[];for(let e=0;e<i;e++){const t=o[e]?.value,i=s[e]?.value;"number"==typeof t&&"number"==typeof i&&(a.push(t),r.push(i))}return{flatDataX:r,flatDataY:a}}function ju(e,t,o){const{flatDataX:s,flatDataY:i}=Zu(e,t),n=i.length;Fi((()=>0!==n&&(!o||1!==n)),Uo("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero);let r=0,a=0;for(let e=0;e<n;e++)r+=i[e],a+=s[e];const l=r/n,c=a/n;let h=0;for(let e=0;e<n;e++)h+=(i[e]-l)*(s[e]-c);return h/(n-(o?1:0))}function Yu(e,t,o,s){let i=0;const n=o?on:tn,r=n(e,((e,t)=>(i+=1,e+t)),0,s);Fi((()=>0!==i&&(!t||1!==i)),Uo("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero);const a=r/i;return n(e,((e,t)=>e+Math.pow(t-a,2)),0,s)/(i-(t?1:0))}function Xu(e,t,o,s){const i=ki(t,s);Fi((()=>o?0<=i&&i<=1:0<i&&i<1),Uo("Function [[FUNCTION_NAME]] parameter 2 value is out of range."));let n,r=[],a=0;return Ki(e,(e=>{const t=e?.value;"number"==typeof t&&(n=gn(r,e,"nextSmaller","asc",r.length,((e,t)=>e[t])),r.splice(n+1,0,t),a++)})),Fi((()=>0!==a),Uo("[[FUNCTION_NAME]] has no valid input data.")),o||Fi((()=>1/(a+1)<=i&&i<=a/(a+1)),Uo("Function [[FUNCTION_NAME]] parameter 2 value is out of range.")),ti(r,i,o)}const Ku={description:Uo("Average magnitude of deviations from mean."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){let t=0;const o=tn(e,((e,o)=>(t+=1,e+o)),0,this.locale);$i(t);const s=o/t;return tn(e,((e,t)=>e+Math.abs(s-t)),0,this.locale)/t},isExported:!0},Ju={description:Uo("Numerical average value in a dataset, ignoring text."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the average value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the average value."))],compute:function(...e){return{value:xl(e,this.locale),format:Mi(e[0])}},isExported:!0},Qu=Uo("[[FUNCTION_NAME]] has mismatched range sizes."),eg=Uo("[[FUNCTION_NAME]] expects the weight to be positive or equal to 0."),tg={description:Uo("Weighted average."),args:[od("values (number, range<number>)",Uo("Values to average.")),od("weights (number, range<number>)",Uo("Weights for each corresponding value.")),od("additional_values (number, range<number>, repeating)",Uo("Additional values to average.")),od("additional_weights (number, range<number>, repeating)",Uo("Additional weights."))],compute:function(...e){let t=0,o=0;for(let s=0;s<e.length-1;s+=2){const i=e[s],n=e[s+1];if(nd(Qu,i,n),bi(i))for(let e=0;e<i.length;e++)for(let s=0;s<i[0].length;s++){const r=i[e][s].value,a=bi(n)?n?.[e][s].value:ki(n,this.locale),l="number"==typeof r,c="number"==typeof a;l&&c?(Fi((()=>a>=0),eg),t+=r*a,o+=a):Fi((()=>l===c),Uo("[[FUNCTION_NAME]] expects number values."))}else{const e=ki(i,this.locale),s=bi(n)?n?.[0][0].value:ki(n,this.locale);"number"==typeof s&&(Fi((()=>s>=0),eg),t+=e*s,o+=s)}}return $i(o),{value:t/o,format:Mi(e[0])}}},og={description:Uo("Numerical average value in a dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the average value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the average value."))],compute:function(...e){let t=0;const o=on(e,((e,o)=>(t+=1,e+o)),0,this.locale);return $i(t),{value:o/t,format:Mi(e[0])}},isExported:!0},sg={description:Uo("Average of values depending on criteria."),args:[od("criteria_range (number, range<number>)",Uo("The range to check against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to criteria_range.")),od("average_range (number, range<number>, default=criteria_range)",Uo("The range to average. If not included, criteria_range is used for the average instead."))],compute:function(e,t,o){const s=vn(void 0===o?e:o);let i=0,n=0;return un([e,t],((e,t)=>{const o=s[e]?.[t]?.value;"number"==typeof o&&(i+=1,n+=o)}),this.locale),$i(i),n/i},isExported:!0},ig={description:Uo("Average of values depending on multiple criteria."),args:[od("average_range (range)",Uo("The range to average.")),od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional criteria_range and criterion to check.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){const o=vn(e);let s=0,i=0;return un(t,((e,t)=>{const n=o[e]?.[t]?.value;"number"==typeof n&&(s+=1,i+=n)}),this.locale),$i(s),i/s},isExported:!0},ng={description:Uo("The number of numeric values in dataset."),args:[od("value1 (number, any, range<number>)",Uo("The first value or range to consider when counting.")),od("value2 (number, any, range<number>, repeating)",Uo("Additional values or ranges to consider when counting."))],compute:function(...e){return Il(e,this.locale)},isExported:!0},rg={description:Uo("The number of values in a dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when counting.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when counting."))],compute:function(...e){return El(e)},isExported:!0},ag={description:Uo("The covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!1)},isExported:!0},lg={description:Uo("The covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!1)},isExported:!0},cg={description:Uo("The sample covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!0)},isExported:!0},hg={description:Uo("Calculates the expected y-value for a specified x based on a linear regression of a dataset."),args:[od("x (number, range<number>)",Uo("The value(s) on the x-axis to forecast.")),od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t,o){const{flatDataX:s,flatDataY:i}=Zu(t,o);return Nl([i],[s],nn(vn(e),(e=>ki(e,this.locale))),!0)},isExported:!0},dg={description:Uo("Fits points to exponential growth trend."),args:[od("known_data_y (range<number>)",Uo("The array or range containing dependent (y) values that are already known, used to curve fit an ideal exponential growth curve.")),od("known_data_x (range<number>, default={1;2;3;...})",Uo("The values of the independent variable(s) corresponding with known_data_y.")),od("new_data_x (any, range, default=known_data_x)",Uo("The data points to return the y values for on the ideal curve fit.")),od("b (boolean, default=TRUE)",Uo("Given a general exponential form of y = b*m^x for a curve fit, calculates b if TRUE or forces b to be 1 and only calculates the m values if FALSE."))],compute:function(e,t=[[]],o=[[]],s={value:!0}){return Ml(Nl(Pl(Li(e,"the first argument (known_data_y)")),Li(t,"the second argument (known_data_x)"),Li(o,"the third argument (new_data_y)"),Zi(s)))}},ug={description:Uo("Compute the intercept of the linear regression."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t),[[],[i]]=_l([o],[s]);return i},isExported:!0},gg={description:Uo("Nth largest element from a data set."),args:[od("data (any, range)",Uo("Array or range containing the dataset to consider.")),od("n (number)",Uo("The rank from largest to smallest of the element to return."))],compute:function(e,t){const o=Math.trunc(ki(t?.value,this.locale));let s,i=[],n=0;Ki([e],(e=>{"number"==typeof e?.value&&(s=gn(i,e,"nextSmaller","asc",i.length,((e,t)=>e[t].value)),i.splice(s+1,0,e),n++,n>o&&(i.shift(),n--))}));const r=i.shift();return Fi((()=>void 0!==r),Uo("[[FUNCTION_NAME]] has no valid input data.")),Fi((()=>n>=o),Uo("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",o)),r},isExported:!0},pg={description:Uo("Given partial data about a linear trend, calculates various parameters about the ideal linear trend using the least-squares method."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>, default={1;2;3;...})",Uo("The range representing the array or matrix of independent data.")),od("calculate_b (boolean, default=TRUE)",Uo("A flag specifying wheter to compute the slope or not")),od("verbose (boolean, default=FALSE)",Uo("A flag specifying whether to return additional regression statistics or only the linear coefficients and the y-intercept"))],compute:function(e,t=[[]],o={value:!0},s={value:!1}){return _l(Li(t,"the first argument (data_y)"),Li(e,"the second argument (data_x)"),Zi(o),Zi(s))},isExported:!0},mg={description:Uo("Given partial data about an exponential growth curve, calculates various parameters about the best fit ideal exponential growth curve."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>, optional, default={1;2;3;...})",Uo("The range representing the array or matrix of independent data.")),od("calculate_b (boolean, default=TRUE)",Uo("A flag specifying wheter to compute the slope or not")),od("verbose (boolean, default=FALSE)",Uo("A flag specifying whether to return additional regression statistics or only the linear coefficients and the y-intercept"))],compute:function(e,t=[[]],o={value:!0},s={value:!1}){const i=_l(Li(t,"the second argument (data_x)"),Pl(Li(e,"the first argument (data_y)")),Zi(o),Zi(s));for(let e=0;e<i.length;e++)i[e][0]=Math.exp(i[e][0]);return i},isExported:!0},fg={description:Uo("Compute the Matthews correlation coefficient of a dataset."),args:[od("data_x (range)",Uo("The range representing the array or matrix of observed data.")),od("data_y (range)",Uo("The range representing the array or matrix of predicted data."))],compute:function(e,t){const o=e.flat(),s=t.flat();if(wl(o,s),0===o.length)return new Ii(Uo("[[FUNCTION_NAME]] expects non-empty ranges for both parameters."));const i=o.length;let n=0,r=0,a=0,l=0;for(let e=0;e<i;++e){const t=Zi(o[e]);t===Zi(s[e])?t?r++:n++:t?l++:a++}return(r*n-a*l)/Math.sqrt((r+a)*(r+l)*(n+a)*(n+l))},isExported:!1},vg={description:Uo("Maximum value in a numeric dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the maximum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the maximum value."))],compute:function(...e){return Rl(e,this.locale)},isExported:!0},bg={description:Uo("Maximum numeric value in a dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when calculating the maximum value.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when calculating the maximum value."))],compute:function(...e){const t=on(e,((e,t)=>Math.max(t,e)),-1/0,this.locale);return{value:t===-1/0?0:t,format:Mi(e[0])}},isExported:!0},Sg={description:Uo("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the maximum will be determined.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=-1/0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o=o<i?i:o)}),this.locale),o===-1/0?0:o},isExported:!0},yg={description:Uo("Median value in a numeric dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when calculating the median value.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when calculating the median value."))],compute:function(...e){let t=[];return Ji(e,(e=>{t.push(e)}),this.locale),{value:Xu(t,{value:.5},!0,this.locale),format:Mi(t[0])}},isExported:!0},Cg={description:Uo("Minimum value in a numeric dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the minimum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the minimum value."))],compute:function(...e){return Tl(e,this.locale)},isExported:!0},wg={description:Uo("Minimum numeric value in a dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the minimum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the minimum value."))],compute:function(...e){const t=on(e,((e,t)=>Math.min(t,e)),1/0,this.locale);return{value:t===1/0?0:t,format:Mi(e[0])}},isExported:!0},xg={description:Uo("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the minimum will be determined.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=1/0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o=o>i?i:o)}),this.locale),o===1/0?0:o},isExported:!0};function Ig(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t);if(0===o.length)throw new Ii(Uo("[[FUNCTION_NAME]] expects non-empty ranges for both parameters."));if(o.length<2)throw new Ii(Uo("[[FUNCTION_NAME]] needs at least two values for both parameters."));const i=o.length;let n=0,r=0,a=0,l=0,c=0;for(let e=0;e<i;e++){const t=o[e],i=s[e];n+=t,r+=i,a+=t*i,l+=t*t,c+=i*i}return(i*a-n*r)/Math.sqrt((i*l-n*n)*(i*c-r*r))}const Eg={description:Uo("Compute the Pearson product-moment correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return Ig(e,t)},isExported:!0},Rg=Eg,Tg={description:Uo("Value at a given percentile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile whose value within data will be calculated and returned."))],compute:function(e,t){return _g.compute.bind(this)(e,t)},isExported:!0},Ag={description:Uo("Value at a given percentile of a dataset exclusive of 0 and 1."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile, exclusive of 0 and 1, whose value within 'data' will be calculated and returned."))],compute:function(e,t){return{value:Xu([e],t,!1,this.locale),format:Mi(e)}},isExported:!0},_g={description:Uo("Value at a given percentile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile whose value within data will be calculated and returned."))],compute:function(e,t){return{value:Xu([e],t,!0,this.locale),format:Mi(e)}},isExported:!0},Dg={description:Uo("Compute the coefficients of polynomial regression of the dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data.")),od("order (number)",Uo("The order of the polynomial to fit the data, between 1 and 6.")),od("intercept (boolean, default=TRUE)",Uo("A flag specifying whether to compute the intercept or not."))],compute:function(e,t,o,s={value:!0}){const{flatDataX:i,flatDataY:n}=Zu(e,t);return Dl(n,i,ki(o,this.locale),Zi(s))},isExported:!1},Og={description:Uo("Predict value by computing a polynomial regression of the dataset."),args:[od("x (number, range<number>)",Uo("The value(s) on the x-axis to forecast.")),od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data.")),od("order (number)",Uo("The order of the polynomial to fit the data, between 1 and 6.")),od("intercept (boolean, default=TRUE)",Uo("A flag specifying whether to compute the intercept or not."))],compute:function(e,t,o,s,i={value:!0}){const n=ki(s,this.locale),{flatDataX:r,flatDataY:a}=Zu(t,o),l=Dl(a,r,n,Zi(i)).flat();return nn(vn(e),(e=>Fl(l,ki(e,this.locale),n)))},isExported:!1},Fg={description:Uo("Value nearest to a specific quartile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value to return."))],compute:function(e,t){return Pg.compute.bind(this)(e,t)},isExported:!0},Mg={description:Uo("Value nearest to a specific quartile of a dataset exclusive of 0 and 4."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value, exclusive of 0 and 4, to return."))],compute:function(e,t){return{value:Xu([e],{value:.25*Math.trunc(ki(t,this.locale))},!1,this.locale),format:Mi(e)}},isExported:!0},Pg={description:Uo("Value nearest to a specific quartile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value to return."))],compute:function(e,t){return{value:Xu([e],{value:.25*Math.trunc(ki(t,this.locale))},!0,this.locale),format:Mi(e)}},isExported:!0},Ng={description:Uo("Returns the rank of a specified value in a dataset."),args:[od("value (number)",Uo("The value whose rank will be determined.")),od("data (range)",Uo("The range containing the dataset to consider.")),od("is_ascending (boolean, default=FALSE)",Uo("Whether to consider the values in data in descending or ascending order."))],compute:function(e,t,o={value:!1}){const s=Zi(o),i=ki(e,this.locale);let n=1,r=!1;for(const e of t)for(const t of e){if("number"!=typeof t.value)continue;const e=ki(t,this.locale);e===i?r=!0:e>i!==s&&n++}return r?n:new Ai(Uo("Value not found in the given data."))},isExported:!0},kg={description:Uo("Compute the square of r, the Pearson product-moment correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return Math.pow(Ig(t,e),2)},isExported:!0},Vg={description:Uo("Compute the slope of the linear regression."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t),[[i]]=_l([o],[s]);return i},isExported:!0},Lg={description:Uo("Nth smallest element in a data set."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("n (number)",Uo("The rank from smallest to largest of the element to return."))],compute:function(e,t){const o=Math.trunc(ki(t?.value,this.locale));let s,i=[],n=0;Ki([e],(e=>{"number"==typeof e?.value&&(s=gn(i,e,"nextSmaller","asc",i.length,((e,t)=>e[t].value)),i.splice(s+1,0,e),n++,n>o&&(i.pop(),n--))}));const r=i.pop();return Fi((()=>void 0!==r),Uo("[[FUNCTION_NAME]] has no valid input data.")),Fi((()=>n>=o),Uo("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",o)),r},isExported:!0},Hg={description:Uo("Compute the Spearman rank correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(t,e),i=o.length,n=o.map(((e,t)=>[e,s[t]]));n.sort(((e,t)=>e[0]-t[0]));for(let e=0;e<i;++e)n[e][0]=e;n.sort(((e,t)=>e[1]-t[1]));let r=0;for(let e=0;e<i;++e)r+=(n[e][0]-e)**2;return 1-6*r/(i**3-i)},isExported:!1},Ug={description:Uo("Standard deviation."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(jg.compute.bind(this)(...e))},isExported:!0},Bg={description:Uo("Standard deviation of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Yg.compute.bind(this)(...e))},isExported:!0},zg={description:Uo("Standard deviation."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(Xg.compute.bind(this)(...e))},isExported:!0},$g={description:Uo("Standard deviation of sample (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(Kg.compute.bind(this)(...e))},isExported:!0},Gg={description:Uo("Standard deviation of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Jg.compute.bind(this)(...e))},isExported:!0},Wg={description:Uo("Standard deviation of entire population (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Qg.compute.bind(this)(...e))},isExported:!0},qg={description:Uo("Calculates the standard error of the predicted y-value for each x in the regression of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t);return _l([o],[s],!0,!0)[1][2]},isExported:!0},Zg={description:Uo("Fits points to linear trend derived via least-squares."),args:[od("known_data_y (number, range<number>)",Uo("The array or range containing dependent (y) values that are already known, used to curve fit an ideal linear trend.")),od("known_data_x (number, range<number>, optional, default={1;2;3;...})",Uo("The values of the independent variable(s) corresponding with known_data_y.")),od("new_data_x (number, range<number>, optional, default=known_data_x)",Uo("The data points to return the y values for on the ideal curve fit.")),od("b (boolean, optional, default=TRUE)",Uo("Given a general linear form of y = m*x+b for a curve fit, calculates b if TRUE or forces b to be 0 and only calculates the m values if FALSE, i.e. forces the curve fit to pass through the origin."))],compute:function(e,t=[[]],o=[[]],s={value:!0}){return Nl(Li(e,"the first argument (known_data_y)"),Li(t,"the second argument (known_data_x)"),Li(o,"the third argument (new_data_y)"),Zi(s))}},jg={description:Uo("Variance."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!1,this.locale)},isExported:!0},Yg={description:Uo("Variance of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!1,this.locale)},isExported:!0},Xg={description:Uo("Variance."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!1,this.locale)},isExported:!0},Kg={description:Uo("Variance of sample (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!0,this.locale)},isExported:!0},Jg={description:Uo("Variance of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!1,this.locale)},isExported:!0},Qg={description:Uo("Variance of entire population (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!0,this.locale)},isExported:!0};var ep=Object.freeze({__proto__:null,AVEDEV:Ku,AVERAGE:Ju,AVERAGEA:og,AVERAGEIF:sg,AVERAGEIFS:ig,AVERAGE_WEIGHTED:tg,CORREL:Rg,COUNT:ng,COUNTA:rg,COVAR:ag,COVARIANCE_P:lg,COVARIANCE_S:cg,FORECAST:hg,GROWTH:dg,INTERCEPT:ug,LARGE:gg,LINEST:pg,LOGEST:mg,MATTHEWS:fg,MAX:vg,MAXA:bg,MAXIFS:Sg,MEDIAN:yg,MIN:Cg,MINA:wg,MINIFS:xg,PEARSON:Eg,PERCENTILE:Tg,PERCENTILE_EXC:Ag,PERCENTILE_INC:_g,POLYFIT_COEFFS:Dg,POLYFIT_FORECAST:Og,QUARTILE:Fg,QUARTILE_EXC:Mg,QUARTILE_INC:Pg,RANK:Ng,RSQ:kg,SLOPE:Vg,SMALL:Lg,SPEARMAN:Hg,STDEV:Ug,STDEVA:$g,STDEVP:Gg,STDEVPA:Wg,STDEV_P:Bg,STDEV_S:zg,STEYX:qg,TREND:Zg,VAR:jg,VARA:Kg,VARP:Jg,VARPA:Qg,VAR_P:Yg,VAR_S:Xg});function tp(e,t,o,s){const i=new Map,n=e.length;for(let t=n-1;t>=0;t--)i.set(Gi(e[t][0]).toUpperCase(),t);const r=t?.value;if("number"!=typeof r&&"string"!=typeof r)throw new Ii(Uo("The field must be a number or a string"));let a;if("number"==typeof r){if(a=Math.trunc(r)-1,a<0||n-1<a)throw new Ii(Uo("The field (%(fieldValue)s) must be one of %(dimRowDB)s or must be a number between 1 and %s inclusive.",{fieldValue:r.toString(),dimRowDB:n.toString()}))}else{const e=Gi(t).toUpperCase();if(a=i.get(e)??-1,-1===a)throw new Ii(Uo("The field (%s) must be one of %s.",Gi(t),[...i.keys()].toString()))}const l=o[0].length;if(l<2)throw new Ii(Uo("The criteria range contains %s row, it must be at least 2 rows.",l.toString()));let c=new Set;const h=e[0].length;for(let t=1;t<l;t++){let n=[],r=!0;for(let s=0;s<o.length;s++){const a=Gi(o[s][0]).toUpperCase(),l=i.get(a),c=o[s][t];if(null!==c.value){if(void 0===l){r=!1;break}n.push([e[l].slice(1,h)]),n.push(c)}}if(r){if(!(n.length>0)){c=new Set(Array(h-1).keys());break}un(n,((e,t)=>{c.add(t)}),s,!0)}}const d=e[a];return[...c].map((e=>d[e+1]))}const op=[od("database (range)",Uo("The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values.")),od("field (number, string)",Uo("Indicates which column in database contains the values to be extracted and operated on.")),od("criteria (range)",Uo("An array or range containing zero or more criteria to filter the database values by before operating."))],sp={description:Uo("Average of a set of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Ju.compute.bind(this)([s])},isExported:!0},ip={description:Uo("Counts values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return ng.compute.bind(this)([s])},isExported:!0},np={description:Uo("Counts values and text from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return rg.compute.bind(this)([s])},isExported:!0},rp={description:Uo("Single value from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Fi((()=>1===s.length),Uo("More than one match found in DGET evaluation.")),s[0]},isExported:!0},ap={description:Uo("Maximum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return vg.compute.bind(this)([s])},isExported:!0},lp={description:Uo("Minimum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Cg.compute.bind(this)([s])},isExported:!0},cp={description:Uo("Product of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Eu.compute.bind(this)([s])},isExported:!0},hp={description:Uo("Standard deviation of population sample from table."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Ug.compute.bind(this)([s])},isExported:!0},dp={description:Uo("Standard deviation of entire population from table."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Gg.compute.bind(this)([s])},isExported:!0},up={description:Uo("Sum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Lu.compute.bind(this)([s])},isExported:!0},gp={description:Uo("Variance of population sample from table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return jg.compute.bind(this)([s])},isExported:!0},pp={description:Uo("Variance of a population from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Jg.compute.bind(this)([s])},isExported:!0};var mp=Object.freeze({__proto__:null,DAVERAGE:sp,DCOUNT:ip,DCOUNTA:np,DGET:rp,DMAX:ap,DMIN:lp,DPRODUCT:cp,DSTDEV:hp,DSTDEVP:dp,DSUM:up,DVAR:gp,DVARP:pp});var fp;!function(e){e.WHOLE_YEARS="Y",e.WHOLE_MONTHS="M",e.WHOLE_DAYS="D",e.DAYS_WITHOUT_WHOLE_MONTHS="MD",e.MONTH_WITHOUT_WHOLE_YEARS="YM",e.DAYS_BETWEEN_NO_MORE_THAN_ONE_YEAR="YD"}(fp||(fp={}));const vp={description:Uo("Converts year/month/day into a date."),args:[od("year (number)",Uo("The year component of the date.")),od("month (number)",Uo("The month component of the date.")),od("day (number)",Uo("The day component of the date."))],compute:function(e,t,o){let s=Math.trunc(ki(e,this.locale));const i=Math.trunc(ki(t,this.locale)),n=Math.trunc(ki(o,this.locale));Fi((()=>0<=s&&s<=9999),Uo("The year (%s) must be between 0 and 9999 inclusive.",s.toString())),s<1900&&(s+=1900);const r=Hs(new ws(s,i-1,n));return Fi((()=>r>=0),Uo("The function [[FUNCTION_NAME]] result must be greater than or equal 01/01/1900.")),{value:r,format:this.locale.dateFormat}},isExported:!0},bp={description:Uo("Calculates the number of days, months, or years between two dates."),args:[od("start_date (date)",Uo("The start date to consider in the calculation. Must be a reference to a cell containing a DATE, a function returning a DATE type, or a number.")),od("end_date (date)",Uo("The end date to consider in the calculation. Must be a reference to a cell containing a DATE, a function returning a DATE type, or a number.")),od("unit (string)",Uo('A text abbreviation for unit of time. Accepted values are "Y" (the number of whole years between start_date and end_date), "M" (the number of whole months between start_date and end_date), "D" (the number of days between start_date and end_date), "MD" (the number of days between start_date and end_date after subtracting whole months), "YM" (the number of whole months between start_date and end_date after subtracting whole years), "YD" (the number of days between start_date and end_date, assuming start_date and end_date were no more than one year apart).'))],compute:function(e,t,o){const s=Gi(o).toUpperCase();Fi((()=>Object.values(fp).includes(s)),((e,t)=>{const o=e.map((e=>`'${e}'`)).join(", ");return Uo("The function [[FUNCTION_NAME]] has an argument with value '%s'. It should be one of: %s.",t,o)})(Object.values(fp),Gi(o)));const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Ls(i),a=Ls(n);switch(Fi((()=>n>=i),Uo("start_date (%s) should be on or before end_date (%s).",r.toLocaleDateString(),a.toLocaleDateString())),s){case fp.WHOLE_YEARS:return js(r,a);case fp.WHOLE_MONTHS:return qs(r,a);case fp.WHOLE_DAYS:return Zs(r,a);case fp.MONTH_WITHOUT_WHOLE_YEARS:return qs(r,a)-12*js(r,a);case fp.DAYS_WITHOUT_WHOLE_MONTHS:let e=a.getDate()-r.getDate();if(e<0){e=Bs(new ws(a.getFullYear(),a.getMonth()-1,1))-Math.abs(e)}return e;case fp.DAYS_BETWEEN_NO_MORE_THAN_ONE_YEAR:{if(function(e,t){return Ws(e,t,1)<1}(i,n))return Zs(r,a);const e=new ws(r.getFullYear(),a.getMonth(),a.getDate());let t=Zs(r,e);return t<0&&(e.setFullYear(r.getFullYear()+1),t=Zs(r,e)),t}}},isExported:!0},Sp={description:Uo("Converts a date string to a date value."),args:[od("date_string (string)",Uo("The string representing the date."))],compute:function(e){const t=Gi(e),o=Vs(t,this.locale);return Fi((()=>null!==o),Uo("The date_string (%s) cannot be parsed to date/time.",t.toString())),Math.trunc(o.value)},isExported:!0},yp={description:Uo("Day of the month that a specific date falls on."),args:[od("date (string)",Uo("The date from which to extract the day."))],compute:function(e){return ji(e,this.locale).getDate()},isExported:!0},Cp={description:Uo("Number of days between two dates."),args:[od("end_date (date)",Uo("The end of the date range.")),od("start_date (date)",Uo("The start of the date range."))],compute:function(e,t){const o=ji(e,this.locale),s=ji(t,this.locale),i=o.getTime()-s.getTime();return Math.round(i/Is)},isExported:!0},wp={description:Uo("Number of days between two dates on a 360-day year (months of 30 days)."),args:[od("start_date (date)",Uo("The start date to consider in the calculation.")),od("end_date (date)",Uo("The end date to consider in the calculation.")),od("method (number, default=0)",Uo("An indicator of what day count method to use. (0) US NASD method (1) European method"))],compute:function(e,t,o={value:0}){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=Ws(s,i,Zi(o)?4:0);return Math.sign(i-s)*Math.round(360*n)},isExported:!0},xp={description:Uo("Date a number of months before/after another date."),args:[od("start_date (date)",Uo("The date from which to calculate the result.")),od("months (number)",Uo("The number of months before (negative) or after (positive) 'start_date' to calculate."))],compute:function(e,t){return{value:Hs($s(ji(e,this.locale),Math.trunc(ki(t,this.locale)),!1)),format:this.locale.dateFormat}},isExported:!0},Ip={description:Uo("Last day of a month before or after a date."),args:[od("start_date (date)",Uo("The date from which to calculate the result.")),od("months (number)",Uo("The number of months before (negative) or after (positive) 'start_date' to consider."))],compute:function(e,t){const o=ji(e,this.locale),s=Math.trunc(ki(t,this.locale)),i=o.getFullYear(),n=o.getMonth();return{value:Hs(new ws(i,n+s+1,0)),format:this.locale.dateFormat}},isExported:!0},Ep={description:Uo("Hour component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the hour component."))],compute:function(e){return ji(e,this.locale).getHours()},isExported:!0},Rp={description:Uo("ISO week number of the year."),args:[od("date (date)",Uo("The date for which to determine the ISO week number. Must be a reference to a cell containing a date, a function returning a date type, or a number."))],compute:function(e){const t=ji(e,this.locale),o=t.getFullYear();let s=1;for(;4!==new ws(o,0,s).getDay();)s+=1;const i=new ws(o,0,s-3);let n=31;for(;4!==new ws(o,11,n).getDay();)n-=1;const r=new ws(o,11,n+3);let a,l;switch(a=i.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=i;break;case 1:l=new ws(o,11,n+3+1);break;case-1:let e=1;for(;4!==new ws(o-1,0,e).getDay();)e+=1;l=new ws(o-1,0,e-3)}const c=(t.getTime()-l.getTime())/Is;return Math.floor(c/7)+1},isExported:!0},Tp={description:Uo("Minute component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the minute component."))],compute:function(e){return ji(e,this.locale).getMinutes()},isExported:!0},Ap={description:Uo("Month of the year a specific date falls in"),args:[od("date (date)",Uo("The date from which to extract the month."))],compute:function(e){return ji(e,this.locale).getMonth()+1},isExported:!0},_p={description:Uo("Net working days between two provided days."),args:[od("start_date (date)",Uo("The start date of the period from which to calculate the number of net working days.")),od("end_date (date)",Uo("The end date of the period from which to calculate the number of net working days.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the date serial numbers to consider holidays."))],compute:function(e,t,o){return Op.compute.bind(this)(e,t,{value:1},o)},isExported:!0};function Dp(e){const t=e?.value;if("string"==typeof t){Fi((()=>{if(7!==t.length)return!1;for(let e of t)if("0"!==e&&"1"!==e)return!1;return!0}),Uo('When weekend is a string (%s) it must be composed of "0" or "1".',t));let e=[];for(let o=0;o<7;o++)"1"===t[o]&&e.push((o+1)%7);return e}if("number"==typeof t)return Fi((()=>1<=t&&t<=7||11<=t&&t<=17),Uo("The weekend (%s) must be a string or a number in the range 1-7 or 11-17.",t.toString())),t<=7?[t-2==-1?6:t-2,t-1]:[t-11];throw new Ii(Uo("The weekend must be a number or a string."))}const Op={description:Uo("Net working days between two dates (specifying weekends)."),args:[od("start_date (date)",Uo("The start date of the period from which to calculate the number of net working days.")),od("end_date (date)",Uo("The end date of the period from which to calculate the number of net working days.")),od("weekend (any, default=1)",Uo("A number or string representing which days of the week are considered weekends.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider as holidays."))],compute:function(e,t,o={value:1},s){const i=ji(e,this.locale),n=ji(t,this.locale),r=Dp(o);let a=new Set;void 0!==s&&Ki([s],(e=>{const t=ji(e,this.locale);a.add(t.getTime())}));const l=i.getTime()>n.getTime(),c=ws.fromTimestamp((l?i:n).getTime());let h=ws.fromTimestamp((l?n:i).getTime());const d=c.getTime();let u=h.getTime(),g=0;for(;u<=d;)r.includes(h.getDay())||a.has(u)||(g+=1),h.setDate(h.getDate()+1),u=h.getTime();return l?-g:g},isExported:!0},Fp={description:Uo("Current date and time as a date value."),args:[],compute:function(){const e=ws.now(),t=e.getTime()-xs.getTime(),o=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return{value:Math.floor(t/Is)+o,format:hl(this.locale)}},isExported:!0},Mp={description:Uo("Minute component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the second component."))],compute:function(e){return ji(e,this.locale).getSeconds()},isExported:!0},Pp={description:Uo("Converts hour/minute/second into a time."),args:[od("hour (number)",Uo("The hour component of the time.")),od("minute (number)",Uo("The minute component of the time.")),od("second (number)",Uo("The second component of the time."))],compute:function(e,t,o){let s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=Math.trunc(ki(o,this.locale));return i+=Math.floor(n/60),n=n%60+(n<0?60:0),s+=Math.floor(i/60),i=i%60+(i<0?60:0),s%=24,Fi((()=>s>=0),Uo("The function [[FUNCTION_NAME]] result cannot be negative")),{value:s/24+i/1440+n/86400,format:this.locale.timeFormat}},isExported:!0},Np={description:Uo("Converts a time string into its serial number representation."),args:[od("time_string (string)",Uo("The string that holds the time representation."))],compute:function(e){const t=Gi(e),o=Vs(t,this.locale);Fi((()=>null!==o),Uo("The time_string (%s) cannot be parsed to date/time.",t));const s=o.value-Math.trunc(o.value);return s<0?1+s:s},isExported:!0},kp={description:Uo("Current date as a date value."),args:[],compute:function(){const e=ws.now();return{value:Hs(new ws(e.getFullYear(),e.getMonth(),e.getDate())),format:this.locale.dateFormat}},isExported:!0},Vp={description:Uo("Day of the week of the date provided (as number)."),args:[od("date (date)",Uo("The date for which to determine the day of the week. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("type (number, default=1)",Uo("A number indicating which numbering system to use to represent weekdays. By default, counts starting with Sunday = 1."))],compute:function(e,t={value:1}){const o=ji(e,this.locale),s=Math.round(ki(t,this.locale)),i=o.getDay();return Fi((()=>[1,2,3].includes(s)),Uo("The type (%s) must be 1, 2 or 3.",s.toString())),1===s?i+1:2===s?0===i?7:i:0===i?6:i-1},isExported:!0},Lp={description:Uo("Week number of the year."),args:[od("date (date)",Uo("The date for which to determine the week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("type (number, default=1)",Uo("A number representing the day that a week starts on. Sunday = 1."))],compute:function(e,t={value:1}){const o=ji(e,this.locale),s=Math.round(ki(t,this.locale));if(Fi((()=>1===s||2===s||11<=s&&s<=17||21===s),Uo("The type (%s) is out of range.",s.toString())),21===s)return Rp.compute.bind(this)(e);let i;i=1===s||2===s?s-1:s-10==7?0:s-10;const n=o.getFullYear();let r=1,a=new ws(n,0,r);for(;a.getDay()!==i;)r+=1,a=new ws(n,0,r);const l=(o.getTime()-a.getTime())/Is;return l<0?1:Math.floor(l/7)+(1===r?1:2)},isExported:!0},Hp={description:Uo("Date after a number of workdays."),args:[od("start_date (date)",Uo("The date from which to begin counting.")),od("num_days (number)",Uo("The number of working days to advance from start_date. If negative, counts backwards.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider holidays."))],compute:function(e,t,o={value:null}){return Up.compute.bind(this)(e,t,{value:1},o)},isExported:!0},Up={description:Uo("Date after a number of workdays (specifying weekends)."),args:[od("start_date (date)",Uo("The date from which to begin counting.")),od("num_days (number)",Uo("The number of working days to advance from start_date. If negative, counts backwards.")),od("weekend (any, default=1)",Uo("A number or string representing which days of the week are considered weekends.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider holidays."))],compute:function(e,t,o={value:1},s){let i=ji(e,this.locale),n=Math.trunc(ki(t,this.locale));"string"==typeof o.value&&Fi((()=>"1111111"!==o.value),Uo("The weekend must be different from '1111111'."));const r=Dp(o);let a=new Set;void 0!==s&&Ki([s],(e=>{const t=ji(e,this.locale);a.add(t.getTime())}));let l=ws.fromTimestamp(i.getTime()),c=l.getTime();const h=Math.sign(n);let d=Math.abs(n);for(;d>0;)l.setDate(l.getDate()+h),c=l.getTime(),r.includes(l.getDay())||a.has(c)||(d-=1);const u=c-xs.getTime();return{value:Math.round(u/Is),format:this.locale.dateFormat}},isExported:!0},Bp={description:Uo("Year specified by a given date."),args:[od("date (date)",Uo("The date from which to extract the year."))],compute:function(e){return ji(e,this.locale).getFullYear()},isExported:!0},zp={description:Uo("Exact number of years between two dates."),args:[od("start_date (date)",Uo("The start date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("end_date (date)",Uo("The end date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("day_count_convention (number, default=0)",Uo("An indicator of what day count method to use."))],compute:function(e,t,o={value:0}){let s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale));const n=Math.trunc(ki(o,this.locale));return Fi((()=>s>=0),Uo("The start_date (%s) must be positive or null.",s.toString())),Fi((()=>i>=0),Uo("The end_date (%s) must be positive or null.",i.toString())),Fi((()=>0<=n&&n<=4),Uo("The day_count_convention (%s) must be between 0 and 4 inclusive.",n.toString())),Ws(s,i,n)}},$p={description:Uo("First day of the month preceding a date."),args:[od("date (date)",Uo("The date from which to calculate the result."))],compute:function(e){const t=ji(e,this.locale),o=t.getFullYear(),s=t.getMonth();return{value:Hs(new ws(o,s,1)),format:this.locale.dateFormat}}},Gp={description:Uo("Last day of the month following a date."),args:[od("date (date)",Uo("The date from which to calculate the result."))],compute:function(e){return Ip.compute.bind(this)(e,{value:0})}},Wp={description:Uo("Quarter of the year a specific date falls in"),args:[od("date (date)",Uo("The date from which to extract the quarter."))],compute:function(e){return Math.ceil((ji(e,this.locale).getMonth()+1)/3)}},qp={description:Uo("First day of the quarter of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the start of quarter."))],compute:function(e){const t=Wp.compute.bind(this)(e),o=Bp.compute.bind(this)(e);return{value:Hs(new ws(o,3*(t-1),1)),format:this.locale.dateFormat}}},Zp={description:Uo("Last day of the quarter of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the end of quarter."))],compute:function(e){const t=Wp.compute.bind(this)(e),o=Bp.compute.bind(this)(e);return{value:Hs(new ws(o,3*t,0)),format:this.locale.dateFormat}}},jp={description:Uo("First day of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the start of the year."))],compute:function(e){const t=Bp.compute.bind(this)(e);return{value:Hs(new ws(t,0,1)),format:this.locale.dateFormat}}},Yp={description:Uo("Last day of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the end of the year."))],compute:function(e){const t=Bp.compute.bind(this)(e);return{value:Hs(new ws(t+1,0,0)),format:this.locale.dateFormat}}};var Xp=Object.freeze({__proto__:null,DATE:vp,DATEDIF:bp,DATEVALUE:Sp,DAY:yp,DAYS:Cp,DAYS360:wp,EDATE:xp,EOMONTH:Ip,HOUR:Ep,ISOWEEKNUM:Rp,MINUTE:Tp,MONTH:Ap,MONTH_END:Gp,MONTH_START:$p,NETWORKDAYS:_p,NETWORKDAYS_INTL:Op,NOW:Fp,QUARTER:Wp,QUARTER_END:Zp,QUARTER_START:qp,SECOND:Mp,TIME:Pp,TIMEVALUE:Np,TODAY:kp,WEEKDAY:Vp,WEEKNUM:Lp,WORKDAY:Hp,WORKDAY_INTL:Up,YEAR:Bp,YEARFRAC:zp,YEAR_END:Yp,YEAR_START:jp});const Kp={description:Uo("Compare two numeric values, returning 1 if they're equal."),args:[od("number1 (number)",Uo("The first number to compare.")),od("number2 (number, default=0)",Uo("The second number to compare."))],compute:function(e,t={value:0}){return ki(e,this.locale)===ki(t,this.locale)?1:0},isExported:!0};var Jp=Object.freeze({__proto__:null,DELTA:Kp});const Qp=[oi.number,oi.error,oi.text,oi.boolean];function em(e){const t="asc"===e?1:-1;return(e,o)=>{if(e.type===oi.empty)return o.type===oi.empty?0:1;if(o.type===oi.empty)return-1;let s=Qp.indexOf(e.type)-Qp.indexOf(o.type);return 0===s&&(s=e.type===oi.text||e.type===oi.error?e.value.localeCompare(o.value):e.value-o.value),t*s}}function tm(e,t,o,s,i){let n=s.right>s.left;if(e.model.getters.doesIntersectMerge(t,s)){let o;n=!1;for(let i=s.top;i<=s.bottom;i++){o=[];for(let n=s.left;n<=s.right;n++){let s=e.model.getters.getMerge({sheetId:t,col:n,row:i});s&&!o.includes(s.id.toString())&&o.push(s.id.toString())}if(o.length>=2){n=!0;break}}}if(n)return void om(e,t,o,s,i);const r=e.model.getters.getContiguousZone(t,s);Qo(r,s)?om(e,t,o,s,i):e.askConfirmation(Uo("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>om(e,t,o,r,i)),(()=>om(e,t,o,s,i)))}function om(e,t,o,s,i,n){const r=e.model.dispatch("SORT_CELLS",{sheetId:t,col:o.col,row:o.row,zone:s,sortDirection:i,sortOptions:n});if(r.isCancelledBecause("InvalidSortZone")){const{col:t,row:i}=o;e.model.selection.selectZone({cell:{col:t,row:i},zone:s}),e.raiseError(Uo("Cannot sort. To sort, select only cells or only merges that have the same size."))}if(r.isCancelledBecause("SortZoneWithArrayFormulas")){const{col:t,row:i}=o;e.model.selection.selectZone({cell:{col:t,row:i},zone:s}),e.raiseError(Uo("Cannot sort a zone with array formulas."))}}function sm(e,t,...o){for(const[e,t]of o.entries())Fi((()=>void 0!==t),Uo("Value for parameter %d is missing, while the function [[FUNCTION_NAME]] expect a number or a range.",e+1));const s=[],i=[],n=e.length;for(let r=0;r<o.length;r+=2){s.push(Zi(Sl(o[r+1])?.value)?"asc":"desc");const a=o[r];if(bi(a)&&(a.length>1||a[0].length>1))Fi((()=>1===a.length&&a[0].length===n),Uo("Wrong size for %s. Expected a range of size 1x%s. Got %sx%s.",`sort_column${r+1}`,n,a.length,a[0].length)),i.push(a.flat().map((e=>e.value)));else{const o=ki(Sl(a)?.value,t);if(o<1||o>e[0].length)return e;i.push(e.map((e=>e[o-1].value)))}}if(0===i.length)for(let t=0;t<e[0].length;t++)i.push(e.map((e=>e[t].value))),s.push("asc");const r={desc:em("desc"),asc:em("asc")},a=je(0,e.length);return a.sort(((e,t)=>{for(const[o,n]of i.entries()){const i=n[e],a=n[t],l={value:i,type:null===i?oi.empty:"string"==typeof i?oi.text:typeof i},c={value:a,type:null===a?oi.empty:"string"==typeof a?oi.text:typeof a},h=r[s[o]](l,c);if(0!==h)return h}return 0})),a.map((t=>e[t]))}const im={description:Uo("Returns a filtered version of the source range, returning only rows or columns that meet the specified conditions."),args:[od("range (any, range<any>)",Uo("The data to be filtered.")),od("condition1 (boolean, range<boolean>)",Uo("A column or row containing true or false values corresponding to the first column or row of range.")),od("condition2 (boolean, range<boolean>, repeating)",Uo("Additional column or row containing true or false values."))],compute:function(e,...t){let o=vn(e);const s=t.map((e=>nn(vn(e),(e=>e.value))));s.map((e=>id(Uo("The arguments condition must be a single column or row."),e))),nd(Uo("The arguments conditions must have the same dimensions."),...t);const i=s.map((e=>e.flat())),n=1===s[0].length?"row":"col";o="row"===n?rn(o):o,Fi((()=>i.every((e=>e.length===o.length))),Uo("FILTER has mismatched sizes on the range and conditions."));const r=[];for(let e=0;e<o.length;e++){const t=o[e];i.every((t=>("boolean"==typeof t[e]||"number"==typeof t[e])&&t[e]))&&r.push(t)}return r.length?"row"===n?rn(r):r:new Ai(Uo("No match found in FILTER evaluation"))},isExported:!1},nm={description:Uo("Sorts the rows of a given array or range by the values in one or more columns."),args:[od("range (range)",Uo("The data to be sorted.")),od("sort_column (any, range<number>, repeating)",Uo("The index of the column in range or a range outside of range containing the values by which to sort.")),od("is_ascending (boolean, repeating)",Uo("TRUE or FALSE indicating whether to sort sort_column in ascending order. FALSE sorts in descending order."))],compute:function(e,...t){const o=rn(e);return rn(sm(o,this.locale,...t))},isExported:!0},rm={description:Uo("Returns the first n items in a data set after performing a sort."),args:[od("range (range)",Uo("The data to be sorted.")),od("n (number, default=1)",Uo("The number of items to return.")),od("display_ties_mode (number, default=0)",Uo("A number representing the way to display ties.")),od("sort_column (number, range<number>, repeating)",Uo("The index of the column in range or a range outside of range containing the values by which to sort.")),od("is_ascending (boolean, repeating)",Uo("TRUE or FALSE indicating whether to sort sort_column in ascending order. FALSE sorts in descending order."))],compute:function(e,t,o,...s){const i=ki(t?.value??1,this.locale);Fi((()=>i>=0),Uo("Wrong value of 'n'. Expected a positive number. Got %s.",i));const n=ki(o?.value??0,this.locale);Fi((()=>n>=0&&n<=3),Uo("Wrong value of 'display_ties_mode'. Expected a positive number between 0 and 3. Got %s.",n));const r=sm(rn(e),this.locale,...s),a=(e,t)=>JSON.stringify(r[e].map((e=>e.value)))===JSON.stringify(r[t].map((e=>e.value)));switch(n){case 0:return rn(r.slice(0,i));case 1:for(let e=i;e<r.length;e++)if(!a(e,i-1))return rn(r.slice(0,e));return rn(r);case 2:{const e=[r[0]];for(let t=1;t<r.length;t++)for(let o=0;o<t&&!a(t,o);o++)o===t-1&&e.push(r[t]);return rn(e.slice(0,i))}case 3:{const e=[r[0]];let t=1;for(let o=1;o<r.length&&(a(o,o-1)||t++,!(t>i));o++)e.push(r[o]);return rn(e)}}},isExported:!1},am={description:Uo("Unique rows in the provided source range."),args:[od("range (any, range<any>)",Uo("The data to filter by unique entries.")),od("by_column (boolean, default=FALSE)",Uo("Whether to filter the data by columns or by rows.")),od("exactly_once (boolean, default=FALSE)",Uo("Whether to return only entries with no duplicates."))],compute:function(e={value:""},t,o){if(!bi(e))return[[e]];const s=Zi(t?.value)||!1,i=Zi(o?.value)||!1;s||(e=rn(e));const n=new Map;for(const t of e){const e=JSON.stringify(t.map((e=>e.value))),o=n.get(e);o?o.count++:n.set(e,{data:t,count:1})}const r=[];for(const e of n.values())i&&e.count>1||r.push(e.data);return r.length?s?r:rn(r):new Ii(Uo("No unique values found"))},isExported:!0};var lm=Object.freeze({__proto__:null,FILTER:im,SORT:nm,SORTN:rm,UNIQUE:am});function cm(e,t){Fi((()=>e<t),Uo("The maturity (%s) must be strictly greater than the settlement (%s).",t.toString(),e.toString()))}function hm(e,t){Fi((()=>t<e),Uo("The settlement date (%s) must be strictly greater than the issue date (%s).",e.toString(),t.toString()))}function dm(e){Fi((()=>[1,2,4].includes(e)),Uo("The frequency (%s) must be one of %s",e.toString(),[1,2,4].toString()))}function um(e){Fi((()=>0<=e&&e<=4),Uo("The day_count_convention (%s) must be between 0 and 4 inclusive.",e.toString()))}function gm(e){Fi((()=>e>0),Uo("The redemption (%s) must be strictly positive.",e.toString()))}function pm(e){Fi((()=>e>0),Uo("The price (%s) must be strictly positive.",e.toString()))}function mm(e){Fi((()=>e>0),Uo("The number_of_periods (%s) must be greater than 0.",e.toString()))}function fm(e){Fi((()=>e>0),Uo("The rate (%s) must be strictly positive.",e.toString()))}function vm(e){Fi((()=>e>0),Uo("The life (%s) must be strictly positive.",e.toString()))}function bm(e){Fi((()=>e>=0),Uo("The cost (%s) must be positive or null.",e.toString()))}function Sm(e){Fi((()=>e>0),Uo("The period (%s) must be strictly positive.",e.toString()))}function ym(e){Fi((()=>e>=0),Uo("The salvage (%s) must be positive or null.",e.toString()))}function Cm(e){Fi((()=>e>0),Uo("The present value (%s) must be strictly positive.",e.toString()))}function wm(e,t){Fi((()=>e<=t),Uo("The period (%s) must be less than or equal life (%s).",e.toString(),t.toString()))}function xm(e){Fi((()=>e>0),Uo("The investment (%s) must be strictly positive.",e.toString()))}function Im(e){Fi((()=>e>0),Uo("The discount (%s) must be strictly positive.",e.toString()))}function Em(e){Fi((()=>e<1),Uo("The discount (%s) must be smaller than 1.",e.toString()))}function Rm(e){Fi((()=>e>0),Uo("The depreciation factor (%s) must be strictly positive.",e.toString()))}function Tm(e,t,o){const s=ji(e,o),i=ji(t,o),n=ji(e,o);n.setFullYear(s.getFullYear()+1),Fi((()=>i.getTime()<=n.getTime()),Uo("The settlement date (%s) must at most one year after the maturity date (%s).",e.toString(),t.toString()))}function Am(e,t,o){mm(o),Fi((()=>e>0),Uo("The first_period (%s) must be strictly positive.",e.toString())),Fi((()=>t>0),Uo("The last_period (%s) must be strictly positive.",t.toString())),Fi((()=>e<=t),Uo("The first_period (%s) must be smaller or equal to the last_period (%s).",e.toString(),t.toString())),Fi((()=>t<=o),Uo("The last_period (%s) must be smaller or equal to the number_of_periods (%s).",e.toString(),o.toString()))}function _m(e){Fi((()=>e>-1),Uo("The rate_guess (%s) must be strictly greater than -1.",e.toString()))}function Dm(e,t){Fi((()=>e.length===t.length&&e[0].length===t[0].length),Uo("The cashflow_amounts and cashflow_dates ranges must have the same dimensions."))}function Om(e){Fi((()=>e.every((t=>t>=e[0]))),Uo("All the dates should be greater or equal to the first date in cashflow_dates (%s).",e[0].toString()))}const Fm=[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))];function Mm(e,t,o,s,i=1e-10,n){let r,a,l,c,h=o,d=!1,u=0;do{l=e(h),isNaN(l)?(Fi((()=>u<s&&void 0!==n),Uo("Function [[FUNCTION_NAME]] didn't find any result.")),u++,h=n(c),c=h):(r=h-l/t(h),a=Math.abs(r-h),h=r,d=a<i||Math.abs(l)<i,Fi((()=>u<s),Uo("Function [[FUNCTION_NAME]] didn't find any result.")),u++)}while(!d);return h}const Pm={description:Uo("Accrued interest of security paying at maturity."),args:[od("issue (date)",Uo("The date the security was initially issued.")),od("maturity (date)",Uo("The maturity date of the security.")),od("rate (number)",Uo("The annualized rate of interest.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(s,this.locale),l=ki(o,this.locale),c=Math.trunc(ki(i,this.locale));!function(e){Fi((()=>e>=0),Uo("The issue (%s) must be positive or null.",e.toString()))}(n),hm(r,n),um(c),gm(a),fm(l);return a*l*Ws(n,r,c)},isExported:!0},Nm={description:Uo("Depreciation for an accounting period."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("purchase_date (date)",Uo("The date the asset was purchased.")),od("first_period_end (date)",Uo("The date the first period ended.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("rate (number)",Uo("The deprecation rate.")),od("day_count_convention (number, optional)",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=ki(e,this.locale),l=Math.trunc(ki(t,this.locale)),c=Math.trunc(ki(o,this.locale)),h=ki(s,this.locale),d=ki(i,this.locale),u=ki(n,this.locale),g=Math.trunc(ki(r,this.locale));!function(e){Fi((()=>e>0),Uo("The cost (%s) must be strictly positive.",e.toString()))}(a),function(e){Fi((()=>e>=0),Uo("The purchase_date (%s) must be positive or null.",e.toString()))}(l),ym(h),function(e,t){Fi((()=>e<=t),Uo("The salvage (%s) must be smaller or equal than the cost (%s).",e.toString(),t.toString()))}(h,a),function(e){Fi((()=>e>=0),Uo("The period (%s) must be positive or null.",e.toString()))}(d),fm(u),um(g),Fi((()=>l<=c),Uo("The purchase_date (%s) must be before the first_period_end (%s).",l.toString(),c.toString()));const p=d<1&&d>0?1:Math.trunc(d),m=a*u,f=Ws(l,c,g),v=l===c?m:m*f,b=a-v-m*p;return b>=h?0===p?v:m:h-b<m?m-(h-b):0},isExported:!0},km={description:Uo("Days in coupon period containing settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));if(cm(i,n),dm(r),um(a),1===a){const i=Bm.compute.bind(this)(e,t,o,s).value;return Hm.compute.bind(this)(e,t,o,s).value-i}return(3===a?365:360)/r},isExported:!0},Vm={description:Uo("Days from settlement until next coupon."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=Bm.compute.bind(this)(e,t,o,s).value;if([1,2,3].includes(a))return i-l;if(4===a){const e=Ws(l,i,a);return Math.round(360*e)}const c=ji(i,this.locale),h=ji(l,this.locale),d=h.getFullYear(),u=c.getFullYear(),g=h.getMonth()+1,p=c.getMonth()+1;let m=h.getDate(),f=c.getDate();return 2===g&&2===p&&zs(h)&&zs(c)&&(f=30),31!==f||30!==m&&31!==m||(f=30),2===g&&zs(h)&&(m=30),31===m&&(m=30),360*(u-d)+30*(p-g)+(f-m)},isExported:!0},Lm={description:Uo("Days from settlement until next coupon."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=Hm.compute.bind(this)(e,t,o,s).value;if([1,2,3].includes(a))return l-i;if(4===a){const e=Ws(i,l,a);return Math.round(360*e)}const c=Vm.compute.bind(this)(e,t,o,s);return km.compute.bind(this)(e,t,o,s)-c},isExported:!0},Hm={description:Uo("Next coupon date after the settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=12/r,c=Um.compute.bind(this)(e,t,o,s);return{value:Hs($s(ji(n,this.locale),-(c-1)*l,!0)),format:this.locale.dateFormat}},isExported:!0},Um={description:Uo("Number of coupons between settlement and maturity."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);let l=1,c=n;const h=12/r;for(;c>i;)c=Hs($s(ji(c,this.locale),-h,!1)),l++;return l-1},isExported:!0},Bm={description:Uo("Last coupon date prior to or on the settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=12/r,c=Um.compute.bind(this)(e,t,o,s);return{value:Hs($s(ji(n,this.locale),-c*l,!0)),format:this.locale.dateFormat}},isExported:!0},zm={description:Uo("Cumulative interest paid over a set of periods."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("first_period (number)",Uo("The number of the payment period to begin the cumulative calculation.")),od("last_period (number)",Uo("The number of the payment period to end the cumulative calculation.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i,n={value:0}){const r=ki(s,this.locale),a=ki(i,this.locale),l=ki(e,this.locale),c=ki(o,this.locale),h=ki(t,this.locale),d=Zi(n)?1:0;Am(r,a,h),fm(l),Cm(c);let u=0;for(let e=r;e<=a;e++)u+=of(l,e,h,c,0,d);return u},isExported:!0},$m={description:Uo("Cumulative principal paid over a set of periods."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("first_period (number)",Uo("The number of the payment period to begin the cumulative calculation.")),od("last_period (number)",Uo("The number of the payment period to end the cumulative calculation.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i,n={value:0}){const r=ki(s,this.locale),a=ki(i,this.locale),l=ki(e,this.locale),c=ki(o,this.locale),h=ki(t,this.locale),d=Zi(n)?1:0;Am(r,a,h),fm(l),Cm(c);let u=0;for(let e=r;e<=a;e++)u+=ff(l,e,h,c,0,d);return u},isExported:!0},Gm={description:Uo("Depreciation via declining balance method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("month (number, optional)",Uo("The number of months in the first year of depreciation."))],compute:function(e,t,o,s,...i){const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=Math.trunc(ki(s,this.locale)),c=i.length?Math.trunc(ki(i[0],this.locale)):12,h=a+(12===c?0:1);bm(n),ym(r),Sm(l),vm(a),Fi((()=>1<=c&&c<=12),Uo("The month (%s) must be between 1 and 12 inclusive.",c.toString())),Fi((()=>l<=h),Uo("The period (%s) must be less than or equal to %s.",l.toString(),h.toString()));const d=c/12;let u=1-Math.pow(r/n,1/a);u=Math.round(1e3*u)/1e3;let g=n,p=n*(1-u*d);for(let e=1;e<l;e++)g=p,p=g*(1-u),e===a&&(p=g*(1-u*(1-d)));return{value:g-p,format:"#,##0.00"}},isExported:!0};function Wm(e,t,o,s,i){if(bm(e),ym(t),Sm(s),vm(o),wm(s,o),Rm(i),0===e||t>=e)return 0;const n=i/o;if(n>1)return 1===s?e-t:0;if(s<=1)return e*n;const r=e*Math.pow(1-n,s-1),a=e*Math.pow(1-n,s),l=a<t?r-t:r-a;return Math.max(l,0)}const qm={description:Uo("Depreciation via double-declining balance method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("factor (number, default=2)",Uo("The factor by which depreciation decreases."))],compute:function(e,t,o,s,i={value:2}){return{value:Wm(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),ki(i,this.locale)),format:"#,##0.00"}},isExported:!0},Zm={description:Uo("Discount rate of a security based on price."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),pm(a),gm(l);return(l-a)/l/Ws(n,r,c)},isExported:!0},jm={description:Uo("Convert a decimal fraction to decimal value."),args:[od("fractional_price (number)",Uo("The price quotation given using fractional decimal conventions.")),od("unit (number)",Uo("The units of the fraction, e.g. 8 for 1/8ths or 32 for 1/32nds."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));Fi((()=>s>0),Uo("The unit (%s) must be strictly positive.",s.toString()));const i=Math.trunc(o);return i+(o-i)*(10**Math.ceil(Math.log10(s))/s)},isExported:!0},Ym={description:Uo("Convert a decimal value to decimal fraction."),args:[od("decimal_price (number)",Uo("The price quotation given as a decimal value.")),od("unit (number)",Uo("The units of the desired fraction, e.g. 8 for 1/8ths or 32 for 1/32nds."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));Fi((()=>s>0),Uo("The unit (%s) must be strictly positive.",s.toString()));const i=Math.trunc(o);return i+(o-i)*(s/10**Math.ceil(Math.log10(s)))},isExported:!0},Xm={description:Uo("Number of periods for an investment to reach a value."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=ki(o,this.locale),c=ki(s,this.locale),h=Math.trunc(ki(i,this.locale)),d=Math.trunc(ki(n,this.locale));cm(r,a),dm(h),um(d),Fi((()=>l>=0),Uo("The rate (%s) must be positive or null.",l.toString())),Fi((()=>c>=0),Uo("The yield (%s) must be positive or null.",c.toString()));const u=Ws(r,a,d),g=u-Math.trunc(u)||1/h,p=Math.ceil(u*h),m=l/h,f=c/h;let v=0,b=0;for(let e=1;e<=p;e++){const t=(m+(e===p?1:0))/(1+f)**e;b+=(g+(e-1)/h)*t,v+=t}return 0===v?0:b/v},isExported:!0},Km={description:Uo("Annual effective interest rate."),args:[od("nominal_rate (number)",Uo("The nominal interest rate per year.")),od("periods_per_year (number)",Uo("The number of compounding periods per year."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));return Fi((()=>o>0),Uo("The nominal rate (%s) must be strictly greater than 0.",o.toString())),Fi((()=>s>0),Uo("The number of periods by year (%s) must strictly greater than 0.",s.toString())),Math.pow(1+o/s,s)-1},isExported:!0};function Jm(e,t,o,s,i){return 0===e?-(s+o*t):-s*(1+e)**t-o*(1+e*i)*((1+e)**t-1)/e}const Qm={description:Uo("Future value of an annuity investment."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_amount (number)",Uo("The amount per period to be paid.")),od("present_value (number, default=0)",Uo("The current value of the annuity.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;return{value:Jm(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),Zi(i)?1:0),format:"#,##0.00"}},isExported:!0},ef={description:Uo("Future value of principal from series of rates."),args:[od("principal (number)",Uo("The amount of initial capital or value to compound against.")),od("rate_schedule (number, range<number>)",Uo("A series of interest rates to compound against the principal."))],compute:function(e,t){return en([t],((e,t)=>e*(1+ki(t,this.locale))),ki(e,this.locale))},isExported:!0},tf={description:Uo("Calculates effective interest rate."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("investment (number)",Uo("The amount invested in the security.")),od("redemption (number)",Uo("The amount to be received at maturity.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(s,this.locale),l=ki(o,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),xm(l),gm(a),um(c);return(a-l)/l/Ws(n,r,c)},isExported:!0};function of(e,t,o,s,i,n){return pf(e,o,s,i,n)-ff(e,t,o,s,i,n)}const sf={description:Uo("Payment on the principal of an investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("period (number)",Uo("The amortization period, in terms of number of periods.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i={value:0},n={value:0}){return{value:of(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),ki(i,this.locale),Zi(n)?1:0),format:"#,##0.00"}},isExported:!0},nf={description:Uo("Internal rate of return given periodic cashflows."),args:[od("cashflow_amounts (number, range<number>)",Uo("An array or range containing the income or payments associated with the investment.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the internal rate of return will be."))],compute:function(e,t={value:.1}){const o=ki(t,this.locale);_m(o);let s=!1,i=!1,n=[];Ji([e],(({value:e})=>{e>0&&(s=!0),e<0&&(i=!0),n.push(e)}),this.locale),Fi((()=>s&&i),Uo("The cashflow_amounts must include negative and positive values."));const r=n.shift();return{value:Mm((function(e){return function(e,t,o){const s=o.length;let i=0;return o.reduce(((t,o)=>(i++,t+o*e**(s-i))),t*e**s)}(e,r,n)}),(function(e){return function(e,t,o){const s=o.length;let i=0;return o.reduce(((t,o)=>(i++,t+o*(s-i)*e**(s-i-1))),t*s*e**(s-1))}(e,r,n)}),o+1,20,1e-5)-1,format:"0%"}},isExported:!0},rf={description:Uo("Returns the interest paid at a particular period of an investment."),args:[od("rate (number)",Uo("The interest rate.")),od("period (number)",Uo("The period for which you want to view the interest payment.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity."))],compute:function(e,t,o,s){const i=ki(e,this.locale),n=ki(t,this.locale),r=ki(o,this.locale),a=ki(s,this.locale);Fi((()=>0!==r),Uo("The number of periods must be different than 0.",r.toString()));return-1*(a-a*(n/r))*i},isExported:!0},af={description:Uo("Modified Macaulay duration."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){return Xm.compute.bind(this)(e,t,o,s,i,n)/(1+ki(s,this.locale)/Math.trunc(ki(i,this.locale)))},isExported:!0},lf={description:Uo("Modified internal rate of return."),args:[od("cashflow_amounts (range<number>)",Uo("A range containing the income or payments associated with the investment. The array should contain bot payments and incomes.")),od("financing_rate (number)",Uo("The interest rate paid on funds invested.")),od("reinvestment_return_rate (number)",Uo("The return (as a percentage) earned on reinvestment of income received from the investment."))],compute:function(e,t,o){const s=ki(t,this.locale),i=ki(o,this.locale),n=rn(e).flat().filter((e=>null!==e.value)).map((e=>ki(e,this.locale))),r=n.length;let a=0,l=0;for(const e of je(0,r)){const t=n[e];t>=0?a+=t*(i+1)**(r-e-1):l+=t/(s+1)**e}Fi((()=>0!==l&&0!==a),Uo("There must be both positive and negative values in cashflow_amounts."));return(-a/l)**(1/(r-1))-1},isExported:!0},cf={description:Uo("Annual nominal interest rate."),args:[od("effective_rate (number)",Uo("The effective interest rate per year.")),od("periods_per_year (number)",Uo("The number of compounding periods per year."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));return Fi((()=>o>0),Uo("The effective rate (%s) must must strictly greater than 0.",o.toString())),Fi((()=>s>0),Uo("The number of periods by year (%s) must strictly greater than 0.",s.toString())),(Math.pow(o+1,1/s)-1)*s},isExported:!0},hf={description:Uo("Number of payment periods for an investment."),args:[od("rate (number)",Uo("The interest rate.")),od("payment_amount (number)",Uo("The amount of each payment made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i)?1:0;if(0===n)return-(l+a)/r;const h=r*(1+n*c)/n;return Math.log((h-l)/(a+h))/Math.log(1+n)},isExported:!0};function df(e,t,o,s){let i=0;return tn(o,((t,o)=>(i++,t+o/(1+e)**i)),t,s)}const uf={description:Uo("The net present value of an investment based on a series of periodic cash flows and a discount rate."),args:[od("discount (number)",Uo("The discount rate of the investment over one period.")),od("cashflow1 (number, range<number>)",Uo("The first future cash flow.")),od("cashflow2 (number, range<number>, repeating)",Uo("Additional future cash flows."))],compute:function(e,...t){const o=ki(e,this.locale);return Fi((()=>-1!==o),Uo("The discount (%s) must be different from -1.",o.toString())),{value:df(o,0,t,this.locale),format:"#,##0.00"}},isExported:!0},gf={description:Uo("Computes the number of periods needed for an investment to reach a value."),args:[od("rate (number)",Uo("The rate at which the investment grows each period.")),od("present_value (number)",Uo("The investment's current value.")),od("future_value (number)",Uo("The investment's desired future value."))],compute:function(e,t,o){const s=ki(e,this.locale),i=ki(t,this.locale),n=ki(o,this.locale);return fm(s),Fi((()=>i>0),Uo("The present_value (%s) must be strictly positive.",i.toString())),Fi((()=>n>0),Uo("The future_value (%s) must be strictly positive.",n.toString())),(Math.log(n)-Math.log(i))/Math.log(1+s)},isExported:!0};function pf(e,t,o,s,i){if(mm(t),0===e)return-(s+o)/t;let n=-(o*(1+e)**t+s);return n=n*e/((1+e*i)*((1+e)**t-1)),n}const mf={description:Uo("Periodic payment for an annuity investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){const n=ki(t,this.locale),r=ki(e,this.locale),a=Zi(i)?1:0,l=ki(s,this.locale);return{value:pf(r,n,ki(o,this.locale),l,a),format:"#,##0.00"}},isExported:!0};function ff(e,t,o,s,i,n){mm(o),Fi((()=>t>0&&t<=o),Uo("The period must be between 1 and number_of_periods (%s)",o));const r=pf(e,o,s,i,n);if(1===n&&1===t)return r;return r+-Jm(e,0===n?t-1:t-2,r,s+r*n,0)*e}const vf={description:Uo("Payment on the principal of an investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("period (number)",Uo("The amortization period, in terms of number of periods.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i={value:0},n={value:0}){const r=ki(o,this.locale),a=ki(e,this.locale),l=ki(t,this.locale),c=Zi(n)?1:0,h=ki(i,this.locale);return{value:ff(a,l,r,ki(s,this.locale),h,c),format:"#,##0.00"}},isExported:!0},bf={description:Uo("Present value of an annuity investment."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_amount (number)",Uo("The amount per period to be paid.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i)?1:0;return{value:n?-(a*(1+n*c)*((1+n)**r-1)/n+l)/(1+n)**r:-(l+a*r),format:"#,##0.00"}},isExported:!0},Sf={description:Uo("Price of a security paying periodic interest."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=Math.trunc(ki(e,this.locale)),l=Math.trunc(ki(t,this.locale)),c=ki(o,this.locale),h=ki(s,this.locale),d=ki(i,this.locale),u=Math.trunc(ki(n,this.locale)),g=Math.trunc(ki(r,this.locale));cm(a,l),dm(u),um(g),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),Fi((()=>h>=0),Uo("The yield (%s) must be positive or null.",h.toString())),gm(d);const p=Ws(a,l,g)*u,m=Math.ceil(p),f=p-Math.floor(p)||1,v=1+h/u,b=100*c/u;if(1===m)return(b+d)/(f*h/u+1)-b*(1-f);let S=0;for(let e=1;e<=m;e++)S+=b/v**(e-1+f);return d/v**(m-1+f)+S-b*(1-f)},isExported:!0},yf={description:Uo("Price of a discount security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the security at time of purchase.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),Im(a),gm(l);return l-a*l*Ws(n,r,c)},isExported:!0},Cf={description:Uo("Calculates the price of a security paying interest at maturity, based on expected yield."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("issue (date)",Uo("The date the security was initially issued.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){n=n||0;const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=Math.trunc(ki(o,this.locale)),c=ki(s,this.locale),h=ki(i,this.locale),d=Math.trunc(ki(n,this.locale));hm(r,l),cm(r,a),um(d),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),Fi((()=>h>=0),Uo("The yield (%s) must be positive or null.",h.toString()));const u=Ws(r,a,d),g=Ws(r,l,d);return(100+Ws(l,a,d)*c*100)/(1+u*h)-g*c*100},isExported:!0},wf=.1,xf={description:Uo("Interest rate of an annuity investment."),args:[od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_per_period (number)",Uo("The amount per period to be paid.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the interest rate will be."))],compute:function(e,t,o,s={value:0},i={value:0},n={value:wf}){const r=ki(e,this.locale),a=ki(t,this.locale),l=Zi(i)?1:0,c=ki(n,this.locale)||wf;let h=ki(s,this.locale),d=ki(o,this.locale);mm(r),Fi((()=>[a,d,h].some((e=>e>0))&&[a,d,h].some((e=>e<0))),Uo("There must be both positive and negative values in [payment_amount, present_value, future_value].",r.toString())),_m(c),h-=a*l,d+=a*l;return{value:Mm((e=>{const t=Math.pow(1+e,r);return h+d*t+a*((t-1)/e)}),(e=>{const t=Math.pow(1+e,r-1),o=Math.pow(1+e,r);return d*r*t+a*(r*t/e-(o-1)/e/e)}),c,40,1e-5),format:"0%"}},isExported:!0},If={description:Uo("Amount received at maturity for a security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("investment (number)",Uo("The amount invested (irrespective of face value of each security).")),od("discount (number)",Uo("The discount rate of the security invested in.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),xm(a),Im(l);return a/(1-l*Ws(n,r,c))},isExported:!0},Ef={description:Uo("Computes the rate needed for an investment to reach a specific value within a specific number of periods."),args:[od("number_of_periods (number)",Uo("The number of periods.")),od("present_value (number)",Uo("The present value of the investment.")),od("future_value (number)",Uo("The future value of the investment."))],compute:function(e,t,o){const s=ki(e,this.locale),i=ki(t,this.locale),n=ki(o,this.locale);return mm(s),(n/i)**(1/s)-1},isExported:!0},Rf={description:Uo("Depreciation of an asset using the straight-line method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated."))],compute:function(e,t,o){return{value:(ki(e,this.locale)-ki(t,this.locale))/ki(o,this.locale),format:"#,##0.00"}},isExported:!0},Tf={description:Uo("Depreciation via sum of years digit method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation."))],compute:function(e,t,o,s){const i=ki(e,this.locale),n=ki(t,this.locale),r=ki(o,this.locale),a=ki(s,this.locale);Sm(a),vm(r),wm(a,r);return{value:(r-a+1)/(r*(r+1)/2)*(i-n),format:"#,##0.00"}},isExported:!0};function Af(e,t,o){return 100*(1-o*Ws(e,t,2))}const _f={description:Uo("Price of a US Treasury bill."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the bill at time of purchase."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);return cm(s,i),Tm(s,i,this.locale),Im(n),Em(n),Af(s,i,n)},isExported:!0},Df={description:Uo("Equivalent rate of return for a US Treasury bill."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the bill at time of purchase."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);cm(s,i),Tm(s,i,this.locale),Im(n),Em(n);const r=Cp.compute.bind(this)({value:i},{value:s});if(r<=182)return 365*n/(360-n*r);const a=Af(s,i,n)/100,l=r/(366===r?366:365);return(-2*l+2*Math.sqrt(l**2-(2*l-1)*(1-1/a)))/(2*l-1)},isExported:!0},Of={description:Uo("The yield of a US Treasury bill based on price."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);cm(s,i),Tm(s,i,this.locale),pm(n);return(100-n)/n*(1/Ws(s,i,2))},isExported:!0},Ff={description:Uo("Variable declining balance. WARNING : does not handle decimal periods."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("start (number)",Uo("Starting period to calculate depreciation.")),od("end (number)",Uo("Ending period to calculate depreciation.")),od("factor (number, default=2)",Uo("The number of months in the first year of depreciation.")),od("no_switch (number, default=false)",Uo("Whether to switch to straight-line depreciation when the depreciation is greater than the declining balance calculation."))],compute:function(e,t,o,s,i,n={value:2},r={value:false}){n=n||0;const a=ki(e,this.locale),l=ki(t,this.locale),c=ki(o,this.locale),h=Math.trunc(ki(s,this.locale)),d=Math.trunc(ki(i,this.locale)),u=ki(n,this.locale),g=Zi(r);if(bm(a),ym(l),function(e,t,o){vm(o),Fi((()=>e>=0),Uo("The start_period (%s) must be greater or equal than 0.",e.toString())),Fi((()=>t>=0),Uo("The end_period (%s) must be greater or equal than 0.",t.toString())),Fi((()=>e<=t),Uo("The start_period (%s) must be smaller or equal to the end_period (%s).",e.toString(),t.toString())),Fi((()=>t<=o),Uo("The end_period (%s) must be smaller or equal to the life (%s).",e.toString(),o.toString()))}(h,d,c),Rm(u),0===a)return 0;if(l>=a)return h<1?a-l:0;const p=u/c;if(p>=1)return h<1?a-l:0;let m=a,f=0,v=0,b=!1;for(let e=0;e<d;e++){if(!b||g){const t=m*p,o=(m-l)/(c-e);!g&&o>t?(b=!0,f=o):f=t}const t=Math.max(m-f,l);e>=h&&(v+=m-t),m=t}return v},isExported:!0},Mf={description:Uo("Internal rate of return given non-periodic cash flows."),args:[od("cashflow_amounts (range<number>)",Uo("An range containing the income or payments associated with the investment.")),od("cashflow_dates (range<number>)",Uo("An range with dates corresponding to the cash flows in cashflow_amounts.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the internal rate of return will be."))],compute:function(e,t,o={value:wf}){const s=ki(o,this.locale),i=e.flat().map((e=>ki(e,this.locale))),n=t.flat().map((e=>ki(e,this.locale)));var r;Dm(e,t),r=i,Fi((()=>r.some((e=>e>0))&&r.some((e=>e<0))),Uo("There must be both positive and negative values in cashflow_amounts.")),Om(n),_m(s);const a=new Map;for(const e of je(0,n.length)){const t=n[e];a.has(t)?a.set(t,a.get(t)+i[e]):a.set(t,i[e])}const l=Array.from(a.keys()),c=l.map((e=>a.get(e)));return Mm((e=>{let t=c[0];for(const o of je(1,c.length)){const s=(l[0]-l[o])/365;t+=c[o]*(1+e)**s}return t}),(e=>{let t=0;for(const o of je(1,c.length)){const s=(l[0]-l[o])/365;t+=s*c[o]*(1+e)**(s-1)}return t}),s,40,1e-5,(e=>e?e/10-.9:-.9))},isExported:!0},Pf={description:Uo("Net present value given to non-periodic cash flows.."),args:[od("discount (number)",Uo("The discount rate of the investment over one period.")),od("cashflow_amounts (number, range<number>)",Uo("An range containing the income or payments associated with the investment.")),od("cashflow_dates (number, range<number>)",Uo("An range with dates corresponding to the cash flows in cashflow_amounts."))],compute:function(e,t,o){const s=ki(e,this.locale),i=bi(t)?t.flat().map((e=>Hi(e,this.locale))):[Hi(t,this.locale)],n=bi(o)?o.flat().map((e=>Hi(e,this.locale))):[Hi(o,this.locale)];if(bi(o)&&bi(t)?Dm(t,o):Fi((()=>i.length===n.length),Uo("There must be the same number of values in cashflow_amounts and cashflow_dates.")),Om(n),fm(s),1===i.length)return i[0];const r=new Map;for(const e of je(0,n.length)){const t=n[e];r.has(t)?r.set(t,r.get(t)+i[e]):r.set(t,i[e])}const a=Array.from(r.keys()),l=a.map((e=>r.get(e)));let c=l[0];for(const e of je(1,l.length)){const t=(a[0]-a[e])/365;c+=l[e]*(1+s)**t}return c},isExported:!0},Nf={description:Uo("Annual yield of a security paying periodic interest."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=Math.trunc(ki(e,this.locale)),l=Math.trunc(ki(t,this.locale)),c=ki(o,this.locale),h=ki(s,this.locale),d=ki(i,this.locale),u=Math.trunc(ki(n,this.locale)),g=Math.trunc(ki(r,this.locale));cm(a,l),dm(u),um(g),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),pm(h),gm(d);const p=Ws(a,l,g)*u,m=Math.ceil(p),f=p-Math.floor(p)||1,v=100*c/u;if(1===m){const e=h+v*(1-f);return(d+v-e)*u*(1/f)/e}const b=Mm((function(e){return function(e,t,o,s,i,n){let r=n-(e+i*(1-t))*s**(o-1+t);for(let e=1;e<=o;e++)r+=i*s**(e-1);return r}(h,f,m,e,v,d)}),(function(e){return function(e,t,o,s,i){let n=-(e+i*(1-t))*(o-1+t)*s**(o-2+t);for(let e=1;e<=o;e++)n+=i*(e-1)*s**(e-2);return n}(h,f,m,e,v)}),1+(c+1)/u,100,1e-5);return(b-1)*u},isExported:!0},kf={description:Uo("Annual yield of a discount security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),pm(a),gm(l);return(l/a-1)/Ws(n,r,c)},isExported:!0},Vf={description:Uo("Annual yield of a security paying interest at maturity."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("issue (date)",Uo("The date the security was initially issued.")),od("rate (number)",Uo("The annualized rate of interest.")),od("price (number)",Uo("The price at which the security is bought.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){n=n||0;const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=Math.trunc(ki(o,this.locale)),c=ki(s,this.locale),h=ki(i,this.locale),d=Math.trunc(ki(n,this.locale));cm(r,a),um(d),Fi((()=>r>=l),Uo("The settlement (%s) must be greater than or equal to the issue (%s).",r.toString(),l.toString())),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),pm(h);const u=Ws(l,a,d),g=Ws(l,r,d),p=Ws(r,a,d);return(100*(1+c*u)/(h+100*c*g)-1)/p},isExported:!0};var Lf,Hf=Object.freeze({__proto__:null,ACCRINTM:Pm,AMORLINC:Nm,COUPDAYBS:Vm,COUPDAYS:km,COUPDAYSNC:Lm,COUPNCD:Hm,COUPNUM:Um,COUPPCD:Bm,CUMIPMT:zm,CUMPRINC:$m,DB:Gm,DDB:qm,DISC:Zm,DOLLARDE:jm,DOLLARFR:Ym,DURATION:Xm,EFFECT:Km,FV:Qm,FVSCHEDULE:ef,INTRATE:tf,IPMT:sf,IRR:nf,ISPMT:rf,MDURATION:af,MIRR:lf,NOMINAL:cf,NPER:hf,NPV:uf,PDURATION:gf,PMT:mf,PPMT:vf,PRICE:Sf,PRICEDISC:yf,PRICEMAT:Cf,PV:bf,RATE:xf,RECEIVED:If,RRI:Ef,SLN:Rf,SYD:Tf,TBILLEQ:Df,TBILLPRICE:_f,TBILLYIELD:Of,VDB:Ff,XIRR:Mf,XNPV:Pf,YIELD:Nf,YIELDDISC:kf,YIELDMAT:Vf});!function(e){e[e.LeftRef=0]="LeftRef",e[e.RightRef=1]="RightRef",e[e.Separator=2]="Separator",e[e.FullColumnSeparator=3]="FullColumnSeparator",e[e.FullRowSeparator=4]="FullRowSeparator",e[e.RightColumnRef=5]="RightColumnRef",e[e.RightRowRef=6]="RightRowRef",e[e.Found=7]="Found"}(Lf||(Lf={}));const Uf=(e,t=(()=>!0))=>[{goTo:e,guard:t}],Bf=(e,t=(()=>!0))=>({goTo:e,guard:t}),zf={[Lf.LeftRef]:{REFERENCE:Uf(Lf.Separator),NUMBER:Uf(Lf.FullRowSeparator),SYMBOL:[Bf(Lf.FullColumnSeparator,(e=>{return t=e.value,Hr.test(t);var t})),Bf(Lf.FullRowSeparator,(e=>zr(e.value)))]},[Lf.FullColumnSeparator]:{SPACE:Uf(Lf.FullColumnSeparator),OPERATOR:Uf(Lf.RightColumnRef,(e=>":"===e.value))},[Lf.FullRowSeparator]:{SPACE:Uf(Lf.FullRowSeparator),OPERATOR:Uf(Lf.RightRowRef,(e=>":"===e.value))},[Lf.Separator]:{SPACE:Uf(Lf.Separator),OPERATOR:Uf(Lf.RightRef,(e=>":"===e.value))},[Lf.RightRef]:{SPACE:Uf(Lf.RightRef),NUMBER:Uf(Lf.Found),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value))),SYMBOL:Uf(Lf.Found,(e=>$r(e.value)||Gr(e.value)))},[Lf.RightColumnRef]:{SPACE:Uf(Lf.RightColumnRef),SYMBOL:Uf(Lf.Found,(e=>$r(e.value))),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value)))},[Lf.RightRowRef]:{SPACE:Uf(Lf.RightRowRef),NUMBER:Uf(Lf.Found),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value))),SYMBOL:Uf(Lf.Found,(e=>Gr(e.value)))},[Lf.Found]:{}};function $f(e){let t=0,o=zf[Lf.LeftRef],s="";for(;void 0!==o;){const i=e[t++];if(!i)return null;const n=o[i.type]?.find((e=>e.guard(i))),r=n?n.goTo:void 0;switch(r){case void 0:return null;case Lf.Found:return s+=i.value,e.splice(0,t),{type:"REFERENCE",value:s};default:o=zf[r],s+=i.value}}return null}function Gf(e,t=fi){const o=Pa(e,t),s=[];for(;o.length;)s.push($f(o)||o.shift());return s}const Wf=/[a-zA-Z0-9\_]+(\.[a-zA-Z0-9\_]+)*/,qf=["-","+"],Zf=["%"],jf=["*","+","&"],Yf={"^":30,"%":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10};function Xf(e){const t=e.shift();if(!t)throw new Ei;switch(t.type){case"DEBUGGER":const o=Qf(e,1e3);return o.debug=!0,o;case"NUMBER":return{type:"NUMBER",value:ei(t.value,fi)};case"STRING":return{type:"STRING",value:Ue(t.value)};case"INVALID_REFERENCE":return{type:"REFERENCE",value:wi.InvalidReference};case"REFERENCE":if(":"===e[0]?.value&&"REFERENCE"===e[1]?.type){e.shift();const o=e.shift();return{type:"REFERENCE",value:`${t.value}:${o?.value}`}}return{type:"REFERENCE",value:t.value};case"SYMBOL":const s=t.value,i=e[0];if("LEFT_PAREN"===i?.type&&Wf.test(t.value)&&s===Ge(s,"'")){const t=function(e){Jf(e,"LEFT_PAREN",Uo("Missing opening parenthesis"));const t=e[0];if("RIGHT_PAREN"===t?.type)return Jf(e,"RIGHT_PAREN"),[];const o=[];o.push(Kf(e));for(;"RIGHT_PAREN"!==e[0]?.type;)Jf(e,"ARG_SEPARATOR",Uo("Wrong function call")),o.push(Kf(e));return Jf(e,"RIGHT_PAREN"),o}(e);return{type:"FUNCALL",value:s,args:t}}const n=s.toUpperCase();return"TRUE"===n||"FALSE"===n?{type:"BOOLEAN",value:"TRUE"===n}:{type:"SYMBOL",value:Ge(t.value,"'")};case"LEFT_PAREN":const r=Qf(e);return Jf(e,"RIGHT_PAREN",Uo("Missing closing parenthesis")),r;case"OPERATOR":const a=t.value;if(qf.includes(a))return{type:"UNARY_OPERATION",value:a,operand:Qf(e,Yf[a])};throw new Ei(Uo("Unexpected token: %s",t.value));default:throw new Ei(Uo("Unexpected token: %s",t.value))}}function Kf(e){const t=e[0];return"ARG_SEPARATOR"===t?.type||"RIGHT_PAREN"===t?.type?{type:"EMPTY",value:""}:Qf(e)}function Jf(e,t,o){const s=e.shift();if(!s||s.type!==t)throw new Ei(o)}function Qf(e,t=0){if(0===e.length)throw new Ei;let o=Xf(e);for(;"OPERATOR"===e[0]?.type&&Yf[e[0].value]>t;){const t=e.shift().value;if(Zf.includes(t))o={type:"UNARY_OPERATION",value:t,operand:o,postfix:!0};else{o={type:"BIN_OPERATION",value:t,left:o,right:Qf(e,Yf[t])}}}return o}function ev(e){return tv(Gf(e))}function tv(e){e=e.filter((e=>"SPACE"!==e.type)),"="===e[0]?.value&&e.splice(0,1);const t=Qf(e);if(e.length)throw new Ei;return t}function ov(e,t,o){return nv(e,(e=>e.type===t?o(e):e))}function sv(e){return Array.from(iv(e))}function*iv(e){switch(yield e,e.type){case"FUNCALL":for(const t of e.args)yield*iv(t);break;case"UNARY_OPERATION":yield*iv(e.operand);break;case"BIN_OPERATION":yield*iv(e.left),yield*iv(e.right)}}function nv(e,t){switch((e=t(e)).type){case"FUNCALL":return{...e,args:e.args.map((e=>nv(e,t)))};case"UNARY_OPERATION":return{...e,operand:nv(e.operand,t)};case"BIN_OPERATION":return{...e,right:nv(e.right,t),left:nv(e.left,t)};default:return e}}function rv(e){switch(e.type){case"FUNCALL":const t=e.args.map((e=>rv(e)));return`${e.value}(${t.join(",")})`;case"NUMBER":return e.value.toString();case"REFERENCE":default:return e.value;case"STRING":return`"${e.value}"`;case"BOOLEAN":return e.value?"TRUE":"FALSE";case"UNARY_OPERATION":return e.postfix?av(e)+e.value:e.value+lv(e);case"BIN_OPERATION":return av(e)+e.value+lv(e)}}function av(e){const t=e.value,o="left"in e?e.left:e.operand,s=o.value;return"BIN_OPERATION"===o.type&&Yf[s]<Yf[t]?`(${rv(o)})`:rv(o)}function lv(e){const t=e.value,o="right"in e?e.right:e.operand,s=Yf[o.value],i=Yf[t];let n=!1;return"BIN_OPERATION"!==o.type?n=!1:s<i?n=!0:s!==i||jf.includes(t)||(n=!0),n?`(${rv(o)})`:rv(o)}function cv(e,t){return function(e){for(const t of e)if(t.functionContext){const{argsTokens:e,args:o}=t.functionContext;if(delete t.functionContext.argsTokens,o.length||!e)continue;"LEFT_PAREN"===e[0]?.[0]?.type&&(e[0]=e[0].slice(1));for(const t of e){let e=t;"ARG_SEPARATOR"===e.at(-1)?.type&&(e=e.slice(0,-1));try{o.push(tv(e))}catch(e){o.push(void 0)}}}return e}(function(e){let t=[],o="";function s(e){if(0===t.length)return;const o=t.at(-1);if(o&&o.argsTokens){const{argsTokens:t,argPosition:s}=o;t[s]||(t[s]=[]),t[s].push({value:e.value,type:e.type})}}return e.map(((e,i)=>{switch(["SPACE","LEFT_PAREN"].includes(e.type)||(o=""),e.type){case"SYMBOL":s(e),o=e.value;break;case"LEFT_PAREN":t.push({parent:o,argPosition:0,argsTokens:[],args:[]}),s(e),o="";break;case"RIGHT_PAREN":const i=t.pop();i?.argsTokens?.flat().forEach(s),s(e);break;case"ARG_SEPARATOR":s(e),t.length&&t[t.length-1].argPosition++;break;default:s(e)}if(t.length){const o=t[t.length-1];o.parent&&(e.functionContext=Object.assign({},o))}return e}))}(function(e){let t=[],o=0;return e.map(((s,i)=>{if("LEFT_PAREN"===s.type){t.push(o+1),o=0;for(let o=i-1;o>=0;o--){if("SPACE"!==e[o].type){"SYMBOL"===e[o].type&&(e[o].parenthesesCode=t.join(":"));break}e[o].parenthesesCode=t.join(":")}}return s.parenthesesCode=t.join(":"),"RIGHT_PAREN"===s.type&&t.length&&(o=t.pop()),s}))}(function(e){let t=0;return e.map((e=>{const o=e.value.toString().length,s=Object.assign({},e,{start:t,end:t+o,length:o});return t=s.end,s}))}(Gf(e,t)))))}function hv(e){if("REFERENCE"!==e.type)return e;const{xc:t,sheetName:o}=qr(e.value),[s,i]=t.split(":"),n=dv(s),r=i?`:${dv(i)}`:"";return{...e,value:Zr(o,n+r)}}function dv(e){switch(function(e){if(function(e){return e.startsWith("$")&&e.length>1&&e.slice(1).includes("$")}(e))return"colrow";if(function(e){return e.startsWith("$")}(e))return"col";if(function(e){return e.includes("$",1)}(e))return"row";return"none"}(e)){case"none":e=uv(e,"colrow");break;case"colrow":e=uv(e,"row");break;case"row":e=uv(e,"col");break;case"col":e=uv(e,"none")}return e}function uv(e,t){if(e.includes("!"))throw new Error("The given XC should not contain a sheet name");let o;switch(e=e.replace(/\$/g,""),t){case"col":return"$"+e;case"row":return o=e.search(/[0-9]/),e.slice(0,o)+"$"+e.slice(o);case"colrow":return o=e.search(/[0-9]/),-1===o||0===o?"$"+e:"$"+(e=e.slice(0,o)+"$"+e.slice(o));case"none":return e}}function gv(e,t,o){const s=(t.startsWith("=")?cv(t,o):[]).filter((t=>t.start<=e.start&&t.end>=e.start||t.start>=e.start&&t.start<e.end)),i=s.filter((e=>"REFERENCE"===e.type));if(0===i.length)return;const n=s.map(hv).map((e=>e.value)).join(""),r=s[0].start,a=s[s.length-1].end,l=t.slice(0,r)+n+t.slice(a),c=l.length-t.length,h={start:i[0].start,end:i[i.length-1].end+c};return 1===i.length&&e.start===e.end&&(h.start=h.end),{content:l,selection:h}}const pv=["address","col","contents","format","row","type"],mv={description:Uo("Gets information about a cell."),args:[od("info_type (string)",Uo("The type of information requested. Can be one of %s",pv.join(", "))),od("reference (meta)",Uo("The reference to the cell."))],compute:function(e,t){const o=Gi(e).toLowerCase();Fi((()=>pv.includes(o)),Uo("The info_type should be one of %s.",pv.join(", ")));const s=this.__originSheetId,i=Gi(t),n=i.includes(":")?i.split(":")[0]:i;let{sheetName:r,xc:a}=qr(n);r=r===this.getters.getSheetName(s)?void 0:r;const l=Zr(r,uv(a,"colrow")),c=this.getters.getRangeFromSheetXC(s,l);switch(o){case"address":return this.getters.getRangeString(c,s);case"col":return c.zone.left+1;case"contents":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top};return this.getters.getEvaluatedCell(e).value}case"format":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top};return this.getters.getEvaluatedCell(e).format||""}case"row":return c.zone.top+1;case"type":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top},t=this.getters.getEvaluatedCell(e).type;return t===oi.empty?"b":t===oi.text?"l":"v"}}return""},isExported:!0},fv={description:Uo("Whether a value is an error other than #N/A."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){const t=e?.value;return Pi(t)&&t!==wi.NotAvailable},isExported:!0},vv={description:Uo("Whether a value is an error."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){const t=e?.value;return Pi(t)},isExported:!0},bv={description:Uo("Whether a value is `true` or `false`."),args:[od("value (any)",Uo("The value to be verified as a logical TRUE or FALSE."))],compute:function(e){return"boolean"==typeof e?.value},isExported:!0},Sv={description:Uo("Whether a value is the error #N/A."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){return e?.value===wi.NotAvailable},isExported:!0},yv={description:Uo("Whether a value is non-textual."),args:[od("value (any)",Uo("The value to be checked."))],compute:function(e){return!wv.compute.bind(this)(e)},isExported:!0},Cv={description:Uo("Whether a value is a number."),args:[od("value (any)",Uo("The value to be verified as a number."))],compute:function(e){return"number"==typeof e?.value},isExported:!0},wv={description:Uo("Whether a value is text."),args:[od("value (any)",Uo("The value to be verified as text."))],compute:function(e){return"string"==typeof e?.value&&!1===Pi(e?.value)},isExported:!0},xv={description:Uo("Whether the referenced cell is empty"),args:[od("value (any)",Uo("Reference to the cell that will be checked for emptiness."))],compute:function(e){return null===e?.value},isExported:!0},Iv={description:Uo("Returns the error value #N/A."),args:[],compute:function(){return{value:wi.NotAvailable}},isExported:!0};var Ev=Object.freeze({__proto__:null,CELL:mv,ISBLANK:xv,ISERR:fv,ISERROR:vv,ISLOGICAL:bv,ISNA:Sv,ISNONTEXT:yv,ISNUMBER:Cv,ISTEXT:wv,NA:Iv});const Rv={description:Uo("Logical `and` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that represent logical values."))],compute:function(...e){const{result:t,foundBoolean:o}=dl(e);return Fi((()=>o),Uo("[[FUNCTION_NAME]] has no valid input data.")),t},isExported:!0},Tv={description:Uo("Logical value `false`."),args:[],compute:function(){return!1},isExported:!0},Av={description:Uo("Returns value depending on logical expression."),args:[od("logical_expression (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE.")),od("value_if_true (any, range)",Uo("The value the function returns if logical_expression is TRUE.")),od("value_if_false (any, range, default=FALSE)",Uo("The value the function returns if logical_expression is FALSE."))],compute:function(e,t,o){if(Cl(e))return an(Av.compute,[e,t,o]);let s=Zi(Sl(e))?t:o;return Cl(s)||(s=Sl(s)),void 0===s?{value:""}:bi(s)||null!==s.value?s:{...s,value:""}},isExported:!0},_v={description:Uo("Value if it is not an error, otherwise 2nd argument."),args:[od("value (any, range)",Uo("The value to return if value itself is not an error.")),od('value_if_error (any, range, default="empty")',Uo("The value the function returns if value is an error."))],compute:function(e,t){if(Cl(e))return an(_v.compute,[e,t]);let o=Pi(Sl(e)?.value)?t:e;return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}},isExported:!0},Dv={description:Uo("Value if it is not an #N/A error, otherwise 2nd argument."),args:[od("value (any, range)",Uo("The value to return if value itself is not #N/A an error.")),od('value_if_error (any, range, default="empty")',Uo("The value the function returns if value is an #N/A error."))],compute:function(e,t){if(Cl(e))return an(Dv.compute,[e,t]);let o=Sl(e)?.value===wi.NotAvailable?t:e;return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}},isExported:!0},Ov={description:Uo("Returns a value depending on multiple logical expressions."),args:[od("condition1 (boolean, range<boolean>)",Uo("The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those.")),od("value1 (any, range)",Uo("The returned value if condition1 is TRUE.")),od("condition2 (boolean, any, range, repeating)",Uo("Additional conditions to be evaluated if the previous ones are FALSE.")),od("value2 (any, range, repeating)",Uo("Additional values to be returned if their corresponding conditions are TRUE."))],compute:function(...e){for(Fi((()=>e.length%2==0),Uo("Wrong number of arguments. Expected an even number of arguments."));e.length>0;){if(Cl(e[0]))return an(Ov.compute,e);const t=Zi(Sl(e.shift()));let o=e.shift();if(t)return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}}return new Ii(Uo("No match."))},isExported:!0},Fv={description:Uo("Returns opposite of provided logical value."),args:[od("logical_expression (boolean)",Uo("An expression or reference to a cell holding an expression that represents some logical value."))],compute:function(e){return!Zi(e)},isExported:!0},Mv={description:Uo("Logical `or` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that evaluate to logical values."))],compute:function(...e){const{result:t,foundBoolean:o}=ul(e);return Fi((()=>o),Uo("[[FUNCTION_NAME]] has no valid input data.")),t},isExported:!0},Pv={description:Uo("Logical value `true`."),args:[],compute:function(){return!0},isExported:!0},Nv={description:Uo("Logical `xor` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that evaluate to logical values."))],compute:function(...e){let t=!1,o=!1;return ln(e,(e=>(t=!0,o=o?!e:e,!0))),Fi((()=>t),Uo("[[FUNCTION_NAME]] has no valid input data.")),o},isExported:!0};var kv=Object.freeze({__proto__:null,AND:Rv,FALSE:Tv,IF:Av,IFERROR:_v,IFNA:Dv,IFS:Ov,NOT:Fv,OR:Mv,TRUE:Pv,XOR:Nv});function Vv(e,t){const o=t.getPivotId(e);if(!o)throw new Ii(Uo('There is no pivot with id "%s"',e));return o}function Lv(e){if(e.length%2!=0)throw new Ii(Uo("Function PIVOT takes an even number of arguments."))}function Hv(e,t,o){const s=[];if("SPREADSHEET"===t.type&&t.dataSet){const{sheetId:o,zone:i}=t.dataSet,n=qo(i),r=e.getters.getRangeFromSheetXC(o,n);if(void 0===r||r.invalidXc||r.invalidSheetName)throw new Ti;if(e.__originCellPosition&&r.sheetId===e.__originSheetId&&os(hs(e.__originCellPosition),i))throw new Ri;s.push(r)}for(const t of o)if(t.computedBy){const o=e.getters.getMeasureCompiledFormula(t);s.push(...o.dependencies.filter((e=>!e.invalidXc)))}const i=e.__originCellPosition;i&&s.length&&(e.updateDependencies?.(i),e.addDependencies?.(i,s))}const Uv=!0;function Bv(e){return{value:wi.NotAvailable,message:Uo("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",Gi(e))}}const zv={description:Uo("Returns a cell reference as a string. "),args:[od("row (number)",Uo("The row number of the cell reference. ")),od("column (number)",Uo("The column number (not name) of the cell reference. A is column number 1. ")),od("absolute_relative_mode (number, default=1)",Uo("An indicator of whether the reference is row/column absolute. 1 is row and column absolute (e.g. $A$1), 2 is row absolute and column relative (e.g. A$1), 3 is row relative and column absolute (e.g. $A1), and 4 is row and column relative (e.g. A1).")),od("use_a1_notation (boolean, default=TRUE)",Uo("A boolean indicating whether to use A1 style notation (TRUE) or R1C1 style notation (FALSE).")),od("sheet (string, optional)",Uo("A string indicating the name of the sheet into which the address points."))],compute:function(e,t,o={value:1},s={value:!0},i){const n=Bi(e,this.locale),r=Bi(t,this.locale);zi(n),zi(r);const a=Bi(o,this.locale);var l,c;Fi((()=>[1,2,3,4].includes(a)),(l=4,c=a,Uo("The function [[FUNCTION_NAME]] expects a number value between %s and %s inclusive, but receives %s.",1..toString(),l.toString(),c.toString())));let h;if(Zi(s)){h=Ao(r-1,n-1,{rowFixed:[1,2].includes(a),colFixed:[1,3].includes(a)})}else{h=([1,2].includes(a)?`R${n}`:`R[${n}]`)+([1,3].includes(a)?`C${r}`:`C[${r}]`)}return void 0!==i?Zr(Gi(i),h):h},isExported:!0},$v={description:Uo("Column number of a specified cell."),args:[od("cell_reference (meta, default='this cell')",Uo("The cell whose column number will be returned. Column A corresponds to 1. By default, the function use the cell in which the formula is entered."))],compute:function(e){if(Pi(e?.value))return e;const t=void 0===e?this.__originCellPosition?.col:$o(e.value).left;return Fi((()=>void 0!==t),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter."),t+1},isExported:!0},Gv={description:Uo("Number of columns in a specified array or range."),args:[od("range (meta)",Uo("The range whose column count will be returned."))],compute:function(e){if(Pi(e?.value))return e;const t=$o(e.value);return t.right-t.left+1},isExported:!0},Wv={description:Uo("Horizontal lookup"),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The range to consider for the search. The first row in the range is searched for the key specified in search_key.")),od("index (number)",Uo("The row index of the value to be returned, where the first row in range is numbered 1.")),od("is_sorted (boolean, default=true)",Uo("Indicates whether the row to be searched (the first row of the specified range) is sorted, in which case the closest match for search_key will be returned."))],compute:function(e,t,o,s={value:Uv}){const i=Math.trunc(ki(o?.value,this.locale)),n=vn(t);Fi((()=>1<=i&&i<=n[0].length),Uo("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const r=(e,t)=>e[t][0].value,a=Zi(s.value)?gn(n,e,"nextSmaller","asc",n.length,r):pn(n,e,"wildcard",n.length,r,this.lookupCaches),l=n[a];return void 0===l?Bv(e):l[i-1]},isExported:!0},qv={description:Uo("Returns the content of a cell, specified by row and column offset."),args:[od("reference (any, range)",Uo("The range of cells from which the values are returned.")),od("row (number, default=0)",Uo("The index of the row to be returned from within the reference range of cells.")),od("column (number, default=0)",Uo("The index of the column to be returned from within the reference range of cells."))],compute:function(e,t={value:0},o={value:0}){const s=vn(e),i=ki(t.value,this.locale),n=ki(o.value,this.locale);return Fi((()=>n>=0&&n-1<s.length&&i>=0&&i-1<s[0].length),Uo("Index out of range.")),0===i&&0===n?s:0===i?[s[n-1]]:0===n?s.map((e=>[e[i-1]])):s[n-1][i-1]},isExported:!0},Zv={description:Uo("Returns the content of a cell, specified by a string."),args:[od("reference (string)",Uo("The range of cells from which the values are returned.")),od("use_a1_notation (boolean, default=TRUE)",Uo("A boolean indicating whether to use A1 style notation (TRUE) or R1C1 style notation (FALSE)."))],compute:function(e,t={value:!0}){let o=e?.value?.toString();if(!o)return new Ti(Uo("Reference should be defined."));if(!Zi(t))return new Ii(Uo("R1C1 notation is not supported."));const s=this.__originSheetId,i=this.__originCellPosition;i&&this.updateDependencies?.(i);const n=this.getters.getRangeFromSheetXC(s,o);if(void 0===n||n.invalidXc||n.invalidSheetName)return new Ti;i&&this.addDependencies?.(i,[n]);const r=[];for(let e=n.zone.left;e<=n.zone.right;e++){const t=[];for(let o=n.zone.top;o<=n.zone.bottom;o++){const s={sheetId:n.sheetId,col:e,row:o};t.push(this.getters.getEvaluatedCell(s))}r.push(t)}return 1===r.length&&1===r[0].length?r[0][0]:r},isExported:!0},jv={description:Uo("Look up a value."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("search_array (any, range)",Uo("One method of using this function is to provide a single sorted row or column search_array to look through for the search_key with a second argument result_range. The other way is to combine these two arguments into one search_array where the first row or column is searched and a value is returned from the last row or column in the array. If search_key is not found, a non-exact match may be returned.")),od("result_range (any, range, optional)",Uo("The range from which to return a result. The value returned corresponds to the location where search_key is found in search_range. This range must be only a single row or column and should not be used if using the search_result_array method."))],compute:function(e,t,o){const s=vn(t),i=vn(o);let n=s.length,r=s[0].length;const a=r>=n,l=a?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,c=gn(s,e,"nextSmaller","asc",a?r:n,l);return-1===c||a&&void 0===s[0][c]||!a&&void 0===s[c][r-1]?Bv(e):0===i[0].length?a?s[n-1][c]:s[c][r-1]:(n=i.length,r=i[0].length,Fi((()=>1===n||1===r),Uo("The result_range must be a single row or a single column.")),n>1?(Fi((()=>c<=n-1),Uo("[[FUNCTION_NAME]] evaluates to an out of range row value %s.",(c+1).toString())),i[c][0]):(Fi((()=>c<=r-1),Uo("[[FUNCTION_NAME]] evaluates to an out of range column value %s.",(c+1).toString())),i[0][c]))},isExported:!0},Yv={description:Uo("Position of item in range that matches value."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The one-dimensional array to be searched.")),od("search_type (number, default=1)",Uo("The search method. 1 (default) finds the largest value less than or equal to search_key when range is sorted in ascending order. 0 finds the exact value when range is unsorted. -1 finds the smallest value greater than or equal to search_key when range is sorted in descending order."))],compute:function(e,t,o={value:1}){let s=ki(o,this.locale);const i=vn(t),n=i.length,r=i[0].length;Fi((()=>1===n||1===r),Uo("The range must be a single row or a single column."));let a=-1;const l=1===n?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,c=1===n?i[0].length:i.length;switch(s=Math.sign(s),s){case 1:a=gn(i,e,"nextSmaller","asc",c,l);break;case 0:a=pn(i,e,"wildcard",c,l,this.lookupCaches);break;case-1:a=gn(i,e,"nextGreater","desc",c,l)}return 1===n&&void 0===i[0][a]||1!==n&&void 0===i[a]?Bv(e):a+1},isExported:!0},Xv={description:Uo("Row number of a specified cell."),args:[od("cell_reference (meta, default='this cell')",Uo("The cell whose row number will be returned. By default, this function uses the cell in which the formula is entered."))],compute:function(e){if(Pi(e?.value))return e;const t=void 0===e?this.__originCellPosition?.row:$o(e.value).top;return Fi((()=>void 0!==t),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter."),t+1},isExported:!0},Kv={description:Uo("Number of rows in a specified array or range."),args:[od("range (meta)",Uo("The range whose row count will be returned."))],compute:function(e){if(Pi(e?.value))return e;const t=$o(e.value);return t.bottom-t.top+1},isExported:!0},Jv={description:Uo("Vertical lookup."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The range to consider for the search. The first column in the range is searched for the key specified in search_key.")),od("index (number)",Uo("The column index of the value to be returned, where the first column in range is numbered 1.")),od("is_sorted (boolean, default=true)",Uo("Indicates whether the column to be searched (the first column of the specified range) is sorted, in which case the closest match for search_key will be returned."))],compute:function(e,t,o,s={value:Uv}){const i=Math.trunc(ki(o?.value,this.locale)),n=vn(t);Fi((()=>1<=i&&i<=n.length),Uo("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const r=(e,t)=>e[0][t].value,a=Zi(s.value)?gn(n,e,"nextSmaller","asc",n[0].length,r):pn(n,e,"wildcard",n[0].length,r,this.lookupCaches),l=n[i-1][a];return void 0===l?Bv(e):l},isExported:!0},Qv={0:"strict",1:"nextGreater","-1":"nextSmaller",2:"wildcard"},eb={description:Uo("Search a range for a match and return the corresponding item from a second range."),args:[od("search_key (string,number,boolean)",Uo("The value to search for.")),od("lookup_range (any, range)",Uo("The range to consider for the search. Should be a single column or a single row.")),od("return_range (any, range)",Uo("The range containing the return value. Should have the same dimensions as lookup_range.")),od("if_not_found (any, optional)",Uo("If a valid match is not found, return this value.")),od("match_mode (any, default=0)",Uo("(0) Exact match. (-1) Return next smaller item if no match. (1) Return next greater item if no match. (2) Wildcard match.")),od("search_mode (any, default=1)",Uo("(1) Search starting at first item. (-1) Search starting at last item. (2) Perform a binary search that relies on lookup_array being sorted in ascending order. If not sorted, invalid results will be returned. (-2) Perform a binary search that relies on lookup_array being sorted in descending order. If not sorted, invalid results will be returned. "))],compute:function(e,t,o,s,i={value:0},n={value:1}){const r=Math.trunc(ki(i.value,this.locale)),a=Math.trunc(ki(n.value,this.locale)),l=vn(t),c=vn(o);Fi((()=>1===l.length||1===l[0].length),Uo("lookup_range should be either a single row or single column.")),Fi((()=>[-1,1,-2,2].includes(a)),Uo("search_mode should be a value in [-1, 1, -2, 2].")),Fi((()=>[-1,0,1,2].includes(r)),Uo("match_mode should be a value in [-1, 0, 1, 2]."));const h=1===l.length?"col":"row";Fi((()=>!(2===r&&[-2,2].includes(a))),Uo("the search and match mode combination is not supported for XLOOKUP evaluation.")),Fi((()=>"col"===h?c[0].length===l[0].length:c.length===l.length),Uo("return_range should have the same dimensions as lookup_range."));const d="col"===h?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,u="col"===h?l[0].length:l.length,g=Qv[r],p=-1===a,m=2===a||-2===a?gn(l,e,g,2===a?"asc":"desc",u,d):pn(l,e,g,u,d,this.lookupCaches,p);return-1!==m?"col"===h?c.map((e=>[e[m]])):[c[m]]:void 0===s?Bv(e):[[s]]},isExported:!0},tb={description:Uo("Get the value from a pivot."),args:[od("pivot_id (number,string)",Uo("ID of the pivot.")),od("measure_name (string)",Uo("Name of the measure.")),od("domain_field_name (string,optional,repeating)",Uo("Field name.")),od("domain_value (number,string,boolean,optional,repeating)",Uo("Value."))],compute:function(e,t,...o){const s=Gi(e),i=Gi(t),n=Vv(s,this.getters);!function(e,t,o){const{measures:s}=o.getPivotCoreDefinition(e);if(!s.find((e=>e.id===t))){const e=`(${s.map((e=>e.id)).join(", ")})`;throw new Ii(Uo("The argument %s is not a valid measure. Here are the measures: %s",t,e))}}(n,i,this.getters),Lv(o);const r=this.getters.getPivot(n),a=this.getters.getPivotCoreDefinition(n);Hv(this,a,a.measures.filter((e=>e.id===i))),r.init({reload:r.needsReevaluation});const l=r.assertIsValid({throwOnError:!1});if(l)return l;if(!r.areDomainArgsFieldsValid(o)){const e=Uo("Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.",`=PIVOT(${s})`);return{value:wi.GenericError,message:Uo("Dimensions don't match the pivot definition")+". "+e}}const c=r.parseArgsToPivotDomain(o);return this.getters.getActiveSheetId()===this.__originSheetId&&this.getters.getPivotPresenceTracker(n)?.trackValue(i,c),r.getPivotCellValueAndFormat(i,c)}},ob={description:Uo("Get the header of a pivot."),args:[od("pivot_id (number,string)",Uo("ID of the pivot.")),od("domain_field_name (string,optional,repeating)",Uo("Field name.")),od("domain_value (number,string,value,optional,repeating)",Uo("Value."))],compute:function(e,...t){const o=Gi(e),s=Vv(o,this.getters);Lv(t);const i=this.getters.getPivot(s);Hv(this,this.getters.getPivotCoreDefinition(s),[]),i.init({reload:i.needsReevaluation});const n=i.assertIsValid({throwOnError:!1});if(n)return n;if(!i.areDomainArgsFieldsValid(t)){const e=Uo("Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.",`=PIVOT(${o})`);return{value:wi.GenericError,message:Uo("Dimensions don't match the pivot definition")+". "+e}}const r=i.parseArgsToPivotDomain(t);this.getters.getActiveSheetId()===this.__originSheetId&&this.getters.getPivotPresenceTracker(s)?.trackHeader(r);const a=r.at(-1);if("measure"===a?.field)return i.getPivotMeasureValue(Gi(a.value),r);const{value:l,format:c}=i.getPivotHeaderValueAndFormat(r);return{value:l,format:a&&"measure"!==a.field&&"false"!==a.value?c:void 0}}},sb={description:Uo("Get a pivot table."),args:[od("pivot_id (string)",Uo("ID of the pivot.")),od("row_count (number, optional)",Uo("number of rows")),od("include_total (boolean, default=TRUE)",Uo("Whether to include total/sub-totals or not.")),od("include_column_titles (boolean, default=TRUE)",Uo("Whether to include the column titles or not.")),od("column_count (number, optional)",Uo("number of columns"))],compute:function(e,t={value:1e4},o={value:!0},s={value:!0},i={value:Number.MAX_VALUE}){const n=Gi(e),r=ki(t,this.locale);if(r<0)return new Ii(Uo("The number of rows must be positive."));const a=ki(i,this.locale);if(a<0)return new Ii(Uo("The number of columns must be positive."));const l=Zi(s),c=Zi(o),h=Vv(n,this.getters),d=this.getters.getPivot(h),u=this.getters.getPivotCoreDefinition(h);Hv(this,u,u.measures),d.init({reload:d.needsReevaluation});const g=d.assertIsValid({throwOnError:!1});if(g)return g;const p=d.getTableStructure(),m=p.getPivotCells(c,l),f=l?p.columns.length:0,v=this.getters.getPivotDisplayName(h),b=Math.min(f+r,m[0].length);if(0===b)return[[{value:v}]];const S=Math.min(1+a,m.length),y=[];for(const e of je(0,S)){y[e]=[];for(const t of je(0,b)){const o=m[e][t];switch(o.type){case"EMPTY":y[e].push({value:""});break;case"HEADER":const t=d.getPivotHeaderValueAndFormat(o.domain);y[e].push(Dc(d,o.domain,t));break;case"MEASURE_HEADER":y[e].push(d.getPivotMeasureValue(o.measure,o.domain));break;case"VALUE":y[e].push(d.getPivotCellValueAndFormat(o.measure,o.domain))}}}return l&&(y[0][0]={value:v}),y}},ib={description:Uo("Returns a range reference shifted by a specified number of rows and columns from a starting cell reference."),args:[od("cell_reference (meta)",Uo("The starting point from which to count the offset rows and columns.")),od("offset_rows (number)",Uo("The number of rows to offset by.")),od("offset_columns (number)",Uo("The number of columns to offset by.")),od("height (number, default='height of cell_reference')",Uo("The number of rows of the range to return starting at the offset target.")),od("width (number, default='width of cell_reference')",Uo("The number of columns of the range to return starting at the offset target."))],compute:function(e,t,o,s,i){if(Pi(e?.value))return e;const n=e?.value;if(!n)return new Ii("In this context, the function OFFSET needs to have a cell or range in parameter.");const r=$o(n);let a=r.bottom-r.top+1,l=r.right-r.left+1;if(s){const e=ki(s,this.locale);rd(Uo("Height value is %(_height)s. It should be greater than or equal to 1.",{_height:e}),e),a=e}if(i){const e=ki(i,this.locale);rd(Uo("Width value is %(_width)s. It should be greater than or equal to 1.",{_width:e}),e),l=e}const{sheetName:c}=qr(n),h=c&&this.getters.getSheetIdByName(c)||this.getters.getActiveSheetId(),d=ki(t,this.locale),u=ki(o,this.locale),g=this.__originCellPosition;g&&this.updateDependencies?.(g);const p=r.left+u,m=r.top+d;if(p<0||m<0)return new Ti(Uo("OFFSET evaluates to an out of bounds range."));const f={left:p,top:m,right:p+l-1,bottom:m+a-1},v=this.getters.getRangeFromZone(this.__originSheetId,f);return v.invalidXc||v.invalidSheetName?new Ti:(g&&this.addDependencies?.(g,[v]),sn(l,a,((e,t)=>this.getters.getEvaluatedCell({sheetId:h,col:p+e,row:m+t}))))}};var nb=Object.freeze({__proto__:null,ADDRESS:zv,COLUMN:$v,COLUMNS:Gv,HLOOKUP:Wv,INDEX:qv,INDIRECT:Zv,LOOKUP:jv,MATCH:Yv,OFFSET:ib,PIVOT:sb,PIVOT_HEADER:ob,PIVOT_VALUE:tb,ROW:Xv,ROWS:Kv,VLOOKUP:Jv,XLOOKUP:eb});const rb={description:Uo("Sum of two numbers."),args:[od("value1 (number)",Uo("The first addend.")),od("value2 (number)",Uo("The second addend."))],compute:function(e,t){return{value:ki(e,this.locale)+ki(t,this.locale),format:e?.format||t?.format}}},ab={description:Uo("Concatenation of two values."),args:[od("value1 (string)",Uo("The value to which value2 will be appended.")),od("value2 (string)",Uo("The value to append to value1."))],compute:function(e,t){return Gi(e)+Gi(t)},isExported:!0},lb={description:Uo("One number divided by another."),args:[od("dividend (number)",Uo("The number to be divided.")),od("divisor (number)",Uo("The number to divide by."))],compute:function(e,t){const o=ki(t,this.locale);return Fi((()=>0!==o),Uo("The divisor must be different from zero."),wi.DivisionByZero),{value:ki(e,this.locale)/o,format:e?.format||t?.format}}};function cb(e){return void 0===e||null===e.value}const hb={number:0,string:"",boolean:!1};function db(e,t,o=2e-16){return Math.abs(e-t)<o}const ub={description:Uo("Equal."),args:[od("value1 (string, number, boolean)",Uo("The first value.")),od("value2 (string, number, boolean)",Uo("The value to test against value1 for equality."))],compute:function(e,t){if(Pi(e?.value))return e;if(Pi(t?.value))return t;let o=cb(e)?hb[typeof t?.value]:e?.value,s=cb(t)?hb[typeof e?.value]:t?.value;return"string"==typeof o&&(o=o.toUpperCase()),"string"==typeof s&&(s=s.toUpperCase()),"number"==typeof o&&"number"==typeof s?{value:db(o,s)}:{value:o===s}}};function gb(e,t,o){if(Pi(e?.value))return e;if(Pi(t?.value))return t;let s=cb(e)?hb[typeof t?.value]:e?.value,i=cb(t)?hb[typeof e?.value]:t?.value;"number"!=typeof s&&(s=Gi(s).toUpperCase()),"number"!=typeof i&&(i=Gi(i).toUpperCase());const n=typeof s,r=typeof i;return"string"===n&&"number"===r?{value:!0}:"string"===r&&"number"===n?{value:!1}:{value:o(s,i)}}const pb={description:Uo("Strictly greater than."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being greater than value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){return gb(e,t,((e,t)=>"number"==typeof e&&"number"==typeof t?!db(e,t)&&e>t:e>t))}},mb={description:Uo("Greater than or equal to."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being greater than or equal to value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){return gb(e,t,((e,t)=>"number"==typeof e&&"number"==typeof t?db(e,t)||e>t:e>=t))}},fb={description:Uo("Less than."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being less than value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){const o=mb.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},vb={description:Uo("Less than or equal to."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being less than or equal to value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){const o=pb.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},bb={description:Uo("Difference of two numbers."),args:[od("value1 (number)",Uo("The minuend, or number to be subtracted from.")),od("value2 (number)",Uo("The subtrahend, or number to subtract from value1."))],compute:function(e,t){return{value:ki(e,this.locale)-ki(t,this.locale),format:e?.format||t?.format}}},Sb={description:Uo("Product of two numbers"),args:[od("factor1 (number)",Uo("The first multiplicand.")),od("factor2 (number)",Uo("The second multiplicand."))],compute:function(e,t){return{value:ki(e,this.locale)*ki(t,this.locale),format:e?.format||t?.format}}},yb={description:Uo("Not equal."),args:[od("value1 (string, number, boolean)",Uo("The first value.")),od("value2 (string, number, boolean)",Uo("The value to test against value1 for inequality."))],compute:function(e,t){const o=ub.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},Cb={description:Uo("A number raised to a power."),args:[od("base (number)",Uo("The number to raise to the exponent power.")),od("exponent (number)",Uo("The exponent to raise base to."))],compute:function(e,t){return Iu.compute.bind(this)(e,t)}},wb={description:Uo("A number with the sign reversed."),args:[od("value (number)",Uo("The number to have its sign reversed. Equivalently, the number to multiply by -1."))],compute:function(e){return{value:-ki(e,this.locale),format:e?.format}}},xb={description:Uo("Value interpreted as a percentage."),args:[od("percentage (number)",Uo("The value to interpret as a percentage."))],compute:function(e){return ki(e,this.locale)/100}},Ib={description:Uo("A specified number, unchanged."),args:[od("value (any)",Uo("The number to return."))],compute:function(e={value:null}){return e}};var Eb=Object.freeze({__proto__:null,ADD:rb,CONCAT:ab,DIVIDE:lb,EQ:ub,GT:pb,GTE:mb,LT:fb,LTE:vb,MINUS:bb,MULTIPLY:Sb,NE:yb,POW:Cb,UMINUS:wb,UNARY_PERCENT:xb,UPLUS:Ib});const Rb=e=>({transform:t=>t*e,inverseTransform:t=>t/e}),Tb={transform:e=>e,inverseTransform:e=>e},Ab=1e-10,_b=.0254,Db=_b/72,Ob=.3048,Fb=.9144,Mb=1609.34,Pb=1852,Nb=946073047258e4,kb={g:{...Tb,category:"weight"},u:{...Rb(166053e-29),category:"weight"},grain:{...Rb(.0647989),category:"weight"},ozm:{...Rb(28.3495),category:"weight"},lbm:{...Rb(453.592),category:"weight"},stone:{...Rb(6350.29),category:"weight"},sg:{...Rb(14593.90294),category:"weight"},cwt:{...Rb(45359.237),category:"weight"},uk_cwt:{...Rb(50802.3),category:"weight"},ton:{...Rb(907184.74),category:"weight"},uk_ton:{...Rb(1016046.9),category:"weight"},m:{...Tb,category:"distance"},km:{...Rb(1e3),category:"distance"},ang:{...Rb(Ab),category:"distance"},Picapt:{...Rb(Db),category:"distance"},pica:{...Rb(_b/6),category:"distance"},in:{...Rb(_b),category:"distance"},ft:{...Rb(Ob),category:"distance"},yd:{...Rb(Fb),category:"distance"},ell:{...Rb(1.143),category:"distance"},mi:{...Rb(Mb),category:"distance"},survey_mi:{...Rb(1609.34),category:"distance"},Nmi:{...Rb(Pb),category:"distance"},ly:{...Rb(Nb),category:"distance"},parsec:{...Rb(0x6da012f95c9fd0),category:"distance"},sec:{...Tb,category:"time"},min:{...Rb(60),category:"time"},hr:{...Rb(3600),category:"time"},day:{...Rb(86400),category:"time"},yr:{...Rb(31556952),category:"time"},Pa:{...Tb,category:"pressure"},bar:{...Rb(1e5),category:"pressure"},mmHg:{...Rb(133.322),category:"pressure"},Torr:{...Rb(133.322),category:"pressure"},psi:{...Rb(6894.76),category:"pressure"},atm:{...Rb(101325),category:"pressure"},N:{...Tb,category:"force"},dyn:{...Rb(1e-5),category:"force"},pond:{...Rb(.00980665),category:"force"},lbf:{...Rb(4.44822),category:"force"},J:{...Tb,category:"energy"},eV:{...Rb(160218e-24),category:"energy"},e:{...Rb(1e-7),category:"energy"},flb:{...Rb(1.3558179483),category:"energy"},c:{...Rb(4.184),category:"energy"},cal:{...Rb(4.1868),category:"energy"},BTU:{...Rb(1055.06),category:"energy"},Wh:{...Rb(3600),category:"energy"},HPh:{...Rb(2684520),category:"energy"},W:{...Tb,category:"power"},PS:{...Rb(735.499),category:"power"},HP:{...Rb(745.7),category:"power"},T:{...Tb,category:"magnetism"},ga:{...Rb(1e-4),category:"magnetism"},K:{...Tb,category:"temperature"},C:{transform:e=>e+273.15,inverseTransform:e=>e-273.15,category:"temperature"},F:{transform:e=>5*(e-32)/9+273.15,inverseTransform:e=>9*(e-273.15)/5+32,category:"temperature"},Rank:{...Rb(5/9),category:"temperature"},Reau:{transform:e=>1.25*e+273.15,inverseTransform:e=>(e-273.15)/1.25,category:"temperature"},"m^3":{...Tb,category:"volume",order:3},"ang^3":{...Rb(Math.pow(Ab,3)),category:"volume",order:3},"Picapt^3":{...Rb(Math.pow(Db,3)),category:"volume",order:3},tsp:{...Rb(492892e-11),category:"volume"},tspm:{...Rb(5e-6),category:"volume"},tbs:{...Rb(14786764825785619e-21),category:"volume"},"in^3":{...Rb(Math.pow(_b,3)),category:"volume",order:3},oz:{...Rb(295735295625e-16),category:"volume"},cup:{...Rb(237e-6),category:"volume"},pt:{...Rb(.0004731765),category:"volume"},uk_pt:{...Rb(568261e-9),category:"volume"},qt:{...Rb(.0009463529),category:"volume"},l:{...Rb(.001),category:"volume"},uk_qt:{...Rb(.0011365225),category:"volume"},gal:{...Rb(.0037854118),category:"volume"},uk_gal:{...Rb(.00454609),category:"volume"},"ft^3":{...Rb(Math.pow(Ob,3)),category:"volume",order:3},bushel:{...Rb(.0352390704),category:"volume"},barrel:{...Rb(.158987295),category:"volume"},"yd^3":{...Rb(Math.pow(Fb,3)),category:"volume",order:3},MTON:{...Rb(1.13267386368),category:"volume"},GRT:{...Rb(2.83168),category:"volume"},"mi^3":{...Rb(Math.pow(Mb,3)),category:"volume",order:3},"Nmi^3":{...Rb(Math.pow(Pb,3)),category:"volume",order:3},"ly^3":{...Rb(Math.pow(Nb,3)),category:"volume",order:3},"m^2":{...Tb,category:"area",order:2},"ang^2":{...Rb(Math.pow(Ab,2)),category:"area",order:2},"Picapt^2":{...Rb(Math.pow(Db,2)),category:"area",order:2},"in^2":{...Rb(Math.pow(_b,2)),category:"area",order:2},"ft^2":{...Rb(Math.pow(Ob,2)),category:"area",order:2},"yd^2":{...Rb(Math.pow(Fb,2)),category:"area",order:2},ar:{...Rb(100),category:"area"},Morgen:{...Rb(2500),category:"area"},uk_acre:{...Rb(4046.8564224),category:"area"},us_acre:{...Rb(4046.8726098743),category:"area"},ha:{...Rb(1e4),category:"area"},"mi^2":{...Rb(Math.pow(Mb,2)),category:"area",order:2},"Nmi^2":{...Rb(Math.pow(Pb,2)),category:"area",order:2},"ly^2":{...Rb(Math.pow(Nb,2)),category:"area",order:2},bit:{...Tb,category:"information"},byte:{...Rb(8),category:"information"},"m/s":{...Tb,category:"speed"},"m/hr":{...Rb(1/3600),category:"speed"},"km/hr":{...Rb(1/3.6),category:"speed"},mph:{...Rb(.44704),category:"speed"},kn:{...Rb(.5144444444),category:"speed"},admkn:{...Rb(.5147733333),category:"speed"}},Vb={shweight:"cwt",lcwt:"uk_cwt",hweight:"uk_cwt",LTON:"uk_ton",brton:"uk_ton",pc:"parsec",Pica:"Picapt",d:"day",mn:"min",s:"sec",p:"Pa",at:"atm",dy:"dyn",ev:"eV",hh:"HPh",wh:"Wh",btu:"BTU",h:"HP",cel:"C",fah:"F",kel:"K",us_pt:"pt",L:"l",lt:"l",ang3:"ang^3",ft3:"ft^3",in3:"in^3",ly3:"ly^3",m3:"m^3",mi3:"mi^3",yd3:"yd^3",Nmi3:"Nmi^3",Picapt3:"Picapt^3","Pica^3":"Picapt^3",Pica3:"Picapt^3",regton:"GRT",ang2:"ang^2",ft2:"ft^2",in2:"in^2",ly2:"ly^2",m2:"m^2",mi2:"mi^2",Nmi2:"Nmi^2",Picapt2:"Picapt^2","Pica^2":"Picapt^2",Pica2:"Picapt^2",yd2:"yd^2","m/h":"m/hr","m/sec":"m/s"},Lb={"":1,Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,h:100,da:10,e:10,d:.1,c:.01,m:.001,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-21,Yi:Math.pow(2,80),Zi:Math.pow(2,70),Ei:Math.pow(2,60),Pi:Math.pow(2,50),Ti:Math.pow(2,40),Gi:Math.pow(2,30),Mi:Math.pow(2,20),ki:Math.pow(2,10)},Hb={weight:Uo("Weight"),distance:Uo("Distance"),time:Uo("Time"),pressure:Uo("Pressure"),force:Uo("Force"),energy:Uo("Energy"),power:Uo("Power"),magnetism:Uo("Magnetism"),temperature:Uo("Temperature"),volume:Uo("Volume"),area:Uo("Area"),information:Uo("Information"),speed:Uo("Speed")};function Ub(e){return Hb[e]??""}function Bb(e){for(const[t,o]of Object.entries(Lb)){if(t&&!e.startsWith(t))continue;const s=e.slice(t.length);let i=kb[s];if(!i&&Vb[s]&&(i=kb[Vb[s]]),i)return{...i,factor:i.order?Math.pow(o,i.order):o}}}const zb={description:Uo("Converts a numeric value to a different unit of measure."),args:[od("value (number)",Uo("the numeric value in start_unit to convert to end_unit")),od("start_unit (string)",Uo("The starting unit, the unit currently assigned to value")),od("end_unit (string)",Uo("The unit of measure into which to convert value"))],compute:function(e,t,o){const s=ki(e,this.locale),i=Gi(t),n=Gi(o),r=Bb(i),a=Bb(n);return r?a?r.category!==a.category?{value:wi.GenericError,message:Uo("Incompatible units of measure ('%s' vs '%s')",Ub(r.category),Ub(a.category))}:{value:a.inverseTransform(r.factor*r.transform(s))/a.factor,format:e?.format}:{value:wi.GenericError,message:Uo("Invalid units of measure ('%s')",n)}:{value:wi.GenericError,message:Uo("Invalid units of measure ('%s')",i)}},isExported:!0};var $b=Object.freeze({__proto__:null,CONVERT:zb});const Gb=/[A-Za-zÀ-ÖØ-öø-ÿ]+/g,Wb={description:Uo("Gets character associated with number."),args:[od("table_number (number)",Uo("The number of the character to look up from the current Unicode table in decimal format."))],compute:function(e){const t=Math.trunc(ki(e,this.locale));return Fi((()=>t>=1),Uo("The table_number (%s) is out of range.",t.toString())),String.fromCharCode(t)},isExported:!0},qb={description:Uo("Remove non-printable characters from a piece of text."),args:[od("text (string)",Uo("The text whose non-printable characters are to be removed."))],compute:function(e){const t=Gi(e);let o="";for(const e of t)e&&e.charCodeAt(0)>31&&(o+=e);return o},isExported:!0},Zb={description:Uo("Appends strings to one another."),args:[od("string1 (string, range<string>)",Uo("The initial string.")),od("string2 (string, range<string>, repeating)",Uo("More strings to append in sequence."))],compute:function(...e){return en(e,((e,t)=>e+Gi(t)),"")},isExported:!0},jb={description:Uo("Tests whether two strings are identical."),args:[od("string1 (string)",Uo("The first string to compare.")),od("string2 (string)",Uo("The second string to compare."))],compute:function(e,t){return Gi(e)===Gi(t)},isExported:!0},Yb={description:Uo("First position of string found in text, case-sensitive."),args:[od("search_for (string)",Uo("The string to look for within text_to_search.")),od("text_to_search (string)",Uo("The text to search for the first occurrence of search_for.")),od("starting_at (number, default=1)",Uo("The character within text_to_search at which to start the search."))],compute:function(e,t,o={value:1}){const s=Gi(e),i=Gi(t),n=ki(o,this.locale);Fi((()=>""!==i),Uo("The text_to_search must be non-empty.")),Fi((()=>n>=1),Uo("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=i.indexOf(s,n-1);return Fi((()=>r>=0),Uo("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",s.toString(),i)),r+1},isExported:!0},Xb={description:Uo("Concatenates elements of arrays with delimiter."),args:[od("delimiter (string)",Uo("The character or string to place between each concatenated value.")),od("value_or_array1 (string, range<string>)",Uo("The value or values to be appended using delimiter.")),od("value_or_array2 (string, range<string>, repeating)",Uo("More values to be appended using delimiter."))],compute:function(e,...t){const o=Gi(e);return en(t,((e,t)=>(e?e+o:"")+Gi(t)),"")}},Kb={description:Uo("Substring from beginning of specified string."),args:[od("text (string)",Uo("The string from which the left portion will be returned.")),od("number_of_characters (number, optional)",Uo("The number of characters to return from the left side of string."))],compute:function(e,...t){const o=t.length?ki(t[0],this.locale):1;return Fi((()=>o>=0),Uo("The number_of_characters (%s) must be positive or null.",o.toString())),Gi(e).substring(0,o)},isExported:!0},Jb={description:Uo("Length of a string."),args:[od("text (string)",Uo("The string whose length will be returned."))],compute:function(e){return Gi(e).length},isExported:!0},Qb={description:Uo("Converts a specified string to lowercase."),args:[od("text (string)",Uo("The string to convert to lowercase."))],compute:function(e){return Gi(e).toLowerCase()},isExported:!0},eS={description:Uo("A segment of a string."),args:[od("text (string)",Uo("The string to extract a segment from.")),od("starting_at (number)",Uo("The index from the left of string from which to begin extracting. The first character in string has the index 1.")),od("extract_length (number)",Uo("The length of the segment to extract."))],compute:function(e,t,o){const s=Gi(e),i=ki(t,this.locale),n=ki(o,this.locale);return Fi((()=>i>=1),Uo("The starting_at argument (%s) must be positive greater than one.",i.toString())),Fi((()=>n>=0),Uo("The extract_length argument (%s) must be positive or null.",n.toString())),s.slice(i-1,i+n-1)},isExported:!0},tS={description:Uo("Capitalizes each word in a specified string."),args:[od("text_to_capitalize (string)",Uo("The text which will be returned with the first letter of each word in uppercase and all other letters in lowercase."))],compute:function(e){return Gi(e).replace(Gb,(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()))},isExported:!0},oS={description:Uo("Replaces part of a text string with different text."),args:[od("text (string)",Uo("The text, a part of which will be replaced.")),od("position (number)",Uo("The position where the replacement will begin (starting from 1).")),od("length (number)",Uo("The number of characters in the text to be replaced.")),od("new_text (string)",Uo("The text which will be inserted into the original text."))],compute:function(e,t,o,s){const i=ki(t,this.locale);Fi((()=>i>=1),Uo("The position (%s) must be greater than or equal to 1.",i.toString()));const n=Gi(e),r=ki(o,this.locale),a=Gi(s);return n.substring(0,i-1)+a+n.substring(i-1+r)},isExported:!0},sS={description:Uo("A substring from the end of a specified string."),args:[od("text (string)",Uo("The string from which the right portion will be returned.")),od("number_of_characters (number, optional)",Uo("The number of characters to return from the right side of string."))],compute:function(e,...t){const o=t.length?ki(t[0],this.locale):1;Fi((()=>o>=0),Uo("The number_of_characters (%s) must be positive or null.",o.toString()));const s=Gi(e),i=s.length;return s.substring(i-o,i)},isExported:!0},iS={description:Uo("First position of string found in text, ignoring case."),args:[od("search_for (string)",Uo("The string to look for within text_to_search.")),od("text_to_search (string)",Uo("The text to search for the first occurrence of search_for.")),od("starting_at (number, default=1)",Uo("The character within text_to_search at which to start the search."))],compute:function(e,t,o={value:1}){const s=Gi(e).toLowerCase(),i=Gi(t).toLowerCase(),n=ki(o,this.locale);if(""===i)return{value:wi.GenericError,message:Uo("The text_to_search must be non-empty.")};if(n<1)return{value:wi.GenericError,message:Uo("The starting_at (%s) must be greater than or equal to 1.",n)};const r=i.indexOf(s,n-1);return-1===r?{value:wi.GenericError,message:Uo("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",s,i)}:{value:r+1}},isExported:!0},nS={description:Uo("Split text by specific character delimiter(s)."),args:[od("text (string)",Uo("The text to divide.")),od("delimiter (string)",Uo("The character or characters to use to split text.")),od("split_by_each (boolean, default=true})",Uo("Whether or not to divide text around each character contained in delimiter.")),od("remove_empty_text (boolean, default=true)",Uo("Whether or not to remove empty text messages from the split results. The default behavior is to treat consecutive delimiters as one (if TRUE). If FALSE, empty cells values are added between consecutive delimiters."))],compute:function(e,t,o={value:true},s={value:true}){const i=Gi(e),n=Be(Gi(t)),r=Zi(o),a=Zi(s);Fi((()=>n.length>0),Uo("The _delimiter (%s) must be not be empty.",n));const l=r?new RegExp(`[${n}]`,"g"):new RegExp(n,"g");let c=i.split(l);return a&&(c=c.filter((e=>""!==e))),rn([c])},isExported:!1},rS={description:Uo("Replaces existing text with new text in a string."),args:[od("text_to_search (string)",Uo("The text within which to search and replace.")),od("search_for (string)",Uo("The string to search for within text_to_search.")),od("replace_with (string)",Uo("The string that will replace search_for.")),od("occurrence_number (number, optional)",Uo("The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced."))],compute:function(e,t,o,s){const i=ki(s,this.locale);Fi((()=>i>=0),Uo("The occurrenceNumber (%s) must be positive or null.",i.toString()));const n=Gi(e),r=Gi(t);if(""===r)return n;const a=Gi(o),l=new RegExp(Be(r),"g");if(0===i)return n.replace(l,a);let c=0;return n.replace(l,(e=>++c===i?a:e))},isExported:!0},aS={description:Uo("Combines text from multiple strings and/or arrays."),args:[od("delimiter (string)",Uo(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")),od("ignore_empty (boolean)",Uo("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")),od("text1 (string, range<string>)",Uo("Any text item. This could be a string, or an array of strings in a range.")),od("text2 (string, range<string>, repeating)",Uo("Additional text item(s)."))],compute:function(e,t,...o){const s=Gi(e),i=Zi(t);let n=0;return en(o,((e,t)=>i&&""===Gi(t)?e:(n++?e+s:"")+Gi(t)),"")},isExported:!0},lS={description:Uo("Removes space characters."),args:[od("text (string)",Uo("The text or reference to a cell containing text to be trimmed."))],compute:function(e){return At(Gi(e))},isExported:!0},cS={description:Uo("Converts a specified string to uppercase."),args:[od("text (string)",Uo("The string to convert to uppercase."))],compute:function(e){return Gi(e).toUpperCase()},isExported:!0},hS={description:Uo("Converts a number to text according to a specified format."),args:[od("number (number)",Uo("The number, date or time to format.")),od("format (string)",Uo("The pattern by which to format the number, enclosed in quotation marks."))],compute:function(e,t){return Kn(ki(e,this.locale),{format:Gi(t),locale:this.locale})},isExported:!0},dS={description:Uo("Converts a string to a numeric value."),args:[od("value (number)",Uo("the string to be converted"))],compute:function(e){return ki(e,this.locale)},isExported:!0};var uS=Object.freeze({__proto__:null,CHAR:Wb,CLEAN:qb,CONCATENATE:Zb,EXACT:jb,FIND:Yb,JOIN:Xb,LEFT:Kb,LEN:Jb,LOWER:Qb,MID:eS,PROPER:tS,REPLACE:oS,RIGHT:sS,SEARCH:iS,SPLIT:nS,SUBSTITUTE:rS,TEXT:hS,TEXTJOIN:aS,TRIM:lS,UPPER:cS,VALUE:dS});const gS={description:Uo("Creates a hyperlink in a cell."),args:[od("url (string)",Uo("The full URL of the link enclosed in quotation marks.")),od("link_label (string, optional)",Uo("The text to display in the cell, enclosed in quotation marks."))],compute:function(e,t){const o=Gi(e).trim(),s=Gi(t)||o;return""===o?s:ot(s,o)},isExported:!0};var pS=Object.freeze({__proto__:null,HYPERLINK:gS});const mS=[{name:Uo("Array"),functions:Fd},{name:Uo("Database"),functions:mp},{name:Uo("Date"),functions:Xp},{name:Uo("Filter"),functions:lm},{name:Uo("Financial"),functions:Hf},{name:Uo("Info"),functions:Ev},{name:Uo("Lookup"),functions:nb},{name:Uo("Logical"),functions:kv},{name:Uo("Math"),functions:qu},{name:Uo("Misc"),functions:Pd},{name:Uo("Operator"),functions:Eb},{name:Uo("Statistical"),functions:ep},{name:Uo("Text"),functions:uS},{name:Uo("Engineering"),functions:Jp},{name:Uo("Web"),functions:pS},{name:Uo("Parser"),functions:$b}],fS=/^[A-Z0-9\_\.]+$/;const vS=new class extends n{mapping={};add(e,t){if(e=e.toUpperCase(),!fS.test(e))throw new Error(Uo("Invalid function name %s. Function names can exclusively contain alphanumerical values separated by dots (.) or underscore (_)",e));const o=sd(t);return function(e){let t=!1,o=!1,s=!1;for(let i of e){if(i.type.includes("META")&&i.type.length>1)throw new Error(Uo("Function ${name} has an argument that has been declared with more than one type whose type 'META'. The 'META' type can only be declared alone."));if(t&&!i.repeating)throw new Error(Uo("Function ${name} has no-repeatable arguments declared after repeatable ones. All repeatable arguments must be declared last."));const e=o||t||s,n=!(i.optional||i.repeating||i.default);if(e&&n)throw new Error(Uo("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=i.repeating,o=i.optional,s=i.default}}(o.args),this.mapping[e]=function(e,t){function o(...o){const i=[];for(let s=0;s<o.length;s++){const n=e.args[e.getArgToFocus(s+1)-1];if(!bi(o[s])&&n.acceptMatrixOnly)throw new Ei(Uo("Function %s expects the parameter '%s' to be reference to a cell or range.",t,(s+1).toString()));i.push(!n.acceptMatrix)}return an(s.bind(this),o,i)}function s(...o){for(let t=0;t<o.length;t++){const s=o[t];if(!e.args[e.getArgToFocus(t+1)-1].acceptErrors&&!bi(s)&&Pi(s?.value))return s}try{return i.apply(this,o)}catch(e){return bS(e,t)}}function i(...o){this.debug;const s=e.compute.apply(this,o);return bi(s)?"object"==typeof s[0][0]&&null!==s[0][0]&&"value"in s[0][0]?(function(e,t){const o=e.length,s=e[0]?.length??0;for(let i=0;i<o;i++)for(let o=0;o<s;o++)t(e[i][o])}(s,(e=>SS(e,t))),s):nn(s,(e=>({value:e}))):"object"==typeof s&&null!==s&&"value"in s?(SS(s,t),s):{value:s}}return o}(o,e),super.add(e,o),this}};for(let e of mS){const t=e.functions;for(let o in t){const s=t[o];s.category=s.category||e.name,o=o.replace(/_/g,"."),vS.add(o,{isExported:!1,...s})}}function bS(e,t){return o=e,void 0!==o?.value&&"string"==typeof o.value&&Pi(e.value)?(CS(e)&&SS(e,t),e):(console.error(e),new Ii(yS+(CS(e)?" "+e.message:"")));var o}function SS(e,t){e.message?.includes("[[FUNCTION_NAME]]")&&(e.message=e.message.replace("[[FUNCTION_NAME]]",t))}const yS=Uo("An unexpected error occurred. Submit a support ticket at odoo.com/help.");function CS(e){return void 0!==e?.message&&"string"==typeof e.message}function wS(e,t,o){const{x:s,y:i,width:n,height:r}=o;if(n<0||r<0)return;const l=t.color||a,{ctx:c}=e;c.save(),t.noBorder||(t.dashed&&c.setLineDash([5,3]),c.strokeStyle=l,t.thinLine?(c.lineWidth=1,c.strokeRect(s,i,n,r)):(c.lineWidth=2,c.strokeRect(s+.5,i+.5,n,r))),t.noFill||(c.fillStyle=Qt(zt(l),t.fillAlpha??.12),c.fillRect(s,i,n,r)),c.restore()}Jh.add("functions",{sequence:100,autoSelectFirstProposal:!0,maxDisplayedProposals:10,getProposals(e){if("SYMBOL"!==e.type)return[];const t=e.value;if(!this.composer.currentContent.startsWith("="))return[];const o=Object.entries(vS.content).filter((([e,{hidden:t}])=>!t)).map((([e,{description:o}])=>({text:e,description:o,htmlContent:Qh(t,e,E,"o-semi-bold")}))).sort(((e,t)=>e.text.length-t.text.length||e.text.localeCompare(t.text)));return o},selectProposal(e,t){let o=e.end,s=e.end;["SYMBOL","FUNCTION"].includes(e.type)&&(o=e.start);const i=this.composer.currentTokens;t+="(";const n=i.map((e=>e.start)).indexOf(e.start);if(n+1<i.length){const e=i[n+1];"LEFT_PAREN"===e?.type&&s++}this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}});class xS extends Xc{mutators=["register","unRegister"];providers=[];constructor(e){super(e),this.onDispose((()=>{this.providers=[]}))}get renderingLayers(){return["Highlights"]}get highlights(){const e=this.getters.getActiveSheetId();return this.providers.flatMap((e=>e.highlights)).filter((t=>t.sheetId===e)).map((e=>{const{numberOfRows:t,numberOfCols:o}=ss(e.zone),s=t*o==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:s}}))}register(e){this.providers.push(e)}unRegister(e){this.providers=this.providers.filter((t=>t!==e))}drawLayer(e,t){if("Highlights"===t)for(const t of this.highlights){wS(e,t,this.getters.getVisibleRect(t.zone))}}}class IS{mutators=["notifyUser","raiseError","askConfirmation","updateNotificationCallbacks"];notifyUser=e=>window.alert(e.text);askConfirmation=(e,t,o)=>{window.confirm(e)?t():o?.()};raiseError=(e,t)=>{window.alert(e),t?.()};updateNotificationCallbacks(e){this.notifyUser=e.notifyUser||this.notifyUser,this.raiseError=e.raiseError||this.raiseError,this.askConfirmation=e.askConfirmation||this.askConfirmation}}const ES="#000000",RS="#3da4ab",TS={OPERATOR:RS,NUMBER:"#02c39a",STRING:"#00a82d",FUNCTION:ES,DEBUGGER:RS,LEFT_PAREN:ES,RIGHT_PAREN:ES,ARG_SEPARATOR:ES,ORPHAN_RIGHT_PAREN:"#ff0000"};class AS extends Xc{mutators=["startEdition","setCurrentContent","stopEdition","stopComposerRangeSelection","cancelEdition","cycleReferences","toggleEditionMode","changeComposerCursorSelection","replaceComposerCursorSelection"];col=0;row=0;editionMode="inactive";sheetId="";_currentContent="";currentTokens=[];selectionStart=0;selectionEnd=0;initialContent="";colorIndexByRange={};notificationStore=this.get(IS);highlightStore=this.get(xS);constructor(e){super(e),this.highlightStore.register(this),this.onDispose((()=>{this.highlightStore.unRegister(this)}))}handleEvent(e){const t=this.getters.getActiveSheetId();let o;if(o=e.options.unbounded?this.getters.getUnboundedZone(t,e.anchor.zone):e.anchor.zone,"newAnchor"===e.mode)"selecting"===this.editionMode&&this.insertSelectedRange(o);else"selecting"===this.editionMode?this.replaceSelectedRange(o):this.updateComposerRange(e.previousAnchor.zone,o)}changeComposerCursorSelection(e,t){this.isSelectionValid(this._currentContent.length,e,t)&&(this.selectionStart=e,this.selectionEnd=t,this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor())}stopComposerRangeSelection(){this.isSelectingRange&&(this.editionMode="editing")}startEdition(e,t){if(t){const o=e||this.getComposerContent(this.getters.getActivePosition());if(!this.isSelectionValid(o.length,t.start,t.end))return}const{col:o,row:s}=this.getters.getActivePosition();this.model.dispatch("SELECT_FIGURE",{id:null}),this.model.dispatch("SCROLL_TO_CELL",{col:o,row:s}),"inactive"!==this.editionMode&&e?this.setContent(e,t):this._startEdition(e,t),this.updateTokenColor(),this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor()}cancelEdition(){this.resetContent(),this.cancelEditionAndActivateSheet()}setCurrentContent(e,t){t&&!this.isSelectionValid(e.length,t.start,t.end)||(this.setContent(e,t,!0),this.updateTokenColor(),this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor())}replaceComposerCursorSelection(e){this.replaceSelection(e)}handle(e){switch(e.type){case"SELECT_FIGURE":e.id&&(this.resetContent(),this.cancelEditionAndActivateSheet());break;case"START_CHANGE_HIGHLIGHT":const{left:t,top:o}=e.zone;this.isSelectingRange&&(this.editionMode="editing"),this.model.selection.resetAnchor(this,{cell:{col:t,row:o},zone:e.zone})}}get currentContent(){return"inactive"===this.editionMode?this.getComposerContent(this.getters.getActivePosition()):this._currentContent}get composerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}get isSelectingRange(){return"selecting"===this.editionMode}get showSelectionIndicator(){return this.isSelectingRange&&this.canStartComposerRangeSelection()}get tokenAtCursor(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return e===t&&0===t?void 0:this.currentTokens.find((o=>o.start<=e&&o.end>=t))}cycleReferences(){const e=this.getters.getLocale(),t=gv(this.composerSelection,this._currentContent,e);void 0!==t&&this.setCurrentContent(t.content,t.selection)}toggleEditionMode(){if("inactive"===this.editionMode)return;const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd),o=[...this.currentTokens].reverse().find((o=>o.end>=e&&t>=o.start&&"REFERENCE"===o.type));if("editing"===this.editionMode&&o){const e=this.getters.getActiveSheetId(),{sheetName:t,xc:s}=qr(o.value),i=this.getters.getSheetIdByName(t);i&&i!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:i}),this.selectionStart=this.selectionEnd=o.end;const n=this.getters.getRangeFromSheetXC(this.sheetId,s).zone;this.captureSelection(n),this.editionMode="selecting"}else this.editionMode="editing"}captureSelection(e,t,o){this.model.selection.capture(this,{cell:{col:t||e.left,row:o||e.right},zone:e},{handleEvent:this.handleEvent.bind(this),release:()=>{this._stopEdition()}})}isSelectionValid(e,t,o){return t>=0&&t<=e&&o>=0&&o<=e}startComposerRangeSelection(){if(this.sheetId===this.getters.getActiveSheetId()){const e=hs({col:this.col,row:this.row});this.model.selection.resetAnchor(this,{cell:{col:this.col,row:this.row},zone:e})}this.editionMode="selecting"}_startEdition(e,t){const o=this.getters.getActiveCell(),s=this.getters.getLocale();e&&o.format?.includes("%")&&Js(e,s)&&(t=t||{start:e.length,end:e.length},e=`${e}%`);const{col:i,row:n,sheetId:r}=this.getters.getActivePosition();this.col=i,this.sheetId=r,this.row=n,this.initialContent=this.getComposerContent({sheetId:r,col:i,row:n}),this.editionMode="editing",this.setContent(e||this.initialContent,t),this.colorIndexByRange={};const a=hs({col:this.col,row:this.row});this.captureSelection(a,i,n)}_stopEdition(){if("inactive"!==this.editionMode){this.cancelEditionAndActivateSheet();let e=this.getCurrentCanonicalContent();if(!(this.initialContent!==e))return;if(e&&e.startsWith("=")){const t=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length-this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length;t>0&&(e+=ut(new Array(t).fill(")")))}this.confirmEdition(e)}}getCurrentCanonicalContent(){return Ka(this._currentContent,this.getters.getLocale())}cancelEditionAndActivateSheet(){if("inactive"===this.editionMode)return;this._cancelEdition();this.getters.getActiveSheetId()!==this.sheetId&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}_cancelEdition(){"inactive"!==this.editionMode&&(this.editionMode="inactive",this.model.selection.release(this),this.colorIndexByRange={})}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,o){const s=this._currentContent!==e;if(this._currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,s||"inactive"!==this.editionMode){const t=this.getters.getLocale();this.currentTokens=e.startsWith("=")?cv(e,t):[],this.currentTokens.length>100&&o&&this.notificationStore.raiseError(Uo("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))}this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}getAutoCompleteProviders(){return Jh.getAll()}insertSelectedRange(e){const t=Math.min(this.selectionStart,this.selectionEnd),o=this.getZoneReference(e);this.canStartComposerRangeSelection()?this.insertText(o,t):this.insertText(","+o,t)}replaceSelectedRange(e){const t=this.getZoneReference(e),o=this.tokenAtCursor,s="REFERENCE"===o?.type?o.start:this.selectionStart;this.replaceText(t,s,this.selectionEnd)}updateComposerRange(e,t){const o=this.getters.getActiveSheetId(),s=this.tokenAtCursor,i=(s?[s,...this.currentTokens]:this.currentTokens).filter((e=>"REFERENCE"===e.type)).find((t=>{const{xc:s,sheetName:i}=qr(t.value),n=i||this.getters.getSheetName(this.sheetId);if(!na(this.getters.getSheetName(o),n))return!1;const r=this.getters.getRangeFromSheetXC(o,s);return Qo(this.getters.expandZone(o,r.zone),e)}));if(!i)return;const n=this.getters.getRangeFromSheetXC(o,i.value);this.selectionStart=i.start,this.selectionEnd=this.selectionStart+i.value.length;const r=this.getters.getRangeFromZone(o,t),a=this.getRangeReference(r,n.parts);this.replaceSelection(a)}getZoneReference(e){const t=this.sheetId,o=this.getters.getActiveSheetId(),s=this.getters.getRangeFromZone(o,e);return this.getters.getSelectionRangeString(s,t)}getRangeReference(e,t){let o=[...t];const s=e.clone({parts:o});return this.getters.getSelectionRangeString(s,this.sheetId)}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),o=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,o)}replaceText(e,t,o){this._currentContent=this._currentContent.slice(0,t)+this._currentContent.slice(o,this._currentContent.length),this.insertText(e,t)}insertText(e,t){const o=this._currentContent.slice(0,t)+e+this._currentContent.slice(t),s=t+e.length;this.setCurrentContent(o,{start:s,end:s})}updateTokenColor(){this.updateRangeColor();for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].color=this.getTokenColor(this.currentTokens[e])}getTokenColor(e){if("REFERENCE"===e.type){const{xc:t,sheetName:o}=qr(e.value);return this.rangeColor(t,o)||ES}if("SYMBOL"===e.type){const t=e.value.toUpperCase();if("TRUE"===t||"FALSE"===t)return TS.NUMBER;if(t in vS.content)return TS.FUNCTION}return["LEFT_PAREN","RIGHT_PAREN"].includes(e.type)&&""===e.parenthesesCode?TS.ORPHAN_RIGHT_PAREN:TS[e.type]||ES}rangeColor(e,t){const o=t?this.model.getters.getSheetIdByName(t):this.sheetId,s=this.highlights.find((t=>{if(t.sheetId!==o)return!1;let s=this.model.getters.getRangeFromSheetXC(o,e).zone;return s=1===gs(s)?this.model.getters.expandZone(o,s):s,Qo(s,t.zone)}));return s&&s.color?s.color:void 0}computeFormulaCursorContext(){for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].isBlurred=!1;if(this.selectionStart!==this.selectionEnd)return;const e=this.getParenthesesCodeAfterCursor(),t=[...this.currentTokens].reverse().find((t=>e.startsWith(t.parenthesesCode)&&"SYMBOL"===t.type));if(t)for(let e=0;e<this.currentTokens.length;e++)(this.currentTokens[e].parenthesesCode||"").startsWith(t.parenthesesCode||"")||(this.currentTokens[e].isBlurred=!0)}getParenthesesCodeAfterCursor(){const e=this.tokenAtCursor?.parenthesesCode||"";return"RIGHT_PAREN"===this.tokenAtCursor?.type?e.slice(0,-1)||"":e}computeParenthesisRelatedToCursor(){for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].isParenthesisLinkedToCursor=!1;const e=this.tokenAtCursor;if(e&&""!==e.parenthesesCode&&["LEFT_PAREN","RIGHT_PAREN"].includes(e.type))for(let t=0;t<this.currentTokens.length;t++){const o=this.currentTokens[t];["LEFT_PAREN","RIGHT_PAREN"].includes(o.type)&&o.parenthesesCode===e.parenthesesCode&&o!==e&&(this.currentTokens[t].isParenthesisLinkedToCursor=!0,this.tokenAtCursor.isParenthesisLinkedToCursor=!0)}}updateRangeColor(){if(!this._currentContent.startsWith("=")||"inactive"===this.editionMode)return;const e=this.sheetId,t=this.getReferencedRanges().map((t=>this.getters.getRangeString(t,e))),o={};for(const e of t)void 0!==this.colorIndexByRange[e]&&(o[e]=this.colorIndexByRange[e]);const s=new Set(Object.values(o));let i=0;const n=()=>{for(;s.has(i);)i++;return s.add(i),i};for(const e of t){const t=e in o?o[e]:n();o[e]=t}this.colorIndexByRange=o}get highlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.editionMode)return[];const e=this.sheetId,t=e=>{const t=this.colorIndexByRange[e];return Ht[t%Ht.length]};return this.getReferencedRanges().map((o=>{const s=this.getters.getRangeString(o,e),{numberOfRows:i,numberOfCols:n}=ss(o.zone);return{zone:i*n==1?this.getters.expandZone(o.sheetId,o.zone):o.zone,color:t(s),sheetId:o.sheetId,interactive:!0}}))}getReferencedRanges(){const e=this.sheetId;return this.currentTokens.filter((e=>"REFERENCE"===e.type)).map((t=>this.getters.getRangeFromSheetXC(e,t.value))).filter((e=>!e.invalidSheetName&&!e.invalidXc))}get autocompleteProvider(){const e=this.currentContent,t=e.startsWith("=")?this.tokenAtCursor:{type:"STRING",value:e};if("inactive"===this.editionMode||!t||["TRUE","FALSE"].includes(t.value.toUpperCase())||!this.canStartComposerRangeSelection()&&!["SYMBOL","STRING","UNKNOWN"].includes(t.type))return;const o={composer:this,getters:this.getters},s=this.getAutoCompleteProviders().sort(((e,t)=>(e.sequence??1/0)-(t.sequence??1/0))).map((s=>({...s,getProposals:s.getProposals.bind(o,t,e),selectProposal:s.selectProposal.bind(o,t)})));for(const e of s){let o=e.getProposals();const s=o?.find((e=>e.text===t.value)),i=t.value.replace(/[ ,\(\)]/g,"");if(this._currentContent===this.initialContent&&e.displayAllOnInitialContent&&o?.length)return{proposals:o,selectProposal:e.selectProposal,autoSelectFirstProposal:e.autoSelectFirstProposal??!1};if(s&&this._currentContent!==this.initialContent)return;if(i&&o&&!["ARG_SEPARATOR","LEFT_PAREN","OPERATOR"].includes(t.type)){const e=Qr(i,o,(e=>e.fuzzySearchKey||e.text));s&&!e.length||(o=e)}if(e.maxDisplayedProposals&&(o=o?.slice(0,e.maxDisplayedProposals)),o?.length)return{proposals:o,selectProposal:e.selectProposal,autoSelectFirstProposal:e.autoSelectFirstProposal??!1}}}canStartComposerRangeSelection(){if(this._currentContent.startsWith("=")){const e=this.tokenAtCursor;if(!e)return!1;const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let o=t,s=e;for(;!["ARG_SEPARATOR","LEFT_PAREN","OPERATOR"].includes(s.type)||Fa.includes(s.value);){if("SPACE"!==s.type||o<1)return!1;o--,s=this.currentTokens[o]}for(o=t+1,s=this.currentTokens[o];s&&!["ARG_SEPARATOR","RIGHT_PAREN","OPERATOR"].includes(s.type);){if("SPACE"!==s.type)return!1;o++,s=this.currentTokens[o]}return!0}return!1}}class _S{scope;code="";constructor(e=new OS){this.scope=e}append(...e){this.code+=e.map((e=>e.toString())).join("\n")+"\n"}return(e){return new DS(this.scope,this.code,e)}toString(){return FS(this.code)}}class DS{scope;returnExpression;code;constructor(e,t,o){this.scope=e,this.returnExpression=o,this.code=FS(t)}toString(){return this.code}assignResultToVariable(){if(this.scope.isAlreadyDeclared(this.returnExpression))return this;const e=this.scope.nextVariableName(),t=new _S(this.scope);return t.append(this.code),t.append(`const ${e} = ${this.returnExpression};`),t.return(e)}}class OS{nextId=1;declaredVariables=new Set;nextVariableName(){const e="_"+this.nextId++;return this.declaredVariables.add(e),e}isAlreadyDeclared(e){return this.declaredVariables.has(e)}}function FS(e){let t="",o=0;const s=e.split("\n").map((e=>e.trim())).filter((e=>""!==e));for(const e of s)e.startsWith("}")&&o--,t+="\t".repeat(o)+e+"\n",e.endsWith("{")&&o++;return t.trim()}const MS=vS.content,PS={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},NS={"-":"UMINUS","+":"UPLUS","%":"UNARY.PERCENT"},kS={};function VS(e){return LS(Gf(e))}function LS(e){try{return function(e){const{dependencies:t,literalValues:o,symbols:s}=function(e){const t={numbers:[],strings:[]},o=[],s=[];for(const i of e)switch(i.type){case"INVALID_REFERENCE":case"REFERENCE":o.push(i.value);break;case"STRING":const e=Ue(i.value);t.strings.push({value:e});break;case"NUMBER":{const e=ei(i.value,fi);t.numbers.push({value:e});break}case"SYMBOL":s.push(Ge(i.value,"'"))}return{dependencies:o,literalValues:t,symbols:s}}(e),i=function(e){let t="";for(const o of e)switch(o.type){case"STRING":t+="|S|";break;case"NUMBER":t+="|N|";break;case"REFERENCE":case"INVALID_REFERENCE":o.value.includes(":")?t+="|R|":t+="|C|";break;case"SPACE":break;default:t+=o.value}return t}(e);if(!kS[i]){const r=tv([...e]),a=new OS;let l=0,c=0,h=0;if("BIN_OPERATION"===r.type&&":"===r.value)throw new Ei(Uo("Invalid formula"));if("EMPTY"===r.type)throw new Ei(Uo("Invalid formula"));const d=m(r),u=new _S;u.append(`// ${i}`),u.append(d),u.append(`return ${d.returnExpression};`);let g=new Function("deps","ref","range","getSymbolValue","ctx",u.toString());function p(e){const{args:t}=e,o=e.value.toUpperCase(),s=MS[o];if(!s)throw new _i(Uo('Unknown function: "%s"',e.value));!function(e){const t=e.args.length,o=e.value.toUpperCase(),s=MS[o];if(t<s.minArgRequired)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",o,s.minArgRequired.toString(),t.toString()));if(t>s.maxArgPossible)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",o,s.maxArgPossible.toString(),t.toString()));const i=s.nbrArgRepeating;if(i>1){const e=s.args.length-i;if((t-e)%i!=0)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",o,e.toString(),i.toString()))}}(e);const i=[];for(let e=0;e<t.length;e++){const o=s.getArgToFocus(e+1)-1,n=s.args[o],r=t[e],a=n.type||[],l=a.includes("META"),c=a.some((e=>HS(e)));i.push(m(r,l,c))}return i}function m(e,t=!1,o=!1){const i=new _S(a);if("REFERENCE"!==e.type&&("BIN_OPERATION"!==e.type||":"!==e.value)&&t)throw new Ei(Uo("Argument must be a reference to a cell or range."));switch(e.debug&&(i.append("debugger;"),i.append('ctx["debug"] = true;')),e.type){case"BOOLEAN":return i.return(`{ value: ${e.value} }`);case"NUMBER":return i.return(`this.literalValues.numbers[${c++}]`);case"STRING":return i.return(`this.literalValues.strings[${l++}]`);case"REFERENCE":return!t&&e.value.includes(":")||o?i.return(`range(deps[${h++}])`):i.return(`ref(deps[${h++}], ${t?"true":"false"})`);case"FUNCALL":const n=p(e).map((e=>e.assignResultToVariable()));i.append(...n);const r=e.value.toUpperCase();return i.return(`ctx['${r}'](${n.map((e=>e.returnExpression))})`);case"UNARY_OPERATION":{const t=NS[e.value],o=m(e.operand,!1,!1).assignResultToVariable();return i.append(o),i.return(`ctx['${t}'](${o.returnExpression})`)}case"BIN_OPERATION":{const t=PS[e.value],o=m(e.left,!1,!1).assignResultToVariable(),s=m(e.right,!1,!1).assignResultToVariable();return i.append(o),i.append(s),i.return(`ctx['${t}'](${o.returnExpression}, ${s.returnExpression})`)}case"SYMBOL":const a=s.indexOf(e.value);return i.return(`getSymbolValue(this.symbols[${a}])`);case"EMPTY":return i.return("undefined")}}kS[i]=g}const n={execute:kS[i],dependencies:t,literalValues:o,symbols:s,tokens:e,isBadExpression:!1,normalizedFormula:i};return n}(e)}catch(t){return{tokens:e,dependencies:[],execute:function(){return t},isBadExpression:!0,normalizedFormula:e.map((e=>e.value)).join("")}}}function HS(e){return e.startsWith("RANGE")}const US=vS.content;function BS(e){try{return 0===sv(tv(e)).filter((e=>"FUNCALL"===e.type&&!US[e.value.toUpperCase()]?.isExported)).length}catch(e){return!1}}function zS(e,t){if(!e.some((e=>"SYMBOL"===e.type&&t.includes(e.value.toUpperCase()))))return[];let o;try{o=tv(e)}catch{return[]}return function(e,t){return sv(e).filter((e=>"FUNCALL"===e.type&&t.includes(e.value.toUpperCase()))).map((e=>({functionName:e.value.toUpperCase(),args:e.args})))}(o,t)}const $S=["PIVOT.VALUE","PIVOT.HEADER","PIVOT"];function GS(e,t){const o=`"${t?`${e.name}:${t}`:e.name}"`,s=e.string!==e.name?e.string+o:o;return{text:o,description:e.string+(e.help?` (${e.help})`:""),htmlContent:[{value:o,color:TS.STRING}],fuzzySearchKey:s}}function WS(e,t){let o=e.end;const s=e.end;"ARG_SEPARATOR"!==e.type&&(o=e.start),this.composer.stopComposerRangeSelection(),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function qS(e,t){let o=e.end;const s=e.end;"LEFT_PAREN"!==e.type&&(o=e.start),this.composer.stopComposerRangeSelection(),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function ZS(e){const t=e.functionContext?.args[0];if(t&&["STRING","NUMBER"].includes(t.type))return t.value}function jS(e){return zS(e,$S)[0]}function YS(e){return zS(e,$S).length}const XS=new n;XS.add("SPREADSHEET",!1),Jh.add("pivot_ids",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!["PIVOT.VALUE","PIVOT.HEADER","PIVOT"].includes(t.parent.toUpperCase())||0!==t.argPosition)return;const o=this.getters.getPivotIds();return o.includes(e.value)?void 0:o.map((e=>{const t=this.getters.getPivotCoreDefinition(e),o=`${this.getters.getPivotFormulaId(e)}`;return{text:o,description:t.name,htmlContent:[{value:o,color:TS.NUMBER}],fuzzySearchKey:o+t.name,alwaysExpanded:!0}})).filter(lt)},selectProposal:qS}),Jh.add("pivot_measures",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if("PIVOT.VALUE"!==t?.parent.toUpperCase()||1!==t.argPosition)return[];const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return[];const i=this.getters.getPivot(s);return i.init(),i.isValid()?i.definition.measures.map((e=>{if("__count"===e.fieldName){const e='"__count"';return{text:e,description:Uo("Count"),htmlContent:[{value:e,color:TS.STRING}],fuzzySearchKey:Uo("Count")+e}}return function(e){const t=`"${e.id}"`,o=e.displayName+e.fieldName+t;return{text:t,description:e.displayName,htmlContent:[{value:t,color:TS.STRING}],fuzzySearchKey:o}}(e)})).filter(lt):[]},selectProposal:WS}),Jh.add("pivot_group_fields",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==0}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==1}(e))return;const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s);i.init();const n=i.getFields(),{columns:r,rows:a}=i.definition;let l=t.args;"PIVOT.VALUE"===t?.parent.toUpperCase()?(l=l.filter(((e,t)=>t%2==0)),l=l.slice(1,t.argPosition)):l=l.filter(((e,t)=>t%2==1));const c=l.map((e=>e?.value)).filter(lt),h=r.map((e=>e.nameWithGranularity)),d=a.map((e=>e.nameWithGranularity)),u=[];let g=["ARG_SEPARATOR","SPACE"].includes(e.type)?c.at(-1):c.at(-2);const p=XS.get(i.type);if(p&&g?.startsWith("#")&&(g=g.slice(1)),void 0===g&&(u.push(h[0]),u.push(d[0])),d.includes(g)){const e=d[d.indexOf(g)+1];u.push(e),u.push(h[0])}if(h.includes(g)){const e=h[h.indexOf(g)+1];u.push(e)}const m=u.filter(lt);return m.map((e=>{const[t,o]=e.split(":"),s=n[t];return s?GS(s,o):void 0})).concat(m.map((e=>{if(!p)return;const t=e.split(":")[0],o=n[t];if(!o)return;const s=`"#${e}"`;return{text:s,description:Uo("%s (positional)",o.string)+(o.help?` (${o.help})`:""),htmlContent:[{value:s,color:TS.STRING}],fuzzySearchKey:o.string+s}}))).filter(lt)},selectProposal:WS}),Jh.add("pivot_group_values",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!e||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==1}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==0}(e))return;const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s);if(!i.isValid())return;const n=t.argPosition,r=e.functionContext?.args[n-1]?.value;if(!r)return;let a;try{a=i.definition.getDimension(r)}catch(e){return}return"month_number"===a.granularity?Object.values(Yn).map(((e,t)=>({text:`${t+1}`,fuzzySearchKey:e.toString(),description:e.toString(),htmlContent:[{value:`${t+1}`,color:TS.NUMBER}]}))):"quarter_number"===a.granularity?[1,2,3,4].map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:Uo("Quarter %s",e),htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"day_of_month"===a.granularity?je(1,32).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"iso_week_number"===a.granularity?je(0,54).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"day_of_week"===a.granularity?je(1,8).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"hour_number"===a.granularity?je(0,24).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"minute_number"===a.granularity?je(0,60).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"second_number"===a.granularity?je(0,60).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):i.getPossibleFieldValues(a).map((({value:e,label:t})=>{const o="string"==typeof e,s=o?`"${e}"`:e.toString(),i=t===e?"":t;return{text:s,description:i,htmlContent:[{value:s,color:o?TS.STRING:TS.NUMBER}],fuzzySearchKey:s+i}}))},selectProposal:WS}),Jh.add("sheet_names",{sequence:150,autoSelectFirstProposal:!0,getProposals(e){return"SYMBOL"===e.type||"UNKNOWN"===e.type&&e.value.startsWith("'")?this.getters.getSheetIds().map((e=>{const t=We(this.getters.getSheetName(e));return{text:t,fuzzySearchKey:t.startsWith("'")?t:"'"+t}})):[]},selectProposal(e,t){const o=e.start,s=e.end;this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t+"!")}});const KS=new n;KS.add("ALPHANUMERIC_INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=`${e.prefix}${e.current.toString().padStart(e.numberPostfixLength||0,"0")}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:o},tooltip:{props:{content:o}}}}}).add("INCREMENT_MODIFIER",{apply:(e,t,o)=>{e.current+=e.increment;const s=e.current.toString(),i=o.getLocale(),n=Kn(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:n}}:void 0}}}).add("DATE_INCREMENT_MODIFIER",{apply:(e,t,o)=>{const s=ji(e.current,o.getLocale());s.setFullYear(s.getFullYear()+e.increment.years||0),s.setMonth(s.getMonth()+e.increment.months||0),s.setDate(s.getDate()+e.increment.days||0);const i=Us(s);e.current=i;const n=o.getLocale(),r=Kn(i,{format:t.cell?.format,locale:n});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i.toString()},tooltip:i?{props:{content:r}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,o)=>{const s=t.cell?.content||"",i={locale:o.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:t.cell?Ir(t.cell,i).formattedValue:""}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let i=0,n=0;switch(s){case"up":i=0,n=-e.current;break;case"down":i=0,n=e.current;break;case"left":i=-e.current,n=0;break;case"right":i=e.current,n=0}const r=t.cell;if(!r||!r.isFormula)return{cellData:{}};const a=t.sheetId,l=o.getTranslatedCellFormula(a,i,n,r.compiledFormula.tokens);return{cellData:{border:t.border,style:r.style,format:r.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const JS=new n,QS=/(\d+)$/,ey=/^(.*\D+)/,ty=/^(.*\D+)(\d+)$/;function oy(e,t,o){let s=[],i=!1;for(let n of t){n===e&&(i=!0);const t=void 0===n||n.isFormula?void 0:Ir(n,{locale:fi,format:n.format});if(t&&o(t))s.push(t);else{if(i)return s;s=[]}}return s}function sy(e){let t=1;return e.length>=2&&(t=function(e){const t=[];let o=e[0];for(let s=1;s<e.length;s++){const i=e[s];t.push(i-o),o=i}return t.reduce(((e,t)=>e+t),0)/t.length}(e)*e.length),t}function iy(e){if(e.length<2)return 1;const t=e.map((e=>ji(e,fi))),o=function(e){if(e.length<2)return[{years:0,months:0,days:0}];const t=e.map(((t,o)=>{if(0===o)return{years:0,months:0,days:0};const s=ws.fromTimestamp(e[o-1].getTime()),i=js(s,t),n=qs(s,t)%12;s.setFullYear(s.getFullYear()+i),s.setMonth(s.getMonth()+n);return{years:i,months:n,days:Zs(s,t)}}));return t.slice(1)}(t),s=(i=o).length<2?i[0]||{years:0,months:0,days:0}:i.every((e=>e.years===i[0].years&&e.months===i[0].months&&e.days===i[0].days))?i[0]:void 0;var i;if(void 0===s)return;const n=1===Object.values(s).filter((e=>0!==e)).length,r=Object.values(s).every((e=>0===e));if(!n||r){const o=t.map(((e,o)=>{if(0===o)return 0;const s=t[o-1];return Math.floor(e.getTime())-Math.floor(s.getTime())})).slice(1);if(o.every((e=>e===o[0])))return e.length*(e[1]-e[0])}return{years:s.years*e.length,months:s.months*e.length,days:s.days*e.length}}JS.add("simple_value_copy",{condition:(e,t)=>!(1!==t.length||e.isFormula||e.format&&nr(e.format)),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("increment_alphanumeric_value",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.text&&ty.test(e.content),generateRule:(e,t,o)=>{const s=parseInt(e.content.match(QS)[0]),i=e.content.match(ey)[0],n=e.content.length-i.length,r=oy(e,t,(e=>e.type===oi.text&&ty.test(e.value))).filter((e=>i===(e.value??"").toString().match(ey)[0])).map((e=>parseInt((e.value??"").toString().match(QS)[0])));let a=sy(r);return["up","left"].includes(o)&&1===r.length&&(a=-a),{type:"ALPHANUMERIC_INCREMENT_MODIFIER",prefix:i,current:s,increment:a,numberPostfixLength:n}},sequence:15}).add("copy_text",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.text,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>e.isFormula,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_dates",{condition:(e,t)=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.number&&!!e.format&&nr(e.format),generateRule:(e,t)=>{const o=iy(oy(e,t,(e=>e.type===oi.number&&!!e.format&&nr(e.format))).map((e=>Number(e.value))));if(void 0===o)return{type:"COPY_MODIFIER"};const s=Ir(e,{locale:fi});return"object"==typeof o?{type:"DATE_INCREMENT_MODIFIER",increment:o,current:s.type===oi.number?s.value:0}:{type:"INCREMENT_MODIFIER",increment:o,current:s.type===oi.number?s.value:0}},sequence:25}).add("increment_number",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.number,generateRule:(e,t,o)=>{const s=oy(e,t,(e=>e.type===oi.number&&!nr(e.format||""))).map((e=>Number(e.value)));let i=sy(s);["up","left"].includes(o)&&1===s.length&&(i=-i);const n=Ir(e,{locale:fi});return{type:"INCREMENT_MODIFIER",increment:i,current:n.type===oi.number?n.value:0}},sequence:40});const ny=new n,ry=30,ay=10,ly=20,cy=12,hy=80,dy="#F3F2F1",uy=6,gy=25;function py(e,t){const o=e.getBoundingClientRect(),s=window.devicePixelRatio||1;e.width=s*o.width,e.height=s*o.height;const i=e.getContext("2d");i.scale(s,s);const n=function(e,t,o){const s=t.maxValue,i=t.minValue,n=t.gaugeValue,r=function(e,t){const o=t?gy:0,s=e.height-ly-o-ay,i=e.width-2*ry;let n,r;i>2*s?(n=2*s,r=s):(n=i,r=i/2);const a=o+ay+(s-r)/2;return{x:ry+(i-n)/2,y:a,width:n,height:r}}(e,t.title.text),a=r.width/6,l=n?(n.value-i.value)/(s.value-i.value):0,c={x:e.width/2,y:r.y+r.height-r.height/12};let h=hy;r.height<300&&(h*=r.height/300);const d=r.width/2,u=n?.label||"-";ha(o,u,{fontSize:h},"px")>d&&(h=function(e,t,o,s=.25){let i=1;if(o(i)>e)return i;if(o(t)<e)return t;let n=(i+t)/2,r=o(n),a=0;for(;Math.abs(r-e)>s&&a<20;)r>=e?t=(i+t)/2:i=(i+t)/2,n=(i+t)/2,r=o(n),a++;return n}(d,h,(e=>ha(o,u,{fontSize:e},"px"))));const g={x:r.x+a/2,y:r.y+r.height+cy},p={x:r.x+r.width-a/2,y:r.y+r.height+cy},m=Sh(t.background),f=function(e,t,o,s){const i=e.maxValue,n=e.minValue,r={x:t.x+t.width/2,y:t.y+t.height},a={fontSize:cy},l=[],c=[];for(const h of e.inflectionValues){const e=(h.value-n.value)/(i.value-n.value),d=ha(s,h.label,a,"px"),u=Math.PI-Math.PI*e,g=Sy(u,t.height+uy,r.x,r.y,d+2,cy);let p=c.some((e=>by(e,g)))?cy:0;c.push(g),l.push({rotation:u,label:h.label,fontSize:cy,color:o,offset:p})}return l}(t,r,m,o);let v=0,b=0,S=0;t.title.text&&({width:b,height:S}=ga(o,t.title.text,{fontSize:X,...t.title},"px"));switch(t.title.align){case"right":v=e.width-b-Z;break;case"center":v=(e.width-b)/2;break;default:v=Z}return{width:e.width,height:e.height,title:{label:t.title.text??"",fontSize:t.title.fontSize??X,textPosition:{x:v,y:Y+S/2},color:t.title.color??m,bold:t.title.bold,italic:t.title.italic},backgroundColor:t.background,gauge:{rect:r,arcWidth:a,percentage:Ze(l,0,1),color:my(t)},inflectionValues:f,gaugeValue:{label:u,textPosition:c,fontSize:h,color:m},minLabel:{label:t.minValue.label,textPosition:g,fontSize:cy,color:m},maxLabel:{label:t.maxValue.label,textPosition:p,fontSize:cy,color:m}}}(o,t,i);!function(e,t){e.save(),e.fillStyle=t.backgroundColor,e.fillRect(0,0,t.width,t.height),e.restore()}(i,n),function(e,t){e.save();const o=t.gauge,s=o.rect.x+o.rect.width/2,i=o.rect.y+o.rect.height,n=o.rect.height-o.arcWidth/2;if(n<0)return;const r=1===o.percentage?0:Math.PI*(1+o.percentage);e.strokeStyle=dy,e.beginPath(),e.lineWidth=o.arcWidth,e.arc(s,i,n,r,0),e.stroke(),e.strokeStyle=o.color,e.beginPath(),e.arc(s,i,n,Math.PI,r),e.stroke(),e.restore()}(i,n),function(e,t){const{x:o,y:s,width:i,height:n}=t.gauge.rect;for(const r of t.inflectionValues){e.save(),e.translate(o+i/2-.5,s+n-.5),e.rotate(Math.PI/2-r.rotation),e.lineWidth=2,e.strokeStyle=Sh(t.backgroundColor)+"aa",e.beginPath(),e.moveTo(0,-(n-t.gauge.arcWidth)),e.lineTo(0,-n-3),e.stroke(),e.textAlign="center",e.font=`${r.fontSize}px ${ve}`,e.fillStyle=r.color;const a=-n-uy-r.offset;e.fillText(r.label,0,a),e.restore()}}(i,n),function(e,t){for(const o of[t.minLabel,t.maxLabel,t.gaugeValue])e.save(),e.textAlign="center",e.fillStyle=o.color,e.font=`${o.fontSize}px ${ve}`,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(i,n),function(e,t){e.save();const o=t.title;e.font=la(o.fontSize,o.bold,o.italic),e.textBaseline="middle",e.fillStyle=o.color,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(i,n)}function my(e){const t=e.gaugeValue?.value;if(void 0===t)return dy;for(let o=0;o<e.inflectionValues.length;o++){const s=e.inflectionValues[o];if("<"===s.operator&&t<s.value)return e.colors[o];if("<="===s.operator&&t<=s.value)return e.colors[o]}return e.colors.at(-1)}function fy(e){return[{start:e.topLeft,end:e.topRight},{start:e.topRight,end:e.bottomRight},{start:e.bottomRight,end:e.bottomLeft},{start:e.bottomLeft,end:e.topLeft}]}function vy(e,t){const o=e.start,s=e.end,i=t.start,n=t.end;function r(e,t,o){return(o.y-e.y)*(t.x-e.x)>(t.y-e.y)*(o.x-e.x)}return r(o,i,n)!==r(s,i,n)&&r(o,s,i)!==r(o,s,n)}function by(e,t){const o=fy(e),s=fy(t);for(const e of o)for(const t of s)if(vy(e,t))return!0;return!1}function Sy(e,t,o,s,i,n){const r=Math.cos(e),a=Math.sin(e),l=r*t,c=a*t,h=a*(i/2),d=r*(i/2),u=r*(t+n),g=a*(t+n);return{bottomLeft:{x:l-h+o,y:s-(c+d)},bottomRight:{x:l+h+o,y:s-(c-d)},topRight:{x:u+h+o,y:s-(g-d)},topLeft:{x:u-h+o,y:s-(g+d)}}}class yy extends t.Component{static template="o-spreadsheet-GaugeChartComponent";canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}setup(){t.useEffect((()=>py(this.canvas.el,this.runtime)),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el,window.devicePixelRatio]}))}}function Cy(e){return 8===(e=zt(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}yy.props={figure:Object};const wy={responsive:!0,maintainAspectRatio:!1,elements:{line:{fill:!1},point:{hitRadius:15}},animation:!1,events:["mousemove","mouseout","click","touchstart","touchmove","mouseup"]};function xy(e,t,o){const s=document.createElement("div");s.style.width=`${t.width}px`,s.style.height=`${t.height}px`;const i=document.createElement("canvas");if(s.append(i),i.setAttribute("width",t.width.toString()),i.setAttribute("height",t.height.toString()),document.body.append(s),"chartJsConfig"in e){const t=ze(e.chartJsConfig);t.plugins=[Iy];const o=new window.Chart(i,t),n=o.toBase64Image();return o.destroy(),s.remove(),n}if("scorecard"===o){Wh(Yh(t,e),i);const o=i.toDataURL();return s.remove(),o}if("gauge"===o){py(i,e);const t=i.toDataURL();return s.remove(),t}}const Iy={id:"customCanvasBackgroundColor",beforeDraw:e=>{const{ctx:t}=e;t.save(),t.globalCompositeOperation="destination-over",t.fillStyle="#ffffff",t.fillRect(0,0,e.width,e.height),t.restore()}};class Ey{xmlString;constructor(e){this.xmlString=e}toString(){return this.xmlString}}const Ry=["areaChart","area3DChart","lineChart","line3DChart","stockChart","radarChart","scatterChart","pieChart","pie3DChart","doughnutChart","barChart","bar3DChart","ofPieChart","surfaceChart","surface3DChart","bubbleChart","comboChart","radarChart"],Ty="000000",Ay={arrows:"3Arrows",smiley:"3Symbols",dots:"3TrafficLights1"},_y={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",table:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",revision:"http://schemas.microsoft.com/office/spreadsheetml/2014/revision",revision3:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",markupCompatibility:"http://schemas.openxmlformats.org/markup-compatibility/2006"},Dy="http://schemas.openxmlformats.org/drawingml/2006/main",Oy="http://schemas.openxmlformats.org/drawingml/2006/chart",Fy={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",macroEnabledWorkbook:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",templateWorkbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",macroEnabledTemplateWorkbook:"application/vnd.ms-excel.template.macroEnabled.main+xml",excelAddInWorkbook:"application/vnd.ms-excel.addin.macroEnabled.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",themes:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",pivot:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",externalLink:"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"},My={document:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",sheet:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",metadata:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata",sharedStrings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",styles:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",drawing:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",chart:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",theme:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",table:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",hyperlink:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",image:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"},Py="bdbb8cdc-fa1e-496e-a857-3c3f30c029c3",Ny="http://schemas.openxmlformats.org/officeDocument/2006/relationships",ky=.75,Vy=.143,Ly=8.43,Hy=12.75,Uy=30,By=100,zy=164,$y={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},Gy=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"],Wy="[Content_Types].xml",qy=new n;th`
9
+ `,nh.add("chartShowValuesPlugin",{register:e=>e.register(Oh),unregister:e=>e.unregister(Oh)}),nh.add("waterfallLinesPlugin",{register:e=>e.register(Mh),unregister:e=>e.unregister(Mh)});class kh extends t.Component{static template="o-spreadsheet-ChartJsComponent";static props={figure:Object};canvas=t.useRef("graphContainer");chart;currentRuntime;currentDevicePixelRatio=window.devicePixelRatio;get background(){return this.chartRuntime.background}get canvasStyle(){return`background-color: ${this.background}`}get chartRuntime(){const e=this.env.model.getters.getChartRuntime(this.props.figure.id);if(!("chartJsConfig"in e))throw new Error("Unsupported chart runtime");return e}setup(){t.onMounted((()=>{const e=this.chartRuntime;this.currentRuntime=e,this.createChart(ze(e.chartJsConfig))})),t.onWillUnmount((()=>this.chart?.destroy())),t.useEffect((()=>{const e=this.chartRuntime;e!==this.currentRuntime?(e.chartJsConfig.type!==this.currentRuntime.chartJsConfig.type?(this.chart?.destroy(),this.createChart(ze(e.chartJsConfig))):this.updateChartJs(ze(e.chartJsConfig)),this.currentRuntime=e):this.currentDevicePixelRatio!==window.devicePixelRatio&&(this.currentDevicePixelRatio=window.devicePixelRatio,this.updateChartJs(ze(this.currentRuntime.chartJsConfig)))}))}createChart(e){const t=this.canvas.el.getContext("2d");this.chart=new window.Chart(t,e)}updateChartJs(e){e.data&&e.data.datasets?(this.chart.data=e.data,e.options?.plugins?.title&&(this.chart.config.options.plugins.title=e.options.plugins.title)):this.chart.data.datasets=[],this.chart.config.options=e.options,this.chart.update()}}class Vh{sheetId;title;getters;constructor(e,t,o){this.title=e.title,this.sheetId=t,this.getters=o}static validateChartDefinition(e,t){throw new Error("This method should be implemented by sub class")}static transformDefinition(e,t){throw new Error("This method should be implemented by sub class")}static getDefinitionFromContextCreation(e){throw new Error("This method should be implemented by sub class")}}function Lh(e,t,o,s,i){if("text"===t||"progress"===t||e?.type!==oi.number||o?.type!==oi.number)return;const n=o.value-e.value;return n>0?s:n<0?i:void 0}function Hh(e,t,o){if("text"===o||e?.type!==oi.number||t?.type!==oi.number)return"neutral";const s=t.value-e.value;return s>0?"up":s<0?"down":"neutral"}function Uh(e){return e.keyValue&&!Br.test(e.keyValue)?"InvalidScorecardKeyValue":"Success"}function Bh(e){return e.baseline&&!Br.test(e.baseline)?"InvalidScorecardBaseline":"Success"}const zh=new window.Path2D("M8.6 4.8a.5.5 0 0 1 0 .75l-3.9 3.9a.5 .5 0 0 1 -.75 0l-3.8 -3.9a.5 .5 0 0 1 0 -.75l.4-.4a.5.5 0 0 1 .75 0l2.3 2.4v-5.7c0-.25.25-.5.5-.5h.6c.25 0 .5.25.5.5v5.8l2.3 -2.4a.5.5 0 0 1 .75 0z"),$h=new window.Path2D("M8.7 5.5a.5.5 0 0 0 0-.75l-3.8-4a.5.5 0 0 0-.75 0l-3.8 4a.5.5 0 0 0 0 .75l.4.4a.5.5 0 0 0 .75 0l2.3-2.4v5.8c0 .25.25.5.5.5h.6c.25 0 .5-.25.5-.5v-5.8l2.2 2.4a.5.5 0 0 0 .75 0z");let Gh=class e extends Vh{keyValue;baseline;baselineMode;baselineDescr;progressBar=!1;background;baselineColorUp;baselineColorDown;fontColor;humanize;type="scorecard";constructor(e,t,o){super(e,t,o),this.keyValue=Xr(o,t,e.keyValue),this.baseline=Xr(o,t,e.baseline),this.baselineMode=e.baselineMode,this.baselineDescr=e.baselineDescr,this.background=e.background,this.baselineColorUp=e.baselineColorUp??Ee,this.baselineColorDown=e.baselineColorDown??Re,this.humanize=e.humanize??!1}static validateChartDefinition(e,t){return e.checkValidations(t,Uh,Bh)}static getDefinitionFromContextCreation(e){return{background:e.background,type:"scorecard",keyValue:e.range?e.range[0].dataRange:void 0,title:e.title||{text:""},baselineMode:Ie,baselineColorUp:Ee,baselineColorDown:Re,baseline:e.auxiliaryRange||""}}static transformDefinition(e,t){let o,s;return e.baseline&&(o=Nc(zo(e.baseline),t)),e.keyValue&&(s=Nc(zo(e.keyValue),t)),{...e,baseline:o?qo(o):void 0,keyValue:s?qo(s):void 0}}duplicateInDuplicatedSheet(t){const o=dh(this.sheetId,t,this.baseline),s=dh(this.sheetId,t,this.keyValue),i=this.getDefinitionWithSpecificRanges(o,s,t);return new e(i,t,this.getters)}copyInSheetId(t){const o=this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue,t);return new e(o,t,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue)}getContextCreation(){return{...this,range:this.keyValue?[{dataRange:this.getters.getRangeString(this.keyValue,this.sheetId)}]:void 0,auxiliaryRange:this.baseline?this.getters.getRangeString(this.baseline,this.sheetId):void 0}}getDefinitionWithSpecificRanges(e,t,o){return{baselineColorDown:this.baselineColorDown,baselineColorUp:this.baselineColorUp,baselineMode:this.baselineMode,title:this.title,type:"scorecard",background:this.background,baseline:e?this.getters.getRangeString(e,o||this.sheetId):void 0,baselineDescr:this.baselineDescr,keyValue:t?this.getters.getRangeString(t,o||this.sheetId):void 0,humanize:this.humanize}}getDefinitionForExcel(){}updateRanges(t){const o=uh(this.baseline,t),s=uh(this.keyValue,t);if(this.baseline===o&&this.keyValue===s)return this;const i=this.getDefinitionWithSpecificRanges(o,s);return new e(i,this.sheetId,this.getters)}};function Wh(e,t){const o=t.getContext("2d"),s=window.devicePixelRatio||1;t.width=s*e.canvas.width,t.height=s*e.canvas.height,o.scale(s,s);const i=e.canvas.width-2*Z;if(o.fillStyle=e.canvas.backgroundColor,o.fillRect(0,0,e.canvas.width,e.canvas.height),e.title){o.font=e.title.style.font,o.fillStyle=e.title.style.color;const t=o.textBaseline;o.textBaseline="middle",o.fillText(Ca(o,e.title.text,i-e.title.position.x),e.title.position.x,e.title.position.y),o.textBaseline=t}if(e.baseline&&(o.font=e.baseline.style.font,o.fillStyle=e.baseline.style.color,wa(o,e.baseline.text,e.baseline.position,e.baseline.style.underline,e.baseline.style.strikethrough)),e.baselineArrow&&e.baselineArrow.style.size>0){o.save(),o.fillStyle=e.baselineArrow.style.color,o.translate(e.baselineArrow.position.x,e.baselineArrow.position.y);const t=e.baselineArrow.style.size/10;switch(o.scale(t,t),e.baselineArrow.direction){case"down":o.fill(zh);break;case"up":o.fill($h)}o.restore()}if(e.baselineDescr){const t=e.baselineDescr[0];o.font=t.style.font,o.fillStyle=t.style.color;for(const t of e.baselineDescr)o.fillText(Ca(o,t.text,i-t.position.x),t.position.x,t.position.y)}if(e.key&&(o.font=e.key.style.font,o.fillStyle=e.key.style.color,wa(o,Ca(o,e.key.text,i-e.key.position.x),e.key.position,e.key.style.underline,e.key.style.strikethrough)),e.progressBar){if(o.fillStyle=e.progressBar.style.backgroundColor,o.beginPath(),o.roundRect(e.progressBar.position.x,e.progressBar.position.y,e.progressBar.dimension.width,e.progressBar.dimension.height,e.progressBar.dimension.height/2),o.fill(),o.fillStyle=e.progressBar.style.color,o.beginPath(),e.progressBar.value>0)o.roundRect(e.progressBar.position.x,e.progressBar.position.y,e.progressBar.dimension.width*Math.max(0,Math.min(1,e.progressBar.value)),e.progressBar.dimension.height,e.progressBar.dimension.height/2);else{const t=e.progressBar.dimension.width*Math.max(0,Math.min(1,-e.progressBar.value));o.roundRect(e.progressBar.position.x+e.progressBar.dimension.width-t,e.progressBar.position.y,t,e.progressBar.dimension.height,e.progressBar.dimension.height/2)}o.fill()}}function qh(e,t){let o,s="";const i=t.getLocale();if(e.keyValue){const n={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};o=t.getEvaluatedCell(n),s=function(e,t,o){return e?t?fr(e,o):e.formattedValue??String(e.value??""):""}(o,e.humanize??!1,i)}let n;const r=e.baseline;if(r){const e={sheetId:r.sheetId,col:r.zone.left,row:r.zone.top};n=t.getEvaluatedCell(e)}const{background:a,fontColor:l}=t.getStyleOfSingleCellChart(e.background,e.keyValue),c=function(e,t,o,s,i){if(!e)return"";if("text"===o||t?.type!==oi.number||e.type!==oi.number)return s?fr(e,i):e.formattedValue;let{value:n,format:r}=e;return"progress"===o?(n=t.value/n,r="0.0%"):(n=Math.abs(t.value-n),"percentage"===o&&0!==n&&(n/=e.value),"percentage"===o&&(r="0.0%"),r||(n=Math.round(100*n)/100)),s?fr({value:n,format:r},i):Kn(n,{format:r,locale:i})}(n,o,e.baselineMode,e.humanize??!1,i),h="progress"===e.baselineMode&&Js(c,i)?ki(c,i):0;return{title:{...e.title,text:e.title.text?Uo(e.title.text):""},keyValue:s,baselineDisplay:c,baselineArrow:Hh(n,o,e.baselineMode),baselineColor:Lh(n,e.baselineMode,o,e.baselineColorUp,e.baselineColorDown),baselineDescr:"progress"!==e.baselineMode&&e.baselineDescr?Uo(e.baselineDescr):"",fontColor:l,background:a,baselineStyle:"percentage"!==e.baselineMode&&"progress"!==e.baselineMode&&r?t.getCellStyle({sheetId:r.sheetId,col:r.zone.left,row:r.zone.top}):void 0,keyValueStyle:e.keyValue?t.getCellStyle({sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top}):void 0,progressBar:"progress"===e.baselineMode?{value:h,color:h>0?e.baselineColorUp:e.baselineColorDown}:void 0}}const Zh=10,jh=.05;function Yh({width:e,height:t},o){return new Xh({width:e,height:t},o).computeDesign()}class Xh{runtime;context;width;height;constructor({width:e,height:t},o){this.runtime=o;const s=document.createElement("canvas");this.width=s.width=e,this.height=s.height=t,this.context=s.getContext("2d")}computeDesign(){const e={canvas:{width:this.width,height:this.height,backgroundColor:this.backgroundColor}},t=this.getTextStyles();let o=0;if(this.title){let s,i;switch(({height:o,width:i}=this.getFullTextDimensions(this.title,t.title.font)),this.runtime.title.align){case"center":s=(this.width-i)/2;break;case"right":s=this.width-i-Zh;break;default:s=Zh}e.title={text:this.title,style:t.title,position:{x:s,y:Zh+o/2}}}const s=t.baselineArrow?.size??0;let{height:i,width:n}=this.getTextDimensions(this.baseline,t.baselineValue.font);this.baseline||(i=this.getTextDimensions(this.baselineDescr,t.baselineDescr.font).height);const r=this.getTextDimensions(this.baselineDescr,t.baselineDescr.font).width;e.baseline={text:this.baseline,style:t.baselineValue,position:{x:(this.width-n-r+s)/2,y:this.keyValue?this.height*(1-jh*(this.runtime.progressBar?1:2)):this.height-(this.height-o-i)/2-Zh}};const a=s+20;if(e.baseline.position.x<a&&(e.baseline.position.x=a),t.baselineArrow&&!this.runtime.progressBar&&(e.baselineArrow={direction:this.baselineArrow,style:t.baselineArrow,position:{x:e.baseline.position.x-s,y:e.baseline.position.y-(i+s)/2}}),this.baselineDescr){const o={x:e.baseline.position.x+n,y:e.baseline.position.y};e.baselineDescr=[{text:this.baselineDescr,style:t.baselineDescr,position:o}]}let l=0;this.runtime.progressBar&&(l=.05*this.height,e.progressBar={position:{x:20,y:.9*this.height-i-l},dimension:{height:l,width:this.width-40},value:this.runtime.progressBar.value,style:{color:this.runtime.progressBar.color,backgroundColor:this.secondaryFontColor}});const{width:c,height:h}=this.getFullTextDimensions(this.keyValue,t.keyValue.font);return this.keyValue&&(e.key={text:this.keyValue,style:t.keyValue,position:{x:Math.max(Zh,(this.width-c)/2),y:.4*this.height+5+(o+h/2)/2}}),e}get title(){return this.runtime.title.text??""}get keyValue(){return this.runtime.keyValue}get baseline(){return this.runtime.baselineDisplay}get baselineDescr(){return function(e,t){const o=e||"";return t&&o?" "+o:o}(this.runtime.baselineDescr,this.baseline)}get baselineArrow(){return this.runtime.baselineArrow}get backgroundColor(){return this.runtime.background}get secondaryFontColor(){return Sh(this.backgroundColor)}getTextDimensions(e,t){this.context.font=t;const o=this.context.measureText(e);return{width:o.width,height:o.actualBoundingBoxAscent+o.actualBoundingBoxDescent}}getFullTextDimensions(e,t){this.context.font=t;const o=this.context.measureText(e);return{width:o.width,height:o.fontBoundingBoxAscent+o.fontBoundingBoxDescent}}getTextStyles(){let e=16;const t=Math.floor(.9*e);return this.runtime.progressBar&&(e/=1.5),{title:{font:la(this.runtime.title.fontSize??14,this.runtime.title.bold,this.runtime.title.italic),color:this.runtime.title.color??this.secondaryFontColor},keyValue:{color:this.runtime.keyValueStyle?.textColor||this.runtime.fontColor,font:la(32,this.runtime.keyValueStyle?.bold,this.runtime.keyValueStyle?.italic),strikethrough:this.runtime.keyValueStyle?.strikethrough,underline:this.runtime.keyValueStyle?.underline},baselineValue:{font:la(e,this.runtime.baselineStyle?.bold,this.runtime.baselineStyle?.italic),strikethrough:this.runtime.baselineStyle?.strikethrough,underline:this.runtime.baselineStyle?.underline,color:this.runtime.baselineStyle?.textColor||this.runtime.baselineColor||this.secondaryFontColor},baselineDescr:{font:la(t),color:this.secondaryFontColor},baselineArrow:"neutral"===this.baselineArrow||this.runtime.progressBar?void 0:{size:this.keyValue?.8*e:0,color:this.runtime.baselineColor||this.secondaryFontColor}}}}class Kh extends t.Component{static template="o-spreadsheet-ScorecardChart";static props={figure:Object};canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}get title(){const e=this.env.model.getters.getChartDefinition(this.props.figure.id).title.text??"";return Uo(e)}setup(){t.useEffect(this.createChart.bind(this),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el,window.devicePixelRatio]}))}createChart(){const e=this.canvas.el;Wh(Yh(e.getBoundingClientRect(),this.runtime),e)}}const Jh=new n;function Qh(e,t,o,s){const i=[];e=e.toLowerCase();for(const n of e){const e=t.toLocaleLowerCase().indexOf(n);-1!==e&&(i.push({value:t.slice(0,e),color:""},{value:t[e],color:o,class:s}),t=t.slice(e+1))}return i.push({value:t}),i.filter((e=>e.value))}Jh.add("dataValidation",{displayAllOnInitialContent:!0,getProposals(e,t){if(t.startsWith("="))return[];if(!this.composer.currentEditedCell)return[];const o=this.composer.currentEditedCell,s=this.getters.getValidationRuleForCell(o);if(!s||"isValueInList"!==s.criterion.type&&"isValueInRange"!==s.criterion.type)return[];let i;if("isValueInList"===s.criterion.type)i=s.criterion.values;else{const e=this.getters.getRangeFromSheetXC(o.sheetId,s.criterion.values[0]);i=Array.from(new Set(this.getters.getRangeValues(e).filter(ct).map((e=>e.toString())).filter((e=>""!==e))))}return i.map((e=>({text:e})))},selectProposal(e,t){this.composer.setCurrentContent(t),this.composer.stopEdition()}});const ed=/(.*?)\((.*?)\)(.*)/,td=["ANY","BOOLEAN","DATE","NUMBER","STRING","RANGE","RANGE<BOOLEAN>","RANGE<DATE>","RANGE<NUMBER>","RANGE<STRING>","META"];function od(e,t=""){return function(e,t){let o=e.match(ed),s=o[1].trim();if(!s)throw new Error(`Function argument definition is missing a name: '${e}'.`);let i,n=[],r=!1,a=!1;for(let e of o[2].split(",")){const t=e.trim().toUpperCase();let o=td.find((e=>t===e));o?n.push(o):"RANGE<ANY>"===t?n.push("RANGE"):"OPTIONAL"===t?r=!0:"REPEATING"===t?a=!0:t.startsWith("DEFAULT=")&&(i=e.trim().slice(8))}const l={name:s,description:t,type:n};(n.includes("ANY")||n.includes("RANGE"))&&(l.acceptErrors=!0);r&&(l.optional=!0);a&&(l.repeating=!0);void 0!==i&&(l.default=!0,l.defaultValue=i);n.some((e=>e.startsWith("RANGE")))&&(l.acceptMatrix=!0);n.every((e=>e.startsWith("RANGE")))&&(l.acceptMatrixOnly=!0);return l}(e,t)}function sd(e){let t=0,o=0,s=0;for(let i of e.args)t++,i.optional||i.repeating||i.default||o++,i.repeating&&s++;const i=e;return i.minArgRequired=o,i.maxArgPossible=s?1/0:t,i.nbrArgRepeating=s,i.getArgToFocus=function(e,t){if(!t)return e=>e;if(1===t)return t=>Math.min(t,e);const o=e-t;return e=>{if(e<=o)return e;return o+((e-o)%t||t)}}(t,s),i.hidden=e.hidden||!1,i}function id(e,t){Fi((()=>1===t.length||1===t[0].length),e)}function nd(e,...t){if(t.every(bi)){const o=t[0].length,s=t[0][0].length;for(const i of t)Fi((()=>i.length===o&&i[0].length===s),e)}else if(t.some((e=>Array.isArray(e)&&(1!==e.length||1!==e[0].length))))throw new Ii(e)}function rd(e,t){Fi((()=>t>0),e)}function ad(e,t){Fi((()=>t.length===t[0].length),e)}const ld={description:Uo("Returns a result array constrained to a specific width and height."),args:[od("input_range (any, range<any>)",Uo("The range to constrain.")),od("rows (number)",Uo("The number of rows in the constrained array.")),od("columns (number)",Uo("The number of columns in the constrained array."))],compute:function(e,t,o){const s=vn(e),i=Ui(t?.value,this.locale),n=Ui(o?.value,this.locale);rd(Uo("The rows argument (%s) must be strictly positive.",i.toString()),i),rd(Uo("The columns argument (%s) must be strictly positive.",i.toString()),n);const r=Math.min(i,s[0].length);return sn(Math.min(n,s.length),r,((e,t)=>s[e][t]))},isExported:!1},cd={description:Uo("Creates a new array from the selected columns in the existing range."),args:[od("array (any, range<any>)",Uo("The array that contains the columns to be returned.")),od("col_num (number, range<number>)",Uo("The first column index of the columns to be returned.")),od("col_num2 (number, range<number>, repeating)",Uo("The columns indexes of the columns to be returned."))],compute:function(e,...t){const o=vn(e),s=bn(t,(e=>Ui(e?.value,this.locale))),i=s.filter((e=>0===e||o.length<Math.abs(e)));Fi((()=>0===i.length),Uo("The columns arguments must be between -%s and %s (got %s), excluding 0.",o.length.toString(),o.length.toString(),i.join(",")));const n=Array(s.length);for(let e=0;e<s.length;e++)s[e]>0?n[e]=o[s[e]-1]:n[e]=o[o.length+s[e]];return n},isExported:!0},hd={description:Uo("Creates a new array from the selected rows in the existing range."),args:[od("array (any, range<any>)",Uo("The array that contains the rows to be returned.")),od("row_num (number, range<number>)",Uo("The first row index of the rows to be returned.")),od("row_num2 (number, range<number>, repeating)",Uo("The rows indexes of the rows to be returned."))],compute:function(e,...t){const o=vn(e),s=bn(t,(e=>Ui(e?.value,this.locale))),i=o.length,n=s.filter((e=>0===e||o[0].length<Math.abs(e)));return Fi((()=>0===n.length),Uo("The rows arguments must be between -%s and %s (got %s), excluding 0.",o[0].length.toString(),o[0].length.toString(),n.join(","))),sn(i,s.length,((e,t)=>s[t]>0?o[e][s[t]-1]:o[e][o[e].length+s[t]]))},isExported:!0},dd={description:Uo("Expands or pads an array to specified row and column dimensions."),args:[od("array (any, range<any>)",Uo("The array to expand.")),od("rows (number)",Uo("The number of rows in the expanded array. If missing, rows will not be expanded.")),od("columns (number, optional)",Uo("The number of columns in the expanded array. If missing, columns will not be expanded.")),od("pad_with (any, default=0)",Uo("The value with which to pad."))],compute:function(e,t,o,s={value:0}){const i=vn(e),n=Ui(t?.value,this.locale),r=void 0!==o?Ui(o.value,this.locale):i.length;return Fi((()=>n>=i[0].length),Uo("The rows arguments (%s) must be greater or equal than the number of rows of the array.",n.toString())),Fi((()=>r>=i.length),Uo("The columns arguments (%s) must be greater or equal than the number of columns of the array.",r.toString())),sn(r,n,((e,t)=>e>=i.length||t>=i[e].length?s:i[e][t]))},isExported:!0},ud={description:Uo("Flattens all the values from one or more ranges into a single column."),args:[od("range (any, range<any>)",Uo("The first range to flatten.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to flatten."))],compute:function(...e){return[bn(e,(e=>void 0===e?{value:""}:e))]},isExported:!1},gd={description:Uo("Calculates the frequency distribution of a range."),args:[od("data (range<number>)",Uo("The array of ranges containing the values to be counted.")),od("classes (number, range<number>)",Uo("The range containing the set of classes."))],compute:function(e,t){const o=bn([e],(e=>e.value)).filter((e=>"number"==typeof e)),s=bn([t],(e=>e.value)).filter((e=>"number"==typeof e)),i=s.map(((e,t)=>({initialIndex:t,value:e,count:0}))).sort(((e,t)=>e.value-t.value));i.push({initialIndex:i.length,value:1/0,count:0});const n=o.sort(((e,t)=>e-t));let r=0;for(const e of n){for(;e>i[r].value&&r<i.length-1;)r++;i[r].count++}return[i.sort(((e,t)=>e.initialIndex-t.initialIndex)).map((e=>e.count))]},isExported:!0},pd={description:Uo("Appends ranges horizontally and in sequence to return a larger array."),args:[od("range1 (any, range<any>)",Uo("The first range to be appended.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to add to range1."))],compute:function(...e){const t=Math.max(...e.map((e=>e?.[0]?.length??0))),o=[];for(const s of e){const e=vn(s);for(let s=0;s<e.length;s++){const i=Array(t).fill({value:null});for(let t=0;t<e[s].length;t++)i[t]=e[s][t];o.push(i)}}return o},isExported:!0},md={description:Uo("Returns the matrix determinant of a square matrix."),args:[od("square_matrix (number, range<number>)",Uo("An range with an equal number of rows and columns representing a matrix whose determinant will be calculated."))],compute:function(e){const t=Li(e,"square_matrix");return ad(Uo("The argument square_matrix must have the same number of columns and rows."),t),fl(t).determinant},isExported:!0},fd={description:Uo("Returns the multiplicative inverse of a square matrix."),args:[od("square_matrix (number, range<number>)",Uo("An range with an equal number of rows and columns representing a matrix whose multiplicative inverse will be calculated."))],compute:function(e){const t=Li(e,"square_matrix");ad(Uo("The argument square_matrix must have the same number of columns and rows."),t);const{inverted:o}=fl(t);return o||new Ii(Uo("The matrix is not invertible."))},isExported:!0},vd={description:Uo("Calculates the matrix product of two matrices."),args:[od("matrix1 (number, range<number>)",Uo("The first matrix in the matrix multiplication operation.")),od("matrix2 (number, range<number>)",Uo("The second matrix in the matrix multiplication operation."))],compute:function(e,t){const o=Li(e,"matrix1"),s=Li(t,"matrix2");return Fi((()=>o.length===s[0].length),Uo("In [[FUNCTION_NAME]], the number of columns of the first matrix (%s) must be equal to the number of rows of the second matrix (%s).",o.length.toString(),s[0].length.toString())),bl(o,s)},isExported:!0},bd={description:Uo("Calculates the sum of the products of corresponding entries in equal-sized ranges."),args:[od("range1 (number, range<number>)",Uo("The first range whose entries will be multiplied with corresponding entries in the other ranges.")),od("range2 (number, range<number>, repeating)",Uo("The other range whose entries will be multiplied with corresponding entries in the other ranges."))],compute:function(...e){nd(Uo("All the ranges must have the same dimensions."),...e);const t=e.map(vn);let o=0;for(let e=0;e<t[0].length;e++)for(let s=0;s<t[0][e].length;s++){if(!t.every((t=>"number"==typeof t[e][s].value)))continue;let i=1;for(const o of t)i*=ki(o[e][s],this.locale);o+=i}return o},isExported:!0};function Sd(e,t,o){nd("The arguments array_x and array_y must have the same dimensions.",e,t);const s=vn(e),i=vn(t);let n=!1,r=0;for(const e in s)for(const t in s[e]){const a=s[e][t].value,l=i[e][t].value;"number"==typeof a&&"number"==typeof l&&(n=!0,r+=o(a,l))}return n?r:new Ii(Uo("The arguments array_x and array_y must contain at least one pair of numbers."))}const yd={description:Uo("Calculates the sum of the difference of the squares of the values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values whose squares will be reduced by the squares of corresponding entries in array_y and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values whose squares will be subtracted from the squares of corresponding entries in array_x and added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>e**2-t**2))},isExported:!0},Cd={description:Uo("Calculates the sum of the sum of the squares of the values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values whose squares will be added to the squares of corresponding entries in array_y and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values whose squares will be added to the squares of corresponding entries in array_x and added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>e**2+t**2))},isExported:!0},wd={description:Uo("Calculates the sum of squares of the differences of values in two array."),args:[od("array_x (number, range<number>)",Uo("The array or range of values that will be reduced by corresponding entries in array_y, squared, and added together.")),od("array_y (number, range<number>)",Uo("The array or range of values that will be subtracted from corresponding entries in array_x, the result squared, and all such results added together."))],compute:function(e,t){return Sd(e,t,((e,t)=>(e-t)**2))},isExported:!0},xd=!1,Id=[od("array (any, range<any>)",Uo("The array which will be transformed.")),od("ignore (number, default=0)",Uo("The control to ignore blanks and errors. 0 (default) is to keep all values, 1 is to ignore blanks, 2 is to ignore errors, and 3 is to ignore blanks and errors.")),od("scan_by_column (number, default=false)",Uo("Whether the array should be scanned by column. True scans the array by column and false (default) scans the array by row."))];function Ed(e){const t=Math.trunc(e);if(0===t)return()=>!0;if(1===t)return e=>null!==e.value;if(2===t)return e=>!Pi(e.value);if(3===t)return e=>null!==e.value&&!Pi(e.value);throw new Ii(Uo("Argument ignore must be between 0 and 3"))}const Rd={description:Uo("Transforms a range of cells into a single column."),args:Id,compute:function(e,t={value:0},o={value:xd}){const s=vn(e),i=ki(t.value,this.locale),n=(Zi(o.value)?s:rn(s)).flat().filter(Ed(i));return 0===n.length?new Ai(Uo("No results for the given arguments of TOCOL.")):[n]},isExported:!0},Td={description:Uo("Transforms a range of cells into a single row."),args:Id,compute:function(e,t={value:0},o={value:xd}){const s=vn(e),i=ki(t.value,this.locale),n=(Zi(o.value)?s:rn(s)).flat().filter(Ed(i)).map((e=>[e]));return 0===n.length||0===n[0].length?new Ai(Uo("No results for the given arguments of TOROW.")):n},isExported:!0},Ad={description:Uo("Transposes the rows and columns of a range."),args:[od("range (any, range<any>)",Uo("The range to be transposed."))],compute:function(e){const t=vn(e);return sn(t[0].length,t.length,((e,o)=>t[o][e]))},isExported:!0},_d={description:Uo("Appends ranges vertically and in sequence to return a larger array."),args:[od("range1 (any, range<any>)",Uo("The first range to be appended.")),od("range2 (any, range<any>, repeating)",Uo("Additional ranges to add to range1."))],compute:function(...e){const t=Math.max(...e.map((e=>vn(e).length))),o=e.reduce(((e,t)=>e+vn(t)[0].length),0),s=Array(t).fill([]).map((()=>Array(o).fill({value:0})));let i=0;for(const t of e){const e=vn(t);for(let t=0;t<e.length;t++)for(let o=0;o<e[t].length;o++)s[t][i+o]=e[t][o];i+=e[0].length}return s},isExported:!0},Dd={description:Uo("Wraps the provided row or column of cells by columns after a specified number of elements to form a new array."),args:[od("range (any, range<any>)",Uo("The range to wrap.")),od("wrap_count (number)",Uo("The maximum number of cells for each column, rounded down to the nearest whole number.")),od("pad_with (any, default=0)",Uo("The value with which to fill the extra cells in the range."))],compute:function(e,t,o={value:0}){const s=vn(e),i=Ui(t?.value,this.locale);id(Uo("Argument range must be a single row or column."),s);const n=s.flat();return sn(Math.ceil(n.length/i),i,((e,t)=>{const s=e*i+t;return s<n.length?n[s]:o}))},isExported:!0},Od={description:Uo("Wraps the provided row or column of cells by rows after a specified number of elements to form a new array."),args:[od("range (any, range<any>)",Uo("The range to wrap.")),od("wrap_count (number)",Uo("The maximum number of cells for each row, rounded down to the nearest whole number.")),od("pad_with (any, default=0)",Uo("The value with which to fill the extra cells in the range."))],compute:function(e,t,o={value:0}){const s=vn(e),i=Ui(t?.value,this.locale);id(Uo("Argument range must be a single row or column."),s);const n=s.flat(),r=Math.ceil(n.length/i);return sn(i,r,((e,t)=>{const s=t*i+e;return s<n.length?n[s]:o}))},isExported:!0};var Fd=Object.freeze({__proto__:null,ARRAY_CONSTRAIN:ld,CHOOSECOLS:cd,CHOOSEROWS:hd,EXPAND:dd,FLATTEN:ud,FREQUENCY:gd,HSTACK:pd,MDETERM:md,MINVERSE:fd,MMULT:vd,SUMPRODUCT:bd,SUMX2MY2:yd,SUMX2PY2:Cd,SUMXMY2:wd,TOCOL:Rd,TOROW:Td,TRANSPOSE:Ad,VSTACK:_d,WRAPCOLS:Dd,WRAPROWS:Od});const Md={description:Uo("Apply a large number format"),args:[od("value (number)",Uo("The number.")),od("unit (string, optional)",Uo("The formatting unit. Use 'k', 'm', or 'b' to force the unit"))],compute:function(e,t){return{value:ki(e,this.locale),format:vr(e,t,this.locale)}}};var Pd=Object.freeze({__proto__:null,FORMAT_LARGE_NUMBER:Md});const Nd=/^-?[a-z0-9]+$/i,kd={description:Uo("Absolute value of a number."),args:[od("value (number)",Uo("The number of which to return the absolute value."))],compute:function(e){return Math.abs(ki(e,this.locale))},isExported:!0},Vd={description:Uo("Inverse cosine of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse cosine. Must be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<=1),Uo("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.acos(t)},isExported:!0},Ld={description:Uo("Inverse hyperbolic cosine of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic cosine. Must be greater than or equal to 1."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>=1),Uo("The value (%s) must be greater than or equal to 1.",t.toString())),Math.acosh(t)},isExported:!0},Hd={description:Uo("Inverse cotangent of a value."),args:[od("value (number)",Uo("The value for which to calculate the inverse cotangent."))],compute:function(e){const t=ki(e,this.locale);return(Math.sign(t)||1)*Math.PI/2-Math.atan(t)},isExported:!0},Ud={description:Uo("Inverse hyperbolic cotangent of a value."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic cotangent. Must not be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)>1),Uo("The value (%s) cannot be between -1 and 1 inclusive.",t.toString())),Math.log((t+1)/(t-1))/2},isExported:!0},Bd={description:Uo("Inverse sine of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse sine. Must be between -1 and 1, inclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<=1),Uo("The value (%s) must be between -1 and 1 inclusive.",t.toString())),Math.asin(t)},isExported:!0},zd={description:Uo("Inverse hyperbolic sine of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic sine."))],compute:function(e){return Math.asinh(ki(e,this.locale))},isExported:!0},$d={description:Uo("Inverse tangent of a value, in radians."),args:[od("value (number)",Uo("The value for which to calculate the inverse tangent."))],compute:function(e){return Math.atan(ki(e,this.locale))},isExported:!0},Gd={description:Uo("Angle from the X axis to a point (x,y), in radians."),args:[od("x (number)",Uo("The x coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis.")),od("y (number)",Uo("The y coordinate of the endpoint of the line segment for which to calculate the angle from the x-axis."))],compute:function(e,t){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>0!==o||0!==s),Uo("Function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero),Math.atan2(s,o)},isExported:!0},Wd={description:Uo("Inverse hyperbolic tangent of a number."),args:[od("value (number)",Uo("The value for which to calculate the inverse hyperbolic tangent. Must be between -1 and 1, exclusive."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>Math.abs(t)<1),Uo("The value (%s) must be between -1 and 1 exclusive.",t.toString())),Math.atanh(t)},isExported:!0},qd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("value (number)",Uo("The value to round up to the nearest integer multiple of factor.")),od("factor (number, default=1)",Uo("The number to whose multiples value will be rounded."))],compute:function(e,t={value:1}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>s>=0||o<=0),Uo("The factor (%s) must be positive when the value (%s) is positive.",s.toString(),o.toString())),{value:s?Math.ceil(o/s)*s:0,format:e?.format}},isExported:!0};function Zd(e,t,o=0){return 0===t?0:(t=Math.abs(t),e>=0?Math.ceil(e/t)*t:0===o?-Math.floor(Math.abs(e)/t)*t:-Math.ceil(Math.abs(e)/t)*t)}const jd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded. The sign of significance will be ignored.")),od("mode (number, default=0)",Uo("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded towards zero. Otherwise, it is rounded away from zero."))],compute:function(e,t={value:1},o={value:0}){const s=ki(t,this.locale);return{value:Zd(ki(e,this.locale),s,ki(o,this.locale)),format:e?.format}},isExported:!0},Yd={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){const o=ki(t,this.locale);return{value:Zd(ki(e,this.locale),o),format:e?.format}},isExported:!0},Xd={description:Uo("Cosine of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cosine of, in radians."))],compute:function(e){return Math.cos(ki(e,this.locale))},isExported:!0},Kd={description:Uo("Hyperbolic cosine of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cosine of."))],compute:function(e){return Math.cosh(ki(e,this.locale))},isExported:!0},Jd={description:Uo("Cotangent of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cotangent of, in radians."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.tan(t)},isExported:!0},Qd={description:Uo("Hyperbolic cotangent of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cotangent of."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.tanh(t)},isExported:!0},eu={description:Uo("Number of empty values."),args:[od("value1 (any, range)",Uo("The first value or range in which to count the number of blanks.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges in which to count the number of blanks."))],compute:function(...e){return en(e,((e,t)=>void 0===t||null===t.value||""===t.value?e+1:e),0)},isExported:!0},tu={description:Uo("A conditional count across a range."),args:[od("range (range)",Uo("The range that is tested against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to range."))],compute:function(...e){let t=0;return un(e,((e,o)=>{t+=1}),this.locale),t},isExported:!0},ou={description:Uo("Count values depending on multiple criteria."),args:[od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("Additional criteria to check."))],compute:function(...e){let t=0;return un(e,((e,o)=>{t+=1}),this.locale),t},isExported:!0},su={description:Uo("Counts number of unique values in a range."),args:[od("value1 (any, range)",Uo("The first value or range to consider for uniqueness.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider for uniqueness."))],compute:function(...e){return pl(e)}},iu={description:Uo("Counts number of unique values in a range, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the number of unique values will be counted.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=new Set;return un(t,((t,s)=>{const i=e[t]?.[s];Sn(i)&&o.add(i.value)}),this.locale),o.size}},nu={description:Uo("Cosecant of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the cosecant of, in radians."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.sin(t)},isExported:!0},ru={description:Uo("Hyperbolic cosecant of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic cosecant of."))],compute:function(e){const t=ki(e,this.locale);return $i(t),1/Math.sinh(t)},isExported:!0},au={description:Uo("Converts from another base to decimal."),args:[od("value (string)",Uo("The number to convert.")),od("base (number)",Uo("The base to convert the value from."))],compute:function(e,t){let o=ki(t,this.locale);o=Math.floor(o),Fi((()=>2<=o&&o<=36),Uo("The base (%s) must be between 2 and 36 inclusive.",o.toString()));const s=Gi(e);if(""===s)return 0;Fi((()=>Nd.test(s)),Uo("The value (%s) must be a valid base %s representation.",s,o.toString()));const i=parseInt(s,o);return Fi((()=>!isNaN(i)),Uo("The value (%s) must be a valid base %s representation.",s,o.toString())),i},isExported:!0},lu={description:Uo("Converts an angle value in radians to degrees."),args:[od("angle (number)",Uo("The angle to convert from radians to degrees."))],compute:function(e){return 180*ki(e,this.locale)/Math.PI},isExported:!0},cu={description:Uo("Euler's number, e (~2.718) raised to a power."),args:[od("value (number)",Uo("The exponent to raise e."))],compute:function(e){return Math.exp(ki(e,this.locale))},isExported:!0},hu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("value (number)",Uo("The value to round down to the nearest integer multiple of factor.")),od("factor (number, default=1)",Uo("The number to whose multiples value will be rounded."))],compute:function(e,t={value:1}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>s>=0||o<=0),Uo("The factor (%s) must be positive when the value (%s) is positive.",s.toString(),o.toString())),{value:s?Math.floor(o/s)*s:0,format:e?.format}},isExported:!0};function du(e,t,o=0){return 0===t?0:(t=Math.abs(t),e>=0?Math.floor(e/t)*t:0===o?-Math.ceil(Math.abs(e)/t)*t:-Math.floor(Math.abs(e)/t)*t)}const uu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round down to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded. The sign of significance will be ignored.")),od("mode (number, default=0)",Uo("If number is negative, specifies the rounding direction. If 0 or blank, it is rounded away from zero. Otherwise, it is rounded towards zero."))],compute:function(e,t={value:1},o={value:0}){const s=ki(t,this.locale);return{value:du(ki(e,this.locale),s,ki(o,this.locale)),format:e?.format}},isExported:!0},gu={description:Uo("Rounds number down to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round down to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){const o=ki(t,this.locale);return{value:du(ki(e,this.locale),o),format:e?.format}},isExported:!0},pu={description:Uo("Whether the provided value is even."),args:[od("value (number)",Uo("The value to be verified as even."))],compute:function(e){const t=Hi(e,this.locale);return!(1&Math.floor(Math.abs(t)))},isExported:!0},mu={description:Uo("Rounds number up to nearest multiple of factor."),args:[od("number (number)",Uo("The value to round up to the nearest integer multiple of significance.")),od("significance (number, default=1)",Uo("The number to whose multiples number will be rounded."))],compute:function(e,t={value:1}){return{value:Zd(ki(e,this.locale),ki(t,this.locale)),format:e?.format}},isExported:!0},fu={description:Uo("Whether the provided value is even."),args:[od("value (number)",Uo("The value to be verified as even."))],compute:function(e){const t=Hi(e,this.locale);return!!(1&Math.floor(Math.abs(t)))},isExported:!0},vu={description:Uo("The logarithm of a number, base e (euler's number)."),args:[od("value (number)",Uo("The value for which to calculate the logarithm, base e."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>0),Uo("The value (%s) must be strictly positive.",t.toString())),Math.log(t)},isExported:!0},bu={description:Uo("The logarithm of a number, for a given base."),args:[od("value (number)",Uo("The value for which to calculate the logarithm.")),od("base (number, default=10)",Uo("The base of the logarithm."))],compute:function(e,t={value:10}){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>o>0),Uo("The value (%s) must be strictly positive.",o.toString())),Fi((()=>s>0),Uo("The base (%s) must be strictly positive.",s.toString())),Fi((()=>1!==s),Uo("The base must be different from 1.")),Math.log10(o)/Math.log10(s)},isExported:!0};function Su(e,t){Fi((()=>0!==t),Uo("The divisor must be different from 0."),wi.DivisionByZero);const o=e%t;return o>0&&t<0||o<0&&t>0?o+t:o}const yu={description:Uo("Modulo (remainder) operator."),args:[od("dividend (number)",Uo("The number to be divided to find the remainder.")),od("divisor (number)",Uo("The number to divide by."))],compute:function(e,t){const o=ki(t,this.locale);return{value:Su(ki(e,this.locale),o),format:e?.format}},isExported:!0},Cu={description:Uo("Returns a n x n unit matrix, where n is the input dimension."),args:[od("dimension (number)",Uo("An integer specifying the dimension size of the unit matrix. It must be positive."))],compute:function(e){const t=Ui(e,this.locale);return rd(Uo("The argument dimension must be positive"),t),ml(t)},isExported:!0},wu={description:Uo("Rounds a number up to the nearest odd integer."),args:[od("value (number)",Uo("The value to round to the next greatest odd number."))],compute:function(e){const t=ki(e,this.locale);let o=Math.ceil(Math.abs(t));return o=1&o?o:o+1,{value:t<0?-o:o,format:e?.format}},isExported:!0},xu={description:Uo("The number pi."),args:[],compute:function(){return Math.PI},isExported:!0},Iu={description:Uo("A number raised to a power."),args:[od("base (number)",Uo("The number to raise to the exponent power.")),od("exponent (number)",Uo("The exponent to raise base to."))],compute:function(e,t){const o=ki(e,this.locale),s=ki(t,this.locale);return Fi((()=>o>=0||Number.isInteger(s)),Uo("The exponent (%s) must be an integer when the base is negative.",s.toString())),{value:Math.pow(o,s),format:e?.format}},isExported:!0},Eu={description:Uo("Result of multiplying a series of numbers together."),args:[od("factor1 (number, range<number>)",Uo("The first number or range to calculate for the product.")),od("factor2 (number, range<number>, repeating)",Uo("More numbers or ranges to calculate for the product."))],compute:function(...e){let t=0,o=1;for(let s of e)if(bi(s))for(let e of s)for(let s of e){const e=s.value;if("number"==typeof e&&(o*=e,t+=1),Pi(e))return s}else void 0!==s&&null!==s.value&&(o*=Hi(s,this.locale),t+=1);return{value:0===t?0:o,format:Mi(e[0])}},isExported:!0},Ru={description:Uo("A random number between 0 inclusive and 1 exclusive."),args:[],compute:function(){return Math.random()},isExported:!0},Tu={description:Uo("Returns a grid of random numbers between 0 inclusive and 1 exclusive."),args:[od("rows (number, default=1)",Uo("The number of rows to be returned.")),od("columns (number, default=1)",Uo("The number of columns to be returned.")),od("min (number, default=0)",Uo("The minimum number you would like returned.")),od("max (number, default=1)",Uo("The maximum number you would like returned.")),od("whole_number (number, default=FALSE)",Uo("Return a whole number or a decimal value."))],compute:function(e={value:1},t={value:1},o={value:0},s={value:1},i={value:!1}){const n=Ui(t,this.locale),r=Ui(e,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i);rd(Uo("The number of columns (%s) must be positive.",n.toString()),n),rd(Uo("The number of rows (%s) must be positive.",r.toString()),r),Fi((()=>a<=l),Uo("The maximum (%s) must be greater than or equal to the minimum (%s).",l.toString(),a.toString())),c&&Fi((()=>Number.isInteger(a)&&Number.isInteger(l)),Uo("The maximum (%s) and minimum (%s) must be integers when whole_number is TRUE.",l.toString(),a.toString()));const h=Array(n);for(let e=0;e<n;e++){h[e]=Array(r);for(let t=0;t<r;t++)h[e][t]=c?Math.floor(Math.random()*(l-a+1)+a):a+Math.random()*(l-a)}return h},isExported:!0},Au={description:Uo("Random integer between two values, inclusive."),args:[od("low (number)",Uo("The low end of the random range.")),od("high (number)",Uo("The high end of the random range."))],compute:function(e,t){let o=ki(e,this.locale);Number.isInteger(o)||(o=Math.ceil(o));let s=ki(t,this.locale);return Number.isInteger(s)||(s=Math.floor(s)),Fi((()=>o<=s),Uo("The high (%s) must be greater than or equal to the low (%s).",s.toString(),o.toString())),{value:o+Math.ceil((s-o+1)*Math.random())-1,format:e?.format}},isExported:!0},_u={description:Uo("Rounds a number according to standard rules."),args:[od("value (number)",Uo("The value to round to places number of places.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.round(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.round(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Du={description:Uo("Rounds down a number."),args:[od("value (number)",Uo("The value to round to places number of places, always rounding down.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.floor(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.floor(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Ou={description:Uo("Rounds up a number."),args:[od("value (number)",Uo("The value to round to places number of places, always rounding up.")),od("places (number, default=0)",Uo("The number of decimal places to which to round."))],compute:function(e,t={value:0}){const o=ki(e,this.locale);let s=ki(t,this.locale);const i=Math.abs(o);let n;return 0===s?n=Math.ceil(i):(Number.isInteger(s)||(s=Math.trunc(s)),n=Math.ceil(i*Math.pow(10,s))/Math.pow(10,s)),{value:o>=0?n:-n,format:e?.format}},isExported:!0},Fu={description:Uo("Secant of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the secant of, in radians."))],compute:function(e){return 1/Math.cos(ki(e,this.locale))},isExported:!0},Mu={description:Uo("Hyperbolic secant of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic secant of."))],compute:function(e){return 1/Math.cosh(ki(e,this.locale))},isExported:!0},Pu={description:Uo("Returns a sequence of numbers."),args:[od("rows (number)",Uo("The number of rows to return")),od("columns (number, optional, default=1)",Uo("The number of columns to return")),od("start (number, optional, default=1)",Uo("The first number in the sequence")),od("step (number, optional, default=1)",Uo("The amount to increment each value in the sequence"))],compute:function(e,t={value:1},o={value:1},s={value:1}){const i=ki(o,this.locale),n=ki(s,this.locale),r=Ui(e,this.locale),a=Ui(t,this.locale);return rd(Uo("The number of columns (%s) must be positive.",a),a),rd(Uo("The number of rows (%s) must be positive.",r),r),sn(a,r,((e,t)=>({value:i+t*a*n+e*n})))},isExported:!0},Nu={description:Uo("Sine of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the sine of, in radians."))],compute:function(e){return Math.sin(ki(e,this.locale))},isExported:!0},ku={description:Uo("Hyperbolic sine of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic sine of."))],compute:function(e){return Math.sinh(ki(e,this.locale))},isExported:!0},Vu={description:Uo("Positive square root of a positive number."),args:[od("value (number)",Uo("The number for which to calculate the positive square root."))],compute:function(e){const t=ki(e,this.locale);return Fi((()=>t>=0),Uo("The value (%s) must be positive or null.",t.toString())),{value:Math.sqrt(t),format:e?.format}},isExported:!0},Lu={description:Uo("Sum of a series of numbers and/or cells."),args:[od("value1 (number, range<number>)",Uo("The first number or range to add together.")),od("value2 (number, range<number>, repeating)",Uo("Additional numbers or ranges to add to value1."))],compute:function(...e){const t=e[0];return{value:gl(e,this.locale),format:Mi(t)}},isExported:!0},Hu={description:Uo("A conditional sum across a range."),args:[od("criteria_range (range)",Uo("The range which is tested against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to range.")),od("sum_range (range, default=criteria_range)",Uo("The range to be summed, if different from range."))],compute:function(e,t,o){void 0===o&&(o=e);let s=0;return un([e,t],((e,t)=>{const i=o[e]?.[t]?.value;"number"==typeof i&&(s+=i)}),this.locale),s},isExported:!0},Uu={description:Uo("Sums a range depending on multiple criteria."),args:[od("sum_range (range)",Uo("The range to sum.")),od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges to check.")),od("criterion2 (string, repeating)",Uo("Additional criteria to check."))],compute:function(e,...t){let o=0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o+=i)}),this.locale),o},isExported:!0},Bu={description:Uo("Tangent of an angle provided in radians."),args:[od("angle (number)",Uo("The angle to find the tangent of, in radians."))],compute:function(e){return Math.tan(ki(e,this.locale))},isExported:!0},zu={description:Uo("Hyperbolic tangent of any real number."),args:[od("value (number)",Uo("Any real value to calculate the hyperbolic tangent of."))],compute:function(e){return Math.tanh(ki(e,this.locale))},isExported:!0};function $u(e,t){return 0===t?Math.trunc(e):(Number.isInteger(t)||(t=Math.trunc(t)),Math.trunc(e*Math.pow(10,t))/Math.pow(10,t))}const Gu={description:Uo("Truncates a number."),args:[od("value (number)",Uo("The value to be truncated.")),od("places (number, default=0)",Uo("The number of significant digits to the right of the decimal point to retain."))],compute:function(e,t={value:0}){return{value:$u(ki(e,this.locale),ki(t,this.locale)),format:e?.format}},isExported:!0},Wu={description:Uo("Rounds a number down to the nearest integer that is less than or equal to it."),args:[od("value (number)",Uo("The number to round down to the nearest integer."))],compute:function(e){return Math.floor(ki(e,this.locale))},isExported:!0};var qu=Object.freeze({__proto__:null,ABS:kd,ACOS:Vd,ACOSH:Ld,ACOT:Hd,ACOTH:Ud,ASIN:Bd,ASINH:zd,ATAN:$d,ATAN2:Gd,ATANH:Wd,CEILING:qd,CEILING_MATH:jd,CEILING_PRECISE:Yd,COS:Xd,COSH:Kd,COT:Jd,COTH:Qd,COUNTBLANK:eu,COUNTIF:tu,COUNTIFS:ou,COUNTUNIQUE:su,COUNTUNIQUEIFS:iu,CSC:nu,CSCH:ru,DECIMAL:au,DEGREES:lu,EXP:cu,FLOOR:hu,FLOOR_MATH:uu,FLOOR_PRECISE:gu,INT:Wu,ISEVEN:pu,ISODD:fu,ISO_CEILING:mu,LN:vu,LOG:bu,MOD:yu,MUNIT:Cu,ODD:wu,PI:xu,POWER:Iu,PRODUCT:Eu,RAND:Ru,RANDARRAY:Tu,RANDBETWEEN:Au,ROUND:_u,ROUNDDOWN:Du,ROUNDUP:Ou,SEC:Fu,SECH:Mu,SEQUENCE:Pu,SIN:Nu,SINH:ku,SQRT:Vu,SUM:Lu,SUMIF:Hu,SUMIFS:Uu,TAN:Bu,TANH:zu,TRUNC:Gu});function Zu(e,t){const o=[],s=[];let i=0,n=0;Ki([e],(e=>{o.push(e),i+=1})),Ki([t],(e=>{s.push(e),n+=1})),Fi((()=>i===n),Uo("[[FUNCTION_NAME]] has mismatched argument count %s vs %s.",i,n));const r=[],a=[];for(let e=0;e<i;e++){const t=o[e]?.value,i=s[e]?.value;"number"==typeof t&&"number"==typeof i&&(a.push(t),r.push(i))}return{flatDataX:r,flatDataY:a}}function ju(e,t,o){const{flatDataX:s,flatDataY:i}=Zu(e,t),n=i.length;Fi((()=>0!==n&&(!o||1!==n)),Uo("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero);let r=0,a=0;for(let e=0;e<n;e++)r+=i[e],a+=s[e];const l=r/n,c=a/n;let h=0;for(let e=0;e<n;e++)h+=(i[e]-l)*(s[e]-c);return h/(n-(o?1:0))}function Yu(e,t,o,s){let i=0;const n=o?on:tn,r=n(e,((e,t)=>(i+=1,e+t)),0,s);Fi((()=>0!==i&&(!t||1!==i)),Uo("Evaluation of function [[FUNCTION_NAME]] caused a divide by zero error."),wi.DivisionByZero);const a=r/i;return n(e,((e,t)=>e+Math.pow(t-a,2)),0,s)/(i-(t?1:0))}function Xu(e,t,o,s){const i=ki(t,s);Fi((()=>o?0<=i&&i<=1:0<i&&i<1),Uo("Function [[FUNCTION_NAME]] parameter 2 value is out of range."));let n,r=[],a=0;return Ki(e,(e=>{const t=e?.value;"number"==typeof t&&(n=gn(r,e,"nextSmaller","asc",r.length,((e,t)=>e[t])),r.splice(n+1,0,t),a++)})),Fi((()=>0!==a),Uo("[[FUNCTION_NAME]] has no valid input data.")),o||Fi((()=>1/(a+1)<=i&&i<=a/(a+1)),Uo("Function [[FUNCTION_NAME]] parameter 2 value is out of range.")),ti(r,i,o)}const Ku={description:Uo("Average magnitude of deviations from mean."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){let t=0;const o=tn(e,((e,o)=>(t+=1,e+o)),0,this.locale);$i(t);const s=o/t;return tn(e,((e,t)=>e+Math.abs(s-t)),0,this.locale)/t},isExported:!0},Ju={description:Uo("Numerical average value in a dataset, ignoring text."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the average value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the average value."))],compute:function(...e){return{value:xl(e,this.locale),format:Mi(e[0])}},isExported:!0},Qu=Uo("[[FUNCTION_NAME]] has mismatched range sizes."),eg=Uo("[[FUNCTION_NAME]] expects the weight to be positive or equal to 0."),tg={description:Uo("Weighted average."),args:[od("values (number, range<number>)",Uo("Values to average.")),od("weights (number, range<number>)",Uo("Weights for each corresponding value.")),od("additional_values (number, range<number>, repeating)",Uo("Additional values to average.")),od("additional_weights (number, range<number>, repeating)",Uo("Additional weights."))],compute:function(...e){let t=0,o=0;for(let s=0;s<e.length-1;s+=2){const i=e[s],n=e[s+1];if(nd(Qu,i,n),bi(i))for(let e=0;e<i.length;e++)for(let s=0;s<i[0].length;s++){const r=i[e][s].value,a=bi(n)?n?.[e][s].value:ki(n,this.locale),l="number"==typeof r,c="number"==typeof a;l&&c?(Fi((()=>a>=0),eg),t+=r*a,o+=a):Fi((()=>l===c),Uo("[[FUNCTION_NAME]] expects number values."))}else{const e=ki(i,this.locale),s=bi(n)?n?.[0][0].value:ki(n,this.locale);"number"==typeof s&&(Fi((()=>s>=0),eg),t+=e*s,o+=s)}}return $i(o),{value:t/o,format:Mi(e[0])}}},og={description:Uo("Numerical average value in a dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the average value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the average value."))],compute:function(...e){let t=0;const o=on(e,((e,o)=>(t+=1,e+o)),0,this.locale);return $i(t),{value:o/t,format:Mi(e[0])}},isExported:!0},sg={description:Uo("Average of values depending on criteria."),args:[od("criteria_range (number, range<number>)",Uo("The range to check against criterion.")),od("criterion (string)",Uo("The pattern or test to apply to criteria_range.")),od("average_range (number, range<number>, default=criteria_range)",Uo("The range to average. If not included, criteria_range is used for the average instead."))],compute:function(e,t,o){const s=vn(void 0===o?e:o);let i=0,n=0;return un([e,t],((e,t)=>{const o=s[e]?.[t]?.value;"number"==typeof o&&(i+=1,n+=o)}),this.locale),$i(i),n/i},isExported:!0},ig={description:Uo("Average of values depending on multiple criteria."),args:[od("average_range (range)",Uo("The range to average.")),od("criteria_range1 (range)",Uo("The range to check against criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1.")),od("criteria_range2 (any, range, repeating)",Uo("Additional criteria_range and criterion to check.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){const o=vn(e);let s=0,i=0;return un(t,((e,t)=>{const n=o[e]?.[t]?.value;"number"==typeof n&&(s+=1,i+=n)}),this.locale),$i(s),i/s},isExported:!0},ng={description:Uo("The number of numeric values in dataset."),args:[od("value1 (number, any, range<number>)",Uo("The first value or range to consider when counting.")),od("value2 (number, any, range<number>, repeating)",Uo("Additional values or ranges to consider when counting."))],compute:function(...e){return Il(e,this.locale)},isExported:!0},rg={description:Uo("The number of values in a dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when counting.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when counting."))],compute:function(...e){return El(e)},isExported:!0},ag={description:Uo("The covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!1)},isExported:!0},lg={description:Uo("The covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!1)},isExported:!0},cg={description:Uo("The sample covariance of a dataset."),args:[od("data_y (any, range)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (any, range)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return ju(e,t,!0)},isExported:!0},hg={description:Uo("Calculates the expected y-value for a specified x based on a linear regression of a dataset."),args:[od("x (number, range<number>)",Uo("The value(s) on the x-axis to forecast.")),od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t,o){const{flatDataX:s,flatDataY:i}=Zu(t,o);return Nl([i],[s],nn(vn(e),(e=>ki(e,this.locale))),!0)},isExported:!0},dg={description:Uo("Fits points to exponential growth trend."),args:[od("known_data_y (range<number>)",Uo("The array or range containing dependent (y) values that are already known, used to curve fit an ideal exponential growth curve.")),od("known_data_x (range<number>, default={1;2;3;...})",Uo("The values of the independent variable(s) corresponding with known_data_y.")),od("new_data_x (any, range, default=known_data_x)",Uo("The data points to return the y values for on the ideal curve fit.")),od("b (boolean, default=TRUE)",Uo("Given a general exponential form of y = b*m^x for a curve fit, calculates b if TRUE or forces b to be 1 and only calculates the m values if FALSE."))],compute:function(e,t=[[]],o=[[]],s={value:!0}){return Ml(Nl(Pl(Li(e,"the first argument (known_data_y)")),Li(t,"the second argument (known_data_x)"),Li(o,"the third argument (new_data_y)"),Zi(s)))}},ug={description:Uo("Compute the intercept of the linear regression."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t),[[],[i]]=_l([o],[s]);return i},isExported:!0},gg={description:Uo("Nth largest element from a data set."),args:[od("data (any, range)",Uo("Array or range containing the dataset to consider.")),od("n (number)",Uo("The rank from largest to smallest of the element to return."))],compute:function(e,t){const o=Math.trunc(ki(t?.value,this.locale));let s,i=[],n=0;Ki([e],(e=>{"number"==typeof e?.value&&(s=gn(i,e,"nextSmaller","asc",i.length,((e,t)=>e[t].value)),i.splice(s+1,0,e),n++,n>o&&(i.shift(),n--))}));const r=i.shift();return Fi((()=>void 0!==r),Uo("[[FUNCTION_NAME]] has no valid input data.")),Fi((()=>n>=o),Uo("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",o)),r},isExported:!0},pg={description:Uo("Given partial data about a linear trend, calculates various parameters about the ideal linear trend using the least-squares method."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>, default={1;2;3;...})",Uo("The range representing the array or matrix of independent data.")),od("calculate_b (boolean, default=TRUE)",Uo("A flag specifying wheter to compute the slope or not")),od("verbose (boolean, default=FALSE)",Uo("A flag specifying whether to return additional regression statistics or only the linear coefficients and the y-intercept"))],compute:function(e,t=[[]],o={value:!0},s={value:!1}){return _l(Li(t,"the first argument (data_y)"),Li(e,"the second argument (data_x)"),Zi(o),Zi(s))},isExported:!0},mg={description:Uo("Given partial data about an exponential growth curve, calculates various parameters about the best fit ideal exponential growth curve."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>, optional, default={1;2;3;...})",Uo("The range representing the array or matrix of independent data.")),od("calculate_b (boolean, default=TRUE)",Uo("A flag specifying wheter to compute the slope or not")),od("verbose (boolean, default=FALSE)",Uo("A flag specifying whether to return additional regression statistics or only the linear coefficients and the y-intercept"))],compute:function(e,t=[[]],o={value:!0},s={value:!1}){const i=_l(Li(t,"the second argument (data_x)"),Pl(Li(e,"the first argument (data_y)")),Zi(o),Zi(s));for(let e=0;e<i.length;e++)i[e][0]=Math.exp(i[e][0]);return i},isExported:!0},fg={description:Uo("Compute the Matthews correlation coefficient of a dataset."),args:[od("data_x (range)",Uo("The range representing the array or matrix of observed data.")),od("data_y (range)",Uo("The range representing the array or matrix of predicted data."))],compute:function(e,t){const o=e.flat(),s=t.flat();if(wl(o,s),0===o.length)return new Ii(Uo("[[FUNCTION_NAME]] expects non-empty ranges for both parameters."));const i=o.length;let n=0,r=0,a=0,l=0;for(let e=0;e<i;++e){const t=Zi(o[e]);t===Zi(s[e])?t?r++:n++:t?l++:a++}return(r*n-a*l)/Math.sqrt((r+a)*(r+l)*(n+a)*(n+l))},isExported:!1},vg={description:Uo("Maximum value in a numeric dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the maximum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the maximum value."))],compute:function(...e){return Rl(e,this.locale)},isExported:!0},bg={description:Uo("Maximum numeric value in a dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when calculating the maximum value.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when calculating the maximum value."))],compute:function(...e){const t=on(e,((e,t)=>Math.max(t,e)),-1/0,this.locale);return{value:t===-1/0?0:t,format:Mi(e[0])}},isExported:!0},Sg={description:Uo("Returns the maximum value in a range of cells, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the maximum will be determined.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=-1/0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o=o<i?i:o)}),this.locale),o===-1/0?0:o},isExported:!0},yg={description:Uo("Median value in a numeric dataset."),args:[od("value1 (any, range)",Uo("The first value or range to consider when calculating the median value.")),od("value2 (any, range, repeating)",Uo("Additional values or ranges to consider when calculating the median value."))],compute:function(...e){let t=[];return Ji(e,(e=>{t.push(e)}),this.locale),{value:Xu(t,{value:.5},!0,this.locale),format:Mi(t[0])}},isExported:!0},Cg={description:Uo("Minimum value in a numeric dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the minimum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the minimum value."))],compute:function(...e){return Tl(e,this.locale)},isExported:!0},wg={description:Uo("Minimum numeric value in a dataset."),args:[od("value1 (number, range<number>)",Uo("The first value or range to consider when calculating the minimum value.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to consider when calculating the minimum value."))],compute:function(...e){const t=on(e,((e,t)=>Math.min(t,e)),1/0,this.locale);return{value:t===1/0?0:t,format:Mi(e[0])}},isExported:!0},xg={description:Uo("Returns the minimum value in a range of cells, filtered by a set of criteria."),args:[od("range (range)",Uo("The range of cells from which the minimum will be determined.")),od("criteria_range1 (range)",Uo("The range of cells over which to evaluate criterion1.")),od("criterion1 (string)",Uo("The pattern or test to apply to criteria_range1, such that each cell that evaluates to TRUE will be included in the filtered set.")),od("criteria_range2 (any, range, repeating)",Uo("Additional ranges over which to evaluate the additional criteria. The filtered set will be the intersection of the sets produced by each criterion-range pair.")),od("criterion2 (string, repeating)",Uo("The pattern or test to apply to criteria_range2."))],compute:function(e,...t){let o=1/0;return un(t,((t,s)=>{const i=e[t]?.[s]?.value;"number"==typeof i&&(o=o>i?i:o)}),this.locale),o===1/0?0:o},isExported:!0};function Ig(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t);if(0===o.length)throw new Ii(Uo("[[FUNCTION_NAME]] expects non-empty ranges for both parameters."));if(o.length<2)throw new Ii(Uo("[[FUNCTION_NAME]] needs at least two values for both parameters."));const i=o.length;let n=0,r=0,a=0,l=0,c=0;for(let e=0;e<i;e++){const t=o[e],i=s[e];n+=t,r+=i,a+=t*i,l+=t*t,c+=i*i}return(i*a-n*r)/Math.sqrt((i*l-n*n)*(i*c-r*r))}const Eg={description:Uo("Compute the Pearson product-moment correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return Ig(e,t)},isExported:!0},Rg=Eg,Tg={description:Uo("Value at a given percentile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile whose value within data will be calculated and returned."))],compute:function(e,t){return _g.compute.bind(this)(e,t)},isExported:!0},Ag={description:Uo("Value at a given percentile of a dataset exclusive of 0 and 1."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile, exclusive of 0 and 1, whose value within 'data' will be calculated and returned."))],compute:function(e,t){return{value:Xu([e],t,!1,this.locale),format:Mi(e)}},isExported:!0},_g={description:Uo("Value at a given percentile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("percentile (number)",Uo("The percentile whose value within data will be calculated and returned."))],compute:function(e,t){return{value:Xu([e],t,!0,this.locale),format:Mi(e)}},isExported:!0},Dg={description:Uo("Compute the coefficients of polynomial regression of the dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data.")),od("order (number)",Uo("The order of the polynomial to fit the data, between 1 and 6.")),od("intercept (boolean, default=TRUE)",Uo("A flag specifying whether to compute the intercept or not."))],compute:function(e,t,o,s={value:!0}){const{flatDataX:i,flatDataY:n}=Zu(e,t);return Dl(n,i,ki(o,this.locale),Zi(s))},isExported:!1},Og={description:Uo("Predict value by computing a polynomial regression of the dataset."),args:[od("x (number, range<number>)",Uo("The value(s) on the x-axis to forecast.")),od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data.")),od("order (number)",Uo("The order of the polynomial to fit the data, between 1 and 6.")),od("intercept (boolean, default=TRUE)",Uo("A flag specifying whether to compute the intercept or not."))],compute:function(e,t,o,s,i={value:!0}){const n=ki(s,this.locale),{flatDataX:r,flatDataY:a}=Zu(t,o),l=Dl(a,r,n,Zi(i)).flat();return nn(vn(e),(e=>Fl(l,ki(e,this.locale),n)))},isExported:!1},Fg={description:Uo("Value nearest to a specific quartile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value to return."))],compute:function(e,t){return Pg.compute.bind(this)(e,t)},isExported:!0},Mg={description:Uo("Value nearest to a specific quartile of a dataset exclusive of 0 and 4."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value, exclusive of 0 and 4, to return."))],compute:function(e,t){return{value:Xu([e],{value:.25*Math.trunc(ki(t,this.locale))},!1,this.locale),format:Mi(e)}},isExported:!0},Pg={description:Uo("Value nearest to a specific quartile of a dataset."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("quartile_number (number)",Uo("Which quartile value to return."))],compute:function(e,t){return{value:Xu([e],{value:.25*Math.trunc(ki(t,this.locale))},!0,this.locale),format:Mi(e)}},isExported:!0},Ng={description:Uo("Returns the rank of a specified value in a dataset."),args:[od("value (number)",Uo("The value whose rank will be determined.")),od("data (range)",Uo("The range containing the dataset to consider.")),od("is_ascending (boolean, default=FALSE)",Uo("Whether to consider the values in data in descending or ascending order."))],compute:function(e,t,o={value:!1}){const s=Zi(o),i=ki(e,this.locale);let n=1,r=!1;for(const e of t)for(const t of e){if("number"!=typeof t.value)continue;const e=ki(t,this.locale);e===i?r=!0:e>i!==s&&n++}return r?n:new Ai(Uo("Value not found in the given data."))},isExported:!0},kg={description:Uo("Compute the square of r, the Pearson product-moment correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){return Math.pow(Ig(t,e),2)},isExported:!0},Vg={description:Uo("Compute the slope of the linear regression."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t),[[i]]=_l([o],[s]);return i},isExported:!0},Lg={description:Uo("Nth smallest element in a data set."),args:[od("data (any, range)",Uo("The array or range containing the dataset to consider.")),od("n (number)",Uo("The rank from smallest to largest of the element to return."))],compute:function(e,t){const o=Math.trunc(ki(t?.value,this.locale));let s,i=[],n=0;Ki([e],(e=>{"number"==typeof e?.value&&(s=gn(i,e,"nextSmaller","asc",i.length,((e,t)=>e[t].value)),i.splice(s+1,0,e),n++,n>o&&(i.pop(),n--))}));const r=i.pop();return Fi((()=>void 0!==r),Uo("[[FUNCTION_NAME]] has no valid input data.")),Fi((()=>n>=o),Uo("Function [[FUNCTION_NAME]] parameter 2 value (%s) is out of range.",o)),r},isExported:!0},Hg={description:Uo("Compute the Spearman rank correlation coefficient of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(t,e),i=o.length,n=o.map(((e,t)=>[e,s[t]]));n.sort(((e,t)=>e[0]-t[0]));for(let e=0;e<i;++e)n[e][0]=e;n.sort(((e,t)=>e[1]-t[1]));let r=0;for(let e=0;e<i;++e)r+=(n[e][0]-e)**2;return 1-6*r/(i**3-i)},isExported:!1},Ug={description:Uo("Standard deviation."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(jg.compute.bind(this)(...e))},isExported:!0},Bg={description:Uo("Standard deviation of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Yg.compute.bind(this)(...e))},isExported:!0},zg={description:Uo("Standard deviation."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(Xg.compute.bind(this)(...e))},isExported:!0},$g={description:Uo("Standard deviation of sample (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Math.sqrt(Kg.compute.bind(this)(...e))},isExported:!0},Gg={description:Uo("Standard deviation of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Jg.compute.bind(this)(...e))},isExported:!0},Wg={description:Uo("Standard deviation of entire population (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Math.sqrt(Qg.compute.bind(this)(...e))},isExported:!0},qg={description:Uo("Calculates the standard error of the predicted y-value for each x in the regression of a dataset."),args:[od("data_y (range<number>)",Uo("The range representing the array or matrix of dependent data.")),od("data_x (range<number>)",Uo("The range representing the array or matrix of independent data."))],compute:function(e,t){const{flatDataX:o,flatDataY:s}=Zu(e,t);return _l([o],[s],!0,!0)[1][2]},isExported:!0},Zg={description:Uo("Fits points to linear trend derived via least-squares."),args:[od("known_data_y (number, range<number>)",Uo("The array or range containing dependent (y) values that are already known, used to curve fit an ideal linear trend.")),od("known_data_x (number, range<number>, optional, default={1;2;3;...})",Uo("The values of the independent variable(s) corresponding with known_data_y.")),od("new_data_x (number, range<number>, optional, default=known_data_x)",Uo("The data points to return the y values for on the ideal curve fit.")),od("b (boolean, optional, default=TRUE)",Uo("Given a general linear form of y = m*x+b for a curve fit, calculates b if TRUE or forces b to be 0 and only calculates the m values if FALSE, i.e. forces the curve fit to pass through the origin."))],compute:function(e,t=[[]],o=[[]],s={value:!0}){return Nl(Li(e,"the first argument (known_data_y)"),Li(t,"the second argument (known_data_x)"),Li(o,"the third argument (new_data_y)"),Zi(s))}},jg={description:Uo("Variance."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!1,this.locale)},isExported:!0},Yg={description:Uo("Variance of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!1,this.locale)},isExported:!0},Xg={description:Uo("Variance."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!1,this.locale)},isExported:!0},Kg={description:Uo("Variance of sample (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the sample.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the sample."))],compute:function(...e){return Yu(e,!0,!0,this.locale)},isExported:!0},Jg={description:Uo("Variance of entire population."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!1,this.locale)},isExported:!0},Qg={description:Uo("Variance of entire population (text as 0)."),args:[od("value1 (number, range<number>)",Uo("The first value or range of the population.")),od("value2 (number, range<number>, repeating)",Uo("Additional values or ranges to include in the population."))],compute:function(...e){return Yu(e,!1,!0,this.locale)},isExported:!0};var ep=Object.freeze({__proto__:null,AVEDEV:Ku,AVERAGE:Ju,AVERAGEA:og,AVERAGEIF:sg,AVERAGEIFS:ig,AVERAGE_WEIGHTED:tg,CORREL:Rg,COUNT:ng,COUNTA:rg,COVAR:ag,COVARIANCE_P:lg,COVARIANCE_S:cg,FORECAST:hg,GROWTH:dg,INTERCEPT:ug,LARGE:gg,LINEST:pg,LOGEST:mg,MATTHEWS:fg,MAX:vg,MAXA:bg,MAXIFS:Sg,MEDIAN:yg,MIN:Cg,MINA:wg,MINIFS:xg,PEARSON:Eg,PERCENTILE:Tg,PERCENTILE_EXC:Ag,PERCENTILE_INC:_g,POLYFIT_COEFFS:Dg,POLYFIT_FORECAST:Og,QUARTILE:Fg,QUARTILE_EXC:Mg,QUARTILE_INC:Pg,RANK:Ng,RSQ:kg,SLOPE:Vg,SMALL:Lg,SPEARMAN:Hg,STDEV:Ug,STDEVA:$g,STDEVP:Gg,STDEVPA:Wg,STDEV_P:Bg,STDEV_S:zg,STEYX:qg,TREND:Zg,VAR:jg,VARA:Kg,VARP:Jg,VARPA:Qg,VAR_P:Yg,VAR_S:Xg});function tp(e,t,o,s){const i=new Map,n=e.length;for(let t=n-1;t>=0;t--)i.set(Gi(e[t][0]).toUpperCase(),t);const r=t?.value;if("number"!=typeof r&&"string"!=typeof r)throw new Ii(Uo("The field must be a number or a string"));let a;if("number"==typeof r){if(a=Math.trunc(r)-1,a<0||n-1<a)throw new Ii(Uo("The field (%(fieldValue)s) must be one of %(dimRowDB)s or must be a number between 1 and %s inclusive.",{fieldValue:r.toString(),dimRowDB:n.toString()}))}else{const e=Gi(t).toUpperCase();if(a=i.get(e)??-1,-1===a)throw new Ii(Uo("The field (%s) must be one of %s.",Gi(t),[...i.keys()].toString()))}const l=o[0].length;if(l<2)throw new Ii(Uo("The criteria range contains %s row, it must be at least 2 rows.",l.toString()));let c=new Set;const h=e[0].length;for(let t=1;t<l;t++){let n=[],r=!0;for(let s=0;s<o.length;s++){const a=Gi(o[s][0]).toUpperCase(),l=i.get(a),c=o[s][t];if(null!==c.value){if(void 0===l){r=!1;break}n.push([e[l].slice(1,h)]),n.push(c)}}if(r){if(!(n.length>0)){c=new Set(Array(h-1).keys());break}un(n,((e,t)=>{c.add(t)}),s,!0)}}const d=e[a];return[...c].map((e=>d[e+1]))}const op=[od("database (range)",Uo("The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values.")),od("field (number, string)",Uo("Indicates which column in database contains the values to be extracted and operated on.")),od("criteria (range)",Uo("An array or range containing zero or more criteria to filter the database values by before operating."))],sp={description:Uo("Average of a set of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Ju.compute.bind(this)([s])},isExported:!0},ip={description:Uo("Counts values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return ng.compute.bind(this)([s])},isExported:!0},np={description:Uo("Counts values and text from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return rg.compute.bind(this)([s])},isExported:!0},rp={description:Uo("Single value from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Fi((()=>1===s.length),Uo("More than one match found in DGET evaluation.")),s[0]},isExported:!0},ap={description:Uo("Maximum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return vg.compute.bind(this)([s])},isExported:!0},lp={description:Uo("Minimum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Cg.compute.bind(this)([s])},isExported:!0},cp={description:Uo("Product of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Eu.compute.bind(this)([s])},isExported:!0},hp={description:Uo("Standard deviation of population sample from table."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Ug.compute.bind(this)([s])},isExported:!0},dp={description:Uo("Standard deviation of entire population from table."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Gg.compute.bind(this)([s])},isExported:!0},up={description:Uo("Sum of values from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Lu.compute.bind(this)([s])},isExported:!0},gp={description:Uo("Variance of population sample from table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return jg.compute.bind(this)([s])},isExported:!0},pp={description:Uo("Variance of a population from a table-like range."),args:op,compute:function(e,t,o){const s=tp(e,t,o,this.locale);return Jg.compute.bind(this)([s])},isExported:!0};var mp=Object.freeze({__proto__:null,DAVERAGE:sp,DCOUNT:ip,DCOUNTA:np,DGET:rp,DMAX:ap,DMIN:lp,DPRODUCT:cp,DSTDEV:hp,DSTDEVP:dp,DSUM:up,DVAR:gp,DVARP:pp});var fp;!function(e){e.WHOLE_YEARS="Y",e.WHOLE_MONTHS="M",e.WHOLE_DAYS="D",e.DAYS_WITHOUT_WHOLE_MONTHS="MD",e.MONTH_WITHOUT_WHOLE_YEARS="YM",e.DAYS_BETWEEN_NO_MORE_THAN_ONE_YEAR="YD"}(fp||(fp={}));const vp={description:Uo("Converts year/month/day into a date."),args:[od("year (number)",Uo("The year component of the date.")),od("month (number)",Uo("The month component of the date.")),od("day (number)",Uo("The day component of the date."))],compute:function(e,t,o){let s=Math.trunc(ki(e,this.locale));const i=Math.trunc(ki(t,this.locale)),n=Math.trunc(ki(o,this.locale));Fi((()=>0<=s&&s<=9999),Uo("The year (%s) must be between 0 and 9999 inclusive.",s.toString())),s<1900&&(s+=1900);const r=Hs(new ws(s,i-1,n));return Fi((()=>r>=0),Uo("The function [[FUNCTION_NAME]] result must be greater than or equal 01/01/1900.")),{value:r,format:this.locale.dateFormat}},isExported:!0},bp={description:Uo("Calculates the number of days, months, or years between two dates."),args:[od("start_date (date)",Uo("The start date to consider in the calculation. Must be a reference to a cell containing a DATE, a function returning a DATE type, or a number.")),od("end_date (date)",Uo("The end date to consider in the calculation. Must be a reference to a cell containing a DATE, a function returning a DATE type, or a number.")),od("unit (string)",Uo('A text abbreviation for unit of time. Accepted values are "Y" (the number of whole years between start_date and end_date), "M" (the number of whole months between start_date and end_date), "D" (the number of days between start_date and end_date), "MD" (the number of days between start_date and end_date after subtracting whole months), "YM" (the number of whole months between start_date and end_date after subtracting whole years), "YD" (the number of days between start_date and end_date, assuming start_date and end_date were no more than one year apart).'))],compute:function(e,t,o){const s=Gi(o).toUpperCase();Fi((()=>Object.values(fp).includes(s)),((e,t)=>{const o=e.map((e=>`'${e}'`)).join(", ");return Uo("The function [[FUNCTION_NAME]] has an argument with value '%s'. It should be one of: %s.",t,o)})(Object.values(fp),Gi(o)));const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Ls(i),a=Ls(n);switch(Fi((()=>n>=i),Uo("start_date (%s) should be on or before end_date (%s).",r.toLocaleDateString(),a.toLocaleDateString())),s){case fp.WHOLE_YEARS:return js(r,a);case fp.WHOLE_MONTHS:return qs(r,a);case fp.WHOLE_DAYS:return Zs(r,a);case fp.MONTH_WITHOUT_WHOLE_YEARS:return qs(r,a)-12*js(r,a);case fp.DAYS_WITHOUT_WHOLE_MONTHS:let e=a.getDate()-r.getDate();if(e<0){e=Bs(new ws(a.getFullYear(),a.getMonth()-1,1))-Math.abs(e)}return e;case fp.DAYS_BETWEEN_NO_MORE_THAN_ONE_YEAR:{if(function(e,t){return Ws(e,t,1)<1}(i,n))return Zs(r,a);const e=new ws(r.getFullYear(),a.getMonth(),a.getDate());let t=Zs(r,e);return t<0&&(e.setFullYear(r.getFullYear()+1),t=Zs(r,e)),t}}},isExported:!0},Sp={description:Uo("Converts a date string to a date value."),args:[od("date_string (string)",Uo("The string representing the date."))],compute:function(e){const t=Gi(e),o=Vs(t,this.locale);return Fi((()=>null!==o),Uo("The date_string (%s) cannot be parsed to date/time.",t.toString())),Math.trunc(o.value)},isExported:!0},yp={description:Uo("Day of the month that a specific date falls on."),args:[od("date (string)",Uo("The date from which to extract the day."))],compute:function(e){return ji(e,this.locale).getDate()},isExported:!0},Cp={description:Uo("Number of days between two dates."),args:[od("end_date (date)",Uo("The end of the date range.")),od("start_date (date)",Uo("The start of the date range."))],compute:function(e,t){const o=ji(e,this.locale),s=ji(t,this.locale),i=o.getTime()-s.getTime();return Math.round(i/Is)},isExported:!0},wp={description:Uo("Number of days between two dates on a 360-day year (months of 30 days)."),args:[od("start_date (date)",Uo("The start date to consider in the calculation.")),od("end_date (date)",Uo("The end date to consider in the calculation.")),od("method (number, default=0)",Uo("An indicator of what day count method to use. (0) US NASD method (1) European method"))],compute:function(e,t,o={value:0}){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=Ws(s,i,Zi(o)?4:0);return Math.sign(i-s)*Math.round(360*n)},isExported:!0},xp={description:Uo("Date a number of months before/after another date."),args:[od("start_date (date)",Uo("The date from which to calculate the result.")),od("months (number)",Uo("The number of months before (negative) or after (positive) 'start_date' to calculate."))],compute:function(e,t){return{value:Hs($s(ji(e,this.locale),Math.trunc(ki(t,this.locale)),!1)),format:this.locale.dateFormat}},isExported:!0},Ip={description:Uo("Last day of a month before or after a date."),args:[od("start_date (date)",Uo("The date from which to calculate the result.")),od("months (number)",Uo("The number of months before (negative) or after (positive) 'start_date' to consider."))],compute:function(e,t){const o=ji(e,this.locale),s=Math.trunc(ki(t,this.locale)),i=o.getFullYear(),n=o.getMonth();return{value:Hs(new ws(i,n+s+1,0)),format:this.locale.dateFormat}},isExported:!0},Ep={description:Uo("Hour component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the hour component."))],compute:function(e){return ji(e,this.locale).getHours()},isExported:!0},Rp={description:Uo("ISO week number of the year."),args:[od("date (date)",Uo("The date for which to determine the ISO week number. Must be a reference to a cell containing a date, a function returning a date type, or a number."))],compute:function(e){const t=ji(e,this.locale),o=t.getFullYear();let s=1;for(;4!==new ws(o,0,s).getDay();)s+=1;const i=new ws(o,0,s-3);let n=31;for(;4!==new ws(o,11,n).getDay();)n-=1;const r=new ws(o,11,n+3);let a,l;switch(a=i.getTime()<=t.getTime()?t.getTime()<=r.getTime()?0:1:-1,a){case 0:l=i;break;case 1:l=new ws(o,11,n+3+1);break;case-1:let e=1;for(;4!==new ws(o-1,0,e).getDay();)e+=1;l=new ws(o-1,0,e-3)}const c=(t.getTime()-l.getTime())/Is;return Math.floor(c/7)+1},isExported:!0},Tp={description:Uo("Minute component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the minute component."))],compute:function(e){return ji(e,this.locale).getMinutes()},isExported:!0},Ap={description:Uo("Month of the year a specific date falls in"),args:[od("date (date)",Uo("The date from which to extract the month."))],compute:function(e){return ji(e,this.locale).getMonth()+1},isExported:!0},_p={description:Uo("Net working days between two provided days."),args:[od("start_date (date)",Uo("The start date of the period from which to calculate the number of net working days.")),od("end_date (date)",Uo("The end date of the period from which to calculate the number of net working days.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the date serial numbers to consider holidays."))],compute:function(e,t,o){return Op.compute.bind(this)(e,t,{value:1},o)},isExported:!0};function Dp(e){const t=e?.value;if("string"==typeof t){Fi((()=>{if(7!==t.length)return!1;for(let e of t)if("0"!==e&&"1"!==e)return!1;return!0}),Uo('When weekend is a string (%s) it must be composed of "0" or "1".',t));let e=[];for(let o=0;o<7;o++)"1"===t[o]&&e.push((o+1)%7);return e}if("number"==typeof t)return Fi((()=>1<=t&&t<=7||11<=t&&t<=17),Uo("The weekend (%s) must be a string or a number in the range 1-7 or 11-17.",t.toString())),t<=7?[t-2==-1?6:t-2,t-1]:[t-11];throw new Ii(Uo("The weekend must be a number or a string."))}const Op={description:Uo("Net working days between two dates (specifying weekends)."),args:[od("start_date (date)",Uo("The start date of the period from which to calculate the number of net working days.")),od("end_date (date)",Uo("The end date of the period from which to calculate the number of net working days.")),od("weekend (any, default=1)",Uo("A number or string representing which days of the week are considered weekends.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider as holidays."))],compute:function(e,t,o={value:1},s){const i=ji(e,this.locale),n=ji(t,this.locale),r=Dp(o);let a=new Set;void 0!==s&&Ki([s],(e=>{const t=ji(e,this.locale);a.add(t.getTime())}));const l=i.getTime()>n.getTime(),c=ws.fromTimestamp((l?i:n).getTime());let h=ws.fromTimestamp((l?n:i).getTime());const d=c.getTime();let u=h.getTime(),g=0;for(;u<=d;)r.includes(h.getDay())||a.has(u)||(g+=1),h.setDate(h.getDate()+1),u=h.getTime();return l?-g:g},isExported:!0},Fp={description:Uo("Current date and time as a date value."),args:[],compute:function(){const e=ws.now(),t=e.getTime()-xs.getTime(),o=e.getHours()/24+e.getMinutes()/1440+e.getSeconds()/86400;return{value:Math.floor(t/Is)+o,format:hl(this.locale)}},isExported:!0},Mp={description:Uo("Minute component of a specific time."),args:[od("time (date)",Uo("The time from which to calculate the second component."))],compute:function(e){return ji(e,this.locale).getSeconds()},isExported:!0},Pp={description:Uo("Converts hour/minute/second into a time."),args:[od("hour (number)",Uo("The hour component of the time.")),od("minute (number)",Uo("The minute component of the time.")),od("second (number)",Uo("The second component of the time."))],compute:function(e,t,o){let s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=Math.trunc(ki(o,this.locale));return i+=Math.floor(n/60),n=n%60+(n<0?60:0),s+=Math.floor(i/60),i=i%60+(i<0?60:0),s%=24,Fi((()=>s>=0),Uo("The function [[FUNCTION_NAME]] result cannot be negative")),{value:s/24+i/1440+n/86400,format:this.locale.timeFormat}},isExported:!0},Np={description:Uo("Converts a time string into its serial number representation."),args:[od("time_string (string)",Uo("The string that holds the time representation."))],compute:function(e){const t=Gi(e),o=Vs(t,this.locale);Fi((()=>null!==o),Uo("The time_string (%s) cannot be parsed to date/time.",t));const s=o.value-Math.trunc(o.value);return s<0?1+s:s},isExported:!0},kp={description:Uo("Current date as a date value."),args:[],compute:function(){const e=ws.now();return{value:Hs(new ws(e.getFullYear(),e.getMonth(),e.getDate())),format:this.locale.dateFormat}},isExported:!0},Vp={description:Uo("Day of the week of the date provided (as number)."),args:[od("date (date)",Uo("The date for which to determine the day of the week. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("type (number, default=1)",Uo("A number indicating which numbering system to use to represent weekdays. By default, counts starting with Sunday = 1."))],compute:function(e,t={value:1}){const o=ji(e,this.locale),s=Math.round(ki(t,this.locale)),i=o.getDay();return Fi((()=>[1,2,3].includes(s)),Uo("The type (%s) must be 1, 2 or 3.",s.toString())),1===s?i+1:2===s?0===i?7:i:0===i?6:i-1},isExported:!0},Lp={description:Uo("Week number of the year."),args:[od("date (date)",Uo("The date for which to determine the week number. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("type (number, default=1)",Uo("A number representing the day that a week starts on. Sunday = 1."))],compute:function(e,t={value:1}){const o=ji(e,this.locale),s=Math.round(ki(t,this.locale));if(Fi((()=>1===s||2===s||11<=s&&s<=17||21===s),Uo("The type (%s) is out of range.",s.toString())),21===s)return Rp.compute.bind(this)(e);let i;i=1===s||2===s?s-1:s-10==7?0:s-10;const n=o.getFullYear();let r=1,a=new ws(n,0,r);for(;a.getDay()!==i;)r+=1,a=new ws(n,0,r);const l=(o.getTime()-a.getTime())/Is;return l<0?1:Math.floor(l/7)+(1===r?1:2)},isExported:!0},Hp={description:Uo("Date after a number of workdays."),args:[od("start_date (date)",Uo("The date from which to begin counting.")),od("num_days (number)",Uo("The number of working days to advance from start_date. If negative, counts backwards.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider holidays."))],compute:function(e,t,o={value:null}){return Up.compute.bind(this)(e,t,{value:1},o)},isExported:!0},Up={description:Uo("Date after a number of workdays (specifying weekends)."),args:[od("start_date (date)",Uo("The date from which to begin counting.")),od("num_days (number)",Uo("The number of working days to advance from start_date. If negative, counts backwards.")),od("weekend (any, default=1)",Uo("A number or string representing which days of the week are considered weekends.")),od("holidays (date, range<date>, optional)",Uo("A range or array constant containing the dates to consider holidays."))],compute:function(e,t,o={value:1},s){let i=ji(e,this.locale),n=Math.trunc(ki(t,this.locale));"string"==typeof o.value&&Fi((()=>"1111111"!==o.value),Uo("The weekend must be different from '1111111'."));const r=Dp(o);let a=new Set;void 0!==s&&Ki([s],(e=>{const t=ji(e,this.locale);a.add(t.getTime())}));let l=ws.fromTimestamp(i.getTime()),c=l.getTime();const h=Math.sign(n);let d=Math.abs(n);for(;d>0;)l.setDate(l.getDate()+h),c=l.getTime(),r.includes(l.getDay())||a.has(c)||(d-=1);const u=c-xs.getTime();return{value:Math.round(u/Is),format:this.locale.dateFormat}},isExported:!0},Bp={description:Uo("Year specified by a given date."),args:[od("date (date)",Uo("The date from which to extract the year."))],compute:function(e){return ji(e,this.locale).getFullYear()},isExported:!0},zp={description:Uo("Exact number of years between two dates."),args:[od("start_date (date)",Uo("The start date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("end_date (date)",Uo("The end date to consider in the calculation. Must be a reference to a cell containing a date, a function returning a date type, or a number.")),od("day_count_convention (number, default=0)",Uo("An indicator of what day count method to use."))],compute:function(e,t,o={value:0}){let s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale));const n=Math.trunc(ki(o,this.locale));return Fi((()=>s>=0),Uo("The start_date (%s) must be positive or null.",s.toString())),Fi((()=>i>=0),Uo("The end_date (%s) must be positive or null.",i.toString())),Fi((()=>0<=n&&n<=4),Uo("The day_count_convention (%s) must be between 0 and 4 inclusive.",n.toString())),Ws(s,i,n)}},$p={description:Uo("First day of the month preceding a date."),args:[od("date (date)",Uo("The date from which to calculate the result."))],compute:function(e){const t=ji(e,this.locale),o=t.getFullYear(),s=t.getMonth();return{value:Hs(new ws(o,s,1)),format:this.locale.dateFormat}}},Gp={description:Uo("Last day of the month following a date."),args:[od("date (date)",Uo("The date from which to calculate the result."))],compute:function(e){return Ip.compute.bind(this)(e,{value:0})}},Wp={description:Uo("Quarter of the year a specific date falls in"),args:[od("date (date)",Uo("The date from which to extract the quarter."))],compute:function(e){return Math.ceil((ji(e,this.locale).getMonth()+1)/3)}},qp={description:Uo("First day of the quarter of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the start of quarter."))],compute:function(e){const t=Wp.compute.bind(this)(e),o=Bp.compute.bind(this)(e);return{value:Hs(new ws(o,3*(t-1),1)),format:this.locale.dateFormat}}},Zp={description:Uo("Last day of the quarter of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the end of quarter."))],compute:function(e){const t=Wp.compute.bind(this)(e),o=Bp.compute.bind(this)(e);return{value:Hs(new ws(o,3*t,0)),format:this.locale.dateFormat}}},jp={description:Uo("First day of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the start of the year."))],compute:function(e){const t=Bp.compute.bind(this)(e);return{value:Hs(new ws(t,0,1)),format:this.locale.dateFormat}}},Yp={description:Uo("Last day of the year a specific date falls in."),args:[od("date (date)",Uo("The date from which to calculate the end of the year."))],compute:function(e){const t=Bp.compute.bind(this)(e);return{value:Hs(new ws(t+1,0,0)),format:this.locale.dateFormat}}};var Xp=Object.freeze({__proto__:null,DATE:vp,DATEDIF:bp,DATEVALUE:Sp,DAY:yp,DAYS:Cp,DAYS360:wp,EDATE:xp,EOMONTH:Ip,HOUR:Ep,ISOWEEKNUM:Rp,MINUTE:Tp,MONTH:Ap,MONTH_END:Gp,MONTH_START:$p,NETWORKDAYS:_p,NETWORKDAYS_INTL:Op,NOW:Fp,QUARTER:Wp,QUARTER_END:Zp,QUARTER_START:qp,SECOND:Mp,TIME:Pp,TIMEVALUE:Np,TODAY:kp,WEEKDAY:Vp,WEEKNUM:Lp,WORKDAY:Hp,WORKDAY_INTL:Up,YEAR:Bp,YEARFRAC:zp,YEAR_END:Yp,YEAR_START:jp});const Kp={description:Uo("Compare two numeric values, returning 1 if they're equal."),args:[od("number1 (number)",Uo("The first number to compare.")),od("number2 (number, default=0)",Uo("The second number to compare."))],compute:function(e,t={value:0}){return ki(e,this.locale)===ki(t,this.locale)?1:0},isExported:!0};var Jp=Object.freeze({__proto__:null,DELTA:Kp});const Qp=[oi.number,oi.error,oi.text,oi.boolean];function em(e){const t="asc"===e?1:-1;return(e,o)=>{if(e.type===oi.empty)return o.type===oi.empty?0:1;if(o.type===oi.empty)return-1;let s=Qp.indexOf(e.type)-Qp.indexOf(o.type);return 0===s&&(s=e.type===oi.text||e.type===oi.error?e.value.localeCompare(o.value):e.value-o.value),t*s}}function tm(e,t,o,s,i){let n=s.right>s.left;if(e.model.getters.doesIntersectMerge(t,s)){let o;n=!1;for(let i=s.top;i<=s.bottom;i++){o=[];for(let n=s.left;n<=s.right;n++){let s=e.model.getters.getMerge({sheetId:t,col:n,row:i});s&&!o.includes(s.id.toString())&&o.push(s.id.toString())}if(o.length>=2){n=!0;break}}}if(n)return void om(e,t,o,s,i);const r=e.model.getters.getContiguousZone(t,s);Qo(r,s)?om(e,t,o,s,i):e.askConfirmation(Uo("We found data next to your selection. Since this data was not selected, it will not be sorted. Do you want to extend your selection?"),(()=>om(e,t,o,r,i)),(()=>om(e,t,o,s,i)))}function om(e,t,o,s,i,n){const r=e.model.dispatch("SORT_CELLS",{sheetId:t,col:o.col,row:o.row,zone:s,sortDirection:i,sortOptions:n});if(r.isCancelledBecause("InvalidSortZone")){const{col:t,row:i}=o;e.model.selection.selectZone({cell:{col:t,row:i},zone:s}),e.raiseError(Uo("Cannot sort. To sort, select only cells or only merges that have the same size."))}if(r.isCancelledBecause("SortZoneWithArrayFormulas")){const{col:t,row:i}=o;e.model.selection.selectZone({cell:{col:t,row:i},zone:s}),e.raiseError(Uo("Cannot sort a zone with array formulas."))}}function sm(e,t,...o){for(const[e,t]of o.entries())Fi((()=>void 0!==t),Uo("Value for parameter %d is missing, while the function [[FUNCTION_NAME]] expect a number or a range.",e+1));const s=[],i=[],n=e.length;for(let r=0;r<o.length;r+=2){s.push(Zi(Sl(o[r+1])?.value)?"asc":"desc");const a=o[r];if(bi(a)&&(a.length>1||a[0].length>1))Fi((()=>1===a.length&&a[0].length===n),Uo("Wrong size for %s. Expected a range of size 1x%s. Got %sx%s.",`sort_column${r+1}`,n,a.length,a[0].length)),i.push(a.flat().map((e=>e.value)));else{const o=ki(Sl(a)?.value,t);if(o<1||o>e[0].length)return e;i.push(e.map((e=>e[o-1].value)))}}if(0===i.length)for(let t=0;t<e[0].length;t++)i.push(e.map((e=>e[t].value))),s.push("asc");const r={desc:em("desc"),asc:em("asc")},a=je(0,e.length);return a.sort(((e,t)=>{for(const[o,n]of i.entries()){const i=n[e],a=n[t],l={value:i,type:null===i?oi.empty:"string"==typeof i?oi.text:typeof i},c={value:a,type:null===a?oi.empty:"string"==typeof a?oi.text:typeof a},h=r[s[o]](l,c);if(0!==h)return h}return 0})),a.map((t=>e[t]))}const im={description:Uo("Returns a filtered version of the source range, returning only rows or columns that meet the specified conditions."),args:[od("range (any, range<any>)",Uo("The data to be filtered.")),od("condition1 (boolean, range<boolean>)",Uo("A column or row containing true or false values corresponding to the first column or row of range.")),od("condition2 (boolean, range<boolean>, repeating)",Uo("Additional column or row containing true or false values."))],compute:function(e,...t){let o=vn(e);const s=t.map((e=>nn(vn(e),(e=>e.value))));s.map((e=>id(Uo("The arguments condition must be a single column or row."),e))),nd(Uo("The arguments conditions must have the same dimensions."),...t);const i=s.map((e=>e.flat())),n=1===s[0].length?"row":"col";o="row"===n?rn(o):o,Fi((()=>i.every((e=>e.length===o.length))),Uo("FILTER has mismatched sizes on the range and conditions."));const r=[];for(let e=0;e<o.length;e++){const t=o[e];i.every((t=>("boolean"==typeof t[e]||"number"==typeof t[e])&&t[e]))&&r.push(t)}return r.length?"row"===n?rn(r):r:new Ai(Uo("No match found in FILTER evaluation"))},isExported:!1},nm={description:Uo("Sorts the rows of a given array or range by the values in one or more columns."),args:[od("range (range)",Uo("The data to be sorted.")),od("sort_column (any, range<number>, repeating)",Uo("The index of the column in range or a range outside of range containing the values by which to sort.")),od("is_ascending (boolean, repeating)",Uo("TRUE or FALSE indicating whether to sort sort_column in ascending order. FALSE sorts in descending order."))],compute:function(e,...t){const o=rn(e);return rn(sm(o,this.locale,...t))},isExported:!0},rm={description:Uo("Returns the first n items in a data set after performing a sort."),args:[od("range (range)",Uo("The data to be sorted.")),od("n (number, default=1)",Uo("The number of items to return.")),od("display_ties_mode (number, default=0)",Uo("A number representing the way to display ties.")),od("sort_column (number, range<number>, repeating)",Uo("The index of the column in range or a range outside of range containing the values by which to sort.")),od("is_ascending (boolean, repeating)",Uo("TRUE or FALSE indicating whether to sort sort_column in ascending order. FALSE sorts in descending order."))],compute:function(e,t,o,...s){const i=ki(t?.value??1,this.locale);Fi((()=>i>=0),Uo("Wrong value of 'n'. Expected a positive number. Got %s.",i));const n=ki(o?.value??0,this.locale);Fi((()=>n>=0&&n<=3),Uo("Wrong value of 'display_ties_mode'. Expected a positive number between 0 and 3. Got %s.",n));const r=sm(rn(e),this.locale,...s),a=(e,t)=>JSON.stringify(r[e].map((e=>e.value)))===JSON.stringify(r[t].map((e=>e.value)));switch(n){case 0:return rn(r.slice(0,i));case 1:for(let e=i;e<r.length;e++)if(!a(e,i-1))return rn(r.slice(0,e));return rn(r);case 2:{const e=[r[0]];for(let t=1;t<r.length;t++)for(let o=0;o<t&&!a(t,o);o++)o===t-1&&e.push(r[t]);return rn(e.slice(0,i))}case 3:{const e=[r[0]];let t=1;for(let o=1;o<r.length&&(a(o,o-1)||t++,!(t>i));o++)e.push(r[o]);return rn(e)}}},isExported:!1},am={description:Uo("Unique rows in the provided source range."),args:[od("range (any, range<any>)",Uo("The data to filter by unique entries.")),od("by_column (boolean, default=FALSE)",Uo("Whether to filter the data by columns or by rows.")),od("exactly_once (boolean, default=FALSE)",Uo("Whether to return only entries with no duplicates."))],compute:function(e={value:""},t,o){if(!bi(e))return[[e]];const s=Zi(t?.value)||!1,i=Zi(o?.value)||!1;s||(e=rn(e));const n=new Map;for(const t of e){const e=JSON.stringify(t.map((e=>e.value))),o=n.get(e);o?o.count++:n.set(e,{data:t,count:1})}const r=[];for(const e of n.values())i&&e.count>1||r.push(e.data);return r.length?s?r:rn(r):new Ii(Uo("No unique values found"))},isExported:!0};var lm=Object.freeze({__proto__:null,FILTER:im,SORT:nm,SORTN:rm,UNIQUE:am});function cm(e,t){Fi((()=>e<t),Uo("The maturity (%s) must be strictly greater than the settlement (%s).",t.toString(),e.toString()))}function hm(e,t){Fi((()=>t<e),Uo("The settlement date (%s) must be strictly greater than the issue date (%s).",e.toString(),t.toString()))}function dm(e){Fi((()=>[1,2,4].includes(e)),Uo("The frequency (%s) must be one of %s",e.toString(),[1,2,4].toString()))}function um(e){Fi((()=>0<=e&&e<=4),Uo("The day_count_convention (%s) must be between 0 and 4 inclusive.",e.toString()))}function gm(e){Fi((()=>e>0),Uo("The redemption (%s) must be strictly positive.",e.toString()))}function pm(e){Fi((()=>e>0),Uo("The price (%s) must be strictly positive.",e.toString()))}function mm(e){Fi((()=>e>0),Uo("The number_of_periods (%s) must be greater than 0.",e.toString()))}function fm(e){Fi((()=>e>0),Uo("The rate (%s) must be strictly positive.",e.toString()))}function vm(e){Fi((()=>e>0),Uo("The life (%s) must be strictly positive.",e.toString()))}function bm(e){Fi((()=>e>=0),Uo("The cost (%s) must be positive or null.",e.toString()))}function Sm(e){Fi((()=>e>0),Uo("The period (%s) must be strictly positive.",e.toString()))}function ym(e){Fi((()=>e>=0),Uo("The salvage (%s) must be positive or null.",e.toString()))}function Cm(e){Fi((()=>e>0),Uo("The present value (%s) must be strictly positive.",e.toString()))}function wm(e,t){Fi((()=>e<=t),Uo("The period (%s) must be less than or equal life (%s).",e.toString(),t.toString()))}function xm(e){Fi((()=>e>0),Uo("The investment (%s) must be strictly positive.",e.toString()))}function Im(e){Fi((()=>e>0),Uo("The discount (%s) must be strictly positive.",e.toString()))}function Em(e){Fi((()=>e<1),Uo("The discount (%s) must be smaller than 1.",e.toString()))}function Rm(e){Fi((()=>e>0),Uo("The depreciation factor (%s) must be strictly positive.",e.toString()))}function Tm(e,t,o){const s=ji(e,o),i=ji(t,o),n=ji(e,o);n.setFullYear(s.getFullYear()+1),Fi((()=>i.getTime()<=n.getTime()),Uo("The settlement date (%s) must at most one year after the maturity date (%s).",e.toString(),t.toString()))}function Am(e,t,o){mm(o),Fi((()=>e>0),Uo("The first_period (%s) must be strictly positive.",e.toString())),Fi((()=>t>0),Uo("The last_period (%s) must be strictly positive.",t.toString())),Fi((()=>e<=t),Uo("The first_period (%s) must be smaller or equal to the last_period (%s).",e.toString(),t.toString())),Fi((()=>t<=o),Uo("The last_period (%s) must be smaller or equal to the number_of_periods (%s).",e.toString(),o.toString()))}function _m(e){Fi((()=>e>-1),Uo("The rate_guess (%s) must be strictly greater than -1.",e.toString()))}function Dm(e,t){Fi((()=>e.length===t.length&&e[0].length===t[0].length),Uo("The cashflow_amounts and cashflow_dates ranges must have the same dimensions."))}function Om(e){Fi((()=>e.every((t=>t>=e[0]))),Uo("All the dates should be greater or equal to the first date in cashflow_dates (%s).",e[0].toString()))}const Fm=[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))];function Mm(e,t,o,s,i=1e-10,n){let r,a,l,c,h=o,d=!1,u=0;do{l=e(h),isNaN(l)?(Fi((()=>u<s&&void 0!==n),Uo("Function [[FUNCTION_NAME]] didn't find any result.")),u++,h=n(c),c=h):(r=h-l/t(h),a=Math.abs(r-h),h=r,d=a<i||Math.abs(l)<i,Fi((()=>u<s),Uo("Function [[FUNCTION_NAME]] didn't find any result.")),u++)}while(!d);return h}const Pm={description:Uo("Accrued interest of security paying at maturity."),args:[od("issue (date)",Uo("The date the security was initially issued.")),od("maturity (date)",Uo("The maturity date of the security.")),od("rate (number)",Uo("The annualized rate of interest.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(s,this.locale),l=ki(o,this.locale),c=Math.trunc(ki(i,this.locale));!function(e){Fi((()=>e>=0),Uo("The issue (%s) must be positive or null.",e.toString()))}(n),hm(r,n),um(c),gm(a),fm(l);return a*l*Ws(n,r,c)},isExported:!0},Nm={description:Uo("Depreciation for an accounting period."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("purchase_date (date)",Uo("The date the asset was purchased.")),od("first_period_end (date)",Uo("The date the first period ended.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("rate (number)",Uo("The deprecation rate.")),od("day_count_convention (number, optional)",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=ki(e,this.locale),l=Math.trunc(ki(t,this.locale)),c=Math.trunc(ki(o,this.locale)),h=ki(s,this.locale),d=ki(i,this.locale),u=ki(n,this.locale),g=Math.trunc(ki(r,this.locale));!function(e){Fi((()=>e>0),Uo("The cost (%s) must be strictly positive.",e.toString()))}(a),function(e){Fi((()=>e>=0),Uo("The purchase_date (%s) must be positive or null.",e.toString()))}(l),ym(h),function(e,t){Fi((()=>e<=t),Uo("The salvage (%s) must be smaller or equal than the cost (%s).",e.toString(),t.toString()))}(h,a),function(e){Fi((()=>e>=0),Uo("The period (%s) must be positive or null.",e.toString()))}(d),fm(u),um(g),Fi((()=>l<=c),Uo("The purchase_date (%s) must be before the first_period_end (%s).",l.toString(),c.toString()));const p=d<1&&d>0?1:Math.trunc(d),m=a*u,f=Ws(l,c,g),v=l===c?m:m*f,b=a-v-m*p;return b>=h?0===p?v:m:h-b<m?m-(h-b):0},isExported:!0},km={description:Uo("Days in coupon period containing settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));if(cm(i,n),dm(r),um(a),1===a){const i=Bm.compute.bind(this)(e,t,o,s).value;return Hm.compute.bind(this)(e,t,o,s).value-i}return(3===a?365:360)/r},isExported:!0},Vm={description:Uo("Days from settlement until next coupon."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=Bm.compute.bind(this)(e,t,o,s).value;if([1,2,3].includes(a))return i-l;if(4===a){const e=Ws(l,i,a);return Math.round(360*e)}const c=ji(i,this.locale),h=ji(l,this.locale),d=h.getFullYear(),u=c.getFullYear(),g=h.getMonth()+1,p=c.getMonth()+1;let m=h.getDate(),f=c.getDate();return 2===g&&2===p&&zs(h)&&zs(c)&&(f=30),31!==f||30!==m&&31!==m||(f=30),2===g&&zs(h)&&(m=30),31===m&&(m=30),360*(u-d)+30*(p-g)+(f-m)},isExported:!0},Lm={description:Uo("Days from settlement until next coupon."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=Hm.compute.bind(this)(e,t,o,s).value;if([1,2,3].includes(a))return l-i;if(4===a){const e=Ws(i,l,a);return Math.round(360*e)}const c=Vm.compute.bind(this)(e,t,o,s);return km.compute.bind(this)(e,t,o,s)-c},isExported:!0},Hm={description:Uo("Next coupon date after the settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=12/r,c=Um.compute.bind(this)(e,t,o,s);return{value:Hs($s(ji(n,this.locale),-(c-1)*l,!0)),format:this.locale.dateFormat}},isExported:!0},Um={description:Uo("Number of coupons between settlement and maturity."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);let l=1,c=n;const h=12/r;for(;c>i;)c=Hs($s(ji(c,this.locale),-h,!1)),l++;return l-1},isExported:!0},Bm={description:Uo("Last coupon date prior to or on the settlement date."),args:Fm,compute:function(e,t,o,s={value:0}){s=s||0;const i=Math.trunc(ki(e,this.locale)),n=Math.trunc(ki(t,this.locale)),r=Math.trunc(ki(o,this.locale)),a=Math.trunc(ki(s,this.locale));cm(i,n),dm(r),um(a);const l=12/r,c=Um.compute.bind(this)(e,t,o,s);return{value:Hs($s(ji(n,this.locale),-c*l,!0)),format:this.locale.dateFormat}},isExported:!0},zm={description:Uo("Cumulative interest paid over a set of periods."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("first_period (number)",Uo("The number of the payment period to begin the cumulative calculation.")),od("last_period (number)",Uo("The number of the payment period to end the cumulative calculation.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i,n={value:0}){const r=ki(s,this.locale),a=ki(i,this.locale),l=ki(e,this.locale),c=ki(o,this.locale),h=ki(t,this.locale),d=Zi(n)?1:0;Am(r,a,h),fm(l),Cm(c);let u=0;for(let e=r;e<=a;e++)u+=of(l,e,h,c,0,d);return u},isExported:!0},$m={description:Uo("Cumulative principal paid over a set of periods."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("first_period (number)",Uo("The number of the payment period to begin the cumulative calculation.")),od("last_period (number)",Uo("The number of the payment period to end the cumulative calculation.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i,n={value:0}){const r=ki(s,this.locale),a=ki(i,this.locale),l=ki(e,this.locale),c=ki(o,this.locale),h=ki(t,this.locale),d=Zi(n)?1:0;Am(r,a,h),fm(l),Cm(c);let u=0;for(let e=r;e<=a;e++)u+=ff(l,e,h,c,0,d);return u},isExported:!0},Gm={description:Uo("Depreciation via declining balance method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("month (number, optional)",Uo("The number of months in the first year of depreciation."))],compute:function(e,t,o,s,...i){const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=Math.trunc(ki(s,this.locale)),c=i.length?Math.trunc(ki(i[0],this.locale)):12,h=a+(12===c?0:1);bm(n),ym(r),Sm(l),vm(a),Fi((()=>1<=c&&c<=12),Uo("The month (%s) must be between 1 and 12 inclusive.",c.toString())),Fi((()=>l<=h),Uo("The period (%s) must be less than or equal to %s.",l.toString(),h.toString()));const d=c/12;let u=1-Math.pow(r/n,1/a);u=Math.round(1e3*u)/1e3;let g=n,p=n*(1-u*d);for(let e=1;e<l;e++)g=p,p=g*(1-u),e===a&&(p=g*(1-u*(1-d)));return{value:g-p,format:"#,##0.00"}},isExported:!0};function Wm(e,t,o,s,i){if(bm(e),ym(t),Sm(s),vm(o),wm(s,o),Rm(i),0===e||t>=e)return 0;const n=i/o;if(n>1)return 1===s?e-t:0;if(s<=1)return e*n;const r=e*Math.pow(1-n,s-1),a=e*Math.pow(1-n,s),l=a<t?r-t:r-a;return Math.max(l,0)}const qm={description:Uo("Depreciation via double-declining balance method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation.")),od("factor (number, default=2)",Uo("The factor by which depreciation decreases."))],compute:function(e,t,o,s,i={value:2}){return{value:Wm(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),ki(i,this.locale)),format:"#,##0.00"}},isExported:!0},Zm={description:Uo("Discount rate of a security based on price."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),pm(a),gm(l);return(l-a)/l/Ws(n,r,c)},isExported:!0},jm={description:Uo("Convert a decimal fraction to decimal value."),args:[od("fractional_price (number)",Uo("The price quotation given using fractional decimal conventions.")),od("unit (number)",Uo("The units of the fraction, e.g. 8 for 1/8ths or 32 for 1/32nds."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));Fi((()=>s>0),Uo("The unit (%s) must be strictly positive.",s.toString()));const i=Math.trunc(o);return i+(o-i)*(10**Math.ceil(Math.log10(s))/s)},isExported:!0},Ym={description:Uo("Convert a decimal value to decimal fraction."),args:[od("decimal_price (number)",Uo("The price quotation given as a decimal value.")),od("unit (number)",Uo("The units of the desired fraction, e.g. 8 for 1/8ths or 32 for 1/32nds."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));Fi((()=>s>0),Uo("The unit (%s) must be strictly positive.",s.toString()));const i=Math.trunc(o);return i+(o-i)*(s/10**Math.ceil(Math.log10(s)))},isExported:!0},Xm={description:Uo("Number of periods for an investment to reach a value."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=ki(o,this.locale),c=ki(s,this.locale),h=Math.trunc(ki(i,this.locale)),d=Math.trunc(ki(n,this.locale));cm(r,a),dm(h),um(d),Fi((()=>l>=0),Uo("The rate (%s) must be positive or null.",l.toString())),Fi((()=>c>=0),Uo("The yield (%s) must be positive or null.",c.toString()));const u=Ws(r,a,d),g=u-Math.trunc(u)||1/h,p=Math.ceil(u*h),m=l/h,f=c/h;let v=0,b=0;for(let e=1;e<=p;e++){const t=(m+(e===p?1:0))/(1+f)**e;b+=(g+(e-1)/h)*t,v+=t}return 0===v?0:b/v},isExported:!0},Km={description:Uo("Annual effective interest rate."),args:[od("nominal_rate (number)",Uo("The nominal interest rate per year.")),od("periods_per_year (number)",Uo("The number of compounding periods per year."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));return Fi((()=>o>0),Uo("The nominal rate (%s) must be strictly greater than 0.",o.toString())),Fi((()=>s>0),Uo("The number of periods by year (%s) must strictly greater than 0.",s.toString())),Math.pow(1+o/s,s)-1},isExported:!0};function Jm(e,t,o,s,i){return 0===e?-(s+o*t):-s*(1+e)**t-o*(1+e*i)*((1+e)**t-1)/e}const Qm={description:Uo("Future value of an annuity investment."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_amount (number)",Uo("The amount per period to be paid.")),od("present_value (number, default=0)",Uo("The current value of the annuity.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;return{value:Jm(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),Zi(i)?1:0),format:"#,##0.00"}},isExported:!0},ef={description:Uo("Future value of principal from series of rates."),args:[od("principal (number)",Uo("The amount of initial capital or value to compound against.")),od("rate_schedule (number, range<number>)",Uo("A series of interest rates to compound against the principal."))],compute:function(e,t){return en([t],((e,t)=>e*(1+ki(t,this.locale))),ki(e,this.locale))},isExported:!0},tf={description:Uo("Calculates effective interest rate."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("investment (number)",Uo("The amount invested in the security.")),od("redemption (number)",Uo("The amount to be received at maturity.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(s,this.locale),l=ki(o,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),xm(l),gm(a),um(c);return(a-l)/l/Ws(n,r,c)},isExported:!0};function of(e,t,o,s,i,n){return pf(e,o,s,i,n)-ff(e,t,o,s,i,n)}const sf={description:Uo("Payment on the principal of an investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("period (number)",Uo("The amortization period, in terms of number of periods.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i={value:0},n={value:0}){return{value:of(ki(e,this.locale),ki(t,this.locale),ki(o,this.locale),ki(s,this.locale),ki(i,this.locale),Zi(n)?1:0),format:"#,##0.00"}},isExported:!0},nf={description:Uo("Internal rate of return given periodic cashflows."),args:[od("cashflow_amounts (number, range<number>)",Uo("An array or range containing the income or payments associated with the investment.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the internal rate of return will be."))],compute:function(e,t={value:.1}){const o=ki(t,this.locale);_m(o);let s=!1,i=!1,n=[];Ji([e],(({value:e})=>{e>0&&(s=!0),e<0&&(i=!0),n.push(e)}),this.locale),Fi((()=>s&&i),Uo("The cashflow_amounts must include negative and positive values."));const r=n.shift();return{value:Mm((function(e){return function(e,t,o){const s=o.length;let i=0;return o.reduce(((t,o)=>(i++,t+o*e**(s-i))),t*e**s)}(e,r,n)}),(function(e){return function(e,t,o){const s=o.length;let i=0;return o.reduce(((t,o)=>(i++,t+o*(s-i)*e**(s-i-1))),t*s*e**(s-1))}(e,r,n)}),o+1,20,1e-5)-1,format:"0%"}},isExported:!0},rf={description:Uo("Returns the interest paid at a particular period of an investment."),args:[od("rate (number)",Uo("The interest rate.")),od("period (number)",Uo("The period for which you want to view the interest payment.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity."))],compute:function(e,t,o,s){const i=ki(e,this.locale),n=ki(t,this.locale),r=ki(o,this.locale),a=ki(s,this.locale);Fi((()=>0!==r),Uo("The number of periods must be different than 0.",r.toString()));return-1*(a-a*(n/r))*i},isExported:!0},af={description:Uo("Modified Macaulay duration."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){return Xm.compute.bind(this)(e,t,o,s,i,n)/(1+ki(s,this.locale)/Math.trunc(ki(i,this.locale)))},isExported:!0},lf={description:Uo("Modified internal rate of return."),args:[od("cashflow_amounts (range<number>)",Uo("A range containing the income or payments associated with the investment. The array should contain bot payments and incomes.")),od("financing_rate (number)",Uo("The interest rate paid on funds invested.")),od("reinvestment_return_rate (number)",Uo("The return (as a percentage) earned on reinvestment of income received from the investment."))],compute:function(e,t,o){const s=ki(t,this.locale),i=ki(o,this.locale),n=rn(e).flat().filter((e=>null!==e.value)).map((e=>ki(e,this.locale))),r=n.length;let a=0,l=0;for(const e of je(0,r)){const t=n[e];t>=0?a+=t*(i+1)**(r-e-1):l+=t/(s+1)**e}Fi((()=>0!==l&&0!==a),Uo("There must be both positive and negative values in cashflow_amounts."));return(-a/l)**(1/(r-1))-1},isExported:!0},cf={description:Uo("Annual nominal interest rate."),args:[od("effective_rate (number)",Uo("The effective interest rate per year.")),od("periods_per_year (number)",Uo("The number of compounding periods per year."))],compute:function(e,t){const o=ki(e,this.locale),s=Math.trunc(ki(t,this.locale));return Fi((()=>o>0),Uo("The effective rate (%s) must must strictly greater than 0.",o.toString())),Fi((()=>s>0),Uo("The number of periods by year (%s) must strictly greater than 0.",s.toString())),(Math.pow(o+1,1/s)-1)*s},isExported:!0},hf={description:Uo("Number of payment periods for an investment."),args:[od("rate (number)",Uo("The interest rate.")),od("payment_amount (number)",Uo("The amount of each payment made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i)?1:0;if(0===n)return-(l+a)/r;const h=r*(1+n*c)/n;return Math.log((h-l)/(a+h))/Math.log(1+n)},isExported:!0};function df(e,t,o,s){let i=0;return tn(o,((t,o)=>(i++,t+o/(1+e)**i)),t,s)}const uf={description:Uo("The net present value of an investment based on a series of periodic cash flows and a discount rate."),args:[od("discount (number)",Uo("The discount rate of the investment over one period.")),od("cashflow1 (number, range<number>)",Uo("The first future cash flow.")),od("cashflow2 (number, range<number>, repeating)",Uo("Additional future cash flows."))],compute:function(e,...t){const o=ki(e,this.locale);return Fi((()=>-1!==o),Uo("The discount (%s) must be different from -1.",o.toString())),{value:df(o,0,t,this.locale),format:"#,##0.00"}},isExported:!0},gf={description:Uo("Computes the number of periods needed for an investment to reach a value."),args:[od("rate (number)",Uo("The rate at which the investment grows each period.")),od("present_value (number)",Uo("The investment's current value.")),od("future_value (number)",Uo("The investment's desired future value."))],compute:function(e,t,o){const s=ki(e,this.locale),i=ki(t,this.locale),n=ki(o,this.locale);return fm(s),Fi((()=>i>0),Uo("The present_value (%s) must be strictly positive.",i.toString())),Fi((()=>n>0),Uo("The future_value (%s) must be strictly positive.",n.toString())),(Math.log(n)-Math.log(i))/Math.log(1+s)},isExported:!0};function pf(e,t,o,s,i){if(mm(t),0===e)return-(s+o)/t;let n=-(o*(1+e)**t+s);return n=n*e/((1+e*i)*((1+e)**t-1)),n}const mf={description:Uo("Periodic payment for an annuity investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){const n=ki(t,this.locale),r=ki(e,this.locale),a=Zi(i)?1:0,l=ki(s,this.locale);return{value:pf(r,n,ki(o,this.locale),l,a),format:"#,##0.00"}},isExported:!0};function ff(e,t,o,s,i,n){mm(o),Fi((()=>t>0&&t<=o),Uo("The period must be between 1 and number_of_periods (%s)",o));const r=pf(e,o,s,i,n);if(1===n&&1===t)return r;return r+-Jm(e,0===n?t-1:t-2,r,s+r*n,0)*e}const vf={description:Uo("Payment on the principal of an investment."),args:[od("rate (number)",Uo("The annualized rate of interest.")),od("period (number)",Uo("The amortization period, in terms of number of periods.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s,i={value:0},n={value:0}){const r=ki(o,this.locale),a=ki(e,this.locale),l=ki(t,this.locale),c=Zi(n)?1:0,h=ki(i,this.locale);return{value:ff(a,l,r,ki(s,this.locale),h,c),format:"#,##0.00"}},isExported:!0},bf={description:Uo("Present value of an annuity investment."),args:[od("rate (number)",Uo("The interest rate.")),od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_amount (number)",Uo("The amount per period to be paid.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period."))],compute:function(e,t,o,s={value:0},i={value:0}){s=s||0,i=i||0;const n=ki(e,this.locale),r=ki(t,this.locale),a=ki(o,this.locale),l=ki(s,this.locale),c=Zi(i)?1:0;return{value:n?-(a*(1+n*c)*((1+n)**r-1)/n+l)/(1+n)**r:-(l+a*r),format:"#,##0.00"}},isExported:!0},Sf={description:Uo("Price of a security paying periodic interest."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=Math.trunc(ki(e,this.locale)),l=Math.trunc(ki(t,this.locale)),c=ki(o,this.locale),h=ki(s,this.locale),d=ki(i,this.locale),u=Math.trunc(ki(n,this.locale)),g=Math.trunc(ki(r,this.locale));cm(a,l),dm(u),um(g),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),Fi((()=>h>=0),Uo("The yield (%s) must be positive or null.",h.toString())),gm(d);const p=Ws(a,l,g)*u,m=Math.ceil(p),f=p-Math.floor(p)||1,v=1+h/u,b=100*c/u;if(1===m)return(b+d)/(f*h/u+1)-b*(1-f);let S=0;for(let e=1;e<=m;e++)S+=b/v**(e-1+f);return d/v**(m-1+f)+S-b*(1-f)},isExported:!0},yf={description:Uo("Price of a discount security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the security at time of purchase.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),Im(a),gm(l);return l-a*l*Ws(n,r,c)},isExported:!0},Cf={description:Uo("Calculates the price of a security paying interest at maturity, based on expected yield."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("issue (date)",Uo("The date the security was initially issued.")),od("rate (number)",Uo("The annualized rate of interest.")),od("yield (number)",Uo("The expected annual yield of the security.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){n=n||0;const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=Math.trunc(ki(o,this.locale)),c=ki(s,this.locale),h=ki(i,this.locale),d=Math.trunc(ki(n,this.locale));hm(r,l),cm(r,a),um(d),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),Fi((()=>h>=0),Uo("The yield (%s) must be positive or null.",h.toString()));const u=Ws(r,a,d),g=Ws(r,l,d);return(100+Ws(l,a,d)*c*100)/(1+u*h)-g*c*100},isExported:!0},wf=.1,xf={description:Uo("Interest rate of an annuity investment."),args:[od("number_of_periods (number)",Uo("The number of payments to be made.")),od("payment_per_period (number)",Uo("The amount per period to be paid.")),od("present_value (number)",Uo("The current value of the annuity.")),od("future_value (number, default=0)",Uo("The future value remaining after the final payment has been made.")),od("end_or_beginning (number, default=0)",Uo("Whether payments are due at the end (0) or beginning (1) of each period.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the interest rate will be."))],compute:function(e,t,o,s={value:0},i={value:0},n={value:wf}){const r=ki(e,this.locale),a=ki(t,this.locale),l=Zi(i)?1:0,c=ki(n,this.locale)||wf;let h=ki(s,this.locale),d=ki(o,this.locale);mm(r),Fi((()=>[a,d,h].some((e=>e>0))&&[a,d,h].some((e=>e<0))),Uo("There must be both positive and negative values in [payment_amount, present_value, future_value].",r.toString())),_m(c),h-=a*l,d+=a*l;return{value:Mm((e=>{const t=Math.pow(1+e,r);return h+d*t+a*((t-1)/e)}),(e=>{const t=Math.pow(1+e,r-1),o=Math.pow(1+e,r);return d*r*t+a*(r*t/e-(o-1)/e/e)}),c,40,1e-5),format:"0%"}},isExported:!0},If={description:Uo("Amount received at maturity for a security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("investment (number)",Uo("The amount invested (irrespective of face value of each security).")),od("discount (number)",Uo("The discount rate of the security invested in.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),xm(a),Im(l);return a/(1-l*Ws(n,r,c))},isExported:!0},Ef={description:Uo("Computes the rate needed for an investment to reach a specific value within a specific number of periods."),args:[od("number_of_periods (number)",Uo("The number of periods.")),od("present_value (number)",Uo("The present value of the investment.")),od("future_value (number)",Uo("The future value of the investment."))],compute:function(e,t,o){const s=ki(e,this.locale),i=ki(t,this.locale),n=ki(o,this.locale);return mm(s),(n/i)**(1/s)-1},isExported:!0},Rf={description:Uo("Depreciation of an asset using the straight-line method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated."))],compute:function(e,t,o){return{value:(ki(e,this.locale)-ki(t,this.locale))/ki(o,this.locale),format:"#,##0.00"}},isExported:!0},Tf={description:Uo("Depreciation via sum of years digit method."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("period (number)",Uo("The single period within life for which to calculate depreciation."))],compute:function(e,t,o,s){const i=ki(e,this.locale),n=ki(t,this.locale),r=ki(o,this.locale),a=ki(s,this.locale);Sm(a),vm(r),wm(a,r);return{value:(r-a+1)/(r*(r+1)/2)*(i-n),format:"#,##0.00"}},isExported:!0};function Af(e,t,o){return 100*(1-o*Ws(e,t,2))}const _f={description:Uo("Price of a US Treasury bill."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the bill at time of purchase."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);return cm(s,i),Tm(s,i,this.locale),Im(n),Em(n),Af(s,i,n)},isExported:!0},Df={description:Uo("Equivalent rate of return for a US Treasury bill."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("discount (number)",Uo("The discount rate of the bill at time of purchase."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);cm(s,i),Tm(s,i,this.locale),Im(n),Em(n);const r=Cp.compute.bind(this)({value:i},{value:s});if(r<=182)return 365*n/(360-n*r);const a=Af(s,i,n)/100,l=r/(366===r?366:365);return(-2*l+2*Math.sqrt(l**2-(2*l-1)*(1-1/a)))/(2*l-1)},isExported:!0},Of={description:Uo("The yield of a US Treasury bill based on price."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value."))],compute:function(e,t,o){const s=Math.trunc(ki(e,this.locale)),i=Math.trunc(ki(t,this.locale)),n=ki(o,this.locale);cm(s,i),Tm(s,i,this.locale),pm(n);return(100-n)/n*(1/Ws(s,i,2))},isExported:!0},Ff={description:Uo("Variable declining balance. WARNING : does not handle decimal periods."),args:[od("cost (number)",Uo("The initial cost of the asset.")),od("salvage (number)",Uo("The value of the asset at the end of depreciation.")),od("life (number)",Uo("The number of periods over which the asset is depreciated.")),od("start (number)",Uo("Starting period to calculate depreciation.")),od("end (number)",Uo("Ending period to calculate depreciation.")),od("factor (number, default=2)",Uo("The number of months in the first year of depreciation.")),od("no_switch (number, default=false)",Uo("Whether to switch to straight-line depreciation when the depreciation is greater than the declining balance calculation."))],compute:function(e,t,o,s,i,n={value:2},r={value:false}){n=n||0;const a=ki(e,this.locale),l=ki(t,this.locale),c=ki(o,this.locale),h=Math.trunc(ki(s,this.locale)),d=Math.trunc(ki(i,this.locale)),u=ki(n,this.locale),g=Zi(r);if(bm(a),ym(l),function(e,t,o){vm(o),Fi((()=>e>=0),Uo("The start_period (%s) must be greater or equal than 0.",e.toString())),Fi((()=>t>=0),Uo("The end_period (%s) must be greater or equal than 0.",t.toString())),Fi((()=>e<=t),Uo("The start_period (%s) must be smaller or equal to the end_period (%s).",e.toString(),t.toString())),Fi((()=>t<=o),Uo("The end_period (%s) must be smaller or equal to the life (%s).",e.toString(),o.toString()))}(h,d,c),Rm(u),0===a)return 0;if(l>=a)return h<1?a-l:0;const p=u/c;if(p>=1)return h<1?a-l:0;let m=a,f=0,v=0,b=!1;for(let e=0;e<d;e++){if(!b||g){const t=m*p,o=(m-l)/(c-e);!g&&o>t?(b=!0,f=o):f=t}const t=Math.max(m-f,l);e>=h&&(v+=m-t),m=t}return v},isExported:!0},Mf={description:Uo("Internal rate of return given non-periodic cash flows."),args:[od("cashflow_amounts (range<number>)",Uo("An range containing the income or payments associated with the investment.")),od("cashflow_dates (range<number>)",Uo("An range with dates corresponding to the cash flows in cashflow_amounts.")),od("rate_guess (number, default=0.1)",Uo("An estimate for what the internal rate of return will be."))],compute:function(e,t,o={value:wf}){const s=ki(o,this.locale),i=e.flat().map((e=>ki(e,this.locale))),n=t.flat().map((e=>ki(e,this.locale)));var r;Dm(e,t),r=i,Fi((()=>r.some((e=>e>0))&&r.some((e=>e<0))),Uo("There must be both positive and negative values in cashflow_amounts.")),Om(n),_m(s);const a=new Map;for(const e of je(0,n.length)){const t=n[e];a.has(t)?a.set(t,a.get(t)+i[e]):a.set(t,i[e])}const l=Array.from(a.keys()),c=l.map((e=>a.get(e)));return Mm((e=>{let t=c[0];for(const o of je(1,c.length)){const s=(l[0]-l[o])/365;t+=c[o]*(1+e)**s}return t}),(e=>{let t=0;for(const o of je(1,c.length)){const s=(l[0]-l[o])/365;t+=s*c[o]*(1+e)**(s-1)}return t}),s,40,1e-5,(e=>e?e/10-.9:-.9))},isExported:!0},Pf={description:Uo("Net present value given to non-periodic cash flows.."),args:[od("discount (number)",Uo("The discount rate of the investment over one period.")),od("cashflow_amounts (number, range<number>)",Uo("An range containing the income or payments associated with the investment.")),od("cashflow_dates (number, range<number>)",Uo("An range with dates corresponding to the cash flows in cashflow_amounts."))],compute:function(e,t,o){const s=ki(e,this.locale),i=bi(t)?t.flat().map((e=>Hi(e,this.locale))):[Hi(t,this.locale)],n=bi(o)?o.flat().map((e=>Hi(e,this.locale))):[Hi(o,this.locale)];if(bi(o)&&bi(t)?Dm(t,o):Fi((()=>i.length===n.length),Uo("There must be the same number of values in cashflow_amounts and cashflow_dates.")),Om(n),fm(s),1===i.length)return i[0];const r=new Map;for(const e of je(0,n.length)){const t=n[e];r.has(t)?r.set(t,r.get(t)+i[e]):r.set(t,i[e])}const a=Array.from(r.keys()),l=a.map((e=>r.get(e)));let c=l[0];for(const e of je(1,l.length)){const t=(a[0]-a[e])/365;c+=l[e]*(1+s)**t}return c},isExported:!0},Nf={description:Uo("Annual yield of a security paying periodic interest."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("rate (number)",Uo("The annualized rate of interest.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("frequency (number)",Uo("The number of interest or coupon payments per year (1, 2, or 4).")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n,r={value:0}){r=r||0;const a=Math.trunc(ki(e,this.locale)),l=Math.trunc(ki(t,this.locale)),c=ki(o,this.locale),h=ki(s,this.locale),d=ki(i,this.locale),u=Math.trunc(ki(n,this.locale)),g=Math.trunc(ki(r,this.locale));cm(a,l),dm(u),um(g),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),pm(h),gm(d);const p=Ws(a,l,g)*u,m=Math.ceil(p),f=p-Math.floor(p)||1,v=100*c/u;if(1===m){const e=h+v*(1-f);return(d+v-e)*u*(1/f)/e}const b=Mm((function(e){return function(e,t,o,s,i,n){let r=n-(e+i*(1-t))*s**(o-1+t);for(let e=1;e<=o;e++)r+=i*s**(e-1);return r}(h,f,m,e,v,d)}),(function(e){return function(e,t,o,s,i){let n=-(e+i*(1-t))*(o-1+t)*s**(o-2+t);for(let e=1;e<=o;e++)n+=i*(e-1)*s**(e-2);return n}(h,f,m,e,v)}),1+(c+1)/u,100,1e-5);return(b-1)*u},isExported:!0},kf={description:Uo("Annual yield of a discount security."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("price (number)",Uo("The price at which the security is bought per 100 face value.")),od("redemption (number)",Uo("The redemption amount per 100 face value, or par.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i={value:0}){i=i||0;const n=Math.trunc(ki(e,this.locale)),r=Math.trunc(ki(t,this.locale)),a=ki(o,this.locale),l=ki(s,this.locale),c=Math.trunc(ki(i,this.locale));cm(n,r),um(c),pm(a),gm(l);return(l/a-1)/Ws(n,r,c)},isExported:!0},Vf={description:Uo("Annual yield of a security paying interest at maturity."),args:[od("settlement (date)",Uo("The settlement date of the security, the date after issuance when the security is delivered to the buyer.")),od("maturity (date)",Uo("The maturity or end date of the security, when it can be redeemed at face, or par value.")),od("issue (date)",Uo("The date the security was initially issued.")),od("rate (number)",Uo("The annualized rate of interest.")),od("price (number)",Uo("The price at which the security is bought.")),od("day_count_convention (number, default=0 )",Uo("An indicator of what day count method to use."))],compute:function(e,t,o,s,i,n={value:0}){n=n||0;const r=Math.trunc(ki(e,this.locale)),a=Math.trunc(ki(t,this.locale)),l=Math.trunc(ki(o,this.locale)),c=ki(s,this.locale),h=ki(i,this.locale),d=Math.trunc(ki(n,this.locale));cm(r,a),um(d),Fi((()=>r>=l),Uo("The settlement (%s) must be greater than or equal to the issue (%s).",r.toString(),l.toString())),Fi((()=>c>=0),Uo("The rate (%s) must be positive or null.",c.toString())),pm(h);const u=Ws(l,a,d),g=Ws(l,r,d),p=Ws(r,a,d);return(100*(1+c*u)/(h+100*c*g)-1)/p},isExported:!0};var Lf,Hf=Object.freeze({__proto__:null,ACCRINTM:Pm,AMORLINC:Nm,COUPDAYBS:Vm,COUPDAYS:km,COUPDAYSNC:Lm,COUPNCD:Hm,COUPNUM:Um,COUPPCD:Bm,CUMIPMT:zm,CUMPRINC:$m,DB:Gm,DDB:qm,DISC:Zm,DOLLARDE:jm,DOLLARFR:Ym,DURATION:Xm,EFFECT:Km,FV:Qm,FVSCHEDULE:ef,INTRATE:tf,IPMT:sf,IRR:nf,ISPMT:rf,MDURATION:af,MIRR:lf,NOMINAL:cf,NPER:hf,NPV:uf,PDURATION:gf,PMT:mf,PPMT:vf,PRICE:Sf,PRICEDISC:yf,PRICEMAT:Cf,PV:bf,RATE:xf,RECEIVED:If,RRI:Ef,SLN:Rf,SYD:Tf,TBILLEQ:Df,TBILLPRICE:_f,TBILLYIELD:Of,VDB:Ff,XIRR:Mf,XNPV:Pf,YIELD:Nf,YIELDDISC:kf,YIELDMAT:Vf});!function(e){e[e.LeftRef=0]="LeftRef",e[e.RightRef=1]="RightRef",e[e.Separator=2]="Separator",e[e.FullColumnSeparator=3]="FullColumnSeparator",e[e.FullRowSeparator=4]="FullRowSeparator",e[e.RightColumnRef=5]="RightColumnRef",e[e.RightRowRef=6]="RightRowRef",e[e.Found=7]="Found"}(Lf||(Lf={}));const Uf=(e,t=(()=>!0))=>[{goTo:e,guard:t}],Bf=(e,t=(()=>!0))=>({goTo:e,guard:t}),zf={[Lf.LeftRef]:{REFERENCE:Uf(Lf.Separator),NUMBER:Uf(Lf.FullRowSeparator),SYMBOL:[Bf(Lf.FullColumnSeparator,(e=>{return t=e.value,Hr.test(t);var t})),Bf(Lf.FullRowSeparator,(e=>zr(e.value)))]},[Lf.FullColumnSeparator]:{SPACE:Uf(Lf.FullColumnSeparator),OPERATOR:Uf(Lf.RightColumnRef,(e=>":"===e.value))},[Lf.FullRowSeparator]:{SPACE:Uf(Lf.FullRowSeparator),OPERATOR:Uf(Lf.RightRowRef,(e=>":"===e.value))},[Lf.Separator]:{SPACE:Uf(Lf.Separator),OPERATOR:Uf(Lf.RightRef,(e=>":"===e.value))},[Lf.RightRef]:{SPACE:Uf(Lf.RightRef),NUMBER:Uf(Lf.Found),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value))),SYMBOL:Uf(Lf.Found,(e=>$r(e.value)||Gr(e.value)))},[Lf.RightColumnRef]:{SPACE:Uf(Lf.RightColumnRef),SYMBOL:Uf(Lf.Found,(e=>$r(e.value))),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value)))},[Lf.RightRowRef]:{SPACE:Uf(Lf.RightRowRef),NUMBER:Uf(Lf.Found),REFERENCE:Uf(Lf.Found,(e=>Wr(e.value))),SYMBOL:Uf(Lf.Found,(e=>Gr(e.value)))},[Lf.Found]:{}};function $f(e){let t=0,o=zf[Lf.LeftRef],s="";for(;void 0!==o;){const i=e[t++];if(!i)return null;const n=o[i.type]?.find((e=>e.guard(i))),r=n?n.goTo:void 0;switch(r){case void 0:return null;case Lf.Found:return s+=i.value,e.splice(0,t),{type:"REFERENCE",value:s};default:o=zf[r],s+=i.value}}return null}function Gf(e,t=fi){const o=Pa(e,t),s=[];for(;o.length;)s.push($f(o)||o.shift());return s}const Wf=/[a-zA-Z0-9\_]+(\.[a-zA-Z0-9\_]+)*/,qf=["-","+"],Zf=["%"],jf=["*","+","&"],Yf={"^":30,"%":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10};function Xf(e){const t=e.shift();if(!t)throw new Ei;switch(t.type){case"DEBUGGER":const o=Qf(e,1e3);return o.debug=!0,o;case"NUMBER":return{type:"NUMBER",value:ei(t.value,fi)};case"STRING":return{type:"STRING",value:Ue(t.value)};case"INVALID_REFERENCE":return{type:"REFERENCE",value:wi.InvalidReference};case"REFERENCE":if(":"===e[0]?.value&&"REFERENCE"===e[1]?.type){e.shift();const o=e.shift();return{type:"REFERENCE",value:`${t.value}:${o?.value}`}}return{type:"REFERENCE",value:t.value};case"SYMBOL":const s=t.value,i=e[0];if("LEFT_PAREN"===i?.type&&Wf.test(t.value)&&s===Ge(s,"'")){const t=function(e){Jf(e,"LEFT_PAREN",Uo("Missing opening parenthesis"));const t=e[0];if("RIGHT_PAREN"===t?.type)return Jf(e,"RIGHT_PAREN"),[];const o=[];o.push(Kf(e));for(;"RIGHT_PAREN"!==e[0]?.type;)Jf(e,"ARG_SEPARATOR",Uo("Wrong function call")),o.push(Kf(e));return Jf(e,"RIGHT_PAREN"),o}(e);return{type:"FUNCALL",value:s,args:t}}const n=s.toUpperCase();return"TRUE"===n||"FALSE"===n?{type:"BOOLEAN",value:"TRUE"===n}:{type:"SYMBOL",value:Ge(t.value,"'")};case"LEFT_PAREN":const r=Qf(e);return Jf(e,"RIGHT_PAREN",Uo("Missing closing parenthesis")),r;case"OPERATOR":const a=t.value;if(qf.includes(a))return{type:"UNARY_OPERATION",value:a,operand:Qf(e,Yf[a])};throw new Ei(Uo("Unexpected token: %s",t.value));default:throw new Ei(Uo("Unexpected token: %s",t.value))}}function Kf(e){const t=e[0];return"ARG_SEPARATOR"===t?.type||"RIGHT_PAREN"===t?.type?{type:"EMPTY",value:""}:Qf(e)}function Jf(e,t,o){const s=e.shift();if(!s||s.type!==t)throw new Ei(o)}function Qf(e,t=0){if(0===e.length)throw new Ei;let o=Xf(e);for(;"OPERATOR"===e[0]?.type&&Yf[e[0].value]>t;){const t=e.shift().value;if(Zf.includes(t))o={type:"UNARY_OPERATION",value:t,operand:o,postfix:!0};else{o={type:"BIN_OPERATION",value:t,left:o,right:Qf(e,Yf[t])}}}return o}function ev(e){return tv(Gf(e))}function tv(e){e=e.filter((e=>"SPACE"!==e.type)),"="===e[0]?.value&&e.splice(0,1);const t=Qf(e);if(e.length)throw new Ei;return t}function ov(e,t,o){return nv(e,(e=>e.type===t?o(e):e))}function sv(e){return Array.from(iv(e))}function*iv(e){switch(yield e,e.type){case"FUNCALL":for(const t of e.args)yield*iv(t);break;case"UNARY_OPERATION":yield*iv(e.operand);break;case"BIN_OPERATION":yield*iv(e.left),yield*iv(e.right)}}function nv(e,t){switch((e=t(e)).type){case"FUNCALL":return{...e,args:e.args.map((e=>nv(e,t)))};case"UNARY_OPERATION":return{...e,operand:nv(e.operand,t)};case"BIN_OPERATION":return{...e,right:nv(e.right,t),left:nv(e.left,t)};default:return e}}function rv(e){switch(e.type){case"FUNCALL":const t=e.args.map((e=>rv(e)));return`${e.value}(${t.join(",")})`;case"NUMBER":return e.value.toString();case"REFERENCE":default:return e.value;case"STRING":return`"${e.value}"`;case"BOOLEAN":return e.value?"TRUE":"FALSE";case"UNARY_OPERATION":return e.postfix?av(e)+e.value:e.value+lv(e);case"BIN_OPERATION":return av(e)+e.value+lv(e)}}function av(e){const t=e.value,o="left"in e?e.left:e.operand,s=o.value;return"BIN_OPERATION"===o.type&&Yf[s]<Yf[t]?`(${rv(o)})`:rv(o)}function lv(e){const t=e.value,o="right"in e?e.right:e.operand,s=Yf[o.value],i=Yf[t];let n=!1;return"BIN_OPERATION"!==o.type?n=!1:s<i?n=!0:s!==i||jf.includes(t)||(n=!0),n?`(${rv(o)})`:rv(o)}function cv(e,t){return function(e){for(const t of e)if(t.functionContext){const{argsTokens:e,args:o}=t.functionContext;if(delete t.functionContext.argsTokens,o.length||!e)continue;"LEFT_PAREN"===e[0]?.[0]?.type&&(e[0]=e[0].slice(1));for(const t of e){let e=t;"ARG_SEPARATOR"===e.at(-1)?.type&&(e=e.slice(0,-1));try{o.push(tv(e))}catch(e){o.push(void 0)}}}return e}(function(e){let t=[],o="";function s(e){if(0===t.length)return;const o=t.at(-1);if(o&&o.argsTokens){const{argsTokens:t,argPosition:s}=o;t[s]||(t[s]=[]),t[s].push({value:e.value,type:e.type})}}return e.map(((e,i)=>{switch(["SPACE","LEFT_PAREN"].includes(e.type)||(o=""),e.type){case"SYMBOL":s(e),o=e.value;break;case"LEFT_PAREN":t.push({parent:o,argPosition:0,argsTokens:[],args:[]}),s(e),o="";break;case"RIGHT_PAREN":const i=t.pop();i?.argsTokens?.flat().forEach(s),s(e);break;case"ARG_SEPARATOR":s(e),t.length&&t[t.length-1].argPosition++;break;default:s(e)}if(t.length){const o=t[t.length-1];o.parent&&(e.functionContext=Object.assign({},o))}return e}))}(function(e){let t=[],o=0;return e.map(((s,i)=>{if("LEFT_PAREN"===s.type){t.push(o+1),o=0;for(let o=i-1;o>=0;o--){if("SPACE"!==e[o].type){"SYMBOL"===e[o].type&&(e[o].parenthesesCode=t.join(":"));break}e[o].parenthesesCode=t.join(":")}}return s.parenthesesCode=t.join(":"),"RIGHT_PAREN"===s.type&&t.length&&(o=t.pop()),s}))}(function(e){let t=0;return e.map((e=>{const o=e.value.toString().length,s=Object.assign({},e,{start:t,end:t+o,length:o});return t=s.end,s}))}(Gf(e,t)))))}function hv(e){if("REFERENCE"!==e.type)return e;const{xc:t,sheetName:o}=qr(e.value),[s,i]=t.split(":"),n=dv(s),r=i?`:${dv(i)}`:"";return{...e,value:Zr(o,n+r)}}function dv(e){switch(function(e){if(function(e){return e.startsWith("$")&&e.length>1&&e.slice(1).includes("$")}(e))return"colrow";if(function(e){return e.startsWith("$")}(e))return"col";if(function(e){return e.includes("$",1)}(e))return"row";return"none"}(e)){case"none":e=uv(e,"colrow");break;case"colrow":e=uv(e,"row");break;case"row":e=uv(e,"col");break;case"col":e=uv(e,"none")}return e}function uv(e,t){if(e.includes("!"))throw new Error("The given XC should not contain a sheet name");let o;switch(e=e.replace(/\$/g,""),t){case"col":return"$"+e;case"row":return o=e.search(/[0-9]/),e.slice(0,o)+"$"+e.slice(o);case"colrow":return o=e.search(/[0-9]/),-1===o||0===o?"$"+e:"$"+(e=e.slice(0,o)+"$"+e.slice(o));case"none":return e}}function gv(e,t,o){const s=(t.startsWith("=")?cv(t,o):[]).filter((t=>t.start<=e.start&&t.end>=e.start||t.start>=e.start&&t.start<e.end)),i=s.filter((e=>"REFERENCE"===e.type));if(0===i.length)return;const n=s.map(hv).map((e=>e.value)).join(""),r=s[0].start,a=s[s.length-1].end,l=t.slice(0,r)+n+t.slice(a),c=l.length-t.length,h={start:i[0].start,end:i[i.length-1].end+c};return 1===i.length&&e.start===e.end&&(h.start=h.end),{content:l,selection:h}}const pv=["address","col","contents","format","row","type"],mv={description:Uo("Gets information about a cell."),args:[od("info_type (string)",Uo("The type of information requested. Can be one of %s",pv.join(", "))),od("reference (meta)",Uo("The reference to the cell."))],compute:function(e,t){const o=Gi(e).toLowerCase();Fi((()=>pv.includes(o)),Uo("The info_type should be one of %s.",pv.join(", ")));const s=this.__originSheetId,i=Gi(t),n=i.includes(":")?i.split(":")[0]:i;let{sheetName:r,xc:a}=qr(n);r=r===this.getters.getSheetName(s)?void 0:r;const l=Zr(r,uv(a,"colrow")),c=this.getters.getRangeFromSheetXC(s,l);switch(o){case"address":return this.getters.getRangeString(c,s);case"col":return c.zone.left+1;case"contents":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top};return this.getters.getEvaluatedCell(e).value}case"format":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top};return this.getters.getEvaluatedCell(e).format||""}case"row":return c.zone.top+1;case"type":{const e={sheetId:c.sheetId,col:c.zone.left,row:c.zone.top},t=this.getters.getEvaluatedCell(e).type;return t===oi.empty?"b":t===oi.text?"l":"v"}}return""},isExported:!0},fv={description:Uo("Whether a value is an error other than #N/A."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){const t=e?.value;return Pi(t)&&t!==wi.NotAvailable},isExported:!0},vv={description:Uo("Whether a value is an error."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){const t=e?.value;return Pi(t)},isExported:!0},bv={description:Uo("Whether a value is `true` or `false`."),args:[od("value (any)",Uo("The value to be verified as a logical TRUE or FALSE."))],compute:function(e){return"boolean"==typeof e?.value},isExported:!0},Sv={description:Uo("Whether a value is the error #N/A."),args:[od("value (any)",Uo("The value to be verified as an error type."))],compute:function(e){return e?.value===wi.NotAvailable},isExported:!0},yv={description:Uo("Whether a value is non-textual."),args:[od("value (any)",Uo("The value to be checked."))],compute:function(e){return!wv.compute.bind(this)(e)},isExported:!0},Cv={description:Uo("Whether a value is a number."),args:[od("value (any)",Uo("The value to be verified as a number."))],compute:function(e){return"number"==typeof e?.value},isExported:!0},wv={description:Uo("Whether a value is text."),args:[od("value (any)",Uo("The value to be verified as text."))],compute:function(e){return"string"==typeof e?.value&&!1===Pi(e?.value)},isExported:!0},xv={description:Uo("Whether the referenced cell is empty"),args:[od("value (any)",Uo("Reference to the cell that will be checked for emptiness."))],compute:function(e){return null===e?.value},isExported:!0},Iv={description:Uo("Returns the error value #N/A."),args:[],compute:function(){return{value:wi.NotAvailable}},isExported:!0};var Ev=Object.freeze({__proto__:null,CELL:mv,ISBLANK:xv,ISERR:fv,ISERROR:vv,ISLOGICAL:bv,ISNA:Sv,ISNONTEXT:yv,ISNUMBER:Cv,ISTEXT:wv,NA:Iv});const Rv={description:Uo("Logical `and` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that represent logical values."))],compute:function(...e){const{result:t,foundBoolean:o}=dl(e);return Fi((()=>o),Uo("[[FUNCTION_NAME]] has no valid input data.")),t},isExported:!0},Tv={description:Uo("Logical value `false`."),args:[],compute:function(){return!1},isExported:!0},Av={description:Uo("Returns value depending on logical expression."),args:[od("logical_expression (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE.")),od("value_if_true (any, range)",Uo("The value the function returns if logical_expression is TRUE.")),od("value_if_false (any, range, default=FALSE)",Uo("The value the function returns if logical_expression is FALSE."))],compute:function(e,t,o){if(Cl(e))return an(Av.compute,[e,t,o]);let s=Zi(Sl(e))?t:o;return Cl(s)||(s=Sl(s)),void 0===s?{value:""}:bi(s)||null!==s.value?s:{...s,value:""}},isExported:!0},_v={description:Uo("Value if it is not an error, otherwise 2nd argument."),args:[od("value (any, range)",Uo("The value to return if value itself is not an error.")),od('value_if_error (any, range, default="empty")',Uo("The value the function returns if value is an error."))],compute:function(e,t){if(Cl(e))return an(_v.compute,[e,t]);let o=Pi(Sl(e)?.value)?t:e;return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}},isExported:!0},Dv={description:Uo("Value if it is not an #N/A error, otherwise 2nd argument."),args:[od("value (any, range)",Uo("The value to return if value itself is not #N/A an error.")),od('value_if_error (any, range, default="empty")',Uo("The value the function returns if value is an #N/A error."))],compute:function(e,t){if(Cl(e))return an(Dv.compute,[e,t]);let o=Sl(e)?.value===wi.NotAvailable?t:e;return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}},isExported:!0},Ov={description:Uo("Returns a value depending on multiple logical expressions."),args:[od("condition1 (boolean, range<boolean>)",Uo("The first condition to be evaluated. This can be a boolean, a number, an array, or a reference to any of those.")),od("value1 (any, range)",Uo("The returned value if condition1 is TRUE.")),od("condition2 (boolean, any, range, repeating)",Uo("Additional conditions to be evaluated if the previous ones are FALSE.")),od("value2 (any, range, repeating)",Uo("Additional values to be returned if their corresponding conditions are TRUE."))],compute:function(...e){for(Fi((()=>e.length%2==0),Uo("Wrong number of arguments. Expected an even number of arguments."));e.length>0;){if(Cl(e[0]))return an(Ov.compute,e);const t=Zi(Sl(e.shift()));let o=e.shift();if(t)return Cl(o)||(o=Sl(o)),void 0===o?{value:""}:bi(o)||null!==o.value?o:{...o,value:""}}return new Ii(Uo("No match."))},isExported:!0},Fv={description:Uo("Returns opposite of provided logical value."),args:[od("logical_expression (boolean)",Uo("An expression or reference to a cell holding an expression that represents some logical value."))],compute:function(e){return!Zi(e)},isExported:!0},Mv={description:Uo("Logical `or` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that evaluate to logical values."))],compute:function(...e){const{result:t,foundBoolean:o}=ul(e);return Fi((()=>o),Uo("[[FUNCTION_NAME]] has no valid input data.")),t},isExported:!0},Pv={description:Uo("Logical value `true`."),args:[],compute:function(){return!0},isExported:!0},Nv={description:Uo("Logical `xor` operator."),args:[od("logical_expression1 (boolean, range<boolean>)",Uo("An expression or reference to a cell containing an expression that represents some logical value, i.e. TRUE or FALSE, or an expression that can be coerced to a logical value.")),od("logical_expression2 (boolean, range<boolean>, repeating)",Uo("More expressions that evaluate to logical values."))],compute:function(...e){let t=!1,o=!1;return ln(e,(e=>(t=!0,o=o?!e:e,!0))),Fi((()=>t),Uo("[[FUNCTION_NAME]] has no valid input data.")),o},isExported:!0};var kv=Object.freeze({__proto__:null,AND:Rv,FALSE:Tv,IF:Av,IFERROR:_v,IFNA:Dv,IFS:Ov,NOT:Fv,OR:Mv,TRUE:Pv,XOR:Nv});function Vv(e,t){const o=t.getPivotId(e);if(!o)throw new Ii(Uo('There is no pivot with id "%s"',e));return o}function Lv(e){if(e.length%2!=0)throw new Ii(Uo("Function PIVOT takes an even number of arguments."))}function Hv(e,t,o){const s=[];if("SPREADSHEET"===t.type&&t.dataSet){const{sheetId:o,zone:i}=t.dataSet,n=qo(i),r=e.getters.getRangeFromSheetXC(o,n);if(void 0===r||r.invalidXc||r.invalidSheetName)throw new Ti;if(e.__originCellPosition&&r.sheetId===e.__originSheetId&&os(hs(e.__originCellPosition),i))throw new Ri;s.push(r)}for(const t of o)if(t.computedBy){const o=e.getters.getMeasureCompiledFormula(t);s.push(...o.dependencies.filter((e=>!e.invalidXc)))}const i=e.__originCellPosition;i&&s.length&&(e.updateDependencies?.(i),e.addDependencies?.(i,s))}const Uv=!0;function Bv(e){return{value:wi.NotAvailable,message:Uo("Did not find value '%s' in [[FUNCTION_NAME]] evaluation.",Gi(e))}}const zv={description:Uo("Returns a cell reference as a string. "),args:[od("row (number)",Uo("The row number of the cell reference. ")),od("column (number)",Uo("The column number (not name) of the cell reference. A is column number 1. ")),od("absolute_relative_mode (number, default=1)",Uo("An indicator of whether the reference is row/column absolute. 1 is row and column absolute (e.g. $A$1), 2 is row absolute and column relative (e.g. A$1), 3 is row relative and column absolute (e.g. $A1), and 4 is row and column relative (e.g. A1).")),od("use_a1_notation (boolean, default=TRUE)",Uo("A boolean indicating whether to use A1 style notation (TRUE) or R1C1 style notation (FALSE).")),od("sheet (string, optional)",Uo("A string indicating the name of the sheet into which the address points."))],compute:function(e,t,o={value:1},s={value:!0},i){const n=Bi(e,this.locale),r=Bi(t,this.locale);zi(n),zi(r);const a=Bi(o,this.locale);var l,c;Fi((()=>[1,2,3,4].includes(a)),(l=4,c=a,Uo("The function [[FUNCTION_NAME]] expects a number value between %s and %s inclusive, but receives %s.",1..toString(),l.toString(),c.toString())));let h;if(Zi(s)){h=Ao(r-1,n-1,{rowFixed:[1,2].includes(a),colFixed:[1,3].includes(a)})}else{h=([1,2].includes(a)?`R${n}`:`R[${n}]`)+([1,3].includes(a)?`C${r}`:`C[${r}]`)}return void 0!==i?Zr(Gi(i),h):h},isExported:!0},$v={description:Uo("Column number of a specified cell."),args:[od("cell_reference (meta, default='this cell')",Uo("The cell whose column number will be returned. Column A corresponds to 1. By default, the function use the cell in which the formula is entered."))],compute:function(e){if(Pi(e?.value))return e;const t=void 0===e?this.__originCellPosition?.col:$o(e.value).left;return Fi((()=>void 0!==t),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter."),t+1},isExported:!0},Gv={description:Uo("Number of columns in a specified array or range."),args:[od("range (meta)",Uo("The range whose column count will be returned."))],compute:function(e){if(Pi(e?.value))return e;const t=$o(e.value);return t.right-t.left+1},isExported:!0},Wv={description:Uo("Horizontal lookup"),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The range to consider for the search. The first row in the range is searched for the key specified in search_key.")),od("index (number)",Uo("The row index of the value to be returned, where the first row in range is numbered 1.")),od("is_sorted (boolean, default=true)",Uo("Indicates whether the row to be searched (the first row of the specified range) is sorted, in which case the closest match for search_key will be returned."))],compute:function(e,t,o,s={value:Uv}){const i=Math.trunc(ki(o?.value,this.locale)),n=vn(t);Fi((()=>1<=i&&i<=n[0].length),Uo("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const r=(e,t)=>e[t][0].value,a=Zi(s.value)?gn(n,e,"nextSmaller","asc",n.length,r):pn(n,e,"wildcard",n.length,r,this.lookupCaches),l=n[a];return void 0===l?Bv(e):l[i-1]},isExported:!0},qv={description:Uo("Returns the content of a cell, specified by row and column offset."),args:[od("reference (any, range)",Uo("The range of cells from which the values are returned.")),od("row (number, default=0)",Uo("The index of the row to be returned from within the reference range of cells.")),od("column (number, default=0)",Uo("The index of the column to be returned from within the reference range of cells."))],compute:function(e,t={value:0},o={value:0}){const s=vn(e),i=ki(t.value,this.locale),n=ki(o.value,this.locale);return Fi((()=>n>=0&&n-1<s.length&&i>=0&&i-1<s[0].length),Uo("Index out of range.")),0===i&&0===n?s:0===i?[s[n-1]]:0===n?s.map((e=>[e[i-1]])):s[n-1][i-1]},isExported:!0},Zv={description:Uo("Returns the content of a cell, specified by a string."),args:[od("reference (string)",Uo("The range of cells from which the values are returned.")),od("use_a1_notation (boolean, default=TRUE)",Uo("A boolean indicating whether to use A1 style notation (TRUE) or R1C1 style notation (FALSE)."))],compute:function(e,t={value:!0}){let o=e?.value?.toString();if(!o)return new Ti(Uo("Reference should be defined."));if(!Zi(t))return new Ii(Uo("R1C1 notation is not supported."));const s=this.__originSheetId,i=this.__originCellPosition;i&&this.updateDependencies?.(i);const n=this.getters.getRangeFromSheetXC(s,o);if(void 0===n||n.invalidXc||n.invalidSheetName)return new Ti;i&&this.addDependencies?.(i,[n]);const r=[];for(let e=n.zone.left;e<=n.zone.right;e++){const t=[];for(let o=n.zone.top;o<=n.zone.bottom;o++){const s={sheetId:n.sheetId,col:e,row:o};t.push(this.getters.getEvaluatedCell(s))}r.push(t)}return 1===r.length&&1===r[0].length?r[0][0]:r},isExported:!0},jv={description:Uo("Look up a value."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("search_array (any, range)",Uo("One method of using this function is to provide a single sorted row or column search_array to look through for the search_key with a second argument result_range. The other way is to combine these two arguments into one search_array where the first row or column is searched and a value is returned from the last row or column in the array. If search_key is not found, a non-exact match may be returned.")),od("result_range (any, range, optional)",Uo("The range from which to return a result. The value returned corresponds to the location where search_key is found in search_range. This range must be only a single row or column and should not be used if using the search_result_array method."))],compute:function(e,t,o){const s=vn(t),i=vn(o);let n=s.length,r=s[0].length;const a=r>=n,l=a?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,c=gn(s,e,"nextSmaller","asc",a?r:n,l);return-1===c||a&&void 0===s[0][c]||!a&&void 0===s[c][r-1]?Bv(e):0===i[0].length?a?s[n-1][c]:s[c][r-1]:(n=i.length,r=i[0].length,Fi((()=>1===n||1===r),Uo("The result_range must be a single row or a single column.")),n>1?(Fi((()=>c<=n-1),Uo("[[FUNCTION_NAME]] evaluates to an out of range row value %s.",(c+1).toString())),i[c][0]):(Fi((()=>c<=r-1),Uo("[[FUNCTION_NAME]] evaluates to an out of range column value %s.",(c+1).toString())),i[0][c]))},isExported:!0},Yv={description:Uo("Position of item in range that matches value."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The one-dimensional array to be searched.")),od("search_type (number, default=1)",Uo("The search method. 1 (default) finds the largest value less than or equal to search_key when range is sorted in ascending order. 0 finds the exact value when range is unsorted. -1 finds the smallest value greater than or equal to search_key when range is sorted in descending order."))],compute:function(e,t,o={value:1}){let s=ki(o,this.locale);const i=vn(t),n=i.length,r=i[0].length;Fi((()=>1===n||1===r),Uo("The range must be a single row or a single column."));let a=-1;const l=1===n?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,c=1===n?i[0].length:i.length;switch(s=Math.sign(s),s){case 1:a=gn(i,e,"nextSmaller","asc",c,l);break;case 0:a=pn(i,e,"wildcard",c,l,this.lookupCaches);break;case-1:a=gn(i,e,"nextGreater","desc",c,l)}return 1===n&&void 0===i[0][a]||1!==n&&void 0===i[a]?Bv(e):a+1},isExported:!0},Xv={description:Uo("Row number of a specified cell."),args:[od("cell_reference (meta, default='this cell')",Uo("The cell whose row number will be returned. By default, this function uses the cell in which the formula is entered."))],compute:function(e){if(Pi(e?.value))return e;const t=void 0===e?this.__originCellPosition?.row:$o(e.value).top;return Fi((()=>void 0!==t),"In this context, the function [[FUNCTION_NAME]] needs to have a cell or range in parameter."),t+1},isExported:!0},Kv={description:Uo("Number of rows in a specified array or range."),args:[od("range (meta)",Uo("The range whose row count will be returned."))],compute:function(e){if(Pi(e?.value))return e;const t=$o(e.value);return t.bottom-t.top+1},isExported:!0},Jv={description:Uo("Vertical lookup."),args:[od("search_key (string, number, boolean)",Uo("The value to search for. For example, 42, 'Cats', or I24.")),od("range (any, range)",Uo("The range to consider for the search. The first column in the range is searched for the key specified in search_key.")),od("index (number)",Uo("The column index of the value to be returned, where the first column in range is numbered 1.")),od("is_sorted (boolean, default=true)",Uo("Indicates whether the column to be searched (the first column of the specified range) is sorted, in which case the closest match for search_key will be returned."))],compute:function(e,t,o,s={value:Uv}){const i=Math.trunc(ki(o?.value,this.locale)),n=vn(t);Fi((()=>1<=i&&i<=n.length),Uo("[[FUNCTION_NAME]] evaluates to an out of bounds range."));const r=(e,t)=>e[0][t].value,a=Zi(s.value)?gn(n,e,"nextSmaller","asc",n[0].length,r):pn(n,e,"wildcard",n[0].length,r,this.lookupCaches),l=n[i-1][a];return void 0===l?Bv(e):l},isExported:!0},Qv={0:"strict",1:"nextGreater","-1":"nextSmaller",2:"wildcard"},eb={description:Uo("Search a range for a match and return the corresponding item from a second range."),args:[od("search_key (string,number,boolean)",Uo("The value to search for.")),od("lookup_range (any, range)",Uo("The range to consider for the search. Should be a single column or a single row.")),od("return_range (any, range)",Uo("The range containing the return value. Should have the same dimensions as lookup_range.")),od("if_not_found (any, optional)",Uo("If a valid match is not found, return this value.")),od("match_mode (any, default=0)",Uo("(0) Exact match. (-1) Return next smaller item if no match. (1) Return next greater item if no match. (2) Wildcard match.")),od("search_mode (any, default=1)",Uo("(1) Search starting at first item. (-1) Search starting at last item. (2) Perform a binary search that relies on lookup_array being sorted in ascending order. If not sorted, invalid results will be returned. (-2) Perform a binary search that relies on lookup_array being sorted in descending order. If not sorted, invalid results will be returned. "))],compute:function(e,t,o,s,i={value:0},n={value:1}){const r=Math.trunc(ki(i.value,this.locale)),a=Math.trunc(ki(n.value,this.locale)),l=vn(t),c=vn(o);Fi((()=>1===l.length||1===l[0].length),Uo("lookup_range should be either a single row or single column.")),Fi((()=>[-1,1,-2,2].includes(a)),Uo("search_mode should be a value in [-1, 1, -2, 2].")),Fi((()=>[-1,0,1,2].includes(r)),Uo("match_mode should be a value in [-1, 0, 1, 2]."));const h=1===l.length?"col":"row";Fi((()=>!(2===r&&[-2,2].includes(a))),Uo("the search and match mode combination is not supported for XLOOKUP evaluation.")),Fi((()=>"col"===h?c[0].length===l[0].length:c.length===l.length),Uo("return_range should have the same dimensions as lookup_range."));const d="col"===h?(e,t)=>e[0][t].value:(e,t)=>e[t][0].value,u="col"===h?l[0].length:l.length,g=Qv[r],p=-1===a,m=2===a||-2===a?gn(l,e,g,2===a?"asc":"desc",u,d):pn(l,e,g,u,d,this.lookupCaches,p);return-1!==m?"col"===h?c.map((e=>[e[m]])):[c[m]]:void 0===s?Bv(e):[[s]]},isExported:!0},tb={description:Uo("Get the value from a pivot."),args:[od("pivot_id (number,string)",Uo("ID of the pivot.")),od("measure_name (string)",Uo("Name of the measure.")),od("domain_field_name (string,optional,repeating)",Uo("Field name.")),od("domain_value (number,string,boolean,optional,repeating)",Uo("Value."))],compute:function(e,t,...o){const s=Gi(e),i=Gi(t),n=Vv(s,this.getters);!function(e,t,o){const{measures:s}=o.getPivotCoreDefinition(e);if(!s.find((e=>e.id===t))){const e=`(${s.map((e=>e.id)).join(", ")})`;throw new Ii(Uo("The argument %s is not a valid measure. Here are the measures: %s",t,e))}}(n,i,this.getters),Lv(o);const r=this.getters.getPivot(n),a=this.getters.getPivotCoreDefinition(n);Hv(this,a,a.measures.filter((e=>e.id===i))),r.init({reload:r.needsReevaluation});const l=r.assertIsValid({throwOnError:!1});if(l)return l;if(!r.areDomainArgsFieldsValid(o)){const e=Uo("Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.",`=PIVOT(${s})`);return{value:wi.GenericError,message:Uo("Dimensions don't match the pivot definition")+". "+e}}const c=r.parseArgsToPivotDomain(o);return this.getters.getActiveSheetId()===this.__originSheetId&&this.getters.getPivotPresenceTracker(n)?.trackValue(i,c),r.getPivotCellValueAndFormat(i,c)}},ob={description:Uo("Get the header of a pivot."),args:[od("pivot_id (number,string)",Uo("ID of the pivot.")),od("domain_field_name (string,optional,repeating)",Uo("Field name.")),od("domain_value (number,string,value,optional,repeating)",Uo("Value."))],compute:function(e,...t){const o=Gi(e),s=Vv(o,this.getters);Lv(t);const i=this.getters.getPivot(s);Hv(this,this.getters.getPivotCoreDefinition(s),[]),i.init({reload:i.needsReevaluation});const n=i.assertIsValid({throwOnError:!1});if(n)return n;if(!i.areDomainArgsFieldsValid(t)){const e=Uo("Consider using a dynamic pivot formula: %s. Or re-insert the static pivot from the Data menu.",`=PIVOT(${o})`);return{value:wi.GenericError,message:Uo("Dimensions don't match the pivot definition")+". "+e}}const r=i.parseArgsToPivotDomain(t);this.getters.getActiveSheetId()===this.__originSheetId&&this.getters.getPivotPresenceTracker(s)?.trackHeader(r);const a=r.at(-1);if("measure"===a?.field)return i.getPivotMeasureValue(Gi(a.value),r);const{value:l,format:c}=i.getPivotHeaderValueAndFormat(r);return{value:l,format:a&&"measure"!==a.field&&"false"!==a.value?c:void 0}}},sb={description:Uo("Get a pivot table."),args:[od("pivot_id (string)",Uo("ID of the pivot.")),od("row_count (number, optional)",Uo("number of rows")),od("include_total (boolean, default=TRUE)",Uo("Whether to include total/sub-totals or not.")),od("include_column_titles (boolean, default=TRUE)",Uo("Whether to include the column titles or not.")),od("column_count (number, optional)",Uo("number of columns"))],compute:function(e,t={value:1e4},o={value:!0},s={value:!0},i={value:Number.MAX_VALUE}){const n=Gi(e),r=ki(t,this.locale);if(r<0)return new Ii(Uo("The number of rows must be positive."));const a=ki(i,this.locale);if(a<0)return new Ii(Uo("The number of columns must be positive."));const l=Zi(s),c=Zi(o),h=Vv(n,this.getters),d=this.getters.getPivot(h),u=this.getters.getPivotCoreDefinition(h);Hv(this,u,u.measures),d.init({reload:d.needsReevaluation});const g=d.assertIsValid({throwOnError:!1});if(g)return g;const p=d.getTableStructure(),m=p.getPivotCells(c,l),f=l?p.columns.length:0,v=this.getters.getPivotDisplayName(h),b=Math.min(f+r,m[0].length);if(0===b)return[[{value:v}]];const S=Math.min(1+a,m.length),y=[];for(const e of je(0,S)){y[e]=[];for(const t of je(0,b)){const o=m[e][t];switch(o.type){case"EMPTY":y[e].push({value:""});break;case"HEADER":const t=d.getPivotHeaderValueAndFormat(o.domain);y[e].push(Dc(d,o.domain,t));break;case"MEASURE_HEADER":y[e].push(d.getPivotMeasureValue(o.measure,o.domain));break;case"VALUE":y[e].push(d.getPivotCellValueAndFormat(o.measure,o.domain))}}}return l&&(y[0][0]={value:v}),y}},ib={description:Uo("Returns a range reference shifted by a specified number of rows and columns from a starting cell reference."),args:[od("cell_reference (meta)",Uo("The starting point from which to count the offset rows and columns.")),od("offset_rows (number)",Uo("The number of rows to offset by.")),od("offset_columns (number)",Uo("The number of columns to offset by.")),od("height (number, default='height of cell_reference')",Uo("The number of rows of the range to return starting at the offset target.")),od("width (number, default='width of cell_reference')",Uo("The number of columns of the range to return starting at the offset target."))],compute:function(e,t,o,s,i){if(Pi(e?.value))return e;const n=e?.value;if(!n)return new Ii("In this context, the function OFFSET needs to have a cell or range in parameter.");const r=$o(n);let a=r.bottom-r.top+1,l=r.right-r.left+1;if(s){const e=ki(s,this.locale);rd(Uo("Height value is %(_height)s. It should be greater than or equal to 1.",{_height:e}),e),a=e}if(i){const e=ki(i,this.locale);rd(Uo("Width value is %(_width)s. It should be greater than or equal to 1.",{_width:e}),e),l=e}const{sheetName:c}=qr(n),h=c&&this.getters.getSheetIdByName(c)||this.getters.getActiveSheetId(),d=ki(t,this.locale),u=ki(o,this.locale),g=this.__originCellPosition;g&&this.updateDependencies?.(g);const p=r.left+u,m=r.top+d;if(p<0||m<0)return new Ti(Uo("OFFSET evaluates to an out of bounds range."));const f={left:p,top:m,right:p+l-1,bottom:m+a-1},v=this.getters.getRangeFromZone(this.__originSheetId,f);return v.invalidXc||v.invalidSheetName?new Ti:(g&&this.addDependencies?.(g,[v]),sn(l,a,((e,t)=>this.getters.getEvaluatedCell({sheetId:h,col:p+e,row:m+t}))))}};var nb=Object.freeze({__proto__:null,ADDRESS:zv,COLUMN:$v,COLUMNS:Gv,HLOOKUP:Wv,INDEX:qv,INDIRECT:Zv,LOOKUP:jv,MATCH:Yv,OFFSET:ib,PIVOT:sb,PIVOT_HEADER:ob,PIVOT_VALUE:tb,ROW:Xv,ROWS:Kv,VLOOKUP:Jv,XLOOKUP:eb});const rb={description:Uo("Sum of two numbers."),args:[od("value1 (number)",Uo("The first addend.")),od("value2 (number)",Uo("The second addend."))],compute:function(e,t){return{value:ki(e,this.locale)+ki(t,this.locale),format:e?.format||t?.format}}},ab={description:Uo("Concatenation of two values."),args:[od("value1 (string)",Uo("The value to which value2 will be appended.")),od("value2 (string)",Uo("The value to append to value1."))],compute:function(e,t){return Gi(e)+Gi(t)},isExported:!0},lb={description:Uo("One number divided by another."),args:[od("dividend (number)",Uo("The number to be divided.")),od("divisor (number)",Uo("The number to divide by."))],compute:function(e,t){const o=ki(t,this.locale);return Fi((()=>0!==o),Uo("The divisor must be different from zero."),wi.DivisionByZero),{value:ki(e,this.locale)/o,format:e?.format||t?.format}}};function cb(e){return void 0===e||null===e.value}const hb={number:0,string:"",boolean:!1};function db(e,t,o=2e-16){return Math.abs(e-t)<o}const ub={description:Uo("Equal."),args:[od("value1 (string, number, boolean)",Uo("The first value.")),od("value2 (string, number, boolean)",Uo("The value to test against value1 for equality."))],compute:function(e,t){if(Pi(e?.value))return e;if(Pi(t?.value))return t;let o=cb(e)?hb[typeof t?.value]:e?.value,s=cb(t)?hb[typeof e?.value]:t?.value;return"string"==typeof o&&(o=o.toUpperCase()),"string"==typeof s&&(s=s.toUpperCase()),"number"==typeof o&&"number"==typeof s?{value:db(o,s)}:{value:o===s}}};function gb(e,t,o){if(Pi(e?.value))return e;if(Pi(t?.value))return t;let s=cb(e)?hb[typeof t?.value]:e?.value,i=cb(t)?hb[typeof e?.value]:t?.value;"number"!=typeof s&&(s=Gi(s).toUpperCase()),"number"!=typeof i&&(i=Gi(i).toUpperCase());const n=typeof s,r=typeof i;return"string"===n&&"number"===r?{value:!0}:"string"===r&&"number"===n?{value:!1}:{value:o(s,i)}}const pb={description:Uo("Strictly greater than."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being greater than value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){return gb(e,t,((e,t)=>"number"==typeof e&&"number"==typeof t?!db(e,t)&&e>t:e>t))}},mb={description:Uo("Greater than or equal to."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being greater than or equal to value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){return gb(e,t,((e,t)=>"number"==typeof e&&"number"==typeof t?db(e,t)||e>t:e>=t))}},fb={description:Uo("Less than."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being less than value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){const o=mb.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},vb={description:Uo("Less than or equal to."),args:[od("value1 (number, string, boolean)",Uo("The value to test as being less than or equal to value2.")),od("value2 (number, string, boolean)",Uo("The second value."))],compute:function(e,t){const o=pb.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},bb={description:Uo("Difference of two numbers."),args:[od("value1 (number)",Uo("The minuend, or number to be subtracted from.")),od("value2 (number)",Uo("The subtrahend, or number to subtract from value1."))],compute:function(e,t){return{value:ki(e,this.locale)-ki(t,this.locale),format:e?.format||t?.format}}},Sb={description:Uo("Product of two numbers"),args:[od("factor1 (number)",Uo("The first multiplicand.")),od("factor2 (number)",Uo("The second multiplicand."))],compute:function(e,t){return{value:ki(e,this.locale)*ki(t,this.locale),format:e?.format||t?.format}}},yb={description:Uo("Not equal."),args:[od("value1 (string, number, boolean)",Uo("The first value.")),od("value2 (string, number, boolean)",Uo("The value to test against value1 for inequality."))],compute:function(e,t){const o=ub.compute.bind(this)(e,t);return Pi(o.value)?o:{value:!o.value}}},Cb={description:Uo("A number raised to a power."),args:[od("base (number)",Uo("The number to raise to the exponent power.")),od("exponent (number)",Uo("The exponent to raise base to."))],compute:function(e,t){return Iu.compute.bind(this)(e,t)}},wb={description:Uo("A number with the sign reversed."),args:[od("value (number)",Uo("The number to have its sign reversed. Equivalently, the number to multiply by -1."))],compute:function(e){return{value:-ki(e,this.locale),format:e?.format}}},xb={description:Uo("Value interpreted as a percentage."),args:[od("percentage (number)",Uo("The value to interpret as a percentage."))],compute:function(e){return ki(e,this.locale)/100}},Ib={description:Uo("A specified number, unchanged."),args:[od("value (any)",Uo("The number to return."))],compute:function(e={value:null}){return e}};var Eb=Object.freeze({__proto__:null,ADD:rb,CONCAT:ab,DIVIDE:lb,EQ:ub,GT:pb,GTE:mb,LT:fb,LTE:vb,MINUS:bb,MULTIPLY:Sb,NE:yb,POW:Cb,UMINUS:wb,UNARY_PERCENT:xb,UPLUS:Ib});const Rb=e=>({transform:t=>t*e,inverseTransform:t=>t/e}),Tb={transform:e=>e,inverseTransform:e=>e},Ab=1e-10,_b=.0254,Db=_b/72,Ob=.3048,Fb=.9144,Mb=1609.34,Pb=1852,Nb=946073047258e4,kb={g:{...Tb,category:"weight"},u:{...Rb(166053e-29),category:"weight"},grain:{...Rb(.0647989),category:"weight"},ozm:{...Rb(28.3495),category:"weight"},lbm:{...Rb(453.592),category:"weight"},stone:{...Rb(6350.29),category:"weight"},sg:{...Rb(14593.90294),category:"weight"},cwt:{...Rb(45359.237),category:"weight"},uk_cwt:{...Rb(50802.3),category:"weight"},ton:{...Rb(907184.74),category:"weight"},uk_ton:{...Rb(1016046.9),category:"weight"},m:{...Tb,category:"distance"},km:{...Rb(1e3),category:"distance"},ang:{...Rb(Ab),category:"distance"},Picapt:{...Rb(Db),category:"distance"},pica:{...Rb(_b/6),category:"distance"},in:{...Rb(_b),category:"distance"},ft:{...Rb(Ob),category:"distance"},yd:{...Rb(Fb),category:"distance"},ell:{...Rb(1.143),category:"distance"},mi:{...Rb(Mb),category:"distance"},survey_mi:{...Rb(1609.34),category:"distance"},Nmi:{...Rb(Pb),category:"distance"},ly:{...Rb(Nb),category:"distance"},parsec:{...Rb(0x6da012f95c9fd0),category:"distance"},sec:{...Tb,category:"time"},min:{...Rb(60),category:"time"},hr:{...Rb(3600),category:"time"},day:{...Rb(86400),category:"time"},yr:{...Rb(31556952),category:"time"},Pa:{...Tb,category:"pressure"},bar:{...Rb(1e5),category:"pressure"},mmHg:{...Rb(133.322),category:"pressure"},Torr:{...Rb(133.322),category:"pressure"},psi:{...Rb(6894.76),category:"pressure"},atm:{...Rb(101325),category:"pressure"},N:{...Tb,category:"force"},dyn:{...Rb(1e-5),category:"force"},pond:{...Rb(.00980665),category:"force"},lbf:{...Rb(4.44822),category:"force"},J:{...Tb,category:"energy"},eV:{...Rb(160218e-24),category:"energy"},e:{...Rb(1e-7),category:"energy"},flb:{...Rb(1.3558179483),category:"energy"},c:{...Rb(4.184),category:"energy"},cal:{...Rb(4.1868),category:"energy"},BTU:{...Rb(1055.06),category:"energy"},Wh:{...Rb(3600),category:"energy"},HPh:{...Rb(2684520),category:"energy"},W:{...Tb,category:"power"},PS:{...Rb(735.499),category:"power"},HP:{...Rb(745.7),category:"power"},T:{...Tb,category:"magnetism"},ga:{...Rb(1e-4),category:"magnetism"},K:{...Tb,category:"temperature"},C:{transform:e=>e+273.15,inverseTransform:e=>e-273.15,category:"temperature"},F:{transform:e=>5*(e-32)/9+273.15,inverseTransform:e=>9*(e-273.15)/5+32,category:"temperature"},Rank:{...Rb(5/9),category:"temperature"},Reau:{transform:e=>1.25*e+273.15,inverseTransform:e=>(e-273.15)/1.25,category:"temperature"},"m^3":{...Tb,category:"volume",order:3},"ang^3":{...Rb(Math.pow(Ab,3)),category:"volume",order:3},"Picapt^3":{...Rb(Math.pow(Db,3)),category:"volume",order:3},tsp:{...Rb(492892e-11),category:"volume"},tspm:{...Rb(5e-6),category:"volume"},tbs:{...Rb(14786764825785619e-21),category:"volume"},"in^3":{...Rb(Math.pow(_b,3)),category:"volume",order:3},oz:{...Rb(295735295625e-16),category:"volume"},cup:{...Rb(237e-6),category:"volume"},pt:{...Rb(.0004731765),category:"volume"},uk_pt:{...Rb(568261e-9),category:"volume"},qt:{...Rb(.0009463529),category:"volume"},l:{...Rb(.001),category:"volume"},uk_qt:{...Rb(.0011365225),category:"volume"},gal:{...Rb(.0037854118),category:"volume"},uk_gal:{...Rb(.00454609),category:"volume"},"ft^3":{...Rb(Math.pow(Ob,3)),category:"volume",order:3},bushel:{...Rb(.0352390704),category:"volume"},barrel:{...Rb(.158987295),category:"volume"},"yd^3":{...Rb(Math.pow(Fb,3)),category:"volume",order:3},MTON:{...Rb(1.13267386368),category:"volume"},GRT:{...Rb(2.83168),category:"volume"},"mi^3":{...Rb(Math.pow(Mb,3)),category:"volume",order:3},"Nmi^3":{...Rb(Math.pow(Pb,3)),category:"volume",order:3},"ly^3":{...Rb(Math.pow(Nb,3)),category:"volume",order:3},"m^2":{...Tb,category:"area",order:2},"ang^2":{...Rb(Math.pow(Ab,2)),category:"area",order:2},"Picapt^2":{...Rb(Math.pow(Db,2)),category:"area",order:2},"in^2":{...Rb(Math.pow(_b,2)),category:"area",order:2},"ft^2":{...Rb(Math.pow(Ob,2)),category:"area",order:2},"yd^2":{...Rb(Math.pow(Fb,2)),category:"area",order:2},ar:{...Rb(100),category:"area"},Morgen:{...Rb(2500),category:"area"},uk_acre:{...Rb(4046.8564224),category:"area"},us_acre:{...Rb(4046.8726098743),category:"area"},ha:{...Rb(1e4),category:"area"},"mi^2":{...Rb(Math.pow(Mb,2)),category:"area",order:2},"Nmi^2":{...Rb(Math.pow(Pb,2)),category:"area",order:2},"ly^2":{...Rb(Math.pow(Nb,2)),category:"area",order:2},bit:{...Tb,category:"information"},byte:{...Rb(8),category:"information"},"m/s":{...Tb,category:"speed"},"m/hr":{...Rb(1/3600),category:"speed"},"km/hr":{...Rb(1/3.6),category:"speed"},mph:{...Rb(.44704),category:"speed"},kn:{...Rb(.5144444444),category:"speed"},admkn:{...Rb(.5147733333),category:"speed"}},Vb={shweight:"cwt",lcwt:"uk_cwt",hweight:"uk_cwt",LTON:"uk_ton",brton:"uk_ton",pc:"parsec",Pica:"Picapt",d:"day",mn:"min",s:"sec",p:"Pa",at:"atm",dy:"dyn",ev:"eV",hh:"HPh",wh:"Wh",btu:"BTU",h:"HP",cel:"C",fah:"F",kel:"K",us_pt:"pt",L:"l",lt:"l",ang3:"ang^3",ft3:"ft^3",in3:"in^3",ly3:"ly^3",m3:"m^3",mi3:"mi^3",yd3:"yd^3",Nmi3:"Nmi^3",Picapt3:"Picapt^3","Pica^3":"Picapt^3",Pica3:"Picapt^3",regton:"GRT",ang2:"ang^2",ft2:"ft^2",in2:"in^2",ly2:"ly^2",m2:"m^2",mi2:"mi^2",Nmi2:"Nmi^2",Picapt2:"Picapt^2","Pica^2":"Picapt^2",Pica2:"Picapt^2",yd2:"yd^2","m/h":"m/hr","m/sec":"m/s"},Lb={"":1,Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,h:100,da:10,e:10,d:.1,c:.01,m:.001,u:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-21,Yi:Math.pow(2,80),Zi:Math.pow(2,70),Ei:Math.pow(2,60),Pi:Math.pow(2,50),Ti:Math.pow(2,40),Gi:Math.pow(2,30),Mi:Math.pow(2,20),ki:Math.pow(2,10)},Hb={weight:Uo("Weight"),distance:Uo("Distance"),time:Uo("Time"),pressure:Uo("Pressure"),force:Uo("Force"),energy:Uo("Energy"),power:Uo("Power"),magnetism:Uo("Magnetism"),temperature:Uo("Temperature"),volume:Uo("Volume"),area:Uo("Area"),information:Uo("Information"),speed:Uo("Speed")};function Ub(e){return Hb[e]??""}function Bb(e){for(const[t,o]of Object.entries(Lb)){if(t&&!e.startsWith(t))continue;const s=e.slice(t.length);let i=kb[s];if(!i&&Vb[s]&&(i=kb[Vb[s]]),i)return{...i,factor:i.order?Math.pow(o,i.order):o}}}const zb={description:Uo("Converts a numeric value to a different unit of measure."),args:[od("value (number)",Uo("the numeric value in start_unit to convert to end_unit")),od("start_unit (string)",Uo("The starting unit, the unit currently assigned to value")),od("end_unit (string)",Uo("The unit of measure into which to convert value"))],compute:function(e,t,o){const s=ki(e,this.locale),i=Gi(t),n=Gi(o),r=Bb(i),a=Bb(n);return r?a?r.category!==a.category?{value:wi.GenericError,message:Uo("Incompatible units of measure ('%s' vs '%s')",Ub(r.category),Ub(a.category))}:{value:a.inverseTransform(r.factor*r.transform(s))/a.factor,format:e?.format}:{value:wi.GenericError,message:Uo("Invalid units of measure ('%s')",n)}:{value:wi.GenericError,message:Uo("Invalid units of measure ('%s')",i)}},isExported:!0};var $b=Object.freeze({__proto__:null,CONVERT:zb});const Gb=/[A-Za-zÀ-ÖØ-öø-ÿ]+/g,Wb={description:Uo("Gets character associated with number."),args:[od("table_number (number)",Uo("The number of the character to look up from the current Unicode table in decimal format."))],compute:function(e){const t=Math.trunc(ki(e,this.locale));return Fi((()=>t>=1),Uo("The table_number (%s) is out of range.",t.toString())),String.fromCharCode(t)},isExported:!0},qb={description:Uo("Remove non-printable characters from a piece of text."),args:[od("text (string)",Uo("The text whose non-printable characters are to be removed."))],compute:function(e){const t=Gi(e);let o="";for(const e of t)e&&e.charCodeAt(0)>31&&(o+=e);return o},isExported:!0},Zb={description:Uo("Appends strings to one another."),args:[od("string1 (string, range<string>)",Uo("The initial string.")),od("string2 (string, range<string>, repeating)",Uo("More strings to append in sequence."))],compute:function(...e){return en(e,((e,t)=>e+Gi(t)),"")},isExported:!0},jb={description:Uo("Tests whether two strings are identical."),args:[od("string1 (string)",Uo("The first string to compare.")),od("string2 (string)",Uo("The second string to compare."))],compute:function(e,t){return Gi(e)===Gi(t)},isExported:!0},Yb={description:Uo("First position of string found in text, case-sensitive."),args:[od("search_for (string)",Uo("The string to look for within text_to_search.")),od("text_to_search (string)",Uo("The text to search for the first occurrence of search_for.")),od("starting_at (number, default=1)",Uo("The character within text_to_search at which to start the search."))],compute:function(e,t,o={value:1}){const s=Gi(e),i=Gi(t),n=ki(o,this.locale);Fi((()=>""!==i),Uo("The text_to_search must be non-empty.")),Fi((()=>n>=1),Uo("The starting_at (%s) must be greater than or equal to 1.",n.toString()));const r=i.indexOf(s,n-1);return Fi((()=>r>=0),Uo("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",s.toString(),i)),r+1},isExported:!0},Xb={description:Uo("Concatenates elements of arrays with delimiter."),args:[od("delimiter (string)",Uo("The character or string to place between each concatenated value.")),od("value_or_array1 (string, range<string>)",Uo("The value or values to be appended using delimiter.")),od("value_or_array2 (string, range<string>, repeating)",Uo("More values to be appended using delimiter."))],compute:function(e,...t){const o=Gi(e);return en(t,((e,t)=>(e?e+o:"")+Gi(t)),"")}},Kb={description:Uo("Substring from beginning of specified string."),args:[od("text (string)",Uo("The string from which the left portion will be returned.")),od("number_of_characters (number, optional)",Uo("The number of characters to return from the left side of string."))],compute:function(e,...t){const o=t.length?ki(t[0],this.locale):1;return Fi((()=>o>=0),Uo("The number_of_characters (%s) must be positive or null.",o.toString())),Gi(e).substring(0,o)},isExported:!0},Jb={description:Uo("Length of a string."),args:[od("text (string)",Uo("The string whose length will be returned."))],compute:function(e){return Gi(e).length},isExported:!0},Qb={description:Uo("Converts a specified string to lowercase."),args:[od("text (string)",Uo("The string to convert to lowercase."))],compute:function(e){return Gi(e).toLowerCase()},isExported:!0},eS={description:Uo("A segment of a string."),args:[od("text (string)",Uo("The string to extract a segment from.")),od("starting_at (number)",Uo("The index from the left of string from which to begin extracting. The first character in string has the index 1.")),od("extract_length (number)",Uo("The length of the segment to extract."))],compute:function(e,t,o){const s=Gi(e),i=ki(t,this.locale),n=ki(o,this.locale);return Fi((()=>i>=1),Uo("The starting_at argument (%s) must be positive greater than one.",i.toString())),Fi((()=>n>=0),Uo("The extract_length argument (%s) must be positive or null.",n.toString())),s.slice(i-1,i+n-1)},isExported:!0},tS={description:Uo("Capitalizes each word in a specified string."),args:[od("text_to_capitalize (string)",Uo("The text which will be returned with the first letter of each word in uppercase and all other letters in lowercase."))],compute:function(e){return Gi(e).replace(Gb,(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()))},isExported:!0},oS={description:Uo("Replaces part of a text string with different text."),args:[od("text (string)",Uo("The text, a part of which will be replaced.")),od("position (number)",Uo("The position where the replacement will begin (starting from 1).")),od("length (number)",Uo("The number of characters in the text to be replaced.")),od("new_text (string)",Uo("The text which will be inserted into the original text."))],compute:function(e,t,o,s){const i=ki(t,this.locale);Fi((()=>i>=1),Uo("The position (%s) must be greater than or equal to 1.",i.toString()));const n=Gi(e),r=ki(o,this.locale),a=Gi(s);return n.substring(0,i-1)+a+n.substring(i-1+r)},isExported:!0},sS={description:Uo("A substring from the end of a specified string."),args:[od("text (string)",Uo("The string from which the right portion will be returned.")),od("number_of_characters (number, optional)",Uo("The number of characters to return from the right side of string."))],compute:function(e,...t){const o=t.length?ki(t[0],this.locale):1;Fi((()=>o>=0),Uo("The number_of_characters (%s) must be positive or null.",o.toString()));const s=Gi(e),i=s.length;return s.substring(i-o,i)},isExported:!0},iS={description:Uo("First position of string found in text, ignoring case."),args:[od("search_for (string)",Uo("The string to look for within text_to_search.")),od("text_to_search (string)",Uo("The text to search for the first occurrence of search_for.")),od("starting_at (number, default=1)",Uo("The character within text_to_search at which to start the search."))],compute:function(e,t,o={value:1}){const s=Gi(e).toLowerCase(),i=Gi(t).toLowerCase(),n=ki(o,this.locale);if(""===i)return{value:wi.GenericError,message:Uo("The text_to_search must be non-empty.")};if(n<1)return{value:wi.GenericError,message:Uo("The starting_at (%s) must be greater than or equal to 1.",n)};const r=i.indexOf(s,n-1);return-1===r?{value:wi.GenericError,message:Uo("In [[FUNCTION_NAME]] evaluation, cannot find '%s' within '%s'.",s,i)}:{value:r+1}},isExported:!0},nS={description:Uo("Split text by specific character delimiter(s)."),args:[od("text (string)",Uo("The text to divide.")),od("delimiter (string)",Uo("The character or characters to use to split text.")),od("split_by_each (boolean, default=true})",Uo("Whether or not to divide text around each character contained in delimiter.")),od("remove_empty_text (boolean, default=true)",Uo("Whether or not to remove empty text messages from the split results. The default behavior is to treat consecutive delimiters as one (if TRUE). If FALSE, empty cells values are added between consecutive delimiters."))],compute:function(e,t,o={value:true},s={value:true}){const i=Gi(e),n=Be(Gi(t)),r=Zi(o),a=Zi(s);Fi((()=>n.length>0),Uo("The _delimiter (%s) must be not be empty.",n));const l=r?new RegExp(`[${n}]`,"g"):new RegExp(n,"g");let c=i.split(l);return a&&(c=c.filter((e=>""!==e))),rn([c])},isExported:!1},rS={description:Uo("Replaces existing text with new text in a string."),args:[od("text_to_search (string)",Uo("The text within which to search and replace.")),od("search_for (string)",Uo("The string to search for within text_to_search.")),od("replace_with (string)",Uo("The string that will replace search_for.")),od("occurrence_number (number, optional)",Uo("The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced."))],compute:function(e,t,o,s){const i=ki(s,this.locale);Fi((()=>i>=0),Uo("The occurrenceNumber (%s) must be positive or null.",i.toString()));const n=Gi(e),r=Gi(t);if(""===r)return n;const a=Gi(o),l=new RegExp(Be(r),"g");if(0===i)return n.replace(l,a);let c=0;return n.replace(l,(e=>++c===i?a:e))},isExported:!0},aS={description:Uo("Combines text from multiple strings and/or arrays."),args:[od("delimiter (string)",Uo(" A string, possible empty, or a reference to a valid string. If empty, the text will be simply concatenated.")),od("ignore_empty (boolean)",Uo("A boolean; if TRUE, empty cells selected in the text arguments won't be included in the result.")),od("text1 (string, range<string>)",Uo("Any text item. This could be a string, or an array of strings in a range.")),od("text2 (string, range<string>, repeating)",Uo("Additional text item(s)."))],compute:function(e,t,...o){const s=Gi(e),i=Zi(t);let n=0;return en(o,((e,t)=>i&&""===Gi(t)?e:(n++?e+s:"")+Gi(t)),"")},isExported:!0},lS={description:Uo("Removes space characters."),args:[od("text (string)",Uo("The text or reference to a cell containing text to be trimmed."))],compute:function(e){return At(Gi(e))},isExported:!0},cS={description:Uo("Converts a specified string to uppercase."),args:[od("text (string)",Uo("The string to convert to uppercase."))],compute:function(e){return Gi(e).toUpperCase()},isExported:!0},hS={description:Uo("Converts a number to text according to a specified format."),args:[od("number (number)",Uo("The number, date or time to format.")),od("format (string)",Uo("The pattern by which to format the number, enclosed in quotation marks."))],compute:function(e,t){return Kn(ki(e,this.locale),{format:Gi(t),locale:this.locale})},isExported:!0},dS={description:Uo("Converts a string to a numeric value."),args:[od("value (number)",Uo("the string to be converted"))],compute:function(e){return ki(e,this.locale)},isExported:!0};var uS=Object.freeze({__proto__:null,CHAR:Wb,CLEAN:qb,CONCATENATE:Zb,EXACT:jb,FIND:Yb,JOIN:Xb,LEFT:Kb,LEN:Jb,LOWER:Qb,MID:eS,PROPER:tS,REPLACE:oS,RIGHT:sS,SEARCH:iS,SPLIT:nS,SUBSTITUTE:rS,TEXT:hS,TEXTJOIN:aS,TRIM:lS,UPPER:cS,VALUE:dS});const gS={description:Uo("Creates a hyperlink in a cell."),args:[od("url (string)",Uo("The full URL of the link enclosed in quotation marks.")),od("link_label (string, optional)",Uo("The text to display in the cell, enclosed in quotation marks."))],compute:function(e,t){const o=Gi(e).trim(),s=Gi(t)||o;return""===o?s:ot(s,o)},isExported:!0};var pS=Object.freeze({__proto__:null,HYPERLINK:gS});const mS=[{name:Uo("Array"),functions:Fd},{name:Uo("Database"),functions:mp},{name:Uo("Date"),functions:Xp},{name:Uo("Filter"),functions:lm},{name:Uo("Financial"),functions:Hf},{name:Uo("Info"),functions:Ev},{name:Uo("Lookup"),functions:nb},{name:Uo("Logical"),functions:kv},{name:Uo("Math"),functions:qu},{name:Uo("Misc"),functions:Pd},{name:Uo("Operator"),functions:Eb},{name:Uo("Statistical"),functions:ep},{name:Uo("Text"),functions:uS},{name:Uo("Engineering"),functions:Jp},{name:Uo("Web"),functions:pS},{name:Uo("Parser"),functions:$b}],fS=/^[A-Z0-9\_\.]+$/;const vS=new class extends n{mapping={};add(e,t){if(e=e.toUpperCase(),!fS.test(e))throw new Error(Uo("Invalid function name %s. Function names can exclusively contain alphanumerical values separated by dots (.) or underscore (_)",e));const o=sd(t);return function(e){let t=!1,o=!1,s=!1;for(let i of e){if(i.type.includes("META")&&i.type.length>1)throw new Error(Uo("Function ${name} has an argument that has been declared with more than one type whose type 'META'. The 'META' type can only be declared alone."));if(t&&!i.repeating)throw new Error(Uo("Function ${name} has no-repeatable arguments declared after repeatable ones. All repeatable arguments must be declared last."));const e=o||t||s,n=!(i.optional||i.repeating||i.default);if(e&&n)throw new Error(Uo("Function ${name} has at mandatory arguments declared after optional ones. All optional arguments must be after all mandatory arguments."));t=i.repeating,o=i.optional,s=i.default}}(o.args),this.mapping[e]=function(e,t){function o(...o){const i=[];for(let s=0;s<o.length;s++){const n=e.args[e.getArgToFocus(s+1)-1];if(!bi(o[s])&&n.acceptMatrixOnly)throw new Ei(Uo("Function %s expects the parameter '%s' to be reference to a cell or range.",t,(s+1).toString()));i.push(!n.acceptMatrix)}return an(s.bind(this),o,i)}function s(...o){for(let t=0;t<o.length;t++){const s=o[t];if(!e.args[e.getArgToFocus(t+1)-1].acceptErrors&&!bi(s)&&Pi(s?.value))return s}try{return i.apply(this,o)}catch(e){return bS(e,t)}}function i(...o){this.debug;const s=e.compute.apply(this,o);return bi(s)?"object"==typeof s[0][0]&&null!==s[0][0]&&"value"in s[0][0]?(function(e,t){const o=e.length,s=e[0]?.length??0;for(let i=0;i<o;i++)for(let o=0;o<s;o++)t(e[i][o])}(s,(e=>SS(e,t))),s):nn(s,(e=>({value:e}))):"object"==typeof s&&null!==s&&"value"in s?(SS(s,t),s):{value:s}}return o}(o,e),super.add(e,o),this}};for(let e of mS){const t=e.functions;for(let o in t){const s=t[o];s.category=s.category||e.name,o=o.replace(/_/g,"."),vS.add(o,{isExported:!1,...s})}}function bS(e,t){return o=e,void 0!==o?.value&&"string"==typeof o.value&&Pi(e.value)?(CS(e)&&SS(e,t),e):(console.error(e),new Ii(yS+(CS(e)?" "+e.message:"")));var o}function SS(e,t){e.message?.includes("[[FUNCTION_NAME]]")&&(e.message=e.message.replace("[[FUNCTION_NAME]]",t))}const yS=Uo("An unexpected error occurred. Submit a support ticket at odoo.com/help.");function CS(e){return void 0!==e?.message&&"string"==typeof e.message}function wS(e,t,o){const{x:s,y:i,width:n,height:r}=o;if(n<0||r<0)return;const l=t.color||a,{ctx:c}=e;c.save(),t.noBorder||(t.dashed&&c.setLineDash([5,3]),c.strokeStyle=l,t.thinLine?(c.lineWidth=1,c.strokeRect(s,i,n,r)):(c.lineWidth=2,c.strokeRect(s+.5,i+.5,n,r))),t.noFill||(c.fillStyle=Qt(zt(l),t.fillAlpha??.12),c.fillRect(s,i,n,r)),c.restore()}Jh.add("functions",{sequence:100,autoSelectFirstProposal:!0,maxDisplayedProposals:10,getProposals(e){if("SYMBOL"!==e.type)return[];const t=e.value;if(!this.composer.currentContent.startsWith("="))return[];const o=Object.entries(vS.content).filter((([e,{hidden:t}])=>!t)).map((([e,{description:o}])=>({text:e,description:o,htmlContent:Qh(t,e,E,"o-semi-bold")}))).sort(((e,t)=>e.text.length-t.text.length||e.text.localeCompare(t.text)));return o},selectProposal(e,t){let o=e.end,s=e.end;["SYMBOL","FUNCTION"].includes(e.type)&&(o=e.start);const i=this.composer.currentTokens;t+="(";const n=i.map((e=>e.start)).indexOf(e.start);if(n+1<i.length){const e=i[n+1];"LEFT_PAREN"===e?.type&&s++}this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}});class xS extends Xc{mutators=["register","unRegister"];providers=[];constructor(e){super(e),this.onDispose((()=>{this.providers=[]}))}get renderingLayers(){return["Highlights"]}get highlights(){const e=this.getters.getActiveSheetId();return this.providers.flatMap((e=>e.highlights)).filter((t=>t.sheetId===e)).map((e=>{const{numberOfRows:t,numberOfCols:o}=ss(e.zone),s=t*o==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:s}}))}register(e){this.providers.push(e)}unRegister(e){this.providers=this.providers.filter((t=>t!==e))}drawLayer(e,t){if("Highlights"===t)for(const t of this.highlights){wS(e,t,this.getters.getVisibleRect(t.zone))}}}class IS{mutators=["notifyUser","raiseError","askConfirmation","updateNotificationCallbacks"];notifyUser=e=>window.alert(e.text);askConfirmation=(e,t,o)=>{window.confirm(e)?t():o?.()};raiseError=(e,t)=>{window.alert(e),t?.()};updateNotificationCallbacks(e){this.notifyUser=e.notifyUser||this.notifyUser,this.raiseError=e.raiseError||this.raiseError,this.askConfirmation=e.askConfirmation||this.askConfirmation}}const ES="#000000",RS="#3da4ab",TS={OPERATOR:RS,NUMBER:"#02c39a",STRING:"#00a82d",FUNCTION:ES,DEBUGGER:RS,LEFT_PAREN:ES,RIGHT_PAREN:ES,ARG_SEPARATOR:ES,ORPHAN_RIGHT_PAREN:"#ff0000"};class AS extends Xc{mutators=["startEdition","setCurrentContent","stopEdition","stopComposerRangeSelection","cancelEdition","cycleReferences","toggleEditionMode","changeComposerCursorSelection","replaceComposerCursorSelection"];col=0;row=0;editionMode="inactive";sheetId="";_currentContent="";currentTokens=[];selectionStart=0;selectionEnd=0;initialContent="";colorIndexByRange={};notificationStore=this.get(IS);highlightStore=this.get(xS);constructor(e){super(e),this.highlightStore.register(this),this.onDispose((()=>{this.highlightStore.unRegister(this)}))}handleEvent(e){const t=this.getters.getActiveSheetId();let o;if(o=e.options.unbounded?this.getters.getUnboundedZone(t,e.anchor.zone):e.anchor.zone,"newAnchor"===e.mode)"selecting"===this.editionMode&&this.insertSelectedRange(o);else"selecting"===this.editionMode?this.replaceSelectedRange(o):this.updateComposerRange(e.previousAnchor.zone,o)}changeComposerCursorSelection(e,t){this.isSelectionValid(this._currentContent.length,e,t)&&(this.selectionStart=e,this.selectionEnd=t,this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor())}stopComposerRangeSelection(){this.isSelectingRange&&(this.editionMode="editing")}startEdition(e,t){if(t){const o=e||this.getComposerContent(this.getters.getActivePosition());if(!this.isSelectionValid(o.length,t.start,t.end))return}const{col:o,row:s}=this.getters.getActivePosition();this.model.dispatch("SELECT_FIGURE",{id:null}),this.model.dispatch("SCROLL_TO_CELL",{col:o,row:s}),"inactive"!==this.editionMode&&e?this.setContent(e,t):this._startEdition(e,t),this.updateTokenColor(),this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor()}cancelEdition(){this.resetContent(),this.cancelEditionAndActivateSheet()}setCurrentContent(e,t){t&&!this.isSelectionValid(e.length,t.start,t.end)||(this.setContent(e,t,!0),this.updateTokenColor(),this.computeFormulaCursorContext(),this.computeParenthesisRelatedToCursor())}replaceComposerCursorSelection(e){this.replaceSelection(e)}handle(e){switch(e.type){case"SELECT_FIGURE":e.id&&(this.resetContent(),this.cancelEditionAndActivateSheet());break;case"START_CHANGE_HIGHLIGHT":const{left:t,top:o}=e.zone;this.isSelectingRange&&(this.editionMode="editing"),this.model.selection.resetAnchor(this,{cell:{col:t,row:o},zone:e.zone})}}get currentContent(){return"inactive"===this.editionMode?this.getComposerContent(this.getters.getActivePosition()):this._currentContent}get composerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}get isSelectingRange(){return"selecting"===this.editionMode}get showSelectionIndicator(){return this.isSelectingRange&&this.canStartComposerRangeSelection()}get tokenAtCursor(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return e===t&&0===t?void 0:this.currentTokens.find((o=>o.start<=e&&o.end>=t))}cycleReferences(){const e=this.getters.getLocale(),t=gv(this.composerSelection,this._currentContent,e);void 0!==t&&this.setCurrentContent(t.content,t.selection)}toggleEditionMode(){if("inactive"===this.editionMode)return;const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd),o=[...this.currentTokens].reverse().find((o=>o.end>=e&&t>=o.start&&"REFERENCE"===o.type));if("editing"===this.editionMode&&o){const e=this.getters.getActiveSheetId(),{sheetName:t,xc:s}=qr(o.value),i=this.getters.getSheetIdByName(t);i&&i!==e&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e,sheetIdTo:i}),this.selectionStart=this.selectionEnd=o.end;const n=this.getters.getRangeFromSheetXC(this.sheetId,s).zone;this.captureSelection(n),this.editionMode="selecting"}else this.editionMode="editing"}captureSelection(e,t,o){this.model.selection.capture(this,{cell:{col:t??e.left,row:o??e.right},zone:e},{handleEvent:this.handleEvent.bind(this),release:()=>{this._stopEdition()}})}isSelectionValid(e,t,o){return t>=0&&t<=e&&o>=0&&o<=e}startComposerRangeSelection(){if(this.sheetId===this.getters.getActiveSheetId()){const e=hs({col:this.col,row:this.row});this.model.selection.resetAnchor(this,{cell:{col:this.col,row:this.row},zone:e})}this.editionMode="selecting"}_startEdition(e,t){const o=this.getters.getActiveCell(),s=this.getters.getLocale();e&&o.format?.includes("%")&&Js(e,s)&&(t=t||{start:e.length,end:e.length},e=`${e}%`);const{col:i,row:n,sheetId:r}=this.getters.getActivePosition();this.col=i,this.sheetId=r,this.row=n,this.initialContent=this.getComposerContent({sheetId:r,col:i,row:n}),this.editionMode="editing",this.setContent(e||this.initialContent,t),this.colorIndexByRange={};const a=hs({col:this.col,row:this.row});this.captureSelection(a,i,n)}_stopEdition(){if("inactive"!==this.editionMode){this.cancelEditionAndActivateSheet();let e=this.getCurrentCanonicalContent();if(!(this.initialContent!==e))return;if(e&&e.startsWith("=")){const t=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length-this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length;t>0&&(e+=ut(new Array(t).fill(")")))}this.confirmEdition(e)}}getCurrentCanonicalContent(){return Ka(this._currentContent,this.getters.getLocale())}cancelEditionAndActivateSheet(){if("inactive"===this.editionMode)return;this._cancelEdition();this.getters.getActiveSheetId()!==this.sheetId&&this.model.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}_cancelEdition(){"inactive"!==this.editionMode&&(this.editionMode="inactive",this.model.selection.release(this),this.colorIndexByRange={})}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,o){const s=this._currentContent!==e;if(this._currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,s||"inactive"!==this.editionMode){const t=this.getters.getLocale();this.currentTokens=e.startsWith("=")?cv(e,t):[],this.currentTokens.length>100&&o&&this.notificationStore.raiseError(Uo("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells"))}this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}getAutoCompleteProviders(){return Jh.getAll()}insertSelectedRange(e){const t=Math.min(this.selectionStart,this.selectionEnd),o=this.getZoneReference(e);this.canStartComposerRangeSelection()?this.insertText(o,t):this.insertText(","+o,t)}replaceSelectedRange(e){const t=this.getZoneReference(e),o=this.tokenAtCursor,s="REFERENCE"===o?.type?o.start:this.selectionStart;this.replaceText(t,s,this.selectionEnd)}updateComposerRange(e,t){const o=this.getters.getActiveSheetId(),s=this.tokenAtCursor,i=(s?[s,...this.currentTokens]:this.currentTokens).filter((e=>"REFERENCE"===e.type)).find((t=>{const{xc:s,sheetName:i}=qr(t.value),n=i||this.getters.getSheetName(this.sheetId);if(!na(this.getters.getSheetName(o),n))return!1;const r=this.getters.getRangeFromSheetXC(o,s);return Qo(this.getters.expandZone(o,r.zone),e)}));if(!i)return;const n=this.getters.getRangeFromSheetXC(o,i.value);this.selectionStart=i.start,this.selectionEnd=this.selectionStart+i.value.length;const r=this.getters.getRangeFromZone(o,t),a=this.getRangeReference(r,n.parts);this.replaceSelection(a)}getZoneReference(e){const t=this.sheetId,o=this.getters.getActiveSheetId(),s=this.getters.getRangeFromZone(o,e);return this.getters.getSelectionRangeString(s,t)}getRangeReference(e,t){let o=[...t];const s=e.clone({parts:o});return this.getters.getSelectionRangeString(s,this.sheetId)}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),o=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,o)}replaceText(e,t,o){this._currentContent=this._currentContent.slice(0,t)+this._currentContent.slice(o,this._currentContent.length),this.insertText(e,t)}insertText(e,t){const o=this._currentContent.slice(0,t)+e+this._currentContent.slice(t),s=t+e.length;this.setCurrentContent(o,{start:s,end:s})}updateTokenColor(){this.updateRangeColor();for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].color=this.getTokenColor(this.currentTokens[e])}getTokenColor(e){if("REFERENCE"===e.type){const{xc:t,sheetName:o}=qr(e.value);return this.rangeColor(t,o)||ES}if("SYMBOL"===e.type){const t=e.value.toUpperCase();if("TRUE"===t||"FALSE"===t)return TS.NUMBER;if(t in vS.content)return TS.FUNCTION}return["LEFT_PAREN","RIGHT_PAREN"].includes(e.type)&&""===e.parenthesesCode?TS.ORPHAN_RIGHT_PAREN:TS[e.type]||ES}rangeColor(e,t){const o=t?this.model.getters.getSheetIdByName(t):this.sheetId,s=this.highlights.find((t=>{if(t.sheetId!==o)return!1;let s=this.model.getters.getRangeFromSheetXC(o,e).zone;return s=1===gs(s)?this.model.getters.expandZone(o,s):s,Qo(s,t.zone)}));return s&&s.color?s.color:void 0}computeFormulaCursorContext(){for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].isBlurred=!1;if(this.selectionStart!==this.selectionEnd)return;const e=this.getParenthesesCodeAfterCursor(),t=[...this.currentTokens].reverse().find((t=>e.startsWith(t.parenthesesCode)&&"SYMBOL"===t.type));if(t)for(let e=0;e<this.currentTokens.length;e++)(this.currentTokens[e].parenthesesCode||"").startsWith(t.parenthesesCode||"")||(this.currentTokens[e].isBlurred=!0)}getParenthesesCodeAfterCursor(){const e=this.tokenAtCursor?.parenthesesCode||"";return"RIGHT_PAREN"===this.tokenAtCursor?.type?e.slice(0,-1)||"":e}computeParenthesisRelatedToCursor(){for(let e=0;e<this.currentTokens.length;e++)this.currentTokens[e].isParenthesisLinkedToCursor=!1;const e=this.tokenAtCursor;if(e&&""!==e.parenthesesCode&&["LEFT_PAREN","RIGHT_PAREN"].includes(e.type))for(let t=0;t<this.currentTokens.length;t++){const o=this.currentTokens[t];["LEFT_PAREN","RIGHT_PAREN"].includes(o.type)&&o.parenthesesCode===e.parenthesesCode&&o!==e&&(this.currentTokens[t].isParenthesisLinkedToCursor=!0,this.tokenAtCursor.isParenthesisLinkedToCursor=!0)}}updateRangeColor(){if(!this._currentContent.startsWith("=")||"inactive"===this.editionMode)return;const e=this.sheetId,t=this.getReferencedRanges().map((t=>this.getters.getRangeString(t,e))),o={};for(const e of t)void 0!==this.colorIndexByRange[e]&&(o[e]=this.colorIndexByRange[e]);const s=new Set(Object.values(o));let i=0;const n=()=>{for(;s.has(i);)i++;return s.add(i),i};for(const e of t){const t=e in o?o[e]:n();o[e]=t}this.colorIndexByRange=o}get highlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.editionMode)return[];const e=this.sheetId,t=e=>{const t=this.colorIndexByRange[e];return Ht[t%Ht.length]};return this.getReferencedRanges().map((o=>{const s=this.getters.getRangeString(o,e),{numberOfRows:i,numberOfCols:n}=ss(o.zone);return{zone:i*n==1?this.getters.expandZone(o.sheetId,o.zone):o.zone,color:t(s),sheetId:o.sheetId,interactive:!0}}))}getReferencedRanges(){const e=this.sheetId;return this.currentTokens.filter((e=>"REFERENCE"===e.type)).map((t=>this.getters.getRangeFromSheetXC(e,t.value))).filter((e=>!e.invalidSheetName&&!e.invalidXc))}get autocompleteProvider(){const e=this.currentContent,t=e.startsWith("=")?this.tokenAtCursor:{type:"STRING",value:e};if("inactive"===this.editionMode||!t||["TRUE","FALSE"].includes(t.value.toUpperCase())||!this.canStartComposerRangeSelection()&&!["SYMBOL","STRING","UNKNOWN"].includes(t.type))return;const o={composer:this,getters:this.getters},s=this.getAutoCompleteProviders().sort(((e,t)=>(e.sequence??1/0)-(t.sequence??1/0))).map((s=>({...s,getProposals:s.getProposals.bind(o,t,e),selectProposal:s.selectProposal.bind(o,t)})));for(const e of s){let o=e.getProposals();const s=o?.find((e=>e.text===t.value)),i=t.value.replace(/[ ,\(\)]/g,"");if(this._currentContent===this.initialContent&&e.displayAllOnInitialContent&&o?.length)return{proposals:o,selectProposal:e.selectProposal,autoSelectFirstProposal:e.autoSelectFirstProposal??!1};if(s&&this._currentContent!==this.initialContent)return;if(i&&o&&!["ARG_SEPARATOR","LEFT_PAREN","OPERATOR"].includes(t.type)){const e=Qr(i,o,(e=>e.fuzzySearchKey||e.text));s&&!e.length||(o=e)}if(e.maxDisplayedProposals&&(o=o?.slice(0,e.maxDisplayedProposals)),o?.length)return{proposals:o,selectProposal:e.selectProposal,autoSelectFirstProposal:e.autoSelectFirstProposal??!1}}}canStartComposerRangeSelection(){if(this._currentContent.startsWith("=")){const e=this.tokenAtCursor;if(!e)return!1;const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let o=t,s=e;for(;!["ARG_SEPARATOR","LEFT_PAREN","OPERATOR"].includes(s.type)||Fa.includes(s.value);){if("SPACE"!==s.type||o<1)return!1;o--,s=this.currentTokens[o]}for(o=t+1,s=this.currentTokens[o];s&&!["ARG_SEPARATOR","RIGHT_PAREN","OPERATOR"].includes(s.type);){if("SPACE"!==s.type)return!1;o++,s=this.currentTokens[o]}return!0}return!1}}class _S{scope;code="";constructor(e=new OS){this.scope=e}append(...e){this.code+=e.map((e=>e.toString())).join("\n")+"\n"}return(e){return new DS(this.scope,this.code,e)}toString(){return FS(this.code)}}class DS{scope;returnExpression;code;constructor(e,t,o){this.scope=e,this.returnExpression=o,this.code=FS(t)}toString(){return this.code}assignResultToVariable(){if(this.scope.isAlreadyDeclared(this.returnExpression))return this;const e=this.scope.nextVariableName(),t=new _S(this.scope);return t.append(this.code),t.append(`const ${e} = ${this.returnExpression};`),t.return(e)}}class OS{nextId=1;declaredVariables=new Set;nextVariableName(){const e="_"+this.nextId++;return this.declaredVariables.add(e),e}isAlreadyDeclared(e){return this.declaredVariables.has(e)}}function FS(e){let t="",o=0;const s=e.split("\n").map((e=>e.trim())).filter((e=>""!==e));for(const e of s)e.startsWith("}")&&o--,t+="\t".repeat(o)+e+"\n",e.endsWith("{")&&o++;return t.trim()}const MS=vS.content,PS={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},NS={"-":"UMINUS","+":"UPLUS","%":"UNARY.PERCENT"},kS={};function VS(e){return LS(Gf(e))}function LS(e){try{return function(e){const{dependencies:t,literalValues:o,symbols:s}=function(e){const t={numbers:[],strings:[]},o=[],s=[];for(const i of e)switch(i.type){case"INVALID_REFERENCE":case"REFERENCE":o.push(i.value);break;case"STRING":const e=Ue(i.value);t.strings.push({value:e});break;case"NUMBER":{const e=ei(i.value,fi);t.numbers.push({value:e});break}case"SYMBOL":s.push(Ge(i.value,"'"))}return{dependencies:o,literalValues:t,symbols:s}}(e),i=function(e){let t="";for(const o of e)switch(o.type){case"STRING":t+="|S|";break;case"NUMBER":t+="|N|";break;case"REFERENCE":case"INVALID_REFERENCE":o.value.includes(":")?t+="|R|":t+="|C|";break;case"SPACE":break;default:t+=o.value}return t}(e);if(!kS[i]){const r=tv([...e]),a=new OS;let l=0,c=0,h=0;if("BIN_OPERATION"===r.type&&":"===r.value)throw new Ei(Uo("Invalid formula"));if("EMPTY"===r.type)throw new Ei(Uo("Invalid formula"));const d=m(r),u=new _S;u.append(`// ${i}`),u.append(d),u.append(`return ${d.returnExpression};`);let g=new Function("deps","ref","range","getSymbolValue","ctx",u.toString());function p(e){const{args:t}=e,o=e.value.toUpperCase(),s=MS[o];if(!s)throw new _i(Uo('Unknown function: "%s"',e.value));!function(e){const t=e.args.length,o=e.value.toUpperCase(),s=MS[o];if(t<s.minArgRequired)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",o,s.minArgRequired.toString(),t.toString()));if(t>s.maxArgPossible)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",o,s.maxArgPossible.toString(),t.toString()));const i=s.nbrArgRepeating;if(i>1){const e=s.args.length-i;if((t-e)%i!=0)throw new Ei(Uo("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",o,e.toString(),i.toString()))}}(e);const i=[];for(let e=0;e<t.length;e++){const o=s.getArgToFocus(e+1)-1,n=s.args[o],r=t[e],a=n.type||[],l=a.includes("META"),c=a.some((e=>HS(e)));i.push(m(r,l,c))}return i}function m(e,t=!1,o=!1){const i=new _S(a);if("REFERENCE"!==e.type&&("BIN_OPERATION"!==e.type||":"!==e.value)&&t)throw new Ei(Uo("Argument must be a reference to a cell or range."));switch(e.debug&&(i.append("debugger;"),i.append('ctx["debug"] = true;')),e.type){case"BOOLEAN":return i.return(`{ value: ${e.value} }`);case"NUMBER":return i.return(`this.literalValues.numbers[${c++}]`);case"STRING":return i.return(`this.literalValues.strings[${l++}]`);case"REFERENCE":return!t&&e.value.includes(":")||o?i.return(`range(deps[${h++}])`):i.return(`ref(deps[${h++}], ${t?"true":"false"})`);case"FUNCALL":const n=p(e).map((e=>e.assignResultToVariable()));i.append(...n);const r=e.value.toUpperCase();return i.return(`ctx['${r}'](${n.map((e=>e.returnExpression))})`);case"UNARY_OPERATION":{const t=NS[e.value],o=m(e.operand,!1,!1).assignResultToVariable();return i.append(o),i.return(`ctx['${t}'](${o.returnExpression})`)}case"BIN_OPERATION":{const t=PS[e.value],o=m(e.left,!1,!1).assignResultToVariable(),s=m(e.right,!1,!1).assignResultToVariable();return i.append(o),i.append(s),i.return(`ctx['${t}'](${o.returnExpression}, ${s.returnExpression})`)}case"SYMBOL":const a=s.indexOf(e.value);return i.return(`getSymbolValue(this.symbols[${a}])`);case"EMPTY":return i.return("undefined")}}kS[i]=g}const n={execute:kS[i],dependencies:t,literalValues:o,symbols:s,tokens:e,isBadExpression:!1,normalizedFormula:i};return n}(e)}catch(t){return{tokens:e,dependencies:[],execute:function(){return t},isBadExpression:!0,normalizedFormula:e.map((e=>e.value)).join("")}}}function HS(e){return e.startsWith("RANGE")}const US=vS.content;function BS(e){try{return 0===sv(tv(e)).filter((e=>"FUNCALL"===e.type&&!US[e.value.toUpperCase()]?.isExported)).length}catch(e){return!1}}function zS(e,t){if(!e.some((e=>"SYMBOL"===e.type&&t.includes(e.value.toUpperCase()))))return[];let o;try{o=tv(e)}catch{return[]}return function(e,t){return sv(e).filter((e=>"FUNCALL"===e.type&&t.includes(e.value.toUpperCase()))).map((e=>({functionName:e.value.toUpperCase(),args:e.args})))}(o,t)}const $S=["PIVOT.VALUE","PIVOT.HEADER","PIVOT"];function GS(e,t){const o=`"${t?`${e.name}:${t}`:e.name}"`,s=e.string!==e.name?e.string+o:o;return{text:o,description:e.string+(e.help?` (${e.help})`:""),htmlContent:[{value:o,color:TS.STRING}],fuzzySearchKey:s}}function WS(e,t){let o=e.end;const s=e.end;"ARG_SEPARATOR"!==e.type&&(o=e.start),this.composer.stopComposerRangeSelection(),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function qS(e,t){let o=e.end;const s=e.end;"LEFT_PAREN"!==e.type&&(o=e.start),this.composer.stopComposerRangeSelection(),this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t)}function ZS(e){const t=e.functionContext?.args[0];if(t&&["STRING","NUMBER"].includes(t.type))return t.value}function jS(e){return zS(e,$S)[0]}function YS(e){return zS(e,$S).length}const XS=new n;XS.add("SPREADSHEET",!1),Jh.add("pivot_ids",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!["PIVOT.VALUE","PIVOT.HEADER","PIVOT"].includes(t.parent.toUpperCase())||0!==t.argPosition)return;const o=this.getters.getPivotIds();return o.includes(e.value)?void 0:o.map((e=>{const t=this.getters.getPivotCoreDefinition(e),o=`${this.getters.getPivotFormulaId(e)}`;return{text:o,description:t.name,htmlContent:[{value:o,color:TS.NUMBER}],fuzzySearchKey:o+t.name,alwaysExpanded:!0}})).filter(lt)},selectProposal:qS}),Jh.add("pivot_measures",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if("PIVOT.VALUE"!==t?.parent.toUpperCase()||1!==t.argPosition)return[];const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return[];const i=this.getters.getPivot(s);return i.init(),i.isValid()?i.definition.measures.map((e=>{if("__count"===e.fieldName){const e='"__count"';return{text:e,description:Uo("Count"),htmlContent:[{value:e,color:TS.STRING}],fuzzySearchKey:Uo("Count")+e}}return function(e){const t=`"${e.id}"`,o=e.displayName+e.fieldName+t;return{text:t,description:e.displayName,htmlContent:[{value:t,color:TS.STRING}],fuzzySearchKey:o}}(e)})).filter(lt):[]},selectProposal:WS}),Jh.add("pivot_group_fields",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==0}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==1}(e))return;const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s);i.init();const n=i.getFields(),{columns:r,rows:a}=i.definition;let l=t.args;"PIVOT.VALUE"===t?.parent.toUpperCase()?(l=l.filter(((e,t)=>t%2==0)),l=l.slice(1,t.argPosition)):l=l.filter(((e,t)=>t%2==1));const c=l.map((e=>e?.value)).filter(lt),h=r.map((e=>e.nameWithGranularity)),d=a.map((e=>e.nameWithGranularity)),u=[];let g=["ARG_SEPARATOR","SPACE"].includes(e.type)?c.at(-1):c.at(-2);const p=XS.get(i.type);if(p&&g?.startsWith("#")&&(g=g.slice(1)),void 0===g&&(u.push(h[0]),u.push(d[0])),d.includes(g)){const e=d[d.indexOf(g)+1];u.push(e),u.push(h[0])}if(h.includes(g)){const e=h[h.indexOf(g)+1];u.push(e)}const m=u.filter(lt);return m.map((e=>{const[t,o]=e.split(":"),s=n[t];return s?GS(s,o):void 0})).concat(m.map((e=>{if(!p)return;const t=e.split(":")[0],o=n[t];if(!o)return;const s=`"#${e}"`;return{text:s,description:Uo("%s (positional)",o.string)+(o.help?` (${o.help})`:""),htmlContent:[{value:s,color:TS.STRING}],fuzzySearchKey:o.string+s}}))).filter(lt)},selectProposal:WS}),Jh.add("pivot_group_values",{sequence:50,autoSelectFirstProposal:!0,getProposals(e){const t=e.functionContext;if(!t||!e||!function(e){const t=e.functionContext;return"PIVOT.VALUE"===t?.parent.toUpperCase()&&t.argPosition>=2&&t.argPosition%2==1}(e)&&!function(e){const t=e.functionContext;return"PIVOT.HEADER"===t?.parent.toUpperCase()&&t.argPosition>=1&&t.argPosition%2==0}(e))return;const o=ZS(e),s=this.getters.getPivotId(o);if(!s||!this.getters.isExistingPivot(s))return;const i=this.getters.getPivot(s);if(!i.isValid())return;const n=t.argPosition,r=e.functionContext?.args[n-1]?.value;if(!r)return;let a;try{a=i.definition.getDimension(r)}catch(e){return}return"month_number"===a.granularity?Object.values(Yn).map(((e,t)=>({text:`${t+1}`,fuzzySearchKey:e.toString(),description:e.toString(),htmlContent:[{value:`${t+1}`,color:TS.NUMBER}]}))):"quarter_number"===a.granularity?[1,2,3,4].map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:Uo("Quarter %s",e),htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"day_of_month"===a.granularity?je(1,32).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"iso_week_number"===a.granularity?je(0,54).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"day_of_week"===a.granularity?je(1,8).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"hour_number"===a.granularity?je(0,24).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"minute_number"===a.granularity?je(0,60).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):"second_number"===a.granularity?je(0,60).map((e=>({text:`${e}`,fuzzySearchKey:`${e}`,description:"",htmlContent:[{value:`${e}`,color:TS.NUMBER}]}))):i.getPossibleFieldValues(a).map((({value:e,label:t})=>{const o="string"==typeof e,s=o?`"${e}"`:e.toString(),i=t===e?"":t;return{text:s,description:i,htmlContent:[{value:s,color:o?TS.STRING:TS.NUMBER}],fuzzySearchKey:s+i}}))},selectProposal:WS}),Jh.add("sheet_names",{sequence:150,autoSelectFirstProposal:!0,getProposals(e){return"SYMBOL"===e.type||"UNKNOWN"===e.type&&e.value.startsWith("'")?this.getters.getSheetIds().map((e=>{const t=We(this.getters.getSheetName(e));return{text:t,fuzzySearchKey:t.startsWith("'")?t:"'"+t}})):[]},selectProposal(e,t){const o=e.start,s=e.end;this.composer.changeComposerCursorSelection(o,s),this.composer.replaceComposerCursorSelection(t+"!")}});const KS=new n;KS.add("ALPHANUMERIC_INCREMENT_MODIFIER",{apply:(e,t)=>{e.current+=e.increment;const o=`${e.prefix}${e.current.toString().padStart(e.numberPostfixLength||0,"0")}`;return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:o},tooltip:{props:{content:o}}}}}).add("INCREMENT_MODIFIER",{apply:(e,t,o)=>{e.current+=e.increment;const s=e.current.toString(),i=o.getLocale(),n=Kn(e.current,{format:t.cell?.format,locale:i});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:n}}:void 0}}}).add("DATE_INCREMENT_MODIFIER",{apply:(e,t,o)=>{const s=ji(e.current,o.getLocale());s.setFullYear(s.getFullYear()+e.increment.years||0),s.setMonth(s.getMonth()+e.increment.months||0),s.setDate(s.getDate()+e.increment.days||0);const i=Us(s);e.current=i;const n=o.getLocale(),r=Kn(i,{format:t.cell?.format,locale:n});return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:i.toString()},tooltip:i?{props:{content:r}}:void 0}}}).add("COPY_MODIFIER",{apply:(e,t,o)=>{const s=t.cell?.content||"",i={locale:o.getLocale(),format:t.cell?.format};return{cellData:{border:t.border,style:t.cell&&t.cell.style,format:t.cell&&t.cell.format,content:s},tooltip:s?{props:{content:t.cell?Ir(t.cell,i).formattedValue:""}}:void 0}}}).add("FORMULA_MODIFIER",{apply:(e,t,o,s)=>{e.current+=e.increment;let i=0,n=0;switch(s){case"up":i=0,n=-e.current;break;case"down":i=0,n=e.current;break;case"left":i=-e.current,n=0;break;case"right":i=e.current,n=0}const r=t.cell;if(!r||!r.isFormula)return{cellData:{}};const a=t.sheetId,l=o.getTranslatedCellFormula(a,i,n,r.compiledFormula.tokens);return{cellData:{border:t.border,style:r.style,format:r.format,content:l},tooltip:l?{props:{content:l}}:void 0}}});const JS=new n,QS=/(\d+)$/,ey=/^(.*\D+)/,ty=/^(.*\D+)(\d+)$/;function oy(e,t,o){let s=[],i=!1;for(let n of t){n===e&&(i=!0);const t=void 0===n||n.isFormula?void 0:Ir(n,{locale:fi,format:n.format});if(t&&o(t))s.push(t);else{if(i)return s;s=[]}}return s}function sy(e){let t=1;return e.length>=2&&(t=function(e){const t=[];let o=e[0];for(let s=1;s<e.length;s++){const i=e[s];t.push(i-o),o=i}return t.reduce(((e,t)=>e+t),0)/t.length}(e)*e.length),t}function iy(e){if(e.length<2)return 1;const t=e.map((e=>ji(e,fi))),o=function(e){if(e.length<2)return[{years:0,months:0,days:0}];const t=e.map(((t,o)=>{if(0===o)return{years:0,months:0,days:0};const s=ws.fromTimestamp(e[o-1].getTime()),i=js(s,t),n=qs(s,t)%12;s.setFullYear(s.getFullYear()+i),s.setMonth(s.getMonth()+n);return{years:i,months:n,days:Zs(s,t)}}));return t.slice(1)}(t),s=(i=o).length<2?i[0]||{years:0,months:0,days:0}:i.every((e=>e.years===i[0].years&&e.months===i[0].months&&e.days===i[0].days))?i[0]:void 0;var i;if(void 0===s)return;const n=1===Object.values(s).filter((e=>0!==e)).length,r=Object.values(s).every((e=>0===e));if(!n||r){const o=t.map(((e,o)=>{if(0===o)return 0;const s=t[o-1];return Math.floor(e.getTime())-Math.floor(s.getTime())})).slice(1);if(o.every((e=>e===o[0])))return e.length*(e[1]-e[0])}return{years:s.years*e.length,months:s.months*e.length,days:s.days*e.length}}JS.add("simple_value_copy",{condition:(e,t)=>!(1!==t.length||e.isFormula||e.format&&nr(e.format)),generateRule:()=>({type:"COPY_MODIFIER"}),sequence:10}).add("increment_alphanumeric_value",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.text&&ty.test(e.content),generateRule:(e,t,o)=>{const s=parseInt(e.content.match(QS)[0]),i=e.content.match(ey)[0],n=e.content.length-i.length,r=oy(e,t,(e=>e.type===oi.text&&ty.test(e.value))).filter((e=>i===(e.value??"").toString().match(ey)[0])).map((e=>parseInt((e.value??"").toString().match(QS)[0])));let a=sy(r);return["up","left"].includes(o)&&1===r.length&&(a=-a),{type:"ALPHANUMERIC_INCREMENT_MODIFIER",prefix:i,current:s,increment:a,numberPostfixLength:n}},sequence:15}).add("copy_text",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.text,generateRule:()=>({type:"COPY_MODIFIER"}),sequence:20}).add("update_formula",{condition:e=>e.isFormula,generateRule:(e,t)=>({type:"FORMULA_MODIFIER",increment:t.length,current:0}),sequence:30}).add("increment_dates",{condition:(e,t)=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.number&&!!e.format&&nr(e.format),generateRule:(e,t)=>{const o=iy(oy(e,t,(e=>e.type===oi.number&&!!e.format&&nr(e.format))).map((e=>Number(e.value))));if(void 0===o)return{type:"COPY_MODIFIER"};const s=Ir(e,{locale:fi});return"object"==typeof o?{type:"DATE_INCREMENT_MODIFIER",increment:o,current:s.type===oi.number?s.value:0}:{type:"INCREMENT_MODIFIER",increment:o,current:s.type===oi.number?s.value:0}},sequence:25}).add("increment_number",{condition:e=>!e.isFormula&&Ir(e,{locale:fi}).type===oi.number,generateRule:(e,t,o)=>{const s=oy(e,t,(e=>e.type===oi.number&&!nr(e.format||""))).map((e=>Number(e.value)));let i=sy(s);["up","left"].includes(o)&&1===s.length&&(i=-i);const n=Ir(e,{locale:fi});return{type:"INCREMENT_MODIFIER",increment:i,current:n.type===oi.number?n.value:0}},sequence:40});const ny=new n,ry=30,ay=10,ly=20,cy=12,hy=80,dy="#F3F2F1",uy=6,gy=25;function py(e,t){const o=e.getBoundingClientRect(),s=window.devicePixelRatio||1;e.width=s*o.width,e.height=s*o.height;const i=e.getContext("2d");i.scale(s,s);const n=function(e,t,o){const s=t.maxValue,i=t.minValue,n=t.gaugeValue,r=function(e,t){const o=t?gy:0,s=e.height-ly-o-ay,i=e.width-2*ry;let n,r;i>2*s?(n=2*s,r=s):(n=i,r=i/2);const a=o+ay+(s-r)/2;return{x:ry+(i-n)/2,y:a,width:n,height:r}}(e,t.title.text),a=r.width/6,l=n?(n.value-i.value)/(s.value-i.value):0,c={x:e.width/2,y:r.y+r.height-r.height/12};let h=hy;r.height<300&&(h*=r.height/300);const d=r.width/2,u=n?.label||"-";ha(o,u,{fontSize:h},"px")>d&&(h=function(e,t,o,s=.25){let i=1;if(o(i)>e)return i;if(o(t)<e)return t;let n=(i+t)/2,r=o(n),a=0;for(;Math.abs(r-e)>s&&a<20;)r>=e?t=(i+t)/2:i=(i+t)/2,n=(i+t)/2,r=o(n),a++;return n}(d,h,(e=>ha(o,u,{fontSize:e},"px"))));const g={x:r.x+a/2,y:r.y+r.height+cy},p={x:r.x+r.width-a/2,y:r.y+r.height+cy},m=Sh(t.background),f=function(e,t,o,s){const i=e.maxValue,n=e.minValue,r={x:t.x+t.width/2,y:t.y+t.height},a={fontSize:cy},l=[],c=[];for(const h of e.inflectionValues){const e=(h.value-n.value)/(i.value-n.value),d=ha(s,h.label,a,"px"),u=Math.PI-Math.PI*e,g=Sy(u,t.height+uy,r.x,r.y,d+2,cy);let p=c.some((e=>by(e,g)))?cy:0;c.push(g),l.push({rotation:u,label:h.label,fontSize:cy,color:o,offset:p})}return l}(t,r,m,o);let v=0,b=0,S=0;t.title.text&&({width:b,height:S}=ga(o,t.title.text,{fontSize:X,...t.title},"px"));switch(t.title.align){case"right":v=e.width-b-Z;break;case"center":v=(e.width-b)/2;break;default:v=Z}return{width:e.width,height:e.height,title:{label:t.title.text??"",fontSize:t.title.fontSize??X,textPosition:{x:v,y:Y+S/2},color:t.title.color??m,bold:t.title.bold,italic:t.title.italic},backgroundColor:t.background,gauge:{rect:r,arcWidth:a,percentage:Ze(l,0,1),color:my(t)},inflectionValues:f,gaugeValue:{label:u,textPosition:c,fontSize:h,color:m},minLabel:{label:t.minValue.label,textPosition:g,fontSize:cy,color:m},maxLabel:{label:t.maxValue.label,textPosition:p,fontSize:cy,color:m}}}(o,t,i);!function(e,t){e.save(),e.fillStyle=t.backgroundColor,e.fillRect(0,0,t.width,t.height),e.restore()}(i,n),function(e,t){e.save();const o=t.gauge,s=o.rect.x+o.rect.width/2,i=o.rect.y+o.rect.height,n=o.rect.height-o.arcWidth/2;if(n<0)return;const r=1===o.percentage?0:Math.PI*(1+o.percentage);e.strokeStyle=dy,e.beginPath(),e.lineWidth=o.arcWidth,e.arc(s,i,n,r,0),e.stroke(),e.strokeStyle=o.color,e.beginPath(),e.arc(s,i,n,Math.PI,r),e.stroke(),e.restore()}(i,n),function(e,t){const{x:o,y:s,width:i,height:n}=t.gauge.rect;for(const r of t.inflectionValues){e.save(),e.translate(o+i/2-.5,s+n-.5),e.rotate(Math.PI/2-r.rotation),e.lineWidth=2,e.strokeStyle=Sh(t.backgroundColor)+"aa",e.beginPath(),e.moveTo(0,-(n-t.gauge.arcWidth)),e.lineTo(0,-n-3),e.stroke(),e.textAlign="center",e.font=`${r.fontSize}px ${ve}`,e.fillStyle=r.color;const a=-n-uy-r.offset;e.fillText(r.label,0,a),e.restore()}}(i,n),function(e,t){for(const o of[t.minLabel,t.maxLabel,t.gaugeValue])e.save(),e.textAlign="center",e.fillStyle=o.color,e.font=`${o.fontSize}px ${ve}`,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(i,n),function(e,t){e.save();const o=t.title;e.font=la(o.fontSize,o.bold,o.italic),e.textBaseline="middle",e.fillStyle=o.color,e.fillText(o.label,o.textPosition.x,o.textPosition.y),e.restore()}(i,n)}function my(e){const t=e.gaugeValue?.value;if(void 0===t)return dy;for(let o=0;o<e.inflectionValues.length;o++){const s=e.inflectionValues[o];if("<"===s.operator&&t<s.value)return e.colors[o];if("<="===s.operator&&t<=s.value)return e.colors[o]}return e.colors.at(-1)}function fy(e){return[{start:e.topLeft,end:e.topRight},{start:e.topRight,end:e.bottomRight},{start:e.bottomRight,end:e.bottomLeft},{start:e.bottomLeft,end:e.topLeft}]}function vy(e,t){const o=e.start,s=e.end,i=t.start,n=t.end;function r(e,t,o){return(o.y-e.y)*(t.x-e.x)>(t.y-e.y)*(o.x-e.x)}return r(o,i,n)!==r(s,i,n)&&r(o,s,i)!==r(o,s,n)}function by(e,t){const o=fy(e),s=fy(t);for(const e of o)for(const t of s)if(vy(e,t))return!0;return!1}function Sy(e,t,o,s,i,n){const r=Math.cos(e),a=Math.sin(e),l=r*t,c=a*t,h=a*(i/2),d=r*(i/2),u=r*(t+n),g=a*(t+n);return{bottomLeft:{x:l-h+o,y:s-(c+d)},bottomRight:{x:l+h+o,y:s-(c-d)},topRight:{x:u+h+o,y:s-(g-d)},topLeft:{x:u-h+o,y:s-(g+d)}}}class yy extends t.Component{static template="o-spreadsheet-GaugeChartComponent";canvas=t.useRef("chartContainer");get runtime(){return this.env.model.getters.getChartRuntime(this.props.figure.id)}setup(){t.useEffect((()=>py(this.canvas.el,this.runtime)),(()=>{const e=this.canvas.el.getBoundingClientRect();return[e.width,e.height,this.runtime,this.canvas.el,window.devicePixelRatio]}))}}function Cy(e){return 8===(e=zt(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}yy.props={figure:Object};const wy={responsive:!0,maintainAspectRatio:!1,elements:{line:{fill:!1},point:{hitRadius:15}},animation:!1,events:["mousemove","mouseout","click","touchstart","touchmove","mouseup"]};function xy(e,t,o){const s=document.createElement("div");s.style.width=`${t.width}px`,s.style.height=`${t.height}px`;const i=document.createElement("canvas");if(s.append(i),i.setAttribute("width",t.width.toString()),i.setAttribute("height",t.height.toString()),document.body.append(s),"chartJsConfig"in e){const t=ze(e.chartJsConfig);t.plugins=[Iy];const o=new window.Chart(i,t),n=o.toBase64Image();return o.destroy(),s.remove(),n}if("scorecard"===o){Wh(Yh(t,e),i);const o=i.toDataURL();return s.remove(),o}if("gauge"===o){py(i,e);const t=i.toDataURL();return s.remove(),t}}const Iy={id:"customCanvasBackgroundColor",beforeDraw:e=>{const{ctx:t}=e;t.save(),t.globalCompositeOperation="destination-over",t.fillStyle="#ffffff",t.fillRect(0,0,e.width,e.height),t.restore()}};class Ey{xmlString;constructor(e){this.xmlString=e}toString(){return this.xmlString}}const Ry=["areaChart","area3DChart","lineChart","line3DChart","stockChart","radarChart","scatterChart","pieChart","pie3DChart","doughnutChart","barChart","bar3DChart","ofPieChart","surfaceChart","surface3DChart","bubbleChart","comboChart","radarChart"],Ty="000000",Ay={arrows:"3Arrows",smiley:"3Symbols",dots:"3TrafficLights1"},_y={styleSheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",sst:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",Relationships:"http://schemas.openxmlformats.org/package/2006/relationships",Types:"http://schemas.openxmlformats.org/package/2006/content-types",worksheet:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",workbook:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",drawing:"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",table:"http://schemas.openxmlformats.org/spreadsheetml/2006/main",revision:"http://schemas.microsoft.com/office/spreadsheetml/2014/revision",revision3:"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3",markupCompatibility:"http://schemas.openxmlformats.org/markup-compatibility/2006"},Dy="http://schemas.openxmlformats.org/drawingml/2006/main",Oy="http://schemas.openxmlformats.org/drawingml/2006/chart",Fy={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",macroEnabledWorkbook:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",templateWorkbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml",macroEnabledTemplateWorkbook:"application/vnd.ms-excel.template.macroEnabled.main+xml",excelAddInWorkbook:"application/vnd.ms-excel.addin.macroEnabled.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",metadata:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",sharedStrings:"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml",styles:"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",drawing:"application/vnd.openxmlformats-officedocument.drawing+xml",chart:"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",themes:"application/vnd.openxmlformats-officedocument.theme+xml",table:"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",pivot:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",externalLink:"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"},My={document:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",sheet:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",metadata:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata",sharedStrings:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",styles:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",drawing:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing",chart:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart",theme:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme",table:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table",hyperlink:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink",image:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"},Py="bdbb8cdc-fa1e-496e-a857-3c3f30c029c3",Ny="http://schemas.openxmlformats.org/officeDocument/2006/relationships",ky=.75,Vy=.143,Ly=8.43,Hy=12.75,Uy=30,By=100,zy=164,$y={FLOOR:[{type:"NUMBER",value:1}],CEILING:[{type:"NUMBER",value:1}],ROUND:[{type:"NUMBER",value:0}],ROUNDUP:[{type:"NUMBER",value:0}],ROUNDDOWN:[{type:"NUMBER",value:0}]},Gy=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","BYCOL","BYROW","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","CHOOSECOLS","CHOOSEROWS","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","DROP","ERF.PRECISE","ERFC.PRECISE","EXPAND","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","FIELDVALUE","FILTERXML","FLOOR.MATH","FLOOR.PRECISE","FORECAST.ETS","FORECAST.ETS.CONFINT","FORECAST.ETS.SEASONALITY","FORECAST.ETS.STAT","FORECAST.LINEAR","FORMULATEXT","GAMMA","GAMMA.DIST","GAMMA.INV","GAMMALN.PRECISE","GAUSS","HSTACK","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOMITTED","ISOWEEKNUM","LAMBDA","LET","LOGNORM.DIST","LOGNORM.INV","MAKEARRAY","MAP","MAXIFS","MINIFS","MODE.MULT","MODE.SNGL","MUNIT","NEGBINOM.DIST","NORM.DIST","NORM.INV","NORM.S.DIST","NORM.S.INV","NUMBERVALUE","PDURATION","PERCENTILE.EXC","PERCENTILE.INC","PERCENTRANK.EXC","PERCENTRANK.INC","PERMUTATIONA","PHI","POISSON.DIST","PQSOURCE","PYTHON_STR","PYTHON_TYPE","PYTHON_TYPENAME","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANDARRAY","RANK.AVG","RANK.EQ","REDUCE","RRI","SCAN","SEC","SECH","SEQUENCE","SHEET","SHEETS","SKEW.P","SORTBY","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TAKE","TEXTAFTER","TEXTBEFORE","TEXTJOIN","TEXTSPLIT","TOCOL","TOROW","UNICHAR","UNICODE","UNIQUE","VAR.P","VAR.S","VSTACK","WEBSERVICE","WEIBULL.DIST","WRAPCOLS","WRAPROWS","XLOOKUP","XOR","Z.TEST"],Wy="[Content_Types].xml",qy=new n;th`
10
10
  .o-spreadsheet {
11
11
  .o-icon {
12
12
  display: flex;
@@ -1079,7 +1079,7 @@
1079
1079
  color: #6aa84f;
1080
1080
  }
1081
1081
  }
1082
- `;class GO extends t.Component{static template="o-spreadsheet-ConditionalFormattingEditor";static props={editedCf:Object,onCancel:Function,onSave:Function};static components={SelectionInput:LD,IconPicker:LO,ColorPickerWidget:KD,ConditionalFormatPreviewList:$O,Section:RD,RoundColorPicker:tO,StandaloneComposer:wO,BadgeSelection:ZD,ValidationMessages:UD};icons=jy;cellIsOperators=zx;iconSets=Yy;getTextDecoration=oh;colorNumberString=Ut;state;setup(){switch(this.state=t.useState({errors:[],currentCFType:this.props.editedCf.rule.type,ranges:this.props.editedCf.ranges,rules:this.getDefaultRules()}),this.props.editedCf.rule.type){case"CellIsRule":this.state.rules.cellIs=this.props.editedCf.rule;break;case"ColorScaleRule":this.state.rules.colorScale=this.props.editedCf.rule;break;case"IconSetRule":this.state.rules.iconSet=this.props.editedCf.rule;break;case"DataBarRule":this.state.rules.dataBar=this.props.editedCf.rule}t.useExternalListener(window,"click",this.closeMenus)}get isRangeValid(){return this.state.errors.includes("EmptyRange")}get errorMessages(){return this.state.errors.map((e=>Bx.Errors[e]||Bx.Errors.Unexpected))}get cfTypesValues(){return[{value:"CellIsRule",label:Uo("Single color")},{value:"ColorScaleRule",label:Uo("Color scale")},{value:"IconSetRule",label:Uo("Icon set")},{value:"DataBarRule",label:Uo("Data bar")}]}updateConditionalFormat(e){const t=e.ranges||this.state.ranges;if(this.state.ranges.some((e=>!e.match(Br))))return e.suppressErrors||(this.state.errors=["InvalidRange"]),["InvalidRange"];const o=this.env.model.getters.getActiveSheetId(),s=this.env.model.getters.getLocale(),i=e.rule||this.getEditedRule(this.state.currentCFType),n=this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{rule:nl(i,s),id:this.props.editedCf.id},ranges:t.map((e=>this.env.model.getters.getRangeDataFromXc(o,e))),sheetId:o}).reasons.filter((e=>"NoChanges"!==e));return e.suppressErrors||(this.state.errors=n),n}getEditedRule(e){switch(e){case"CellIsRule":return this.state.rules.cellIs;case"ColorScaleRule":return this.state.rules.colorScale;case"IconSetRule":return this.state.rules.iconSet;case"DataBarRule":return this.state.rules.dataBar}}onSave(){0===this.updateConditionalFormat({}).length&&this.props.onSave()}getDefaultRules(){return{cellIs:{type:"CellIsRule",operator:"IsNotEmpty",values:[],style:{fillColor:"#b6d7a8"}},colorScale:{type:"ColorScaleRule",minimum:{type:"value",color:xC("EFF7FF")},midpoint:void 0,maximum:{type:"value",color:6989903}},iconSet:{type:"IconSetRule",icons:{upper:"arrowGood",middle:"arrowNeutral",lower:"arrowBad"},upperInflectionPoint:{type:"percentage",value:"66",operator:"gt"},lowerInflectionPoint:{type:"percentage",value:"33",operator:"gt"}},dataBar:{type:"DataBarRule",color:14281427}}}changeRuleType(e){this.state.currentCFType!==e&&(this.state.errors=[],this.state.currentCFType=e,this.updateConditionalFormat({rule:this.getEditedRule(e),suppressErrors:!0}))}onRangeUpdate(e){this.state.ranges=e}onRangeConfirmed(){this.updateConditionalFormat({ranges:this.state.ranges})}toggleMenu(e){const t=this.state.openedMenu===e;this.closeMenus(),t||(this.state.openedMenu=e)}closeMenus(){this.state.openedMenu=void 0}get isValue1Invalid(){return this.state.errors.includes("FirstArgMissing")||this.state.errors.includes("ValueCellIsInvalidFormula")}get isValue2Invalid(){return this.state.errors.includes("SecondArgMissing")}toggleStyle(e){const t=this.state.rules.cellIs.style;t[e]=!t[e],this.updateConditionalFormat({rule:this.state.rules.cellIs}),this.closeMenus()}onKeydown(e){if("F4"===e.key){const t=e.target,o=gv({start:t.selectionStart??0,end:t.selectionEnd??0},t.value,this.env.model.getters.getLocale());if(!o)return;t.value=o.content,t.setSelectionRange(o.selection.start,o.selection.end),t.dispatchEvent(new Event("input"))}}setColor(e,t){this.state.rules.cellIs.style[e]=t,this.updateConditionalFormat({rule:this.state.rules.cellIs}),this.closeMenus()}editOperator(e){this.state.rules.cellIs.operator=e,this.updateConditionalFormat({rule:this.state.rules.cellIs,suppressErrors:!0}),this.closeMenus()}isValueInvalid(e){switch(e){case"minimum":return this.state.errors.includes("MinInvalidFormula")||this.state.errors.includes("MinBiggerThanMid")||this.state.errors.includes("MinBiggerThanMax")||this.state.errors.includes("MinNaN");case"midpoint":return this.state.errors.includes("MidInvalidFormula")||this.state.errors.includes("MidNaN")||this.state.errors.includes("MidBiggerThanMax");case"maximum":return this.state.errors.includes("MaxInvalidFormula")||this.state.errors.includes("MaxNaN");default:return!1}}setColorScaleColor(e,t){if(!$t(t))return;const o=this.state.rules.colorScale[e];o&&(o.color=Bt(t)),this.updateConditionalFormat({rule:this.state.rules.colorScale}),this.closeMenus()}getPreviewGradient(){const e=this.state.rules.colorScale,t=Ut(e.minimum.color),o=Ut(e.midpoint?.color||v),s=Ut(e.maximum.color),i="background-image: linear-gradient(to right, ";return void 0===e.midpoint?i+t+", "+s+")":i+t+", "+o+", "+s+")"}getThresholdColor(e){return Ut(e?e.color:v)}onMidpointChange(e){const t=e.target.value,o=this.state.rules.colorScale;o.midpoint="none"===t?void 0:{color:v,value:"",...o.midpoint,type:t},this.updateConditionalFormat({rule:o,suppressErrors:!0})}updateThresholdType(e,t){this.state.rules.colorScale[e].type=t,this.updateConditionalFormat({rule:this.state.rules.colorScale,suppressErrors:!0})}updateThresholdValue(e,t){this.state.rules.colorScale[e].value=t,this.updateConditionalFormat({rule:this.state.rules.colorScale})}isInflectionPointInvalid(e){switch(e){case"lowerInflectionPoint":return this.state.errors.includes("ValueLowerInflectionNaN")||this.state.errors.includes("ValueLowerInvalidFormula")||this.state.errors.includes("LowerBiggerThanUpper");case"upperInflectionPoint":return this.state.errors.includes("ValueUpperInflectionNaN")||this.state.errors.includes("ValueUpperInvalidFormula")||this.state.errors.includes("LowerBiggerThanUpper");default:return!0}}reverseIcons(){const e=this.state.rules.iconSet.icons,t=e.upper;e.upper=e.lower,e.lower=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setIconSet(e){const t=this.state.rules.iconSet.icons;t.upper=this.iconSets[e].good,t.middle=this.iconSets[e].neutral,t.lower=this.iconSets[e].bad,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setIcon(e,t){this.state.rules.iconSet.icons[e]=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionOperator(e,t){this.state.rules.iconSet[e].operator=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionValue(e,t){this.state.rules.iconSet[e].value=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionType(e,t,o){this.state.rules.iconSet[e].type=t,this.updateConditionalFormat({rule:this.state.rules.iconSet,suppressErrors:!0})}getCellIsRuleComposerProps(e){const t=0===e?this.isValue1Invalid:this.isValue2Invalid;return{onConfirm:t=>{this.state.rules.cellIs.values[e]=t,this.updateConditionalFormat({rule:this.state.rules.cellIs})},composerContent:this.state.rules.cellIs.values[e],placeholder:Uo("Value or formula"),defaultStatic:!0,invalid:t,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getColorScaleComposerProps(e){const t=this.state.rules.colorScale[e];if(!t)throw new Error("Threshold not found");const o=this.isValueInvalid(e);return{onConfirm:e=>{t.value=e,this.updateConditionalFormat({rule:this.state.rules.colorScale})},composerContent:t.value||"",placeholder:Uo("Formula"),defaultStatic:!0,invalid:o,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getColorIconSetComposerProps(e){const t=this.state.rules.iconSet[e],o=this.isInflectionPointInvalid(e);return{onConfirm:e=>{t.value=e,this.updateConditionalFormat({rule:this.state.rules.iconSet})},composerContent:t.value||"",placeholder:Uo("Formula"),defaultStatic:!0,invalid:o,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getRangeValues(){return[this.state.rules.dataBar.rangeValues||""]}updateDataBarColor(e){$t(e)&&(this.state.rules.dataBar.color=Number.parseInt(e.slice(1),16),this.updateConditionalFormat({rule:this.state.rules.dataBar}))}onDataBarRangeUpdate(e){this.state.rules.dataBar.rangeValues=e[0]}onDataBarRangeChange(){this.updateConditionalFormat({rule:this.state.rules.dataBar})}}class WO extends t.Component{static template="o-spreadsheet-ConditionalFormattingPanel";static props={selection:{type:Object,optional:!0},onCloseSidePanel:Function};static components={ConditionalFormatPreviewList:$O,ConditionalFormattingEditor:GO,Section:RD};activeSheetId;originalEditedCf=void 0;state=t.useState({mode:"list"});setup(){this.activeSheetId=this.env.model.getters.getActiveSheetId();const e=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getRulesSelection(e,this.props.selection||[]);if(1===o.length){const e=this.conditionalFormats.find((e=>e.id===o[0]));e&&this.editConditionalFormat(e)}t.onWillUpdateProps((e=>{const t=this.env.model.getters.getActiveSheetId();if(t!==this.activeSheetId)this.activeSheetId=t,this.switchToList();else if(e.selection!==this.props.selection){const t=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getRulesSelection(t,e.selection||[]);if(1===o.length){const e=this.conditionalFormats.find((e=>e.id===o[0]));e&&this.editConditionalFormat(e)}else this.switchToList()}}))}get conditionalFormats(){return this.env.model.getters.getConditionalFormats(this.env.model.getters.getActiveSheetId()).map((e=>({...e,rule:rl(e.rule,this.env.model.getters.getLocale())})))}switchToList(){this.state.mode="list",this.state.editedCfId=void 0,this.originalEditedCf=void 0}addConditionalFormat(){const e=this.env.model.uuidGenerator.smallUuid();this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,ranges:this.env.model.getters.getSelectedZones().map((e=>this.env.model.getters.getRangeDataFromZone(this.activeSheetId,e))),cf:{id:e,rule:{type:"CellIsRule",operator:"IsNotEmpty",style:{fillColor:"#b6d7a8"},values:[]}}}),this.state.editedCfId=e,this.state.mode="edit",this.originalEditedCf=void 0}editConditionalFormat(e){this.state.mode="edit",this.state.editedCfId=e.id,this.originalEditedCf=e}cancelEdition(){this.originalEditedCf?this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,ranges:this.originalEditedCf.ranges.map((e=>this.env.model.getters.getRangeDataFromXc(this.activeSheetId,e))),cf:this.originalEditedCf}):this.state.editedCfId&&this.env.model.dispatch("REMOVE_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,id:this.state.editedCfId}),this.switchToList()}get editedCF(){return this.conditionalFormats.find((e=>e.id===this.state.editedCfId))}}th`
1082
+ `;class GO extends t.Component{static template="o-spreadsheet-ConditionalFormattingEditor";static props={editedCf:Object,onCancel:Function,onSave:Function};static components={SelectionInput:LD,IconPicker:LO,ColorPickerWidget:KD,ConditionalFormatPreviewList:$O,Section:RD,RoundColorPicker:tO,StandaloneComposer:wO,BadgeSelection:ZD,ValidationMessages:UD};icons=jy;cellIsOperators=zx;iconSets=Yy;getTextDecoration=oh;colorNumberString=Ut;state;setup(){switch(this.state=t.useState({errors:[],currentCFType:this.props.editedCf.rule.type,ranges:this.props.editedCf.ranges,rules:this.getDefaultRules()}),this.props.editedCf.rule.type){case"CellIsRule":this.state.rules.cellIs=this.props.editedCf.rule;break;case"ColorScaleRule":this.state.rules.colorScale=this.props.editedCf.rule;break;case"IconSetRule":this.state.rules.iconSet=this.props.editedCf.rule;break;case"DataBarRule":this.state.rules.dataBar=this.props.editedCf.rule}t.useExternalListener(window,"click",this.closeMenus)}get isRangeValid(){return this.state.errors.includes("EmptyRange")}get errorMessages(){return this.state.errors.map((e=>Bx.Errors[e]||Bx.Errors.Unexpected))}get cfTypesValues(){return[{value:"CellIsRule",label:Uo("Single color")},{value:"ColorScaleRule",label:Uo("Color scale")},{value:"IconSetRule",label:Uo("Icon set")},{value:"DataBarRule",label:Uo("Data bar")}]}updateConditionalFormat(e){const t=e.ranges||this.state.ranges;if(this.state.ranges.some((e=>!e.match(Br))))return e.suppressErrors||(this.state.errors=["InvalidRange"]),["InvalidRange"];const o=this.env.model.getters.getActiveSheetId(),s=this.env.model.getters.getLocale(),i=e.rule||this.getEditedRule(this.state.currentCFType),n=this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{rule:nl(i,s),id:this.props.editedCf.id},ranges:t.map((e=>this.env.model.getters.getRangeDataFromXc(o,e))),sheetId:o}).reasons.filter((e=>"NoChanges"!==e));return e.suppressErrors||(this.state.errors=n),n}getEditedRule(e){switch(e){case"CellIsRule":return this.state.rules.cellIs;case"ColorScaleRule":return this.state.rules.colorScale;case"IconSetRule":return this.state.rules.iconSet;case"DataBarRule":return this.state.rules.dataBar}}onSave(){0===this.updateConditionalFormat({}).length&&this.props.onSave()}getDefaultRules(){return{cellIs:{type:"CellIsRule",operator:"IsNotEmpty",values:[],style:{fillColor:"#b6d7a8"}},colorScale:{type:"ColorScaleRule",minimum:{type:"value",color:xC("EFF7FF")},midpoint:void 0,maximum:{type:"value",color:6989903}},iconSet:{type:"IconSetRule",icons:{upper:"arrowGood",middle:"arrowNeutral",lower:"arrowBad"},upperInflectionPoint:{type:"percentage",value:"66",operator:"gt"},lowerInflectionPoint:{type:"percentage",value:"33",operator:"gt"}},dataBar:{type:"DataBarRule",color:14281427}}}changeRuleType(e){this.state.currentCFType!==e&&(this.state.errors=[],this.state.currentCFType=e,this.updateConditionalFormat({rule:this.getEditedRule(e),suppressErrors:!0}))}onRangeUpdate(e){this.state.ranges=e}onRangeConfirmed(){this.updateConditionalFormat({ranges:this.state.ranges})}toggleMenu(e){const t=this.state.openedMenu===e;this.closeMenus(),t||(this.state.openedMenu=e)}closeMenus(){this.state.openedMenu=void 0}get isValue1Invalid(){return this.state.errors.includes("FirstArgMissing")||this.state.errors.includes("ValueCellIsInvalidFormula")}get isValue2Invalid(){return this.state.errors.includes("SecondArgMissing")}toggleStyle(e){const t=this.state.rules.cellIs.style;t[e]=!t[e],this.updateConditionalFormat({rule:this.state.rules.cellIs}),this.closeMenus()}onKeydown(e){if("F4"===e.key){const t=e.target,o=gv({start:t.selectionStart??0,end:t.selectionEnd??0},t.value,this.env.model.getters.getLocale());if(!o)return;t.value=o.content,t.setSelectionRange(o.selection.start,o.selection.end),t.dispatchEvent(new Event("input"))}}setColor(e,t){this.state.rules.cellIs.style[e]=t,this.updateConditionalFormat({rule:this.state.rules.cellIs}),this.closeMenus()}editOperator(e){this.state.rules.cellIs.operator=e,this.updateConditionalFormat({rule:this.state.rules.cellIs,suppressErrors:!0}),this.closeMenus()}isValueInvalid(e){switch(e){case"minimum":return this.state.errors.includes("MinInvalidFormula")||this.state.errors.includes("MinBiggerThanMid")||this.state.errors.includes("MinBiggerThanMax")||this.state.errors.includes("MinNaN");case"midpoint":return this.state.errors.includes("MidInvalidFormula")||this.state.errors.includes("MidNaN")||this.state.errors.includes("MidBiggerThanMax");case"maximum":return this.state.errors.includes("MaxInvalidFormula")||this.state.errors.includes("MaxNaN");default:return!1}}setColorScaleColor(e,t){if(!$t(t))return;const o=this.state.rules.colorScale[e];o&&(o.color=Bt(t)),this.updateConditionalFormat({rule:this.state.rules.colorScale}),this.closeMenus()}getPreviewGradient(){const e=this.state.rules.colorScale,t=Ut(e.minimum.color),o=Ut(e.midpoint?.color||v),s=Ut(e.maximum.color),i="background-image: linear-gradient(to right, ";return void 0===e.midpoint?i+t+", "+s+")":i+t+", "+o+", "+s+")"}getThresholdColor(e){return Ut(e?e.color:v)}onMidpointChange(e){const t=e.target.value,o=this.state.rules.colorScale;o.midpoint="none"===t?void 0:{color:v,value:"",...o.midpoint,type:t},this.updateConditionalFormat({rule:o,suppressErrors:!0})}updateThresholdType(e,t){this.state.rules.colorScale[e].type=t,this.updateConditionalFormat({rule:this.state.rules.colorScale,suppressErrors:!0})}updateThresholdValue(e,t){this.state.rules.colorScale[e].value=t,this.updateConditionalFormat({rule:this.state.rules.colorScale})}isInflectionPointInvalid(e){switch(e){case"lowerInflectionPoint":return this.state.errors.includes("ValueLowerInflectionNaN")||this.state.errors.includes("ValueLowerInvalidFormula")||this.state.errors.includes("LowerBiggerThanUpper");case"upperInflectionPoint":return this.state.errors.includes("ValueUpperInflectionNaN")||this.state.errors.includes("ValueUpperInvalidFormula")||this.state.errors.includes("LowerBiggerThanUpper");default:return!0}}reverseIcons(){const e=this.state.rules.iconSet.icons,t=e.upper;e.upper=e.lower,e.lower=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setIconSet(e){const t=this.state.rules.iconSet.icons;t.upper=this.iconSets[e].good,t.middle=this.iconSets[e].neutral,t.lower=this.iconSets[e].bad,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setIcon(e,t){this.state.rules.iconSet.icons[e]=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionOperator(e,t){this.state.rules.iconSet[e].operator=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionValue(e,t){this.state.rules.iconSet[e].value=t,this.updateConditionalFormat({rule:this.state.rules.iconSet})}setInflectionType(e,t,o){this.state.rules.iconSet[e].type=t,this.updateConditionalFormat({rule:this.state.rules.iconSet,suppressErrors:!0})}getCellIsRuleComposerProps(e){const t=0===e?this.isValue1Invalid:this.isValue2Invalid;return{onConfirm:t=>{this.state.rules.cellIs.values[e]=t,this.updateConditionalFormat({rule:this.state.rules.cellIs})},composerContent:this.state.rules.cellIs.values[e],placeholder:Uo("Value or formula"),defaultStatic:!0,invalid:t,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getColorScaleComposerProps(e){const t=this.state.rules.colorScale[e];if(!t)throw new Error("Threshold not found");const o=this.isValueInvalid(e);return{onConfirm:e=>{t.value=e,this.updateConditionalFormat({rule:this.state.rules.colorScale})},composerContent:t.value||"",placeholder:Uo("Formula"),defaultStatic:!0,invalid:o,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getColorIconSetComposerProps(e){const t=this.state.rules.iconSet[e],o=this.isInflectionPointInvalid(e);return{onConfirm:e=>{t.value=e,this.updateConditionalFormat({rule:this.state.rules.iconSet})},composerContent:t.value||"",placeholder:Uo("Formula"),defaultStatic:!0,invalid:o,class:"o-sidePanel-composer",defaultRangeSheetId:this.env.model.getters.getActiveSheetId()}}getRangeValues(){return[this.state.rules.dataBar.rangeValues||""]}updateDataBarColor(e){$t(e)&&(this.state.rules.dataBar.color=Number.parseInt(e.slice(1),16),this.updateConditionalFormat({rule:this.state.rules.dataBar}))}onDataBarRangeUpdate(e){this.state.rules.dataBar.rangeValues=e[0]}onDataBarRangeChange(){this.updateConditionalFormat({rule:this.state.rules.dataBar})}}class WO extends t.Component{static template="o-spreadsheet-ConditionalFormattingPanel";static props={selection:{type:Object,optional:!0},onCloseSidePanel:Function};static components={ConditionalFormatPreviewList:$O,ConditionalFormattingEditor:GO,Section:RD};activeSheetId;originalEditedCf=void 0;state=t.useState({mode:"list"});setup(){this.activeSheetId=this.env.model.getters.getActiveSheetId();const e=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getRulesSelection(e,this.props.selection||[]);if(1===o.length){const e=this.conditionalFormats.find((e=>e.id===o[0]));e&&this.editConditionalFormat(e)}t.onWillUpdateProps((e=>{const t=this.env.model.getters.getActiveSheetId();if(t!==this.activeSheetId)this.activeSheetId=t,this.switchToList();else if(e.selection!==this.props.selection){const t=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getRulesSelection(t,e.selection||[]);if(1===o.length){const e=this.conditionalFormats.find((e=>e.id===o[0]));e&&this.editConditionalFormat(e)}else this.switchToList()}else this.editedCF||this.switchToList()}))}get conditionalFormats(){return this.env.model.getters.getConditionalFormats(this.env.model.getters.getActiveSheetId()).map((e=>({...e,rule:rl(e.rule,this.env.model.getters.getLocale())})))}switchToList(){this.state.mode="list",this.state.editedCfId=void 0,this.originalEditedCf=void 0}addConditionalFormat(){const e=this.env.model.uuidGenerator.smallUuid();this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,ranges:this.env.model.getters.getSelectedZones().map((e=>this.env.model.getters.getRangeDataFromZone(this.activeSheetId,e))),cf:{id:e,rule:{type:"CellIsRule",operator:"IsNotEmpty",style:{fillColor:"#b6d7a8"},values:[]}}}),this.state.editedCfId=e,this.state.mode="edit",this.originalEditedCf=void 0}editConditionalFormat(e){this.state.mode="edit",this.state.editedCfId=e.id,this.originalEditedCf=e}cancelEdition(){this.originalEditedCf?this.env.model.dispatch("ADD_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,ranges:this.originalEditedCf.ranges.map((e=>this.env.model.getters.getRangeDataFromXc(this.activeSheetId,e))),cf:this.originalEditedCf}):this.state.editedCfId&&this.env.model.dispatch("REMOVE_CONDITIONAL_FORMAT",{sheetId:this.activeSheetId,id:this.state.editedCfId}),this.switchToList()}get editedCF(){return this.conditionalFormats.find((e=>e.id===this.state.editedCfId))}}th`
1083
1083
  .o-custom-currency {
1084
1084
  .o-format-proposals {
1085
1085
  color: black;
@@ -2549,7 +2549,7 @@
2549
2549
  color: ${M};
2550
2550
  }
2551
2551
  }
2552
- `;class Dk extends t.Component{static template="o-spreadsheet-Spreadsheet";static props={model:Object,notifyUser:{type:Function,optional:!0},raiseError:{type:Function,optional:!0},askConfirmation:{type:Function,optional:!0}};static components={TopBar:Ak,Grid:IP,BottomBar:gk,SidePanel:yk,SpreadsheetDashboard:mk,HeaderGroupContainer:Sk};sidePanel;spreadsheetRef=t.useRef("spreadsheet");spreadsheetRect=lR();_focusGrid;isViewportTooSmall=!1;notificationStore;composerFocusStore;get model(){return this.props.model}getStyle(){const e={};return this.env.isDashboard()?e["grid-template-rows"]="auto":e["grid-template-rows"]="max-content auto 37px",e["grid-template-columns"]=`auto ${this.sidePanel.panelSize}px`,ih(e)}setup(){const e=Bc();e.inject(Zc,this.model),this.notificationStore=zc(IS),this.composerFocusStore=zc(Jc),this.sidePanel=zc(yP);const o=this.model.config.external.fileStore;t.useSubEnv({model:this.model,imageProvider:o?new nk(o):void 0,loadCurrencies:this.model.config.external.loadCurrencies,loadLocales:this.model.config.external.loadLocales,isDashboard:()=>this.model.getters.isDashboard(),openSidePanel:this.sidePanel.open.bind(this.sidePanel),toggleSidePanel:this.sidePanel.toggle.bind(this.sidePanel),clipboard:this.env.clipboard||new _k(navigator.clipboard),startCellEdition:e=>this.composerFocusStore.focusActiveComposer({content:e}),notifyUser:e=>this.notificationStore.notifyUser(e),askConfirmation:(e,t,o)=>this.notificationStore.askConfirmation(e,t,o),raiseError:(e,t)=>this.notificationStore.raiseError(e,t)}),this.notificationStore.updateNotificationCallbacks({...this.props}),t.useEffect((()=>{!this.spreadsheetRef.el.contains(document.activeElement)&&document.activeElement?.contains(this.spreadsheetRef.el)&&this.focusGrid()}),(()=>[this.env.model.getters.getActiveSheetId()])),t.useExternalListener(window,"resize",(()=>this.render(!0))),t.useExternalListener(document.body,"wheel",(()=>{})),this.bindModelEvents(),t.onWillUpdateProps((e=>{if(e.model!==this.props.model)throw new Error("Changing the props model is not supported at the moment.");e.notifyUser===this.props.notifyUser&&e.askConfirmation===this.props.askConfirmation&&e.raiseError===this.props.raiseError||this.notificationStore.updateNotificationCallbacks({...e})}));const s=function(e){let t=!1;return async(...o)=>{t||(t=!0,await Promise.resolve(),t=!1,e(...o))}}(this.render.bind(this,!0));t.onMounted((()=>{this.checkViewportSize(),e.on("store-updated",this,s),i.observe(this.spreadsheetRef.el),rh()})),t.onWillUnmount((()=>{this.unbindModelEvents(),e.off("store-updated",this),i.disconnect(),function(){if(window.Chart)for(const e of nh.getAll())e.unregister(window.Chart)}()})),t.onPatched((()=>{this.checkViewportSize()}));const i=new ResizeObserver((()=>{this.sidePanel.changePanelSize(this.sidePanel.panelSize,this.spreadsheetRect.width)}))}bindModelEvents(){this.model.on("update",this,(()=>this.render(!0))),this.model.on("notify-ui",this,(e=>this.notificationStore.notifyUser(e))),this.model.on("raise-error-ui",this,(({text:e})=>this.notificationStore.raiseError(e)))}unbindModelEvents(){this.model.off("update",this),this.model.off("notify-ui",this),this.model.off("raise-error-ui",this)}checkViewportSize(){const{xRatio:e,yRatio:t}=this.env.model.getters.getFrozenSheetViewRatio(this.env.model.getters.getActiveSheetId());if(isFinite(e)&&isFinite(t))if(t>.85||e>.85){if(this.isViewportTooSmall)return;this.notificationStore.notifyUser({text:Uo("The current window is too small to display this sheet properly. Consider resizing your browser window or adjusting frozen rows and columns."),type:"warning",sticky:!1}),this.isViewportTooSmall=!0}else this.isViewportTooSmall=!1}focusGrid(){this._focusGrid&&this._focusGrid()}get gridHeight(){const{height:e}=this.env.model.getters.getSheetViewDimension();return e}get gridContainerStyle(){const e=le*this.rowLayers.length,t=le*this.colLayers.length;return ih({"grid-template-columns":`${e?e+2:0}px auto`,"grid-template-rows":`${t?t+2:0}px auto`})}get rowLayers(){const e=this.env.model.getters.getActiveSheetId();return this.env.model.getters.getVisibleGroupLayers(e,"ROW")}get colLayers(){const e=this.env.model.getters.getActiveSheetId();return this.env.model.getters.getVisibleGroupLayers(e,"COL")}}class Ok{listeners=[];async sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}function Fk(e){return JE.get(e.type)(e)}class Mk{buildTransformation;operations;constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){return this.operations[this.operations.length-1]?.id}getFirstOperationAmong(e,t){for(const o of this.operations){if(o.id===e)return e;if(o.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const o=this.buildTransformation.with(e.data),{before:s,operation:i,after:n}=this.locateOperation(t);this.operations=[...s,i,e,...n.map((e=>e.transformed(o)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new Mk(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:o}=this.locateOperation(e);this.operations=t.concat([o])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class Pk{id;data;constructor(e,t){this.id=e,this.data=t}transformed(e){return new Nk(this.id,gt((()=>e(this.data))))}}class Nk{id;lazyData;constructor(e,t){this.id=e,this.lazyData=t}get data(){return this.lazyData()}transformed(e){return new Nk(this.id,this.lazyData.map(e))}}class kk{operations;constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new kk(function*(e,t){for(const o of e)if(yield o,o.operation.id===t)return}(this.operations,e))}stopBefore(e){return new kk(function*(e,t){for(const o of e){if(o.operation.id===t)return;yield o}}(this.operations,e))}startAfter(e){return new kk(function*(e,t){let o=!0;for(const s of e)o||(yield s),s.operation.id===t&&(o=!1)}(this.operations,e))}}class Vk{buildTransformation;branches;branchingOperationIds=new Map;constructor(e,t){this.buildTransformation=e,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new kk(Xe(this._execution(e),this._execution(e)))}revertedExecution(e){return new kk(Xe(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){const o=e.getLastOperationId()||this.previousBranch(e)?.getLastOperationId();e.append(t),o&&this.insertPrevious(e,t,o)}insertOperationAfter(e,t,o){e.insert(t,o),this.updateNextWith(e,t,o),this.insertPrevious(e,t,o)}undo(e,t){const o=this.buildTransformation.without(t.data),s=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const i=e.fork(t.id);s&&this.branchingOperationIds.set(i,s),this.insertBranchAfter(e,i),this.transform(i,o)}redo(e){const t=this.nextBranch(e);if(!t)return;const o=this.nextBranch(t);this.removeBranchFromTree(t);const s=this.branchingOperationIds.get(t);s?this.branchingOperationIds.set(e,s):this.branchingOperationIds.delete(e),o&&this.rebaseUp(o)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const o of this.revertedExecution(e))if(o.operation.id===t)return o;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!t||!o)return;const s=this.buildTransformation.without(o.data),i=t.fork(o.id);this.branchingOperationIds.set(i,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,i),i.transform(s);const n=this.nextBranch(i);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const o=this.branches.findIndex((t=>t===e));this.branches.splice(o+1,0,t)}updateNextWith(e,t,o){const s=this.branchingOperationIds.get(e),i=this.nextBranch(e);if(s&&i)if(e.getFirstOperationAmong(o,s)===s){const n=this.addToNextBranch(e,i,s,t,o);this.updateNextWith(i,n,o)}else{const e=this.buildTransformation.with(t.data);this.transform(i,e)}}addToNextBranch(e,t,o,s,i){let n=s;return i===o?(n=this.getTransformedOperation(e,o,s),t.prepend(n)):t.contains(i)?(n=this.getTransformedOperation(e,o,s),t.insert(n,i)):t.append(s),n}getTransformedOperation(e,t,o){const s=e.getOperation(t),i=this.buildTransformation.without(s.data);return o.transformed(i)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const o=this.nextBranch(e);o&&this.transform(o,t)}insertPrevious(e,t,o){const{previousBranch:s,branchingOperation:i}=this.findPreviousBranchingOperation(e);if(!s||!i)return;const n=this.buildTransformation.with(i.data),r=e.fork(o);r.transform(n),s.cutAfter(o),s.appendBranch(r);const a=t.transformed(n);this.insertPrevious(s,a,o)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const o=this.branchingOperationIds.get(t);return o?{previousBranch:t,branchingOperation:t.getOperation(o)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let o=!!t;const s=e.getOperations();for(let i=s.length-1;i>=0;i--){const n=s[i];n.id===t&&(o=!1),o||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const i=this.previousBranch(e);yield*i?this._revertedExecution(i):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class Lk{HEAD_BRANCH;HEAD_OPERATION;tree;applyOperation;revertOperation;buildEmpty;buildTransformation;constructor(e){this.applyOperation=e.applyOperation,this.revertOperation=e.revertOperation,this.buildEmpty=e.buildEmpty,this.buildTransformation=e.buildTransformation,this.HEAD_BRANCH=new Mk(this.buildTransformation),this.tree=new Vk(this.buildTransformation,this.HEAD_BRANCH);const t=e.initialOperationId,o=new Pk(t,this.buildEmpty(t));this.tree.insertOperationLast(this.HEAD_BRANCH,o),this.HEAD_OPERATION=o}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const o=new Pk(e,t),s=this.tree.getLastBranch();this.tree.insertOperationLast(s,o),this.HEAD_BRANCH=s,this.HEAD_OPERATION=o}insert(e,t,o){const s=new Pk(e,t);this.revertTo(o),this.tree.insertOperationAfter(this.HEAD_BRANCH,s,o),this.fastForward()}undo(e,t,o){const{branch:s,operation:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(s,i),this.fastForward(),this.insert(t,this.buildEmpty(t),o)}redo(e,t,o){const{branch:s}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(s),this.fastForward(),this.insert(t,this.buildEmpty(t),o)}rebase(e){const t=this.get(e),o=[...this.tree.execution(this.HEAD_BRANCH).startAfter(e)];this.revertBefore(e);const s=this.HEAD_OPERATION.id;this.tree.drop(e),this.insert(e,t,s);for(const{operation:e}of o)this.insert(e.id,e.data,this.HEAD_OPERATION.id)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:o,isCancelled:s}of e)s||this.revertOperation(o.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:o,isCancelled:s}of e)s||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=o}}function Hk(e){return new Lk({initialOperationId:e.initialRevisionId,applyOperation:t=>{const o=t.commands.slice(),{changes:s}=e.recordChanges((()=>{for(const t of o)e.dispatch(t)}));t.setChanges(s)},revertOperation:e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Uk(t.changes[e])}}([e]),buildEmpty:e=>new NN(e,"empty",[]),buildTransformation:{with:e=>t=>new NN(t.id,t.clientId,MN(t.commands,e.commands),t.rootCommand,void 0,t.timestamp),without:e=>t=>new NN(t.id,t.clientId,MN(t.commands,e.commands.map(Fk).flat()),t.rootCommand,void 0,t.timestamp)}})}function Uk(e){const t=e.target,o=e.key,s=e.before;void 0===s?delete t[o]:t[o]=s}class Bk{observers=new Map;defaultSubscription;mainSubscription;registerAsDefault(e,t){this.defaultSubscription={owner:e,callbacks:t},this.mainSubscription||(this.mainSubscription=this.defaultSubscription)}observe(e,t){this.observers.set(e,{owner:e,callbacks:t})}detachObserver(e){this.observers.delete(e)}capture(e,t){if(this.observers.get(e))throw new Error("You are already subscribed forever");this.mainSubscription?.owner&&this.mainSubscription.owner!==e&&this.mainSubscription.callbacks.release?.(),this.mainSubscription={owner:e,callbacks:t}}release(e){this.mainSubscription?.owner!==e||this.observers.get(e)||(this.mainSubscription=this.defaultSubscription)}getBackToDefault(){this.mainSubscription!==this.defaultSubscription&&(this.mainSubscription?.callbacks.release?.(),this.mainSubscription=this.defaultSubscription)}isListening(e){return this.mainSubscription?.owner===e}send(e){this.mainSubscription?.callbacks.handleEvent(e),this.observers.forEach((t=>t.callbacks.handleEvent(e)))}}class zk{getters;stream;anchor;defaultAnchor;constructor(e){this.getters=e,this.stream=new Bk,this.anchor={cell:{col:0,row:0},zone:hs({col:0,row:0})},this.defaultAnchor=this.anchor}capture(e,t,o){this.stream.capture(e,o),this.anchor=t}registerAsDefault(e,t,o){this.checkAnchorZoneOrThrow(t),this.stream.registerAsDefault(e,o),this.defaultAnchor=t,this.capture(e,t,o)}resetDefaultAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t),this.defaultAnchor=t}resetAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t)}observe(e,t){this.stream.observe(e,t)}detachObserver(e){this.stream.detachObserver(e)}release(e){this.stream.isListening(e)&&(this.stream.release(e),this.anchor=this.defaultAnchor)}getBackToDefault(){this.stream.getBackToDefault()}modifyAnchor(e,t,o){const s=this.getters.getActiveSheetId();return e={...e,zone:this.getters.expandZone(s,e.zone)},this.processEvent({options:o,anchor:e,mode:t})}selectZone(e,t={scrollIntoView:!0}){return this.modifyAnchor(e,"overrideSelection",t)}selectCell(e,t){const o=hs({col:e,row:t});return this.selectZone({zone:o,cell:{col:e,row:t}},{scrollIntoView:!0})}moveAnchorCell(e,t=1){if("end"!==t&&t<=0)return new ui("InvalidSelectionStep");const{col:o,row:s}=this.getNextAvailablePosition(e,t);return this.selectCell(o,s)}setAnchorCorner(e,t){const o=this.getters.getActiveSheetId(),{col:s,row:i}=this.anchor.cell,n={left:Math.min(s,e),top:Math.min(i,t),right:Math.max(s,e),bottom:Math.max(i,t)},r={zone:this.getters.expandZone(o,n),cell:{col:s,row:i}};return this.processEvent({mode:"updateAnchor",anchor:r,options:{scrollIntoView:!1}})}addCellToSelection(e,t){const o=this.getters.getActiveSheetId();({col:e,row:t}=this.getters.getMainCellPosition({sheetId:o,col:e,row:t}));const s=this.getters.expandZone(o,hs({col:e,row:t}));return this.processEvent({options:{scrollIntoView:!0},anchor:{zone:s,cell:{col:e,row:t}},mode:"newAnchor"})}resizeAnchorZone(e,t=1){if("end"!==t&&t<=0)return new ui("InvalidSelectionStep");const o=this.getters.getActiveSheetId(),s=this.anchor,{col:i,row:n}=s.cell,{left:r,right:a,top:l,bottom:c}=s.zone,h=this.getStartingPosition(e);let[d,u]=this.deltaToTarget(h,e,t);if(0===d&&0===u)return ui.Success;let g=s.zone;const p=e=>{e=as(e);const{left:t,right:s,top:i,bottom:n}=this.getters.expandZone(o,e);return{left:Math.max(0,t),right:Math.min(this.getters.getNumberCols(o)-1,s),top:Math.max(0,i),bottom:Math.min(this.getters.getNumberRows(o)-1,n)}},{col:m,row:f}=this.getReferencePosition();let v=0;for(;null!==g;){if(v++,d<0){const e=this.getNextAvailableCol(d,a-(v-1),f);g=m<=a-v?p({top:l,left:r,bottom:c,right:e}):null}if(d>0){const e=this.getNextAvailableCol(d,r+(v-1),f);g=r+v<=m?p({top:l,left:e,bottom:c,right:a}):null}if(u<0){const e=this.getNextAvailableRow(u,m,c-(v-1));g=f<=c-v?p({top:l,left:r,bottom:e,right:a}):null}if(u>0){const e=this.getNextAvailableRow(u,m,l+(v-1));g=l+v<=f?p({top:e,left:r,bottom:c,right:a}):null}if(g=g?as(g):g,g&&!Qo(g,s.zone))return this.processEvent({options:{scrollIntoView:!0},mode:"updateAnchor",anchor:{zone:g,cell:{col:i,row:n}}})}g=p(Ko({top:n,bottom:n,left:i,right:i},as({top:this.getNextAvailableRow(u,m,l),left:this.getNextAvailableCol(d,r,f),bottom:this.getNextAvailableRow(u,m,c),right:this.getNextAvailableCol(d,a,f)})));const b={zone:g,cell:{col:i,row:n}};return this.processEvent({anchor:b,mode:"updateAnchor",options:{scrollIntoView:!0}})}selectColumn(e,t){const o=this.getters.getActiveSheetId(),s=this.getters.getNumberRows(o)-1;let i={left:e,right:e,top:0,bottom:s};const n=this.getters.findFirstVisibleColRowIndex(o,"ROW");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=e,a=n;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),i=Ko(i,{left:r,right:r,top:n,bottom:s})}return this.processEvent({options:{scrollIntoView:!1,unbounded:!0},anchor:{zone:i,cell:{col:r,row:a}},mode:t})}selectRow(e,t){const o=this.getters.getActiveSheetId(),s=this.getters.getNumberCols(o)-1;let i={top:e,bottom:e,left:0,right:s};const n=this.getters.findFirstVisibleColRowIndex(o,"COL");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=n,a=e;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),i=Ko(i,{left:n,right:s,top:a,bottom:a})}return this.processEvent({options:{scrollIntoView:!1,unbounded:!0},anchor:{zone:i,cell:{col:r,row:a}},mode:t})}loopSelection(){const e=this.getters.getActiveSheetId(),t=this.anchor;if(Qo(this.anchor.zone,this.getters.getSheetZone(e)))return this.modifyAnchor({...t,zone:hs(t.cell)},"updateAnchor",{scrollIntoView:!1});const o=this.getters.getContiguousZone(e,t.zone);return ft(o,t.zone)?this.selectAll():this.modifyAnchor({...t,zone:o},"updateAnchor",{scrollIntoView:!1})}selectTableAroundSelection(){const e=this.getters.getActiveSheetId(),t=this.getters.getContiguousZone(e,this.anchor.zone);return this.modifyAnchor({...this.anchor,zone:t},"updateAnchor",{scrollIntoView:!1})}selectAll(){const e=this.getters.getActiveSheetId(),t={left:0,top:0,bottom:this.getters.getNumberRows(e)-1,right:this.getters.getNumberCols(e)-1};return this.processEvent({mode:"overrideSelection",anchor:{zone:t,cell:this.anchor.cell},options:{scrollIntoView:!1}})}isListening(e){return this.stream.isListening(e)}processEvent(e){const t={...e,previousAnchor:ze(this.anchor)},o=this.checkEventAnchorZone(t);return"Success"!==o?new ui(o):(this.anchor=t.anchor,this.stream.send(t),ui.Success)}checkEventAnchorZone(e){return this.checkAnchorZone(e.anchor)}checkAnchorZone(e){const{cell:t,zone:o}=e;if(!ts(t.col,t.row,o))return"InvalidAnchorZone";const{left:s,right:i,top:n,bottom:r}=o,a=this.getters.getActiveSheetId(),l=this.getters.findVisibleHeader(a,"COL",s,i);return void 0===this.getters.findVisibleHeader(a,"ROW",n,r)||void 0===l?"SelectionOutOfBound":"Success"}checkAnchorZoneOrThrow(e){if("InvalidAnchorZone"===this.checkAnchorZone(e))throw new Error(Uo("The provided anchor is invalid. The cell must be part of the zone."))}getNextAvailablePosition(e,t=1){const{col:o,row:s}=this.anchor.cell,i=this.deltaToTarget({col:o,row:s},e,t);return{col:this.getNextAvailableCol(i[0],o,s),row:this.getNextAvailableRow(i[1],o,s)}}getNextAvailableCol(e,t,o){const s=this.getters.getActiveSheetId(),i={col:t,row:o};return this.getNextAvailableHeader(e,"COL",t,i,(e=>this.getters.isInSameMerge(s,t,o,e,o)))}getNextAvailableRow(e,t,o){const s=this.getters.getActiveSheetId(),i={col:t,row:o};return this.getNextAvailableHeader(e,"ROW",o,i,(e=>this.getters.isInSameMerge(s,t,o,t,e)))}getNextAvailableHeader(e,t,o,s,i){const n=this.getters.getActiveSheetId();if(0===e)return o;const r=Math.sign(e);let a=o+e;for(;i(a);)a+=r;for(;this.getters.isHeaderHidden(n,t,a);)a+=r;return a<0||a>this.getters.getNumberHeaders(n,t)-1?this.getters.isHeaderHidden(n,t,o)?this.getNextAvailableHeader(-r,t,o,s,i):o:a}getReferencePosition(){const e=this.getters.getActiveSheetId(),t=this.anchor,{left:o,right:s,top:i,bottom:n}=t.zone,{col:r,row:a}=t.cell;return{col:this.getters.isColHidden(e,r)&&this.getters.findVisibleHeader(e,"COL",o,s)||r,row:this.getters.isRowHidden(e,a)&&this.getters.findVisibleHeader(e,"ROW",i,n)||a}}deltaToTarget(e,t,o){switch(t){case"up":return"end"!==o?[0,-o]:[0,this.getEndOfCluster(e,"rows",-1)-e.row];case"down":return"end"!==o?[0,o]:[0,this.getEndOfCluster(e,"rows",1)-e.row];case"left":return"end"!==o?[-o,0]:[this.getEndOfCluster(e,"cols",-1)-e.col,0];case"right":return"end"!==o?[o,0]:[this.getEndOfCluster(e,"cols",1)-e.col,0]}}getStartingPosition(e){let{col:t,row:o}=this.getPosition();const s=this.anchor.zone;switch(e){case"down":case"up":o=o===s.top?s.bottom:s.top;break;case"left":case"right":t=t===s.right?s.left:s.right}return{col:t,row:o}}getEndOfCluster(e,t,o){const s=this.getters.getActiveSheetId();let i=e;const n=this.getNextCellPosition(e,t,o);let r=this.isCellSkippableInCluster({...i,sheetId:s})||this.isCellSkippableInCluster({...n,sheetId:s})?"nextCluster":"endOfCluster";for(;;){const e=this.getNextCellPosition(i,t,o);if(i.col===e.col&&i.row===e.row)break;const n=this.isCellSkippableInCluster({...e,sheetId:s});if("endOfCluster"===r&&n)break;if("nextCluster"===r&&!n){i=e;break}i=e}return"cols"===t?i.col:i.row}getNextCellPosition(e,t,o){const s={...e};return s["cols"===t?"col":"row"]="cols"===t?this.getNextAvailableCol(o,s.col,s.row):this.getNextAvailableRow(o,s.col,s.row),{col:s.col,row:s.row}}getPosition(){return{...this.anchor.cell}}isCellSkippableInCluster(e){const t=this.getters.getMainCellPosition(e),o=this.getters.getEvaluatedCell(t);return o.type===oi.empty||o.type===oi.text&&""===o.value}}function $k(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class Gk{changes;commands=[];recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let o=e[0],s=e.at(-1);const i=e.length-2;for(let t=1;t<=i;t++){const s=e[t];if(void 0===o[s]){const i=e[t+1];o[s]=$k(i)}o=o[s]}o[s]!==t&&(this.changes?.push({key:s,target:o,before:o[s]}),void 0===t?delete o[s]:o[s]=t)}}const Wk=17781237,qk=17781238,Zk=88853993,jk=88853994;function Yk(e,t,o){const s=[["xmlns:r",Ny],["xmlns:a",Dy],["xmlns:c",Oy]],i=Xk({backgroundColor:e.data.backgroundColor,line:{color:"000000"}});let n=nx``;if(e.data.title?.text){const t=Cy(Sh(e.data.backgroundColor)),o=e.data.title.fontSize??X;n=nx`
2552
+ `;class Dk extends t.Component{static template="o-spreadsheet-Spreadsheet";static props={model:Object,notifyUser:{type:Function,optional:!0},raiseError:{type:Function,optional:!0},askConfirmation:{type:Function,optional:!0}};static components={TopBar:Ak,Grid:IP,BottomBar:gk,SidePanel:yk,SpreadsheetDashboard:mk,HeaderGroupContainer:Sk};sidePanel;spreadsheetRef=t.useRef("spreadsheet");spreadsheetRect=lR();_focusGrid;isViewportTooSmall=!1;notificationStore;composerFocusStore;get model(){return this.props.model}getStyle(){const e={};return this.env.isDashboard()?e["grid-template-rows"]="auto":e["grid-template-rows"]="max-content auto 37px",e["grid-template-columns"]=`auto ${this.sidePanel.panelSize}px`,ih(e)}setup(){const e=Bc();e.inject(Zc,this.model),this.notificationStore=zc(IS),this.composerFocusStore=zc(Jc),this.sidePanel=zc(yP);const o=this.model.config.external.fileStore;t.useSubEnv({model:this.model,imageProvider:o?new nk(o):void 0,loadCurrencies:this.model.config.external.loadCurrencies,loadLocales:this.model.config.external.loadLocales,isDashboard:()=>this.model.getters.isDashboard(),openSidePanel:this.sidePanel.open.bind(this.sidePanel),toggleSidePanel:this.sidePanel.toggle.bind(this.sidePanel),clipboard:this.env.clipboard||new _k(navigator.clipboard),startCellEdition:e=>this.composerFocusStore.focusActiveComposer({content:e}),notifyUser:e=>this.notificationStore.notifyUser(e),askConfirmation:(e,t,o)=>this.notificationStore.askConfirmation(e,t,o),raiseError:(e,t)=>this.notificationStore.raiseError(e,t)}),this.notificationStore.updateNotificationCallbacks({...this.props}),t.useEffect((()=>{!this.spreadsheetRef.el.contains(document.activeElement)&&document.activeElement?.contains(this.spreadsheetRef.el)&&this.focusGrid()}),(()=>[this.env.model.getters.getActiveSheetId()])),t.useExternalListener(window,"resize",(()=>this.render(!0))),t.useExternalListener(document.body,"wheel",(()=>{})),this.bindModelEvents(),t.onWillUpdateProps((e=>{if(e.model!==this.props.model)throw new Error("Changing the props model is not supported at the moment.");e.notifyUser===this.props.notifyUser&&e.askConfirmation===this.props.askConfirmation&&e.raiseError===this.props.raiseError||this.notificationStore.updateNotificationCallbacks({...e})}));const s=function(e){let t=!1;return async(...o)=>{t||(t=!0,await Promise.resolve(),t=!1,e(...o))}}(this.render.bind(this,!0));t.onMounted((()=>{this.checkViewportSize(),e.on("store-updated",this,s),i.observe(this.spreadsheetRef.el),rh()})),t.onWillUnmount((()=>{this.unbindModelEvents(),e.off("store-updated",this),i.disconnect(),function(){if(window.Chart)for(const e of nh.getAll())e.unregister(window.Chart)}()})),t.onPatched((()=>{this.checkViewportSize()}));const i=new ResizeObserver((()=>{this.sidePanel.changePanelSize(this.sidePanel.panelSize,this.spreadsheetRect.width)}))}bindModelEvents(){this.model.on("update",this,(()=>this.render(!0))),this.model.on("notify-ui",this,(e=>this.notificationStore.notifyUser(e))),this.model.on("raise-error-ui",this,(({text:e})=>this.notificationStore.raiseError(e)))}unbindModelEvents(){this.model.off("update",this),this.model.off("notify-ui",this),this.model.off("raise-error-ui",this)}checkViewportSize(){const{xRatio:e,yRatio:t}=this.env.model.getters.getFrozenSheetViewRatio(this.env.model.getters.getActiveSheetId());if(isFinite(e)&&isFinite(t))if(t>.85||e>.85){if(this.isViewportTooSmall)return;this.notificationStore.notifyUser({text:Uo("The current window is too small to display this sheet properly. Consider resizing your browser window or adjusting frozen rows and columns."),type:"warning",sticky:!1}),this.isViewportTooSmall=!0}else this.isViewportTooSmall=!1}focusGrid(){this._focusGrid&&this._focusGrid()}get gridHeight(){const{height:e}=this.env.model.getters.getSheetViewDimension();return e}get gridContainerStyle(){const e=le*this.rowLayers.length,t=le*this.colLayers.length;return ih({"grid-template-columns":`${e?e+2:0}px auto`,"grid-template-rows":`${t?t+2:0}px auto`})}get rowLayers(){const e=this.env.model.getters.getActiveSheetId();return this.env.model.getters.getVisibleGroupLayers(e,"ROW")}get colLayers(){const e=this.env.model.getters.getActiveSheetId();return this.env.model.getters.getVisibleGroupLayers(e,"COL")}}class Ok{listeners=[];async sendMessage(e){for(const{callback:t}of this.listeners)t(e)}onNewMessage(e,t){this.listeners.push({id:e,callback:t})}leave(e){this.listeners=this.listeners.filter((t=>t.id!==e))}}function Fk(e){return JE.get(e.type)(e)}class Mk{buildTransformation;operations;constructor(e,t=[]){this.buildTransformation=e,this.operations=t}getOperations(){return this.operations}getOperation(e){const t=this.operations.find((t=>t.id===e));if(!t)throw new Error(`Operation ${e} not found`);return t}getLastOperationId(){return this.operations[this.operations.length-1]?.id}getFirstOperationAmong(e,t){for(const o of this.operations){if(o.id===e)return e;if(o.id===t)return t}throw new Error(`Operation ${e} and ${t} not found`)}contains(e){return!!this.operations.find((t=>t.id===e))}prepend(e){const t=this.buildTransformation.with(e.data);this.operations=[e,...this.operations.map((e=>e.transformed(t)))]}insert(e,t){const o=this.buildTransformation.with(e.data),{before:s,operation:i,after:n}=this.locateOperation(t);this.operations=[...s,i,e,...n.map((e=>e.transformed(o)))]}append(e){this.operations.push(e)}appendBranch(e){this.operations=this.operations.concat(e.operations)}fork(e){const{after:t}=this.locateOperation(e);return new Mk(this.buildTransformation,t)}transform(e){this.operations=this.operations.map((t=>t.transformed(e)))}cutBefore(e){this.operations=this.locateOperation(e).before}cutAfter(e){const{before:t,operation:o}=this.locateOperation(e);this.operations=t.concat([o])}locateOperation(e){const t=this.operations.findIndex((t=>t.id===e));if(-1===t)throw new Error(`Operation ${e} not found`);return{before:this.operations.slice(0,t),operation:this.operations[t],after:this.operations.slice(t+1)}}}class Pk{id;data;constructor(e,t){this.id=e,this.data=t}transformed(e){return new Nk(this.id,gt((()=>e(this.data))))}}class Nk{id;lazyData;constructor(e,t){this.id=e,this.lazyData=t}get data(){return this.lazyData()}transformed(e){return new Nk(this.id,this.lazyData.map(e))}}class kk{operations;constructor(e){this.operations=e}[Symbol.iterator](){return this.operations[Symbol.iterator]()}stopWith(e){return new kk(function*(e,t){for(const o of e)if(yield o,o.operation.id===t)return}(this.operations,e))}stopBefore(e){return new kk(function*(e,t){for(const o of e){if(o.operation.id===t)return;yield o}}(this.operations,e))}startAfter(e){return new kk(function*(e,t){let o=!0;for(const s of e)o||(yield s),s.operation.id===t&&(o=!1)}(this.operations,e))}}class Vk{buildTransformation;branches;branchingOperationIds=new Map;constructor(e,t){this.buildTransformation=e,this.branches=[t]}getLastBranch(){return this.branches[this.branches.length-1]}execution(e){return new kk(Xe(this._execution(e),this._execution(e)))}revertedExecution(e){return new kk(Xe(this._revertedExecution(e),this._revertedExecution(e)))}insertOperationLast(e,t){const o=e.getLastOperationId()||this.previousBranch(e)?.getLastOperationId();e.append(t),o&&this.insertPrevious(e,t,o)}insertOperationAfter(e,t,o){e.insert(t,o),this.updateNextWith(e,t,o),this.insertPrevious(e,t,o)}undo(e,t){const o=this.buildTransformation.without(t.data),s=this.branchingOperationIds.get(e);this.branchingOperationIds.set(e,t.id);const i=e.fork(t.id);s&&this.branchingOperationIds.set(i,s),this.insertBranchAfter(e,i),this.transform(i,o)}redo(e){const t=this.nextBranch(e);if(!t)return;const o=this.nextBranch(t);this.removeBranchFromTree(t);const s=this.branchingOperationIds.get(t);s?this.branchingOperationIds.set(e,s):this.branchingOperationIds.delete(e),o&&this.rebaseUp(o)}drop(e){for(const t of this.branches)t.contains(e)&&t.cutBefore(e)}findOperation(e,t){for(const o of this.revertedExecution(e))if(o.operation.id===t)return o;throw new Error(`Operation ${t} not found`)}rebaseUp(e){const{previousBranch:t,branchingOperation:o}=this.findPreviousBranchingOperation(e);if(!t||!o)return;const s=this.buildTransformation.without(o.data),i=t.fork(o.id);this.branchingOperationIds.set(i,this.branchingOperationIds.get(e)),this.removeBranchFromTree(e),this.insertBranchAfter(t,i),i.transform(s);const n=this.nextBranch(i);n&&this.rebaseUp(n)}removeBranchFromTree(e){const t=this.branches.findIndex((t=>t===e));this.branches.splice(t,1)}insertBranchAfter(e,t){const o=this.branches.findIndex((t=>t===e));this.branches.splice(o+1,0,t)}updateNextWith(e,t,o){const s=this.branchingOperationIds.get(e),i=this.nextBranch(e);if(s&&i)if(e.getFirstOperationAmong(o,s)===s){const n=this.addToNextBranch(e,i,s,t,o);this.updateNextWith(i,n,o)}else{const e=this.buildTransformation.with(t.data);this.transform(i,e)}}addToNextBranch(e,t,o,s,i){let n=s;return i===o?(n=this.getTransformedOperation(e,o,s),t.prepend(n)):t.contains(i)?(n=this.getTransformedOperation(e,o,s),t.insert(n,i)):t.append(s),n}getTransformedOperation(e,t,o){const s=e.getOperation(t),i=this.buildTransformation.without(s.data);return o.transformed(i)}shouldExecute(e,t){return t.id!==this.branchingOperationIds.get(e)}transform(e,t){e.transform(t);const o=this.nextBranch(e);o&&this.transform(o,t)}insertPrevious(e,t,o){const{previousBranch:s,branchingOperation:i}=this.findPreviousBranchingOperation(e);if(!s||!i)return;const n=this.buildTransformation.with(i.data),r=e.fork(o);r.transform(n),s.cutAfter(o),s.appendBranch(r);const a=t.transformed(n);this.insertPrevious(s,a,o)}findPreviousBranchingOperation(e){const t=this.previousBranch(e);if(!t)return{previousBranch:void 0,branchingOperation:void 0};const o=this.branchingOperationIds.get(t);return o?{previousBranch:t,branchingOperation:t.getOperation(o)}:{previousBranch:void 0,branchingOperation:void 0}}nextBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t+1]}previousBranch(e){const t=this.branches.findIndex((t=>t===e));if(-1!==t)return this.branches[t-1]}*_revertedExecution(e){const t=this.branchingOperationIds.get(e);let o=!!t;const s=e.getOperations();for(let i=s.length-1;i>=0;i--){const n=s[i];n.id===t&&(o=!1),o||(yield{operation:n,branch:e,isCancelled:!this.shouldExecute(e,n)})}const i=this.previousBranch(e);yield*i?this._revertedExecution(i):[]}*_execution(e){for(const t of e.getOperations())if(yield{operation:t,branch:e,isCancelled:!this.shouldExecute(e,t)},t.id===this.branchingOperationIds.get(e)){const t=this.nextBranch(e);return void(yield*t?this._execution(t):[])}if(!this.branchingOperationIds.get(e)){const t=this.nextBranch(e);yield*t?this._execution(t):[]}}}class Lk{HEAD_BRANCH;HEAD_OPERATION;tree;applyOperation;revertOperation;buildEmpty;buildTransformation;constructor(e){this.applyOperation=e.applyOperation,this.revertOperation=e.revertOperation,this.buildEmpty=e.buildEmpty,this.buildTransformation=e.buildTransformation,this.HEAD_BRANCH=new Mk(this.buildTransformation),this.tree=new Vk(this.buildTransformation,this.HEAD_BRANCH);const t=e.initialOperationId,o=new Pk(t,this.buildEmpty(t));this.tree.insertOperationLast(this.HEAD_BRANCH,o),this.HEAD_OPERATION=o}get(e){return this.tree.findOperation(this.HEAD_BRANCH,e).operation.data}append(e,t){const o=new Pk(e,t),s=this.tree.getLastBranch();this.tree.insertOperationLast(s,o),this.HEAD_BRANCH=s,this.HEAD_OPERATION=o}insert(e,t,o){const s=new Pk(e,t);this.revertTo(o),this.tree.insertOperationAfter(this.HEAD_BRANCH,s,o),this.fastForward()}undo(e,t,o){const{branch:s,operation:i}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.undo(s,i),this.fastForward(),this.insert(t,this.buildEmpty(t),o)}redo(e,t,o){const{branch:s}=this.tree.findOperation(this.HEAD_BRANCH,e);this.revertBefore(e),this.tree.redo(s),this.fastForward(),this.insert(t,this.buildEmpty(t),o)}rebase(e){const t=this.get(e),o=[...this.tree.execution(this.HEAD_BRANCH).startAfter(e)];this.revertBefore(e);const s=this.HEAD_OPERATION.id;this.tree.drop(e),this.insert(e,t,s);for(const{operation:e}of o)this.insert(e.id,e.data,this.HEAD_OPERATION.id)}revertBefore(e){const t=this.tree.revertedExecution(this.HEAD_BRANCH).stopWith(e);this.revert(t)}revertTo(e){const t=e?this.tree.revertedExecution(this.HEAD_BRANCH).stopBefore(e):this.tree.revertedExecution(this.HEAD_BRANCH);this.revert(t)}revert(e){for(const{next:t,operation:o,isCancelled:s}of e)s||this.revertOperation(o.data),t&&(this.HEAD_BRANCH=t.branch,this.HEAD_OPERATION=t.operation)}fastForward(){const e=this.HEAD_OPERATION?this.tree.execution(this.HEAD_BRANCH).startAfter(this.HEAD_OPERATION.id):this.tree.execution(this.HEAD_BRANCH);for(const{operation:t,branch:o,isCancelled:s}of e)s||this.applyOperation(t.data),this.HEAD_OPERATION=t,this.HEAD_BRANCH=o}}function Hk(e){return new Lk({initialOperationId:e.initialRevisionId,applyOperation:t=>{const o=t.commands.slice(),{changes:s}=e.recordChanges((()=>{for(const t of o)e.dispatch(t)}));t.setChanges(s)},revertOperation:e=>function(e){for(const t of e.slice().reverse())for(let e=t.changes.length-1;e>=0;e--){Uk(t.changes[e])}}([e]),buildEmpty:e=>new NN(e,"empty",[]),buildTransformation:{with:e=>t=>new NN(t.id,t.clientId,MN(t.commands,e.commands),t.rootCommand,void 0,t.timestamp),without:e=>t=>new NN(t.id,t.clientId,MN(t.commands,e.commands.map(Fk).flat()),t.rootCommand,void 0,t.timestamp)}})}function Uk(e){const t=e.target,o=e.key,s=e.before;void 0===s?delete t[o]:t[o]=s}class Bk{observers=new Map;defaultSubscription;mainSubscription;registerAsDefault(e,t){this.defaultSubscription={owner:e,callbacks:t},this.mainSubscription||(this.mainSubscription=this.defaultSubscription)}observe(e,t){this.observers.set(e,{owner:e,callbacks:t})}detachObserver(e){this.observers.delete(e)}capture(e,t){if(this.observers.get(e))throw new Error("You are already subscribed forever");this.mainSubscription?.owner&&this.mainSubscription.owner!==e&&this.mainSubscription.callbacks.release?.(),this.mainSubscription={owner:e,callbacks:t}}release(e){this.mainSubscription?.owner!==e||this.observers.get(e)||(this.mainSubscription=this.defaultSubscription)}getBackToDefault(){this.mainSubscription!==this.defaultSubscription&&(this.mainSubscription?.callbacks.release?.(),this.mainSubscription=this.defaultSubscription)}isListening(e){return this.mainSubscription?.owner===e}send(e){this.mainSubscription?.callbacks.handleEvent(e),this.observers.forEach((t=>t.callbacks.handleEvent(e)))}}class zk{getters;stream;anchor;defaultAnchor;constructor(e){this.getters=e,this.stream=new Bk,this.anchor={cell:{col:0,row:0},zone:hs({col:0,row:0})},this.defaultAnchor=this.anchor}capture(e,t,o){this.stream.capture(e,o),this.anchor=t}registerAsDefault(e,t,o){this.checkAnchorZoneOrThrow(t),this.stream.registerAsDefault(e,o),this.defaultAnchor=t,this.capture(e,t,o)}resetDefaultAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t),this.defaultAnchor=t}resetAnchor(e,t){this.checkAnchorZoneOrThrow(t),this.stream.isListening(e)&&(this.anchor=t)}observe(e,t){this.stream.observe(e,t)}detachObserver(e){this.stream.detachObserver(e)}release(e){this.stream.isListening(e)&&(this.stream.release(e),this.anchor=this.defaultAnchor)}getBackToDefault(){this.stream.getBackToDefault()}modifyAnchor(e,t,o){const s=this.getters.getActiveSheetId();return e={...e,zone:this.getters.expandZone(s,e.zone)},this.processEvent({options:o,anchor:e,mode:t})}selectZone(e,t={scrollIntoView:!0}){return this.modifyAnchor(e,"overrideSelection",t)}selectCell(e,t){const o=hs({col:e,row:t});return this.selectZone({zone:o,cell:{col:e,row:t}},{scrollIntoView:!0})}moveAnchorCell(e,t=1){if("end"!==t&&t<=0)return new ui("InvalidSelectionStep");const{col:o,row:s}=this.getNextAvailablePosition(e,t);return this.selectCell(o,s)}setAnchorCorner(e,t){const o=this.getters.getActiveSheetId(),{col:s,row:i}=this.anchor.cell,n={left:Math.min(s,e),top:Math.min(i,t),right:Math.max(s,e),bottom:Math.max(i,t)},r={zone:this.getters.expandZone(o,n),cell:{col:s,row:i}};return this.processEvent({mode:"updateAnchor",anchor:r,options:{scrollIntoView:!1}})}addCellToSelection(e,t){const o=this.getters.getActiveSheetId();({col:e,row:t}=this.getters.getMainCellPosition({sheetId:o,col:e,row:t}));const s=this.getters.expandZone(o,hs({col:e,row:t}));return this.processEvent({options:{scrollIntoView:!0},anchor:{zone:s,cell:{col:e,row:t}},mode:"newAnchor"})}resizeAnchorZone(e,t=1){if("end"!==t&&t<=0)return new ui("InvalidSelectionStep");const o=this.getters.getActiveSheetId(),s=this.anchor,{col:i,row:n}=s.cell,{left:r,right:a,top:l,bottom:c}=s.zone,h=this.getStartingPosition(e);let[d,u]=this.deltaToTarget(h,e,t);if(0===d&&0===u)return ui.Success;let g=s.zone;const p=e=>{e=as(e);const{left:t,right:s,top:i,bottom:n}=this.getters.expandZone(o,e);return{left:Math.max(0,t),right:Math.min(this.getters.getNumberCols(o)-1,s),top:Math.max(0,i),bottom:Math.min(this.getters.getNumberRows(o)-1,n)}},{cell:m,zone:f}=this.getReferenceAnchor(),{col:v,row:b}=m;let S=0;for(;null!==g;){if(S++,d<0){const e=this.getNextAvailableCol(d,a-(S-1),b);g=f.right<=a-S?p({top:l,left:r,bottom:c,right:e}):null}if(d>0){const e=this.getNextAvailableCol(d,r+(S-1),b);g=r+S<=f.left?p({top:l,left:e,bottom:c,right:a}):null}if(u<0){const e=this.getNextAvailableRow(u,v,c-(S-1));g=f.bottom<=c-S?p({top:l,left:r,bottom:e,right:a}):null}if(u>0){const e=this.getNextAvailableRow(u,v,l+(S-1));g=l+S<=f.top?p({top:e,left:r,bottom:c,right:a}):null}if(g=g?as(g):g,g&&!Qo(g,s.zone))return this.processEvent({options:{scrollIntoView:!0},mode:"updateAnchor",anchor:{zone:g,cell:{col:i,row:n}}})}g=p(Ko({top:n,bottom:n,left:i,right:i},as({top:this.getNextAvailableRow(u,v,l),left:this.getNextAvailableCol(d,r,b),bottom:this.getNextAvailableRow(u,v,c),right:this.getNextAvailableCol(d,a,b)})));const y={zone:g,cell:{col:i,row:n}};return this.processEvent({anchor:y,mode:"updateAnchor",options:{scrollIntoView:!0}})}selectColumn(e,t){const o=this.getters.getActiveSheetId(),s=this.getters.getNumberRows(o)-1;let i={left:e,right:e,top:0,bottom:s};const n=this.getters.findFirstVisibleColRowIndex(o,"ROW");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=e,a=n;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),i=Ko(i,{left:r,right:r,top:n,bottom:s})}return this.processEvent({options:{scrollIntoView:!1,unbounded:!0},anchor:{zone:i,cell:{col:r,row:a}},mode:t})}selectRow(e,t){const o=this.getters.getActiveSheetId(),s=this.getters.getNumberCols(o)-1;let i={top:e,bottom:e,left:0,right:s};const n=this.getters.findFirstVisibleColRowIndex(o,"COL");let r,a;switch(t){case"overrideSelection":case"newAnchor":r=n,a=e;break;case"updateAnchor":({col:r,row:a}=this.anchor.cell),i=Ko(i,{left:n,right:s,top:a,bottom:a})}return this.processEvent({options:{scrollIntoView:!1,unbounded:!0},anchor:{zone:i,cell:{col:r,row:a}},mode:t})}loopSelection(){const e=this.getters.getActiveSheetId(),t=this.anchor;if(Qo(this.anchor.zone,this.getters.getSheetZone(e)))return this.modifyAnchor({...t,zone:hs(t.cell)},"updateAnchor",{scrollIntoView:!1});const o=this.getters.getContiguousZone(e,t.zone);return ft(o,t.zone)?this.selectAll():this.modifyAnchor({...t,zone:o},"updateAnchor",{scrollIntoView:!1})}selectTableAroundSelection(){const e=this.getters.getActiveSheetId(),t=this.getters.getContiguousZone(e,this.anchor.zone);return this.modifyAnchor({...this.anchor,zone:t},"updateAnchor",{scrollIntoView:!1})}selectAll(){const e=this.getters.getActiveSheetId(),t={left:0,top:0,bottom:this.getters.getNumberRows(e)-1,right:this.getters.getNumberCols(e)-1};return this.processEvent({mode:"overrideSelection",anchor:{zone:t,cell:this.anchor.cell},options:{scrollIntoView:!1}})}isListening(e){return this.stream.isListening(e)}processEvent(e){const t={...e,previousAnchor:ze(this.anchor)},o=this.checkEventAnchorZone(t);return"Success"!==o?new ui(o):(this.anchor=t.anchor,this.stream.send(t),ui.Success)}checkEventAnchorZone(e){return this.checkAnchorZone(e.anchor)}checkAnchorZone(e){const{cell:t,zone:o}=e;if(!ts(t.col,t.row,o))return"InvalidAnchorZone";const{left:s,right:i,top:n,bottom:r}=o,a=this.getters.getActiveSheetId(),l=this.getters.findVisibleHeader(a,"COL",s,i);return void 0===this.getters.findVisibleHeader(a,"ROW",n,r)||void 0===l?"SelectionOutOfBound":"Success"}checkAnchorZoneOrThrow(e){if("InvalidAnchorZone"===this.checkAnchorZone(e))throw new Error(Uo("The provided anchor is invalid. The cell must be part of the zone."))}getNextAvailablePosition(e,t=1){const{col:o,row:s}=this.anchor.cell,i=this.deltaToTarget({col:o,row:s},e,t);return{col:this.getNextAvailableCol(i[0],o,s),row:this.getNextAvailableRow(i[1],o,s)}}getNextAvailableCol(e,t,o){const s=this.getters.getActiveSheetId(),i={col:t,row:o};return this.getNextAvailableHeader(e,"COL",t,i,(e=>this.getters.isInSameMerge(s,t,o,e,o)))}getNextAvailableRow(e,t,o){const s=this.getters.getActiveSheetId(),i={col:t,row:o};return this.getNextAvailableHeader(e,"ROW",o,i,(e=>this.getters.isInSameMerge(s,t,o,t,e)))}getNextAvailableHeader(e,t,o,s,i){const n=this.getters.getActiveSheetId();if(0===e)return o;const r=Math.sign(e);let a=o+e;for(;i(a);)a+=r;for(;this.getters.isHeaderHidden(n,t,a);)a+=r;return a<0||a>this.getters.getNumberHeaders(n,t)-1?this.getters.isHeaderHidden(n,t,o)?this.getNextAvailableHeader(-r,t,o,s,i):o:a}getReferenceAnchor(){const e=this.getters.getActiveSheetId(),t=this.anchor,{left:o,right:s,top:i,bottom:n}=t.zone,{col:r,row:a}=t.cell,l=this.getters.isColHidden(e,r)&&this.getters.findVisibleHeader(e,"COL",o,s)||r,c=this.getters.isRowHidden(e,a)&&this.getters.findVisibleHeader(e,"ROW",i,n)||a;return{cell:{col:l,row:c},zone:this.getters.expandZone(e,{left:l,right:l,top:c,bottom:c})}}deltaToTarget(e,t,o){switch(t){case"up":return"end"!==o?[0,-o]:[0,this.getEndOfCluster(e,"rows",-1)-e.row];case"down":return"end"!==o?[0,o]:[0,this.getEndOfCluster(e,"rows",1)-e.row];case"left":return"end"!==o?[-o,0]:[this.getEndOfCluster(e,"cols",-1)-e.col,0];case"right":return"end"!==o?[o,0]:[this.getEndOfCluster(e,"cols",1)-e.col,0]}}getStartingPosition(e){let{col:t,row:o}=this.getPosition();const s=this.anchor.zone;switch(e){case"down":case"up":o=o===s.top?s.bottom:s.top;break;case"left":case"right":t=t===s.right?s.left:s.right}return{col:t,row:o}}getEndOfCluster(e,t,o){const s=this.getters.getActiveSheetId();let i=e;const n=this.getNextCellPosition(e,t,o);let r=this.isCellSkippableInCluster({...i,sheetId:s})||this.isCellSkippableInCluster({...n,sheetId:s})?"nextCluster":"endOfCluster";for(;;){const e=this.getNextCellPosition(i,t,o);if(i.col===e.col&&i.row===e.row)break;const n=this.isCellSkippableInCluster({...e,sheetId:s});if("endOfCluster"===r&&n)break;if("nextCluster"===r&&!n){i=e;break}i=e}return"cols"===t?i.col:i.row}getNextCellPosition(e,t,o){const s={...e};return s["cols"===t?"col":"row"]="cols"===t?this.getNextAvailableCol(o,s.col,s.row):this.getNextAvailableRow(o,s.col,s.row),{col:s.col,row:s.row}}getPosition(){return{...this.anchor.cell}}isCellSkippableInCluster(e){const t=this.getters.getMainCellPosition(e),o=this.getters.getEvaluatedCell(t);return o.type===oi.empty||o.type===oi.text&&""===o.value}}function $k(e){if("string"==typeof e)return{};if("number"==typeof e)return[];throw new Error("Cannot create new node")}class Gk{changes;commands=[];recordChanges(e){return this.changes=[],this.commands=[],e(),{changes:this.changes,commands:this.commands}}addCommand(e){this.commands.push(e)}addChange(...e){const t=e.pop();let o=e[0],s=e.at(-1);const i=e.length-2;for(let t=1;t<=i;t++){const s=e[t];if(void 0===o[s]){const i=e[t+1];o[s]=$k(i)}o=o[s]}o[s]!==t&&(this.changes?.push({key:s,target:o,before:o[s]}),void 0===t?delete o[s]:o[s]=t)}}const Wk=17781237,qk=17781238,Zk=88853993,jk=88853994;function Yk(e,t,o){const s=[["xmlns:r",Ny],["xmlns:a",Dy],["xmlns:c",Oy]],i=Xk({backgroundColor:e.data.backgroundColor,line:{color:"000000"}});let n=nx``;if(e.data.title?.text){const t=Cy(Sh(e.data.backgroundColor)),o=e.data.title.fontSize??X;n=nx`
2553
2553
  <c:title>
2554
2554
  ${Jk(e.data.title.text,t,o,e.data.title)}
2555
2555
  <c:overlay val="0" />
@@ -3286,4 +3286,4 @@
3286
3286
  <tableParts count="${e.tables.length}">
3287
3287
  ${ix(a)}
3288
3288
  </tableParts>
3289
- `}var GV;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(GV||(GV={}));function WV(e,t={}){const o=ze(t);return o.type=e,o}const qV={},ZV={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:ee,HEADER_WIDTH:te,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:oe,DEFAULT_CELL_HEIGHT:se,SCROLLBAR_WIDTH:ie},jV={autoCompleteProviders:Jh,autofillModifiersRegistry:KS,autofillRulesRegistry:JS,cellMenuRegistry:AA,colMenuRegistry:bD,errorTypes:xi,linkMenuRegistry:OR,functionRegistry:vS,featurePluginRegistry:tk,iconsOnCellRegistry:qy,statefulUIPluginRegistry:ok,coreViewsPluginRegistry:sk,corePluginRegistry:ek,rowMenuRegistry:wD,sidePanelRegistry:SM,figureRegistry:jE,chartSidePanelComponentRegistry:PO,chartComponentRegistry:BE,chartRegistry:UE,chartSubtypeRegistry:$E,topbarMenuRegistry:ID,topbarComponentRegistry:yM,clickableCellRegistry:ik,otRegistry:ED,inverseCommandRegistry:JE,urlRegistry:Cn,cellPopoverRegistry:ny,numberFormatMenuRegistry:SD,repeatLocalCommandTransformRegistry:YN,repeatCommandTransformRegistry:jN,clipboardHandlersRegistries:Pc,pivotRegistry:WF,pivotTimeAdapterRegistry:Xl,pivotSidePanelRegistry:YF,pivotNormalizationValueRegistry:Tc,supportedPivotPositionalFormulaRegistry:XS,pivotToFunctionValueRegistry:Ac,migrationStepRegistry:Tx,chartJsExtensionRegistry:nh},YV={arg:od,isEvaluationError:Pi,toBoolean:Zi,toJsDate:ji,toNumber:ki,toString:Gi,toNormalizedPivotValue:xc,toXC:Ao,toZone:$o,toUnboundedZone:zo,toCartesian:To,numberToLetters:vo,lettersToNumber:bo,UuidGenerator:xa,formatValue:Kn,createCurrencyFormat:dr,ColorGenerator:uo,computeTextWidth:ha,createEmptyWorkbookData:Nx,createEmptySheet:Px,createEmptyExcelSheet:kx,rgbaToHex:Zt,colorToRGBA:jt,positionToZone:hs,isDefined:lt,isMatrix:bi,lazy:gt,genericRepeat:XN,createAction:i,createActions:o,transformRangeData:kc,deepEquals:ft,overlap:es,union:Ko,isInside:ts,deepCopy:ze,expandZoneOnInsertion:Zo,reduceZoneOnDeletion:Xo,unquote:Ge,getMaxObjectId:mc,getFunctionsFromTokens:zS,getFirstPivotFunction:jS,getNumberOfPivotFunctions:YS,parseDimension:bc,isDateOrDatetimeField:Sc,makeFieldProposal:GS,insertTokenAfterArgSeparator:WS,insertTokenAfterLeftParenthesis:qS,mergeContiguousZones:ms,getPivotHighlights:xD,pivotTimeAdapter:Kl,UNDO_REDO_PIVOT_COMMANDS:CN,createPivotFormula:wc,areDomainArgsFieldsValid:Cc,splitReference:qr,sanitizeSheetName:qe,getUniqueText:kt,isNumber:Js,isDateTime:Ns},XV={isMarkdownLink:et,parseMarkdownLink:st,markdownLink:ot,openLink:Rn,urlRepresentation:En},KV={Checkbox:fR,Section:RD,RoundColorPicker:tO,ChartDataSeries:HD,ChartErrorSection:BD,ChartLabelRange:zD,ChartTitle:QD,ChartPanel:VO,ChartFigure:WE,ChartJsComponent:kh,Grid:IP,GridOverlay:eP,ScorecardChart:Kh,LineConfigPanel:AO,BarConfigPanel:GD,PieChartDesignPanel:_O,GenericChartConfigPanel:$D,ChartWithAxisDesignPanel:aO,GaugeChartConfigPanel:cO,GaugeChartDesignPanel:xO,ScorecardChartConfigPanel:OO,ScorecardChartDesignPanel:FO,RadarChartDesignPanel:DO,WaterfallChartDesignPanel:MO,ComboChartDesignPanel:lO,ChartTypePicker:NO,FigureComponent:CM,Menu:WR,Popover:hR,SelectionInput:LD,ValidationMessages:UD,AddDimensionButton:yF,PivotDimensionGranularity:IF,PivotDimensionOrder:EF,PivotDimension:xF,PivotLayoutConfigurator:AF,PivotHTMLRenderer:EP,PivotDeferUpdate:SF,PivotTitleSection:_F,CogWheelMenu:wF,TextInput:CF,SidePanelCollapsible:qD,RadioSelection:iO},JV={useDragAndDropListItems:_D,useHighlights:BO,useHighlightsOnHover:UO},QV={useStoreProvider:Bc,DependencyContainer:Lc,CellPopoverStore:iR,ComposerFocusStore:Jc,CellComposerStore:FM,FindAndReplaceStore:gF,HighlightStore:xS,HoveredCellStore:sR,ModelStore:Zc,NotificationStore:IS,RendererStore:Yc,SelectionInputStore:VD,SpreadsheetStore:Xc,useStore:zc,useLocalStore:$c,SidePanelStore:yP,PivotSidePanelStore:ZF,PivotMeasureDisplayPanelStore:vF};const eL={DEFAULT_LOCALE:fi,HIGHLIGHT_COLOR:a,PIVOT_TABLE_CONFIG:Ve,ChartTerms:$x},tL={...QR,...vE};e.AbstractCellClipboardHandler=Oa,e.AbstractChart=Vh,e.AbstractFigureClipboardHandler=Mc,e.CellErrorType=wi,e.CorePlugin=TP,e.CoreViewPlugin=NP,e.DispatchResult=ui,e.EvaluationError=Ii,e.Model=class extends Vc{corePlugins=[];statefulUIPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;coreViewPluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},o={},s=[],i=new xa,n=!1){const r=performance.now();console.debug("##### Model creation #####"),super(),Vo===No&&Lo===ko&&(Lo=()=>!0),s=Fx(e,s);const a=Ox(e,n);this.state=new Gk,this.uuidGenerator=i,this.config=this.setupConfig(o),this.session=this.setupSession(a.revisionId),this.coreGetters={},this.range=new MP(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.coreGetters.adaptFormulaStringDependencies=this.range.adaptFormulaStringDependencies.bind(this.range),this.coreGetters.copyFormulaStringForSheet=this.range.copyFormulaStringForSheet.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode},this.selection=new zk(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.coreViewPluginConfig=this.setupCoreViewPluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of ek.getAll())this.setupCorePlugin(e,a);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(s);for(let e of sk.getAll()){const t=this.setupCoreViewPlugin(e);this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of ok.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of tk.getAll()){const t=this.setupUiPlugin(e);this.handlers.push(t),this.uiHandlers.push(t)}if(this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.joinSession(),o.snapshotRequested||e["[Content_Types].xml"]&&!this.getters.isReadonly()){const e=performance.now();console.debug("Snapshot requested"),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.debug("Snapshot taken in",performance.now()-e,"ms")}t.markRaw(this),console.debug("Model created in",performance.now()-r,"ms"),console.debug("######")}joinSession(){this.session.join(this.config.client)}async leaveSession(){const e=this.getters.isReadonly()?void 0:gt((()=>this.exportData()));await this.session.leave(e)}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}for(const o of e.layers)this.renderers[o]||(this.renderers[o]=[]),this.renderers[o].push(t);return t}setupCoreViewPlugin(e){const t=new e(this.coreViewPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}return t}setupCorePlugin(e,t){const o=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in o))throw new Error(`Invalid getter name: ${t} for plugin ${o.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=o[t].bind(o)}o.import(t),this.corePlugins.push(o),this.coreHandlers.push(o),this.handlers.push(o)}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new VN(Hk({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{this.checkDispatchAllowed(e).isSuccessful?(this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1):this.dispatchToHandlers(this.coreHandlers,{type:"UNDO",commands:[e]})}}),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-undone",this,(({commands:e})=>{this.dispatchFromCorePlugin("UNDO",{commands:e}),this.finalize()})),this.session.on("revision-redone",this,(({commands:e})=>{this.dispatchFromCorePlugin("REDO",{commands:e}),this.finalize()})),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.smallUuid(),name:Uo("Anonymous").toString()},o=e.transportService||new Ok;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:o,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),raiseBlockingErrorUI:e=>this.trigger("raise-error-ui",{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){const t=e.loadLocales||(()=>Promise.resolve(mi));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,custom:this.config.custom,external:this.config.external}}setupCoreViewPluginConfig(){return{getters:this.getters,stateObserver:this.state,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}checkDispatchAllowed(e){const t=di(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some((e=>"Success"!==e))?new ui(t.flat()):ui.Success}checkDispatchAllowedCoreCommand(e){const t=this.corePlugins.map((t=>t.allowDispatch(e)));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map((t=>t.allowDispatch(e)))}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0,this.trigger("command-finalized")}canDispatch=(e,t)=>this.checkDispatchAllowed(WV(e,t));dispatch=(e,t)=>{const o=WV(e,t);let s=this.status;if(this.getters.isReadonly()&&(i=o,!ci.has(i.type)))return new ui("Readonly");var i;if(!this.session.canApplyOptimisticUpdate())return new ui("WaitingSessionConfirmation");switch(s){case 0:const t=this.checkDispatchAllowed(o);if(!t.isSuccessful)return this.trigger("update"),t;this.status=1;const{changes:s,commands:i}=this.state.recordChanges((()=>{const t=performance.now();di(o)&&this.state.addCommand(o),this.dispatchToHandlers(this.handlers,o),this.finalize();const s=performance.now()-t;s>5&&console.debug(e,s,"ms")}));this.session.save(o,i,s),this.status=0,this.trigger("update");break;case 1:if(di(o)){const e=this.checkDispatchAllowed(o);if(!e.isSuccessful)return e;this.state.addCommand(o)}this.dispatchToHandlers(this.handlers,o);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(di(o))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,o)}return ui.Success};dispatchFromCorePlugin=(e,t)=>{const o=WV(e,t),s=this.status;this.status=2;const i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,o),this.status=s,ui.Success};dispatchToHandlers(e,t){const o=di(t);for(const s of e)!o&&s instanceof TP||s.beforeHandle(t);for(const s of e)!o&&s instanceof TP||s.handle(t);this.trigger("command-dispatched",t)}drawLayer(e,t){const o=this.renderers[t];if(o)for(const s of o)e.ctx.save(),s.drawLayer(e,t),e.ctx.restore()}exportData(){let e=Nx();for(let t of this.handlers)t instanceof TP&&t.export(e);return e.revisionId=this.session.getRevisionId()||ye,e=ze(e),e}updateMode(e){this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...Nx(),sheets:[kx(Dx,"Sheet1")]};for(let t of this.handlers)t instanceof RP&&t.exportForExcel(e);return e=ze(e),zV(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.PivotRuntimeDefinition=DF,e.Registry=n,e.Revision=NN,e.SPREADSHEET_DIMENSIONS=ZV,e.Spreadsheet=Dk,e.SpreadsheetPivotTable=MF,e.UIPlugin=xN,e.__info__=qV,e.addFunction=function e(t,o){return vS.add(t,o),{addFunction:(t,o)=>e(t,o)}},e.addRenderingLayer=function(e,t){if(yi[e])throw new Error(`Layer ${e} already exists`);yi[e]=t},e.astToFormula=rv,e.chartHelpers=tL,e.compile=VS,e.compileTokens=LS,e.components=KV,e.constants=eL,e.convertAstNodes=ov,e.coreTypes=hi,e.findCellInNewZone=cs,e.functionCache=kS,e.helpers=YV,e.hooks=JV,e.invalidateCFEvaluationCommands=ai,e.invalidateDependenciesCommands=ri,e.invalidateEvaluationCommands=ii,e.iterateAstNodes=sv,e.links=XV,e.load=Ox,e.parse=ev,e.parseTokens=tv,e.readonlyAllowedCommands=ci,e.registries=jV,e.setDefaultSheetViewSize=function(e){Me=e},e.setTranslationMethod=function(e,t=(()=>!0)){Vo=e,Lo=t},e.stores=QV,e.tokenColors=TS,e.tokenize=Pa,qV.version="18.2.19",qV.date="2025-06-23T15:07:13.023Z",qV.hash="430d931"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
3289
+ `}var GV;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(GV||(GV={}));function WV(e,t={}){const o=ze(t);return o.type=e,o}const qV={},ZV={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:ee,HEADER_WIDTH:te,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:oe,DEFAULT_CELL_HEIGHT:se,SCROLLBAR_WIDTH:ie},jV={autoCompleteProviders:Jh,autofillModifiersRegistry:KS,autofillRulesRegistry:JS,cellMenuRegistry:AA,colMenuRegistry:bD,errorTypes:xi,linkMenuRegistry:OR,functionRegistry:vS,featurePluginRegistry:tk,iconsOnCellRegistry:qy,statefulUIPluginRegistry:ok,coreViewsPluginRegistry:sk,corePluginRegistry:ek,rowMenuRegistry:wD,sidePanelRegistry:SM,figureRegistry:jE,chartSidePanelComponentRegistry:PO,chartComponentRegistry:BE,chartRegistry:UE,chartSubtypeRegistry:$E,topbarMenuRegistry:ID,topbarComponentRegistry:yM,clickableCellRegistry:ik,otRegistry:ED,inverseCommandRegistry:JE,urlRegistry:Cn,cellPopoverRegistry:ny,numberFormatMenuRegistry:SD,repeatLocalCommandTransformRegistry:YN,repeatCommandTransformRegistry:jN,clipboardHandlersRegistries:Pc,pivotRegistry:WF,pivotTimeAdapterRegistry:Xl,pivotSidePanelRegistry:YF,pivotNormalizationValueRegistry:Tc,supportedPivotPositionalFormulaRegistry:XS,pivotToFunctionValueRegistry:Ac,migrationStepRegistry:Tx,chartJsExtensionRegistry:nh},YV={arg:od,isEvaluationError:Pi,toBoolean:Zi,toJsDate:ji,toNumber:ki,toString:Gi,toNormalizedPivotValue:xc,toXC:Ao,toZone:$o,toUnboundedZone:zo,toCartesian:To,numberToLetters:vo,lettersToNumber:bo,UuidGenerator:xa,formatValue:Kn,createCurrencyFormat:dr,ColorGenerator:uo,computeTextWidth:ha,createEmptyWorkbookData:Nx,createEmptySheet:Px,createEmptyExcelSheet:kx,rgbaToHex:Zt,colorToRGBA:jt,positionToZone:hs,isDefined:lt,isMatrix:bi,lazy:gt,genericRepeat:XN,createAction:i,createActions:o,transformRangeData:kc,deepEquals:ft,overlap:es,union:Ko,isInside:ts,deepCopy:ze,expandZoneOnInsertion:Zo,reduceZoneOnDeletion:Xo,unquote:Ge,getMaxObjectId:mc,getFunctionsFromTokens:zS,getFirstPivotFunction:jS,getNumberOfPivotFunctions:YS,parseDimension:bc,isDateOrDatetimeField:Sc,makeFieldProposal:GS,insertTokenAfterArgSeparator:WS,insertTokenAfterLeftParenthesis:qS,mergeContiguousZones:ms,getPivotHighlights:xD,pivotTimeAdapter:Kl,UNDO_REDO_PIVOT_COMMANDS:CN,createPivotFormula:wc,areDomainArgsFieldsValid:Cc,splitReference:qr,sanitizeSheetName:qe,getUniqueText:kt,isNumber:Js,isDateTime:Ns},XV={isMarkdownLink:et,parseMarkdownLink:st,markdownLink:ot,openLink:Rn,urlRepresentation:En},KV={Checkbox:fR,Section:RD,RoundColorPicker:tO,ChartDataSeries:HD,ChartErrorSection:BD,ChartLabelRange:zD,ChartTitle:QD,ChartPanel:VO,ChartFigure:WE,ChartJsComponent:kh,Grid:IP,GridOverlay:eP,ScorecardChart:Kh,LineConfigPanel:AO,BarConfigPanel:GD,PieChartDesignPanel:_O,GenericChartConfigPanel:$D,ChartWithAxisDesignPanel:aO,GaugeChartConfigPanel:cO,GaugeChartDesignPanel:xO,ScorecardChartConfigPanel:OO,ScorecardChartDesignPanel:FO,RadarChartDesignPanel:DO,WaterfallChartDesignPanel:MO,ComboChartDesignPanel:lO,ChartTypePicker:NO,FigureComponent:CM,Menu:WR,Popover:hR,SelectionInput:LD,ValidationMessages:UD,AddDimensionButton:yF,PivotDimensionGranularity:IF,PivotDimensionOrder:EF,PivotDimension:xF,PivotLayoutConfigurator:AF,PivotHTMLRenderer:EP,PivotDeferUpdate:SF,PivotTitleSection:_F,CogWheelMenu:wF,TextInput:CF,SidePanelCollapsible:qD,RadioSelection:iO},JV={useDragAndDropListItems:_D,useHighlights:BO,useHighlightsOnHover:UO},QV={useStoreProvider:Bc,DependencyContainer:Lc,CellPopoverStore:iR,ComposerFocusStore:Jc,CellComposerStore:FM,FindAndReplaceStore:gF,HighlightStore:xS,HoveredCellStore:sR,ModelStore:Zc,NotificationStore:IS,RendererStore:Yc,SelectionInputStore:VD,SpreadsheetStore:Xc,useStore:zc,useLocalStore:$c,SidePanelStore:yP,PivotSidePanelStore:ZF,PivotMeasureDisplayPanelStore:vF};const eL={DEFAULT_LOCALE:fi,HIGHLIGHT_COLOR:a,PIVOT_TABLE_CONFIG:Ve,ChartTerms:$x},tL={...QR,...vE};e.AbstractCellClipboardHandler=Oa,e.AbstractChart=Vh,e.AbstractFigureClipboardHandler=Mc,e.CellErrorType=wi,e.CorePlugin=TP,e.CoreViewPlugin=NP,e.DispatchResult=ui,e.EvaluationError=Ii,e.Model=class extends Vc{corePlugins=[];statefulUIPlugins=[];range;session;isReplayingCommand=!1;renderers={};status=0;config;corePluginConfig;coreViewPluginConfig;uiPluginConfig;state;selection;getters;coreGetters;uuidGenerator;handlers=[];uiHandlers=[];coreHandlers=[];constructor(e={},o={},s=[],i=new xa,n=!1){const r=performance.now();console.debug("##### Model creation #####"),super(),Vo===No&&Lo===ko&&(Lo=()=>!0),s=Fx(e,s);const a=Ox(e,n);this.state=new Gk,this.uuidGenerator=i,this.config=this.setupConfig(o),this.session=this.setupSession(a.revisionId),this.coreGetters={},this.range=new MP(this.coreGetters),this.coreGetters.getRangeString=this.range.getRangeString.bind(this.range),this.coreGetters.getRangeFromSheetXC=this.range.getRangeFromSheetXC.bind(this.range),this.coreGetters.createAdaptedRanges=this.range.createAdaptedRanges.bind(this.range),this.coreGetters.getRangeDataFromXc=this.range.getRangeDataFromXc.bind(this.range),this.coreGetters.getRangeDataFromZone=this.range.getRangeDataFromZone.bind(this.range),this.coreGetters.getRangeFromRangeData=this.range.getRangeFromRangeData.bind(this.range),this.coreGetters.getRangeFromZone=this.range.getRangeFromZone.bind(this.range),this.coreGetters.recomputeRanges=this.range.recomputeRanges.bind(this.range),this.coreGetters.isRangeValid=this.range.isRangeValid.bind(this.range),this.coreGetters.extendRange=this.range.extendRange.bind(this.range),this.coreGetters.getRangesUnion=this.range.getRangesUnion.bind(this.range),this.coreGetters.removeRangesSheetPrefix=this.range.removeRangesSheetPrefix.bind(this.range),this.coreGetters.adaptFormulaStringDependencies=this.range.adaptFormulaStringDependencies.bind(this.range),this.coreGetters.copyFormulaStringForSheet=this.range.copyFormulaStringForSheet.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode},this.selection=new zk(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.coreViewPluginConfig=this.setupCoreViewPluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of ek.getAll())this.setupCorePlugin(e,a);Object.assign(this.getters,this.coreGetters),this.session.loadInitialMessages(s);for(let e of sk.getAll()){const t=this.setupCoreViewPlugin(e);this.handlers.push(t),this.uiHandlers.push(t),this.coreHandlers.push(t)}for(let e of ok.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t),this.uiHandlers.push(t)}for(let e of tk.getAll()){const t=this.setupUiPlugin(e);this.handlers.push(t),this.uiHandlers.push(t)}if(this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.joinSession(),o.snapshotRequested||e["[Content_Types].xml"]&&!this.getters.isReadonly()){const e=performance.now();console.debug("Snapshot requested"),this.session.snapshot(this.exportData()),this.garbageCollectExternalResources(),console.debug("Snapshot taken in",performance.now()-e,"ms")}t.markRaw(this),console.debug("Model created in",performance.now()-r,"ms"),console.debug("######")}joinSession(){this.session.join(this.config.client)}async leaveSession(){const e=this.getters.isReadonly()?void 0:gt((()=>this.exportData()));await this.session.leave(e)}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}for(const o of e.layers)this.renderers[o]||(this.renderers[o]=[]),this.renderers[o].push(t);return t}setupCoreViewPlugin(e){const t=new e(this.coreViewPluginConfig);for(let o of e.getters){if(!(o in t))throw new Error(`Invalid getter name: ${o} for plugin ${t.constructor}`);if(o in this.getters)throw new Error(`Getter "${o}" is already defined.`);this.getters[o]=t[o].bind(t)}return t}setupCorePlugin(e,t){const o=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in o))throw new Error(`Invalid getter name: ${t} for plugin ${o.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=o[t].bind(o)}o.import(t),this.corePlugins.push(o),this.coreHandlers.push(o),this.handlers.push(o)}onRemoteRevisionReceived({commands:e}){for(let t of e){const e=this.status;this.status=2,this.dispatchToHandlers(this.statefulUIPlugins,t),this.status=e}this.finalize()}setupSession(e){return new VN(Hk({initialRevisionId:e,recordChanges:this.state.recordChanges.bind(this.state),dispatch:e=>{this.checkDispatchAllowed(e).isSuccessful?(this.isReplayingCommand=!0,this.dispatchToHandlers(this.coreHandlers,e),this.isReplayingCommand=!1):this.dispatchToHandlers(this.coreHandlers,{type:"UNDO",commands:[e]})}}),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-undone",this,(({commands:e})=>{this.dispatchFromCorePlugin("UNDO",{commands:e}),this.finalize()})),this.session.on("revision-redone",this,(({commands:e})=>{this.dispatchFromCorePlugin("REDO",{commands:e}),this.finalize()})),this.session.on("unexpected-revision-id",this,(()=>this.trigger("unexpected-revision-id"))),this.session.on("collaborative-event-received",this,(()=>{this.trigger("update")}))}setupConfig(e){const t=e.client||{id:this.uuidGenerator.smallUuid(),name:Uo("Anonymous").toString()},o=e.transportService||new Ok;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:this.setupExternalConfig(e.external||{}),transportService:o,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),raiseBlockingErrorUI:e=>this.trigger("raise-error-ui",{text:e}),customColors:e.customColors||[]}}setupExternalConfig(e){const t=e.loadLocales||(()=>Promise.resolve(mi));return{...e,loadLocales:t}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,canDispatch:this.canDispatch,custom:this.config.custom,external:this.config.external}}setupCoreViewPluginConfig(){return{getters:this.getters,stateObserver:this.state,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,canDispatch:this.canDispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,session:this.session,defaultCurrency:this.config.defaultCurrency,customColors:this.config.customColors||[],external:this.config.external}}checkDispatchAllowed(e){const t=di(e)?this.checkDispatchAllowedCoreCommand(e):this.checkDispatchAllowedLocalCommand(e);return t.some((e=>"Success"!==e))?new ui(t.flat()):ui.Success}checkDispatchAllowedCoreCommand(e){const t=this.corePlugins.map((t=>t.allowDispatch(e)));return t.push(this.range.allowDispatch(e)),t}checkDispatchAllowedLocalCommand(e){return this.uiHandlers.map((t=>t.allowDispatch(e)))}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0,this.trigger("command-finalized")}canDispatch=(e,t)=>this.checkDispatchAllowed(WV(e,t));dispatch=(e,t)=>{const o=WV(e,t);let s=this.status;if(this.getters.isReadonly()&&(i=o,!ci.has(i.type)))return new ui("Readonly");var i;if(!this.session.canApplyOptimisticUpdate())return new ui("WaitingSessionConfirmation");switch(s){case 0:const t=this.checkDispatchAllowed(o);if(!t.isSuccessful)return this.trigger("update"),t;this.status=1;const{changes:s,commands:i}=this.state.recordChanges((()=>{const t=performance.now();di(o)&&this.state.addCommand(o),this.dispatchToHandlers(this.handlers,o),this.finalize();const s=performance.now()-t;s>5&&console.debug(e,s,"ms")}));this.session.save(o,i,s),this.status=0,this.trigger("update");break;case 1:if(di(o)){const e=this.checkDispatchAllowed(o);if(!e.isSuccessful)return e;this.state.addCommand(o)}this.dispatchToHandlers(this.handlers,o);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(di(o))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,o)}return ui.Success};dispatchFromCorePlugin=(e,t)=>{const o=WV(e,t),s=this.status;this.status=2;const i=this.isReplayingCommand?this.coreHandlers:this.handlers;return this.dispatchToHandlers(i,o),this.status=s,ui.Success};dispatchToHandlers(e,t){const o=di(t);for(const s of e)!o&&s instanceof TP||s.beforeHandle(t);for(const s of e)!o&&s instanceof TP||s.handle(t);this.trigger("command-dispatched",t)}drawLayer(e,t){const o=this.renderers[t];if(o)for(const s of o)e.ctx.save(),s.drawLayer(e,t),e.ctx.restore()}exportData(){let e=Nx();for(let t of this.handlers)t instanceof TP&&t.export(e);return e.revisionId=this.session.getRevisionId()||ye,e=ze(e),e}updateMode(e){this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...Nx(),sheets:[kx(Dx,"Sheet1")]};for(let t of this.handlers)t instanceof RP&&t.exportForExcel(e);return e=ze(e),zV(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.PivotRuntimeDefinition=DF,e.Registry=n,e.Revision=NN,e.SPREADSHEET_DIMENSIONS=ZV,e.Spreadsheet=Dk,e.SpreadsheetPivotTable=MF,e.UIPlugin=xN,e.__info__=qV,e.addFunction=function e(t,o){return vS.add(t,o),{addFunction:(t,o)=>e(t,o)}},e.addRenderingLayer=function(e,t){if(yi[e])throw new Error(`Layer ${e} already exists`);yi[e]=t},e.astToFormula=rv,e.chartHelpers=tL,e.compile=VS,e.compileTokens=LS,e.components=KV,e.constants=eL,e.convertAstNodes=ov,e.coreTypes=hi,e.findCellInNewZone=cs,e.functionCache=kS,e.helpers=YV,e.hooks=JV,e.invalidateCFEvaluationCommands=ai,e.invalidateDependenciesCommands=ri,e.invalidateEvaluationCommands=ii,e.iterateAstNodes=sv,e.links=XV,e.load=Ox,e.parse=ev,e.parseTokens=tv,e.readonlyAllowedCommands=ci,e.registries=jV,e.setDefaultSheetViewSize=function(e){Me=e},e.setTranslationMethod=function(e,t=(()=>!0)){Vo=e,Lo=t},e.stores=QV,e.tokenColors=TS,e.tokenize=Pa,qV.version="18.2.20",qV.date="2025-06-27T09:11:55.800Z",qV.hash="16dfc38"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);