@odoo/o-spreadsheet 16.2.20 → 16.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/o-spreadsheet.cjs.js +19 -18
- package/dist/o-spreadsheet.d.ts +7 -9
- package/dist/o-spreadsheet.esm.js +19 -18
- package/dist/o-spreadsheet.iife.js +19 -18
- package/dist/o-spreadsheet.iife.min.js +3 -3
- package/dist/o_spreadsheet.xml +3531 -0
- package/package.json +3 -2
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
-
`;class ns extends t.Component{constructor(){super(...arguments),this.menuItems=os.getMenuItems(),this.link=t.useState(this.defaultState),this.menu=t.useState({isOpen:!1}),this.linkEditorRef=t.useRef("linkEditor"),this.position=$n(this.linkEditorRef),this.urlInput=t.useRef("urlInput")}setup(){t.onMounted((()=>{var e;return null===(e=this.urlInput.el)||void 0===e?void 0:e.focus()}))}get defaultState(){const{col:e,row:t}=this.props.cellPosition,i=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getEvaluatedCell({sheetId:i,col:e,row:t});return o.link?{url:o.link.url,label:o.formattedValue,isUrlEditable:o.link.isUrlEditable}:{label:o.formattedValue,url:"",isUrlEditable:!0}}get menuPosition(){return{x:this.position.x+320-12-2,y:this.position.y+100}}onSpecialLink(e){const{detail:t}=e,i=_o(t);i&&(this.link.url=i.url,this.link.label=i.label,this.link.isUrlEditable=i.isUrlEditable)}getUrlRepresentation(e){return Oo(e,this.env.model.getters)}openMenu(){this.menu.isOpen=!0}removeLink(){this.link.url="",this.link.isUrlEditable=!0}save(){var e,t;const{col:i,row:o}=this.props.cellPosition,n=this.link.label||this.link.url;this.env.model.dispatch("UPDATE_CELL",{col:i,row:o,sheetId:this.env.model.getters.getActiveSheetId(),content:Ke(n,this.link.url)}),null===(t=(e=this.props).onClosed)||void 0===t||t.call(e)}cancel(){var e,t;null===(t=(e=this.props).onClosed)||void 0===t||t.call(e)}onKeyDown(e){switch(e.key){case"Enter":this.link.url&&this.save(),e.stopPropagation();break;case"Escape":this.cancel(),e.stopPropagation()}}}ns.template="o-spreadsheet-LinkEditor",ns.components={Menu:Yn};const ss={onOpen:(e,t)=>({isOpen:!0,props:{cellPosition:e},Component:ns,cellCorner:"BottomLeft"})};ns.props={cellPosition:Object,onClosed:{type:Function,optional:!0}};const rs=new xo;function as(e){return 8===(e=wt(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}rs.add("ErrorToolTip",Fn).add("LinkCell",Qn).add("LinkEditor",ss).add("FilterMenu",Pn);class ls{constructor(e,t,i){this.title=e.title,this.sheetId=t,this.getters=i}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 cs(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?qi(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?$i(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function hs(e,t,i,o){let n=!1;const s=[];for(let o in i){let r=i[o];if(r.labelCell){const e=gs(r.labelCell,t);r.labelCell!==e&&(n=!0,r={...r,labelCell:e})}const a=gs(r.dataRange,t);void 0===a||e.getRangeString(a,a.sheetId)===K?(n=!0,r=void 0):a!==r.dataRange&&(n=!0,r={...r,dataRange:a}),s[o]=r}let r=o;const a=gs(r,t);a!==r&&(n=!0,r=a);return{isStale:n,dataSets:s.filter(ot),labelRange:r}}function ds(e,t,i){return i.map((i=>({dataRange:Di(e,t,i.dataRange),labelCell:i.labelCell?Di(e,t,i.labelCell):void 0})))}function us(e,t,i){return i?Di(e,t,i):void 0}function gs(e,t){if(!e)return;const i=t(e);switch(i.changeType){case"NONE":return e;case"REMOVE":return;default:return i.range}}function ps(e,t,i,o){const n=[];for(const s of t){const t=e.getRangeFromSheetXC(i,s),{unboundedZone:r,sheetId:a,invalidSheetName:l}=t;if(!l)if(r.left!==r.right&&r.top!==r.bottom){if(void 0===r.right)continue;for(let t=r.left;t<=r.right;t++){const i={...r,left:t,right:t};n.push(ms(e,a,i,o?{top:i.top,bottom:i.top,left:i.left,right:i.left}:void 0))}}else r.left===r.right&&r.top===r.bottom?o||n.push(ms(e,a,r,void 0)):n.push(ms(e,a,r,o?{top:r.top,bottom:r.top,left:r.left,right:r.left}:void 0))}return n}function ms(e,t,i,o){if(i.left!==i.right&&i.top!==i.bottom)throw new Error(`Zone should be a single column or row: ${Hi(i)}`);if(o){const n=Hi(i),s=Hi(o);return{labelCell:e.getRangeFromSheetXC(t,s),dataRange:e.getRangeFromSheetXC(t,n)}}return{labelCell:void 0,dataRange:e.getRangeFromSheetXC(t,Hi(i))}}function fs(e,t){var i;const o=null===(i=t.labelCell)||void 0===i?void 0:i.zone;let n=t.dataRange.zone;if(o){const{numberOfRows:e,numberOfCols:t}=to(n);1===e?n={...n,left:n.left+1}:1===t&&(n={...n,top:n.top+1})}const s=t.dataRange.clone({zone:n});return{label:t.labelCell?e.getRangeString(t.labelCell,"forceSheetReference"):void 0,range:e.getRangeString(s,"forceSheetReference")}}function vs(e,t){let i;if(e.labelRange){const o=cs(Vi(e.labelRange),t);i=o?Hi(o):void 0}const o=e.dataSets.map(Vi).map((e=>cs(e,t))).filter(ot).map(Hi);return{...e,labelRange:i,dataSets:o}}const bs=["rgb(31,119,180)","rgb(255,127,14)","rgb(174,199,232)","rgb(255,187,120)","rgb(44,160,44)","rgb(152,223,138)","rgb(214,39,40)","rgb(255,152,150)","rgb(148,103,189)","rgb(197,176,213)","rgb(140,86,75)","rgb(196,156,148)","rgb(227,119,194)","rgb(247,182,210)","rgb(127,127,127)","rgb(199,199,199)","rgb(188,189,34)","rgb(219,219,141)","rgb(23,190,207)","rgb(158,218,229)"];class Ss{constructor(){this.graphColorIndex=0}next(){return bs[this.graphColorIndex++%bs.length]}}function Cs(e){return e&&Rt(e)<.3?"#FFFFFF":"#000000"}function Es(e){if(e.dataSets){const t=void 0!==e.dataSets.find((e=>!Lt.test(e)));if(t)return 32;if(e.dataSets.map(Vi).some((e=>e.top!==e.bottom&&lo(e))))return 32}return 0}function ws(e){if(e.labelRange){if(!Lt.test(e.labelRange||""))return 33}return 0}function ys(e,t,i){if(e){if("text"===i||(null==t?void 0:t.type)!==rn.number||e.type!==rn.number)return e.formattedValue;{let o=t.value-e.value;if("percentage"===i&&0!==o&&(o=o/e.value*100),"percentage"!==i&&e.format)return pi(o,e.format);const n=Math.abs(parseFloat(o.toFixed(2))).toLocaleString();return"percentage"===i?n+"%":n}}return""}function xs(e,t,i,o,n){if("text"===t||(null==e?void 0:e.type)!==rn.number||(null==i?void 0:i.type)!==rn.number)return;const s=i.value-e.value;return s>0?o:s<0?n:void 0}function Is(e,t,i){if("text"===i||(null==e?void 0:e.type)!==rn.number||(null==t?void 0:t.type)!==rn.number)return"neutral";const o=t.value-e.value;return o>0?"up":o<0?"down":"neutral"}const Rs={Errors:{25:s("The range is invalid"),51:s("The argument is missing. Please provide a value"),52:s("The second argument is missing. Please provide a value"),53:s("The minpoint must be a number"),54:s("The midpoint must be a number"),55:s("The maxpoint must be a number"),56:s("The first value must be a number"),57:s("The second value must be a number"),47:s("Minimum must be smaller then Maximum"),50:s("Minimum must be smaller then Midpoint"),49:s("Midpoint must be smaller then Maximum"),48:s("Lower inflection point must be smaller than upper inflection point"),58:s("Invalid Minpoint formula"),60:s("Invalid Maxpoint formula"),59:s("Invalid Midpoint formula"),61:s("Invalid upper inflection point formula"),62:s("Invalid lower inflection point formula"),24:s("A range needs to be defined"),Unexpected:s("The rule is invalid for an unknown reason")},ColorScale:s("Color scale"),IconSet:s("Icon set")},Ts={IsEmpty:s("Is empty"),IsNotEmpty:s("Is not empty"),ContainsText:s("Contains"),NotContains:s("Does not contain"),BeginsWith:s("Starts with"),EndsWith:s("Ends with"),Equal:s("Is equal to"),NotEqual:s("Is not equal to"),GreaterThan:s("Is greater than"),GreaterThanOrEqual:s("Is greater than or equal to"),LessThan:s("Is less than"),LessThanOrEqual:s("Is less than or equal to"),Between:s("Is between"),NotBetween:s("Is not between")},As={Series:s("Series"),Errors:{Unexpected:s("The chart definition is invalid for an unknown reason"),32:s("The dataset is invalid"),33:s("Labels are invalid"),34:s("The key value is invalid"),35:s("The baseline value is invalid"),36:s("The data range is invalid"),37:s("A minimum range limit value is needed"),38:s("The minimum range limit value must be a number"),39:s("A maximum range limit value is needed"),40:s("The maximum range limit value must be a number"),41:s("Minimum range limit must be smaller than maximum range limit"),42:s("The lower inflection point value must be a number"),43:s("The upper inflection point value must be a number")}},Ms={Automatic:s("Automatic"),Number:s("Number"),Percent:s("Percent"),Currency:s("Currency"),CurrencyRounded:s("Currency rounded"),Date:s("Date"),Time:s("Time"),DateTime:s("Date time"),Duration:s("Duration"),CustomCurrency:s("Custom currency")},Os={Custom:s("Custom")},Ns=s("Merged cells are preventing this operation. Unmerge those cells and try again.");function _s(e,t){if(t.dataRange){const i=t.labelCell?[Hi(t.labelCell.zone)]:[],o=Ji([Hi(t.dataRange.zone)],i)[0];if(void 0===o)return[];const n=e.getRangeFromSheetXC(t.dataRange.sheetId,o);return e.getRangeValues(n).map((e=>""===e?void 0:e))}return[]}function Fs(e,t){const i=$e(0,Math.max(e.length,...t.map((e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.length)||0})))).filter((i=>{const o=e[i],n=t.map((e=>{var t;return null===(t=e.data)||void 0===t?void 0:t[i]}));return o||n.some((e=>0===e||Boolean(e)))}));return{labels:i.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:i.map((t=>e.data[t]))})))}}function Ds(e,t){const i=new Set(e),o={};i.forEach((e=>{o[e]=new Array(t.length).fill(0)}));for(const i of $e(0,e.length)){const s=e[i];for(const e of $e(0,t.length))o[s][e]+="number"==typeof(n=t[e].data[i])?n:0}var n;return{labels:Object.keys(o),dataSetsValues:t.map(((e,t)=>({...e,data:Object.values(o).map((e=>e[t]))})))}}function ks(e){return e?e.length>J?e.substring(0,J)+"…":e:""}function Ls(e,t,i,o){return{type:e.type,options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:e.title?10:25,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!!e.title,fontSize:22,fontStyle:"normal",text:n(e.title),fontColor:i},legend:{onClick:void 0},tooltips:{callbacks:{label:function(e,t){var i,n,s,r,a;let l=null===(n=null===(i=t.datasets)||void 0===i?void 0:i[e.datasetIndex||0])||void 0===n?void 0:n.label;const c=""!==e.yLabel?e.yLabel:null===(a=null===(r=null===(s=t.datasets)||void 0===s?void 0:s[e.datasetIndex||0])||void 0===r?void 0:r.data)||void 0===a?void 0:a[e.index||0],h=o&&"number"==typeof c?pi(c,o):(null==c?void 0:c.toLocaleString())||"";return l?`${l}: ${h}`:h}}}},data:{labels:t.map(ks),datasets:[]}}}function Ps(e,t,i){let o={values:[],formattedValues:[]};if(i)i.invalidXc||i.invalidSheetName||(o={formattedValues:e.getRangeFormattedValues(i),values:e.getRangeValues(i).map((e=>String(e)))});else if(1===t.length)for(let i=0;i<_s(e,t[0]).length;i++)o.formattedValues.push(""),o.values.push("");else if(t[0]){o={formattedValues:$e(0,_s(e,t[0]).length).map((e=>e.toString())),values:o.formattedValues}}return o}function Us(e,t){for(const i of t){const t=e.getRangeFormats(i.dataRange).find((e=>void 0!==e&&!Ci(e)));if(t)return t}}function Vs(e,t){const i=[];for(const[o,n]of Object.entries(t)){let t;if(n.labelCell){const i=n.labelCell,s=i?e.getEvaluatedCell({sheetId:i.sheetId,col:i.zone.left,row:i.zone.top}):void 0;t=s&&i?ks(s.formattedValue):t=`${As.Series} ${parseInt(o)+1}`}else t=t=`${As.Series} ${parseInt(o)+1}`;let s=n.dataRange?_s(e,n):[];i.push({data:s,label:t})}return i}function zs(e){return 0===e?"origin":e-1}class Bs extends ls{constructor(e,t,i){super(e,t,i),this.type="bar",this.dataSets=ps(i,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(i,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.stacked=e.stacked,this.aggregated=e.aggregated}static transformDefinition(e,t){return vs(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,stacked:!1,aggregated:!1,legendPosition:"top",title:e.title||"",type:"bar",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0}}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new Bs(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Bs(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,i){return{type:"bar",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,stacked:this.stacked,aggregated:this.aggregated}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),dataSets:e}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new Bs(n,this.sheetId,this.getters)}}function Hs(e){return e.dataRange&&!Lt.test(e.dataRange)?36:0}function $s(e,t){return t((t=>t.sectionRule?e(t.sectionRule.rangeMin,"rangeMin"):0),(t=>t.sectionRule?e(t.sectionRule.rangeMax,"rangeMax"):0))}function Ws(e){return e.sectionRule&&Number(e.sectionRule.rangeMin)>=Number(e.sectionRule.rangeMax)?41:0}function Gs(e,t){if(""===e)switch(t){case"rangeMin":return 37;case"rangeMax":return 39}return 0}function qs(e,t){if(isNaN(e))switch(t){case"rangeMin":return 38;case"rangeMax":return 40;case"lowerInflectionPointValue":return 42;case"upperInflectionPointValue":return 43}return 0}class Zs extends ls{constructor(e,t,i){super(e,t,i),this.type="gauge",this.dataRange=ki(this.getters,this.sheetId,e.dataRange),this.sectionRule=e.sectionRule,this.background=e.background}static validateChartDefinition(e,t){return e.checkValidations(t,Hs,e.chainValidations($s(Gs,e.batchValidations),$s(qs,e.batchValidations),Ws),e.chainValidations((i=qs,(0,e.batchValidations)((e=>e.sectionRule?i(e.sectionRule.lowerInflectionPoint.value,"lowerInflectionPointValue"):0),(e=>e.sectionRule?i(e.sectionRule.upperInflectionPoint.value,"upperInflectionPointValue"):0)))));var i}static transformDefinition(e,t){let i;return e.dataRange&&(i=cs(Vi(e.dataRange),t)),{...e,dataRange:i?Hi(i):void 0}}static getDefinitionFromContextCreation(e){return{background:e.background,title:e.title||"",type:"gauge",dataRange:e.range?e.range[0]:void 0,sectionRule:{colors:{lowerColor:"#cc0000",middleColor:"#f1c232",upperColor:"#6aa84f"},rangeMin:"0",rangeMax:"100",lowerInflectionPoint:{type:"percentage",value:"15"},upperInflectionPoint:{type:"percentage",value:"40"}}}}copyForSheetId(e){const t=us(this.sheetId,e,this.dataRange),i=this.getDefinitionWithSpecificRanges(t,e);return new Zs(i,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.dataRange,e);return new Zs(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.dataRange)}getDefinitionWithSpecificRanges(e,t){return{background:this.background,sectionRule:this.sectionRule,title:this.title,type:"gauge",dataRange:e?this.getters.getRangeString(e,t||this.sheetId):void 0}}getDefinitionForExcel(){}getContextCreation(){return{background:this.background,title:this.title,range:this.dataRange?[this.getters.getRangeString(this.dataRange,this.sheetId)]:void 0}}updateRanges(e){const t=gs(this.dataRange,e);if(this.dataRange===t)return this;const i=this.getDefinitionWithSpecificRanges(t);return new Zs(i,this.sheetId,this.getters)}}const js={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,year:31536e6},Xs={inSeconds:function(e){return Math.floor(e/js.second)},inMinutes:function(e){return Math.floor(e/js.minute)},inHours:function(e){return Math.floor(e/js.hour)},inDays:function(e){return Math.floor(e/js.day)},inMonths:function(e){return Math.floor(e/js.month)},inYears:function(e){return Math.floor(e/js.year)}},Ys=/^((d|dd|m|mm|yyyy|yy|hh|h|ss|a)(-|:|\s|\/))*(d|dd|m|mm|yyyy|yy|hh|h|ss|a)$/i;function Ks(e,t){const i=function(e){const t=(e=(e=e.replace(/y/g,"Y")).replace(/d/g,"D")).indexOf("h");e=t>=0?e.slice(0,t).replace(/m/g,"M")+e.slice(t):e.replace(/m/g,"M");e.includes("a")||(e=e.replace(/h/g,"H"));return e}(t),o=function(e,t){const i=e.map((e=>{var t;return null===(t=Ee(e))||void 0===t?void 0:t.jsDate}));if(i.some((e=>void 0===e))||e.length<2)return;const o=i.map((e=>e.getTime())),n=Math.max(...o)-Math.min(...o),s=function(e){if(e.includes("s"))return"second";if(e.includes("m"))return"minute";if(e.includes("h")||e.includes("H"))return"hour";if(e.includes("D"))return"day";if(e.includes("M"))return"month";return"year"}(t);if(js.second>=js[s]&&Xs.inSeconds(n)<180)return"second";if(js.minute>=js[s]&&Xs.inMinutes(n)<180)return"minute";if(js.hour>=js[s]&&Xs.inHours(n)<96)return"hour";if(js.day>=js[s]&&Xs.inDays(n)<90)return"day";if(js.month>=js[s]&&Xs.inMonths(n)<36)return"month";return"year"}(e,i),n={};return o&&(n[o]=i),{parser:i,displayFormats:n,unit:o}}class Qs extends ls{constructor(e,t,i){super(e,t,i),this.type="line",this.dataSets=ps(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(this.getters,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.stacked=e.stacked,this.aggregated=e.aggregated,this.cumulative=e.cumulative}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static transformDefinition(e,t){return vs(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,labelsAsText:!1,legendPosition:"top",title:e.title||"",type:"line",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0,stacked:!1,aggregated:!1,cumulative:!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,i){return{type:"line",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,stacked:this.stacked,aggregated:this.aggregated,cumulative:this.cumulative}}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new Qs(n,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),dataSets:e}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new Qs(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Qs(t,e,this.getters)}}function Js(e,t){return tr(e,t)||ir(e,t)}function er(e,t){return function(e,t){return!e.labelsAsText&&tr(e.labelRange,t)}(e,t)?"time":function(e,t){return!e.labelsAsText&&ir(e.labelRange,t)}(e,t)?"linear":"category"}function tr(e,t){if(!e||!ir(e,t))return!1;const i=t.getEvaluatedCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}).format;return Boolean(i&&Ys.test(i))}function ir(e,t){if(!e)return!1;const i=t.getRangeValues(e);return!i.some((e=>isNaN(Number(e))&&e))&&!i.every((e=>!e))}class or extends ls{constructor(e,t,i){super(e,t,i),this.type="pie",this.dataSets=ps(i,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(i,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated}static transformDefinition(e,t){return vs(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,legendPosition:"top",title:e.title||"",type:"pie",labelRange:e.auxiliaryRange||void 0,aggregated:!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinitionWithSpecificDataSets(e,t,i){return{type:"pie",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,aggregated:this.aggregated}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new or(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new or(t,e,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),verticalAxisPosition:"left",dataSets:e}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new or(n,this.sheetId,this.getters)}}function nr(e,t){const i=[],o=Math.max(...t.map((e=>e.data.length)));for(let t=0;t<=o;t++)i.push(e.next());return i}function sr(e){return e.keyValue&&!Lt.test(e.keyValue)?34:0}function rr(e){return e.baseline&&!Lt.test(e.baseline)?35:0}class ar extends ls{constructor(e,t,i){super(e,t,i),this.type="scorecard",this.keyValue=ki(i,t,e.keyValue),this.baseline=ki(i,t,e.baseline),this.baselineMode=e.baselineMode,this.baselineDescr=e.baselineDescr,this.background=e.background,this.baselineColorUp=e.baselineColorUp,this.baselineColorDown=e.baselineColorDown}static validateChartDefinition(e,t){return e.checkValidations(t,sr,rr)}static getDefinitionFromContextCreation(e){return{background:e.background,type:"scorecard",keyValue:e.range?e.range[0]:void 0,title:e.title||"",baselineMode:te,baselineColorUp:ie,baselineColorDown:oe,baseline:e.auxiliaryRange||""}}static transformDefinition(e,t){let i,o;return e.baseline&&(i=cs(Vi(e.baseline),t)),e.keyValue&&(o=cs(Vi(e.keyValue),t)),{...e,baseline:i?Hi(i):void 0,keyValue:o?Hi(o):void 0}}copyForSheetId(e){const t=us(this.sheetId,e,this.baseline),i=us(this.sheetId,e,this.keyValue),o=this.getDefinitionWithSpecificRanges(t,i,e);return new ar(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue,e);return new ar(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue)}getContextCreation(){return{background:this.background,title:this.title,range:this.keyValue?[this.getters.getRangeString(this.keyValue,this.sheetId)]:void 0,auxiliaryRange:this.baseline?this.getters.getRangeString(this.baseline,this.sheetId):void 0}}getDefinitionWithSpecificRanges(e,t,i){return{baselineColorDown:this.baselineColorDown,baselineColorUp:this.baselineColorUp,baselineMode:this.baselineMode,title:this.title,type:"scorecard",background:this.background,baseline:e?this.getters.getRangeString(e,i||this.sheetId):void 0,baselineDescr:this.baselineDescr,keyValue:t?this.getters.getRangeString(t,i||this.sheetId):void 0}}getDefinitionForExcel(){}updateRanges(e){const t=gs(this.baseline,e),i=gs(this.keyValue,e);if(this.baseline===t&&this.keyValue===i)return this;const o=this.getDefinitionWithSpecificRanges(t,i);return new ar(o,this.sheetId,this.getters)}}const lr=new xo;lr.add("bar",{match:e=>"bar"===e,createChart:(e,t,i)=>new Bs(e,t,i),getChartRuntime:function(e,t){let i=Ps(t,e.dataSets,e.labelRange).formattedValues,o=Vs(t,e.dataSets);({labels:i,dataSetsValues:o}=Fs(i,o)),e.aggregated&&({labels:i,dataSetsValues:o}=Ds(i,o));const n=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2,fontColor:n}}],yAxes:[{position:e.verticalAxisPosition,ticks:{fontColor:n,beginAtZero:!0,callback:e=>i?pi(e,i):(null==e?void 0:e.toLocaleString())||e}}]},e.stacked&&(s.options.scales.xAxes[0].stacked=!0,s.options.scales.yAxes[0].stacked=!0),s}(e,i,Us(t,e.dataSets)),s=new Ss;for(let{label:e,data:t}of o){const i=s.next(),o={label:e,data:t,borderColor:i,backgroundColor:i};n.data.datasets.push(o)}return{chartJsConfig:n,background:e.background||w}},validateChartDefinition:(e,t)=>Bs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Bs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Bs.getDefinitionFromContextCreation(e),name:s("Bar"),sequence:10}),lr.add("line",{match:e=>"line"===e,createChart:(e,t,i)=>new Qs(e,t,i),getChartRuntime:function(e,t){const i=er(e,t),o=Ps(t,e.dataSets,e.labelRange);let n="linear"===i?o.values:o.formattedValues,s=Vs(t,e.dataSets);({labels:n,dataSetsValues:s}=Fs(n,s)),"time"===i&&({labels:n,dataSetsValues:s}=function(e,t){if(0===e.length||e.every((e=>!e)))return{labels:e,dataSetsValues:t};const i=[...e],o=Fe(t);for(let e=0;e<i.length;e++)if(!i[e]){i[e]=lt(i,e);for(let t of o)t.data[e]=void 0}return{labels:i,dataSetsValues:o}}(n,s)),e.aggregated&&({labels:n,dataSetsValues:s}=Ds(n,s));const r=Us(t,e.dataSets),a=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n,generateLabels(e){const{data:t}=e,i=window.Chart.defaults.global.legend.labels.generateLabels(e);for(const[e,o]of i.entries())o.fillStyle=t.datasets[e].borderColor;return i}}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2,fontColor:n}}],yAxes:[{position:e.verticalAxisPosition,ticks:{fontColor:n,beginAtZero:!0,callback:e=>i?pi(e,i):(null==e?void 0:e.toLocaleString())||e}}]},e.stacked&&(s.options.scales.yAxes[0].stacked=!0),s}(e,n,r),l=function(e,t){if(t)return e.getEvaluatedCell({sheetId:t.sheetId,col:t.zone.left,row:t.zone.top}).format}(t,e.labelRange);"time"===i?(a.options.scales.xAxes[0].type="time",a.options.scales.xAxes[0].time=Ks(n,l),a.options.scales.xAxes[0].ticks.maxTicksLimit=15):"linear"===i&&(a.options.scales.xAxes[0].type="linear",a.options.scales.xAxes[0].ticks.callback=e=>pi(e,l),a.options.tooltips.callbacks.title=e=>{var t;return pi((null===(t=e[0])||void 0===t?void 0:t.xLabel)||"",l)});const c=new Ss;for(let[t,{label:o,data:r}]of s.entries()){["linear","time"].includes(i)&&(r=r.map(((e,t)=>({x:n[t]||void 0,y:e}))));const s=c.next();let l=At(s);if(e.stacked&&(l.a=ne),e.cumulative){let e=0;r=r.map((t=>isNaN(t)?t:(e+=parseFloat(t),e)))}const h={label:o,data:r,lineTension:0,borderColor:s,backgroundColor:Tt(l),pointBackgroundColor:s,fill:!!e.stacked&&zs(t)};a.data.datasets.push(h)}return{chartJsConfig:a,background:e.background||w}},validateChartDefinition:(e,t)=>Qs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Qs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Qs.getDefinitionFromContextCreation(e),name:s("Line"),sequence:20}),lr.add("pie",{match:e=>"pie"===e,createChart:(e,t,i)=>new or(e,t,i),getChartRuntime:function(e,t){let i=Ps(t,e.dataSets,e.labelRange).formattedValues,o=Vs(t,e.dataSets);({labels:i,dataSetsValues:o}=Fs(i,o)),e.aggregated&&({labels:i,dataSetsValues:o}=Ds(i,o));const n=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.tooltips.callbacks.title=function(e,t){return t.datasets[e[0].datasetIndex].label},s}(e,i,Us(t,e.dataSets)),s=new Ss;for(let{label:e,data:t}of o){const i={label:e,data:t,borderColor:"#FFFFFF",backgroundColor:nr(s,o)};n.data.datasets.push(i)}return{chartJsConfig:n,background:e.background||w}},validateChartDefinition:(e,t)=>or.validateChartDefinition(e,t),transformDefinition:(e,t)=>or.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>or.getDefinitionFromContextCreation(e),name:s("Pie"),sequence:30}),lr.add("scorecard",{match:e=>"scorecard"===e,createChart:(e,t,i)=>new ar(e,t,i),getChartRuntime:function(e,t){let i,o,s="",r="";if(e.keyValue){const o={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};i=t.getEvaluatedCell(o),s=String(i.value),r=i.formattedValue}const a=e.baseline;if(a){const i={sheetId:e.baseline.sheetId,col:e.baseline.zone.left,row:e.baseline.zone.top};o=t.getEvaluatedCell(i)}const l=t.getBackgroundOfSingleCellChart(e.background,e.keyValue);return{title:n(e.title),keyValue:r||s,baselineDisplay:ys(o,i,e.baselineMode),baselineArrow:Is(o,i,e.baselineMode),baselineColor:xs(o,e.baselineMode,i,e.baselineColorUp,e.baselineColorDown),baselineDescr:e.baselineDescr?n(e.baselineDescr):"",fontColor:Cs(l),background:l,baselineStyle:"percentage"!==e.baselineMode&&a?t.getCellStyle({sheetId:a.sheetId,col:a.zone.left,row:a.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}},validateChartDefinition:(e,t)=>ar.validateChartDefinition(e,t),transformDefinition:(e,t)=>ar.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>ar.getDefinitionFromContextCreation(e),name:s("Scorecard"),sequence:40}),lr.add("gauge",{match:e=>"gauge"===e,createChart:(e,t,i)=>new Zs(e,t,i),getChartRuntime:function(e,t){const i=function(e){const t=Ls(e,[],Cs(e.background));return t.options.hover=void 0,t.options.events=[],t.options.layout={padding:{left:30,right:30,top:e.title?10:25,bottom:25}},t.options.needle={radiusPercentage:2,widthPercentage:3.2,lengthPercentage:80,color:"#000000"},t.options.valueLabel={display:!1,formatter:null,color:"#FFFFFF",backgroundColor:"#000000",fontSize:30,borderRadius:5,padding:{top:5,right:5,bottom:5,left:5},bottomMarginPercentage:5},t}(e),o=e.sectionRule.colors,n=e.sectionRule.lowerInflectionPoint,s=e.sectionRule.upperInflectionPoint,r=Number(n.value),a=Number(s.value),l=Number(e.sectionRule.rangeMin),c=Number(e.sectionRule.rangeMax),h=c-l,d=[];if(""!==n.value){const e="number"===n.type?r:l+h*r/100;d.push({value:Le(e,l,c),color:o.lowerColor})}if(""!==s.value){const e="number"===s.type?a:l+h*a/100;d.push({value:Le(e,l,c),color:o.middleColor})}const u=[],g=[];d.sort(((e,t)=>e.value-t.value)).map((e=>{u.push(e.value),g.push(e.color)})),u.push(c),g.push(o.upperColor);const p=e.dataRange,m=h/30;let f=l-m,v=null,b=!1;if(void 0!==p){const e=t.getEvaluatedCell({sheetId:p.sheetId,col:p.zone.left,row:p.zone.top});e.type===rn.number&&(f=Le(e.value,l-m,c+m),v=()=>t.getRangeFormattedValues(p)[0],b=!0)}return i.options.valueLabel.display=b,i.options.valueLabel.formatter=v,i.data.datasets.push({data:u,minValue:Number(e.sectionRule.rangeMin),value:f,backgroundColor:g}),{chartJsConfig:i,background:t.getBackgroundOfSingleCellChart(e.background,p)}},validateChartDefinition:(e,t)=>Zs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Zs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Zs.getDefinitionFromContextCreation(e),name:s("Gauge"),sequence:50});const cr=new xo;cr.add("line",uo),cr.add("bar",uo),cr.add("pie",uo),cr.add("gauge",uo),cr.add("scorecard",Eo);const hr=new xo;mo`
|
|
344
|
+
`;class ns extends t.Component{constructor(){super(...arguments),this.menuItems=os.getMenuItems(),this.link=t.useState(this.defaultState),this.menu=t.useState({isOpen:!1}),this.linkEditorRef=t.useRef("linkEditor"),this.position=$n(this.linkEditorRef),this.urlInput=t.useRef("urlInput")}setup(){t.onMounted((()=>{var e;return null===(e=this.urlInput.el)||void 0===e?void 0:e.focus()}))}get defaultState(){const{col:e,row:t}=this.props.cellPosition,i=this.env.model.getters.getActiveSheetId(),o=this.env.model.getters.getEvaluatedCell({sheetId:i,col:e,row:t});return o.link?{url:o.link.url,label:o.formattedValue,isUrlEditable:o.link.isUrlEditable}:{label:o.formattedValue,url:"",isUrlEditable:!0}}get menuPosition(){return{x:this.position.x+320-12-2,y:this.position.y+100}}onSpecialLink(e){const{detail:t}=e,i=_o(t);i&&(this.link.url=i.url,this.link.label=i.label,this.link.isUrlEditable=i.isUrlEditable)}getUrlRepresentation(e){return Oo(e,this.env.model.getters)}openMenu(){this.menu.isOpen=!0}removeLink(){this.link.url="",this.link.isUrlEditable=!0}save(){var e,t;const{col:i,row:o}=this.props.cellPosition,n=this.link.label||this.link.url;this.env.model.dispatch("UPDATE_CELL",{col:i,row:o,sheetId:this.env.model.getters.getActiveSheetId(),content:Ke(n,this.link.url)}),null===(t=(e=this.props).onClosed)||void 0===t||t.call(e)}cancel(){var e,t;null===(t=(e=this.props).onClosed)||void 0===t||t.call(e)}onKeyDown(e){switch(e.key){case"Enter":this.link.url&&this.save(),e.stopPropagation();break;case"Escape":this.cancel(),e.stopPropagation()}}}ns.template="o-spreadsheet-LinkEditor",ns.components={Menu:Yn};const ss={onOpen:(e,t)=>({isOpen:!0,props:{cellPosition:e},Component:ns,cellCorner:"BottomLeft"})};ns.props={cellPosition:Object,onClosed:{type:Function,optional:!0}};const rs=new xo;function as(e){return 8===(e=wt(e).replace("#","")).length?e.slice(6)+e.slice(0,6):e}rs.add("ErrorToolTip",Fn).add("LinkCell",Qn).add("LinkEditor",ss).add("FilterMenu",Pn);class ls{constructor(e,t,i){this.title=e.title,this.sheetId=t,this.getters=i}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 cs(e,t){return"REMOVE_COLUMNS_ROWS"===t.type?qi(e,"COL"===t.dimension?"left":"top",t.elements):"ADD_COLUMNS_ROWS"===t.type?$i(e,"COL"===t.dimension?"left":"top",t.base,t.position,t.quantity):{...e}}function hs(e,t,i,o){let n=!1;const s=[];for(let o in i){let r=i[o];if(r.labelCell){const e=gs(r.labelCell,t);r.labelCell!==e&&(n=!0,r={...r,labelCell:e})}const a=gs(r.dataRange,t);void 0===a||e.getRangeString(a,a.sheetId)===K?(n=!0,r=void 0):a!==r.dataRange&&(n=!0,r={...r,dataRange:a}),s[o]=r}let r=o;const a=gs(r,t);a!==r&&(n=!0,r=a);return{isStale:n,dataSets:s.filter(ot),labelRange:r}}function ds(e,t,i){return i.map((i=>({dataRange:Di(e,t,i.dataRange),labelCell:i.labelCell?Di(e,t,i.labelCell):void 0})))}function us(e,t,i){return i?Di(e,t,i):void 0}function gs(e,t){if(!e)return;const i=t(e);switch(i.changeType){case"NONE":return e;case"REMOVE":return;default:return i.range}}function ps(e,t,i,o){const n=[];for(const s of t){const t=e.getRangeFromSheetXC(i,s),{unboundedZone:r,sheetId:a,invalidSheetName:l}=t;if(!l)if(r.left!==r.right&&r.top!==r.bottom){if(void 0===r.right)continue;for(let t=r.left;t<=r.right;t++){const i={...r,left:t,right:t};n.push(ms(e,a,i,o?{top:i.top,bottom:i.top,left:i.left,right:i.left}:void 0))}}else r.left===r.right&&r.top===r.bottom?o||n.push(ms(e,a,r,void 0)):n.push(ms(e,a,r,o?{top:r.top,bottom:r.top,left:r.left,right:r.left}:void 0))}return n}function ms(e,t,i,o){if(i.left!==i.right&&i.top!==i.bottom)throw new Error(`Zone should be a single column or row: ${Hi(i)}`);if(o){const n=Hi(i),s=Hi(o);return{labelCell:e.getRangeFromSheetXC(t,s),dataRange:e.getRangeFromSheetXC(t,n)}}return{labelCell:void 0,dataRange:e.getRangeFromSheetXC(t,Hi(i))}}function fs(e,t){var i;const o=null===(i=t.labelCell)||void 0===i?void 0:i.zone;let n=t.dataRange.zone;if(o){const{numberOfRows:e,numberOfCols:t}=to(n);1===e?n={...n,left:n.left+1}:1===t&&(n={...n,top:n.top+1})}const s=t.dataRange.clone({zone:n});return{label:t.labelCell?e.getRangeString(t.labelCell,"forceSheetReference"):void 0,range:e.getRangeString(s,"forceSheetReference")}}function vs(e,t){let i;if(e.labelRange){const o=cs(Vi(e.labelRange),t);i=o?Hi(o):void 0}const o=e.dataSets.map(Vi).map((e=>cs(e,t))).filter(ot).map(Hi);return{...e,labelRange:i,dataSets:o}}const bs=["rgb(31,119,180)","rgb(255,127,14)","rgb(174,199,232)","rgb(255,187,120)","rgb(44,160,44)","rgb(152,223,138)","rgb(214,39,40)","rgb(255,152,150)","rgb(148,103,189)","rgb(197,176,213)","rgb(140,86,75)","rgb(196,156,148)","rgb(227,119,194)","rgb(247,182,210)","rgb(127,127,127)","rgb(199,199,199)","rgb(188,189,34)","rgb(219,219,141)","rgb(23,190,207)","rgb(158,218,229)"];class Ss{constructor(){this.graphColorIndex=0}next(){return bs[this.graphColorIndex++%bs.length]}}function Cs(e){return e&&Rt(e)<.3?"#FFFFFF":"#000000"}function Es(e){if(e.dataSets){const t=void 0!==e.dataSets.find((e=>!Lt.test(e)));if(t)return 32;if(e.dataSets.map(Vi).some((e=>e.top!==e.bottom&&lo(e))))return 32}return 0}function ws(e){if(e.labelRange){if(!Lt.test(e.labelRange||""))return 33}return 0}function ys(e,t,i){if(e){if("text"===i||(null==t?void 0:t.type)!==rn.number||e.type!==rn.number)return e.formattedValue;{let o=t.value-e.value;if("percentage"===i&&0!==o&&(o=o/e.value*100),"percentage"!==i&&e.format)return pi(o,e.format);const n=Math.abs(parseFloat(o.toFixed(2))).toLocaleString();return"percentage"===i?n+"%":n}}return""}function xs(e,t,i,o,n){if("text"===t||(null==e?void 0:e.type)!==rn.number||(null==i?void 0:i.type)!==rn.number)return;const s=i.value-e.value;return s>0?o:s<0?n:void 0}function Is(e,t,i){if("text"===i||(null==e?void 0:e.type)!==rn.number||(null==t?void 0:t.type)!==rn.number)return"neutral";const o=t.value-e.value;return o>0?"up":o<0?"down":"neutral"}const Rs={Errors:{25:s("The range is invalid"),51:s("The argument is missing. Please provide a value"),52:s("The second argument is missing. Please provide a value"),53:s("The minpoint must be a number"),54:s("The midpoint must be a number"),55:s("The maxpoint must be a number"),56:s("The first value must be a number"),57:s("The second value must be a number"),47:s("Minimum must be smaller then Maximum"),50:s("Minimum must be smaller then Midpoint"),49:s("Midpoint must be smaller then Maximum"),48:s("Lower inflection point must be smaller than upper inflection point"),58:s("Invalid Minpoint formula"),60:s("Invalid Maxpoint formula"),59:s("Invalid Midpoint formula"),61:s("Invalid upper inflection point formula"),62:s("Invalid lower inflection point formula"),24:s("A range needs to be defined"),Unexpected:s("The rule is invalid for an unknown reason")},ColorScale:s("Color scale"),IconSet:s("Icon set")},Ts={IsEmpty:s("Is empty"),IsNotEmpty:s("Is not empty"),ContainsText:s("Contains"),NotContains:s("Does not contain"),BeginsWith:s("Starts with"),EndsWith:s("Ends with"),Equal:s("Is equal to"),NotEqual:s("Is not equal to"),GreaterThan:s("Is greater than"),GreaterThanOrEqual:s("Is greater than or equal to"),LessThan:s("Is less than"),LessThanOrEqual:s("Is less than or equal to"),Between:s("Is between"),NotBetween:s("Is not between")},As={Series:s("Series"),Errors:{Unexpected:s("The chart definition is invalid for an unknown reason"),32:s("The dataset is invalid"),33:s("Labels are invalid"),34:s("The key value is invalid"),35:s("The baseline value is invalid"),36:s("The data range is invalid"),37:s("A minimum range limit value is needed"),38:s("The minimum range limit value must be a number"),39:s("A maximum range limit value is needed"),40:s("The maximum range limit value must be a number"),41:s("Minimum range limit must be smaller than maximum range limit"),42:s("The lower inflection point value must be a number"),43:s("The upper inflection point value must be a number")}},Ms={Automatic:s("Automatic"),Number:s("Number"),Percent:s("Percent"),Currency:s("Currency"),CurrencyRounded:s("Currency rounded"),Date:s("Date"),Time:s("Time"),DateTime:s("Date time"),Duration:s("Duration"),CustomCurrency:s("Custom currency")},Os={Custom:s("Custom")},Ns=s("Merged cells are preventing this operation. Unmerge those cells and try again.");function _s(e,t){if(t.dataRange){const i=t.labelCell?[Hi(t.labelCell.zone)]:[],o=Ji([Hi(t.dataRange.zone)],i)[0];if(void 0===o)return[];const n=e.getRangeFromSheetXC(t.dataRange.sheetId,o);return e.getRangeValues(n).map((e=>""===e?void 0:e))}return[]}function Fs(e,t){const i=$e(0,Math.max(e.length,...t.map((e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.length)||0})))).filter((i=>{const o=e[i],n=t.map((e=>{var t;return null===(t=e.data)||void 0===t?void 0:t[i]}));return o||n.some((e=>0===e||Boolean(e)))}));return{labels:i.map((t=>e[t]||"")),dataSetsValues:t.map((e=>({...e,data:i.map((t=>e.data[t]))})))}}function Ds(e,t){const i=new Set(e),o={};i.forEach((e=>{o[e]=new Array(t.length).fill(0)}));for(const i of $e(0,e.length)){const s=e[i];for(const e of $e(0,t.length))o[s][e]+="number"==typeof(n=t[e].data[i])?n:0}var n;return{labels:Object.keys(o),dataSetsValues:t.map(((e,t)=>({...e,data:Object.values(o).map((e=>e[t]))})))}}function ks(e){return e?e.length>J?e.substring(0,J)+"…":e:""}function Ls(e,t,i,o){return{type:e.type,options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:20,right:20,top:e.title?10:25,bottom:10}},elements:{line:{fill:!1},point:{hitRadius:15}},animation:{duration:0},hover:{animationDuration:10},responsiveAnimationDuration:0,title:{display:!!e.title,fontSize:22,fontStyle:"normal",text:n(e.title),fontColor:i},legend:{onClick:void 0},tooltips:{callbacks:{label:function(e,t){var i,n,s,r,a;let l=null===(n=null===(i=t.datasets)||void 0===i?void 0:i[e.datasetIndex||0])||void 0===n?void 0:n.label;const c=""!==e.yLabel?e.yLabel:null===(a=null===(r=null===(s=t.datasets)||void 0===s?void 0:s[e.datasetIndex||0])||void 0===r?void 0:r.data)||void 0===a?void 0:a[e.index||0],h=o&&"number"==typeof c?pi(c,o):(null==c?void 0:c.toLocaleString())||"";return l?`${l}: ${h}`:h}}}},data:{labels:t.map(ks),datasets:[]}}}function Ps(e,t,i){let o={values:[],formattedValues:[]};if(i)i.invalidXc||i.invalidSheetName||(o={formattedValues:e.getRangeFormattedValues(i),values:e.getRangeValues(i).map((e=>String(e)))});else if(1===t.length)for(let i=0;i<_s(e,t[0]).length;i++)o.formattedValues.push(""),o.values.push("");else if(t[0]){o={formattedValues:$e(0,_s(e,t[0]).length).map((e=>e.toString())),values:o.formattedValues}}return o}function Us(e,t){for(const i of t){const t=e.getRangeFormats(i.dataRange).find((e=>void 0!==e&&!Ci(e)));if(t)return t}}function Vs(e,t){const i=[];for(const[o,n]of Object.entries(t)){let t;if(n.labelCell){const i=n.labelCell,s=i?e.getEvaluatedCell({sheetId:i.sheetId,col:i.zone.left,row:i.zone.top}):void 0;t=s&&i?ks(s.formattedValue):t=`${As.Series} ${parseInt(o)+1}`}else t=t=`${As.Series} ${parseInt(o)+1}`;let s=n.dataRange?_s(e,n):[];i.push({data:s,label:t})}return i}function zs(e){return 0===e?"origin":e-1}class Bs extends ls{constructor(e,t,i){super(e,t,i),this.type="bar",this.dataSets=ps(i,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(i,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.stacked=e.stacked,this.aggregated=e.aggregated}static transformDefinition(e,t){return vs(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,stacked:!1,aggregated:!1,legendPosition:"top",title:e.title||"",type:"bar",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0}}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new Bs(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Bs(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,i){return{type:"bar",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,stacked:this.stacked,aggregated:this.aggregated}}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),dataSets:e}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new Bs(n,this.sheetId,this.getters)}}function Hs(e){return e.dataRange&&!Lt.test(e.dataRange)?36:0}function $s(e,t){return t((t=>t.sectionRule?e(t.sectionRule.rangeMin,"rangeMin"):0),(t=>t.sectionRule?e(t.sectionRule.rangeMax,"rangeMax"):0))}function Ws(e){return e.sectionRule&&Number(e.sectionRule.rangeMin)>=Number(e.sectionRule.rangeMax)?41:0}function Gs(e,t){if(""===e)switch(t){case"rangeMin":return 37;case"rangeMax":return 39}return 0}function qs(e,t){if(isNaN(e))switch(t){case"rangeMin":return 38;case"rangeMax":return 40;case"lowerInflectionPointValue":return 42;case"upperInflectionPointValue":return 43}return 0}class Zs extends ls{constructor(e,t,i){super(e,t,i),this.type="gauge",this.dataRange=ki(this.getters,this.sheetId,e.dataRange),this.sectionRule=e.sectionRule,this.background=e.background}static validateChartDefinition(e,t){return e.checkValidations(t,Hs,e.chainValidations($s(Gs,e.batchValidations),$s(qs,e.batchValidations),Ws),e.chainValidations((i=qs,(0,e.batchValidations)((e=>e.sectionRule?i(e.sectionRule.lowerInflectionPoint.value,"lowerInflectionPointValue"):0),(e=>e.sectionRule?i(e.sectionRule.upperInflectionPoint.value,"upperInflectionPointValue"):0)))));var i}static transformDefinition(e,t){let i;return e.dataRange&&(i=cs(Vi(e.dataRange),t)),{...e,dataRange:i?Hi(i):void 0}}static getDefinitionFromContextCreation(e){return{background:e.background,title:e.title||"",type:"gauge",dataRange:e.range?e.range[0]:void 0,sectionRule:{colors:{lowerColor:"#cc0000",middleColor:"#f1c232",upperColor:"#6aa84f"},rangeMin:"0",rangeMax:"100",lowerInflectionPoint:{type:"percentage",value:"15"},upperInflectionPoint:{type:"percentage",value:"40"}}}}copyForSheetId(e){const t=us(this.sheetId,e,this.dataRange),i=this.getDefinitionWithSpecificRanges(t,e);return new Zs(i,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.dataRange,e);return new Zs(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.dataRange)}getDefinitionWithSpecificRanges(e,t){return{background:this.background,sectionRule:this.sectionRule,title:this.title,type:"gauge",dataRange:e?this.getters.getRangeString(e,t||this.sheetId):void 0}}getDefinitionForExcel(){}getContextCreation(){return{background:this.background,title:this.title,range:this.dataRange?[this.getters.getRangeString(this.dataRange,this.sheetId)]:void 0}}updateRanges(e){const t=gs(this.dataRange,e);if(this.dataRange===t)return this;const i=this.getDefinitionWithSpecificRanges(t);return new Zs(i,this.sheetId,this.getters)}}const js={second:1e3,minute:6e4,hour:36e5,day:864e5,month:2592e6,year:31536e6},Xs={inSeconds:function(e){return Math.floor(e/js.second)},inMinutes:function(e){return Math.floor(e/js.minute)},inHours:function(e){return Math.floor(e/js.hour)},inDays:function(e){return Math.floor(e/js.day)},inMonths:function(e){return Math.floor(e/js.month)},inYears:function(e){return Math.floor(e/js.year)}},Ys=/^((d|dd|m|mm|yyyy|yy|hh|h|ss|a)(-|:|\s|\/))*(d|dd|m|mm|yyyy|yy|hh|h|ss|a)$/i;function Ks(e,t){const i=function(e){const t=(e=(e=e.replace(/y/g,"Y")).replace(/d/g,"D")).indexOf("h");e=t>=0?e.slice(0,t).replace(/m/g,"M")+e.slice(t):e.replace(/m/g,"M");e.includes("a")||(e=e.replace(/h/g,"H"));return e}(t),o=function(e,t){const i=e.map((e=>{var t;return null===(t=Ee(e))||void 0===t?void 0:t.jsDate}));if(i.some((e=>void 0===e))||e.length<2)return;const o=i.map((e=>e.getTime())),n=Math.max(...o)-Math.min(...o),s=function(e){if(e.includes("s"))return"second";if(e.includes("m"))return"minute";if(e.includes("h")||e.includes("H"))return"hour";if(e.includes("D"))return"day";if(e.includes("M"))return"month";return"year"}(t);if(js.second>=js[s]&&Xs.inSeconds(n)<180)return"second";if(js.minute>=js[s]&&Xs.inMinutes(n)<180)return"minute";if(js.hour>=js[s]&&Xs.inHours(n)<96)return"hour";if(js.day>=js[s]&&Xs.inDays(n)<90)return"day";if(js.month>=js[s]&&Xs.inMonths(n)<36)return"month";return"year"}(e,i),n={};return o&&(n[o]=i),{parser:i,displayFormats:n,unit:o}}class Qs extends ls{constructor(e,t,i){super(e,t,i),this.type="line",this.dataSets=ps(this.getters,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(this.getters,t,e.labelRange),this.background=e.background,this.verticalAxisPosition=e.verticalAxisPosition,this.legendPosition=e.legendPosition,this.labelsAsText=e.labelsAsText,this.stacked=e.stacked,this.aggregated=e.aggregated,this.cumulative=e.cumulative}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static transformDefinition(e,t){return vs(e,t)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,labelsAsText:!1,legendPosition:"top",title:e.title||"",type:"line",verticalAxisPosition:"left",labelRange:e.auxiliaryRange||void 0,stacked:!1,aggregated:!1,cumulative:!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getDefinitionWithSpecificDataSets(e,t,i){return{type:"line",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,verticalAxisPosition:this.verticalAxisPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,labelsAsText:this.labelsAsText,stacked:this.stacked,aggregated:this.aggregated,cumulative:this.cumulative}}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new Qs(n,this.sheetId,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),dataSets:e}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new Qs(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new Qs(t,e,this.getters)}}function Js(e,t){return tr(e,t)||ir(e,t)}function er(e,t){return function(e,t){return!e.labelsAsText&&tr(e.labelRange,t)}(e,t)?"time":function(e,t){return!e.labelsAsText&&ir(e.labelRange,t)}(e,t)?"linear":"category"}function tr(e,t){if(!e||!ir(e,t))return!1;const i=t.getEvaluatedCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}).format;return Boolean(i&&Ys.test(i))}function ir(e,t){if(!e)return!1;const i=t.getRangeValues(e);return!i.some((e=>isNaN(Number(e))&&e))&&!i.every((e=>!e))}class or extends ls{constructor(e,t,i){super(e,t,i),this.type="pie",this.dataSets=ps(i,e.dataSets,t,e.dataSetsHaveTitle),this.labelRange=ki(i,t,e.labelRange),this.background=e.background,this.legendPosition=e.legendPosition,this.aggregated=e.aggregated}static transformDefinition(e,t){return vs(e,t)}static validateChartDefinition(e,t){return e.checkValidations(t,Es,ws)}static getDefinitionFromContextCreation(e){return{background:e.background,dataSets:e.range?e.range:[],dataSetsHaveTitle:!1,legendPosition:"top",title:e.title||"",type:"pie",labelRange:e.auxiliaryRange||void 0,aggregated:!1}}getDefinition(){return this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange)}getContextCreation(){return{background:this.background,title:this.title,range:this.dataSets.map((e=>this.getters.getRangeString(e.dataRange,this.sheetId))),auxiliaryRange:this.labelRange?this.getters.getRangeString(this.labelRange,this.sheetId):void 0}}getDefinitionWithSpecificDataSets(e,t,i){return{type:"pie",dataSetsHaveTitle:!!e.length&&Boolean(e[0].labelCell),background:this.background,dataSets:e.map((e=>this.getters.getRangeString(e.dataRange,i||this.sheetId))),legendPosition:this.legendPosition,labelRange:t?this.getters.getRangeString(t,i||this.sheetId):void 0,title:this.title,aggregated:this.aggregated}}copyForSheetId(e){const t=ds(this.sheetId,e,this.dataSets),i=us(this.sheetId,e,this.labelRange),o=this.getDefinitionWithSpecificDataSets(t,i,e);return new or(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificDataSets(this.dataSets,this.labelRange,e);return new or(t,e,this.getters)}getDefinitionForExcel(){if(this.aggregated)return;const e=this.dataSets.map((e=>fs(this.getters,e))).filter((e=>""!==e.range));return{...this.getDefinition(),backgroundColor:as(this.background||w),fontColor:as(Cs(this.background)),verticalAxisPosition:"left",dataSets:e}}updateRanges(e){const{dataSets:t,labelRange:i,isStale:o}=hs(this.getters,e,this.dataSets,this.labelRange);if(!o)return this;const n=this.getDefinitionWithSpecificDataSets(t,i);return new or(n,this.sheetId,this.getters)}}function nr(e,t){const i=[],o=Math.max(...t.map((e=>e.data.length)));for(let t=0;t<=o;t++)i.push(e.next());return i}function sr(e){return e.keyValue&&!Lt.test(e.keyValue)?34:0}function rr(e){return e.baseline&&!Lt.test(e.baseline)?35:0}class ar extends ls{constructor(e,t,i){super(e,t,i),this.type="scorecard",this.keyValue=ki(i,t,e.keyValue),this.baseline=ki(i,t,e.baseline),this.baselineMode=e.baselineMode,this.baselineDescr=e.baselineDescr,this.background=e.background,this.baselineColorUp=e.baselineColorUp,this.baselineColorDown=e.baselineColorDown}static validateChartDefinition(e,t){return e.checkValidations(t,sr,rr)}static getDefinitionFromContextCreation(e){return{background:e.background,type:"scorecard",keyValue:e.range?e.range[0]:void 0,title:e.title||"",baselineMode:te,baselineColorUp:ie,baselineColorDown:oe,baseline:e.auxiliaryRange||""}}static transformDefinition(e,t){let i,o;return e.baseline&&(i=cs(Vi(e.baseline),t)),e.keyValue&&(o=cs(Vi(e.keyValue),t)),{...e,baseline:i?Hi(i):void 0,keyValue:o?Hi(o):void 0}}copyForSheetId(e){const t=us(this.sheetId,e,this.baseline),i=us(this.sheetId,e,this.keyValue),o=this.getDefinitionWithSpecificRanges(t,i,e);return new ar(o,e,this.getters)}copyInSheetId(e){const t=this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue,e);return new ar(t,e,this.getters)}getDefinition(){return this.getDefinitionWithSpecificRanges(this.baseline,this.keyValue)}getContextCreation(){return{background:this.background,title:this.title,range:this.keyValue?[this.getters.getRangeString(this.keyValue,this.sheetId)]:void 0,auxiliaryRange:this.baseline?this.getters.getRangeString(this.baseline,this.sheetId):void 0}}getDefinitionWithSpecificRanges(e,t,i){return{baselineColorDown:this.baselineColorDown,baselineColorUp:this.baselineColorUp,baselineMode:this.baselineMode,title:this.title,type:"scorecard",background:this.background,baseline:e?this.getters.getRangeString(e,i||this.sheetId):void 0,baselineDescr:this.baselineDescr,keyValue:t?this.getters.getRangeString(t,i||this.sheetId):void 0}}getDefinitionForExcel(){}updateRanges(e){const t=gs(this.baseline,e),i=gs(this.keyValue,e);if(this.baseline===t&&this.keyValue===i)return this;const o=this.getDefinitionWithSpecificRanges(t,i);return new ar(o,this.sheetId,this.getters)}}const lr=new xo;lr.add("bar",{match:e=>"bar"===e,createChart:(e,t,i)=>new Bs(e,t,i),getChartRuntime:function(e,t){let i=Ps(t,e.dataSets,e.labelRange).formattedValues,o=Vs(t,e.dataSets);({labels:i,dataSetsValues:o}=Fs(i,o)),e.aggregated&&({labels:i,dataSetsValues:o}=Ds(i,o));const n=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2,fontColor:n}}],yAxes:[{position:e.verticalAxisPosition,ticks:{fontColor:n,beginAtZero:!0,callback:e=>i?pi(e,i):(null==e?void 0:e.toLocaleString())||e}}]},e.stacked&&(s.options.scales.xAxes[0].stacked=!0,s.options.scales.yAxes[0].stacked=!0),s}(e,i,Us(t,e.dataSets)),s=new Ss;for(let{label:e,data:t}of o){const i=s.next(),o={label:e,data:t,borderColor:i,backgroundColor:i};n.data.datasets.push(o)}return{chartJsConfig:n,background:e.background||w}},validateChartDefinition:(e,t)=>Bs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Bs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Bs.getDefinitionFromContextCreation(e),name:s("Bar"),sequence:10}),lr.add("line",{match:e=>"line"===e,createChart:(e,t,i)=>new Qs(e,t,i),getChartRuntime:function(e,t){const i=er(e,t),o=Ps(t,e.dataSets,e.labelRange);let n="linear"===i?o.values:o.formattedValues,s=Vs(t,e.dataSets);({labels:n,dataSetsValues:s}=Fs(n,s)),"time"===i&&({labels:n,dataSetsValues:s}=function(e,t){if(0===e.length||e.every((e=>!e)))return{labels:e,dataSetsValues:t};const i=[...e],o=Fe(t);for(let e=0;e<i.length;e++)if(!i[e]){i[e]=lt(i,e);for(let t of o)t.data[e]=void 0}return{labels:i,dataSetsValues:o}}(n,s)),e.aggregated&&({labels:n,dataSetsValues:s}=Ds(n,s));const r=Us(t,e.dataSets),a=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n,generateLabels(e){const{data:t}=e,i=window.Chart.defaults.global.legend.labels.generateLabels(e);for(const[e,o]of i.entries())o.fillStyle=t.datasets[e].borderColor;return i}}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.scales={xAxes:[{ticks:{maxRotation:60,minRotation:15,padding:5,labelOffset:2,fontColor:n}}],yAxes:[{position:e.verticalAxisPosition,ticks:{fontColor:n,beginAtZero:!0,callback:e=>i?pi(e,i):(null==e?void 0:e.toLocaleString())||e}}]},e.stacked&&(s.options.scales.yAxes[0].stacked=!0),s}(e,n,r),l=function(e,t){if(t)return e.getEvaluatedCell({sheetId:t.sheetId,col:t.zone.left,row:t.zone.top}).format}(t,e.labelRange);"time"===i?(a.options.scales.xAxes[0].type="time",a.options.scales.xAxes[0].time=Ks(n,l),a.options.scales.xAxes[0].ticks.maxTicksLimit=15):"linear"===i&&(a.options.scales.xAxes[0].type="linear",a.options.scales.xAxes[0].ticks.callback=e=>pi(e,l),a.options.tooltips.callbacks.title=e=>{var t;return pi((null===(t=e[0])||void 0===t?void 0:t.xLabel)||"",l)});const c=new Ss;for(let[t,{label:o,data:r}]of s.entries()){["linear","time"].includes(i)&&(r=r.map(((e,t)=>({x:n[t]||void 0,y:e}))));const s=c.next();let l=At(s);if(e.stacked&&(l.a=ne),e.cumulative){let e=0;r=r.map((t=>isNaN(t)?t:(e+=parseFloat(t),e)))}const h={label:o,data:r,lineTension:0,borderColor:s,backgroundColor:Tt(l),pointBackgroundColor:s,fill:!!e.stacked&&zs(t)};a.data.datasets.push(h)}return{chartJsConfig:a,background:e.background||w}},validateChartDefinition:(e,t)=>Qs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Qs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Qs.getDefinitionFromContextCreation(e),name:s("Line"),sequence:20}),lr.add("pie",{match:e=>"pie"===e,createChart:(e,t,i)=>new or(e,t,i),getChartRuntime:function(e,t){let i=Ps(t,e.dataSets,e.labelRange).formattedValues,o=Vs(t,e.dataSets);({labels:i,dataSetsValues:o}=Fs(i,o)),e.aggregated&&({labels:i,dataSetsValues:o}=Ds(i,o));const n=function(e,t,i){var o;const n=Cs(e.background),s=Ls(e,t,n,i),r={labels:{fontColor:n}};return!e.labelRange&&1===e.dataSets.length||"none"===e.legendPosition?r.display=!1:r.position=e.legendPosition,s.options.legend={...null===(o=s.options)||void 0===o?void 0:o.legend,...r},s.options.layout={padding:{left:20,right:20,top:e.title?10:25,bottom:10}},s.options.tooltips.callbacks.title=function(e,t){return t.datasets[e[0].datasetIndex].label},s}(e,i,Us(t,e.dataSets)),s=new Ss;for(let{label:e,data:t}of o){const i={label:e,data:t,borderColor:"#FFFFFF",backgroundColor:nr(s,o)};n.data.datasets.push(i)}return{chartJsConfig:n,background:e.background||w}},validateChartDefinition:(e,t)=>or.validateChartDefinition(e,t),transformDefinition:(e,t)=>or.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>or.getDefinitionFromContextCreation(e),name:s("Pie"),sequence:30}),lr.add("scorecard",{match:e=>"scorecard"===e,createChart:(e,t,i)=>new ar(e,t,i),getChartRuntime:function(e,t){let i,o,s="",r="";if(e.keyValue){const o={sheetId:e.keyValue.sheetId,col:e.keyValue.zone.left,row:e.keyValue.zone.top};i=t.getEvaluatedCell(o),s=String(i.value),r=i.formattedValue}const a=e.baseline;if(a){const i={sheetId:e.baseline.sheetId,col:e.baseline.zone.left,row:e.baseline.zone.top};o=t.getEvaluatedCell(i)}const{background:l,fontColor:c}=t.getStyleOfSingleCellChart(e.background,e.keyValue);return{title:n(e.title),keyValue:r||s,baselineDisplay:ys(o,i,e.baselineMode),baselineArrow:Is(o,i,e.baselineMode),baselineColor:xs(o,e.baselineMode,i,e.baselineColorUp,e.baselineColorDown),baselineDescr:e.baselineDescr?n(e.baselineDescr):"",fontColor:c,background:l,baselineStyle:"percentage"!==e.baselineMode&&a?t.getCellStyle({sheetId:a.sheetId,col:a.zone.left,row:a.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}},validateChartDefinition:(e,t)=>ar.validateChartDefinition(e,t),transformDefinition:(e,t)=>ar.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>ar.getDefinitionFromContextCreation(e),name:s("Scorecard"),sequence:40}),lr.add("gauge",{match:e=>"gauge"===e,createChart:(e,t,i)=>new Zs(e,t,i),getChartRuntime:function(e,t){const i=function(e){const t=Ls(e,[],Cs(e.background));return t.options.hover=void 0,t.options.events=[],t.options.layout={padding:{left:30,right:30,top:e.title?10:25,bottom:25}},t.options.needle={radiusPercentage:2,widthPercentage:3.2,lengthPercentage:80,color:"#000000"},t.options.valueLabel={display:!1,formatter:null,color:"#FFFFFF",backgroundColor:"#000000",fontSize:30,borderRadius:5,padding:{top:5,right:5,bottom:5,left:5},bottomMarginPercentage:5},t}(e),o=e.sectionRule.colors,n=e.sectionRule.lowerInflectionPoint,s=e.sectionRule.upperInflectionPoint,r=Number(n.value),a=Number(s.value),l=Number(e.sectionRule.rangeMin),c=Number(e.sectionRule.rangeMax),h=c-l,d=[];if(""!==n.value){const e="number"===n.type?r:l+h*r/100;d.push({value:Le(e,l,c),color:o.lowerColor})}if(""!==s.value){const e="number"===s.type?a:l+h*a/100;d.push({value:Le(e,l,c),color:o.middleColor})}const u=[],g=[];d.sort(((e,t)=>e.value-t.value)).map((e=>{u.push(e.value),g.push(e.color)})),u.push(c),g.push(o.upperColor);const p=e.dataRange,m=h/30;let f=l-m,v=null,b=!1;if(void 0!==p){const e=t.getEvaluatedCell({sheetId:p.sheetId,col:p.zone.left,row:p.zone.top});e.type===rn.number&&(f=Le(e.value,l-m,c+m),v=()=>t.getRangeFormattedValues(p)[0],b=!0)}return i.options.valueLabel.display=b,i.options.valueLabel.formatter=v,i.data.datasets.push({data:u,minValue:Number(e.sectionRule.rangeMin),value:f,backgroundColor:g}),{chartJsConfig:i,background:t.getStyleOfSingleCellChart(e.background,p).background}},validateChartDefinition:(e,t)=>Zs.validateChartDefinition(e,t),transformDefinition:(e,t)=>Zs.transformDefinition(e,t),getChartDefinitionFromContextCreation:e=>Zs.getDefinitionFromContextCreation(e),name:s("Gauge"),sequence:50});const cr=new xo;cr.add("line",uo),cr.add("bar",uo),cr.add("pie",uo),cr.add("gauge",uo),cr.add("scorecard",Eo);const hr=new xo;mo`
|
|
345
345
|
.o-chart-container {
|
|
346
346
|
width: 100%;
|
|
347
347
|
height: 100%;
|
|
@@ -1397,7 +1397,7 @@
|
|
|
1397
1397
|
onScroll.bind="onScroll"
|
|
1398
1398
|
/>`,pp.defaultProps={topOffset:0},pp.props={topOffset:{type:Number,optional:!0}};const mp={ROW:ca,COL:la,CELL:aa};class fp extends t.Component{constructor(){super(...arguments),this.HEADER_HEIGHT=N,this.HEADER_WIDTH=_,this.keyDownMapping={ENTER:()=>{this.env.model.getters.getActiveCell().type===rn.empty?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},TAB:()=>this.env.model.selection.moveAnchorCell("right",1),"SHIFT+TAB":()=>this.env.model.selection.moveAnchorCell("left",1),F2:()=>{this.env.model.getters.getActiveCell().type===rn.empty?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()},DELETE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},BACKSPACE:()=>{this.env.model.dispatch("DELETE_CONTENT",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones()})},ESCAPE:()=>{this.env.model.getters.hasOpenedPopover()?this.closeOpenedPopover():this.menuState.isOpen?this.closeMenu():this.env.model.dispatch("CLEAN_CLIPBOARD_HIGHLIGHT")},"CTRL+A":()=>this.env.model.selection.loopSelection(),"CTRL+Z":()=>this.env.model.dispatch("REQUEST_UNDO"),"CTRL+Y":()=>this.env.model.dispatch("REQUEST_REDO"),"CTRL+B":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{bold:!this.env.model.getters.getCurrentStyle().bold}}),"CTRL+I":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{italic:!this.env.model.getters.getCurrentStyle().italic}}),"CTRL+U":()=>this.env.model.dispatch("SET_FORMATTING",{sheetId:this.env.model.getters.getActiveSheetId(),target:this.env.model.getters.getSelectedZones(),style:{underline:!this.env.model.getters.getCurrentStyle().underline}}),"ALT+=":()=>{var e;const t=this.env.model.getters.getActiveSheetId(),i=this.env.model.getters.getSelectedZone(),{anchor:o}=this.env.model.getters.getSelection(),n=this.env.model.getters.getAutomaticSums(t,i,o.cell);if(this.env.model.getters.isSingleCellOrMerge(t,i)||this.env.model.getters.isEmpty(t,i)&&n.length<=1){const i=(null===(e=n[0])||void 0===e?void 0:e.zone)?this.env.model.getters.zoneToXC(t,n[0].zone):"",o=`=SUM(${i})`;this.props.onGridComposerCellFocused(o,{start:5,end:5+i.length})}else this.env.model.dispatch("SUM_SELECTION")},"CTRL+HOME":()=>{const e=this.env.model.getters.getActiveSheetId(),{col:t,row:i}=this.env.model.getters.getNextVisibleCellPosition({sheetId:e,col:0,row:0});this.env.model.selection.selectCell(t,i)},"CTRL+END":()=>{const e=this.env.model.getters.getActiveSheetId(),t=this.env.model.getters.findVisibleHeader(e,"COL",this.env.model.getters.getNumberCols(e)-1,0),i=this.env.model.getters.findVisibleHeader(e,"ROW",this.env.model.getters.getNumberRows(e)-1,0);this.env.model.selection.selectCell(t,i)},"SHIFT+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),left:0,right:this.env.model.getters.getNumberCols(e)-1},i=this.env.model.getters.getActivePosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+ ":()=>{const e=this.env.model.getters.getActiveSheetId(),t={...this.env.model.getters.getSelectedZone(),top:0,bottom:this.env.model.getters.getNumberRows(e)-1},i=this.env.model.getters.getActivePosition();this.env.model.selection.selectZone({cell:i,zone:t})},"CTRL+SHIFT+ ":()=>{this.env.model.selection.selectAll()},"SHIFT+PAGEDOWN":()=>{this.env.model.dispatch("ACTIVATE_NEXT_SHEET")},"SHIFT+PAGEUP":()=>{this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET")},PAGEDOWN:()=>this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),PAGEUP:()=>this.env.model.dispatch("SHIFT_VIEWPORT_UP"),"CTRL+K":()=>ia(this.env)}}setup(){this.menuState=t.useState({isOpen:!1,position:null,menuItems:[]}),this.gridRef=t.useRef("grid"),this.hiddenInput=t.useRef("hiddenInput"),this.canvasPosition=$n(this.gridRef),this.hoveredCell=t.useState({col:void 0,row:void 0}),t.useChildSubEnv({getPopoverContainerRect:()=>this.getGridRect()}),t.useExternalListener(document.body,"cut",this.copy.bind(this,!0)),t.useExternalListener(document.body,"copy",this.copy.bind(this,!1)),t.useExternalListener(document.body,"paste",this.paste),t.onMounted((()=>this.focus())),this.props.exposeFocus((()=>this.focus())),rp("canvas",this.env.model,(()=>this.env.model.getters.getSheetViewDimensionWithHeaders())),t.useEffect((()=>this.focus()),(()=>[this.env.model.getters.getActiveSheetId()])),this.onMouseWheel=ap(((e,t)=>{this.moveCanvas(e,t),this.hoveredCell.col=void 0,this.hoveredCell.row=void 0}))}onCellHovered({col:e,row:t}){this.hoveredCell.col=e,this.hoveredCell.row=t}get gridOverlayDimensions(){return So({top:"26px",left:"48px",height:"calc(100% - 41px)",width:"calc(100% - 63px)"})}onClosePopover(){this.env.model.getters.hasOpenedPopover()&&this.closeOpenedPopover(),this.focus()}focus(){var e;this.env.model.getters.getSelectedFigureId()||"inactive"!==this.env.model.getters.getEditionMode()||null===(e=this.hiddenInput.el)||void 0===e||e.focus()}get gridEl(){if(!this.gridRef.el)throw new Error("Grid el is not defined.");return this.gridRef.el}getAutofillPosition(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect(e);return{left:t.x+t.width-4,top:t.y+t.height-4}}get isAutofillVisible(){const e=this.env.model.getters.getSelectedZone(),t=this.env.model.getters.getVisibleRect({left:e.right,right:e.right,top:e.bottom,bottom:e.bottom});return!(0===t.width||0===t.height)}onGridResized({height:e,width:t}){this.env.model.dispatch("RESIZE_SHEETVIEW",{width:t,height:e,gridOffsetX:_,gridOffsetY:N})}moveCanvas(e,t){const{scrollX:i,scrollY:o}=this.env.model.getters.getActiveSheetDOMScrollInfo();this.env.model.dispatch("SET_VIEWPORT_OFFSET",{offsetX:i+e,offsetY:o+t})}getClientPositionKey(e){var t,i,o;return`${e.id}-${null===(t=e.position)||void 0===t?void 0:t.sheetId}-${null===(i=e.position)||void 0===i?void 0:i.col}-${null===(o=e.position)||void 0===o?void 0:o.row}`}isCellHovered(e,t){return this.hoveredCell.col===e&&this.hoveredCell.row===t}getGridRect(){return{...this.canvasPosition,...this.env.model.getters.getSheetViewDimensionWithHeaders()}}onCellClicked(e,t,{ctrlKey:i,shiftKey:o}){i&&this.env.model.dispatch("PREPARE_SELECTION_INPUT_EXPANSION"),this.env.model.getters.hasOpenedPopover()&&this.closeOpenedPopover(),"editing"===this.env.model.getters.getEditionMode()&&this.env.model.dispatch("STOP_EDITION"),o?this.env.model.selection.setAnchorCorner(e,t):i?this.env.model.selection.addCellToSelection(e,t):this.env.model.selection.selectCell(e,t);let n=e,s=t;Fg(this.env,((e,t,i)=>{i.preventDefault(),(e!==n&&-1!=e||t!==s&&-1!=t)&&(n=-1===e?n:e,s=-1===t?s:t,this.env.model.selection.setAnchorCorner(n,s))}),(()=>{this.env.model.dispatch("STOP_SELECTION_INPUT"),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}))}onCellDoubleClicked(e,t){const i=this.env.model.getters.getActiveSheetId();({col:e,row:t}=this.env.model.getters.getMainCellPosition({sheetId:i,col:e,row:t}));this.env.model.getters.getEvaluatedCell({sheetId:i,col:e,row:t}).type===rn.empty?this.props.onGridComposerCellFocused():this.props.onComposerContentFocused()}closeOpenedPopover(){this.env.model.dispatch("CLOSE_CELL_POPOVER")}processArrows(e){e.preventDefault(),e.stopPropagation(),this.env.model.getters.hasOpenedPopover()&&this.closeOpenedPopover(),ig(e,this.env.model.selection),this.env.model.getters.isPaintingFormat()&&this.env.model.dispatch("PASTE",{target:this.env.model.getters.getSelectedZones()})}onKeydown(e){if(e.key.startsWith("Arrow"))return void this.processArrows(e);let t="";e.ctrlKey&&(t+="CTRL+"),e.metaKey&&(t+="CTRL+"),e.altKey&&(t+="ALT+"),e.shiftKey&&(t+="SHIFT+"),t+=e.key.toUpperCase();let i=this.keyDownMapping[t];return i?(e.preventDefault(),e.stopPropagation(),void i()):void 0}onInput(e){(e.isComposing||"insertFromPaste"!==e.inputType)&&e.data&&(e.preventDefault(),e.stopPropagation(),this.props.onGridComposerCellFocused(e.data))}onInputContextMenu(e){e.preventDefault();const t=this.env.model.getters.getSelectedZone(),{left:i,top:o}=t;let n="CELL";this.env.model.dispatch("STOP_EDITION"),this.env.model.getters.getActiveCols().has(i)?n="COL":this.env.model.getters.getActiveRows().has(o)&&(n="ROW");const{x:s,y:r,width:a,height:l}=this.env.model.getters.getVisibleRect(t);this.toggleContextMenu(n,s+a,r+l)}onCellRightClicked(e,t,{x:i,y:o}){const n=this.env.model.getters.getSelectedZones();let s="CELL";Ki(e,t,n[n.length-1])?this.env.model.getters.getActiveCols().has(e)?s="COL":this.env.model.getters.getActiveRows().has(t)&&(s="ROW"):(this.env.model.selection.getBackToDefault(),this.env.model.selection.selectCell(e,t)),this.toggleContextMenu(s,i,o)}toggleContextMenu(e,t,i){this.env.model.getters.hasOpenedPopover()&&this.closeOpenedPopover(),this.menuState.isOpen=!0,this.menuState.position={x:t,y:i},this.menuState.menuItems=mp[e].getMenuItems()}copy(e,t){if(!this.gridEl.contains(document.activeElement))return;const i=t.clipboardData;if(!i)return void this.displayWarningCopyPasteNotSupported();if("inactive"!==this.env.model.getters.getEditionMode())return;e?xr(this.env):this.env.model.dispatch("COPY");const o=this.env.model.getters.getClipboardContent();for(const e in o)i.setData(e,o[e]);t.preventDefault()}paste(e){if(!this.gridEl.contains(document.activeElement))return;const t=e.clipboardData;if(t){if(t.types.indexOf(an.PlainText)>-1){const e=t.getData(an.PlainText),i=this.env.model.getters.getSelectedZones();this.env.model.getters.getClipboardTextContent()===e?Mr(this.env,i):Or(this.env,i,e)}}else this.displayWarningCopyPasteNotSupported()}displayWarningCopyPasteNotSupported(){this.env.raiseError(s("Copy/Paste is not supported in this browser."))}closeMenu(){this.menuState.isOpen=!1,this.focus()}}fp.template="o-spreadsheet-Grid",fp.components={GridComposer:Zg,GridOverlay:ep,GridPopover:tp,HeadersOverlay:sp,Menu:Yn,Autofill:Dg,ClientTag:Lg,Highlight:hp,Popover:qn,VerticalScrollBar:pp,HorizontalScrollBar:gp,FilterIconsOverlay:Kg},fp.props={sidePanelIsOpen:Boolean,exposeFocus:Function,focusComposer:String,onComposerContentFocused:Function,onGridComposerCellFocused:Function};class vp{constructor(e){this.xmlString=e}toString(){return this.xmlString}}const bp=["areaChart","area3DChart","lineChart","line3DChart","stockChart","radarChart","scatterChart","pieChart","pie3DChart","doughnutChart","barChart","bar3DChart","ofPieChart","surfaceChart","surface3DChart","bubbleChart"],Sp="000000",Cp={arrow:"3Arrows",smiley:"3Symbols",dot:"3TrafficLights1"},Ep={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"},wp="http://schemas.openxmlformats.org/drawingml/2006/main",yp="http://schemas.openxmlformats.org/drawingml/2006/chart",xp={workbook:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",sheet:"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+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"},Ip={document:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",sheet:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",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"},Rp="http://schemas.openxmlformats.org/officeDocument/2006/relationships",Tp=.75,Ap=.1317,Mp=8.43,Op=12.75,Np=30,_p=100,Fp=164,Dp={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}]},kp=["ACOT","ACOTH","AGGREGATE","ARABIC","BASE","BETA.DIST","BETA.INV","BINOM.DIST","BINOM.DIST.RANGE","BINOM.INV","BITAND","BITLSHIFT","BITOR","BITRSHIFT","BITXOR","CEILING.MATH","CEILING.PRECISE","CHISQ.DIST","CHISQ.DIST.RT","CHISQ.INV","CHISQ.INV.RT","CHISQ.TEST","COMBINA","CONCAT","CONFIDENCE.NORM","CONFIDENCE.T","COT","COTH","COVARIANCE.P","COVARIANCE.S","CSC","CSCH","DAYS","DECIMAL","ERF.PRECISE","ERFC.PRECISE","EXPON.DIST","F.DIST","F.DIST.RT","F.INV","F.INV.RT","F.TEST","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","HYPGEOM.DIST","IFNA","IFS","IMCOSH","IMCOT","IMCSC","IMCSCH","IMSEC","IMSECH","IMSINH","IMTAN","ISFORMULA","ISOWEEKNUM","LOGNORM.DIST","LOGNORM.INV","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","QUARTILE.EXC","QUARTILE.INC","QUERYSTRING","RANK.AVG","RANK.EQ","RRI","SEC","SECH","SHEET","SHEETS","SKEW.P","STDEV.P","STDEV.S","SWITCH","T.DIST","T.DIST.2T","T.DIST.RT","T.INV","T.INV.2T","T.TEST","TEXTJOIN","UNICHAR","UNICODE","VAR.P","VAR.S","WEBSERVICE","WEIBULL.DIST","XOR","Z.TEST"],Lp="[Content_Types].xml";var Pp;!function(e){e.DiagonalBorderNotSupported="Diagonal Borders",e.BorderStyleNotSupported="Border style",e.FillStyleNotSupported="Fill Style",e.FontNotSupported="Font",e.HorizontalAlignmentNotSupported="Horizontal Alignment",e.VerticalAlignmentNotSupported="Vertical Alignments",e.MultipleRulesCfNotSupported="Multiple rules conditional formats",e.CfTypeNotSupported="Conditional format type",e.CfFormatBorderNotSupported="Borders in conditional formats",e.CfFormatAlignmentNotSupported="Alignment in conditional formats",e.CfFormatNumFmtNotSupported="Num formats in conditional formats",e.CfIconSetEmptyIconNotSupported="IconSets with empty icons",e.BadlyFormattedHyperlink="Badly formatted hyperlink",e.NumFmtIdNotSupported="Number format"}(Pp||(Pp={}));class Up{constructor(){this._parsingWarnings=new Set,this._conversionWarnings=new Set}addParsingWarning(e){this._parsingWarnings.add(e)}addConversionWarning(e){this._conversionWarnings.add(e)}get warnings(){return[...this._parsingWarnings,...this._conversionWarnings]}generateNotSupportedWarning(e,t,i){let o=`${e} ${t?'"'+t+'" is':"are"} not yet supported. `;i&&(o+=`Only ${i.join(", ")} are currently supported.`),this._conversionWarnings.has(o)||this._conversionWarnings.add(o)}}const Vp=["thin"],zp=["general","left","center","right"],Bp=["Arial"],Hp=["solid"],$p=["expression","cellIs","colorScale","iconSet","containsText","notContainsText","beginsWith","endsWith","containsBlanks","notContainsBlanks"],Wp={b:"boolean",d:"date",e:"error",inlineStr:"inlineStr",n:"number",s:"sharedString",str:"str"},Gp={dashDot:"thin",dashDotDot:"thin",dashed:"thin",dotted:"thin",double:"thin",hair:"thin",medium:"thin",mediumDashDot:"thin",mediumDashDotDot:"thin",mediumDashed:"thin",none:void 0,slantDashDot:"thin",thick:"thin",thin:"thin"},qp={general:void 0,left:"left",center:"center",right:"right",fill:"left",justify:"left",centerContinuous:"center",distributed:"center"};const Zp={aboveAverage:void 0,expression:void 0,cellIs:void 0,colorScale:void 0,dataBar:void 0,iconSet:void 0,top10:void 0,uniqueValues:void 0,duplicateValues:void 0,containsText:"ContainsText",notContainsText:"NotContains",beginsWith:"BeginsWith",endsWith:"EndsWith",containsBlanks:"IsEmpty",notContainsBlanks:"IsNotEmpty",containsErrors:void 0,notContainsErrors:void 0,timePeriod:void 0},jp={num:"number",percent:"percentage",max:"value",min:"value",percentile:"percentile",formula:"formula"},Xp={NoIcons:void 0,"3Arrows":"arrows","3ArrowsGray":"arrows","3Symbols":"smiley","3Symbols2":"smiley","3Signs":"dots","3Flags":"dots","3TrafficLights1":"dots","3TrafficLights2":"dots","4Arrows":"arrows","4ArrowsGray":"arrows","4RedToBlack":"dots","4Rating":"smiley","4TrafficLights":"dots","5Arrows":"arrows","5ArrowsGray":"arrows","5Rating":"smiley","5Quarters":"dots","3Stars":"smiley","3Triangles":"arrows","5Boxes":"dots"},Yp={b:"bottom",t:"top",l:"left",r:"right",tr:"right"},Kp={areaChart:void 0,area3DChart:void 0,lineChart:"line",line3DChart:void 0,stockChart:void 0,radarChart:void 0,scatterChart:void 0,pieChart:"pie",pie3DChart:void 0,doughnutChart:"pie",barChart:"bar",bar3DChart:void 0,ofPieChart:void 0,surfaceChart:void 0,surface3DChart:void 0,bubbleChart:void 0},Qp={1:"AVERAGE",2:"COUNT",3:"COUNTA",4:"MAX",5:"MIN",6:"PRODUCT",7:"STDEV",8:"STDEVP",9:"SUM",10:"VAR",11:"VARP",101:"AVERAGE",102:"COUNT",103:"COUNTA",104:"MAX",105:"MIN",106:"PRODUCT",107:"STDEV",108:"STDEVP",109:"SUM",110:"VAR",111:"VARP"},Jp={0:"",1:"0",2:"0.00",3:"#,#00",4:"#,##0.00",9:"0%",10:"0.00%",11:void 0,12:void 0,13:void 0,14:"m/d/yyyy",15:"m/d/yyyy",16:"m/d/yyyy",17:"m/d/yyyy",18:"hh:mm:ss a",19:"hh:mm:ss a",20:"hhhh:mm:ss",21:"hhhh:mm:ss",22:"m/d/yy h:mm",37:void 0,38:void 0,39:void 0,40:void 0,45:"hhhh:mm:ss",46:"hhhh:mm:ss",47:"hhhh:mm:ss",48:void 0,49:void 0},em={0:1,"0.00":2,"#,#00":3,"#,##0.00":4,"0%":9,"0.00%":10,"0.00E+00":11,"# ?/?":12,"# ??/??":13,"mm-dd-yy":14,"d-mm-yy":15,"mm-yy":16,"mmm-yy":17,"h:mm AM/PM":18,"h:mm:ss AM/PM":19,"h:mm":20,"h:mm:ss":21,"m/d/yy h:mm":22,"#,##0 ;(#,##0)":37,"#,##0 ;[Red](#,##0)":38,"#,##0.00;(#,##0.00)":39,"#,##0.00;[Red](#,##0.00)":40,"mm:ss":45,"[h]:mm:ss":46,"mmss.0":47,"##0.0E+0":48,"@":49,"hh:mm:ss a":19},tm={0:"000000",1:"FFFFFF",2:"FF0000",3:"00FF00",4:"0000FF",5:"FFFF00",6:"FF00FF",7:"00FFFF",8:"000000",9:"FFFFFF",10:"FF0000",11:"00FF00",12:"0000FF",13:"FFFF00",14:"FF00FF",15:"00FFFF",16:"800000",17:"008000",18:"000080",19:"808000",20:"800080",21:"008080",22:"C0C0C0",23:"808080",24:"9999FF",25:"993366",26:"FFFFCC",27:"CCFFFF",28:"660066",29:"FF8080",30:"0066CC",31:"CCCCFF",32:"000080",33:"FF00FF",34:"FFFF00",35:"00FFFF",36:"800080",37:"800000",38:"008080",39:"0000FF",40:"00CCFF",41:"CCFFFF",42:"CCFFCC",43:"FFFF99",44:"99CCFF",45:"FF99CC",46:"CC99FF",47:"FFCC99",48:"3366FF",49:"33CCCC",50:"99CC00",51:"FFCC00",52:"FF9900",53:"FF6600",54:"666699",55:"969696",56:"003366",57:"339966",58:"003300",59:"333300",60:"993300",61:"993366",62:"333399",63:"333333",64:"000000",65:"FFFFFF"},im={"image/avif":"avif","image/bmp":"bmp","image/gif":"gif","image/vnd.microsoft.icon":"ico","image/jpeg":"jpeg","image/png":"png","image/tiff":"tiff","image/webp":"webp"};function om(e){if(!e)return;let t;if(e.rgb)t=e.rgb;else if(e.auto)t=Sp;else{if(!e.indexed)return;t=tm[e.indexed]}var i;return t=6===(i=t).length?"#"+i+"FF":"#"+i.slice(2)+i.slice(0,2),e.tint&&(t=function(e,t){const i=At(e),o=Ot(i);t<0&&(o.l=o.l*(1+t));t>0&&(o.l=o.l*(1-t)+(100-100*(1-t)));return Tt(Mt(o))}(t,e.tint)),t=t.toUpperCase(),9===t.length&&t.endsWith("FF")&&(t=t.slice(0,7)),t}function nm(e,t){const i=e.split("/"),o=t.split("/");let n="",s=0;for(let e=0;e<i.length-1;e++)i[e]===o[e]?s++:n+="../";return n+=o.slice(s).join("/"),n}function sm(e,t=0){const i={};for(let o=0;o<e.length;o++)e[o]&&(i[o+t]=e[o]);return i}function rm(e){const t=[];for(let i of Object.keys(e).map(Number))t[i]=e[i];return t}function am(e){return e.replace(/_x([0-9a-zA-Z]{4})_/g,((e,t)=>String.fromCharCode(parseInt(t,16))))}const lm=/^(yy|yyyy|m{1,5}|d{1,4}|h{1,2}|s{1,2}|am\/pm|a\/m|\s|-|\/|\.|:)+$/i;function cm(e,t,i){var o,n,s;if(0===e)return;let r=Jp[e]||(null===(o=t.find((t=>t.id===e)))||void 0===o?void 0:o.format);if(r)try{let e=r.replace(/(.*?);.*/,"$1");e=e.replace(/\[(.*)-[A-Z0-9]{3}\]/g,"[$1]"),e=e.replace(/\[\$\]/g,"");const t=(null===(n=e.match(/"/g))||void 0===n?void 0:n.length)||0;if(t/2+((null===(s=e.match(/\[/g))||void 0===s?void 0:s.length)||0)>1)throw new Error("Multiple escaped blocks in format");if(e=e.replace(/"(.*)"/g,"[$$$1]"),e=e.replace(/_.{1}/g,""),e=e.replace(/\*.{1}/g,""),e=e.replace(/\\ /g," "),e=e.replace(/\\./g,(e=>e[1])),function(e){return null!==e.match(lm)}(e)&&(e=function(e){return e=e.toLowerCase(),e=e.replace(/mmmmm/g,"mmm"),e=e.replace(/am\/pm|a\/m/g,"a"),e=e.replace(/hhhh/g,"hh"),e=e.replace(/\bh\b/g,"hh"),e}(e)),function(e){try{return pi(0,e),!0}catch(e){return!1}}(e))return e}catch(e){}i.generateNotSupportedWarning(Pp.NumFmtIdNotSupported,r||`nmFmtId ${e}`)}function hm(e,t){const i=e.borders.map((e=>{!function(e,t){e.diagonal&&t.generateNotSupportedWarning(Pp.DiagonalBorderNotSupported)}(e,t);const i={top:dm(e.top,t),bottom:dm(e.bottom,t),left:dm(e.left,t),right:dm(e.right,t)};return Object.keys(i).forEach((e=>void 0===i[e]&&delete i[e])),i}));return sm(i,1)}function dm(e,t){if(!e)return;!function(e,t){Vp.includes(e.style)||t.generateNotSupportedWarning(Pp.BorderStyleNotSupported,e.style,Vp)}(e,t);const i=Gp[e.style];return i?[i,om(e.color)]:void 0}function um(e,t){return sm(e.styles.map((i=>gm({fontStyle:e.fonts[i.fontId],fillStyle:e.fills[i.fillId],alignment:i.alignment},t))),1)}function gm(e,t){var i,o,n,s,r,a,l,c,h,d,u,g;return function(e,t,i){e&&e.name&&!Bp.includes(e.name)&&i.generateNotSupportedWarning(Pp.FontNotSupported,e.name,Bp);t&&t.patternType&&!Hp.includes(t.patternType)&&i.generateNotSupportedWarning(Pp.FillStyleNotSupported,t.patternType,Hp)}(null==e?void 0:e.fontStyle,null==e?void 0:e.fillStyle,t),function(e,t){e&&!zp.includes(e)&&t.generateNotSupportedWarning(Pp.HorizontalAlignmentNotSupported,e,zp)}(null===(i=null==e?void 0:e.alignment)||void 0===i?void 0:i.horizontal,t),function(e,t){e&&t.generateNotSupportedWarning(Pp.VerticalAlignmentNotSupported)}(null===(o=null==e?void 0:e.alignment)||void 0===o?void 0:o.vertical,t),{bold:null===(n=e.fontStyle)||void 0===n?void 0:n.bold,italic:null===(s=e.fontStyle)||void 0===s?void 0:s.italic,strikethrough:null===(r=e.fontStyle)||void 0===r?void 0:r.strike,underline:null===(a=e.fontStyle)||void 0===a?void 0:a.underline,align:(null===(l=e.alignment)||void 0===l?void 0:l.horizontal)?qp[e.alignment.horizontal]:void 0,fillColor:"solid"===(null===(c=e.fillStyle)||void 0===c?void 0:c.patternType)?om(null===(h=e.fillStyle)||void 0===h?void 0:h.fgColor):om(null===(d=e.fillStyle)||void 0===d?void 0:d.bgColor),textColor:om(null===(u=e.fontStyle)||void 0===u?void 0:u.color),fontSize:null===(g=e.fontStyle)||void 0===g?void 0:g.size}}function pm(e,t){const i=[];for(let o of e.styles){const n=cm(o.numFmtId,e.numFmts,t);n&&(i[o.numFmtId]=n)}return sm(i,1)}function mm(e,t,i){const o=[];let n=1;for(let r of e){if(0===r.cfRules.length)continue;Sm(r,t,i);const e=r.cfRules[0];let a;const l=[];if(void 0!==e.dxfId||"colorScale"===e.type||"iconSet"===e.type){switch(e.type){case"aboveAverage":case"containsErrors":case"notContainsErrors":case"dataBar":case"duplicateValues":case"expression":case"top10":case"uniqueValues":case"timePeriod":continue;case"colorScale":const t=fm(n++,r);t&&o.push(t);continue;case"iconSet":const c=vm(n++,r,i);c&&o.push(c);continue;case"containsText":case"notContainsText":case"beginsWith":case"endsWith":if(!e.text)continue;a=Zp[e.type],l.push(e.text);break;case"containsBlanks":case"notContainsBlanks":a=Zp[e.type];break;case"cellIs":if(!e.operator||!e.formula||0===e.formula.length)continue;a=(s=e.operator).slice(0,1).toUpperCase()+s.slice(1),l.push(e.formula[0]),2===e.formula.length&&l.push(e.formula[1])}a&&void 0!==e.dxfId&&o.push({id:(n++).toString(),ranges:r.sqref,stopIfTrue:e.stopIfTrue,rule:{type:"CellIsRule",operator:a,values:l,style:gm({fontStyle:t[e.dxfId].font,fillStyle:t[e.dxfId].fill},i)}})}}var s;return o}function fm(e,t){const i=t.cfRules[0].colorScale;if(!i||i.cfvos.length!==i.colors.length||i.cfvos.length<2||i.cfvos.length>3)return;const o=[];for(let e=0;e<i.cfvos.length;e++)o.push({color:(n=om(i.colors[e])||"#FFFFFF",9===n.length&&(n=n.slice(0,7)),parseInt(n.replace("#",""),16)),type:jp[i.cfvos[e].type],value:i.cfvos[e].value});var n;const s=o[0],r=2===o.length?o[1]:o[2],a=3===o.length?o[1]:void 0;return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"ColorScaleRule",minimum:s,midpoint:a,maximum:r}}}function vm(e,t,i){const o=t.cfRules[0].iconSet;if(!o)return;let n=o.cfvos,s=o.cfIcons;if(n.length<3||s&&s.length<3)return;n.length>3&&(n=[n[0],n[Math.floor(n.length/2)],n[n.length-1]]),s&&s.length>3&&(s=[s[0],s[Math.floor(s.length/2)],s[s.length-1]]);const r=[];for(let e=1;e<=2;e++){const t=jp[n[e].type];if("value"===t)return;r.push({value:n[e].value||"",operator:n[e].gte?"ge":"gt",type:t})}let a={lower:s?bm(s[0].iconSet,s[0].iconId):bm(o.iconSet,0),middle:s?bm(s[1].iconSet,s[1].iconId):bm(o.iconSet,1),upper:s?bm(s[2].iconSet,s[2].iconId):bm(o.iconSet,2)};o.reverse&&(a={upper:a.lower,middle:a.middle,lower:a.upper});for(let e of Object.keys(a))if(!a[e])switch(i.generateNotSupportedWarning(Pp.CfIconSetEmptyIconNotSupported),e){case"upper":a[e]=xg.dots.good;break;case"middle":a[e]=xg.dots.neutral;break;case"lower":a[e]=xg.dots.bad}return{id:e.toString(),stopIfTrue:t.cfRules[0].stopIfTrue,ranges:t.sqref,rule:{type:"IconSetRule",icons:a,upperInflectionPoint:r[1],lowerInflectionPoint:r[0]}}}function bm(e,t){const i=Xp[e];return i?0===t?xg[i].bad:1===t?xg[i].neutral:xg[i].good:""}function Sm(e,t,i){if(e.cfRules.length>1&&i.generateNotSupportedWarning(Pp.MultipleRulesCfNotSupported),$p.includes(e.cfRules[0].type)||i.generateNotSupportedWarning(Pp.CfTypeNotSupported,e.cfRules[0].type),e.cfRules[0].dxfId){const o=t[e.cfRules[0].dxfId];o.border&&i.generateNotSupportedWarning(Pp.CfFormatBorderNotSupported),o.alignment&&i.generateNotSupportedWarning(Pp.CfFormatAlignmentNotSupported),o.numFmt&&i.generateNotSupportedWarning(Pp.CfFormatNumFmtNotSupported)}}class Cm{constructor(e=new wm){this.scope=e,this.code=""}append(...e){this.code+=e.map((e=>e.toString())).join("\n")+"\n"}return(e){return new Em(this.scope,this.code,e)}toString(){return ym(this.code)}}class Em{constructor(e,t,i){this.scope=e,this.returnExpression=i,this.code=ym(t)}toString(){return this.code}wrapInClosure(){const e=this.scope.nextVariableName(),t=new Cm(this.scope);return t.append(`const ${e} = () => {`),t.append(this.code),t.append(`return ${this.returnExpression};`),t.append("}"),t.return(e)}assignResultToVariable(){if(this.scope.isAlreadyDeclared(this.returnExpression))return this;const e=this.scope.nextVariableName(),t=new Cm(this.scope);return t.append(this.code),t.append(`const ${e} = ${this.returnExpression};`),t.return(e)}}class wm{constructor(){this.nextId=1,this.declaredVariables=new Set}nextVariableName(){const e="_"+this.nextId++;return this.declaredVariables.add(e),e}isAlreadyDeclared(e){return this.declaredVariables.has(e)}}function ym(e){let t="",i=0;const o=e.split("\n").map((e=>e.trim())).filter((e=>""!==e));for(const e of o)e.startsWith("}")&&i--,t+="\t".repeat(i)+e+"\n",e.endsWith("{")&&i++;return t.trim()}const xm=Yu.content,Im=["%"],Rm="+,-,*,/,:,=,<>,>=,>,<=,<,^,&".split(",").concat(Im);function Tm(e){const t=(e=vt(e)).split(""),i=[];for(;t.length;){let e=Pm(t)||Om(t)||_m(t)||Dm(t)||Am(t)||Um(t)||Fm(t)||Lm(t);e||(e={type:"UNKNOWN",value:t.shift()}),i.push(e)}return i}function Am(e){return"?"===e[0]?(e.shift(),{type:"DEBUGGER",value:"?"}):null}const Mm={",":"COMMA","(":"LEFT_PAREN",")":"RIGHT_PAREN"};function Om(e){if(e[0]in Mm){const t=e.shift();return{type:Mm[t],value:t}}return null}function Nm(e,t){for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}function _m(e){for(let t of Rm)if(Nm(e,t))return e.splice(0,t.length),{type:"OPERATOR",value:t};return null}function Fm(e){const t=rt(e).match(Yt);return t?(e.splice(0,t[0].length),{type:"NUMBER",value:t[0]}):null}function Dm(e){if('"'===e[0]){const t=e.shift();let i=t;for(;e[0]&&(e[0]!==t||"\\"===i[i.length-1]);)i+=e.shift();return'"'===e[0]&&(i+=e.shift()),{type:"STRING",value:i}}return null}const km=/\w|\.|!|\$/;function Lm(e){let t="";if("'"===e[0]){let i=e.shift();for(t+=i;e[0];)if(i=e.shift(),t+=i,"'"===i){if(!e[0]||"'"!==e[0])break;i=e.shift(),t+=i}if("'"!==i)return{type:"UNKNOWN",value:t}}for(;e[0]&&e[0].match(km);)t+=e.shift();if(t.length){const e=t;if(e.toUpperCase()in xm)return{type:"FUNCTION",value:e};return e.match(Lt)?{type:"REFERENCE",value:e}:{type:"SYMBOL",value:e}}return null}function Pm(e){let t=0;for(;e[0]===he;)t++,e.shift();if(t)return{type:"SPACE",value:he.repeat(t)};for(;" "===e[0];)t++,e.shift();return t?{type:"SPACE",value:" ".repeat(t)}:null}function Um(e){return Nm(e,K)?(e.splice(0,K.length),{type:"INVALID_REFERENCE",value:K}):null}const Vm=/[a-zA-Z0-9\_]+(\.[a-zA-Z0-9\_]+)*/,zm=["-","+"],Bm=["%"],Hm=["*","+","&"],$m={"^":30,"%":30,"*":20,"/":20,"+":15,"-":15,"&":13,">":10,"<>":10,">=":10,"<":10,"<=":10,"=":10};function Wm(e){var t,i,o;const n=e.shift();if(!n)throw new h(le);switch(n.type){case"DEBUGGER":const r=Zm(e,1e3);return r.debug=!0,r;case"NUMBER":return{type:"NUMBER",value:ni(n.value)};case"STRING":return{type:"STRING",value:Ne(n.value)};case"FUNCTION":const a=function(e){var t;qm(e,"LEFT_PAREN",s("Missing opening parenthesis"));const i=e[0];if("RIGHT_PAREN"===(null==i?void 0:i.type))return qm(e,"RIGHT_PAREN"),[];const o=[];o.push(Gm(e));for(;"RIGHT_PAREN"!==(null===(t=e[0])||void 0===t?void 0:t.type);)qm(e,"COMMA",s("Wrong function call")),o.push(Gm(e));return qm(e,"RIGHT_PAREN"),o}(e);return{type:"FUNCALL",value:n.value,args:a};case"INVALID_REFERENCE":throw new u;case"REFERENCE":if(":"===(null===(t=e[0])||void 0===t?void 0:t.value)&&"REFERENCE"===(null===(i=e[1])||void 0===i?void 0:i.type)){e.shift();const t=e.shift();return{type:"REFERENCE",value:`${n.value}:${null==t?void 0:t.value}`}}return{type:"REFERENCE",value:n.value};case"SYMBOL":if(["TRUE","FALSE"].includes(n.value.toUpperCase()))return{type:"BOOLEAN",value:"TRUE"===n.value.toUpperCase()};if(n.value&&Vm.test(n.value)&&"LEFT_PAREN"===(null===(o=e[0])||void 0===o?void 0:o.type))throw new p(n.value);throw new h(s("Invalid formula"));case"LEFT_PAREN":const l=Zm(e);return qm(e,"RIGHT_PAREN",s("Missing closing parenthesis")),l;case"OPERATOR":const c=n.value;if(zm.includes(c))return{type:"UNARY_OPERATION",value:c,operand:Zm(e,$m[c])};throw new h(s("Unexpected token: %s",n.value));default:throw new h(s("Unexpected token: %s",n.value))}}function Gm(e){const t=e[0];return"COMMA"===(null==t?void 0:t.type)||"RIGHT_PAREN"===(null==t?void 0:t.type)?{type:"EMPTY",value:""}:Zm(e)}function qm(e,t,i=le){const o=e.shift();if(!o||o.type!==t)throw new h(i)}function Zm(e,t=0){var i;if(0===e.length)throw new h(le);let o=Wm(e);for(;"OPERATOR"===(null===(i=e[0])||void 0===i?void 0:i.type)&&$m[e[0].value]>t;){const t=e.shift().value;if(Bm.includes(t))o={type:"UNARY_OPERATION",value:t,operand:o,postfix:!0};else{o={type:"BIN_OPERATION",value:t,left:o,right:Zm(e,$m[t])}}}return o}function jm(e){return Xm(Tm(e))}function Xm(e){"="===(e=e.filter((e=>"SPACE"!==e.type)))[0].value&&e.splice(0,1);const t=Zm(e);if(e.length)throw new h(le);return t}function Ym(e,t,i){switch(t===e.type&&(e=i(e)),e.type){case"FUNCALL":return{...e,args:e.args.map((e=>Ym(e,t,i)))};case"UNARY_OPERATION":return{...e,operand:Ym(e.operand,t,i)};case"BIN_OPERATION":return{...e,right:Ym(e.right,t,i),left:Ym(e.left,t,i)};default:return e}}function Km(e){switch(e.type){case"FUNCALL":const t=e.args.map((e=>Km(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?Qm(e)+e.value:e.value+Jm(e);case"BIN_OPERATION":return Qm(e)+e.value+Jm(e)}}function Qm(e){const t=e.value,i="left"in e?e.left:e.operand,o=i.value;return"BIN_OPERATION"===i.type&&$m[o]<$m[t]?`(${Km(i)})`:Km(i)}function Jm(e){const t=e.value,i="right"in e?e.right:e.operand,o=$m[i.value],n=$m[t];let s=!1;return"BIN_OPERATION"!==i.type?s=!1:o<n?s=!0:o!==n||Hm.includes(t)||(s=!0),s?`(${Km(i)})`:Km(i)}var ef;!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"}(ef||(ef={}));const tf=(e,t=(()=>!0))=>[{goTo:e,guard:t}],of=(e,t=(()=>!0))=>({goTo:e,guard:t}),nf={[ef.LeftRef]:{REFERENCE:tf(ef.Separator),NUMBER:tf(ef.FullRowSeparator),SYMBOL:[of(ef.FullColumnSeparator,(e=>Pt(e.value))),of(ef.FullRowSeparator,(e=>Ut(e.value)))]},[ef.FullColumnSeparator]:{SPACE:tf(ef.FullColumnSeparator),OPERATOR:tf(ef.RightColumnRef,(e=>":"===e.value))},[ef.FullRowSeparator]:{SPACE:tf(ef.FullRowSeparator),OPERATOR:tf(ef.RightRowRef,(e=>":"===e.value))},[ef.Separator]:{SPACE:tf(ef.Separator),OPERATOR:tf(ef.RightRef,(e=>":"===e.value))},[ef.RightRef]:{SPACE:tf(ef.RightRef),NUMBER:tf(ef.Found),REFERENCE:tf(ef.Found,(e=>zt(e.value))),SYMBOL:tf(ef.Found,(e=>Vt(e.value)))},[ef.RightColumnRef]:{SPACE:tf(ef.RightColumnRef),SYMBOL:tf(ef.Found,(e=>Vt(e.value))),REFERENCE:tf(ef.Found,(e=>zt(e.value)))},[ef.RightRowRef]:{SPACE:tf(ef.RightRowRef),NUMBER:tf(ef.Found),REFERENCE:tf(ef.Found,(e=>zt(e.value)))},[ef.Found]:{}};function sf(e){var t;let i=0,o=nf[ef.LeftRef];const n=[];for(;void 0!==o;){const s=e[i++];if(!s)return null;const r=null===(t=o[s.type])||void 0===t?void 0:t.find((e=>e.guard(s))),a=r?r.goTo:void 0;switch(a){case void 0:return null;case ef.Found:return n.push(s),e.splice(0,i),{type:"REFERENCE",value:rt(n.map((e=>e.value)))};default:o=nf[a],n.push(s)}}return null}function rf(e){const t=Tm(e),i=[];for(;t.length;)i.push(sf(t)||t.shift());return i}const af=Yu.content,lf={"=":"EQ","+":"ADD","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",">=":"GTE","<>":"NE",">":"GT","<=":"LTE","<":"LT","^":"POWER","&":"CONCATENATE"},cf={"-":"UMINUS","+":"UPLUS","%":"UNARY.PERCENT"},hf={};function df(e){const t=rf(e),{dependencies:i,constantValues:o}=function(e){const t={numbers:[],strings:[]},i=[];for(const o of e)switch(o.type){case"INVALID_REFERENCE":case"REFERENCE":i.push(o.value);break;case"STRING":const e=Ne(o.value);t.strings.includes(e)||t.strings.push(e);break;case"NUMBER":{const e=ni(o.value);t.numbers.includes(e)||t.numbers.push(e);break}}return{dependencies:i,constantValues:t}}(t),n=function(e,t,i){return rt(e.map((e=>{switch(e.type){case"STRING":const o=Ne(e.value);return`|S${i.strings.indexOf(o)}|`;case"NUMBER":return`|N${i.numbers.indexOf(ni(e.value))}|`;case"REFERENCE":case"INVALID_REFERENCE":return`|${t.indexOf(e.value)}|`;case"SPACE":return"";default:return e.value}})))}(t,i,o);if(!hf[n]){const r=Xm([...t]),a=new wm;if("BIN_OPERATION"===r.type&&":"===r.value)throw new h(s("Invalid formula"));if("EMPTY"===r.type)throw new h(s("Invalid formula"));const l=g(r),c=new Cm;c.append(`// ${n}`),c.append(l),c.append(`return ${l.returnExpression};`);let d=new Function("deps","ref","range","ctx",c.toString());function u(e){const t=af[e.value.toUpperCase()],i=e.args,o=i.length;if(o<t.minArgRequired)throw new h(s("Invalid number of arguments for the %s function. Expected %s minimum, but got %s instead.",e.value.toUpperCase(),t.minArgRequired.toString(),o.toString()));if(o>t.maxArgPossible)throw new h(s("Invalid number of arguments for the %s function. Expected %s maximum, but got %s instead.",e.value.toUpperCase(),t.maxArgPossible.toString(),o.toString()));const n=t.nbrArgRepeating;if(n>1){const i=t.args.length-n;if((o-i)%n!=0)throw new h(s("Invalid number of arguments for the %s function. Expected all arguments after position %s to be supplied by groups of %s arguments",e.value.toUpperCase(),i.toString(),n.toString()))}let r=[];for(let n=0;n<o;n++){const o=t.getArgToFocus(n+1)-1;if(0<=o&&o<t.args.length){const a=i[n],l=t.args[o],c=l.type||[],d=c.includes("META"),u=l.lazy,p=c.some((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e)),m=c.every((e=>"RANGE"===e||"RANGE<BOOLEAN>"===e||"RANGE<DATE>"===e||"RANGE<NUMBER>"===e||"RANGE<STRING>"===e));if(m&&"REFERENCE"!==a.type)throw new h(s("Function %s expects the parameter %s to be reference to a cell or range, not a %s.",e.value.toUpperCase(),(n+1).toString(),a.type.toLowerCase()));const f=g(a,d,p,{functionName:e.value.toUpperCase(),paramIndex:n+1});r.push(u?f.wrapInClosure():f)}}return r}function g(e,t=!1,n=!1,r={}){const l=new Cm(a);if("REFERENCE"!==e.type&&("BIN_OPERATION"!==e.type||":"!==e.value)&&t)throw new h(s("Argument must be a reference to a cell or range."));switch(e.debug&&l.append("debugger;"),e.type){case"BOOLEAN":return l.return(`{ value: ${e.value} }`);case"NUMBER":return l.return(`{ value: this.constantValues.numbers[${o.numbers.indexOf(e.value)}] }`);case"STRING":return l.return(`{ value: this.constantValues.strings[${o.strings.indexOf(e.value)}] }`);case"REFERENCE":const s=i.indexOf(e.value);return n?l.return(`range(deps[${s}])`):l.return(`ref(deps[${s}], ${t?"true":"false"}, "${r.functionName||lf["="]}", ${r.paramIndex})`);case"FUNCALL":const a=u(e).map((e=>e.assignResultToVariable()));l.append(...a);const c=e.value.toUpperCase();return l.append(`ctx.__lastFnCalled = '${c}';`),l.return(`ctx['${c}'](${a.map((e=>e.returnExpression))})`);case"UNARY_OPERATION":{const t=cf[e.value],i=g(e.operand,!1,!1,{functionName:t}).assignResultToVariable();return l.append(i),l.append(`ctx.__lastFnCalled = '${t}';`),l.return(`ctx['${t}'](${i.returnExpression})`)}case"BIN_OPERATION":{const t=lf[e.value],i=g(e.left,!1,!1,{functionName:t}).assignResultToVariable(),o=g(e.right,!1,!1,{functionName:t}).assignResultToVariable();return l.append(i),l.append(o),l.append(`ctx.__lastFnCalled = '${t}';`),l.return(`ctx['${t}'](${i.returnExpression}, ${o.returnExpression})`)}case"EMPTY":return l.return("undefined")}}hf[n]={execute:d}}return{execute:hf[n].execute,dependencies:i,constantValues:o,tokens:t}}function uf(e){return function(e){let t=[],i="";return e.map(((e,o)=>{switch(["SPACE","LEFT_PAREN"].includes(e.type)||(i=""),e.type){case"FUNCTION":i=e.value;break;case"LEFT_PAREN":t.push({parent:i,argPosition:0}),i="";break;case"RIGHT_PAREN":t.pop();break;case"COMMA":t.length&&t[t.length-1].argPosition++}if(t.length){const i=t[t.length-1];i.parent&&(e.functionContext=Object.assign({},i))}return e}))}(function(e){let t=1;const i=[];return e.map((e=>("LEFT_PAREN"===e.type?(i.push(t),e.parenIndex=t,t++):"RIGHT_PAREN"===e.type&&(e.parenIndex=i.pop()),e)))}(function(e){let t=0;return e.map((e=>{const i=e.value.toString().length,o=Object.assign({},e,{start:t,end:t+i,length:i});return t=o.end,o}))}(rf(e))))}function gf(e){switch(e){case"IsNotEmpty":case"NotContains":return"notContainsBlanks";case"IsEmpty":return"containsBlanks";default:return e.charAt(0).toLowerCase()+e.slice(1)}}function pf(e){return Math.round(Tp*e*100)/100}function mf(e){return Math.round(Ap*e*100)/100}function ff(e){if(e)return{style:e[0],color:{rgb:e[1]}}}function vf(e,t){let i={};e.style&&(i=t.styles[e.style]);const o=function(e,t){if(e.format)return t.formats[e.format];if(e.isFormula){const t=Tm(e.content||""),i=Yu.content;if(!t.filter((e=>"FUNCTION"===e.type)).every((e=>i[e.value.toUpperCase()].isExported)))return e.computedFormat}return}(e,t),n={};if(e.border){const i=t.borders[e.border];n.left=ff(i.left),n.right=ff(i.right),n.bottom=ff(i.bottom),n.top=ff(i.top)}const s={font:{size:(null==i?void 0:i.fontSize)||q,color:{rgb:(null==i?void 0:i.textColor)?i.textColor:"000000"},family:2,name:"Arial"},fill:(null==i?void 0:i.fillColor)?{fgColor:{rgb:i.fillColor}}:{reservedAttribute:"none"},numFmt:o?{format:o,id:0}:void 0,border:n||{},alignment:{vertical:"center",horizontal:i.align}};return s.font.strike=!!(null==i?void 0:i.strikethrough)||void 0,s.font.underline=!!(null==i?void 0:i.underline)||void 0,s.font.bold=!!(null==i?void 0:i.bold)||void 0,s.font.italic=!!(null==i?void 0:i.italic)||void 0,s}function bf(e,t){const{id:i}=Cf(t.font,e.fonts),{id:o}=Cf(t.fill,e.fills),{id:n}=Cf(t.border,e.borders),s=function(e,t){if(!e)return 0;let i=em[e.format];if(!i){const{id:o}=Cf(e,t);i=o+Fp}return i}(t.numFmt,e.numFmts),r={fontId:i,fillId:o,borderId:n,numFmtId:s,alignment:{vertical:t.alignment.vertical,horizontal:t.alignment.horizontal}},{id:a}=Cf(r,e.styles);return a}function Sf(e,t,i){let o,n=e.find((e=>e.path===t));return n?(o=`rId${(n.rels.length+1).toString()}`,n.rels.push({...i,id:o})):(o="rId1",e.push({path:t,rels:[{...i,id:o}]})),o}function Cf(e,t){for(let[i,o]of Object.entries(t))if(JSON.stringify(o)===JSON.stringify(e))return{id:parseInt(i,10),list:t};let i=t.findIndex((t=>JSON.stringify(t)===JSON.stringify(e)));return-1===i&&(t.push(e),i=t.length-1),{id:i,list:t}}const Ef=[];function wf(e){const t=Ef.findIndex((t=>t===e));return-1===t?(Ef.push(e),Ef.length):t+1}const yf=[];function xf(e){const t=yf.findIndex((t=>t===e));return-1===t?(yf.push(e),yf.length):t+1}function If(e){return Math.round(914400*e/96)}function Rf(e,t,i){let o,n,s=e;if(({xc:s,sheetName:o}=Bt(e)),o){const e=i.sheets.findIndex((e=>e.name===o));if(e<0)throw new Error("Unable to find a sheet with the name "+o);n=e}else n=Number(t);const r=Vi(s);return void 0===r.right&&(r.right=i.sheets[n].colNumber),void 0===r.bottom&&(r.bottom=i.sheets[n].rowNumber),(r.right-r.left+1)*(r.bottom-r.top+1)}function Tf(e){return Math.round(96*e/914400)}function Af(e,t){var i;let o=0;for(let n=0;n<e;n++){const e=t.cols.find((e=>n>=e.min&&n<=e.max));(null==e?void 0:e.width)?o+=e.width:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?o+=t.sheetFormat.defaultColWidth:o+=Mp}return o/Ap}function Mf(e,t){var i;let o=0;for(let n=0;n<e;n++){const e=t.rows[n];(null==e?void 0:e.height)?o+=e.height:(null===(i=t.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?o+=t.sheetFormat.defaultRowHeight:o+=Op}return o/Tp}function Of(e){let t=1;return e.figures.map((i=>function(e,t,i){const o=Af(e.anchors[0].col,i)+Tf(e.anchors[0].colOffset),n=Af(e.anchors[1].col,i)+Tf(e.anchors[1].colOffset),s=Mf(e.anchors[0].row,i)+Tf(e.anchors[0].rowOffset),r=Mf(e.anchors[1].row,i)+Tf(e.anchors[1].rowOffset),a=n-o,l=r-s,c=Nf(e.data);return c?{id:t,x:o,y:s,width:a,height:l,tag:"chart",data:Nf(e.data)}:void 0}(i,(t++).toString(),e))).filter(ot)}function Nf(e){var t;const i=null===(t=e.dataSets[0].label)||void 0===t?void 0:t.replace(/\$/g,"");let o=e.dataSets.map((e=>e.range.replace(/\$/g,"")));return"pie"===e.type&&o.reverse(),{dataSets:o,dataSetsHaveTitle:!1,labelRange:i,title:e.title||"",type:e.type,background:om({rgb:e.backgroundColor})||"#FFFFFF",verticalAxisPosition:e.verticalAxisPosition,legendPosition:e.legendPosition,stacked:e.stacked||!1,aggregated:!1,cumulative:e.cumulative||!1,labelsAsText:!1}}const _f=new RegExp(/'?\[([0-9]*)\](.*)'?!(\$?[a-zA-Z]*\$?[0-9]*)/g),Ff=new RegExp(/SUBTOTAL\(([0-9]*),/g),Df=new RegExp(Nt.source,"ig");function kf(e,t){const i=function(e){const t={};for(let i of e.rows)for(let e of i.cells)e.formula&&void 0!==e.formula.sharedIndex&&e.formula.content&&(t[e.formula.sharedIndex]={refCellXc:e.xc,formula:e.formula.content});return t}(e);for(let o of e.rows.map((e=>e.cells)).flat())(null==o?void 0:o.formula)&&(o.formula.content=void 0===o.formula.sharedIndex||o.formula.content?"="+o.formula.content:"="+Pf(o.xc,i[o.formula.sharedIndex]),o.formula.content=Lf(o.formula.content,t))}function Lf(e,t){return e=(e=(e=(e=e.replace("_xlfn.","")).replace(/#REF!/g,"#REF")).replace(Ff,((e,t)=>{const i=Qp[t];return i?i+"(":e}))).replace(_f,((e,i,o,n)=>{var s;i=Number(i)-1,n=n.replace(/\$/g,"");const r=t.externalBooks[i].sheetNames.findIndex((e=>e===o));if(-1===r)return e;const a=null===(s=t.externalBooks[i].datasets.find((e=>e.sheetId===r)))||void 0===s?void 0:s.data;if(!a)return e;const l=a&&a[n];return(Number(l)?l:`"${l}"`)||e}))}function Pf(e,t){const i=Wt(t.refCellXc);let o,n=t.formula.slice();do{if(o=Df.exec(n),o){const t=Wt(o[0].replace("$","")),s=Wt(e),r={colFixed:o[0].startsWith("$"),rowFixed:o[0].includes("$",1)},a={col:s.col-i.col,row:s.row-i.row},l={col:r.colFixed?t.col:t.col+a.col,row:r.rowFixed?t.row:t.row+a.row};n=n.slice(0,o.index)+Gt(l.col,l.row,r)+n.slice(o.index+o[0].length)}}while(o);return n}function Uf(e,t){return e.sheets.map((i=>{kf(i,e);const o=function(e){const t=[0,0];for(let i of e.rows)t[0]=Math.max(t[0],...i.cells.map((e=>Wt(e.xc).col))),t[1]=Math.max(t[1],i.index);return t[0]=Math.max(t[0],Np),t[1]=Math.max(t[1],_p),t}(i),n=i.sheetViews[0];return{id:i.sheetName,areGridLinesVisible:!n||n.showGridLines,name:i.sheetName,colNumber:o[0],rowNumber:o[1],cells:Bf(i,e,o,t),merges:i.merges,cols:Vf(i,o[0]),rows:zf(i,o[1]),conditionalFormats:mm(i.cfs,e.dxfs,t),figures:Of(i),isVisible:i.isVisible,panes:n?{xSplit:n.pane.xSplit,ySplit:n.pane.ySplit}:{xSplit:0,ySplit:0},filterTables:[]}}))}function Vf(e,t){var i;const o={};for(let s=1;s<t+1;s++){const t=e.cols.find((e=>e.min<=s&&s<=e.max));let r;r=t&&t.width?t.width:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultColWidth)?e.sheetFormat.defaultColWidth:Mp,o[s-1]={size:(n=r,n?Math.round(n/Ap*100)/100:n),isHidden:null==t?void 0:t.hidden}}var n;return o}function zf(e,t){var i;const o={};for(let s=1;s<t+1;s++){const t=e.rows.find((e=>e.index===s));let r;r=t&&t.height?t.height:(null===(i=e.sheetFormat)||void 0===i?void 0:i.defaultRowHeight)?e.sheetFormat.defaultRowHeight:Op,o[s-1]={size:(n=r,n?Math.round(n/Tp*100)/100:n),isHidden:null==t?void 0:t.hidden}}var n;return o}function Bf(e,t,i,o){const n={},s=t.sharedStrings.map((e=>e.replace(/\n/g,"")));const r=e.hyperlinks.reduce(((e,t)=>(e[t.xc]=t,e)),{});for(let i of e.rows)for(let e of i.cells)n[e.xc]={content:Hf(e,r,s,o),style:e.styleIndex?e.styleIndex+1:void 0,border:e.styleIndex?t.styles[e.styleIndex].borderId+1:void 0,format:e.styleIndex?t.styles[e.styleIndex].numFmtId+1:void 0};for(let o of e.rows.filter((e=>e.styleIndex)))for(let e=1;e<=i[0];e++){const i=Gt(e-1,o.index-1);let s=n[i];s||(s={},n[i]=s),s.style=s.style?s.style:o.styleIndex+1,s.border=s.border?s.border:t.styles[o.styleIndex].borderId+1,s.format=s.format?s.format:t.styles[o.styleIndex].numFmtId+1}for(let o of e.cols.filter((e=>e.styleIndex)))for(let e=o.min;e<=Math.min(o.max,i[0]);e++)for(let s=1;s<=i[1];s++){const i=Gt(e-1,s-1);let r=n[i];r||(r={},n[i]=r),r.style=r.style?r.style:o.styleIndex+1,r.border=r.border?r.border:t.styles[o.styleIndex].borderId+1,r.format=r.format?r.format:t.styles[o.styleIndex].numFmtId+1}return n}function Hf(e,t,i,o){let n;switch(e.type){case"sharedString":n=i[parseInt(e.value,10)];break;case"boolean":n=Number(e.value)?"TRUE":"FALSE";break;case"date":case"error":case"inlineStr":case"number":case"str":n=e.value}return n&&t[e.xc]&&(n=function(e,t,i){const o=e.display||t;e.relTarget||e.location||i.generateNotSupportedWarning(Pp.BadlyFormattedHyperlink);const n=e.relTarget?e.relTarget:tt(Bt(e.location).sheetName);return Ke(o,n)}(t[e.xc],n,o)),e.formula&&(n=e.formula.content),n}const $f={fillColor:"#000000",textColor:"#ffffff",bold:!0},Wf={bold:!0},Gf=["thin","#000000FF"];function qf(e,t){for(const i of t.sheets)for(const t of i.tables){const o=e.sheets.find((e=>e.name===i.sheetName));o&&t.autoFilter&&(o.filterTables||(o.filterTables=[]),o.filterTables.push({range:t.ref}))}!function(e,t){var i,o,n,s;const r=rm(e.styles),a=rm(e.borders);for(let l of t.sheets)for(let t of l.tables){const c=e.sheets.find((e=>e.name===l.sheetName));if(!c)continue;const h=zi(t.ref);for(let e=0;e<t.headerRowCount;e++)Zf($f,{...h,bottom:h.top+e},c.cells,r);for(let e=0;e<t.totalsRowCount;e++)Zf(Wf,{...h,top:h.bottom-e},c.cells,r);(null===(i=t.style)||void 0===i?void 0:i.showFirstColumn)&&Zf(Wf,{...h,right:h.left},c.cells,r),(null===(o=t.style)||void 0===o?void 0:o.showLastColumn)&&Zf(Wf,{...h,left:h.right},c.cells,r);for(let e=h.left;e<=h.right;e++)for(let i=h.top;i<=h.bottom;i++){const o=Gt(e,i),r=c.cells[o],l={left:e===h.left||(null===(n=t.style)||void 0===n?void 0:n.showColumnStripes)?Gf:void 0,right:e===h.right?Gf:void 0,top:i===h.top||(null===(s=t.style)||void 0===s?void 0:s.showRowStripes)||i>h.bottom-t.totalsRowCount?Gf:void 0,bottom:i===h.bottom?Gf:void 0},d=(null==r?void 0:r.border)?{...a[r.border],...l}:l;let u=a.findIndex((e=>ht(e,d)));-1===u&&(u=a.length,a.push(d)),r?r.border=u:c.cells[o]={border:u}}}e.styles=sm(r),e.borders=sm(a)}(e,t),function(e,t){for(let i of e){const e=t.find((e=>e.sheetName===i.name)).tables;for(let t of e){const e=t.name+"[";for(let o of oo(zi(t.ref))){const n=Gt(o.col,o.row),s=i.cells[n];if(s&&s.content&&s.content.startsWith("=")){let i;for(;-1!==(i=s.content.indexOf(e));){let o=s.content.slice(i+e.length),r=o.indexOf("]");o.startsWith("[")&&(r=o.indexOf("]",r+1),r=o.indexOf("]",r+1)),o=o.slice(0,r);const a=jf(o,t,n);s.content=s.content.slice(0,i)+a+s.content.slice(e.length+i+r+1)}}}}}}(e.sheets,t.sheets)}function Zf(e,t,i,o){for(let n=t.left;n<=t.right;n++)for(let s=t.top;s<=t.bottom;s++){const t=Gt(n,s),r=i[t],a=(null==r?void 0:r.style)?{...o[r.style],...e}:e;let l=o.findIndex((e=>ht(e,a)));-1===l&&(l=o.length,o.push(a)),r?r.style=l:i[t]={style:l}}}function jf(e,t,i){const o=e.split(","),n=zi(t.ref),s={...n};let r=!0;if(1===o.length){const e=t.cols.findIndex((e=>e.name===o[0]));s.left=s.right=e+n.left,t.headerRowCount&&(s.top+=t.headerRowCount),t.totalsRowCount&&(s.bottom-=1)}else{switch(o[0].slice(1,o[0].length-1)){case"#All":s.top=t.headerRowCount?n.top+t.headerRowCount:n.top,s.bottom=n.bottom;break;case"#Data":s.top=t.headerRowCount?n.top+t.headerRowCount:n.top,s.bottom=t.totalsRowCount?n.bottom+1:n.bottom;break;case"#This Row":s.top=s.bottom=Wt(i).row;break;case"#Headers":s.top=s.bottom=n.top,t.headerRowCount||(r=!1);break;case"#Totals":s.top=s.bottom=n.bottom,t.totalsRowCount||(r=!1)}const e=o[1].slice(1,o[1].length-1),a=t.cols.findIndex((t=>t.name===e));s.left=s.right=a+n.left}return r?s.top!==s.bottom?Hi(s):Gt(s.left,s.top):K}function Xf(e,t,i){return{content:(new XMLSerializer).serializeToString(e),path:t,contentType:i}}function Yf(e){return String(e).replace(/\&/g,"&").replace(/\</g,"<").replace(/\>/g,">").replace(/\"/g,""").replace(/\'/g,"'").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function Kf(e){return new vp(e.map((([e,t])=>`${e}="${Yf(t)}"`)).join(" "))}function Qf(e,t="text/xml"){const i=(new DOMParser).parseFromString(e.toString(),t),o=i.querySelector("parsererror");if(o){const t=o.innerHTML,i=parseInt(t.split(":")[0],10),n=e.toString().trim().split("\n"),s=n.slice(Math.max(i-3,0),Math.min(i+2,n.length)).join("\n");throw new Error(`XML string could not be parsed: ${t}\n${s}`)}return i}function Jf(e,t){return tv`
|
|
1399
1399
|
<Override ContentType="${t}" PartName="${e}" />
|
|
1400
|
-
`}function ev(e){return new vp(e.join("\n"))}function tv(e,...t){let i=[e[0]];for(let o=0;o<t.length;o++){const n=t[o]instanceof vp?t[o]:Yf(t[o]);i.push(n+e[o+1])}return new vp(rt(i))}function iv(e){return e.replace(/[a-z0-9]+:(?=[a-z0-9]+)/gi,"")}function ov(e){return e.replace(/([a-z0-9]+):(?=[a-z0-9]+)/gi,"$1\\:")}class nv{constructor(e){this.value=e}asString(){return am(String(this.value))}asBool(){return Boolean(Number(this.value))}asNum(){return Number(this.value)}}class sv{constructor(e,t,i){this.currentFile=void 0,this.rootFile=e,this.currentFile=e.file.fileName,this.xlsxFileStructure=t,this.warningManager=i,this.areNamespaceIgnored=null!==(new DOMParser).parseFromString("<t:test xmlns:t='a'/>","text/xml").querySelector("test"),this.relationships={},e.rels&&this.extractRelationships(e.rels).map((e=>{this.relationships[e.id]=e}))}extractRelationships(e){return this.mapOnElements({parent:e.xml,query:"Relationship"},(e=>({id:this.extractAttr(e,"Id",{required:!0}).asString(),target:this.extractAttr(e,"Target",{required:!0}).asString(),type:this.extractAttr(e,"Type",{required:!0}).asString()})))}getListOfFiles(){return Object.values(this.xlsxFileStructure).flat().filter(ot)}mapOnElements(e,t){var i;const o=[],n=this.currentFile;let s;if(e.children){const t=null===(i=this.querySelector(e.parent,e.query))||void 0===i?void 0:i.children;s=t||[]}else s=this.querySelectorAll(e.parent,e.query);if(s)for(let e of s)try{o.push(t(e))}catch(t){this.catchErrorOnElement(t,e)}return this.currentFile=n,o}catchErrorOnElement(e,t){const i=t?`Error when parsing an element <${t.tagName}> of file ${this.currentFile}, skip this element. \n${e.stack}`:`Error when parsing file ${this.currentFile}.`;this.warningManager.addParsingWarning([i,e.message].join("\n"))}extractAttr(e,t,i){const o=e.attributes[t];o||this.handleMissingValue(e,`attribute "${t}"`,i);const n=(null==o?void 0:o.value)?o.value:null==i?void 0:i.default;return void 0===n?void 0:new nv(n)}extractTextContent(e,t){var i;if(void 0!==(null==t?void 0:t.default)&&"string"!=typeof t.default)throw new Error("extractTextContent default value should be a string");const o="preserve"===(null===(i=null==e?void 0:e.attributes["xml:space"])||void 0===i?void 0:i.value);let n=null==e?void 0:e.textContent;return e&&null!==n||this.handleMissingValue(e,"text content",t),n&&(n=o?n:n.trim()),n?am(n):null==t?void 0:t.default}extractChildAttr(e,t,i,o){var n;let s;s="number"==typeof t?e.children[t]:this.querySelector(e,t),s||this.handleMissingValue(e,"number"==typeof t?`child at index ${t}`:`child <${t}>`,o);const r=s?null===(n=this.extractAttr(s,i,o))||void 0===n?void 0:n.asString():null==o?void 0:o.default;return void 0!==r?new nv(r):void 0}extractChildTextContent(e,t,i){if(void 0!==(null==i?void 0:i.default)&&"string"!=typeof i.default)throw new Error("extractTextContent default value should be a string");let o=this.querySelector(e,t);return o||this.handleMissingValue(e,`child <${t}>`,i),o?this.extractTextContent(o,i):null==i?void 0:i.default}handleMissingValue(e,t,i){if(null==i?void 0:i.required){if(!(null==i?void 0:i.default))throw new Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`);this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${i.default}`)}}extractColor(e,t,i){var o,n,s,r,a;if(!e)return i?{rgb:i}:void 0;const l=null===(o=this.extractAttr(e,"theme"))||void 0===o?void 0:o.asString();let c;if(void 0!==l){if(!t||!t.clrScheme)throw new Error("Color referencing a theme but no theme was provided");c=this.getThemeColor(l,t.clrScheme)}else c=null===(n=this.extractAttr(e,"rgb"))||void 0===n?void 0:n.asString();return{rgb:c,auto:null===(s=this.extractAttr(e,"auto"))||void 0===s?void 0:s.asBool(),indexed:null===(r=this.extractAttr(e,"indexed"))||void 0===r?void 0:r.asNum(),tint:null===(a=this.extractAttr(e,"tint"))||void 0===a?void 0:a.asNum()}}getTargetXmlFile(e){if(!e)throw new Error("Undefined target file");let t=e.target;t=t.replace("../",""),t=t.replace("./","");const i=this.getListOfFiles().find((e=>e.file.fileName.endsWith(t)));if(!i||!i.file)throw new Error("Cannot find target file");return i}querySelector(e,t){return t=this.areNamespaceIgnored?iv(t):ov(t),e.querySelector(t)}querySelectorAll(e,t){return t=this.areNamespaceIgnored?iv(t):ov(t),e.querySelectorAll(t)}getThemeColor(e,t){switch(e){case"0":return"FFFFFF";case"1":return"000000";case"2":return t[3].value;case"3":return t[2].value;default:return t[e].value}}}class rv extends sv{getTheme(){return{clrScheme:this.mapOnElements({query:"a:clrScheme",parent:this.rootFile.file.xml,children:!0},(e=>({name:e.tagName,value:this.extractChildAttr(e,0,"val",{required:!0,default:Sp}).asString(),lastClr:this.extractChildAttr(e,0,"lastClr",{default:Sp}).asString()})))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"si"},(e=>"t"===e.children[0].tagName?this.extractTextContent(e)||"":this.mapOnElements({parent:e,query:"t"},(e=>this.extractTextContent(e)||"")).join("")))}}class av extends sv{constructor(e,t,i,o){super(e,t,i),this.theme=o}extractConditionalFormattings(){const e=this.mapOnElements({parent:this.rootFile.file.xml,query:"worksheet > conditionalFormatting"},(e=>{var t;return{sqref:this.extractAttr(e,"sqref",{required:!0}).asString().split(" "),pivot:null===(t=this.extractAttr(e,"pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:"extLst x14:conditionalFormatting"},(e=>{var t;return{sqref:this.extractChildTextContent(e,"xm:sqref",{required:!0}).split(" "),pivot:null===(t=this.extractAttr(e,"xm:pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:"cfRule, x14:cfRule"},(e=>{var i,o,n,s,r,a,l,c,h,d,u;const g=this.extractAttr(e,"type",{required:!0}).asString();if("dataBar"===g)throw new Error("Databars conditional formats are not supported.");return{type:g,priority:this.extractAttr(e,"priority",{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:null===(i=this.extractAttr(e,"dxfId"))||void 0===i?void 0:i.asNum(),stopIfTrue:null===(o=this.extractAttr(e,"stopIfTrue"))||void 0===o?void 0:o.asBool(),aboveAverage:null===(n=this.extractAttr(e,"aboveAverage"))||void 0===n?void 0:n.asBool(),percent:null===(s=this.extractAttr(e,"percent"))||void 0===s?void 0:s.asBool(),bottom:null===(r=this.extractAttr(e,"bottom"))||void 0===r?void 0:r.asBool(),operator:null===(a=this.extractAttr(e,"operator"))||void 0===a?void 0:a.asString(),text:null===(l=this.extractAttr(e,"text"))||void 0===l?void 0:l.asString(),timePeriod:null===(c=this.extractAttr(e,"timePeriod"))||void 0===c?void 0:c.asString(),rank:null===(h=this.extractAttr(e,"rank"))||void 0===h?void 0:h.asNum(),stdDev:null===(d=this.extractAttr(e,"stdDev"))||void 0===d?void 0:d.asNum(),equalAverage:null===(u=this.extractAttr(e,"equalAverage"))||void 0===u?void 0:u.asBool()}}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:"formula"},(e=>this.extractTextContent(e,{required:!0})))}extractCfColorScale(e,t){const i=this.querySelector(e,"colorScale");if(i)return{colors:this.mapOnElements({parent:i,query:"color"},(e=>this.extractColor(e,t,"ffffff"))),cfvos:this.extractCFVos(i)}}extractCfIconSet(e){var t,i;const o=this.querySelector(e,"iconSet, x14:iconSet");if(o)return{iconSet:this.extractAttr(o,"iconSet",{default:"3TrafficLights1"}).asString(),showValue:this.extractAttr(o,"showValue",{default:!0}).asBool(),percent:this.extractAttr(o,"percent",{default:!0}).asBool(),reverse:null===(t=this.extractAttr(o,"reverse"))||void 0===t?void 0:t.asBool(),custom:null===(i=this.extractAttr(o,"custom"))||void 0===i?void 0:i.asBool(),cfvos:this.extractCFVos(o),cfIcons:this.extractCfIcons(o)}}extractCfIcons(e){const t=this.mapOnElements({parent:e,query:"cfIcon, x14:cfIcon"},(e=>({iconSet:this.extractAttr(e,"iconSet",{required:!0}).asString(),iconId:this.extractAttr(e,"iconId",{required:!0}).asNum()})));return 0===t.length?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:"cfvo, x14:cfvo"},(e=>{var t,i;return{type:this.extractAttr(e,"type",{required:!0}).asString(),gte:null===(t=this.extractAttr(e,"gte",{default:!0}))||void 0===t?void 0:t.asBool(),value:e.attributes.val?null===(i=this.extractAttr(e,"val"))||void 0===i?void 0:i.asString():this.extractChildTextContent(e,"f, xm:f")}}))}}class lv extends sv{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"c:chartSpace"},(e=>{const t=this.getChartType(e);if(!Kp[t])throw new Error(`Unsupported chart type ${t}`);const i=this.mapOnElements({parent:e,query:"c:title a:t"},(e=>e.textContent||"")).join(""),o=this.extractChildAttr(e,"c:grouping","val",{default:"clustered"}).asString();return{title:i,type:Kp[t],dataSets:this.extractChartDatasets(this.querySelector(e,`c:${t}`)),backgroundColor:this.extractChildAttr(e,"c:chartSpace > c:spPr a:srgbClr","val",{default:"ffffff"}).asString(),verticalAxisPosition:"r"===this.extractChildAttr(e,"c:valAx > c:axPos","val",{default:"l"}).asString()?"right":"left",legendPosition:Yp[this.extractChildAttr(e,"c:legendPos","val",{default:"b"}).asString()],stacked:"stacked"===o,fontColor:"000000"}}))[0]}extractChartDatasets(e){return this.mapOnElements({parent:e,query:"c:ser"},(e=>({label:this.extractChildTextContent(e,"c:cat c:f"),range:this.extractChildTextContent(e,"c:val c:f",{required:!0})})))}getChartType(e){const t=this.querySelector(e,"c:plotArea");if(!t)throw new Error("Missing plot area in the chart definition.");for(let e of t.children){const t=iv(e.tagName);if(bp.some((e=>e===t)))return t}throw new Error("Unknown chart type")}}class cv extends sv{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"xdr:wsDr",children:!0},(e=>{if("twoCellAnchor"!==iv(e.tagName))throw new Error("Only twoCellAnchor are supported for xlsx drawings.");const t=this.querySelector(e,"c:chart");if(!t)throw new Error("Only chart figures are currently supported.");return{anchors:[this.extractFigureAnchor("xdr:from",e),this.extractFigureAnchor("xdr:to",e)],data:this.extractChart(t)}}))}extractFigureAnchor(e,t){const i=this.querySelector(t,e);if(!i)throw new Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(i,"xdr:col",{required:!0})),colOffset:Number(this.extractChildTextContent(i,"xdr:colOff",{required:!0})),row:Number(this.extractChildTextContent(i,"xdr:row",{required:!0})),rowOffset:Number(this.extractChildTextContent(i,"xdr:rowOff",{required:!0}))}}extractChart(e){const t=this.extractAttr(e,"r:id",{required:!0}).asString(),i=this.getTargetXmlFile(this.relationships[t]),o=new lv(i,this.xlsxFileStructure,this.warningManager).extractChart();if(!o)throw new Error("Unable to extract chart definition");return o}}class hv extends sv{getPivotTable(){return this.mapOnElements({query:":root",parent:this.rootFile.file.xml},(e=>({displayName:this.extractAttr(e,"name",{required:!0}).asString(),id:this.extractAttr(e,"name",{required:!0}).asString(),ref:this.extractChildAttr(e,"location","ref",{required:!0}).asString(),headerRowCount:this.extractChildAttr(e,"location","firstDataRow",{default:0}).asNum(),totalsRowCount:1,cols:[],style:{showFirstColumn:!0,showRowStripes:!0}})))[0]}}class dv extends sv{getTable(){return this.mapOnElements({query:"table",parent:this.rootFile.file.xml},(e=>{var t;return{displayName:this.extractAttr(e,"displayName",{required:!0}).asString(),name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),id:this.extractAttr(e,"id",{required:!0}).asString(),ref:this.extractAttr(e,"ref",{required:!0}).asString(),headerRowCount:this.extractAttr(e,"headerRowCount",{default:1}).asNum(),totalsRowCount:this.extractAttr(e,"totalsRowCount",{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}}))[0]}extractTableCols(e){return this.mapOnElements({query:"tableColumn",parent:e},(e=>({id:this.extractAttr(e,"id",{required:!0}).asString(),name:this.extractAttr(e,"name",{required:!0}).asString(),colFormula:this.extractChildTextContent(e,"calculatedColumnFormula")})))}extractTableStyleInfo(e){return this.mapOnElements({query:"tableStyleInfo",parent:e},(e=>{var t,i,o,n,s;return{name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),showFirstColumn:null===(i=this.extractAttr(e,"showFirstColumn"))||void 0===i?void 0:i.asBool(),showLastColumn:null===(o=this.extractAttr(e,"showLastColumn"))||void 0===o?void 0:o.asBool(),showRowStripes:null===(n=this.extractAttr(e,"showRowStripes"))||void 0===n?void 0:n.asBool(),showColumnStripes:null===(s=this.extractAttr(e,"showColumnStripes"))||void 0===s?void 0:s.asBool()}}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:"autoFilter",parent:e},(e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,"ref",{required:!0}).asString()})))[0]}extractFilterColumns(e){return this.mapOnElements({query:"tableColumn",parent:e},(t=>({colId:this.extractAttr(e,"colId",{required:!0}).asNum(),hiddenButton:this.extractAttr(e,"hiddenButton",{default:!1}).asBool(),filters:this.extractSimpleFilter(t)})))}extractSimpleFilter(e){return this.mapOnElements({query:"filter",parent:e},(e=>({val:this.extractAttr(e,"val",{required:!0}).asString()})))}}class uv extends sv{constructor(e,t,i,o){super(e,t,i),this.theme=o}getSheet(){return this.mapOnElements({query:"worksheet",parent:this.rootFile.file.xml},(e=>{const t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:[...this.extractTables(e),...this.extractPivotTables()],isVisible:"visible"===t.state}}))[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:"sheetView"},(e=>{const t=this.querySelector(e,"pane");return{tabSelected:this.extractAttr(e,"tabSelected",{default:!1}).asBool(),showFormulas:this.extractAttr(e,"showFormulas",{default:!1}).asBool(),showGridLines:this.extractAttr(e,"showGridLines",{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,"showRowColHeaders",{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,"xSplit",{default:0}).asNum():0,ySplit:t?this.extractAttr(t,"ySplit",{default:0}).asNum():0}}}))}extractSheetName(){const e=nm(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,"sheet"))if(e.attributes["r:id"].value===t)return e.attributes.name.value;throw new Error("Missing sheet name")}getSheetWorkbookInfo(){const e=nm(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id,i=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:"sheet"},(e=>({relationshipId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetId:this.extractAttr(e,"sheetId",{required:!0}).asString(),sheetName:this.extractAttr(e,"name",{required:!0}).asString(),state:this.extractAttr(e,"state",{default:"visible"}).asString()}))).find((e=>e.relationshipId===t));if(!i)throw new Error("Cannot find corresponding workbook sheet");return i}extractConditionalFormats(){return new av(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractFigures(e){return this.mapOnElements({parent:e,query:"drawing"},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),o=this.getTargetXmlFile(this.relationships[i]);return new cv(o,this.xlsxFileStructure,this.warningManager).extractFigures()}))[0]||[]}extractTables(e){return this.mapOnElements({query:"tablePart",parent:e},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),o=this.getTargetXmlFile(this.relationships[i]);return new dv(o,this.xlsxFileStructure,this.warningManager).getTable()}))}extractPivotTables(){try{return Object.values(this.relationships).filter((e=>e.type.endsWith("pivotTable"))).map((e=>{const t=this.getTargetXmlFile(e);return new hv(t,this.xlsxFileStructure,this.warningManager).getPivotTable()}))}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:"mergeCell"},(e=>this.extractAttr(e,"ref",{required:!0}).asString()))}extractSheetFormat(e){const t=this.querySelector(e,"sheetFormatPr");if(t)return{defaultColWidth:this.extractAttr(t,"defaultColWidth",{default:Mp.toString()}).asNum(),defaultRowHeight:this.extractAttr(t,"defaultRowHeight",{default:Op.toString()}).asNum()}}extractCols(e){return this.mapOnElements({parent:e,query:"cols col"},(e=>{var t,i,o,n,s,r,a;return{width:null===(t=this.extractAttr(e,"width"))||void 0===t?void 0:t.asNum(),customWidth:null===(i=this.extractAttr(e,"customWidth"))||void 0===i?void 0:i.asBool(),bestFit:null===(o=this.extractAttr(e,"bestFit"))||void 0===o?void 0:o.asBool(),hidden:null===(n=this.extractAttr(e,"hidden"))||void 0===n?void 0:n.asBool(),min:null===(s=this.extractAttr(e,"min",{required:!0}))||void 0===s?void 0:s.asNum(),max:null===(r=this.extractAttr(e,"max",{required:!0}))||void 0===r?void 0:r.asNum(),styleIndex:null===(a=this.extractAttr(e,"style"))||void 0===a?void 0:a.asNum()}}))}extractRows(e){return this.mapOnElements({parent:e,query:"sheetData row"},(e=>{var t,i,o,n,s;return{index:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asNum(),cells:this.extractCells(e),height:null===(i=this.extractAttr(e,"ht"))||void 0===i?void 0:i.asNum(),customHeight:null===(o=this.extractAttr(e,"customHeight"))||void 0===o?void 0:o.asBool(),hidden:null===(n=this.extractAttr(e,"hidden"))||void 0===n?void 0:n.asBool(),styleIndex:null===(s=this.extractAttr(e,"s"))||void 0===s?void 0:s.asNum()}}))}extractCells(e){return this.mapOnElements({parent:e,query:"c"},(e=>{var t,i,o;return{xc:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asString(),styleIndex:null===(i=this.extractAttr(e,"s"))||void 0===i?void 0:i.asNum(),type:Wp[null===(o=this.extractAttr(e,"t",{default:"n"}))||void 0===o?void 0:o.asString()],value:this.extractChildTextContent(e,"v"),formula:this.extractCellFormula(e)}}))}extractCellFormula(e){var t,i;const o=this.querySelector(e,"f");if(o)return{content:this.extractTextContent(o),sharedIndex:null===(t=this.extractAttr(o,"si"))||void 0===t?void 0:t.asNum(),ref:null===(i=this.extractAttr(o,"ref"))||void 0===i?void 0:i.asString()}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:"hyperlink"},(e=>{var t,i,o,n;const s=null===(t=this.extractAttr(e,"r:id"))||void 0===t?void 0:t.asString();return{xc:null===(i=this.extractAttr(e,"ref",{required:!0}))||void 0===i?void 0:i.asString(),location:null===(o=this.extractAttr(e,"location"))||void 0===o?void 0:o.asString(),display:null===(n=this.extractAttr(e,"display"))||void 0===n?void 0:n.asString(),relTarget:s?this.relationships[s].target:void 0}}))}extractSharedFormulas(e){const t=this.querySelectorAll(e,"f[si][ref]"),i={};for(let e of t){const t=this.extractAttr(e,"si",{required:!0}).asNum(),o=this.extractTextContent(e,{required:!0});i[t]=o}const o=[];for(let e=0;e<Object.keys(i).length;e++)i[e]?o.push(i[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),o.push(""));return o}}class gv extends sv{constructor(e,t,i){super(e.styles,e,t),this.theme=i}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"numFmt"},(e=>this.extractNumFormats(e)))}extractNumFormats(e){return{id:this.extractAttr(e,"numFmtId",{required:!0}).asNum(),format:this.extractAttr(e,"formatCode",{required:!0,default:""}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"font"},(e=>this.extractFont(e)))}extractFont(e){var t,i,o,n;const s=this.extractChildAttr(e,"name","val",{default:"Arial"}).asString(),r=this.extractChildAttr(e,"sz","val",{default:q.toString()}).asNum(),a=this.extractColor(this.querySelector(e,"color"),this.theme),l=this.querySelector(e,"i")||void 0,c=l&&"0"!==(null===(t=l.attributes.val)||void 0===t?void 0:t.value),h=this.querySelector(e,"b")||void 0,d=h&&"0"!==(null===(i=h.attributes.val)||void 0===i?void 0:i.value),u=this.querySelector(e,"strike")||void 0,g=u&&"0"!==(null===(o=u.attributes.val)||void 0===o?void 0:o.value),p=this.querySelector(e,"u")||void 0;return{name:s,size:r,color:a,italic:c,bold:d,underline:p&&"none"!==(null===(n=p.attributes.val)||void 0===n?void 0:n.value),strike:g}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"fill"},(e=>this.extractFill(e)))}extractFill(e){var t;const i=e.children[0];return"patternFill"===i.tagName?{patternType:null===(t=i.attributes.patternType)||void 0===t?void 0:t.value,bgColor:this.extractColor(this.querySelector(i,"bgColor"),this.theme),fgColor:this.extractColor(this.querySelector(i,"fgColor"),this.theme)}:{patternType:"solid",fgColor:this.extractColor(this.querySelectorAll(i,"color")[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"border"},(e=>this.extractBorder(e)))}extractBorder(e){var t,i;const o={left:this.extractSingleBorder(e,"left",this.theme),right:this.extractSingleBorder(e,"right",this.theme),top:this.extractSingleBorder(e,"top",this.theme),bottom:this.extractSingleBorder(e,"bottom",this.theme),diagonal:this.extractSingleBorder(e,"diagonal",this.theme)};return o.diagonal&&(o.diagonalUp=null===(t=this.extractAttr(e,"diagonalUp"))||void 0===t?void 0:t.asBool(),o.diagonalDown=null===(i=this.extractAttr(e,"diagonalDown"))||void 0===i?void 0:i.asBool()),o}extractSingleBorder(e,t,i){const o=this.querySelector(e,t);if(o&&o.attributes.style)return{style:this.extractAttr(o,"style",{required:!0,default:"thin"}).asString(),color:this.extractColor(o.children[0],i,"000000")}}extractAlignment(e){var t,i,o,n,s,r,a;return{horizontal:this.extractAttr(e,"horizontal",{default:"general"}).asString(),vertical:this.extractAttr(e,"vertical",{default:"center"}).asString(),textRotation:null===(t=this.extractAttr(e,"textRotation"))||void 0===t?void 0:t.asNum(),wrapText:null===(i=this.extractAttr(e,"wrapText"))||void 0===i?void 0:i.asBool(),indent:null===(o=this.extractAttr(e,"indent"))||void 0===o?void 0:o.asNum(),relativeIndent:null===(n=this.extractAttr(e,"relativeIndent"))||void 0===n?void 0:n.asNum(),justifyLastLine:null===(s=this.extractAttr(e,"justifyLastLine"))||void 0===s?void 0:s.asBool(),shrinkToFit:null===(r=this.extractAttr(e,"shrinkToFit"))||void 0===r?void 0:r.asBool(),readingOrder:null===(a=this.extractAttr(e,"readingOrder"))||void 0===a?void 0:a.asNum()}}getDxfs(){return this.mapOnElements({query:"dxf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"font"),i=this.querySelector(e,"fill"),o=this.querySelector(e,"border"),n=this.querySelector(e,"numFmt"),s=this.querySelector(e,"alignment");return{font:t?this.extractFont(t):void 0,fill:i?this.extractFill(i):void 0,numFmt:n?this.extractNumFormats(n):void 0,alignment:s?this.extractAlignment(s):void 0,border:o?this.extractBorder(o):void 0}}))}getStyles(){return this.mapOnElements({query:"cellXfs xf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"alignment");return{fontId:this.extractAttr(e,"fontId",{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,"fillId",{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,"borderId",{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,"numFmtId",{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}}))}}class pv extends sv{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"externalBook"},(e=>({rId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:"sheetName"},(e=>this.extractAttr(e,"val",{required:!0}).asString())),datasets:this.extractExternalSheetData(e)})))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:"sheetData"},(e=>{const t=this.mapOnElements({parent:e,query:"cell"},(e=>({xc:this.extractAttr(e,"r",{required:!0}).asString(),value:this.extractChildTextContent(e,"v",{required:!0})}))),i={};for(let e of t)i[e.xc]=e.value;return{sheetId:this.extractAttr(e,"sheetId",{required:!0}).asNum(),data:i}}))}}function mv(e,t){const i=function(e,t){const i=t[Lp],o=i.querySelectorAll(`Override[ContentType="${e}"]`),n=[];for(let e of o){const t=null==e?void 0:e.attributes.PartName.value;n.push(t.substring(1))}return n}(e,t);return function(e,t){const i=[];for(let o of e){const e=fv(o,t);i.push({file:{fileName:o,xml:t[o]},rels:e?{fileName:e,xml:t[e]}:void 0})}return i}(i,t)}function fv(e,t){if(e===Lp)return"_rels/.rels";let i="";const o=e.split("/");for(let e=0;e<o.length-1;e++)i+=o[e]+"/";return i+="_rels/",i+=o[o.length-1]+".rels",t[i]||(i=void 0),i}class vv{constructor(e){this.warningManager=new Up,this.xmls={};for(let t of Object.keys(e))(t.endsWith(".xml")||t.endsWith(".rels"))&&(this.xmls[t]=Qf(new vp(e[t])))}convertXlsx(){const e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){const e=this.buildXlsxFileStructure(),t=e.theme?new rv(e.theme,e,this.warningManager).getTheme():void 0,i=e.sharedStrings?new rv(e.sharedStrings,e,this.warningManager).getSharedStrings():[],o=e.sheets.sort(((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0}))).map((i=>new uv(i,e,this.warningManager,t).getSheet())),n=e.externalLinks.map((t=>new pv(t,e,this.warningManager).getExternalBook())),s=new gv(e,this.warningManager,t);return{fonts:s.getFonts(),fills:s.getFills(),borders:s.getBorders(),dxfs:s.getDxfs(),numFmts:s.getNumFormats(),styles:s.getStyles(),sheets:o,sharedStrings:i,externalBooks:n}}buildXlsxFileStructure(){const e={sheets:mv(xp.sheet,this.xmls),workbook:mv(xp.workbook,this.xmls)[0],styles:mv(xp.styles,this.xmls)[0],sharedStrings:mv(xp.sharedStrings,this.xmls)[0],theme:mv(xp.themes,this.xmls)[0],charts:mv(xp.chart,this.xmls),figures:mv(xp.drawing,this.xmls),tables:mv(xp.table,this.xmls),pivots:mv(xp.pivot,this.xmls),externalLinks:mv(xp.externalLink,this.xmls)};if(!e.workbook.rels)throw Error(s("Cannot find workbook relations file"));return e}convertImportedData(e){const t={version:12,sheets:Uf(e,this.warningManager),styles:um(e,this.warningManager),formats:pm(e,this.warningManager),borders:hm(e,this.warningManager),entities:{},revisionId:Q};return qf(t,e),Object.keys(e.styles).map((t=>{e.styles[t]=ut(e.styles[t])})),t}}function bv(e){const t=rf(e);let i=[];return{text:"".concat(...t.map((e=>{if("REFERENCE"===e.type&&Nt.test(e.value)){const t=e.value.trim();return i.includes(t)||i.push(t),`${ae}${i.indexOf(t)}${ae}`}return e.value}))),dependencies:i}}const Sv=12,Cv="Sheet1";function Ev(e,t){if(!e)return Rv();if(e["[Content_Types].xml"]){const i=new vv(e);if(e=i.convertXlsx(),t)for(let e of i.warningManager.warnings.sort())console.warn(e)}return"version"in(e=Fe(e))&&e.version<Sv&&(e=function(e){for(let t=wv.findIndex((t=>t.from===e.version));t<wv.length;t++)e=wv[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,i=new Ui;for(const o of e.sheets||[])for(const e of o.figures||[])t.has(e.id)&&(e.id+=i.uuidv4()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(Rv(),e,{version:Sv}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(Iv(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(Iv(Cv,"Sheet1"));return e}(e),e}(e),e}const wv=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];i.content&&i.content.startsWith("=")&&(i.formula=bv(i.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:i,...o}=t.figures[e].data,n=[];for(let e of i)if(e.labelCell){const t=zi(e.dataRange),i=e.labelCell+":"+Gt(t.right,t.bottom);n.push(i)}else n.push(e.dataRange);o.dataSetsHaveTitle=Boolean(i[0].labelCell),o.dataSets=n,t.figures[e].data=o}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const i=[],o=new RegExp(re,"g");for(let n of e.sheets||[]){if(!n.name)continue;const e=n.name,s=e.replace(o,"_");let r=1,a=s;for(;i.includes(a);)a=`${s}${r}`,r++;n.name=a,i.push(a);const l=t=>{if(void 0===t)return t;let i=t.replace(e,a),o=t;for(;o!==i;)o=i,i=o.replace(e,a);return o};for(let e in n.cells){const t=n.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of n.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),i=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:i}}for(let e of n.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const i of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[i])||void 0===t?void 0:t.type)&&(e.rule[i].value=l(e.rule[i].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=w,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stacked=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];if(i.formula){let{text:e,dependencies:t}=i.formula;for(let[i,o]of Object.entries(t)){const t=`\\${ae}${i}\\${ae}`;e=e.replace(new RegExp(t,"g"),o)}i.content=e,delete i.formula}}return e}},{description:"normalize the formats of the cells",from:10,to:11,applyMigration(e){const t={};for(let i of e.sheets||[])for(let e in i.cells||[]){const o=i.cells[e];o.format&&(o.format=st(o.format,t))}return e.formats=t,e}},{description:"Add isVisible to sheets",from:11,to:12,applyMigration(e){for(let t of e.sheets||[])t.isVisible=!0;return e}}];function yv(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const i=[],o=[],n=e=>{if("CREATE_SHEET"===e.type)i.push(e.sheetId);else if("sheetId"in e&&!i.includes(e.sheetId))return{...e,sheetId:Cv};return e};for(const e of t)"REMOTE_REVISION"===e.type?o.push({...e,commands:e.commands.map(n)}):o.push(e);return o}(e,t),t=xv(t,"SORT_CELLS"),t=function(e,t){var i;const o=[],n={};for(const t of e.sheets||[])null===(i=t.figures)||void 0===i||i.forEach((e=>{"chart"===e.tag&&(n[e.id]=e.data)}));for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const i of e.commands){let e=i;switch(i.type){case"CREATE_CHART":n[i.id]=i.definition;break;case"UPDATE_CHART":if(!n[i.id]){console.log(`Fix chart definition: chart with id ${i.id} not found.`);continue}const t={...n[i.id],...i.definition};e={...i,definition:t},n[i.id]=t}t.push(e)}o.push({...e,commands:t})}else o.push(e);return o}(e,t=xv(t,"SET_DECIMAL")),t}function xv(e,t){const i=[];for(const o of e)"REMOTE_REVISION"===o.type?i.push({...o,commands:o.commands.filter((e=>e.type!==t))}):i.push(o);return i}function Iv(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[],filterTables:[],isVisible:!0}}function Rv(e="Sheet1"){return{version:Sv,sheets:[Iv(Cv,e)],entities:{},styles:{},formats:{},borders:{},revisionId:Q,uniqueFigureIds:!0}}function Tv(e,t){return{...Iv(e,t),charts:[],images:[]}}class Av{constructor(e,t){this.history=Object.assign(Object.create(e),{update:e.addChange.bind(e,this),selectCell:()=>{}}),this.dispatch=t}exportForExcel(e){}allowDispatch(e){return 0}beforeHandle(e){}handle(e){}finalize(){}batchValidations(...e){return t=>e.map((e=>e.call(this,t))).flat()}chainValidations(...e){return t=>{for(const i of e){let e=i.call(this,t);Array.isArray(e)||(e=[e]);const o=e.filter((e=>0!==e));if(o.length)return o}return 0}}checkValidations(e,...t){return this.batchValidations(...t)(e)}}Av.getters=[];class Mv extends Av{constructor({getters:e,stateObserver:t,range:i,dispatch:o,uuidGenerator:n}){super(t,o),this.range=i,i.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=n}import(e){}export(e){}adaptRanges(e,t){}garbageCollectExternalResources(){}}class Ov extends Mv{constructor(){super(...arguments),this.borders={}}handle(e){switch(e.type){case"ADD_MERGE":for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const i=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,i)}break;case"DELETE_SHEET":const i={...this.borders};delete i[e.sheetId],this.history.update("borders",i);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(e.sheetId,t,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":for(let t of e.elements)"COL"===e.dimension?this.shiftBordersHorizontally(e.sheetId,t+1,-1):this.shiftBordersVertically(e.sheetId,t+1,-1);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){let t,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,i)}handleAddRows(e){let t,i;"before"===e.position?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity,{moveFirstTopBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity,{moveFirstTopBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,i)}getCellBorder({sheetId:e,col:t,row:i}){var o,n,s,r,a,l,c,h,d,u,g,p;const m={top:null===(s=null===(n=null===(o=this.borders[e])||void 0===o?void 0:o[t])||void 0===n?void 0:n[i])||void 0===s?void 0:s.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i])||void 0===d?void 0:d.vertical,right:null===(p=null===(g=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===g?void 0:g[i])||void 0===p?void 0:p.vertical};return m.bottom||m.left||m.right||m.top?m:null}ensureColumnBorderContinuity(e,t,i){const o=$e(t+1,i);for(let n=0;n<this.getters.getNumberRows(e);n++){const s=this.getCellBorder({sheetId:e,col:t,row:n}),r=this.getCellBorder({sheetId:e,col:i,row:n});if(s&&r){const t=this.getCommonSides(s,r);for(let i of o)this.addBorder(e,i,n,t)}}}ensureRowBorderContinuity(e,t,i){const o=$e(t+1,i);for(let n=0;n<this.getters.getNumberCols(e);n++){const s=this.getCellBorder({sheetId:e,col:n,row:t}),r=this.getCellBorder({sheetId:e,col:n,row:i});if(s&&r){const t=this.getCommonSides(s,r);for(let i of o)this.addBorder(e,n,i,t)}}}getCommonSides(e,t){const i={};for(let o of["top","bottom","left","right"])e[o]&&e[o]===t[o]&&(i[o]=e[o]);return i}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsRange(e){return this.borders[e]?$e(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,i,{moveFirstLeftBorder:o}={}){this.borders[e]&&(i<0&&this.moveBordersOfColumn(e,t,i,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((n=>{(n===t&&o||n!==t)&&this.moveBordersOfColumn(e,n,i,"vertical"),this.moveBordersOfColumn(e,n,i,"horizontal")})))}shiftBordersVertically(e,t,i,{moveFirstTopBorder:o}={}){this.borders[e]&&(i<0&&this.moveBordersOfRow(e,t,i,"horizontal",{destructive:!1}),this.getRowsRange(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((n=>{(n===t&&o||n!==t)&&this.moveBordersOfRow(e,n,i,"horizontal"),this.moveBordersOfRow(e,n,i,"vertical")})))}moveBordersOfRow(e,t,i,o,{destructive:n}={destructive:!0}){const s=this.borders[e];s&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[r])||void 0===a?void 0:a[t+i])||void 0===l?void 0:l[o],u=null===(h=null===(c=s[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[o];this.history.update("borders",e,r,t+i,o,n?u:u||d),this.history.update("borders",e,r,t,o,void 0)}))}moveBordersOfColumn(e,t,i,o,{destructive:n}={destructive:!0}){const s=this.borders[e];s&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[t+i])||void 0===a?void 0:a[r])||void 0===l?void 0:l[o],u=null===(h=null===(c=s[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[o];this.history.update("borders",e,t+i,r,o,n?u:u||d),this.history.update("borders",e,t,r,o,void 0)}))}setBorder(e,t,i,o,n=!0){var s,r,a,l,c,h,d,u,g,p,m,f,v,b,S,C;!n&&(null===(l=null===(a=null===(r=null===(s=this.borders)||void 0===s?void 0:s[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i])||void 0===l?void 0:l.vertical)||this.history.update("borders",e,t,i,"vertical",null==o?void 0:o.left),!n&&(null===(u=null===(d=null===(h=null===(c=this.borders)||void 0===c?void 0:c[e])||void 0===h?void 0:h[t])||void 0===d?void 0:d[i])||void 0===u?void 0:u.horizontal)||this.history.update("borders",e,t,i,"horizontal",null==o?void 0:o.top),!n&&(null===(f=null===(m=null===(p=null===(g=this.borders)||void 0===g?void 0:g[e])||void 0===p?void 0:p[t+1])||void 0===m?void 0:m[i])||void 0===f?void 0:f.vertical)||this.history.update("borders",e,t+1,i,"vertical",null==o?void 0:o.right),!n&&(null===(C=null===(S=null===(b=null===(v=this.borders)||void 0===v?void 0:v[e])||void 0===b?void 0:b[t])||void 0===S?void 0:S[i+1])||void 0===C?void 0:C.horizontal)||this.history.update("borders",e,t,i+1,"horizontal",null==o?void 0:o.bottom)}clearBorders(e,t){for(let i of t){for(let t=i.top;t<=i.bottom;t++){this.history.update("borders",e,i.right+1,t,"vertical",void 0);for(let o=i.left;o<=i.right;o++)this.history.update("borders",e,o,t,void 0)}for(let t=i.left;t<=i.right;t++)this.history.update("borders",e,t,i.bottom+1,"horizontal",void 0)}}addBorder(e,t,i,o){this.setBorder(e,t,i,{...this.getCellBorder({sheetId:e,col:t,row:i}),...o})}setBorders(e,t,i){if("clear"===i)return this.clearBorders(e,t);for(let o of t){if("h"===i||"hv"===i||"all"===i)for(let t=o.top+1;t<=o.bottom;t++)for(let i=o.left;i<=o.right;i++)this.addBorder(e,i,t,{top:j});if("v"===i||"hv"===i||"all"===i)for(let t=o.top;t<=o.bottom;t++)for(let i=o.left+1;i<=o.right;i++)this.addBorder(e,i,t,{left:j});if("left"===i||"all"===i||"external"===i)for(let t=o.top;t<=o.bottom;t++)this.addBorder(e,o.left,t,{left:j});if("right"===i||"all"===i||"external"===i)for(let t=o.top;t<=o.bottom;t++)this.addBorder(e,o.right+1,t,{left:j});if("top"===i||"all"===i||"external"===i)for(let t=o.left;t<=o.right;t++)this.addBorder(e,t,o.top,{top:j});if("bottom"===i||"all"===i||"external"===i)for(let t=o.left;t<=o.right;t++)this.addBorder(e,t,o.bottom+1,{top:j})}}addBordersToMerge(e,t){const{left:i,right:o,top:n,bottom:s}=t,r=this.getCellBorder({sheetId:e,col:i,row:n}),a=this.getCellBorder({sheetId:e,col:o,row:s});this.clearBorders(e,[t]),(null==r?void 0:r.top)&&this.setBorders(e,[{...t,bottom:n}],"top"),(null==r?void 0:r.left)&&this.setBorders(e,[{...t,right:i}],"left"),((null==a?void 0:a.bottom)||(null==r?void 0:r.bottom))&&this.setBorders(e,[{...t,top:s}],"bottom"),((null==a?void 0:a.right)||(null==r?void 0:r.right))&&this.setBorders(e,[{...t,left:o}],"right")}import(e){if(e.borders)for(let t of e.sheets)for(let[i,o]of Object.entries(t.cells))if(null==o?void 0:o.border){const n=e.borders[o.border],{col:s,row:r}=Wt(i);this.setBorder(t.id,s,r,n,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,zi(e))}export(e){let t=0;const i={};function o(e){for(let[t,o]of Object.entries(i))if(Oe(o)===Oe(e))return parseInt(t,10);return i[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let i=0;i<t.rowNumber;i++){const n=this.getCellBorder({sheetId:t.id,col:e,row:i});if(n){const s=Gt(e,i),r=t.cells[s],a=o(n);r?r.border=a:t.cells[s]={border:a}}}e.borders=i}exportForExcel(e){this.export(e)}}Ov.getters=["getCellBorder"];class Nv extends Mv{constructor(){super(...arguments),this.nextId=1,this.cells={}}adaptRanges(e,t){for(const i of Object.keys(this.cells))for(const o of Object.values(this.cells[i]||{}))if(o.isFormula)for(const n of o.dependencies)if(!t||n.sheetId===t){const t=e(n);"NONE"!==t.changeType&&this.history.update("cells",i,o.id,"dependencies",o.dependencies.indexOf(n),t.range)}}allowDispatch(e){switch(e.type){case"UPDATE_CELL":case"CLEAR_CELL":return this.checkCellOutOfSheet(e.sheetId,e.col,e.row);default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearFormatting(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(e.sheetId,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""})}}setFormatter(e,t,i){for(let o of t)for(let t=o.top;t<=o.bottom;t++)for(let n=o.left;n<=o.right;n++)this.dispatch("UPDATE_CELL",{sheetId:e,col:n,row:t,format:i})}clearFormatting(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:null,format:""})}handleAddColumnsRows(e,t){let i,o;"before"===e.position?(i=$e(e.base,e.base+e.quantity),o=e.base+e.quantity):(i=$e(e.base+1,e.base+e.quantity+1),o=e.base),t(e.sheetId,o,i)}import(e){for(let t of e.sheets)for(let i in t.cells){const o=t.cells[i],{col:n,row:s}=Wt(i);if((null==o?void 0:o.content)||(null==o?void 0:o.format)||(null==o?void 0:o.style)){const i=this.importCell(t.id,o,e.styles,e.formats);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cellId:i.id,col:n,row:s,sheetId:t.id})}}}export(e){const t={},i={};for(let o of e.sheets){const e={},n=Object.keys(this.cells[o.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const o of n){const n=this.getters.getCell(o);e[Gt(o.col,o.row)]={style:n.style?st(n.style,t):void 0,format:n.format?st(n.format,i):void 0,content:n.content||void 0}}o.cells=e}e.styles=t,e.formats=i}importCell(e,t,i,o){const n=t.style&&i[t.style]||void 0,s=t.format&&o[t.format]||void 0,r=this.getNextUid();return this.createCell(r,(null==t?void 0:t.content)||"",s,n,e)}exportForExcel(e){this.export(e)}getCells(e){return this.cells[e]||{}}getCellById(e){for(const t in this.cells){const i=this.cells[t][e];if(i)return i}}buildFormulaContent(e,t,i){const o=i||t.dependencies;let n=0;return rt(t.compiledFormula.tokens.map((t=>{if("REFERENCE"===t.type){const t=o[n++];return this.getters.getRangeString(t,e)}return t.value})))}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t)}getCellStyle(e){var t;return(null===(t=this.getters.getCell(e))||void 0===t?void 0:t.style)||{}}zoneToXC(e,t,i=[{colFixed:!1,rowFixed:!1}]){const o=Gt((t=this.getters.expandZone(e,t)).left,t.top,i[0]),n=Gt(t.right,t.bottom,i.length>1?i[1]:i[0]),s=this.getters.getMainCellPosition({sheetId:e,col:t.left,row:t.top}),r=this.getters.getMainCellPosition({sheetId:e,col:t.right,row:t.bottom}),a=s.col===r.col&&s.row===r.row;return o==n||a?o:o+":"+n}setStyle(e,t,i){for(let o of t)for(let t=o.left;t<=o.right;t++)for(let n=o.top;n<=o.bottom;n++){const o=this.getters.getCell({sheetId:e,col:t,row:n});this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,style:i?{...null==o?void 0:o.style,...i}:void 0})}}copyColumnStyle(e,t,i){for(let o=0;o<this.getters.getNumberRows(e);o++){const n=this.getFormat(e,t,o);if(n.style||n.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,...n})}}copyRowStyle(e,t,i){for(let o=0;o<this.getters.getNumberCols(e);o++){const n=this.getFormat(e,o,t);if(n.style||n.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,...n})}}getFormat(e,t,i){const o={},n=this.getters.getMainCellPosition({sheetId:e,col:t,row:i}),s=this.getters.getCell(n);return s&&(s.style&&(o.style=s.style),s.format&&(o.format=s.format)),o}getNextUid(){const e=this.nextId.toString();return this.history.update("nextId",this.nextId+1),e}updateCell(e,t,i,o){const n=this.getters.getCell({sheetId:e,col:t,row:i}),s="content"in o||"formula"in o,r=s?vt(null==o?void 0:o.content):(null==n?void 0:n.content)||"";let a;a=void 0!==o.style?o.style||void 0:n?n.style:void 0;let l=("format"in o?o.format:n&&n.format)||Ii(r);if((s&&!r&&!o.formula||!s&&(!n||""===n.content))&&!a&&!l)return void(n&&(this.history.update("cells",e,n.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:void 0,col:t,row:i,sheetId:e})));const c=(null==n?void 0:n.id)||this.getNextUid(),h=this.createCell(c,r,l,a,e);this.history.update("cells",e,h.id,h),this.dispatch("UPDATE_CELL_POSITION",{cellId:h.id,col:t,row:i,sheetId:e})}createCell(e,t,i,o,n){if(!t.startsWith("="))return this.createLiteralCell(e,t,i,o);try{return this.createFormulaCell(e,t,i,o,n)}catch(n){return this.createErrorFormula(e,t,i,o,n)}}createLiteralCell(e,t,i,o){return{id:e,content:t,style:o,format:i,isFormula:!1}}createFormulaCell(e,t,i,o,n){const s=df(t);return s.dependencies.length?this.createFormulaCellWithDependencies(e,s,i,o,n):{id:e,content:t,style:o,format:i,isFormula:!0,compiledFormula:s,dependencies:[]}}createFormulaCellWithDependencies(e,t,i,o,n){const s=t.dependencies.map((e=>this.getters.getRangeFromSheetXC(n,e))),r=this.buildFormulaContent.bind(this);return{id:e,get content(){return r(n,{dependencies:this.dependencies,compiledFormula:this.compiledFormula})},style:o,format:i,isFormula:!0,compiledFormula:t,dependencies:s}}createErrorFormula(e,t,i,o,n){return{id:e,content:t,style:o,format:i,isFormula:!0,compiledFormula:{dependencies:[],tokens:Tm(t),execute:function(){throw n}},dependencies:[]}}checkCellOutOfSheet(e,t,i){if(!this.getters.tryGetSheet(e))return 27;return Ki(t,i,this.getters.getSheetZone(e))?0:18}}Nv.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class _v extends Mv{constructor(){super(...arguments),this.charts={},this.createChart=function(e){const t=lr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i,o,n){const s=t.find((e=>e.match(o.type)));if(!s)throw new Error(`No builder for this chart: ${o.type}`);return s.createChart(o,n,e)}}(this.getters),this.validateChartDefinition=e=>function(e,t){const i=lr.getAll().find((e=>e.match(t.type)));if(!i)throw new Error("Unknown chart type.");return i.validateChartDefinition(e,t)}(this,e.definition)}adaptRanges(e){for(const[t,i]of Object.entries(this.charts))this.history.update("charts",t,null==i?void 0:i.updateRanges(e))}allowDispatch(e){switch(e.type){case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartDuplicate));case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists));default:return 0}}handle(e){var t;switch(e.type){case"CREATE_CHART":this.addFigure(e.id,e.sheetId,e.position,e.size),this.addChart(e.id,e.definition);break;case"UPDATE_CHART":this.addChart(e.id,e.definition);break;case"DUPLICATE_SHEET":{const i=this.getters.getFigures(e.sheetId);for(const o of i)if("chart"===o.tag){const i=o.id.split(ee).pop(),n=`${e.sheetIdTo}${ee}${i}`,s=null===(t=this.charts[o.id])||void 0===t?void 0:t.copyForSheetId(e.sheetIdTo);s&&this.dispatch("CREATE_CHART",{id:n,position:{x:o.x,y:o.y},size:{width:o.width,height:o.height},definition:s.getDefinition(),sheetId:e.sheetIdTo})}break}case"DELETE_FIGURE":this.history.update("charts",e.id,void 0);break;case"DELETE_SHEET":for(let t of this.getChartIds(e.sheetId))this.history.update("charts",t,void 0)}}getContextCreationChart(e){var t;return null===(t=this.charts[e])||void 0===t?void 0:t.getContextCreation()}getChart(e){return this.charts[e]}getChartType(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.type;if(!i)throw new Error("Chart not defined.");return i}isChartDefined(e){return e in this.charts&&void 0!==this.charts}getChartIds(e){return Object.entries(this.charts).filter((([,t])=>(null==t?void 0:t.sheetId)===e)).map((([e])=>e))}getChartDefinition(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.getDefinition();if(!i)throw new Error(`There is no chart with the given figureId: ${e}`);return i}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)"chart"===e.tag&&(this.charts[e.id]=this.createChart(e.id,e.data,t.id))}export(e){var t;if(e.sheets)for(let i of e.sheets){const e=this.getters.getFigures(i.id),o=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=null===(t=this.charts[e.id])||void 0===t?void 0:t.getDefinition();i&&(e.data=i,o.push(e))}else o.push(e)}i.figures=o}}exportForExcel(e){var t;for(let i of e.sheets){const e=this.getters.getFigures(i.id),o=[];for(let i of e)if(i&&"chart"===i.tag){const e=null===(t=this.charts[i.id])||void 0===t?void 0:t.getDefinitionForExcel();e&&o.push({...i,data:e})}i.charts=o}}addFigure(e,t,i={x:0,y:0},o={width:536,height:335}){if(this.getters.getFigure(t,e))return;const n={id:e,x:i.x,y:i.y,width:o.width,height:o.height,tag:"chart"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:n})}addChart(e,t){const i=this.getters.getFigureSheetId(e);i&&this.history.update("charts",e,this.createChart(e,t,i))}checkChartDuplicate(e){return this.getters.getFigureSheetId(e.id)?84:0}checkChartExists(e){return this.getters.getFigureSheetId(e.id)?0:85}}function Fv(e){return""===e?NaN:Number(e)}_v.getters=["isChartDefined","getChartDefinition","getChartType","getChartIds","getChart","getContextCreationChart"];class Dv extends Mv{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const i of this.cfRules[e])for(const o of i.ranges){const n=t(o);switch(n.changeType){case"REMOVE":let t=i.ranges.slice();t.splice(i.ranges.indexOf(o),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",t):this.removeConditionalFormatting(i.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",i.ranges.indexOf(o),n.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){switch(e.type){case"ADD_CONDITIONAL_FORMAT":return this.checkValidations(e,this.checkCFRule,this.checkEmptyRange);case"MOVE_CONDITIONAL_FORMAT":return this.checkValidReordering(e.cfId,e.direction,e.sheetId)}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const i={...e.cf,ranges:e.ranges.map((t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId)))};this.addConditionalFormatting(i,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId);break;case"MOVE_CONDITIONAL_FORMAT":this.reorderConditionalFormatting(e.cfId,e.direction,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){this.export(e)}getConditionalFormats(e){var t;return(null===(t=this.cfRules[e])||void 0===t?void 0:t.map((t=>this.mapToConditionalFormat(e,t))))||[]}getRulesSelection(e,t){const i=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{i.add(e)}))})),Array.from(i)}getRulesByZone(e,t){const i=new Set;for(let o=t.top;o<=t.bottom;o++)for(let n=t.left;n<=t.right;n++){this.getRulesByCell(e,n,o).forEach((e=>{i.add(e.id)}))}return i}getRulesByCell(e,t,i){const o=[];for(let n of this.cfRules[e])for(let e of n.ranges)Ki(t,i,e.zone)&&o.push(n);return new Set(o.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e)))}}mapToConditionalFormatInternal(e,t){const i={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return i}addConditionalFormatting(e,t){const i=this.cfRules[t].slice(),o=i.findIndex((t=>t.id===e.id)),n=this.mapToConditionalFormatInternal(t,e);o>-1?i.splice(o,1,n):i.push(n),this.history.update("cfRules",t,i)}checkValidReordering(e,t,i){if(!this.cfRules[i])return 27;const o=this.cfRules[i].findIndex((t=>t.id===e));if(-1===o)return 71;const n="up"===t?o-1:o+1;return n<0||n>=this.cfRules[i].length?71:0}checkEmptyRange(e){return e.ranges.length?0:24}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return i=>{if(t.includes(i.operator)){const t=[],o=e=>void 0===e||""===e;return e>=1&&o(i.values[0])&&t.push(51),e>=2&&o(i.values[1])&&t.push(52),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 53;case"max":return 55;case"mid":return 54;case"upperInflectionPoint":return 56;case"lowerInflectionPoint":return 57}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{df(e.value||"")}catch(e){switch(t){case"min":return 58;case"max":return 60;case"mid":return 59;case"upperInflectionPoint":return 61;case"lowerInflectionPoint":return 62}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,i=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(i)?48:0}checkMinBiggerThanMax(e){const t=e.minimum.value,i=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&Fv(t)>=Fv(i)?47:0}checkMidBiggerThanMax(e){var t;const i=null===(t=e.midpoint)||void 0===t?void 0:t.value,o=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&Fv(i)>=Fv(o)?49:0}checkMinBiggerThanMid(e){var t;const i=e.minimum.value,o=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&Fv(i)>=Fv(o)?50:0}removeConditionalFormatting(e,t){const i=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==i){const e=this.cfRules[t].slice();e.splice(i,1),this.history.update("cfRules",t,e)}}reorderConditionalFormatting(e,t,i){const o=this.cfRules[i].findIndex((t=>t.id===e)),n="up"===t?o-1:o+1;if(!(n<0||n>=this.cfRules[i].length)&&-1!==o&&-1!==n){const e=[...this.cfRules[i]],t=e[o];e[o]=e[n],e[n]=t,this.history.update("cfRules",i,e)}}}Dv.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class kv extends Mv{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:i,...o}=e,n=o;this.updateFigure(i,n);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[i,o]of Object.entries(t))switch(i){case"x":case"y":void 0!==o&&this.history.update("figures",e,t.id,i,Math.max(o,0));break;case"width":case"height":void 0!==o&&this.history.update("figures",e,t.id,i,o)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var i;return void 0===(null===(i=this.figures[e])||void 0===i?void 0:i[t])?70:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?82:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(ot)}getFigure(e,t){var i;return null===(i=this.figures[e])||void 0===i?void 0:i[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var i;return void 0!==(null===(i=this.figures[t])||void 0===i?void 0:i[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const i=void 0;t.figures.push({...e,data:i})}}exportForExcel(e){this.export(e)}}kv.getters=["getFigures","getFigure","getFigureSheetId"];class Lv{constructor(e){this.filters=[],this.zone=e;const t=new Ui;this.id=t.uuidv4();for(const i of $e(e.left,e.right+1)){const e={...this.zone,left:i,right:i};this.filters.push(new Pv(t.uuidv4(),e))}}get contentZone(){if(this.zone.bottom!==this.zone.top)return{...this.zone,top:this.zone.top+1}}getFilterId(e){var t;return null===(t=this.filters.find((t=>t.col===e)))||void 0===t?void 0:t.id}clone(){return new Lv(this.zone)}}class Pv{constructor(e,t){if(t.left!==t.right)throw new Error("Can only define a filter on a single column");this.id=e,this.zoneWithHeaders=t}get col(){return this.zoneWithHeaders.left}get filteredZone(){const e=this.zoneWithHeaders;if(e.bottom!==e.top)return{...e,top:e.top+1}}}class Uv extends Mv{constructor(){super(...arguments),this.tables={}}allowDispatch(e){switch(e.type){case"CREATE_FILTER_TABLE":if(!ho(...e.target))return 81;const t=Zi(...e.target),i=()=>this.getFilterTables(e.sheetId).some((e=>Yi(e.zone,t)))?78:0,o=()=>{const i=this.getters.getMergesInZone(e.sheetId,t);for(let e of i)if(Yi(t,e))return 80;return 0};return this.checkValidations(e,i,o);case"ADD_MERGE":for(let t of e.target)for(let i of this.getFilterTables(e.sheetId))if(Yi(i.zone,t))return 80}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.history.update("tables",e.sheetId,{});break;case"DELETE_SHEET":const t={...this.tables};delete t[e.sheetId],this.history.update("tables",t);break;case"DUPLICATE_SHEET":const i={};for(const t of Object.values(this.tables[e.sheetId]||{}))if(t){const e=Fe(t);i[e.id]=e}this.history.update("tables",e.sheetIdTo,i);break;case"ADD_COLUMNS_ROWS":this.onAddColumnsRows(e);break;case"REMOVE_COLUMNS_ROWS":this.onDeleteColumnsRows(e);break;case"CREATE_FILTER_TABLE":{const t=Zi(...e.target),i=this.createFilterTable(t);this.history.update("tables",e.sheetId,i.id,i);break}case"REMOVE_FILTER_TABLE":{const t={};for(const i of this.getFilterTables(e.sheetId))e.target.every((e=>!ji(e,i.zone)))&&(t[i.id]=i);this.history.update("tables",e.sheetId,t);break}case"UPDATE_CELL":{const t=e.sheetId;for(let i of this.getFilterTables(t))this.canUpdateCellCmdExtendTable(e,i)&&this.extendTableDown(t,i);break}}}getFilters(e){return this.getFilterTables(e).map((e=>e.filters)).flat()}getFilterTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(ot):[]}getFilter(e){var t;return null===(t=this.getFilterTable(e))||void 0===t?void 0:t.filters.find((t=>t.col===e.col))}getFilterId(e){var t;return null===(t=this.getFilter(e))||void 0===t?void 0:t.id}getFilterTable({sheetId:e,col:t,row:i}){return this.getFilterTables(e).find((e=>Ki(t,i,e.zone)))}getFilterTablesInZone(e,t){return this.getFilterTables(e).filter((e=>Qi(e.zone,t)))}doesZonesContainFilter(e,t){for(const i of t)for(const t of this.getFilterTables(e))if(ji(i,t.zone))return!0;return!1}onAddColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=$i(t.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),o=[];for(const i of t.filters){const t=$i(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);o.push(new Pv(i.id,t))}if(o.length<to(i).numberOfCols){for(let e=i.left;e<=i.right;e++)o.find((t=>t.col===e))||o.push(new Pv(this.uuidGenerator.uuidv4(),{...i,left:e,right:e}));o.sort(((e,t)=>e.col-t.col))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",o)}}onDeleteColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=qi(t.zone,"COL"===e.dimension?"left":"top",e.elements);if(i){if(Hi(i)!==Hi(t.zone)){const o=[];for(const i of t.filters){const t=qi(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.elements);t&&o.push(new Pv(i.id,t))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",o)}}else{const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i)}}}createFilterTable(e){return new Lv(e)}extendTableDown(e,t){const i={...t.zone,bottom:t.zone.bottom+1};this.history.update("tables",e,t.id,"zone",i);for(let i=0;i<t.filters.length;i++){const o=t.filters[i],n={...o.zoneWithHeaders,bottom:o.zoneWithHeaders.bottom+1};this.history.update("tables",e,t.id,"filters",i,"zoneWithHeaders",n)}}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:i,row:o},n){var s;if(!e)return;const r=n.zone;if(!(r.bottom+1===o&&i>=r.left&&i<=r.right))return!1;for(const e of $e(r.left,r.right+1)){const i={sheetId:t,col:e,row:o};if(null===(s=this.getters.getCell(i))||void 0===s?void 0:s.content)return!1;if(this.getters.getFilter(i))return!1;if(this.getters.isInMerge(i))return!1}return!0}import(e){for(const t of e.sheets)for(const e of t.filterTables||[]){const i=this.createFilterTable(zi(e.range));this.history.update("tables",t.id,i.id,i)}}export(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))t.filterTables.push({range:Hi(e.zone)})}exportForExcel(e){this.export(e)}}Uv.getters=["doesZonesContainFilter","getFilter","getFilters","getFilterTable","getFilterTables","getFilterTablesInZone","getFilterId"];class Vv extends Mv{constructor(){super(...arguments),this.sizes={}}handle(e){var t,i;switch(e.type){case"CREATE_SHEET":{const t=this.computeSheetSizes(e.sheetId),i={COL:t.COL.map((e=>({manualSize:void 0,computedSize:at(e)}))),ROW:t.ROW.map((e=>({manualSize:void 0,computedSize:at(e)})))};this.history.update("sizes",e.sheetId,i);break}case"DUPLICATE_SHEET":for(const t of this.sizes[e.sheetId].ROW)t.computedSize();for(const t of this.sizes[e.sheetId].COL)t.computedSize();this.history.update("sizes",e.sheetIdTo,Fe(this.sizes[e.sheetId]));break;case"DELETE_SHEET":const o={...this.sizes};delete o[e.sheetId],this.history.update("sizes",o);break;case"REMOVE_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);const i=Math.min(...e.elements);t=t.map(((t,o)=>"ROW"===e.dimension&&o>=i?{manualSize:t.manualSize,computedSize:at((()=>this.getRowTallestCellSize(e.sheetId,o)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];const i=ct(e.position,e.base),o=t[e.base],n=$e(0,e.quantity).map((()=>({manualSize:o.manualSize,computedSize:at(o.computedSize())})));t.splice(i,0,...n),t=t.map(((t,i)=>"ROW"===e.dimension&&i>e.base+e.quantity?{manualSize:t.manualSize,computedSize:at((()=>this.getRowTallestCellSize(e.sheetId,i)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"RESIZE_COLUMNS_ROWS":for(let t of e.elements)if("ROW"===e.dimension){const i=this.getRowTallestCellSize(e.sheetId,t);this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:at(i)})}else this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:at(e.size||F)});break;case"UPDATE_CELL":const n=null===(i=null===(t=this.sizes[e.sheetId])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[e.row];if(n&&!n.manualSize){const{sheetId:t,row:i}=e;this.history.update("sizes",t,"ROW",i,"computedSize",at((()=>this.getRowTallestCellSize(t,i))))}break;case"ADD_MERGE":case"REMOVE_MERGE":for(let t of e.target)for(let i of $e(t.top,t.bottom+1)){const t=this.getRowTallestCellSize(e.sheetId,i);t!==this.getRowSize(e.sheetId,i)&&this.history.update("sizes",e.sheetId,"ROW",i,"computedSize",at(t))}}}getColSize(e,t){return this.getHeaderSize(e,"COL",t)}getRowSize(e,t){return this.getHeaderSize(e,"ROW",t)}getHeaderSize(e,t,i){var o,n,s,r;return Math.round((null===(n=null===(o=this.sizes[e])||void 0===o?void 0:o[t][i])||void 0===n?void 0:n.manualSize)||(null===(r=null===(s=this.sizes[e])||void 0===s?void 0:s[t][i])||void 0===r?void 0:r.computedSize())||this.getDefaultHeaderSize(t))}computeSheetSizes(e){var t,i;const o={COL:[],ROW:[]};for(let t of $e(0,this.getters.getNumberCols(e)))o.COL.push(this.getHeaderSize(e,"COL",t));for(let n of $e(0,this.getters.getNumberRows(e))){let s=null===(i=null===(t=this.sizes[e])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[n].manualSize;if(!s){s=this.getRowTallestCellSize(e,n)}o.ROW.push(s)}return o}getDefaultHeaderSize(e){return"COL"===e?F:D}getCellHeight(e){const t=this.getters.getMerge(e);if(t&&t.bottom!==t.top)return D;return function(e){return e&&e.content?Pe(He(e.style),e.isFormula?1:e.content.split(he).length)+2*z:D}(this.getters.getCell(e))}getRowTallestCellSize(e,t){const i=this.getters.getRowCells(e,t);let o=0;for(let e=0;e<i.length;e++){const t=this.getters.getCellById(i[e]);if(!t)continue;const n=this.getters.getCellPosition(t.id),s=this.getCellHeight(n);s>o&&s>D&&(o=s)}return o<=D?D:o}import(e){for(let t of e.sheets){const e={COL:[],ROW:[]};for(let[i,o]of Object.entries(t.rows))o.size&&(e.ROW[i]=o.size);for(let[i,o]of Object.entries(t.cols))o.size&&(e.COL[i]=o.size);const i=this.computeSheetSizes(t.id);this.sizes[t.id]={COL:i.COL.map(((t,i)=>({manualSize:e.COL[i],computedSize:at(t)}))),ROW:i.ROW.map(((t,i)=>({manualSize:e.ROW[i],computedSize:at(t)})))}}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){var i,o;for(let n of e.sheets){void 0===n.rows&&(n.rows={});for(let e of $e(0,this.getters.getNumberRows(n.id)))(t||(null===(i=this.sizes[n.id].ROW[e])||void 0===i?void 0:i.manualSize))&&(n.rows[e]={...n.rows[e],size:this.getRowSize(n.id,e)});void 0===n.cols&&(n.cols={});for(let e of $e(0,this.getters.getNumberCols(n.id)))(t||(null===(o=this.sizes[n.id].COL[e])||void 0===o?void 0:o.manualSize))&&(n.cols[e]={...n.cols[e],size:this.getColSize(n.id,e)})}}}Vv.getters=["getRowSize","getColSize"];class zv extends Mv{constructor(){super(...arguments),this.hiddenHeaders={}}allowDispatch(e){switch(e.type){case"HIDE_COLUMNS_ROWS":{if(!this.getters.tryGetSheet(e.sheetId))return 27;const t="COL"===e.dimension?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),i="COL"===e.dimension?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=i?66:Math.min(...e.elements)<0||Math.max(...e.elements)>i?86:0}case"REMOVE_COLUMNS_ROWS":return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?8:0:27}return 0}handle(e){switch(e.type){case"CREATE_SHEET":const t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update("hiddenHeaders",e.sheetId,t);break;case"DUPLICATE_SHEET":this.history.update("hiddenHeaders",e.sheetIdTo,Fe(this.hiddenHeaders[e.sheetId]));break;case"DELETE_SHEET":this.history.update("hiddenHeaders",e.sheetId,void 0);break;case"REMOVE_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]],i=ct(e.position,e.base);t.splice(i,0,...Array(e.quantity).fill(!1)),this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"HIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!0);break;case"UNHIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!1)}}checkElementsIncludeAllVisibleHeaders(e,t,i){return dt(i,this.getAllVisibleHeaders(e,t))}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]}getHiddenColsGroups(e){const t=[[]],i=this.hiddenHeaders[e].COL;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getHiddenRowsGroups(e){const t=[[]],i=this.hiddenHeaders[e].ROW;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getAllVisibleHeaders(e,t){return $e(0,this.hiddenHeaders[e][t].length).filter((i=>!this.hiddenHeaders[e][t][i]))}import(e){var t,i;for(let o of e.sheets){this.hiddenHeaders[o.id]={COL:[],ROW:[]};for(let e=0;e<o.rowNumber;e++)this.hiddenHeaders[o.id].ROW[e]=Boolean(null===(t=o.rows[e])||void 0===t?void 0:t.isHidden);for(let e=0;e<o.colNumber;e++)this.hiddenHeaders[o.id].COL[e]=Boolean(null===(i=o.cols[e])||void 0===i?void 0:i.isHidden)}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let i of e.sheets){void 0===i.rows&&(i.rows={});for(let e=0;e<this.getters.getNumberRows(i.id);e++)(t||this.hiddenHeaders[i.id].ROW[e])&&(void 0===i.rows[e]&&(i.rows[e]={}),i.rows[e].isHidden=this.hiddenHeaders[i.id].ROW[e]);void 0===i.cols&&(i.cols={});for(let e=0;e<this.getters.getNumberCols(i.id);e++)(t||this.hiddenHeaders[i.id].COL[e])&&(void 0===i.cols[e]&&(i.cols[e]={}),i.cols[e].isHidden=this.hiddenHeaders[i.id].COL[e])}}}zv.getters=["checkElementsIncludeAllVisibleHeaders","getHiddenColsGroups","getHiddenRowsGroups","isRowHiddenByUser","isColHiddenByUser"];class Bv extends Mv{constructor(e){super(e),this.images={},this.syncedImages=new Set,this.fileStore=e.external.fileStore}allowDispatch(e){return"CREATE_IMAGE"===e.type&&this.getters.getFigure(e.sheetId,e.figureId)?28:0}handle(e){switch(e.type){case"CREATE_IMAGE":this.addFigure(e.figureId,e.sheetId,e.position,e.size),this.history.update("images",e.sheetId,e.figureId,e.definition),this.syncedImages.add(e.definition.path);break;case"DUPLICATE_SHEET":{const t=this.getters.getFigures(e.sheetId);for(const i of t)if("image"===i.tag){const t=i.id.split(ee).pop(),o=`${e.sheetIdTo}${ee}${t}`,n=this.getImage(i.id);if(n){const t={width:i.width,height:i.height};this.dispatch("CREATE_IMAGE",{sheetId:e.sheetIdTo,figureId:o,position:{x:i.x,y:i.y},size:t,definition:Fe(n)})}}break}case"DELETE_FIGURE":this.history.update("images",e.sheetId,e.id,void 0);break;case"DELETE_SHEET":this.history.update("images",e.sheetId,void 0)}}garbageCollectExternalResources(){var e;const t=new Set(this.getAllImages().map((e=>e.path)));for(const i of this.syncedImages)t.has(i)||null===(e=this.fileStore)||void 0===e||e.delete(i)}getImage(e){for(const t of Object.values(this.images))if(t&&t[e])return t[e];throw new Error(`There is no image with the given figureId: ${e}`)}getImagePath(e){return this.getImage(e).path}getImageSize(e){return this.getImage(e).size}addFigure(e,t,i,o){const n={id:e,x:i.x,y:i.y,width:o.width,height:o.height,tag:"image"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:n})}import(e){for(const t of e.sheets){const e=(t.figures||[]).filter((e=>"image"===e.tag));for(const i of e)this.history.update("images",t.id,i.id,i.data),this.syncedImages.add(i.data.path)}}export(e){var t;for(const i of e.sheets){const e=i.figures.filter((e=>"image"===e.tag));for(const o of e)o.data=null===(t=this.images[i.id])||void 0===t?void 0:t[o.id]}}exportForExcel(e){for(const t of e.sheets){const e=this.getters.getFigures(t.id),i=[];for(const t of e)if("image"===(null==t?void 0:t.tag)){const e=this.getImage(t.id);e&&i.push({...t,data:Fe(e)})}t.images=i}}getAllImages(){const e=[];for(const t in this.images)e.push(...Object.values(this.images[t]||{}).filter(ot));return e}}Bv.getters=["getImage","getImagePath","getImageSize"];class Hv extends Mv{constructor(){super(...arguments),this.nextId=1,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":const t=this.merges[e.sheetId];if(!t)break;for(const i of Object.values(t).filter(ot))this.addMerge(e.sheetIdTo,i.zone);break;case"ADD_MERGE":for(const t of e.target)this.addMerge(e.sheetId,t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t)}}adaptRanges(e,t){const i=t?[t]:Object.keys(this.merges);for(const t of i)this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map((t=>this.getMergeById(e,parseInt(t,10)))).filter(ot)}getMerge({sheetId:e,col:t,row:i}){var o;const n=this.mergeCellMap[e],s=n?t in n&&(null===(o=n[t])||void 0===o?void 0:o[i]):void 0;return s?this.getMergeById(e,s):void 0}getMergesInZone(e,t){var i;const o=this.mergeCellMap[e];if(!o)return[];const n=new Set;for(const{col:e,row:s}of oo(t)){const t=null===(i=o[e])||void 0===i?void 0:i[s];t&&n.add(t)}return Array.from(n).map((t=>this.getMergeById(e,t))).filter(ot)}doesIntersectMerge(e,t){return oo(t).some((({col:t,row:i})=>void 0!==this.getMerge({sheetId:e,col:t,row:i})))}doesColumnsHaveCommonMerges(e,t,i){const o=this.getters.getSheet(e);for(let n=0;n<this.getters.getNumberRows(e);n++)if(this.isInSameMerge(o.id,t,n,i,n))return!0;return!1}doesRowsHaveCommonMerges(e,t,i){const o=this.getters.getSheet(e);for(let n=0;n<=this.getters.getNumberCols(e);n++)if(this.isInSameMerge(o.id,n,t,n,i))return!0;return!1}expandZone(e,t){let{left:i,right:o,top:n,bottom:s}=t,r={left:i,right:o,top:n,bottom:s};for(let t in this.merges[e]){const i=this.getMergeById(e,parseInt(t));i&&Yi(i,r)&&(r=Zi(i,r))}return Xi(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,i,o,n){const s=this.getMerge({sheetId:e,col:t,row:i}),r=this.getMerge({sheetId:e,col:o,row:n});return!(!s||!r)&&Xi(s,r)}isInMerge({sheetId:e,col:t,row:i}){var o;const n=this.mergeCellMap[e];return!!n&&(t in n&&Boolean(null===(o=n[t])||void 0===o?void 0:o[i]))}getMainCellPosition(e){if(!this.isInMerge(e))return e;const t=this.getMerge(e).topLeft;return{sheetId:e.sheetId,col:t.col,row:t.row}}getBottomLeftCell(e){if(!this.isInMerge(e))return e;const{bottom:t,left:i}=this.getMerge(e);return{sheetId:e.sheetId,col:i,row:t}}isMergeHidden(e,t){const i=this.getters.getHiddenColsGroups(e),o=this.getters.getHiddenRowsGroups(e);for(let e of i)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of o)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const i=this.getMerge({sheetId:e,col:t.left,row:t.top});if(i)return Xi(t,i);const{numberOfCols:o,numberOfRows:n}=to(t);return 1===o&&1===n}isMergeDestructive(e,t){let{left:i,right:o,top:n,bottom:s}=t;o=Le(o,0,this.getters.getNumberCols(e)-1),s=Le(s,0,this.getters.getNumberRows(e)-1);for(let t=n;t<=s;t++)for(let s=i;s<=o;s++)if(s!==i||t!==n){const i=this.getters.getCell({sheetId:e,col:s,row:t});if(i&&""!==i.content)return!0}return!1}getMergeById(e,t){var i;const o=null===(i=this.merges[e])||void 0===i?void 0:i[t];return void 0!==o?Wv(t,o):void 0}checkDestructiveMerge({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;return t.some((t=>this.isMergeDestructive(e,t)))?3:0}checkOverlap({target:e}){for(const t of e)for(const i of e)if(t!==i&&Yi(t,i))return 65;return 0}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;const{xSplit:i,ySplit:o}=this.getters.getPaneDivisions(e);for(const e of t)if(e.left<i&&e.right>=i||e.top<o&&e.bottom>=o)return 75;return 0}checkMergedContentUpdate(e){const{col:t,row:i,content:o}=e;if(void 0===o)return 0;const{col:n,row:s}=this.getMainCellPosition(e);return n===t&&s===i?0:4}checkMergeExists(e){const{sheetId:t,target:i}=e;for(const e of i){const{left:i,top:o}=e,n=this.getMerge({sheetId:t,col:i,row:o});if(void 0===n||!Xi(e,n))return 5}return 0}addMerge(e,t){let{left:i,right:o,top:n,bottom:s}=t;o=Le(o,0,this.getters.getNumberCols(e)-1),s=Le(s,0,this.getters.getNumberRows(e)-1);if(Gt(i,n)===Gt(o,s))return;const r=this.getters.getCell({sheetId:e,col:i,row:n});let a=this.nextId++;this.history.update("merges",e,a,this.getters.getRangeFromSheetXC(e,Hi({left:i,top:n,right:o,bottom:s})));let l=new Set;for(let t=n;t<=s;t++)for(let s=i;s<=o;s++){s===i&&t===n||this.dispatch("UPDATE_CELL",{sheetId:e,col:s,row:t,style:r?r.style:null,content:""});const o=this.getMerge({sheetId:e,col:s,row:t});o&&l.add(o.id),this.history.update("mergeCellMap",e,s,t,a)}for(let t of l){const{top:i,bottom:o,left:n,right:s}=this.getMergeById(e,t);for(let t=i;t<=o;t++)for(let i=n;i<=s;i++){const o={sheetId:e,col:i,row:t},n=this.getMerge(o);n&&n.id===a||(this.history.update("mergeCellMap",e,i,t,void 0),this.dispatch("CLEAR_CELL",o))}this.history.update("merges",e,t,void 0)}}removeMerge(e,t){const{left:i,top:o,bottom:n,right:s}=t,r=this.getMerge({sheetId:e,col:i,row:o});if(void 0!==r&&Xi(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=o;t<=n;t++)for(let o=i;o<=s;o++)this.history.update("mergeCellMap",e,o,t,void 0)}}applyRangeChangeOnSheet(e,t){const i=Object.entries(this.merges[e]||{});for(const[o,n]of i)if(n){const i=n.zone,s=t(n);switch(s.changeType){case"NONE":break;case"REMOVE":this.removeMerge(e,i);break;default:const{numberOfCols:t,numberOfRows:n}=to(s.range.zone);1===t&&1===n?this.removeMerge(e,i):this.history.update("merges",e,parseInt(o,10),s.range)}}this.history.update("mergeCellMap",e,{});for(const t of this.getMerges(e))for(const{col:i,row:o}of oo(t))this.history.update("mergeCellMap",e,i,o,t.id)}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let i of t)this.addMerge(e,zi(i))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...$v(e))}}exportForExcel(e){this.export(e)}}function $v(e){return Object.entries(e).map((([e,t])=>t?Wv(parseInt(e,10),t):void 0)).filter(ot).map((e=>Gt(e.left,e.top)+":"+Gt(e.right,e.bottom)))}function Wv(e,t){return{...t.zone,topLeft:{col:t.zone.left,row:t.zone.top},id:e}}Hv.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCellPosition","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","getMergesInZone","isSingleCellOrMerge"];class Gv{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return"MOVE_RANGES"===e.type?1===e.target.length?0:26:0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",o="COL"===e.dimension?"columns":"rows";const n=[...e.elements];n.sort(((e,t)=>t-e));const s=We(n);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of s){const s=Math.min(...e),l=Math.max(...e);if(n.zone[t]<=s&&s<=n.zone[i]){const e=Math.min(n.zone[i],l)-s+1;a="RESIZE",r=this.createAdaptedRange(r,o,a,-e)}else if(n.zone[t]>=s&&n.zone[i]<=l)a="REMOVE",r=n.clone({...this.getInvalidRange()});else if(n.zone[t]<=l&&n.zone[i]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,o,a,-e),r=this.createAdaptedRange(r,o,"MOVE",-(n.zone[t]-s))}else s<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,o,a,-(l-s+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",o="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(n.zone[t]<=e.base&&e.base<n.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(n,o,"RESIZE",e.quantity)};if(e.base<n.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(n,o,"MOVE",e.quantity)}}else{if(n.zone[t]<e.base&&e.base<=n.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(n,o,"RESIZE",e.quantity)};if(e.base<=n.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(n,o,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId!==e.sheetId)return{changeType:"NONE"};const i=this.getters.getSheetName(e.sheetId);return{changeType:"REMOVE",range:t=t.clone({...this.getInvalidRange(),invalidSheetName:i})}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(e.name&&t.invalidSheetName===e.name){const i=void 0,o=e.sheetId;return{changeType:"CHANGE",range:t.clone({sheetId:o,invalidSheetName:i})}}return{changeType:"NONE"}}));break;case"MOVE_RANGES":{const t=e.target[0];this.executeOnAllRanges((i=>{if(i.sheetId!==e.sheetId||!Qi(i.zone,t))return{changeType:"NONE"};const o=e.targetSheetId,n=e.col-t.left,s=e.row-t.top,r=this.createAdaptedRange(i,"both","MOVE",[n,s]),a=e.sheetId!==o||r.prefixSheet;return{changeType:"MOVE",range:r.clone({sheetId:o,prefixSheet:a})}}));break}}}finalize(){}verifyRangeRemoved(e){return t=>{const i=e(t);return"NONE"===i.changeType||Bi(i.range.zone)?i:{range:i.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,i,o){const n=no(e.unboundedZone,t,i,o);return e.clone({zone:n})}executeOnAllRanges(e,t){const i=this.verifyRangeRemoved(e);for(const e of this.providers)e(i,t)}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,i,o){const n=e.map((e=>Fi.fromRange(e,this.getters)));return n.map((e=>{if(!Bi(e.zone))return e;const n=e.prefixSheet?e.sheetId:o,s={...e.unboundedZone,left:e.isFullRow&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:e.isFullRow?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.isFullCol&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:i),bottom:e.isFullCol?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:i)};return e.clone({sheetId:n,zone:s}).orderZone()}))}getRangeFromSheetXC(e,t){if(!Lt.test(t))return new Fi({sheetId:"",zone:{left:-1,top:-1,right:-1,bottom:-1},parts:[],invalidXc:t,prefixSheet:!1},this.getters.getSheetSize);let i,o=t,n=!1;t.includes("!")&&(({xc:o,sheetName:i}=Bt(t)),i&&(n=!0));const s=Vi(o),r=Fi.getRangeParts(o,s),a=i&&!this.getters.getSheetIdByName(i)?i:void 0,l=this.getters.getSheetIdByName(i)||e;return new Fi({prefixSheet:n,zone:s,sheetId:l,invalidSheetName:a,parts:r},this.getters.getSheetSize).orderZone()}getSelectionRangeString(e,t){const i=Fi.fromRange(e,this.getters),o=this.getters.expandZone(i.sheetId,i.zone),n=i.clone({zone:{...o,bottom:i.isFullCol?void 0:o.bottom,right:i.isFullRow?void 0:o.right}});return this.getRangeString(n,t)}getRangeString(e,t){if(!e)return K;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return K;if(e.zone.left<0||e.zone.top<0)return K;const i=Fi.fromRange(e,this.getters);let o=i.sheetId!==t||i.invalidSheetName||i.prefixSheet,n="";if(o&&(n=i.invalidSheetName?i.invalidSheetName:ke(this.getters.getSheetName(i.sheetId))),o&&!n)return K;let s=this.getRangePartString(i,0);return i.parts&&2===i.parts.length&&(i.zone.top!==i.zone.bottom||i.zone.left!==i.zone.right||i.parts[0].rowFixed||i.parts[0].colFixed||i.parts[1].rowFixed||i.parts[1].colFixed)&&(s+=":",s+=this.getRangePartString(i,1)),`${o?n+"!":""}${s}`}getRangeDataFromXc(e,t){return this.getters.getRangeFromSheetXC(e,t).rangeData}getRangeDataFromZone(e,t){return{_sheetId:e,_zone:t}}getRangeFromRangeData(e){const t={prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]};return new Fi(t,this.getters.getSheetSize)}getRangePartString(e,t){const i=e.parts&&e.parts[t].colFixed?"$":"",o=Ht(0===t?e.zone.left:e.zone.right),n=e.parts&&e.parts[t].rowFixed?"$":"",s=String(0===t?e.zone.top+1:e.zone.bottom+1);let r="";return r=e.isFullCol?0===t&&e.unboundedZone.hasHeader?i+o+n+s:i+o:e.isFullRow?0===t&&e.unboundedZone.hasHeader?i+o+n+s:n+s:i+o+n+s,r}getInvalidRange(){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:K}}}Gv.getters=["getRangeString","getSelectionRangeString","getRangeFromSheetXC","createAdaptedRanges","getRangeDataFromXc","getRangeDataFromZone","getRangeFromRangeData"];class qv extends Mv{constructor(){super(...arguments),this.sheetIdsMapName={},this.orderedSheetIds=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"HIDE_SHEET":return 1===this.getVisibleSheetIds().length?9:0;case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"MOVE_SHEET":try{const t=this.orderedSheetIds.findIndex((t=>t===e.sheetId));return this.findIndexOfTargetSheet(t,e.delta),0}catch(e){return 14}case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.orderedSheetIds.length>1?0:9;case"ADD_COLUMNS_ROWS":const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return e.base<0||e.base>t?86:e.quantity<=0?87:0;case"REMOVE_COLUMNS_ROWS":{const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return Math.min(...e.elements)<0||Math.max(...e.elements)>t?86:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?8:0}case"FREEZE_ROWS":return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case"FREEZE_COLUMNS":return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIdsMapName",t.name,t.id);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.delta);break;case"RENAME_SHEET":this.renameSheet(this.sheets[e.sheetId],e.name);break;case"HIDE_SHEET":this.hideSheet(e.sheetId);break;case"SHOW_SHEET":this.showSheet(e.sheetId);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e);break;case"FREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,e.quantity,"COL");break;case"FREEZE_ROWS":this.setPaneDivisions(e.sheetId,e.quantity,"ROW");break;case"UNFREEZE_ROWS":this.setPaneDivisions(e.sheetId,0,"ROW");break;case"UNFREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,0,"COL");break;case"UNFREEZE_COLUMNS_ROWS":this.setPaneDivisions(e.sheetId,0,"COL"),this.setPaneDivisions(e.sheetId,0,"ROW")}}import(e){var t,i;for(let t of e.sheets)this.sheetIdsMapName[t.name]=t.id;for(let o of e.sheets){const e=o.name||n("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:r}=this.getImportedSheetSize(o),a={id:o.id,name:e,numberOfCols:s,rows:Pi(r),areGridLinesVisible:void 0===o.areGridLinesVisible||o.areGridLinesVisible,isVisible:o.isVisible,panes:{xSplit:(null===(t=o.panes)||void 0===t?void 0:t.xSplit)||0,ySplit:(null===(i=o.panes)||void 0===i?void 0:i.ySplit)||0}};this.orderedSheetIds.push(a.id),this.sheets[a.id]=a}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(ot).map((e=>{const t=this.sheets[e],i={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},conditionalFormats:[],figures:[],filterTables:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible,isVisible:t.isVisible};return(t.panes.xSplit||t.panes.ySplit)&&(i.panes=t.panes),i}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const t=De(e);for(const e in this.sheetIdsMapName)if(e.toUpperCase()===t.toUpperCase())return this.sheetIdsMapName[e]}}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}getEvaluationSheets(){return this.sheets}doesHeaderExist(e,t,i){return"COL"===t?i>=0&&i<this.getNumberCols(e):i>=0&&i<this.getNumberRows(e)}getRow(e,t){const i=this.getSheet(e).rows[t];if(!i)throw new Error(`Row ${i} not found.`);return i}getCell({sheetId:e,col:t,row:i}){var o;const n=this.tryGetSheet(e),s=null===(o=null==n?void 0:n.rows[i])||void 0===o?void 0:o.cells[t];if(void 0!==s)return this.getters.getCellById(s)}getColsZone(e,t,i){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:i}}getRowCells(e,t){var i;return Object.values(null===(i=this.getSheet(e).rows[t])||void 0===i?void 0:i.cells).filter(ot)}getRowsZone(e,t,i){return{top:t,bottom:i,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return"COL"===t?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e="Sheet"){let t=1;const i=this.orderedSheetIds.map(this.getSheetName.bind(this));let o=`${e}${t}`;for(;i.includes(o);)o=`${e}${t}`,t++;return o}getSheetSize(e){return{numberOfRows:this.getNumberRows(e),numberOfCols:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,i){const o={...this.getPaneDivisions(e)};"COL"===i?o.xSplit=t:"ROW"===i&&(o.ySplit=t),this.history.update("sheets",e,"panes",o)}checkElementsIncludeAllNonFrozenHeaders(e,t,i){const o=this.getters.getPaneDivisions(e),n="ROW"===t?o.ySplit:o.xSplit,s=this.getters.getNumberHeaders(e,t);if(!n)return!1;return dt(i,$e(n,s))}isEmpty(e,t){return oo(t).map((({col:t,row:i})=>this.getCell({sheetId:e,col:t,row:i}))).every((e=>!e||""===e.content))}updateCellPosition(e){const{sheetId:t,cellId:i,col:o,row:n}=e;i?this.setNewPosition(i,t,o,n):this.clearPosition(t,o,n)}setNewPosition(e,t,i,o){const n=this.cellPosition[e];n&&this.clearPosition(t,n.col,n.row),this.history.update("cellPosition",e,{row:o,col:i,sheetId:t}),this.history.update("sheets",t,"rows",o,"cells",i,e)}clearPosition(e,t,i){var o;const n=null===(o=this.sheets[e])||void 0===o?void 0:o.rows[i].cells[t];n&&(this.history.update("cellPosition",n,void 0),this.history.update("sheets",e,"rows",i,"cells",t,void 0))}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++){this.sheets[e].rows[o].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:o})}}createSheet(e,t,i,o,n){const s={id:e,name:t,numberOfCols:i,rows:Pi(o),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},r=this.orderedSheetIds.slice();r.splice(n,0,s.id);const a=this.sheets;return this.history.update("orderedSheetIds",r),this.history.update("sheets",Object.assign({},a,{[s.id]:s})),s}moveSheet(e,t){const i=this.orderedSheetIds.slice(),o=i.findIndex((t=>t===e)),n=i.splice(o,1);let s=this.findIndexOfTargetSheet(o,t);i.splice(s,0,n[0]),this.history.update("orderedSheetIds",i)}findIndexOfTargetSheet(e,t){for(;0!=t&&0<=e&&e<=this.orderedSheetIds.length;)t>0?(e++,this.isSheetVisible(this.orderedSheetIds[e])&&t--):t<0&&(e--,this.isSheetVisible(this.orderedSheetIds[e])&&t++);if(0===t)return e;throw new Error(s("There is not enough visible sheets"))}checkSheetName(e){const{orderedSheetIds:t,sheets:i}=this,o=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return(null===(t=i[e])||void 0===t?void 0:t.name.toLowerCase())===o}))?11:re.test(o)?13:0}checkSheetPosition(e){const{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?15:0}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?0:74}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?0:74}checkRowFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.top<e.quantity&&e.quantity<=i.bottom)return 65;return 0}checkColFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.left<e.quantity&&e.quantity<=i.right)return 65;return 0}isRenameAllowed(e){return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const i=e.name;this.history.update("sheets",e.id,"name",t.trim());const o=Object.assign({},this.sheetIdsMapName);o[t]=e.id,delete o[i],this.history.update("sheetIdsMapName",o)}hideSheet(e){this.history.update("sheets",e,"isVisible",!1)}showSheet(e){this.history.update("sheets",e,"isVisible",!0)}duplicateSheet(e,t){const i=this.getSheet(e),o=this.getDuplicateSheetName(i.name),n=Fe(i);n.id=t,n.name=o;for(let e=0;e<=n.numberOfCols;e++)for(let t=0;t<=n.rows.length;t++)n.rows[t]&&(n.rows[t].cells[e]=void 0);const s=this.orderedSheetIds.slice(),r=s.indexOf(e);s.splice(r+1,0,n.id),this.history.update("orderedSheetIds",s),this.history.update("sheets",Object.assign({},this.sheets,{[n.id]:n}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:i}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:n.id,col:e,row:i,content:t.content,format:t.format,style:t.style})}const a=Object.assign({},this.sheetIdsMapName);a[n.name]=n.id,this.history.update("sheetIdsMapName",a)}getDuplicateSheetName(e){let t=1;const i=this.orderedSheetIds.map(this.getSheetName.bind(this)),o=s("Copy of %s",e);let n=o.toString();for(;i.includes(n);)n=`${o} (${t})`,t++;return n}deleteSheet(e){const t=e.name,i=Object.assign({},this.sheets);delete i[e.id],this.history.update("sheets",i);const o=this.orderedSheetIds.slice(),n=o.indexOf(e.id);o.splice(n,1),this.history.update("orderedSheetIds",o);const s=Object.assign({},this.sheetIdsMapName);delete s[t],this.history.update("sheetIdsMapName",s)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let i of t)this.moveCellOnColumnsDeletion(e,i);const i=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",i-t.length);const o=t.filter((t=>t<e.panes.xSplit)).length;o&&this.setPaneDivisions(e.id,e.panes.xSplit-o,"COL")}removeRows(e,t){t.sort(((e,t)=>t-e));for(let i of We(t))this.moveCellOnRowsDeletion(e,i[i.length-1],i[0]),i.map((t=>this.updateRowsStructureOnDeletion(t,e)));const i=t.filter((t=>t<e.panes.ySplit)).length;i&&this.setPaneDivisions(e.id,e.panes.ySplit-i,"ROW")}addColumns(e,t,i,o){const n="before"===i?t:t+1;this.moveCellsOnAddition(e,n,o,"columns");const s=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",s+o),n<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+o,"COL")}addRows(e,t,i,o){const n="before"===i?t:t+1;this.addEmptyRows(e,o),this.moveCellsOnAddition(e,n,o,"rows"),this.updateRowsStructureOnAddition(e,t,o),n<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+o,"ROW")}moveCellOnColumnsDeletion(e,t){for(let i=0;i<e.rows.length;i++){const o=e.rows[i];for(let n in o.cells){const s=Number(n),r=o.cells[n];r&&(s===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:i}),s>t&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r,col:s-1,row:i}))}}}moveCellsOnAddition(e,t,i,o){const n=[];for(let s=0;s<e.rows.length;s++){const r=e.rows[s];if("rows"!==o||s>=t)for(let a in r.cells){const l=Number(a),c=r.cells[a];c&&("rows"===o||l>=t)&&n.push({type:"UPDATE_CELL_POSITION",sheetId:e.id,cellId:c,col:l+("columns"===o?i:0),row:s+("rows"===o?i:0)})}}for(let e of n.reverse())this.dispatch(e.type,e)}moveCellOnRowsDeletion(e,t,i){const o=i-t+1;for(let n=0;n<e.rows.length;n++){const s=e.rows[n];if(n>=t&&n<=i)for(let t in s.cells){const i=Number(t);s.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:i,row:n})}if(n>i)for(let t in s.cells){const i=Number(t),r=s.cells[t];r&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r,col:i,row:n-o})}}}updateRowsStructureOnDeletion(e,t){const i=[],o=t.rows.map((e=>e.cells));for(let n in t.rows)Number(n)!==e&&i.push({cells:o.shift()});this.history.update("sheets",t.id,"rows",i)}updateRowsStructureOnAddition(e,t,i){const o=[],n=e.rows.map((e=>e.cells));e.rows.forEach((()=>o.push({cells:n.shift()}))),this.history.update("sheets",e.id,"rows",o)}addEmptyRows(e,t){const i=e.rows.slice();for(let e=0;e<t;e++)i.push({cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(Wt);let i=e.rowNumber,o=e.colNumber;for(let{col:e,row:n}of t)i=Math.max(i,n+1),o=Math.max(o,e+1);return{rowNumber:i,colNumber:o}}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?27:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),"ranges"in e&&Array.isArray(e.ranges)&&t.push(...e.ranges.map((e=>this.getters.getRangeFromRangeData(e).zone))),!t.every(Bi))return 25;if(t.length&&"sheetId"in e){const i=this.getSheetZone(e.sheetId);return t.every((e=>Qi(e,i)))?0:18}return 0}}qv.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheetIds","getVisibleSheetIds","isSheetVisible","getEvaluationSheets","doesHeaderExist","getCell","getCellPosition","getColsZone","getRowCells","getRowsZone","getNumberCols","getNumberRows","getNumberHeaders","getGridLinesVisibility","getNextSheetName","isEmpty","getSheetSize","getSheetZone","getPaneDivisions","checkElementsIncludeAllNonFrozenHeaders"];class Zv extends Av{constructor({getters:e,stateObserver:t,dispatch:i,uiActions:o,selection:n}){super(t,i),this.getters=e,this.ui=o,this.selection=n}drawGrid(e,t){}}Zv.layers=[];class jv extends Zv{constructor(){super(...arguments),this.customColors=new Set,this.shouldUpdateColors=!1}handle(e){switch(e.type){case"UPDATE_CELL":case"UPDATE_CHART":case"CREATE_CHART":case"ADD_CONDITIONAL_FORMAT":this.shouldUpdateColors=!0}}finalize(){if(this.shouldUpdateColors){this.shouldUpdateColors=!1;for(const e of this.getCustomColors())this.tryToAddColor(e)}}getCustomColors(){let e=[];for(const t of this.getters.getSheetIds()){const i=Object.values(this.getters.getCells(t));e=e.concat(this.getColorsFromCells(i),this.getFormattingColors(t),this.getChartColors(t))}return function(e){const t=[{leadColor:It(255,0,0),colors:[]},{leadColor:It(255,128,0),colors:[]},{leadColor:It(128,128,0),colors:[]},{leadColor:It(128,255,0),colors:[]},{leadColor:It(0,255,0),colors:[]},{leadColor:It(0,255,128),colors:[]},{leadColor:It(0,255,255),colors:[]},{leadColor:It(0,127,255),colors:[]},{leadColor:It(0,0,255),colors:[]},{leadColor:It(127,0,255),colors:[]},{leadColor:It(128,0,128),colors:[]},{leadColor:It(255,0,128),colors:[]}];for(const i of e.map(At)){let e=500,o=0;t.forEach(((t,n)=>{const s=(r=i,a=t.leadColor,Math.sqrt(Math.pow(r.r-a.r,2)+Math.pow(r.g-a.g,2)+Math.pow(r.b-a.b,2)));var r,a;e>s&&(e=s,o=n)})),t[o].colors.push(i)}return t.map((e=>e.colors.sort(((e,t)=>Ot(e).s-Ot(t).s)))).flat().map(Tt)}([...new Set([...new Set([...e,...this.customColors])].filter(yt).map(wt))]).filter((e=>!O.includes(e)))}getColorsFromCells(e){var t,i;const o=new Set;for(const n of e)(null===(t=n.style)||void 0===t?void 0:t.textColor)&&o.add(n.style.textColor),(null===(i=n.style)||void 0===i?void 0:i.fillColor)&&o.add(n.style.fillColor);return[...o]}getFormattingColors(e){const t=this.getters.getConditionalFormats(e),i=[];for(const e of t){const t=e.rule;"CellIsRule"===t.type?(i.push(t.style.textColor),i.push(t.style.fillColor)):"ColorScaleRule"===t.type&&(i.push(Et(t.minimum.color)),i.push(t.midpoint?Et(t.midpoint.color):void 0),i.push(Et(t.maximum.color)))}return i.filter(ot)}getChartColors(e){const t=this.getters.getChartIds(e).map((e=>this.getters.getChart(e)));let i=new Set;for(let e of t){if(void 0===e)continue;const t=e.getDefinition().background;switch(void 0!==t&&i.add(t),e.type){case"gauge":const t=e.sectionRule.colors;i.add(t.lowerColor),i.add(t.middleColor),i.add(t.upperColor);break;case"scorecard":const o=e;i.add(o.baselineColorDown),i.add(o.baselineColorUp)}}return[...i]}tryToAddColor(e){const t=wt(e);e&&!O.includes(t)&&this.customColors.add(t)}}jv.getters=["getCustomColors"];const Xv=Yu.mapping;class Yv extends Zv{constructor(e){super(e),this.isUpToDate=!1,this.evaluatedCells={},this.evalContext=e.custom,this.lazyEvaluation=e.lazyEvaluation}handle(e){switch(ln.has(e.type)&&(this.isUpToDate=!1),e.type){case"UPDATE_CELL":("content"in e||"format"in e)&&(this.isUpToDate=!1);break;case"EVALUATE_CELLS":this.evaluate()}}finalize(){this.isUpToDate||(this.evaluate(),this.isUpToDate=!0)}evaluateFormula(e,t=this.getters.getActiveSheetId()){const i=df(e),o=this.getCompilationParameters((e=>this.getEvaluatedCell(this.getters.getCellPosition(e.id)))),n=[];for(let e of i.dependencies)n.push(this.getters.getRangeFromSheetXC(t,e));return i.execute(n,...o).value}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.formattedValue))}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.value))}getRangeFormats(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.format))}getEvaluatedCell({sheetId:e,col:t,row:i}){var o,n,s;return void 0===this.getters.getCell({sheetId:e,col:t,row:i})?Sn(""):(null===(s=null===(n=null===(o=this.evaluatedCells[e])||void 0===o?void 0:o[t])||void 0===n?void 0:n[i])||void 0===s?void 0:s.call(n))||Sn("")}getEvaluatedCells(e){const t=this.getters.getCells(e)||{},i={};for(let e of Object.keys(t)){const t=this.getters.getCellPosition(e);i[e]=this.getEvaluatedCell(t)}return i}getColEvaluatedCells(e,t){var i;return Object.values((null===(i=this.evaluatedCells[e])||void 0===i?void 0:i[t])||[]).filter(ot).map((e=>e()))}getEvaluatedCellsInZone(e,t){return oo(t).map((({col:t,row:i})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:i})))}setEvaluatedCell(e,t){const{col:i,row:o,sheetId:n}=this.getters.getCellPosition(e);this.evaluatedCells[n]||(this.evaluatedCells[n]={}),this.evaluatedCells[n][i]||(this.evaluatedCells[n][i]={}),this.evaluatedCells[n][i][o]=t,this.lazyEvaluation||this.evaluatedCells[n][i][o]()}*getAllCells(){for(const e of this.getters.getSheetIds()){const t=this.getters.getCells(e);for(const e in t)yield t[e]}}evaluate(){this.evaluatedCells={};const e=new Set,t=e=>{var t,n;const s=e.id,{col:r,row:a,sheetId:l}=this.getters.getCellPosition(s),c=null===(n=null===(t=this.evaluatedCells[l])||void 0===t?void 0:t[r])||void 0===n?void 0:n[a];return c||at((()=>{try{switch(e.isFormula){case!0:return o(e);case!1:return vn(e.content,e.format)}}catch(t){return i(t,e)}}))},i=(e,t)=>{e instanceof Error||(e=new Error(e));const i=(null==e?void 0:e.errorType)||a.GenericError,o=n[2].__lastFnCalled||"",s=new c(i,e.message.replace("[[FUNCTION_NAME]]",o),void 0!==e.logLevel?e.logLevel:l.error);return yn(t.content,s)},o=t=>{const i=t.id;if(e.has(i))throw new d;n[2].__originCellXC=()=>{const e=n[2].getters.getCellPosition(i);return Gt(e.col,e.row)},e.add(i);const o=t.compiledFormula.execute(t.dependencies,...n);if(e.delete(i),Array.isArray(o.value))throw new Error(s("This formula depends on invalid values"));return Sn(o.value,t.format||o.format)},n=this.getCompilationParameters((e=>t(e)()));for(const e of this.getAllCells())this.setEvaluatedCell(e.id,t(e))}getCompilationParameters(e){const t=Object.assign(Object.create(Xv),this.evalContext,{getters:this.getters}),i=this.getters;const o=t=>{const i=e(t);if(i.type===rn.error)throw i.error;return i};return[function(e,t,n,r){if(t)return{value:Hi(e.zone)};if(!Bi(e.zone))throw new u;if(e.zone.bottom!==e.zone.top||e.zone.left!==e.zone.right)throw new Error(r?s("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",n.toString(),r.toString()):s("Function %s expects its parameters to be single values or single cell references, not ranges.",n.toString()));if(e.invalidSheetName)throw new Error(s("Invalid sheet name: %s",e.invalidSheetName));return function(e){let t;if(!i.tryGetSheet(e.sheetId))throw new Error(s("Invalid sheet name"));return t=i.getCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}),t&&""!==t.content?o(t):{value:null,format:null==t?void 0:t.format}}(e)},function(e){const n=e.sheetId;if(!Bi(e.zone))throw new u;const s=i.getSheetZone(n),r=[],a=ji(e.zone,s);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const n=[];for(let s=a.top;s<=a.bottom;s++){const r=t.getters.getCell({sheetId:e.sheetId,col:i,row:s});n.push(r?o(r):void 0)}r.push(n)}return r},t]}exportForExcel(e){for(let t of e.sheets)for(const e in t.cells){const i={sheetId:t.id,...Wt(e)},o=this.getters.getCell(i);if(o){const n=t.cells[e],s=this.getEvaluatedCell(i);n.value=s.value,n.isFormula=o.isFormula&&!this.isBadExpression(o.content),o.format!==s.format&&(n.computedFormat=s.format)}}}isBadExpression(e){try{return df(e),!1}catch(e){return!0}}}Yv.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues","getRangeFormats","getEvaluatedCell","getEvaluatedCells","getColEvaluatedCells","getEvaluatedCellsInZone"];class Kv extends Zv{constructor(){super(...arguments),this.charts={},this.createRuntimeChart=function(e){const t=lr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i){const o=t.find((e=>e.match(i.type)));if(!o)throw new Error("No runtime builder for this chart.");return o.getChartRuntime(i,e)}}(this.getters)}handle(e){if(ln.has(e.type)||cn.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type)for(const e in this.charts)this.charts[e]=void 0;switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":case"DELETE_FIGURE":this.charts[e.id]=void 0;break;case"DELETE_SHEET":for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0)}}getChartRuntime(e){if(!this.charts[e]){const t=this.getters.getChart(e);if(!t)throw new Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getBackgroundOfSingleCellChart(e,t){if(e)return e;if(!t)return w;const i=t.zone.left,o=t.zone.top,n=t.sheetId;return this.getters.getCellComputedStyle({sheetId:n,col:i,row:o}).fillColor||w}}Kv.getters=["getChartRuntime","getBackgroundOfSingleCellChart"];class Qv extends Zv{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new Ui,this.rulePredicate={CellIsRule:(e,t)=>{if(e.type===rn.error)return!1;const i=t.values.map(bn);switch(t.operator){case"IsEmpty":return""===e.value.toString().trim();case"IsNotEmpty":return""!==e.value.toString().trim();case"BeginsWith":return""!==i[0]&&e.value.toString().startsWith(i[0].toString());case"EndsWith":return""!==i[0]&&e.value.toString().endsWith(i[0].toString());case"Between":return e.value>=i[0]&&e.value<=i[1];case"NotBetween":return!(e.value>=i[0]&&e.value<=i[1]);case"ContainsText":return e.value.toString().indexOf(i[0].toString())>-1;case"NotContains":return!e.value||-1==e.value.toString().indexOf(i[0].toString());case"GreaterThan":return e.value>i[0];case"GreaterThanOrEqual":return e.value>=i[0];case"LessThan":return e.value<i[0];case"LessThanOrEqual":return e.value<=i[0];case"NotEqual":return""!==i[0]&&e.value!==i[0];case"Equal":return""===i[0]||e.value===i[0];default:console.warn(s("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch((cn.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isStale=!0),e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const i=this.getters.getActiveSheetId(),o=this.getters.getRulesByCell(i,e.originCol,e.originRow);for(const t of o)this.adaptRules(i,t,[Gt(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation)}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getCellComputedStyle(e){var t;const{sheetId:i,col:o,row:n}=e,s=this.getters.getCell(e),r=this.computedStyles[i],a=r&&(null===(t=r[o])||void 0===t?void 0:t[n]),l={...null==s?void 0:s.style,...a};return this.getters.getEvaluatedCell(e).link&&!l.textColor&&(l.textColor=I),this.getters.isFilterHeader(e)&&(l.bold=!0),l}getConditionalIcon({col:e,row:t}){var i;const o=this.getters.getActiveSheetId(),n=this.computedIcons[o];return n&&(null===(i=n[e])||void 0===i?void 0:i[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const i=this.computedStyles[t];for(let o of this.getters.getConditionalFormats(t).reverse())try{switch(o.rule.type){case"ColorScaleRule":for(let e of o.ranges)this.applyColorScale(e,o.rule);break;case"IconSetRule":for(let e of o.ranges)this.applyIcon(e,o.rule);break;default:for(let n of o.ranges){const s=this.getters.getRangeFromSheetXC(t,n).zone;for(let n=s.top;n<=s.bottom;n++)for(let r=s.left;r<=s.right;r++){const s=this.rulePredicate[o.rule.type];let a=this.getters.getEvaluatedCell({sheetId:t,col:r,row:n});s&&s(a,o.rule)&&(i[r]||(i[r]=[]),i[r][n]=Object.assign((null===(e=i[r])||void 0===e?void 0:e[n])||{},o.rule.style))}}}}catch(e){}}parsePoint(e,t,i){const o=this.getters.getActiveSheetId(),n=this.getters.getEvaluatedCellsInZone(o,this.getters.getRangeFromSheetXC(o,e).zone).filter((e=>e.type===rn.number)).map((e=>e.value));switch(t.type){case"value":return"max"===i?Math.max(...n):Math.min(...n);case"number":return Number(t.value);case"percentage":const e=Math.min(...n);return e+(Math.max(...n)-e)*Number(t.value)/100;case"percentile":return si(n,Number(t.value)/100,!0);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return o instanceof Promise?null:o;default:return null}}applyIcon(e,t){const i=this.parsePoint(e,t.lowerInflectionPoint),o=this.parsePoint(e,t.upperInflectionPoint);if(null===i||null===o||i>o)return;const n=this.getters.getActiveSheetId(),s=this.getters.getRangeFromSheetXC(n,e).zone,r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=s.top;e<=s.bottom;e++)for(let l=s.left;l<=s.right;l++){const s=this.getters.getEvaluatedCell({sheetId:n,col:l,row:e});if(s.type!==rn.number)continue;const c=this.computeIcon(s.value,o,t.upperInflectionPoint.operator,i,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,i,o,n,s){return"ge"===i&&e>=t||"gt"===i&&e>t?s[0]:"ge"===n&&e>=o||"gt"===n&&e>o?s[1]:s[2]}applyColorScale(e,t){var i;const o=this.parsePoint(e,t.minimum,"min"),n=t.midpoint?this.parsePoint(e,t.midpoint):null,s=this.parsePoint(e,t.maximum,"max");if(null===o||null===s||o>=s||n&&(o>=n||n>=s))return;const r=this.getters.getActiveSheetId(),a=this.getters.getRangeFromSheetXC(r,e).zone,l=this.computedStyles[r],c=[];t.midpoint&&n?(c.push({minValue:o,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.minimum.color,t.midpoint.color)}),c.push({minValue:n,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(n,s,t.midpoint.color,t.maximum.color)})):c.push({minValue:o,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(o,s,t.minimum.color,t.maximum.color)});for(let e=a.top;e<=a.bottom;e++)for(let t=a.left;t<=a.right;t++){const a=this.getters.getEvaluatedCell({sheetId:r,col:t,row:e});if(a.type===rn.number){const r=Le(a.value,o,s);let h;h=2===c.length&&n?r<=n?this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(r,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(i=l[t])||void 0===i?void 0:i[e])||{},l[t][e].fillColor=Et(h)}}}computeColorDiffUnits(e,t,i,o){const n=t-e;return[((i>>16)%256-(o>>16)%256)/n,((i>>8)%256-(o>>8)%256)/n,(i%256-o%256)/n]}colorCell(e,t,i,o){const[n,s,r]=o;return Math.round((i>>16)%256-n*(e-t))<<16|Math.round((i>>8)%256-s*(e-t))<<8|Math.round(i%256-r*(e-t))}adaptRules(e,t,i,o){if(0===i.length&&0===o.length)return;const n=this.getters.getConditionalFormats(e),s=n.findIndex((e=>e.id===t.id));let r=[];s>-1&&(r=n[s].ranges),r=r.concat(i);const a=Ji(r,o);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},ranges:a.map((t=>this.getters.getRangeDataFromXc(e,t))),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,i){const o=Gt(t.col,t.row);for(let n of this.getters.getConditionalFormats(e.sheetId))for(let s of n.ranges)if(Ki(e.col,e.row,this.getters.getRangeFromSheetXC(e.sheetId,s).zone)){const s=n,r=[];if("CUT"===i&&r.push(Gt(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,s,[o],r);else{this.adaptRules(e.sheetId,s,[],r);const i=this.getCFToCopyTo(t.sheetId,s);this.adaptRules(t.sheetId,i,[o],[])}}}getCFToCopyTo(e,t){const i=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&ht(e.rule,t.rule)));return i||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}Qv.getters=["getConditionalIcon","getCellComputedStyle"];class Jv extends Zv{constructor(){super(...arguments),this.filterValues={},this.hiddenRows=new Set,this.isEvaluationDirty=!1}allowDispatch(e){if("UPDATE_FILTER"===e.type)if(!this.getters.getFilterId(e))return 79;return 0}handle(e){switch(e.type){case"UNDO":case"REDO":case"UPDATE_CELL":case"EVALUATE_CELLS":case"ACTIVATE_SHEET":case"REMOVE_FILTER_TABLE":this.isEvaluationDirty=!0;break;case"START":for(const e of this.getters.getSheetIds()){this.filterValues[e]={};for(const t of this.getters.getFilters(e))this.filterValues[e][t.id]=[]}break;case"CREATE_SHEET":this.filterValues[e.sheetId]={};break;case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":this.updateHiddenRows();break;case"UPDATE_FILTER":this.updateFilter(e),this.updateHiddenRows();break;case"DUPLICATE_SHEET":const t={};for(const i of this.getters.getFilters(e.sheetIdTo)){const o=i.zoneWithHeaders;t[i.id]=this.getFilterValues({sheetId:e.sheetId,col:o.left,row:o.top})}this.filterValues[e.sheetIdTo]=t}}finalize(){this.isEvaluationDirty&&(this.updateHiddenRows(),this.isEvaluationDirty=!1)}isRowFiltered(e,t){return e===this.getters.getActiveSheetId()&&this.hiddenRows.has(t)}getCellBorderWithFilterBorder(e){const{sheetId:t,col:i,row:o}=e;let n;for(let e of this.getters.getFilterTables(t)){const s=e.zone;if(Ki(i,o,s)){const e=this.intersectZoneWithViewport(t,s);n={top:o===e.top?X:void 0,bottom:o===e.bottom?X:void 0,left:i===e.left?X:void 0,right:i===e.right?X:void 0}}}const s=this.getters.getCellBorder(e),r={...n,...ut(s||{})};return nt(r)?null:r}getFilterHeaders(e){const t=[];for(let i of this.getters.getFilterTables(e)){const o=i.zone;if(!o)continue;const n=o.top;for(let i=o.left;i<=o.right;i++)this.getters.isColHidden(e,i)||this.getters.isRowHidden(e,n)||t.push({col:i,row:n})}return t}getFilterValues(e){const t=this.getters.getFilterId(e),i=e.sheetId;return t&&this.filterValues[i]&&this.filterValues[i][t]||[]}isFilterHeader({sheetId:e,col:t,row:i}){return this.getFilterHeaders(e).some((e=>e.col===t&&e.row===i))}isFilterActive(e){var t,i;const o=this.getters.getFilterId(e),n=e.sheetId;return Boolean(o&&(null===(i=null===(t=this.filterValues[n])||void 0===t?void 0:t[o])||void 0===i?void 0:i.length))}intersectZoneWithViewport(e,t){return{left:this.getters.findVisibleHeader(e,"COL",t.left,t.right),right:this.getters.findVisibleHeader(e,"COL",t.right,t.left),top:this.getters.findVisibleHeader(e,"ROW",t.top,t.bottom),bottom:this.getters.findVisibleHeader(e,"ROW",t.bottom,t.top)}}updateFilter({col:e,row:t,values:i,sheetId:o}){const n=this.getters.getFilterId({sheetId:o,col:e,row:t});n&&(this.filterValues[o]||(this.filterValues[o]={}),this.filterValues[o][n]=i)}updateHiddenRows(){var e,t;const i=this.getters.getActiveSheetId(),o=this.getters.getFilters(i).sort(((e,t)=>e.zoneWithHeaders.top-t.zoneWithHeaders.top)),n=new Set;for(let s of o){if(this.getters.isRowHiddenByUser(i,s.zoneWithHeaders.top))continue;if(n.has(s.zoneWithHeaders.top))continue;const o=null===(t=null===(e=this.filterValues[i])||void 0===e?void 0:e[s.id])||void 0===t?void 0:t.map(gt);if(o&&s.filteredZone)for(let e=s.filteredZone.top;e<=s.filteredZone.bottom;e++){const t=this.getCellValueAsString(i,s.col,e);o.includes(t)&&n.add(e)}}this.hiddenRows=n}getCellValueAsString(e,t,i){return this.getters.getEvaluatedCell({sheetId:e,col:t,row:i}).formattedValue.toLowerCase()}exportForExcel(e){for(const t of e.sheets){const e=t.id;for(const i of t.filterTables){const o=zi(i.range),n=[],s=[];for(const i of $e(0,to(o).numberOfCols)){const r={sheetId:t.id,col:o.left+i,row:o.top},a=this.getFilterValues(r),l=this.getters.getFilter(r);if(!l)continue;const c=l.filteredZone?oo(l.filteredZone).map((t=>this.getters.getEvaluatedCell({sheetId:e,...t}).formattedValue)):[];if(a.length){const e=c.filter((e=>e)).filter((e=>!a.includes(e)));n.push({colId:i,displayedValues:[...new Set(e)],displayBlanks:!a.includes("")&&c.some((e=>!e))})}const h={col:l.col,row:l.zoneWithHeaders.top,sheetId:e},d=this.getters.getEvaluatedCell(h).formattedValue,u=this.getUniqueColNameForExcel(i,d,s);s.push(u),t.cells[Gt(h.col,h.row)]={...t.cells[Gt(h.col,h.row)],content:u,value:u,isFormula:!1}}i.filters=n}}}getUniqueColNameForExcel(e,t,i){t||(t=`Column${e}`);let o=t,n=2;for(;i.includes(o);)o=t+String(n),n++;return o}}Jv.getters=["getCellBorderWithFilterBorder","getFilterHeaders","getFilterValues","isFilterHeader","isRowFiltered","isFilterActive"];class eb{constructor(e,t,i,o,n,s){this.getters=e,this.sheetId=t,this.boundaries=i,this.viewportWidth=o.width,this.viewportHeight=o.height,this.offsetScrollbarX=s.x,this.offsetScrollbarY=s.y,this.canScrollVertically=n.canScrollVertically,this.canScrollHorizontally=n.canScrollHorizontally,this.offsetCorrectionX=this.getters.getColDimensions(this.sheetId,this.boundaries.left).start,this.offsetCorrectionY=this.getters.getRowDimensions(this.sheetId,this.boundaries.top).start,this.adjustViewportOffsetX(),this.adjustViewportOffsetY()}getMaxSize(){const e=this.getters.findLastVisibleColRowIndex(this.sheetId,"COL",{first:this.boundaries.left,last:this.boundaries.right}),t=this.getters.findLastVisibleColRowIndex(this.sheetId,"ROW",{first:this.boundaries.top,last:this.boundaries.bottom}),{end:i,size:o}=this.getters.getColDimensions(this.sheetId,e),{end:n,size:s}=this.getters.getRowDimensions(this.sheetId,t),r=this.searchHeaderIndex("COL",i-this.viewportWidth,0),a=this.getters.getColSize(this.sheetId,r),l=this.searchHeaderIndex("ROW",n-this.viewportHeight,0),c=this.getters.getRowSize(this.sheetId,l);let h=i-this.offsetCorrectionX;this.canScrollHorizontally&&(h+=Math.max(F,Math.min(a,this.viewportWidth-o)),h=Math.max(h,this.viewportWidth));let d=n-this.offsetCorrectionY;return this.canScrollVertically&&(d+=Math.max(D+5,Math.min(c,this.viewportHeight-s)),d=Math.max(d,this.viewportHeight)),{width:h,height:d}}getColIndex(e,t=!1){return e<this.offsetCorrectionX||e>this.offsetCorrectionX+this.viewportWidth?-1:this.searchHeaderIndex("COL",e-this.offsetCorrectionX,this.left,t)}getRowIndex(e,t=!1){return e<this.offsetCorrectionY||e>this.offsetCorrectionY+this.viewportHeight?-1:this.searchHeaderIndex("ROW",e-this.offsetCorrectionY,this.top,t)}adjustPosition(e){const t=this.sheetId;e||(e=this.getters.getSheetPosition(t));const i=this.getters.getMainCellPosition({sheetId:t,...e}),{col:o,row:n}=this.getters.getNextVisibleCellPosition(i);Ki(o,this.boundaries.top,this.boundaries)&&this.adjustPositionX(o),Ki(this.boundaries.left,n,this.boundaries)&&this.adjustPositionY(n)}adjustPositionX(e){const t=this.sheetId,{end:i}=this.getters.getColDimensions(t,e),o=this.getters.getNumberCols(t);if(this.offsetX+this.offsetCorrectionX+this.viewportWidth<i){let i=e;for(;this.getters.isColHidden(t,i)&&e<o;)i++;const n=this.getters.getColDimensions(t,i).end,s=this.searchHeaderIndex("COL",n-this.viewportWidth-this.offsetCorrectionX,this.boundaries.left,!0);this.offsetX=this.getters.getColDimensions(t,s).end-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}else if(this.left>e){let i=e;for(;this.getters.isColHidden(t,i)&&e>0;)i--;this.offsetX=this.getters.getColDimensions(t,i).start-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}}adjustPositionY(e){const t=this.sheetId,{end:i}=this.getters.getRowDimensions(t,e),o=this.getters.getNumberRows(t);if(this.offsetY+this.viewportHeight+this.offsetCorrectionY<i){let i=e;for(;this.getters.isRowHidden(t,i)&&e<o;)i++;const n=this.getters.getRowDimensions(t,i).end,s=this.searchHeaderIndex("ROW",n-this.viewportHeight-this.offsetCorrectionY,this.boundaries.top,!0);this.offsetY=this.getters.getRowDimensions(t,s).end-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}else if(this.top>e){let i=e;for(;this.getters.isRowHidden(t,i)&&e>0;)i--;this.offsetY=this.getters.getRowDimensions(t,i).start-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}}setViewportOffset(e,t){this.setViewportOffsetX(e),this.setViewportOffsetY(t)}adjustViewportZone(){this.adjustViewportZoneX(),this.adjustViewportZoneY()}getRect(e){const t=ji(e,this.zone);if(t){return{x:this.getters.getColRowOffset("COL",this.zone.left,t.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,t.top)+this.offsetCorrectionY,width:Math.min(this.getters.getColRowOffset("COL",t.left,t.right+1),this.viewportWidth),height:Math.min(this.getters.getColRowOffset("ROW",t.top,t.bottom+1),this.viewportHeight)}}}isVisible(e,t){return t<=this.bottom&&t>=this.top&&e>=this.left&&e<=this.right&&!this.getters.isColHidden(this.sheetId,e)&&!this.getters.isRowHidden(this.sheetId,t)}searchHeaderIndex(e,t,i=0,o=!1){let n=0;const s=this.sheetId,r=this.getters.getNumberHeaders(s,e);for(let a=i;a<=r-1;a++){const i=o||"COL"!==e?a<this.top&&a>this.bottom:a<this.left&&a>this.right;if(!this.getters.isHeaderHidden(s,e,a)&&!i&&(n+="COL"===e?this.getters.getColSize(s,a):this.getters.getRowSize(s,a),n>t))return a}return-1}get zone(){return{left:this.left,right:this.right,top:this.top,bottom:this.bottom}}setViewportOffsetX(e){this.canScrollHorizontally&&(this.offsetScrollbarX=e,this.adjustViewportZoneX())}setViewportOffsetY(e){this.canScrollVertically&&(this.offsetScrollbarY=e,this.adjustViewportZoneY())}adjustViewportOffsetX(){if(this.canScrollHorizontally){const{width:e}=this.getMaxSize();this.viewportWidth+this.offsetScrollbarX>e&&(this.offsetScrollbarX=Math.max(0,e-this.viewportWidth))}this.left=this.getColIndex(this.offsetScrollbarX,!0),this.right=this.getColIndex(this.offsetScrollbarX+this.viewportWidth,!0),-1===this.right&&(this.right=this.boundaries.right),this.adjustViewportZoneX()}adjustViewportOffsetY(){if(this.canScrollVertically){const{height:e}=this.getMaxSize();this.viewportHeight+this.offsetScrollbarY>e&&(this.offsetScrollbarY=Math.max(0,e-this.viewportHeight))}this.top=this.getRowIndex(this.offsetScrollbarY,!0),this.bottom=this.getRowIndex(this.offsetScrollbarY+this.viewportWidth,!0),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.adjustViewportZoneY()}adjustViewportZoneX(){const e=this.sheetId;this.left=this.searchHeaderIndex("COL",this.offsetScrollbarX,this.boundaries.left),this.right=Math.min(this.boundaries.right,this.searchHeaderIndex("COL",this.viewportWidth,this.left)),-1===this.left&&(this.left=this.boundaries.left),-1===this.right&&(this.right=this.getters.getNumberCols(e)-1),this.offsetX=this.getters.getColDimensions(e,this.left).start-this.getters.getColDimensions(e,this.boundaries.left).start}adjustViewportZoneY(){const e=this.sheetId;this.top=this.searchHeaderIndex("ROW",this.offsetScrollbarY,this.boundaries.top),this.bottom=Math.min(this.boundaries.bottom,this.searchHeaderIndex("ROW",this.viewportHeight,this.top)),-1===this.top&&(this.top=this.boundaries.top),-1===this.bottom&&(this.bottom=this.getters.getNumberRows(e)-1),this.offsetY=this.getters.getRowDimensions(e,this.top).start-this.getters.getRowDimensions(e,this.boundaries.top).start}}class tb extends Zv{constructor(){super(...arguments),this.viewports={},this.sheetViewWidth=1e3,this.sheetViewHeight=1e3,this.gridOffsetX=0,this.gridOffsetY=0,this.sheetsWithDirtyViewports=new Set}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkScrollingDirection(e);case"RESIZE_SHEETVIEW":return this.chainValidations(this.checkValuesAreDifferent,this.checkPositiveDimension)(e);default:return 0}}handleEvent(e){switch(e.type){case"HeadersSelected":case"AlterZone":break;case"ZonesSelected":let{col:t,row:i}=so(e.previousAnchor.zone,e.anchor.zone);if("updateAnchor"===e.mode){const o=e.previousAnchor.zone,n=e.anchor.zone,{top:s,bottom:r,left:a,right:l}=this.getters.getActiveMainViewport();o.left===n.left&&o.right===n.right&&(t=a>t||t>l?a:t),o.top===n.top&&o.bottom===n.bottom&&(i=s>i||i>r?s:i)}const o=this.getters.getActiveSheetId();t=Math.min(t,this.getters.getNumberCols(o)-1),i=Math.min(i,this.getters.getNumberRows(o)-1),this.refreshViewport(this.getters.getActiveSheetId(),{col:t,row:i})}}handle(e){var t;switch(this.cleanViewports(),e.type){case"START":this.selection.observe(this,{handleEvent:this.handleEvent.bind(this)}),this.resetViewports(this.getters.getActiveSheetId());break;case"UNDO":case"REDO":this.resetSheetViews();break;case"RESIZE_SHEETVIEW":this.resizeSheetView(e.height,e.width,e.gridOffsetX,e.gridOffsetY);break;case"SET_VIEWPORT_OFFSET":this.setSheetViewOffset(e.offsetX,e.offsetY);break;case"SHIFT_VIEWPORT_DOWN":const{top:i}=this.getActiveMainViewport(),o=this.getters.getActiveSheetId(),n=this.clipOffsetY(this.getters.getRowDimensions(o,i).start+this.sheetViewHeight);this.shiftVertically(n);break;case"SHIFT_VIEWPORT_UP":{const{top:e}=this.getActiveMainViewport(),t=this.getters.getActiveSheetId(),i=this.clipOffsetY(this.getters.getRowDimensions(t,e).end-this.sheetViewHeight);this.shiftVertically(i);break}case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"UPDATE_FILTER":this.resetViewports(e.sheetId);break;case"UPDATE_CELL":("content"in e||"format"in e||void 0!==(null===(t=e.style)||void 0===t?void 0:t.fontSize))&&this.sheetsWithDirtyViewports.add(e.sheetId);break;case"ACTIVATE_SHEET":this.setViewports(),this.refreshViewport(e.sheetIdTo);break;case"UNFREEZE_ROWS":case"UNFREEZE_COLUMNS":case"FREEZE_COLUMNS":case"FREEZE_ROWS":case"UNFREEZE_COLUMNS_ROWS":this.resetViewports(this.getters.getActiveSheetId());break;case"DELETE_SHEET":this.sheetsWithDirtyViewports.delete(e.sheetId);break;case"START_EDITION":const{col:s,row:r}=this.getters.getActivePosition();this.refreshViewport(this.getters.getActiveSheetId(),{col:s,row:r})}}finalize(){for(const e of this.sheetsWithDirtyViewports)this.resetViewports(e);this.sheetsWithDirtyViewports=new Set,this.setViewports()}setViewports(){var e;const t=this.getters.getSheetIds();for(const i of t)(null===(e=this.viewports[i])||void 0===e?void 0:e.bottomRight)||this.resetViewports(i)}getColIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getColIndex(e))))}getRowIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getRowIndex(e))))}getSheetViewDimensionWithHeaders(){return{width:this.sheetViewWidth+this.gridOffsetX,height:this.sheetViewHeight+this.gridOffsetY}}getSheetViewDimension(){return{width:this.sheetViewWidth,height:this.sheetViewHeight}}getActiveMainViewport(){const e=this.getters.getActiveSheetId();return this.getMainViewport(e)}getActiveSheetScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetX,scrollY:t.offsetY}}getActiveSheetDOMScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetScrollbarX,scrollY:t.offsetScrollbarY}}getSheetViewVisibleCols(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.left,e.right+1))).flat())].filter((t=>!this.getters.isHeaderHidden(e,"COL",t)))}getSheetViewVisibleRows(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.top,e.bottom+1))).flat())].filter((t=>!this.getters.isHeaderHidden(e,"ROW",t)))}getMainViewportRect(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e),{xSplit:i,ySplit:o}=this.getters.getPaneDivisions(e);let{width:n,height:s}=t.getMaxSize();return{x:this.getters.getColDimensions(e,i).start,y:this.getters.getRowDimensions(e,o).start,width:n,height:s}}getMaximumSheetOffset(){const e=this.getters.getActiveSheetId(),{width:t,height:i}=this.getMainViewportRect(),o=this.getMainInternalViewport(e);return{maxOffsetX:Math.max(0,t-o.viewportWidth+1),maxOffsetY:Math.max(0,i-o.viewportHeight+1)}}getColRowOffsetInViewport(e,t,i){const o=this.getters.getActiveSheetId(),n=this.getters.getSheetViewVisibleCols(),s=this.getters.getSheetViewVisibleRows();if(i<t)return-this.getColRowOffsetInViewport(e,i,t);let r=0;const a="COL"===e?n:s;for(let n=t;n<i;n++)a.includes(n)&&(r+="COL"===e?this.getters.getColSize(o,n):this.getters.getRowSize(o,n));return r}isVisibleInViewport({sheetId:e,col:t,row:i}){return this.getSubViewports(e).some((e=>e.isVisible(t,i)))}getEdgeScrollCol(e,t,i){let o=!1,n=0,s=0;const{xSplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{width:a}=this.getSheetViewDimension(),{x:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollX;return e>a?(o=!0,s=Xt(e-a),n=1):e<l&&i>=l&&c>0?(o=!0,s=Xt(l-e),n=-1):r&&t<l&&e>l&&(o=!0,s=Xt(e),n="reset"),{canEdgeScroll:o,direction:n,delay:s}}getEdgeScrollRow(e,t,i){let o=!1,n=0,s=0;const{ySplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{height:a}=this.getSheetViewDimension(),{y:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollY;return e>a?(o=!0,s=Xt(e-a),n=1):e<l&&i>=l&&c>0?(o=!0,s=Xt(l-e),n=-1):r&&t<l&&e>l&&(o=!0,s=Xt(e),n="reset"),{canEdgeScroll:o,direction:n,delay:s}}getVisibleRect(e){const t=this.getters.getActiveSheetId(),i=this.getSubViewports(t).map((t=>t.getRect(e))).filter(ot);if(0===i.length)return{x:0,y:0,width:0,height:0};const o=Math.min(...i.map((e=>e.x))),n=Math.min(...i.map((e=>e.y))),s=Math.max(...i.map((e=>e.x+e.width)))-o,r=Math.max(...i.map((e=>e.y+e.height)))-n;return{x:o+this.gridOffsetX,y:n+this.gridOffsetY,width:s,height:r}}getMainViewportCoordinates(){const e=this.getters.getActiveSheetId(),{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e);return{x:this.getters.getColDimensions(e,t).start,y:this.getters.getRowDimensions(e,i).start}}ensureMainViewportExist(e){this.viewports[e]||this.resetViewports(e)}getSubViewports(e){return this.ensureMainViewportExist(e),Object.values(this.viewports[e]).filter(ot)}checkPositiveDimension(e){return e.width<0||e.height<0?68:0}checkValuesAreDifferent(e){const{height:t,width:i}=this.getSheetViewDimension();return e.gridOffsetX===this.gridOffsetX&&e.gridOffsetY===this.gridOffsetY&&e.width===i&&e.height===t?76:0}checkScrollingDirection({offsetX:e,offsetY:t}){const i=this.getMainInternalViewport(this.getters.getActiveSheetId());return!i.canScrollHorizontally&&e>0||!i.canScrollVertically&&t>0?69:0}getMainViewport(e){const t=this.getMainInternalViewport(e);return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}getMainInternalViewport(e){return this.ensureMainViewportExist(e),this.viewports[e].bottomRight}cleanViewports(){const e=this.getters.getSheetIds();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetSheetViews(){for(let e of Object.keys(this.viewports)){const t=this.getters.getSheetPosition(e);this.resetViewports(e);const i=this.getSubViewports(e);Object.values(i).forEach((e=>{e.adjustPosition(t)}))}}resizeSheetView(e,t,i=0,o=0){this.sheetViewHeight=e,this.sheetViewWidth=t,this.gridOffsetX=i,this.gridOffsetY=o,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.resetViewports(e)}setSheetViewOffset(e,t){const i=this.getters.getActiveSheetId(),{maxOffsetX:o,maxOffsetY:n}=this.getMaximumSheetOffset();Object.values(this.getSubViewports(i)).forEach((i=>i.setViewportOffset(Le(e,0,o),Le(t,0,n))))}clipOffsetY(e){const{height:t}=this.getMainViewportRect(),i=t-this.sheetViewHeight;return e=Math.min(e,i),e=Math.max(e,0)}getViewportOffset(e){var t,i;return{x:(null===(t=this.viewports[e])||void 0===t?void 0:t.bottomRight.offsetScrollbarX)||0,y:(null===(i=this.viewports[e])||void 0===i?void 0:i.bottomRight.offsetScrollbarY)||0}}resetViewports(e){if(!this.getters.tryGetSheet(e))return;const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),o=this.getters.getNumberCols(e),n=this.getters.getNumberRows(e),s=this.getters.getColRowOffset("COL",0,t,e),r=this.getters.getColRowOffset("ROW",0,i,e),{xRatio:a,yRatio:l}=this.getFrozenSheetViewRatio(e),c=a<1,h=l<1,d=this.getViewportOffset(e),u={topLeft:i&&t&&new eb(this.getters,e,{left:0,right:t-1,top:0,bottom:i-1},{width:s,height:r},{canScrollHorizontally:!1,canScrollVertically:!1},{x:0,y:0})||void 0,topRight:i&&new eb(this.getters,e,{left:t,right:o-1,top:0,bottom:i-1},{width:this.sheetViewWidth-s,height:r},{canScrollHorizontally:c,canScrollVertically:!1},{x:c?d.x:0,y:0})||void 0,bottomLeft:t&&new eb(this.getters,e,{left:0,right:t-1,top:i,bottom:n-1},{width:s,height:this.sheetViewHeight-r},{canScrollHorizontally:!1,canScrollVertically:h},{x:0,y:h?d.y:0})||void 0,bottomRight:new eb(this.getters,e,{left:t,right:o-1,top:i,bottom:n-1},{width:this.sheetViewWidth-s,height:this.sheetViewHeight-r},{canScrollHorizontally:c,canScrollVertically:h},{x:c?d.x:0,y:h?d.y:0})};this.viewports[e]=u}refreshViewport(e,t){Object.values(this.getSubViewports(e)).forEach((e=>{e.adjustViewportZone(),e.adjustPosition(t)}))}shiftVertically(e){const{top:t}=this.getActiveMainViewport(),{scrollX:i}=this.getActiveSheetScrollInfo();this.setSheetViewOffset(i,e);const{anchor:o}=this.getters.getSelection(),n=this.getActiveMainViewport().top-t;this.selection.selectCell(o.cell.col,o.cell.row+n)}getVisibleFigures(){const e=this.getters.getActiveSheetId(),t=[],i=this.getters.getFigures(e),{scrollX:o,scrollY:n}=this.getActiveSheetScrollInfo(),{x:s,y:r}=this.getters.getMainViewportCoordinates(),{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders();for(const e of i)e.x>=s&&(e.x+e.width<=s+o||e.x>=a+o+s)||e.y>=r&&(e.y+e.height<=r+n||e.y>=l+n+r)||t.push(e);return t}getFrozenSheetViewRatio(e){const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),o=this.getters.getColDimensions(e,t).start,n=this.getters.getRowDimensions(e,i).start;return{xRatio:o/(this.sheetViewWidth+this.gridOffsetX),yRatio:n/(this.sheetViewHeight+this.gridOffsetY)}}}tb.getters=["getColIndex","getRowIndex","getActiveMainViewport","getSheetViewDimension","getSheetViewDimensionWithHeaders","getMainViewportRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow","getVisibleFigures","getVisibleRect","getColRowOffsetInViewport","getMainViewportCoordinates","getActiveSheetScrollInfo","getActiveSheetDOMScrollInfo","getSheetViewVisibleCols","getSheetViewVisibleRows","getFrozenSheetViewRatio"];class ib{constructor(e,t,i){this.index=0,this.cells=e,this.getters=t,this.direction=i}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:i,tooltip:o}=In.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:i,tooltip:o,origin:{col:e.data.col,row:e.data.row}}}}class ob extends Zv{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:Le(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:Le(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:45;case"AUTOFILL_AUTO":const i=this.getters.getSelectedZone();return i.top===i.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),i=this.autofillZone;switch(this.direction){case"down":for(let o=t.left;o<=t.right;o++){const n=[];for(let e=t.top;e<=t.bottom;e++)n.push(Gt(o,e));const s=this.createGenerator(n);for(let t=i.top;t<=i.bottom;t++)this.computeNewCell(s,o,t,e)}break;case"up":for(let o=t.left;o<=t.right;o++){const n=[];for(let e=t.bottom;e>=t.top;e--)n.push(Gt(o,e));const s=this.createGenerator(n);for(let t=i.bottom;t>=i.top;t--)this.computeNewCell(s,o,t,e)}break;case"left":for(let o=t.top;o<=t.bottom;o++){const n=[];for(let e=t.right;e>=t.left;e--)n.push(Gt(e,o));const s=this.createGenerator(n);for(let t=i.right;t>=i.left;t--)this.computeNewCell(s,t,o,e)}break;case"right":for(let o=t.top;o<=t.bottom;o++){const n=[];for(let e=t.left;e<=t.right;e++)n.push(Gt(e,o));const s=this.createGenerator(n);for(let t=i.left;t<=i.right;t++)this.computeNewCell(s,t,o,e)}}e&&(this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0)}select(e,t){const i=this.getters.getSelectedZone();if(Ki(e,t,i))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case"up":this.saveZone(t,i.top-1,i.left,i.right),this.steps=i.top-t;break;case"down":this.saveZone(i.bottom+1,t,i.left,i.right),this.steps=t-i.bottom;break;case"left":this.saveZone(i.top,i.bottom,e,i.left-1),this.steps=i.left-e;break;case"right":this.saveZone(i.top,i.bottom,i.right+1,e),this.steps=e-i.right}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let i=e.left,o=e.bottom;if(i>0){let e=this.getters.getEvaluatedCell({sheetId:t,col:i-1,row:o});for(;e.type!==rn.empty;)o+=1,e=this.getters.getEvaluatedCell({sheetId:t,col:i-1,row:o})}if(o===e.bottom&&(i=e.right,i<=this.getters.getNumberCols(t))){let e=this.getters.getEvaluatedCell({sheetId:t,col:i+1,row:o});for(;e.type!==rn.empty;)o+=1,e=this.getters.getEvaluatedCell({sheetId:t,col:i+1,row:o})}o!==e.bottom&&(this.select(e.left,o-1),this.autofill(!0))}computeNewCell(e,t,i,o){const{cellData:n,tooltip:s,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=n;this.tooltip=s,o&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:i,content:a,style:l,border:c,format:h})}getRule(e,t){const i=Rn.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((i=>i.condition(e,t)));return i&&i.generateRule(e,t)}createGenerator(e){const t=[],i=[],o=this.getters.getActiveSheetId();for(let t of e){const{col:e,row:n}=Wt(t),s=this.getters.getCell({sheetId:o,col:e,row:n});i.push({col:e,row:n,cell:s,sheetId:o})}const n=i.map((e=>e.cell));for(let e of i){let i={type:"COPY_MODIFIER"};if(e&&e.cell){i=this.getRule(e.cell,n)||i}const o=this.getters.getCellBorder(e)||void 0;t.push({data:{...e,border:o},rule:i})}return new ib(t,this.getters,this.direction)}saveZone(e,t,i,o){this.autofillZone={top:e,bottom:t,left:i,right:o}}getDirection(e,t){const i=this.getters.getSelectedZone(),o={up:{number:i.top-t,value:"up"},down:{number:t-i.bottom,value:"down"},left:{number:i.left-e,value:"left"},right:{number:e-i.right,value:"right"}};if(1===Object.values(o).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(o).find((e=>e.number>0?1:0)).value;const n=o.up.number>0?"up":"down",s=o.left.number>0?"left":"right";return Math.abs(o[n].number)>=Math.abs(o[s].number)?o[n].value:o[s].value}autoFillMerge(e,t,i,o){const n=this.getters.getActiveSheetId(),s={sheetId:n,col:i,row:o},r={sheetId:n,col:e,row:t};if(this.getters.isInMerge(s)&&!this.getters.isInMerge(r)){const e=this.getters.getMerge(s);e&&this.dispatch("REMOVE_MERGE",{sheetId:n,target:[e]})}const a=this.getters.getMerge(r);(null==a?void 0:a.topLeft.col)===e&&(null==a?void 0:a.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:n,target:[{top:o,bottom:o+a.bottom-a.top,left:i,right:i+a.right-a.left}]})}drawGrid(e){if(!this.autofillZone)return;const{ctx:t,thinLineWidth:i}=e,{x:o,y:n,width:s,height:r}=this.getters.getVisibleRect(this.autofillZone);s>0&&r>0&&(t.strokeStyle="black",t.lineWidth=i,t.setLineDash([3]),t.strokeRect(o,n,s,r),t.setLineDash([]))}}ob.layers=[5],ob.getters=["getAutofillTooltip"];class nb extends Zv{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:i}=this.getters.getSelection();for(const o of t){const t=this.getAutomaticSums(e,o,i.cell);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,i){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,i):this.sumData(e,t)}sumData(e,t){const i=this.dimensionsToSum(e,t),o=this.sumDimensions(e,t,i).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return i.has("ROW")&&i.has("COL")&&o.push(this.sumTotal(t)),o}sumAdjacentData(e,t,i){const{col:o,row:n}=Ki(i.col,i.row,t)?i:{col:t.left,row:t.top},s=this.findAdjacentData(e,o,n);return s?this.getters.isSingleCellOrMerge(e,t)||io(Zi(s,t))?[{position:{col:o,row:n},zone:s}]:this.sumDimensions(e,Zi(s,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,i){const o=this.getters.getSheet(e),n=this.getters.getMainCellPosition({sheetId:e,col:t,row:i}),s=this.findSuitableZoneToSum(o,n.col,n.row);if(s)return this.getters.expandZone(e,s)}findSuitableZoneToSum(e,t,i){const o=this.getters.getEvaluatedCell({sheetId:e.id,col:t,row:i-1}),n=this.getters.getEvaluatedCell({sheetId:e.id,col:t-1,row:i});if(this.isNumber(n)&&!this.isNumber(o))return this.findHorizontalZone(e,t,i);const s=this.findVerticalZone(e,t,i);if(this.isZoneValid(s))return s;const r=this.findHorizontalZone(e,t,i);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,i){const o={top:0,bottom:i-1,left:t,right:t},n=this.reduceZoneStart(e,o,o.bottom);return{...o,top:n}}findHorizontalZone(e,t,i){const o={top:i,bottom:i,left:0,right:t-1},n=this.reduceZoneStart(e,o,o.right);return{...o,left:n}}reduceZoneStart(e,t,i){const o=this.getters.getEvaluatedCellsInZone(e.id,t),n=$e(i,-1,-1),s=n.filter((e=>o[e]&&!o[e].isAutoSummable)),r=Math.max(...s),a=We(n.filter((e=>this.isNumber(o[e]))))[0]||[];return Math.max(...a)<r?1/0:Math.min(...a)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return e.type===rn.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(Y))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const i=new Set;return io(t)?(i.add(1===to(t).numberOfCols?"COL":"ROW"),i):(this.lastColIsEmpty(e,t)&&i.add("ROW"),this.lastRowIsEmpty(e,t)&&i.add("COL"),0===i.size&&i.add("COL"),i)}sumDimensions(e,t,i){return[...i.has("COL")?this.sumColumns(t,e):[],...i.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:i}=e;return{position:{col:i,row:t},zone:{...e,top:t,right:i-1}}}sumColumns(e,t){const i=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,i.bottom-1)},oo(i).map((t=>({position:t,zone:{...e,right:t.col,left:t.col}})))}sumRows(e,t){const i=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,i.right-1)},oo(i).map((t=>({position:t,zone:{...e,top:t.row,bottom:t.row}})))}dispatchCellUpdates(e,t){for(const i of t){const{col:t,row:o}=i.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,content:`=SUM(${this.getters.zoneToXC(e,i.zone)})`})}}nextEmptyRow(e,t){let i=t.bottom+1;const{left:o,right:n}=t;for(;!this.getters.isEmpty(e,{bottom:i,top:i,left:o,right:n});)i++;return{...t,top:i,bottom:i}}nextEmptyCol(e,t){let i=t.right+1;const{top:o,bottom:n}=t;for(;!this.getters.isEmpty(e,{left:i,right:i,top:o,bottom:n});)i++;return{...t,left:i,right:i}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}nb.getters=["getAutomaticSums"];class sb extends Zv{allowDispatch(e){if("OPEN_CELL_POPOVER"===e.type){try{rs.get(e.popoverType)}catch(e){return 72}return 0}return 0}handle(e){switch(e.type){case"ACTIVATE_SHEET":case"CLOSE_CELL_POPOVER":this.persistentPopover=void 0;break;case"OPEN_CELL_POPOVER":this.persistentPopover={col:e.col,row:e.row,sheetId:this.getters.getActiveSheetId(),type:e.popoverType}}}getCellPopover({col:e,row:t}){var i,o;const n=this.getters.getActiveSheetId();if(this.persistentPopover&&this.getters.isVisibleInViewport(this.persistentPopover)){const e=this.getters.getMainCellPosition(this.persistentPopover),t=null===(o=(i=rs.get(this.persistentPopover.type)).onOpen)||void 0===o?void 0:o.call(i,e,this.getters);return(null==t?void 0:t.isOpen)?{...t,anchorRect:this.computePopoverAnchorRect(this.persistentPopover)}:{isOpen:!1}}if(void 0===e||void 0===t||!this.getters.isVisibleInViewport({sheetId:n,col:e,row:t}))return{isOpen:!1};const s=this.getters.getMainCellPosition({sheetId:n,col:e,row:t}),r=rs.getAll().map((e=>{var t;return null===(t=e.onHover)||void 0===t?void 0:t.call(e,s,this.getters)})).find((e=>null==e?void 0:e.isOpen));return(null==r?void 0:r.isOpen)?{...r,anchorRect:this.computePopoverAnchorRect(s)}:{isOpen:!1}}hasOpenedPopover(){return void 0!==this.persistentPopover}getPersistentPopoverTypeAtPosition({col:e,row:t}){if(this.persistentPopover&&this.persistentPopover.col===e&&this.persistentPopover.row===t)return this.persistentPopover.type}computePopoverAnchorRect({col:e,row:t}){const i=this.getters.getActiveSheetId(),o=this.getters.getMerge({sheetId:i,col:e,row:t});return o?this.getters.getVisibleRect(o):this.getters.getVisibleRect(ao({col:e,row:t}))}}sb.getters=["getCellPopover","getPersistentPopoverTypeAtPosition","hasOpenedPopover"];var rb;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(rb||(rb={}));class ab extends Zv{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.toSearch="",this.isSearchDirty=!1}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(rb.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(rb.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith);break;case"UNDO":case"REDO":case"REMOVE_FILTER_TABLE":case"UPDATE_FILTER":case"REMOVE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":this.isSearchDirty=!0;break;case"ACTIVATE_SHEET":this.refreshSearch()}}finalize(){this.isSearchDirty&&(this.refreshSearch(),this.isSearchDirty=!1)}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(rb.current)}updateRegex(){let e=_e(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),i=[];if(this.toSearch)for(const o of Object.values(t)){const{col:t,row:n}=this.getters.getCellPosition(o.id),s=this.getters.isColHidden(e,t),r=this.getters.isRowHidden(e,n);if(!s&&!r&&(o&&this.currentSearchRegex&&this.currentSearchRegex.test(this.getSearchableString({sheetId:e,col:t,row:n})))){const e={col:t,row:n,selected:!1};i.push(e)}}return i.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let i;i=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,i=(i%t.length+t.length)%t.length,this.selectedMatchIndex=i,this.selection.selectCell(t[i].col,t[i].row);for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1}}replaceMatch(e,t){if(!this.currentSearchRegex)return;const i=this.getters.getActiveSheetId(),o=this.getters.getCell({sheetId:i,...e}),{col:n,row:s}=e;if((null==o?void 0:o.isFormula)&&!this.searchOptions.searchFormulas)return;const r=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),a=this.getSearchableString({sheetId:i,col:n,row:s}).replace(r,t);this.dispatch("UPDATE_CELL",{sheetId:i,col:n,row:s,content:a})}replace(e){if(null===this.selectedMatchIndex)return;const t=this.searchMatches[this.selectedMatchIndex];this.replaceMatch(t,e),this.selectNextCell(rb.next)}replaceAll(e){const t=this.searchMatches.length;for(let i=0;i<t;i++)this.replaceMatch(this.searchMatches[i],e)}getSearchableString(e){const t=this.getters.getCell(e);return this.searchOptions.searchFormulas&&(null==t?void 0:t.isFormula)?t.content:this.getters.getEvaluatedCell(e).formattedValue}drawGrid(e){const{ctx:t}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge({sheetId:i,col:e.col,row:e.row}),n=o?o.left:e.col,s=o?o.right:e.col,r=o?o.top:e.row,a=o?o.bottom:e.row,{x:l,y:c,width:h,height:d}=this.getters.getVisibleRect({top:r,left:n,right:s,bottom:a});h>0&&d>0&&(t.fillStyle="#8B008B33",t.fillRect(l,c,h,d),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(l,c,h,d)))}}}ab.layers=[3],ab.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class lb extends Zv{isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,i){return"COL"===t?this.isColHidden(e,i):this.isRowHidden(e,i)}getNextVisibleCellPosition({sheetId:e,col:t,row:i}){return{sheetId:e,col:this.findVisibleHeader(e,"COL",t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,"ROW",i,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,i,o){if(i<=o)for(let n=i;n<=o;n++)if(this.getters.doesHeaderExist(e,t,n)&&!this.isHeaderHidden(e,t,n))return n;if(i>o)for(let n=i;n>=o;n--)if(this.getters.doesHeaderExist(e,t,n)&&!this.isHeaderHidden(e,t,n))return n}findLastVisibleColRowIndex(e,t,{last:i,first:o}){return $e(i,o,-1).find((i=>!this.isHeaderHidden(e,t,i)))||o}findFirstVisibleColRowIndex(e,t){const i=this.getters.getNumberHeaders(e,t);for(let o=0;o<i;o++){if("COL"===t&&!this.isColHidden(e,o))return o;if("ROW"===t&&!this.isRowHidden(e,o))return o}}exportForExcel(e){for(const t of e.sheets)for(const[e,i]of Object.entries(t.rows)){const o=this.isRowHidden(t.id,Number(e));i.isHidden=o}}}lb.getters=["getNextVisibleCellPosition","findVisibleHeader","findLastVisibleColRowIndex","findFirstVisibleColRowIndex","isRowHidden","isColHidden","isHeaderHidden"];class cb extends Zv{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){return e.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getNumberRows(e.sheetId)&&e.zone.right<this.getters.getNumberCols(e.sheetId))).map((e=>{const{numberOfRows:t,numberOfCols:i}=to(e.zone),o=t*i==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:o}}))}drawGrid(e){const{ctx:t,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;const s=this.getHighlights();for(let e of s.filter(((e,t)=>s.findIndex((t=>Xi(t.zone,e.zone)&&t.sheetId===o))===t))){const{x:i,y:o,width:s,height:r}=this.getters.getVisibleRect(e.zone);s>0&&r>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,s-n,r-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,s-2*n,r-2*n))}}}cb.layers=[1],cb.getters=["getHighlights"];class hb extends Zv{constructor(){super(...arguments),this.boxes=[]}getColDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleCols()),o=this.getters.getColRowOffsetInViewport("COL",i,t),n=this.getters.getColSize(e,t);return{start:o,size:n,end:o+(this.getters.isColHidden(e,t)?0:n)}}getRowDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleRows()),o=this.getters.getColRowOffsetInViewport("ROW",i,t),n=this.getters.getRowSize(e,t);return{start:o,size:n,end:o+(this.getters.isRowHidden(e,t)?0:n)}}getHeaderOffset(e,t,i){let o=this.getters.getColRowOffsetInViewport(e,t,i);return this.getters.isDashboard()||(o+="ROW"===e?N:_),o}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(),this.drawBackground(e),this.drawOverflowingCellBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e))}}drawBackground(e){const{ctx:t,thinLineWidth:i}=e,{width:o,height:n}=this.getters.getSheetViewDimensionWithHeaders();t.fillStyle="#ffffff",t.fillRect(0,0,o+m,n+m);const s=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId()),r=s?.1*i:0;if(s)for(const e of this.boxes)t.strokeStyle="#E2E3E3",t.lineWidth=i,t.strokeRect(e.x+r,e.y+r,e.width-2*r,e.height-2*r)}drawCellBackground(e){const{ctx:t}=e;for(const e of this.boxes){let i=e.style;i.fillColor&&"#ffffff"!==i.fillColor&&(t.fillStyle=i.fillColor||"#ffffff",t.fillRect(e.x,e.y,e.width,e.height)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawOverflowingCellBackground(e){var t,i;const{ctx:o,thinLineWidth:n}=e;for(const e of this.boxes)if(e.content&&e.isOverflow){const s=e.content.align||"left";let r,a;const l=e.y+n/2,c=e.height-n,h=Math.min((null===(t=e.clipRect)||void 0===t?void 0:t.width)||1/0,e.content.width);"left"===s?(r=e.x+n/2,a=h-2*n):"right"===s?(r=e.x+e.width-n/2,a=2*n-h):(r=((null===(i=e.clipRect)||void 0===i?void 0:i.x)||e.x+e.width/2-e.content.width/2)+n/2,a=h-2*n),o.fillStyle="#ffffff",o.fillRect(r,l,a,c)}}drawBorders(e){const{ctx:t,thinLineWidth:i}=e;for(let e of this.boxes){const t=e.border;if(t){const{x:i,y:n,width:s,height:r}=e;t.left&&o(t.left,i,n,i,n+r),t.top&&o(t.top,i,n,i+s,n),t.right&&o(t.right,i+s,n,i+s,n+r),t.bottom&&o(t.bottom,i,n+r,i+s,n+r)}}function o([e,o],n,s,r,a){t.strokeStyle=o,t.lineWidth=("thin"===e?2:3)*i,t.beginPath(),t.moveTo(n,s),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:i}=e;let o;t.textBaseline="top";for(let e of this.boxes)if(e.content){const n=e.style||{},s=e.content.align||"left",r=Be(n);r!==o&&(o=r,t.font=r),t.fillStyle=n.textColor||"#000";let a=e.x;if(a+="left"===s?V+(e.image?e.image.size+U:0):"right"===s?e.width-V-(e.isFilterHeader?20:0):e.width/2,t.textAlign=s,e.clipRect){t.save(),t.beginPath();const{x:i,y:o,width:n,height:s}=e.clipRect;t.rect(i,o,n,s),t.clip()}const l=He(n),c=e.content.textLines.length;let h=this.computeTextYCoordinate(e,l,c);for(let o of e.content.textLines){if(t.fillText(o,Math.round(a),Math.round(h)),n.strikethrough||n.underline){const e=Ue(t,o,n);let r=a;"right"===s?r-=e:"center"===s&&(r-=e/2),n.strikethrough&&t.fillRect(r,h+l/2,e,2.6*i),n.underline&&t.fillRect(r,h+l+1,e,1.3*i)}h+=V+l}e.clipRect&&t.restore()}}drawIcon(e){const{ctx:t}=e;for(const e of this.boxes)if(e.image){const i=e.image.image;if(e.image.clipIcon){t.save(),t.beginPath();const{x:i,y:o,width:n,height:s}=e.image.clipIcon;t.rect(i,o,n,s),t.clip()}const o=e.image.size,n=this.computeTextYCoordinate(e,o);t.drawImage(i,e.x+U,n,o,o),e.image.clipIcon&&t.restore()}}computeTextYCoordinate(e,t,i=1){const o=e.y+1,n=Pe(t,i),s=e.height>n+2*V,r=e.verticalAlign||"middle";if(s){if("middle"===r)return o+(e.height-n)/2;if("bottom"===r)return o+e.height-n-V}return o+V}drawHeaders(e){const{ctx:t,thinLineWidth:i}=e,o=this.getters.getSheetViewVisibleCols(),n=o[0],s=o[o.length-1],r=this.getters.getSheetViewVisibleRows(),a=r[0],l=r[r.length-1],{width:c,height:h}=this.getters.getSheetViewDimensionWithHeaders(),d=this.getters.getSelectedZones(),u=function(e){const t=new Set;for(let i of e)for(let e of $e(i.left,i.right+1))t.add(e);return t}(d),g=function(e){const t=new Set;for(let i of e)for(let e of $e(i.top,i.bottom+1))t.add(e);return t}(d),p=this.getters.getActiveSheetId(),m=this.getters.getNumberCols(p),f=this.getters.getNumberRows(p),E=this.getters.getActiveCols(),w=this.getters.getActiveRows();t.font=`400 11px ${Z}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333";for(let e=n;e<=s;e++){const i={left:e,right:e,top:0,bottom:f-1},{x:o,width:n}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(p,[i]),r=E.has(e),a=u.has(e);t.fillStyle=r?s?R:S:a?s?A:b:s?T:v,t.fillRect(o,0,n,N)}for(let e=a;e<=l;e++){const i={top:e,bottom:e,left:0,right:m-1},{y:o,height:n}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(p,[i]),r=w.has(e),a=g.has(e);t.fillStyle=r?s?R:S:a?s?A:b:s?T:v,t.fillRect(0,o,_,n)}t.beginPath(),t.moveTo(_,0),t.lineTo(_,h),t.moveTo(0,N),t.lineTo(c,N),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(const e of o){const i=this.getters.getColSize(p,e),o=Ht(e);t.fillStyle=E.has(e)?"#fff":C;let s=this.getHeaderOffset("COL",n,e);t.fillText(o,s+i/2,13),t.moveTo(s+i,0),t.lineTo(s+i,N)}for(const e of r){const i=this.getters.getRowSize(p,e);t.fillStyle=w.has(e)?"#fff":C;let o=this.getHeaderOffset("ROW",a,e);t.fillText(String(e+1),24,o+i/2),t.moveTo(0,o+i),t.lineTo(_,o+i)}t.stroke()}drawFrozenPanesHeaders(e){const{ctx:t,thinLineWidth:i}=e,{x:o,y:n}=this.getters.getMainViewportCoordinates(),s=this.getters.isDashboard()?0:_,r=this.getters.isDashboard()?0:N;t.lineWidth=6*i,t.strokeStyle="#BCBCBC",t.beginPath(),o&&(t.moveTo(s+o,0),t.lineTo(s+o,r)),n&&(t.moveTo(0,r+n),t.lineTo(s,r+n)),t.stroke()}drawFrozenPanes(e){const{ctx:t,thinLineWidth:i}=e,{x:o,y:n}=this.getters.getMainViewportCoordinates(),s=this.getters.getSheetViewVisibleCols(),r=s[0],a=s[s.length-1],l=this.getters.getSheetViewVisibleRows(),c={left:r,right:a,top:l[0],bottom:l[l.length-1]},h=this.getters.getVisibleRect(c),d=this.getters.isDashboard()?0:_,u=this.getters.isDashboard()?0:N;t.lineWidth=6*i,t.strokeStyle="#DADFE8",t.beginPath(),o&&(t.moveTo(d+o,u),t.lineTo(d+o,h.height+u)),n&&(t.moveTo(d,u+n),t.lineTo(h.width+d,u+n)),t.stroke()}findNextEmptyCol(e,t,i){const o=this.getters.getActiveSheetId();let n=e;for(;n<t;){const e={sheetId:o,col:n+1,row:i},t=this.getters.getEvaluatedCell(e),s=this.getters.getCellBorderWithFilterBorder(e);if(t.type!==rn.empty||this.getters.isInMerge(e)||(null==s?void 0:s.left))return n;n++}return n}findPreviousEmptyCol(e,t,i){const o=this.getters.getActiveSheetId();let n=e;for(;n>t;){const e={sheetId:o,col:n-1,row:i},t=this.getters.getEvaluatedCell(e),s=this.getters.getCellBorderWithFilterBorder(e);if(t.type!==rn.empty||this.getters.isInMerge(e)||(null==s?void 0:s.right))return n;n--}return n}computeCellAlignment(e,t){const i=this.getters.getCell(e);if((null==i?void 0:i.isFormula)&&this.getters.shouldShowFormulas())return"left";const{align:o}=this.getters.getCellStyle(e),n=this.getters.getEvaluatedCell(e);return t&&n.type===rn.number?"center"!==o?"left":o:o||n.defaultAlign}createZoneBox(e,t,i){const{left:o,right:n}=i,s=t.left,r=t.top,a={sheetId:e,col:s,row:r},c=this.getters.getEvaluatedCell(a),h=this.getters.shouldShowFormulas(),{x:d,y:u,width:g,height:p}=this.getters.getVisibleRect(t),{verticalAlign:m}=this.getters.getCellStyle(a),f={x:d,y:u,width:g,height:p,border:this.getters.getCellBorderWithFilterBorder(a)||void 0,style:this.getters.getCellComputedStyle(a),verticalAlign:m};if(c.type===rn.empty)return f;const v=this.getters.getConditionalIcon(a),b=He(f.style),S=v?U+b:0;v&&(f.image={type:"icon",size:b,clipIcon:{x:f.x,y:f.y,width:Math.min(S,g),height:p},image:yg[v].img}),f.isFilterHeader=this.getters.isFilterHeader(a);const C=f.isFilterHeader?19:0,E=this.getters.getCellComputedStyle(a),w=E.wrapping||"overflow",y="wrap"!==w||h?void 0:g-2*V,x=this.getters.getCellMultiLineText(a,y),I=Math.max(...x.map((e=>this.getters.getTextWidth(e,E)+V))),R=S+I+C,T=this.computeCellAlignment(a,R>g);f.content={textLines:x,width:"overflow"===w?I:g,align:T},c.type===rn.error&&c.error.logLevel>l.silent&&(f.error=c.error.message);const A=R>g||b>p;if(v||f.isFilterHeader)f.clipRect={x:f.x+S,y:f.y,width:Math.max(0,g-S-C),height:p};else if(A&&"overflow"===w){let e,i;switch(this.getters.isInMerge(a)?(e=this.getters.getMerge(a).right,i=s):(e=this.findNextEmptyCol(s,n,r),i=this.findPreviousEmptyCol(s,o,r),f.isOverflow=!0),T){case"left":{const i=ao({col:e,row:r}),{x:o,y:n,width:s,height:a}=this.getters.getVisibleRect(Zi(t,i));(s<R||b>a||x.length>1)&&(f.clipRect={x:o,y:n,width:s,height:a});break}case"right":{const e=ao({col:i,row:r}),{x:o,y:n,width:s,height:a}=this.getters.getVisibleRect(Zi(t,e));(s<R||b>a||x.length>1)&&(f.clipRect={x:o,y:n,width:s,height:a});break}case"center":{const o={...t,left:i,right:e},{x:n,y:s,height:r,width:a}=this.getters.getVisibleRect(o),l=R/2,c=f.x+f.width/2;if(n+a<c+l||n>c-l||b>r||x.length>1){const e=n>c-l?n:c-l,t=n+a-e;f.clipRect={x:e,y:s,width:t,height:r}}break}}}else("clip"===w||"wrap"===w||x.length>1)&&(f.clipRect={x:f.x,y:f.y,width:g,height:p});return f}getGridBoxes(){const e=[],t=this.getters.getSheetViewVisibleCols(),i=t[0],o=t[t.length-1],n=this.getters.getSheetViewVisibleRows(),s={left:i,right:o,top:n[0],bottom:n[n.length-1]},r=this.getters.getActiveSheetId();for(const i of n)for(const o of t){const t={sheetId:r,col:o,row:i};this.getters.isInMerge(t)||e.push(this.createZoneBox(r,ao(t),s))}for(const t of this.getters.getMerges(r))if(!this.getters.isMergeHidden(r,t)&&Yi(t,s)){const i=this.createZoneBox(r,t,s),o=this.getters.getCellBorder({sheetId:r,col:t.right,row:t.bottom});i.border={...i.border,bottom:o?o.bottom:void 0,right:o?o.right:void 0},i.isMerge=!0,e.push(i)}return e}}hb.layers=[0,7],hb.getters=["getColDimensionsInViewport","getRowDimensionsInViewport"];class db extends Zv{constructor(e,t,i){if(i&&t.length>1)throw new Error("Input with a single range cannot be instantiated with several range references.");super(e),this.inputHasSingleRange=i,this.ranges=[],this.focusedRangeIndex=null,this.willAddNewRange=!1,this.insertNewRange(0,t),this.activeSheet=this.getters.getActiveSheetId(),0===this.ranges.length&&(this.insertNewRange(this.ranges.length,[""]),this.focusLast())}allowDispatch(e){switch(e.type){case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange&&1===this.ranges.length)return 30;break;case"CHANGE_RANGE":if(this.inputHasSingleRange&&e.value.split(",").length>1)return 30}return 0}handleEvent(e){const t=Hi(e.anchor.zone),i=this.activeSheet,o=this.getters.getActiveSheetId(),n=this.getters.getSheetName(o);this.add([o===i?t:`${ke(n)}!${t}`])}handle(e){switch(e.type){case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(this.getIndex(e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.rangeId);if(null!==t&&this.focusedRangeIndex!==t&&this.focus(t),null!==t){const i=e.value.replace(/^,+/,"").split(",").map((e=>e.trim()));this.setRange(t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(this.ranges.length,[""]),this.focusLast();break;case"REMOVE_RANGE":const t=this.getIndex(e.rangeId);null!==t&&this.removeRange(t);break;case"STOP_SELECTION_INPUT":this.willAddNewRange=!1;break;case"PREPARE_SELECTION_INPUT_EXPANSION":{const e=this.focusedRangeIndex;null===e||this.inputHasSingleRange||(this.willAddNewRange=""!==this.ranges[e].xc.trim());break}case"ACTIVATE_SHEET":if(e.sheetIdFrom!==e.sheetIdTo){const{col:t,row:i}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0}),o=this.getters.expandZone(e.sheetIdTo,ao({col:t,row:i}));this.selection.resetAnchor(this,{cell:{col:t,row:i},zone:o})}}}getSelectionInputValue(){return this.cleanInputs(this.ranges.map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.ranges.map((e=>this.inputToHighlights(e))).flat()}focus(e){this.focusedRangeIndex=e}focusLast(){this.focus(this.ranges.length-1)}unfocus(){this.focusedRangeIndex=null}add(e){null!==this.focusedRangeIndex&&0!==e.length&&(this.willAddNewRange?(this.insertNewRange(this.ranges.length,e),this.focusLast(),this.willAddNewRange=!1):this.setRange(this.focusedRangeIndex,e))}setContent(e,t){this.ranges[e]={...this.ranges[e],xc:t}}insertNewRange(e,t){const i=Math.max(0,...this.ranges.map((e=>Number(e.id))));this.ranges.splice(e,0,...t.map(((e,t)=>({xc:e,id:i+t+1,color:Ct[(i+t)%Ct.length]}))))}setRange(e,t){const[,...i]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,i),i.length&&this.focus(e+i.length)}removeRange(e){this.ranges.splice(e,1),null!==this.focusedRangeIndex&&this.focusLast()}inputToHighlights({xc:e,color:t}){const i=this.cleanInputs([e]).filter((e=>this.getters.isRangeValid(e))).filter((e=>this.shouldBeHighlighted(this.activeSheet,e)));return i.map((e=>{const{sheetName:i}=Bt(e);return{zone:this.getters.getRangeFromSheetXC(this.activeSheet,e).zone,sheetId:i&&this.getters.getSheetIdByName(i)||this.activeSheet,color:t}}))}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:i}=Bt(t),o=this.getters.getSheetIdByName(i),n=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(o===n||void 0===o&&n===e)}getIndex(e){const t=this.ranges.findIndex((t=>t.id===e));return t>=0?t:null}}db.layers=[1],db.getters=[];class ub extends Zv{get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e){super(e),this.config=e,this.inputs={},this.focusedInputId=null}allowDispatch(e){var t,i;if("FOCUS_RANGE"===e.type){const o=null===(t=this.currentInput)||void 0===t?void 0:t.getIndex(e.rangeId);if(this.focusedInputId===e.id&&(null===(i=this.currentInput)||void 0===i?void 0:i.focusedRangeIndex)===o)return 29}return this.currentInput?this.currentInput.allowDispatch(e):0}handle(e){var t;switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:ao({col:0,row:0})},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}break;case"FOCUS_RANGE":case"CHANGE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id],i=t.ranges.find((t=>t.id===e.rangeId)),o=this.getters.getActiveSheetId(),n=this.getters.getRangeFromSheetXC(o,(null==i?void 0:i.xc)||"A1").zone;this.selection.capture(t,{cell:{col:n.left,row:n.top},zone:n},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}}null===(t=this.currentInput)||void 0===t||t.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map(((t,i)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.inputs[e].focusedRangeIndex&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===i}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:i}=Bt(e);return null!==t.match(Lt)&&(!i||void 0!==this.getters.getSheetIdByName(i))}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,i=!1){if(this.inputs[e]=new db(this.config,t,i),0===t.length){const t=this.inputs[e],i={zone:ao({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,i,{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}}ub.layers=[1],ub.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class gb{constructor(){this.subscriptions={}}on(e,t,i){if(!i)throw new Error("Missing callback");this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:i})}trigger(e,t){const i=this.subscriptions[e]||[];for(let e=0,o=i.length;e<o;e++){const o=i[e];o.callback.call(o.owner,t)}}off(e,t){const i=this.subscriptions[e];i&&(this.subscriptions[e]=i.filter((e=>e.owner!==t)))}clear(){this.subscriptions={}}}function pb(e,t){return{...e,definition:Cr(e.definition,t)}}function mb(e,t){if(e.sheetId!==t.sheetId)return e;if(("FREEZE_COLUMNS"===e.type?"COL":"ROW")!==t.dimension)return e;let i=e.quantity;if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));for(let t of e)i>t&&i--}if("ADD_COLUMNS_ROWS"===t.type){i=i>("before"===t.position?t.base-1:t.base)?i+t.quantity:i}return i>0?{...e,quantity:i}:void 0}eg.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],pb),eg.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],pb),eg.addTransformation("DELETE_SHEET",["MOVE_RANGES"],(function(e,t){const i=t.sheetId;if(e.targetSheetId===i||e.sheetId===i)return;return e})),eg.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),eg.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var i;if(e.name===t.name)return{...e,name:(null===(i=e.name)||void 0===i?void 0:i.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),eg.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE","CREATE_FILTER_TABLE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const i=[];for(const o of e.target)for(const e of t.target)Yi(o,e)||i.push({...o});if(i.length)return{...e,target:i};return})),eg.addTransformation("ADD_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],mb),eg.addTransformation("REMOVE_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],mb),eg.addTransformation("CREATE_FILTER_TABLE",["CREATE_FILTER_TABLE","ADD_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;for(const i of e.target)for(const e of t.target)if(Yi(e,i))return;return e}));const fb=[{match:function(e){return"sheetId"in e},fn:Sb},{match:function(e){return"target"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;const o=[];for(const i of e.target){const e=cs(i,t);e&&o.push(e)}if(!o.length)return"IGNORE_COMMAND";return{...e,target:o}}},{match:function(e){return"col"in e&&"row"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const i="COL"===t.dimension?"col":"row";let o=e[i];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(o))return"IGNORE_COMMAND";for(let t of e)o>=t&&o--}"ADD_COLUMNS_ROWS"===t.type&&(o>t.base||o===t.base&&"before"===t.position)&&(o+=t.quantity);return{...e,[i]:o}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const i of t.target){if(!(e.col===i.left&&e.row===i.top)&&Ki(e.col,e.row,i))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const i="ADD_COLUMNS_ROWS"===e.type,o=i?"base":"elements";let n=i?[e[o]]:e[o];if("REMOVE_COLUMNS_ROWS"===t.type&&(n=n.map((e=>{if(t.elements.includes(e))return;const i=t.elements.sort(((e,t)=>t-e));for(let t of i)e>t&&e--;return e})).filter(ot)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;n=n.map((i=>i>e?i+t.quantity:i))}if(n.length){let t=n;return i&&(t=n[0]),{...e,[o]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}},{match:function(e){return"ranges"in e},fn:function(e,t){const i=[],o="DELETE_SHEET"===t.type&&t.sheetId;for(const n of e.ranges)if(n._sheetId!==t.sheetId)i.push({...n,_zone:n._zone});else{const e=cs(n._zone,t);e&&o!==n._sheetId&&i.push({...n,_zone:e})}if(!i.length)return"IGNORE_COMMAND";return{...e,ranges:i}}}];function vb(e,t){const i=eg.getTransformation(e.type,t.type);return i?i(e,t):function(e,t){for(const{match:i,fn:o}of fb)if(i(e)){const i=o(e,t);if("SKIP_TRANSFORMATION"===i)continue;if("IGNORE_COMMAND"===i)return;e=i}return e}(e,t)}function bb(e,t){let i=[...e];for(const e of t)i=i.map((t=>vb(t,e))).filter(ot);return i}function Sb(e,t){const i="DELETE_SHEET"===t.type&&t.sheetId;return e.sheetId===i?"IGNORE_COMMAND":"CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId?e:"SKIP_TRANSFORMATION"}class Cb{constructor(e,t,i,o){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...i],this._changes=o?[...o]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Eb extends Error{}class wb extends gb{constructor(e,t,i=Q){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=i,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new Ui,this.debouncedMove=function(e,t,i){let o;return function(){const n=this,s=arguments,r=i&&!o;clearTimeout(o),o=setTimeout((function(){o=null,i||e.apply(n,s)}),t),r&&e.apply(n,s)}}(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const i=new Cb(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(i.id,i),this.trigger("new-local-state-update",{id:i.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:i.id,clientId:i.clientId,commands:i.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new Eb("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(ot))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const i=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==i?void 0:i.col)===e.col&&i.row===e.row&&i.sheetId===e.sheetId)return;const o=i?"CLIENT_MOVED":"CLIENT_JOINED",n=this.getClient();this.clients[this.clientId]={...n,position:e},this.transportService.sendMessage({type:o,version:1,client:{...n,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:i}=e,o=new Cb(e.nextRevisionId,t,i);if(o.clientId!==this.clientId){this.revisions.insert(o.id,o,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:bb(i,t)})}break;case"SNAPSHOT_CREATED":{const t=new Cb(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||(this.waitingAck=!0,this.sendPendingMessage())}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){const t=this.revisions.get(e.nextRevisionId);if(0===t.commands.length){this.revisions.drop(t.id);const e=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.nextRevisionId));return this.trigger("pending-revisions-dropped",{revisionIds:e}),this.waitingAck=!1,this.waitingUndoRedoAck=!1,void(this.pendingMessages=[])}e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage()}}isAlreadyProcessed(e){if("CLIENT_MOVED"===e.type&&e.client.id===this.clientId)return!0;switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const yb=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class xb extends Zv{constructor(){super(...arguments),this.availableColors=new Set(yb),this.colors={}}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(yb));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof Eb)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const i of this.getters.getConnectedClients())if(i.id!==this.getters.getClient().id&&i.position&&i.position.sheetId===e&&this.isPositionValid(i.position)){const e=i.position;this.colors[i.id]||(this.colors[i.id]=this.chooseNewColor());const o=this.colors[i.id];t.push({...i,position:e,color:o})}return t}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:s}=e.position,r=this.getters.expandZone(o,{top:n,bottom:n,left:s,right:s}),{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);if(c<=0||h<=0)continue;const d=e.color,u=`${d}10`;t.fillStyle=u,t.lineWidth=4*i,t.strokeStyle=d,t.globalCompositeOperation="multiply",t.fillRect(a,l,c,h),t.globalCompositeOperation="source-over",t.strokeRect(a,l,c,h),t.font=`bold ${q+1}px ${Z}`}}}xb.getters=["getClientsToDisplay"],xb.layers=[6];class Ib extends Zv{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Ki(e.col,e.row,e.zone))throw new Error(s("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{})}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;return oo(t).some((({col:t,row:i})=>!this.getters.isInMerge({sheetId:e,col:t,row:i})))?63:0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const i=this.getters.getMerges(e).filter((e=>Yi(e,t))),o=to(i[0]);let[n,s]=[o.numberOfCols,o.numberOfRows];return i.every((e=>{let[t,i]=[e.right-e.left+1,e.bottom-e.top+1];return t===n&&i===s}))?0:63}expand(e,t){const{left:i,right:o,top:n,bottom:s}=this.getters.expandZone(e,t);return{left:Math.max(0,i),right:Math.min(this.getters.getNumberCols(e)-1,o),top:Math.max(0,n),bottom:Math.min(this.getters.getNumberRows(e)-1,s)}}checkExpandedValues(e,t){const i=this.expand(e,t);let o;if(this.getters.doesIntersectMerge(e,i)){const{left:t,right:n,top:s,bottom:r}=i;for(let i=t;i<=n;i++)for(let t=s;t<=r;t++){const{col:n,row:s}=this.getters.getMainCellPosition({sheetId:e,col:i,row:t});if(o=this.getters.getEvaluatedCell({sheetId:e,col:n,row:s}),o.formattedValue)return!0}}else for(let t of this.getters.getEvaluatedCellsInZone(e,i))if(t.formattedValue)return!0;return!1}getContiguousZone(e,t){let i,{top:o,bottom:n,left:s,right:r}=t,a=!1;for(;!a;)a=!0,o>0&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:o-1,bottom:o-1}),i&&(a=!1,o--)),s>0&&(i=this.checkExpandedValues(e,{left:s-1,right:s-1,top:o-1,bottom:n+1}),i&&(a=!1,s--)),r<this.getters.getNumberCols(e)-1&&(i=this.checkExpandedValues(e,{left:r+1,right:r+1,top:o-1,bottom:n+1}),i&&(a=!1,r++)),n<this.getters.getNumberRows(e)-1&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:n+1,bottom:n+1}),i&&(a=!1,n++));return{left:s,right:r,top:o,bottom:n}}hasHeader(e,t){if(1===t[0].length)return!1;let i=t.map((t=>t.map((({col:t,row:i})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:i}).type))));return i[0][0]===rn.empty&&(i=i.slice(1)),!i.some((e=>e[0]===rn.empty))&&!!i.some((e=>e[1]!==rn.empty&&e[0]!==e[1]))}sortZone(e,t,i,o,n){const[s,r]=this.mainCellsSteps(e,i);let a=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,l=Object.assign({},i),c=this.mainCells(e,i);!n.sortHeaders&&this.hasHeader(e,c)&&(l.top+=r),c=this.mainCells(e,l);const h=function(e,t,i){const o=e.map(((e,t)=>({index:t,type:e.type,value:e.value})));let n=o.filter((e=>e.type===rn.empty)),s=o.filter((e=>e.type!==rn.empty));i&&(s.push(...n.map((e=>({...e,type:rn.number,value:0})))),n=[]);const r="descending"===t?-1:1;return s.sort(((e,t)=>{let i=wr.indexOf(e.type)-wr.indexOf(t.type);return 0===i&&(i=e.type===rn.text||e.type===rn.error?e.value.localeCompare(t.value):e.value-t.value),r*i})).concat(n)}(c[a-l.left].map((e=>this.getters.getEvaluatedCell(e))),o,Boolean(n.emptyCellAsZero)),d=h.map((e=>e.index)),[u,g]=[c.length,c[0].length],p=[];for(let e=0;e<u;e++)for(let t=0;t<g;t++){let{col:i,row:o,sheetId:n}=c[e][d[t]];const a=this.getters.getCell({sheetId:n,col:i,row:o});let h=l.left+e*s,u=l.top+t*r,g={sheetId:n,col:h,row:u,content:""};if(a){let e=a.content;if(a.isFormula){const t=u-this.getters.getCellPosition(a.id).row,i=this.getters.createAdaptedRanges(a.dependencies,0,t,n);e=this.getters.buildFormulaContent(n,a,i)}g.style=a.style,g.content=e,g.format=a.format}p.push(g)}p.forEach((e=>this.dispatch("UPDATE_CELL",e)))}mainCellsSteps(e,t){const i=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[i?i.right-i.left+1:1,i?i.bottom-i.top+1:1]}mainCells(e,t){const[i,o]=this.mainCellsSteps(e,t),n=[],s=$e(t.left,t.right+1,i),r=$e(t.top,t.bottom+1,o);for(const t of s){const i=[];n.push(i);for(const o of r)i.push({sheetId:e,col:t,row:o})}return n}}Ib.getters=["getContiguousZone"];class Rb extends Zv{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}Rb.getters=["shouldShowFormulas"];class Tb extends Zv{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":try{this.getters.getSheet(e.sheetId);break}catch(e){return 27}}return 0}handle(e){switch(e.type){case"AUTORESIZE_COLUMNS":for(let t of e.cols){const i=this.getColMaxWidth(e.sheetId,t);0!==i&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:i,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows)this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:null,sheetId:e.sheetId})}}getCellWidth(e){const t=this.getCellText(e),i=this.getters.getCellComputedStyle(e),o=t.split(he);let n=Math.max(...o.map((e=>this.getTextWidth(e,i))));this.getters.getConditionalIcon(e)&&(n+=function(e){return He(e)+2*U}(this.getters.getCellStyle(e)));if(this.getters.isFilterHeader(e)&&(n+=20),n>0&&(n+=2*B,"wrap"===this.getters.getCellStyle(e).wrapping)){const t=this.getters.getColSize(this.getters.getActiveSheetId(),e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return Ue(this.ctx,e,t)}getCellText(e,t=!1){const i=this.getters.getCell(e);return t&&(null==i?void 0:i.isFormula)?i.content:this.getters.getEvaluatedCell(e).formattedValue}getCellMultiLineText(e,t){const i=this.getters.getCellStyle(e),o=this.getters.getCellText(e,this.getters.shouldShowFormulas()),n=[];for(const e of o.split("\n")){const o=e.split(" ");if(!t){n.push(e);continue}let s="",r=t;for(let e of o){const o=this.splitWordToSpecificWidth(this.ctx,e,t,i),a=o.pop(),l=Ue(this.ctx,a,i);if(o.length)""!==s&&(n.push(s),s="",r=t),o.forEach((e=>{n.push(e)})),s=a,r=t-l;else{const e=""===s?a:" "+a,o=Ue(this.ctx,e,i);o<=r?(s+=e,r-=o):(n.push(s),s=a,r=t-l)}}""!==s&&n.push(s)}return n}getColDimensions(e,t){const i=this.getColRowOffset("COL",0,t,e),o=this.getters.getColSize(e,t);return{start:i,size:o,end:i+(this.getters.isColHidden(e,t)?0:o)}}getRowDimensions(e,t){const i=this.getColRowOffset("ROW",0,t,e),o=this.getters.getRowSize(e,t);return{start:i,size:o,end:i+(this.getters.isRowHidden(e,t)?0:o)}}getColRowOffset(e,t,i,o=this.getters.getActiveSheetId()){if(i<t)return-this.getColRowOffset(e,i,t);let n=0;for(let s=t;s<i;s++)this.getters.isHeaderHidden(o,e,s)||(n+="COL"===e?this.getters.getColSize(o,s):this.getters.getRowSize(o,s));return n}getColMaxWidth(e,t){const i=oo(this.getters.getColsZone(e,t,t)).map((t=>this.getCellWidth({sheetId:e,...t})));return Math.max(0,...i)}splitWordToSpecificWidth(e,t,i,o){if(Ue(e,t,o)<=i)return[t];const n=[];let s="";for(let r of t){Ue(e,s+r,o)>i?(n.push(s),s=r):s+=r}return n.push(s),n}}Tb.getters=["getCellWidth","getTextWidth","getCellText","getCellMultiLineText","getColDimensions","getRowDimensions","getColRowOffset"];class Ab{constructor(e,t,i,o){this.getters=t,this.dispatch=i,this.selection=o,this.operation=e,this.sheetId=t.getActiveSheetId()}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0}addMissingDimensions(e,t,i,o){const n=this.getters.getActiveSheetId(),s=t+o-this.getters.getNumberRows(n);s>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:this.getters.getNumberRows(n)-1,sheetId:n,quantity:s,position:"after"});const r=e+i-this.getters.getNumberCols(n);r>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:this.getters.getNumberCols(n)-1,sheetId:n,quantity:r,position:"after"})}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Mb extends Ab{constructor(e,t,i,o,n){if(super(t,i,o,n),!e.length)return this.cells=[[]],this.zones=[],void(this.copiedTables=[]);const s=new Set(e.map((e=>e.left))),r=new Set(e.map((e=>e.right))),a=new Set(e.map((e=>e.top))),l=new Set(e.map((e=>e.bottom))),c=1===a.size&&1===l.size||1===s.size&&1===r.size?function(e){return e.reduce(((e,t)=>{const i=e.length;for(let o=0;o<i;o++)if(Yi(e[o],t))return e[o]=Zi(e[o],t),e;return e[i]=t,e}),[])}(e):[e[e.length-1]],h=c.map((e=>oo(e))).flat(),d=[...new Set(h.map((e=>e.col)))].sort(((e,t)=>e-t)),u=[...new Set(h.map((e=>e.row)))].sort(((e,t)=>e-t)),g=[],p=i.getActiveSheetId();for(let e of u){let t=[];for(let o of d){const n={col:o,row:e,sheetId:p};t.push({cell:i.getCell(n),style:i.getCellComputedStyle(n),evaluatedCell:i.getEvaluatedCell(n),border:i.getCellBorder(n)||void 0,position:n})}g.push(t)}const m=[];for(const t of e)for(const e of this.getters.getFilterTablesInZone(p,t)){const t=[];for(const i of $e(e.zone.left,e.zone.right+1))t.push(this.getters.getFilterValues({sheetId:p,col:i,row:e.zone.top}));m.push({filtersValues:t,zone:e.zone})}this.cells=g,this.zones=c,this.copiedTables=m}isCutAllowed(e){return 1!==e.length?19:0}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId();if("CUT"===this.operation&&void 0!==(null==t?void 0:t.pasteOption))return 21;if(e.length>1&&(this.cells.length>1||this.cells[0].length>1))return 20;const o=this.cells.length,n=this.cells[0].length;for(let t of this.getPasteZones(e))if(this.getters.doesIntersectMerge(i,t)&&(e.length>1||!this.getters.isSingleCellOrMerge(i,e[0])||o*n!=1))return 2;const{xSplit:s,ySplit:r}=this.getters.getPaneDivisions(i);for(const t of this.getPasteZones(e))if(t.left<s&&t.right>=s||t.top<r&&t.bottom>=r)return 75;return 0}paste(e,t){"COPY"===this.operation?this.pasteFromCopy(e,t):this.pasteFromCut(e,t);const i=this.cells.length,o=this.cells[0].length,n="CUT"===this.operation;(null==t?void 0:t.selectTarget)&&this.selectPastedZone(o,i,n,e)}pasteFromCopy(e,t){if(1===e.length){const i=this.cells.length,o=this.cells[0].length,n=this.pastedZones(e,o,i);for(const e of n)this.pasteZone(e.left,e.top,t)}else for(const i of e)for(let e=i.left;e<=i.right;e++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,o,t);void 0===(null==t?void 0:t.pasteOption)&&this.pasteCopiedTables(e)}pasteFromCut(e,t){this.clearClippedZones();const i=e[0];this.pasteZone(i.left,i.top,t),this.dispatch("MOVE_RANGES",{target:this.zones,sheetId:this.sheetId,targetSheetId:this.getters.getActiveSheetId(),col:i.left,row:i.top});for(const e of this.copiedTables)this.dispatch("REMOVE_FILTER_TABLE",{sheetId:this.sheetId,target:[e.zone]});this.pasteCopiedTables(e)}pastedZones(e,t,i){const o=e[0],n=Math.max(1,Math.floor((o.right+1-o.left)/t)),s=Math.max(1,Math.floor((o.bottom+1-o.top)/i)),r=[];for(let e=0;e<n;e++)for(let n=0;n<s;n++){const s=o.top+n*i,a=o.left+e*t;r.push({left:a,top:s,bottom:s+i-1,right:a+t-1})}return r}getPasteZones(e){const t=this.cells;if(!t.length||!t[0].length)return e;const i=[],o=t.length,n=t[0].length,s=e[e.length-1],r=s.left,a=s.top,l=Math.max(1,Math.floor((s.right+1-r)/n)),c=Math.max(1,Math.floor((s.bottom+1-a)/o));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)i.push({left:r,top:a,right:r-1+e*n,bottom:a-1+t*o});return i}selectPastedZone(e,t,i,o){const n=o[0],s=n.left,r=n.top;if(t>1||e>1||i){const n=this.pastedZones(o,e,t),a=i?n[0]:Zi(...n);this.selection.selectZone({cell:{col:s,row:r},zone:a})}}clearClippedZones(){for(const e of this.cells)for(const t of e)t.cell&&this.dispatch("CLEAR_CELL",t.position);this.dispatch("CLEAR_FORMATTING",{sheetId:this.sheetId,target:this.zones})}pasteZone(e,t,i){const o=this.cells.length,n=this.cells[0].length,s="onlyValue"!==(null==i?void 0:i.pasteOption)&&(null==i?void 0:i.shouldPasteCF),r=this.getters.getActiveSheetId();this.addMissingDimensions(n,o,e,t);for(let a=0;a<o;a++){const o=this.cells[a];for(let l=0;l<n;l++){const n=o[l],c={col:e+l,row:t+a,sheetId:r};"CUT"!==this.operation&&this.pasteMergeIfExist(n.position,c),this.pasteCell(n,c,this.operation,i),s&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:c,operation:this.operation})}}}pasteCell(e,t,i,o){const{sheetId:n,col:s,row:r}=t,a=this.getters.getEvaluatedCell(t);if("onlyValue"!==(null==o?void 0:o.pasteOption)){const i=this.getters.getCellBorder(t),o=e.border,a={top:(null==i?void 0:i.top)||(null==o?void 0:o.top),bottom:(null==i?void 0:i.bottom)||(null==o?void 0:o.bottom),left:(null==i?void 0:i.left)||(null==o?void 0:o.left),right:(null==i?void 0:i.right)||(null==o?void 0:o.right)};this.dispatch("SET_BORDER",{sheetId:n,col:s,row:r,border:a})}if(e.cell){if("onlyFormat"===(null==o?void 0:o.pasteOption))return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.evaluatedCell.format});if("onlyValue"===(null==o?void 0:o.pasteOption)){const i=pi(e.evaluatedCell.value);return void this.dispatch("UPDATE_CELL",{...t,content:i})}let a=e.cell.content;if(e.cell.isFormula&&"COPY"===i){const t=s-e.position.col,o=r-e.position.row;a=this.getUpdatedContent(n,e.cell,t,o,i)}this.dispatch("UPDATE_CELL",{...t,content:a,style:e.cell.style||null,format:e.cell.format})}else a&&("onlyValue"===(null==o?void 0:o.pasteOption)?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===(null==o?void 0:o.pasteOption)?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,i,o,n){const s=this.getters.createAdaptedRanges(t.dependencies,i,o,e);return this.getters.buildFormulaContent(e,t,s)}pasteMergeIfExist(e,t){let{sheetId:i,col:o,row:n}=e;const{col:s,row:r}=this.getters.getMainCellPosition(e);if(s===o&&r===n){const s=this.getters.getMerge(e);if(!s)return;({sheetId:i,col:o,row:n}=t),this.dispatch("ADD_MERGE",{sheetId:i,force:!0,target:[{left:o,top:n,right:o+s.right-s.left,bottom:n+s.bottom-s.top}]})}}pasteCopiedTables(e){const t=this.getters.getActiveSheetId(),i=e[0],o=this.zones[0],n=[i.left-o.left,i.top-o.top];for(const e of this.copiedTables){const i=no(e.zone,"both","MOVE",n);this.dispatch("CREATE_FILTER_TABLE",{sheetId:t,target:[i]});for(const o of $e(0,e.filtersValues.length))this.dispatch("UPDATE_FILTER",{sheetId:t,col:i.left+o,row:i.top,values:e.filtersValues[o]})}}getClipboardContent(){return{[an.PlainText]:this.getPlainTextContent(),[an.Html]:this.getHTMLContent()}}getPlainTextContent(){return this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.position,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}getHTMLContent(){if(1==this.cells.length&&1==this.cells[0].length)return this.getters.getCellText(this.cells[0][0].position);let e='<table border="1" style="border-collapse:collapse">';for(const t of this.cells){e+="<tr>";for(const i of t){e+=`<td style="${So(vo(i.style))}">`+Yf(this.getters.getCellText(i.position))+"</td>"}e+="</tr>"}return e+="</table>",e}isColRowDirtyingClipboard(e,t){if(!this.zones)return!1;for(let i of this.zones){if("COL"===t&&e<=i.right)return!0;if("ROW"===t&&e<=i.bottom)return!0}return!1}drawClipboard(e){const{ctx:t,thinLineWidth:i}=e;if(this.sheetId===this.getters.getActiveSheetId()&&this.zones&&this.zones.length){t.setLineDash([8,5]),t.strokeStyle=E,t.lineWidth=3.3*i;for(const e of this.zones){const{x:i,y:o,width:n,height:s}=this.getters.getVisibleRect(e);n>0&&s>0&&t.strokeRect(i,o,n,s)}}}}class Ob{constructor(e,t,i){this.operation=e,this.getters=t,this.dispatch=i,this.sheetId=t.getActiveSheetId();const o=t.getSelectedFigureId();if(!o)throw new Error("No figure selected");const n=t.getFigure(this.sheetId,o);if(!n)throw new Error(`No figure for the given id: ${o}`);switch(this.copiedFigure={...n},n.tag){case"chart":this.copiedFigureContent=new Nb(i,t,this.sheetId,o);break;case"image":this.copiedFigureContent=new _b(i,t,this.sheetId,o);break;default:throw new Error(`Unknow tag '${n.tag}' for the given figure id: ${o}`)}}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0===e.length?73:void 0!==(null==t?void 0:t.pasteOption)?22:0}paste(e){const t=this.getters.getActiveSheetId(),i={x:this.getters.getColDimensions(t,e[0].left).start,y:this.getters.getRowDimensions(t,e[0].top).start},o={height:this.copiedFigure.height,width:this.copiedFigure.width},n=(new Ui).uuidv4();this.copiedFigureContent.paste(t,n,i,o),"CUT"===this.operation&&this.dispatch("DELETE_FIGURE",{sheetId:this.copiedFigureContent.sheetId,id:this.copiedFigure.id}),this.dispatch("SELECT_FIGURE",{id:n})}getClipboardContent(){return{[an.PlainText]:"\t"}}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Nb{constructor(e,t,i,o){this.dispatch=e,this.sheetId=i;const n=t.getChart(o);if(!n)throw new Error(`No chart for the given id: ${o}`);this.copiedChart=n.copyInSheetId(i)}paste(e,t,i,o){const n=this.copiedChart.copyInSheetId(e);this.dispatch("CREATE_CHART",{id:t,sheetId:e,position:i,size:o,definition:n.getDefinition()})}}class _b{constructor(e,t,i,o){this.dispatch=e,this.sheetId=i;const n=t.getImage(o);this.copiedImage=Fe(n)}paste(e,t,i,o){const n=Fe(this.copiedImage);this.dispatch("CREATE_IMAGE",{figureId:t,sheetId:e,position:i,size:o,definition:n})}}class Fb extends Ab{constructor(e,t,i,o){super("COPY",t,i,o),this.values=e.replace(/\r/g,"").split("\n").map((e=>e.split("\t")))}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId(),o=this.getPasteZone(e);return this.getters.doesIntersectMerge(i,o)?2:0}paste(e){const t=this.values,i=this.getPasteZone(e),{left:o,top:n}=i,{numberOfCols:s,numberOfRows:r}=to(i),a=this.getters.getActiveSheetId();this.addMissingDimensions(s,r,o,n);for(let e=0;e<t.length;e++)for(let i=0;i<t[e].length;i++)this.dispatch("UPDATE_CELL",{row:n+e,col:o+i,content:t[e][i],sheetId:a});const l={left:o,top:n,right:o+s-1,bottom:n+r-1};this.selection.selectZone({cell:{col:o,row:n},zone:l})}getClipboardContent(){return{[an.PlainText]:this.values.map((e=>e.join("\t"))).join("\n")}}getPasteZone(e){const t=this.values.length,i=Math.max(...this.values.map((e=>e.length))),{left:o,top:n}=e[0];return{top:n,left:o,bottom:n+t-1,right:o+i-1}}}class Db extends Zv{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"CUT":const t=this.getters.getSelectedZones();return this.getClipboardState(t,e.type).isCutAllowed(t);case"PASTE":if(!this.state)return 23;const i=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);return this.state.isPasteAllowed(e.target,{pasteOption:i});case"PASTE_FROM_OS_CLIPBOARD":return new Fb(e.text,this.getters,this.dispatch,this.selection).isPasteAllowed(e.target);case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}}return 0}handle(e){var t,i;switch(e.type){case"COPY":case"CUT":const o=this.getters.getSelectedZones();this.state=this.getClipboardState(o,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);this._isPaintingFormat=!1,this.state.paste(e.target,{pasteOption:n,shouldPasteCF:!0,selectTarget:!0}),"CUT"===this.state.operation&&(this.state=void 0),this.status="invisible";break;case"CLEAN_CLIPBOARD_HIGHLIGHT":this.status="invisible";break;case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Bi(t[0])){for(const{col:t,row:i}of oo(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:i,sheetId:this.getters.getActiveSheetId()});break}this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation))return;this.state.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(i=this.state)||void 0===i?void 0:i.operation))return;for(let t of e.elements){if(this.state.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":new Fb(e.text,this.getters,this.dispatch,this.selection).paste(e.target),this.status="invisible";break;case"ACTIVATE_PAINT_FORMAT":{const e=this.getters.getSelectedZones();this.state=this.getClipboardStateForCopyCells(e,"COPY"),this._isPaintingFormat=!0,this.status="visible";break}default:un(e)&&(this.status="invisible")}}getClipboardContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent())||{[an.PlainText]:"\t"}}getClipboardTextContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent()[an.PlainText])||"\t"}isCutOperation(){return!!this.state&&"CUT"===this.state.operation}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const i=this.getters.getActiveSheetId();let o;return o="COL"===t?{...e,left:e.right+1,right:this.getters.getNumberCols(i)-1}:{...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1},{cut:[o],paste:[e]}}getInsertCellsTargets(e,t){const i=this.getters.getActiveSheetId();let o,n;return"COL"===t?(o={...e,right:this.getters.getNumberCols(i)-1},n={...e,left:e.right+1,right:e.right+1}):(o={...e,bottom:this.getters.getNumberRows(i)-1},n={...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1}),{cut:[o],paste:[n]}}getClipboardStateForCopyCells(e,t){return new Mb(e,t,this.getters,this.dispatch,this.selection)}getClipboardState(e,t){return this.getters.getSelectedFigureId()?new Ob(t,this.getters,this.dispatch):new Mb(e,t,this.getters,this.dispatch,this.selection)}drawGrid(e){"visible"===this.status&&this.state&&this.state.drawClipboard(e)}}function kb(e){if("REFERENCE"!==e.type)return e;const{xc:t,sheetName:i}=Bt(e.value),[o,n]=t.split(":"),s=i?`${ke(i)}!`:"",r=Lb(o),a=n?`:${Lb(n)}`:"";return{...e,value:s+r+a}}function Lb(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=Pb(e,"colrow");break;case"colrow":e=Pb(e,"row");break;case"row":e=Pb(e,"col");break;case"col":e=Pb(e,"none")}return e}function Pb(e,t){let i;switch(e=e.replace(/\$/g,""),t){case"col":return"$"+e;case"row":return i=e.search(/[0-9]/),e.slice(0,i)+"$"+e.slice(i);case"colrow":return i=e.search(/[0-9]/),"$"+(e=e.slice(0,i)+"$"+e.slice(i));case"none":return e}}Db.layers=[2],Db.getters=["getClipboardContent","getClipboardTextContent","isCutOperation","isPaintingFormat"];const Ub=s("The cell you are trying to edit has been deleted.");class Vb extends Zv{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheetId="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.initialContent="",this.previousRef="",this.previousRange=void 0,this.colorIndexByRange={}}allowDispatch(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":return this.validateSelection(this.currentContent.length,e.start,e.end);case"SET_CURRENT_CONTENT":return e.selection?this.validateSelection(e.content.length,e.selection.start,e.selection.end):0;case"START_EDITION":if(e.selection){const t=e.text||this.getComposerContent(this.getters.getActivePosition());return this.validateSelection(t.length,e.selection.start,e.selection.end)}return 0;default:return 0}}handleEvent(e){if("selecting"===this.mode)if("newAnchor"===e.mode)this.insertSelectedRange(e.anchor.zone);else this.replaceSelectedRanges(e.anchor.zone)}handle(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":this.selectionStart=e.start,this.selectionEnd=e.end;break;case"STOP_COMPOSER_RANGE_SELECTION":this.isSelectingForComposer()&&(this.mode="editing");break;case"START_EDITION":"inactive"!==this.mode&&e.text?this.setContent(e.text,e.selection):this.startEdition(e.text,e.selection),this.updateRangeColor();break;case"STOP_EDITION":e.cancel?(this.cancelEditionAndActivateSheet(),this.resetContent()):this.stopEdition(),this.colorIndexByRange={};break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0),this.updateRangeColor();break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEditionAndActivateSheet(),this.resetContent();break;case"ADD_COLUMNS_ROWS":this.onAddElements(e);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);break;case"START_CHANGE_HIGHLIGHT":this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const t=this.getters.getRangeFromRangeData(e.range),i=this.currentTokens.filter((e=>"REFERENCE"===e.type)).find((e=>{const{xc:i,sheetName:o}=Bt(e.value),n=o||this.getters.getSheetName(this.sheetId),s=this.getters.getActiveSheetId();if(this.getters.getSheetName(s)!==n)return!1;const r=this.getters.getRangeFromSheetXC(s,i);return Xi(this.getters.expandZone(s,r.zone),t.zone)}));this.previousRef=i.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=i.start;break;case"CHANGE_HIGHLIGHT":const o=this.getters.getRangeFromRangeData(e.range),n=this.getRangeReference(o,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(n),this.previousRef=n,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"ACTIVATE_SHEET":if(this.currentContent.startsWith("=")||(this.cancelEdition(),this.resetContent()),e.sheetIdFrom!==e.sheetIdTo){const t=this.getters.getActivePosition(),{col:i,row:o}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:t.col,row:t.row}),n=this.getters.expandZone(e.sheetIdTo,ao({col:i,row:o}));this.selection.resetAnchor(this,{cell:{col:i,row:o},zone:n})}break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheetId)||"inactive"===this.mode||(this.sheetId=this.getters.getActiveSheetId(),this.cancelEditionAndActivateSheet(),this.resetContent(),this.ui.notifyUI({type:"ERROR",text:Ub}));break;case"CYCLE_EDITION_REFERENCES":this.cycleReferences()}}getEditionMode(){return this.mode}getCurrentContent(){return"inactive"===this.mode?this.getComposerContent(this.getters.getActivePosition()):this.currentContent}getEditionSheet(){return this.sheetId}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}getCurrentEditedCell(){return{sheetId:this.sheetId,col:this.col,row:this.row}}isSelectingForComposer(){return"selecting"===this.mode}showSelectionIndicator(){return this.isSelectingForComposer()&&this.canStartComposerRangeSelection()}getCurrentTokens(){return this.currentTokens}getTokenAtCursor(){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((i=>i.start<=e&&i.end>=t))}cycleReferences(){const e=this.getTokensInSelection(),t=e.filter((e=>"REFERENCE"===e.type));if(0===t.length)return;const i=e.map(kb).map((e=>e.value)).join(""),o=this.currentContent,n=e[0].start,s=e[e.length-1].end,r=o.slice(0,n)+i+o.slice(s),a=r.length-o.length,l={start:t[0].start,end:t[t.length-1].end+a};1===t.length&&this.selectionStart===this.selectionEnd&&(l.start=l.end),this.dispatch("SET_CURRENT_CONTENT",{content:r,selection:l})}validateSelection(e,t,i){return t>=0&&t<=e&&i>=0&&i<=e?0:46}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUI({type:"ERROR",text:Ub});const{top:t,left:i}=Gi({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",[...e.elements]);this.col=i,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUI({type:"ERROR",text:Ub});const{top:t,left:i}=Gi({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",[...e.elements]);this.col=i,this.row=t}onAddElements(e){const{top:t,left:i}=Wi({left:this.col,right:this.col,top:this.row,bottom:this.row},"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.col=i,this.row=t}startComposerRangeSelection(){if(this.sheetId===this.getters.getActiveSheetId()){const e=ao({col:this.col,row:this.row});this.selection.resetAnchor(this,{cell:{col:this.col,row:this.row},zone:e})}this.mode="selecting",this.selectionInitialStart=this.selectionStart}startEdition(e,t){var i;const o=this.getters.getActiveCell();e&&(null===(i=o.format)||void 0===i?void 0:i.includes("%"))&&ii(e)&&(t=t||{start:e.length,end:e.length},e=`${e}%`);const{col:n,row:s,sheetId:r}=this.getters.getActivePosition();this.col=n,this.sheetId=r,this.row=s,this.initialContent=this.getComposerContent({sheetId:r,col:n,row:s}),this.mode="editing",this.setContent(e||this.initialContent,t),this.colorIndexByRange={};const a=ao({col:this.col,row:this.row});this.selection.capture(this,{cell:{col:this.col,row:this.row},zone:a},{handleEvent:this.handleEvent.bind(this),release:()=>{this.stopEdition()}})}stopEdition(){if("inactive"!==this.mode){this.cancelEditionAndActivateSheet();const e=this.col,t=this.row;let i=this.currentContent;if(!(this.initialContent!==i))return;if(i){const o=this.getters.getActiveSheetId(),n=this.getters.getEvaluatedCell({sheetId:o,col:this.col,row:this.row});if(i.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,o=e-t;o>0&&(i+=rt(new Array(o).fill(")")))}else n.link&&(i=Ke(i,n.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheetId,col:e,row:t,content:i})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheetId,content:"",col:e,row:t});this.setContent("")}}cancelEditionAndActivateSheet(){if("inactive"===this.mode)return;this.cancelEdition();this.getters.getActiveSheetId()!==this.sheetId&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}getComposerContent(e){const t=this.getters.getCell(e);if(null==t?void 0:t.isFormula)return t.content;const{format:i,value:o,type:n,formattedValue:s}=this.getters.getEvaluatedCell(e);switch(n){case rn.text:case rn.empty:return o;case rn.boolean:return s;case rn.error:return(null==t?void 0:t.content)||"";case rn.number:return i&&Ci(i)?s:this.numberComposerContent(o,i)}}numberComposerContent(e,t){return(null==t?void 0:t.includes("%"))?100*e+"%":function(e){const{integerDigits:t,decimalDigits:i}=vi(e,20);return i?`${t}.${i}`:t}(e)}cancelEdition(){"inactive"!==this.mode&&(this.mode="inactive",this.selection.release(this))}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,i){const o=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(o||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?uf(e):[],this.currentTokens.length>100&&i&&this.ui.notifyUI({type:"ERROR",text:s("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells")})),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(e){const t=Math.min(this.selectionStart,this.selectionEnd),i=this.getZoneReference(e);this.canStartComposerRangeSelection()?(this.insertText(i,t),this.selectionInitialStart=t):(this.insertText(","+i,t),this.selectionInitialStart=t+1)}replaceSelectedRanges(e){const t=this.getZoneReference(e);this.replaceText(t,this.selectionInitialStart,this.selectionEnd)}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const i=this.getters.getActiveSheetId();let o=this.getters.zoneToXC(i,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){o=`${ke(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${o}`}return o}getRangeReference(e,t=[{colFixed:!1,rowFixed:!1}]){let i=[...t];1===t.length&&co(e.zone)>1?i.push({...t[0]}):2===t.length&&1===co(e.zone)&&i.pop();const o=e.clone({parts:i});return this.getters.getSelectionRangeString(o,this.getters.getEditionSheet())}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),i=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,i)}replaceText(e,t,i){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(i,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const i=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),o=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:i,selection:{start:o,end:o}})}updateRangeColor(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return;const e=this.getters.getEditionSheet(),t=this.getReferencedRanges().map((t=>this.getters.getRangeString(t,e))),i={};for(const e of t)void 0!==this.colorIndexByRange[e]&&(i[e]=this.colorIndexByRange[e]);const o=new Set(Object.values(i));let n=0;const s=()=>{for(;o.has(n);)n++;return o.add(n),n};for(const e of t){const t=e in i?i[e]:s();i[e]=t}this.colorIndexByRange=i}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=this.getters.getEditionSheet(),t=e=>{const t=this.colorIndexByRange[e];return Ct[t%Ct.length]};return this.getReferencedRanges().map((i=>{const o=this.getters.getRangeString(i,e);return{zone:i.zone,color:t(o),sheetId:i.sheetId}}))}getReferencedRanges(){const e=this.getters.getEditionSheet();return this.currentTokens.filter((e=>"REFERENCE"===e.type)).map((t=>this.getters.getRangeFromSheetXC(e,t.value)))}canStartComposerRangeSelection(){if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(!e)return!1;const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let i=t,o=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(o.type)||Im.includes(o.value);){if("SPACE"!==o.type||i<1)return!1;i--,o=this.currentTokens[i]}for(i=t+1,o=this.currentTokens[i];o&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(o.type);){if("SPACE"!==o.type)return!1;i++,o=this.currentTokens[i]}return!0}return!1}getTokensInSelection(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return this.currentTokens.filter((i=>i.start<=e&&i.end>=e||i.start>=e&&i.start<t))}}Vb.getters=["getEditionMode","isSelectingForComposer","showSelectionIndicator","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights","getCurrentEditedCell"];const zb=[{name:s("Sum"),types:[rn.number],compute:e=>ul.compute([e])},{name:s("Avg"),types:[rn.number],compute:e=>yl.compute([e])},{name:s("Min"),types:[rn.number],compute:e=>zl.compute([e])},{name:s("Max"),types:[rn.number],compute:e=>Ll.compute([e])},{name:s("Count"),types:[rn.number,rn.text,rn.boolean,rn.error],compute:e=>Nl.compute([e])},{name:s("Count Numbers"),types:[rn.number,rn.text,rn.boolean,rn.error],compute:e=>Ol.compute([e])}];class Bb extends Zv{constructor(e){super(e),this.gridSelection={anchor:{cell:{col:0,row:0},zone:{top:0,left:0,bottom:0,right:0}},zones:[{top:0,left:0,bottom:0,right:0}]},this.selectedFigureId=null,this.sheetsData={},this.activeSheet=null,this.moveClient=e.moveClient}allowDispatch(e){switch(e.type){case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 27}case"MOVE_COLUMNS_ROWS":return this.isMoveElementAllowed(e)}return 0}handleEvent(e){const t=e.anchor;let i=[];switch(e.mode){case"overrideSelection":i=[t.zone];break;case"updateAnchor":i=[...this.gridSelection.zones];const o=i.findIndex((t=>Xi(t,e.previousAnchor.zone)));o>=0&&(i[o]=t.zone);break;case"newAnchor":i=[...this.gridSelection.zones,t.zone]}this.setSelectionMixin(e.anchor,i),this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor));const{col:o,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:o,row:n}),this.selectedFigureId=null}handle(e){switch(e.type){case"START_EDITION":case"ACTIVATE_SHEET":this.selectedFigureId=null;break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;case"DELETE_SHEET":this.selectedFigureId&&this.getters.getFigure(e.sheetId,this.selectedFigureId)&&(this.selectedFigureId=null)}switch(e.type){case"START":const t=this.getters.getVisibleSheetIds()[0];this.dispatch("ACTIVATE_SHEET",{sheetIdTo:t,sheetIdFrom:t});const{col:i,row:o}=this.getters.getNextVisibleCellPosition({sheetId:t,col:0,row:0});this.selectCell(i,o),this.selection.registerAsDefault(this,this.gridSelection.anchor,{handleEvent:this.handleEvent.bind(this)}),this.moveClient({sheetId:t,col:0,row:0});break;case"ACTIVATE_SHEET":if(this.getters.isSheetVisible(e.sheetIdTo)||this.dispatch("SHOW_SHEET",{sheetId:e.sheetIdTo}),this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={gridSelection:Fe(this.gridSelection)},e.sheetIdTo in this.sheetsData)Object.assign(this,this.sheetsData[e.sheetIdTo]),this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor));else{const{col:t,row:i}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0});this.selectCell(t,i)}break;case"REMOVE_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);const{col:i,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:o})}break}case"ADD_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){this.onAddElements(e);const{col:i,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:o})}break}case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left");break;case"HIDE_SHEET":e.sheetId===this.getActiveSheetId()&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.sheetId,sheetIdTo:this.getters.getVisibleSheetIds()[0]});break;case"UNDO":case"REDO":case"DELETE_SHEET":const n=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of n)delete this.sheetsData[e];for(const e in this.sheetsData){const t=this.clipSelection(e,this.sheetsData[e].gridSelection);this.sheetsData[e]={gridSelection:Fe(t)}}if(!this.getters.tryGetSheet(this.getters.getActiveSheetId())){const e=this.getters.getVisibleSheetIds();if(this.activeSheet=this.getters.getSheet(e[0]),this.activeSheet.id in this.sheetsData){const{anchor:e}=this.clipSelection(this.activeSheet.id,this.sheetsData[this.activeSheet.id].gridSelection);this.selectCell(e.cell.col,e.cell.row)}else this.selectCell(0,0);const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:t,row:i})}const s=this.getters.getActiveSheetId();this.gridSelection.zones=this.gridSelection.zones.map((e=>this.getters.expandZone(s,e))),this.gridSelection.anchor.zone=this.getters.expandZone(s,this.gridSelection.anchor.zone),this.setSelectionMixin(this.gridSelection.anchor,this.gridSelection.zones)}this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor))}isGridSelectionActive(){return this.selection.isListening(this)}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){return this.getters.getEvaluatedCell(this.getActivePosition())}getActiveCols(){const e=new Set;for(let t of this.gridSelection.zones)if(0===t.top&&t.bottom===this.getters.getNumberRows(this.getters.getActiveSheetId())-1)for(let i=t.left;i<=t.right;i++)e.add(i);return e}getActiveRows(){const e=new Set,t=this.getters.getActiveSheetId();for(let i of this.gridSelection.zones)if(0===i.left&&i.right===this.getters.getNumberCols(t)-1)for(let t=i.top;t<=i.bottom;t++)e.add(t);return e}getCurrentStyle(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();return this.getters.getCellStyle({sheetId:t,col:e.left,row:e.top})}getSelectedZones(){return Fe(this.gridSelection.zones)}getSelectedZone(){return Fe(this.gridSelection.anchor.zone)}getSelection(){return Fe(this.gridSelection)}getSelectedFigureId(){return this.selectedFigureId}getActivePosition(){return this.getters.getMainCellPosition({sheetId:this.getActiveSheetId(),col:this.gridSelection.anchor.cell.col,row:this.gridSelection.anchor.cell.row})}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getActivePosition();{const t=this.sheetsData[e];return t?{sheetId:e,col:t.gridSelection.anchor.cell.col,row:t.gridSelection.anchor.cell.row}:this.getters.getNextVisibleCellPosition({sheetId:e,col:0,row:0})}}getStatisticFnResults(){const e=this.getters.getActiveSheetId(),t=new Set;for(const i of this.gridSelection.zones)for(const{col:o,row:n}of oo(i)){if(this.getters.isRowHidden(e,n)||this.getters.isColHidden(e,o))continue;const i=this.getters.getEvaluatedCell({sheetId:e,col:o,row:n});i.type!==rn.empty&&t.add(i)}let i=new Set,o=[];for(let e of t)i.add(e.type),o.push(e.value);let n={};for(let e of zb){let t;e.types.some((e=>i.has(e)))&&(t=e.compute(o)),n[e.name]=t}return n}getAggregate(){let e=0,t=0;const i=this.getters.getActiveSheetId(),o=this.gridSelection.zones.map(oo).flat();for(const{col:n,row:s}of o){const o=this.getters.getEvaluatedCell({sheetId:i,col:n,row:s});o.type===rn.number&&(t++,e+=o.value)}return t<2?null:pi(e)}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Xi(t,e)))}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let i=[];const o="COL"===e?"left":"top",n="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[n]-e[o]+1},((t,i)=>e[o]+i));i=i.concat(t)}return[...new Set(i)].sort()}setSelectionMixin(e,t){const{anchor:i,zones:o}=this.clipSelection(this.getters.getActiveSheetId(),{anchor:e,zones:t});this.gridSelection.anchor=i,this.gridSelection.zones=function(e){return e.reverse().filter(((e,t,i)=>t===i.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}(o)}selectCell(e,t){const i=this.getters.getActiveSheetId(),o=this.getters.expandZone(i,{left:e,right:e,top:t,bottom:t});this.setSelectionMixin({zone:o,cell:{col:e,row:t}},[o])}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}activateNextSheet(e){const t=this.getters.getSheetIds(),i=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[i]})}onColumnsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,o=Gi(i,"left",[...e.elements]);let n={left:t.col,right:t.col,top:t.row,bottom:t.row};n=Gi(n,"left",[...e.elements]);const s={cell:{col:n.left,row:n.top},zone:o};this.setSelectionMixin(s,[o])}onRowsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,o=Gi(i,"top",[...e.elements]);let n={left:t.col,right:t.col,top:t.row,bottom:t.row};n=Gi(n,"top",[...e.elements]);const s={cell:{col:n.left,row:n.top},zone:o};this.setSelectionMixin(s,[o])}onAddElements(e){const t=Wi(this.gridSelection.anchor.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),i={cell:{col:t.left,row:t.top},zone:t};this.setSelectionMixin(i,[t])}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:"before"});const i="COL"===e.dimension,o=e.elements[0],n=e.elements[t-1],s=e.base<o,r=s&&i?t:0,a=s&&!i?t:0,l=[{left:i?o+r:0,right:i?n+r:this.getters.getNumberCols(e.sheetId)-1,top:i?0:o+a,bottom:i?this.getters.getNumberRows(e.sheetId)-1:n+a}],c=new Mb(l,"CUT",this.getters,this.dispatch,this.selection),h=[{left:i?e.base:0,right:i?e.base+t-1:this.getters.getNumberCols(e.sheetId)-1,top:i?0:e.base,bottom:i?this.getters.getNumberRows(e.sheetId)-1:e.base+t-1}];c.paste(h,{selectTarget:!0});const d=s?e.elements.map((e=>e+t)):e.elements;let u=e.base;for(const t of d){const i="COL"===e.dimension?this.getters.getColSize(e.sheetId,t):this.getters.getRowSize(e.sheetId,t);this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:i,elements:[u]}),u+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:d})}isMoveElementAllowed(e){const t="COL"===e.dimension,i=e.elements[0],o=e.elements[e.elements.length-1],n=e.sheetId,s=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return s(n,i-1,i)||s(n,o,o+1)||s(n,e.base-1,e.base)?2:0}clipSelection(e,t){const i=this.getters.getNumberCols(e)-1,o=this.getters.getNumberRows(e)-1;return{zones:t.zones.map((e=>({left:Le(e.left,0,i),right:Le(e.right,0,i),top:Le(e.top,0,o),bottom:Le(e.bottom,0,o)}))),anchor:{cell:{col:Le(t.anchor.cell.col,0,i),row:Le(t.anchor.cell.row,0,o)},zone:{left:Le(t.anchor.zone.left,0,i),right:Le(t.anchor.zone.right,0,i),top:Le(t.anchor.zone.top,0,o),bottom:Le(t.anchor.zone.bottom,0,o)}}}}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,o=this.getSelectedZones();t.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;t.fillStyle=n?"#f3f7fe":"#e9f0ff",t.strokeStyle=E,t.lineWidth=1.5*i;for(const e of o){const{x:i,y:o,width:n,height:s}=this.getters.getVisibleRect(e);t.globalCompositeOperation="multiply",t.fillRect(i,o,n,s),t.globalCompositeOperation="source-over",t.strokeRect(i,o,n,s)}t.globalCompositeOperation="source-over";const s=this.getActivePosition();let r;t.strokeStyle=E,t.lineWidth=3*i,r=this.getters.isInMerge(s)?this.getters.getMerge(s):ao(s);const{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);c>0&&h>0&&t.strokeRect(a,l,c,h)}}Bb.layers=[6],Bb.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getStatisticFnResults","getAggregate","getSelectedFigureId","getSelection","getActivePosition","getSheetPosition","isSelected","getElementsFromSelection","isGridSelectionActive"];const Hb=(new xo).add("sheet",qv).add("header visibility",zv).add("filters",Uv).add("cell",Nv).add("merge",Hv).add("headerSize",Vv).add("borders",Ov).add("conditional formatting",Dv).add("figures",kv).add("chart",_v).add("image",Bv),$b=(new xo).add("ui_sheet",Tb).add("header_visibility_ui",lb).add("ui_options",Rb).add("selectionInputManager",ub).add("highlight",cb).add("grid renderer",hb).add("autofill",ob).add("find_and_replace",ab).add("sort",Ib).add("automatic_sum",nb).add("format",class extends Zv{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,i){for(const o of t)for(const t of oo(o)){const o=this.getCellNumberFormat({sheetId:e,...t});if(void 0!==o){const n=Ti(o,i);this.dispatch("SET_FORMATTING",{sheetId:e,target:[ao(t)],format:n})}}}getCellNumberFormat(e){var t;for(const i of[e]){const e=this.getters.getEvaluatedCell(i);if(e.type===rn.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(Y)))return e.format||xi(e.value)}}}).add("cell_popovers",sb).add("selection_multiuser",xb),Wb=(new xo).add("selection",Bb).add("clipboard",Db).add("edition",Vb),Gb=(new xo).add("evaluation",Yv).add("evaluation_filter",Jv).add("evaluation_chart",Kv).add("evaluation_cf",Qv).add("viewport",tb).add("custom_colors",jv),qb=new xo;qb.add("link",{condition:(e,t)=>!!t.model.getters.getEvaluatedCell(e).link,action:(e,t)=>No(t.model.getters.getEvaluatedCell(e).link,t),sequence:5});class Zb{constructor(e){this.fileStore=e}async requestImage(){const e=await this.getImageFromUser(),t=await this.fileStore.upload(e);return{path:t,size:await this.getImageSize(t),mimetype:e.type}}getImageFromUser(){return new Promise(((e,t)=>{const i=document.createElement("input");i.setAttribute("type","file"),i.setAttribute("accept","image/*"),i.addEventListener("change",(async()=>{null===i.files||1!=i.files.length?t():e(i.files[0])})),i.click()}))}getImageSize(e){return new Promise(((t,i)=>{const o=new Image;o.src=e,o.addEventListener("load",(()=>{const e={width:o.width,height:o.height};t(e)})),o.addEventListener("error",i)}))}}const jb=[{transform:"scale(0)"},{transform:"scale(0.8)",offset:.33},{opacity:"0",transform:"scale(1)",offset:1}];mo`
|
|
1400
|
+
`}function ev(e){return new vp(e.join("\n"))}function tv(e,...t){let i=[e[0]];for(let o=0;o<t.length;o++){const n=t[o]instanceof vp?t[o]:Yf(t[o]);i.push(n+e[o+1])}return new vp(rt(i))}function iv(e){return e.replace(/[a-z0-9]+:(?=[a-z0-9]+)/gi,"")}function ov(e){return e.replace(/([a-z0-9]+):(?=[a-z0-9]+)/gi,"$1\\:")}class nv{constructor(e){this.value=e}asString(){return am(String(this.value))}asBool(){return Boolean(Number(this.value))}asNum(){return Number(this.value)}}class sv{constructor(e,t,i){this.currentFile=void 0,this.rootFile=e,this.currentFile=e.file.fileName,this.xlsxFileStructure=t,this.warningManager=i,this.areNamespaceIgnored=null!==(new DOMParser).parseFromString("<t:test xmlns:t='a'/>","text/xml").querySelector("test"),this.relationships={},e.rels&&this.extractRelationships(e.rels).map((e=>{this.relationships[e.id]=e}))}extractRelationships(e){return this.mapOnElements({parent:e.xml,query:"Relationship"},(e=>({id:this.extractAttr(e,"Id",{required:!0}).asString(),target:this.extractAttr(e,"Target",{required:!0}).asString(),type:this.extractAttr(e,"Type",{required:!0}).asString()})))}getListOfFiles(){return Object.values(this.xlsxFileStructure).flat().filter(ot)}mapOnElements(e,t){var i;const o=[],n=this.currentFile;let s;if(e.children){const t=null===(i=this.querySelector(e.parent,e.query))||void 0===i?void 0:i.children;s=t||[]}else s=this.querySelectorAll(e.parent,e.query);if(s)for(let e of s)try{o.push(t(e))}catch(t){this.catchErrorOnElement(t,e)}return this.currentFile=n,o}catchErrorOnElement(e,t){const i=t?`Error when parsing an element <${t.tagName}> of file ${this.currentFile}, skip this element. \n${e.stack}`:`Error when parsing file ${this.currentFile}.`;this.warningManager.addParsingWarning([i,e.message].join("\n"))}extractAttr(e,t,i){const o=e.attributes[t];o||this.handleMissingValue(e,`attribute "${t}"`,i);const n=(null==o?void 0:o.value)?o.value:null==i?void 0:i.default;return void 0===n?void 0:new nv(n)}extractTextContent(e,t){var i;if(void 0!==(null==t?void 0:t.default)&&"string"!=typeof t.default)throw new Error("extractTextContent default value should be a string");const o="preserve"===(null===(i=null==e?void 0:e.attributes["xml:space"])||void 0===i?void 0:i.value);let n=null==e?void 0:e.textContent;return e&&null!==n||this.handleMissingValue(e,"text content",t),n&&(n=o?n:n.trim()),n?am(n):null==t?void 0:t.default}extractChildAttr(e,t,i,o){var n;let s;s="number"==typeof t?e.children[t]:this.querySelector(e,t),s||this.handleMissingValue(e,"number"==typeof t?`child at index ${t}`:`child <${t}>`,o);const r=s?null===(n=this.extractAttr(s,i,o))||void 0===n?void 0:n.asString():null==o?void 0:o.default;return void 0!==r?new nv(r):void 0}extractChildTextContent(e,t,i){if(void 0!==(null==i?void 0:i.default)&&"string"!=typeof i.default)throw new Error("extractTextContent default value should be a string");let o=this.querySelector(e,t);return o||this.handleMissingValue(e,`child <${t}>`,i),o?this.extractTextContent(o,i):null==i?void 0:i.default}handleMissingValue(e,t,i){if(null==i?void 0:i.required){if(!(null==i?void 0:i.default))throw new Error(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, and no default value was set`);this.warningManager.addParsingWarning(`Missing required ${t} in element <${e.tagName}> of ${this.currentFile}, replacing it by the default value ${i.default}`)}}extractColor(e,t,i){var o,n,s,r,a;if(!e)return i?{rgb:i}:void 0;const l=null===(o=this.extractAttr(e,"theme"))||void 0===o?void 0:o.asString();let c;if(void 0!==l){if(!t||!t.clrScheme)throw new Error("Color referencing a theme but no theme was provided");c=this.getThemeColor(l,t.clrScheme)}else c=null===(n=this.extractAttr(e,"rgb"))||void 0===n?void 0:n.asString();return{rgb:c,auto:null===(s=this.extractAttr(e,"auto"))||void 0===s?void 0:s.asBool(),indexed:null===(r=this.extractAttr(e,"indexed"))||void 0===r?void 0:r.asNum(),tint:null===(a=this.extractAttr(e,"tint"))||void 0===a?void 0:a.asNum()}}getTargetXmlFile(e){if(!e)throw new Error("Undefined target file");let t=e.target;t=t.replace("../",""),t=t.replace("./","");const i=this.getListOfFiles().find((e=>e.file.fileName.endsWith(t)));if(!i||!i.file)throw new Error("Cannot find target file");return i}querySelector(e,t){return t=this.areNamespaceIgnored?iv(t):ov(t),e.querySelector(t)}querySelectorAll(e,t){return t=this.areNamespaceIgnored?iv(t):ov(t),e.querySelectorAll(t)}getThemeColor(e,t){switch(e){case"0":return"FFFFFF";case"1":return"000000";case"2":return t[3].value;case"3":return t[2].value;default:return t[e].value}}}class rv extends sv{getTheme(){return{clrScheme:this.mapOnElements({query:"a:clrScheme",parent:this.rootFile.file.xml,children:!0},(e=>({name:e.tagName,value:this.extractChildAttr(e,0,"val",{required:!0,default:Sp}).asString(),lastClr:this.extractChildAttr(e,0,"lastClr",{default:Sp}).asString()})))}}getSharedStrings(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"si"},(e=>"t"===e.children[0].tagName?this.extractTextContent(e)||"":this.mapOnElements({parent:e,query:"t"},(e=>this.extractTextContent(e)||"")).join("")))}}class av extends sv{constructor(e,t,i,o){super(e,t,i),this.theme=o}extractConditionalFormattings(){const e=this.mapOnElements({parent:this.rootFile.file.xml,query:"worksheet > conditionalFormatting"},(e=>{var t;return{sqref:this.extractAttr(e,"sqref",{required:!0}).asString().split(" "),pivot:null===(t=this.extractAttr(e,"pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}));return e.push(...this.mapOnElements({parent:this.rootFile.file.xml,query:"extLst x14:conditionalFormatting"},(e=>{var t;return{sqref:this.extractChildTextContent(e,"xm:sqref",{required:!0}).split(" "),pivot:null===(t=this.extractAttr(e,"xm:pivot"))||void 0===t?void 0:t.asBool(),cfRules:this.extractCFRules(e,this.theme)}}))),e}extractCFRules(e,t){return this.mapOnElements({parent:e,query:"cfRule, x14:cfRule"},(e=>{var i,o,n,s,r,a,l,c,h,d,u;const g=this.extractAttr(e,"type",{required:!0}).asString();if("dataBar"===g)throw new Error("Databars conditional formats are not supported.");return{type:g,priority:this.extractAttr(e,"priority",{required:!0}).asNum(),colorScale:this.extractCfColorScale(e,t),formula:this.extractCfFormula(e),iconSet:this.extractCfIconSet(e),dxfId:null===(i=this.extractAttr(e,"dxfId"))||void 0===i?void 0:i.asNum(),stopIfTrue:null===(o=this.extractAttr(e,"stopIfTrue"))||void 0===o?void 0:o.asBool(),aboveAverage:null===(n=this.extractAttr(e,"aboveAverage"))||void 0===n?void 0:n.asBool(),percent:null===(s=this.extractAttr(e,"percent"))||void 0===s?void 0:s.asBool(),bottom:null===(r=this.extractAttr(e,"bottom"))||void 0===r?void 0:r.asBool(),operator:null===(a=this.extractAttr(e,"operator"))||void 0===a?void 0:a.asString(),text:null===(l=this.extractAttr(e,"text"))||void 0===l?void 0:l.asString(),timePeriod:null===(c=this.extractAttr(e,"timePeriod"))||void 0===c?void 0:c.asString(),rank:null===(h=this.extractAttr(e,"rank"))||void 0===h?void 0:h.asNum(),stdDev:null===(d=this.extractAttr(e,"stdDev"))||void 0===d?void 0:d.asNum(),equalAverage:null===(u=this.extractAttr(e,"equalAverage"))||void 0===u?void 0:u.asBool()}}))}extractCfFormula(e){return this.mapOnElements({parent:e,query:"formula"},(e=>this.extractTextContent(e,{required:!0})))}extractCfColorScale(e,t){const i=this.querySelector(e,"colorScale");if(i)return{colors:this.mapOnElements({parent:i,query:"color"},(e=>this.extractColor(e,t,"ffffff"))),cfvos:this.extractCFVos(i)}}extractCfIconSet(e){var t,i;const o=this.querySelector(e,"iconSet, x14:iconSet");if(o)return{iconSet:this.extractAttr(o,"iconSet",{default:"3TrafficLights1"}).asString(),showValue:this.extractAttr(o,"showValue",{default:!0}).asBool(),percent:this.extractAttr(o,"percent",{default:!0}).asBool(),reverse:null===(t=this.extractAttr(o,"reverse"))||void 0===t?void 0:t.asBool(),custom:null===(i=this.extractAttr(o,"custom"))||void 0===i?void 0:i.asBool(),cfvos:this.extractCFVos(o),cfIcons:this.extractCfIcons(o)}}extractCfIcons(e){const t=this.mapOnElements({parent:e,query:"cfIcon, x14:cfIcon"},(e=>({iconSet:this.extractAttr(e,"iconSet",{required:!0}).asString(),iconId:this.extractAttr(e,"iconId",{required:!0}).asNum()})));return 0===t.length?void 0:t}extractCFVos(e){return this.mapOnElements({parent:e,query:"cfvo, x14:cfvo"},(e=>{var t,i;return{type:this.extractAttr(e,"type",{required:!0}).asString(),gte:null===(t=this.extractAttr(e,"gte",{default:!0}))||void 0===t?void 0:t.asBool(),value:e.attributes.val?null===(i=this.extractAttr(e,"val"))||void 0===i?void 0:i.asString():this.extractChildTextContent(e,"f, xm:f")}}))}}class lv extends sv{extractChart(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"c:chartSpace"},(e=>{const t=this.getChartType(e);if(!Kp[t])throw new Error(`Unsupported chart type ${t}`);const i=this.mapOnElements({parent:e,query:"c:title a:t"},(e=>e.textContent||"")).join(""),o=this.extractChildAttr(e,"c:grouping","val",{default:"clustered"}).asString();return{title:i,type:Kp[t],dataSets:this.extractChartDatasets(this.querySelector(e,`c:${t}`)),backgroundColor:this.extractChildAttr(e,"c:chartSpace > c:spPr a:srgbClr","val",{default:"ffffff"}).asString(),verticalAxisPosition:"r"===this.extractChildAttr(e,"c:valAx > c:axPos","val",{default:"l"}).asString()?"right":"left",legendPosition:Yp[this.extractChildAttr(e,"c:legendPos","val",{default:"b"}).asString()],stacked:"stacked"===o,fontColor:"000000"}}))[0]}extractChartDatasets(e){return this.mapOnElements({parent:e,query:"c:ser"},(e=>({label:this.extractChildTextContent(e,"c:cat c:f"),range:this.extractChildTextContent(e,"c:val c:f",{required:!0})})))}getChartType(e){const t=this.querySelector(e,"c:plotArea");if(!t)throw new Error("Missing plot area in the chart definition.");for(let e of t.children){const t=iv(e.tagName);if(bp.some((e=>e===t)))return t}throw new Error("Unknown chart type")}}class cv extends sv{extractFigures(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"xdr:wsDr",children:!0},(e=>{if("twoCellAnchor"!==iv(e.tagName))throw new Error("Only twoCellAnchor are supported for xlsx drawings.");const t=this.querySelector(e,"c:chart");if(!t)throw new Error("Only chart figures are currently supported.");return{anchors:[this.extractFigureAnchor("xdr:from",e),this.extractFigureAnchor("xdr:to",e)],data:this.extractChart(t)}}))}extractFigureAnchor(e,t){const i=this.querySelector(t,e);if(!i)throw new Error(`Missing anchor element ${e}`);return{col:Number(this.extractChildTextContent(i,"xdr:col",{required:!0})),colOffset:Number(this.extractChildTextContent(i,"xdr:colOff",{required:!0})),row:Number(this.extractChildTextContent(i,"xdr:row",{required:!0})),rowOffset:Number(this.extractChildTextContent(i,"xdr:rowOff",{required:!0}))}}extractChart(e){const t=this.extractAttr(e,"r:id",{required:!0}).asString(),i=this.getTargetXmlFile(this.relationships[t]),o=new lv(i,this.xlsxFileStructure,this.warningManager).extractChart();if(!o)throw new Error("Unable to extract chart definition");return o}}class hv extends sv{getPivotTable(){return this.mapOnElements({query:":root",parent:this.rootFile.file.xml},(e=>({displayName:this.extractAttr(e,"name",{required:!0}).asString(),id:this.extractAttr(e,"name",{required:!0}).asString(),ref:this.extractChildAttr(e,"location","ref",{required:!0}).asString(),headerRowCount:this.extractChildAttr(e,"location","firstDataRow",{default:0}).asNum(),totalsRowCount:1,cols:[],style:{showFirstColumn:!0,showRowStripes:!0}})))[0]}}class dv extends sv{getTable(){return this.mapOnElements({query:"table",parent:this.rootFile.file.xml},(e=>{var t;return{displayName:this.extractAttr(e,"displayName",{required:!0}).asString(),name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),id:this.extractAttr(e,"id",{required:!0}).asString(),ref:this.extractAttr(e,"ref",{required:!0}).asString(),headerRowCount:this.extractAttr(e,"headerRowCount",{default:1}).asNum(),totalsRowCount:this.extractAttr(e,"totalsRowCount",{default:0}).asNum(),cols:this.extractTableCols(e),style:this.extractTableStyleInfo(e),autoFilter:this.extractTableAutoFilter(e)}}))[0]}extractTableCols(e){return this.mapOnElements({query:"tableColumn",parent:e},(e=>({id:this.extractAttr(e,"id",{required:!0}).asString(),name:this.extractAttr(e,"name",{required:!0}).asString(),colFormula:this.extractChildTextContent(e,"calculatedColumnFormula")})))}extractTableStyleInfo(e){return this.mapOnElements({query:"tableStyleInfo",parent:e},(e=>{var t,i,o,n,s;return{name:null===(t=this.extractAttr(e,"name"))||void 0===t?void 0:t.asString(),showFirstColumn:null===(i=this.extractAttr(e,"showFirstColumn"))||void 0===i?void 0:i.asBool(),showLastColumn:null===(o=this.extractAttr(e,"showLastColumn"))||void 0===o?void 0:o.asBool(),showRowStripes:null===(n=this.extractAttr(e,"showRowStripes"))||void 0===n?void 0:n.asBool(),showColumnStripes:null===(s=this.extractAttr(e,"showColumnStripes"))||void 0===s?void 0:s.asBool()}}))[0]}extractTableAutoFilter(e){return this.mapOnElements({query:"autoFilter",parent:e},(e=>({columns:this.extractFilterColumns(e),zone:this.extractAttr(e,"ref",{required:!0}).asString()})))[0]}extractFilterColumns(e){return this.mapOnElements({query:"tableColumn",parent:e},(t=>({colId:this.extractAttr(e,"colId",{required:!0}).asNum(),hiddenButton:this.extractAttr(e,"hiddenButton",{default:!1}).asBool(),filters:this.extractSimpleFilter(t)})))}extractSimpleFilter(e){return this.mapOnElements({query:"filter",parent:e},(e=>({val:this.extractAttr(e,"val",{required:!0}).asString()})))}}class uv extends sv{constructor(e,t,i,o){super(e,t,i),this.theme=o}getSheet(){return this.mapOnElements({query:"worksheet",parent:this.rootFile.file.xml},(e=>{const t=this.getSheetWorkbookInfo();return{sheetName:this.extractSheetName(),sheetViews:this.extractSheetViews(e),sheetFormat:this.extractSheetFormat(e),cols:this.extractCols(e),rows:this.extractRows(e),sharedFormulas:this.extractSharedFormulas(e),merges:this.extractMerges(e),cfs:this.extractConditionalFormats(),figures:this.extractFigures(e),hyperlinks:this.extractHyperLinks(e),tables:[...this.extractTables(e),...this.extractPivotTables()],isVisible:"visible"===t.state}}))[0]}extractSheetViews(e){return this.mapOnElements({parent:e,query:"sheetView"},(e=>{const t=this.querySelector(e,"pane");return{tabSelected:this.extractAttr(e,"tabSelected",{default:!1}).asBool(),showFormulas:this.extractAttr(e,"showFormulas",{default:!1}).asBool(),showGridLines:this.extractAttr(e,"showGridLines",{default:!0}).asBool(),showRowColHeaders:this.extractAttr(e,"showRowColHeaders",{default:!0}).asBool(),pane:{xSplit:t?this.extractAttr(t,"xSplit",{default:0}).asNum():0,ySplit:t?this.extractAttr(t,"ySplit",{default:0}).asNum():0}}}))}extractSheetName(){const e=nm(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id;for(let e of this.querySelectorAll(this.xlsxFileStructure.workbook.file.xml,"sheet"))if(e.attributes["r:id"].value===t)return e.attributes.name.value;throw new Error("Missing sheet name")}getSheetWorkbookInfo(){const e=nm(this.xlsxFileStructure.workbook.file.fileName,this.rootFile.file.fileName),t=this.extractRelationships(this.xlsxFileStructure.workbook.rels).find((t=>t.target===e)).id,i=this.mapOnElements({parent:this.xlsxFileStructure.workbook.file.xml,query:"sheet"},(e=>({relationshipId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetId:this.extractAttr(e,"sheetId",{required:!0}).asString(),sheetName:this.extractAttr(e,"name",{required:!0}).asString(),state:this.extractAttr(e,"state",{default:"visible"}).asString()}))).find((e=>e.relationshipId===t));if(!i)throw new Error("Cannot find corresponding workbook sheet");return i}extractConditionalFormats(){return new av(this.rootFile,this.xlsxFileStructure,this.warningManager,this.theme).extractConditionalFormattings()}extractFigures(e){return this.mapOnElements({parent:e,query:"drawing"},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),o=this.getTargetXmlFile(this.relationships[i]);return new cv(o,this.xlsxFileStructure,this.warningManager).extractFigures()}))[0]||[]}extractTables(e){return this.mapOnElements({query:"tablePart",parent:e},(e=>{var t;const i=null===(t=this.extractAttr(e,"r:id",{required:!0}))||void 0===t?void 0:t.asString(),o=this.getTargetXmlFile(this.relationships[i]);return new dv(o,this.xlsxFileStructure,this.warningManager).getTable()}))}extractPivotTables(){try{return Object.values(this.relationships).filter((e=>e.type.endsWith("pivotTable"))).map((e=>{const t=this.getTargetXmlFile(e);return new hv(t,this.xlsxFileStructure,this.warningManager).getPivotTable()}))}catch(e){return this.catchErrorOnElement(e),[]}}extractMerges(e){return this.mapOnElements({parent:e,query:"mergeCell"},(e=>this.extractAttr(e,"ref",{required:!0}).asString()))}extractSheetFormat(e){const t=this.querySelector(e,"sheetFormatPr");if(t)return{defaultColWidth:this.extractAttr(t,"defaultColWidth",{default:Mp.toString()}).asNum(),defaultRowHeight:this.extractAttr(t,"defaultRowHeight",{default:Op.toString()}).asNum()}}extractCols(e){return this.mapOnElements({parent:e,query:"cols col"},(e=>{var t,i,o,n,s,r,a;return{width:null===(t=this.extractAttr(e,"width"))||void 0===t?void 0:t.asNum(),customWidth:null===(i=this.extractAttr(e,"customWidth"))||void 0===i?void 0:i.asBool(),bestFit:null===(o=this.extractAttr(e,"bestFit"))||void 0===o?void 0:o.asBool(),hidden:null===(n=this.extractAttr(e,"hidden"))||void 0===n?void 0:n.asBool(),min:null===(s=this.extractAttr(e,"min",{required:!0}))||void 0===s?void 0:s.asNum(),max:null===(r=this.extractAttr(e,"max",{required:!0}))||void 0===r?void 0:r.asNum(),styleIndex:null===(a=this.extractAttr(e,"style"))||void 0===a?void 0:a.asNum()}}))}extractRows(e){return this.mapOnElements({parent:e,query:"sheetData row"},(e=>{var t,i,o,n,s;return{index:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asNum(),cells:this.extractCells(e),height:null===(i=this.extractAttr(e,"ht"))||void 0===i?void 0:i.asNum(),customHeight:null===(o=this.extractAttr(e,"customHeight"))||void 0===o?void 0:o.asBool(),hidden:null===(n=this.extractAttr(e,"hidden"))||void 0===n?void 0:n.asBool(),styleIndex:null===(s=this.extractAttr(e,"s"))||void 0===s?void 0:s.asNum()}}))}extractCells(e){return this.mapOnElements({parent:e,query:"c"},(e=>{var t,i,o;return{xc:null===(t=this.extractAttr(e,"r",{required:!0}))||void 0===t?void 0:t.asString(),styleIndex:null===(i=this.extractAttr(e,"s"))||void 0===i?void 0:i.asNum(),type:Wp[null===(o=this.extractAttr(e,"t",{default:"n"}))||void 0===o?void 0:o.asString()],value:this.extractChildTextContent(e,"v"),formula:this.extractCellFormula(e)}}))}extractCellFormula(e){var t,i;const o=this.querySelector(e,"f");if(o)return{content:this.extractTextContent(o),sharedIndex:null===(t=this.extractAttr(o,"si"))||void 0===t?void 0:t.asNum(),ref:null===(i=this.extractAttr(o,"ref"))||void 0===i?void 0:i.asString()}}extractHyperLinks(e){return this.mapOnElements({parent:e,query:"hyperlink"},(e=>{var t,i,o,n;const s=null===(t=this.extractAttr(e,"r:id"))||void 0===t?void 0:t.asString();return{xc:null===(i=this.extractAttr(e,"ref",{required:!0}))||void 0===i?void 0:i.asString(),location:null===(o=this.extractAttr(e,"location"))||void 0===o?void 0:o.asString(),display:null===(n=this.extractAttr(e,"display"))||void 0===n?void 0:n.asString(),relTarget:s?this.relationships[s].target:void 0}}))}extractSharedFormulas(e){const t=this.querySelectorAll(e,"f[si][ref]"),i={};for(let e of t){const t=this.extractAttr(e,"si",{required:!0}).asNum(),o=this.extractTextContent(e,{required:!0});i[t]=o}const o=[];for(let e=0;e<Object.keys(i).length;e++)i[e]?o.push(i[e]):(this.warningManager.addParsingWarning(`Missing shared formula ${e}, replacing it by empty formula`),o.push(""));return o}}class gv extends sv{constructor(e,t,i){super(e.styles,e,t),this.theme=i}getNumFormats(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"numFmt"},(e=>this.extractNumFormats(e)))}extractNumFormats(e){return{id:this.extractAttr(e,"numFmtId",{required:!0}).asNum(),format:this.extractAttr(e,"formatCode",{required:!0,default:""}).asString()}}getFonts(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"font"},(e=>this.extractFont(e)))}extractFont(e){var t,i,o,n;const s=this.extractChildAttr(e,"name","val",{default:"Arial"}).asString(),r=this.extractChildAttr(e,"sz","val",{default:q.toString()}).asNum(),a=this.extractColor(this.querySelector(e,"color"),this.theme),l=this.querySelector(e,"i")||void 0,c=l&&"0"!==(null===(t=l.attributes.val)||void 0===t?void 0:t.value),h=this.querySelector(e,"b")||void 0,d=h&&"0"!==(null===(i=h.attributes.val)||void 0===i?void 0:i.value),u=this.querySelector(e,"strike")||void 0,g=u&&"0"!==(null===(o=u.attributes.val)||void 0===o?void 0:o.value),p=this.querySelector(e,"u")||void 0;return{name:s,size:r,color:a,italic:c,bold:d,underline:p&&"none"!==(null===(n=p.attributes.val)||void 0===n?void 0:n.value),strike:g}}getFills(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"fill"},(e=>this.extractFill(e)))}extractFill(e){var t;const i=e.children[0];return"patternFill"===i.tagName?{patternType:null===(t=i.attributes.patternType)||void 0===t?void 0:t.value,bgColor:this.extractColor(this.querySelector(i,"bgColor"),this.theme),fgColor:this.extractColor(this.querySelector(i,"fgColor"),this.theme)}:{patternType:"solid",fgColor:this.extractColor(this.querySelectorAll(i,"color")[1],this.theme)}}getBorders(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"border"},(e=>this.extractBorder(e)))}extractBorder(e){var t,i;const o={left:this.extractSingleBorder(e,"left",this.theme),right:this.extractSingleBorder(e,"right",this.theme),top:this.extractSingleBorder(e,"top",this.theme),bottom:this.extractSingleBorder(e,"bottom",this.theme),diagonal:this.extractSingleBorder(e,"diagonal",this.theme)};return o.diagonal&&(o.diagonalUp=null===(t=this.extractAttr(e,"diagonalUp"))||void 0===t?void 0:t.asBool(),o.diagonalDown=null===(i=this.extractAttr(e,"diagonalDown"))||void 0===i?void 0:i.asBool()),o}extractSingleBorder(e,t,i){const o=this.querySelector(e,t);if(o&&o.attributes.style)return{style:this.extractAttr(o,"style",{required:!0,default:"thin"}).asString(),color:this.extractColor(o.children[0],i,"000000")}}extractAlignment(e){var t,i,o,n,s,r,a;return{horizontal:this.extractAttr(e,"horizontal",{default:"general"}).asString(),vertical:this.extractAttr(e,"vertical",{default:"center"}).asString(),textRotation:null===(t=this.extractAttr(e,"textRotation"))||void 0===t?void 0:t.asNum(),wrapText:null===(i=this.extractAttr(e,"wrapText"))||void 0===i?void 0:i.asBool(),indent:null===(o=this.extractAttr(e,"indent"))||void 0===o?void 0:o.asNum(),relativeIndent:null===(n=this.extractAttr(e,"relativeIndent"))||void 0===n?void 0:n.asNum(),justifyLastLine:null===(s=this.extractAttr(e,"justifyLastLine"))||void 0===s?void 0:s.asBool(),shrinkToFit:null===(r=this.extractAttr(e,"shrinkToFit"))||void 0===r?void 0:r.asBool(),readingOrder:null===(a=this.extractAttr(e,"readingOrder"))||void 0===a?void 0:a.asNum()}}getDxfs(){return this.mapOnElements({query:"dxf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"font"),i=this.querySelector(e,"fill"),o=this.querySelector(e,"border"),n=this.querySelector(e,"numFmt"),s=this.querySelector(e,"alignment");return{font:t?this.extractFont(t):void 0,fill:i?this.extractFill(i):void 0,numFmt:n?this.extractNumFormats(n):void 0,alignment:s?this.extractAlignment(s):void 0,border:o?this.extractBorder(o):void 0}}))}getStyles(){return this.mapOnElements({query:"cellXfs xf",parent:this.rootFile.file.xml},(e=>{const t=this.querySelector(e,"alignment");return{fontId:this.extractAttr(e,"fontId",{required:!0,default:0}).asNum(),fillId:this.extractAttr(e,"fillId",{required:!0,default:0}).asNum(),borderId:this.extractAttr(e,"borderId",{required:!0,default:0}).asNum(),numFmtId:this.extractAttr(e,"numFmtId",{required:!0,default:0}).asNum(),alignment:t?this.extractAlignment(t):void 0}}))}}class pv extends sv{getExternalBook(){return this.mapOnElements({parent:this.rootFile.file.xml,query:"externalBook"},(e=>({rId:this.extractAttr(e,"r:id",{required:!0}).asString(),sheetNames:this.mapOnElements({parent:e,query:"sheetName"},(e=>this.extractAttr(e,"val",{required:!0}).asString())),datasets:this.extractExternalSheetData(e)})))[0]}extractExternalSheetData(e){return this.mapOnElements({parent:e,query:"sheetData"},(e=>{const t=this.mapOnElements({parent:e,query:"cell"},(e=>({xc:this.extractAttr(e,"r",{required:!0}).asString(),value:this.extractChildTextContent(e,"v",{required:!0})}))),i={};for(let e of t)i[e.xc]=e.value;return{sheetId:this.extractAttr(e,"sheetId",{required:!0}).asNum(),data:i}}))}}function mv(e,t){const i=function(e,t){const i=t[Lp],o=i.querySelectorAll(`Override[ContentType="${e}"]`),n=[];for(let e of o){const t=null==e?void 0:e.attributes.PartName.value;n.push(t.substring(1))}return n}(e,t);return function(e,t){const i=[];for(let o of e){const e=fv(o,t);i.push({file:{fileName:o,xml:t[o]},rels:e?{fileName:e,xml:t[e]}:void 0})}return i}(i,t)}function fv(e,t){if(e===Lp)return"_rels/.rels";let i="";const o=e.split("/");for(let e=0;e<o.length-1;e++)i+=o[e]+"/";return i+="_rels/",i+=o[o.length-1]+".rels",t[i]||(i=void 0),i}class vv{constructor(e){this.warningManager=new Up,this.xmls={};for(let t of Object.keys(e))(t.endsWith(".xml")||t.endsWith(".rels"))&&(this.xmls[t]=Qf(new vp(e[t])))}convertXlsx(){const e=this.getXlsxData();return this.convertImportedData(e)}getXlsxData(){const e=this.buildXlsxFileStructure(),t=e.theme?new rv(e.theme,e,this.warningManager).getTheme():void 0,i=e.sharedStrings?new rv(e.sharedStrings,e,this.warningManager).getSharedStrings():[],o=e.sheets.sort(((e,t)=>e.file.fileName.localeCompare(t.file.fileName,void 0,{numeric:!0}))).map((i=>new uv(i,e,this.warningManager,t).getSheet())),n=e.externalLinks.map((t=>new pv(t,e,this.warningManager).getExternalBook())),s=new gv(e,this.warningManager,t);return{fonts:s.getFonts(),fills:s.getFills(),borders:s.getBorders(),dxfs:s.getDxfs(),numFmts:s.getNumFormats(),styles:s.getStyles(),sheets:o,sharedStrings:i,externalBooks:n}}buildXlsxFileStructure(){const e={sheets:mv(xp.sheet,this.xmls),workbook:mv(xp.workbook,this.xmls)[0],styles:mv(xp.styles,this.xmls)[0],sharedStrings:mv(xp.sharedStrings,this.xmls)[0],theme:mv(xp.themes,this.xmls)[0],charts:mv(xp.chart,this.xmls),figures:mv(xp.drawing,this.xmls),tables:mv(xp.table,this.xmls),pivots:mv(xp.pivot,this.xmls),externalLinks:mv(xp.externalLink,this.xmls)};if(!e.workbook.rels)throw Error(s("Cannot find workbook relations file"));return e}convertImportedData(e){const t={version:12,sheets:Uf(e,this.warningManager),styles:um(e,this.warningManager),formats:pm(e,this.warningManager),borders:hm(e,this.warningManager),entities:{},revisionId:Q};return qf(t,e),Object.keys(e.styles).map((t=>{e.styles[t]=ut(e.styles[t])})),t}}function bv(e){const t=rf(e);let i=[];return{text:"".concat(...t.map((e=>{if("REFERENCE"===e.type&&Nt.test(e.value)){const t=e.value.trim();return i.includes(t)||i.push(t),`${ae}${i.indexOf(t)}${ae}`}return e.value}))),dependencies:i}}const Sv=12,Cv="Sheet1";function Ev(e,t){if(!e)return Rv();if(e["[Content_Types].xml"]){const i=new vv(e);if(e=i.convertXlsx(),t)for(let e of i.warningManager.warnings.sort())console.warn(e)}return"version"in(e=Fe(e))&&e.version<Sv&&(e=function(e){for(let t=wv.findIndex((t=>t.from===e.version));t<wv.length;t++)e=wv[t].applyMigration(e);return e}(e)),e=function(e){return e=function(e){if(e.uniqueFigureIds)return e;const t=new Set,i=new Ui;for(const o of e.sheets||[])for(const e of o.figures||[])t.has(e.id)&&(e.id+=i.uuidv4()),t.add(e.id);return e.uniqueFigureIds=!0,e}(e),e=function(e){e=Object.assign(Rv(),e,{version:Sv}),e.sheets=e.sheets?e.sheets.map(((e,t)=>Object.assign(Iv(`Sheet${t+1}`,`Sheet${t+1}`),e))):[],0===e.sheets.length&&e.sheets.push(Iv(Cv,"Sheet1"));return e}(e),e}(e),e}const wv=[{description:"add the `activeSheet` field on data",from:1,to:2,applyMigration:e=>(e.sheets&&e.sheets[0]&&(e.activeSheet=e.sheets[0].name),e)},{description:"add an id field in each sheet",from:2,to:3,applyMigration(e){if(e.sheets&&e.sheets.length)for(let t of e.sheets)t.id=t.id||t.name;return e}},{description:"activeSheet is now an id, not the name of a sheet",from:3,to:4,applyMigration(e){if(e.sheets&&e.activeSheet){const t=e.sheets.find((t=>t.name===e.activeSheet));e.activeSheet=t.id}return e}},{description:"add figures object in each sheets",from:4,to:5,applyMigration(e){for(let t of e.sheets||[])t.figures=t.figures||[];return e}},{description:"normalize the content of the cell if it is a formula to avoid parsing all the formula that vary only by the cells they use",from:5,to:6,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];i.content&&i.content.startsWith("=")&&(i.formula=bv(i.content))}return e}},{description:"transform chart data structure",from:6,to:7,applyMigration(e){for(let t of e.sheets||[])for(let e in t.figures||[]){const{dataSets:i,...o}=t.figures[e].data,n=[];for(let e of i)if(e.labelCell){const t=zi(e.dataRange),i=e.labelCell+":"+Gt(t.right,t.bottom);n.push(i)}else n.push(e.dataRange);o.dataSetsHaveTitle=Boolean(i[0].labelCell),o.dataSets=n,t.figures[e].data=o}return e}},{description:"remove single quotes in sheet names",from:7,to:8,applyMigration(e){var t;const i=[],o=new RegExp(re,"g");for(let n of e.sheets||[]){if(!n.name)continue;const e=n.name,s=e.replace(o,"_");let r=1,a=s;for(;i.includes(a);)a=`${s}${r}`,r++;n.name=a,i.push(a);const l=t=>{if(void 0===t)return t;let i=t.replace(e,a),o=t;for(;o!==i;)o=i,i=o.replace(e,a);return o};for(let e in n.cells){const t=n.cells[e];t.formula&&(t.formula.dependencies=t.formula.dependencies.map(l))}for(let e of n.figures||[])if("chart"===e.type){const t=e.data.dataSets.map(l),i=l(e.data.labelRange);e.data={...e.data,dataSets:t,labelRange:i}}for(let e of n.conditionalFormats||[]){e.ranges=e.ranges.map(l);for(const i of["minimum","maximum","midpoint","upperInflectionPoint","lowerInflectionPoint"])"formula"===(null===(t=e.rule[i])||void 0===t?void 0:t.type)&&(e.rule[i].value=l(e.rule[i].value))}}return e}},{description:"transform chart data structure with design attributes",from:8,to:9,applyMigration(e){for(const t of e.sheets||[])for(const e of t.figures||[])e.data.background=w,e.data.verticalAxisPosition="left",e.data.legendPosition="top",e.data.stacked=!1;return e}},{description:"de-normalize formula to reduce exported json size (~30%)",from:9,to:10,applyMigration(e){for(let t of e.sheets||[])for(let e in t.cells||[]){const i=t.cells[e];if(i.formula){let{text:e,dependencies:t}=i.formula;for(let[i,o]of Object.entries(t)){const t=`\\${ae}${i}\\${ae}`;e=e.replace(new RegExp(t,"g"),o)}i.content=e,delete i.formula}}return e}},{description:"normalize the formats of the cells",from:10,to:11,applyMigration(e){const t={};for(let i of e.sheets||[])for(let e in i.cells||[]){const o=i.cells[e];o.format&&(o.format=st(o.format,t))}return e.formats=t,e}},{description:"Add isVisible to sheets",from:11,to:12,applyMigration(e){for(let t of e.sheets||[])t.isVisible=!0;return e}}];function yv(e,t){return t=function(e,t){if(0!==Object.keys(e).length)return t;const i=[],o=[],n=e=>{if("CREATE_SHEET"===e.type)i.push(e.sheetId);else if("sheetId"in e&&!i.includes(e.sheetId))return{...e,sheetId:Cv};return e};for(const e of t)"REMOTE_REVISION"===e.type?o.push({...e,commands:e.commands.map(n)}):o.push(e);return o}(e,t),t=xv(t,"SORT_CELLS"),t=function(e,t){var i;const o=[],n={};for(const t of e.sheets||[])null===(i=t.figures)||void 0===i||i.forEach((e=>{"chart"===e.tag&&(n[e.id]=e.data)}));for(const e of t)if("REMOTE_REVISION"===e.type){const t=[];for(const i of e.commands){let e=i;switch(i.type){case"CREATE_CHART":n[i.id]=i.definition;break;case"UPDATE_CHART":if(!n[i.id]){console.log(`Fix chart definition: chart with id ${i.id} not found.`);continue}const t={...n[i.id],...i.definition};e={...i,definition:t},n[i.id]=t}t.push(e)}o.push({...e,commands:t})}else o.push(e);return o}(e,t=xv(t,"SET_DECIMAL")),t}function xv(e,t){const i=[];for(const o of e)"REMOTE_REVISION"===o.type?i.push({...o,commands:o.commands.filter((e=>e.type!==t))}):i.push(o);return i}function Iv(e,t){return{id:e,name:t,colNumber:26,rowNumber:100,cells:{},cols:{},rows:{},merges:[],conditionalFormats:[],figures:[],filterTables:[],isVisible:!0}}function Rv(e="Sheet1"){return{version:Sv,sheets:[Iv(Cv,e)],entities:{},styles:{},formats:{},borders:{},revisionId:Q,uniqueFigureIds:!0}}function Tv(e,t){return{...Iv(e,t),charts:[],images:[]}}class Av{constructor(e,t){this.history=Object.assign(Object.create(e),{update:e.addChange.bind(e,this),selectCell:()=>{}}),this.dispatch=t}exportForExcel(e){}allowDispatch(e){return 0}beforeHandle(e){}handle(e){}finalize(){}batchValidations(...e){return t=>e.map((e=>e.call(this,t))).flat()}chainValidations(...e){return t=>{for(const i of e){let e=i.call(this,t);Array.isArray(e)||(e=[e]);const o=e.filter((e=>0!==e));if(o.length)return o}return 0}}checkValidations(e,...t){return this.batchValidations(...t)(e)}}Av.getters=[];class Mv extends Av{constructor({getters:e,stateObserver:t,range:i,dispatch:o,uuidGenerator:n}){super(t,o),this.range=i,i.addRangeProvider(this.adaptRanges.bind(this)),this.getters=e,this.uuidGenerator=n}import(e){}export(e){}adaptRanges(e,t){}garbageCollectExternalResources(){}}class Ov extends Mv{constructor(){super(...arguments),this.borders={}}handle(e){switch(e.type){case"ADD_MERGE":for(const t of e.target)this.addBordersToMerge(e.sheetId,t);break;case"DUPLICATE_SHEET":const t=this.borders[e.sheetId];if(t){const i=t.slice().map((e=>null==e?void 0:e.slice().map((e=>({...e})))));this.history.update("borders",e.sheetIdTo,i)}break;case"DELETE_SHEET":const i={...this.borders};delete i[e.sheetId],this.history.update("borders",i);break;case"SET_BORDER":this.setBorder(e.sheetId,e.col,e.row,e.border);break;case"SET_FORMATTING":if(e.border){const t=e.target.map((t=>this.getters.expandZone(e.sheetId,t)));this.setBorders(e.sheetId,t,e.border)}break;case"CLEAR_FORMATTING":this.clearBorders(e.sheetId,e.target);break;case"REMOVE_COLUMNS_ROWS":for(let t of e.elements)"COL"===e.dimension?this.shiftBordersHorizontally(e.sheetId,t+1,-1):this.shiftBordersVertically(e.sheetId,t+1,-1);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumns(e):this.handleAddRows(e)}}handleAddColumns(e){let t,i;"before"===e.position?(this.shiftBordersHorizontally(e.sheetId,e.base,e.quantity,{moveFirstLeftBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersHorizontally(e.sheetId,e.base+1,e.quantity,{moveFirstLeftBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureColumnBorderContinuity(e.sheetId,t,i)}handleAddRows(e){let t,i;"before"===e.position?(this.shiftBordersVertically(e.sheetId,e.base,e.quantity,{moveFirstTopBorder:!0}),t=e.base-1,i=e.base+e.quantity):(this.shiftBordersVertically(e.sheetId,e.base+1,e.quantity,{moveFirstTopBorder:!1}),t=e.base,i=e.base+e.quantity+1),this.ensureRowBorderContinuity(e.sheetId,t,i)}getCellBorder({sheetId:e,col:t,row:i}){var o,n,s,r,a,l,c,h,d,u,g,p;const m={top:null===(s=null===(n=null===(o=this.borders[e])||void 0===o?void 0:o[t])||void 0===n?void 0:n[i])||void 0===s?void 0:s.horizontal,bottom:null===(l=null===(a=null===(r=this.borders[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i+1])||void 0===l?void 0:l.horizontal,left:null===(d=null===(h=null===(c=this.borders[e])||void 0===c?void 0:c[t])||void 0===h?void 0:h[i])||void 0===d?void 0:d.vertical,right:null===(p=null===(g=null===(u=this.borders[e])||void 0===u?void 0:u[t+1])||void 0===g?void 0:g[i])||void 0===p?void 0:p.vertical};return m.bottom||m.left||m.right||m.top?m:null}ensureColumnBorderContinuity(e,t,i){const o=$e(t+1,i);for(let n=0;n<this.getters.getNumberRows(e);n++){const s=this.getCellBorder({sheetId:e,col:t,row:n}),r=this.getCellBorder({sheetId:e,col:i,row:n});if(s&&r){const t=this.getCommonSides(s,r);for(let i of o)this.addBorder(e,i,n,t)}}}ensureRowBorderContinuity(e,t,i){const o=$e(t+1,i);for(let n=0;n<this.getters.getNumberCols(e);n++){const s=this.getCellBorder({sheetId:e,col:n,row:t}),r=this.getCellBorder({sheetId:e,col:n,row:i});if(s&&r){const t=this.getCommonSides(s,r);for(let i of o)this.addBorder(e,n,i,t)}}}getCommonSides(e,t){const i={};for(let o of["top","bottom","left","right"])e[o]&&e[o]===t[o]&&(i[o]=e[o]);return i}getColumnsWithBorders(e){const t=this.borders[e];return t?Object.keys(t).map((e=>parseInt(e,10))):[]}getRowsRange(e){return this.borders[e]?$e(0,this.getters.getNumberRows(e)+1):[]}shiftBordersHorizontally(e,t,i,{moveFirstLeftBorder:o}={}){this.borders[e]&&(i<0&&this.moveBordersOfColumn(e,t,i,"vertical",{destructive:!1}),this.getColumnsWithBorders(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((n=>{(n===t&&o||n!==t)&&this.moveBordersOfColumn(e,n,i,"vertical"),this.moveBordersOfColumn(e,n,i,"horizontal")})))}shiftBordersVertically(e,t,i,{moveFirstTopBorder:o}={}){this.borders[e]&&(i<0&&this.moveBordersOfRow(e,t,i,"horizontal",{destructive:!1}),this.getRowsRange(e).filter((e=>e>=t)).sort(((e,t)=>i<0?e-t:t-e)).forEach((n=>{(n===t&&o||n!==t)&&this.moveBordersOfRow(e,n,i,"horizontal"),this.moveBordersOfRow(e,n,i,"vertical")})))}moveBordersOfRow(e,t,i,o,{destructive:n}={destructive:!0}){const s=this.borders[e];s&&this.getColumnsWithBorders(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[r])||void 0===a?void 0:a[t+i])||void 0===l?void 0:l[o],u=null===(h=null===(c=s[r])||void 0===c?void 0:c[t])||void 0===h?void 0:h[o];this.history.update("borders",e,r,t+i,o,n?u:u||d),this.history.update("borders",e,r,t,o,void 0)}))}moveBordersOfColumn(e,t,i,o,{destructive:n}={destructive:!0}){const s=this.borders[e];s&&this.getRowsRange(e).forEach((r=>{var a,l,c,h;const d=null===(l=null===(a=s[t+i])||void 0===a?void 0:a[r])||void 0===l?void 0:l[o],u=null===(h=null===(c=s[t])||void 0===c?void 0:c[r])||void 0===h?void 0:h[o];this.history.update("borders",e,t+i,r,o,n?u:u||d),this.history.update("borders",e,t,r,o,void 0)}))}setBorder(e,t,i,o,n=!0){var s,r,a,l,c,h,d,u,g,p,m,f,v,b,S,C;!n&&(null===(l=null===(a=null===(r=null===(s=this.borders)||void 0===s?void 0:s[e])||void 0===r?void 0:r[t])||void 0===a?void 0:a[i])||void 0===l?void 0:l.vertical)||this.history.update("borders",e,t,i,"vertical",null==o?void 0:o.left),!n&&(null===(u=null===(d=null===(h=null===(c=this.borders)||void 0===c?void 0:c[e])||void 0===h?void 0:h[t])||void 0===d?void 0:d[i])||void 0===u?void 0:u.horizontal)||this.history.update("borders",e,t,i,"horizontal",null==o?void 0:o.top),!n&&(null===(f=null===(m=null===(p=null===(g=this.borders)||void 0===g?void 0:g[e])||void 0===p?void 0:p[t+1])||void 0===m?void 0:m[i])||void 0===f?void 0:f.vertical)||this.history.update("borders",e,t+1,i,"vertical",null==o?void 0:o.right),!n&&(null===(C=null===(S=null===(b=null===(v=this.borders)||void 0===v?void 0:v[e])||void 0===b?void 0:b[t])||void 0===S?void 0:S[i+1])||void 0===C?void 0:C.horizontal)||this.history.update("borders",e,t,i+1,"horizontal",null==o?void 0:o.bottom)}clearBorders(e,t){for(let i of t){for(let t=i.top;t<=i.bottom;t++){this.history.update("borders",e,i.right+1,t,"vertical",void 0);for(let o=i.left;o<=i.right;o++)this.history.update("borders",e,o,t,void 0)}for(let t=i.left;t<=i.right;t++)this.history.update("borders",e,t,i.bottom+1,"horizontal",void 0)}}addBorder(e,t,i,o){this.setBorder(e,t,i,{...this.getCellBorder({sheetId:e,col:t,row:i}),...o})}setBorders(e,t,i){if("clear"===i)return this.clearBorders(e,t);for(let o of t){if("h"===i||"hv"===i||"all"===i)for(let t=o.top+1;t<=o.bottom;t++)for(let i=o.left;i<=o.right;i++)this.addBorder(e,i,t,{top:j});if("v"===i||"hv"===i||"all"===i)for(let t=o.top;t<=o.bottom;t++)for(let i=o.left+1;i<=o.right;i++)this.addBorder(e,i,t,{left:j});if("left"===i||"all"===i||"external"===i)for(let t=o.top;t<=o.bottom;t++)this.addBorder(e,o.left,t,{left:j});if("right"===i||"all"===i||"external"===i)for(let t=o.top;t<=o.bottom;t++)this.addBorder(e,o.right+1,t,{left:j});if("top"===i||"all"===i||"external"===i)for(let t=o.left;t<=o.right;t++)this.addBorder(e,t,o.top,{top:j});if("bottom"===i||"all"===i||"external"===i)for(let t=o.left;t<=o.right;t++)this.addBorder(e,t,o.bottom+1,{top:j})}}addBordersToMerge(e,t){const{left:i,right:o,top:n,bottom:s}=t,r=this.getCellBorder({sheetId:e,col:i,row:n}),a=this.getCellBorder({sheetId:e,col:o,row:s});this.clearBorders(e,[t]),(null==r?void 0:r.top)&&this.setBorders(e,[{...t,bottom:n}],"top"),(null==r?void 0:r.left)&&this.setBorders(e,[{...t,right:i}],"left"),((null==a?void 0:a.bottom)||(null==r?void 0:r.bottom))&&this.setBorders(e,[{...t,top:s}],"bottom"),((null==a?void 0:a.right)||(null==r?void 0:r.right))&&this.setBorders(e,[{...t,left:o}],"right")}import(e){if(e.borders)for(let t of e.sheets)for(let[i,o]of Object.entries(t.cells))if(null==o?void 0:o.border){const n=e.borders[o.border],{col:s,row:r}=Wt(i);this.setBorder(t.id,s,r,n,!1)}for(let t of e.sheets)if(t.merges)for(let e of t.merges)this.addBordersToMerge(t.id,zi(e))}export(e){let t=0;const i={};function o(e){for(let[t,o]of Object.entries(i))if(Oe(o)===Oe(e))return parseInt(t,10);return i[++t]=e,t}for(let t of e.sheets)for(let e=0;e<t.colNumber;e++)for(let i=0;i<t.rowNumber;i++){const n=this.getCellBorder({sheetId:t.id,col:e,row:i});if(n){const s=Gt(e,i),r=t.cells[s],a=o(n);r?r.border=a:t.cells[s]={border:a}}}e.borders=i}exportForExcel(e){this.export(e)}}Ov.getters=["getCellBorder"];class Nv extends Mv{constructor(){super(...arguments),this.nextId=1,this.cells={}}adaptRanges(e,t){for(const i of Object.keys(this.cells))for(const o of Object.values(this.cells[i]||{}))if(o.isFormula)for(const n of o.dependencies)if(!t||n.sheetId===t){const t=e(n);"NONE"!==t.changeType&&this.history.update("cells",i,o.id,"dependencies",o.dependencies.indexOf(n),t.range)}}allowDispatch(e){switch(e.type){case"UPDATE_CELL":case"CLEAR_CELL":return this.checkCellOutOfSheet(e.sheetId,e.col,e.row);default:return 0}}handle(e){switch(e.type){case"SET_FORMATTING":"style"in e&&this.setStyle(e.sheetId,e.target,e.style),"format"in e&&void 0!==e.format&&this.setFormatter(e.sheetId,e.target,e.format);break;case"CLEAR_FORMATTING":this.clearFormatting(e.sheetId,e.target);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.handleAddColumnsRows(e,this.copyColumnStyle.bind(this)):this.handleAddColumnsRows(e,this.copyRowStyle.bind(this));break;case"UPDATE_CELL":this.updateCell(e.sheetId,e.col,e.row,e);break;case"CLEAR_CELL":this.dispatch("UPDATE_CELL",{sheetId:e.sheetId,col:e.col,row:e.row,content:"",style:null,format:""})}}setFormatter(e,t,i){for(let o of t)for(let t=o.top;t<=o.bottom;t++)for(let n=o.left;n<=o.right;n++)this.dispatch("UPDATE_CELL",{sheetId:e,col:n,row:t,format:i})}clearFormatting(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,style:null,format:""})}handleAddColumnsRows(e,t){let i,o;"before"===e.position?(i=$e(e.base,e.base+e.quantity),o=e.base+e.quantity):(i=$e(e.base+1,e.base+e.quantity+1),o=e.base),t(e.sheetId,o,i)}import(e){for(let t of e.sheets)for(let i in t.cells){const o=t.cells[i],{col:n,row:s}=Wt(i);if((null==o?void 0:o.content)||(null==o?void 0:o.format)||(null==o?void 0:o.style)){const i=this.importCell(t.id,o,e.styles,e.formats);this.history.update("cells",t.id,i.id,i),this.dispatch("UPDATE_CELL_POSITION",{cellId:i.id,col:n,row:s,sheetId:t.id})}}}export(e){const t={},i={};for(let o of e.sheets){const e={},n=Object.keys(this.cells[o.id]||{}).map((e=>this.getters.getCellPosition(e))).sort(((e,t)=>e.col===t.col?e.row-t.row:e.col-t.col));for(const o of n){const n=this.getters.getCell(o);e[Gt(o.col,o.row)]={style:n.style?st(n.style,t):void 0,format:n.format?st(n.format,i):void 0,content:n.content||void 0}}o.cells=e}e.styles=t,e.formats=i}importCell(e,t,i,o){const n=t.style&&i[t.style]||void 0,s=t.format&&o[t.format]||void 0,r=this.getNextUid();return this.createCell(r,(null==t?void 0:t.content)||"",s,n,e)}exportForExcel(e){this.export(e)}getCells(e){return this.cells[e]||{}}getCellById(e){for(const t in this.cells){const i=this.cells[t][e];if(i)return i}}buildFormulaContent(e,t,i){const o=i||t.dependencies;let n=0;return rt(t.compiledFormula.tokens.map((t=>{if("REFERENCE"===t.type){const t=o[n++];return this.getters.getRangeString(t,e)}return t.value})))}getFormulaCellContent(e,t){return this.buildFormulaContent(e,t)}getCellStyle(e){var t;return(null===(t=this.getters.getCell(e))||void 0===t?void 0:t.style)||{}}zoneToXC(e,t,i=[{colFixed:!1,rowFixed:!1}]){const o=Gt((t=this.getters.expandZone(e,t)).left,t.top,i[0]),n=Gt(t.right,t.bottom,i.length>1?i[1]:i[0]),s=this.getters.getMainCellPosition({sheetId:e,col:t.left,row:t.top}),r=this.getters.getMainCellPosition({sheetId:e,col:t.right,row:t.bottom}),a=s.col===r.col&&s.row===r.row;return o==n||a?o:o+":"+n}setStyle(e,t,i){for(let o of t)for(let t=o.left;t<=o.right;t++)for(let n=o.top;n<=o.bottom;n++){const o=this.getters.getCell({sheetId:e,col:t,row:n});this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:n,style:i?{...null==o?void 0:o.style,...i}:void 0})}}copyColumnStyle(e,t,i){for(let o=0;o<this.getters.getNumberRows(e);o++){const n=this.getFormat(e,t,o);if(n.style||n.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,...n})}}copyRowStyle(e,t,i){for(let o=0;o<this.getters.getNumberCols(e);o++){const n=this.getFormat(e,o,t);if(n.style||n.format)for(let t of i)this.dispatch("UPDATE_CELL",{sheetId:e,col:o,row:t,...n})}}getFormat(e,t,i){const o={},n=this.getters.getMainCellPosition({sheetId:e,col:t,row:i}),s=this.getters.getCell(n);return s&&(s.style&&(o.style=s.style),s.format&&(o.format=s.format)),o}getNextUid(){const e=this.nextId.toString();return this.history.update("nextId",this.nextId+1),e}updateCell(e,t,i,o){const n=this.getters.getCell({sheetId:e,col:t,row:i}),s="content"in o||"formula"in o,r=s?vt(null==o?void 0:o.content):(null==n?void 0:n.content)||"";let a;a=void 0!==o.style?o.style||void 0:n?n.style:void 0;let l=("format"in o?o.format:n&&n.format)||Ii(r);if((s&&!r&&!o.formula||!s&&(!n||""===n.content))&&!a&&!l)return void(n&&(this.history.update("cells",e,n.id,void 0),this.dispatch("UPDATE_CELL_POSITION",{cellId:void 0,col:t,row:i,sheetId:e})));const c=(null==n?void 0:n.id)||this.getNextUid(),h=this.createCell(c,r,l,a,e);this.history.update("cells",e,h.id,h),this.dispatch("UPDATE_CELL_POSITION",{cellId:h.id,col:t,row:i,sheetId:e})}createCell(e,t,i,o,n){if(!t.startsWith("="))return this.createLiteralCell(e,t,i,o);try{return this.createFormulaCell(e,t,i,o,n)}catch(n){return this.createErrorFormula(e,t,i,o,n)}}createLiteralCell(e,t,i,o){return{id:e,content:t,style:o,format:i,isFormula:!1}}createFormulaCell(e,t,i,o,n){const s=df(t);return s.dependencies.length?this.createFormulaCellWithDependencies(e,s,i,o,n):{id:e,content:t,style:o,format:i,isFormula:!0,compiledFormula:s,dependencies:[]}}createFormulaCellWithDependencies(e,t,i,o,n){const s=t.dependencies.map((e=>this.getters.getRangeFromSheetXC(n,e))),r=this.buildFormulaContent.bind(this);return{id:e,get content(){return r(n,{dependencies:this.dependencies,compiledFormula:this.compiledFormula})},style:o,format:i,isFormula:!0,compiledFormula:t,dependencies:s}}createErrorFormula(e,t,i,o,n){return{id:e,content:t,style:o,format:i,isFormula:!0,compiledFormula:{dependencies:[],tokens:Tm(t),execute:function(){throw n}},dependencies:[]}}checkCellOutOfSheet(e,t,i){if(!this.getters.tryGetSheet(e))return 27;return Ki(t,i,this.getters.getSheetZone(e))?0:18}}Nv.getters=["zoneToXC","getCells","getFormulaCellContent","getCellStyle","buildFormulaContent","getCellById"];class _v extends Mv{constructor(){super(...arguments),this.charts={},this.createChart=function(e){const t=lr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i,o,n){const s=t.find((e=>e.match(o.type)));if(!s)throw new Error(`No builder for this chart: ${o.type}`);return s.createChart(o,n,e)}}(this.getters),this.validateChartDefinition=e=>function(e,t){const i=lr.getAll().find((e=>e.match(t.type)));if(!i)throw new Error("Unknown chart type.");return i.validateChartDefinition(e,t)}(this,e.definition)}adaptRanges(e){for(const[t,i]of Object.entries(this.charts))this.history.update("charts",t,null==i?void 0:i.updateRanges(e))}allowDispatch(e){switch(e.type){case"CREATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartDuplicate));case"UPDATE_CHART":return this.checkValidations(e,this.chainValidations(this.validateChartDefinition,this.checkChartExists));default:return 0}}handle(e){var t;switch(e.type){case"CREATE_CHART":this.addFigure(e.id,e.sheetId,e.position,e.size),this.addChart(e.id,e.definition);break;case"UPDATE_CHART":this.addChart(e.id,e.definition);break;case"DUPLICATE_SHEET":{const i=this.getters.getFigures(e.sheetId);for(const o of i)if("chart"===o.tag){const i=o.id.split(ee).pop(),n=`${e.sheetIdTo}${ee}${i}`,s=null===(t=this.charts[o.id])||void 0===t?void 0:t.copyForSheetId(e.sheetIdTo);s&&this.dispatch("CREATE_CHART",{id:n,position:{x:o.x,y:o.y},size:{width:o.width,height:o.height},definition:s.getDefinition(),sheetId:e.sheetIdTo})}break}case"DELETE_FIGURE":this.history.update("charts",e.id,void 0);break;case"DELETE_SHEET":for(let t of this.getChartIds(e.sheetId))this.history.update("charts",t,void 0)}}getContextCreationChart(e){var t;return null===(t=this.charts[e])||void 0===t?void 0:t.getContextCreation()}getChart(e){return this.charts[e]}getChartType(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.type;if(!i)throw new Error("Chart not defined.");return i}isChartDefined(e){return e in this.charts&&void 0!==this.charts}getChartIds(e){return Object.entries(this.charts).filter((([,t])=>(null==t?void 0:t.sheetId)===e)).map((([e])=>e))}getChartDefinition(e){var t;const i=null===(t=this.charts[e])||void 0===t?void 0:t.getDefinition();if(!i)throw new Error(`There is no chart with the given figureId: ${e}`);return i}import(e){for(let t of e.sheets)if(t.figures)for(let e of t.figures)"chart"===e.tag&&(this.charts[e.id]=this.createChart(e.id,e.data,t.id))}export(e){var t;if(e.sheets)for(let i of e.sheets){const e=this.getters.getFigures(i.id),o=[];for(let i of e){const e=i;if(e&&"chart"===e.tag){const i=null===(t=this.charts[e.id])||void 0===t?void 0:t.getDefinition();i&&(e.data=i,o.push(e))}else o.push(e)}i.figures=o}}exportForExcel(e){var t;for(let i of e.sheets){const e=this.getters.getFigures(i.id),o=[];for(let i of e)if(i&&"chart"===i.tag){const e=null===(t=this.charts[i.id])||void 0===t?void 0:t.getDefinitionForExcel();e&&o.push({...i,data:e})}i.charts=o}}addFigure(e,t,i={x:0,y:0},o={width:536,height:335}){if(this.getters.getFigure(t,e))return;const n={id:e,x:i.x,y:i.y,width:o.width,height:o.height,tag:"chart"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:n})}addChart(e,t){const i=this.getters.getFigureSheetId(e);i&&this.history.update("charts",e,this.createChart(e,t,i))}checkChartDuplicate(e){return this.getters.getFigureSheetId(e.id)?84:0}checkChartExists(e){return this.getters.getFigureSheetId(e.id)?0:85}}function Fv(e){return""===e?NaN:Number(e)}_v.getters=["isChartDefined","getChartDefinition","getChartType","getChartIds","getChart","getContextCreationChart"];class Dv extends Mv{constructor(){super(...arguments),this.cfRules={}}loopThroughRangesOfSheet(e,t){for(const i of this.cfRules[e])for(const o of i.ranges){const n=t(o);switch(n.changeType){case"REMOVE":let t=i.ranges.slice();t.splice(i.ranges.indexOf(o),1),t.length>=1?this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",t):this.removeConditionalFormatting(i.id,e);break;case"RESIZE":case"MOVE":case"CHANGE":this.history.update("cfRules",e,this.cfRules[e].indexOf(i),"ranges",i.ranges.indexOf(o),n.range)}}}adaptRanges(e,t){if(t)this.loopThroughRangesOfSheet(t,e);else for(const t of Object.keys(this.cfRules))this.loopThroughRangesOfSheet(t,e)}allowDispatch(e){switch(e.type){case"ADD_CONDITIONAL_FORMAT":return this.checkValidations(e,this.checkCFRule,this.checkEmptyRange);case"MOVE_CONDITIONAL_FORMAT":return this.checkValidReordering(e.cfId,e.direction,e.sheetId)}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.cfRules[e.sheetId]=[];break;case"DUPLICATE_SHEET":this.history.update("cfRules",e.sheetIdTo,[]);for(const t of this.getConditionalFormats(e.sheetId))this.addConditionalFormatting(t,e.sheetIdTo);break;case"DELETE_SHEET":const t=Object.assign({},this.cfRules);delete t[e.sheetId],this.history.update("cfRules",t);break;case"ADD_CONDITIONAL_FORMAT":const i={...e.cf,ranges:e.ranges.map((t=>this.getters.getRangeString(this.getters.getRangeFromRangeData(t),e.sheetId)))};this.addConditionalFormatting(i,e.sheetId);break;case"REMOVE_CONDITIONAL_FORMAT":this.removeConditionalFormatting(e.id,e.sheetId);break;case"MOVE_CONDITIONAL_FORMAT":this.reorderConditionalFormatting(e.cfId,e.direction,e.sheetId)}}import(e){for(let t of e.sheets)this.cfRules[t.id]=t.conditionalFormats.map((e=>this.mapToConditionalFormatInternal(t.id,e)))}export(e){if(e.sheets)for(let t of e.sheets)this.cfRules[t.id]&&(t.conditionalFormats=this.cfRules[t.id].map((e=>this.mapToConditionalFormat(t.id,e))))}exportForExcel(e){this.export(e)}getConditionalFormats(e){var t;return(null===(t=this.cfRules[e])||void 0===t?void 0:t.map((t=>this.mapToConditionalFormat(e,t))))||[]}getRulesSelection(e,t){const i=new Set;return t.forEach((t=>{this.getRulesByZone(e,t).forEach((e=>{i.add(e)}))})),Array.from(i)}getRulesByZone(e,t){const i=new Set;for(let o=t.top;o<=t.bottom;o++)for(let n=t.left;n<=t.right;n++){this.getRulesByCell(e,n,o).forEach((e=>{i.add(e.id)}))}return i}getRulesByCell(e,t,i){const o=[];for(let n of this.cfRules[e])for(let e of n.ranges)Ki(t,i,e.zone)&&o.push(n);return new Set(o.map((t=>this.mapToConditionalFormat(e,t))))}mapToConditionalFormat(e,t){return{...t,ranges:t.ranges.map((t=>this.getters.getRangeString(t,e)))}}mapToConditionalFormatInternal(e,t){const i={...t,ranges:t.ranges.map((t=>this.getters.getRangeFromSheetXC(e,t)))};return i}addConditionalFormatting(e,t){const i=this.cfRules[t].slice(),o=i.findIndex((t=>t.id===e.id)),n=this.mapToConditionalFormatInternal(t,e);o>-1?i.splice(o,1,n):i.push(n),this.history.update("cfRules",t,i)}checkValidReordering(e,t,i){if(!this.cfRules[i])return 27;const o=this.cfRules[i].findIndex((t=>t.id===e));if(-1===o)return 71;const n="up"===t?o-1:o+1;return n<0||n>=this.cfRules[i].length?71:0}checkEmptyRange(e){return e.ranges.length?0:24}checkCFRule(e){const t=e.cf.rule;switch(t.type){case"CellIsRule":return this.checkValidations(t,this.checkOperatorArgsNumber(2,["Between","NotBetween"]),this.checkOperatorArgsNumber(1,["BeginsWith","ContainsText","EndsWith","GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual","NotContains"]),this.checkOperatorArgsNumber(0,["IsEmpty","IsNotEmpty"]));case"ColorScaleRule":return this.checkValidations(t,this.chainValidations(this.checkThresholds(this.checkFormulaCompilation)),this.chainValidations(this.checkThresholds(this.checkNaN),this.batchValidations(this.checkMinBiggerThanMax,this.checkMinBiggerThanMid,this.checkMidBiggerThanMax)));case"IconSetRule":return this.checkValidations(t,this.chainValidations(this.checkInflectionPoints(this.checkNaN),this.checkLowerBiggerThanUpper),this.chainValidations(this.checkInflectionPoints(this.checkFormulaCompilation)))}return 0}checkOperatorArgsNumber(e,t){if(e>2)throw new Error("Checking more than 2 arguments is currently not supported. Add the appropriate CommandResult if you want to.");return i=>{if(t.includes(i.operator)){const t=[],o=e=>void 0===e||""===e;return e>=1&&o(i.values[0])&&t.push(51),e>=2&&o(i.values[1])&&t.push(52),t.length?t:0}return 0}}checkNaN(e,t){if(["number","percentage","percentile"].includes(e.type)&&(""===e.value||isNaN(e.value)))switch(t){case"min":return 53;case"max":return 55;case"mid":return 54;case"upperInflectionPoint":return 56;case"lowerInflectionPoint":return 57}return 0}checkFormulaCompilation(e,t){if("formula"!==e.type)return 0;try{df(e.value||"")}catch(e){switch(t){case"min":return 58;case"max":return 60;case"mid":return 59;case"upperInflectionPoint":return 61;case"lowerInflectionPoint":return 62}}return 0}checkThresholds(e){return this.batchValidations((t=>e(t.minimum,"min")),(t=>e(t.maximum,"max")),(t=>t.midpoint?e(t.midpoint,"mid"):0))}checkInflectionPoints(e){return this.batchValidations((t=>e(t.lowerInflectionPoint,"lowerInflectionPoint")),(t=>e(t.upperInflectionPoint,"upperInflectionPoint")))}checkLowerBiggerThanUpper(e){const t=e.lowerInflectionPoint.value,i=e.upperInflectionPoint.value;return["number","percentage","percentile"].includes(e.lowerInflectionPoint.type)&&e.lowerInflectionPoint.type===e.upperInflectionPoint.type&&Number(t)>Number(i)?48:0}checkMinBiggerThanMax(e){const t=e.minimum.value,i=e.maximum.value;return["number","percentage","percentile"].includes(e.minimum.type)&&e.minimum.type===e.maximum.type&&Fv(t)>=Fv(i)?47:0}checkMidBiggerThanMax(e){var t;const i=null===(t=e.midpoint)||void 0===t?void 0:t.value,o=e.maximum.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.midpoint.type===e.maximum.type&&Fv(i)>=Fv(o)?49:0}checkMinBiggerThanMid(e){var t;const i=e.minimum.value,o=null===(t=e.midpoint)||void 0===t?void 0:t.value;return e.midpoint&&["number","percentage","percentile"].includes(e.midpoint.type)&&e.minimum.type===e.midpoint.type&&Fv(i)>=Fv(o)?50:0}removeConditionalFormatting(e,t){const i=this.cfRules[t].findIndex((t=>t.id===e));if(-1!==i){const e=this.cfRules[t].slice();e.splice(i,1),this.history.update("cfRules",t,e)}}reorderConditionalFormatting(e,t,i){const o=this.cfRules[i].findIndex((t=>t.id===e)),n="up"===t?o-1:o+1;if(!(n<0||n>=this.cfRules[i].length)&&-1!==o&&-1!==n){const e=[...this.cfRules[i]],t=e[o];e[o]=e[n],e[n]=t,this.history.update("cfRules",i,e)}}}Dv.getters=["getConditionalFormats","getRulesSelection","getRulesByCell"];class kv extends Mv{constructor(){super(...arguments),this.figures={}}allowDispatch(e){switch(e.type){case"CREATE_FIGURE":return this.checkFigureDuplicate(e.figure.id);case"UPDATE_FIGURE":case"DELETE_FIGURE":return this.checkFigureExists(e.sheetId,e.id);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":this.figures[e.sheetId]={};break;case"DELETE_SHEET":this.deleteSheet(e.sheetId);break;case"CREATE_FIGURE":this.addFigure(e.figure,e.sheetId);break;case"UPDATE_FIGURE":const{type:t,sheetId:i,...o}=e,n=o;this.updateFigure(i,n);break;case"DELETE_FIGURE":this.removeFigure(e.id,e.sheetId)}}updateFigure(e,t){if("id"in t)for(const[i,o]of Object.entries(t))switch(i){case"x":case"y":void 0!==o&&this.history.update("figures",e,t.id,i,Math.max(o,0));break;case"width":case"height":void 0!==o&&this.history.update("figures",e,t.id,i,o)}}addFigure(e,t){this.history.update("figures",t,e.id,e)}deleteSheet(e){this.history.update("figures",e,void 0)}removeFigure(e,t){this.history.update("figures",t,e,void 0)}checkFigureExists(e,t){var i;return void 0===(null===(i=this.figures[e])||void 0===i?void 0:i[t])?70:0}checkFigureDuplicate(e){return Object.values(this.figures).find((t=>null==t?void 0:t[e]))?82:0}getFigures(e){return Object.values(this.figures[e]||{}).filter(ot)}getFigure(e,t){var i;return null===(i=this.figures[e])||void 0===i?void 0:i[t]}getFigureSheetId(e){return Object.keys(this.figures).find((t=>{var i;return void 0!==(null===(i=this.figures[t])||void 0===i?void 0:i[e])}))}import(e){for(let t of e.sheets){const e={};t.figures.forEach((t=>{e[t.id]=t})),this.figures[t.id]=e}}export(e){for(const t of e.sheets)for(const e of this.getFigures(t.id)){const i=void 0;t.figures.push({...e,data:i})}}exportForExcel(e){this.export(e)}}kv.getters=["getFigures","getFigure","getFigureSheetId"];class Lv{constructor(e){this.filters=[],this.zone=e;const t=new Ui;this.id=t.uuidv4();for(const i of $e(e.left,e.right+1)){const e={...this.zone,left:i,right:i};this.filters.push(new Pv(t.uuidv4(),e))}}get contentZone(){if(this.zone.bottom!==this.zone.top)return{...this.zone,top:this.zone.top+1}}getFilterId(e){var t;return null===(t=this.filters.find((t=>t.col===e)))||void 0===t?void 0:t.id}clone(){return new Lv(this.zone)}}class Pv{constructor(e,t){if(t.left!==t.right)throw new Error("Can only define a filter on a single column");this.id=e,this.zoneWithHeaders=t}get col(){return this.zoneWithHeaders.left}get filteredZone(){const e=this.zoneWithHeaders;if(e.bottom!==e.top)return{...e,top:e.top+1}}}class Uv extends Mv{constructor(){super(...arguments),this.tables={}}allowDispatch(e){switch(e.type){case"CREATE_FILTER_TABLE":if(!ho(...e.target))return 81;const t=Zi(...e.target),i=()=>this.getFilterTables(e.sheetId).some((e=>Yi(e.zone,t)))?78:0,o=()=>{const i=this.getters.getMergesInZone(e.sheetId,t);for(let e of i)if(Yi(t,e))return 80;return 0};return this.checkValidations(e,i,o);case"ADD_MERGE":for(let t of e.target)for(let i of this.getFilterTables(e.sheetId))if(Yi(i.zone,t))return 80}return 0}handle(e){switch(e.type){case"CREATE_SHEET":this.history.update("tables",e.sheetId,{});break;case"DELETE_SHEET":const t={...this.tables};delete t[e.sheetId],this.history.update("tables",t);break;case"DUPLICATE_SHEET":const i={};for(const t of Object.values(this.tables[e.sheetId]||{}))if(t){const e=Fe(t);i[e.id]=e}this.history.update("tables",e.sheetIdTo,i);break;case"ADD_COLUMNS_ROWS":this.onAddColumnsRows(e);break;case"REMOVE_COLUMNS_ROWS":this.onDeleteColumnsRows(e);break;case"CREATE_FILTER_TABLE":{const t=Zi(...e.target),i=this.createFilterTable(t);this.history.update("tables",e.sheetId,i.id,i);break}case"REMOVE_FILTER_TABLE":{const t={};for(const i of this.getFilterTables(e.sheetId))e.target.every((e=>!ji(e,i.zone)))&&(t[i.id]=i);this.history.update("tables",e.sheetId,t);break}case"UPDATE_CELL":{const t=e.sheetId;for(let i of this.getFilterTables(t))this.canUpdateCellCmdExtendTable(e,i)&&this.extendTableDown(t,i);break}}}getFilters(e){return this.getFilterTables(e).map((e=>e.filters)).flat()}getFilterTables(e){return this.tables[e]?Object.values(this.tables[e]).filter(ot):[]}getFilter(e){var t;return null===(t=this.getFilterTable(e))||void 0===t?void 0:t.filters.find((t=>t.col===e.col))}getFilterId(e){var t;return null===(t=this.getFilter(e))||void 0===t?void 0:t.id}getFilterTable({sheetId:e,col:t,row:i}){return this.getFilterTables(e).find((e=>Ki(t,i,e.zone)))}getFilterTablesInZone(e,t){return this.getFilterTables(e).filter((e=>Qi(e.zone,t)))}doesZonesContainFilter(e,t){for(const i of t)for(const t of this.getFilterTables(e))if(ji(i,t.zone))return!0;return!1}onAddColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=$i(t.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),o=[];for(const i of t.filters){const t=$i(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);o.push(new Pv(i.id,t))}if(o.length<to(i).numberOfCols){for(let e=i.left;e<=i.right;e++)o.find((t=>t.col===e))||o.push(new Pv(this.uuidGenerator.uuidv4(),{...i,left:e,right:e}));o.sort(((e,t)=>e.col-t.col))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",o)}}onDeleteColumnsRows(e){for(const t of this.getFilterTables(e.sheetId)){const i=qi(t.zone,"COL"===e.dimension?"left":"top",e.elements);if(i){if(Hi(i)!==Hi(t.zone)){const o=[];for(const i of t.filters){const t=qi(i.zoneWithHeaders,"COL"===e.dimension?"left":"top",e.elements);t&&o.push(new Pv(i.id,t))}this.history.update("tables",e.sheetId,t.id,"zone",i),this.history.update("tables",e.sheetId,t.id,"filters",o)}}else{const i={...this.tables[e.sheetId]};delete i[t.id],this.history.update("tables",e.sheetId,i)}}}createFilterTable(e){return new Lv(e)}extendTableDown(e,t){const i={...t.zone,bottom:t.zone.bottom+1};this.history.update("tables",e,t.id,"zone",i);for(let i=0;i<t.filters.length;i++){const o=t.filters[i],n={...o.zoneWithHeaders,bottom:o.zoneWithHeaders.bottom+1};this.history.update("tables",e,t.id,"filters",i,"zoneWithHeaders",n)}}canUpdateCellCmdExtendTable({content:e,sheetId:t,col:i,row:o},n){var s;if(!e)return;const r=n.zone;if(!(r.bottom+1===o&&i>=r.left&&i<=r.right))return!1;for(const e of $e(r.left,r.right+1)){const i={sheetId:t,col:e,row:o};if(null===(s=this.getters.getCell(i))||void 0===s?void 0:s.content)return!1;if(this.getters.getFilter(i))return!1;if(this.getters.isInMerge(i))return!1}return!0}import(e){for(const t of e.sheets)for(const e of t.filterTables||[]){const i=this.createFilterTable(zi(e.range));this.history.update("tables",t.id,i.id,i)}}export(e){for(const t of e.sheets)for(const e of this.getFilterTables(t.id))t.filterTables.push({range:Hi(e.zone)})}exportForExcel(e){this.export(e)}}Uv.getters=["doesZonesContainFilter","getFilter","getFilters","getFilterTable","getFilterTables","getFilterTablesInZone","getFilterId"];class Vv extends Mv{constructor(){super(...arguments),this.sizes={}}handle(e){var t,i;switch(e.type){case"CREATE_SHEET":{const t=this.computeSheetSizes(e.sheetId),i={COL:t.COL.map((e=>({manualSize:void 0,computedSize:at(e)}))),ROW:t.ROW.map((e=>({manualSize:void 0,computedSize:at(e)})))};this.history.update("sizes",e.sheetId,i);break}case"DUPLICATE_SHEET":for(const t of this.sizes[e.sheetId].ROW)t.computedSize();for(const t of this.sizes[e.sheetId].COL)t.computedSize();this.history.update("sizes",e.sheetIdTo,Fe(this.sizes[e.sheetId]));break;case"DELETE_SHEET":const o={...this.sizes};delete o[e.sheetId],this.history.update("sizes",o);break;case"REMOVE_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);const i=Math.min(...e.elements);t=t.map(((t,o)=>"ROW"===e.dimension&&o>=i?{manualSize:t.manualSize,computedSize:at((()=>this.getRowTallestCellSize(e.sheetId,o)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{let t=[...this.sizes[e.sheetId][e.dimension]];const i=ct(e.position,e.base),o=t[e.base],n=$e(0,e.quantity).map((()=>({manualSize:o.manualSize,computedSize:at(o.computedSize())})));t.splice(i,0,...n),t=t.map(((t,i)=>"ROW"===e.dimension&&i>e.base+e.quantity?{manualSize:t.manualSize,computedSize:at((()=>this.getRowTallestCellSize(e.sheetId,i)))}:t)),this.history.update("sizes",e.sheetId,e.dimension,t);break}case"RESIZE_COLUMNS_ROWS":for(let t of e.elements)if("ROW"===e.dimension){const i=this.getRowTallestCellSize(e.sheetId,t);this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:at(i)})}else this.history.update("sizes",e.sheetId,e.dimension,t,{manualSize:e.size||void 0,computedSize:at(e.size||F)});break;case"UPDATE_CELL":const n=null===(i=null===(t=this.sizes[e.sheetId])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[e.row];if(n&&!n.manualSize){const{sheetId:t,row:i}=e;this.history.update("sizes",t,"ROW",i,"computedSize",at((()=>this.getRowTallestCellSize(t,i))))}break;case"ADD_MERGE":case"REMOVE_MERGE":for(let t of e.target)for(let i of $e(t.top,t.bottom+1)){const t=this.getRowTallestCellSize(e.sheetId,i);t!==this.getRowSize(e.sheetId,i)&&this.history.update("sizes",e.sheetId,"ROW",i,"computedSize",at(t))}}}getColSize(e,t){return this.getHeaderSize(e,"COL",t)}getRowSize(e,t){return this.getHeaderSize(e,"ROW",t)}getHeaderSize(e,t,i){var o,n,s,r;return Math.round((null===(n=null===(o=this.sizes[e])||void 0===o?void 0:o[t][i])||void 0===n?void 0:n.manualSize)||(null===(r=null===(s=this.sizes[e])||void 0===s?void 0:s[t][i])||void 0===r?void 0:r.computedSize())||this.getDefaultHeaderSize(t))}computeSheetSizes(e){var t,i;const o={COL:[],ROW:[]};for(let t of $e(0,this.getters.getNumberCols(e)))o.COL.push(this.getHeaderSize(e,"COL",t));for(let n of $e(0,this.getters.getNumberRows(e))){let s=null===(i=null===(t=this.sizes[e])||void 0===t?void 0:t.ROW)||void 0===i?void 0:i[n].manualSize;if(!s){s=this.getRowTallestCellSize(e,n)}o.ROW.push(s)}return o}getDefaultHeaderSize(e){return"COL"===e?F:D}getCellHeight(e){const t=this.getters.getMerge(e);if(t&&t.bottom!==t.top)return D;return function(e){return e&&e.content?Pe(He(e.style),e.isFormula?1:e.content.split(he).length)+2*z:D}(this.getters.getCell(e))}getRowTallestCellSize(e,t){const i=this.getters.getRowCells(e,t);let o=0;for(let e=0;e<i.length;e++){const t=this.getters.getCellById(i[e]);if(!t)continue;const n=this.getters.getCellPosition(t.id),s=this.getCellHeight(n);s>o&&s>D&&(o=s)}return o<=D?D:o}import(e){for(let t of e.sheets){const e={COL:[],ROW:[]};for(let[i,o]of Object.entries(t.rows))o.size&&(e.ROW[i]=o.size);for(let[i,o]of Object.entries(t.cols))o.size&&(e.COL[i]=o.size);const i=this.computeSheetSizes(t.id);this.sizes[t.id]={COL:i.COL.map(((t,i)=>({manualSize:e.COL[i],computedSize:at(t)}))),ROW:i.ROW.map(((t,i)=>({manualSize:e.ROW[i],computedSize:at(t)})))}}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){var i,o;for(let n of e.sheets){void 0===n.rows&&(n.rows={});for(let e of $e(0,this.getters.getNumberRows(n.id)))(t||(null===(i=this.sizes[n.id].ROW[e])||void 0===i?void 0:i.manualSize))&&(n.rows[e]={...n.rows[e],size:this.getRowSize(n.id,e)});void 0===n.cols&&(n.cols={});for(let e of $e(0,this.getters.getNumberCols(n.id)))(t||(null===(o=this.sizes[n.id].COL[e])||void 0===o?void 0:o.manualSize))&&(n.cols[e]={...n.cols[e],size:this.getColSize(n.id,e)})}}}Vv.getters=["getRowSize","getColSize"];class zv extends Mv{constructor(){super(...arguments),this.hiddenHeaders={}}allowDispatch(e){switch(e.type){case"HIDE_COLUMNS_ROWS":{if(!this.getters.tryGetSheet(e.sheetId))return 27;const t="COL"===e.dimension?this.getHiddenColsGroups(e.sheetId):this.getHiddenRowsGroups(e.sheetId),i="COL"===e.dimension?this.getters.getNumberCols(e.sheetId):this.getters.getNumberRows(e.sheetId);return new Set((t||[]).flat().concat(e.elements)).size>=i?66:Math.min(...e.elements)<0||Math.max(...e.elements)>i?86:0}case"REMOVE_COLUMNS_ROWS":return this.getters.tryGetSheet(e.sheetId)?this.checkElementsIncludeAllVisibleHeaders(e.sheetId,e.dimension,e.elements)?8:0:27}return 0}handle(e){switch(e.type){case"CREATE_SHEET":const t={COL:Array(this.getters.getNumberCols(e.sheetId)).fill(!1),ROW:Array(this.getters.getNumberRows(e.sheetId)).fill(!1)};this.history.update("hiddenHeaders",e.sheetId,t);break;case"DUPLICATE_SHEET":this.history.update("hiddenHeaders",e.sheetIdTo,Fe(this.hiddenHeaders[e.sheetId]));break;case"DELETE_SHEET":this.history.update("hiddenHeaders",e.sheetId,void 0);break;case"REMOVE_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]];for(let i of[...e.elements].sort(((e,t)=>t-e)))t.splice(i,1);this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"ADD_COLUMNS_ROWS":{const t=[...this.hiddenHeaders[e.sheetId][e.dimension]],i=ct(e.position,e.base);t.splice(i,0,...Array(e.quantity).fill(!1)),this.history.update("hiddenHeaders",e.sheetId,e.dimension,t);break}case"HIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!0);break;case"UNHIDE_COLUMNS_ROWS":for(let t of e.elements)this.history.update("hiddenHeaders",e.sheetId,e.dimension,t,!1)}}checkElementsIncludeAllVisibleHeaders(e,t,i){return dt(i,this.getAllVisibleHeaders(e,t))}isRowHiddenByUser(e,t){return this.hiddenHeaders[e].ROW[t]}isColHiddenByUser(e,t){return this.hiddenHeaders[e].COL[t]}getHiddenColsGroups(e){const t=[[]],i=this.hiddenHeaders[e].COL;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getHiddenRowsGroups(e){const t=[[]],i=this.hiddenHeaders[e].ROW;for(let e=0;e<i.length;e++){i[e]?t[t.length-1].push(e):0!==t[t.length-1].length&&t.push([])}return 0===t[t.length-1].length&&t.pop(),t}getAllVisibleHeaders(e,t){return $e(0,this.hiddenHeaders[e][t].length).filter((i=>!this.hiddenHeaders[e][t][i]))}import(e){var t,i;for(let o of e.sheets){this.hiddenHeaders[o.id]={COL:[],ROW:[]};for(let e=0;e<o.rowNumber;e++)this.hiddenHeaders[o.id].ROW[e]=Boolean(null===(t=o.rows[e])||void 0===t?void 0:t.isHidden);for(let e=0;e<o.colNumber;e++)this.hiddenHeaders[o.id].COL[e]=Boolean(null===(i=o.cols[e])||void 0===i?void 0:i.isHidden)}}exportForExcel(e){this.exportData(e,!0)}export(e){this.exportData(e)}exportData(e,t=!1){for(let i of e.sheets){void 0===i.rows&&(i.rows={});for(let e=0;e<this.getters.getNumberRows(i.id);e++)(t||this.hiddenHeaders[i.id].ROW[e])&&(void 0===i.rows[e]&&(i.rows[e]={}),i.rows[e].isHidden=this.hiddenHeaders[i.id].ROW[e]);void 0===i.cols&&(i.cols={});for(let e=0;e<this.getters.getNumberCols(i.id);e++)(t||this.hiddenHeaders[i.id].COL[e])&&(void 0===i.cols[e]&&(i.cols[e]={}),i.cols[e].isHidden=this.hiddenHeaders[i.id].COL[e])}}}zv.getters=["checkElementsIncludeAllVisibleHeaders","getHiddenColsGroups","getHiddenRowsGroups","isRowHiddenByUser","isColHiddenByUser"];class Bv extends Mv{constructor(e){super(e),this.images={},this.syncedImages=new Set,this.fileStore=e.external.fileStore}allowDispatch(e){return"CREATE_IMAGE"===e.type&&this.getters.getFigure(e.sheetId,e.figureId)?28:0}handle(e){switch(e.type){case"CREATE_IMAGE":this.addFigure(e.figureId,e.sheetId,e.position,e.size),this.history.update("images",e.sheetId,e.figureId,e.definition),this.syncedImages.add(e.definition.path);break;case"DUPLICATE_SHEET":{const t=this.getters.getFigures(e.sheetId);for(const i of t)if("image"===i.tag){const t=i.id.split(ee).pop(),o=`${e.sheetIdTo}${ee}${t}`,n=this.getImage(i.id);if(n){const t={width:i.width,height:i.height};this.dispatch("CREATE_IMAGE",{sheetId:e.sheetIdTo,figureId:o,position:{x:i.x,y:i.y},size:t,definition:Fe(n)})}}break}case"DELETE_FIGURE":this.history.update("images",e.sheetId,e.id,void 0);break;case"DELETE_SHEET":this.history.update("images",e.sheetId,void 0)}}garbageCollectExternalResources(){var e;const t=new Set(this.getAllImages().map((e=>e.path)));for(const i of this.syncedImages)t.has(i)||null===(e=this.fileStore)||void 0===e||e.delete(i)}getImage(e){for(const t of Object.values(this.images))if(t&&t[e])return t[e];throw new Error(`There is no image with the given figureId: ${e}`)}getImagePath(e){return this.getImage(e).path}getImageSize(e){return this.getImage(e).size}addFigure(e,t,i,o){const n={id:e,x:i.x,y:i.y,width:o.width,height:o.height,tag:"image"};this.dispatch("CREATE_FIGURE",{sheetId:t,figure:n})}import(e){for(const t of e.sheets){const e=(t.figures||[]).filter((e=>"image"===e.tag));for(const i of e)this.history.update("images",t.id,i.id,i.data),this.syncedImages.add(i.data.path)}}export(e){var t;for(const i of e.sheets){const e=i.figures.filter((e=>"image"===e.tag));for(const o of e)o.data=null===(t=this.images[i.id])||void 0===t?void 0:t[o.id]}}exportForExcel(e){for(const t of e.sheets){const e=this.getters.getFigures(t.id),i=[];for(const t of e)if("image"===(null==t?void 0:t.tag)){const e=this.getImage(t.id);e&&i.push({...t,data:Fe(e)})}t.images=i}}getAllImages(){const e=[];for(const t in this.images)e.push(...Object.values(this.images[t]||{}).filter(ot));return e}}Bv.getters=["getImage","getImagePath","getImageSize"];class Hv extends Mv{constructor(){super(...arguments),this.nextId=1,this.merges={},this.mergeCellMap={}}allowDispatch(e){const t="force"in e&&!!e.force;switch(e.type){case"ADD_MERGE":return t?this.checkValidations(e,this.checkFrozenPanes):this.checkValidations(e,this.checkDestructiveMerge,this.checkOverlap,this.checkFrozenPanes);case"UPDATE_CELL":return this.checkMergedContentUpdate(e);case"REMOVE_MERGE":return this.checkMergeExists(e);default:return 0}}handle(e){switch(e.type){case"CREATE_SHEET":case"DELETE_SHEET":this.history.update("merges",e.sheetId,{}),this.history.update("mergeCellMap",e.sheetId,{});break;case"DUPLICATE_SHEET":const t=this.merges[e.sheetId];if(!t)break;for(const i of Object.values(t).filter(ot))this.addMerge(e.sheetIdTo,i.zone);break;case"ADD_MERGE":for(const t of e.target)this.addMerge(e.sheetId,t);break;case"REMOVE_MERGE":for(const t of e.target)this.removeMerge(e.sheetId,t)}}adaptRanges(e,t){const i=t?[t]:Object.keys(this.merges);for(const t of i)this.applyRangeChangeOnSheet(t,e)}getMerges(e){return Object.keys(this.merges[e]||{}).map((t=>this.getMergeById(e,parseInt(t,10)))).filter(ot)}getMerge({sheetId:e,col:t,row:i}){var o;const n=this.mergeCellMap[e],s=n?t in n&&(null===(o=n[t])||void 0===o?void 0:o[i]):void 0;return s?this.getMergeById(e,s):void 0}getMergesInZone(e,t){var i;const o=this.mergeCellMap[e];if(!o)return[];const n=new Set;for(const{col:e,row:s}of oo(t)){const t=null===(i=o[e])||void 0===i?void 0:i[s];t&&n.add(t)}return Array.from(n).map((t=>this.getMergeById(e,t))).filter(ot)}doesIntersectMerge(e,t){return oo(t).some((({col:t,row:i})=>void 0!==this.getMerge({sheetId:e,col:t,row:i})))}doesColumnsHaveCommonMerges(e,t,i){const o=this.getters.getSheet(e);for(let n=0;n<this.getters.getNumberRows(e);n++)if(this.isInSameMerge(o.id,t,n,i,n))return!0;return!1}doesRowsHaveCommonMerges(e,t,i){const o=this.getters.getSheet(e);for(let n=0;n<=this.getters.getNumberCols(e);n++)if(this.isInSameMerge(o.id,n,t,n,i))return!0;return!1}expandZone(e,t){let{left:i,right:o,top:n,bottom:s}=t,r={left:i,right:o,top:n,bottom:s};for(let t in this.merges[e]){const i=this.getMergeById(e,parseInt(t));i&&Yi(i,r)&&(r=Zi(i,r))}return Xi(r,t)?r:this.expandZone(e,r)}isInSameMerge(e,t,i,o,n){const s=this.getMerge({sheetId:e,col:t,row:i}),r=this.getMerge({sheetId:e,col:o,row:n});return!(!s||!r)&&Xi(s,r)}isInMerge({sheetId:e,col:t,row:i}){var o;const n=this.mergeCellMap[e];return!!n&&(t in n&&Boolean(null===(o=n[t])||void 0===o?void 0:o[i]))}getMainCellPosition(e){if(!this.isInMerge(e))return e;const t=this.getMerge(e).topLeft;return{sheetId:e.sheetId,col:t.col,row:t.row}}getBottomLeftCell(e){if(!this.isInMerge(e))return e;const{bottom:t,left:i}=this.getMerge(e);return{sheetId:e.sheetId,col:i,row:t}}isMergeHidden(e,t){const i=this.getters.getHiddenColsGroups(e),o=this.getters.getHiddenRowsGroups(e);for(let e of i)if(t.left>=e[0]&&t.right<=e[e.length-1])return!0;for(let e of o)if(t.top>=e[0]&&t.bottom<=e[e.length-1])return!0;return!1}isSingleCellOrMerge(e,t){const i=this.getMerge({sheetId:e,col:t.left,row:t.top});if(i)return Xi(t,i);const{numberOfCols:o,numberOfRows:n}=to(t);return 1===o&&1===n}isMergeDestructive(e,t){let{left:i,right:o,top:n,bottom:s}=t;o=Le(o,0,this.getters.getNumberCols(e)-1),s=Le(s,0,this.getters.getNumberRows(e)-1);for(let t=n;t<=s;t++)for(let s=i;s<=o;s++)if(s!==i||t!==n){const i=this.getters.getCell({sheetId:e,col:s,row:t});if(i&&""!==i.content)return!0}return!1}getMergeById(e,t){var i;const o=null===(i=this.merges[e])||void 0===i?void 0:i[t];return void 0!==o?Wv(t,o):void 0}checkDestructiveMerge({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;return t.some((t=>this.isMergeDestructive(e,t)))?3:0}checkOverlap({target:e}){for(const t of e)for(const i of e)if(t!==i&&Yi(t,i))return 65;return 0}checkFrozenPanes({sheetId:e,target:t}){if(!this.getters.tryGetSheet(e))return 0;const{xSplit:i,ySplit:o}=this.getters.getPaneDivisions(e);for(const e of t)if(e.left<i&&e.right>=i||e.top<o&&e.bottom>=o)return 75;return 0}checkMergedContentUpdate(e){const{col:t,row:i,content:o}=e;if(void 0===o)return 0;const{col:n,row:s}=this.getMainCellPosition(e);return n===t&&s===i?0:4}checkMergeExists(e){const{sheetId:t,target:i}=e;for(const e of i){const{left:i,top:o}=e,n=this.getMerge({sheetId:t,col:i,row:o});if(void 0===n||!Xi(e,n))return 5}return 0}addMerge(e,t){let{left:i,right:o,top:n,bottom:s}=t;o=Le(o,0,this.getters.getNumberCols(e)-1),s=Le(s,0,this.getters.getNumberRows(e)-1);if(Gt(i,n)===Gt(o,s))return;const r=this.getters.getCell({sheetId:e,col:i,row:n});let a=this.nextId++;this.history.update("merges",e,a,this.getters.getRangeFromSheetXC(e,Hi({left:i,top:n,right:o,bottom:s})));let l=new Set;for(let t=n;t<=s;t++)for(let s=i;s<=o;s++){s===i&&t===n||this.dispatch("UPDATE_CELL",{sheetId:e,col:s,row:t,style:r?r.style:null,content:""});const o=this.getMerge({sheetId:e,col:s,row:t});o&&l.add(o.id),this.history.update("mergeCellMap",e,s,t,a)}for(let t of l){const{top:i,bottom:o,left:n,right:s}=this.getMergeById(e,t);for(let t=i;t<=o;t++)for(let i=n;i<=s;i++){const o={sheetId:e,col:i,row:t},n=this.getMerge(o);n&&n.id===a||(this.history.update("mergeCellMap",e,i,t,void 0),this.dispatch("CLEAR_CELL",o))}this.history.update("merges",e,t,void 0)}}removeMerge(e,t){const{left:i,top:o,bottom:n,right:s}=t,r=this.getMerge({sheetId:e,col:i,row:o});if(void 0!==r&&Xi(t,r)){this.history.update("merges",e,r.id,void 0);for(let t=o;t<=n;t++)for(let o=i;o<=s;o++)this.history.update("mergeCellMap",e,o,t,void 0)}}applyRangeChangeOnSheet(e,t){const i=Object.entries(this.merges[e]||{});for(const[o,n]of i)if(n){const i=n.zone,s=t(n);switch(s.changeType){case"NONE":break;case"REMOVE":this.removeMerge(e,i);break;default:const{numberOfCols:t,numberOfRows:n}=to(s.range.zone);1===t&&1===n?this.removeMerge(e,i):this.history.update("merges",e,parseInt(o,10),s.range)}}this.history.update("mergeCellMap",e,{});for(const t of this.getMerges(e))for(const{col:i,row:o}of oo(t))this.history.update("mergeCellMap",e,i,o,t.id)}import(e){const t=e.sheets||[];for(let e of t)this.history.update("merges",e.id,{}),this.history.update("mergeCellMap",e.id,{}),e.merges&&this.importMerges(e.id,e.merges)}importMerges(e,t){for(let i of t)this.addMerge(e,zi(i))}export(e){for(let t of e.sheets){const e=this.merges[t.id];e&&t.merges.push(...$v(e))}}exportForExcel(e){this.export(e)}}function $v(e){return Object.entries(e).map((([e,t])=>t?Wv(parseInt(e,10),t):void 0)).filter(ot).map((e=>Gt(e.left,e.top)+":"+Gt(e.right,e.bottom)))}function Wv(e,t){return{...t.zone,topLeft:{col:t.zone.left,row:t.zone.top},id:e}}Hv.getters=["isInMerge","isInSameMerge","isMergeHidden","getMainCellPosition","getBottomLeftCell","expandZone","doesIntersectMerge","doesColumnsHaveCommonMerges","doesRowsHaveCommonMerges","getMerges","getMerge","getMergesInZone","isSingleCellOrMerge"];class Gv{constructor(e){this.providers=[],this.getters=e}allowDispatch(e){return"MOVE_RANGES"===e.type?1===e.target.length?0:26:0}beforeHandle(e){}handle(e){switch(e.type){case"REMOVE_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",o="COL"===e.dimension?"columns":"rows";const n=[...e.elements];n.sort(((e,t)=>t-e));const s=We(n);this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};let r=n,a="NONE";for(let e of s){const s=Math.min(...e),l=Math.max(...e);if(n.zone[t]<=s&&s<=n.zone[i]){const e=Math.min(n.zone[i],l)-s+1;a="RESIZE",r=this.createAdaptedRange(r,o,a,-e)}else if(n.zone[t]>=s&&n.zone[i]<=l)a="REMOVE",r=n.clone({...this.getInvalidRange()});else if(n.zone[t]<=l&&n.zone[i]>=l){const e=l-n.zone[t]+1;a="RESIZE",r=this.createAdaptedRange(r,o,a,-e),r=this.createAdaptedRange(r,o,"MOVE",-(n.zone[t]-s))}else s<n.zone[t]&&(a="MOVE",r=this.createAdaptedRange(r,o,a,-(l-s+1)))}return"NONE"!==a?{changeType:a,range:r}:{changeType:"NONE"}}),e.sheetId);break}case"ADD_COLUMNS_ROWS":{let t="COL"===e.dimension?"left":"top",i="COL"===e.dimension?"right":"bottom",o="COL"===e.dimension?"columns":"rows";this.executeOnAllRanges((n=>{if(n.sheetId!==e.sheetId)return{changeType:"NONE"};if("after"===e.position){if(n.zone[t]<=e.base&&e.base<n.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(n,o,"RESIZE",e.quantity)};if(e.base<n.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(n,o,"MOVE",e.quantity)}}else{if(n.zone[t]<e.base&&e.base<=n.zone[i])return{changeType:"RESIZE",range:this.createAdaptedRange(n,o,"RESIZE",e.quantity)};if(e.base<=n.zone[t])return{changeType:"MOVE",range:this.createAdaptedRange(n,o,"MOVE",e.quantity)}}return{changeType:"NONE"}}),e.sheetId);break}case"DELETE_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId!==e.sheetId)return{changeType:"NONE"};const i=this.getters.getSheetName(e.sheetId);return{changeType:"REMOVE",range:t=t.clone({...this.getInvalidRange(),invalidSheetName:i})}}),e.sheetId);break;case"RENAME_SHEET":this.executeOnAllRanges((t=>{if(t.sheetId===e.sheetId)return{changeType:"CHANGE",range:t};if(e.name&&t.invalidSheetName===e.name){const i=void 0,o=e.sheetId;return{changeType:"CHANGE",range:t.clone({sheetId:o,invalidSheetName:i})}}return{changeType:"NONE"}}));break;case"MOVE_RANGES":{const t=e.target[0];this.executeOnAllRanges((i=>{if(i.sheetId!==e.sheetId||!Qi(i.zone,t))return{changeType:"NONE"};const o=e.targetSheetId,n=e.col-t.left,s=e.row-t.top,r=this.createAdaptedRange(i,"both","MOVE",[n,s]),a=e.sheetId!==o||r.prefixSheet;return{changeType:"MOVE",range:r.clone({sheetId:o,prefixSheet:a})}}));break}}}finalize(){}verifyRangeRemoved(e){return t=>{const i=e(t);return"NONE"===i.changeType||Bi(i.range.zone)?i:{range:i.range,changeType:"REMOVE"}}}createAdaptedRange(e,t,i,o){const n=no(e.unboundedZone,t,i,o);return e.clone({zone:n})}executeOnAllRanges(e,t){const i=this.verifyRangeRemoved(e);for(const e of this.providers)e(i,t)}addRangeProvider(e){this.providers.push(e)}createAdaptedRanges(e,t,i,o){const n=e.map((e=>Fi.fromRange(e,this.getters)));return n.map((e=>{if(!Bi(e.zone))return e;const n=e.prefixSheet?e.sheetId:o,s={...e.unboundedZone,left:e.isFullRow&&!e.unboundedZone.hasHeader?e.unboundedZone.left:e.unboundedZone.left+(e.parts[0].colFixed?0:t),right:e.isFullRow?e.unboundedZone.right:e.unboundedZone.right+((e.parts[1]||e.parts[0]).colFixed?0:t),top:e.isFullCol&&!e.unboundedZone.hasHeader?e.unboundedZone.top:e.unboundedZone.top+(e.parts[0].rowFixed?0:i),bottom:e.isFullCol?e.unboundedZone.bottom:e.unboundedZone.bottom+((e.parts[1]||e.parts[0]).rowFixed?0:i)};return e.clone({sheetId:n,zone:s}).orderZone()}))}getRangeFromSheetXC(e,t){if(!Lt.test(t))return new Fi({sheetId:"",zone:{left:-1,top:-1,right:-1,bottom:-1},parts:[],invalidXc:t,prefixSheet:!1},this.getters.getSheetSize);let i,o=t,n=!1;t.includes("!")&&(({xc:o,sheetName:i}=Bt(t)),i&&(n=!0));const s=Vi(o),r=Fi.getRangeParts(o,s),a=i&&!this.getters.getSheetIdByName(i)?i:void 0,l=this.getters.getSheetIdByName(i)||e;return new Fi({prefixSheet:n,zone:s,sheetId:l,invalidSheetName:a,parts:r},this.getters.getSheetSize).orderZone()}getSelectionRangeString(e,t){const i=Fi.fromRange(e,this.getters),o=this.getters.expandZone(i.sheetId,i.zone),n=i.clone({zone:{...o,bottom:i.isFullCol?void 0:o.bottom,right:i.isFullRow?void 0:o.right}});return this.getRangeString(n,t)}getRangeString(e,t){if(!e)return K;if(e.invalidXc)return e.invalidXc;if(e.zone.bottom-e.zone.top<0||e.zone.right-e.zone.left<0)return K;if(e.zone.left<0||e.zone.top<0)return K;const i=Fi.fromRange(e,this.getters);let o=i.sheetId!==t||i.invalidSheetName||i.prefixSheet,n="";if(o&&(n=i.invalidSheetName?i.invalidSheetName:ke(this.getters.getSheetName(i.sheetId))),o&&!n)return K;let s=this.getRangePartString(i,0);return i.parts&&2===i.parts.length&&(i.zone.top!==i.zone.bottom||i.zone.left!==i.zone.right||i.parts[0].rowFixed||i.parts[0].colFixed||i.parts[1].rowFixed||i.parts[1].colFixed)&&(s+=":",s+=this.getRangePartString(i,1)),`${o?n+"!":""}${s}`}getRangeDataFromXc(e,t){return this.getters.getRangeFromSheetXC(e,t).rangeData}getRangeDataFromZone(e,t){return{_sheetId:e,_zone:t}}getRangeFromRangeData(e){const t={prefixSheet:!1,zone:e._zone,sheetId:e._sheetId,invalidSheetName:void 0,parts:[{colFixed:!1,rowFixed:!1},{colFixed:!1,rowFixed:!1}]};return new Fi(t,this.getters.getSheetSize)}getRangePartString(e,t){const i=e.parts&&e.parts[t].colFixed?"$":"",o=Ht(0===t?e.zone.left:e.zone.right),n=e.parts&&e.parts[t].rowFixed?"$":"",s=String(0===t?e.zone.top+1:e.zone.bottom+1);let r="";return r=e.isFullCol?0===t&&e.unboundedZone.hasHeader?i+o+n+s:i+o:e.isFullRow?0===t&&e.unboundedZone.hasHeader?i+o+n+s:n+s:i+o+n+s,r}getInvalidRange(){return{parts:[],prefixSheet:!1,zone:{left:-1,top:-1,right:-1,bottom:-1},sheetId:"",invalidXc:K}}}Gv.getters=["getRangeString","getSelectionRangeString","getRangeFromSheetXC","createAdaptedRanges","getRangeDataFromXc","getRangeDataFromZone","getRangeFromRangeData"];class qv extends Mv{constructor(){super(...arguments),this.sheetIdsMapName={},this.orderedSheetIds=[],this.sheets={},this.cellPosition={}}allowDispatch(e){const t=this.chainValidations(this.checkSheetExists,this.checkZones)(e);if(0!==t)return t;switch(e.type){case"HIDE_SHEET":return 1===this.getVisibleSheetIds().length?9:0;case"CREATE_SHEET":return this.checkValidations(e,this.checkSheetName,this.checkSheetPosition);case"MOVE_SHEET":try{const t=this.orderedSheetIds.findIndex((t=>t===e.sheetId));return this.findIndexOfTargetSheet(t,e.delta),0}catch(e){return 14}case"RENAME_SHEET":return this.isRenameAllowed(e);case"DELETE_SHEET":return this.orderedSheetIds.length>1?0:9;case"ADD_COLUMNS_ROWS":const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return e.base<0||e.base>t?86:e.quantity<=0?87:0;case"REMOVE_COLUMNS_ROWS":{const t="COL"===e.dimension?this.getNumberCols(e.sheetId):this.getNumberRows(e.sheetId);return Math.min(...e.elements)<0||Math.max(...e.elements)>t?86:this.checkElementsIncludeAllNonFrozenHeaders(e.sheetId,e.dimension,e.elements)?8:0}case"FREEZE_ROWS":return this.checkValidations(e,this.checkRowFreezeQuantity,this.checkRowFreezeOverlapMerge);case"FREEZE_COLUMNS":return this.checkValidations(e,this.checkColFreezeQuantity,this.checkColFreezeOverlapMerge);default:return 0}}handle(e){switch(e.type){case"SET_GRID_LINES_VISIBILITY":this.setGridLinesVisibility(e.sheetId,e.areGridLinesVisible);break;case"DELETE_CONTENT":this.clearZones(e.sheetId,e.target);break;case"CREATE_SHEET":const t=this.createSheet(e.sheetId,e.name||this.getNextSheetName(),e.cols||26,e.rows||100,e.position);this.history.update("sheetIdsMapName",t.name,t.id);break;case"MOVE_SHEET":this.moveSheet(e.sheetId,e.delta);break;case"RENAME_SHEET":this.renameSheet(this.sheets[e.sheetId],e.name);break;case"HIDE_SHEET":this.hideSheet(e.sheetId);break;case"SHOW_SHEET":this.showSheet(e.sheetId);break;case"DUPLICATE_SHEET":this.duplicateSheet(e.sheetId,e.sheetIdTo);break;case"DELETE_SHEET":this.deleteSheet(this.sheets[e.sheetId]);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.removeColumns(this.sheets[e.sheetId],[...e.elements]):this.removeRows(this.sheets[e.sheetId],[...e.elements]);break;case"ADD_COLUMNS_ROWS":"COL"===e.dimension?this.addColumns(this.sheets[e.sheetId],e.base,e.position,e.quantity):this.addRows(this.sheets[e.sheetId],e.base,e.position,e.quantity);break;case"UPDATE_CELL_POSITION":this.updateCellPosition(e);break;case"FREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,e.quantity,"COL");break;case"FREEZE_ROWS":this.setPaneDivisions(e.sheetId,e.quantity,"ROW");break;case"UNFREEZE_ROWS":this.setPaneDivisions(e.sheetId,0,"ROW");break;case"UNFREEZE_COLUMNS":this.setPaneDivisions(e.sheetId,0,"COL");break;case"UNFREEZE_COLUMNS_ROWS":this.setPaneDivisions(e.sheetId,0,"COL"),this.setPaneDivisions(e.sheetId,0,"ROW")}}import(e){var t,i;for(let t of e.sheets)this.sheetIdsMapName[t.name]=t.id;for(let o of e.sheets){const e=o.name||n("Sheet")+(Object.keys(this.sheets).length+1),{colNumber:s,rowNumber:r}=this.getImportedSheetSize(o),a={id:o.id,name:e,numberOfCols:s,rows:Pi(r),areGridLinesVisible:void 0===o.areGridLinesVisible||o.areGridLinesVisible,isVisible:o.isVisible,panes:{xSplit:(null===(t=o.panes)||void 0===t?void 0:t.xSplit)||0,ySplit:(null===(i=o.panes)||void 0===i?void 0:i.ySplit)||0}};this.orderedSheetIds.push(a.id),this.sheets[a.id]=a}}exportSheets(e){e.sheets=this.orderedSheetIds.filter(ot).map((e=>{const t=this.sheets[e],i={id:t.id,name:t.name,colNumber:t.numberOfCols,rowNumber:this.getters.getNumberRows(t.id),rows:{},cols:{},merges:[],cells:{},conditionalFormats:[],figures:[],filterTables:[],areGridLinesVisible:void 0===t.areGridLinesVisible||t.areGridLinesVisible,isVisible:t.isVisible};return(t.panes.xSplit||t.panes.ySplit)&&(i.panes=t.panes),i}))}export(e){this.exportSheets(e)}exportForExcel(e){this.exportSheets(e)}getGridLinesVisibility(e){return this.getSheet(e).areGridLinesVisible}tryGetSheet(e){return this.sheets[e]}getSheet(e){const t=this.sheets[e];if(!t)throw new Error(`Sheet ${e} not found.`);return t}isSheetVisible(e){return this.getSheet(e).isVisible}getSheetName(e){return this.getSheet(e).name}tryGetSheetName(e){var t;return null===(t=this.tryGetSheet(e))||void 0===t?void 0:t.name}getSheetIdByName(e){if(e){const t=De(e);for(const e in this.sheetIdsMapName)if(e.toUpperCase()===t.toUpperCase())return this.sheetIdsMapName[e]}}getSheetIds(){return this.orderedSheetIds}getVisibleSheetIds(){return this.orderedSheetIds.filter(this.isSheetVisible.bind(this))}getEvaluationSheets(){return this.sheets}doesHeaderExist(e,t,i){return"COL"===t?i>=0&&i<this.getNumberCols(e):i>=0&&i<this.getNumberRows(e)}getRow(e,t){const i=this.getSheet(e).rows[t];if(!i)throw new Error(`Row ${i} not found.`);return i}getCell({sheetId:e,col:t,row:i}){var o;const n=this.tryGetSheet(e),s=null===(o=null==n?void 0:n.rows[i])||void 0===o?void 0:o.cells[t];if(void 0!==s)return this.getters.getCellById(s)}getColsZone(e,t,i){return{top:0,bottom:this.getNumberRows(e)-1,left:t,right:i}}getRowCells(e,t){var i;return Object.values(null===(i=this.getSheet(e).rows[t])||void 0===i?void 0:i.cells).filter(ot)}getRowsZone(e,t,i){return{top:t,bottom:i,left:0,right:this.getSheet(e).numberOfCols-1}}getCellPosition(e){const t=this.cellPosition[e];if(!t)throw new Error(`asking for a cell position that doesn't exist, cell id: ${e}`);return t}getNumberCols(e){return this.getSheet(e).numberOfCols}getNumberRows(e){return this.getSheet(e).rows.length}getNumberHeaders(e,t){return"COL"===t?this.getNumberCols(e):this.getNumberRows(e)}getNextSheetName(e="Sheet"){let t=1;const i=this.orderedSheetIds.map(this.getSheetName.bind(this));let o=`${e}${t}`;for(;i.includes(o);)o=`${e}${t}`,t++;return o}getSheetSize(e){return{numberOfRows:this.getNumberRows(e),numberOfCols:this.getNumberCols(e)}}getSheetZone(e){return{top:0,left:0,bottom:this.getNumberRows(e)-1,right:this.getNumberCols(e)-1}}getPaneDivisions(e){return this.getSheet(e).panes}setPaneDivisions(e,t,i){const o={...this.getPaneDivisions(e)};"COL"===i?o.xSplit=t:"ROW"===i&&(o.ySplit=t),this.history.update("sheets",e,"panes",o)}checkElementsIncludeAllNonFrozenHeaders(e,t,i){const o=this.getters.getPaneDivisions(e),n="ROW"===t?o.ySplit:o.xSplit,s=this.getters.getNumberHeaders(e,t);if(!n)return!1;return dt(i,$e(n,s))}isEmpty(e,t){return oo(t).map((({col:t,row:i})=>this.getCell({sheetId:e,col:t,row:i}))).every((e=>!e||""===e.content))}updateCellPosition(e){const{sheetId:t,cellId:i,col:o,row:n}=e;i?this.setNewPosition(i,t,o,n):this.clearPosition(t,o,n)}setNewPosition(e,t,i,o){const n=this.cellPosition[e];n&&this.clearPosition(t,n.col,n.row),this.history.update("cellPosition",e,{row:o,col:i,sheetId:t}),this.history.update("sheets",t,"rows",o,"cells",i,e)}clearPosition(e,t,i){var o;const n=null===(o=this.sheets[e])||void 0===o?void 0:o.rows[i].cells[t];n&&(this.history.update("cellPosition",n,void 0),this.history.update("sheets",e,"rows",i,"cells",t,void 0))}setGridLinesVisibility(e,t){this.history.update("sheets",e,"areGridLinesVisible",t)}clearZones(e,t){for(let i of t)for(let t=i.left;t<=i.right;t++)for(let o=i.top;o<=i.bottom;o++){this.sheets[e].rows[o].cells[t]&&this.dispatch("UPDATE_CELL",{sheetId:e,content:"",col:t,row:o})}}createSheet(e,t,i,o,n){const s={id:e,name:t,numberOfCols:i,rows:Pi(o),areGridLinesVisible:!0,isVisible:!0,panes:{xSplit:0,ySplit:0}},r=this.orderedSheetIds.slice();r.splice(n,0,s.id);const a=this.sheets;return this.history.update("orderedSheetIds",r),this.history.update("sheets",Object.assign({},a,{[s.id]:s})),s}moveSheet(e,t){const i=this.orderedSheetIds.slice(),o=i.findIndex((t=>t===e)),n=i.splice(o,1);let s=this.findIndexOfTargetSheet(o,t);i.splice(s,0,n[0]),this.history.update("orderedSheetIds",i)}findIndexOfTargetSheet(e,t){for(;0!=t&&0<=e&&e<=this.orderedSheetIds.length;)t>0?(e++,this.isSheetVisible(this.orderedSheetIds[e])&&t--):t<0&&(e--,this.isSheetVisible(this.orderedSheetIds[e])&&t++);if(0===t)return e;throw new Error(s("There is not enough visible sheets"))}checkSheetName(e){const{orderedSheetIds:t,sheets:i}=this,o=e.name&&e.name.trim().toLowerCase();return t.find((e=>{var t;return(null===(t=i[e])||void 0===t?void 0:t.name.toLowerCase())===o}))?11:re.test(o)?13:0}checkSheetPosition(e){const{orderedSheetIds:t}=this;return e.position>t.length||e.position<0?15:0}checkRowFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberRows(e.sheetId)?0:74}checkColFreezeQuantity(e){return e.quantity>=1&&e.quantity<this.getNumberCols(e.sheetId)?0:74}checkRowFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.top<e.quantity&&e.quantity<=i.bottom)return 65;return 0}checkColFreezeOverlapMerge(e){const t=this.getters.getMerges(e.sheetId);for(let i of t)if(i.left<e.quantity&&e.quantity<=i.right)return 65;return 0}isRenameAllowed(e){return e.name&&e.name.trim().toLowerCase()?this.checkSheetName(e):10}renameSheet(e,t){const i=e.name;this.history.update("sheets",e.id,"name",t.trim());const o=Object.assign({},this.sheetIdsMapName);o[t]=e.id,delete o[i],this.history.update("sheetIdsMapName",o)}hideSheet(e){this.history.update("sheets",e,"isVisible",!1)}showSheet(e){this.history.update("sheets",e,"isVisible",!0)}duplicateSheet(e,t){const i=this.getSheet(e),o=this.getDuplicateSheetName(i.name),n=Fe(i);n.id=t,n.name=o;for(let e=0;e<=n.numberOfCols;e++)for(let t=0;t<=n.rows.length;t++)n.rows[t]&&(n.rows[t].cells[e]=void 0);const s=this.orderedSheetIds.slice(),r=s.indexOf(e);s.splice(r+1,0,n.id),this.history.update("orderedSheetIds",s),this.history.update("sheets",Object.assign({},this.sheets,{[n.id]:n}));for(const t of Object.values(this.getters.getCells(e))){const{col:e,row:i}=this.getCellPosition(t.id);this.dispatch("UPDATE_CELL",{sheetId:n.id,col:e,row:i,content:t.content,format:t.format,style:t.style})}const a=Object.assign({},this.sheetIdsMapName);a[n.name]=n.id,this.history.update("sheetIdsMapName",a)}getDuplicateSheetName(e){let t=1;const i=this.orderedSheetIds.map(this.getSheetName.bind(this)),o=s("Copy of %s",e);let n=o.toString();for(;i.includes(n);)n=`${o} (${t})`,t++;return n}deleteSheet(e){const t=e.name,i=Object.assign({},this.sheets);delete i[e.id],this.history.update("sheets",i);const o=this.orderedSheetIds.slice(),n=o.indexOf(e.id);o.splice(n,1),this.history.update("orderedSheetIds",o);const s=Object.assign({},this.sheetIdsMapName);delete s[t],this.history.update("sheetIdsMapName",s)}removeColumns(e,t){t.sort(((e,t)=>t-e));for(let i of t)this.moveCellOnColumnsDeletion(e,i);const i=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",i-t.length);const o=t.filter((t=>t<e.panes.xSplit)).length;o&&this.setPaneDivisions(e.id,e.panes.xSplit-o,"COL")}removeRows(e,t){t.sort(((e,t)=>t-e));for(let i of We(t))this.moveCellOnRowsDeletion(e,i[i.length-1],i[0]),i.map((t=>this.updateRowsStructureOnDeletion(t,e)));const i=t.filter((t=>t<e.panes.ySplit)).length;i&&this.setPaneDivisions(e.id,e.panes.ySplit-i,"ROW")}addColumns(e,t,i,o){const n="before"===i?t:t+1;this.moveCellsOnAddition(e,n,o,"columns");const s=this.sheets[e.id].numberOfCols;this.history.update("sheets",e.id,"numberOfCols",s+o),n<e.panes.xSplit&&this.setPaneDivisions(e.id,e.panes.xSplit+o,"COL")}addRows(e,t,i,o){const n="before"===i?t:t+1;this.addEmptyRows(e,o),this.moveCellsOnAddition(e,n,o,"rows"),this.updateRowsStructureOnAddition(e,t,o),n<e.panes.ySplit&&this.setPaneDivisions(e.id,e.panes.ySplit+o,"ROW")}moveCellOnColumnsDeletion(e,t){for(let i=0;i<e.rows.length;i++){const o=e.rows[i];for(let n in o.cells){const s=Number(n),r=o.cells[n];r&&(s===t&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:s,row:i}),s>t&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r,col:s-1,row:i}))}}}moveCellsOnAddition(e,t,i,o){const n=[];for(let s=0;s<e.rows.length;s++){const r=e.rows[s];if("rows"!==o||s>=t)for(let a in r.cells){const l=Number(a),c=r.cells[a];c&&("rows"===o||l>=t)&&n.push({type:"UPDATE_CELL_POSITION",sheetId:e.id,cellId:c,col:l+("columns"===o?i:0),row:s+("rows"===o?i:0)})}}for(let e of n.reverse())this.dispatch(e.type,e)}moveCellOnRowsDeletion(e,t,i){const o=i-t+1;for(let n=0;n<e.rows.length;n++){const s=e.rows[n];if(n>=t&&n<=i)for(let t in s.cells){const i=Number(t);s.cells[t]&&this.dispatch("CLEAR_CELL",{sheetId:e.id,col:i,row:n})}if(n>i)for(let t in s.cells){const i=Number(t),r=s.cells[t];r&&this.dispatch("UPDATE_CELL_POSITION",{sheetId:e.id,cellId:r,col:i,row:n-o})}}}updateRowsStructureOnDeletion(e,t){const i=[],o=t.rows.map((e=>e.cells));for(let n in t.rows)Number(n)!==e&&i.push({cells:o.shift()});this.history.update("sheets",t.id,"rows",i)}updateRowsStructureOnAddition(e,t,i){const o=[],n=e.rows.map((e=>e.cells));e.rows.forEach((()=>o.push({cells:n.shift()}))),this.history.update("sheets",e.id,"rows",o)}addEmptyRows(e,t){const i=e.rows.slice();for(let e=0;e<t;e++)i.push({cells:{}});this.history.update("sheets",e.id,"rows",i)}getImportedSheetSize(e){const t=Object.keys(e.cells).map(Wt);let i=e.rowNumber,o=e.colNumber;for(let{col:e,row:n}of t)i=Math.max(i,n+1),o=Math.max(o,e+1);return{rowNumber:i,colNumber:o}}checkSheetExists(e){return"CREATE_SHEET"!==e.type&&"sheetId"in e&&void 0===this.sheets[e.sheetId]?27:"CREATE_SHEET"===e.type&&void 0!==this.sheets[e.sheetId]?12:0}checkZones(e){const t=[];if("zone"in e&&t.push(e.zone),"target"in e&&Array.isArray(e.target)&&t.push(...e.target),"ranges"in e&&Array.isArray(e.ranges)&&t.push(...e.ranges.map((e=>this.getters.getRangeFromRangeData(e).zone))),!t.every(Bi))return 25;if(t.length&&"sheetId"in e){const i=this.getSheetZone(e.sheetId);return t.every((e=>Qi(e,i)))?0:18}return 0}}qv.getters=["getSheetName","tryGetSheetName","getSheet","tryGetSheet","getSheetIdByName","getSheetIds","getVisibleSheetIds","isSheetVisible","getEvaluationSheets","doesHeaderExist","getCell","getCellPosition","getColsZone","getRowCells","getRowsZone","getNumberCols","getNumberRows","getNumberHeaders","getGridLinesVisibility","getNextSheetName","isEmpty","getSheetSize","getSheetZone","getPaneDivisions","checkElementsIncludeAllNonFrozenHeaders"];class Zv extends Av{constructor({getters:e,stateObserver:t,dispatch:i,uiActions:o,selection:n}){super(t,i),this.getters=e,this.ui=o,this.selection=n}drawGrid(e,t){}}Zv.layers=[];class jv extends Zv{constructor(){super(...arguments),this.customColors=new Set,this.shouldUpdateColors=!1}handle(e){switch(e.type){case"UPDATE_CELL":case"UPDATE_CHART":case"CREATE_CHART":case"ADD_CONDITIONAL_FORMAT":this.shouldUpdateColors=!0}}finalize(){if(this.shouldUpdateColors){this.shouldUpdateColors=!1;for(const e of this.getCustomColors())this.tryToAddColor(e)}}getCustomColors(){let e=[];for(const t of this.getters.getSheetIds()){const i=Object.values(this.getters.getCells(t));e=e.concat(this.getColorsFromCells(i),this.getFormattingColors(t),this.getChartColors(t))}return function(e){const t=[{leadColor:It(255,0,0),colors:[]},{leadColor:It(255,128,0),colors:[]},{leadColor:It(128,128,0),colors:[]},{leadColor:It(128,255,0),colors:[]},{leadColor:It(0,255,0),colors:[]},{leadColor:It(0,255,128),colors:[]},{leadColor:It(0,255,255),colors:[]},{leadColor:It(0,127,255),colors:[]},{leadColor:It(0,0,255),colors:[]},{leadColor:It(127,0,255),colors:[]},{leadColor:It(128,0,128),colors:[]},{leadColor:It(255,0,128),colors:[]}];for(const i of e.map(At)){let e=500,o=0;t.forEach(((t,n)=>{const s=(r=i,a=t.leadColor,Math.sqrt(Math.pow(r.r-a.r,2)+Math.pow(r.g-a.g,2)+Math.pow(r.b-a.b,2)));var r,a;e>s&&(e=s,o=n)})),t[o].colors.push(i)}return t.map((e=>e.colors.sort(((e,t)=>Ot(e).s-Ot(t).s)))).flat().map(Tt)}([...new Set([...new Set([...e,...this.customColors])].filter(yt).map(wt))]).filter((e=>!O.includes(e)))}getColorsFromCells(e){var t,i;const o=new Set;for(const n of e)(null===(t=n.style)||void 0===t?void 0:t.textColor)&&o.add(n.style.textColor),(null===(i=n.style)||void 0===i?void 0:i.fillColor)&&o.add(n.style.fillColor);return[...o]}getFormattingColors(e){const t=this.getters.getConditionalFormats(e),i=[];for(const e of t){const t=e.rule;"CellIsRule"===t.type?(i.push(t.style.textColor),i.push(t.style.fillColor)):"ColorScaleRule"===t.type&&(i.push(Et(t.minimum.color)),i.push(t.midpoint?Et(t.midpoint.color):void 0),i.push(Et(t.maximum.color)))}return i.filter(ot)}getChartColors(e){const t=this.getters.getChartIds(e).map((e=>this.getters.getChart(e)));let i=new Set;for(let e of t){if(void 0===e)continue;const t=e.getDefinition().background;switch(void 0!==t&&i.add(t),e.type){case"gauge":const t=e.sectionRule.colors;i.add(t.lowerColor),i.add(t.middleColor),i.add(t.upperColor);break;case"scorecard":const o=e;i.add(o.baselineColorDown),i.add(o.baselineColorUp)}}return[...i]}tryToAddColor(e){const t=wt(e);e&&!O.includes(t)&&this.customColors.add(t)}}jv.getters=["getCustomColors"];const Xv=Yu.mapping;class Yv extends Zv{constructor(e){super(e),this.isUpToDate=!1,this.evaluatedCells={},this.evalContext=e.custom,this.lazyEvaluation=e.lazyEvaluation}handle(e){switch(ln.has(e.type)&&(this.isUpToDate=!1),e.type){case"UPDATE_CELL":("content"in e||"format"in e)&&(this.isUpToDate=!1);break;case"EVALUATE_CELLS":this.evaluate()}}finalize(){this.isUpToDate||(this.evaluate(),this.isUpToDate=!0)}evaluateFormula(e,t=this.getters.getActiveSheetId()){const i=df(e),o=this.getCompilationParameters((e=>this.getEvaluatedCell(this.getters.getCellPosition(e.id)))),n=[];for(let e of i.dependencies)n.push(this.getters.getRangeFromSheetXC(t,e));return i.execute(n,...o).value}getRangeFormattedValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.formattedValue))}getRangeValues(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.value))}getRangeFormats(e){const t=this.getters.tryGetSheet(e.sheetId);return void 0===t?[]:this.getters.getEvaluatedCellsInZone(t.id,e.zone).map((e=>e.format))}getEvaluatedCell({sheetId:e,col:t,row:i}){var o,n,s;return void 0===this.getters.getCell({sheetId:e,col:t,row:i})?Sn(""):(null===(s=null===(n=null===(o=this.evaluatedCells[e])||void 0===o?void 0:o[t])||void 0===n?void 0:n[i])||void 0===s?void 0:s.call(n))||Sn("")}getEvaluatedCells(e){const t=this.getters.getCells(e)||{},i={};for(let e of Object.keys(t)){const t=this.getters.getCellPosition(e);i[e]=this.getEvaluatedCell(t)}return i}getColEvaluatedCells(e,t){var i;return Object.values((null===(i=this.evaluatedCells[e])||void 0===i?void 0:i[t])||[]).filter(ot).map((e=>e()))}getEvaluatedCellsInZone(e,t){return oo(t).map((({col:t,row:i})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:i})))}setEvaluatedCell(e,t){const{col:i,row:o,sheetId:n}=this.getters.getCellPosition(e);this.evaluatedCells[n]||(this.evaluatedCells[n]={}),this.evaluatedCells[n][i]||(this.evaluatedCells[n][i]={}),this.evaluatedCells[n][i][o]=t,this.lazyEvaluation||this.evaluatedCells[n][i][o]()}*getAllCells(){for(const e of this.getters.getSheetIds()){const t=this.getters.getCells(e);for(const e in t)yield t[e]}}evaluate(){this.evaluatedCells={};const e=new Set,t=e=>{var t,n;const s=e.id,{col:r,row:a,sheetId:l}=this.getters.getCellPosition(s),c=null===(n=null===(t=this.evaluatedCells[l])||void 0===t?void 0:t[r])||void 0===n?void 0:n[a];return c||at((()=>{try{switch(e.isFormula){case!0:return o(e);case!1:return vn(e.content,e.format)}}catch(t){return i(t,e)}}))},i=(e,t)=>{e instanceof Error||(e=new Error(e));const i=(null==e?void 0:e.errorType)||a.GenericError,o=n[2].__lastFnCalled||"",s=new c(i,e.message.replace("[[FUNCTION_NAME]]",o),void 0!==e.logLevel?e.logLevel:l.error);return yn(t.content,s)},o=t=>{const i=t.id;if(e.has(i))throw new d;n[2].__originCellXC=()=>{const e=n[2].getters.getCellPosition(i);return Gt(e.col,e.row)},e.add(i);const o=t.compiledFormula.execute(t.dependencies,...n);if(e.delete(i),Array.isArray(o.value))throw new Error(s("This formula depends on invalid values"));return Sn(o.value,t.format||o.format)},n=this.getCompilationParameters((e=>t(e)()));for(const e of this.getAllCells())this.setEvaluatedCell(e.id,t(e))}getCompilationParameters(e){const t=Object.assign(Object.create(Xv),this.evalContext,{getters:this.getters}),i=this.getters;const o=t=>{const i=e(t);if(i.type===rn.error)throw i.error;return i};return[function(e,t,n,r){if(t)return{value:Hi(e.zone)};if(!Bi(e.zone))throw new u;if(e.zone.bottom!==e.zone.top||e.zone.left!==e.zone.right)throw new Error(r?s("Function %s expects the parameter %s to be a single value or a single cell reference, not a range.",n.toString(),r.toString()):s("Function %s expects its parameters to be single values or single cell references, not ranges.",n.toString()));if(e.invalidSheetName)throw new Error(s("Invalid sheet name: %s",e.invalidSheetName));return function(e){let t;if(!i.tryGetSheet(e.sheetId))throw new Error(s("Invalid sheet name"));return t=i.getCell({sheetId:e.sheetId,col:e.zone.left,row:e.zone.top}),t&&""!==t.content?o(t):{value:null,format:null==t?void 0:t.format}}(e)},function(e){const n=e.sheetId;if(!Bi(e.zone))throw new u;const s=i.getSheetZone(n),r=[],a=ji(e.zone,s);if(!a)return r.push([]),r;for(let i=a.left;i<=a.right;i++){const n=[];for(let s=a.top;s<=a.bottom;s++){const r=t.getters.getCell({sheetId:e.sheetId,col:i,row:s});n.push(r?o(r):void 0)}r.push(n)}return r},t]}exportForExcel(e){for(let t of e.sheets)for(const e in t.cells){const i={sheetId:t.id,...Wt(e)},o=this.getters.getCell(i);if(o){const n=t.cells[e],s=this.getEvaluatedCell(i);n.value=s.value,n.isFormula=o.isFormula&&!this.isBadExpression(o.content),o.format!==s.format&&(n.computedFormat=s.format)}}}isBadExpression(e){try{return df(e),!1}catch(e){return!0}}}Yv.getters=["evaluateFormula","getRangeFormattedValues","getRangeValues","getRangeFormats","getEvaluatedCell","getEvaluatedCells","getColEvaluatedCells","getEvaluatedCellsInZone"];class Kv extends Zv{constructor(){super(...arguments),this.charts={},this.createRuntimeChart=function(e){const t=lr.getAll().sort(((e,t)=>e.sequence-t.sequence));return function(i){const o=t.find((e=>e.match(i.type)));if(!o)throw new Error("No runtime builder for this chart.");return o.getChartRuntime(i,e)}}(this.getters)}handle(e){if(ln.has(e.type)||cn.has(e.type)||"EVALUATE_CELLS"===e.type||"UPDATE_CELL"===e.type)for(const e in this.charts)this.charts[e]=void 0;switch(e.type){case"UPDATE_CHART":case"CREATE_CHART":case"DELETE_FIGURE":this.charts[e.id]=void 0;break;case"DELETE_SHEET":for(let e in this.charts)this.getters.isChartDefined(e)||(this.charts[e]=void 0)}}getChartRuntime(e){if(!this.charts[e]){const t=this.getters.getChart(e);if(!t)throw new Error(`No chart for the given id: ${e}`);this.charts[e]=this.createRuntimeChart(t)}return this.charts[e]}getStyleOfSingleCellChart(e,t){if(e)return{background:e,fontColor:Cs(e)};if(!t)return{background:w,fontColor:Cs(w)};const i=t.zone.left,o=t.zone.top,n=t.sheetId,s=this.getters.getCellComputedStyle({sheetId:n,col:i,row:o}),r=s.fillColor||w;return{background:r,fontColor:s.textColor||Cs(r)}}}Kv.getters=["getChartRuntime","getStyleOfSingleCellChart"];class Qv extends Zv{constructor(){super(...arguments),this.isStale=!0,this.computedStyles={},this.computedIcons={},this.uuidGenerator=new Ui,this.rulePredicate={CellIsRule:(e,t)=>{if(e.type===rn.error)return!1;const i=t.values.map(bn);switch(t.operator){case"IsEmpty":return""===e.value.toString().trim();case"IsNotEmpty":return""!==e.value.toString().trim();case"BeginsWith":return""!==i[0]&&e.value.toString().startsWith(i[0].toString());case"EndsWith":return""!==i[0]&&e.value.toString().endsWith(i[0].toString());case"Between":return e.value>=i[0]&&e.value<=i[1];case"NotBetween":return!(e.value>=i[0]&&e.value<=i[1]);case"ContainsText":return e.value.toString().indexOf(i[0].toString())>-1;case"NotContains":return!e.value||-1==e.value.toString().indexOf(i[0].toString());case"GreaterThan":return e.value>i[0];case"GreaterThanOrEqual":return e.value>=i[0];case"LessThan":return e.value<i[0];case"LessThanOrEqual":return e.value<=i[0];case"NotEqual":return""!==i[0]&&e.value!==i[0];case"Equal":return""===i[0]||e.value===i[0];default:console.warn(s("Not implemented operator %s for kind of conditional formatting: %s",t.operator,t.type))}return!1}}}handle(e){switch((cn.has(e.type)||"UPDATE_CELL"===e.type&&"content"in e)&&(this.isStale=!0),e.type){case"ACTIVATE_SHEET":const t=e.sheetIdTo;this.computedStyles[t]=this.computedStyles[t]||{},this.computedIcons[t]=this.computedIcons[t]||{},this.isStale=!0;break;case"AUTOFILL_CELL":const i=this.getters.getActiveSheetId(),o=this.getters.getRulesByCell(i,e.originCol,e.originRow);for(const t of o)this.adaptRules(i,t,[Gt(e.col,e.row)],[]);break;case"PASTE_CONDITIONAL_FORMAT":this.pasteCf(e.origin,e.target,e.operation)}}finalize(){this.isStale&&(this.computeStyles(),this.isStale=!1)}getCellComputedStyle(e){var t;const{sheetId:i,col:o,row:n}=e,s=this.getters.getCell(e),r=this.computedStyles[i],a=r&&(null===(t=r[o])||void 0===t?void 0:t[n]),l={...null==s?void 0:s.style,...a};return this.getters.getEvaluatedCell(e).link&&!l.textColor&&(l.textColor=I),this.getters.isFilterHeader(e)&&(l.bold=!0),l}getConditionalIcon({col:e,row:t}){var i;const o=this.getters.getActiveSheetId(),n=this.computedIcons[o];return n&&(null===(i=n[e])||void 0===i?void 0:i[t])}computeStyles(){var e;const t=this.getters.getActiveSheetId();this.computedStyles[t]={},this.computedIcons[t]={};const i=this.computedStyles[t];for(let o of this.getters.getConditionalFormats(t).reverse())try{switch(o.rule.type){case"ColorScaleRule":for(let e of o.ranges)this.applyColorScale(e,o.rule);break;case"IconSetRule":for(let e of o.ranges)this.applyIcon(e,o.rule);break;default:for(let n of o.ranges){const s=this.getters.getRangeFromSheetXC(t,n).zone;for(let n=s.top;n<=s.bottom;n++)for(let r=s.left;r<=s.right;r++){const s=this.rulePredicate[o.rule.type];let a=this.getters.getEvaluatedCell({sheetId:t,col:r,row:n});s&&s(a,o.rule)&&(i[r]||(i[r]=[]),i[r][n]=Object.assign((null===(e=i[r])||void 0===e?void 0:e[n])||{},o.rule.style))}}}}catch(e){}}parsePoint(e,t,i){const o=this.getters.getActiveSheetId(),n=this.getters.getEvaluatedCellsInZone(o,this.getters.getRangeFromSheetXC(o,e).zone).filter((e=>e.type===rn.number)).map((e=>e.value));switch(t.type){case"value":return"max"===i?Math.max(...n):Math.min(...n);case"number":return Number(t.value);case"percentage":const e=Math.min(...n);return e+(Math.max(...n)-e)*Number(t.value)/100;case"percentile":return si(n,Number(t.value)/100,!0);case"formula":const o=t.value&&this.getters.evaluateFormula(t.value);return o instanceof Promise?null:o;default:return null}}applyIcon(e,t){const i=this.parsePoint(e,t.lowerInflectionPoint),o=this.parsePoint(e,t.upperInflectionPoint);if(null===i||null===o||i>o)return;const n=this.getters.getActiveSheetId(),s=this.getters.getRangeFromSheetXC(n,e).zone,r=this.computedIcons[n],a=[t.icons.upper,t.icons.middle,t.icons.lower];for(let e=s.top;e<=s.bottom;e++)for(let l=s.left;l<=s.right;l++){const s=this.getters.getEvaluatedCell({sheetId:n,col:l,row:e});if(s.type!==rn.number)continue;const c=this.computeIcon(s.value,o,t.upperInflectionPoint.operator,i,t.lowerInflectionPoint.operator,a);r[l]||(r[l]=[]),r[l][e]=c}}computeIcon(e,t,i,o,n,s){return"ge"===i&&e>=t||"gt"===i&&e>t?s[0]:"ge"===n&&e>=o||"gt"===n&&e>o?s[1]:s[2]}applyColorScale(e,t){var i;const o=this.parsePoint(e,t.minimum,"min"),n=t.midpoint?this.parsePoint(e,t.midpoint):null,s=this.parsePoint(e,t.maximum,"max");if(null===o||null===s||o>=s||n&&(o>=n||n>=s))return;const r=this.getters.getActiveSheetId(),a=this.getters.getRangeFromSheetXC(r,e).zone,l=this.computedStyles[r],c=[];t.midpoint&&n?(c.push({minValue:o,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(o,n,t.minimum.color,t.midpoint.color)}),c.push({minValue:n,minColor:t.midpoint.color,colorDiffUnit:this.computeColorDiffUnits(n,s,t.midpoint.color,t.maximum.color)})):c.push({minValue:o,minColor:t.minimum.color,colorDiffUnit:this.computeColorDiffUnits(o,s,t.minimum.color,t.maximum.color)});for(let e=a.top;e<=a.bottom;e++)for(let t=a.left;t<=a.right;t++){const a=this.getters.getEvaluatedCell({sheetId:r,col:t,row:e});if(a.type===rn.number){const r=Le(a.value,o,s);let h;h=2===c.length&&n?r<=n?this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit):this.colorCell(r,c[1].minValue,c[1].minColor,c[1].colorDiffUnit):this.colorCell(r,c[0].minValue,c[0].minColor,c[0].colorDiffUnit),l[t]||(l[t]=[]),l[t][e]=(null===(i=l[t])||void 0===i?void 0:i[e])||{},l[t][e].fillColor=Et(h)}}}computeColorDiffUnits(e,t,i,o){const n=t-e;return[((i>>16)%256-(o>>16)%256)/n,((i>>8)%256-(o>>8)%256)/n,(i%256-o%256)/n]}colorCell(e,t,i,o){const[n,s,r]=o;return Math.round((i>>16)%256-n*(e-t))<<16|Math.round((i>>8)%256-s*(e-t))<<8|Math.round(i%256-r*(e-t))}adaptRules(e,t,i,o){if(0===i.length&&0===o.length)return;const n=this.getters.getConditionalFormats(e),s=n.findIndex((e=>e.id===t.id));let r=[];s>-1&&(r=n[s].ranges),r=r.concat(i);const a=Ji(r,o);0!==a.length?this.dispatch("ADD_CONDITIONAL_FORMAT",{cf:{id:t.id,rule:t.rule,stopIfTrue:t.stopIfTrue},ranges:a.map((t=>this.getters.getRangeDataFromXc(e,t))),sheetId:e}):this.dispatch("REMOVE_CONDITIONAL_FORMAT",{id:t.id,sheetId:e})}pasteCf(e,t,i){const o=Gt(t.col,t.row);for(let n of this.getters.getConditionalFormats(e.sheetId))for(let s of n.ranges)if(Ki(e.col,e.row,this.getters.getRangeFromSheetXC(e.sheetId,s).zone)){const s=n,r=[];if("CUT"===i&&r.push(Gt(e.col,e.row)),e.sheetId===t.sheetId)this.adaptRules(e.sheetId,s,[o],r);else{this.adaptRules(e.sheetId,s,[],r);const i=this.getCFToCopyTo(t.sheetId,s);this.adaptRules(t.sheetId,i,[o],[])}}}getCFToCopyTo(e,t){const i=this.getters.getConditionalFormats(e).find((e=>e.stopIfTrue===t.stopIfTrue&&ht(e.rule,t.rule)));return i||{...t,id:this.uuidGenerator.uuidv4(),ranges:[]}}}Qv.getters=["getConditionalIcon","getCellComputedStyle"];class Jv extends Zv{constructor(){super(...arguments),this.filterValues={},this.hiddenRows=new Set,this.isEvaluationDirty=!1}allowDispatch(e){if("UPDATE_FILTER"===e.type)if(!this.getters.getFilterId(e))return 79;return 0}handle(e){switch(e.type){case"UNDO":case"REDO":case"UPDATE_CELL":case"EVALUATE_CELLS":case"ACTIVATE_SHEET":case"REMOVE_FILTER_TABLE":this.isEvaluationDirty=!0;break;case"START":for(const e of this.getters.getSheetIds()){this.filterValues[e]={};for(const t of this.getters.getFilters(e))this.filterValues[e][t.id]=[]}break;case"CREATE_SHEET":this.filterValues[e.sheetId]={};break;case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":this.updateHiddenRows();break;case"UPDATE_FILTER":this.updateFilter(e),this.updateHiddenRows();break;case"DUPLICATE_SHEET":const t={};for(const i of this.getters.getFilters(e.sheetIdTo)){const o=i.zoneWithHeaders;t[i.id]=this.getFilterValues({sheetId:e.sheetId,col:o.left,row:o.top})}this.filterValues[e.sheetIdTo]=t}}finalize(){this.isEvaluationDirty&&(this.updateHiddenRows(),this.isEvaluationDirty=!1)}isRowFiltered(e,t){return e===this.getters.getActiveSheetId()&&this.hiddenRows.has(t)}getCellBorderWithFilterBorder(e){const{sheetId:t,col:i,row:o}=e;let n;for(let e of this.getters.getFilterTables(t)){const s=e.zone;if(Ki(i,o,s)){const e=this.intersectZoneWithViewport(t,s);n={top:o===e.top?X:void 0,bottom:o===e.bottom?X:void 0,left:i===e.left?X:void 0,right:i===e.right?X:void 0}}}const s=this.getters.getCellBorder(e),r={...n,...ut(s||{})};return nt(r)?null:r}getFilterHeaders(e){const t=[];for(let i of this.getters.getFilterTables(e)){const o=i.zone;if(!o)continue;const n=o.top;for(let i=o.left;i<=o.right;i++)this.getters.isColHidden(e,i)||this.getters.isRowHidden(e,n)||t.push({col:i,row:n})}return t}getFilterValues(e){const t=this.getters.getFilterId(e),i=e.sheetId;return t&&this.filterValues[i]&&this.filterValues[i][t]||[]}isFilterHeader({sheetId:e,col:t,row:i}){return this.getFilterHeaders(e).some((e=>e.col===t&&e.row===i))}isFilterActive(e){var t,i;const o=this.getters.getFilterId(e),n=e.sheetId;return Boolean(o&&(null===(i=null===(t=this.filterValues[n])||void 0===t?void 0:t[o])||void 0===i?void 0:i.length))}intersectZoneWithViewport(e,t){return{left:this.getters.findVisibleHeader(e,"COL",t.left,t.right),right:this.getters.findVisibleHeader(e,"COL",t.right,t.left),top:this.getters.findVisibleHeader(e,"ROW",t.top,t.bottom),bottom:this.getters.findVisibleHeader(e,"ROW",t.bottom,t.top)}}updateFilter({col:e,row:t,values:i,sheetId:o}){const n=this.getters.getFilterId({sheetId:o,col:e,row:t});n&&(this.filterValues[o]||(this.filterValues[o]={}),this.filterValues[o][n]=i)}updateHiddenRows(){var e,t;const i=this.getters.getActiveSheetId(),o=this.getters.getFilters(i).sort(((e,t)=>e.zoneWithHeaders.top-t.zoneWithHeaders.top)),n=new Set;for(let s of o){if(this.getters.isRowHiddenByUser(i,s.zoneWithHeaders.top))continue;if(n.has(s.zoneWithHeaders.top))continue;const o=null===(t=null===(e=this.filterValues[i])||void 0===e?void 0:e[s.id])||void 0===t?void 0:t.map(gt);if(o&&s.filteredZone)for(let e=s.filteredZone.top;e<=s.filteredZone.bottom;e++){const t=this.getCellValueAsString(i,s.col,e);o.includes(t)&&n.add(e)}}this.hiddenRows=n}getCellValueAsString(e,t,i){return this.getters.getEvaluatedCell({sheetId:e,col:t,row:i}).formattedValue.toLowerCase()}exportForExcel(e){for(const t of e.sheets){const e=t.id;for(const i of t.filterTables){const o=zi(i.range),n=[],s=[];for(const i of $e(0,to(o).numberOfCols)){const r={sheetId:t.id,col:o.left+i,row:o.top},a=this.getFilterValues(r),l=this.getters.getFilter(r);if(!l)continue;const c=l.filteredZone?oo(l.filteredZone).map((t=>this.getters.getEvaluatedCell({sheetId:e,...t}).formattedValue)):[];if(a.length){const e=c.filter((e=>e)).filter((e=>!a.includes(e)));n.push({colId:i,displayedValues:[...new Set(e)],displayBlanks:!a.includes("")&&c.some((e=>!e))})}const h={col:l.col,row:l.zoneWithHeaders.top,sheetId:e},d=this.getters.getEvaluatedCell(h).formattedValue,u=this.getUniqueColNameForExcel(i,d,s);s.push(u),t.cells[Gt(h.col,h.row)]={...t.cells[Gt(h.col,h.row)],content:u,value:u,isFormula:!1}}i.filters=n}}}getUniqueColNameForExcel(e,t,i){t||(t=`Column${e}`);let o=t,n=2;for(;i.includes(o);)o=t+String(n),n++;return o}}Jv.getters=["getCellBorderWithFilterBorder","getFilterHeaders","getFilterValues","isFilterHeader","isRowFiltered","isFilterActive"];class eb{constructor(e,t,i,o,n,s){this.getters=e,this.sheetId=t,this.boundaries=i,this.viewportWidth=o.width,this.viewportHeight=o.height,this.offsetScrollbarX=s.x,this.offsetScrollbarY=s.y,this.canScrollVertically=n.canScrollVertically,this.canScrollHorizontally=n.canScrollHorizontally,this.offsetCorrectionX=this.getters.getColDimensions(this.sheetId,this.boundaries.left).start,this.offsetCorrectionY=this.getters.getRowDimensions(this.sheetId,this.boundaries.top).start,this.adjustViewportOffsetX(),this.adjustViewportOffsetY()}getMaxSize(){const e=this.getters.findLastVisibleColRowIndex(this.sheetId,"COL",{first:this.boundaries.left,last:this.boundaries.right}),t=this.getters.findLastVisibleColRowIndex(this.sheetId,"ROW",{first:this.boundaries.top,last:this.boundaries.bottom}),{end:i,size:o}=this.getters.getColDimensions(this.sheetId,e),{end:n,size:s}=this.getters.getRowDimensions(this.sheetId,t),r=this.searchHeaderIndex("COL",i-this.viewportWidth,0),a=this.getters.getColSize(this.sheetId,r),l=this.searchHeaderIndex("ROW",n-this.viewportHeight,0),c=this.getters.getRowSize(this.sheetId,l);let h=i-this.offsetCorrectionX;this.canScrollHorizontally&&(h+=Math.max(F,Math.min(a,this.viewportWidth-o)),h=Math.max(h,this.viewportWidth));let d=n-this.offsetCorrectionY;return this.canScrollVertically&&(d+=Math.max(D+5,Math.min(c,this.viewportHeight-s)),d=Math.max(d,this.viewportHeight)),{width:h,height:d}}getColIndex(e,t=!1){return e<this.offsetCorrectionX||e>this.offsetCorrectionX+this.viewportWidth?-1:this.searchHeaderIndex("COL",e-this.offsetCorrectionX,this.left,t)}getRowIndex(e,t=!1){return e<this.offsetCorrectionY||e>this.offsetCorrectionY+this.viewportHeight?-1:this.searchHeaderIndex("ROW",e-this.offsetCorrectionY,this.top,t)}adjustPosition(e){const t=this.sheetId;e||(e=this.getters.getSheetPosition(t));const i=this.getters.getMainCellPosition({sheetId:t,...e}),{col:o,row:n}=this.getters.getNextVisibleCellPosition(i);Ki(o,this.boundaries.top,this.boundaries)&&this.adjustPositionX(o),Ki(this.boundaries.left,n,this.boundaries)&&this.adjustPositionY(n)}adjustPositionX(e){const t=this.sheetId,{end:i}=this.getters.getColDimensions(t,e),o=this.getters.getNumberCols(t);if(this.offsetX+this.offsetCorrectionX+this.viewportWidth<i){let i=e;for(;this.getters.isColHidden(t,i)&&e<o;)i++;const n=this.getters.getColDimensions(t,i).end,s=this.searchHeaderIndex("COL",n-this.viewportWidth-this.offsetCorrectionX,this.boundaries.left,!0);this.offsetX=this.getters.getColDimensions(t,s).end-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}else if(this.left>e){let i=e;for(;this.getters.isColHidden(t,i)&&e>0;)i--;this.offsetX=this.getters.getColDimensions(t,i).start-this.offsetCorrectionX,this.offsetScrollbarX=this.offsetX,this.adjustViewportZoneX()}}adjustPositionY(e){const t=this.sheetId,{end:i}=this.getters.getRowDimensions(t,e),o=this.getters.getNumberRows(t);if(this.offsetY+this.viewportHeight+this.offsetCorrectionY<i){let i=e;for(;this.getters.isRowHidden(t,i)&&e<o;)i++;const n=this.getters.getRowDimensions(t,i).end,s=this.searchHeaderIndex("ROW",n-this.viewportHeight-this.offsetCorrectionY,this.boundaries.top,!0);this.offsetY=this.getters.getRowDimensions(t,s).end-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}else if(this.top>e){let i=e;for(;this.getters.isRowHidden(t,i)&&e>0;)i--;this.offsetY=this.getters.getRowDimensions(t,i).start-this.offsetCorrectionY,this.offsetScrollbarY=this.offsetY,this.adjustViewportZoneY()}}setViewportOffset(e,t){this.setViewportOffsetX(e),this.setViewportOffsetY(t)}adjustViewportZone(){this.adjustViewportZoneX(),this.adjustViewportZoneY()}getRect(e){const t=ji(e,this.zone);if(t){return{x:this.getters.getColRowOffset("COL",this.zone.left,t.left)+this.offsetCorrectionX,y:this.getters.getColRowOffset("ROW",this.zone.top,t.top)+this.offsetCorrectionY,width:Math.min(this.getters.getColRowOffset("COL",t.left,t.right+1),this.viewportWidth),height:Math.min(this.getters.getColRowOffset("ROW",t.top,t.bottom+1),this.viewportHeight)}}}isVisible(e,t){return t<=this.bottom&&t>=this.top&&e>=this.left&&e<=this.right&&!this.getters.isColHidden(this.sheetId,e)&&!this.getters.isRowHidden(this.sheetId,t)}searchHeaderIndex(e,t,i=0,o=!1){let n=0;const s=this.sheetId,r=this.getters.getNumberHeaders(s,e);for(let a=i;a<=r-1;a++){const i=o||"COL"!==e?a<this.top&&a>this.bottom:a<this.left&&a>this.right;if(!this.getters.isHeaderHidden(s,e,a)&&!i&&(n+="COL"===e?this.getters.getColSize(s,a):this.getters.getRowSize(s,a),n>t))return a}return-1}get zone(){return{left:this.left,right:this.right,top:this.top,bottom:this.bottom}}setViewportOffsetX(e){this.canScrollHorizontally&&(this.offsetScrollbarX=e,this.adjustViewportZoneX())}setViewportOffsetY(e){this.canScrollVertically&&(this.offsetScrollbarY=e,this.adjustViewportZoneY())}adjustViewportOffsetX(){if(this.canScrollHorizontally){const{width:e}=this.getMaxSize();this.viewportWidth+this.offsetScrollbarX>e&&(this.offsetScrollbarX=Math.max(0,e-this.viewportWidth))}this.left=this.getColIndex(this.offsetScrollbarX,!0),this.right=this.getColIndex(this.offsetScrollbarX+this.viewportWidth,!0),-1===this.right&&(this.right=this.boundaries.right),this.adjustViewportZoneX()}adjustViewportOffsetY(){if(this.canScrollVertically){const{height:e}=this.getMaxSize();this.viewportHeight+this.offsetScrollbarY>e&&(this.offsetScrollbarY=Math.max(0,e-this.viewportHeight))}this.top=this.getRowIndex(this.offsetScrollbarY,!0),this.bottom=this.getRowIndex(this.offsetScrollbarY+this.viewportWidth,!0),-1===this.bottom&&(this.bottom=this.boundaries.bottom),this.adjustViewportZoneY()}adjustViewportZoneX(){const e=this.sheetId;this.left=this.searchHeaderIndex("COL",this.offsetScrollbarX,this.boundaries.left),this.right=Math.min(this.boundaries.right,this.searchHeaderIndex("COL",this.viewportWidth,this.left)),-1===this.left&&(this.left=this.boundaries.left),-1===this.right&&(this.right=this.getters.getNumberCols(e)-1),this.offsetX=this.getters.getColDimensions(e,this.left).start-this.getters.getColDimensions(e,this.boundaries.left).start}adjustViewportZoneY(){const e=this.sheetId;this.top=this.searchHeaderIndex("ROW",this.offsetScrollbarY,this.boundaries.top),this.bottom=Math.min(this.boundaries.bottom,this.searchHeaderIndex("ROW",this.viewportHeight,this.top)),-1===this.top&&(this.top=this.boundaries.top),-1===this.bottom&&(this.bottom=this.getters.getNumberRows(e)-1),this.offsetY=this.getters.getRowDimensions(e,this.top).start-this.getters.getRowDimensions(e,this.boundaries.top).start}}class tb extends Zv{constructor(){super(...arguments),this.viewports={},this.sheetViewWidth=1e3,this.sheetViewHeight=1e3,this.gridOffsetX=0,this.gridOffsetY=0,this.sheetsWithDirtyViewports=new Set}allowDispatch(e){switch(e.type){case"SET_VIEWPORT_OFFSET":return this.checkScrollingDirection(e);case"RESIZE_SHEETVIEW":return this.chainValidations(this.checkValuesAreDifferent,this.checkPositiveDimension)(e);default:return 0}}handleEvent(e){switch(e.type){case"HeadersSelected":case"AlterZone":break;case"ZonesSelected":let{col:t,row:i}=so(e.previousAnchor.zone,e.anchor.zone);if("updateAnchor"===e.mode){const o=e.previousAnchor.zone,n=e.anchor.zone,{top:s,bottom:r,left:a,right:l}=this.getters.getActiveMainViewport();o.left===n.left&&o.right===n.right&&(t=a>t||t>l?a:t),o.top===n.top&&o.bottom===n.bottom&&(i=s>i||i>r?s:i)}const o=this.getters.getActiveSheetId();t=Math.min(t,this.getters.getNumberCols(o)-1),i=Math.min(i,this.getters.getNumberRows(o)-1),this.refreshViewport(this.getters.getActiveSheetId(),{col:t,row:i})}}handle(e){var t;switch(this.cleanViewports(),e.type){case"START":this.selection.observe(this,{handleEvent:this.handleEvent.bind(this)}),this.resetViewports(this.getters.getActiveSheetId());break;case"UNDO":case"REDO":this.resetSheetViews();break;case"RESIZE_SHEETVIEW":this.resizeSheetView(e.height,e.width,e.gridOffsetX,e.gridOffsetY);break;case"SET_VIEWPORT_OFFSET":this.setSheetViewOffset(e.offsetX,e.offsetY);break;case"SHIFT_VIEWPORT_DOWN":const{top:i}=this.getActiveMainViewport(),o=this.getters.getActiveSheetId(),n=this.clipOffsetY(this.getters.getRowDimensions(o,i).start+this.sheetViewHeight);this.shiftVertically(n);break;case"SHIFT_VIEWPORT_UP":{const{top:e}=this.getActiveMainViewport(),t=this.getters.getActiveSheetId(),i=this.clipOffsetY(this.getters.getRowDimensions(t,e).end-this.sheetViewHeight);this.shiftVertically(i);break}case"REMOVE_COLUMNS_ROWS":case"RESIZE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"UPDATE_FILTER":this.resetViewports(e.sheetId);break;case"UPDATE_CELL":("content"in e||"format"in e||void 0!==(null===(t=e.style)||void 0===t?void 0:t.fontSize))&&this.sheetsWithDirtyViewports.add(e.sheetId);break;case"ACTIVATE_SHEET":this.setViewports(),this.refreshViewport(e.sheetIdTo);break;case"UNFREEZE_ROWS":case"UNFREEZE_COLUMNS":case"FREEZE_COLUMNS":case"FREEZE_ROWS":case"UNFREEZE_COLUMNS_ROWS":this.resetViewports(this.getters.getActiveSheetId());break;case"DELETE_SHEET":this.sheetsWithDirtyViewports.delete(e.sheetId);break;case"START_EDITION":const{col:s,row:r}=this.getters.getActivePosition();this.refreshViewport(this.getters.getActiveSheetId(),{col:s,row:r})}}finalize(){for(const e of this.sheetsWithDirtyViewports)this.resetViewports(e);this.sheetsWithDirtyViewports=new Set,this.setViewports()}setViewports(){var e;const t=this.getters.getSheetIds();for(const i of t)(null===(e=this.viewports[i])||void 0===e?void 0:e.bottomRight)||this.resetViewports(i)}getColIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getColIndex(e))))}getRowIndex(e){const t=this.getters.getActiveSheetId();return Math.max(...this.getSubViewports(t).map((t=>t.getRowIndex(e))))}getSheetViewDimensionWithHeaders(){return{width:this.sheetViewWidth+this.gridOffsetX,height:this.sheetViewHeight+this.gridOffsetY}}getSheetViewDimension(){return{width:this.sheetViewWidth,height:this.sheetViewHeight}}getActiveMainViewport(){const e=this.getters.getActiveSheetId();return this.getMainViewport(e)}getActiveSheetScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetX,scrollY:t.offsetY}}getActiveSheetDOMScrollInfo(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e);return{scrollX:t.offsetScrollbarX,scrollY:t.offsetScrollbarY}}getSheetViewVisibleCols(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.left,e.right+1))).flat())].filter((t=>!this.getters.isHeaderHidden(e,"COL",t)))}getSheetViewVisibleRows(){const e=this.getters.getActiveSheetId(),t=this.getSubViewports(e);return[...new Set(t.map((e=>$e(e.top,e.bottom+1))).flat())].filter((t=>!this.getters.isHeaderHidden(e,"ROW",t)))}getMainViewportRect(){const e=this.getters.getActiveSheetId(),t=this.getMainInternalViewport(e),{xSplit:i,ySplit:o}=this.getters.getPaneDivisions(e);let{width:n,height:s}=t.getMaxSize();return{x:this.getters.getColDimensions(e,i).start,y:this.getters.getRowDimensions(e,o).start,width:n,height:s}}getMaximumSheetOffset(){const e=this.getters.getActiveSheetId(),{width:t,height:i}=this.getMainViewportRect(),o=this.getMainInternalViewport(e);return{maxOffsetX:Math.max(0,t-o.viewportWidth+1),maxOffsetY:Math.max(0,i-o.viewportHeight+1)}}getColRowOffsetInViewport(e,t,i){const o=this.getters.getActiveSheetId(),n=this.getters.getSheetViewVisibleCols(),s=this.getters.getSheetViewVisibleRows();if(i<t)return-this.getColRowOffsetInViewport(e,i,t);let r=0;const a="COL"===e?n:s;for(let n=t;n<i;n++)a.includes(n)&&(r+="COL"===e?this.getters.getColSize(o,n):this.getters.getRowSize(o,n));return r}isVisibleInViewport({sheetId:e,col:t,row:i}){return this.getSubViewports(e).some((e=>e.isVisible(t,i)))}getEdgeScrollCol(e,t,i){let o=!1,n=0,s=0;const{xSplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{width:a}=this.getSheetViewDimension(),{x:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollX;return e>a?(o=!0,s=Xt(e-a),n=1):e<l&&i>=l&&c>0?(o=!0,s=Xt(l-e),n=-1):r&&t<l&&e>l&&(o=!0,s=Xt(e),n="reset"),{canEdgeScroll:o,direction:n,delay:s}}getEdgeScrollRow(e,t,i){let o=!1,n=0,s=0;const{ySplit:r}=this.getters.getPaneDivisions(this.getters.getActiveSheetId()),{height:a}=this.getSheetViewDimension(),{y:l}=this.getMainViewportCoordinates(),c=this.getActiveSheetScrollInfo().scrollY;return e>a?(o=!0,s=Xt(e-a),n=1):e<l&&i>=l&&c>0?(o=!0,s=Xt(l-e),n=-1):r&&t<l&&e>l&&(o=!0,s=Xt(e),n="reset"),{canEdgeScroll:o,direction:n,delay:s}}getVisibleRect(e){const t=this.getters.getActiveSheetId(),i=this.getSubViewports(t).map((t=>t.getRect(e))).filter(ot);if(0===i.length)return{x:0,y:0,width:0,height:0};const o=Math.min(...i.map((e=>e.x))),n=Math.min(...i.map((e=>e.y))),s=Math.max(...i.map((e=>e.x+e.width)))-o,r=Math.max(...i.map((e=>e.y+e.height)))-n;return{x:o+this.gridOffsetX,y:n+this.gridOffsetY,width:s,height:r}}getMainViewportCoordinates(){const e=this.getters.getActiveSheetId(),{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e);return{x:this.getters.getColDimensions(e,t).start,y:this.getters.getRowDimensions(e,i).start}}ensureMainViewportExist(e){this.viewports[e]||this.resetViewports(e)}getSubViewports(e){return this.ensureMainViewportExist(e),Object.values(this.viewports[e]).filter(ot)}checkPositiveDimension(e){return e.width<0||e.height<0?68:0}checkValuesAreDifferent(e){const{height:t,width:i}=this.getSheetViewDimension();return e.gridOffsetX===this.gridOffsetX&&e.gridOffsetY===this.gridOffsetY&&e.width===i&&e.height===t?76:0}checkScrollingDirection({offsetX:e,offsetY:t}){const i=this.getMainInternalViewport(this.getters.getActiveSheetId());return!i.canScrollHorizontally&&e>0||!i.canScrollVertically&&t>0?69:0}getMainViewport(e){const t=this.getMainInternalViewport(e);return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}}getMainInternalViewport(e){return this.ensureMainViewportExist(e),this.viewports[e].bottomRight}cleanViewports(){const e=this.getters.getSheetIds();for(let t of Object.keys(this.viewports))e.includes(t)||delete this.viewports[t]}resetSheetViews(){for(let e of Object.keys(this.viewports)){const t=this.getters.getSheetPosition(e);this.resetViewports(e);const i=this.getSubViewports(e);Object.values(i).forEach((e=>{e.adjustPosition(t)}))}}resizeSheetView(e,t,i=0,o=0){this.sheetViewHeight=e,this.sheetViewWidth=t,this.gridOffsetX=i,this.gridOffsetY=o,this.recomputeViewports()}recomputeViewports(){for(let e of Object.keys(this.viewports))this.resetViewports(e)}setSheetViewOffset(e,t){const i=this.getters.getActiveSheetId(),{maxOffsetX:o,maxOffsetY:n}=this.getMaximumSheetOffset();Object.values(this.getSubViewports(i)).forEach((i=>i.setViewportOffset(Le(e,0,o),Le(t,0,n))))}clipOffsetY(e){const{height:t}=this.getMainViewportRect(),i=t-this.sheetViewHeight;return e=Math.min(e,i),e=Math.max(e,0)}getViewportOffset(e){var t,i;return{x:(null===(t=this.viewports[e])||void 0===t?void 0:t.bottomRight.offsetScrollbarX)||0,y:(null===(i=this.viewports[e])||void 0===i?void 0:i.bottomRight.offsetScrollbarY)||0}}resetViewports(e){if(!this.getters.tryGetSheet(e))return;const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),o=this.getters.getNumberCols(e),n=this.getters.getNumberRows(e),s=this.getters.getColRowOffset("COL",0,t,e),r=this.getters.getColRowOffset("ROW",0,i,e),{xRatio:a,yRatio:l}=this.getFrozenSheetViewRatio(e),c=a<1,h=l<1,d=this.getViewportOffset(e),u={topLeft:i&&t&&new eb(this.getters,e,{left:0,right:t-1,top:0,bottom:i-1},{width:s,height:r},{canScrollHorizontally:!1,canScrollVertically:!1},{x:0,y:0})||void 0,topRight:i&&new eb(this.getters,e,{left:t,right:o-1,top:0,bottom:i-1},{width:this.sheetViewWidth-s,height:r},{canScrollHorizontally:c,canScrollVertically:!1},{x:c?d.x:0,y:0})||void 0,bottomLeft:t&&new eb(this.getters,e,{left:0,right:t-1,top:i,bottom:n-1},{width:s,height:this.sheetViewHeight-r},{canScrollHorizontally:!1,canScrollVertically:h},{x:0,y:h?d.y:0})||void 0,bottomRight:new eb(this.getters,e,{left:t,right:o-1,top:i,bottom:n-1},{width:this.sheetViewWidth-s,height:this.sheetViewHeight-r},{canScrollHorizontally:c,canScrollVertically:h},{x:c?d.x:0,y:h?d.y:0})};this.viewports[e]=u}refreshViewport(e,t){Object.values(this.getSubViewports(e)).forEach((e=>{e.adjustViewportZone(),e.adjustPosition(t)}))}shiftVertically(e){const{top:t}=this.getActiveMainViewport(),{scrollX:i}=this.getActiveSheetScrollInfo();this.setSheetViewOffset(i,e);const{anchor:o}=this.getters.getSelection(),n=this.getActiveMainViewport().top-t;this.selection.selectCell(o.cell.col,o.cell.row+n)}getVisibleFigures(){const e=this.getters.getActiveSheetId(),t=[],i=this.getters.getFigures(e),{scrollX:o,scrollY:n}=this.getActiveSheetScrollInfo(),{x:s,y:r}=this.getters.getMainViewportCoordinates(),{width:a,height:l}=this.getters.getSheetViewDimensionWithHeaders();for(const e of i)e.x>=s&&(e.x+e.width<=s+o||e.x>=a+o+s)||e.y>=r&&(e.y+e.height<=r+n||e.y>=l+n+r)||t.push(e);return t}getFrozenSheetViewRatio(e){const{xSplit:t,ySplit:i}=this.getters.getPaneDivisions(e),o=this.getters.getColDimensions(e,t).start,n=this.getters.getRowDimensions(e,i).start;return{xRatio:o/(this.sheetViewWidth+this.gridOffsetX),yRatio:n/(this.sheetViewHeight+this.gridOffsetY)}}}tb.getters=["getColIndex","getRowIndex","getActiveMainViewport","getSheetViewDimension","getSheetViewDimensionWithHeaders","getMainViewportRect","isVisibleInViewport","getEdgeScrollCol","getEdgeScrollRow","getVisibleFigures","getVisibleRect","getColRowOffsetInViewport","getMainViewportCoordinates","getActiveSheetScrollInfo","getActiveSheetDOMScrollInfo","getSheetViewVisibleCols","getSheetViewVisibleRows","getFrozenSheetViewRatio"];class ib{constructor(e,t,i){this.index=0,this.cells=e,this.getters=t,this.direction=i}next(){const e=this.cells[this.index++%this.cells.length],t=e.rule,{cellData:i,tooltip:o}=In.get(t.type).apply(t,e.data,this.getters,this.direction);return{cellData:i,tooltip:o,origin:{col:e.data.col,row:e.data.row}}}}class ob extends Zv{constructor(){super(...arguments),this.lastCellSelected={}}allowDispatch(e){switch(e.type){case"AUTOFILL_SELECT":const t=this.getters.getActiveSheetId();return this.lastCellSelected.col=-1===e.col?this.lastCellSelected.col:Le(e.col,0,this.getters.getNumberCols(t)),this.lastCellSelected.row=-1===e.row?this.lastCellSelected.row:Le(e.row,0,this.getters.getNumberRows(t)),void 0!==this.lastCellSelected.col&&void 0!==this.lastCellSelected.row?0:45;case"AUTOFILL_AUTO":const i=this.getters.getSelectedZone();return i.top===i.bottom?0:1}return 0}handle(e){switch(e.type){case"AUTOFILL":this.autofill(!0);break;case"AUTOFILL_SELECT":this.select(e.col,e.row);break;case"AUTOFILL_AUTO":this.autofillAuto();break;case"AUTOFILL_CELL":this.autoFillMerge(e.originCol,e.originRow,e.col,e.row);const t=this.getters.getActiveSheetId();this.dispatch("UPDATE_CELL",{sheetId:t,col:e.col,row:e.row,style:e.style||null,content:e.content||"",format:e.format||""}),this.dispatch("SET_BORDER",{sheetId:t,col:e.col,row:e.row,border:e.border})}}getAutofillTooltip(){return this.tooltip}autofill(e){if(!this.autofillZone||!this.steps||void 0===this.direction)return void(this.tooltip=void 0);const t=this.getters.getSelectedZone(),i=this.autofillZone;switch(this.direction){case"down":for(let o=t.left;o<=t.right;o++){const n=[];for(let e=t.top;e<=t.bottom;e++)n.push(Gt(o,e));const s=this.createGenerator(n);for(let t=i.top;t<=i.bottom;t++)this.computeNewCell(s,o,t,e)}break;case"up":for(let o=t.left;o<=t.right;o++){const n=[];for(let e=t.bottom;e>=t.top;e--)n.push(Gt(o,e));const s=this.createGenerator(n);for(let t=i.bottom;t>=i.top;t--)this.computeNewCell(s,o,t,e)}break;case"left":for(let o=t.top;o<=t.bottom;o++){const n=[];for(let e=t.right;e>=t.left;e--)n.push(Gt(e,o));const s=this.createGenerator(n);for(let t=i.right;t>=i.left;t--)this.computeNewCell(s,t,o,e)}break;case"right":for(let o=t.top;o<=t.bottom;o++){const n=[];for(let e=t.left;e<=t.right;e++)n.push(Gt(e,o));const s=this.createGenerator(n);for(let t=i.left;t<=i.right;t++)this.computeNewCell(s,t,o,e)}}e&&(this.autofillZone=void 0,this.selection.resizeAnchorZone(this.direction,this.steps),this.lastCellSelected={},this.direction=void 0,this.steps=0,this.tooltip=void 0)}select(e,t){const i=this.getters.getSelectedZone();if(Ki(e,t,i))this.autofillZone=void 0;else{switch(this.direction=this.getDirection(e,t),this.direction){case"up":this.saveZone(t,i.top-1,i.left,i.right),this.steps=i.top-t;break;case"down":this.saveZone(i.bottom+1,t,i.left,i.right),this.steps=t-i.bottom;break;case"left":this.saveZone(i.top,i.bottom,e,i.left-1),this.steps=i.left-e;break;case"right":this.saveZone(i.top,i.bottom,i.right+1,e),this.steps=e-i.right}this.autofill(!1)}}autofillAuto(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();let i=e.left,o=e.bottom;if(i>0){let e=this.getters.getEvaluatedCell({sheetId:t,col:i-1,row:o});for(;e.type!==rn.empty;)o+=1,e=this.getters.getEvaluatedCell({sheetId:t,col:i-1,row:o})}if(o===e.bottom&&(i=e.right,i<=this.getters.getNumberCols(t))){let e=this.getters.getEvaluatedCell({sheetId:t,col:i+1,row:o});for(;e.type!==rn.empty;)o+=1,e=this.getters.getEvaluatedCell({sheetId:t,col:i+1,row:o})}o!==e.bottom&&(this.select(e.left,o-1),this.autofill(!0))}computeNewCell(e,t,i,o){const{cellData:n,tooltip:s,origin:r}=e.next(),{content:a,style:l,border:c,format:h}=n;this.tooltip=s,o&&this.dispatch("AUTOFILL_CELL",{originCol:r.col,originRow:r.row,col:t,row:i,content:a,style:l,border:c,format:h})}getRule(e,t){const i=Rn.getAll().sort(((e,t)=>e.sequence-t.sequence)).find((i=>i.condition(e,t)));return i&&i.generateRule(e,t)}createGenerator(e){const t=[],i=[],o=this.getters.getActiveSheetId();for(let t of e){const{col:e,row:n}=Wt(t),s=this.getters.getCell({sheetId:o,col:e,row:n});i.push({col:e,row:n,cell:s,sheetId:o})}const n=i.map((e=>e.cell));for(let e of i){let i={type:"COPY_MODIFIER"};if(e&&e.cell){i=this.getRule(e.cell,n)||i}const o=this.getters.getCellBorder(e)||void 0;t.push({data:{...e,border:o},rule:i})}return new ib(t,this.getters,this.direction)}saveZone(e,t,i,o){this.autofillZone={top:e,bottom:t,left:i,right:o}}getDirection(e,t){const i=this.getters.getSelectedZone(),o={up:{number:i.top-t,value:"up"},down:{number:t-i.bottom,value:"down"},left:{number:i.left-e,value:"left"},right:{number:e-i.right,value:"right"}};if(1===Object.values(o).map((e=>e.number>0?1:0)).reduce(((e,t)=>e+t)))return Object.values(o).find((e=>e.number>0?1:0)).value;const n=o.up.number>0?"up":"down",s=o.left.number>0?"left":"right";return Math.abs(o[n].number)>=Math.abs(o[s].number)?o[n].value:o[s].value}autoFillMerge(e,t,i,o){const n=this.getters.getActiveSheetId(),s={sheetId:n,col:i,row:o},r={sheetId:n,col:e,row:t};if(this.getters.isInMerge(s)&&!this.getters.isInMerge(r)){const e=this.getters.getMerge(s);e&&this.dispatch("REMOVE_MERGE",{sheetId:n,target:[e]})}const a=this.getters.getMerge(r);(null==a?void 0:a.topLeft.col)===e&&(null==a?void 0:a.topLeft.row)===t&&this.dispatch("ADD_MERGE",{sheetId:n,target:[{top:o,bottom:o+a.bottom-a.top,left:i,right:i+a.right-a.left}]})}drawGrid(e){if(!this.autofillZone)return;const{ctx:t,thinLineWidth:i}=e,{x:o,y:n,width:s,height:r}=this.getters.getVisibleRect(this.autofillZone);s>0&&r>0&&(t.strokeStyle="black",t.lineWidth=i,t.setLineDash([3]),t.strokeRect(o,n,s,r),t.setLineDash([]))}}ob.layers=[5],ob.getters=["getAutofillTooltip"];class nb extends Zv{handle(e){if("SUM_SELECTION"===e.type){const e=this.getters.getActiveSheetId(),{zones:t,anchor:i}=this.getters.getSelection();for(const o of t){const t=this.getAutomaticSums(e,o,i.cell);this.dispatchCellUpdates(e,t)}}}getAutomaticSums(e,t,i){return this.shouldFindData(e,t)?this.sumAdjacentData(e,t,i):this.sumData(e,t)}sumData(e,t){const i=this.dimensionsToSum(e,t),o=this.sumDimensions(e,t,i).filter((({zone:t})=>!this.getters.isEmpty(e,t)));return i.has("ROW")&&i.has("COL")&&o.push(this.sumTotal(t)),o}sumAdjacentData(e,t,i){const{col:o,row:n}=Ki(i.col,i.row,t)?i:{col:t.left,row:t.top},s=this.findAdjacentData(e,o,n);return s?this.getters.isSingleCellOrMerge(e,t)||io(Zi(s,t))?[{position:{col:o,row:n},zone:s}]:this.sumDimensions(e,Zi(s,t),this.transpose(this.dimensionsToSum(e,t))):[]}findAdjacentData(e,t,i){const o=this.getters.getSheet(e),n=this.getters.getMainCellPosition({sheetId:e,col:t,row:i}),s=this.findSuitableZoneToSum(o,n.col,n.row);if(s)return this.getters.expandZone(e,s)}findSuitableZoneToSum(e,t,i){const o=this.getters.getEvaluatedCell({sheetId:e.id,col:t,row:i-1}),n=this.getters.getEvaluatedCell({sheetId:e.id,col:t-1,row:i});if(this.isNumber(n)&&!this.isNumber(o))return this.findHorizontalZone(e,t,i);const s=this.findVerticalZone(e,t,i);if(this.isZoneValid(s))return s;const r=this.findHorizontalZone(e,t,i);return this.isZoneValid(r)?r:void 0}findVerticalZone(e,t,i){const o={top:0,bottom:i-1,left:t,right:t},n=this.reduceZoneStart(e,o,o.bottom);return{...o,top:n}}findHorizontalZone(e,t,i){const o={top:i,bottom:i,left:0,right:t-1},n=this.reduceZoneStart(e,o,o.right);return{...o,left:n}}reduceZoneStart(e,t,i){const o=this.getters.getEvaluatedCellsInZone(e.id,t),n=$e(i,-1,-1),s=n.filter((e=>o[e]&&!o[e].isAutoSummable)),r=Math.max(...s),a=We(n.filter((e=>this.isNumber(o[e]))))[0]||[];return Math.max(...a)<r?1/0:Math.min(...a)}shouldFindData(e,t){return this.getters.isEmpty(e,t)||this.getters.isSingleCellOrMerge(e,t)}isNumber(e){var t;return e.type===rn.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(Y))}isZoneValid(e){return e.bottom>=e.top&&e.right>=e.left}lastColIsEmpty(e,t){return this.getters.isEmpty(e,{...t,left:t.right})}lastRowIsEmpty(e,t){return this.getters.isEmpty(e,{...t,top:t.bottom})}dimensionsToSum(e,t){const i=new Set;return io(t)?(i.add(1===to(t).numberOfCols?"COL":"ROW"),i):(this.lastColIsEmpty(e,t)&&i.add("ROW"),this.lastRowIsEmpty(e,t)&&i.add("COL"),0===i.size&&i.add("COL"),i)}sumDimensions(e,t,i){return[...i.has("COL")?this.sumColumns(t,e):[],...i.has("ROW")?this.sumRows(t,e):[]]}sumTotal(e){const{bottom:t,right:i}=e;return{position:{col:i,row:t},zone:{...e,top:t,right:i-1}}}sumColumns(e,t){const i=this.nextEmptyRow(t,{...e,bottom:e.bottom-1});return e={...e,bottom:Math.min(e.bottom,i.bottom-1)},oo(i).map((t=>({position:t,zone:{...e,right:t.col,left:t.col}})))}sumRows(e,t){const i=this.nextEmptyCol(t,{...e,right:e.right-1});return e={...e,right:Math.min(e.right,i.right-1)},oo(i).map((t=>({position:t,zone:{...e,top:t.row,bottom:t.row}})))}dispatchCellUpdates(e,t){for(const i of t){const{col:t,row:o}=i.position;this.dispatch("UPDATE_CELL",{sheetId:e,col:t,row:o,content:`=SUM(${this.getters.zoneToXC(e,i.zone)})`})}}nextEmptyRow(e,t){let i=t.bottom+1;const{left:o,right:n}=t;for(;!this.getters.isEmpty(e,{bottom:i,top:i,left:o,right:n});)i++;return{...t,top:i,bottom:i}}nextEmptyCol(e,t){let i=t.right+1;const{top:o,bottom:n}=t;for(;!this.getters.isEmpty(e,{left:i,right:i,top:o,bottom:n});)i++;return{...t,left:i,right:i}}transpose(e){return new Set([...e.values()].map((e=>"COL"===e?"ROW":"COL")))}}nb.getters=["getAutomaticSums"];class sb extends Zv{allowDispatch(e){if("OPEN_CELL_POPOVER"===e.type){try{rs.get(e.popoverType)}catch(e){return 72}return 0}return 0}handle(e){switch(e.type){case"ACTIVATE_SHEET":case"CLOSE_CELL_POPOVER":this.persistentPopover=void 0;break;case"OPEN_CELL_POPOVER":this.persistentPopover={col:e.col,row:e.row,sheetId:this.getters.getActiveSheetId(),type:e.popoverType}}}getCellPopover({col:e,row:t}){var i,o;const n=this.getters.getActiveSheetId();if(this.persistentPopover&&this.getters.isVisibleInViewport(this.persistentPopover)){const e=this.getters.getMainCellPosition(this.persistentPopover),t=null===(o=(i=rs.get(this.persistentPopover.type)).onOpen)||void 0===o?void 0:o.call(i,e,this.getters);return(null==t?void 0:t.isOpen)?{...t,anchorRect:this.computePopoverAnchorRect(this.persistentPopover)}:{isOpen:!1}}if(void 0===e||void 0===t||!this.getters.isVisibleInViewport({sheetId:n,col:e,row:t}))return{isOpen:!1};const s=this.getters.getMainCellPosition({sheetId:n,col:e,row:t}),r=rs.getAll().map((e=>{var t;return null===(t=e.onHover)||void 0===t?void 0:t.call(e,s,this.getters)})).find((e=>null==e?void 0:e.isOpen));return(null==r?void 0:r.isOpen)?{...r,anchorRect:this.computePopoverAnchorRect(s)}:{isOpen:!1}}hasOpenedPopover(){return void 0!==this.persistentPopover}getPersistentPopoverTypeAtPosition({col:e,row:t}){if(this.persistentPopover&&this.persistentPopover.col===e&&this.persistentPopover.row===t)return this.persistentPopover.type}computePopoverAnchorRect({col:e,row:t}){const i=this.getters.getActiveSheetId(),o=this.getters.getMerge({sheetId:i,col:e,row:t});return o?this.getters.getVisibleRect(o):this.getters.getVisibleRect(ao({col:e,row:t}))}}sb.getters=["getCellPopover","getPersistentPopoverTypeAtPosition","hasOpenedPopover"];var rb;!function(e){e[e.previous=-1]="previous",e[e.current=0]="current",e[e.next=1]="next"}(rb||(rb={}));class ab extends Zv{constructor(){super(...arguments),this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1},this.toSearch="",this.isSearchDirty=!1}handle(e){switch(e.type){case"UPDATE_SEARCH":this.updateSearch(e.toSearch,e.searchOptions);break;case"CLEAR_SEARCH":this.clearSearch();break;case"SELECT_SEARCH_PREVIOUS_MATCH":this.selectNextCell(rb.previous);break;case"SELECT_SEARCH_NEXT_MATCH":this.selectNextCell(rb.next);break;case"REPLACE_SEARCH":this.replace(e.replaceWith);break;case"REPLACE_ALL_SEARCH":this.replaceAll(e.replaceWith);break;case"UNDO":case"REDO":case"REMOVE_FILTER_TABLE":case"UPDATE_FILTER":case"REMOVE_COLUMNS_ROWS":case"HIDE_COLUMNS_ROWS":case"UNHIDE_COLUMNS_ROWS":case"ADD_COLUMNS_ROWS":case"EVALUATE_CELLS":case"UPDATE_CELL":this.isSearchDirty=!0;break;case"ACTIVATE_SHEET":this.refreshSearch()}}finalize(){this.isSearchDirty&&(this.refreshSearch(),this.isSearchDirty=!1)}getSearchMatches(){return this.searchMatches}getCurrentSelectedMatchIndex(){return this.selectedMatchIndex}updateSearch(e,t){this.searchOptions=t,e!==this.toSearch&&(this.selectedMatchIndex=null),this.toSearch=e,this.updateRegex(),this.refreshSearch()}refreshSearch(){const e=this.findMatches();this.searchMatches=e,this.selectNextCell(rb.current)}updateRegex(){let e=_e(this.toSearch);const t=this.searchOptions.matchCase?"":"i";this.searchOptions.exactMatch&&(e=`^${e}$`),this.currentSearchRegex=RegExp(e,t)}findMatches(){const e=this.getters.getActiveSheetId(),t=this.getters.getCells(e),i=[];if(this.toSearch)for(const o of Object.values(t)){const{col:t,row:n}=this.getters.getCellPosition(o.id),s=this.getters.isColHidden(e,t),r=this.getters.isRowHidden(e,n);if(!s&&!r&&(o&&this.currentSearchRegex&&this.currentSearchRegex.test(this.getSearchableString({sheetId:e,col:t,row:n})))){const e={col:t,row:n,selected:!1};i.push(e)}}return i.sort(this.sortByRowThenColumn)}sortByRowThenColumn(e,t){return e.row===t.row?e.col-t.col:e.row>t.row?1:-1}selectNextCell(e){const t=this.searchMatches;if(!t.length)return void(this.selectedMatchIndex=null);let i;i=null===this.selectedMatchIndex?0:this.selectedMatchIndex+e,i=(i%t.length+t.length)%t.length,this.selectedMatchIndex=i,this.selection.selectCell(t[i].col,t[i].row);for(let e=0;e<this.searchMatches.length;e++)this.searchMatches[e].selected=e===this.selectedMatchIndex}clearSearch(){this.toSearch="",this.searchMatches=[],this.selectedMatchIndex=null,this.currentSearchRegex=null,this.searchOptions={matchCase:!1,exactMatch:!1,searchFormulas:!1}}replaceMatch(e,t){if(!this.currentSearchRegex)return;const i=this.getters.getActiveSheetId(),o=this.getters.getCell({sheetId:i,...e}),{col:n,row:s}=e;if((null==o?void 0:o.isFormula)&&!this.searchOptions.searchFormulas)return;const r=new RegExp(this.currentSearchRegex.source,this.currentSearchRegex.flags+"g"),a=this.getSearchableString({sheetId:i,col:n,row:s}).replace(r,t);this.dispatch("UPDATE_CELL",{sheetId:i,col:n,row:s,content:a})}replace(e){if(null===this.selectedMatchIndex)return;const t=this.searchMatches[this.selectedMatchIndex];this.replaceMatch(t,e),this.selectNextCell(rb.next)}replaceAll(e){const t=this.searchMatches.length;for(let i=0;i<t;i++)this.replaceMatch(this.searchMatches[i],e)}getSearchableString(e){const t=this.getters.getCell(e);return this.searchOptions.searchFormulas&&(null==t?void 0:t.isFormula)?t.content:this.getters.getEvaluatedCell(e).formattedValue}drawGrid(e){const{ctx:t}=e,i=this.getters.getActiveSheetId();for(const e of this.searchMatches){const o=this.getters.getMerge({sheetId:i,col:e.col,row:e.row}),n=o?o.left:e.col,s=o?o.right:e.col,r=o?o.top:e.row,a=o?o.bottom:e.row,{x:l,y:c,width:h,height:d}=this.getters.getVisibleRect({top:r,left:n,right:s,bottom:a});h>0&&d>0&&(t.fillStyle="#8B008B33",t.fillRect(l,c,h,d),e.selected&&(t.strokeStyle="#8B008B",t.strokeRect(l,c,h,d)))}}}ab.layers=[3],ab.getters=["getSearchMatches","getCurrentSelectedMatchIndex"];class lb extends Zv{isRowHidden(e,t){return this.getters.isRowHiddenByUser(e,t)||this.getters.isRowFiltered(e,t)}isColHidden(e,t){return this.getters.isColHiddenByUser(e,t)}isHeaderHidden(e,t,i){return"COL"===t?this.isColHidden(e,i):this.isRowHidden(e,i)}getNextVisibleCellPosition({sheetId:e,col:t,row:i}){return{sheetId:e,col:this.findVisibleHeader(e,"COL",t,this.getters.getNumberCols(e)-1),row:this.findVisibleHeader(e,"ROW",i,this.getters.getNumberRows(e)-1)}}findVisibleHeader(e,t,i,o){if(i<=o)for(let n=i;n<=o;n++)if(this.getters.doesHeaderExist(e,t,n)&&!this.isHeaderHidden(e,t,n))return n;if(i>o)for(let n=i;n>=o;n--)if(this.getters.doesHeaderExist(e,t,n)&&!this.isHeaderHidden(e,t,n))return n}findLastVisibleColRowIndex(e,t,{last:i,first:o}){return $e(i,o,-1).find((i=>!this.isHeaderHidden(e,t,i)))||o}findFirstVisibleColRowIndex(e,t){const i=this.getters.getNumberHeaders(e,t);for(let o=0;o<i;o++){if("COL"===t&&!this.isColHidden(e,o))return o;if("ROW"===t&&!this.isRowHidden(e,o))return o}}exportForExcel(e){for(const t of e.sheets)for(const[e,i]of Object.entries(t.rows)){const o=this.isRowHidden(t.id,Number(e));i.isHidden=o}}}lb.getters=["getNextVisibleCellPosition","findVisibleHeader","findLastVisibleColRowIndex","findFirstVisibleColRowIndex","isRowHidden","isColHidden","isHeaderHidden"];class cb extends Zv{getHighlights(){return this.prepareHighlights(this.getters.getComposerHighlights().concat(this.getters.getSelectionInputHighlights()))}prepareHighlights(e){return e.filter((e=>e.zone.top>=0&&e.zone.left>=0&&e.zone.bottom<this.getters.getNumberRows(e.sheetId)&&e.zone.right<this.getters.getNumberCols(e.sheetId))).map((e=>{const{numberOfRows:t,numberOfCols:i}=to(e.zone),o=t*i==1?this.getters.expandZone(e.sheetId,e.zone):e.zone;return{...e,zone:o}}))}drawGrid(e){const{ctx:t,thinLineWidth:i}=e,o=this.getters.getActiveSheetId(),n=3*i;t.lineWidth=n;const s=this.getHighlights();for(let e of s.filter(((e,t)=>s.findIndex((t=>Xi(t.zone,e.zone)&&t.sheetId===o))===t))){const{x:i,y:o,width:s,height:r}=this.getters.getVisibleRect(e.zone);s>0&&r>0&&(t.strokeStyle=e.color,t.strokeRect(i+n/2,o+n/2,s-n,r-n),t.globalCompositeOperation="source-over",t.fillStyle=e.color+"20",t.fillRect(i+n,o+n,s-2*n,r-2*n))}}}cb.layers=[1],cb.getters=["getHighlights"];class hb extends Zv{constructor(){super(...arguments),this.boxes=[]}getColDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleCols()),o=this.getters.getColRowOffsetInViewport("COL",i,t),n=this.getters.getColSize(e,t);return{start:o,size:n,end:o+(this.getters.isColHidden(e,t)?0:n)}}getRowDimensionsInViewport(e,t){const i=Math.min(...this.getters.getSheetViewVisibleRows()),o=this.getters.getColRowOffsetInViewport("ROW",i,t),n=this.getters.getRowSize(e,t);return{start:o,size:n,end:o+(this.getters.isRowHidden(e,t)?0:n)}}getHeaderOffset(e,t,i){let o=this.getters.getColRowOffsetInViewport(e,t,i);return this.getters.isDashboard()||(o+="ROW"===e?N:_),o}drawGrid(e,t){switch(t){case 0:this.boxes=this.getGridBoxes(),this.drawBackground(e),this.drawOverflowingCellBackground(e),this.drawCellBackground(e),this.drawBorders(e),this.drawTexts(e),this.drawIcon(e),this.drawFrozenPanes(e);break;case 7:this.getters.isDashboard()||(this.drawHeaders(e),this.drawFrozenPanesHeaders(e))}}drawBackground(e){const{ctx:t,thinLineWidth:i}=e,{width:o,height:n}=this.getters.getSheetViewDimensionWithHeaders();t.fillStyle="#ffffff",t.fillRect(0,0,o+m,n+m);const s=!this.getters.isDashboard()&&this.getters.getGridLinesVisibility(this.getters.getActiveSheetId()),r=s?.1*i:0;if(s)for(const e of this.boxes)t.strokeStyle="#E2E3E3",t.lineWidth=i,t.strokeRect(e.x+r,e.y+r,e.width-2*r,e.height-2*r)}drawCellBackground(e){const{ctx:t}=e;for(const e of this.boxes){let i=e.style;i.fillColor&&"#ffffff"!==i.fillColor&&(t.fillStyle=i.fillColor||"#ffffff",t.fillRect(e.x,e.y,e.width,e.height)),e.error&&(t.fillStyle="red",t.beginPath(),t.moveTo(e.x+e.width-5,e.y),t.lineTo(e.x+e.width,e.y),t.lineTo(e.x+e.width,e.y+5),t.fill())}}drawOverflowingCellBackground(e){var t,i;const{ctx:o,thinLineWidth:n}=e;for(const e of this.boxes)if(e.content&&e.isOverflow){const s=e.content.align||"left";let r,a;const l=e.y+n/2,c=e.height-n,h=Math.min((null===(t=e.clipRect)||void 0===t?void 0:t.width)||1/0,e.content.width);"left"===s?(r=e.x+n/2,a=h-2*n):"right"===s?(r=e.x+e.width-n/2,a=2*n-h):(r=((null===(i=e.clipRect)||void 0===i?void 0:i.x)||e.x+e.width/2-e.content.width/2)+n/2,a=h-2*n),o.fillStyle="#ffffff",o.fillRect(r,l,a,c)}}drawBorders(e){const{ctx:t,thinLineWidth:i}=e;for(let e of this.boxes){const t=e.border;if(t){const{x:i,y:n,width:s,height:r}=e;t.left&&o(t.left,i,n,i,n+r),t.top&&o(t.top,i,n,i+s,n),t.right&&o(t.right,i+s,n,i+s,n+r),t.bottom&&o(t.bottom,i,n+r,i+s,n+r)}}function o([e,o],n,s,r,a){t.strokeStyle=o,t.lineWidth=("thin"===e?2:3)*i,t.beginPath(),t.moveTo(n,s),t.lineTo(r,a),t.stroke()}}drawTexts(e){const{ctx:t,thinLineWidth:i}=e;let o;t.textBaseline="top";for(let e of this.boxes)if(e.content){const n=e.style||{},s=e.content.align||"left",r=Be(n);r!==o&&(o=r,t.font=r),t.fillStyle=n.textColor||"#000";let a=e.x;if(a+="left"===s?V+(e.image?e.image.size+U:0):"right"===s?e.width-V-(e.isFilterHeader?20:0):e.width/2,t.textAlign=s,e.clipRect){t.save(),t.beginPath();const{x:i,y:o,width:n,height:s}=e.clipRect;t.rect(i,o,n,s),t.clip()}const l=He(n),c=e.content.textLines.length;let h=this.computeTextYCoordinate(e,l,c);for(let o of e.content.textLines){if(t.fillText(o,Math.round(a),Math.round(h)),n.strikethrough||n.underline){const e=Ue(t,o,n);let r=a;"right"===s?r-=e:"center"===s&&(r-=e/2),n.strikethrough&&t.fillRect(r,h+l/2,e,2.6*i),n.underline&&t.fillRect(r,h+l+1,e,1.3*i)}h+=V+l}e.clipRect&&t.restore()}}drawIcon(e){const{ctx:t}=e;for(const e of this.boxes)if(e.image){const i=e.image.image;if(e.image.clipIcon){t.save(),t.beginPath();const{x:i,y:o,width:n,height:s}=e.image.clipIcon;t.rect(i,o,n,s),t.clip()}const o=e.image.size,n=this.computeTextYCoordinate(e,o);t.drawImage(i,e.x+U,n,o,o),e.image.clipIcon&&t.restore()}}computeTextYCoordinate(e,t,i=1){const o=e.y+1,n=Pe(t,i),s=e.height>n+2*V,r=e.verticalAlign||"middle";if(s){if("middle"===r)return o+(e.height-n)/2;if("bottom"===r)return o+e.height-n-V}return o+V}drawHeaders(e){const{ctx:t,thinLineWidth:i}=e,o=this.getters.getSheetViewVisibleCols(),n=o[0],s=o[o.length-1],r=this.getters.getSheetViewVisibleRows(),a=r[0],l=r[r.length-1],{width:c,height:h}=this.getters.getSheetViewDimensionWithHeaders(),d=this.getters.getSelectedZones(),u=function(e){const t=new Set;for(let i of e)for(let e of $e(i.left,i.right+1))t.add(e);return t}(d),g=function(e){const t=new Set;for(let i of e)for(let e of $e(i.top,i.bottom+1))t.add(e);return t}(d),p=this.getters.getActiveSheetId(),m=this.getters.getNumberCols(p),f=this.getters.getNumberRows(p),E=this.getters.getActiveCols(),w=this.getters.getActiveRows();t.font=`400 11px ${Z}`,t.textAlign="center",t.textBaseline="middle",t.lineWidth=i,t.strokeStyle="#333";for(let e=n;e<=s;e++){const i={left:e,right:e,top:0,bottom:f-1},{x:o,width:n}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(p,[i]),r=E.has(e),a=u.has(e);t.fillStyle=r?s?R:S:a?s?A:b:s?T:v,t.fillRect(o,0,n,N)}for(let e=a;e<=l;e++){const i={top:e,bottom:e,left:0,right:m-1},{y:o,height:n}=this.getters.getVisibleRect(i),s=this.getters.doesZonesContainFilter(p,[i]),r=w.has(e),a=g.has(e);t.fillStyle=r?s?R:S:a?s?A:b:s?T:v,t.fillRect(0,o,_,n)}t.beginPath(),t.moveTo(_,0),t.lineTo(_,h),t.moveTo(0,N),t.lineTo(c,N),t.strokeStyle="#C0C0C0",t.stroke(),t.beginPath();for(const e of o){const i=this.getters.getColSize(p,e),o=Ht(e);t.fillStyle=E.has(e)?"#fff":C;let s=this.getHeaderOffset("COL",n,e);t.fillText(o,s+i/2,13),t.moveTo(s+i,0),t.lineTo(s+i,N)}for(const e of r){const i=this.getters.getRowSize(p,e);t.fillStyle=w.has(e)?"#fff":C;let o=this.getHeaderOffset("ROW",a,e);t.fillText(String(e+1),24,o+i/2),t.moveTo(0,o+i),t.lineTo(_,o+i)}t.stroke()}drawFrozenPanesHeaders(e){const{ctx:t,thinLineWidth:i}=e,{x:o,y:n}=this.getters.getMainViewportCoordinates(),s=this.getters.isDashboard()?0:_,r=this.getters.isDashboard()?0:N;t.lineWidth=6*i,t.strokeStyle="#BCBCBC",t.beginPath(),o&&(t.moveTo(s+o,0),t.lineTo(s+o,r)),n&&(t.moveTo(0,r+n),t.lineTo(s,r+n)),t.stroke()}drawFrozenPanes(e){const{ctx:t,thinLineWidth:i}=e,{x:o,y:n}=this.getters.getMainViewportCoordinates(),s=this.getters.getSheetViewVisibleCols(),r=s[0],a=s[s.length-1],l=this.getters.getSheetViewVisibleRows(),c={left:r,right:a,top:l[0],bottom:l[l.length-1]},h=this.getters.getVisibleRect(c),d=this.getters.isDashboard()?0:_,u=this.getters.isDashboard()?0:N;t.lineWidth=6*i,t.strokeStyle="#DADFE8",t.beginPath(),o&&(t.moveTo(d+o,u),t.lineTo(d+o,h.height+u)),n&&(t.moveTo(d,u+n),t.lineTo(h.width+d,u+n)),t.stroke()}findNextEmptyCol(e,t,i){const o=this.getters.getActiveSheetId();let n=e;for(;n<t;){const e={sheetId:o,col:n+1,row:i},t=this.getters.getEvaluatedCell(e),s=this.getters.getCellBorderWithFilterBorder(e);if(t.type!==rn.empty||this.getters.isInMerge(e)||(null==s?void 0:s.left))return n;n++}return n}findPreviousEmptyCol(e,t,i){const o=this.getters.getActiveSheetId();let n=e;for(;n>t;){const e={sheetId:o,col:n-1,row:i},t=this.getters.getEvaluatedCell(e),s=this.getters.getCellBorderWithFilterBorder(e);if(t.type!==rn.empty||this.getters.isInMerge(e)||(null==s?void 0:s.right))return n;n--}return n}computeCellAlignment(e,t){const i=this.getters.getCell(e);if((null==i?void 0:i.isFormula)&&this.getters.shouldShowFormulas())return"left";const{align:o}=this.getters.getCellStyle(e),n=this.getters.getEvaluatedCell(e);return t&&n.type===rn.number?"center"!==o?"left":o:o||n.defaultAlign}createZoneBox(e,t,i){const{left:o,right:n}=i,s=t.left,r=t.top,a={sheetId:e,col:s,row:r},c=this.getters.getEvaluatedCell(a),h=this.getters.shouldShowFormulas(),{x:d,y:u,width:g,height:p}=this.getters.getVisibleRect(t),{verticalAlign:m}=this.getters.getCellStyle(a),f={x:d,y:u,width:g,height:p,border:this.getters.getCellBorderWithFilterBorder(a)||void 0,style:this.getters.getCellComputedStyle(a),verticalAlign:m};if(c.type===rn.empty)return f;const v=this.getters.getConditionalIcon(a),b=He(f.style),S=v?U+b:0;v&&(f.image={type:"icon",size:b,clipIcon:{x:f.x,y:f.y,width:Math.min(S,g),height:p},image:yg[v].img}),f.isFilterHeader=this.getters.isFilterHeader(a);const C=f.isFilterHeader?19:0,E=this.getters.getCellComputedStyle(a),w=E.wrapping||"overflow",y="wrap"!==w||h?void 0:g-2*V,x=this.getters.getCellMultiLineText(a,y),I=Math.max(...x.map((e=>this.getters.getTextWidth(e,E)+V))),R=S+I+C,T=this.computeCellAlignment(a,R>g);f.content={textLines:x,width:"overflow"===w?I:g,align:T},c.type===rn.error&&c.error.logLevel>l.silent&&(f.error=c.error.message);const A=R>g||b>p;if(v||f.isFilterHeader)f.clipRect={x:f.x+S,y:f.y,width:Math.max(0,g-S-C),height:p};else if(A&&"overflow"===w){let e,i;switch(this.getters.isInMerge(a)?(e=this.getters.getMerge(a).right,i=s):(e=this.findNextEmptyCol(s,n,r),i=this.findPreviousEmptyCol(s,o,r),f.isOverflow=!0),T){case"left":{const i=ao({col:e,row:r}),{x:o,y:n,width:s,height:a}=this.getters.getVisibleRect(Zi(t,i));(s<R||b>a||x.length>1)&&(f.clipRect={x:o,y:n,width:s,height:a});break}case"right":{const e=ao({col:i,row:r}),{x:o,y:n,width:s,height:a}=this.getters.getVisibleRect(Zi(t,e));(s<R||b>a||x.length>1)&&(f.clipRect={x:o,y:n,width:s,height:a});break}case"center":{const o={...t,left:i,right:e},{x:n,y:s,height:r,width:a}=this.getters.getVisibleRect(o),l=R/2,c=f.x+f.width/2;if(n+a<c+l||n>c-l||b>r||x.length>1){const e=n>c-l?n:c-l,t=n+a-e;f.clipRect={x:e,y:s,width:t,height:r}}break}}}else("clip"===w||"wrap"===w||x.length>1)&&(f.clipRect={x:f.x,y:f.y,width:g,height:p});return f}getGridBoxes(){const e=[],t=this.getters.getSheetViewVisibleCols(),i=t[0],o=t[t.length-1],n=this.getters.getSheetViewVisibleRows(),s={left:i,right:o,top:n[0],bottom:n[n.length-1]},r=this.getters.getActiveSheetId();for(const i of n)for(const o of t){const t={sheetId:r,col:o,row:i};this.getters.isInMerge(t)||e.push(this.createZoneBox(r,ao(t),s))}for(const t of this.getters.getMerges(r))if(!this.getters.isMergeHidden(r,t)&&Yi(t,s)){const i=this.createZoneBox(r,t,s),o=this.getters.getCellBorder({sheetId:r,col:t.right,row:t.bottom});i.border={...i.border,bottom:o?o.bottom:void 0,right:o?o.right:void 0},i.isMerge=!0,e.push(i)}return e}}hb.layers=[0,7],hb.getters=["getColDimensionsInViewport","getRowDimensionsInViewport"];class db extends Zv{constructor(e,t,i){if(i&&t.length>1)throw new Error("Input with a single range cannot be instantiated with several range references.");super(e),this.inputHasSingleRange=i,this.ranges=[],this.focusedRangeIndex=null,this.willAddNewRange=!1,this.insertNewRange(0,t),this.activeSheet=this.getters.getActiveSheetId(),0===this.ranges.length&&(this.insertNewRange(this.ranges.length,[""]),this.focusLast())}allowDispatch(e){switch(e.type){case"ADD_EMPTY_RANGE":if(this.inputHasSingleRange&&1===this.ranges.length)return 30;break;case"CHANGE_RANGE":if(this.inputHasSingleRange&&e.value.split(",").length>1)return 30}return 0}handleEvent(e){const t=Hi(e.anchor.zone),i=this.activeSheet,o=this.getters.getActiveSheetId(),n=this.getters.getSheetName(o);this.add([o===i?t:`${ke(n)}!${t}`])}handle(e){switch(e.type){case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"FOCUS_RANGE":this.focus(this.getIndex(e.rangeId));break;case"CHANGE_RANGE":{const t=this.getIndex(e.rangeId);if(null!==t&&this.focusedRangeIndex!==t&&this.focus(t),null!==t){const i=e.value.replace(/^,+/,"").split(",").map((e=>e.trim()));this.setRange(t,i)}break}case"ADD_EMPTY_RANGE":this.insertNewRange(this.ranges.length,[""]),this.focusLast();break;case"REMOVE_RANGE":const t=this.getIndex(e.rangeId);null!==t&&this.removeRange(t);break;case"STOP_SELECTION_INPUT":this.willAddNewRange=!1;break;case"PREPARE_SELECTION_INPUT_EXPANSION":{const e=this.focusedRangeIndex;null===e||this.inputHasSingleRange||(this.willAddNewRange=""!==this.ranges[e].xc.trim());break}case"ACTIVATE_SHEET":if(e.sheetIdFrom!==e.sheetIdTo){const{col:t,row:i}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0}),o=this.getters.expandZone(e.sheetIdTo,ao({col:t,row:i}));this.selection.resetAnchor(this,{cell:{col:t,row:i},zone:o})}}}getSelectionInputValue(){return this.cleanInputs(this.ranges.map((e=>e.xc?e.xc:"")))}getSelectionInputHighlights(){return this.ranges.map((e=>this.inputToHighlights(e))).flat()}focus(e){this.focusedRangeIndex=e}focusLast(){this.focus(this.ranges.length-1)}unfocus(){this.focusedRangeIndex=null}add(e){null!==this.focusedRangeIndex&&0!==e.length&&(this.willAddNewRange?(this.insertNewRange(this.ranges.length,e),this.focusLast(),this.willAddNewRange=!1):this.setRange(this.focusedRangeIndex,e))}setContent(e,t){this.ranges[e]={...this.ranges[e],xc:t}}insertNewRange(e,t){const i=Math.max(0,...this.ranges.map((e=>Number(e.id))));this.ranges.splice(e,0,...t.map(((e,t)=>({xc:e,id:i+t+1,color:Ct[(i+t)%Ct.length]}))))}setRange(e,t){const[,...i]=t;this.setContent(e,t[0]),this.insertNewRange(e+1,i),i.length&&this.focus(e+i.length)}removeRange(e){this.ranges.splice(e,1),null!==this.focusedRangeIndex&&this.focusLast()}inputToHighlights({xc:e,color:t}){const i=this.cleanInputs([e]).filter((e=>this.getters.isRangeValid(e))).filter((e=>this.shouldBeHighlighted(this.activeSheet,e)));return i.map((e=>{const{sheetName:i}=Bt(e);return{zone:this.getters.getRangeFromSheetXC(this.activeSheet,e).zone,sheetId:i&&this.getters.getSheetIdByName(i)||this.activeSheet,color:t}}))}cleanInputs(e){return e.map((e=>e.split(","))).flat().map((e=>e.trim())).filter((e=>""!==e))}shouldBeHighlighted(e,t){const{sheetName:i}=Bt(t),o=this.getters.getSheetIdByName(i),n=this.getters.getActiveSheet().id;return this.getters.isRangeValid(t)&&(o===n||void 0===o&&n===e)}getIndex(e){const t=this.ranges.findIndex((t=>t.id===e));return t>=0?t:null}}db.layers=[1],db.getters=[];class ub extends Zv{get currentInput(){return this.focusedInputId?this.inputs[this.focusedInputId]:null}constructor(e){super(e),this.config=e,this.inputs={},this.focusedInputId=null}allowDispatch(e){var t,i;if("FOCUS_RANGE"===e.type){const o=null===(t=this.currentInput)||void 0===t?void 0:t.getIndex(e.rangeId);if(this.focusedInputId===e.id&&(null===(i=this.currentInput)||void 0===i?void 0:i.focusedRangeIndex)===o)return 29}return this.currentInput?this.currentInput.allowDispatch(e):0}handle(e){var t;switch(e.type){case"ENABLE_NEW_SELECTION_INPUT":this.initInput(e.id,e.initialRanges||[],e.hasSingleRange);break;case"DISABLE_SELECTION_INPUT":this.focusedInputId===e.id&&this.unfocus(),delete this.inputs[e.id];break;case"UNFOCUS_SELECTION_INPUT":this.unfocus();break;case"ADD_EMPTY_RANGE":case"REMOVE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id];this.selection.capture(t,{cell:{col:0,row:0},zone:ao({col:0,row:0})},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}break;case"FOCUS_RANGE":case"CHANGE_RANGE":if(e.id!==this.focusedInputId){const t=this.inputs[e.id],i=t.ranges.find((t=>t.id===e.rangeId)),o=this.getters.getActiveSheetId(),n=this.getters.getRangeFromSheetXC(o,(null==i?void 0:i.xc)||"A1").zone;this.selection.capture(t,{cell:{col:n.left,row:n.top},zone:n},{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e.id}}null===(t=this.currentInput)||void 0===t||t.handle(e)}getSelectionInput(e){return this.inputs[e]?this.inputs[e].ranges.map(((t,i)=>Object.assign({},t,{color:this.focusedInputId===e&&null!==this.inputs[e].focusedRangeIndex&&this.isRangeValid(t.xc)?t.color:null,isFocused:this.focusedInputId===e&&this.inputs[e].focusedRangeIndex===i}))):[]}isRangeValid(e){if(!e)return!1;const{xc:t,sheetName:i}=Bt(e);return null!==t.match(Lt)&&(!i||void 0!==this.getters.getSheetIdByName(i))}getSelectionInputValue(e){return this.inputs[e].getSelectionInputValue()}getSelectionInputHighlights(){return this.focusedInputId?this.inputs[this.focusedInputId].getSelectionInputHighlights():[]}initInput(e,t,i=!1){if(this.inputs[e]=new db(this.config,t,i),0===t.length){const t=this.inputs[e],i={zone:ao({col:0,row:0}),cell:{col:0,row:0}};this.selection.capture(t,i,{handleEvent:t.handleEvent.bind(t)}),this.focusedInputId=e}}unfocus(){this.selection.release(this.currentInput),this.focusedInputId=null}}ub.layers=[1],ub.getters=["getSelectionInput","getSelectionInputValue","isRangeValid","getSelectionInputHighlights"];class gb{constructor(){this.subscriptions={}}on(e,t,i){if(!i)throw new Error("Missing callback");this.subscriptions[e]||(this.subscriptions[e]=[]),this.subscriptions[e].push({owner:t,callback:i})}trigger(e,t){const i=this.subscriptions[e]||[];for(let e=0,o=i.length;e<o;e++){const o=i[e];o.callback.call(o.owner,t)}}off(e,t){const i=this.subscriptions[e];i&&(this.subscriptions[e]=i.filter((e=>e.owner!==t)))}clear(){this.subscriptions={}}}function pb(e,t){return{...e,definition:Cr(e.definition,t)}}function mb(e,t){if(e.sheetId!==t.sheetId)return e;if(("FREEZE_COLUMNS"===e.type?"COL":"ROW")!==t.dimension)return e;let i=e.quantity;if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));for(let t of e)i>t&&i--}if("ADD_COLUMNS_ROWS"===t.type){i=i>("before"===t.position?t.base-1:t.base)?i+t.quantity:i}return i>0?{...e,quantity:i}:void 0}eg.addTransformation("ADD_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],pb),eg.addTransformation("REMOVE_COLUMNS_ROWS",["CREATE_CHART","UPDATE_CHART"],pb),eg.addTransformation("DELETE_SHEET",["MOVE_RANGES"],(function(e,t){const i=t.sheetId;if(e.targetSheetId===i||e.sheetId===i)return;return e})),eg.addTransformation("DELETE_FIGURE",["UPDATE_FIGURE","UPDATE_CHART"],(function(e,t){if(e.id===t.id)return;return e})),eg.addTransformation("CREATE_SHEET",["CREATE_SHEET"],(function(e,t){var i;if(e.name===t.name)return{...e,name:(null===(i=e.name)||void 0===i?void 0:i.match(/\d+/))?e.name.replace(/\d+/,(e=>(parseInt(e)+1).toString())):`${e.name}~`,position:e.position+1};return e})),eg.addTransformation("ADD_MERGE",["ADD_MERGE","REMOVE_MERGE","CREATE_FILTER_TABLE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;const i=[];for(const o of e.target)for(const e of t.target)Yi(o,e)||i.push({...o});if(i.length)return{...e,target:i};return})),eg.addTransformation("ADD_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],mb),eg.addTransformation("REMOVE_COLUMNS_ROWS",["FREEZE_COLUMNS","FREEZE_ROWS"],mb),eg.addTransformation("CREATE_FILTER_TABLE",["CREATE_FILTER_TABLE","ADD_MERGE"],(function(e,t){if(e.sheetId!==t.sheetId)return e;for(const i of e.target)for(const e of t.target)if(Yi(e,i))return;return e}));const fb=[{match:function(e){return"sheetId"in e},fn:Sb},{match:function(e){return"target"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;const o=[];for(const i of e.target){const e=cs(i,t);e&&o.push(e)}if(!o.length)return"IGNORE_COMMAND";return{...e,target:o}}},{match:function(e){return"col"in e&&"row"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type)return function(e,t){const i="COL"===t.dimension?"col":"row";let o=e[i];if("REMOVE_COLUMNS_ROWS"===t.type){const e=[...t.elements].sort(((e,t)=>t-e));if(e.includes(o))return"IGNORE_COMMAND";for(let t of e)o>=t&&o--}"ADD_COLUMNS_ROWS"===t.type&&(o>t.base||o===t.base&&"before"===t.position)&&(o+=t.quantity);return{...e,[i]:o}}(e,t);if("ADD_MERGE"===t.type)return function(e,t){for(const i of t.target){if(!(e.col===i.left&&e.row===i.top)&&Ki(e.col,e.row,i))return"IGNORE_COMMAND"}return e}(e,t);return"SKIP_TRANSFORMATION"}},{match:function(e){return"dimension"in e&&"sheetId"in e},fn:function(e,t){const i=Sb(e,t);if("SKIP_TRANSFORMATION"!==i)return"IGNORE_COMMAND"===i?"IGNORE_COMMAND":e;if("ADD_COLUMNS_ROWS"===t.type||"REMOVE_COLUMNS_ROWS"===t.type){if(t.dimension!==e.dimension)return e;const i="ADD_COLUMNS_ROWS"===e.type,o=i?"base":"elements";let n=i?[e[o]]:e[o];if("REMOVE_COLUMNS_ROWS"===t.type&&(n=n.map((e=>{if(t.elements.includes(e))return;const i=t.elements.sort(((e,t)=>t-e));for(let t of i)e>t&&e--;return e})).filter(ot)),"ADD_COLUMNS_ROWS"===t.type){const e="before"===t.position?t.base-1:t.base;n=n.map((i=>i>e?i+t.quantity:i))}if(n.length){let t=n;return i&&(t=n[0]),{...e,[o]:t}}return"IGNORE_COMMAND"}return"SKIP_TRANSFORMATION"}},{match:function(e){return"ranges"in e},fn:function(e,t){const i=[],o="DELETE_SHEET"===t.type&&t.sheetId;for(const n of e.ranges)if(n._sheetId!==t.sheetId)i.push({...n,_zone:n._zone});else{const e=cs(n._zone,t);e&&o!==n._sheetId&&i.push({...n,_zone:e})}if(!i.length)return"IGNORE_COMMAND";return{...e,ranges:i}}}];function vb(e,t){const i=eg.getTransformation(e.type,t.type);return i?i(e,t):function(e,t){for(const{match:i,fn:o}of fb)if(i(e)){const i=o(e,t);if("SKIP_TRANSFORMATION"===i)continue;if("IGNORE_COMMAND"===i)return;e=i}return e}(e,t)}function bb(e,t){let i=[...e];for(const e of t)i=i.map((t=>vb(t,e))).filter(ot);return i}function Sb(e,t){const i="DELETE_SHEET"===t.type&&t.sheetId;return e.sheetId===i?"IGNORE_COMMAND":"CREATE_SHEET"===e.type||"CREATE_SHEET"===t.type||e.sheetId!==t.sheetId?e:"SKIP_TRANSFORMATION"}class Cb{constructor(e,t,i,o){this._commands=[],this._changes=[],this.id=e,this.clientId=t,this._commands=[...i],this._changes=o?[...o]:[]}setChanges(e){this._changes=e}get commands(){return this._commands}get changes(){return this._changes}}class Eb extends Error{}class wb extends gb{constructor(e,t,i=Q){super(),this.revisions=e,this.transportService=t,this.serverRevisionId=i,this.clients={},this.clientId="local",this.pendingMessages=[],this.waitingAck=!1,this.waitingUndoRedoAck=!1,this.isReplayingInitialRevisions=!1,this.processedRevisions=new Set,this.uuidGenerator=new Ui,this.debouncedMove=function(e,t,i){let o;return function(){const n=this,s=arguments,r=i&&!o;clearTimeout(o),o=setTimeout((function(){o=null,i||e.apply(n,s)}),t),r&&e.apply(n,s)}}(this._move.bind(this),200)}canApplyOptimisticUpdate(){return!this.waitingUndoRedoAck}save(e,t){if(!e.length||!t.length||!this.canApplyOptimisticUpdate())return;const i=new Cb(this.uuidGenerator.uuidv4(),this.clientId,e,t);this.revisions.append(i.id,i),this.trigger("new-local-state-update",{id:i.id}),this.sendUpdateMessage({type:"REMOTE_REVISION",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:i.id,clientId:i.clientId,commands:i.commands})}undo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_UNDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),undoneRevisionId:e})}redo(e){this.waitingUndoRedoAck=!0,this.sendUpdateMessage({type:"REVISION_REDONE",version:1,serverRevisionId:this.serverRevisionId,nextRevisionId:this.uuidGenerator.uuidv4(),redoneRevisionId:e})}move(e){this.debouncedMove(e)}join(e){e?(this.clients[e.id]=e,this.clientId=e.id):(this.clients.local={id:"local",name:"local"},this.clientId="local"),this.transportService.onNewMessage(this.clientId,this.onMessageReceived.bind(this))}loadInitialMessages(e){this.isReplayingInitialRevisions=!0;for(const t of e)this.onMessageReceived(t);this.isReplayingInitialRevisions=!1}leave(){delete this.clients[this.clientId],this.transportService.leave(this.clientId),this.transportService.sendMessage({type:"CLIENT_LEFT",clientId:this.clientId,version:1})}snapshot(e){const t=this.uuidGenerator.uuidv4();this.transportService.sendMessage({type:"SNAPSHOT",nextRevisionId:t,serverRevisionId:this.serverRevisionId,data:{...e,revisionId:t},version:1})}getClient(){const e=this.clients[this.clientId];if(!e)throw new Eb("The client left the session");return e}getConnectedClients(){return new Set(Object.values(this.clients).filter(ot))}getRevisionId(){return this.serverRevisionId}isFullySynchronized(){return 0===this.pendingMessages.length}_move(e){var t;if(!this.clients[this.clientId])return;const i=null===(t=this.clients[this.clientId])||void 0===t?void 0:t.position;if((null==i?void 0:i.col)===e.col&&i.row===e.row&&i.sheetId===e.sheetId)return;const o=i?"CLIENT_MOVED":"CLIENT_JOINED",n=this.getClient();this.clients[this.clientId]={...n,position:e},this.transportService.sendMessage({type:o,version:1,client:{...n,position:e}})}onMessageReceived(e){if(!this.isAlreadyProcessed(e))if(this.isWrongServerRevisionId(e))this.trigger("unexpected-revision-id");else{switch(e.type){case"CLIENT_MOVED":this.onClientMoved(e);break;case"CLIENT_JOINED":this.onClientJoined(e);break;case"CLIENT_LEFT":this.onClientLeft(e);break;case"REVISION_REDONE":this.revisions.redo(e.redoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-redone",{revisionId:e.redoneRevisionId,commands:this.revisions.get(e.redoneRevisionId).commands});break;case"REVISION_UNDONE":this.revisions.undo(e.undoneRevisionId,e.nextRevisionId,e.serverRevisionId),this.trigger("revision-undone",{revisionId:e.undoneRevisionId,commands:this.revisions.get(e.undoneRevisionId).commands});break;case"REMOTE_REVISION":const{clientId:t,commands:i}=e,o=new Cb(e.nextRevisionId,t,i);if(o.clientId!==this.clientId){this.revisions.insert(o.id,o,e.serverRevisionId);const t=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.commands)).flat();this.trigger("remote-revision-received",{commands:bb(i,t)})}break;case"SNAPSHOT_CREATED":{const t=new Cb(e.nextRevisionId,"server",[]);this.revisions.insert(t.id,t,e.serverRevisionId),this.dropPendingHistoryMessages(),this.trigger("snapshot");break}}this.acknowledge(e),this.trigger("collaborative-event-received")}}onClientMoved(e){e.client.id!==this.clientId&&(this.clients[e.client.id]=e.client)}onClientJoined(e){if(e.client.id!==this.clientId){this.clients[e.client.id]=e.client;const t=this.clients[this.clientId];if(t){const{position:e}=t;e&&this.transportService.sendMessage({type:"CLIENT_MOVED",version:1,client:{...t,position:e}})}}}onClientLeft(e){e.clientId!==this.clientId&&delete this.clients[e.clientId]}sendUpdateMessage(e){this.pendingMessages.push(e),this.waitingAck||(this.waitingAck=!0,this.sendPendingMessage())}sendPendingMessage(){let e=this.pendingMessages[0];if(e){if("REMOTE_REVISION"===e.type){const t=this.revisions.get(e.nextRevisionId);if(0===t.commands.length){this.revisions.drop(t.id);const e=this.pendingMessages.filter((e=>"REMOTE_REVISION"===e.type)).map((e=>e.nextRevisionId));return this.trigger("pending-revisions-dropped",{revisionIds:e}),this.waitingAck=!1,this.waitingUndoRedoAck=!1,void(this.pendingMessages=[])}e={...e,clientId:t.clientId,commands:t.commands}}if(this.isReplayingInitialRevisions)throw new Error(`Trying to send a new revision while replaying initial revision. This can lead to endless dispatches every time the spreadsheet is open.\n ${JSON.stringify(e)}`);this.transportService.sendMessage({...e,serverRevisionId:this.serverRevisionId})}}acknowledge(e){switch("REVISION_UNDONE"!==e.type&&"REVISION_REDONE"!==e.type||(this.waitingUndoRedoAck=!1),e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":this.waitingAck=!1,this.pendingMessages=this.pendingMessages.filter((t=>t.nextRevisionId!==e.nextRevisionId)),this.serverRevisionId=e.nextRevisionId,this.processedRevisions.add(e.nextRevisionId),this.sendPendingMessage()}}isAlreadyProcessed(e){if("CLIENT_MOVED"===e.type&&e.client.id===this.clientId)return!0;switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":return this.processedRevisions.has(e.nextRevisionId);default:return!1}}isWrongServerRevisionId(e){switch(e.type){case"REMOTE_REVISION":case"REVISION_REDONE":case"REVISION_UNDONE":case"SNAPSHOT_CREATED":return e.serverRevisionId!==this.serverRevisionId;default:return!1}}dropPendingHistoryMessages(){this.waitingUndoRedoAck=!1,this.pendingMessages=this.pendingMessages.filter((({type:e})=>"REVISION_REDONE"!==e&&"REVISION_UNDONE"!==e))}}const yb=["#ff851b","#0074d9","#7fdbff","#b10dc9","#39cccc","#f012be","#3d9970","#111111","#ff4136","#aaaaaa","#85144b","#001f3f"];class xb extends Zv{constructor(){super(...arguments),this.availableColors=new Set(yb),this.colors={}}isPositionValid(e){return e.row<this.getters.getNumberRows(e.sheetId)&&e.col<this.getters.getNumberCols(e.sheetId)}chooseNewColor(){0===this.availableColors.size&&(this.availableColors=new Set(yb));const e=(t=[...this.availableColors.values()])[Math.floor(Math.random()*t.length)];var t;return this.availableColors.delete(e),e}getClientsToDisplay(){try{this.getters.getClient()}catch(e){if(e instanceof Eb)return[];throw e}const e=this.getters.getActiveSheetId(),t=[];for(const i of this.getters.getConnectedClients())if(i.id!==this.getters.getClient().id&&i.position&&i.position.sheetId===e&&this.isPositionValid(i.position)){const e=i.position;this.colors[i.id]||(this.colors[i.id]=this.chooseNewColor());const o=this.colors[i.id];t.push({...i,position:e,color:o})}return t}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,o=this.getters.getActiveSheetId();for(const e of this.getClientsToDisplay()){const{row:n,col:s}=e.position,r=this.getters.expandZone(o,{top:n,bottom:n,left:s,right:s}),{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);if(c<=0||h<=0)continue;const d=e.color,u=`${d}10`;t.fillStyle=u,t.lineWidth=4*i,t.strokeStyle=d,t.globalCompositeOperation="multiply",t.fillRect(a,l,c,h),t.globalCompositeOperation="source-over",t.strokeRect(a,l,c,h),t.font=`bold ${q+1}px ${Z}`}}}xb.getters=["getClientsToDisplay"],xb.layers=[6];class Ib extends Zv{allowDispatch(e){if("SORT_CELLS"===e.type){if(!Ki(e.col,e.row,e.zone))throw new Error(s("The anchor must be part of the provided zone"));return this.checkValidations(e,this.checkMerge,this.checkMergeSizes)}return 0}handle(e){if("SORT_CELLS"===e.type)this.sortZone(e.sheetId,e,e.zone,e.sortDirection,e.sortOptions||{})}checkMerge({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;return oo(t).some((({col:t,row:i})=>!this.getters.isInMerge({sheetId:e,col:t,row:i})))?63:0}checkMergeSizes({sheetId:e,zone:t}){if(!this.getters.doesIntersectMerge(e,t))return 0;const i=this.getters.getMerges(e).filter((e=>Yi(e,t))),o=to(i[0]);let[n,s]=[o.numberOfCols,o.numberOfRows];return i.every((e=>{let[t,i]=[e.right-e.left+1,e.bottom-e.top+1];return t===n&&i===s}))?0:63}expand(e,t){const{left:i,right:o,top:n,bottom:s}=this.getters.expandZone(e,t);return{left:Math.max(0,i),right:Math.min(this.getters.getNumberCols(e)-1,o),top:Math.max(0,n),bottom:Math.min(this.getters.getNumberRows(e)-1,s)}}checkExpandedValues(e,t){const i=this.expand(e,t);let o;if(this.getters.doesIntersectMerge(e,i)){const{left:t,right:n,top:s,bottom:r}=i;for(let i=t;i<=n;i++)for(let t=s;t<=r;t++){const{col:n,row:s}=this.getters.getMainCellPosition({sheetId:e,col:i,row:t});if(o=this.getters.getEvaluatedCell({sheetId:e,col:n,row:s}),o.formattedValue)return!0}}else for(let t of this.getters.getEvaluatedCellsInZone(e,i))if(t.formattedValue)return!0;return!1}getContiguousZone(e,t){let i,{top:o,bottom:n,left:s,right:r}=t,a=!1;for(;!a;)a=!0,o>0&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:o-1,bottom:o-1}),i&&(a=!1,o--)),s>0&&(i=this.checkExpandedValues(e,{left:s-1,right:s-1,top:o-1,bottom:n+1}),i&&(a=!1,s--)),r<this.getters.getNumberCols(e)-1&&(i=this.checkExpandedValues(e,{left:r+1,right:r+1,top:o-1,bottom:n+1}),i&&(a=!1,r++)),n<this.getters.getNumberRows(e)-1&&(i=this.checkExpandedValues(e,{left:s-1,right:r+1,top:n+1,bottom:n+1}),i&&(a=!1,n++));return{left:s,right:r,top:o,bottom:n}}hasHeader(e,t){if(1===t[0].length)return!1;let i=t.map((t=>t.map((({col:t,row:i})=>this.getters.getEvaluatedCell({sheetId:e,col:t,row:i}).type))));return i[0][0]===rn.empty&&(i=i.slice(1)),!i.some((e=>e[0]===rn.empty))&&!!i.some((e=>e[1]!==rn.empty&&e[0]!==e[1]))}sortZone(e,t,i,o,n){const[s,r]=this.mainCellsSteps(e,i);let a=this.getters.getMainCellPosition({sheetId:e,col:t.col,row:t.row}).col,l=Object.assign({},i),c=this.mainCells(e,i);!n.sortHeaders&&this.hasHeader(e,c)&&(l.top+=r),c=this.mainCells(e,l);const h=function(e,t,i){const o=e.map(((e,t)=>({index:t,type:e.type,value:e.value})));let n=o.filter((e=>e.type===rn.empty)),s=o.filter((e=>e.type!==rn.empty));i&&(s.push(...n.map((e=>({...e,type:rn.number,value:0})))),n=[]);const r="descending"===t?-1:1;return s.sort(((e,t)=>{let i=wr.indexOf(e.type)-wr.indexOf(t.type);return 0===i&&(i=e.type===rn.text||e.type===rn.error?e.value.localeCompare(t.value):e.value-t.value),r*i})).concat(n)}(c[a-l.left].map((e=>this.getters.getEvaluatedCell(e))),o,Boolean(n.emptyCellAsZero)),d=h.map((e=>e.index)),[u,g]=[c.length,c[0].length],p=[];for(let e=0;e<u;e++)for(let t=0;t<g;t++){let{col:i,row:o,sheetId:n}=c[e][d[t]];const a=this.getters.getCell({sheetId:n,col:i,row:o});let h=l.left+e*s,u=l.top+t*r,g={sheetId:n,col:h,row:u,content:""};if(a){let e=a.content;if(a.isFormula){const t=u-this.getters.getCellPosition(a.id).row,i=this.getters.createAdaptedRanges(a.dependencies,0,t,n);e=this.getters.buildFormulaContent(n,a,i)}g.style=a.style,g.content=e,g.format=a.format}p.push(g)}p.forEach((e=>this.dispatch("UPDATE_CELL",e)))}mainCellsSteps(e,t){const i=this.getters.getMerge({sheetId:e,col:t.left,row:t.top});return[i?i.right-i.left+1:1,i?i.bottom-i.top+1:1]}mainCells(e,t){const[i,o]=this.mainCellsSteps(e,t),n=[],s=$e(t.left,t.right+1,i),r=$e(t.top,t.bottom+1,o);for(const t of s){const i=[];n.push(i);for(const o of r)i.push({sheetId:e,col:t,row:o})}return n}}Ib.getters=["getContiguousZone"];class Rb extends Zv{constructor(){super(...arguments),this.showFormulas=!1}handle(e){if("SET_FORMULA_VISIBILITY"===e.type)this.showFormulas=e.show}shouldShowFormulas(){return this.showFormulas}}Rb.getters=["shouldShowFormulas"];class Tb extends Zv{constructor(){super(...arguments),this.ctx=document.createElement("canvas").getContext("2d")}allowDispatch(e){switch(e.type){case"AUTORESIZE_ROWS":case"AUTORESIZE_COLUMNS":try{this.getters.getSheet(e.sheetId);break}catch(e){return 27}}return 0}handle(e){switch(e.type){case"AUTORESIZE_COLUMNS":for(let t of e.cols){const i=this.getColMaxWidth(e.sheetId,t);0!==i&&this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"COL",size:i,sheetId:e.sheetId})}break;case"AUTORESIZE_ROWS":for(let t of e.rows)this.dispatch("RESIZE_COLUMNS_ROWS",{elements:[t],dimension:"ROW",size:null,sheetId:e.sheetId})}}getCellWidth(e){const t=this.getCellText(e),i=this.getters.getCellComputedStyle(e),o=t.split(he);let n=Math.max(...o.map((e=>this.getTextWidth(e,i))));this.getters.getConditionalIcon(e)&&(n+=function(e){return He(e)+2*U}(this.getters.getCellStyle(e)));if(this.getters.isFilterHeader(e)&&(n+=20),n>0&&(n+=2*B,"wrap"===this.getters.getCellStyle(e).wrapping)){const t=this.getters.getColSize(this.getters.getActiveSheetId(),e.col);return Math.min(t,n)}return n}getTextWidth(e,t){return Ue(this.ctx,e,t)}getCellText(e,t=!1){const i=this.getters.getCell(e);return t&&(null==i?void 0:i.isFormula)?i.content:this.getters.getEvaluatedCell(e).formattedValue}getCellMultiLineText(e,t){const i=this.getters.getCellStyle(e),o=this.getters.getCellText(e,this.getters.shouldShowFormulas()),n=[];for(const e of o.split("\n")){const o=e.split(" ");if(!t){n.push(e);continue}let s="",r=t;for(let e of o){const o=this.splitWordToSpecificWidth(this.ctx,e,t,i),a=o.pop(),l=Ue(this.ctx,a,i);if(o.length)""!==s&&(n.push(s),s="",r=t),o.forEach((e=>{n.push(e)})),s=a,r=t-l;else{const e=""===s?a:" "+a,o=Ue(this.ctx,e,i);o<=r?(s+=e,r-=o):(n.push(s),s=a,r=t-l)}}""!==s&&n.push(s)}return n}getColDimensions(e,t){const i=this.getColRowOffset("COL",0,t,e),o=this.getters.getColSize(e,t);return{start:i,size:o,end:i+(this.getters.isColHidden(e,t)?0:o)}}getRowDimensions(e,t){const i=this.getColRowOffset("ROW",0,t,e),o=this.getters.getRowSize(e,t);return{start:i,size:o,end:i+(this.getters.isRowHidden(e,t)?0:o)}}getColRowOffset(e,t,i,o=this.getters.getActiveSheetId()){if(i<t)return-this.getColRowOffset(e,i,t);let n=0;for(let s=t;s<i;s++)this.getters.isHeaderHidden(o,e,s)||(n+="COL"===e?this.getters.getColSize(o,s):this.getters.getRowSize(o,s));return n}getColMaxWidth(e,t){const i=oo(this.getters.getColsZone(e,t,t)).map((t=>this.getCellWidth({sheetId:e,...t})));return Math.max(0,...i)}splitWordToSpecificWidth(e,t,i,o){if(Ue(e,t,o)<=i)return[t];const n=[];let s="";for(let r of t){Ue(e,s+r,o)>i?(n.push(s),s=r):s+=r}return n.push(s),n}}Tb.getters=["getCellWidth","getTextWidth","getCellText","getCellMultiLineText","getColDimensions","getRowDimensions","getColRowOffset"];class Ab{constructor(e,t,i,o){this.getters=t,this.dispatch=i,this.selection=o,this.operation=e,this.sheetId=t.getActiveSheetId()}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0}addMissingDimensions(e,t,i,o){const n=this.getters.getActiveSheetId(),s=t+o-this.getters.getNumberRows(n);s>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"ROW",base:this.getters.getNumberRows(n)-1,sheetId:n,quantity:s,position:"after"});const r=e+i-this.getters.getNumberCols(n);r>0&&this.dispatch("ADD_COLUMNS_ROWS",{dimension:"COL",base:this.getters.getNumberCols(n)-1,sheetId:n,quantity:r,position:"after"})}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Mb extends Ab{constructor(e,t,i,o,n){if(super(t,i,o,n),!e.length)return this.cells=[[]],this.zones=[],void(this.copiedTables=[]);const s=new Set(e.map((e=>e.left))),r=new Set(e.map((e=>e.right))),a=new Set(e.map((e=>e.top))),l=new Set(e.map((e=>e.bottom))),c=1===a.size&&1===l.size||1===s.size&&1===r.size?function(e){return e.reduce(((e,t)=>{const i=e.length;for(let o=0;o<i;o++)if(Yi(e[o],t))return e[o]=Zi(e[o],t),e;return e[i]=t,e}),[])}(e):[e[e.length-1]],h=c.map((e=>oo(e))).flat(),d=[...new Set(h.map((e=>e.col)))].sort(((e,t)=>e-t)),u=[...new Set(h.map((e=>e.row)))].sort(((e,t)=>e-t)),g=[],p=i.getActiveSheetId();for(let e of u){let t=[];for(let o of d){const n={col:o,row:e,sheetId:p};t.push({cell:i.getCell(n),style:i.getCellComputedStyle(n),evaluatedCell:i.getEvaluatedCell(n),border:i.getCellBorder(n)||void 0,position:n})}g.push(t)}const m=[];for(const t of e)for(const e of this.getters.getFilterTablesInZone(p,t)){const t=[];for(const i of $e(e.zone.left,e.zone.right+1))t.push(this.getters.getFilterValues({sheetId:p,col:i,row:e.zone.top}));m.push({filtersValues:t,zone:e.zone})}this.cells=g,this.zones=c,this.copiedTables=m}isCutAllowed(e){return 1!==e.length?19:0}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId();if("CUT"===this.operation&&void 0!==(null==t?void 0:t.pasteOption))return 21;if(e.length>1&&(this.cells.length>1||this.cells[0].length>1))return 20;const o=this.cells.length,n=this.cells[0].length;for(let t of this.getPasteZones(e))if(this.getters.doesIntersectMerge(i,t)&&(e.length>1||!this.getters.isSingleCellOrMerge(i,e[0])||o*n!=1))return 2;const{xSplit:s,ySplit:r}=this.getters.getPaneDivisions(i);for(const t of this.getPasteZones(e))if(t.left<s&&t.right>=s||t.top<r&&t.bottom>=r)return 75;return 0}paste(e,t){"COPY"===this.operation?this.pasteFromCopy(e,t):this.pasteFromCut(e,t);const i=this.cells.length,o=this.cells[0].length,n="CUT"===this.operation;(null==t?void 0:t.selectTarget)&&this.selectPastedZone(o,i,n,e)}pasteFromCopy(e,t){if(1===e.length){const i=this.cells.length,o=this.cells[0].length,n=this.pastedZones(e,o,i);for(const e of n)this.pasteZone(e.left,e.top,t)}else for(const i of e)for(let e=i.left;e<=i.right;e++)for(let o=i.top;o<=i.bottom;o++)this.pasteZone(e,o,t);void 0===(null==t?void 0:t.pasteOption)&&this.pasteCopiedTables(e)}pasteFromCut(e,t){this.clearClippedZones();const i=e[0];this.pasteZone(i.left,i.top,t),this.dispatch("MOVE_RANGES",{target:this.zones,sheetId:this.sheetId,targetSheetId:this.getters.getActiveSheetId(),col:i.left,row:i.top});for(const e of this.copiedTables)this.dispatch("REMOVE_FILTER_TABLE",{sheetId:this.sheetId,target:[e.zone]});this.pasteCopiedTables(e)}pastedZones(e,t,i){const o=e[0],n=Math.max(1,Math.floor((o.right+1-o.left)/t)),s=Math.max(1,Math.floor((o.bottom+1-o.top)/i)),r=[];for(let e=0;e<n;e++)for(let n=0;n<s;n++){const s=o.top+n*i,a=o.left+e*t;r.push({left:a,top:s,bottom:s+i-1,right:a+t-1})}return r}getPasteZones(e){const t=this.cells;if(!t.length||!t[0].length)return e;const i=[],o=t.length,n=t[0].length,s=e[e.length-1],r=s.left,a=s.top,l=Math.max(1,Math.floor((s.right+1-r)/n)),c=Math.max(1,Math.floor((s.bottom+1-a)/o));for(let e=1;e<=l;e++)for(let t=1;t<=c;t++)i.push({left:r,top:a,right:r-1+e*n,bottom:a-1+t*o});return i}selectPastedZone(e,t,i,o){const n=o[0],s=n.left,r=n.top;if(t>1||e>1||i){const n=this.pastedZones(o,e,t),a=i?n[0]:Zi(...n);this.selection.selectZone({cell:{col:s,row:r},zone:a})}}clearClippedZones(){for(const e of this.cells)for(const t of e)t.cell&&this.dispatch("CLEAR_CELL",t.position);this.dispatch("CLEAR_FORMATTING",{sheetId:this.sheetId,target:this.zones})}pasteZone(e,t,i){const o=this.cells.length,n=this.cells[0].length,s="onlyValue"!==(null==i?void 0:i.pasteOption)&&(null==i?void 0:i.shouldPasteCF),r=this.getters.getActiveSheetId();this.addMissingDimensions(n,o,e,t);for(let a=0;a<o;a++){const o=this.cells[a];for(let l=0;l<n;l++){const n=o[l],c={col:e+l,row:t+a,sheetId:r};"CUT"!==this.operation&&this.pasteMergeIfExist(n.position,c),this.pasteCell(n,c,this.operation,i),s&&this.dispatch("PASTE_CONDITIONAL_FORMAT",{origin:n.position,target:c,operation:this.operation})}}}pasteCell(e,t,i,o){const{sheetId:n,col:s,row:r}=t,a=this.getters.getEvaluatedCell(t);if("onlyValue"!==(null==o?void 0:o.pasteOption)){const i=this.getters.getCellBorder(t),o=e.border,a={top:(null==i?void 0:i.top)||(null==o?void 0:o.top),bottom:(null==i?void 0:i.bottom)||(null==o?void 0:o.bottom),left:(null==i?void 0:i.left)||(null==o?void 0:o.left),right:(null==i?void 0:i.right)||(null==o?void 0:o.right)};this.dispatch("SET_BORDER",{sheetId:n,col:s,row:r,border:a})}if(e.cell){if("onlyFormat"===(null==o?void 0:o.pasteOption))return void this.dispatch("UPDATE_CELL",{...t,style:e.cell.style,format:e.evaluatedCell.format});if("onlyValue"===(null==o?void 0:o.pasteOption)){const i=pi(e.evaluatedCell.value);return void this.dispatch("UPDATE_CELL",{...t,content:i})}let a=e.cell.content;if(e.cell.isFormula&&"COPY"===i){const t=s-e.position.col,o=r-e.position.row;a=this.getUpdatedContent(n,e.cell,t,o,i)}this.dispatch("UPDATE_CELL",{...t,content:a,style:e.cell.style||null,format:e.cell.format})}else a&&("onlyValue"===(null==o?void 0:o.pasteOption)?this.dispatch("UPDATE_CELL",{...t,content:""}):"onlyFormat"===(null==o?void 0:o.pasteOption)?this.dispatch("UPDATE_CELL",{...t,style:null,format:""}):this.dispatch("CLEAR_CELL",t))}getUpdatedContent(e,t,i,o,n){const s=this.getters.createAdaptedRanges(t.dependencies,i,o,e);return this.getters.buildFormulaContent(e,t,s)}pasteMergeIfExist(e,t){let{sheetId:i,col:o,row:n}=e;const{col:s,row:r}=this.getters.getMainCellPosition(e);if(s===o&&r===n){const s=this.getters.getMerge(e);if(!s)return;({sheetId:i,col:o,row:n}=t),this.dispatch("ADD_MERGE",{sheetId:i,force:!0,target:[{left:o,top:n,right:o+s.right-s.left,bottom:n+s.bottom-s.top}]})}}pasteCopiedTables(e){const t=this.getters.getActiveSheetId(),i=e[0],o=this.zones[0],n=[i.left-o.left,i.top-o.top];for(const e of this.copiedTables){const i=no(e.zone,"both","MOVE",n);this.dispatch("CREATE_FILTER_TABLE",{sheetId:t,target:[i]});for(const o of $e(0,e.filtersValues.length))this.dispatch("UPDATE_FILTER",{sheetId:t,col:i.left+o,row:i.top,values:e.filtersValues[o]})}}getClipboardContent(){return{[an.PlainText]:this.getPlainTextContent(),[an.Html]:this.getHTMLContent()}}getPlainTextContent(){return this.cells.map((e=>e.map((e=>e.cell?this.getters.getCellText(e.position,this.getters.shouldShowFormulas()):"")).join("\t"))).join("\n")||"\t"}getHTMLContent(){if(1==this.cells.length&&1==this.cells[0].length)return this.getters.getCellText(this.cells[0][0].position);let e='<table border="1" style="border-collapse:collapse">';for(const t of this.cells){e+="<tr>";for(const i of t){e+=`<td style="${So(vo(i.style))}">`+Yf(this.getters.getCellText(i.position))+"</td>"}e+="</tr>"}return e+="</table>",e}isColRowDirtyingClipboard(e,t){if(!this.zones)return!1;for(let i of this.zones){if("COL"===t&&e<=i.right)return!0;if("ROW"===t&&e<=i.bottom)return!0}return!1}drawClipboard(e){const{ctx:t,thinLineWidth:i}=e;if(this.sheetId===this.getters.getActiveSheetId()&&this.zones&&this.zones.length){t.setLineDash([8,5]),t.strokeStyle=E,t.lineWidth=3.3*i;for(const e of this.zones){const{x:i,y:o,width:n,height:s}=this.getters.getVisibleRect(e);n>0&&s>0&&t.strokeRect(i,o,n,s)}}}}class Ob{constructor(e,t,i){this.operation=e,this.getters=t,this.dispatch=i,this.sheetId=t.getActiveSheetId();const o=t.getSelectedFigureId();if(!o)throw new Error("No figure selected");const n=t.getFigure(this.sheetId,o);if(!n)throw new Error(`No figure for the given id: ${o}`);switch(this.copiedFigure={...n},n.tag){case"chart":this.copiedFigureContent=new Nb(i,t,this.sheetId,o);break;case"image":this.copiedFigureContent=new _b(i,t,this.sheetId,o);break;default:throw new Error(`Unknow tag '${n.tag}' for the given figure id: ${o}`)}}isCutAllowed(e){return 0}isPasteAllowed(e,t){return 0===e.length?73:void 0!==(null==t?void 0:t.pasteOption)?22:0}paste(e){const t=this.getters.getActiveSheetId(),i={x:this.getters.getColDimensions(t,e[0].left).start,y:this.getters.getRowDimensions(t,e[0].top).start},o={height:this.copiedFigure.height,width:this.copiedFigure.width},n=(new Ui).uuidv4();this.copiedFigureContent.paste(t,n,i,o),"CUT"===this.operation&&this.dispatch("DELETE_FIGURE",{sheetId:this.copiedFigureContent.sheetId,id:this.copiedFigure.id}),this.dispatch("SELECT_FIGURE",{id:n})}getClipboardContent(){return{[an.PlainText]:"\t"}}isColRowDirtyingClipboard(e,t){return!1}drawClipboard(e){}}class Nb{constructor(e,t,i,o){this.dispatch=e,this.sheetId=i;const n=t.getChart(o);if(!n)throw new Error(`No chart for the given id: ${o}`);this.copiedChart=n.copyInSheetId(i)}paste(e,t,i,o){const n=this.copiedChart.copyInSheetId(e);this.dispatch("CREATE_CHART",{id:t,sheetId:e,position:i,size:o,definition:n.getDefinition()})}}class _b{constructor(e,t,i,o){this.dispatch=e,this.sheetId=i;const n=t.getImage(o);this.copiedImage=Fe(n)}paste(e,t,i,o){const n=Fe(this.copiedImage);this.dispatch("CREATE_IMAGE",{figureId:t,sheetId:e,position:i,size:o,definition:n})}}class Fb extends Ab{constructor(e,t,i,o){super("COPY",t,i,o),this.values=e.replace(/\r/g,"").split("\n").map((e=>e.split("\t")))}isPasteAllowed(e,t){const i=this.getters.getActiveSheetId(),o=this.getPasteZone(e);return this.getters.doesIntersectMerge(i,o)?2:0}paste(e){const t=this.values,i=this.getPasteZone(e),{left:o,top:n}=i,{numberOfCols:s,numberOfRows:r}=to(i),a=this.getters.getActiveSheetId();this.addMissingDimensions(s,r,o,n);for(let e=0;e<t.length;e++)for(let i=0;i<t[e].length;i++)this.dispatch("UPDATE_CELL",{row:n+e,col:o+i,content:t[e][i],sheetId:a});const l={left:o,top:n,right:o+s-1,bottom:n+r-1};this.selection.selectZone({cell:{col:o,row:n},zone:l})}getClipboardContent(){return{[an.PlainText]:this.values.map((e=>e.join("\t"))).join("\n")}}getPasteZone(e){const t=this.values.length,i=Math.max(...this.values.map((e=>e.length))),{left:o,top:n}=e[0];return{top:n,left:o,bottom:n+t-1,right:o+i-1}}}class Db extends Zv{constructor(){super(...arguments),this.status="invisible",this._isPaintingFormat=!1}allowDispatch(e){switch(e.type){case"CUT":const t=this.getters.getSelectedZones();return this.getClipboardState(t,e.type).isCutAllowed(t);case"PASTE":if(!this.state)return 23;const i=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);return this.state.isPasteAllowed(e.target,{pasteOption:i});case"PASTE_FROM_OS_CLIPBOARD":return new Fb(e.text,this.getters,this.dispatch,this.selection).isPasteAllowed(e.target);case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);return this.getClipboardStateForCopyCells(t,"CUT").isPasteAllowed(i)}}return 0}handle(e){var t,i;switch(e.type){case"COPY":case"CUT":const o=this.getters.getSelectedZones();this.state=this.getClipboardState(o,e.type),this.status="visible";break;case"PASTE":if(!this.state)break;const n=e.pasteOption||(this._isPaintingFormat?"onlyFormat":void 0);this._isPaintingFormat=!1,this.state.paste(e.target,{pasteOption:n,shouldPasteCF:!0,selectTarget:!0}),"CUT"===this.state.operation&&(this.state=void 0),this.status="invisible";break;case"CLEAN_CLIPBOARD_HIGHLIGHT":this.status="invisible";break;case"DELETE_CELL":{const{cut:t,paste:i}=this.getDeleteCellsTargets(e.zone,e.shiftDimension);if(!Bi(t[0])){for(const{col:t,row:i}of oo(e.zone))this.dispatch("CLEAR_CELL",{col:t,row:i,sheetId:this.getters.getActiveSheetId()});break}this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"INSERT_CELL":{const{cut:t,paste:i}=this.getInsertCellsTargets(e.zone,e.shiftDimension);this.getClipboardStateForCopyCells(t,"CUT").paste(i);break}case"ADD_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(t=this.state)||void 0===t?void 0:t.operation))return;this.state.isColRowDirtyingClipboard("before"===e.position?e.base:e.base+1,e.dimension)&&(this.state=void 0);break;case"REMOVE_COLUMNS_ROWS":if(this.status="invisible","CUT"!==(null===(i=this.state)||void 0===i?void 0:i.operation))return;for(let t of e.elements){if(this.state.isColRowDirtyingClipboard(t,e.dimension)){this.state=void 0;break}}this.status="invisible";break;case"PASTE_FROM_OS_CLIPBOARD":new Fb(e.text,this.getters,this.dispatch,this.selection).paste(e.target),this.status="invisible";break;case"ACTIVATE_PAINT_FORMAT":{const e=this.getters.getSelectedZones();this.state=this.getClipboardStateForCopyCells(e,"COPY"),this._isPaintingFormat=!0,this.status="visible";break}default:un(e)&&(this.status="invisible")}}getClipboardContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent())||{[an.PlainText]:"\t"}}getClipboardTextContent(){var e;return(null===(e=this.state)||void 0===e?void 0:e.getClipboardContent()[an.PlainText])||"\t"}isCutOperation(){return!!this.state&&"CUT"===this.state.operation}isPaintingFormat(){return this._isPaintingFormat}getDeleteCellsTargets(e,t){const i=this.getters.getActiveSheetId();let o;return o="COL"===t?{...e,left:e.right+1,right:this.getters.getNumberCols(i)-1}:{...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1},{cut:[o],paste:[e]}}getInsertCellsTargets(e,t){const i=this.getters.getActiveSheetId();let o,n;return"COL"===t?(o={...e,right:this.getters.getNumberCols(i)-1},n={...e,left:e.right+1,right:e.right+1}):(o={...e,bottom:this.getters.getNumberRows(i)-1},n={...e,top:e.bottom+1,bottom:this.getters.getNumberRows(i)-1}),{cut:[o],paste:[n]}}getClipboardStateForCopyCells(e,t){return new Mb(e,t,this.getters,this.dispatch,this.selection)}getClipboardState(e,t){return this.getters.getSelectedFigureId()?new Ob(t,this.getters,this.dispatch):new Mb(e,t,this.getters,this.dispatch,this.selection)}drawGrid(e){"visible"===this.status&&this.state&&this.state.drawClipboard(e)}}function kb(e){if("REFERENCE"!==e.type)return e;const{xc:t,sheetName:i}=Bt(e.value),[o,n]=t.split(":"),s=i?`${ke(i)}!`:"",r=Lb(o),a=n?`:${Lb(n)}`:"";return{...e,value:s+r+a}}function Lb(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=Pb(e,"colrow");break;case"colrow":e=Pb(e,"row");break;case"row":e=Pb(e,"col");break;case"col":e=Pb(e,"none")}return e}function Pb(e,t){let i;switch(e=e.replace(/\$/g,""),t){case"col":return"$"+e;case"row":return i=e.search(/[0-9]/),e.slice(0,i)+"$"+e.slice(i);case"colrow":return i=e.search(/[0-9]/),"$"+(e=e.slice(0,i)+"$"+e.slice(i));case"none":return e}}Db.layers=[2],Db.getters=["getClipboardContent","getClipboardTextContent","isCutOperation","isPaintingFormat"];const Ub=s("The cell you are trying to edit has been deleted.");class Vb extends Zv{constructor(){super(...arguments),this.col=0,this.row=0,this.mode="inactive",this.sheetId="",this.currentContent="",this.currentTokens=[],this.selectionStart=0,this.selectionEnd=0,this.selectionInitialStart=0,this.initialContent="",this.previousRef="",this.previousRange=void 0,this.colorIndexByRange={}}allowDispatch(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":return this.validateSelection(this.currentContent.length,e.start,e.end);case"SET_CURRENT_CONTENT":return e.selection?this.validateSelection(e.content.length,e.selection.start,e.selection.end):0;case"START_EDITION":if(e.selection){const t=e.text||this.getComposerContent(this.getters.getActivePosition());return this.validateSelection(t.length,e.selection.start,e.selection.end)}return 0;default:return 0}}handleEvent(e){if("selecting"===this.mode)if("newAnchor"===e.mode)this.insertSelectedRange(e.anchor.zone);else this.replaceSelectedRanges(e.anchor.zone)}handle(e){switch(e.type){case"CHANGE_COMPOSER_CURSOR_SELECTION":this.selectionStart=e.start,this.selectionEnd=e.end;break;case"STOP_COMPOSER_RANGE_SELECTION":this.isSelectingForComposer()&&(this.mode="editing");break;case"START_EDITION":"inactive"!==this.mode&&e.text?this.setContent(e.text,e.selection):this.startEdition(e.text,e.selection),this.updateRangeColor();break;case"STOP_EDITION":e.cancel?(this.cancelEditionAndActivateSheet(),this.resetContent()):this.stopEdition(),this.colorIndexByRange={};break;case"SET_CURRENT_CONTENT":this.setContent(e.content,e.selection,!0),this.updateRangeColor();break;case"REPLACE_COMPOSER_CURSOR_SELECTION":this.replaceSelection(e.text);break;case"SELECT_FIGURE":this.cancelEditionAndActivateSheet(),this.resetContent();break;case"ADD_COLUMNS_ROWS":this.onAddElements(e);break;case"REMOVE_COLUMNS_ROWS":"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);break;case"START_CHANGE_HIGHLIGHT":this.dispatch("STOP_COMPOSER_RANGE_SELECTION");const t=this.getters.getRangeFromRangeData(e.range),i=this.currentTokens.filter((e=>"REFERENCE"===e.type)).find((e=>{const{xc:i,sheetName:o}=Bt(e.value),n=o||this.getters.getSheetName(this.sheetId),s=this.getters.getActiveSheetId();if(this.getters.getSheetName(s)!==n)return!1;const r=this.getters.getRangeFromSheetXC(s,i);return Xi(this.getters.expandZone(s,r.zone),t.zone)}));this.previousRef=i.value,this.previousRange=this.getters.getRangeFromSheetXC(this.getters.getActiveSheetId(),this.previousRef),this.selectionInitialStart=i.start;break;case"CHANGE_HIGHLIGHT":const o=this.getters.getRangeFromRangeData(e.range),n=this.getRangeReference(o,this.previousRange.parts);this.selectionStart=this.selectionInitialStart,this.selectionEnd=this.selectionInitialStart+this.previousRef.length,this.replaceSelection(n),this.previousRef=n,this.selectionStart=this.currentContent.length,this.selectionEnd=this.currentContent.length;break;case"ACTIVATE_SHEET":if(this.currentContent.startsWith("=")||(this.cancelEdition(),this.resetContent()),e.sheetIdFrom!==e.sheetIdTo){const t=this.getters.getActivePosition(),{col:i,row:o}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:t.col,row:t.row}),n=this.getters.expandZone(e.sheetIdTo,ao({col:i,row:o}));this.selection.resetAnchor(this,{cell:{col:i,row:o},zone:n})}break;case"DELETE_SHEET":case"UNDO":case"REDO":!!this.getters.tryGetSheet(this.sheetId)||"inactive"===this.mode||(this.sheetId=this.getters.getActiveSheetId(),this.cancelEditionAndActivateSheet(),this.resetContent(),this.ui.notifyUI({type:"ERROR",text:Ub}));break;case"CYCLE_EDITION_REFERENCES":this.cycleReferences()}}getEditionMode(){return this.mode}getCurrentContent(){return"inactive"===this.mode?this.getComposerContent(this.getters.getActivePosition()):this.currentContent}getEditionSheet(){return this.sheetId}getComposerSelection(){return{start:this.selectionStart,end:this.selectionEnd}}getCurrentEditedCell(){return{sheetId:this.sheetId,col:this.col,row:this.row}}isSelectingForComposer(){return"selecting"===this.mode}showSelectionIndicator(){return this.isSelectingForComposer()&&this.canStartComposerRangeSelection()}getCurrentTokens(){return this.currentTokens}getTokenAtCursor(){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((i=>i.start<=e&&i.end>=t))}cycleReferences(){const e=this.getTokensInSelection(),t=e.filter((e=>"REFERENCE"===e.type));if(0===t.length)return;const i=e.map(kb).map((e=>e.value)).join(""),o=this.currentContent,n=e[0].start,s=e[e.length-1].end,r=o.slice(0,n)+i+o.slice(s),a=r.length-o.length,l={start:t[0].start,end:t[t.length-1].end+a};1===t.length&&this.selectionStart===this.selectionEnd&&(l.start=l.end),this.dispatch("SET_CURRENT_CONTENT",{content:r,selection:l})}validateSelection(e,t,i){return t>=0&&t<=e&&i>=0&&i<=e?0:46}onColumnsRemoved(e){if(e.elements.includes(this.col)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUI({type:"ERROR",text:Ub});const{top:t,left:i}=Gi({left:this.col,right:this.col,top:this.row,bottom:this.row},"left",[...e.elements]);this.col=i,this.row=t}onRowsRemoved(e){if(e.elements.includes(this.row)&&"inactive"!==this.mode)return this.dispatch("STOP_EDITION",{cancel:!0}),void this.ui.notifyUI({type:"ERROR",text:Ub});const{top:t,left:i}=Gi({left:this.col,right:this.col,top:this.row,bottom:this.row},"top",[...e.elements]);this.col=i,this.row=t}onAddElements(e){const{top:t,left:i}=Wi({left:this.col,right:this.col,top:this.row,bottom:this.row},"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity);this.col=i,this.row=t}startComposerRangeSelection(){if(this.sheetId===this.getters.getActiveSheetId()){const e=ao({col:this.col,row:this.row});this.selection.resetAnchor(this,{cell:{col:this.col,row:this.row},zone:e})}this.mode="selecting",this.selectionInitialStart=this.selectionStart}startEdition(e,t){var i;const o=this.getters.getActiveCell();e&&(null===(i=o.format)||void 0===i?void 0:i.includes("%"))&&ii(e)&&(t=t||{start:e.length,end:e.length},e=`${e}%`);const{col:n,row:s,sheetId:r}=this.getters.getActivePosition();this.col=n,this.sheetId=r,this.row=s,this.initialContent=this.getComposerContent({sheetId:r,col:n,row:s}),this.mode="editing",this.setContent(e||this.initialContent,t),this.colorIndexByRange={};const a=ao({col:this.col,row:this.row});this.selection.capture(this,{cell:{col:this.col,row:this.row},zone:a},{handleEvent:this.handleEvent.bind(this),release:()=>{this.stopEdition()}})}stopEdition(){if("inactive"!==this.mode){this.cancelEditionAndActivateSheet();const e=this.col,t=this.row;let i=this.currentContent;if(!(this.initialContent!==i))return;if(i){const o=this.getters.getActiveSheetId(),n=this.getters.getEvaluatedCell({sheetId:o,col:this.col,row:this.row});if(i.startsWith("=")){const e=this.currentTokens.filter((e=>"LEFT_PAREN"===e.type)).length,t=this.currentTokens.filter((e=>"RIGHT_PAREN"===e.type)).length,o=e-t;o>0&&(i+=rt(new Array(o).fill(")")))}else n.link&&(i=Ke(i,n.link.url));this.dispatch("UPDATE_CELL",{sheetId:this.sheetId,col:e,row:t,content:i})}else this.dispatch("UPDATE_CELL",{sheetId:this.sheetId,content:"",col:e,row:t});this.setContent("")}}cancelEditionAndActivateSheet(){if("inactive"===this.mode)return;this.cancelEdition();this.getters.getActiveSheetId()!==this.sheetId&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getters.getActiveSheetId(),sheetIdTo:this.sheetId})}getComposerContent(e){const t=this.getters.getCell(e);if(null==t?void 0:t.isFormula)return t.content;const{format:i,value:o,type:n,formattedValue:s}=this.getters.getEvaluatedCell(e);switch(n){case rn.text:case rn.empty:return o;case rn.boolean:return s;case rn.error:return(null==t?void 0:t.content)||"";case rn.number:return i&&Ci(i)?s:this.numberComposerContent(o,i)}}numberComposerContent(e,t){return(null==t?void 0:t.includes("%"))?100*e+"%":function(e){const{integerDigits:t,decimalDigits:i}=vi(e,20);return i?`${t}.${i}`:t}(e)}cancelEdition(){"inactive"!==this.mode&&(this.mode="inactive",this.selection.release(this))}resetContent(){this.setContent(this.initialContent||"")}setContent(e,t,i){const o=this.currentContent!==e;this.currentContent=e,t?(this.selectionStart=t.start,this.selectionEnd=t.end):this.selectionStart=this.selectionEnd=e.length,(o||"inactive"!==this.mode)&&(this.currentTokens=e.startsWith("=")?uf(e):[],this.currentTokens.length>100&&i&&this.ui.notifyUI({type:"ERROR",text:s("This formula has over 100 parts. It can't be processed properly, consider splitting it into multiple cells")})),this.canStartComposerRangeSelection()&&this.startComposerRangeSelection()}insertSelectedRange(e){const t=Math.min(this.selectionStart,this.selectionEnd),i=this.getZoneReference(e);this.canStartComposerRangeSelection()?(this.insertText(i,t),this.selectionInitialStart=t):(this.insertText(","+i,t),this.selectionInitialStart=t+1)}replaceSelectedRanges(e){const t=this.getZoneReference(e);this.replaceText(t,this.selectionInitialStart,this.selectionEnd)}getZoneReference(e,t=[{colFixed:!1,rowFixed:!1}]){const i=this.getters.getActiveSheetId();let o=this.getters.zoneToXC(i,e,t);if(this.getters.getEditionSheet()!==this.getters.getActiveSheetId()){o=`${ke(this.getters.getSheetName(this.getters.getActiveSheetId()))}!${o}`}return o}getRangeReference(e,t=[{colFixed:!1,rowFixed:!1}]){let i=[...t];1===t.length&&co(e.zone)>1?i.push({...t[0]}):2===t.length&&1===co(e.zone)&&i.pop();const o=e.clone({parts:i});return this.getters.getSelectionRangeString(o,this.getters.getEditionSheet())}replaceSelection(e){const t=Math.min(this.selectionStart,this.selectionEnd),i=Math.max(this.selectionStart,this.selectionEnd);this.replaceText(e,t,i)}replaceText(e,t,i){this.currentContent=this.currentContent.slice(0,t)+this.currentContent.slice(i,this.currentContent.length),this.insertText(e,t)}insertText(e,t){const i=this.currentContent.slice(0,t)+e+this.currentContent.slice(t),o=t+e.length;this.dispatch("SET_CURRENT_CONTENT",{content:i,selection:{start:o,end:o}})}updateRangeColor(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return;const e=this.getters.getEditionSheet(),t=this.getReferencedRanges().map((t=>this.getters.getRangeString(t,e))),i={};for(const e of t)void 0!==this.colorIndexByRange[e]&&(i[e]=this.colorIndexByRange[e]);const o=new Set(Object.values(i));let n=0;const s=()=>{for(;o.has(n);)n++;return o.add(n),n};for(const e of t){const t=e in i?i[e]:s();i[e]=t}this.colorIndexByRange=i}getComposerHighlights(){if(!this.currentContent.startsWith("=")||"inactive"===this.mode)return[];const e=this.getters.getEditionSheet(),t=e=>{const t=this.colorIndexByRange[e];return Ct[t%Ct.length]};return this.getReferencedRanges().map((i=>{const o=this.getters.getRangeString(i,e);return{zone:i.zone,color:t(o),sheetId:i.sheetId}}))}getReferencedRanges(){const e=this.getters.getEditionSheet();return this.currentTokens.filter((e=>"REFERENCE"===e.type)).map((t=>this.getters.getRangeFromSheetXC(e,t.value)))}canStartComposerRangeSelection(){if(this.currentContent.startsWith("=")){const e=this.getTokenAtCursor();if(!e)return!1;const t=this.currentTokens.map((e=>e.start)).indexOf(e.start);let i=t,o=e;for(;!["COMMA","LEFT_PAREN","OPERATOR"].includes(o.type)||Im.includes(o.value);){if("SPACE"!==o.type||i<1)return!1;i--,o=this.currentTokens[i]}for(i=t+1,o=this.currentTokens[i];o&&!["COMMA","RIGHT_PAREN","OPERATOR"].includes(o.type);){if("SPACE"!==o.type)return!1;i++,o=this.currentTokens[i]}return!0}return!1}getTokensInSelection(){const e=Math.min(this.selectionStart,this.selectionEnd),t=Math.max(this.selectionStart,this.selectionEnd);return this.currentTokens.filter((i=>i.start<=e&&i.end>=e||i.start>=e&&i.start<t))}}Vb.getters=["getEditionMode","isSelectingForComposer","showSelectionIndicator","getCurrentContent","getEditionSheet","getComposerSelection","getCurrentTokens","getTokenAtCursor","getComposerHighlights","getCurrentEditedCell"];const zb=[{name:s("Sum"),types:[rn.number],compute:e=>ul.compute([e])},{name:s("Avg"),types:[rn.number],compute:e=>yl.compute([e])},{name:s("Min"),types:[rn.number],compute:e=>zl.compute([e])},{name:s("Max"),types:[rn.number],compute:e=>Ll.compute([e])},{name:s("Count"),types:[rn.number,rn.text,rn.boolean,rn.error],compute:e=>Nl.compute([e])},{name:s("Count Numbers"),types:[rn.number,rn.text,rn.boolean,rn.error],compute:e=>Ol.compute([e])}];class Bb extends Zv{constructor(e){super(e),this.gridSelection={anchor:{cell:{col:0,row:0},zone:{top:0,left:0,bottom:0,right:0}},zones:[{top:0,left:0,bottom:0,right:0}]},this.selectedFigureId=null,this.sheetsData={},this.activeSheet=null,this.moveClient=e.moveClient}allowDispatch(e){switch(e.type){case"ACTIVATE_SHEET":try{this.getters.getSheet(e.sheetIdTo);break}catch(e){return 27}case"MOVE_COLUMNS_ROWS":return this.isMoveElementAllowed(e)}return 0}handleEvent(e){const t=e.anchor;let i=[];switch(e.mode){case"overrideSelection":i=[t.zone];break;case"updateAnchor":i=[...this.gridSelection.zones];const o=i.findIndex((t=>Xi(t,e.previousAnchor.zone)));o>=0&&(i[o]=t.zone);break;case"newAnchor":i=[...this.gridSelection.zones,t.zone]}this.setSelectionMixin(e.anchor,i),this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor));const{col:o,row:n}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:o,row:n}),this.selectedFigureId=null}handle(e){switch(e.type){case"START_EDITION":case"ACTIVATE_SHEET":this.selectedFigureId=null;break;case"DELETE_FIGURE":this.selectedFigureId===e.id&&(this.selectedFigureId=null);break;case"DELETE_SHEET":this.selectedFigureId&&this.getters.getFigure(e.sheetId,this.selectedFigureId)&&(this.selectedFigureId=null)}switch(e.type){case"START":const t=this.getters.getVisibleSheetIds()[0];this.dispatch("ACTIVATE_SHEET",{sheetIdTo:t,sheetIdFrom:t});const{col:i,row:o}=this.getters.getNextVisibleCellPosition({sheetId:t,col:0,row:0});this.selectCell(i,o),this.selection.registerAsDefault(this,this.gridSelection.anchor,{handleEvent:this.handleEvent.bind(this)}),this.moveClient({sheetId:t,col:0,row:0});break;case"ACTIVATE_SHEET":if(this.getters.isSheetVisible(e.sheetIdTo)||this.dispatch("SHOW_SHEET",{sheetId:e.sheetIdTo}),this.setActiveSheet(e.sheetIdTo),this.sheetsData[e.sheetIdFrom]={gridSelection:Fe(this.gridSelection)},e.sheetIdTo in this.sheetsData)Object.assign(this,this.sheetsData[e.sheetIdTo]),this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor));else{const{col:t,row:i}=this.getters.getNextVisibleCellPosition({sheetId:e.sheetIdTo,col:0,row:0});this.selectCell(t,i)}break;case"REMOVE_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){"COL"===e.dimension?this.onColumnsRemoved(e):this.onRowsRemoved(e);const{col:i,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:o})}break}case"ADD_COLUMNS_ROWS":{const t=this.getters.getActiveSheetId();if(e.sheetId===t){this.onAddElements(e);const{col:i,row:o}=this.gridSelection.anchor.cell;this.moveClient({sheetId:t,col:i,row:o})}break}case"MOVE_COLUMNS_ROWS":e.sheetId===this.getActiveSheetId()&&this.onMoveElements(e);break;case"SELECT_FIGURE":this.selectedFigureId=e.id;break;case"ACTIVATE_NEXT_SHEET":this.activateNextSheet("right");break;case"ACTIVATE_PREVIOUS_SHEET":this.activateNextSheet("left");break;case"HIDE_SHEET":e.sheetId===this.getActiveSheetId()&&this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:e.sheetId,sheetIdTo:this.getters.getVisibleSheetIds()[0]});break;case"UNDO":case"REDO":case"DELETE_SHEET":const n=Object.keys(this.sheetsData).filter((e=>!this.getters.tryGetSheet(e)));for(const e of n)delete this.sheetsData[e];for(const e in this.sheetsData){const t=this.clipSelection(e,this.sheetsData[e].gridSelection);this.sheetsData[e]={gridSelection:Fe(t)}}if(!this.getters.tryGetSheet(this.getters.getActiveSheetId())){const e=this.getters.getVisibleSheetIds();if(this.activeSheet=this.getters.getSheet(e[0]),this.activeSheet.id in this.sheetsData){const{anchor:e}=this.clipSelection(this.activeSheet.id,this.sheetsData[this.activeSheet.id].gridSelection);this.selectCell(e.cell.col,e.cell.row)}else this.selectCell(0,0);const{col:t,row:i}=this.gridSelection.anchor.cell;this.moveClient({sheetId:this.getters.getActiveSheetId(),col:t,row:i})}const s=this.getters.getActiveSheetId();this.gridSelection.zones=this.gridSelection.zones.map((e=>this.getters.expandZone(s,e))),this.gridSelection.anchor.zone=this.getters.expandZone(s,this.gridSelection.anchor.zone),this.setSelectionMixin(this.gridSelection.anchor,this.gridSelection.zones)}this.selection.resetDefaultAnchor(this,Fe(this.gridSelection.anchor))}isGridSelectionActive(){return this.selection.isListening(this)}getActiveSheet(){return this.activeSheet}getActiveSheetId(){return this.activeSheet.id}getActiveCell(){return this.getters.getEvaluatedCell(this.getActivePosition())}getActiveCols(){const e=new Set;for(let t of this.gridSelection.zones)if(0===t.top&&t.bottom===this.getters.getNumberRows(this.getters.getActiveSheetId())-1)for(let i=t.left;i<=t.right;i++)e.add(i);return e}getActiveRows(){const e=new Set,t=this.getters.getActiveSheetId();for(let i of this.gridSelection.zones)if(0===i.left&&i.right===this.getters.getNumberCols(t)-1)for(let t=i.top;t<=i.bottom;t++)e.add(t);return e}getCurrentStyle(){const e=this.getters.getSelectedZone(),t=this.getters.getActiveSheetId();return this.getters.getCellStyle({sheetId:t,col:e.left,row:e.top})}getSelectedZones(){return Fe(this.gridSelection.zones)}getSelectedZone(){return Fe(this.gridSelection.anchor.zone)}getSelection(){return Fe(this.gridSelection)}getSelectedFigureId(){return this.selectedFigureId}getActivePosition(){return this.getters.getMainCellPosition({sheetId:this.getActiveSheetId(),col:this.gridSelection.anchor.cell.col,row:this.gridSelection.anchor.cell.row})}getSheetPosition(e){if(e===this.getters.getActiveSheetId())return this.getActivePosition();{const t=this.sheetsData[e];return t?{sheetId:e,col:t.gridSelection.anchor.cell.col,row:t.gridSelection.anchor.cell.row}:this.getters.getNextVisibleCellPosition({sheetId:e,col:0,row:0})}}getStatisticFnResults(){const e=this.getters.getActiveSheetId(),t=new Set;for(const i of this.gridSelection.zones)for(const{col:o,row:n}of oo(i)){if(this.getters.isRowHidden(e,n)||this.getters.isColHidden(e,o))continue;const i=this.getters.getEvaluatedCell({sheetId:e,col:o,row:n});i.type!==rn.empty&&t.add(i)}let i=new Set,o=[];for(let e of t)i.add(e.type),o.push(e.value);let n={};for(let e of zb){let t;e.types.some((e=>i.has(e)))&&(t=e.compute(o)),n[e.name]=t}return n}getAggregate(){let e=0,t=0;const i=this.getters.getActiveSheetId(),o=this.gridSelection.zones.map(oo).flat();for(const{col:n,row:s}of o){const o=this.getters.getEvaluatedCell({sheetId:i,col:n,row:s});o.type===rn.number&&(t++,e+=o.value)}return t<2?null:pi(e)}isSelected(e){return!!this.getters.getSelectedZones().find((t=>Xi(t,e)))}getElementsFromSelection(e){if("COL"===e&&0===this.getters.getActiveCols().size)return[];if("ROW"===e&&0===this.getters.getActiveRows().size)return[];const t=this.getters.getSelectedZones();let i=[];const o="COL"===e?"left":"top",n="COL"===e?"right":"bottom";for(const e of t){const t=Array.from({length:e[n]-e[o]+1},((t,i)=>e[o]+i));i=i.concat(t)}return[...new Set(i)].sort()}setSelectionMixin(e,t){const{anchor:i,zones:o}=this.clipSelection(this.getters.getActiveSheetId(),{anchor:e,zones:t});this.gridSelection.anchor=i,this.gridSelection.zones=function(e){return e.reverse().filter(((e,t,i)=>t===i.findIndex((t=>t.top===e.top&&t.bottom===e.bottom&&t.left===e.left&&t.right===e.right)))).reverse()}(o)}selectCell(e,t){const i=this.getters.getActiveSheetId(),o=this.getters.expandZone(i,{left:e,right:e,top:t,bottom:t});this.setSelectionMixin({zone:o,cell:{col:e,row:t}},[o])}setActiveSheet(e){const t=this.getters.getSheet(e);this.activeSheet=t}activateNextSheet(e){const t=this.getters.getSheetIds(),i=(t.findIndex((e=>e===this.activeSheet.id))+("left"===e?t.length-1:1))%t.length;this.dispatch("ACTIVATE_SHEET",{sheetIdFrom:this.getActiveSheetId(),sheetIdTo:t[i]})}onColumnsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,o=Gi(i,"left",[...e.elements]);let n={left:t.col,right:t.col,top:t.row,bottom:t.row};n=Gi(n,"left",[...e.elements]);const s={cell:{col:n.left,row:n.top},zone:o};this.setSelectionMixin(s,[o])}onRowsRemoved(e){const{cell:t,zone:i}=this.gridSelection.anchor,o=Gi(i,"top",[...e.elements]);let n={left:t.col,right:t.col,top:t.row,bottom:t.row};n=Gi(n,"top",[...e.elements]);const s={cell:{col:n.left,row:n.top},zone:o};this.setSelectionMixin(s,[o])}onAddElements(e){const t=Wi(this.gridSelection.anchor.zone,"COL"===e.dimension?"left":"top",e.base,e.position,e.quantity),i={cell:{col:t.left,row:t.top},zone:t};this.setSelectionMixin(i,[t])}onMoveElements(e){const t=e.elements.length;this.dispatch("ADD_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,base:e.base,quantity:t,position:"before"});const i="COL"===e.dimension,o=e.elements[0],n=e.elements[t-1],s=e.base<o,r=s&&i?t:0,a=s&&!i?t:0,l=[{left:i?o+r:0,right:i?n+r:this.getters.getNumberCols(e.sheetId)-1,top:i?0:o+a,bottom:i?this.getters.getNumberRows(e.sheetId)-1:n+a}],c=new Mb(l,"CUT",this.getters,this.dispatch,this.selection),h=[{left:i?e.base:0,right:i?e.base+t-1:this.getters.getNumberCols(e.sheetId)-1,top:i?0:e.base,bottom:i?this.getters.getNumberRows(e.sheetId)-1:e.base+t-1}];c.paste(h,{selectTarget:!0});const d=s?e.elements.map((e=>e+t)):e.elements;let u=e.base;for(const t of d){const i="COL"===e.dimension?this.getters.getColSize(e.sheetId,t):this.getters.getRowSize(e.sheetId,t);this.dispatch("RESIZE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,size:i,elements:[u]}),u+=1}this.dispatch("REMOVE_COLUMNS_ROWS",{dimension:e.dimension,sheetId:e.sheetId,elements:d})}isMoveElementAllowed(e){const t="COL"===e.dimension,i=e.elements[0],o=e.elements[e.elements.length-1],n=e.sheetId,s=t?this.getters.doesColumnsHaveCommonMerges:this.getters.doesRowsHaveCommonMerges;return s(n,i-1,i)||s(n,o,o+1)||s(n,e.base-1,e.base)?2:0}clipSelection(e,t){const i=this.getters.getNumberCols(e)-1,o=this.getters.getNumberRows(e)-1;return{zones:t.zones.map((e=>({left:Le(e.left,0,i),right:Le(e.right,0,i),top:Le(e.top,0,o),bottom:Le(e.bottom,0,o)}))),anchor:{cell:{col:Le(t.anchor.cell.col,0,i),row:Le(t.anchor.cell.row,0,o)},zone:{left:Le(t.anchor.zone.left,0,i),right:Le(t.anchor.zone.right,0,i),top:Le(t.anchor.zone.top,0,o),bottom:Le(t.anchor.zone.bottom,0,o)}}}}drawGrid(e){if(this.getters.isDashboard())return;const{ctx:t,thinLineWidth:i}=e,o=this.getSelectedZones();t.fillStyle="#f3f7fe";const n=1===o.length&&o[0].left===o[0].right&&o[0].top===o[0].bottom;t.fillStyle=n?"#f3f7fe":"#e9f0ff",t.strokeStyle=E,t.lineWidth=1.5*i;for(const e of o){const{x:i,y:o,width:n,height:s}=this.getters.getVisibleRect(e);t.globalCompositeOperation="multiply",t.fillRect(i,o,n,s),t.globalCompositeOperation="source-over",t.strokeRect(i,o,n,s)}t.globalCompositeOperation="source-over";const s=this.getActivePosition();let r;t.strokeStyle=E,t.lineWidth=3*i,r=this.getters.isInMerge(s)?this.getters.getMerge(s):ao(s);const{x:a,y:l,width:c,height:h}=this.getters.getVisibleRect(r);c>0&&h>0&&t.strokeRect(a,l,c,h)}}Bb.layers=[6],Bb.getters=["getActiveSheet","getActiveSheetId","getActiveCell","getActiveCols","getActiveRows","getCurrentStyle","getSelectedZones","getSelectedZone","getStatisticFnResults","getAggregate","getSelectedFigureId","getSelection","getActivePosition","getSheetPosition","isSelected","getElementsFromSelection","isGridSelectionActive"];const Hb=(new xo).add("sheet",qv).add("header visibility",zv).add("filters",Uv).add("cell",Nv).add("merge",Hv).add("headerSize",Vv).add("borders",Ov).add("conditional formatting",Dv).add("figures",kv).add("chart",_v).add("image",Bv),$b=(new xo).add("ui_sheet",Tb).add("header_visibility_ui",lb).add("ui_options",Rb).add("selectionInputManager",ub).add("highlight",cb).add("grid renderer",hb).add("autofill",ob).add("find_and_replace",ab).add("sort",Ib).add("automatic_sum",nb).add("format",class extends Zv{handle(e){if("SET_DECIMAL"===e.type)this.setDecimal(e.sheetId,e.target,e.step)}setDecimal(e,t,i){for(const o of t)for(const t of oo(o)){const o=this.getCellNumberFormat({sheetId:e,...t});if(void 0!==o){const n=Ti(o,i);this.dispatch("SET_FORMATTING",{sheetId:e,target:[ao(t)],format:n})}}}getCellNumberFormat(e){var t;for(const i of[e]){const e=this.getters.getEvaluatedCell(i);if(e.type===rn.number&&!(null===(t=e.format)||void 0===t?void 0:t.match(Y)))return e.format||xi(e.value)}}}).add("cell_popovers",sb).add("selection_multiuser",xb),Wb=(new xo).add("selection",Bb).add("clipboard",Db).add("edition",Vb),Gb=(new xo).add("evaluation",Yv).add("evaluation_filter",Jv).add("evaluation_chart",Kv).add("evaluation_cf",Qv).add("viewport",tb).add("custom_colors",jv),qb=new xo;qb.add("link",{condition:(e,t)=>!!t.model.getters.getEvaluatedCell(e).link,action:(e,t)=>No(t.model.getters.getEvaluatedCell(e).link,t),sequence:5});class Zb{constructor(e){this.fileStore=e}async requestImage(){const e=await this.getImageFromUser(),t=await this.fileStore.upload(e);return{path:t,size:await this.getImageSize(t),mimetype:e.type}}getImageFromUser(){return new Promise(((e,t)=>{const i=document.createElement("input");i.setAttribute("type","file"),i.setAttribute("accept","image/*"),i.addEventListener("change",(async()=>{null===i.files||1!=i.files.length?t():e(i.files[0])})),i.click()}))}getImageSize(e){return new Promise(((t,i)=>{const o=new Image;o.src=e,o.addEventListener("load",(()=>{const e={width:o.width,height:o.height};t(e)})),o.addEventListener("error",i)}))}}const jb=[{transform:"scale(0)"},{transform:"scale(0.8)",offset:.33},{opacity:"0",transform:"scale(1)",offset:1}];mo`
|
|
1401
1401
|
.o-ripple {
|
|
1402
1402
|
z-index: 1;
|
|
1403
1403
|
}
|
|
@@ -2455,4 +2455,4 @@
|
|
|
2455
2455
|
<tableParts count="${e.filterTables.length}">
|
|
2456
2456
|
${ev(a)}
|
|
2457
2457
|
</tableParts>
|
|
2458
|
-
`}var pC;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(pC||(pC={}));const mC={},fC={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:N,HEADER_WIDTH:_,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:F,DEFAULT_CELL_HEIGHT:D,SCROLLBAR_WIDTH:k},vC={autofillModifiersRegistry:In,autofillRulesRegistry:Rn,cellMenuRegistry:aa,colMenuRegistry:la,linkMenuRegistry:os,functionRegistry:Yu,featurePluginRegistry:$b,statefulUIPluginRegistry:Wb,coreViewsPluginRegistry:Gb,corePluginRegistry:Hb,rowMenuRegistry:ca,sidePanelRegistry:Mg,figureRegistry:pr,chartSidePanelComponentRegistry:Cg,chartComponentRegistry:cr,chartRegistry:lr,topbarMenuRegistry:Qu,topbarComponentRegistry:Og,clickableCellRegistry:qb,otRegistry:eg,inverseCommandRegistry:br,urlRegistry:Ro,cellPopoverRegistry:rs},bC={arg:ua,toBoolean:Bo,toJsDate:Ho,toNumber:Lo,toString:Uo,toXC:Gt,toZone:zi,toCartesian:Wt,numberToLetters:Ht,UuidGenerator:Ui,formatValue:pi,computeTextWidth:Ue,createEmptyWorkbookData:Rv,createEmptySheet:Iv,createEmptyExcelSheet:Tv,getDefaultChartJsRuntime:Ls,chartFontColor:Cs,ChartColors:Ss,EvaluationError:c,CellErrorLevel:l,getFillingMode:zs,rgbaToHex:Tt,colorToRGBA:At,positionToZone:ao,isDefined:ot,lazy:at},SC={isMarkdownLink:Xe,parseMarkdownLink:Qe,markdownLink:Ke,openLink:No,urlRepresentation:Oo},CC={ChartPanel:Eg,ChartFigure:dr,ChartJsComponent:uo,Grid:fp,GridOverlay:ep,ScorecardChart:Eo,LineConfigPanel:fg,LineBarPieDesignPanel:ug,BarConfigPanel:rg,LineBarPieConfigPanel:sg,GaugeChartConfigPanel:pg,GaugeChartDesignPanel:mg,ScorecardChartConfigPanel:bg,ScorecardChartDesignPanel:Sg,FigureComponent:Ng};e.AbstractChart=ls,e.CorePlugin=Mv,e.DATETIME_FORMAT=Y,e.DispatchResult=gn,e.EvaluationError=c,e.Model=class extends gb{constructor(e={},i={},o=[],n=new Ui,s=!0){super(),this.corePlugins=[],this.featurePlugins=[],this.statefulUIPlugins=[],this.coreViewsPlugins=[],this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.handlers=[],this.coreHandlers=[],this.dispatch=(e,t)=>{const i={...t,type:e};let o=this.status;if(this.getters.isReadonly()&&(n=i,!hn.has(n.type)))return new gn(67);var n;if(!this.session.canApplyOptimisticUpdate())return new gn(64);switch(o){case 0:const t=this.checkDispatchAllowed(i);if(!t.isSuccessful)return t;this.status=1;const{changes:o,commands:n}=this.state.recordChanges((()=>{un(i)&&this.state.addCommand(i),this.dispatchToHandlers(this.handlers,i),this.finalize()}));this.session.save(n,o),this.status=0,this.trigger("update");break;case 1:if(un(i)){const e=this.checkDispatchAllowed(i);if(!e.isSuccessful)return e;this.state.addCommand(i)}this.dispatchToHandlers(this.handlers,i);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(un(i))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,i)}return gn.Success},this.dispatchFromCorePlugin=(e,t)=>{const i={...t,type:e},o=this.status;this.status=2;const n=this.isReplayingCommand?[this.range,...this.corePlugins,...this.coreViewsPlugins]:this.handlers;return this.dispatchToHandlers(n,i),this.status=o,gn.Success},o=yv(e,o);const r=Ev(e,s);this.state=new TS,this.uuidGenerator=n,this.config=this.setupConfig(i),this.session=this.setupSession(r.revisionId),this.history=new xS(this.dispatchFromCorePlugin,this.session),this.coreGetters={},this.range=new Gv(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.getSelectionRangeString=this.range.getSelectionRangeString.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode,canUndo:this.history.canUndo.bind(this.history),canRedo:this.history.canRedo.bind(this.history),getClient:this.session.getClient.bind(this.session),getConnectedClients:this.session.getConnectedClients.bind(this.session),isFullySynchronized:this.session.isFullySynchronized.bind(this.session)},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new RS(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of Hb.getAll())this.setupCorePlugin(e,r);Object.assign(this.getters,this.coreGetters);for(let e of Wb.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t)}for(let e of Gb.getAll()){const t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.coreHandlers.push(t)}for(let e of $b.getAll()){const t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t)}this.uuidGenerator.setIsFastStrategy(!1),this.handlers.push(this.history),this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.session.loadInitialMessages(o),this.joinSession(),i.snapshotRequested&&(this.session.snapshot(this.exportData()),this.garbageCollectExternalResources()),t.markRaw(this)}joinSession(){this.session.join(this.config.client)}leaveSession(){this.session.leave()}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let i of e.getters){if(!(i in t))throw new Error(`Invalid getter name: ${i} for plugin ${t.constructor}`);if(i in this.getters)throw new Error(`Getter "${i}" is already defined.`);this.getters[i]=t[i].bind(t)}const i=e.layers.map((e=>[t,e]));return this.renderers.push(...i),this.renderers.sort(((e,t)=>e[1]-t[1])),t}setupCorePlugin(e,t){const i=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in i))throw new Error(`Invalid getter name: ${t} for plugin ${i.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=i[t].bind(i)}i.import(t),this.corePlugins.push(i),this.coreHandlers.push(i),this.handlers.push(i)}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 wb(wS(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers([this.range,...this.corePlugins,...this.coreViewsPlugins],e),this.isReplayingCommand=!1)})),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-redone",this,this.finalize),this.session.on("revision-undone",this,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.uuidv4(),name:s("Anonymous").toString()},i=e.transportService||new gS;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:e.external||{},transportService:i,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),lazyEvaluation:!("lazyEvaluation"in e)||e.lazyEvaluation}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,lazyEvaluation:this.config.lazyEvaluation}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return new gn(t.flat())}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}dispatchToHandlers(e,t){t=Fe(t);for(const i of e)i.beforeHandle(t);for(const i of e)i.handle(t)}drawGrid(e){for(let[t,i]of this.renderers)e.ctx.save(),t.drawGrid(e,i),e.ctx.restore()}exportData(){let e=Rv();for(let t of this.handlers)t instanceof Mv&&t.export(e);return e.revisionId=this.session.getRevisionId()||Q,e=Fe(e),e}updateMode(e){"normal"!==e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...Rv(),sheets:[Tv(Cv,"Sheet1")]};for(let t of this.handlers)t instanceof Av&&t.exportForExcel(e);return e=Fe(e),uC(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.Registry=xo,e.Revision=Cb,e.SPREADSHEET_DIMENSIONS=fC,e.Spreadsheet=uS,e.UIPlugin=Zv,e.__info__=mC,e.addFunction=function(e,t){Yu.add(e,t)},e.astToFormula=Km,e.compile=df,e.components=CC,e.convertAstNodes=Ym,e.coreTypes=dn,e.findCellInNewZone=so,e.functionCache=hf,e.helpers=bC,e.invalidateEvaluationCommands=ln,e.links=SC,e.load=Ev,e.parse=jm,e.readonlyAllowedCommands=hn,e.registries=vC,e.setTranslationMethod=function(e){i=e},e.tokenize=Tm,Object.defineProperty(e,"__esModule",{value:!0}),mC.version="16.2.
|
|
2458
|
+
`}var pC;!function(e){e[e.Ready=0]="Ready",e[e.Running=1]="Running",e[e.RunningCore=2]="RunningCore",e[e.Finalizing=3]="Finalizing"}(pC||(pC={}));const mC={},fC={MIN_ROW_HEIGHT:10,MIN_COL_WIDTH:5,HEADER_HEIGHT:N,HEADER_WIDTH:_,TOPBAR_HEIGHT:63,BOTTOMBAR_HEIGHT:36,DEFAULT_CELL_WIDTH:F,DEFAULT_CELL_HEIGHT:D,SCROLLBAR_WIDTH:k},vC={autofillModifiersRegistry:In,autofillRulesRegistry:Rn,cellMenuRegistry:aa,colMenuRegistry:la,linkMenuRegistry:os,functionRegistry:Yu,featurePluginRegistry:$b,statefulUIPluginRegistry:Wb,coreViewsPluginRegistry:Gb,corePluginRegistry:Hb,rowMenuRegistry:ca,sidePanelRegistry:Mg,figureRegistry:pr,chartSidePanelComponentRegistry:Cg,chartComponentRegistry:cr,chartRegistry:lr,topbarMenuRegistry:Qu,topbarComponentRegistry:Og,clickableCellRegistry:qb,otRegistry:eg,inverseCommandRegistry:br,urlRegistry:Ro,cellPopoverRegistry:rs},bC={arg:ua,toBoolean:Bo,toJsDate:Ho,toNumber:Lo,toString:Uo,toXC:Gt,toZone:zi,toCartesian:Wt,numberToLetters:Ht,UuidGenerator:Ui,formatValue:pi,computeTextWidth:Ue,createEmptyWorkbookData:Rv,createEmptySheet:Iv,createEmptyExcelSheet:Tv,getDefaultChartJsRuntime:Ls,chartFontColor:Cs,ChartColors:Ss,EvaluationError:c,CellErrorLevel:l,getFillingMode:zs,rgbaToHex:Tt,colorToRGBA:At,positionToZone:ao,isDefined:ot,lazy:at},SC={isMarkdownLink:Xe,parseMarkdownLink:Qe,markdownLink:Ke,openLink:No,urlRepresentation:Oo},CC={ChartPanel:Eg,ChartFigure:dr,ChartJsComponent:uo,Grid:fp,GridOverlay:ep,ScorecardChart:Eo,LineConfigPanel:fg,LineBarPieDesignPanel:ug,BarConfigPanel:rg,LineBarPieConfigPanel:sg,GaugeChartConfigPanel:pg,GaugeChartDesignPanel:mg,ScorecardChartConfigPanel:bg,ScorecardChartDesignPanel:Sg,FigureComponent:Ng};e.AbstractChart=ls,e.CorePlugin=Mv,e.DATETIME_FORMAT=Y,e.DispatchResult=gn,e.EvaluationError=c,e.Model=class extends gb{constructor(e={},i={},o=[],n=new Ui,s=!0){super(),this.corePlugins=[],this.featurePlugins=[],this.statefulUIPlugins=[],this.coreViewsPlugins=[],this.isReplayingCommand=!1,this.renderers=[],this.status=0,this.handlers=[],this.coreHandlers=[],this.dispatch=(e,t)=>{const i={...t,type:e};let o=this.status;if(this.getters.isReadonly()&&(n=i,!hn.has(n.type)))return new gn(67);var n;if(!this.session.canApplyOptimisticUpdate())return new gn(64);switch(o){case 0:const t=this.checkDispatchAllowed(i);if(!t.isSuccessful)return t;this.status=1;const{changes:o,commands:n}=this.state.recordChanges((()=>{un(i)&&this.state.addCommand(i),this.dispatchToHandlers(this.handlers,i),this.finalize()}));this.session.save(n,o),this.status=0,this.trigger("update");break;case 1:if(un(i)){const e=this.checkDispatchAllowed(i);if(!e.isSuccessful)return e;this.state.addCommand(i)}this.dispatchToHandlers(this.handlers,i);break;case 3:throw new Error("Cannot dispatch commands in the finalize state");case 2:if(un(i))throw new Error(`A UI plugin cannot dispatch ${e} while handling a core command`);this.dispatchToHandlers(this.handlers,i)}return gn.Success},this.dispatchFromCorePlugin=(e,t)=>{const i={...t,type:e},o=this.status;this.status=2;const n=this.isReplayingCommand?[this.range,...this.corePlugins,...this.coreViewsPlugins]:this.handlers;return this.dispatchToHandlers(n,i),this.status=o,gn.Success},o=yv(e,o);const r=Ev(e,s);this.state=new TS,this.uuidGenerator=n,this.config=this.setupConfig(i),this.session=this.setupSession(r.revisionId),this.history=new xS(this.dispatchFromCorePlugin,this.session),this.coreGetters={},this.range=new Gv(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.getSelectionRangeString=this.range.getSelectionRangeString.bind(this.range),this.getters={isReadonly:()=>"readonly"===this.config.mode||"dashboard"===this.config.mode,isDashboard:()=>"dashboard"===this.config.mode,canUndo:this.history.canUndo.bind(this.history),canRedo:this.history.canRedo.bind(this.history),getClient:this.session.getClient.bind(this.session),getConnectedClients:this.session.getConnectedClients.bind(this.session),isFullySynchronized:this.session.isFullySynchronized.bind(this.session)},this.uuidGenerator.setIsFastStrategy(!0),this.selection=new RS(this.getters),this.coreHandlers.push(this.range),this.handlers.push(this.range),this.corePluginConfig=this.setupCorePluginConfig(),this.uiPluginConfig=this.setupUiPluginConfig();for(let e of Hb.getAll())this.setupCorePlugin(e,r);Object.assign(this.getters,this.coreGetters);for(let e of Wb.getAll()){const t=this.setupUiPlugin(e);this.statefulUIPlugins.push(t),this.handlers.push(t)}for(let e of Gb.getAll()){const t=this.setupUiPlugin(e);this.coreViewsPlugins.push(t),this.handlers.push(t),this.coreHandlers.push(t)}for(let e of $b.getAll()){const t=this.setupUiPlugin(e);this.featurePlugins.push(t),this.handlers.push(t)}this.uuidGenerator.setIsFastStrategy(!1),this.handlers.push(this.history),this.dispatch("START"),this.selection.observe(this,{handleEvent:()=>this.trigger("update")}),this.setupSessionEvents(),this.session.loadInitialMessages(o),this.joinSession(),i.snapshotRequested&&(this.session.snapshot(this.exportData()),this.garbageCollectExternalResources()),t.markRaw(this)}joinSession(){this.session.join(this.config.client)}leaveSession(){this.session.leave()}setupUiPlugin(e){const t=new e(this.uiPluginConfig);for(let i of e.getters){if(!(i in t))throw new Error(`Invalid getter name: ${i} for plugin ${t.constructor}`);if(i in this.getters)throw new Error(`Getter "${i}" is already defined.`);this.getters[i]=t[i].bind(t)}const i=e.layers.map((e=>[t,e]));return this.renderers.push(...i),this.renderers.sort(((e,t)=>e[1]-t[1])),t}setupCorePlugin(e,t){const i=new e(this.corePluginConfig);for(let t of e.getters){if(!(t in i))throw new Error(`Invalid getter name: ${t} for plugin ${i.constructor}`);if(t in this.coreGetters)throw new Error(`Getter "${t}" is already defined.`);this.coreGetters[t]=i[t].bind(i)}i.import(t),this.corePlugins.push(i),this.coreHandlers.push(i),this.handlers.push(i)}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 wb(wS(e,this.state.recordChanges.bind(this.state),(e=>{this.checkDispatchAllowed(e).isSuccessful&&(this.isReplayingCommand=!0,this.dispatchToHandlers([this.range,...this.corePlugins,...this.coreViewsPlugins],e),this.isReplayingCommand=!1)})),this.config.transportService,e)}setupSessionEvents(){this.session.on("remote-revision-received",this,this.onRemoteRevisionReceived),this.session.on("revision-redone",this,this.finalize),this.session.on("revision-undone",this,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.uuidv4(),name:s("Anonymous").toString()},i=e.transportService||new gS;return{...e,mode:e.mode||"normal",custom:e.custom||{},external:e.external||{},transportService:i,client:t,moveClient:()=>{},snapshotRequested:!1,notifyUI:e=>this.trigger("notify-ui",e),lazyEvaluation:!("lazyEvaluation"in e)||e.lazyEvaluation}}setupCorePluginConfig(){return{getters:this.coreGetters,stateObserver:this.state,range:this.range,dispatch:this.dispatchFromCorePlugin,uuidGenerator:this.uuidGenerator,custom:this.config.custom,external:this.config.external}}setupUiPluginConfig(){return{getters:this.getters,stateObserver:this.state,dispatch:this.dispatch,selection:this.selection,moveClient:this.session.move.bind(this.session),custom:this.config.custom,uiActions:this.config,lazyEvaluation:this.config.lazyEvaluation}}checkDispatchAllowed(e){const t=this.handlers.map((t=>t.allowDispatch(e)));return new gn(t.flat())}finalize(){this.status=3;for(const e of this.handlers)e.finalize();this.status=0}dispatchToHandlers(e,t){t=Fe(t);for(const i of e)i.beforeHandle(t);for(const i of e)i.handle(t)}drawGrid(e){for(let[t,i]of this.renderers)e.ctx.save(),t.drawGrid(e,i),e.ctx.restore()}exportData(){let e=Rv();for(let t of this.handlers)t instanceof Mv&&t.export(e);return e.revisionId=this.session.getRevisionId()||Q,e=Fe(e),e}updateMode(e){"normal"!==e&&this.dispatch("STOP_EDITION",{cancel:!0}),this.config.mode=e,this.trigger("update")}exportXLSX(){this.dispatch("EVALUATE_CELLS");let e={...Rv(),sheets:[Tv(Cv,"Sheet1")]};for(let t of this.handlers)t instanceof Av&&t.exportForExcel(e);return e=Fe(e),uC(e)}garbageCollectExternalResources(){for(const e of this.corePlugins)e.garbageCollectExternalResources()}},e.Registry=xo,e.Revision=Cb,e.SPREADSHEET_DIMENSIONS=fC,e.Spreadsheet=uS,e.UIPlugin=Zv,e.__info__=mC,e.addFunction=function(e,t){Yu.add(e,t)},e.astToFormula=Km,e.compile=df,e.components=CC,e.convertAstNodes=Ym,e.coreTypes=dn,e.findCellInNewZone=so,e.functionCache=hf,e.helpers=bC,e.invalidateEvaluationCommands=ln,e.links=SC,e.load=Ev,e.parse=jm,e.readonlyAllowedCommands=hn,e.registries=vC,e.setTranslationMethod=function(e){i=e},e.tokenize=Tm,Object.defineProperty(e,"__esModule",{value:!0}),mC.version="16.2.21",mC.date="2023-11-02T09:31:50.545Z",mC.hash="cc30e85"}(this.o_spreadsheet=this.o_spreadsheet||{},owl);
|